Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3382651ybp; Sun, 6 Oct 2019 10:42:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyL8rXNDbSKsxL1Vpd2uuzsazi2upS9S4GQWjQrHyH8k30dPwLfTwkdPa04V0OCfd+U4gjz X-Received: by 2002:a50:ce06:: with SMTP id y6mr24859677edi.282.1570383765819; Sun, 06 Oct 2019 10:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383765; cv=none; d=google.com; s=arc-20160816; b=JL/R3arsFJ2iGmv/AmSMPTUyHH37xg13eRg3K4sMmQxndFDocWQuTmu67OMm3oSEwL Ez3ANWkK4Jl8EBQo34K+6xg88FHrk0exclvtNHMwYuA0sCJg3V1eAnejryDxD1nRLYvb HF1+TVs5Wg5gEE1WrMQRStR6OwB2A6Lh6lc4NGZo8iTzXWT4Zzqe5Cl0EcjrBUhKZXvT 1rre7Q6MfKBe4Qn4LWwD94BldGsGAjxzaski8PxSK/0InhlKZ1+o+VGq0efI66TjLlgG nuMvlPu5glAQs8eq7O6zHYwH4fh9hNrpMg8kifr6Mn8qVnYSAtQz4wJKCm8iQ+eQPVy1 d6fA== 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=rCYn4QhrkJkt9IFgltbztBjT5G14w32RKHnLSd6m90U=; b=Q98RZkzPcgyBOMi/3QFM3a+yoPRGd/W8NttagG8y5oaS/tu9SdPPMyjYh5eOpgDk+Z 1AH5J9cpnA+UpXKd+JxnJWgo9JDVcm5hEOOYZmnvfJUejUCA6/KfAXDhLbH8mQaPhDAO sh2Dm5MjNAh53GdnXBA/PVJJeWbSqA8NY8uT6VoRbid1vJ9m0VKZlh13u6XJUK4LRVx1 SnmJdu/g7MrbF/Z/13ap6JPlERXf2/Hnu4VcSzni/syHALi5Gpdkrw3ij+8x1VxM+S5c 0PuDwGGUTJeBnhefEmOrLEDNdHtUKuvJmgtylrbs2qzHWZNecSCdqLZB9I9an6ydztE9 P/vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mYxBil6O; 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 v25si7895306edb.286.2019.10.06.10.42.22; Sun, 06 Oct 2019 10:42:45 -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=mYxBil6O; 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 S1731118AbfJFRlC (ORCPT + 99 others); Sun, 6 Oct 2019 13:41:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:40582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730436AbfJFRk7 (ORCPT ); Sun, 6 Oct 2019 13:40:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 AE5D62080F; Sun, 6 Oct 2019 17:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383658; bh=C/gvul4pQ/MCqY9bjfcyrpOzvUH27jWmlmQUkP3PWqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mYxBil6Og076GAYLKSIUct0XN+HppkH++EVvgyQ5FGxh6alMLtcpReyBlxty91NEH rpaYMjKW1JXC839+fTBEVviOasqFoLc9MAEt13CvEwChKsVolT8p05TkuzlV1SKCam T1SiEPe2BFZj+bgdxHzOfFmvnWN3oy95ipbCz8Lk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, hexin , Liu Qi , Zhang Yu , Alex Williamson , Sasha Levin Subject: [PATCH 5.3 048/166] vfio_pci: Restore original state on release Date: Sun, 6 Oct 2019 19:20:14 +0200 Message-Id: <20191006171217.062817068@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171212.850660298@linuxfoundation.org> References: <20191006171212.850660298@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 From: hexin [ Upstream commit 92c8026854c25093946e0d7fe536fd9eac440f06 ] vfio_pci_enable() saves the device's initial configuration information with the intent that it is restored in vfio_pci_disable(). However, the commit referenced in Fixes: below replaced the call to __pci_reset_function_locked(), which is not wrapped in a state save and restore, with pci_try_reset_function(), which overwrites the restored device state with the current state before applying it to the device. Reinstate use of __pci_reset_function_locked() to return to the desired behavior. Fixes: 890ed578df82 ("vfio-pci: Use pci "try" reset interface") Signed-off-by: hexin Signed-off-by: Liu Qi Signed-off-by: Zhang Yu Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/pci/vfio_pci.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 703948c9fbe10..02206162eaa9e 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -438,11 +438,20 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev) pci_write_config_word(pdev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE); /* - * Try to reset the device. The success of this is dependent on - * being able to lock the device, which is not always possible. + * Try to get the locks ourselves to prevent a deadlock. The + * success of this is dependent on being able to lock the device, + * which is not always possible. + * We can not use the "try" reset interface here, which will + * overwrite the previously restored configuration information. */ - if (vdev->reset_works && !pci_try_reset_function(pdev)) - vdev->needs_reset = false; + if (vdev->reset_works && pci_cfg_access_trylock(pdev)) { + if (device_trylock(&pdev->dev)) { + if (!__pci_reset_function_locked(pdev)) + vdev->needs_reset = false; + device_unlock(&pdev->dev); + } + pci_cfg_access_unlock(pdev); + } pci_restore_state(pdev); out: -- 2.20.1