From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FB7337CD5A for ; Mon, 15 Jun 2026 13:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781529092; cv=none; b=Sz51Sq5quDnPhR7M1/NcDg71cQ6RYtHr/EixMw+EDiH0+pUZGH94hQVCQPvw9bAvW0CF0qKVdkWNDrqo0gyRjjQiy4vqF4AZ9Gt4o3O1qoqIhy4oIL/lfRlVsWTMoaxiAuJ/zgmXGySoVmJE1ECbcd4AnHupZ96qJCWZJrgB1QM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781529092; c=relaxed/simple; bh=cI6CZJti5/aPMIs+HJPMCqFkUJo9NlZ3x9Oc3FXQpMM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UlT8uAR/DpE8mF5KIPvS9SVVbvkq059uAJ5Is3rwvE98dnUFyjA0LOQzASS677MnK5xkeosH7zyH+bE4Soo8z1d56dPXAeI+iCmW4/HRNB6u2qqsqYmszkmoU2vwNZubBfda1+9iKdO77/y6YfwB9BWgPlbzSxEvqltfR4w7SiI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=T1jp77HB; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="T1jp77HB" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-490cf322ed0so22861965e9.1 for ; Mon, 15 Jun 2026 06:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781529090; x=1782133890; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OUgsqjBTFZvdCdtQA3mADF26jeRTv++PPR68ymFBShw=; b=T1jp77HBDbEZeIAMpwPpKr1i/sPDwa12wa73jkl2s0wuI0lo8Por3a88LQ44gZBstt SEgeX8DcUIU9crEU2K5O2oBnruUJ5BkzAP20PwZJwXt/4JyEMsOv2YZhAVx/CUCprAbD Ugh9Klg1qKZ8t7aywwGeS0m2IUpyFX1+/kH6j5EGDx9Ji0s9Elvf6cBCR18JLTcs+gkS XI0Z02t4Q1geS2+Hpla6SA00exCq8NP2UOR23TsnwjPBf6PbqcSa+/XHwSAjelQisqOt XTNu7CHBDAb28Nv5i9gmlMDqZI+OETaYLVX9Sn1XHU+lZt+PZDznKPdCG5b9W4yvaQog VF6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781529090; x=1782133890; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OUgsqjBTFZvdCdtQA3mADF26jeRTv++PPR68ymFBShw=; b=SxlhYRecQBXeBD2DYzjuvqz5W6j07750xUYouquU5MVHkoYIpNGVsdGeUqWtQuhQ3D dw56MI4uZYXVPvc0CjTMxL2e2KQhheyLhRvQ/3xIABHL6kDWPcfBpe0mF/CPNwYp3kjJ NSyWRHQKFehWFBczRZt3RGFgYym8NtrO13qGOQ8BqoUFU4We7LGWOnr3zXS56T7nTyDY 97Hlf8DLmJW1I9lh63RvXyKs6J+Yrd2NTnnVfiGY1hSyQp3qbaGSNOKUVV5AcyeIyzw6 OBdwSoRWhrUgl4R1p+wEg5DCOiuRrTO1joL+uCQim6JJ/imvBGRgCRU8epIWuqDUaYyX zIvg== X-Forwarded-Encrypted: i=1; AFNElJ9p+JnYn/rFTa++NZMrfg+pU+6RGWfTP6YKJo4VT4fkBc1zxlN3vDqJCStoNdSSECd8lRYcDLFrWEa49Nk=@vger.kernel.org X-Gm-Message-State: AOJu0YzSUWnuHSQrkV/2mnZjD0FdnSBG4hVacSP+IZFUCzzetDqpQc07 GRKx3gknmRbkvOtkpBYfPVdxZVR9lwpWdcLpWC8oVpluL1VJBvsfiS4o/0XEEZMsyg== X-Gm-Gg: Acq92OEqiVZAV1SgL6e+tBYaNmyfs/4G8xC0QrFpmp4k4A1lbzkPOvE8QgTXZBQF0tE /U+xda1FhUfsldlQcFEjGiUt7ATKuw86PadBrCjYD2B6HO14XpxwTL/chuQBgCtnMkQDrc0sE3Q Cqs1PvtGEiX9P8j3BQNyr3bjo87HmZcAd3ud978kb4+vaNucZ7WiYicvBt3m00WyDgHqkDp1jAt 5cjHpzzovfhVuiV0bvB0Ftq9N9eudC2ayXOHlA/v87rYE4CrE0Y6R97/tVqSnISQgQRhcfnA+Ut 2Cg0TrP2v4xfwajmERWNg2UwW5NP9GRv/p4Xv7TqqW7i5JSX6SxVoICY5VnMQX9thio80GZUX3/ Us9GxeYkFiVTor2itR0c9XuO8sHjDwGia9cpjnC+U0yP1/GkZRZIGYqgonxogkO1V7Zf2sq7IwM svOu1s1pxSIbc+VpSCRQFkjxXl1Q41GHw397cVyBDIDVGb2EVrhz/q0f/xlev7QqAxwKA= X-Received: by 2002:a05:600c:628f:b0:492:1e36:85dc with SMTP id 5b1f17b1804b1-4922017b005mr126783175e9.36.1781529088951; Mon, 15 Jun 2026 06:11:28 -0700 (PDT) Received: from google.com (135.91.155.104.bc.googleusercontent.com. [104.155.91.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490ea95b274sm341373985e9.1.2026.06.15.06.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 06:11:28 -0700 (PDT) Date: Mon, 15 Jun 2026 14:11:24 +0100 From: Vincent Donnefort To: tabba@google.com Cc: Marc Zyngier , Oliver Upton , Will Deacon , Catalin Marinas , Quentin Perret , Sebastian Ene , Per Larsen , Suzuki K Poulose , Zenghui Yu , Joey Gouly , Steffen Eiden , Mark Rutland , Jonathan Cameron , Hyunwoo Kim , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 05/11] KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code Message-ID: References: <20260612065925.755562-1-tabba@google.com> <20260612065925.755562-6-tabba@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260612065925.755562-6-tabba@google.com> On Fri, Jun 12, 2026 at 07:59:19AM +0100, tabba@google.com wrote: > The vcpu_{read,write}_sys_reg() accessors are host-only, so helpers > built on them such as kvm_vcpu_set_be()/kvm_vcpu_is_be() cannot be > shared with hyp code. Add _vcpu_read_sys_reg()/_vcpu_write_sys_reg() > inlines in kvm_emulate.h that dispatch on is_nvhe_hyp_code() to the > host- or hyp-side accessor. A follow-up series uses this to share that > emulation code at EL2. > > No functional change intended. > > Signed-off-by: Fuad Tabba > --- > arch/arm64/include/asm/kvm_emulate.h | 22 +++++++++++++++++++--- > 1 file changed, 19 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index 5bf3d7e1d92c..aed9fc0b717b 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -506,6 +506,22 @@ static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu) > return __vcpu_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK; > } > > +static inline u64 _vcpu_read_sys_reg(struct kvm_vcpu *vcpu, enum vcpu_sysreg reg) I am not sure a single underscore is widely used in the kernel. Why not move __vcpu_read_sys_reg() and __vcpu_write_sys_reg() from exception.c to kvm_emulate.h? especially this already checks has_vhe(). > +{ > + if (!is_nvhe_hyp_code()) > + return vcpu_read_sys_reg(vcpu, reg); > + > + return __vcpu_sys_reg(vcpu, reg); > +} > + > +static inline void _vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, enum vcpu_sysreg reg) > +{ > + if (!is_nvhe_hyp_code()) > + vcpu_write_sys_reg(vcpu, val, reg); > + else > + __vcpu_assign_sys_reg(vcpu, reg, val); > +} > + > static inline void kvm_vcpu_set_be(struct kvm_vcpu *vcpu) > { > if (vcpu_mode_is_32bit(vcpu)) { > @@ -516,9 +532,9 @@ static inline void kvm_vcpu_set_be(struct kvm_vcpu *vcpu) > > r = vcpu_has_nv(vcpu) ? SCTLR_EL2 : SCTLR_EL1; > > - sctlr = vcpu_read_sys_reg(vcpu, r); > + sctlr = _vcpu_read_sys_reg(vcpu, r); > sctlr |= SCTLR_ELx_EE; > - vcpu_write_sys_reg(vcpu, sctlr, r); > + _vcpu_write_sys_reg(vcpu, sctlr, r); > } > } > > @@ -533,7 +549,7 @@ static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu) > r = is_hyp_ctxt(vcpu) ? SCTLR_EL2 : SCTLR_EL1; > bit = vcpu_mode_priv(vcpu) ? SCTLR_ELx_EE : SCTLR_EL1_E0E; > > - return vcpu_read_sys_reg(vcpu, r) & bit; > + return _vcpu_read_sys_reg(vcpu, r) & bit; > } > > static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu, > -- > 2.54.0.1136.gdb2ca164c4-goog >