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 E67686F079 for ; Tue, 28 May 2024 08:16:27 +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=1716884188; cv=none; b=ceYguki5B4t66cKQK6+oaOy/GpkAG29nUoMeEar3y9/sGuL4w8DarZIcGrtmm1cspl9LMkHDGmpYIaz8oFEn8cipxyQFm/DSN7o2m42WOAkI5oaV/fwJNDozAuB14YBcvbZAmnkM36syfSDrJ4QK/z0H1QvlJBtPFW3cG+w8XAA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716884188; c=relaxed/simple; bh=c/aCl4A92v+AL/YnLF2mG4LjuecMfHezvyygU6RSG+M=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=Ix5m/OmMBl9iADbbgTpDVD065RgE4FjS7q1PuDOQUhLJIaulp88Vbp5Vv2eUkrMEITwETu8Iwn90qnc6Sbfnm2Bguq5myou7Ig8ix0R4f60YJWmNupLZ4B55+yVYN7bLnvhvebJtgrvGamxdc2mXkQ9Xv734KIXlInkNTyZxCYQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mu2W787A; 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="mu2W787A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61186C3277B; Tue, 28 May 2024 08:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716884187; bh=c/aCl4A92v+AL/YnLF2mG4LjuecMfHezvyygU6RSG+M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=mu2W787AnI97s0IWOJG4L98V8EMW83U3cOTnVFPXCGszju1OaxR06l48FGPDqzrS+ AGMeAcA4NL8DdvunZOc++mvAuO7k+If4g5VreeYU2ApJFt1PEpy6aoeHNzrHXOeip0 qF2Zvo7yLGZpmZUOZbA9bbZmyjGyyfxOflvbByg6yn1zb5GefJ9axoqx+TMEiZVpAt TyPkwYKf0QSlKs2md8dzMW7JqTXlnD8TF2EpBhfJrjs6ZLbujl0ITlI9E7o5+HaQix r2ZKj+TABkymT82n8N6IGf6XrT8ohHfuxxxneGUp6T6hGDjVqnRsGEHq3yyGRZKgqr 0mxVVp6xEjS+Q== 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 1sBs0P-00GDqf-9u; Tue, 28 May 2024 09:16:25 +0100 Date: Tue, 28 May 2024 09:16:24 +0100 Message-ID: <86h6eimjvr.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, will@kernel.org, qperret@google.com, seanjc@google.com, alexandru.elisei@arm.com, catalin.marinas@arm.com, philmd@linaro.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, mark.rutland@arm.com, broonie@kernel.org, joey.gouly@arm.com, rananta@google.com, yuzenghui@huawei.com Subject: Re: [PATCH v2 5/7] KVM: arm64: Allocate memory at hyp for host sve state in pKVM In-Reply-To: References: <20240521163720.3812851-1-tabba@google.com> <20240521163720.3812851-6-tabba@google.com> <86plten8kr.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.2 (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=UTF-8 Content-Transfer-Encoding: quoted-printable 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, will@kernel.org, qperret@google.com, seanjc@google.com, alexandru.elisei@arm.com, catalin.marinas@arm.com, philmd@linaro.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, mark.rutland@arm.com, broonie@kernel.org, joey.gouly@arm.com, rananta@google.com, yuzenghui@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Wed, 22 May 2024 15:37:53 +0100, Fuad Tabba wrote: >=20 > Hi Marc, >=20 > On Tue, May 21, 2024 at 10:44=E2=80=AFPM Marc Zyngier wr= ote: > > > > On Tue, 21 May 2024 17:37:18 +0100, > > Fuad Tabba wrote: > > > > > > Protected mode needs to maintain (save/restore) the host's sve > > > state, rather than relying on the host kernel to do that. This is > > > to avoid leaking information to the host about guests and the > > > type of operations they are performing. > > > > > > As a first step towards that, allocate memory at hyp, per cpu, to > > > hold the host sve data. The following patch will use this memory > > > to save/restore the host state. > > > > What I read in the code contradicts this statement. The memory is > > definitely allocated on the *host*. >=20 > You're right. I should say memory mapped at hyp. >=20 > > > > > > Signed-off-by: Fuad Tabba > > > --- > > > Note that the last patch in this series will consolidate the > > > setup of the host's fpsimd and sve states, which currently take > > > place in two different locations. Moreover, that last patch will > > > also place the host fpsimd and sve_state pointers in a union. > > > --- > > > arch/arm64/include/asm/kvm_host.h | 2 + > > > arch/arm64/include/asm/kvm_pkvm.h | 9 ++++ > > > arch/arm64/include/uapi/asm/ptrace.h | 14 ++++++ > > > arch/arm64/kvm/arm.c | 68 ++++++++++++++++++++++++++= ++ > > > arch/arm64/kvm/hyp/nvhe/setup.c | 24 ++++++++++ > > > 5 files changed, 117 insertions(+) > > > > > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/a= sm/kvm_host.h > > > index 0a5fceb20f3a..7b3745ef1d73 100644 > > > --- a/arch/arm64/include/asm/kvm_host.h > > > +++ b/arch/arm64/include/asm/kvm_host.h > > > @@ -535,7 +535,9 @@ struct kvm_cpu_context { > > > */ > > > struct kvm_host_data { > > > struct kvm_cpu_context host_ctxt; > > > + > > > struct user_fpsimd_state *fpsimd_state; /* hyp VA */ > > > + struct user_sve_state *sve_state; /* hyp VA */ > > > > > > /* Ownership of the FP regs */ > > > enum { > > > diff --git a/arch/arm64/include/asm/kvm_pkvm.h b/arch/arm64/include/a= sm/kvm_pkvm.h > > > index ad9cfb5c1ff4..b9d12e123efb 100644 > > > --- a/arch/arm64/include/asm/kvm_pkvm.h > > > +++ b/arch/arm64/include/asm/kvm_pkvm.h > > > @@ -128,4 +128,13 @@ static inline unsigned long hyp_ffa_proxy_pages(= void) > > > return (2 * KVM_FFA_MBOX_NR_PAGES) + DIV_ROUND_UP(desc_max, PAG= E_SIZE); > > > } > > > > > > +static inline size_t pkvm_host_sve_state_size(void) > > > +{ > > > + if (!system_supports_sve()) > > > + return 0; > > > + > > > + return size_add(sizeof(struct user_sve_state), > > > + SVE_SIG_REGS_SIZE(sve_vq_from_vl(kvm_host_sve_m= ax_vl))); > > > +} > > > + > > > #endif /* __ARM64_KVM_PKVM_H__ */ > > > diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/includ= e/uapi/asm/ptrace.h > > > index 7fa2f7036aa7..77aabf964071 100644 > > > --- a/arch/arm64/include/uapi/asm/ptrace.h > > > +++ b/arch/arm64/include/uapi/asm/ptrace.h > > > @@ -120,6 +120,20 @@ struct user_sve_header { > > > __u16 __reserved; > > > }; > > > > > > +struct user_sve_state { > > > + __u64 zcr_el1; > > > + > > > + /* > > > + * Ordering is important since __sve_save_state/__sve_restore_s= tate > > > + * relies on it. > > > + */ > > > + __u32 fpsr; > > > + __u32 fpcr; > > > + > > > + /* Must be SVE_VQ_BYTES (128 bit) aligned. */ > > > + __u8 sve_regs[]; > > > +}; > > > + > > > > Huh, why is this in uapi? Why should userspace even care about this at > > all? From what I can tell, this is purely internal to the kernel, and > > in any case, KVM isn't tied to that format if it doesn't dump stuff in > > the userspace thread context. Given the number of bugs this format has > > generated, I really wouldn't mind moving away from it. >=20 > I put it here since the sve_header is here, as well as other similar stru= ctures. >=20 > Should I move it to asm/kvm_pkvm.h? kvm_host.h or kvm_types.h seem like the best option (replacing the "user" prefix with something else), as this is directly consumed by kvm_host.h. Thanks, M. --=20 Without deviation from the norm, progress is not possible.