KVM: s390: Fall back to short-term pinning in MAP ioctl
Subsystems (4)
PATCH v3 1/1 KVM: s390: Fall back to short-term pinning in MAP ioctl
FOLL_LONGTERM pinning fails for some memory types, such as file-backed guest memory. As a result, kvm_s390_adapter_map() returns -EINVAL and irqfd adapter registration fails even though interrupt delivery could still work via the existing non-atomic path.
When FOLL_LONGTERM pinning fails, verify that the page is accessible using a short-term pin instead. If the short-term pin succeeds, unpin the page and add a map entry with pinned=false to preserve MAP/UNMAP symmetry. The non-atomic irqfd path already performs short-term pinning for interrupt delivery, so this restores the previous behavior for memory that cannot be pinned long-term.
get_map_info() is updated to return NULL for unpinned entries so that the atomic irqfd fast path falls back to the non-atomic path. kvm_s390_adapter_unmap() and kvm_s390_unmap_all_adapters() skip dirty marking and unpin for unpinned entries.
Update Documentation/virt/kvm/devices/s390_flic.rst to reflect the new MAP/UNMAP behavior.
--- Documentation/virt/kvm/devices/s390_flic.rst | 15 +++++- arch/s390/include/asm/kvm_host.h | 5 ++ arch/s390/kvm/interrupt.c | 56 +++++++++++++++----- 3 files changed, 60 insertions(+), 16 deletions(-)
Documentation/virt/kvm/devices/s390_flic.rst +13 -2
@@ -112,9 +112,20 @@ Groups: mask or unmask the adapter, as specified in mask KVM_S390_IO_ADAPTER_MAP - This is now a no-op. The mapping is purely done by the irq route. + Map an adapter indicator or summary page for long-term pinning so that + interrupt injection can be performed in atomic context. If long-term + pinning is not possible (e.g. file-backed memory), the page is verified + via a short-term pin and the ioctl returns success; interrupt injection + will use the non-atomic irqfd path with short-term pinning on each + interrupt. In Secure Execution mode this is a no-op and the ioctl + returns success. + KVM_S390_IO_ADAPTER_UNMAP - This is now a no-op. The mapping is purely done by the irq route. + Unmap a previously mapped adapter indicator or summary page and release + the long-term pin. If the page was not long-term pinned (e.g. file-backed + memory), the map entry is removed and success is returned; if no prior + map entry exists, -ENOENT is returned. In Secure Execution mode this is + a no-op and the ioctl returns success. KVM_DEV_FLIC_AISM modify the adapter-interruption-suppression mode for a given isc if the
arch/s390/include/asm/kvm_host.h +5 -0
@@ -476,6 +476,11 @@ struct s390_map_info {__u64 guest_addr;__u64 addr;struct page *page; +/* +* True if the page is long-term pinned. False if long-term pinning +* failed and this entry exists only to preserve MAP/UNMAP symmetry. +*/ +bool pinned; };struct s390_io_adapter {
arch/s390/kvm/interrupt.c +42 -14
99 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Guest-triggerable WARN_ON_ONCE in adapter_indicators_set leads to host DoS. --
--- Patch [1]: [PATCH v3] KVM: s390: Fall back to short-term pinning in MAP ioctl --- commit 07b3642c0ab06a5f6b361f58b4393eb785c7021c
Author: Jaehoon Kim <[email protected]>
KVM: s390: Fall back to short-term pinning in MAP ioctl
This commit modifies the KVM s390 MAP ioctl to support memory types that cannot be long-term pinned, such as file-backed memory. It falls back to verifying access with a short-term pin, preserving a map entry with a new pinned flag set to false. Accesses in the interrupt fast path are updated to skip these unpinned entries, causing them to fall back to the non-atomic path.
Quoted 3 lines
arch/s390/kvm/interrupt.c +0
-0
[ ... ]
arch/s390/kvm/interrupt.c static struct s390_map_info *get_map_info(struct s390_io_adapter *adapter, · line 2959
Quoted 8 lines
arch/s390/kvm/interrupt.c +3
-1@@ -2929,8 +2954,11 @@ static struct s390_map_info *get_map_info(struct s390_io_adapter *adapter,return NULL ;list_for_each_entry (map, &adapter->maps, list) { -if (map->addr == addr) +if (map->addr == addr) { +if (!map->pinned) +return NULL ;
[Severity: High]
This isn't a bug introduced by this patch, but returning NULL here forces the caller to fall back to the non-atomic path in adapter_indicators_set().
If a malicious guest or untrusted userspace configures an IRQ routing entry with an unmapped host virtual address for summary_addr, the short-term pin will fail:
arch/s390/kvm/interrupt.c:adapter_indicators_set() {
...
summary_info = get_map_info(adapter, adapter_int->summary_addr);
if (!summary_info) {
...
summary_page = pin_map_page(kvm, adapter_int->summary_addr, 0);
if (WARN_ON_ONCE(!summary_page))
return -1;
...
}Could this guest-triggerable WARN_ON_ONCE lead to a host denial of service if panic_on_warn is enabled on the host?
Should this WARN_ON_ONCE be downgraded to a normal error return so that it safely handles unmapped addresses?
Quoted 5 lines
arch/s390/kvm/interrupt.c +1
-0return map; + } }return NULL ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Christian Borntraeger
maintainerAm 24.07.26 um 15:39 schrieb Jaehoon Kim:
Quoted 17 lines
FOLL_LONGTERMpinning fails for some memory types, such as file-backed guest memory. As a result,kvm_s390_adapter_map()returns-EINVALand irqfd adapter registration fails even though interrupt delivery could still work via the existing non-atomic path.When
FOLL_LONGTERMpinning fails, verify that the page is accessible using a short-term pin instead. If the short-term pin succeeds, unpin the page and add a map entry with pinned=false to preserve MAP/UNMAP symmetry. The non-atomic irqfd path already performs short-term pinning for interrupt delivery, so this restores the previous behavior for memory that cannot be pinned long-term.
get_map_info()is updated to return NULL for unpinned entries so that the atomic irqfd fast path falls back to the non-atomic path.kvm_s390_adapter_unmap()andkvm_s390_unmap_all_adapters()skip dirty marking and unpin for unpinned entries.
Quoted 7 lines
Update
Documentation/virt/kvm/devices/s390_flic.rstto reflect the new MAP/UNMAP behavior.Fixes c9a568838086 ("KVM: s390: Add map/unmap ioctl and clean mappings post-guest")Signed-off-by Jaehoon Kim <[email protected]>Reviewed-by Douglas Freimuth <[email protected]>Reviewed-by Matthew Rosato <[email protected]>
queued for kvm/master.
Doug, Jaehoon, Matt,
can you have a look at the sashiko feedback for the pre-existing issue and work on a followup fix?
Quoted 27 lines · Christian Borntraeger
Am 24.07.26 um 15:39 schrieb Jaehoon Kim:
Quoted 17 lines
FOLL_LONGTERMpinning fails for some memory types, such as file-backed guest memory. As a result,kvm_s390_adapter_map()returns-EINVALand irqfd adapter registration fails even though interrupt delivery could still work via the existing non-atomic path.When
FOLL_LONGTERMpinning fails, verify that the page is accessible using a short-term pin instead. If the short-term pin succeeds, unpin the page and add a map entry with pinned=false to preserve MAP/UNMAP symmetry. The non-atomic irqfd path already performs short-term pinning for interrupt delivery, so this restores the previous behavior for memory that cannot be pinned long-term.
get_map_info()is updated to return NULL for unpinned entries so that the atomic irqfd fast path falls back to the non-atomic path.kvm_s390_adapter_unmap()andkvm_s390_unmap_all_adapters()skip dirty marking and unpin for unpinned entries.Quoted 8 lines
Update
Documentation/virt/kvm/devices/s390_flic.rstto reflect the new MAP/UNMAP behavior.Fixes c9a568838086 ("KVM: s390: Add map/unmap ioctl and cleanmappings post-guest")
Signed-off-by Jaehoon Kim <[email protected]>Reviewed-by Douglas Freimuth <[email protected]>Reviewed-by Matthew Rosato <[email protected]>
Quoted 8 lines
queued for kvm/master.
Doug, Jaehoon, Matt,
can you have a look at the sashiko feedback for the pre-existing issue and work on a
followup fix?
I believe this report is not nearly as extreme as it sounds.
It claims:
"If a malicious guest or untrusted userspace configures an IRQ routing entry with an unmapped host virtual address for summary_addr, the short-term pin will fail:"
However: the summary_page was previously validated when the route was setup in kvm_set_routing_entry():
uaddr_s = gpa_to_hva(kvm, ue->u.adapter.summary_addr);
...
if (kvm_is_error_hva(uaddr_s) || kvm_is_error_hva(uaddr_i))
return -EFAULT;
e->adapter.summary_addr = uaddr_s;
So we already know that the address was pre-validated before we try to use it in adapter_indicators_set(). BTW this is similar to what Janosch did fordcf96f7ad556 KVM: s390: Limit adapter indicator access to mapped page
I think we could only have some problem if we later remove a memslot that happened to have the summary page on it such that the up-front validation is no longer accurate? Can this even happen?
So: Not nearly as easy or user-controlled as 'guest provides bogus address, crashing panic_on_warn=1 host'
All that said:
The only reason this case is 'weird' is because we may have already indicated AIBV successfully (made changes to the guest) but cannot complete delivery because AISB is unreachable.
Maybe the simple answer is to downgrade this to something like pr_warn_once("Cannot indicate summary on previously-validated routing entry") so we don't lose the breadcrumbs for this highly-unlikely scenario but also don't add the potential panic in the first place? If we ever reach this situation, the guest in question is going to get bits set in AIBV but will likely never see them because it will poll first on AISB which we cannot set anymore.
That would track with
https://docs.kernel.org/process/coding-style.html#do-not-warn-lightly
even if I don't think it's easy to trigger.
Doug / Jaehoon / s390 KVM maintainers -- thoughts?
Quoted 76 lines · Matthew Rosato
Quoted 26 lines · Christian Borntraeger
Am 24.07.26 um 15:39 schrieb Jaehoon Kim:
Quoted 17 lines
FOLL_LONGTERMpinning fails for some memory types, such as file-backed guest memory. As a result,kvm_s390_adapter_map()returns-EINVALand irqfd adapter registration fails even though interrupt delivery could still work via the existing non-atomic path.When
FOLL_LONGTERMpinning fails, verify that the page is accessible using a short-term pin instead. If the short-term pin succeeds, unpin the page and add a map entry with pinned=false to preserve MAP/UNMAP symmetry. The non-atomic irqfd path already performs short-term pinning for interrupt delivery, so this restores the previous behavior for memory that cannot be pinned long-term.
get_map_info()is updated to return NULL for unpinned entries so that the atomic irqfd fast path falls back to the non-atomic path.kvm_s390_adapter_unmap()andkvm_s390_unmap_all_adapters()skip dirty marking and unpin for unpinned entries.Quoted 8 lines
Update
Documentation/virt/kvm/devices/s390_flic.rstto reflect the new MAP/UNMAP behavior.Fixes c9a568838086 ("KVM: s390: Add map/unmap ioctl and cleanmappings post-guest")
Signed-off-by Jaehoon Kim <[email protected]>Reviewed-by Douglas Freimuth <[email protected]>Reviewed-by Matthew Rosato <[email protected]>Quoted 8 lines
queued for kvm/master.
Doug, Jaehoon, Matt,
can you have a look at the sashiko feedback for the pre-existing issue and work on a
followup fix?I believe this report is not nearly as extreme as it sounds.
It claims:
"If a malicious guest or untrusted userspace configures an IRQ routing entry with an unmapped host virtual address forsummary_addr, the short-term pin will fail:"However: the
summary_pagewas previously validated when the route was setup inkvm_set_routing_entry():
uaddr_s=gpa_to_hva(kvm, ue->u.adapter.summary_addr);
...
if (kvm_is_error_hva(uaddr_s)||kvm_is_error_hva(uaddr_i))return -EFAULT;
e->adapter.summary_addr=uaddr_s;So we already know that the address was pre-validated before we try to use it in
adapter_indicators_set(). BTW this is similar to what Janosch did fordcf96f7ad556KVM: s390: Limit adapter indicator access to mapped pageI think we could only have some problem if we later remove a memslot that happened to have the summary page on it such that the up-front validation is no longer accurate? Can this even happen?
So: Not nearly as easy or user-controlled as 'guest provides bogus address, crashing panic_on_warn=1 host'
All that said:
The only reason this case is 'weird' is because we may have already indicated AIBV successfully (made changes to the guest) but cannot complete delivery because AISB is unreachable.
Maybe the simple answer is to downgrade this to something likepr_warn_once("Cannot indicate summary on previously-validated routing entry")so we don't lose the breadcrumbs for this highly-unlikely scenario but also don't add the potential panic in the first place? If we ever reach this situation, the guest in question is going to get bits set in AIBV but will likely never see them because it will poll first on AISB which we cannot set anymore.
Quoted 5 lines
That would track with
https://docs.kernel.org/process/coding-style.html#do-not-warn-lightly
even if I don't think it's easy to trigger.Doug / Jaehoon / s390 KVM maintainers -- thoughts?
Thanks for clarifying. I agree that this is different from the original Sashiko concern, since the address is already validated. pr_warn_once() sounds like a good balance to keep the breadcrumb while avoiding a potential panic.
Quoted 81 lines · JAEHOON KIM
Quoted 80 lines · Matthew Rosato
Quoted 26 lines · Christian Borntraeger
Am 24.07.26 um 15:39 schrieb Jaehoon Kim:
Quoted 17 lines
FOLL_LONGTERMpinning fails for some memory types, such as file-backed guest memory. As a result,kvm_s390_adapter_map()returns-EINVALand irqfd adapter registration fails even though interrupt delivery could still work via the existing non-atomic path.When
FOLL_LONGTERMpinning fails, verify that the page is accessible using a short-term pin instead. If the short-term pin succeeds, unpin the page and add a map entry with pinned=false to preserve MAP/UNMAP symmetry. The non-atomic irqfd path already performs short-term pinning for interrupt delivery, so this restores the previous behavior for memory that cannot be pinned long-term.
get_map_info()is updated to return NULL for unpinned entries so that the atomic irqfd fast path falls back to the non-atomic path.kvm_s390_adapter_unmap()andkvm_s390_unmap_all_adapters()skip dirty marking and unpin for unpinned entries.Quoted 8 lines
Update
Documentation/virt/kvm/devices/s390_flic.rstto reflect the new MAP/UNMAP behavior.Fixes c9a568838086 ("KVM: s390: Add map/unmap ioctl and cleanmappings post-guest")
Signed-off-by Jaehoon Kim <[email protected]>Reviewed-by Douglas Freimuth <[email protected]>Reviewed-by Matthew Rosato <[email protected]>Quoted 8 lines
queued for kvm/master.
Doug, Jaehoon, Matt,
can you have a look at the sashiko feedback for the pre-existing issue and work on a
followup fix?I believe this report is not nearly as extreme as it sounds.
It claims:
"If a malicious guest or untrusted userspace configures an IRQ routing entry with an unmapped host virtual address forsummary_addr, the short-term pin will fail:"However: the
summary_pagewas previously validated when the route was setup inkvm_set_routing_entry():
uaddr_s=gpa_to_hva(kvm, ue->u.adapter.summary_addr);
...
if (kvm_is_error_hva(uaddr_s)||kvm_is_error_hva(uaddr_i)) return-EFAULT;e->adapter.summary_addr=uaddr_s;So we already know that the address was pre-validated before we try to use it in adapter_indicators_set(). BTW this is similar to what Janosch did for
dcf96f7ad556KVM: s390: Limit adapter indicator access to mapped pageI think we could only have some problem if we later remove a memslot that happened to have the summary page on it such that the up-front validation is no longer accurate? Can this even happen?
So: Not nearly as easy or user-controlled as 'guest provides bogus address, crashing panic_on_warn=1 host'
All that said:
The only reason this case is 'weird' is because we may have already indicated AIBV successfully (made changes to the guest) but cannot complete delivery because AISB is unreachable.
Maybe the simple answer is to downgrade this to something likepr_warn_once("Cannot indicate summary on previously-validated routing entry")so we don't lose the breadcrumbs for this highly-unlikely scenario but also don't add the potential panic in the first place? If we ever reach this situation, the guest in question is going to get bits set in AIBV but will likely never see them because it will poll first on AISB which we cannot set anymore.That would track with
https://docs.kernel.org/process/coding-style.html#do-not-warn-lightly
even if I don't think it's easy to trigger.
Quoted 7 lines
Quoted 1 line
Doug / Jaehoon / s390 KVM maintainers -- thoughts?
Thanks for clarifying. I agree that this is different from the original Sashiko concern, since the address is already validated.
pr_warn_once()sounds like a good balance to keep the breadcrumb while avoiding a potential panic.
The answer depends on the environment the system is running in. If it is running in an environment with tight tolerances for good reason then we might want to panic since the error state should be rare and we have note warned lightly. Tight tolerances can be set by enabling panic on WARN_ON_ONCE.
The admin knows how tightly they want to control the system so if they dont configure panic on WARN_ON_ONCE then this is just logged as desired without panic.
If we are concerned or have observed that the usage of panic for WARN_ON_ONCE is not done very discreetly then pr_warn_once("Cannot indicate summary on previously-validated routing entry") is the answer.