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 08764C001DF for ; Wed, 26 Jul 2023 17:35:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232546AbjGZRff (ORCPT ); Wed, 26 Jul 2023 13:35:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232644AbjGZRfO (ORCPT ); Wed, 26 Jul 2023 13:35:14 -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 7E3F72685 for ; Wed, 26 Jul 2023 10:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690392867; 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=L06ULfrhr6hW9gvP83AY+VEDaqsbr34/NwjBXuEOU0w=; b=NyYImzB2t4fmQ2XlaHUQ5yNU2NgoI3wfyEHLAMSk/wA7QfDDIePTy2AUK5CVLC2oj3xl8o 89e/40tBMpNsr1C0940EGxO27MpaE5vlMHO9/R4bn4fZdG74tCNi1g9viOWnDi2SuCy2J4 xjVDrLnbdj3ipPft8GBEiSTddK31NeI= Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-342-2fu-VHNhOveo9VomLkmzjA-1; Wed, 26 Jul 2023 13:34:26 -0400 X-MC-Unique: 2fu-VHNhOveo9VomLkmzjA-1 Received: by mail-io1-f70.google.com with SMTP id ca18e2360f4ac-780addd7382so707139f.1 for ; Wed, 26 Jul 2023 10:34:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690392866; x=1690997666; h=content-transfer-encoding:mime-version:organization: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=L06ULfrhr6hW9gvP83AY+VEDaqsbr34/NwjBXuEOU0w=; b=GsGn1cB99Y5RYiVV40aNxupqWotJ/m/k4Jrv6XSTApqkpUwpyqhIRZXWzqux7Q3lxU w47QziPwnzuIIEe2nA+L+J+hRZmLQvcyGXvqQRd+7xw2jQc5WWoZzrz0ts/Lt4fKN61D wDyxVi8pOme8oxJ+MnZPp0gMsO2ssX3ibIMcNLe65NtC7ZZ7vaqcb0BSq2IbfDNU9rfC JRkQDp+N2ycTbYskKJ5nppu1qONP5CHImzlXKSDyk2GITccVXJOmqErEVW5qmIj/DWqM 8TenBzq8W+eddKjQ8MRR9GuLT97ViGfkgPMI/zEdfzKmAw5xTExmoigu5lIVfXIzNBX2 a/EA== X-Gm-Message-State: ABy/qLZBNdLyV1LgIrCKkTfEB9KDdiYJWiz9//8d+3sifbbvcYCBk0YE BJLsPQihiKKjrfOBbYMU3nYApDB7Zjgy55vCRAqYZBgnpwAd0l7E6dlX6fECmDcuD1W48t1YiRf 9bNqMR1Z9L0jl X-Received: by 2002:a05:6602:19c7:b0:783:6906:a32c with SMTP id ba7-20020a05660219c700b007836906a32cmr2715321iob.16.1690392865899; Wed, 26 Jul 2023 10:34:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlGr/w0JObmLyn2KNA8gvVrm90xfj5H02NMUwVxRdYRCVlbW1sfxWsJzqC1FqZ4V7KdvwQIing== X-Received: by 2002:a05:6602:19c7:b0:783:6906:a32c with SMTP id ba7-20020a05660219c700b007836906a32cmr2715306iob.16.1690392865656; Wed, 26 Jul 2023 10:34:25 -0700 (PDT) Received: from redhat.com ([38.15.60.12]) by smtp.gmail.com with ESMTPSA id p16-20020a02b390000000b004300d87030csm546160jan.109.2023.07.26.10.34.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 10:34:25 -0700 (PDT) Date: Wed, 26 Jul 2023 11:34:24 -0600 From: Alex Williamson To: Nicolin Chen Cc: , , , , , , , , , , , , Subject: Re: [PATCH v8 4/4] vfio: Support IO page table replacement Message-ID: <20230726113424.0e016e07.alex.williamson@redhat.com> In-Reply-To: <182b79f3838f84f220ede6089a0326b6f3f44acf.1690226015.git.nicolinc@nvidia.com> References: <182b79f3838f84f220ede6089a0326b6f3f44acf.1690226015.git.nicolinc@nvidia.com> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, 24 Jul 2023 12:47:07 -0700 Nicolin Chen wrote: > Now both the physical path and the emulated path should support an IO page > table replacement. Call iommufd_device_replace/iommufd_access_replace(), > when vdev->iommufd_attached is true. > > Also update the VFIO_DEVICE_ATTACH_IOMMUFD_PT kdoc in the uAPI header. > > Reviewed-by: Kevin Tian > Signed-off-by: Nicolin Chen > --- > drivers/vfio/iommufd.c | 11 ++++++----- > include/uapi/linux/vfio.h | 6 ++++++ > 2 files changed, 12 insertions(+), 5 deletions(-) Reviewed-by: Alex Williamson > > diff --git a/drivers/vfio/iommufd.c b/drivers/vfio/iommufd.c > index 4d84904fd927..82eba6966fa5 100644 > --- a/drivers/vfio/iommufd.c > +++ b/drivers/vfio/iommufd.c > @@ -146,9 +146,9 @@ int vfio_iommufd_physical_attach_ioas(struct vfio_device *vdev, u32 *pt_id) > return -EINVAL; > > if (vdev->iommufd_attached) > - return -EBUSY; > - > - rc = iommufd_device_attach(vdev->iommufd_device, pt_id); > + rc = iommufd_device_replace(vdev->iommufd_device, pt_id); > + else > + rc = iommufd_device_attach(vdev->iommufd_device, pt_id); > if (rc) > return rc; > vdev->iommufd_attached = true; > @@ -223,8 +223,9 @@ int vfio_iommufd_emulated_attach_ioas(struct vfio_device *vdev, u32 *pt_id) > lockdep_assert_held(&vdev->dev_set->lock); > > if (vdev->iommufd_attached) > - return -EBUSY; > - rc = iommufd_access_attach(vdev->iommufd_access, *pt_id); > + rc = iommufd_access_replace(vdev->iommufd_access, *pt_id); > + else > + rc = iommufd_access_attach(vdev->iommufd_access, *pt_id); > if (rc) > return rc; > vdev->iommufd_attached = true; > diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h > index fa06e3eb4955..537157ff8670 100644 > --- a/include/uapi/linux/vfio.h > +++ b/include/uapi/linux/vfio.h > @@ -939,6 +939,12 @@ struct vfio_device_bind_iommufd { > * Undo by VFIO_DEVICE_DETACH_IOMMUFD_PT or device fd close. This is only > * allowed on cdev fds. > * > + * If a vfio device is currently attached to a valid hw_pagetable, without doing > + * a VFIO_DEVICE_DETACH_IOMMUFD_PT, a second VFIO_DEVICE_ATTACH_IOMMUFD_PT ioctl > + * passing in another hw_pagetable (hwpt) id is allowed. This action, also known > + * as a hw_pagetable replacement, will replace the device's currently attached > + * hw_pagetable with a new hw_pagetable corresponding to the given pt_id. > + * > * Return: 0 on success, -errno on failure. > */ > struct vfio_device_attach_iommufd_pt {