From patchwork Tue Apr 8 03:04:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Kamensky X-Patchwork-Id: 3950841 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 13331BFF02 for ; Tue, 8 Apr 2014 19:17:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 253C9204AF for ; Tue, 8 Apr 2014 19:17:54 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1FFBF204AE for ; Tue, 8 Apr 2014 19:17:53 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXY1l-0002Hv-CY; Tue, 08 Apr 2014 15:33:33 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXY1J-0006K8-Jp; Tue, 08 Apr 2014 15:33:06 +0000 Received: from bombadil.infradead.org ([2001:1868:205::9]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXXkT-0003gg-Pj for linux-arm-kernel@merlin.infradead.org; Tue, 08 Apr 2014 15:15:41 +0000 Received: from mail-pd0-f171.google.com ([209.85.192.171]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXMLV-0005Up-8t for linux-arm-kernel@lists.infradead.org; Tue, 08 Apr 2014 03:05:10 +0000 Received: by mail-pd0-f171.google.com with SMTP id r10so356606pdi.16 for ; Mon, 07 Apr 2014 20:04:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C9eDk82uFUB3RfFN7/hcROCRmD6hcW/GVwnW6M31Yzo=; b=dW9KwzcfyOoRdIXxMZTnE5PtFIDySoPitkGic+WfktKk6mvSyXyUiRO3EXzvEXzdFe bXNqTz87XAm4jv3zfFbOjDyVKDvXtlR6ONWY41O2IglxpLBIxVB1/DxrkiFqlBTJC98s c73Xsqw0l7Nc2awVaBqhNLpq6OJ/CLFHt4n+hzC5FUgEICv5ypwSeelPaWIW66Ya8jr3 +DtWw0+cuZZXABaFkgY7HxEC8MQ/hdZ8sMopJ3oOuKZ2vkU/4itEefDqk+owe3NRYAEl qRww9Wxj4r1XVtssXM+FEmVrNETYNvOwq3zQcHAY8ZkSHyYCvALqsWuckTqD63yFABKk rSUA== X-Gm-Message-State: ALoCoQniJ8pcUYFCKzmnXdnqXAis6LuADN4RhAeCJaMS+rtjxZAH0NbDHFu9hyeOFQseo3dwV2jo X-Received: by 10.67.15.42 with SMTP id fl10mr1455837pad.30.1396926280724; Mon, 07 Apr 2014 20:04:40 -0700 (PDT) Received: from kamensky-w530.cisco.com (128-107-239-233.cisco.com. [128.107.239.233]) by mx.google.com with ESMTPSA id ei4sm1097725pbb.42.2014.04.07.20.04.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Apr 2014 20:04:40 -0700 (PDT) From: Victor Kamensky To: linux-arm-kernel@lists.infradead.org, dave.long@linaro.org, oleg@redhat.com Subject: [RFC PATCH] ARM: uprobes need icache flush after xol write Date: Mon, 7 Apr 2014 20:04:20 -0700 Message-Id: <1396926260-7705-2-git-send-email-victor.kamensky@linaro.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1396926260-7705-1-git-send-email-victor.kamensky@linaro.org> References: <1396926260-7705-1-git-send-email-victor.kamensky@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140407_200509_356480_7F4721AA X-CRM114-Status: GOOD ( 14.20 ) X-Spam-Score: -0.0 (/) Cc: tixy@linaro.org, linaro-kernel@lists.linaro.org, ananth@in.ibm.com, Victor Kamensky , taras.kondratiuk@linaro.org, will.deacon@arm.com, rabin@rab.in, Dave.Martin@arm.com, rmk@arm.linux.org.uk X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After instruction write into xol area, on ARM V7 architecture code need to flush icache to sync up dcache and icache. Having just 'flush_dcache_page(page)' call is not enough - it is possible to have stale instruction sitting in icache for given xol area slot address. Introduce arch_uprobe_xol_sync_dcache_icache weak function that by default calls 'flush_dcache_page(page)' and on ARM define one that calls __cpuc_coherent_user_range. Signed-off-by: Victor Kamensky --- arch/arm/kernel/uprobes.c | 6 ++++++ include/linux/uprobes.h | 3 +++ kernel/events/uprobes.c | 20 +++++++++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/arch/arm/kernel/uprobes.c b/arch/arm/kernel/uprobes.c index f9bacee..841750b 100644 --- a/arch/arm/kernel/uprobes.c +++ b/arch/arm/kernel/uprobes.c @@ -113,6 +113,12 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, return 0; } +void arch_uprobe_xol_sync_dcache_icache(struct page *page, + unsigned long addr, unsigned long size) +{ + __cpuc_coherent_user_range(addr, size); +} + int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs) { struct uprobe_task *utask = current->utask; diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index edff2b9..2fe3dfd 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -32,6 +32,7 @@ struct vm_area_struct; struct mm_struct; struct inode; struct notifier_block; +struct page; #define UPROBE_HANDLER_REMOVE 1 #define UPROBE_HANDLER_MASK 1 @@ -127,6 +128,8 @@ extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned l extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs); extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs); extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs); +extern void __weak arch_uprobe_xol_sync_dcache_icache(struct page *page, + unsigned long addr, unsigned long size); #else /* !CONFIG_UPROBES */ struct uprobes_state { }; diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 04709b6..0027883 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -1299,11 +1299,9 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe) /* Initialize the slot */ copy_to_page(area->page, xol_vaddr, &uprobe->arch.ixol, sizeof(uprobe->arch.ixol)); - /* - * We probably need flush_icache_user_range() but it needs vma. - * This should work on supported architectures too. - */ - flush_dcache_page(area->page); + + arch_uprobe_xol_sync_dcache_icache(area->page, + xol_vaddr, sizeof(uprobe->arch.ixol)); return xol_vaddr; } @@ -1346,6 +1344,18 @@ static void xol_free_insn_slot(struct task_struct *tsk) } } +void __weak arch_uprobe_xol_sync_dcache_icache(struct page *page, + unsigned long addr, unsigned long len) +{ + /* + * We probably need flush_icache_user_range() but it needs vma. + * This should work on most of architectures by default. If + * architecture needs to do something different it can define + * its own version of the function. + */ + flush_dcache_page(page); +} + /** * uprobe_get_swbp_addr - compute address of swbp given post-swbp regs * @regs: Reflects the saved state of the task after it has hit a breakpoint