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 1C406C43334 for ; Sun, 12 Jun 2022 09:00:49 +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=PUrGqRwEEPpER4JhqeicUwYLxiWeGaFNB0mPIBOwmGs=; b=xySMiMlbkiTZts 879lUSQ0VEMKc0iWJLw0vhW0EAVjafL40nRwecuY/nOYnmYkysT0iD4o5q20ANN/zZfXMNfpFrWUQ znEDwUrhKu7I3RANjQRCYjWS5HJWGur23KfPizkwq8EuenFehSN0WTlxoa+DTD3+Hf5CsMPMJN9n1 nQU2RoiDA6xtbqQW8RB1Vj41IY3NRAgm0tPRH/Br3EZPqIJlq+tOt63spYrKUUofO+nZb1MYQpaed cRUTwYf31TEQlvGu4p5c9G2fm+AaD+2DBSTZ2oPjPbXzaHnBazSh32cZAeNh4idtu8CtE06j23RC0 qTPFVho9JnZVfCMgr07A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0JRa-00G36r-PV; Sun, 12 Jun 2022 08:59:38 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0JRV-00G35c-9i for linux-arm-kernel@lists.infradead.org; Sun, 12 Jun 2022 08:59:37 +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 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 Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Linux ARM , James Morse , Suzuki K Poulose , Alexandru Elisei , Oliver Upton , Will Deacon , Fuad Tabba , Quentin Perret , Mark Brown , kernel-team@android.com 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220612_015936_023245_5B1B6304 X-CRM114-Status: GOOD ( 42.62 ) 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 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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel