Skip to content

Commit 466eec4

Browse files
committed
KVM: SVM: Use unsigned integers when dealing with ASIDs
Convert all local ASID variables and parameters throughout the SEV code from signed integers to unsigned integers. As ASIDs are fundamentally unsigned values, and the global min/max variables are appropriately unsigned integers, too. Functionally, this is a glorified nop as KVM guarantees min_sev_asid is non-zero, and no CPU supports -1u as the _only_ asid, i.e. the signed vs. unsigned goof won't cause problems in practice. Opportunistically use sev_get_asid() in sev_flush_encrypted_page() instead of open coding an equivalent. Reviewed-by: Tom Lendacky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent cc4ce37 commit 466eec4

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ struct enc_region {
8484
};
8585

8686
/* Called with the sev_bitmap_lock held, or on shutdown */
87-
static int sev_flush_asids(int min_asid, int max_asid)
87+
static int sev_flush_asids(unsigned int min_asid, unsigned int max_asid)
8888
{
89-
int ret, asid, error = 0;
89+
int ret, error = 0;
90+
unsigned int asid;
9091

9192
/* Check if there are any ASIDs to reclaim before performing a flush */
9293
asid = find_next_bit(sev_reclaim_asid_bitmap, nr_asids, min_asid);
@@ -116,7 +117,7 @@ static inline bool is_mirroring_enc_context(struct kvm *kvm)
116117
}
117118

118119
/* Must be called with the sev_bitmap_lock held */
119-
static bool __sev_recycle_asids(int min_asid, int max_asid)
120+
static bool __sev_recycle_asids(unsigned int min_asid, unsigned int max_asid)
120121
{
121122
if (sev_flush_asids(min_asid, max_asid))
122123
return false;
@@ -143,8 +144,9 @@ static void sev_misc_cg_uncharge(struct kvm_sev_info *sev)
143144

144145
static int sev_asid_new(struct kvm_sev_info *sev)
145146
{
146-
int asid, min_asid, max_asid, ret;
147+
unsigned int asid, min_asid, max_asid;
147148
bool retry = true;
149+
int ret;
148150

149151
WARN_ON(sev->misc_cg);
150152
sev->misc_cg = get_current_misc_cg();
@@ -188,7 +190,7 @@ static int sev_asid_new(struct kvm_sev_info *sev)
188190
return ret;
189191
}
190192

191-
static int sev_get_asid(struct kvm *kvm)
193+
static unsigned int sev_get_asid(struct kvm *kvm)
192194
{
193195
struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
194196

@@ -284,8 +286,8 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp)
284286

285287
static int sev_bind_asid(struct kvm *kvm, unsigned int handle, int *error)
286288
{
289+
unsigned int asid = sev_get_asid(kvm);
287290
struct sev_data_activate activate;
288-
int asid = sev_get_asid(kvm);
289291
int ret;
290292

291293
/* activate ASID on the given handle */
@@ -2312,7 +2314,7 @@ int sev_cpu_init(struct svm_cpu_data *sd)
23122314
*/
23132315
static void sev_flush_encrypted_page(struct kvm_vcpu *vcpu, void *va)
23142316
{
2315-
int asid = to_kvm_svm(vcpu->kvm)->sev_info.asid;
2317+
unsigned int asid = sev_get_asid(vcpu->kvm);
23162318

23172319
/*
23182320
* Note! The address must be a kernel address, as regular page walk
@@ -2630,7 +2632,7 @@ void sev_es_unmap_ghcb(struct vcpu_svm *svm)
26302632
void pre_sev_run(struct vcpu_svm *svm, int cpu)
26312633
{
26322634
struct svm_cpu_data *sd = per_cpu_ptr(&svm_data, cpu);
2633-
int asid = sev_get_asid(svm->vcpu.kvm);
2635+
unsigned int asid = sev_get_asid(svm->vcpu.kvm);
26342636

26352637
/* Assign the asid allocated with this SEV guest */
26362638
svm->asid = asid;

arch/x86/kvm/trace.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,13 @@ TRACE_EVENT(kvm_nested_intr_vmexit,
732732
* Tracepoint for nested #vmexit because of interrupt pending
733733
*/
734734
TRACE_EVENT(kvm_invlpga,
735-
TP_PROTO(__u64 rip, int asid, u64 address),
735+
TP_PROTO(__u64 rip, unsigned int asid, u64 address),
736736
TP_ARGS(rip, asid, address),
737737

738738
TP_STRUCT__entry(
739-
__field( __u64, rip )
740-
__field( int, asid )
741-
__field( __u64, address )
739+
__field( __u64, rip )
740+
__field( unsigned int, asid )
741+
__field( __u64, address )
742742
),
743743

744744
TP_fast_assign(
@@ -747,7 +747,7 @@ TRACE_EVENT(kvm_invlpga,
747747
__entry->address = address;
748748
),
749749

750-
TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
750+
TP_printk("rip: 0x%016llx asid: %u address: 0x%016llx",
751751
__entry->rip, __entry->asid, __entry->address)
752752
);
753753

0 commit comments

Comments
 (0)