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 Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FC12CCA473 for ; Sun, 12 Jun 2022 08:59:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 4D13F4B4A5; Sun, 12 Jun 2022 04:59:37 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@kernel.org Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Qs2PgP0SIvaD; Sun, 12 Jun 2022 04:59:36 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 089304B422; Sun, 12 Jun 2022 04:59:36 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 22BDD4B422 for ; Sun, 12 Jun 2022 04:59:34 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kdR3JT9fzUsQ for ; Sun, 12 Jun 2022 04:59:32 -0400 (EDT) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id C9C714B411 for ; Sun, 12 Jun 2022 04:59:32 -0400 (EDT) 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 DE5EF60C07; Sun, 12 Jun 2022 08:59:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40D6CC34115; Sun, 12 Jun 2022 08:59:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655024371; bh=lAZd4om3O/HhLmnjR6wY2GSgGFgCHW1e+OFvSSyBIds=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tBA2DhCeU+J+TQVwkHA+0m0syzbtrutzouveFNnovfkfbe0tG/RExhAV406Y2kiw0 1GtK06OLvCwuNweJo2nu3xZf7rAT0PgP7KWuIAEt2AZNbQZKJaiUrQ6IbcWwPql/VR C5BcXeACz3JXJwg9ujtbrl4FKnqRoF0CEWXydbtWRiovHIHNqqYQXwnd6yMC9nnl9w O4npE1M3QOAr1s09VQyFzx+OrtcZeSEawgDxlV/72FkmhLryGee1R37WtvoOhw9z6v inxqYzTUdYWnhDUMuxNxfBwJeEeyY1yxP1xPiVSgSINnJz87s7Jz9jKRJF8nvWDqZW rlapsgc4Mg+JA== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1o0JRQ-00HVLI-W9; Sun, 12 Jun 2022 09:59:29 +0100 Date: Sun, 12 Jun 2022 09:59:03 +0100 Message-ID: <87zgiip8a0.wl-maz@kernel.org> From: Marc Zyngier To: Reiji Watanabe Subject: Re: [PATCH v2 05/19] KVM: arm64: Add helpers to manipulate vcpu flags among a set In-Reply-To: References: <20220610092838.1205755-1-maz@kernel.org> <20220610092838.1205755-6-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") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: reijiw@google.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, oupton@google.com, will@kernel.org, tabba@google.com, qperret@google.com, broonie@kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: kernel-team@android.com, kvm@vger.kernel.org, Will Deacon , Mark Brown , kvmarm@lists.cs.columbia.edu, Linux ARM X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Sat, 11 Jun 2022 19:37:50 +0100, Reiji Watanabe wrote: > > On Fri, Jun 10, 2022 at 2:28 AM Marc Zyngier wrote: > > > > Careful analysis of the vcpu flags show that this is a mix of > > configuration, communication between the host and the hypervisor, > > as well as anciliary state that has no consistency. It'd be a lot > > better if we could split these flags into consistent categories. > > > > However, even if we split these flags apart, we want to make sure > > that each flag can only be applied to its own set, and not across > > sets. > > > > To achieve this, use a preprocessor hack so that each flag is always > > associated with: > > > > - the set that contains it, > > > > - a mask that describe all the bits that contain it (for a simple > > flag, this is the same thing as the flag itself, but we will > > eventually have values that cover multiple bits at once). > > > > Each flag is thus a triplet that is not directly usable as a value, > > but used by three helpers that allow the flag to be set, cleared, > > and fetched. By mandating the use of such helper, we can easily > > enforce that a flag can only be used with the set it belongs to. > > > > Finally, one last helper "unpacks" the raw value from the triplet > > that represents a flag, which is useful for multi-bit values that > > need to be enumerated (in a switch statement, for example). > > > > Further patches will start making use of this infrastructure. > > > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/include/asm/kvm_host.h | 44 +++++++++++++++++++++++++++++++ > > 1 file changed, 44 insertions(+) > > > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > > index 372c5642cfab..6d30ac7e3164 100644 > > --- a/arch/arm64/include/asm/kvm_host.h > > +++ b/arch/arm64/include/asm/kvm_host.h > > @@ -415,6 +415,50 @@ struct kvm_vcpu_arch { > > } steal; > > }; > > > > +/* > > + * Each 'flag' is composed of a comma-separated triplet: > > + * > > + * - the flag-set it belongs to in the vcpu->arch structure > > + * - the value for that flag > > + * - the mask for that flag > > + * > > + * __vcpu_single_flag() builds such a triplet for a single-bit flag. > > + * unpack_vcpu_flag() extract the flag value from the triplet for > > + * direct use outside of the flag accessors. > > + */ > > +#define __vcpu_single_flag(_set, _f) _set, (_f), (_f) > > + > > +#define __unpack_flag(_set, _f, _m) _f > > +#define unpack_vcpu_flag(...) __unpack_flag(__VA_ARGS__) > > + > > +#define __vcpu_get_flag(v, flagset, f, m) \ > > + ({ \ > > + v->arch.flagset & (m); \ > > + }) > > + > > +#define __vcpu_set_flag(v, flagset, f, m) \ > > + do { \ > > + typeof(v->arch.flagset) *fset; \ > > + \ > > + fset = &v->arch.flagset; \ > > + if (HWEIGHT(m) > 1) \ > > + *fset &= ~(m); \ > > + *fset |= (f); \ > > + } while (0) > > + > > +#define __vcpu_clear_flag(v, flagset, f, m) \ > > + do { \ > > + typeof(v->arch.flagset) *fset; \ > > + \ > > + fset = &v->arch.flagset; \ > > + *fset &= ~(m); \ > > + } while (0) > > Reviewed-by: Reiji Watanabe > > IMHO I would prefer to have 'v' enclosed in parentheses in the > implementation of __vcpu_{get,set,clear}_flag rather than in > the implementation of vcpu_{get,set,clear}_flag though. > (That was what I meant in my comment for v1) I understood what you were asking the first place, but I don't think this has any advantage over what is above. __vcpu_{get,set,clear}_flag are not meant to be used directly, and adding extra bracketing to these only makes them more painful to read. If you can show a case where it breaks, I'll be happy to revisit this. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm