Skip to content

Commit 9d3004b

Browse files
sleinerjgross1
authored andcommitted
arm/xen: Add misuse warning to virt_to_gfn
As virt_to_gfn uses virt_to_phys, it will return invalid addresses when used with vmalloc'd addresses. This patch introduces a warning, when virt_to_gfn is used in this way. Signed-off-by: Simon Leiner <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent d742db7 commit 9d3004b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/xen/arm/page.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
7676
#define bfn_to_local_pfn(bfn) bfn_to_pfn(bfn)
7777

7878
/* VIRT <-> GUEST conversion */
79-
#define virt_to_gfn(v) (pfn_to_gfn(virt_to_phys(v) >> XEN_PAGE_SHIFT))
79+
#define virt_to_gfn(v) \
80+
({ \
81+
WARN_ON_ONCE(!virt_addr_valid(v)); \
82+
pfn_to_gfn(virt_to_phys(v) >> XEN_PAGE_SHIFT); \
83+
})
8084
#define gfn_to_virt(m) (__va(gfn_to_pfn(m) << XEN_PAGE_SHIFT))
8185

8286
/* Only used in PV code. But ARM guests are always HVM. */

0 commit comments

Comments
 (0)