From patchwork Tue Oct 15 21:04:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 21050 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5E2DE20D84 for ; Tue, 15 Oct 2013 21:04:39 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id va2sf33311369obc.9 for ; Tue, 15 Oct 2013 14:04:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=KkwDFs9dt716HN1qagirar8OkvysQ13/CXn0pzsz2UI=; b=KwFdNseW+OCRRA/fPJmSJp0RYVb6iLTR1fN1Wp+N2r6peYn0s9Wux86o8vvF2ZwcHt rnMpKlZh+CQ8+tGAFqlx9cz0xjy6UyBGuS9qewARQzS3podIZ0+JaxWpkDk1VvFeiFc1 s1LeYOm1aucENhiEwzW3ZtE6VI9zdfLX7NCs3GbC9m/s72VGZDGCoW0PQyy0kMJSiFEF CLozBptd+8mSmHA6K33TTs1U2CqrEEd/ptHc3kHhXQZYRhMPDr7r4qYvgk8qS7ySVc/n gXfrtd1k3UERvf/K9bUsssd9KkxklK79CEnVf3DxdYLWVifJ2qmL8Jde4ZMbEBdCSRZa 4iGA== X-Received: by 10.182.87.2 with SMTP id t2mr15163525obz.2.1381871078966; Tue, 15 Oct 2013 14:04:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.109.102 with SMTP id hr6ls269215qeb.13.gmail; Tue, 15 Oct 2013 14:04:38 -0700 (PDT) X-Received: by 10.52.22.110 with SMTP id c14mr2129270vdf.28.1381871078857; Tue, 15 Oct 2013 14:04:38 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id gq10si23438462vdc.30.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Oct 2013 14:04:38 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id cz12so607927veb.3 for ; Tue, 15 Oct 2013 14:04:38 -0700 (PDT) X-Gm-Message-State: ALoCoQkdn7S79YeCAWG4FRC4I4HlEPzOygKPsYBoDJliEPU1trUNzgZebjlpV+FISkyqh3wHNjDS X-Received: by 10.220.1.203 with SMTP id 11mr13570291vcg.15.1381871078766; Tue, 15 Oct 2013 14:04:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp328418vcz; Tue, 15 Oct 2013 14:04:38 -0700 (PDT) X-Received: by 10.224.73.200 with SMTP id r8mr32896893qaj.72.1381871078327; Tue, 15 Oct 2013 14:04:38 -0700 (PDT) Received: from mail-qc0-f179.google.com (mail-qc0-f179.google.com [209.85.216.179]) by mx.google.com with ESMTPS id kj7si14694743qcb.70.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Oct 2013 14:04:38 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.216.179 is neither permitted nor denied by best guess record for domain of dave.long@linaro.org) client-ip=209.85.216.179; Received: by mail-qc0-f179.google.com with SMTP id l4so6359239qcv.24 for ; Tue, 15 Oct 2013 14:04:38 -0700 (PDT) X-Received: by 10.49.25.1 with SMTP id y1mr49464592qef.22.1381871078097; Tue, 15 Oct 2013 14:04:38 -0700 (PDT) Received: from localhost.localdomain (pool-72-71-243-183.cncdnh.fast00.myfairpoint.net. [72.71.243.183]) by mx.google.com with ESMTPSA id i4sm159645128qan.0.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Oct 2013 14:04:37 -0700 (PDT) From: David Long To: linux-arm-kernel@lists.infradead.org Cc: Rabin Vincent , "Jon Medhurst (Tixy)" , Oleg Nesterov , Srikar Dronamraju , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH v2 05/13] uprobes: add arch write opcode hook Date: Tue, 15 Oct 2013 17:04:20 -0400 Message-Id: <1381871068-27660-6-git-send-email-dave.long@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1381871068-27660-1-git-send-email-dave.long@linaro.org> References: <1381871068-27660-1-git-send-email-dave.long@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: dave.long@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Rabin Vincent Allow arches to write the opcode with a custom function. ARM needs to customize the swbp instruction depending on the condition code of the instruction it replaces. Signed-off-by: Rabin Vincent Signed-off-by: David A. Long --- include/linux/uprobes.h | 3 +++ kernel/events/uprobes.c | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index a28dcbe..34375da 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -136,6 +136,9 @@ extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_ extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs); extern void __weak arch_uprobe_xol_copy(struct arch_uprobe *auprobe, void *vaddr); extern int __weak arch_uprobes_init(void); +extern void __weak arch_uprobe_write_opcode(struct arch_uprobe *auprobe, + void *vaddr, + uprobe_opcode_t opcode); #else /* !CONFIG_UPROBES */ struct uprobes_state { }; diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 9734a5f..cb01d82 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -248,6 +248,12 @@ static int verify_opcode(struct page *page, unsigned long vaddr, uprobe_opcode_t * have fixed length instructions. */ +void __weak arch_uprobe_write_opcode(struct arch_uprobe *auprobe, void *vaddr, + uprobe_opcode_t opcode) +{ + memcpy(vaddr, &opcode, UPROBE_SWBP_INSN_SIZE); +} + /* * write_opcode - write the opcode at a given virtual address. * @mm: the probed process address space. @@ -260,11 +266,12 @@ static int verify_opcode(struct page *page, unsigned long vaddr, uprobe_opcode_t * For mm @mm, write the opcode at @vaddr. * Return 0 (success) or a negative errno. */ -static int write_opcode(struct mm_struct *mm, unsigned long vaddr, - uprobe_opcode_t opcode) +static int write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, + unsigned long vaddr, uprobe_opcode_t opcode) { struct page *old_page, *new_page; struct vm_area_struct *vma; + void *vaddr_new; int ret; retry: @@ -285,7 +292,10 @@ retry: __SetPageUptodate(new_page); copy_highpage(new_page, old_page); - copy_to_page(new_page, vaddr, &opcode, UPROBE_SWBP_INSN_SIZE); + vaddr_new = kmap_atomic(new_page); + arch_uprobe_write_opcode(auprobe, vaddr_new + (vaddr & ~PAGE_MASK), + opcode); + kunmap_atomic(vaddr_new); ret = anon_vma_prepare(vma); if (ret) @@ -314,7 +324,7 @@ put_old: */ int __weak set_swbp(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr) { - return write_opcode(mm, vaddr, UPROBE_SWBP_INSN); + return write_opcode(auprobe, mm, vaddr, UPROBE_SWBP_INSN); } /** @@ -329,7 +339,8 @@ int __weak set_swbp(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned int __weak set_orig_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr) { - return write_opcode(mm, 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)