* [PATCH] x86/hyperv: use pointed-to type size for page table offsets
@ 2026-11-01 8:20 mdshahid03
2026-11-01 22:41 ` Michael Kelley
0 siblings, 1 reply; 3+ messages in thread
From: mdshahid03 @ 2026-11-01 8:20 UTC (permalink / raw)
To: haiyangz, wei.liu, decui
Cc: tglx, mingo, bp, dave.hansen, hpa, x86, linux-hyperv,
linux-kernel, Mohammad Shahid
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] x86/hyperv: use pointed-to type size for page table offsets
2026-11-01 8:20 [PATCH] x86/hyperv: use pointed-to type size for page table offsets mdshahid03
@ 2026-11-01 22:41 ` Michael Kelley
2026-11-03 1:09 ` Wei Liu
0 siblings, 1 reply; 3+ messages in thread
From: Michael Kelley @ 2026-11-01 22:41 UTC (permalink / raw)
To: mdshahid03, haiyangz, wei.liu, decui
Cc: tglx, mingo, bp, dave.hansen, hpa, x86, linux-hyperv, linux-kernel
From: mdshahid03@gmail.com <mdshahid03@gmail.com> Sent: Sunday, November 1, 2026 1:21 AM
>
> 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.
FWIW, this issue was also reported by the kernel test robot.
See [1] & [2]. So you should probably add "Reported-by:" and
"Closes: " tags for those reports.
In any case, the fix looks good to me.
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
[1] https://lore.kernel.org/lkml/202603101143.qUL1R1iy-lkp@intel.com/
[2] https://lore.kernel.org/lkml/202610080503.ivDF5iYX-lkp@intel.com/
>
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/hyperv: use pointed-to type size for page table offsets
2026-11-01 22:41 ` Michael Kelley
@ 2026-11-03 1:09 ` Wei Liu
0 siblings, 0 replies; 3+ messages in thread
From: Wei Liu @ 2026-11-03 1:09 UTC (permalink / raw)
To: Michael Kelley
Cc: mdshahid03, haiyangz, wei.liu, decui, tglx, mingo, bp,
dave.hansen, hpa, x86, linux-hyperv, linux-kernel
On Sun, Nov 01, 2026 at 10:41:05PM +0000, Michael Kelley wrote:
> From: mdshahid03@gmail.com <mdshahid03@gmail.com> Sent: Sunday, November 1, 2026 1:21 AM
> >
> > 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.
>
> FWIW, this issue was also reported by the kernel test robot.
> See [1] & [2]. So you should probably add "Reported-by:" and
> "Closes: " tags for those reports.
>
> In any case, the fix looks good to me.
>
> Reviewed-by: Michael Kelley <mhklinux@outlook.com>
>
> [1] https://lore.kernel.org/lkml/202603101143.qUL1R1iy-lkp@intel.com/
> [2] https://lore.kernel.org/lkml/202610080503.ivDF5iYX-lkp@intel.com/
Applied. Thanks.
Wei
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-03 1:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-01 8:20 [PATCH] x86/hyperv: use pointed-to type size for page table offsets mdshahid03
2026-11-01 22:41 ` Michael Kelley
2026-11-03 1:09 ` Wei Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®