Linux-HyperV List
 help / color / mirror / Atom feed
From: mdshahid03@gmail.com
To: haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com
Cc: tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, hpa@zytor.com, x86@kernel.org,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mohammad Shahid <mdshahid03@gmail.com>
Subject: [PATCH] x86/hyperv: use pointed-to type size for page table offsets
Date: Sun,  1 Nov 2026 13:50:34 +0530	[thread overview]
Message-ID: <20261101082034.134583-1-mdshahid03@gmail.com> (raw)

From: Mohammad Shahid <mdshahid03@gmail.com>

The Hyper-V crash trampoline code calculated page table entry
offsets using sizeof() on pointer variables.

Use sizeof(*ptr) instead to calculates the size of the
pointed-to page table entry.

This makes entry size explicit and avoids relying on the
pointer size matching the page table entry size.

This issue was reported by Coccinelle script noderef.cocci.

Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
---
 arch/x86/hyperv/hv_crash.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/hyperv/hv_crash.c b/arch/x86/hyperv/hv_crash.c
index 5ffcc23255de..810eb1a4a0a2 100644
--- a/arch/x86/hyperv/hv_crash.c
+++ b/arch/x86/hyperv/hv_crash.c
@@ -512,20 +512,20 @@ static void hv_crash_build_tramp_pt(void)
 	pte_t *pte;
 	u64 pa, addr = trampoline_pa;
 
-	p4d = hv_crash_ptpgs[0] + pgd_index(addr) * sizeof(p4d);
+	p4d = hv_crash_ptpgs[0] + pgd_index(addr) * sizeof(*p4d);
 	pa = virt_to_phys(hv_crash_ptpgs[1]);
 	set_p4d(p4d, __p4d(_PAGE_TABLE | pa));
 	p4d->p4d &= ~(_PAGE_NX);	/* enable execute */
 
-	pud = hv_crash_ptpgs[1] + pud_index(addr) * sizeof(pud);
+	pud = hv_crash_ptpgs[1] + pud_index(addr) * sizeof(*pud);
 	pa = virt_to_phys(hv_crash_ptpgs[2]);
 	set_pud(pud, __pud(_PAGE_TABLE | pa));
 
-	pmd = hv_crash_ptpgs[2] + pmd_index(addr) * sizeof(pmd);
+	pmd = hv_crash_ptpgs[2] + pmd_index(addr) * sizeof(*pmd);
 	pa = virt_to_phys(hv_crash_ptpgs[3]);
 	set_pmd(pmd, __pmd(_PAGE_TABLE | pa));
 
-	pte = hv_crash_ptpgs[3] + pte_index(addr) * sizeof(pte);
+	pte = hv_crash_ptpgs[3] + pte_index(addr) * sizeof(*pte);
 	set_pte(pte, pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
 }
 
-- 
2.43.0


                 reply	other threads:[~2026-11-01  8:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261101082034.134583-1-mdshahid03@gmail.com \
    --to=mdshahid03@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox