Skip to content

Commit bb2aa78

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: x86: SVM: move tsc ratio definitions to svm.h
Another piece of SVM spec which should be in the header file Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Message-Id: <20220322172449.235575-6-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 0dacc3d commit bb2aa78

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

arch/x86/include/asm/svm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
221221
#define SVM_NESTED_CTL_SEV_ES_ENABLE BIT(2)
222222

223223

224+
#define SVM_TSC_RATIO_RSVD 0xffffff0000000000ULL
225+
#define SVM_TSC_RATIO_MIN 0x0000000000000001ULL
226+
#define SVM_TSC_RATIO_MAX 0x000000ffffffffffULL
227+
#define SVM_TSC_RATIO_DEFAULT 0x0100000000ULL
228+
229+
224230
/* AVIC */
225231
#define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFFULL)
226232
#define AVIC_LOGICAL_ID_ENTRY_VALID_BIT 31

arch/x86/kvm/svm/svm.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ MODULE_DEVICE_TABLE(x86cpu, svm_cpu_id);
7272

7373
#define DEBUGCTL_RESERVED_BITS (~(0x3fULL))
7474

75-
#define TSC_RATIO_RSVD 0xffffff0000000000ULL
76-
#define TSC_RATIO_MIN 0x0000000000000001ULL
77-
#define TSC_RATIO_MAX 0x000000ffffffffffULL
78-
7975
static bool erratum_383_found __read_mostly;
8076

8177
u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly;
@@ -87,7 +83,6 @@ u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly;
8783
static uint64_t osvw_len = 4, osvw_status;
8884

8985
static DEFINE_PER_CPU(u64, current_tsc_ratio);
90-
#define TSC_RATIO_DEFAULT 0x0100000000ULL
9186

9287
static const struct svm_direct_access_msrs {
9388
u32 index; /* Index of the MSR */
@@ -480,7 +475,7 @@ static void svm_hardware_disable(void)
480475
{
481476
/* Make sure we clean up behind us */
482477
if (tsc_scaling)
483-
wrmsrl(MSR_AMD64_TSC_RATIO, TSC_RATIO_DEFAULT);
478+
wrmsrl(MSR_AMD64_TSC_RATIO, SVM_TSC_RATIO_DEFAULT);
484479

485480
cpu_svm_disable();
486481

@@ -526,8 +521,8 @@ static int svm_hardware_enable(void)
526521
* Set the default value, even if we don't use TSC scaling
527522
* to avoid having stale value in the msr
528523
*/
529-
wrmsrl(MSR_AMD64_TSC_RATIO, TSC_RATIO_DEFAULT);
530-
__this_cpu_write(current_tsc_ratio, TSC_RATIO_DEFAULT);
524+
wrmsrl(MSR_AMD64_TSC_RATIO, SVM_TSC_RATIO_DEFAULT);
525+
__this_cpu_write(current_tsc_ratio, SVM_TSC_RATIO_DEFAULT);
531526
}
532527

533528

@@ -2723,7 +2718,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
27232718
break;
27242719
}
27252720

2726-
if (data & TSC_RATIO_RSVD)
2721+
if (data & SVM_TSC_RATIO_RSVD)
27272722
return 1;
27282723

27292724
svm->tsc_ratio_msr = data;
@@ -4765,7 +4760,7 @@ static __init int svm_hardware_setup(void)
47654760
} else {
47664761
pr_info("TSC scaling supported\n");
47674762
kvm_has_tsc_control = true;
4768-
kvm_max_tsc_scaling_ratio = TSC_RATIO_MAX;
4763+
kvm_max_tsc_scaling_ratio = SVM_TSC_RATIO_MAX;
47694764
kvm_tsc_scaling_ratio_frac_bits = 32;
47704765
}
47714766
}

0 commit comments

Comments
 (0)