Skip to content

Commit 53e63e9

Browse files
Paul Durrantsean-jc
authored andcommitted
KVM: pfncache: stop open-coding offset_in_page()
Some code in pfncache uses offset_in_page() but in other places it is open- coded. Use offset_in_page() consistently everywhere. Signed-off-by: Paul Durrant <pdurrant@amazon.com> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Link: https://lore.kernel.org/r/20240215152916.1158-7-paul@xen.org Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent a4bff3d commit 53e63e9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

virt/kvm/pfncache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len)
4848
if (!gpc->active)
4949
return false;
5050

51-
if ((gpc->gpa & ~PAGE_MASK) + len > PAGE_SIZE)
51+
if (offset_in_page(gpc->gpa) + len > PAGE_SIZE)
5252
return false;
5353

5454
if (gpc->generation != slots->generation || kvm_is_error_hva(gpc->uhva))
@@ -192,7 +192,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)
192192

193193
gpc->valid = true;
194194
gpc->pfn = new_pfn;
195-
gpc->khva = new_khva + (gpc->gpa & ~PAGE_MASK);
195+
gpc->khva = new_khva + offset_in_page(gpc->gpa);
196196

197197
/*
198198
* Put the reference to the _new_ pfn. The pfn is now tracked by the
@@ -213,7 +213,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa,
213213
unsigned long len)
214214
{
215215
struct kvm_memslots *slots = kvm_memslots(gpc->kvm);
216-
unsigned long page_offset = gpa & ~PAGE_MASK;
216+
unsigned long page_offset = offset_in_page(gpa);
217217
bool unmap_old = false;
218218
unsigned long old_uhva;
219219
kvm_pfn_t old_pfn;

0 commit comments

Comments
 (0)