Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp276990ybi; Wed, 29 May 2019 21:12:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8Jk+M8EDRDSz02UWzzOFazJKW54EfsbaVCxRObbgDULmDuUyQf+N3CJo3iRE5op/qIi6p X-Received: by 2002:a62:6145:: with SMTP id v66mr1718385pfb.144.1559189567932; Wed, 29 May 2019 21:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559189567; cv=none; d=google.com; s=arc-20160816; b=J8tuRdtN1oEoyArJoZ/VIoagaA/8V/2eYbnV1RphGz2N5HopYntu1l6JIU54jiZ5PX UeXrRhMFoZ6PV7ZnsiVEViIRdv8OSFzKdrupEkhH96qQ4CwglDDoyf9KrdIULfVZn6Jt MWy9y8HCfgIVyw05Pyq4MTjW75Ow1/JIXqHiUCuZglN8R+9VQ3QLYYhkq61ZmnFELVk2 k4TyWx0XhvGlqIjqtt87xS/J/uLFZyUk3+wr4MZ1IRHV3dDPkjHgGhyHHjsntDoTUlbY uIB5IaMBzY+k1DLpmR0VIW7kmV5pLOFbzG5W2XDARWBRQ3LmRSLTHycuTrBL6l45RYD/ SMoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RcTOkyP1wfAMvGs+TYT4ijoPWSTJWWVc7LAaiSuqj8o=; b=nYuAA4d4vPw5kOMieQczFYDWcHK6RKDUMMRyMDv9lfIXhgdcx+tEmHNRYRcHyzBa4M 3quZeJA+cJVU8QXtORftELsKWMR4lvLGdRJYY/ciVZd7J2qbINfbeyjdxE4MwFbZ3+5r DeMRQKppEDFDdIoe1AWs4Meo758ejQf677S/M+6Z+2SFdM8KLn6yIisKz4QRuoCIn2oc bL6seKx0nisFTD8ubCBM+hzw7Q7Z4Izxyzx3L3GKusZBsSorWpNGcS8RJ3LE3Wqtpp8B A7KUdgyqKq7VDf4KRN31m67CJVb7QdF9dpCtrTnseztiOkKJgJ92o32f0IGdjlbv/rGd RBbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tMPLDs0q; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y22si1816061pgj.402.2019.05.29.21.12.31; Wed, 29 May 2019 21:12:47 -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; dkim=pass header.i=@kernel.org header.s=default header.b=tMPLDs0q; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727261AbfE3EK1 (ORCPT + 99 others); Thu, 30 May 2019 00:10:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:44448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730881AbfE3DRA (ORCPT ); Wed, 29 May 2019 23:17:00 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 56D482464B; Thu, 30 May 2019 03:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186219; bh=bZizr1t6BzbjwN0yJ7fX+f7uZ1SGbNSRud942rvWzQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tMPLDs0qC9HUSgVtyQHMLc9uud80kn8tSMy6TLIGXPyUl3Tiz59zyxBmVlmricGgh rBP2Kth/F8DboXhRfPdenjQ5x/zemG/pLJNQCNM/Q/WUnucpRGbI5UxAokwbv2Q3Mc B5CUlNj58nBqGR1WFYDo2vDwfMqK6wmta2QMgZww= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Farhan Ali , Eric Farman , Cornelia Huck , Sasha Levin Subject: [PATCH 4.19 109/276] vfio-ccw: Release any channel program when releasing/removing vfio-ccw mdev Date: Wed, 29 May 2019 20:04:27 -0700 Message-Id: <20190530030532.829145465@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit b49bdc8602b7c9c7a977758bee4125683f73e59f ] When releasing the vfio-ccw mdev, we currently do not release any existing channel program and its pinned pages. This can lead to the following warning: [1038876.561565] WARNING: CPU: 2 PID: 144727 at drivers/vfio/vfio_iommu_type1.c:1494 vfio_sanity_check_pfn_list+0x40/0x70 [vfio_iommu_type1] .... 1038876.561921] Call Trace: [1038876.561935] ([<00000009897fb870>] 0x9897fb870) [1038876.561949] [<000003ff8013bf62>] vfio_iommu_type1_detach_group+0xda/0x2f0 [vfio_iommu_type1] [1038876.561965] [<000003ff8007b634>] __vfio_group_unset_container+0x64/0x190 [vfio] [1038876.561978] [<000003ff8007b87e>] vfio_group_put_external_user+0x26/0x38 [vfio] [1038876.562024] [<000003ff806fc608>] kvm_vfio_group_put_external_user+0x40/0x60 [kvm] [1038876.562045] [<000003ff806fcb9e>] kvm_vfio_destroy+0x5e/0xd0 [kvm] [1038876.562065] [<000003ff806f63fc>] kvm_put_kvm+0x2a4/0x3d0 [kvm] [1038876.562083] [<000003ff806f655e>] kvm_vm_release+0x36/0x48 [kvm] [1038876.562098] [<00000000003c2dc4>] __fput+0x144/0x228 [1038876.562113] [<000000000016ee82>] task_work_run+0x8a/0xd8 [1038876.562125] [<000000000014c7a8>] do_exit+0x5d8/0xd90 [1038876.562140] [<000000000014d084>] do_group_exit+0xc4/0xc8 [1038876.562155] [<000000000015c046>] get_signal+0x9ae/0xa68 [1038876.562169] [<0000000000108d66>] do_signal+0x66/0x768 [1038876.562185] [<0000000000b9e37e>] system_call+0x1ea/0x2d8 [1038876.562195] 2 locks held by qemu-system-s39/144727: [1038876.562205] #0: 00000000537abaf9 (&container->group_lock){++++}, at: __vfio_group_unset_container+0x3c/0x190 [vfio] [1038876.562230] #1: 00000000670008b5 (&iommu->lock){+.+.}, at: vfio_iommu_type1_detach_group+0x36/0x2f0 [vfio_iommu_type1] [1038876.562250] Last Breaking-Event-Address: [1038876.562262] [<000003ff8013aa24>] vfio_sanity_check_pfn_list+0x3c/0x70 [vfio_iommu_type1] [1038876.562272] irq event stamp: 4236481 [1038876.562287] hardirqs last enabled at (4236489): [<00000000001cee7a>] console_unlock+0x6d2/0x740 [1038876.562299] hardirqs last disabled at (4236496): [<00000000001ce87e>] console_unlock+0xd6/0x740 [1038876.562311] softirqs last enabled at (4234162): [<0000000000b9fa1e>] __do_softirq+0x556/0x598 [1038876.562325] softirqs last disabled at (4234153): [<000000000014e4cc>] irq_exit+0xac/0x108 [1038876.562337] ---[ end trace 6c96d467b1c3ca06 ]--- Similarly we do not free the channel program when we are removing the vfio-ccw device. Let's fix this by resetting the device and freeing the channel program and pinned pages in the release path. For the remove path we can just quiesce the device, since in the remove path the mediated device is going away for good and so we don't need to do a full reset. Signed-off-by: Farhan Ali Message-Id: Acked-by: Eric Farman Signed-off-by: Cornelia Huck Signed-off-by: Sasha Levin --- drivers/s390/cio/vfio_ccw_ops.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index f673e106c0415..dc5ff47de3fee 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -130,11 +130,12 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev) if ((private->state != VFIO_CCW_STATE_NOT_OPER) && (private->state != VFIO_CCW_STATE_STANDBY)) { - if (!vfio_ccw_mdev_reset(mdev)) + if (!vfio_ccw_sch_quiesce(private->sch)) private->state = VFIO_CCW_STATE_STANDBY; /* The state will be NOT_OPER on error. */ } + cp_free(&private->cp); private->mdev = NULL; atomic_inc(&private->avail); @@ -158,6 +159,14 @@ static void vfio_ccw_mdev_release(struct mdev_device *mdev) struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); + if ((private->state != VFIO_CCW_STATE_NOT_OPER) && + (private->state != VFIO_CCW_STATE_STANDBY)) { + if (!vfio_ccw_mdev_reset(mdev)) + private->state = VFIO_CCW_STATE_STANDBY; + /* The state will be NOT_OPER on error. */ + } + + cp_free(&private->cp); vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, &private->nb); } -- 2.20.1