Received: by 10.213.65.68 with SMTP id h4csp497920imn; Fri, 6 Apr 2018 04:09:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/wXy1vQhsAiXY8hAdx0rF1lOxSORZ/0DbC7y6iKb/Eaj6MYLJoZKZLnNIMI4K6KuKIUhVD X-Received: by 2002:a17:902:566:: with SMTP id 93-v6mr26076504plf.327.1523012948532; Fri, 06 Apr 2018 04:09:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523012948; cv=none; d=google.com; s=arc-20160816; b=nSr092TqgAfJeetQSZaKG2cK6zZSsE5kq4LsJEbl15gzXIotSrFsRFDOfZVZeUHJiy aVqRCY3MiVAaFnPVqKNpa1QMElLj5DwwfjbOFkwKsW9gCXUxWoKCReAGiekdE0Mee2is Vrnk0wVYRgDOAp7bti0yXBrgYaQxBoq30mr1Ax7k8AvNmWHTujRTKqVZmEME3fut7e98 W2/7itKi20XFTRcN6YRqPAvMwkUozNv0o6sTPPkUoywKIyqjuVI0/4DJf0m2YaM+iIYg u6Al7RNnZsWfMWl4Pie9NVNr86oaGrUFLDqr17Ivq8t3l/IzsG5kc46IwpqtBIQrvINk +h5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=ekgWmpjKXC8yIruD2AD2Px9tcTd7mMgRDrX0nKmFBPA=; b=NYOU5qdxppysEgRxzgipE6/lhcY37Vqq+il9AJxCqZrDWv7SdjH5goSYHFfxsWfoLb HcoUhuU4/yJym4bGQq/h+oQD391FIHH8EV9TuBIkHiCFr6106a76sv9ESaV54YHggcb0 otwugk9XV2DUzSscbyu7VygQIWXQEjw/QPtUElBMsaa4pEzHiiwzFzPkui8x1lcibmeu EYJvPf/0oY85dnj9SdpkMucJ/nQQPdlEJWDtoiQxSTdN5XnE4wPr4uRXHcMVYPCpkTKP KhuhzPpXX+wZG5etZwGkKw953USGQwWV10ki7wa5724NMZ4vmtS4b05OjDhPwHGVoCAx BxxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2si6950569pgc.753.2018.04.06.04.08.54; Fri, 06 Apr 2018 04:09:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752156AbeDFLHK (ORCPT + 99 others); Fri, 6 Apr 2018 07:07:10 -0400 Received: from foss.arm.com ([217.140.101.70]:35200 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751897AbeDFLHJ (ORCPT ); Fri, 6 Apr 2018 07:07:09 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1877D1529; Fri, 6 Apr 2018 04:07:09 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8EC953F487; Fri, 6 Apr 2018 04:07:05 -0700 (PDT) Date: Fri, 6 Apr 2018 12:07:03 +0100 From: Mark Rutland To: Yury Norov Cc: "Paul E. McKenney" , Will Deacon , Chris Metcalf , Christopher Lameter , Russell King - ARM Linux , Steven Rostedt , Mathieu Desnoyers , Catalin Marinas , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Alexey Klimov , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, kvm-ppc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/5] arm64: early ISB at exit from extended quiescent state Message-ID: <20180406110702.pew7xfd3y5c72he7@lakrids.cambridge.arm.com> References: <20180405171800.5648-1-ynorov@caviumnetworks.com> <20180405171800.5648-4-ynorov@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180405171800.5648-4-ynorov@caviumnetworks.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 05, 2018 at 08:17:58PM +0300, Yury Norov wrote: > This series enables delaying of kernel memory synchronization > for CPUs running in extended quiescent state (EQS) till the exit > of that state. > > ARM64 uses IPI mechanism to notify all cores in SMP system that > kernel text is changed; and IPI handler calls isb() to synchronize. > > If we don't deliver IPI to EQS CPUs anymore, we should add ISB early > in EQS exit path. > > There are 2 such paths. One starts in do_idle() loop, and other > in el0_svc entry. For do_idle(), isb() is added in > arch_cpu_idle_exit() hook. And for SVC handler, isb is called in > el0_svc_naked. > > Suggested-by: Will Deacon > Signed-off-by: Yury Norov > --- > arch/arm64/kernel/entry.S | 16 +++++++++++++++- > arch/arm64/kernel/process.c | 7 +++++++ > 2 files changed, 22 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S > index c8d9ec363ddd..b1e1c19b4432 100644 > --- a/arch/arm64/kernel/entry.S > +++ b/arch/arm64/kernel/entry.S > @@ -48,7 +48,7 @@ > .endm > > .macro el0_svc_restore_syscall_args > -#if defined(CONFIG_CONTEXT_TRACKING) > +#if !defined(CONFIG_TINY_RCU) || defined(CONFIG_CONTEXT_TRACKING) > restore_syscall_args > #endif > .endm > @@ -483,6 +483,19 @@ __bad_stack: > ASM_BUG() > .endm > > +/* > + * If CPU is in extended quiescent state we need isb to ensure that > + * possible change of kernel text is visible by the core. > + */ > + .macro isb_if_eqs > +#ifndef CONFIG_TINY_RCU > + bl rcu_is_watching > + cbnz x0, 1f > + isb // pairs with aarch64_insn_patch_text > +1: > +#endif > + .endm > + > el0_sync_invalid: > inv_entry 0, BAD_SYNC > ENDPROC(el0_sync_invalid) > @@ -949,6 +962,7 @@ alternative_else_nop_endif > > el0_svc_naked: // compat entry point > stp x0, xscno, [sp, #S_ORIG_X0] // save the original x0 and syscall number > + isb_if_eqs As I mentioned before, this is too early. If we only kick active CPUs, then until we exit a quiescent state, we can race with concurrent modification, and cannot reliably ensure that instructions are up-to-date. Practically speaking, that means that we cannot patch any code used on the path to exit a quiescent state. Also, if this were needed in the SVC path, it would be necessary for all exceptions from EL0. Buggy userspace can always trigger a data abort, even if it doesn't intend to. > enable_daif > ct_user_exit > el0_svc_restore_syscall_args > diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c > index f08a2ed9db0d..74cad496b07b 100644 > --- a/arch/arm64/kernel/process.c > +++ b/arch/arm64/kernel/process.c > @@ -88,6 +88,13 @@ void arch_cpu_idle(void) > trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id()); > } > > +void arch_cpu_idle_exit(void) > +{ > + /* Pairs with aarch64_insn_patch_text() for EQS CPUs. */ > + if (!rcu_is_watching()) > + isb(); > +} Likewise, this is too early as we haven't left the extended quiescent state yet. Thanks, Mark.