Message ID | 20240205071538.2665628-1-Emily.Deng@amd.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-52113-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp714553dyb; Sun, 4 Feb 2024 23:16:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjtxqMUTpCfNh9VcU+33hhNzij3TtP0WX/1f0AS/c1bEXXSyVZ83lrijoWELGmX7dmgaJl X-Received: by 2002:a17:90b:4c49:b0:296:8eac:b4a1 with SMTP id np9-20020a17090b4c4900b002968eacb4a1mr1608533pjb.27.1707117380998; Sun, 04 Feb 2024 23:16:20 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXXysV3zYTUkz4tch3uqOT9TXSRogRygFV8UcuWBtOWnMlsTMcPCj7g5Doqc1/roY29ZDBOshd1trqBwKcpq15ME4SUmA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a18-20020a170902ecd200b001d8882dd6a7si6006207plh.392.2024.02.04.23.16.20 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 23:16:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52113-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=a2hvI48m; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-52113-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52113-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AD80B2837BF for <ouuuleilei@gmail.com>; Mon, 5 Feb 2024 07:16:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC9E310A39; Mon, 5 Feb 2024 07:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="a2hvI48m" Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2067.outbound.protection.outlook.com [40.107.92.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E4C9C148; Mon, 5 Feb 2024 07:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707117354; cv=fail; b=hYHkEegNp06BNonOjZq0WHQGPH3Rou8ceeQ8lX7jvwdCJuW3hHknG6hbsFcJ2HwlfMkotGwVZD8yBD2W9UP8ue6NW09qFngfU6gXn//DfqNIH/qKGZRDxDlbikxgjRqxIZJaoam0YUK0DMrc35RcpfKwlqd5Oibb339zhmmhO7Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707117354; c=relaxed/simple; bh=3L+FOPsYwtTvOMeNpENsatgn7x0UpbGEa4ghrigY1/4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=It4aogNMzemdggDnBbPvrzh/4KbAgM5zLNbpnARdqJZ8umU4ISUkdOuWb8ZFNLqiE4fxhE+Gf2YOEk4BybFgOIvnHWavqrPEDm4L+aspyrmOX0tR6HDa83hq950u3+HJDQltsALXwccgoOiJXZZCE6ZyP/mJMtwbsqA3fU3cZ+M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=a2hvI48m; arc=fail smtp.client-ip=40.107.92.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KZbkuPybk+Fib++wVCKQhFCXn214/uw4l3auTjktdbMjlLJa0mf5ObBwGMfSHpM11C9GXHw1dZZ2hLV8yhSY17+Ts1C/arFZ0yJukWwmacHqyXzmC++jv7YVAgHHQvq9IqnjU7DtgLYfjZ4FLpmq/FnDemKL69mZy54BAEuvDyzX1BQdXnMqFcxnCBdvVNvZfjouRg+1RjMvVDKGgOVpI3HLDI7sIChrwP9ZS5usvqLSdhbfgGOhpZ43//z3uBHRAMtV6DlKGwQXj21uGefsdB+hhDk+3I6gVMQX5Mhe9EQPGfmVDoCNX7imA6Q4QJh0w3LrGfE1htSEl4TmLsWHUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SDZoyxV0PBYEGXzdw06CQ7HWzz1npsZS2UYPoIw1f/o=; b=Hjt/T8U0NGmqLBfSDHnjIX9dnhBf9N2GNVLqyTGUb7sey/4TSo5/JEjCRRXYSOpz7Wt7kvbNlmqhYrtY+eWKX67DGCIiGdEBrK2AY8tADDgzDUWVVJjlBX8wludrkbiCvrVenm8keMixyFyUHNqg7oVggW80NhVNuGaZOVMECHBBoZ0C+WAyfK3JtxLwuy5ZKlKfF/dCH+7O3vChIu0be3rgZZUtbfFWEFVRJPBZoScGP+VIoUQw/fTGMY+UZwX3WoN3pEhsIjxDBYY6zMSa0UtWMfc1vSs/QEj2wOjktxF5ows2HYsXkMT+8MhoXhDBHiltm4GdNRW3fBqvrdi45Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SDZoyxV0PBYEGXzdw06CQ7HWzz1npsZS2UYPoIw1f/o=; b=a2hvI48masqBA+ZjrwS9EedJpzcqRyNJpISnGL50Dlh8G3+VtZ+OtQuHKU17b5UHE0prBHC3xz0kwE61CJcuOTq24TycFtglxGq4k0eCTv/8fBV3xnjIs9aCJKJfyIcvZz5EJRV0rYpXBW5syIRftp6+iQD+hZC6k86vuhUgLhE= Received: from BN9PR03CA0053.namprd03.prod.outlook.com (2603:10b6:408:fb::28) by SJ2PR12MB7992.namprd12.prod.outlook.com (2603:10b6:a03:4c3::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.15; Mon, 5 Feb 2024 07:15:49 +0000 Received: from BN2PEPF000044A7.namprd04.prod.outlook.com (2603:10b6:408:fb:cafe::d2) by BN9PR03CA0053.outlook.office365.com (2603:10b6:408:fb::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.34 via Frontend Transport; Mon, 5 Feb 2024 07:15:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF000044A7.mail.protection.outlook.com (10.167.243.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7249.19 via Frontend Transport; Mon, 5 Feb 2024 07:15:49 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 5 Feb 2024 01:15:49 -0600 Received: from emily-Z10PA-U8-Series.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.34 via Frontend Transport; Mon, 5 Feb 2024 01:15:46 -0600 From: Emily Deng <Emily.Deng@amd.com> To: <bhelgaas@google.com>, <alex.williamson@redhat.com>, <linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <kvm@vger.kernel.org> CC: <Jerry.Jiang@amd.com>, <Andy.Zhang@amd.com>, <HaiJun.Chang@amd.com>, <Monk.Liu@amd.com>, <Horace.Chen@amd.com>, <ZhenGuo.Yin@amd.com>, Emily Deng <Emily.Deng@amd.com> Subject: [PATCH 1/2] PCI: Add VF reset notification to PF's VFIO user mode driver Date: Mon, 5 Feb 2024 15:15:37 +0800 Message-ID: <20240205071538.2665628-1-Emily.Deng@amd.com> X-Mailer: git-send-email 2.36.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A7:EE_|SJ2PR12MB7992:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c238bb4-fd5b-43a6-8226-08dc261a47da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AWttwe5zmuO/kJ9UV+E3LKMPN4ivsIBvEP/LfUa1PyKEJ7b05VBZfNyB9oz4jBhtZvPImVl/KMkhMvwiop9FMEpejhWFXeq8r5wJA4iazVn8Bk5/B+y5Wn+nTA33HAte6b7gBkkK0FiOX1YjIso0l/prfdr/7kAVB24UIPQ5TAzf1Ly1XVUPyc7mGASq9OU5giWGnUCwKen6KaaaJ6qekicuuMGcH5cbUS7npIMLd+kDgYBdZAYNH49Xf6eBytz4FospoBWHu+AiIWeWOxqylvIkFnkcEWhmfNvuIYHSJBZVRyjwFqiB+xgWtCob12JGyWzGUDfnkOLZeGZhvl4+Z2DG1H2J8BwB35GJZ5LoMvgIH10A/EwDm7cMcwyLxACYXwmkXVPnDjPPl4T2dvh5vbCMajpKl4IyPgrPrxhEu876VUSnf+baArWH2n06htMXmkcrEa4ZFWr5DpCrAZdMhJywYX+/1fuSECga1bmBECI8QQDad7X/rPoxW6HL/P8fU/mWjGNLKvTXmpgEPafQbKOHCgY3nHKfvv0Y9CmXxd/Cs7CBQn7J40fbER9FednlxpY24OTvRlshMGQ4kq4e7ZukPe/quHqALs/X3u3lMcAeLTQKvG26e9bQ/80ol6k0bNa75TFd3XaQ6dpimtlSylW5TOuhSEqdNdwDw1Oe/6tszsWTDsogVzQNLKjdMgkdV09VueujUR5I7hgiu8M2b7NwUfJlPEJZeTMSMEi0LFJF2u1QIDuHwvJIbj2/qs6mExVyDzrBT04Hn0lqzxBnvw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(136003)(346002)(396003)(39860400002)(230922051799003)(82310400011)(64100799003)(186009)(1800799012)(451199024)(46966006)(36840700001)(40470700004)(41300700001)(40480700001)(40460700003)(86362001)(478600001)(36756003)(426003)(336012)(1076003)(2616005)(81166007)(82740400003)(47076005)(356005)(26005)(83380400001)(2906002)(316002)(5660300002)(70206006)(54906003)(7696005)(6666004)(36860700001)(8676002)(4326008)(8936002)(70586007)(110136005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2024 07:15:49.5806 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c238bb4-fd5b-43a6-8226-08dc261a47da X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A7.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7992 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790042314601969851 X-GMAIL-MSGID: 1790042314601969851 |
Series |
[1/2] PCI: Add VF reset notification to PF's VFIO user mode driver
|
|
Commit Message
Emily Deng
Feb. 5, 2024, 7:15 a.m. UTC
VF doesn't have the ability to reset itself completely which will cause the
hardware in unstable state. So notify PF driver when the VF has been reset
to let the PF resets the VF completely, and remove the VF out of schedule.
How to implement this?
Add the reset callback function in pci_driver
Implement the callback functin in VFIO_PCI driver.
Add the VF RESET IRQ for user mode driver to let the user mode driver
know the VF has been reset.
Signed-off-by: Emily Deng <Emily.Deng@amd.com>
---
drivers/pci/pci.c | 8 ++++++++
include/linux/pci.h | 1 +
2 files changed, 9 insertions(+)
Comments
On Mon, Feb 05, 2024 at 03:15:37PM +0800, Emily Deng wrote: > VF doesn't have the ability to reset itself completely which will cause the > hardware in unstable state. So notify PF driver when the VF has been reset > to let the PF resets the VF completely, and remove the VF out of schedule. I'm sorry but this explanation is not different from the previous version. Please provide a better explanation of the problem, why it is needed, which VFs need and can't reset themselves, how and why it worked before e.t.c. In addition, please follow kernel submission guidelines, write changelong, add versions, cover letter e.t.c. Thanks > > How to implement this? > Add the reset callback function in pci_driver > > Implement the callback functin in VFIO_PCI driver. > > Add the VF RESET IRQ for user mode driver to let the user mode driver > know the VF has been reset. > > Signed-off-by: Emily Deng <Emily.Deng@amd.com> > --- > drivers/pci/pci.c | 8 ++++++++ > include/linux/pci.h | 1 + > 2 files changed, 9 insertions(+) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 60230da957e0..aca937b05531 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -4780,6 +4780,14 @@ EXPORT_SYMBOL_GPL(pcie_flr); > */ > int pcie_reset_flr(struct pci_dev *dev, bool probe) > { > + struct pci_dev *pf_dev; > + > + if (dev->is_virtfn) { > + pf_dev = dev->physfn; > + if (pf_dev->driver->sriov_vf_reset_notification) > + pf_dev->driver->sriov_vf_reset_notification(pf_dev, dev); > + } > + > if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) > return -ENOTTY; > > diff --git a/include/linux/pci.h b/include/linux/pci.h > index c69a2cc1f412..4fa31d9b0aa7 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -926,6 +926,7 @@ struct pci_driver { > int (*sriov_configure)(struct pci_dev *dev, int num_vfs); /* On PF */ > int (*sriov_set_msix_vec_count)(struct pci_dev *vf, int msix_vec_count); /* On PF */ > u32 (*sriov_get_vf_total_msix)(struct pci_dev *pf); > + void (*sriov_vf_reset_notification)(struct pci_dev *pf, struct pci_dev *vf); > const struct pci_error_handlers *err_handler; > const struct attribute_group **groups; > const struct attribute_group **dev_groups; > -- > 2.36.1 > >
On Mon, 5 Feb 2024 15:15:37 +0800 Emily Deng <Emily.Deng@amd.com> wrote: > VF doesn't have the ability to reset itself completely which will cause the > hardware in unstable state. So notify PF driver when the VF has been reset > to let the PF resets the VF completely, and remove the VF out of schedule. > > How to implement this? > Add the reset callback function in pci_driver > > Implement the callback functin in VFIO_PCI driver. > > Add the VF RESET IRQ for user mode driver to let the user mode driver > know the VF has been reset. The solution that already exists for this sort of issue is a vfio-pci variant driver for the VF which communicates with an in-kernel PF driver to coordinate the VF FLR with the PF driver. This can be done by intercepting the userspace access to the VF FLR config space region. This solution of involving PCI-core and extending the vfio-pci interface only exists for userspace PF drivers. I don't see that facilitating vendors to implement their PF drivers in userspace to avoid upstreaming is a compelling reason to extend the vfio-pci interface. Thanks, Alex > Signed-off-by: Emily Deng <Emily.Deng@amd.com> > --- > drivers/pci/pci.c | 8 ++++++++ > include/linux/pci.h | 1 + > 2 files changed, 9 insertions(+) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 60230da957e0..aca937b05531 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -4780,6 +4780,14 @@ EXPORT_SYMBOL_GPL(pcie_flr); > */ > int pcie_reset_flr(struct pci_dev *dev, bool probe) > { > + struct pci_dev *pf_dev; > + > + if (dev->is_virtfn) { > + pf_dev = dev->physfn; > + if (pf_dev->driver->sriov_vf_reset_notification) > + pf_dev->driver->sriov_vf_reset_notification(pf_dev, dev); > + } > + > if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) > return -ENOTTY; > > diff --git a/include/linux/pci.h b/include/linux/pci.h > index c69a2cc1f412..4fa31d9b0aa7 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -926,6 +926,7 @@ struct pci_driver { > int (*sriov_configure)(struct pci_dev *dev, int num_vfs); /* On PF */ > int (*sriov_set_msix_vec_count)(struct pci_dev *vf, int msix_vec_count); /* On PF */ > u32 (*sriov_get_vf_total_msix)(struct pci_dev *pf); > + void (*sriov_vf_reset_notification)(struct pci_dev *pf, struct pci_dev *vf); > const struct pci_error_handlers *err_handler; > const struct attribute_group **groups; > const struct attribute_group **dev_groups;
On Tue, 6 Feb 2024 04:03:46 +0000 "Liu, Monk" <Monk.Liu@amd.com> wrote: > [AMD Official Use Only - General] > > Hi Alex > > Thanks for your comment, I’m still not quite following you. > > >>This can be done by intercepting the userspace access to the VF FLR config space region. > > Would you mind let us know to do that ? See basically any of the vfio-pci variant drivers in drivers/vfio/pci/*/ For instance the virtio-vfio-pci driver is emulating a PCI IO BAR in config space and accesses through that BAR interact with the in-kernel PF driver. > our scenario is that: > 1, vf already pass-throughed to qemu > 2, a user mode driver on PF’s vfio arch is running there, and it want > to receive VF’s reset request (by Qemu through vfio interface), and > do some hw/fw sequences to achieve the real Vf reset goal > > >>. I don't see that facilitating vendors to implement their PF > >>drivers in userspace to avoid upstreaming > is a compelling reason to extend the vfio-pci interface. > > Some background here (our user mode PF driver is not given the > purpose to avoid upstream): We don’t see value to upstream a user > mode pf driver that only benefit AMD device, as it must be out of > kernel-tree so we don’t see where the appropriate repo for it is to > upstream to … (we cannot make it in Qemu right ? otherwise Qemu will > be over designed if it knows hw/fw details of vendors) An in-kernel driver within the mainline kernel is the right place for it. I'm not asking to upstream a user mode driver, you're right that there is no repo for that, I'm questioning the motivation for making it a user mode PF driver in the first place. All device drivers are essentially meant to benefit the device vendor, but in-kernel drivers also offer a benefit to the community and users of those devices for ongoing support and development. Let me turn the question around, what benefit does it provide this PF driver to exist in userspace? Without having seen it, I'd venture that there's nothing this userspace PF driver could do that couldn't also be done via a kernel driver, either in-tree or out-of-tree, but the userspace driver avoids the upstreaming work of an in-tree driver and the tainting of an out-of-tree driver. > Isn’t VFIO arch intentionally to give user mode driver freedom and > ability to manipulate the HW ? VFIO is not intended to provide an alternative means to implement kernel drivers. VFIO is intended to provide secure, isolated access to devices for userspace drivers. What's the isolation relative to the VF if this PF driver needs to be involved in reset? How much VF data does the PF device have access to? This is the reason that vfio-pci introduced the vf-token barrier with SR-IOV support. The intention of this vf-token is to indicate a gap in trust. Only another userspace process knowing the vf-token configured by the PF userspace driver can access the device. We should not normalize vf-tokens. The requirement of a vf-token for a driver not strictly developed alongside the PF userspace driver should effectively be considered a tainted device. Therefore, what does this userspace PF driver offer that isn't better reflected using the existing vfio-pci-core code split to implement a vfio-pci variant driver, which has no need for the extension proposed here? Thanks, Alex > From: Alex Williamson <alex.williamson@redhat.com> > Date: Tuesday, February 6, 2024 at 00:43 > To: Deng, Emily <Emily.Deng@amd.com> > Cc: bhelgaas@google.com <bhelgaas@google.com>, > linux-pci@vger.kernel.org <linux-pci@vger.kernel.org>, > linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>, > kvm@vger.kernel.org <kvm@vger.kernel.org>, Jiang, Jerry (SW) > <Jerry.Jiang@amd.com>, Zhang, Andy <Andy.Zhang@amd.com>, Chang, > HaiJun <HaiJun.Chang@amd.com>, Liu, Monk <Monk.Liu@amd.com>, Chen, > Horace <Horace.Chen@amd.com>, Yin, ZhenGuo (Chris) > <ZhenGuo.Yin@amd.com> Subject: Re: [PATCH 1/2] PCI: Add VF reset > notification to PF's VFIO user mode driver On Mon, 5 Feb 2024 > 15:15:37 +0800 Emily Deng <Emily.Deng@amd.com> wrote: > > > VF doesn't have the ability to reset itself completely which will > > cause the hardware in unstable state. So notify PF driver when the > > VF has been reset to let the PF resets the VF completely, and > > remove the VF out of schedule. > > > > How to implement this? > > Add the reset callback function in pci_driver > > > > Implement the callback functin in VFIO_PCI driver. > > > > Add the VF RESET IRQ for user mode driver to let the user mode > > driver know the VF has been reset. > > The solution that already exists for this sort of issue is a vfio-pci > variant driver for the VF which communicates with an in-kernel PF > driver to coordinate the VF FLR with the PF driver. This can be done > by intercepting the userspace access to the VF FLR config space > region. > > This solution of involving PCI-core and extending the vfio-pci > interface only exists for userspace PF drivers. I don't see that > facilitating vendors to implement their PF drivers in userspace to > avoid upstreaming is a compelling reason to extend the vfio-pci > interface. Thanks, > > Alex > > > Signed-off-by: Emily Deng <Emily.Deng@amd.com> > > --- > > drivers/pci/pci.c | 8 ++++++++ > > include/linux/pci.h | 1 + > > 2 files changed, 9 insertions(+) > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > index 60230da957e0..aca937b05531 100644 > > --- a/drivers/pci/pci.c > > +++ b/drivers/pci/pci.c > > @@ -4780,6 +4780,14 @@ EXPORT_SYMBOL_GPL(pcie_flr); > > */ > > int pcie_reset_flr(struct pci_dev *dev, bool probe) > > { > > + struct pci_dev *pf_dev; > > + > > + if (dev->is_virtfn) { > > + pf_dev = dev->physfn; > > + if (pf_dev->driver->sriov_vf_reset_notification) > > + > > pf_dev->driver->sriov_vf_reset_notification(pf_dev, dev); > > + } > > + > > if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) > > return -ENOTTY; > > > > diff --git a/include/linux/pci.h b/include/linux/pci.h > > index c69a2cc1f412..4fa31d9b0aa7 100644 > > --- a/include/linux/pci.h > > +++ b/include/linux/pci.h > > @@ -926,6 +926,7 @@ struct pci_driver { > > int (*sriov_configure)(struct pci_dev *dev, int num_vfs); > > /* On PF */ int (*sriov_set_msix_vec_count)(struct pci_dev *vf, > > int msix_vec_count); /* On PF */ u32 > > (*sriov_get_vf_total_msix)(struct pci_dev *pf); > > + void (*sriov_vf_reset_notification)(struct pci_dev *pf, > > struct pci_dev *vf); const struct pci_error_handlers *err_handler; > > const struct attribute_group **groups; > > const struct attribute_group **dev_groups;
On Tue, 6 Feb 2024 04:08:18 +0000 "Liu, Monk" <Monk.Liu@amd.com> wrote: > [AMD Official Use Only - General] > > Hi Leon > > The thing is when qemu reset a VM it calls vfio’s reset ioctl to the > given VF device, and in kernel the VFIO-pci module will do the reset > to that VF device via its PCI config space register, but > unfortunately our VF GPU isnot designed to support those > “reset”/”flr” commands … not supported by the VF, (and even many PF > cannot handle those commands well) PFs are not required to implement FLR, VFs are. SR-IOV spec, rev. 1.1: 2.2.2. FLR That Targets a VF VFs must support Function Level Reset (FLR). > > So the idea we can cook up is to move those Vf’s reset notification > to our PF driver (which is a user mode driver running on PF’s VFIO > arch), and our user mode driver can program HW and do the reset for > that VF. The PF driver being able to arbitrarily reset a VF device provided to another userspace process doesn't sound like separate, isolated devices. What else can the PF access? As noted in my other reply, vf-tokens should not be normalized and users of VFs provided by third party userspace PF drivers should consider the device no less tainted than if it were provided by an out-of-tree kernel driver. The idea to virtualize FLR on the VF to resolve the hardware defect is a good one, but it should be done in the context of a vfio-pci variant driver. Thanks, Alex > From: Leon Romanovsky <leon@kernel.org> > Date: Monday, February 5, 2024 at 17:04 > To: Deng, Emily <Emily.Deng@amd.com> > Cc: bhelgaas@google.com <bhelgaas@google.com>, > alex.williamson@redhat.com <alex.williamson@redhat.com>, > linux-pci@vger.kernel.org <linux-pci@vger.kernel.org>, > linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>, > kvm@vger.kernel.org <kvm@vger.kernel.org>, Jiang, Jerry (SW) > <Jerry.Jiang@amd.com>, Zhang, Andy <Andy.Zhang@amd.com>, Chang, > HaiJun <HaiJun.Chang@amd.com>, Liu, Monk <Monk.Liu@amd.com>, Chen, > Horace <Horace.Chen@amd.com>, Yin, ZhenGuo (Chris) > <ZhenGuo.Yin@amd.com> Subject: Re: [PATCH 1/2] PCI: Add VF reset > notification to PF's VFIO user mode driver On Mon, Feb 05, 2024 at > 03:15:37PM +0800, Emily Deng wrote: > > VF doesn't have the ability to reset itself completely which will > > cause the hardware in unstable state. So notify PF driver when the > > VF has been reset to let the PF resets the VF completely, and > > remove the VF out of schedule. > > > I'm sorry but this explanation is not different from the previous > version. Please provide a better explanation of the problem, why it is > needed, which VFs need and can't reset themselves, how and why it > worked before e.t.c. > > In addition, please follow kernel submission guidelines, write > changelong, add versions, cover letter e.t.c. > > Thanks > > > > > How to implement this? > > Add the reset callback function in pci_driver > > > > Implement the callback functin in VFIO_PCI driver. > > > > Add the VF RESET IRQ for user mode driver to let the user mode > > driver know the VF has been reset. > > > > Signed-off-by: Emily Deng <Emily.Deng@amd.com> > > --- > > drivers/pci/pci.c | 8 ++++++++ > > include/linux/pci.h | 1 + > > 2 files changed, 9 insertions(+) > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > index 60230da957e0..aca937b05531 100644 > > --- a/drivers/pci/pci.c > > +++ b/drivers/pci/pci.c > > @@ -4780,6 +4780,14 @@ EXPORT_SYMBOL_GPL(pcie_flr); > > */ > > int pcie_reset_flr(struct pci_dev *dev, bool probe) > > { > > + struct pci_dev *pf_dev; > > + > > + if (dev->is_virtfn) { > > + pf_dev = dev->physfn; > > + if (pf_dev->driver->sriov_vf_reset_notification) > > + > > pf_dev->driver->sriov_vf_reset_notification(pf_dev, dev); > > + } > > + > > if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) > > return -ENOTTY; > > > > diff --git a/include/linux/pci.h b/include/linux/pci.h > > index c69a2cc1f412..4fa31d9b0aa7 100644 > > --- a/include/linux/pci.h > > +++ b/include/linux/pci.h > > @@ -926,6 +926,7 @@ struct pci_driver { > > int (*sriov_configure)(struct pci_dev *dev, int num_vfs); > > /* On PF */ int (*sriov_set_msix_vec_count)(struct pci_dev *vf, > > int msix_vec_count); /* On PF */ u32 > > (*sriov_get_vf_total_msix)(struct pci_dev *pf); > > + void (*sriov_vf_reset_notification)(struct pci_dev *pf, > > struct pci_dev *vf); const struct pci_error_handlers *err_handler; > > const struct attribute_group **groups; > > const struct attribute_group **dev_groups; > > -- > > 2.36.1 > > > >
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 60230da957e0..aca937b05531 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4780,6 +4780,14 @@ EXPORT_SYMBOL_GPL(pcie_flr); */ int pcie_reset_flr(struct pci_dev *dev, bool probe) { + struct pci_dev *pf_dev; + + if (dev->is_virtfn) { + pf_dev = dev->physfn; + if (pf_dev->driver->sriov_vf_reset_notification) + pf_dev->driver->sriov_vf_reset_notification(pf_dev, dev); + } + if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) return -ENOTTY; diff --git a/include/linux/pci.h b/include/linux/pci.h index c69a2cc1f412..4fa31d9b0aa7 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -926,6 +926,7 @@ struct pci_driver { int (*sriov_configure)(struct pci_dev *dev, int num_vfs); /* On PF */ int (*sriov_set_msix_vec_count)(struct pci_dev *vf, int msix_vec_count); /* On PF */ u32 (*sriov_get_vf_total_msix)(struct pci_dev *pf); + void (*sriov_vf_reset_notification)(struct pci_dev *pf, struct pci_dev *vf); const struct pci_error_handlers *err_handler; const struct attribute_group **groups; const struct attribute_group **dev_groups;