From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E7C5125A5 for ; Mon, 18 Dec 2023 09:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d1cgMwPE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EA4EC433C8; Mon, 18 Dec 2023 09:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702892422; bh=Mrq3Rom+ycuK3rYqygSdQOf1nhuvr7TGGuRUQdwXW4o=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=d1cgMwPE+mHEO6XaIWyYpfOXwShiBd1ZtX1G7yndxxkCSU7hY2TWxTtmJnMOU5sm1 DE8xX6zfVEsou1strAaEpgl6NmIp+N2GS6bjCI2jseZauyBvPxdzemgVbNCZ9+FXFq dzJ069KSL/DbmNQeuyuGm4eZenQJOU2u8MESgBLJO0UMfvSFpr6ip420efOv43LmT8 YZg63FE2hMYrAbEE2ye8vw+JpJSxq8XBXK7gNKlBnWg3S9EQV+G82Y0b1kePqMD6cE 47um83ilnA1rFbwQGBQNFtgiH5Vg/UXSuv6v+OFZHuwluJOlbFs9uiPyRCyN81haFw yyQ5sVoW/LASw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.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 1rFA6l-004z1D-Mr; Mon, 18 Dec 2023 09:40:19 +0000 Date: Mon, 18 Dec 2023 09:40:18 +0000 Message-ID: <86wmtbalx9.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvmarm@lists.linux.dev, oliver.upton@linux.dev, broonie@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, eric.auger@redhat.com, jingzhangos@google.com, joey.gouly@arm.com, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v3 14/17] KVM: arm64: Macros for setting/clearing FGT bits In-Reply-To: <20231214100158.2305400-15-tabba@google.com> References: <20231214100158.2305400-1-tabba@google.com> <20231214100158.2305400-15-tabba@google.com> 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/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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: tabba@google.com, kvmarm@lists.linux.dev, oliver.upton@linux.dev, broonie@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, eric.auger@redhat.com, jingzhangos@google.com, joey.gouly@arm.com, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Thu, 14 Dec 2023 10:01:54 +0000, Fuad Tabba wrote: > > There's a lot of boilerplate code for setting and clearing FGT > bits when activating guest traps. Refactor it into macros. These > macros will also be used in future patch series. > > No functional change intended. > > Signed-off-by: Fuad Tabba > --- > arch/arm64/kvm/hyp/include/hyp/switch.h | 60 +++++++++---------------- > 1 file changed, 21 insertions(+), 39 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index 17ce40f5b006..e223fc0d5193 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -79,6 +79,23 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu) > clr |= ~hfg & __ ## reg ## _nMASK; \ > } while(0) > > +#define update_fgt_traps_cs(reg, clr, set) \ > + do { \ > + struct kvm_cpu_context *hctxt = \ > + &this_cpu_ptr(&kvm_host_data)->host_ctxt; \ > + u64 val, c = 0, s = 0; \ > + \ > + ctxt_sys_reg(hctxt, reg) = read_sysreg_s(SYS_ ## reg); \ > + compute_clr_set(vcpu, reg, c, s); \ You are referring to a variable name that is in the scope of the macro user, and not the macro itself. It is so fragile it isn't funny. Why don't you simply pass the vcpu as a parameter to the function? Another thing is that this read/write can be expensive. How about not doing anything when there is no change to the value of the sysreg? I'll see if I can come up with something. M. -- Without deviation from the norm, progress is not possible.