Skip to content

Commit 7645829

Browse files
committed
KVM: x86/mmu: Add KVM_RMAP_MANY to replace open coded '1' and '1ul' literals
Replace all of the open coded '1' literals used to mark a PTE list as having many/multiple entries with a proper define. It's hard enough to read the code with one magic bit, and a future patch to support "locking" a single rmap will add another. No functional change intended. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 7aac9dc commit 7645829

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ static struct kvm_memory_slot *gfn_to_memslot_dirty_bitmap(struct kvm_vcpu *vcpu
912912
* in this rmap chain. Otherwise, (rmap_head->val & ~1) points to a struct
913913
* pte_list_desc containing more mappings.
914914
*/
915+
#define KVM_RMAP_MANY BIT(0)
915916

916917
/*
917918
* Returns the number of pointers in the rmap chain, not counting the new one.
@@ -924,16 +925,16 @@ static int pte_list_add(struct kvm_mmu_memory_cache *cache, u64 *spte,
924925

925926
if (!rmap_head->val) {
926927
rmap_head->val = (unsigned long)spte;
927-
} else if (!(rmap_head->val & 1)) {
928+
} else if (!(rmap_head->val & KVM_RMAP_MANY)) {
928929
desc = kvm_mmu_memory_cache_alloc(cache);
929930
desc->sptes[0] = (u64 *)rmap_head->val;
930931
desc->sptes[1] = spte;
931932
desc->spte_count = 2;
932933
desc->tail_count = 0;
933-
rmap_head->val = (unsigned long)desc | 1;
934+
rmap_head->val = (unsigned long)desc | KVM_RMAP_MANY;
934935
++count;
935936
} else {
936-
desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
937+
desc = (struct pte_list_desc *)(rmap_head->val & ~KVM_RMAP_MANY);
937938
count = desc->tail_count + desc->spte_count;
938939

939940
/*
@@ -942,10 +943,10 @@ static int pte_list_add(struct kvm_mmu_memory_cache *cache, u64 *spte,
942943
*/
943944
if (desc->spte_count == PTE_LIST_EXT) {
944945
desc = kvm_mmu_memory_cache_alloc(cache);
945-
desc->more = (struct pte_list_desc *)(rmap_head->val & ~1ul);
946+
desc->more = (struct pte_list_desc *)(rmap_head->val & ~KVM_RMAP_MANY);
946947
desc->spte_count = 0;
947948
desc->tail_count = count;
948-
rmap_head->val = (unsigned long)desc | 1;
949+
rmap_head->val = (unsigned long)desc | KVM_RMAP_MANY;
949950
}
950951
desc->sptes[desc->spte_count++] = spte;
951952
}
@@ -956,7 +957,7 @@ static void pte_list_desc_remove_entry(struct kvm *kvm,
956957
struct kvm_rmap_head *rmap_head,
957958
struct pte_list_desc *desc, int i)
958959
{
959-
struct pte_list_desc *head_desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
960+
struct pte_list_desc *head_desc = (struct pte_list_desc *)(rmap_head->val & ~KVM_RMAP_MANY);
960961
int j = head_desc->spte_count - 1;
961962

962963
/*
@@ -985,7 +986,7 @@ static void pte_list_desc_remove_entry(struct kvm *kvm,
985986
if (!head_desc->more)
986987
rmap_head->val = 0;
987988
else
988-
rmap_head->val = (unsigned long)head_desc->more | 1;
989+
rmap_head->val = (unsigned long)head_desc->more | KVM_RMAP_MANY;
989990
mmu_free_pte_list_desc(head_desc);
990991
}
991992

@@ -998,13 +999,13 @@ static void pte_list_remove(struct kvm *kvm, u64 *spte,
998999
if (KVM_BUG_ON_DATA_CORRUPTION(!rmap_head->val, kvm))
9991000
return;
10001001

1001-
if (!(rmap_head->val & 1)) {
1002+
if (!(rmap_head->val & KVM_RMAP_MANY)) {
10021003
if (KVM_BUG_ON_DATA_CORRUPTION((u64 *)rmap_head->val != spte, kvm))
10031004
return;
10041005

10051006
rmap_head->val = 0;
10061007
} else {
1007-
desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
1008+
desc = (struct pte_list_desc *)(rmap_head->val & ~KVM_RMAP_MANY);
10081009
while (desc) {
10091010
for (i = 0; i < desc->spte_count; ++i) {
10101011
if (desc->sptes[i] == spte) {
@@ -1037,12 +1038,12 @@ static bool kvm_zap_all_rmap_sptes(struct kvm *kvm,
10371038
if (!rmap_head->val)
10381039
return false;
10391040

1040-
if (!(rmap_head->val & 1)) {
1041+
if (!(rmap_head->val & KVM_RMAP_MANY)) {
10411042
mmu_spte_clear_track_bits(kvm, (u64 *)rmap_head->val);
10421043
goto out;
10431044
}
10441045

1045-
desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
1046+
desc = (struct pte_list_desc *)(rmap_head->val & ~KVM_RMAP_MANY);
10461047

10471048
for (; desc; desc = next) {
10481049
for (i = 0; i < desc->spte_count; i++)
@@ -1062,10 +1063,10 @@ unsigned int pte_list_count(struct kvm_rmap_head *rmap_head)
10621063

10631064
if (!rmap_head->val)
10641065
return 0;
1065-
else if (!(rmap_head->val & 1))
1066+
else if (!(rmap_head->val & KVM_RMAP_MANY))
10661067
return 1;
10671068

1068-
desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
1069+
desc = (struct pte_list_desc *)(rmap_head->val & ~KVM_RMAP_MANY);
10691070
return desc->tail_count + desc->spte_count;
10701071
}
10711072

@@ -1127,13 +1128,13 @@ static u64 *rmap_get_first(struct kvm_rmap_head *rmap_head,
11271128
if (!rmap_head->val)
11281129
return NULL;
11291130

1130-
if (!(rmap_head->val & 1)) {
1131+
if (!(rmap_head->val & KVM_RMAP_MANY)) {
11311132
iter->desc = NULL;
11321133
sptep = (u64 *)rmap_head->val;
11331134
goto out;
11341135
}
11351136

1136-
iter->desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
1137+
iter->desc = (struct pte_list_desc *)(rmap_head->val & ~KVM_RMAP_MANY);
11371138
iter->pos = 0;
11381139
sptep = iter->desc->sptes[iter->pos];
11391140
out:

0 commit comments

Comments
 (0)