KVM: s390: Introducing kvm_arch_set_irq_inatomic Fast Inject
v7 cover KVM: s390: Introducing kvm_arch_set_irq_inatomic Fast Inject
s390 needs this series of three patches in order to enable a non-blocking path for irqfd injection on s390 via kvm_arch_set_irq_inatomic(). Before these changes, kvm_arch_set_irq_inatomic() would just return -EWOULDBLOCK and place all interrupts on the global work queue, which must subsequently be processed by a different thread. This series of patches implements an s390 version of inatomic and is relevant to virtio-blk and virtio-net and was tested against virtio-pci and virtio-ccw.
The inatomic fast path cannot lose control since it is running with interrupts disabled. This meant making the following changes that exist on the slow path today. First, the adapter_indicators page needs to be mapped since it is accessed with interrupts disabled, so we added map/unmap functions. Second, access to shared resources between the fast and slow paths needed to be changed from mutex and semaphores to spin_lock's. Finally, the memory allocation on the slow path utilizes GFP_KERNEL_ACCOUNT but we had to implement the fast path with GFP_ATOMIC allocation. Each of these enhancements were required to prevent blocking on the fast inject path.
s390 doesn't support a PREEMPT_RT kernel and this patch doesn't either. Given this fact, we are not using raw_spin_lock instead we are using regular spin_lock.
Statistical counters have been added to enable analysis of irq injection on the fast path and slow path including io_390_inatomic, io_flic_inject_airq, io_set_adapter_int and io_390_inatomic_adapter_masked. And counters have been added to analyze map/unmap of the adapter_indicator
pages in non-Secure Execution environments and to track fencing of Fast Inject in Secure Execution environments. In order to take advantage of this kernel series with virtio-pci, a QEMU that includes the 's390x/pci: set kvm_msi_via_irqfd_allowed' fix is needed. Additionally, the guest xml needs a thread pool and threads explicitly assigned per disk device using the common way of defining threads for disks.
Patch 1 enables map/unmap of adapter indicator pages but for Secure Execution environments it avoids the long term mapping.
v6->v7: Drop all raw_spin_lock in previous patch and make them spin_locks. v6->v7: Hold the kvm->lock in register_io_adapter.v6->v7: Call kvm_s390_unmap_all_adapters() directly in kvm_s390_handle_pv. v6->v7: Simplify unpin logic in adapter_indicators_set. v6->v7: Make the caller of kvm_s390_inject_vm() kfree(inti)
Douglas Freimuth (3):
KVM: s390: Add map/unmap ioctl and clean mappings post-guest
KVM: s390: Enable adapter_indicators_set to use mapped pages
KVM: s390: Introducing kvm_arch_set_irq_inatomic fast inject
arch/s390/include/asm/kvm_host.h | 11 +- arch/s390/kvm/interrupt.c | 444 ++++++++++++++++++++++++++----- arch/s390/kvm/kvm-s390.c | 30 ++- arch/s390/kvm/kvm-s390.h | 5 +- 4 files changed, 418 insertions(+), 72 deletions(-)
Signature · 1 line
2.54.0
PATCH v7 1/3 KVM: s390: Add map/unmap ioctl and clean mappings post-guest
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.
--- 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(-)
arch/s390/include/asm/kvm_host.h +5 -0
@@ -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)
arch/s390/kvm/interrupt.c +164 -30
246 lines not on this page · raw message
arch/s390/kvm/kvm-s390.c +3 -0
@@ -68,6 +68,8 @@const struct kvm_stats_desc kvm_vm_stats_desc[] = {KVM_GENERIC_VM_STATS (),STATS_DESC_COUNTER (VM , inject_io), +STATS_DESC_COUNTER (VM , io_390_adapter_map), +STATS_DESC_COUNTER (VM , io_390_adapter_unmap),STATS_DESC_COUNTER (VM , inject_float_mchk),STATS_DESC_COUNTER (VM , inject_pfault_done),STATS_DESC_COUNTER (VM , inject_service_signal),
@@ -2513,6 +2515,7 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)if (kvm_s390_pv_is_protected (kvm))break ; +kvm_s390_unmap_all_adapters (kvm);mmap_write_lock (kvm->mm);/* * Disable creation of new THPs. Existing THPs can stay, they
arch/s390/kvm/kvm-s390.h +2 -0
@@ -560,6 +560,8 @@ void kvm_s390_gisa_disable(struct kvm *kvm);void kvm_s390_gisa_enable (struct kvm *kvm);int __init kvm_s390_gib_init (u8 nisc);void kvm_s390_gib_destroy (void ); +void kvm_s390_unmap_all_adapters (struct kvm *kvm); +/* implemented in guestdbg.c */ void kvm_s390_backup_guest_per_regs (struct kvm_vcpu *vcpu);
Signature · 1 line
2.54.0
Re: [PATCH v7 1/3] KVM: s390: Add map/unmap ioctl and clean mappings post-guest
Quoted 52 lines · Douglas Freimuth
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_remoteis used for both the ioctl as well as the pin-on-demand logic inadapter_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 <[email protected]>--- 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(-)arch/s390/include/asm/kvm_host.h +5
-0@@ -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)arch/s390/kvm/interrupt.c +0
-0
arch/s390/kvm/interrupt.c static int register_io_adapter(struct kvm_device *dev, · line 2432
Quoted 4 lines
arch/s390/kvm/interrupt.c +1
-0@@ -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:
PATCH v7 2/3 KVM: s390: Enable adapter_indicators_set to use mapped pages
In reply to Douglas FreimuthThe s390 adapter_indicators_set function can now be optimized to use long-term mapped pages when available so that work can be processed, on a fast path when interrupts are disabled.
If adapter indicator pages are not mapped then local mapping is done on a slow path as it is prior to this patch. For example, Secure Execution environments will take the local mapping path as it does prior to this patch.
--- arch/s390/kvm/interrupt.c | 89 ++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 24 deletions(-)
arch/s390/kvm/interrupt.c +65 -24
@@ -2885,41 +2885,82 @@ static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap)return swap ? (bit ^ (BITS_PER_LONG -1 )) : bit; } +static struct s390_map_info *get_map_info (struct s390_io_adapter *adapter, +u64 addr) +{ +struct s390_map_info *map; + +if (!adapter) +return NULL ; + +list_for_each_entry (map, &adapter->maps, list) { +if (map->addr == addr) +return map; + } +return NULL ; +} +static int adapter_indicators_set (struct kvm *kvm,struct s390_io_adapter *adapter,struct kvm_s390_adapter_int *adapter_int) {unsigned long bit;int summary_set, idx; -struct page *ind_page, *summary_page; +struct s390_map_info *ind_info, *summary_info;void *map; +struct page *ind_page, *summary_page; +unsigned long flags; - ind_page =pin_map_page (kvm, adapter_int->ind_addr,0 ); -if (!ind_page) -return -1 ; - summary_page =pin_map_page (kvm, adapter_int->summary_addr,0 ); -if (!summary_page) { + ind_page =NULL ; + +spin_lock_irqsave (&adapter->maps_lock, flags); + ind_info =get_map_info (adapter, adapter_int->ind_addr); +if (!ind_info) { +spin_unlock_irqrestore (&adapter->maps_lock, flags); + ind_page =pin_map_page (kvm, adapter_int->ind_addr,0 ); +if (!ind_page) +return -1 ; + idx =srcu_read_lock (&kvm->srcu); + map =page_address (ind_page); + bit =get_ind_bit (adapter_int->ind_addr, + adapter_int->ind_offset, adapter->swap); +set_bit (bit, map); +mark_page_dirty (kvm, adapter_int->ind_gaddr >>PAGE_SHIFT ); +set_page_dirty_lock (ind_page); +srcu_read_unlock (&kvm->srcu, idx);unpin_user_page (ind_page); -return -1 ; + }else { + map =page_address (ind_info->page); + bit =get_ind_bit (ind_info->addr, adapter_int->ind_offset, adapter->swap); +set_bit (bit, map); +spin_unlock_irqrestore (&adapter->maps_lock, flags); + } +spin_lock_irqsave (&adapter->maps_lock, flags); + summary_info =get_map_info (adapter, adapter_int->summary_addr); +if (!summary_info) { +spin_unlock_irqrestore (&adapter->maps_lock, flags); + summary_page =pin_map_page (kvm, adapter_int->summary_addr,0 ); +if (!summary_page) { +WARN_ON_ONCE (ind_page || ind_info); +return -1 ; + } + idx =srcu_read_lock (&kvm->srcu); + map =page_address (summary_page); + bit =get_ind_bit (adapter_int->summary_addr, + adapter_int->summary_offset, adapter->swap); + summary_set =test_and_set_bit (bit, map); +mark_page_dirty (kvm, adapter_int->summary_gaddr >>PAGE_SHIFT ); +set_page_dirty_lock (summary_page); +srcu_read_unlock (&kvm->srcu, idx); +unpin_user_page (summary_page); + }else { + map =page_address (summary_info->page); + bit =get_ind_bit (summary_info->addr, adapter_int->summary_offset, + adapter->swap); + summary_set =test_and_set_bit (bit, map); +spin_unlock_irqrestore (&adapter->maps_lock, flags); } - idx =srcu_read_lock (&kvm->srcu); - map =page_address (ind_page); - bit =get_ind_bit (adapter_int->ind_addr, - adapter_int->ind_offset, adapter->swap); -set_bit (bit, map); -mark_page_dirty (kvm, adapter_int->ind_gaddr >>PAGE_SHIFT ); -set_page_dirty_lock (ind_page); - map =page_address (summary_page); - bit =get_ind_bit (adapter_int->summary_addr, - adapter_int->summary_offset, adapter->swap); - summary_set =test_and_set_bit (bit, map); -mark_page_dirty (kvm, adapter_int->summary_gaddr >>PAGE_SHIFT ); -set_page_dirty_lock (summary_page); -srcu_read_unlock (&kvm->srcu, idx); - -unpin_user_page (ind_page); -unpin_user_page (summary_page);return summary_set ?0 :1 ; }
Signature · 1 line
2.54.0
Re: [PATCH v7 2/3] KVM: s390: Enable adapter_indicators_set to use mapped pages
Quoted 3 lines · Douglas Freimuth
The s390
adapter_indicators_setfunction can now be optimized to use long-term mapped pages when available so that work can be processed, on a fast path when interrupts are disabled.
nit: drop the comma
Quoted 72 lines
If adapter indicator pages are not mapped then local mapping is done on a slow path as it is prior to this patch. For example, Secure Execution environments will take the local mapping path as it does prior to this patch.
Signed-off-by Douglas Freimuth <[email protected]>--- arch/s390/kvm/interrupt.c | 89 ++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 24 deletions(-)arch/s390/kvm/interrupt.c +38
-7@@ -2885,41 +2885,82 @@ static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap)return swap ? (bit ^ (BITS_PER_LONG -1 )) : bit; } +static struct s390_map_info *get_map_info (struct s390_io_adapter *adapter, +u64 addr) +{ +struct s390_map_info *map; + +if (!adapter) +return NULL ; + +list_for_each_entry (map, &adapter->maps, list) { +if (map->addr == addr) +return map; + } +return NULL ; +} +static int adapter_indicators_set (struct kvm *kvm,struct s390_io_adapter *adapter,struct kvm_s390_adapter_int *adapter_int) {unsigned long bit;int summary_set, idx; -struct page *ind_page, *summary_page; +struct s390_map_info *ind_info, *summary_info;void *map; +struct page *ind_page, *summary_page; +unsigned long flags; - ind_page =pin_map_page (kvm, adapter_int->ind_addr,0 ); -if (!ind_page) -return -1 ; - summary_page =pin_map_page (kvm, adapter_int->summary_addr,0 ); -if (!summary_page) { + ind_page =NULL ; + +spin_lock_irqsave (&adapter->maps_lock, flags); + ind_info =get_map_info (adapter, adapter_int->ind_addr); +if (!ind_info) { +spin_unlock_irqrestore (&adapter->maps_lock, flags); + ind_page =pin_map_page (kvm, adapter_int->ind_addr,0 ); +if (!ind_page) +return -1 ; + idx =srcu_read_lock (&kvm->srcu); + map =page_address (ind_page); + bit =get_ind_bit (adapter_int->ind_addr, + adapter_int->ind_offset, adapter->swap); +set_bit (bit, map); +mark_page_dirty (kvm, adapter_int->ind_gaddr >>PAGE_SHIFT ); +set_page_dirty_lock (ind_page); +srcu_read_unlock (&kvm->srcu, idx);unpin_user_page (ind_page); -return -1 ; + }else { + map =page_address (ind_info->page); + bit =get_ind_bit (ind_info->addr, adapter_int->ind_offset, adapter->swap);
arch/s390/kvm/interrupt.c static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) · line 2944
Quoted 10 lines
arch/s390/kvm/interrupt.c +10
-0+set_bit (bit, map); +spin_unlock_irqrestore (&adapter->maps_lock, flags); + } +spin_lock_irqsave (&adapter->maps_lock, flags); + summary_info =get_map_info (adapter, adapter_int->summary_addr); +if (!summary_info) { +spin_unlock_irqrestore (&adapter->maps_lock, flags); + summary_page =pin_map_page (kvm, adapter_int->summary_addr,0 ); +if (!summary_page) { +WARN_ON_ONCE (ind_page || ind_info);
I think this was my suggestion on v6, but this is basically WARN_ON_ONCE(true). We can't reach this code unless we got the indicator page somehow.
Really then it should be:
if (WARN_ON_ONCE(!summary_page))
return -1;
And we catch the first instance of setting indicator bits but failing to set the summary bit.
With that:
PATCH v7 3/3 KVM: s390: Introducing kvm_arch_set_irq_inatomic fast inject
In reply to Douglas Freimuths390 needs a fast path for irq injection, and along those lines we introduce kvm_arch_set_irq_inatomic. Instead of placing all interrupts on the global work queue as it does today, this patch provides a fast path for irq injection.
The inatomic fast path cannot lose control since it is running with interrupts disabled. This meant making the following changes that exist on the slow path today. First, the adapter_indicators page needs to be mapped since it is accessed with interrupts disabled, so we added map/unmap functions. Second, access to shared resources between the fast and slow paths needed to be changed from mutex and semaphores to spin_lock's. Finally, the memory allocation on the slow path utilizes GFP_KERNEL_ACCOUNT but we had to implement the fast path with GFP_ATOMIC allocation. Each of these enhancements were required to prevent blocking on the fast inject path.
Fencing of Fast Inject in Secure Execution environments is enabled in the patch series by not mapping adapter indicator pages. In Secure Execution environments the path of execution available before this patch is followed.
Statistical counters have been added to enable analysis of irq injection on the fast path and slow path including io_390_inatomic, io_flic_inject_airq, io_set_adapter_int and io_390_inatomic_adapter_masked.
--- arch/s390/include/asm/kvm_host.h | 6 +- arch/s390/kvm/interrupt.c | 181 +++++++++++++++++++++++++++---- arch/s390/kvm/kvm-s390.c | 27 ++++- arch/s390/kvm/kvm-s390.h | 3 +- 4 files changed, 189 insertions(+), 28 deletions(-)
arch/s390/include/asm/kvm_host.h +5 -1
@@ -359,7 +359,7 @@ struct kvm_s390_float_interrupt {struct kvm_s390_mchk_info mchk;struct kvm_s390_ext_info srv_signal;int last_sleep_cpu; -struct mutex ais_lock; +spinlock_t ais_lock;u8 simm;u8 nimm; };
@@ -450,6 +450,10 @@ struct kvm_vm_stat {u64 inject_io;u64 io_390_adapter_map;u64 io_390_adapter_unmap; +u64 io_390_inatomic; +u64 io_flic_inject_airq; +u64 io_set_adapter_int; +u64 io_390_inatomic_adapter_masked;u64 inject_float_mchk;u64 inject_pfault_done;u64 inject_service_signal;
arch/s390/kvm/interrupt.c +159 -22
293 lines not on this page · raw message
arch/s390/kvm/kvm-s390.c +23 -4
@@ -70,6 +70,10 @@ const struct kvm_stats_desc kvm_vm_stats_desc[] = {STATS_DESC_COUNTER (VM , inject_io),STATS_DESC_COUNTER (VM , io_390_adapter_map),STATS_DESC_COUNTER (VM , io_390_adapter_unmap), +STATS_DESC_COUNTER (VM , io_390_inatomic), +STATS_DESC_COUNTER (VM , io_flic_inject_airq), +STATS_DESC_COUNTER (VM , io_set_adapter_int), +STATS_DESC_COUNTER (VM , io_390_inatomic_adapter_masked),STATS_DESC_COUNTER (VM , inject_float_mchk),STATS_DESC_COUNTER (VM , inject_pfault_done), STATS_DESC_COUNTER(VM, inject_service_signal),
@@ -2851,6 +2855,7 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)void __user *argp = (void __user *)arg;struct kvm_device_attr attr;int r; +struct kvm_s390_interrupt_info *inti;switch (ioctl) {case KVM_S390_INTERRUPT : {
@@ -2859,7 +2864,12 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) r = -EFAULT ;if (copy_from_user (&s390int, argp,sizeof (s390int)))break ; - r =kvm_s390_inject_vm (kvm, &s390int); + inti =kzalloc_obj (*inti,GFP_KERNEL_ACCOUNT ); +if (!inti) +return -ENOMEM ; + r =kvm_s390_inject_vm (kvm, &s390int, inti); +if (r) +kfree (inti);break ; }case KVM_CREATE_IRQCHIP : {
@@ -3257,7 +3267,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)mutex_unlock (&kvm->lock); } -mutex_init (&kvm->arch.float_int.ais_lock); +spin_lock_init (&kvm->arch.float_int.ais_lock);spin_lock_init (&kvm->arch.float_int.lock);for (i =0 ; i <FIRQ_LIST_COUNT ; i++)INIT_LIST_HEAD (&kvm->arch.float_int.lists[i]);
@@ -4379,19 +4389,28 @@ int kvm_s390_try_set_tod_clock(struct kvm *kvm, const struct kvm_s390_vm_tod_clo }static void __kvm_inject_pfault_token (struct kvm_vcpu *vcpu,bool start_token, -unsigned long token) +unsigned long token) {struct kvm_s390_interrupt inti;struct kvm_s390_irq irq; +struct kvm_s390_interrupt_info *inti_mem =NULL ; +int ret =0 ;if (start_token) { irq.u.ext.ext_params2 = token; irq.type =KVM_S390_INT_PFAULT_INIT ;WARN_ON_ONCE (kvm_s390_inject_vcpu (vcpu, &irq)); }else { + inti_mem =kzalloc_obj (*inti_mem,GFP_KERNEL_ACCOUNT ); +if (WARN_ON_ONCE (!inti_mem)) +return ; + inti.type =KVM_S390_INT_PFAULT_DONE ; inti.parm64 = token; -WARN_ON_ONCE (kvm_s390_inject_vm (vcpu->kvm, &inti)); + ret =kvm_s390_inject_vm (vcpu->kvm, &inti, inti_mem); +if (ret) +kfree (inti_mem); +WARN_ON_ONCE (ret); } }
arch/s390/kvm/kvm-s390.h +2 -1
@@ -376,7 +376,8 @@ int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);void kvm_s390_clear_local_irqs (struct kvm_vcpu *vcpu);void kvm_s390_clear_float_irqs (struct kvm *kvm);int __must_check kvm_s390_inject_vm (struct kvm *kvm, -struct kvm_s390_interrupt *s390int); +struct kvm_s390_interrupt *s390int, +struct kvm_s390_interrupt_info *inti);int __must_check kvm_s390_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq); static inline int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu,
Signature · 1 line
2.54.0
Re: [PATCH v7 3/3] KVM: s390: Introducing kvm_arch_set_irq_inatomic fast inject
Quoted 25 lines · Douglas Freimuth
s390 needs a fast path for irq injection, and along those lines we introduce
kvm_arch_set_irq_inatomic. Instead of placing all interrupts on the global work queue as it does today, this patch provides a fast path for irq injection.The inatomic fast path cannot lose control since it is running with interrupts disabled. This meant making the following changes that exist on the slow path today. First, the
adapter_indicatorspage needs to be mapped since it is accessed with interrupts disabled, so we added map/unmap functions. Second, access to shared resources between the fast and slow paths needed to be changed from mutex and semaphores to spin_lock's. Finally, the memory allocation on the slow path utilizesGFP_KERNEL_ACCOUNTbut we had to implement the fast path withGFP_ATOMICallocation. Each of these enhancements were required to prevent blocking on the fast inject path.Fencing of Fast Inject in Secure Execution environments is enabled in the patch series by not mapping adapter indicator pages. In Secure Execution environments the path of execution available before this patch is followed.
Statistical counters have been added to enable analysis of irq injection on the fast path and slow path including
io_390_inatomic,io_flic_inject_airq,io_set_adapter_intandio_390_inatomic_adapter_masked.Signed-off-by Douglas Freimuth <[email protected]>
[...]
Quoted 15 lines
int kvm_s390_inject_vm(struct kvm *kvm,
arch/s390/kvm/interrupt.c +1
-6- struct kvm_s390_interrupt *s390int) + struct kvm_s390_interrupt *s390int, struct kvm_s390_interrupt_info *inti) { -struct kvm_s390_interrupt_info *inti; int rc; - inti =kzalloc_obj (*inti,GFP_KERNEL_ACCOUNT ); -if (!inti) -return -ENOMEM ; - inti->type = s390int->type;switch (inti->type) {case KVM_S390_INT_VIRTIO :
arch/s390/kvm/interrupt.c int kvm_s390_inject_vm(struct kvm *kvm, · line 2014
Quoted 5 lines
arch/s390/kvm/interrupt.c +0
-2@@ -2010,8 +2005,7 @@ int kvm_s390_inject_vm(struct kvm *kvm, 2); rc =__inject_vm (kvm, inti); -if (rc) -kfree (inti);
You removed this kfree, but there's still one in the default case above. Remove that as well so the caller is always responsible for both allocating and freeing the kvm_s390_interrupt_info.
This appears to match the Sashiko complaint about a double-free, but you want to fix it here -- not at the individual caller(s).
Quoted 4 lines
arch/s390/kvm/interrupt.c +1
-0+return rc; }
[...]
Quoted 12 lines
arch/s390/kvm/interrupt.c +12
-0+ +/* +* kvm_arch_set_irq_inatomic: fast-path for irqfd injection +*/ +int kvm_arch_set_irq_inatomic (struct kvm_kernel_irq_routing_entry *e, +struct kvm *kvm,int irq_source_id,int level, +bool line_status) +{ +int ret, setbit; +struct s390_io_adapter *adapter; +struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; +struct kvm_s390_interrupt_info *inti;
arch/s390/kvm/interrupt.c int __init kvm_s390_gib_init(u8 nisc) · line 3713
Quoted 10 lines
arch/s390/kvm/interrupt.c +10
-0+struct kvm_s390_interrupt s390int = { + .type =KVM_S390_INT_IO (1 ,0 ,0 ,0 ), + .parm =0 , + }; + + kvm->stat.io_390_inatomic++; + +/* We're only interested in the 0->1 transition. */ +if (!level) +return -EWOULDBLOCK ;
Sashiko makes a good point here; if we -EWOULDBLOCK, it's just going to fall back to the irqfd_inject path which will drive set_adapter_int() which will always return 0 due to the same !level check.
So while functionally it's not harmful, it would be an optimization to simply return 0 here. Please test it out.
arch/s390/kvm/interrupt.c int __init kvm_s390_gib_init(u8 nisc) · line 3726
Quoted 13 lines
arch/s390/kvm/interrupt.c +13
-0+if (e->type !=KVM_IRQ_ROUTING_S390_ADAPTER ) +return -EWOULDBLOCK ; + + adapter =get_io_adapter (kvm, e->adapter.adapter_id); +if (!adapter) +return -EWOULDBLOCK ; + + s390int.parm64 =isc_to_int_word (adapter->isc); + setbit =1 ; + ret =adapter_indicators_set_fast (kvm, adapter, &e->adapter, setbit); +if (ret <0 ) +return -EWOULDBLOCK ; +if (!ret || adapter->masked) {
Sashiko made me double-check your work here. AFAICT this is correct:
Let's compare it to set_adapter_int(), where we inject only if
if ((ret > 0) && !adapter->masked) {
ret = kvm_s390_inject_airq(kvm, adapter);Here we are trying to decide whether to NOT inject, so invert it:
if (ret <= 0 || adapter->masked)
and you already checked ret < 0 above, so:
if (ret == 0 || adapter->masked)
or
if (!ret || adapter->masked)
I guess it's more a question of whether you want to consider masked interrupts (adapter->masked) as a different counter than coalesced interrupts (!ret). I'm not sure we care that much to track this distinction, but I think the sum counter is still valuable; it's how many times times we delivered interrupts in atomic without actually injecting the adapter interrupt. (Actually, not quite true, see below)
All of this is a long-winded way of saying 'maybe you should rename the counter to more-accurately describe what you're counting'. And don't forget to update the commit message.
arch/s390/kvm/interrupt.c int __init kvm_s390_gib_init(u8 nisc) · line 3738
Quoted 12 lines
arch/s390/kvm/interrupt.c +12
-0+ kvm->stat.io_390_inatomic_adapter_masked++; +return 0 ; + } + + inti =kzalloc_obj (*inti,GFP_ATOMIC ); +if (!inti) { + setbit =0 ; +adapter_indicators_set_fast (kvm, adapter, &e->adapter, setbit); +return -EWOULDBLOCK ; + } + +if (!test_kvm_facility (kvm,72 ) || !adapter->suppressible) {
Please look into the sashiko reports re: irqsave and the fi->lock.
Quoted 6 lines
arch/s390/kvm/interrupt.c +6
-0+ ret =kvm_s390_inject_vm (kvm, &s390int, inti); +if (ret ==0 ) { +return ret; + }else { + setbit =0 ; +adapter_indicators_set_fast (kvm, adapter, &e->adapter, setbit);
arch/s390/kvm/interrupt.c int __init kvm_s390_gib_init(u8 nisc) · line 3754
Quoted 10 lines
arch/s390/kvm/interrupt.c +10
-0+kfree (inti); +return -EWOULDBLOCK ; + } + } + +spin_lock (&fi->ais_lock); +if (fi->nimm &AIS_MODE_MASK (adapter->isc)) { +trace_kvm_s390_airq_suppressed (adapter->id, adapter->isc); +spin_unlock (&fi->ais_lock); +kfree (inti);
Actually, about that comment above re: io_390_inatomic_adapter_masked.. Here is another place where we set the indicators without injecting an adapter interrupt. Now due to adapter interrupt suppression.
If you want that counter to include all 3 (coalesced, masked, and suppressed) then you should increment it here as well after you rename it.
Quoted 2 lines
(quoted diff) +2
-0+ return 0; + }