public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment
@ 2026-02-09  3:24 kyle-jk.liao
  2026-02-09  9:22 ` Marc Zyngier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: kyle-jk.liao @ 2026-02-09  3:24 UTC (permalink / raw)
  To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
	Zenghui Yu, Catalin Marinas, Will Deacon, Matthias Brugger,
	AngeloGioacchino Del Regno, Quentin Perret, Vincent Donnefort,
	linux-arm-kernel, kvmarm, linux-kernel, linux-mediatek
  Cc: wsd_upstream, rock.yeh, hungwen.chien, kyle-jk.liao

From: "kyle-jk.liao" <kyle-jk.liao@mediatek.com>

The host_stage2_adjust_range() function triggers a WARN_ON when
encountering pages marked as both PKVM_NOPAGE and PKVM_MODULE_OWNED_PAGE.
This occurs when load_unaligned_zeropad() accesses memory that crosses
page boundaries, where one of the pages is module-owned.

Extend the check to accept pages with the PKVM_MODULE_OWNED_PAGE flag
in addition to PKVM_NOPAGE, preventing spurious warnings during normal
module memory access patterns.

Signed-off-by: kyle-jk.liao <kyle-jk.liao@mediatek.com>
---
 arch/arm64/kvm/hyp/nvhe/mem_protect.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
index 49db32f3ddf7..baaabf4b5112 100644
--- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
+++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
@@ -495,6 +495,7 @@ static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range)
 	u64 granule;
 	s8 level;
 	int ret;
+	enum pkvm_page_state state;
 
 	hyp_assert_lock_held(&host_mmu.lock);
 	ret = kvm_pgtable_get_leaf(&host_mmu.pgt, addr, &pte, &level);
@@ -505,8 +506,9 @@ static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range)
 		return -EAGAIN;
 
 	if (pte) {
+		state = get_host_state(hyp_phys_to_page(addr));
 		WARN_ON(addr_is_memory(addr) &&
-			get_host_state(hyp_phys_to_page(addr)) != PKVM_NOPAGE);
+			(state != PKVM_NOPAGE && state != (PKVM_NOPAGE | PKVM_MODULE_OWNED_PAGE)));
 		return -EPERM;
 	}
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment
  2026-02-09  3:24 [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment kyle-jk.liao
@ 2026-02-09  9:22 ` Marc Zyngier
  2026-02-09 17:35 ` kernel test robot
  2026-02-09 22:44 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2026-02-09  9:22 UTC (permalink / raw)
  To: kyle-jk.liao
  Cc: Oliver Upton, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
	Catalin Marinas, Will Deacon, Matthias Brugger,
	AngeloGioacchino Del Regno, Quentin Perret, Vincent Donnefort,
	linux-arm-kernel, kvmarm, linux-kernel, linux-mediatek,
	wsd_upstream, rock.yeh, hungwen.chien

On Mon, 09 Feb 2026 03:24:13 +0000,
<kyle-jk.liao@mediatek.com> wrote:
> 
> From: "kyle-jk.liao" <kyle-jk.liao@mediatek.com>
> 
> The host_stage2_adjust_range() function triggers a WARN_ON when
> encountering pages marked as both PKVM_NOPAGE and PKVM_MODULE_OWNED_PAGE.
> This occurs when load_unaligned_zeropad() accesses memory that crosses
> page boundaries, where one of the pages is module-owned.
> 
> Extend the check to accept pages with the PKVM_MODULE_OWNED_PAGE flag
> in addition to PKVM_NOPAGE, preventing spurious warnings during normal
> module memory access patterns.
> 
> Signed-off-by: kyle-jk.liao <kyle-jk.liao@mediatek.com>
> ---
>  arch/arm64/kvm/hyp/nvhe/mem_protect.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> index 49db32f3ddf7..baaabf4b5112 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> @@ -495,6 +495,7 @@ static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range)
>  	u64 granule;
>  	s8 level;
>  	int ret;
> +	enum pkvm_page_state state;
>  
>  	hyp_assert_lock_held(&host_mmu.lock);
>  	ret = kvm_pgtable_get_leaf(&host_mmu.pgt, addr, &pte, &level);
> @@ -505,8 +506,9 @@ static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range)
>  		return -EAGAIN;
>  
>  	if (pte) {
> +		state = get_host_state(hyp_phys_to_page(addr));
>  		WARN_ON(addr_is_memory(addr) &&
> -			get_host_state(hyp_phys_to_page(addr)) != PKVM_NOPAGE);
> +			(state != PKVM_NOPAGE && state != (PKVM_NOPAGE | PKVM_MODULE_OWNED_PAGE)));
>  		return -EPERM;
>  	}
>  

None of that exists upstream.

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment
  2026-02-09  3:24 [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment kyle-jk.liao
  2026-02-09  9:22 ` Marc Zyngier
@ 2026-02-09 17:35 ` kernel test robot
  2026-02-09 22:44 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-02-09 17:35 UTC (permalink / raw)
  To: kyle-jk.liao, Marc Zyngier, Oliver Upton, Joey Gouly,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Matthias Brugger, AngeloGioacchino Del Regno, Quentin Perret,
	Vincent Donnefort, linux-arm-kernel, kvmarm, linux-kernel,
	linux-mediatek
  Cc: oe-kbuild-all, wsd_upstream, rock.yeh, hungwen.chien,
	kyle-jk.liao

Hi,

kernel test robot noticed the following build errors:

[auto build test ERROR on kvmarm/next]
[also build test ERROR on linus/master v6.19 next-20260205]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/kyle-jk-liao-mediatek-com/KVM-arm64-Allow-module-owned-pages-in-host-stage-2-range-adjustment/20260209-112902
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next
patch link:    https://lore.kernel.org/r/20260209032421.1278325-1-kyle-jk.liao%40mediatek.com
patch subject: [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment
config: arm64-defconfig (https://download.01.org/0day-ci/archive/20260210/202602100127.gNjhsGVB-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260210/202602100127.gNjhsGVB-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602100127.gNjhsGVB-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from arch/arm64/include/asm/bug.h:26,
                    from include/linux/bug.h:5,
                    from include/linux/thread_info.h:13,
                    from arch/arm64/include/asm/processor.h:35,
                    from include/linux/sched.h:13,
                    from include/linux/resume_user_mode.h:6,
                    from include/linux/entry-virt.h:6,
                    from include/linux/kvm_host.h:5,
                    from arch/arm64/kvm/hyp/nvhe/mem_protect.c:7:
   arch/arm64/kvm/hyp/nvhe/mem_protect.c: In function 'host_stage2_adjust_range':
>> arch/arm64/kvm/hyp/nvhe/mem_protect.c:513:74: error: 'PKVM_MODULE_OWNED_PAGE' undeclared (first use in this function)
     513 |                         (state != PKVM_NOPAGE && state != (PKVM_NOPAGE | PKVM_MODULE_OWNED_PAGE)));
         |                                                                          ^~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/bug.h:110:32: note: in definition of macro 'WARN_ON'
     110 |         int __ret_warn_on = !!(condition);                              \
         |                                ^~~~~~~~~
   arch/arm64/kvm/hyp/nvhe/mem_protect.c:513:74: note: each undeclared identifier is reported only once for each function it appears in
     513 |                         (state != PKVM_NOPAGE && state != (PKVM_NOPAGE | PKVM_MODULE_OWNED_PAGE)));
         |                                                                          ^~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/bug.h:110:32: note: in definition of macro 'WARN_ON'
     110 |         int __ret_warn_on = !!(condition);                              \
         |                                ^~~~~~~~~


vim +/PKVM_MODULE_OWNED_PAGE +513 arch/arm64/kvm/hyp/nvhe/mem_protect.c

   492	
   493	static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range)
   494	{
   495		struct kvm_mem_range cur;
   496		kvm_pte_t pte;
   497		u64 granule;
   498		s8 level;
   499		int ret;
   500		enum pkvm_page_state state;
   501	
   502		hyp_assert_lock_held(&host_mmu.lock);
   503		ret = kvm_pgtable_get_leaf(&host_mmu.pgt, addr, &pte, &level);
   504		if (ret)
   505			return ret;
   506	
   507		if (kvm_pte_valid(pte))
   508			return -EAGAIN;
   509	
   510		if (pte) {
   511			state = get_host_state(hyp_phys_to_page(addr));
   512			WARN_ON(addr_is_memory(addr) &&
 > 513				(state != PKVM_NOPAGE && state != (PKVM_NOPAGE | PKVM_MODULE_OWNED_PAGE)));
   514			return -EPERM;
   515		}
   516	
   517		for (; level <= KVM_PGTABLE_LAST_LEVEL; level++) {
   518			if (!kvm_level_supports_block_mapping(level))
   519				continue;
   520			granule = kvm_granule_size(level);
   521			cur.start = ALIGN_DOWN(addr, granule);
   522			cur.end = cur.start + granule;
   523			if (!range_included(&cur, range))
   524				continue;
   525			*range = cur;
   526			return 0;
   527		}
   528	
   529		WARN_ON(1);
   530	
   531		return -EINVAL;
   532	}
   533	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment
  2026-02-09  3:24 [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment kyle-jk.liao
  2026-02-09  9:22 ` Marc Zyngier
  2026-02-09 17:35 ` kernel test robot
@ 2026-02-09 22:44 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-02-09 22:44 UTC (permalink / raw)
  To: kyle-jk.liao, Marc Zyngier, Oliver Upton, Joey Gouly,
	Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
	Matthias Brugger, AngeloGioacchino Del Regno, Quentin Perret,
	Vincent Donnefort, linux-arm-kernel, kvmarm, linux-kernel,
	linux-mediatek
  Cc: llvm, oe-kbuild-all, wsd_upstream, rock.yeh, hungwen.chien,
	kyle-jk.liao

Hi,

kernel test robot noticed the following build errors:

[auto build test ERROR on kvmarm/next]
[also build test ERROR on linus/master v6.19 next-20260209]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/kyle-jk-liao-mediatek-com/KVM-arm64-Allow-module-owned-pages-in-host-stage-2-range-adjustment/20260209-112902
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next
patch link:    https://lore.kernel.org/r/20260209032421.1278325-1-kyle-jk.liao%40mediatek.com
patch subject: [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20260210/202602100627.0HOjIqkT-lkp@intel.com/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260210/202602100627.0HOjIqkT-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602100627.0HOjIqkT-lkp@intel.com/

All errors (new ones prefixed by >>):

>> arch/arm64/kvm/hyp/nvhe/mem_protect.c:513:53: error: use of undeclared identifier 'PKVM_MODULE_OWNED_PAGE'
     513 |                         (state != PKVM_NOPAGE && state != (PKVM_NOPAGE | PKVM_MODULE_OWNED_PAGE)));
         |                                                                          ^
   1 error generated.


vim +/PKVM_MODULE_OWNED_PAGE +513 arch/arm64/kvm/hyp/nvhe/mem_protect.c

   492	
   493	static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range)
   494	{
   495		struct kvm_mem_range cur;
   496		kvm_pte_t pte;
   497		u64 granule;
   498		s8 level;
   499		int ret;
   500		enum pkvm_page_state state;
   501	
   502		hyp_assert_lock_held(&host_mmu.lock);
   503		ret = kvm_pgtable_get_leaf(&host_mmu.pgt, addr, &pte, &level);
   504		if (ret)
   505			return ret;
   506	
   507		if (kvm_pte_valid(pte))
   508			return -EAGAIN;
   509	
   510		if (pte) {
   511			state = get_host_state(hyp_phys_to_page(addr));
   512			WARN_ON(addr_is_memory(addr) &&
 > 513				(state != PKVM_NOPAGE && state != (PKVM_NOPAGE | PKVM_MODULE_OWNED_PAGE)));
   514			return -EPERM;
   515		}
   516	
   517		for (; level <= KVM_PGTABLE_LAST_LEVEL; level++) {
   518			if (!kvm_level_supports_block_mapping(level))
   519				continue;
   520			granule = kvm_granule_size(level);
   521			cur.start = ALIGN_DOWN(addr, granule);
   522			cur.end = cur.start + granule;
   523			if (!range_included(&cur, range))
   524				continue;
   525			*range = cur;
   526			return 0;
   527		}
   528	
   529		WARN_ON(1);
   530	
   531		return -EINVAL;
   532	}
   533	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-09 22:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-09  3:24 [PATCH] KVM: arm64: Allow module-owned pages in host stage-2 range adjustment kyle-jk.liao
2026-02-09  9:22 ` Marc Zyngier
2026-02-09 17:35 ` kernel test robot
2026-02-09 22:44 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox