Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3255355rdb; Tue, 6 Feb 2024 11:38:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHh1bJLmlXSSTKlQdaTe3pWW+8aI0b7xmVGDCmhWv6rZ/ikU8SK/UfP6Ari0JAUh7h/Pa/S X-Received: by 2002:a05:6402:14c8:b0:55f:fb25:47d9 with SMTP id f8-20020a05640214c800b0055ffb2547d9mr2569446edx.8.1707248328549; Tue, 06 Feb 2024 11:38:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707248328; cv=pass; d=google.com; s=arc-20160816; b=mLCIFBKlUh2YWBXeOi6uZOFShv7/Lnl1dYF+bAu2WtkDAe6/DnO5bU4GITnHAoM5bw Fm35NjxYRKyIYP6k2YQlwMgSUEXbWs0NnZNyi4pSapKKZfL3KUEQIo3z1qFpHPeib3PF LRgxP5qtW0dqtOYrQ8sZHMzVmdQNek1cWPNdRb+rhvseWy1gqe+GkuWwh2YzSh2+KEnW nlu0p2QEYGBKm7996w0JF8b3afre4dSM908/yNVb1wAjU8zX81RE0T+8EVDAAldbyQBg 0ymIm5yLS5BnrpAK7S/31NKEBKJ17CSRdohF/bT6xrWGtzepR8wjAA5Z9GUQOxcvVSPf mrEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=MqPXh+3PVtuj68WUVgRk8x+eLMW85S8wemYEFlZX5vA=; fh=EWXKRYj34A+gW7g961azjx6epSBbu0pV6bCdjx6uuAs=; b=tI/CE6AHW1edHvLYVhJm3K+dz2rX1CXKM3R4UjeI846o+VF9LAWLR1sQ2dKDjbGOjX lpCReRw3rRFU69aADjokMA2REf8cXFfKMEVqKPayW7VZIBD5iUgBO3v36NWvipHqt5zz T+XdLNmQN3PYqZQ3VrjLyTWiKql3FrPMdT3B0+XoxBZpBTx9O9RokIUI2yRAp1d9Bqn2 C2MMt2OlPWSZF3w360qqbPUbj8PhbhtUFoiKDVOG20pwufhAMi8kH9ZaIJmu+NRZEGo5 XYWn4RrYK2PkKZtP3MUrhr4CGrRcGVimUmYizoKbGGBfl4BgKDEVvgDGPzhv0RiBMQuz mmVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Slrs2rNJ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-55564-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55564-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWed2LyuASYwf1Gp2g5rh9qQsw5In4jH8+nWx7gquAG1kkJglCA/cYD1i4kIW5NJ9K1TZcPZ/wfYhjda6CPvhlHL70R/ZwLs4zmXYKVLQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x2-20020a05640226c200b0055f9b95bd23si1496535edd.309.2024.02.06.11.38.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 11:38:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55564-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Slrs2rNJ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-55564-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55564-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 20FB71F24440 for ; Tue, 6 Feb 2024 19:38:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B106117579; Tue, 6 Feb 2024 19:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Slrs2rNJ" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 B57CD175B4 for ; Tue, 6 Feb 2024 19:38:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707248318; cv=none; b=U597bcE4FyVXMsYYceUHdtAGR0C+wm2mUgvPnc381DnbxgaovxidAo++WnB+Y6K58dAyyyjVBnXFijF1fN3Gv5b++1LhCpoblUd9UpIUmY6R3ADa5qMlgbmtTdH/HQEWJk+UNhTkFMhPkOXexMK3jgtoIXXmq92gL3WOw46q5Qk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707248318; c=relaxed/simple; bh=1RKHX581Bljkl+OsLAv6WNsHz+SuqRDwBI74iH/Yddw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ge4o03naNvHYz5f5tGoms7GaPn9HYevojBvDVLe60KQnZDDNK2sKia6CjrAY4Xj1qYXDxX0qeL3nE2XxffyAdxIPmZimUUW0EdkPr/1amGTvlpa51d97i20BADZGvq+rH7BqqLKf2lbddb9s1uQ6ny6N8P+vc/bKA9kgpN42YN4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Slrs2rNJ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707248315; h=from:from: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; bh=MqPXh+3PVtuj68WUVgRk8x+eLMW85S8wemYEFlZX5vA=; b=Slrs2rNJRTLpWiYR0+gkEOhBtO6mBnMCXJpULDLcvdNicgFGElaDAVBuD7nklj1sCMPwHs NOO5761Gkk4dMW1FTcDGFGjdHmLW7g6kMkrBLtZu74RIn9aKmk3fJebnOahR55FP1NZuh6 WhuVrbMdWqCvZ3Z6+zk5hvvTflhriok= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-189-m556owSiO9-iEIg6YEJCPg-1; Tue, 06 Feb 2024 14:38:34 -0500 X-MC-Unique: m556owSiO9-iEIg6YEJCPg-1 Received: by mail-io1-f69.google.com with SMTP id ca18e2360f4ac-7bf36117dfbso755710939f.3 for ; Tue, 06 Feb 2024 11:38:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707248313; x=1707853113; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MqPXh+3PVtuj68WUVgRk8x+eLMW85S8wemYEFlZX5vA=; b=EvQt6E6W4+726fg2kAnamLGVIwMszFwFMAYhhGhnxBIlabH+SSH6+blWjoiu+rUPlW hJTvtUcLMF+5dqjhHxV0CK/qcAe5COlqUDkzt7Ka00Hz3QPaMWWIvxgrGOpwVYGEUm8x cE6K1snhSId4jvgRTpe2stlsZcWF/3DRVK75PJXyJh6BjVrJkQZHSguIHgqtZk1LBESp 8JI9fu9ccIH6wesZEOvhgTmbvTptHcysH6bZxcxFhpKNGgYA8phuhUk4NwMXeOw8j14b qLStTF/cKg6a/99hlkgC3J3zCXLmpXiJHNQxV1pG8eYvlEOelOi5hrJBGW6AL75kX2yc OU8g== X-Gm-Message-State: AOJu0Ywfn03tugL1phbAyLz7Sh4B8RtHPXPL+Sf3kjWsh/3ceow5A5Fm DYSGoCGpX1LESo4ObumlQ4K4IEduGtDwZcBrrRY76a9ElaJuUgBsAYeIGhap7ZsH0vIXofboF8A vox92EEx03hAziNG2yP3+gW2mhIAhl61TLp0aIxkvBXVZEYWfjTE02bfSLdyEgQ== X-Received: by 2002:a05:6602:1782:b0:7c3:e96a:5fcb with SMTP id y2-20020a056602178200b007c3e96a5fcbmr4047129iox.7.1707248313339; Tue, 06 Feb 2024 11:38:33 -0800 (PST) X-Received: by 2002:a05:6602:1782:b0:7c3:e96a:5fcb with SMTP id y2-20020a056602178200b007c3e96a5fcbmr4047115iox.7.1707248313038; Tue, 06 Feb 2024 11:38:33 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUklQHg+GFkFMMkX7zIASOCS4WYlYMt6/OK8XEGCMIThxt3GltvUMryfQmnZUfTVugZhONPd0bEifL7tGGwxsrTNjU6UIh8MVllqIbOtyA52qdTjpT24DJjpmQF0dyQIf0sa7mrxRrugORtqAWgjzTZQ56Z2F0+erf99ZilkdIANeFU9Hqf7KrAmsybt9+maJ3A67zNYaNRWu+wpkKVEDrzDoCMdKUHEHPaSf/xCo9j0xCRGsneC7bkpMExZERTqjNd2TKfdbylC/GEjr0AEUZscdZVFByWBYRw5v/P+tSQkw7nX1aWOppish53pwsy9Gx8e1eUjUIiiKlc Received: from redhat.com ([38.15.36.11]) by smtp.gmail.com with ESMTPSA id bs14-20020a056e02240e00b0036381100013sm720530ilb.67.2024.02.06.11.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 11:38:32 -0800 (PST) Date: Tue, 6 Feb 2024 12:38:30 -0700 From: Alex Williamson To: "Liu, Monk" Cc: "Deng, Emily" , "bhelgaas@google.com" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "Jiang, Jerry (SW)" , "Zhang, Andy" , "Chang, HaiJun" , "Chen, Horace" , "Yin, ZhenGuo (Chris)" Subject: Re: [PATCH 1/2] PCI: Add VF reset notification to PF's VFIO user mode driver Message-ID: <20240206123830.7b330790.alex.williamson@redhat.com> In-Reply-To: References: <20240205071538.2665628-1-Emily.Deng@amd.com> <20240205094330.59ca4c0a.alex.williamson@redhat.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.38; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 6 Feb 2024 04:03:46 +0000 "Liu, Monk" wrote: > [AMD Official Use Only - General] >=20 > Hi Alex >=20 > Thanks for your comment, I=E2=80=99m still not quite following you. >=20 > >>This can be done by intercepting the userspace access to the VF FLR con= fig space region. =20 >=20 > 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=E2=80=99s vfio arch is running there, and it = want > to receive VF=E2=80=99s reset request (by Qemu through vfio interface), a= nd > do some hw/fw sequences to achieve the real Vf reset goal >=20 > >>. I don't see that facilitating vendors to implement their PF > >>drivers in userspace to avoid upstreaming =20 > is a compelling reason to extend the vfio-pci interface. >=20 > Some background here (our user mode PF driver is not given the > purpose to avoid upstream): We don=E2=80=99t 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=E2=80=99t see where the appropriate repo for it is = to > upstream to =E2=80=A6 (we cannot make it in Qemu right ? otherwise Qemu w= ill > 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. =20 > Isn=E2=80=99t 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 > Date: Tuesday, February 6, 2024 at 00:43 > To: Deng, Emily > Cc: bhelgaas@google.com , > linux-pci@vger.kernel.org , > linux-kernel@vger.kernel.org , > kvm@vger.kernel.org , Jiang, Jerry (SW) > , Zhang, Andy , Chang, > HaiJun , Liu, Monk , Chen, > Horace , Yin, ZhenGuo (Chris) > 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 wrote: >=20 > > 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. =20 >=20 > 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. >=20 > 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, >=20 > Alex >=20 > > Signed-off-by: Emily Deng > > --- > > 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 =3D 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; =20