From patchwork Mon Feb 5 12:02:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gowans, James" X-Patchwork-Id: 13545364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E64DC48291 for ; Mon, 5 Feb 2024 12:06:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3B888D0001; Mon, 5 Feb 2024 07:06:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DEC106B00AB; Mon, 5 Feb 2024 07:06:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC6DD8D0001; Mon, 5 Feb 2024 07:06:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B800A6B00AA for ; Mon, 5 Feb 2024 07:06:40 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 99CF4A03E0 for ; Mon, 5 Feb 2024 12:06:40 +0000 (UTC) X-FDA: 81757623360.07.65B5318 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf26.hostedemail.com (Postfix) with ESMTP id 9BE1B140018 for ; Mon, 5 Feb 2024 12:06:38 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=KS4I5EHo; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf26.hostedemail.com: domain of "prvs=75897cb1d=jgowans@amazon.com" designates 72.21.196.25 as permitted sender) smtp.mailfrom="prvs=75897cb1d=jgowans@amazon.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707134798; a=rsa-sha256; cv=none; b=dU+Dz0jf8hMYvrYLqZG/TTFI1QS3Eb6oCJQXyPqIkrQcnb9u7kNOQtHA6836et4lqisTY7 dz8FTGhtzBe1EBa1SI26vihhhgyampPTfreW+/GdshAc6t6bSnDF8RS/xHXJOAaPdhUXB7 IezM4abMXMXwy5TTKwLfAed3CqT4usM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=KS4I5EHo; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf26.hostedemail.com: domain of "prvs=75897cb1d=jgowans@amazon.com" designates 72.21.196.25 as permitted sender) smtp.mailfrom="prvs=75897cb1d=jgowans@amazon.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707134798; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FiBUV1fiPqoy2U4uMejLoWWd/EiydMvzfGCqIJIuYJY=; b=jXzOKQV6UcC55t1dhDx9NxnVIALEd+fUq7AWpNClKqXKGLMuQDOVaEggCUg7UCThs5itQn MukSVEruRTFSMbXfVtwM/lucYgFpOUjROwmO3UgP0Y7w6tgRrd4gtJntG2Has3arIbcDqB DryE0VlFnjyqKovOf/x/c/3EyBzYyFk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1707134799; x=1738670799; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FiBUV1fiPqoy2U4uMejLoWWd/EiydMvzfGCqIJIuYJY=; b=KS4I5EHoPb/GLevhTJXhrqZGA19Gu0J1gr1dLxgNL42X9GGMElWCxcV6 TMkSKYaGibsuGrDtJ/BVIk12A5B2F6AeD63lMV41v1myZ+ZGI6khCfgDA KtYbjAX5a0RIQlGh00w6P5OeRBJ1H9xpdzO4LHNt/rm5sA/HwFOxllbTC U=; X-IronPort-AV: E=Sophos;i="6.05,245,1701129600"; d="scan'208";a="378967633" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 12:06:35 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.17.79:8094] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.45.85:2525] with esmtp (Farcaster) id 26f74936-a3bc-4ca0-9d65-59fbb5471a6c; Mon, 5 Feb 2024 12:06:32 +0000 (UTC) X-Farcaster-Flow-ID: 26f74936-a3bc-4ca0-9d65-59fbb5471a6c Received: from EX19D014EUC004.ant.amazon.com (10.252.51.182) by EX19MTAEUC002.ant.amazon.com (10.252.51.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:06:32 +0000 Received: from dev-dsk-jgowans-1a-a3faec1f.eu-west-1.amazon.com (172.19.112.191) by EX19D014EUC004.ant.amazon.com (10.252.51.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:06:26 +0000 From: James Gowans To: CC: Eric Biederman , , "Joerg Roedel" , Will Deacon , , Alexander Viro , "Christian Brauner" , , Paolo Bonzini , Sean Christopherson , , Andrew Morton , , Alexander Graf , David Woodhouse , "Jan H . Schoenherr" , Usama Arif , Anthony Yznaga , Stanislav Kinsburskii , , , Subject: [RFC 18/18] vfio-pci: Assume device working after liveupdate Date: Mon, 5 Feb 2024 12:02:03 +0000 Message-ID: <20240205120203.60312-19-jgowans@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205120203.60312-1-jgowans@amazon.com> References: <20240205120203.60312-1-jgowans@amazon.com> MIME-Version: 1.0 X-Originating-IP: [172.19.112.191] X-ClientProxiedBy: EX19D044UWB004.ant.amazon.com (10.13.139.134) To EX19D014EUC004.ant.amazon.com (10.252.51.182) X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9BE1B140018 X-Stat-Signature: 3zbwes88tdxwwm3w36redunsiyucpsfp X-HE-Tag: 1707134798-260343 X-HE-Meta: U2FsdGVkX1/w66Z8PFdhAE9/pSMTwh4mqg5AI5m3ZpS5Pkbpwf0Ta7/ICwrzNPdl9lzJjcvqNdYN11TsEW3WWfbf5czFczipR/J/JWvEI6O7n1QYAnK3fbFikKHuwnxfhIsthdvg2qldCHTf5O6Xzl5QjZGZGmp60hiT6uDZBwvD8zZSDnesFCeLXnrDtZsbdniqgAEs4aimrA4jaP3Zh86VCbXnLoZt/xvmg6bKro8EijB1ZMaTXCHNxJhj2sJ+cPkclE/txmhYPsHZyqSGhoQkLuDKN8CPuFsT6hZ3nyNCHDZsVDOogyI1VAb6em21hrqa/uvW0xAYOOhxJb9VtdkHq7ZjH8p6+91SKiwe5Lpu0P3vx7Yo7cyW7ih8PZQX8Zl5C19fyZHzxSn9n+7/TpJ2lzo4UQPIoX4kh5LXAfRIp94oQeAmOclvopBAJtrpJ8nBKjd0Sef44ymd5TerIyaNtmEKREslHnde+Agr1L95teTpsw5kxmj+Z8azEuHcr5ozpAMwgfBuytzBR7IHmMdRsgXX4wcLbGzN0RvAzzTrAriSp/1bDLUAL/IRq2F9ORQ2QbsQ9sHpqCVdTxB4bU5vPMbMMHcjhed9gbDImq/4UaICW41zBiqZE4RfdvyGgTNwDI0QzbHGwg0vVtKdBTCSV3igH8mD++COZuyOtMUkcrdoUVn7FR74MzQyemZmKeetxUyNse73bMQ5q7lqqwTV2Pp3ePzx+tjsu25KH0fzxe2MF6SD9o6roTDqh70doCGH7aPWBuMSknmUZP6urYVDbyw0Akk5LJdbRnvrGAFyqWnnWUuJaRGE8tVMAsbLIg+0udUCikyNRljoGu194LAwrUd6yGen2Jvxk8SIZVX+7NcDbLwERvHJ8lH2h6YJ7b5yUmw0q704LWrWLS1hr93vCyI+5Rr27Wg85FUGrjHbLMMqUmK8dwcn4XLHsTsjK8BYK5kzMM0yyaCDK3V GYGuxnQf 4GR4Wcy91u4FmHMHu0qhQAB10S1j1EIAvKVD8HURZoGpKb2sjyAVEqmpYacQgQqQKgSgikOE2AhjV4Pbxk5muUZkDGhUW8Z0hcjpI/nyqK6t6Nii4wea4HK6qeissFBxfEip+Fa/8RvHGw4SBg8PpNlSCCAzLRQ/Rg27QQxZcP2Vy0OnNFzqAqD9osHJTHz9s8opIALyrjcci5A+5aGuQw+ncONOwf4RKhBOkEZaVP+NYbA3kitnA9m3zQCCvZfdsgkOjuvl0Y7NeW64w8bHPF5Bi/jOa1c2ssz5Np3ioY9Bmo3j9ccN6YIUlcyfZhtEaHo9VDVAkH+nOX4EsqJYFCWVxyjNfizLLt4DDSvdmVZjBs0jK1HbsgwREDq6V/RIjYS7F X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When re-creating a VFIO device after liveupdate no desctructive actions should be taken on it to avoid interrupting any ongoing DMA. Specifically bus mastering should not be cleared and the device should not be reset. Assume that reset works properly and skip over bus mastering reset. Ideally this would only be done for persistent devices but in this rough RFC there currently is no mechanism at this point to easily tell if a device is persisted or not. --- drivers/vfio/pci/vfio_pci_core.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 1929103ee59a..a7f56d43e0a4 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -480,19 +480,25 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) return ret; } - /* Don't allow our initial saved state to include busmaster */ - pci_clear_master(pdev); + if (!liveupdate) { + /* Don't allow our initial saved state to include busmaster */ + pci_clear_master(pdev); + } ret = pci_enable_device(pdev); if (ret) goto out_power; - /* If reset fails because of the device lock, fail this path entirely */ - ret = pci_try_reset_function(pdev); - if (ret == -EAGAIN) - goto out_disable_device; + if (!liveupdate) { + /* If reset fails because of the device lock, fail this path entirely */ + ret = pci_try_reset_function(pdev); + if (ret == -EAGAIN) + goto out_disable_device; - vdev->reset_works = !ret; + vdev->reset_works = !ret; + } else { + vdev->reset_works = 1; + } pci_save_state(pdev); vdev->pci_saved_state = pci_store_saved_state(pdev); if (!vdev->pci_saved_state)