Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Matthew Rosato <mjrosato@linux.ibm.com>
To: Douglas Freimuth <freimuth@linux.ibm.com>,
	borntraeger@linux.ibm.com, imbrenda@linux.ibm.com,
	frankja@linux.ibm.com, david@kernel.org, hca@linux.ibm.com,
	gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com,
	kvm@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 1/4] KVM: s390: Add map/unmap ioctl and clean mappings post-guest
Date: Wed, 13 May 2026 12:14:56 -0400	[thread overview]
Message-ID: <5df7c185-67eb-4125-a990-62dcda992ad9@linux.ibm.com> (raw)
In-Reply-To: <20260511161451.209464-2-freimuth@linux.ibm.com>

On 5/11/26 12:14 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.
> 
> 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.

I think it's worth mentioning that this patch also converts to
pin_user_pages_remote for both the ioctl as well as the pin-on-demand
logic in adapter_indicators_set()

[...]

> +
> +void kvm_s390_unmap_all_adapters(struct kvm *kvm)
> +{
> +	struct s390_map_info *map, *tmp;
> +	unsigned long flags;
> +	int i, idx;

Sashiko makes a valid point here:
the ioctl is doing unmaps with the kvm->lock held.
the kvm_s390_unmap_all_adapters_pv() path is also.
But the registration of adapters is not, nor is the direct call to 
kvm_s390_unmap_all_adapter() from kvm_s390_destroy_adapters(), the
latter of which is not too big of a deal since vcpus are already gone.

The goal here is to protect the contents of kvm->arch.adapters[] from
changing while you're running the list here.  

Can you look at acquiring the kvm->lock over register_io_adapter() as
part of this patch?  AFAICT it should be fine to do so.  There are
other flic operations like kvm_s390_clear_float_irqs() which do so.

> +
> +	for (i = 0; i < MAX_S390_IO_ADAPTERS; i++) {
> +		struct s390_io_adapter *adapter = kvm->arch.adapters[i];
> +		LIST_HEAD(local_list);
> +
> +		if (!adapter)
> +			continue;
> +
> +		raw_spin_lock_irqsave(&adapter->maps_lock, flags);
> +		list_splice_init(&adapter->maps, &local_list);
> +		adapter->nr_maps = 0;
> +		raw_spin_unlock_irqrestore(&adapter->maps_lock, flags);
> +
> +		list_for_each_entry_safe(map, tmp, &local_list, list) {
> +			list_del(&map->list);
> +			idx = srcu_read_lock(&kvm->srcu);
> +			mark_page_dirty(kvm, map->guest_addr >> PAGE_SHIFT);
> +			set_page_dirty_lock(map->page);
> +			srcu_read_unlock(&kvm->srcu, idx);
> +			unpin_user_page(map->page);
> +			kfree(map);
> +		}
> +	}
> +}

[...]

> +static void kvm_s390_unmap_all_adapters_pv(struct kvm *kvm)
> +{
> +	kvm_s390_unmap_all_adapters(kvm);
> +}

Just get rid of kvm_s390_unmap_all_adapters_pv() and call
kvm_s390_unmap_all_adapters() directly in kvm_s390_handle_pv()?

Otherwise this patch looks good to me.

Thanks,
Matt

  reply	other threads:[~2026-05-13 16:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 16:14 [PATCH v6 0/4] KVM: s390: Introducing kvm_arch_set_irq_inatomic Fast Inject Douglas Freimuth
2026-05-11 16:14 ` [PATCH v6 1/4] KVM: s390: Add map/unmap ioctl and clean mappings post-guest Douglas Freimuth
2026-05-13 16:14   ` Matthew Rosato [this message]
2026-05-11 16:14 ` [PATCH v6 2/4] KVM: s390: Enable adapter_indicators_set to use mapped pages Douglas Freimuth
2026-05-13 16:16   ` Matthew Rosato
2026-05-11 16:14 ` [PATCH v6 3/4] KVM: S390: Change fi->lock, li->lock to raw Douglas Freimuth
2026-05-11 16:14 ` [PATCH v6 4/4] KVM: s390: Introducing kvm_arch_set_irq_inatomic fast inject Douglas Freimuth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5df7c185-67eb-4125-a990-62dcda992ad9@linux.ibm.com \
    --to=mjrosato@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@kernel.org \
    --cc=frankja@linux.ibm.com \
    --cc=freimuth@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox