Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31843C433FE for ; Thu, 13 Jan 2022 11:55:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234296AbiAMLzQ (ORCPT ); Thu, 13 Jan 2022 06:55:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231260AbiAMLzP (ORCPT ); Thu, 13 Jan 2022 06:55:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51B78C06173F; Thu, 13 Jan 2022 03:55:15 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E755D6192E; Thu, 13 Jan 2022 11:55:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C913C36AE9; Thu, 13 Jan 2022 11:55:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642074914; bh=xwf4rfuOm8Hdt8fSJ7KijfPm+4qC2pRWBLFd/b9Nme0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nLzb7fwN4GlQDGkmMxnC+nh05v2BliCSnsvebAVAUSXedaF/X4rJ2Dqd+r5OnXQRf 6JQgcd3RdZv2I3TR8hK0eJ2KaQORA1c1OA+6kk1lTkxLUB+8zZ0A614j8dm6AF+aLT fDcLVRhn0aIyhLpwZGM2hI8oTd9ux9pTSFZDWhyhmnKhaLh8iJJbmyb7fEPSyxejgD Z2XZP7XzwEhvC07oXyawKEiVXuNuTh9qITNZEJIH7N/tE9mWHahRctAT6qRor40dAT bXPRM0EtKLfhmgWdCmQmOVTHIZeycdLKJ1YrQidwwJ8K1055B+SXbYdLD27oJIpIBb RWZrUjImiHFeg== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n7yhE-000Gjp-AC; Thu, 13 Jan 2022 11:55:12 +0000 Date: Thu, 13 Jan 2022 11:55:11 +0000 Message-ID: <87pmov97fk.wl-maz@kernel.org> From: Marc Zyngier To: Mark Rutland Cc: linux-kernel@vger.kernel.org, aleksandar.qemu.devel@gmail.com, alexandru.elisei@arm.com, anup.patel@wdc.com, aou@eecs.berkeley.edu, atish.patra@wdc.com, benh@kernel.crashing.org, borntraeger@linux.ibm.com, bp@alien8.de, catalin.marinas@arm.com, chenhuacai@kernel.org, dave.hansen@linux.intel.com, david@redhat.com, frankja@linux.ibm.com, frederic@kernel.org, gor@linux.ibm.com, hca@linux.ibm.com, imbrenda@linux.ibm.com, james.morse@arm.com, jmattson@google.com, joro@8bytes.org, kvm@vger.kernel.org, mingo@redhat.com, mpe@ellerman.id.au, nsaenzju@redhat.com, palmer@dabbelt.com, paulmck@kernel.org, paulus@samba.org, paul.walmsley@sifive.com, pbonzini@redhat.com, seanjc@google.com, suzuki.poulose@arm.com, tglx@linutronix.de, tsbogend@alpha.franken.de, vkuznets@redhat.com, wanpengli@tencent.com, will@kernel.org Subject: Re: [PATCH 1/5] kvm: add exit_to_guest_mode() and enter_from_guest_mode() In-Reply-To: References: <20220111153539.2532246-1-mark.rutland@arm.com> <20220111153539.2532246-2-mark.rutland@arm.com> <87v8yqrwcs.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: mark.rutland@arm.com, linux-kernel@vger.kernel.org, aleksandar.qemu.devel@gmail.com, alexandru.elisei@arm.com, anup.patel@wdc.com, aou@eecs.berkeley.edu, atish.patra@wdc.com, benh@kernel.crashing.org, borntraeger@linux.ibm.com, bp@alien8.de, catalin.marinas@arm.com, chenhuacai@kernel.org, dave.hansen@linux.intel.com, david@redhat.com, frankja@linux.ibm.com, frederic@kernel.org, gor@linux.ibm.com, hca@linux.ibm.com, imbrenda@linux.ibm.com, james.morse@arm.com, jmattson@google.com, joro@8bytes.org, kvm@vger.kernel.org, mingo@redhat.com, mpe@ellerman.id.au, nsaenzju@redhat.com, palmer@dabbelt.com, paulmck@kernel.org, paulus@samba.org, paul.walmsley@sifive.com, pbonzini@redhat.com, seanjc@google.com, suzuki.poulose@arm.com, tglx@linutronix.de, tsbogend@alpha.franken.de, vkuznets@redhat.com, wanpengli@tencent.com, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Jan 2022 11:01:30 +0000, Mark Rutland wrote: > > On Tue, Jan 11, 2022 at 05:54:59PM +0000, Marc Zyngier wrote: > > Hi Mark, > > > > On Tue, 11 Jan 2022 15:35:35 +0000, > > Mark Rutland wrote: [...] > > > +/* > > > + * Enter guest context and enter an RCU extended quiescent state. > > > + * > > > + * This should be the last thing called before entering the guest, and must be > > > + * called after any potential use of RCU (including any potentially > > > + * instrumented code). > > > > nit: "the last thing called" is terribly ambiguous. Any architecture > > obviously calls a ****load of stuff after this point. Should this be > > 'the last thing involving RCU' instead? > > I agree this is unclear and I struggled to fing good wording for this. Is the > following any better? > > /* > * Enter guest context and enter an RCU extended quiescent state. > * > * Between guest_context_enter_irqoff() and guest_context_exit_irqoff() it is > * unsafe to use any code which may directly or indirectly use RCU, tracing > * (including IRQ flag tracing), or lockdep. All code in this period must be > * non-instrumentable. > */ > > If that's good I can add similar to guest_context_exit_irqoff(). Yes, that's much clearer, thanks. > > [...] > > > > +/** > > > + * exit_to_guest_mode - Fixup state when exiting to guest mode > > > + * > > > + * This is analagous to exit_to_user_mode(), and ensures we perform the > > > + * following in order: > > > + * > > > + * 1) Trace interrupts on state > > > + * 2) Invoke context tracking if enabled to adjust RCU state > > > + * 3) Tell lockdep that interrupts are enabled > > > > nit: or rather, are about to be enabled? Certainly on arm64, the > > enable happens much later, right at the point where we enter the guest > > for real. > > True; I'd cribbed the wording from the comment block above exit_to_user_mode(), > but I stripped the context that made that clear. I'll make that: > > /** > * exit_to_guest_mode - Fixup state when exiting to guest mode > * > * Entry to a guest will enable interrupts, but the kernel state is > * interrupts disabled when this is invoked. Also tell RCU about it. > * > * 1) Trace interrupts on state > * 2) Invoke context tracking if enabled to adjust RCU state > * 3) Tell lockdep that interrupts are enabled > * > * Invoked from architecture specific code before entering a guest. > * Must be called with interrupts disabled and the caller must be > * non-instrumentable. > * The caller has to invoke guest_timing_enter_irqoff() before this. > * > * Note: this is analagous to exit_to_user_mode(). nit: analogous > */ > > ... with likewise for enter_from_guest_mode(), if that's clear enough? Yes, that's great. Thanks again, M. -- Without deviation from the norm, progress is not possible.