From patchwork Wed Dec 19 19:17:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Mueller X-Patchwork-Id: 10737987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0F42746 for ; Wed, 19 Dec 2018 19:18:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77A5726AE3 for ; Wed, 19 Dec 2018 19:18:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B85026B41; Wed, 19 Dec 2018 19:18:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D522726AE3 for ; Wed, 19 Dec 2018 19:18:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730626AbeLSTSk (ORCPT ); Wed, 19 Dec 2018 14:18:40 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42172 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730571AbeLSTS0 (ORCPT ); Wed, 19 Dec 2018 14:18:26 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wBJIwv4X094732 for ; Wed, 19 Dec 2018 14:18:25 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2pft326m45-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 19 Dec 2018 14:18:25 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 19 Dec 2018 19:18:22 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 19 Dec 2018 19:18:19 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wBJJIH5S65077464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 19 Dec 2018 19:18:17 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B025752050; Wed, 19 Dec 2018 19:18:17 +0000 (GMT) Received: from s38lp84.lnxne.boe (unknown [9.152.108.100]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 55AC85204E; Wed, 19 Dec 2018 19:18:17 +0000 (GMT) From: Michael Mueller To: KVM Mailing List Cc: Linux-S390 Mailing List , linux-kernel@vger.kernel.org, kvm390-list@tuxmaker.boeblingen.de.ibm.com, Martin Schwidefsky , Heiko Carstens , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Halil Pasic , Pierre Morel , Michael Mueller Subject: [PATCH v5 13/15] KVM: s390: add function process_gib_alert_list() Date: Wed, 19 Dec 2018 20:17:54 +0100 X-Mailer: git-send-email 2.13.4 In-Reply-To: <20181219191756.57973-1-mimu@linux.ibm.com> References: <20181219191756.57973-1-mimu@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18121919-0020-0000-0000-000002F9F032 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18121919-0021-0000-0000-00002149FDDD Message-Id: <20181219191756.57973-14-mimu@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-19_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812190150 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This function processes the Gib Alert List (GAL). It is required to run when either a gib alert interruption has been received or a gisa that is in the alert list is cleared or dropped. The GAL is build up by millicode, when the respective ISC bit is set in the Interruption Alert Mask (IAM) and an interruption of that class is observed. Signed-off-by: Michael Mueller Reviewed-by: Pierre Morel --- arch/s390/kvm/interrupt.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 48a93f5e5333..03e7ba4f215a 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -2941,6 +2941,146 @@ int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, __u8 __user *buf, int len) return n; } +static int __try_airqs_kick(struct kvm *kvm, u8 ipm) +{ + struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; + struct kvm_vcpu *vcpu = NULL, *kick_vcpu[MAX_ISC + 1]; + int online_vcpus = atomic_read(&kvm->online_vcpus); + u8 ioint_mask, isc_mask, kick_mask = 0x00; + int vcpu_id, kicked = 0; + + /* Loop over vcpus in WAIT state. */ + for (vcpu_id = find_first_bit(fi->idle_mask, online_vcpus); + /* Until all pending ISCs have a vcpu open for airqs. */ + (~kick_mask & ipm) && vcpu_id < online_vcpus; + vcpu_id = find_next_bit(fi->idle_mask, online_vcpus, vcpu_id)) { + vcpu = kvm_get_vcpu(kvm, vcpu_id); + if (psw_ioint_disabled(vcpu)) + continue; + ioint_mask = (u8)(vcpu->arch.sie_block->gcr[6] >> 24); + for (isc_mask = 0x80; isc_mask; isc_mask >>= 1) { + /* ISC pending in IPM ? */ + if (!(ipm & isc_mask)) + continue; + /* vcpu for this ISC already found ? */ + if (kick_mask & isc_mask) + continue; + /* vcpu open for airq of this ISC ? */ + if (!(ioint_mask & isc_mask)) + continue; + /* use this vcpu (for all ISCs in ioint_mask) */ + kick_mask |= ioint_mask; + kick_vcpu[kicked++] = vcpu; + } + } + + if (vcpu && ~kick_mask & ipm) + VM_EVENT(kvm, 4, "gib alert undeliverable isc mask 0x%02x", + ~kick_mask & ipm); + + for (vcpu_id = 0; vcpu_id < kicked; vcpu_id++) + kvm_s390_vcpu_wakeup(kick_vcpu[vcpu_id]); + + return (online_vcpus != 0) ? kicked : -ENODEV; +} + +static void __floating_airqs_kick(struct kvm *kvm) +{ + struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; + int online_vcpus, kicked; + u8 ipm_t0, ipm; + + /* Get IPM and return if clean, IAM has been restored. */ + ipm = get_ipm(kvm->arch.gisa, IRQ_FLAG_IAM); + if (!ipm) + return; +retry: + ipm_t0 = ipm; + + /* Try to kick some vcpus in WAIT state. */ + kicked = __try_airqs_kick(kvm, ipm); + if (kicked < 0) + return; + + /* Get IPM and return if clean, IAM has been restored. */ + ipm = get_ipm(kvm->arch.gisa, IRQ_FLAG_IAM); + if (!ipm) + return; + + /* Start over, if new ISC bits are pending in IPM. */ + if ((ipm_t0 ^ ipm) & ~ipm_t0) + goto retry; + + /* + * Return as we just kicked at least one vcpu in WAIT state + * open for airqs. The IAM will be restored latest when one + * of them goes into WAIT or STOP state. + */ + if (kicked > 0) + return; + + /* + * No vcpu was kicked either because no vcpu was in WAIT state + * or none of the vcpus in WAIT state are open for airqs. + * Return immediately if no vcpus are in WAIT state. + * There are vcpus in RUN state. They will process the airqs + * if not closed for airqs as well. In that case the system will + * delay airqs until a vcpu decides to take airqs again. + */ + online_vcpus = atomic_read(&kvm->online_vcpus); + if (!bitmap_weight(fi->idle_mask, online_vcpus)) + return; + + /* + * None of the vcpus in WAIT state take airqs and we might + * have no running vcpus as at least one vcpu is in WAIT state + * and IPM is dirty. + */ + set_iam(kvm->arch.gisa, kvm->arch.iam); +} + +#define NULL_GISA_ADDR 0x00000000UL +#define NONE_GISA_ADDR 0x00000001UL +#define GISA_ADDR_MASK 0xfffff000UL + +static void __maybe_unused process_gib_alert_list(void) +{ + u32 final, next_alert, origin = 0UL; + struct kvm_s390_gisa *gisa; + struct kvm *kvm; + + do { + /* + * If the NONE_GISA_ADDR is still stored in the alert list + * origin, we will leave the outer loop. No further GISA has + * been added to the alert list by millicode while processing + * the current alert list. + */ + final = (origin & NONE_GISA_ADDR); + /* + * Cut off the alert list and store the NONE_GISA_ADDR in the + * alert list origin to avoid further GAL interruptions. + * A new alert list can be build up by millicode in parallel + * for guests not in the yet cut-off alert list. When in the + * final loop, store the NULL_GISA_ADDR instead. This will re- + * enable GAL interruptions on the host again. + */ + origin = xchg(&gib->alert_list_origin, + (!final) ? NONE_GISA_ADDR : NULL_GISA_ADDR); + /* Loop through the just cut-off alert list. */ + while (origin & GISA_ADDR_MASK) { + gisa = (struct kvm_s390_gisa *)(u64)origin; + next_alert = gisa->next_alert; + /* Unlink the GISA from the alert list. */ + gisa->next_alert = origin; + kvm = container_of(gisa, struct sie_page2, gisa)->kvm; + /* Kick suitable vcpus */ + __floating_airqs_kick(kvm); + origin = next_alert; + } + } while (!final); +} + static void nullify_gisa(struct kvm_s390_gisa *gisa) { memset(gisa, 0, sizeof(struct kvm_s390_gisa));