As vaddr is aligned down, vaddr_end accordingly needs to be aligned. Otherwise, vaddr_end would be one page short. While at it, compute vaddr and vaddr_end using kernel defined headers.
Fixes: dc3f3d2474b8 ("x86/mm: Validate memory when changing the C-bit") Fixes: 5e5ccff60a29 ("x86/sev: Add helper for validating pages in early enc attribute changes") Suggested-by: Nikunj Dadhania nikunj.dadhania@amd.com Cc: stable@vger.kernel.org Signed-off-by: Pavan Kumar Paluri papaluri@amd.com --- arch/x86/kernel/sev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 679026a640ef..0f261cb306c3 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -648,8 +648,8 @@ static void pvalidate_pages(unsigned long vaddr, unsigned int npages, bool valid unsigned long vaddr_end; int rc;
- vaddr = vaddr & PAGE_MASK; - vaddr_end = vaddr + (npages << PAGE_SHIFT); + vaddr_end = PAGE_ALIGN(vaddr + (npages << PAGE_SHIFT)); + vaddr = PAGE_ALIGN_DOWN(vaddr);
while (vaddr < vaddr_end) { rc = pvalidate(vaddr, RMP_PG_SIZE_4K, validate); @@ -886,8 +886,8 @@ static void set_pages_state(unsigned long vaddr, unsigned int npages, int op) if (!desc) panic("SNP: failed to allocate memory for PSC descriptor\n");
- vaddr = vaddr & PAGE_MASK; - vaddr_end = vaddr + (npages << PAGE_SHIFT); + vaddr_end = PAGE_ALIGN(vaddr + (npages << PAGE_SHIFT)); + vaddr = PAGE_ALIGN_DOWN(vaddr);
while (vaddr < vaddr_end) { /* Calculate the last vaddr that fits in one struct snp_psc_desc. */