From patchwork Wed Apr 9 18:45:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 3957091 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 276D0BFF02 for ; Wed, 9 Apr 2014 18:46:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 135A4206A4 for ; Wed, 9 Apr 2014 18:46:03 +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 4555E206A3 for ; Wed, 9 Apr 2014 18:46:01 +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 1WXxVQ-00032N-0Q; Wed, 09 Apr 2014 18:45:52 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXxVN-0008RT-OJ; Wed, 09 Apr 2014 18:45:49 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXxVD-0008Qk-AP for linux-arm-kernel@lists.infradead.org; Wed, 09 Apr 2014 18:45:40 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s39IivXm011647 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 9 Apr 2014 14:44:57 -0400 Received: from tranklukator.brq.redhat.com (dhcp-1-104.brq.redhat.com [10.34.1.104]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id s39IirdD025180; Wed, 9 Apr 2014 14:44:54 -0400 Received: by tranklukator.brq.redhat.com (nbSMTP-1.00) for uid 500 oleg@redhat.com; Wed, 9 Apr 2014 20:45:11 +0200 (CEST) Date: Wed, 9 Apr 2014 20:45:07 +0200 From: Oleg Nesterov To: Victor Kamensky Subject: Re: [PATCH v2] ARM: uprobes need icache flush after xol write Message-ID: <20140409184507.GA1058@redhat.com> References: <1397023132-10313-1-git-send-email-victor.kamensky@linaro.org> <1397023132-10313-2-git-send-email-victor.kamensky@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1397023132-10313-2-git-send-email-victor.kamensky@linaro.org> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140409_144539_502239_E7225F52 X-CRM114-Status: GOOD ( 21.39 ) X-Spam-Score: -7.2 (-------) Cc: tixy@linaro.org, linaro-kernel@lists.linaro.org, ananth@in.ibm.com, rmk@arm.linux.org.uk, will.deacon@arm.com, rabin@rab.in, dave.long@linaro.org, taras.kondratiuk@linaro.org, Dave.Martin@arm.com, linux-arm-kernel@lists.infradead.org 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: , 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 Victor, sorry, I can't even read this thread now, will try to reply tomorrow... But at first glance, On 04/08, Victor Kamensky wrote: > > Because on ARM cache flush function need kernel address ... > --- a/kernel/events/uprobes.c > +++ b/kernel/events/uprobes.c > @@ -1287,6 +1287,7 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe) > { > struct xol_area *area; > unsigned long xol_vaddr; > + void *xol_page_kaddr; > > area = get_xol_area(); > if (!area) > @@ -1296,14 +1297,22 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe) > if (unlikely(!xol_vaddr)) > return 0; > > - /* 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. > + * We don't use copy_to_page here because we need kernel page > + * addr to invalidate caches correctly > */ > - flush_dcache_page(area->page); > + xol_page_kaddr = kmap_atomic(area->page); > + > + /* Initialize the slot */ > + memcpy(xol_page_kaddr + (xol_vaddr & ~PAGE_MASK), > + &uprobe->arch.ixol, > + sizeof(uprobe->arch.ixol)); > + > + arch_uprobe_flush_xol_access(area->page, xol_vaddr, > + xol_page_kaddr + (xol_vaddr & ~PAGE_MASK), > + sizeof(uprobe->arch.ixol)); > + > + kunmap_atomic(xol_page_kaddr); > > return xol_vaddr; > } > @@ -1346,6 +1355,18 @@ static void xol_free_insn_slot(struct task_struct *tsk) > } > } > > +void __weak arch_uprobe_flush_xol_access(struct page *page, unsigned long vaddr, > + void *kaddr, 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); > +} In this case I'd suggest to move this kmap/memcpy horror into arch_ helper. IOW, something like below. If arm needs the kernel address we are writing to, let it do kmap/etc in its implementation. Oleg. --- x/kernel/events/uprobes.c +++ x/kernel/events/uprobes.c @@ -1291,18 +1291,16 @@ static unsigned long xol_get_insn_slot(s if (unlikely(!xol_vaddr)) return 0; - /* 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_xxx(area->page, xol_vaddr, ...); return xol_vaddr; } +void __weak arch_uprobe_xxx(page, xol_vaddr, ...) +{ + copy_to_page(page, xol_vaddr, ...) + flush_dcache_page(page); +} + /* * xol_free_insn_slot - If slot was earlier allocated by * @xol_get_insn_slot(), make the slot available for