summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Leiner <simon@leiner.me>2020-08-25 11:31:53 +0200
committerJuergen Gross <jgross@suse.com>2020-08-27 08:58:51 +0200
commit9d3004bf7ba32c89873bb8422671d52b4bb52ce1 (patch)
tree3abe4c81ebdcb3f1b167489e4e3466675814e202
parentd742db70033c745e410523e00522ee0cfe2aa416 (diff)
downloadlinux-stable-9d3004bf7ba32c89873bb8422671d52b4bb52ce1.tar.gz
linux-stable-9d3004bf7ba32c89873bb8422671d52b4bb52ce1.tar.bz2
linux-stable-9d3004bf7ba32c89873bb8422671d52b4bb52ce1.zip
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 <simon@leiner.me> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> Link: https://lore.kernel.org/r/20200825093153.35500-2-simon@leiner.me Signed-off-by: Juergen Gross <jgross@suse.com>
-rw-r--r--include/xen/arm/page.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/include/xen/arm/page.h b/include/xen/arm/page.h
index d7f6af50e200..39df751d0dc4 100644
--- a/include/xen/arm/page.h
+++ b/include/xen/arm/page.h
@@ -76,7 +76,11 @@ static inline unsigned long bfn_to_pfn(unsigned long bfn)
#define bfn_to_local_pfn(bfn) bfn_to_pfn(bfn)
/* VIRT <-> GUEST conversion */
-#define virt_to_gfn(v) (pfn_to_gfn(virt_to_phys(v) >> XEN_PAGE_SHIFT))
+#define virt_to_gfn(v) \
+ ({ \
+ WARN_ON_ONCE(!virt_addr_valid(v)); \
+ pfn_to_gfn(virt_to_phys(v) >> XEN_PAGE_SHIFT); \
+ })
#define gfn_to_virt(m) (__va(gfn_to_pfn(m) << XEN_PAGE_SHIFT))
/* Only used in PV code. But ARM guests are always HVM. */