From e8b3f31d7a60648343ecbd45ab58dbcfc425b22c Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Tue, 17 May 2022 07:52:53 +0000 Subject: [PATCH] ANDROID: arm64: Fix MMIO guard ioremap when called before slab_is_available(). The ioremap hook can be called before slab is initialised, at which time calling into kmalloc() is not allowed. Signed-off-by: Keir Fraser Bug: 232894028 Fixes: 078e81b0c108 ("ANDROID: arm64: Implement ioremap/iounmap hooks calling into KVM's MMIO guard") Change-Id: Ieaf5adbdacdb196e37f4629998164a015e15c6d8 --- arch/arm64/mm/ioremap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c index 7c09ca4cdc1b..d3d5c3e4e731 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -108,7 +108,8 @@ void ioremap_phys_range_hook(phys_addr_t phys_addr, size_t size, pgprot_t prot) * This page will be permanently accessible, similar to a * saturated refcount. */ - ref = kzalloc(sizeof(*ref), GFP_KERNEL); + if (slab_is_available()) + ref = kzalloc(sizeof(*ref), GFP_KERNEL); if (ref) { refcount_set(&ref->count, 1); if (xa_err(xa_store(&ioremap_guard_array, pfn, ref,