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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77B06C43334 for ; Wed, 8 Jun 2022 06:52:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=igzjJAzXHrBQwN4Ye/n/Oyo1uYFMQlYK1lE3nam46c8=; b=vplMQtsOeQ1BM/ lZa26NdC1UjPqdgJQdtKoJ41d+0KoB4WKsAKEiXurmUJpqHh9OW7swxJHkMgExdvWgPicsuqbdQTn pmm7YF4wWiLFekFyzCBg1PvjelGoPFAsnt/1CIxx9+JwravNe1amqo6KJQXEaaROXI+bQsizsooFy +48r9P7N+wQY5N3XfYmi3eS86VHm/f7UGXt0bnbhmo2Ur9wBYJE2vQHDsMNr9Z09BA3+HScv2NKdr ANhNbFFUn3RQnkajB94BMYym9pq5oGWRpwCdwx3Fc8xcM6deIphgqgtNnAma6BXq26umZIlC4yhch 6yNulRBC7uLfLMNNfrdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nypXp-00BMB0-5R; Wed, 08 Jun 2022 06:51:57 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nypXl-00BMA5-7t for linux-arm-kernel@lists.infradead.org; Wed, 08 Jun 2022 06:51:55 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id E97DAB825C4; Wed, 8 Jun 2022 06:51:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABE58C34116; Wed, 8 Jun 2022 06:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654671108; bh=tEuXuGR91oCqrXVyUNjiWANWK4YAFe0ot1fJPPR7W9k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=AU7+WLwfAFxrM3h9jSTznpFJcvEV3Z88Yaz9eGzI5T+XIEIdNrH742JPhw0mkvUDS hyHSPaTvPywXb/f4Gu6KcaafGXf1g8YovFILgcuLYUE8pbsP3OIYEZGaLsTV0/HZ6j bkqE288qesQ4aMOss4B7BT8esKYnGB2CebCk+kow3cPmymBCH4ykyJzWqSKEzvKVdd /81qvI6FswGgMoQ5y8yLqTUPvhOYBEDH04Z80ynq6XAc8SWScGDL9PWllm/g5lWqYZ TgG6nstiYFa1Lg2RyfpDik2gKu23xTQkMtiG/AS4ZVhy+bsiT5Yv2xgNqbXvhOFtdC +uJ3ieWwgBjWQ== Received: from ip-185-104-136-29.ptr.icomera.net ([185.104.136.29] 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.94.2) (envelope-from ) id 1nypXc-00GVxt-MK; Wed, 08 Jun 2022 07:51:46 +0100 Date: Wed, 08 Jun 2022 07:51:30 +0100 Message-ID: <87mtenzlzh.wl-maz@kernel.org> From: Marc Zyngier To: Reiji Watanabe Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Linux ARM , kernel-team@android.com, Will Deacon , Mark Brown Subject: Re: [PATCH 05/18] KVM: arm64: Add helpers to manipulate vcpu flags among a set In-Reply-To: References: <20220528113829.1043361-1-maz@kernel.org> <20220528113829.1043361-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.104.136.29 X-SA-Exim-Rcpt-To: reijiw@google.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, will@kernel.org, broonie@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220607_235153_650349_A68444B7 X-CRM114-Status: GOOD ( 41.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Wed, 08 Jun 2022 06:26:44 +0100, Reiji Watanabe wrote: > > Hi Marc, > > On Sat, May 28, 2022 at 4:38 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 | 33 +++++++++++++++++++++++++++++++ > > 1 file changed, 33 insertions(+) > > > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > > index a46f952b97f6..5eb6791df608 100644 > > --- a/arch/arm64/include/asm/kvm_host.h > > +++ b/arch/arm64/include/asm/kvm_host.h > > @@ -418,6 +418,39 @@ struct kvm_vcpu_arch { > > } steal; > > }; > > > > +#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) > > I think 'v' should be enclosed in parentheses in those three macros. Fair enough. > > > > + > > +#define vcpu_get_flag(v, ...) __vcpu_get_flag(v, __VA_ARGS__) > > +#define vcpu_set_flag(v, ...) __vcpu_set_flag(v, __VA_ARGS__) > > +#define vcpu_clear_flag(v, ...) __vcpu_clear_flag(v, __VA_ARGS__) > > + > > +#define __vcpu_single_flag(_set, _f) _set, (_f), (_f) > > + > > +#define __flag_unpack(_set, _f, _m) _f > > Nit: Probably it might be worth adding a comment that explains the > above two macros ? (e.g. what is each element of the triplets ?) How about this? /* * 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_flag_unpack(...) __flag_unpack(__VA_ARGS__) > > Minor nit: KVM Functions and macros whose names begin with "vcpu_" > make me think that they are the operations for a vCPU specified in > the argument, but this macro is not (this might just my own > assumption?). So, IMHO I would prefer a name whose prefix is not > "vcpu_". Having said that, I don't have any good suggestions though... > Perhaps I might prefer "unpack_vcpu_flag" a bit instead? Sold! Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel