diff options
| author | Sean Christopherson <[email protected]> | 2025-06-10 22:57:30 +0000 |
|---|---|---|
| committer | Sean Christopherson <[email protected]> | 2025-06-20 20:07:33 +0000 |
| commit | 5c9c084763637460acaeb3e22508c692a70b6905 (patch) | |
| tree | db2492ff7a3ff5a2939f1490feabaae92bc8c837 /arch/x86/kvm/svm/nested.c | |
| parent | KVM: SVM: Drop explicit check on MSRPM offset when emulating SEV-ES accesses (diff) | |
| download | kernel-5c9c084763637460acaeb3e22508c692a70b6905.tar.gz kernel-5c9c084763637460acaeb3e22508c692a70b6905.zip | |
KVM: SVM: Move svm_msrpm_offset() to nested.c
Move svm_msrpm_offset() from svm.c to nested.c now that all usage of the
u32-index offsets is nested virtualization specific.
No functional change intended.
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Sean Christopherson <[email protected]>
Diffstat (limited to 'arch/x86/kvm/svm/nested.c')
| -rw-r--r-- | arch/x86/kvm/svm/nested.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index cf148f7db887..13de4f63a9c2 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -197,6 +197,29 @@ void recalc_intercepts(struct vcpu_svm *svm) static int nested_svm_msrpm_merge_offsets[6] __ro_after_init; static int nested_svm_nr_msrpm_merge_offsets __ro_after_init; +static const u32 msrpm_ranges[] = {0, 0xc0000000, 0xc0010000}; + +static u32 svm_msrpm_offset(u32 msr) +{ + u32 offset; + int i; + + for (i = 0; i < ARRAY_SIZE(msrpm_ranges); i++) { + if (msr < msrpm_ranges[i] || + msr >= msrpm_ranges[i] + SVM_MSRS_PER_RANGE) + continue; + + offset = (msr - msrpm_ranges[i]) / SVM_MSRS_PER_BYTE; + offset += (i * SVM_MSRPM_BYTES_PER_RANGE); /* add range offset */ + + /* Now we have the u8 offset - but need the u32 offset */ + return offset / 4; + } + + /* MSR not in any range */ + return MSR_INVALID; +} + int __init nested_svm_init_msrpm_merge_offsets(void) { static const u32 merge_msrs[] __initconst = { |
