From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 3E61A3D648F for ; Fri, 12 Jun 2026 06:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781247578; cv=none; b=mX1f0MSqvLDf/1Xy6zkMAPEgeXFwZWpkdyiq4XyMFBWjlmDiZmgOZfLUVkl/S2do/ZzzHJL5tfIHk6UkTT4CR///q6OWqcJRvJern4UPSwZ3zuFGrZUds2hnnPDheVBlY/r4SErWwdbMt4PAdslCoUGBAYaUvUmNKz7I/AMRTtM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781247578; c=relaxed/simple; bh=4WURvpJDPVYYj0WGTWF5CptahrmCXc9euJ9wF9TVrqg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UdWVsphwhyzNDDYv6FhMtOUMrPjrUzTmeFvdBcGBazJXqnXljx57C3x63VNDS78Splr8Bvgfnh2iZSJaIfd+dpBMhrMqqmip0rJKBa9g+4q5S4XYn/n8+d7aCDoQsm+MPcrozvdj/2oLFDxb2dJCdE5Wnabr6TXU/qGtnB3zlIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tWLeWxNq; arc=none smtp.client-ip=209.85.128.74 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=flex--tabba.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tWLeWxNq" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-490b0682d2fso5965335e9.0 for ; Thu, 11 Jun 2026 23:59:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781247572; x=1781852372; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cPQ40+RMSw9qS4ujNZWl4iP11kHXvB3QBni3mxBtwvQ=; b=tWLeWxNqhixYk3taAMlLIUM+eFlQ7ZEMxwFvdFooVifJ3d9S81qf48P2YbgxHbGxUZ 4UDTKcPUvFSu+xPaWV2w6MTzKyTGbPbrf05ORmjQe1l6wTiRSTqwZuPZwwoxhoCGG2tN a5gDWQ3j+tppitsLKV4F5NAHmyXa8Z2dU5fnkFN/FzTDLCTt9PjbrKgABsCQGXs/EbNa tfnPcAr16unpzzwrJoNAYt3X+DmAp9mzy2OnwA/kmw5U+8RK3fkzWl9KK4kI5qz0O0g3 pA+L/Cocm16DL30PaSxzcK6KyJ1Nve1seGLIU5Yf+9N23yw2h1Wz1m17ZjzkRsxSfD36 Nmjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781247572; x=1781852372; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cPQ40+RMSw9qS4ujNZWl4iP11kHXvB3QBni3mxBtwvQ=; b=dOn1xepqUlvkx++2mumalnQMFbnAZRYezwKj1doad7vJiV8+1UtBG/ps/0Q3QZy6+b GrvC7By7+6Li5reoTk4KzvTu9MA1OL1zg0LMWAXAaEUxDpN4lwE91dJXOhskr/uJCaXM sf7DpPkHP0bNo43Av5PAMvIRR0nGm1DRT4RE5rpjDg/eQgN/twEWShxVzg/a0Xwj97jA /h+f+vmGbgDvtNwacQIijxW8VfMxNn/2790HORAD3I2Hn1lnVZhPXpH5poSmkID5N0uB m0kAU7/1koCeel/xcqcEqPjfb/hArlWavVloiBW4X+IUA6Je+tk8FtNzID568jdzBXkG bcEw== X-Forwarded-Encrypted: i=1; AFNElJ9e8hiJxgCKbM6/IHgp84BHZ4hD9/zu0aNZX7O+P2fm8YaUupPZ+a3d2Xk5VtgAkmSl38rLhu7DMaR2Utc=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4N3ZhkD4UeyKp/yPaUF7sEZabVRA3w0uG/fm8FoX2SQKtiLRZ mplxf3MSzkW/NGjGHde+4UBETiz4XbblJQXU59pl1YLQSocjYWKDuMM855tCAKhjxxusKA3e0DZ g5A== X-Received: from wmdd27.prod.google.com ([2002:a05:600c:a21b:b0:488:9c2a:aec4]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3104:b0:490:58ef:cea7 with SMTP id 5b1f17b1804b1-490ec4f2603mr16796025e9.22.1781247571436; Thu, 11 Jun 2026 23:59:31 -0700 (PDT) Date: Fri, 12 Jun 2026 07:59:19 +0100 In-Reply-To: <20260612065925.755562-1-tabba@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260612065925.755562-1-tabba@google.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260612065925.755562-6-tabba@google.com> Subject: [PATCH v1 05/11] KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code From: tabba@google.com To: Marc Zyngier , Oliver Upton Cc: Fuad Tabba , Will Deacon , Catalin Marinas , Quentin Perret , Vincent Donnefort , 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 Content-Type: text/plain; charset="UTF-8" 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) +{ + 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