From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F27C1EB64D7 for ; Tue, 13 Jun 2023 15:05:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242982AbjFMPFC (ORCPT ); Tue, 13 Jun 2023 11:05:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242957AbjFMPE5 (ORCPT ); Tue, 13 Jun 2023 11:04:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A263C10FC for ; Tue, 13 Jun 2023 08:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686668655; 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=YydBu9r/6A39lhq1fyNCaOJcqqvwoNcoQa6tVejSDeQ=; b=CA13gdcdyKqw9nX9yHnu8WyHzZBV0aijgHJ5NePezdjU5L28H7X0x0k+IdaBck796MsEPf sxhKvgdLW86qDKdBxLw1TkzBACx1yHESDi1pSgNgzg1ZYr/4184UX+8ZteMEOgrv+E4H6h /MeRmrudguH3RvMZDtjTC3ecv0COaIY= Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-484-qvhU1-gLOLWl77OrYRQFkA-1; Tue, 13 Jun 2023 11:04:08 -0400 X-MC-Unique: qvhU1-gLOLWl77OrYRQFkA-1 Received: by mail-il1-f197.google.com with SMTP id e9e14a558f8ab-33d93feefb5so49465135ab.1 for ; Tue, 13 Jun 2023 08:04:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686668646; x=1689260646; 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=YydBu9r/6A39lhq1fyNCaOJcqqvwoNcoQa6tVejSDeQ=; b=LmBwC/Mn/JMmTSutF9z9BYVNYfL2x+n9JC6WL//x8oxuH7Qwo46ZWaBdIBhmxLtU8Q bexnIYsxFXP+xpWuti/KC8CJ0gIA/kaGh8jLFyeZKYkIoS7PHzDNiGykczjJSXAkiCKc PxdVaDAvbiJYgtVcBYENnGxuY2RhWEMysrxsDRlGQ4BSh0Wbsv7Ygp+CkY9YLx2/+gXF IyItNnjdQg3Mf4V9AFC/e5y5UKqt6RTclgk62aXwpFDOvdzB2GGTphB4zw+9XnHgd4D3 Jc+T8z8XX8a3/vvuRSdwkkx2Q+QfLi312sRPSkJjFIuZKtLWAXDLlPfalp2SaTJr062T u+6w== X-Gm-Message-State: AC+VfDz0auf3cV5KJoFc35y469ogLxhaj9nmbH0YfLgtHeq54JWQ9dkP vVH1GCqXpx1SslS6EpqPOx3agCNokmTsb/fPCvgJNq6zyfdymeJz5dggCLQ3eFG83LQSd5xRm49 OtC2wGOlkjc+PKyC3VZJaJA== X-Received: by 2002:a92:4a10:0:b0:33d:6988:c00f with SMTP id m16-20020a924a10000000b0033d6988c00fmr10759835ilf.23.1686668645666; Tue, 13 Jun 2023 08:04:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hRUczWeT/vsf09o44UFWMaqisCqWHnjTGKmeIzpiXZMGJpdYNOuBusIkgotULHLq+g9dlEQ== X-Received: by 2002:a92:4a10:0:b0:33d:6988:c00f with SMTP id m16-20020a924a10000000b0033d6988c00fmr10759765ilf.23.1686668645012; Tue, 13 Jun 2023 08:04:05 -0700 (PDT) Received: from redhat.com ([38.15.36.239]) by smtp.gmail.com with ESMTPSA id m10-20020a924b0a000000b0033355fa5440sm3963186ilg.37.2023.06.13.08.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 08:04:04 -0700 (PDT) Date: Tue, 13 Jun 2023 09:04:03 -0600 From: Alex Williamson To: "Liu, Yi L" Cc: "jgg@nvidia.com" , "Tian, Kevin" , "joro@8bytes.org" , "robin.murphy@arm.com" , "cohuck@redhat.com" , "eric.auger@redhat.com" , "nicolinc@nvidia.com" , "kvm@vger.kernel.org" , "mjrosato@linux.ibm.com" , "chao.p.peng@linux.intel.com" , "yi.y.sun@linux.intel.com" , "peterx@redhat.com" , "jasowang@redhat.com" , "shameerali.kolothum.thodi@huawei.com" , "lulu@redhat.com" , "suravee.suthikulpanit@amd.com" , "intel-gvt-dev@lists.freedesktop.org" , "intel-gfx@lists.freedesktop.org" , "linux-s390@vger.kernel.org" , "Hao, Xudong" , "Zhao, Yan Y" , "Xu, Terrence" , "Jiang, Yanting" , "Duan, Zhenzhong" , "clegoate@redhat.com" Subject: Re: [PATCH v12 24/24] docs: vfio: Add vfio device cdev description Message-ID: <20230613090403.1eecd1a3.alex.williamson@redhat.com> In-Reply-To: References: <20230602121653.80017-1-yi.l.liu@intel.com> <20230602121653.80017-25-yi.l.liu@intel.com> <20230612170628.661ab2a6.alex.williamson@redhat.com> <20230613082427.453748f5.alex.williamson@redhat.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.35; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-s390@vger.kernel.org On Tue, 13 Jun 2023 14:48:02 +0000 "Liu, Yi L" wrote: > > From: Alex Williamson > > Sent: Tuesday, June 13, 2023 10:24 PM > > > > On Tue, 13 Jun 2023 12:01:51 +0000 > > "Liu, Yi L" wrote: > > > > > > From: Alex Williamson > > > > Sent: Tuesday, June 13, 2023 7:06 AM > > > > > > > > On Fri, 2 Jun 2023 05:16:53 -0700 > > > > Yi Liu wrote: > > > > > > > > > This gives notes for userspace applications on device cdev usage. > > > > > > > > > > Reviewed-by: Kevin Tian > > > > > Signed-off-by: Yi Liu > > > > > --- > > > > > Documentation/driver-api/vfio.rst | 132 ++++++++++++++++++++++++++++++ > > > > > 1 file changed, 132 insertions(+) > > > > > > > > > > diff --git a/Documentation/driver-api/vfio.rst b/Documentation/driver-api/vfio.rst > > > > > index 363e12c90b87..f00c9b86bda0 100644 > > > > > --- a/Documentation/driver-api/vfio.rst > > > > > +++ b/Documentation/driver-api/vfio.rst > > > > > @@ -239,6 +239,130 @@ group and can access them as follows:: > > > > > /* Gratuitous device reset and go... */ > > > > > ioctl(device, VFIO_DEVICE_RESET); > > > > > > > > > > +IOMMUFD and vfio_iommu_type1 > > > > > +---------------------------- > > > > > + > > > > > +IOMMUFD is the new user API to manage I/O page tables from userspace. > > > > > +It intends to be the portal of delivering advanced userspace DMA > > > > > +features (nested translation [5]_, PASID [6]_, etc.) while also providing > > > > > +a backwards compatibility interface for existing VFIO_TYPE1v2_IOMMU use > > > > > +cases. Eventually the vfio_iommu_type1 driver, as well as the legacy > > > > > +vfio container and group model is intended to be deprecated. > > > > > + > > > > > +The IOMMUFD backwards compatibility interface can be enabled two ways. > > > > > +In the first method, the kernel can be configured with > > > > > +CONFIG_IOMMUFD_VFIO_CONTAINER, in which case the IOMMUFD subsystem > > > > > +transparently provides the entire infrastructure for the VFIO > > > > > +container and IOMMU backend interfaces. The compatibility mode can > > > > > +also be accessed if the VFIO container interface, ie. /dev/vfio/vfio is > > > > > +simply symlink'd to /dev/iommu. Note that at the time of writing, the > > > > > +compatibility mode is not entirely feature complete relative to > > > > > +VFIO_TYPE1v2_IOMMU (ex. DMA mapping MMIO) and does not attempt to > > > > > +provide compatibility to the VFIO_SPAPR_TCE_IOMMU interface. Therefore > > > > > +it is not generally advisable at this time to switch from native VFIO > > > > > +implementations to the IOMMUFD compatibility interfaces. > > > > > + > > > > > +Long term, VFIO users should migrate to device access through the cdev > > > > > +interface described below, and native access through the IOMMUFD > > > > > +provided interfaces. > > > > > + > > > > > +VFIO Device cdev > > > > > +---------------- > > > > > + > > > > > +Traditionally user acquires a device fd via VFIO_GROUP_GET_DEVICE_FD > > > > > +in a VFIO group. > > > > > + > > > > > +With CONFIG_VFIO_DEVICE_CDEV=y the user can now acquire a device fd > > > > > +by directly opening a character device /dev/vfio/devices/vfioX where > > > > > +"X" is the number allocated uniquely by VFIO for registered devices. > > > > > +cdev interface does not support noiommu, so user should use the legacy > > > > > +group interface if noiommu is needed. > > > > > + > > > > > +The cdev only works with IOMMUFD. Both VFIO drivers and applications > > > > > +must adapt to the new cdev security model which requires using > > > > > +VFIO_DEVICE_BIND_IOMMUFD to claim DMA ownership before starting to > > > > > +actually use the device. Once BIND succeeds then a VFIO device can > > > > > +be fully accessed by the user. > > > > > + > > > > > +VFIO device cdev doesn't rely on VFIO group/container/iommu drivers. > > > > > +Hence those modules can be fully compiled out in an environment > > > > > +where no legacy VFIO application exists. > > > > > + > > > > > +So far SPAPR does not support IOMMUFD yet. So it cannot support device > > > > > +cdev neither. > > > > > > > > s/neither/either/ > > > > > > Got it. > > > > > > > > > > > Unless I missed it, we've not described that vfio device cdev access is > > > > still bound by IOMMU group semantics, ie. there can be one DMA owner > > > > for the group. That's a pretty common failure point for multi-function > > > > consumer device use cases, so the why, where, and how it fails should > > > > be well covered. > > > > > > Yes. this needs to be documented. How about below words: > > > > > > vfio device cdev access is still bound by IOMMU group semantics, ie. there > > > can be only one DMA owner for the group. Devices belonging to the same > > > group can not be bound to multiple iommufd_ctx. > > > > ... or shared between native kernel and vfio drivers. > > I suppose you mean the devices in one group are bound to different > drivers. right? Essentially, but we need to be careful that we're developing multiple vfio drivers for a given bus now, which is why I try to distinguish between the two sets of drivers. Thanks, Alex > > > The users that try to bind > > > such device to different iommufd shall be failed in VFIO_DEVICE_BIND_IOMMUFD > > > which is the start point to get full access for the device. > > > > "A violation of this ownership requirement will fail at the > > VFIO_DEVICE_BIND_IOMMUFD ioctl, which gates full device access." > > Got it. > > Regards, > Yi Liu >