Skip to content

Commit 067e4f1

Browse files
linuswjgross1
authored andcommitted
x86/xen: Make virt_to_pfn() a static inline
Making virt_to_pfn() a static inline taking a strongly typed (const void *) makes the contract of a passing a pointer of that type to the function explicit and exposes any misuse of the macro virt_to_pfn() acting polymorphic and accepting many types such as (void *), (unitptr_t) or (unsigned long) as arguments without warnings. Also fix all offending call sites to pass a (void *) rather than an unsigned long. Since virt_to_mfn() is wrapping virt_to_pfn() this function has become polymorphic as well so the usage need to be fixed up. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Juergen Gross <jgross@suse.com> Link: https://lore.kernel.org/r/20230810-virt-to-phys-x86-xen-v1-1-9e966d333e7a@linaro.org Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent d826c9e commit 067e4f1

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

arch/x86/include/asm/xen/page.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ static inline unsigned long bfn_to_local_pfn(unsigned long mfn)
295295

296296
/* VIRT <-> MACHINE conversion */
297297
#define virt_to_machine(v) (phys_to_machine(XPADDR(__pa(v))))
298-
#define virt_to_pfn(v) (PFN_DOWN(__pa(v)))
298+
static inline unsigned long virt_to_pfn(const void *v)
299+
{
300+
return PFN_DOWN(__pa(v));
301+
}
299302
#define virt_to_mfn(v) (pfn_to_mfn(virt_to_pfn(v)))
300303
#define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
301304

arch/x86/xen/enlighten_pv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
523523
BUG_ON(size > PAGE_SIZE);
524524
BUG_ON(va & ~PAGE_MASK);
525525

526-
pfn = virt_to_pfn(va);
526+
pfn = virt_to_pfn((void *)va);
527527
mfn = pfn_to_mfn(pfn);
528528

529529
pte = pfn_pte(pfn, PAGE_KERNEL_RO);

arch/x86/xen/mmu_pv.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,13 +2202,13 @@ static void xen_zap_pfn_range(unsigned long vaddr, unsigned int order,
22022202
mcs = __xen_mc_entry(0);
22032203

22042204
if (in_frames)
2205-
in_frames[i] = virt_to_mfn(vaddr);
2205+
in_frames[i] = virt_to_mfn((void *)vaddr);
22062206

22072207
MULTI_update_va_mapping(mcs.mc, vaddr, VOID_PTE, 0);
2208-
__set_phys_to_machine(virt_to_pfn(vaddr), INVALID_P2M_ENTRY);
2208+
__set_phys_to_machine(virt_to_pfn((void *)vaddr), INVALID_P2M_ENTRY);
22092209

22102210
if (out_frames)
2211-
out_frames[i] = virt_to_pfn(vaddr);
2211+
out_frames[i] = virt_to_pfn((void *)vaddr);
22122212
}
22132213
xen_mc_issue(0);
22142214
}
@@ -2250,7 +2250,7 @@ static void xen_remap_exchanged_ptes(unsigned long vaddr, int order,
22502250
MULTI_update_va_mapping(mcs.mc, vaddr,
22512251
mfn_pte(mfn, PAGE_KERNEL), flags);
22522252

2253-
set_phys_to_machine(virt_to_pfn(vaddr), mfn);
2253+
set_phys_to_machine(virt_to_pfn((void *)vaddr), mfn);
22542254
}
22552255

22562256
xen_mc_issue(0);
@@ -2321,7 +2321,7 @@ int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
23212321
xen_zap_pfn_range(vstart, order, in_frames, NULL);
23222322

23232323
/* 2. Get a new contiguous memory extent. */
2324-
out_frame = virt_to_pfn(vstart);
2324+
out_frame = virt_to_pfn((void *)vstart);
23252325
success = xen_exchange_memory(1UL << order, 0, in_frames,
23262326
1, order, &out_frame,
23272327
address_bits);
@@ -2354,7 +2354,7 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
23542354
spin_lock_irqsave(&xen_reservation_lock, flags);
23552355

23562356
/* 1. Find start MFN of contiguous extent. */
2357-
in_frame = virt_to_mfn(vstart);
2357+
in_frame = virt_to_mfn((void *)vstart);
23582358

23592359
/* 2. Zap current PTEs. */
23602360
xen_zap_pfn_range(vstart, order, NULL, out_frames);

arch/x86/xen/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static void __init xen_do_set_identity_and_remap_chunk(
340340

341341
WARN_ON(size == 0);
342342

343-
mfn_save = virt_to_mfn(buf);
343+
mfn_save = virt_to_mfn((void *)buf);
344344

345345
for (ident_pfn_iter = start_pfn, remap_pfn_iter = remap_pfn;
346346
ident_pfn_iter < ident_end_pfn;
@@ -503,7 +503,7 @@ void __init xen_remap_memory(void)
503503
unsigned long pfn_s = ~0UL;
504504
unsigned long len = 0;
505505

506-
mfn_save = virt_to_mfn(buf);
506+
mfn_save = virt_to_mfn((void *)buf);
507507

508508
while (xen_remap_mfn != INVALID_P2M_ENTRY) {
509509
/* Map the remap information */

0 commit comments

Comments
 (0)