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 1364E20371E for ; Mon, 2 Dec 2024 14:29:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733149797; cv=none; b=tQz2S8OC7UbVImq0lBaqesET2JMURe1/7BvovqOMWtck1RDZnQoUtL69bmaij7JubRd3V8EBaj5sn9+jWeXIlrt1WD8tdK3sUanl8896CqKspQ2hvmJAhe1HHqhIj+qdP1eiBia+bonxnTdm5P2r0s+z0T/pgZUHGr6nD+SxPKQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733149797; c=relaxed/simple; bh=zXR6eQrgz3AScDFaT1NWaDHwLo2yw/lqyGIISozyVrA=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=lGk1Z5MeCJtnpsfRiBdXvElLGfKWBs+BTO57GMeqLnU3XvfO/OnM1z4X0mvgoh4HdEJWDtPTFcTqh1kw7IBUE5AnVVVYyBRD/1qWRyjFiRlKOwVQA04RvHogR6/KEy6L7x6RGDSo/d/XqenmtjzSY+XjGgRK6KOcURi48zYJOf0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dI+vp98K; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dI+vp98K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82161C4CED1; Mon, 2 Dec 2024 14:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733149796; bh=zXR6eQrgz3AScDFaT1NWaDHwLo2yw/lqyGIISozyVrA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dI+vp98KwxM0HKBbgdeiQAOBMA3jilc5DZjKNGFTlUgCgz6TgI+3/CbkQFnAOaqRm JR4pi00J64NRzk8tdcHD31jQtHJLl1d/5NhUKSnCPEle0exynenfszcDutaPy4qRJB PuS4I1UOKGkEtaayRBocWFzIYIKmuwMsVhmkG2K/Pzd/uLQ1zSjnqYGBCYnnRgF+5o 1m44whoDf+wPkKPva4eU0MshyX05i5IN3osdYNT39922016uujCoeKlBoD8Py6yaDe mGVL4DfMRyFIKrZWOw9opQxM35/jKOOO9nnOADoiIx0VEHDfx31ptevvisXfAHd8BV 5heDtnsdOOqjA== 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 1tI7Qv-00HMtc-WD; Mon, 02 Dec 2024 14:29:54 +0000 Date: Mon, 02 Dec 2024 14:29:53 +0000 Message-ID: <86v7w2taxq.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, james.clark@linaro.org, will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, broonie@kernel.org, qperret@google.com, kristina.martsenko@arm.com Subject: Re: [PATCH v3 14/15] KVM: arm64: Convert the SVE guest vcpu flag to a vm flag In-Reply-To: References: <20241128123515.1709777-1-tabba@google.com> <20241128123515.1709777-15-tabba@google.com> <864j3nv9tk.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/29.4 (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, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, james.clark@linaro.org, will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, broonie@kernel.org, qperret@google.com, kristina.martsenko@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 02 Dec 2024 12:57:44 +0000, Fuad Tabba wrote: > > Hi Marc, > > On Sun, 1 Dec 2024 at 16:01, Fuad Tabba wrote: > > > > Hi Marc, > > > > > > On Sun, 1 Dec 2024 at 12:58, Marc Zyngier wrote: > > > > > > On Thu, 28 Nov 2024 12:35:14 +0000, > > > Fuad Tabba wrote: > > > > > > > > The vcpu flag GUEST_HAS_SVE is per-vcpu, but it is based on what > > > > is now a per-vm feature. Make the flag per-vm. > > > > > > > > Signed-off-by: Fuad Tabba > > > > --- > > > > arch/arm64/include/asm/kvm_emulate.h | 6 +++--- > > > > arch/arm64/include/asm/kvm_host.h | 10 ++++++---- > > > > arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- > > > > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 2 +- > > > > arch/arm64/kvm/hyp/nvhe/pkvm.c | 11 +++++++---- > > > > arch/arm64/kvm/hyp/nvhe/switch.c | 8 ++++---- > > > > arch/arm64/kvm/hyp/vhe/switch.c | 2 +- > > > > arch/arm64/kvm/reset.c | 2 +- > > > > 8 files changed, 24 insertions(+), 19 deletions(-) > > > > > > > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > > > > index 406e99a452bf..ae6d0dc0e4ff 100644 > > > > --- a/arch/arm64/include/asm/kvm_emulate.h > > > > +++ b/arch/arm64/include/asm/kvm_emulate.h > > > > @@ -620,7 +620,7 @@ static __always_inline void kvm_write_cptr_el2(u64 val) > > > > } > > > > > > > > /* Resets the value of cptr_el2 when returning to the host. */ > > > > -static __always_inline void kvm_reset_cptr_el2(struct kvm_vcpu *vcpu) > > > > +static __always_inline void kvm_reset_cptr_el2(struct kvm *kvm) > > > > > > I'd rather you avoid the resulting churn: > > > > > > static __always_inline void kvm_reset_cptr_el2(struct kvm_vcpu *vcpu) > > > { > > > struct kvm *kvm = kern_hyp_va(vcpu->kvm); > > > [...] > > > > > > which does the trick at zero cost. It is also more logical to keep the > > > vcpu as a parameter, as the per-VM-ness is only an implementation > > > detail. > > > > The reason for the churn (here and below for vcpu_has_sve()), which in > > hindsight I should have mentioned in the commit message or as a note, > > is that this code is called by the host kernel (e.g., in reset.c), and > > by the hypervisor). For nvhe, we need kern_hyp_va(), but not for the > > host. Should I gate the va conversion with is_hyp_nvhe()? > > I spoke too soon. Your suggestion results in less churn, and of > course, solves the issue I had with kern_hyp_va. > > I did have to convert kvm_reset_cptr_el2() into a macro, because it > now needs kern_hyp_va(), defined in kvm_mmu.h, which in turn includes > kvm_emulate.h. But since it's __always_inline, it shouldn't make any > difference in practice. > > If this conversion to a macro is alright by you, I'll respin this. If you can convert it to something like: static __always_inline void __kvm_reset_cptr_el2(struct kvm *kvm) { [...] } #define kvm_reset_cptr_el2(v) __kvm_reset_cptr_el2(kern_hyp_va((v)->kvm)) that'd be great, as it keeps the body of the function as C code, which helps with debugging. Thanks, M. -- Without deviation from the norm, progress is not possible.