From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 234BC3DB64A for ; Tue, 5 May 2026 19:53:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778010783; cv=none; b=nJtZHr4+ozISOU8pgRefjivHyRDvO7SIkWYA5thmYKEaIq3iySb5zBY92b6jpKOWffRML0gb5BA1+WPBkw8p9yOOtoC6r1DnPi3XzhcHmbanJ7TvdoJGV+77E6zpg9+vm5lRwwm/UhR4m5zE+ECRnK0EteVkTztGWkxgDQu/AOI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778010783; c=relaxed/simple; bh=7mx2Rcdlygnmrs2vjtPcfbzzCBA11TiFb3NszhIEg/A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RyD/b66Ug7J8CU483f+jtrPNpQjYYfDPDU7TYk/OWSeAn5ibncZY0mhA0SA7o4U/fL/H1A7cbhuI37yJFagOTvL3S0fHvTZbPUGaw8aOFW1DVvvbIX8T/VfMBx02HxV2m+C8LGIe/8ncRRwKGondU0/WRTSEy3esBLW9zoau2/M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=O+ZfGEjd; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=tZ5iXO7R; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="O+ZfGEjd"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="tZ5iXO7R" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778010781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N4tj7QeNb58lXu2azaV28nS46uz+bzJfiBhVJBY6iLw=; b=O+ZfGEjdJsX6RBQaHwmZkaT3FQFAEhGq74GZv8ExMdR7psORpMiwoFyz78cvwCUDN0I/Zf wasbw5O1jw3w9LM4g/lNSVZSXfH9dAidebwv23XvS3REqSx5syNQ/CtPLZFWnyEGt/dN7U Tsaypl6BgG7PLyhOFlD4ZEb0iz8jtvw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-XMVVcrx-PNyQR7ZVYfLzjw-1; Tue, 05 May 2026 15:53:00 -0400 X-MC-Unique: XMVVcrx-PNyQR7ZVYfLzjw-1 X-Mimecast-MFC-AGG-ID: XMVVcrx-PNyQR7ZVYfLzjw_1778010779 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-488f973ddfeso41385985e9.3 for ; Tue, 05 May 2026 12:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778010778; x=1778615578; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N4tj7QeNb58lXu2azaV28nS46uz+bzJfiBhVJBY6iLw=; b=tZ5iXO7R2uu7dSc/U34XdWUUcqe1kNxapnTfxIzf3LAU+krSiW0/r7ii8IbqjPW/Et FndRqFTGWTwBssgJhwrlczhA18VNFxuPtRpavP2t+T0M+b0kOpBAtLDnE3938+rvdktk fqfBd4WSbRrYI29JHu+rFBFc4BZQ8dmKu+8D2bTwm0CQI7h63efTtUd23NrdNz6+6QA3 JDmknYjf0PurvU1w1FprnCXHWqOSbJiLKw0qkwppBO8MC/HlLoVYa85IdzIVeoTUcCgR TP+yRtyGoSmxMoN4WJLll57esiJsUnWxScYFx6HNtYITrW8sLd+oOw+Vd8BMUPdqfWFJ epsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778010778; x=1778615578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=N4tj7QeNb58lXu2azaV28nS46uz+bzJfiBhVJBY6iLw=; b=qUyQ8zNykInFPDnasiWUqtR+n0vNte1xos5LSpD14IwrL2JTizLKq/JBwtT08mWk7d w2To179C92h/EZvpxla/Lg3WV3LRAh3nClkYp2yYeoENIRe51aDliyIzzD/A7ytJTQRs B4U67gJY4h+VYRe1CrIKnEpmKRqqBrS4MuGPhYratXGSZeSi9pRc9W7y6Jnv4bWlCjyU ASs7fziNB0R9AQ1zWVwLcU1b0jhGtTe1RyFKYCUewxh2DlOsrn3WuF+5KrY77lWs89Y7 ebZbLEREe3RjwPIV5EtZmwVIrOrKDIle9Yc1QX99XZd5D4fAyF6VcQioxGZ5IYHSGnrB N54A== X-Gm-Message-State: AOJu0Ywzvvi97U95ERYrKd8Jj9E66cIbetpIFKPW2G3thBQRjp8w/EMY WVvd1jF1ErqVzUCaFMt/fr+F51CeuKvkJxbyju99X+zG4JBi3rIOY/Yxr5lvVDiPSQAzbM8PcFT rIPtDUrgnAcaTNstADsukpAimk1KjBI0QxWHMAlhDgHJVvqxcxlNGr7wJ13bWRqFoFxrsMnzOB0 t1nMYS7xP97DjV+AaMSDnCnqeSk9bRHA2LnmIodPTgEMyuMJ+wxg== X-Gm-Gg: AeBDietIYLgq/6GAnMuX7WNoq5Hz4SW8P57HIAoYLUdIvnDweY2UGlv6E3G2TS5nZA3 trAuksHKWrBKeCXXGwMmSlkbgs5ZtdhIloMVeX09ehv8fpn/U1y89AghHHOKr602p7KnCz3nZAM qv7paG4r+a2timzDqRU1rXkfwtWzc3bgvwrd1YcIDr6XL4pRkuxyAo8+NdUlfy1g027GtLuWERN ikKfF8GGJ/UUMGMEkwuC/ylnOiq4+/jbR+bAsmBtp5wZ+cwW8JOgCanyYMhOxztlOKUnZ7gyks7 XvDwqLV5j/u2f9Kk6Jmr5s5XjudJ85OX+JVJbpq7/Nn+RPqw3el4Tllke13+LQrQArRx+o/1h8l 6HhOYoiCZp0quhevQc7hEyDmPqZ92E3Pul2eWPhnk9k6KlzxwyVwdDxNrmr8+5EiraWcE49WPw3 OGAh6TAgqsFDB0xSllQ4CmiddDdSAZOCzm9DrxFAc= X-Received: by 2002:a05:600c:34c8:b0:486:fba7:b150 with SMTP id 5b1f17b1804b1-48e51f2ed22mr11863885e9.15.1778010778348; Tue, 05 May 2026 12:52:58 -0700 (PDT) X-Received: by 2002:a05:600c:34c8:b0:486:fba7:b150 with SMTP id 5b1f17b1804b1-48e51f2ed22mr11863355e9.15.1778010777821; Tue, 05 May 2026 12:52:57 -0700 (PDT) Received: from [192.168.10.48] ([176.206.106.181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e52859ac7sm1615405e9.1.2026.05.05.12.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 12:52:56 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: d.riley@proxmox.com, jon@nutanix.com Subject: [PATCH 12/28] KVM: x86: make translate_nested_gpa vendor-specific Date: Tue, 5 May 2026 21:52:10 +0200 Message-ID: <20260505195226.563317-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260505195226.563317-1-pbonzini@redhat.com> References: <20260505195226.563317-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit EPT and NPT have different rules for passing PFERR_USER_MASK to the nested page table walk. In particular, for final addresses EPT uses the U bit of the guest (nGVA->nGPA) walk. While at it, remove PFERR_USER_MASK from the VMX version of the function, since it is actually ignored by the tables that update_permission_bitmask() generates for EPT. Tested-by: David Riley Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm_host.h | 4 ++++ arch/x86/kvm/hyperv.c | 3 ++- arch/x86/kvm/mmu.h | 9 +++------ arch/x86/kvm/svm/nested.c | 15 +++++++++++++++ arch/x86/kvm/vmx/nested.c | 12 ++++++++++++ arch/x86/kvm/x86.c | 16 ---------------- 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 8f2a1b915df9..62dc782b2dd3 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2010,6 +2010,10 @@ struct kvm_x86_nested_ops { struct kvm_nested_state *kvm_state); bool (*get_nested_state_pages)(struct kvm_vcpu *vcpu); int (*write_log_dirty)(struct kvm_vcpu *vcpu, gpa_t l2_gpa); + gpa_t (*translate_nested_gpa)(struct kvm_vcpu *vcpu, gpa_t gpa, + u64 access, + struct x86_exception *exception, + u64 pte_access); int (*enable_evmcs)(struct kvm_vcpu *vcpu, uint16_t *vmcs_version); diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 53688f7b76eb..f35fae3a7b3d 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -2041,7 +2041,8 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc) * read with kvm_read_guest(). */ if (!hc->fast && is_guest_mode(vcpu)) { - hc->ingpa = translate_nested_gpa(vcpu, hc->ingpa, + hc->ingpa = kvm_x86_ops.nested_ops->translate_nested_gpa( + vcpu, hc->ingpa, PFERR_GUEST_FINAL_MASK, NULL, 0); if (unlikely(hc->ingpa == INVALID_GPA)) return HV_STATUS_INVALID_HYPERCALL_INPUT; diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 635c2e5d8513..63be5c5efed9 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -294,10 +294,6 @@ static inline void kvm_update_page_stats(struct kvm *kvm, int level, int count) atomic64_add(count, &kvm->stat.pages[level - 1]); } -gpa_t translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u64 access, - struct x86_exception *exception, - u64 pte_access); - static inline gpa_t kvm_translate_gpa(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, gpa_t gpa, u64 access, @@ -306,8 +302,9 @@ static inline gpa_t kvm_translate_gpa(struct kvm_vcpu *vcpu, { if (mmu != &vcpu->arch.nested_mmu) return gpa; - return translate_nested_gpa(vcpu, gpa, access, exception, - pte_access); + return kvm_x86_ops.nested_ops->translate_nested_gpa(vcpu, gpa, access, + exception, + pte_access); } static inline bool kvm_has_mirrored_tdp(const struct kvm *kvm) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 961804df5f45..df232153eb24 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -2071,8 +2071,23 @@ static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu) return true; } +static gpa_t svm_translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, + u64 access, + struct x86_exception *exception, + u64 pte_access) +{ + struct kvm_mmu *mmu = vcpu->arch.mmu; + + BUG_ON(!mmu_is_nested(vcpu)); + + /* NPT walks are always user-walks */ + access |= PFERR_USER_MASK; + return mmu->gva_to_gpa(vcpu, mmu, gpa, access, exception); +} + struct kvm_x86_nested_ops svm_nested_ops = { .leave_nested = svm_leave_nested, + .translate_nested_gpa = svm_translate_nested_gpa, .is_exception_vmexit = nested_svm_is_exception_vmexit, .check_events = svm_check_nested_events, .triple_fault = nested_svm_triple_fault, diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 3fe88f29be7a..cd1924c6e075 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -7438,8 +7438,20 @@ __init int nested_vmx_hardware_setup(int (*exit_handlers[])(struct kvm_vcpu *)) return 0; } +static gpa_t vmx_translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, + u64 access, + struct x86_exception *exception, + u64 pte_access) +{ + struct kvm_mmu *mmu = vcpu->arch.mmu; + + BUG_ON(!mmu_is_nested(vcpu)); + return mmu->gva_to_gpa(vcpu, mmu, gpa, access, exception); +} + struct kvm_x86_nested_ops vmx_nested_ops = { .leave_nested = vmx_leave_nested, + .translate_nested_gpa = vmx_translate_nested_gpa, .is_exception_vmexit = nested_vmx_is_exception_vmexit, .check_events = vmx_check_nested_events, .has_events = vmx_has_nested_events, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 67979b7de5d6..7c6942afae81 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7848,22 +7848,6 @@ void kvm_get_segment(struct kvm_vcpu *vcpu, kvm_x86_call(get_segment)(vcpu, var, seg); } -gpa_t translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u64 access, - struct x86_exception *exception, - u64 pte_access) -{ - struct kvm_mmu *mmu = vcpu->arch.mmu; - gpa_t t_gpa; - - BUG_ON(!mmu_is_nested(vcpu)); - - /* NPT walks are always user-walks */ - access |= PFERR_USER_MASK; - t_gpa = mmu->gva_to_gpa(vcpu, mmu, gpa, access, exception); - - return t_gpa; -} - gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva, struct x86_exception *exception) { -- 2.54.0