Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3343e6a authored by Srikar Dronamraju's avatar Srikar Dronamraju Committed by Ingo Molnar
Browse files

uprobes/core: Make order of function parameters consistent across functions



If a function takes struct uprobe or struct arch_uprobe, then it
is passed as the first parameter.

This is pure cleanup, no functional change intended.

Signed-off-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Jim Keniston <jkenisto@linux.vnet.ibm.com>
Cc: Linux-mm <linux-mm@kvack.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20120312092530.5379.18394.sendpatchset@srdronam.in.ibm.com


Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 900771a4
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -39,5 +39,5 @@ struct arch_uprobe {
#endif
#endif
};
};


extern int arch_uprobes_analyze_insn(struct mm_struct *mm, struct arch_uprobe *arch_uprobe);
extern int arch_uprobes_analyze_insn(struct arch_uprobe *aup, struct mm_struct *mm);
#endif	/* _ASM_UPROBES_H */
#endif	/* _ASM_UPROBES_H */
+8 −7
Original line number Original line Diff line number Diff line
@@ -297,7 +297,8 @@ static void prepare_fixups(struct arch_uprobe *auprobe, struct insn *insn)
 *  - There's never a SIB byte.
 *  - There's never a SIB byte.
 *  - The displacement is always 4 bytes.
 *  - The displacement is always 4 bytes.
 */
 */
static void handle_riprel_insn(struct mm_struct *mm, struct arch_uprobe *auprobe, struct insn *insn)
static void
handle_riprel_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, struct insn *insn)
{
{
	u8 *cursor;
	u8 *cursor;
	u8 reg;
	u8 reg;
@@ -381,19 +382,19 @@ static int validate_insn_64bits(struct arch_uprobe *auprobe, struct insn *insn)
	return -ENOTSUPP;
	return -ENOTSUPP;
}
}


static int validate_insn_bits(struct mm_struct *mm, struct arch_uprobe *auprobe, struct insn *insn)
static int validate_insn_bits(struct arch_uprobe *auprobe, struct mm_struct *mm, struct insn *insn)
{
{
	if (mm->context.ia32_compat)
	if (mm->context.ia32_compat)
		return validate_insn_32bits(auprobe, insn);
		return validate_insn_32bits(auprobe, insn);
	return validate_insn_64bits(auprobe, insn);
	return validate_insn_64bits(auprobe, insn);
}
}
#else /* 32-bit: */
#else /* 32-bit: */
static void handle_riprel_insn(struct mm_struct *mm, struct arch_uprobe *auprobe, struct insn *insn)
static void handle_riprel_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, struct insn *insn)
{
{
	/* No RIP-relative addressing on 32-bit */
	/* No RIP-relative addressing on 32-bit */
}
}


static int validate_insn_bits(struct mm_struct *mm, struct arch_uprobe *auprobe, struct insn *insn)
static int validate_insn_bits(struct arch_uprobe *auprobe, struct mm_struct *mm,  struct insn *insn)
{
{
	return validate_insn_32bits(auprobe, insn);
	return validate_insn_32bits(auprobe, insn);
}
}
@@ -405,17 +406,17 @@ static int validate_insn_bits(struct mm_struct *mm, struct arch_uprobe *auprobe,
 * @arch_uprobe: the probepoint information.
 * @arch_uprobe: the probepoint information.
 * Return 0 on success or a -ve number on error.
 * Return 0 on success or a -ve number on error.
 */
 */
int arch_uprobes_analyze_insn(struct mm_struct *mm, struct arch_uprobe *auprobe)
int arch_uprobes_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm)
{
{
	int ret;
	int ret;
	struct insn insn;
	struct insn insn;


	auprobe->fixups = 0;
	auprobe->fixups = 0;
	ret = validate_insn_bits(mm, auprobe, &insn);
	ret = validate_insn_bits(auprobe, mm, &insn);
	if (ret != 0)
	if (ret != 0)
		return ret;
		return ret;


	handle_riprel_insn(mm, auprobe, &insn);
	handle_riprel_insn(auprobe, mm, &insn);
	prepare_fixups(auprobe, &insn);
	prepare_fixups(auprobe, &insn);


	return 0;
	return 0;
+6 −6
Original line number Original line Diff line number Diff line
@@ -52,20 +52,20 @@ struct uprobe_consumer {
};
};


#ifdef CONFIG_UPROBES
#ifdef CONFIG_UPROBES
extern int __weak set_bkpt(struct mm_struct *mm, struct arch_uprobe *auprobe, unsigned long vaddr);
extern int __weak set_bkpt(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
extern int __weak set_orig_insn(struct mm_struct *mm, struct arch_uprobe *auprobe, unsigned long vaddr, bool verify);
extern int __weak set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm,  unsigned long vaddr, bool verify);
extern bool __weak is_bkpt_insn(uprobe_opcode_t *insn);
extern bool __weak is_bkpt_insn(uprobe_opcode_t *insn);
extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer);
extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer);
extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
extern int uprobe_mmap(struct vm_area_struct *vma);
extern int uprobe_mmap(struct vm_area_struct *vma);
#else /* CONFIG_UPROBES is not defined */
#else /* CONFIG_UPROBES is not defined */
static inline int
static inline int
uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer)
uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
{
{
	return -ENOSYS;
	return -ENOSYS;
}
}
static inline void
static inline void
uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer)
uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
{
{
}
}
static inline int uprobe_mmap(struct vm_area_struct *vma)
static inline int uprobe_mmap(struct vm_area_struct *vma)
+48 −45
Original line number Original line Diff line number Diff line
@@ -192,8 +192,8 @@ bool __weak is_bkpt_insn(uprobe_opcode_t *insn)


/*
/*
 * write_opcode - write the opcode at a given virtual address.
 * write_opcode - write the opcode at a given virtual address.
 * @auprobe: arch breakpointing information.
 * @mm: the probed process address space.
 * @mm: the probed process address space.
 * @arch_uprobe: the breakpointing information.
 * @vaddr: the virtual address to store the opcode.
 * @vaddr: the virtual address to store the opcode.
 * @opcode: opcode to be written at @vaddr.
 * @opcode: opcode to be written at @vaddr.
 *
 *
@@ -203,7 +203,7 @@ bool __weak is_bkpt_insn(uprobe_opcode_t *insn)
 * For mm @mm, write the opcode at @vaddr.
 * For mm @mm, write the opcode at @vaddr.
 * Return 0 (success) or a negative errno.
 * Return 0 (success) or a negative errno.
 */
 */
static int write_opcode(struct mm_struct *mm, struct arch_uprobe *auprobe,
static int write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
			unsigned long vaddr, uprobe_opcode_t opcode)
			unsigned long vaddr, uprobe_opcode_t opcode)
{
{
	struct page *old_page, *new_page;
	struct page *old_page, *new_page;
@@ -334,14 +334,14 @@ static int is_bkpt_at_addr(struct mm_struct *mm, unsigned long vaddr)


/**
/**
 * set_bkpt - store breakpoint at a given address.
 * set_bkpt - store breakpoint at a given address.
 * @auprobe: arch specific probepoint information.
 * @mm: the probed process address space.
 * @mm: the probed process address space.
 * @uprobe: the probepoint information.
 * @vaddr: the virtual address to insert the opcode.
 * @vaddr: the virtual address to insert the opcode.
 *
 *
 * For mm @mm, store the breakpoint instruction at @vaddr.
 * For mm @mm, store the breakpoint instruction at @vaddr.
 * Return 0 (success) or a negative errno.
 * Return 0 (success) or a negative errno.
 */
 */
int __weak set_bkpt(struct mm_struct *mm, struct arch_uprobe *auprobe, unsigned long vaddr)
int __weak set_bkpt(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr)
{
{
	int result;
	int result;


@@ -352,13 +352,13 @@ int __weak set_bkpt(struct mm_struct *mm, struct arch_uprobe *auprobe, unsigned
	if (result)
	if (result)
		return result;
		return result;


	return write_opcode(mm, auprobe, vaddr, UPROBE_BKPT_INSN);
	return write_opcode(auprobe, mm, vaddr, UPROBE_BKPT_INSN);
}
}


/**
/**
 * set_orig_insn - Restore the original instruction.
 * set_orig_insn - Restore the original instruction.
 * @mm: the probed process address space.
 * @mm: the probed process address space.
 * @uprobe: the probepoint information.
 * @auprobe: arch specific probepoint information.
 * @vaddr: the virtual address to insert the opcode.
 * @vaddr: the virtual address to insert the opcode.
 * @verify: if true, verify existance of breakpoint instruction.
 * @verify: if true, verify existance of breakpoint instruction.
 *
 *
@@ -366,7 +366,7 @@ int __weak set_bkpt(struct mm_struct *mm, struct arch_uprobe *auprobe, unsigned
 * Return 0 (success) or a negative errno.
 * Return 0 (success) or a negative errno.
 */
 */
int __weak
int __weak
set_orig_insn(struct mm_struct *mm, struct arch_uprobe *auprobe, unsigned long vaddr, bool verify)
set_orig_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr, bool verify)
{
{
	if (verify) {
	if (verify) {
		int result;
		int result;
@@ -378,7 +378,7 @@ set_orig_insn(struct mm_struct *mm, struct arch_uprobe *auprobe, unsigned long v
		if (result != 1)
		if (result != 1)
			return result;
			return result;
	}
	}
	return write_opcode(mm, auprobe, vaddr, *(uprobe_opcode_t *)auprobe->insn);
	return write_opcode(auprobe, mm, vaddr, *(uprobe_opcode_t *)auprobe->insn);
}
}


static int match_uprobe(struct uprobe *l, struct uprobe *r)
static int match_uprobe(struct uprobe *l, struct uprobe *r)
@@ -525,30 +525,30 @@ static struct uprobe *alloc_uprobe(struct inode *inode, loff_t offset)


/* Returns the previous consumer */
/* Returns the previous consumer */
static struct uprobe_consumer *
static struct uprobe_consumer *
consumer_add(struct uprobe *uprobe, struct uprobe_consumer *consumer)
consumer_add(struct uprobe *uprobe, struct uprobe_consumer *uc)
{
{
	down_write(&uprobe->consumer_rwsem);
	down_write(&uprobe->consumer_rwsem);
	consumer->next = uprobe->consumers;
	uc->next = uprobe->consumers;
	uprobe->consumers = consumer;
	uprobe->consumers = uc;
	up_write(&uprobe->consumer_rwsem);
	up_write(&uprobe->consumer_rwsem);


	return consumer->next;
	return uc->next;
}
}


/*
/*
 * For uprobe @uprobe, delete the consumer @consumer.
 * For uprobe @uprobe, delete the consumer @uc.
 * Return true if the @consumer is deleted successfully
 * Return true if the @uc is deleted successfully
 * or return false.
 * or return false.
 */
 */
static bool consumer_del(struct uprobe *uprobe, struct uprobe_consumer *consumer)
static bool consumer_del(struct uprobe *uprobe, struct uprobe_consumer *uc)
{
{
	struct uprobe_consumer **con;
	struct uprobe_consumer **con;
	bool ret = false;
	bool ret = false;


	down_write(&uprobe->consumer_rwsem);
	down_write(&uprobe->consumer_rwsem);
	for (con = &uprobe->consumers; *con; con = &(*con)->next) {
	for (con = &uprobe->consumers; *con; con = &(*con)->next) {
		if (*con == consumer) {
		if (*con == uc) {
			*con = consumer->next;
			*con = uc->next;
			ret = true;
			ret = true;
			break;
			break;
		}
		}
@@ -558,8 +558,8 @@ static bool consumer_del(struct uprobe *uprobe, struct uprobe_consumer *consumer
	return ret;
	return ret;
}
}


static int __copy_insn(struct address_space *mapping,
static int
			struct vm_area_struct *vma, char *insn,
__copy_insn(struct address_space *mapping, struct vm_area_struct *vma, char *insn,
			unsigned long nbytes, unsigned long offset)
			unsigned long nbytes, unsigned long offset)
{
{
	struct file *filp = vma->vm_file;
	struct file *filp = vma->vm_file;
@@ -590,7 +590,8 @@ static int __copy_insn(struct address_space *mapping,
	return 0;
	return 0;
}
}


static int copy_insn(struct uprobe *uprobe, struct vm_area_struct *vma, unsigned long addr)
static int
copy_insn(struct uprobe *uprobe, struct vm_area_struct *vma, unsigned long addr)
{
{
	struct address_space *mapping;
	struct address_space *mapping;
	unsigned long nbytes;
	unsigned long nbytes;
@@ -617,7 +618,8 @@ static int copy_insn(struct uprobe *uprobe, struct vm_area_struct *vma, unsigned
	return __copy_insn(mapping, vma, uprobe->arch.insn, bytes, uprobe->offset);
	return __copy_insn(mapping, vma, uprobe->arch.insn, bytes, uprobe->offset);
}
}


static int install_breakpoint(struct mm_struct *mm, struct uprobe *uprobe,
static int
install_breakpoint(struct uprobe *uprobe, struct mm_struct *mm,
			struct vm_area_struct *vma, loff_t vaddr)
			struct vm_area_struct *vma, loff_t vaddr)
{
{
	unsigned long addr;
	unsigned long addr;
@@ -643,20 +645,21 @@ static int install_breakpoint(struct mm_struct *mm, struct uprobe *uprobe,
		if (is_bkpt_insn((uprobe_opcode_t *)uprobe->arch.insn))
		if (is_bkpt_insn((uprobe_opcode_t *)uprobe->arch.insn))
			return -EEXIST;
			return -EEXIST;


		ret = arch_uprobes_analyze_insn(mm, &uprobe->arch);
		ret = arch_uprobes_analyze_insn(&uprobe->arch, mm);
		if (ret)
		if (ret)
			return ret;
			return ret;


		uprobe->flags |= UPROBE_COPY_INSN;
		uprobe->flags |= UPROBE_COPY_INSN;
	}
	}
	ret = set_bkpt(mm, &uprobe->arch, addr);
	ret = set_bkpt(&uprobe->arch, mm, addr);


	return ret;
	return ret;
}
}


static void remove_breakpoint(struct mm_struct *mm, struct uprobe *uprobe, loff_t vaddr)
static void
remove_breakpoint(struct uprobe *uprobe, struct mm_struct *mm, loff_t vaddr)
{
{
	set_orig_insn(mm, &uprobe->arch, (unsigned long)vaddr, true);
	set_orig_insn(&uprobe->arch, mm, (unsigned long)vaddr, true);
}
}


static void delete_uprobe(struct uprobe *uprobe)
static void delete_uprobe(struct uprobe *uprobe)
@@ -671,9 +674,9 @@ static void delete_uprobe(struct uprobe *uprobe)
	atomic_dec(&uprobe_events);
	atomic_dec(&uprobe_events);
}
}


static struct vma_info *__find_next_vma_info(struct list_head *head,
static struct vma_info *
			loff_t offset, struct address_space *mapping,
__find_next_vma_info(struct address_space *mapping, struct list_head *head,
			struct vma_info *vi, bool is_register)
			struct vma_info *vi, loff_t offset, bool is_register)
{
{
	struct prio_tree_iter iter;
	struct prio_tree_iter iter;
	struct vm_area_struct *vma;
	struct vm_area_struct *vma;
@@ -719,8 +722,8 @@ static struct vma_info *__find_next_vma_info(struct list_head *head,
 * yet been inserted.
 * yet been inserted.
 */
 */
static struct vma_info *
static struct vma_info *
find_next_vma_info(struct list_head *head, loff_t offset, struct address_space *mapping,
find_next_vma_info(struct address_space *mapping, struct list_head *head,
		   bool is_register)
		loff_t offset, bool is_register)
{
{
	struct vma_info *vi, *retvi;
	struct vma_info *vi, *retvi;


@@ -729,7 +732,7 @@ find_next_vma_info(struct list_head *head, loff_t offset, struct address_space *
		return ERR_PTR(-ENOMEM);
		return ERR_PTR(-ENOMEM);


	mutex_lock(&mapping->i_mmap_mutex);
	mutex_lock(&mapping->i_mmap_mutex);
	retvi = __find_next_vma_info(head, offset, mapping, vi, is_register);
	retvi = __find_next_vma_info(mapping, head, vi, offset, is_register);
	mutex_unlock(&mapping->i_mmap_mutex);
	mutex_unlock(&mapping->i_mmap_mutex);


	if (!retvi)
	if (!retvi)
@@ -754,7 +757,7 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register)
	ret = 0;
	ret = 0;


	for (;;) {
	for (;;) {
		vi = find_next_vma_info(&try_list, uprobe->offset, mapping, is_register);
		vi = find_next_vma_info(mapping, &try_list, uprobe->offset, is_register);
		if (!vi)
		if (!vi)
			break;
			break;


@@ -784,9 +787,9 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register)
		}
		}


		if (is_register)
		if (is_register)
			ret = install_breakpoint(mm, uprobe, vma, vi->vaddr);
			ret = install_breakpoint(uprobe, mm, vma, vi->vaddr);
		else
		else
			remove_breakpoint(mm, uprobe, vi->vaddr);
			remove_breakpoint(uprobe, mm, vi->vaddr);


		up_read(&mm->mmap_sem);
		up_read(&mm->mmap_sem);
		mmput(mm);
		mmput(mm);
@@ -823,25 +826,25 @@ static void __uprobe_unregister(struct uprobe *uprobe)
 * uprobe_register - register a probe
 * uprobe_register - register a probe
 * @inode: the file in which the probe has to be placed.
 * @inode: the file in which the probe has to be placed.
 * @offset: offset from the start of the file.
 * @offset: offset from the start of the file.
 * @consumer: information on howto handle the probe..
 * @uc: information on howto handle the probe..
 *
 *
 * Apart from the access refcount, uprobe_register() takes a creation
 * Apart from the access refcount, uprobe_register() takes a creation
 * refcount (thro alloc_uprobe) if and only if this @uprobe is getting
 * refcount (thro alloc_uprobe) if and only if this @uprobe is getting
 * inserted into the rbtree (i.e first consumer for a @inode:@offset
 * inserted into the rbtree (i.e first consumer for a @inode:@offset
 * tuple).  Creation refcount stops uprobe_unregister from freeing the
 * tuple).  Creation refcount stops uprobe_unregister from freeing the
 * @uprobe even before the register operation is complete. Creation
 * @uprobe even before the register operation is complete. Creation
 * refcount is released when the last @consumer for the @uprobe
 * refcount is released when the last @uc for the @uprobe
 * unregisters.
 * unregisters.
 *
 *
 * Return errno if it cannot successully install probes
 * Return errno if it cannot successully install probes
 * else return 0 (success)
 * else return 0 (success)
 */
 */
int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer)
int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
{
{
	struct uprobe *uprobe;
	struct uprobe *uprobe;
	int ret;
	int ret;


	if (!inode || !consumer || consumer->next)
	if (!inode || !uc || uc->next)
		return -EINVAL;
		return -EINVAL;


	if (offset > i_size_read(inode))
	if (offset > i_size_read(inode))
@@ -851,7 +854,7 @@ int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *
	mutex_lock(uprobes_hash(inode));
	mutex_lock(uprobes_hash(inode));
	uprobe = alloc_uprobe(inode, offset);
	uprobe = alloc_uprobe(inode, offset);


	if (uprobe && !consumer_add(uprobe, consumer)) {
	if (uprobe && !consumer_add(uprobe, uc)) {
		ret = __uprobe_register(uprobe);
		ret = __uprobe_register(uprobe);
		if (ret) {
		if (ret) {
			uprobe->consumers = NULL;
			uprobe->consumers = NULL;
@@ -871,13 +874,13 @@ int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *
 * uprobe_unregister - unregister a already registered probe.
 * uprobe_unregister - unregister a already registered probe.
 * @inode: the file in which the probe has to be removed.
 * @inode: the file in which the probe has to be removed.
 * @offset: offset from the start of the file.
 * @offset: offset from the start of the file.
 * @consumer: identify which probe if multiple probes are colocated.
 * @uc: identify which probe if multiple probes are colocated.
 */
 */
void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer)
void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
{
{
	struct uprobe *uprobe;
	struct uprobe *uprobe;


	if (!inode || !consumer)
	if (!inode || !uc)
		return;
		return;


	uprobe = find_uprobe(inode, offset);
	uprobe = find_uprobe(inode, offset);
@@ -886,7 +889,7 @@ void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consume


	mutex_lock(uprobes_hash(inode));
	mutex_lock(uprobes_hash(inode));


	if (consumer_del(uprobe, consumer)) {
	if (consumer_del(uprobe, uc)) {
		if (!uprobe->consumers) {
		if (!uprobe->consumers) {
			__uprobe_unregister(uprobe);
			__uprobe_unregister(uprobe);
			uprobe->flags &= ~UPROBE_RUN_HANDLER;
			uprobe->flags &= ~UPROBE_RUN_HANDLER;
@@ -993,7 +996,7 @@ int uprobe_mmap(struct vm_area_struct *vma)
		if (!ret) {
		if (!ret) {
			vaddr = vma_address(vma, uprobe->offset);
			vaddr = vma_address(vma, uprobe->offset);
			if (vaddr >= vma->vm_start && vaddr < vma->vm_end) {
			if (vaddr >= vma->vm_start && vaddr < vma->vm_end) {
				ret = install_breakpoint(vma->vm_mm, uprobe, vma, vaddr);
				ret = install_breakpoint(uprobe, vma->vm_mm, vma, vaddr);
				/* Ignore double add: */
				/* Ignore double add: */
				if (ret == -EEXIST)
				if (ret == -EEXIST)
					ret = 0;
					ret = 0;