Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6188334yba; Thu, 11 Apr 2019 14:04:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzoxbMYgW95G9fK9wAbUx58DWe2slVwcTb9g/ubBJq3c6qqlR2To3HmdfG9RYQvW67Emhlq X-Received: by 2002:a63:5405:: with SMTP id i5mr48734858pgb.212.1555016684240; Thu, 11 Apr 2019 14:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555016684; cv=none; d=google.com; s=arc-20160816; b=DiVntOyLLIDoMKN1czdlHDvX5CXZgom78bdOwZjeIpeIRsWf/DY1orhQcvwN38w5JG WdBSZO71W5pJNvLWve8bnExZ8fu+We/GW7b83bNfGWQtaWXJ/iWgB0hEgqYxy3HGlgPX GSZiSMLcDolwpCU7DymeL2g3hZvi8oMo3+WR9fQwMD0SrRA6InWYL7gbdCYtYsNA45Rr osKmLaL4gYatGvO8aoiESiOV66lJTSdSsLb0ERPBiSa/JuxNI5E+DHBa1B+K1lX3HduD LRHFiQS88lKrs+Re+0hkm+8u3gSSGBL3vm+lwp3PzGcG21+Twzhdvb7HYBXoedbvjOhk 9SCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from; bh=A95zGXfR52Wor2pcTvVaAkSeZOU8dLl7jK/2HMXwGfs=; b=FZbEtBsaYSnBiNVogBkyCwxN9yOYwPc83B340jJ8FJL0opr4xNDaX38TNmopnQKA7z WGxyAm5iH1oKd8rShpgNJE7icye6GJmzLMswzl+MrZ4SsW9p+Z88deRwNr4tBiFIIxvy qSFsSj/v5BYH7IZKS50aS4xChUZXIKG+oCF+pmzL4JXxS+fJcQu9IVp7dmnBL+clOkyB 4N07YBo8ZUx9RgDIHmdfdnA5KytyFihIUq/XUuWERFTsU82enf1O4+NNzf52MIlkj5cA w5HLUEUcUEjkcZdbp49IKpJzYOFtNEsWBWndULjwjgKYhoepGnLIzliBIqR2/LeKtSlC YSYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j5si19751060plk.328.2019.04.11.14.04.27; Thu, 11 Apr 2019 14:04:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726968AbfDKVDq (ORCPT + 99 others); Thu, 11 Apr 2019 17:03:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53030 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726865AbfDKVDn (ORCPT ); Thu, 11 Apr 2019 17:03:43 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3BKnphc095346 for ; Thu, 11 Apr 2019 17:03:42 -0400 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rtc9v2639-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 Apr 2019 17:03:42 -0400 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 11 Apr 2019 22:03:41 +0100 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e14.ny.us.ibm.com (146.89.104.201) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 11 Apr 2019 22:03:38 +0100 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3BL3Ye130212180 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Apr 2019 21:03:34 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6BEEAE05F; Thu, 11 Apr 2019 21:03:34 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 76E10AE060; Thu, 11 Apr 2019 21:03:34 +0000 (GMT) Received: from akrowiak-ThinkPad-P50.endicott.ibm.com (unknown [9.60.75.235]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTPS; Thu, 11 Apr 2019 21:03:34 +0000 (GMT) From: Tony Krowiak To: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: freude@linux.ibm.com, borntraeger@de.ibm.com, cohuck@redhat.com, frankja@linux.ibm.com, david@redhat.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, pmorel@linux.ibm.com, pasic@linux.ibm.com, alex.williamson@redhat.com, kwankhede@nvidia.com, Tony Krowiak Subject: [PATCH 5/7] s390: vfio-ap: wait for queue empty on queue reset Date: Thu, 11 Apr 2019 17:03:22 -0400 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1555016604-2008-1-git-send-email-akrowiak@linux.ibm.com> References: <1555016604-2008-1-git-send-email-akrowiak@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19041121-0052-0000-0000-000003AAE700 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010910; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000284; SDB=6.01187697; UDB=6.00622145; IPR=6.00968461; MB=3.00026399; MTD=3.00000008; XFM=3.00000015; UTC=2019-04-11 21:03:41 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19041121-0053-0000-0000-000060770458 Message-Id: <1555016604-2008-6-git-send-email-akrowiak@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-11_13:,, 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-1904110136 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactors the AP queue reset function to wait until the queue is empty after the PQAP(ZAPQ) instruction is executed to zero out the queue as required by the AP architecture. Signed-off-by: Tony Krowiak --- drivers/s390/crypto/vfio_ap_ops.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index cda1d216ee38..ade2c150fe6b 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -664,15 +664,44 @@ static int vfio_ap_mdev_group_notifier(struct notifier_block *nb, return NOTIFY_OK; } -static int vfio_ap_mdev_reset_queue(unsigned int apid, unsigned int apqi, - unsigned int retry) +static void vfio_ap_mdev_wait_for_qempty(unsigned long apid, unsigned long apqi) { struct ap_queue_status status; + ap_qid_t qid = AP_MKQID(apid, apqi); + int retry = 5; + + do { + status = ap_tapq(qid, NULL); + switch (status.response_code) { + case AP_RESPONSE_NORMAL: + if (status.queue_empty) + return; + msleep(20); + break; + case AP_RESPONSE_RESET_IN_PROGRESS: + case AP_RESPONSE_BUSY: + msleep(20); + break; + default: + pr_warn("%s: tapq err %02x: 0x%04x may not be empty\n", + __func__, status.response_code, q->apqn); + return; + } + } while (--retry); +} + +int vfio_ap_mdev_reset_queue(unsigned int apid, unsigned int apqi) +{ + struct ap_queue_status status; + int retry = 5; do { status = ap_zapq(AP_MKQID(apid, apqi)); switch (status.response_code) { case AP_RESPONSE_NORMAL: + vfio_ap_mdev_wait_for_qempty(apid, apqi); + return 0; + case AP_RESPONSE_DECONFIGURED: return 0; case AP_RESPONSE_RESET_IN_PROGRESS: case AP_RESPONSE_BUSY: @@ -698,7 +727,7 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev) matrix_mdev->matrix.apm_max + 1) { for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm, matrix_mdev->matrix.aqm_max + 1) { - ret = vfio_ap_mdev_reset_queue(apid, apqi, 1); + ret = vfio_ap_mdev_reset_queue(apid, apqi); /* * Regardless whether a queue turns out to be busy, or * is not operational, we need to continue resetting -- 2.7.4