Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp870070pxb; Fri, 22 Apr 2022 13:04:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKb0CqB3woA/3b/rXP8Q4mz5XSCI6setTCNTRGFZdR0m/qTcVcnkjRaVH8E49Exrv5+zxv X-Received: by 2002:a17:90b:48c1:b0:1d2:7859:dfce with SMTP id li1-20020a17090b48c100b001d27859dfcemr18108775pjb.14.1650657880478; Fri, 22 Apr 2022 13:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650657880; cv=none; d=google.com; s=arc-20160816; b=kSVf1pRkzPGh6hz72t7dQ9ZU4wRYg5ZewGsZu6sWff+0nx+HtUeiG9d0egGwdjPT0O u6FJbzcDEPXrbtV9wPVZySJVoj5Yfu83AHz33Dqrgxul+J4k2kFAMmnug82wodblzbF8 l9/Eg81LyAqZJiozl1GXJG0oajyEcjp8Ka97UZhgu1nmza3Uq3KtFbXqfVMeO713WtW3 hlUPU1KMk6W7CM14mFnDOylG22vY7Z05rAxx27vfRZkIbDZ4+X59FtJa2mSvh6+hOqvh XFyCBk1+nYC/F5fRGMb1ns0ZKPxjr5zVr2qW8T6jsQxZ//dLHAgd1KIf+9JWxGRa26tP i7Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=PnOThlPMhwMAwL6AKc8O2pMHt9hNlo70ngvtJn+UxdM=; b=zC0yqCOECINSLGiEEHw2aR1R+UUZCOsGqjUyXQhHRSQef1wlaMhSu73IJ+A/ixq5gr 7Xro/XSKbe7bbAeVjy7/lONzoeBCe8n7SAQm4EVatjpMHLeqKibZzgQ7mpQHTvWniB0I aOseQlbhpXt65Y2UQlB0UmFIVHzT/z6Kq/aadxVawVIR/b/Tdd+wZShMvy1x3pzdzxq7 wmOF+QJ+JHeHCColtA+7v0oMiviuyZuGdSkZ8qot7RdgUlMBYNHg1bszUYWhDrLQqhOj 7FVDPQqe7pymFQvNfA5B4+6nmITbsQ08KBar9lzyvbKHELV4EwjNzvtXbEa9N/MyOTrm 9BhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=TZn6vbz0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l12-20020a170903120c00b00153b2d16577si9682607plh.383.2022.04.22.13.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:04:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=TZn6vbz0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BE966244141; Fri, 22 Apr 2022 12:02:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350324AbiDSJUr (ORCPT + 99 others); Tue, 19 Apr 2022 05:20:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231799AbiDSJUp (ORCPT ); Tue, 19 Apr 2022 05:20:45 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4961F26AFB; Tue, 19 Apr 2022 02:18:03 -0700 (PDT) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23J7kGM6005903; Tue, 19 Apr 2022 09:18:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=PnOThlPMhwMAwL6AKc8O2pMHt9hNlo70ngvtJn+UxdM=; b=TZn6vbz0ytUPJ3gzMhrgtxRlhTbHsPVPkzBArpEiLCn4rdvPxXjhs/qhYaQYNv5k/QJf 29xsZKZTfx8X5vxZj0kz/Hn1NLw/UkQ2Xmmou+crcDn/6Kbofg47dt0yqcRbfbD49/Nu bH8AosoSKinXNUBMVOflDBE1tCGFclbWk1CcLy2HVudm0i13LnLqznxTA2O+/UESxy37 ARFipXabzzdoEU+pbsN8zXgknIkpGEwUlmIXqGLhpFDSe3wMac20r5PBohqxbW6QaJqd Dyh58sOivCjTwURz3PlB7sWZIuOROjw/CapXdjfh5sSnya2Dmfuwybvolj5TnZ9yyNSN gQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fg7rf2ss2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Apr 2022 09:18:01 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23J8nmNZ003588; Tue, 19 Apr 2022 09:18:00 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fg7rf2sre-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Apr 2022 09:18:00 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23J9D1Qw015746; Tue, 19 Apr 2022 09:17:58 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma02fra.de.ibm.com with ESMTP id 3fgu6u1qfd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Apr 2022 09:17:58 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23J9Hton51904956 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Apr 2022 09:17:55 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 342AD42041; Tue, 19 Apr 2022 09:17:55 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2A994203F; Tue, 19 Apr 2022 09:17:53 +0000 (GMT) Received: from [9.171.88.57] (unknown [9.171.88.57]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Apr 2022 09:17:53 +0000 (GMT) Message-ID: <496acdc3-3473-bfc4-1f16-8853f364c48c@linux.ibm.com> Date: Tue, 19 Apr 2022 11:21:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH v5 12/21] KVM: s390: pci: enable host forwarding of Adapter Event Notifications Content-Language: en-US To: Matthew Rosato , linux-s390@vger.kernel.org Cc: alex.williamson@redhat.com, cohuck@redhat.com, schnelle@linux.ibm.com, farman@linux.ibm.com, borntraeger@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, gerald.schaefer@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, frankja@linux.ibm.com, david@redhat.com, imbrenda@linux.ibm.com, vneethv@linux.ibm.com, oberpar@linux.ibm.com, freude@linux.ibm.com, thuth@redhat.com, pasic@linux.ibm.com, pbonzini@redhat.com, corbet@lwn.net, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org References: <20220404174349.58530-1-mjrosato@linux.ibm.com> <20220404174349.58530-13-mjrosato@linux.ibm.com> From: Pierre Morel In-Reply-To: <20220404174349.58530-13-mjrosato@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: hlp3FJCy1bdXRlMVs6W0nx5XGdHPe5aK X-Proofpoint-ORIG-GUID: BH6k25lFg3UdMpiwHj9BEew1GTIx1zes X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-19_03,2022-04-15_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 malwarescore=0 phishscore=0 clxscore=1015 bulkscore=0 spamscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204190051 X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/4/22 19:43, Matthew Rosato wrote: > In cases where interrupts are not forwarded to the guest via firmware, > KVM is responsible for ensuring delivery. When an interrupt presents > with the forwarding bit, we must process the forwarding tables until > all interrupts are delivered. > > Signed-off-by: Matthew Rosato Reviewed-by: Pierre Morel > --- > arch/s390/include/asm/kvm_host.h | 1 + > arch/s390/include/asm/tpi.h | 13 ++++++ > arch/s390/kvm/interrupt.c | 77 +++++++++++++++++++++++++++++++- > arch/s390/kvm/kvm-s390.c | 3 +- > arch/s390/kvm/pci.h | 10 +++++ > 5 files changed, 102 insertions(+), 2 deletions(-) > > diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h > index 766028d54a3e..c1518a505060 100644 > --- a/arch/s390/include/asm/kvm_host.h > +++ b/arch/s390/include/asm/kvm_host.h > @@ -759,6 +759,7 @@ struct kvm_vm_stat { > u64 inject_pfault_done; > u64 inject_service_signal; > u64 inject_virtio; > + u64 aen_forward; > }; > > struct kvm_arch_memory_slot { > diff --git a/arch/s390/include/asm/tpi.h b/arch/s390/include/asm/tpi.h > index 1ac538b8cbf5..f76e5fdff23a 100644 > --- a/arch/s390/include/asm/tpi.h > +++ b/arch/s390/include/asm/tpi.h > @@ -19,6 +19,19 @@ struct tpi_info { > u32 :12; > } __packed __aligned(4); > > +/* I/O-Interruption Code as stored by TPI for an Adapter I/O */ > +struct tpi_adapter_info { > + u32 aism:8; > + u32 :22; > + u32 error:1; > + u32 forward:1; > + u32 reserved; > + u32 adapter_IO:1; > + u32 directed_irq:1; > + u32 isc:3; > + u32 :27; > +} __packed __aligned(4); > + > #endif /* __ASSEMBLY__ */ > > #endif /* _ASM_S390_TPI_H */ > diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c > index 57a27dfc85ea..bea0cc59eeba 100644 > --- a/arch/s390/kvm/interrupt.c > +++ b/arch/s390/kvm/interrupt.c > @@ -3313,11 +3313,86 @@ int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc) > } > EXPORT_SYMBOL_GPL(kvm_s390_gisc_unregister); > > +static void aen_host_forward(unsigned long si) > +{ > + struct kvm_s390_gisa_interrupt *gi; > + struct zpci_gaite *gaite; > + struct kvm *kvm; > + > + gaite = (struct zpci_gaite *)aift->gait + > + (si * sizeof(struct zpci_gaite)); > + if (gaite->count == 0) > + return; > + if (gaite->aisb != 0) > + set_bit_inv(gaite->aisbo, (unsigned long *)gaite->aisb); > + > + kvm = kvm_s390_pci_si_to_kvm(aift, si); > + if (!kvm) > + return; > + gi = &kvm->arch.gisa_int; > + > + if (!(gi->origin->g1.simm & AIS_MODE_MASK(gaite->gisc)) || > + !(gi->origin->g1.nimm & AIS_MODE_MASK(gaite->gisc))) { > + gisa_set_ipm_gisc(gi->origin, gaite->gisc); > + if (hrtimer_active(&gi->timer)) > + hrtimer_cancel(&gi->timer); > + hrtimer_start(&gi->timer, 0, HRTIMER_MODE_REL); > + kvm->stat.aen_forward++; > + } > +} > + > +static void aen_process_gait(u8 isc) > +{ > + bool found = false, first = true; > + union zpci_sic_iib iib = {{0}}; > + unsigned long si, flags; > + > + spin_lock_irqsave(&aift->gait_lock, flags); > + > + if (!aift->gait) { > + spin_unlock_irqrestore(&aift->gait_lock, flags); > + return; > + } > + > + for (si = 0;;) { > + /* Scan adapter summary indicator bit vector */ > + si = airq_iv_scan(aift->sbv, si, airq_iv_end(aift->sbv)); > + if (si == -1UL) { > + if (first || found) { > + /* Re-enable interrupts. */ > + zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, isc, > + &iib); > + first = found = false; > + } else { > + /* Interrupts on and all bits processed */ > + break; > + } > + found = false; > + si = 0; > + /* Scan again after re-enabling interrupts */ > + continue; > + } > + found = true; > + aen_host_forward(si); > + } > + > + spin_unlock_irqrestore(&aift->gait_lock, flags); > +} > + > static void gib_alert_irq_handler(struct airq_struct *airq, > struct tpi_info *tpi_info) > { > + struct tpi_adapter_info *info = (struct tpi_adapter_info *)tpi_info; > + > inc_irq_stat(IRQIO_GAL); > - process_gib_alert_list(); > + > + if (IS_ENABLED(CONFIG_VFIO_PCI) && (info->forward || info->error)) { > + aen_process_gait(info->isc); > + if (info->aism != 0) > + process_gib_alert_list(); > + } else { > + process_gib_alert_list(); > + } > } > > static struct airq_struct gib_alert_irq = { > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index 9db6f8080f71..a9eb8b75af93 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -64,7 +64,8 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { > STATS_DESC_COUNTER(VM, inject_float_mchk), > STATS_DESC_COUNTER(VM, inject_pfault_done), > STATS_DESC_COUNTER(VM, inject_service_signal), > - STATS_DESC_COUNTER(VM, inject_virtio) > + STATS_DESC_COUNTER(VM, inject_virtio), > + STATS_DESC_COUNTER(VM, aen_forward) > }; > > const struct kvm_stats_header kvm_vm_stats_header = { > diff --git a/arch/s390/kvm/pci.h b/arch/s390/kvm/pci.h > index a6a62db792b6..d4997e2236ef 100644 > --- a/arch/s390/kvm/pci.h > +++ b/arch/s390/kvm/pci.h > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -40,6 +41,15 @@ struct zpci_aift { > > extern struct zpci_aift *aift; > > +static inline struct kvm *kvm_s390_pci_si_to_kvm(struct zpci_aift *aift, > + unsigned long si) > +{ > + if (!IS_ENABLED(CONFIG_VFIO_PCI) || aift->kzdev == 0 || > + aift->kzdev[si] == 0) > + return 0; > + return aift->kzdev[si]->kvm; > +}; > + > int kvm_s390_pci_aen_init(u8 nisc); > void kvm_s390_pci_aen_exit(void); > > -- Pierre Morel IBM Lab Boeblingen