From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23DDCC64E7B for ; Mon, 30 Nov 2020 11:23:37 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8FD0F207BC for ; Mon, 30 Nov 2020 11:23:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Iy9d/cEI"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="NnBtszzb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FD0F207BC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JcqgiqHdTbMUgWS6wTVc7RX4y1DG04fKwrmVujt0Wf8=; b=Iy9d/cEIoqljcbYfnDPcdcvNS ZdNmPdvVIrc4WiQ7L+VsQwSrbYkGZpfMLiLc0atTLB/WsnlPl0v+3YvZik3m1lCE5jQOE7bpsPJzA SP87IYObu9rCQg9bY56kwWPW81W9eENV5Q9ztQlRdIWs40E07ZUzeedF7JbwNQDxsIXv0aYqDjLkx 75UNrsIOc6zT755bbpcINCW2yZbo76jHmQedw9bSFEvOwLwMHC2o0dVrnH8DjqPDJSoOyF1QlfGPx QZu9LG5MEKj/xLGZSMFeYfhqlhg6ndBrqGl+Adalq79shRtuwK2z8iHxp2jKg31WuZBOKcxl6Ih3I IofbluaeA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjhG7-00033d-PH; Mon, 30 Nov 2020 11:22:19 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjhG4-00032a-6d for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2020 11:22:17 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 60F0C206C0; Mon, 30 Nov 2020 11:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606735335; bh=0uu0chsQSXBhrb30xYzrrqVlrr+E1QPeV3nOx0j5X60=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NnBtszzbYa16y0OkOlpcebO/Ym0oPHbaKVR/pFh7tNmV1yfKWzQxQz2X2oWiED1cc F6AalEi+XtXWddnYhWeWi8pQLiR1LAfiDkqJqZR3FzODs0dcMfMhHdUaXZg+3rq2+j 8jYiD/h+OoaW3MRPK4rL2WXMoP/ijSshOgOGxE6k= Date: Mon, 30 Nov 2020 11:22:09 +0000 From: Will Deacon To: Mark Rutland Subject: Re: [PATCH 09/11] arm64: entry: fix non-NMI kernel<->kernel transitions Message-ID: <20201130112209.GD24098@willie-the-truck> References: <20201126123602.23454-1-mark.rutland@arm.com> <20201126123602.23454-10-mark.rutland@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201126123602.23454-10-mark.rutland@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_062216_487768_3822C610 X-CRM114-Status: GOOD ( 28.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elver@google.com, paulmck@kernel.org, peterz@infradead.org, catalin.marinas@arm.com, james.morse@arm.com, linux-arm-kernel@lists.infradead.org, dvyukov@google.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Nov 26, 2020 at 12:36:00PM +0000, Mark Rutland wrote: > There are periods in kernel mode when RCU is not watching and/or the > scheduler tick is disabled, but we can still take exceptions such as > interrupts. The arm64 exception handlers do not account for this, and > it's possible that RCU is not watching while an exception handler runs. > > The x86/generic entry code handles this by ensuring that all (non-NMI) > kernel exception handlers call irqentry_enter() and irqentry_exit(), > which handle RCU, lockdep, and IRQ flag tracing. We can't yet move to > the generic entry code, and already hadnle the user<->kernel transitions > elsewhere, so we add new kernel<->kernel transition helpers alog the > lines of the generic entry code. > > Since we now track interrupts becoming masked when an exception is > taken, local_daif_inherit() is modified to track interrupts becoming > re-enabled when the original context is inherited. To balance the > entry/exit paths, each handler masks all DAIF exceptions before > exit_to_kernel_mode(). > > Signed-off-by: Mark Rutland > Cc: Catalin Marinas > Cc: James Morse > Cc: Will Deacon > --- > arch/arm64/include/asm/daifflags.h | 3 ++ > arch/arm64/kernel/entry-common.c | 59 ++++++++++++++++++++++++++++++++++++-- > 2 files changed, 59 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h > index ec213b4a1650..1c26d7baa67f 100644 > --- a/arch/arm64/include/asm/daifflags.h > +++ b/arch/arm64/include/asm/daifflags.h > @@ -128,6 +128,9 @@ static inline void local_daif_inherit(struct pt_regs *regs) > { > unsigned long flags = regs->pstate & DAIF_MASK; > > + if (interrupts_enabled(regs)) > + trace_hardirqs_on(); > + > /* > * We can't use local_daif_restore(regs->pstate) here as > * system_has_prio_mask_debugging() won't restore the I bit if it can > diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c > index 49d1c1dd9baf..526e98cec86e 100644 > --- a/arch/arm64/kernel/entry-common.c > +++ b/arch/arm64/kernel/entry-common.c > @@ -17,12 +17,50 @@ > #include > #include > > +static void noinstr enter_from_kernel_mode(struct pt_regs *regs) > +{ > + regs->exit_rcu = false; > + > + if (!IS_ENABLED(CONFIG_TINY_RCU) && is_idle_task(current)) { > + lockdep_hardirqs_off(CALLER_ADDR0); > + rcu_irq_enter(); > + trace_hardirqs_off_finish(); > + > + regs->exit_rcu = true; > + return; > + } > + > + lockdep_hardirqs_off(CALLER_ADDR0); > + rcu_irq_enter_check_tick(); > + trace_hardirqs_off_finish(); > +} > + > +static void noinstr exit_to_kernel_mode(struct pt_regs *regs) > +{ > + lockdep_assert_irqs_disabled(); > + > + if (interrupts_enabled(regs)) { > + if (regs->exit_rcu) { > + trace_hardirqs_on_prepare(); > + lockdep_hardirqs_on_prepare(CALLER_ADDR0); > + rcu_irq_exit(); > + lockdep_hardirqs_on(CALLER_ADDR0); > + return; > + } > + > + trace_hardirqs_on(); > + } else { > + if (regs->exit_rcu) > + rcu_irq_exit(); > + } > +} Hmm. I'd prefer to rework this to avoid the nested early return: e.g: // exit_to_kernel_mode() if (!interrupts_enabled(regs)) { if (regs->exit_rcu) rcu_irq_exit() } else if (regs->exit_rcu) { trace_hardirqs_on_prepare(); ... } else { trace_hardirqs_on(); } but I see you're following the pattern in kernel/entry/common.c, which makes sense given that the long-term goal should be to move over to that. In which case, can you add a comment somewhere that this is deliberately structured to map to the common code? Cheers, Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel