Re: [PATCH v7 1/3] KVM: s390: Add map/unmap ioctl and clean mappings post-guest

From: Matthew Rosato

Date: Fri May 22 2026 - 13:45:34 EST


On 5/20/26 12:04 PM, Douglas Freimuth wrote:
> s390 needs map/unmap ioctls, which map the adapter set
> indicator pages, so the pages can be accessed when interrupts are
> disabled. The mappings are cleaned up when the guest is removed.
> pin_user_pages_remote is used for both the ioctl as well
> as the pin-on-demand logic in adapter_indicators_set().
>
> Map/Unmap ioctls are fenced in order to avoid the longterm pinning
> in Secure Execution environments. In Secure Execution
> environments the path of execution available before this patch is followed.
>
> Statistical counters to count map/unmap functions for adapter indicator
> pages are added. The counters can be used to analyze
> map/unmap functions in non-Secure Execution environments and similarly
> can be used to analyze Secure Execution environments where the counters
> will not be incremented as the adapter indicator pages are not mapped.
>
> Signed-off-by: Douglas Freimuth <freimuth@xxxxxxxxxxxxx>
> ---
> arch/s390/include/asm/kvm_host.h | 5 +
> arch/s390/kvm/interrupt.c | 194 ++++++++++++++++++++++++++-----
> arch/s390/kvm/kvm-s390.c | 3 +
> arch/s390/kvm/kvm-s390.h | 2 +
> 4 files changed, 174 insertions(+), 30 deletions(-)
>
> diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
> index 8a4f4a39f7a2..0056cc9414a0 100644
> --- a/arch/s390/include/asm/kvm_host.h
> +++ b/arch/s390/include/asm/kvm_host.h
> @@ -448,6 +448,8 @@ struct kvm_vcpu_arch {
> struct kvm_vm_stat {
> struct kvm_vm_stat_generic generic;
> u64 inject_io;
> + u64 io_390_adapter_map;
> + u64 io_390_adapter_unmap;
> u64 inject_float_mchk;
> u64 inject_pfault_done;
> u64 inject_service_signal;
> @@ -479,6 +481,9 @@ struct s390_io_adapter {
> bool masked;
> bool swap;
> bool suppressible;
> + spinlock_t maps_lock;
> + struct list_head maps;
> + unsigned int nr_maps;
> };
>
> #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
> diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
> index 3bcdbbbb6891..654c37e5e898 100644
> --- a/arch/s390/kvm/interrupt.c
> +++ b/arch/s390/kvm/interrupt.c
> @@ -2429,6 +2429,10 @@ static int register_io_adapter(struct kvm_device *dev,
> if (!adapter)
> return -ENOMEM;
>
> + mutex_lock(&dev->kvm->lock);

Sashiko mentions, and I agree, that you should get this lock a bit
earlier so that you protect the reference to kvm->arch.adapters[]

With that change:

Reviewed-by: Matthew Rosato <mjrosato@xxxxxxxxxxxxx>