Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1131383pxb; Thu, 4 Mar 2021 04:15:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJz9zw15oD57SX7zgD/OETuyNCufDG/2G3E3uKhwWY1TL9eceXy9kt3yUchOo04Awvp8bqPa X-Received: by 2002:a17:907:216a:: with SMTP id rl10mr59607ejb.365.1614860127062; Thu, 04 Mar 2021 04:15:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614860127; cv=none; d=google.com; s=arc-20160816; b=vqTCrHEoC6YahXoY+Yd3Y6u6XBQhuFobS+8Ypb8+t61ew9l0SlqmoRSw1Uw/1ty8U3 Vu4CkNboS9pu6nQWbbP+OtIfbiAKE7bSQWAjpPEvaW9/AIGOiQxD8tOrtUBmDssp3ywo GGvRgWOnyhK505dskr1Lhc8ZpYOC9nURHPR8igrXfnPmXtODv2FRjZjYaQmltFgBD8Kv 5xRQhSm86+ZdW12HOxAFIKwnNXafrHfOc4PyMgu8iKSJLJJTPZrv9ylUbJuBPU5GEd4d v5qGBjxpfLh9R2w+pEs9XavUKvgnUau1Ie6I01TVIQ5q2E9B7IUq82vJd4yBRzdsmX15 81/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=xB4pj5ZQmdaIfWonq+qYZ9igM/UR1LN9BL/+/khQTwY=; b=K/fhi3o1N8WU0pwWBm7wk+ZMhA/fkCAZ4dUtgxaQzXNhDiOb2+nETn8T2WSZXCq9Zp GkQ38p1ZWbtJPM21NWEDa05gvJoZtBEwcsoRezXNITmPw9KmUxO42HPPZpXIEx4z3JgC dHetw04qCDaTUi9ZO0c+bg2ygrpyJwDAODVwauKOcybS0gBMrCpLr9/a7ON0xnwVNGd9 d4Rj7SNWgxjg3kZhLhDfBXVaK9+5iDsd+XxAQCHZ5YObI7AE2NEjxGoBaWdEbUUgv++C jLCfCXqJKmsC2WF+aWrWFfpYCyzHbBahbFCuxPv8/QXQHmiK7WSsY9MBrLnih7Pa7rMx SJuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HwfrlT+M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si18701359ejl.444.2021.03.04.04.15.02; Thu, 04 Mar 2021 04:15:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HwfrlT+M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1580798AbhCCSfJ (ORCPT + 99 others); Wed, 3 Mar 2021 13:35:09 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:4588 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233473AbhCCRLf (ORCPT ); Wed, 3 Mar 2021 12:11:35 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 123H3YMN036521; Wed, 3 Mar 2021 12:10:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=xB4pj5ZQmdaIfWonq+qYZ9igM/UR1LN9BL/+/khQTwY=; b=HwfrlT+MWatOCZWhscq4UHiyg4cbIjTMAEIagbWjaEoz7svKwLB5tK/Xwo02drucOYec ZcBJgFtW+y0qd7sJZiQlVWkpNrX+gFnXh3LxqFay/li/CXdVq3BvZTyk1JbgcYJcArzv Tal++cENl7yLtZBLqCICg8XYJAcw8rQzSlqrHKzSw3HWc1LfRc92UDjurVjkbEjDVyMm 1kJkLU7JPKRLnTcduFgurqih1tFO+1RDYP8za4aU+C3N8jMrGFesJYsJFzi9yjBHRa69 +b3fvZnZwyYCKwQnTf+YXX8sXph6AEMjh4Cg+n2Y6aL+oL4txMnKjSrZS6INmz2maM2V VQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 372dwshnb6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 03 Mar 2021 12:10:17 -0500 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 123H3uvX042538; Wed, 3 Mar 2021 12:10:17 -0500 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 372dwshnaq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 03 Mar 2021 12:10:16 -0500 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 123Gw93R032762; Wed, 3 Mar 2021 17:10:16 GMT Received: from b03cxnp07027.gho.boulder.ibm.com (b03cxnp07027.gho.boulder.ibm.com [9.17.130.14]) by ppma03dal.us.ibm.com with ESMTP id 3720r0eckk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 03 Mar 2021 17:10:16 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp07027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 123HAEtU24379838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 3 Mar 2021 17:10:14 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7E63F13604F; Wed, 3 Mar 2021 17:10:14 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BFF2136053; Wed, 3 Mar 2021 17:10:12 +0000 (GMT) Received: from cpe-66-24-58-13.stny.res.rr.com (unknown [9.85.150.254]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 3 Mar 2021 17:10:12 +0000 (GMT) Subject: Re: [PATCH v3 1/1] s390/vfio-ap: fix circular lockdep when setting/clearing crypto masks To: Halil Pasic Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, stable@vger.kernel.org, borntraeger@de.ibm.com, cohuck@redhat.com, kwankhede@nvidia.com, pbonzini@redhat.com, alex.williamson@redhat.com, pasic@linux.vnet.ibm.com References: <20210302204322.24441-1-akrowiak@linux.ibm.com> <20210302204322.24441-2-akrowiak@linux.ibm.com> <20210303162332.4d227dbe.pasic@linux.ibm.com> From: Tony Krowiak Message-ID: <14665bcf-2224-e313-43ff-357cadd177cf@linux.ibm.com> Date: Wed, 3 Mar 2021 12:10:11 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20210303162332.4d227dbe.pasic@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-03-03_05:2021-03-03,2021-03-03 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 adultscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103030123 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/3/21 10:23 AM, Halil Pasic wrote: > On Tue, 2 Mar 2021 15:43:22 -0500 > Tony Krowiak wrote: > >> This patch fixes a lockdep splat introduced by commit f21916ec4826 >> ("s390/vfio-ap: clean up vfio_ap resources when KVM pointer invalidated"). >> The lockdep splat only occurs when starting a Secure Execution guest. >> Crypto virtualization (vfio_ap) is not yet supported for SE guests; >> however, in order to avoid this problem when support becomes available, >> this fix is being provided. > [..] > >> @@ -1038,14 +1116,28 @@ static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev, >> { >> struct ap_matrix_mdev *m; >> >> - list_for_each_entry(m, &matrix_dev->mdev_list, node) { >> - if ((m != matrix_mdev) && (m->kvm == kvm)) >> - return -EPERM; >> - } >> + if (kvm->arch.crypto.crycbd) { >> + matrix_mdev->kvm_busy = true; >> >> - matrix_mdev->kvm = kvm; >> - kvm_get_kvm(kvm); >> - kvm->arch.crypto.pqap_hook = &matrix_mdev->pqap_hook; >> + list_for_each_entry(m, &matrix_dev->mdev_list, node) { >> + if ((m != matrix_mdev) && (m->kvm == kvm)) { >> + wake_up_all(&matrix_mdev->wait_for_kvm); > This ain't no good. kvm_busy will remain true if we take this exit. The > wake_up_all() is not needed, because we hold the lock, so nobody can > observe it if we don't forget kvm_busy set. > > I suggest moving matrix_mdev->kvm_busy = true; after this loop, maybe right > before the unlock, and removing the wake_up_all(). > >> + return -EPERM; >> + } >> + } >> + >> + kvm_get_kvm(kvm); >> + mutex_unlock(&matrix_dev->lock); >> + kvm_arch_crypto_set_masks(kvm, >> + matrix_mdev->matrix.apm, >> + matrix_mdev->matrix.aqm, >> + matrix_mdev->matrix.adm); >> + mutex_lock(&matrix_dev->lock); >> + kvm->arch.crypto.pqap_hook = &matrix_mdev->pqap_hook; >> + matrix_mdev->kvm = kvm; >> + matrix_mdev->kvm_busy = false; >> + wake_up_all(&matrix_mdev->wait_for_kvm); >> + } >> >> return 0; >> } > [..] > >> @@ -1300,7 +1406,21 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev, >> ret = vfio_ap_mdev_get_device_info(arg); >> break; >> case VFIO_DEVICE_RESET: >> - ret = vfio_ap_mdev_reset_queues(mdev); >> + matrix_mdev = mdev_get_drvdata(mdev); >> + >> + /* >> + * If the KVM pointer is in the process of being set, wait until >> + * the process has completed. >> + */ >> + wait_event_cmd(matrix_mdev->wait_for_kvm, >> + matrix_mdev->kvm_busy == false, >> + mutex_unlock(&matrix_dev->lock), >> + mutex_lock(&matrix_dev->lock)); >> + >> + if (matrix_mdev->kvm) >> + ret = vfio_ap_mdev_reset_queues(mdev); >> + else >> + ret = -ENODEV; > I don't think rejecting the reset is a good idea. I have you a more detailed > explanation of the list, where we initially discussed this question. > > How do you exect userspace to react to this -ENODEV? After reading your more detailed explanation, I have come to the conclusion that the test for matrix_mdev->kvm should not be performed here and the the vfio_ap_mdev_reset_queues() function should be called regardless. Each queue assigned to the mdev that is also bound to the vfio_ap driver will get reset and its IRQ resources cleaned up if they haven't already been and the other required conditions are met (i.e., see vfio_ap_mdev_free_irq_resources()). > > Otherwise looks good to me! > > I've tested your branch from yesterday (which looks to me like this patch > without the above check on ->kvm and reset) for the lockdep splat, but I > didn't do any comprehensive testing -- which would ensure that we didn't > break something else in the process. With the two issues fixed, and your > word that the patch was properly tested (except for the lockdep splat > which I tested myself), I feel comfortable with moving forward with this. > > Regards, >