From nobody Mon Feb 9 21:03:31 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 7025C26E6FA for ; Tue, 10 Jun 2025 22:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749596306; cv=none; b=D3R5CDPRrHRl0+F2bsZQWnxiagnOdYuvolDyo4OlE8TC8T7bi/JTG5bABbevZ5kYIr7iE5XD2fi+oGoMhYgICRUmfs1FO7iqHDo42TVbOpkIBRiWHnPiW7XH6ceUNwrpVRXVu3Ba/dOCgfaxzEIay3dm+BzTzkInbxNXAjOvi7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749596306; c=relaxed/simple; bh=ZMrkmpCRHBNEmqTXy2uAR5fh6WPPiHvvzXeNcQCC0eI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UWu0+j1G+o/haeq/bDLYOnQLex1gLR64xrkaM+N4UxKS3XLRSU/gqjNa3/NbhOeM1lqBEVCedXoN2g6jzT+ORW5ZuxEiQIKWPp2+o5VFmHs7/LbJ90rtTjZCnacszJJrbWKu+4FEjNhIcFJt4b/FnQr3lfzl7kW1hXsmvFOSsKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pJvmIVlT; arc=none smtp.client-ip=209.85.210.201 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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pJvmIVlT" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-747adea6ddbso3907337b3a.0 for ; Tue, 10 Jun 2025 15:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749596305; x=1750201105; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=iMsn/XCpk3SvMnv5TdPAcg1wTJ8i5wLPr3bJ43LVwSc=; b=pJvmIVlTFa5tVZm0GNyiMHxDSyqHoFCmkK4jNJ6VIK9fVuGbuy7mszd0p6ToK04fzc dp5L44H0p2K/0Xx8UrYQQxWXhyKiXv0hE92FCAE8X2iWWPfams78Sm0fLxLGwEDskHLo Ve8iw0TJRdoL6gyh/vVfSnO03M7aX0YfltRqUM4HvaXlGhPmn/X29ddXSBpEMBBtTvPh lZPiyCGdRkmVMceTFC4fw2WDZ3SoQWiEsLrSEH+CQn6VQYrIK/XnxpJL32lEs7ni4HrN 9aC3JSHHcZLYlWOtXm+p1yzMrnspKmkJPv3ddihIMudqKIhzF1TGIwfI1lfTncmtAO7Y XvUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749596305; x=1750201105; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iMsn/XCpk3SvMnv5TdPAcg1wTJ8i5wLPr3bJ43LVwSc=; b=ZcWlNlznskobl8GmyUlJTl73Q4OPeJbycVNcBvJXMhq0NOBkQsN7K1tOWXDU/CUy38 lHyY4MdZU9L41/mNsrF3E4m9PZl/LJ3yTnftm6g+qAKoH6Ahjd3edNQ5QKoFgx/qDtrJ lMxN5oqle7NzVq6ykPpWF/OuwX1ijtQrhP5lsob4LPE7py4qeOv+3WjbiXX0odTcQJcr xuFSwla4wL8ht3DagpUIOsakcmNeBB5ibVhkyz22iOYzgaG7mGzA20M7IyaHg3vE6l3G Trb+RjXb4TT6BwG0wwXXSBCHnk+eXr1VuW205iap4+yEzPsW8j5U7y9VtsuNJzQWITtG LohQ== X-Forwarded-Encrypted: i=1; AJvYcCXmI76U8X7Bw3RXCQeywN8kknlR9WSxKtoSI/1MPklULxtoFA6Eq6gN8+GrYhJGR9Y3F93v9ez94BAZHoY=@vger.kernel.org X-Gm-Message-State: AOJu0YxWEXsdDB2G4gMZ8lNb1ewdhpieXsFMBKMBGye5Fqy7w2rPchE3 70LnM59mqe3ngXISNnUtWrFsxL81UAt/M0UpfolWStujI9Dc87GZpBiAgCYsCxM6+hdb/urnmD4 9CXBoFQ== X-Google-Smtp-Source: AGHT+IE0kK/JdurOn2YSGpKLeGkBXQuZuXlLOBNcSKRwobgbYBfija/k/FnwePHxSxLV3CrEwUySJM0qVwE= X-Received: from pgbda4.prod.google.com ([2002:a05:6a02:2384:b0:b2f:1e09:528b]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7a46:b0:218:bcd3:6d2e with SMTP id adf61e73a8af0-21f867474e5mr1981438637.36.1749596304697; Tue, 10 Jun 2025 15:58:24 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 10 Jun 2025 15:57:31 -0700 In-Reply-To: <20250610225737.156318-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250610225737.156318-1-seanjc@google.com> X-Mailer: git-send-email 2.50.0.rc0.642.g800a2b2222-goog Message-ID: <20250610225737.156318-27-seanjc@google.com> Subject: [PATCH v2 26/32] KVM: SVM: Store MSRPM pointer as "void *" instead of "u32 *" From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Gao , Borislav Petkov , Xin Li , Dapeng Mi , Francesco Lavra , Manali Shukla Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Store KVM's MSRPM pointers as "void *" instead of "u32 *" to guard against directly accessing the bitmaps outside of code that is explicitly written to access the bitmaps with a specific type. Opportunistically use svm_vcpu_free_msrpm() in svm_vcpu_free() instead of open coding an equivalent. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/nested.c | 4 +++- arch/x86/kvm/svm/svm.c | 8 ++++---- arch/x86/kvm/svm/svm.h | 13 ++++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 13de4f63a9c2..f9bda148273e 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -277,6 +277,8 @@ int __init nested_svm_init_msrpm_merge_offsets(void) static bool nested_svm_merge_msrpm(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm =3D to_svm(vcpu); + u32 *msrpm02 =3D svm->nested.msrpm; + u32 *msrpm01 =3D svm->msrpm; int i; =20 /* @@ -311,7 +313,7 @@ static bool nested_svm_merge_msrpm(struct kvm_vcpu *vcp= u) if (kvm_vcpu_read_guest(vcpu, offset, &value, 4)) return false; =20 - svm->nested.msrpm[p] =3D svm->msrpm[p] | value; + msrpm02[p] =3D msrpm01[p] | value; } =20 svm->nested.force_msr_bitmap_recalc =3D false; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 5008e929b1a5..fc41ec70b6de 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -728,11 +728,11 @@ void svm_enable_intercept_for_msr(struct kvm_vcpu *vc= pu, u32 msr, int type) svm->nested.force_msr_bitmap_recalc =3D true; } =20 -u32 *svm_vcpu_alloc_msrpm(void) +void *svm_vcpu_alloc_msrpm(void) { unsigned int order =3D get_order(MSRPM_SIZE); struct page *pages =3D alloc_pages(GFP_KERNEL_ACCOUNT, order); - u32 *msrpm; + void *msrpm; =20 if (!pages) return NULL; @@ -805,7 +805,7 @@ void svm_set_x2apic_msr_interception(struct vcpu_svm *s= vm, bool intercept) svm->x2avic_msrs_intercepted =3D intercept; } =20 -void svm_vcpu_free_msrpm(u32 *msrpm) +void svm_vcpu_free_msrpm(void *msrpm) { __free_pages(virt_to_page(msrpm), get_order(MSRPM_SIZE)); } @@ -1353,7 +1353,7 @@ static void svm_vcpu_free(struct kvm_vcpu *vcpu) sev_free_vcpu(vcpu); =20 __free_page(__sme_pa_to_page(svm->vmcb01.pa)); - __free_pages(virt_to_page(svm->msrpm), get_order(MSRPM_SIZE)); + svm_vcpu_free_msrpm(svm->msrpm); } =20 #ifdef CONFIG_CPU_MITIGATIONS diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index a0c14256cc56..e078df15f1d8 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -186,8 +186,11 @@ struct svm_nested_state { u64 vmcb12_gpa; u64 last_vmcb12_gpa; =20 - /* These are the merged vectors */ - u32 *msrpm; + /* + * The MSR permissions map used for vmcb02, which is the merge result + * of vmcb01 and vmcb12 + */ + void *msrpm; =20 /* A VMRUN has started but has not yet been performed, so * we cannot inject a nested vmexit yet. */ @@ -268,7 +271,7 @@ struct vcpu_svm { */ u64 virt_spec_ctrl; =20 - u32 *msrpm; + void *msrpm; =20 ulong nmi_iret_rip; =20 @@ -666,8 +669,8 @@ BUILD_SVM_MSR_BITMAP_HELPERS(void, set, __set) /* svm.c */ extern bool dump_invalid_vmcb; =20 -u32 *svm_vcpu_alloc_msrpm(void); -void svm_vcpu_free_msrpm(u32 *msrpm); +void *svm_vcpu_alloc_msrpm(void); +void svm_vcpu_free_msrpm(void *msrpm); void svm_copy_lbrs(struct vmcb *to_vmcb, struct vmcb *from_vmcb); void svm_enable_lbrv(struct kvm_vcpu *vcpu); void svm_update_lbrv(struct kvm_vcpu *vcpu); --=20 2.50.0.rc0.642.g800a2b2222-goog