[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1322490213.2921.133.camel@twins>
Date: Mon, 28 Nov 2011 15:23:33 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Srikar Dronamraju <srikar@...ux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Oleg Nesterov <oleg@...hat.com>,
Andrew Morton <akpm@...ux-foundation.org>,
LKML <linux-kernel@...r.kernel.org>,
Linux-mm <linux-mm@...ck.org>, Ingo Molnar <mingo@...e.hu>,
Andi Kleen <andi@...stfloor.org>,
Christoph Hellwig <hch@...radead.org>,
Steven Rostedt <rostedt@...dmis.org>,
Roland McGrath <roland@...k.frob.com>,
Thomas Gleixner <tglx@...utronix.de>,
Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
Arnaldo Carvalho de Melo <acme@...radead.org>,
Anton Arapov <anton@...hat.com>,
Ananth N Mavinakayanahalli <ananth@...ibm.com>,
Jim Keniston <jkenisto@...ux.vnet.ibm.com>,
Stephen Wilson <wilsons@...rt.ca>
Subject: Re: [PATCH v7 3.2-rc2 5/30] uprobes: copy of the original
instruction.
On Fri, 2011-11-18 at 16:37 +0530, Srikar Dronamraju wrote:
> +static int __copy_insn(struct address_space *mapping,
> + struct vm_area_struct *vma, char *insn,
> + unsigned long nbytes, unsigned long offset)
> +{
> + struct file *filp = vma->vm_file;
> + struct page *page;
> + void *vaddr;
> + unsigned long off1;
> + unsigned long idx;
> +
> + if (!filp)
> + return -EINVAL;
> +
> + idx = (unsigned long)(offset >> PAGE_CACHE_SHIFT);
> + off1 = offset &= ~PAGE_MASK;
> +
> + /*
> + * Ensure that the page that has the original instruction is
> + * populated and in page-cache.
> + */
> + page = read_mapping_page(mapping, idx, filp);
> + if (IS_ERR(page))
> + return -ENOMEM;
> +
> + vaddr = kmap_atomic(page);
> + memcpy(insn, vaddr + off1, nbytes);
> + kunmap_atomic(vaddr);
> + page_cache_release(page);
> + return 0;
> +}
> +
> +static int copy_insn(struct uprobe *uprobe, struct vm_area_struct *vma,
> + unsigned long addr)
> +{
> + struct address_space *mapping;
> + int bytes;
> + unsigned long nbytes;
> +
> + addr &= ~PAGE_MASK;
> + nbytes = PAGE_SIZE - addr;
> + mapping = uprobe->inode->i_mapping;
> +
> + /* Instruction at end of binary; copy only available bytes */
> + if (uprobe->offset + MAX_UINSN_BYTES > uprobe->inode->i_size)
> + bytes = uprobe->inode->i_size - uprobe->offset;
> + else
> + bytes = MAX_UINSN_BYTES;
> +
> + /* Instruction at the page-boundary; copy bytes in second page */
> + if (nbytes < bytes) {
> + if (__copy_insn(mapping, vma, uprobe->insn + nbytes,
> + bytes - nbytes, uprobe->offset + nbytes))
> + return -ENOMEM;
You just lost your possible -EINVAL return value.
> +
> + bytes = nbytes;
> + }
> + return __copy_insn(mapping, vma, uprobe->insn, bytes, uprobe->offset);
> +}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists