Message ID | 58b67ca78925186b246ce8ed3639a1c92e56f98a.1678284812.git.nicolinc@nvidia.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp373774wrd; Wed, 8 Mar 2023 06:42:20 -0800 (PST) X-Google-Smtp-Source: AK7set8vAox/G2q4IXMIrltF9siXWLzmTGNlJR61gEVIjl2vefF7Pmakn7i4oAbImZ2B+eLfvGmS X-Received: by 2002:a17:902:ec81:b0:19c:f888:ad52 with SMTP id x1-20020a170902ec8100b0019cf888ad52mr23790813plg.49.1678286540262; Wed, 08 Mar 2023 06:42:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1678286540; cv=pass; d=google.com; s=arc-20160816; b=aCnkDD+LMkk74QMrAmUiRY8SZZtlfnLA+5xxS8yvZfTHA3Tv2UqT76ce5s6dcknMuA 0nTw8u+wA+o1t/Z9/96tanTeb7oeUgau3Un1aT0B99BGeacV1shYSMK5KIanE0yPO3dj 5piHFEsH67Y541X5KEBHJiCiAkp/wdCD58MPZk2TfPMOegukBxqjfOU9+SbNMYnWGGLn XqMioS1FboGv9u7n1EonGko2AO9UzwtXpEWZ/42ZITejyb7sMJZyww6f7AP4TUvXO1+8 ODb6FlesBrESo5z2uYvgRitJFlr+lizR2IBpWHU3B18QMFF34ADpAkNTb0UtJXc0xv4Y /e7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ASDw3GKkMVKHR5vFMjUe7HP5KDKS5oD9aQGH4N66VTc=; b=Hr9nKfgrt/2jfpHymOCFIxrv/6Cnum4X79/jXXfsmutYZnewT6ndm7eSb7T3+PBqRZ oQ0LoFkgtTF67PQr4LfePbxxmUmU5jsf2z/ooz7QWNVZDbvEbX11Hl6x8jWgXSIHYmgZ imS7ujmW2LwpFy0cVPNHem2KOa5bKriNvcq5QD+jDAuGGiewdO62Xmj1XA4K42kY2XxG 50yA1j4dqE78+bRzq1Z60cvEW15afbTH1I/Srn0gyOcO9wAxghdcxtIstiebFZeb+x1G Ctulo0FSx+MPU9Y7+bw6RmyxSzk8kM8YASU4Ww6/l7LuvIzQ1zY6sFXC7+BudN8YzXbr AsYg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=r3AFjY2o; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f18-20020a170902ce9200b0019e4154578esi16377988plg.76.2023.03.08.06.42.08; Wed, 08 Mar 2023 06:42:20 -0800 (PST) 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=@Nvidia.com header.s=selector2 header.b=r3AFjY2o; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231501AbjCHO0j (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Wed, 8 Mar 2023 09:26:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231402AbjCHO0g (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 8 Mar 2023 09:26:36 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2068.outbound.protection.outlook.com [40.107.100.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02A37C5604; Wed, 8 Mar 2023 06:26:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FfiPXlNWio6I1JkEO95ungASUprhjhfNCD1YMMCEfvYA8zi5gMIfj3XC/4Z4uFf5bPAqTZX+6PUUQyRcOzBkqgfyyKjatS7aNEjneYusoQmFs9/aKh4FurVBAinQG5/Ssw+mHwBgWu2M2/QsudGYubqfPSVi3QFR0TQbMM/fVUuJAVDvuWSXDDxk0yekNIyzuZ3+ic6vHbA69e9APNarzmz+I0SbmqyWjMU3qykZzSggNLwWJ5Js854vj/8h45GQSQJ2zI8wcG2mp0BbwAKdtcYqBXyoDQYaDkgkys2xWl8W2E1fHmxv9oRALgRtc4F6QVuVHJ5og7VwnrbcVuKJkw== 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=ASDw3GKkMVKHR5vFMjUe7HP5KDKS5oD9aQGH4N66VTc=; b=hIUxEqmDaya+OM5DSJAY9uCgJfRv7APmeQlemVFx8gW61xfq6EaorH6zGanqVnDoKIYxPHf3EGju/DMEoy/2Jb8oBuLZErBwn/tbXewE7DW2YiHxRriZUbGYvimEhdiaxlkZlakBfym2ld5D1OIDkhCKwcUgSogCkaoUhJueEJXFRxiSLCQHZerML2bo2bkR1I8fka/JWczWfyFbRSzvxft7dapshrSr2yAqG90uSSuj/cZMSzHn0QM5pBwMTIKz93t3mRJQpAIND4/VkhK8KcFYW84ExgOX6cd/wECl1UMtJbokl+LQyRzg5SA3gGBxQzGIrhcxCshOfRMy62YWcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ASDw3GKkMVKHR5vFMjUe7HP5KDKS5oD9aQGH4N66VTc=; b=r3AFjY2o5adBLD5mpOZ7WPJ/Xw2SWYffwYAzKmtc409DVsnZPBokBYfexUFKCT9Kh7QudgTNot9DkDeguabGZjyxQwwDpf7ODXuWJRong2jufj5aWUI9rHs7PHaq7lqOOeO7QHXwoCuE1+wmLMiO17ubgUllraLt5PhvlNWbuw6H0xSjf/ima4wT2uxWY7CX+vMNHqGdrR1V6qL1bvC0DPZZ2hbRDxMGhPeiGEySvu7o6u7bdNtugJpBnXczmvwhJTdOp5yMa9v3l1FO6OPcytY/kMMtO/Bm5fn3PnJGSiJH64fVema1gUKL31vUcADy3ulCKv92DeErT6KFbz4QSQ== Received: from BN9PR03CA0087.namprd03.prod.outlook.com (2603:10b6:408:fc::32) by PH7PR12MB7891.namprd12.prod.outlook.com (2603:10b6:510:27a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17; Wed, 8 Mar 2023 14:26:31 +0000 Received: from BN8NAM11FT108.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fc:cafe::14) by BN9PR03CA0087.outlook.office365.com (2603:10b6:408:fc::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29 via Frontend Transport; Wed, 8 Mar 2023 14:26:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN8NAM11FT108.mail.protection.outlook.com (10.13.176.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17 via Frontend Transport; Wed, 8 Mar 2023 14:26:31 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 8 Mar 2023 06:26:22 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 8 Mar 2023 06:26:21 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 8 Mar 2023 06:26:21 -0800 From: Nicolin Chen <nicolinc@nvidia.com> To: <jgg@nvidia.com>, <kevin.tian@intel.com>, <joro@8bytes.org>, <will@kernel.org>, <robin.murphy@arm.com>, <alex.williamson@redhat.com>, <shuah@kernel.org> CC: <yi.l.liu@intel.com>, <linux-kernel@vger.kernel.org>, <iommu@lists.linux.dev>, <kvm@vger.kernel.org>, <linux-kselftest@vger.kernel.org>, <mjrosato@linux.ibm.com>, <farman@linux.ibm.com> Subject: [PATCH v4 3/5] iommufd: Add replace support in iommufd_access_set_ioas() Date: Wed, 8 Mar 2023 06:26:00 -0800 Message-ID: <58b67ca78925186b246ce8ed3639a1c92e56f98a.1678284812.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <cover.1678284812.git.nicolinc@nvidia.com> References: <cover.1678284812.git.nicolinc@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT108:EE_|PH7PR12MB7891:EE_ X-MS-Office365-Filtering-Correlation-Id: fe2b4725-ebe6-415f-0fad-08db1fe11cc0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GpGScsGc0ZD6qJ6b4INqyG7YZs2hUlLVAge0IOVF8WppyM6j0Age0OUTTyFJlEp3EZGIolqK3J3nRiY8Ze/uBQRUraqyTqLNnpuFxPONAAtTHuc3zRqu616sIbbVlZWLG2v5h40mqu8HsfH6EuDwg6UgtWDxYhks0jDB5l4kGdQYkgXPwvgqrWyjaiPrfa8ykdBZZUsBCNmZR5YkB26H/gbj0sVkaZ5BhMOVHAHXU/zeoBApQU4ajSSK0Siq/x5mmdAY873mI3oOm6BTm+GroeP//PnYHzVzx8RDEDR2Nlu7BhtjP1xkVE07F5sFHzF73cGFkL8/A+tAfL1igmBpZfQyt8YLwhE3yeYOP+0apjWEhpTTceiwQ3UPr/F1gzQjtSoy/L9Lbe4QBiwfwpNel8E93U2cTjFelPQUNOgRlcxaY+HN1h+UdFaDEOxrD6e6ZkPSg3jJ+oQKYJ42N0kq7AceNWGPih7pIwSNpNydsUVdRKutdROvcL1lz1SOfrXub6M0cNEauqxXSexdP4FxljkRCXPc9mTafp+MtEq/vuOiyHski/xZwgZXEdTw4ixo+BeZzOE+68NjxZANtdu+RobP6e1BPDLwxqPqi7JpXCYVivyO9d/Nz7jhn6cTov4cPCRas8lecafKc+u3N6gJgDzRXi+39wbzjGJ90+HQVFM9QSTWhpNJJ7WHn6JxOrG8qYPD6CL+5pX+dc4ZiqzzQw== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(376002)(39860400002)(346002)(136003)(396003)(451199018)(36840700001)(46966006)(40470700004)(82310400005)(86362001)(41300700001)(6666004)(8676002)(70206006)(70586007)(47076005)(426003)(36756003)(336012)(40480700001)(7696005)(316002)(110136005)(4326008)(40460700003)(54906003)(83380400001)(2906002)(186003)(478600001)(7636003)(82740400003)(26005)(356005)(8936002)(2616005)(36860700001)(7416002)(5660300002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2023 14:26:31.1633 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe2b4725-ebe6-415f-0fad-08db1fe11cc0 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT108.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7891 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,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, URIBL_BLOCKED autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759810986857924078?= X-GMAIL-MSGID: =?utf-8?q?1759810986857924078?= |
Series |
Add IO page table replacement support
|
|
Commit Message
Nicolin Chen
March 8, 2023, 2:26 p.m. UTC
Support an access->ioas replacement in iommufd_access_set_ioas(), which
sets the access->ioas to NULL provisionally so that any further incoming
iommufd_access_pin_pages() callback can be blocked.
Then, call access->ops->unmap() to clean up the entire iopt. To allow an
iommufd_access_unpin_pages() callback to happen via this unmap() call,
add an ioas_unpin pointer so the unpin routine won't be affected by the
"access->ioas = NULL" trick above.
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/iommufd/device.c | 17 +++++++++++++++--
drivers/iommu/iommufd/iommufd_private.h | 1 +
2 files changed, 16 insertions(+), 2 deletions(-)
Comments
> From: Nicolin Chen <nicolinc@nvidia.com> > Sent: Wednesday, March 8, 2023 10:26 PM > > Support an access->ioas replacement in iommufd_access_set_ioas(), which > sets the access->ioas to NULL provisionally so that any further incoming > iommufd_access_pin_pages() callback can be blocked. > > Then, call access->ops->unmap() to clean up the entire iopt. To allow an > iommufd_access_unpin_pages() callback to happen via this unmap() call, > add an ioas_unpin pointer so the unpin routine won't be affected by the > "access->ioas = NULL" trick above. > > Suggested-by: Jason Gunthorpe <jgg@nvidia.com> > Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 612a5f424bd7..c10e02f6a0be 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -727,11 +727,24 @@ int iommufd_access_set_ioas(struct iommufd_access *access, u32 ioas_id) iommufd_ref_to_users(obj); } + /* + * Set ioas to NULL to block any further iommufd_access_pin_pages(). + * iommufd_access_unpin_pages() can continue using access->ioas_unpin. + */ + access->ioas = NULL; + + if (access->ops->unmap) { + mutex_unlock(&access->ioas_lock); + access->ops->unmap(access->data, 0, ULONG_MAX); + mutex_lock(&access->ioas_lock); + } + if (cur_ioas) { iopt_remove_access(&cur_ioas->iopt, access); refcount_dec(&cur_ioas->obj.users); } + access->ioas_unpin = new_ioas; access->ioas = new_ioas; mutex_unlock(&access->ioas_lock); @@ -805,11 +818,11 @@ void iommufd_access_unpin_pages(struct iommufd_access *access, return; mutex_lock(&access->ioas_lock); - if (!access->ioas) { + if (!access->ioas_unpin) { mutex_unlock(&access->ioas_lock); return; } - iopt = &access->ioas->iopt; + iopt = &access->ioas_unpin->iopt; down_read(&iopt->iova_rwsem); iopt_for_each_contig_area(&iter, area, iopt, iova, last_iova) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index db1ead8ff9d0..b18f843ad6a4 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -312,6 +312,7 @@ struct iommufd_access { struct iommufd_object obj; struct iommufd_ctx *ictx; struct iommufd_ioas *ioas; + struct iommufd_ioas *ioas_unpin; struct mutex ioas_lock; const struct iommufd_access_ops *ops; void *data;