Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1345177rwb; Wed, 26 Jul 2023 11:02:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlGJ98aYpGYBaw3DlLJ2aLZSnZhT8p39xSJeFpRmRyZc90NESZwbDkcYtJkBJb7jbZQflTGW X-Received: by 2002:a17:902:e844:b0:1bb:5d9a:9054 with SMTP id t4-20020a170902e84400b001bb5d9a9054mr3456400plg.12.1690394535304; Wed, 26 Jul 2023 11:02:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690394535; cv=none; d=google.com; s=arc-20160816; b=a7XITKqYyWGit2L1QZcEwFoEtux7QzSJf5j0s35JQjk48xnZVzfi1Rv213UC7A9Mya /7yKI/sbXVNKnGt/1nS8B25YK53oIXEgDGK569ThcJYiD3gBIXVKseALSGNZBv1MafNI R7D8dxfGdQn9D30WQTYLe+O1GPEeYkcBAARvi95RDxSmW3sh8H8vfBZkqrI0a2+uRs49 WamVpNPQ1pz5WSqDOJbu06QHJO64awOPJwF9tVNDg6oeesUkbDO/Yxwzee4MeVdlX7bz ESDJBhas2tI3pNnNZajTaRargU9lcQcj/o5FiUTJNZ50j1quHT4G90wldFUNcq3qCgcq G6eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=L06ULfrhr6hW9gvP83AY+VEDaqsbr34/NwjBXuEOU0w=; fh=RQnaglbUlGrjnFJJ4F4l5AOfSBCe72V5TeoRbN2brXE=; b=dQBxGr9kCoiHNA0WhijzivVyfDNwyUuWMDCG9udDk0rYBnGfCqycUMk+tDD0FQQsOD xZrbJxVaI+vGbueoXU+XzW9z3NavjS7ANEsdnazt9VjTq7MgjK07sLpJbCDC0gGquJw4 S5sx2EzGeIJ5u3M8x6Wr4d4pCrNqtArfgV86aRi9c5xVXYM6gBS455bAfuIO5LSHGKoJ wxFs/jpbK1b/wpjb8qca7TxujFFIDL9AINWxnd6ySl0crr4T5D4PyXV3i9Pi00Ko18lS NkI/GvrhzgD34uKUQajNHhPlkh16OaENDPNjCUykU9Rsw9tBbuu/NvK1C8K764wHW0+l Q8IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BVKuA3w+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u186-20020a6379c3000000b00553ebb05d14si13265390pgc.111.2023.07.26.11.01.57; Wed, 26 Jul 2023 11:02:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BVKuA3w+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230455AbjGZRff (ORCPT + 99 others); Wed, 26 Jul 2023 13:35:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232642AbjGZRfO (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 15A572697 for ; Wed, 26 Jul 2023 10:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690392868; 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=BVKuA3w+MzxpfsX3HwIc7eSHy2eMdlwsnO4YEp6b9AwFSVpDYQfptQTleBaHiZ+aCB9FA3 WkjALvi03LovDfFEpc6hAO4FS26UxWsQJz3LI626enkEREcqrpvss3oSUBl+vp14m5y+iK PaeH9mytOewavbnA97DCF2cL+oHgeoQ= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-402-Nr_2BWezMXeTAeTR82aNAA-1; Wed, 26 Jul 2023 13:34:26 -0400 X-MC-Unique: Nr_2BWezMXeTAeTR82aNAA-1 Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-780addd7382so707239f.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=EeYNw0UPaE+h/e8BHIRIOGl03i0oaVhBRcCnGs2+7CH1W6tJp3cvX4aGl41dS8KRoX x3V17FF2yGODcH0cxOprCFjJBbyYohKz7Mdmn3hTFkAmsIv32+zwrdnn2XcoMgerqktN 3w4snB1QSH3qgaueHPyrR+VE/P7GkmQVLt4Kb2f1SMb8sEiHDHYRbNdPcvqbkXE+SlAT OP59qCWVASsFhw3oQYno093Ev7Wy7p1kIjGWfaYq56FTF/PuK9O2K/Et6JwObk3cjniP ZxM7iRWgHylJ/ENwp2y67eGq5j0JkKWB+KU46tIZuQnXotpftnnD8BGqzLiQkFVMUVqY dIDQ== X-Gm-Message-State: ABy/qLZGPJZ9IUhlNT4UJOma58kjqvuMF+WvUm/3dTBkhUllHMC9Jr30 Aezm/5MB2FOtsyoZi3FnOzdkHXtegtsk65OECM80svdM6FnQTOJ9i0royYgh/mO37QN4qoK9Q3s YDhXhlMuAmybaK7QS3UqMBYxx X-Received: by 2002:a05:6602:19c7:b0:783:6906:a32c with SMTP id ba7-20020a05660219c700b007836906a32cmr2715328iob.16.1690392865997; Wed, 26 Jul 2023 10:34:25 -0700 (PDT) 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 {