[PATCH v3 7/9] KVM: pass the mmu_notifier event and flags to kvm_gfn_range

Claudio Imbrenda imbrenda at linux.ibm.com
Tue Nov 24 10:19:56 PST 2026


On Thu, 12 Nov 2026 15:20:36 +0100
Carlos López <clopez at suse.de> wrote:

> Propagate the event and flags of the mmu_notifier invalidation into
> struct kvm_gfn_range, so that architecture handlers can detect a
> permission upgrade (MMU_NOTIFIER_RANGE_PERM_UPGRADE). No functional
> change.
> 
> Signed-off-by: Carlos López <clopez at suse.de>

straightforward, and also exactly what I wanted to implement myself,
thanks for doing it for me :D

Reviewed-by: Claudio Imbrenda <imbrenda at linux.ibm.com>

> ---
>  include/linux/kvm_host.h | 3 +++
>  virt/kvm/kvm_main.c      | 8 ++++++++
>  2 files changed, 11 insertions(+)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index e7fc94e2910a..1f5ce4410ddb 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -274,6 +274,9 @@ struct kvm_gfn_range {
>  	enum kvm_gfn_range_filter attr_filter;
>  	bool may_block;
>  	bool lockless;
> +	/* From the mmu_notifier invalidation, if any. */
> +	enum mmu_notifier_event event;
> +	unsigned int flags;
>  };
>  bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range);
>  bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range);
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index cf4cb586f140..c517d1deb488 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -532,6 +532,8 @@ struct kvm_mmu_notifier_range {
>  	bool flush_on_ret;
>  	bool may_block;
>  	bool lockless;
> +	enum mmu_notifier_event event;
> +	unsigned int flags;
>  };
>  
>  /*
> @@ -613,6 +615,8 @@ static __always_inline kvm_mn_ret_t kvm_handle_hva_range(struct kvm *kvm,
>  			 */
>  			gfn_range.arg = range->arg;
>  			gfn_range.may_block = range->may_block;
> +			gfn_range.event = range->event;
> +			gfn_range.flags = range->flags;
>  			/*
>  			 * HVA-based notifications aren't relevant to private
>  			 * mappings as they don't have a userspace mapping.
> @@ -738,6 +742,8 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
>  		.on_lock	= kvm_mmu_invalidate_start,
>  		.flush_on_ret	= true,
>  		.may_block	= mmu_notifier_range_blockable(range),
> +		.event		= range->event,
> +		.flags		= range->flags,
>  	};
>  
>  	trace_kvm_unmap_hva_range(range->start, range->end);
> @@ -2552,6 +2558,8 @@ static __always_inline void kvm_handle_gfn_range(struct kvm *kvm,
>  
>  	gfn_range.arg = range->arg;
>  	gfn_range.may_block = range->may_block;
> +	gfn_range.event = range->event;
> +	gfn_range.flags = range->flags;
>  
>  	/*
>  	 * If/when KVM supports more attributes beyond private .vs shared, this




More information about the linux-riscv mailing list