From patchwork Wed Jul 6 06:27:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12907353 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 8B348C433EF for ; Wed, 6 Jul 2022 06:28:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229455AbiGFG2S (ORCPT ); Wed, 6 Jul 2022 02:28:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbiGFG2Q (ORCPT ); Wed, 6 Jul 2022 02:28:16 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2066.outbound.protection.outlook.com [40.107.100.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 816517650; Tue, 5 Jul 2022 23:28:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S/NaYOk3M/wyEvGJAdA2STUQSJEtMyWir5Uud9c70VI7ruhOtAIA/YVeOxQIZ5wbd0yjhGtKdbhN9UdN94VJuJVHFvAVhhJHS2T2dxfMSAr4doR2usviZB0kIcNWKaa2b+++QbvnypoZLTYqzHsjf2GmyecTPIEZOxIxFQy2F7sXowuYu9308VbOV75ZR5FRJU1TVseqlhxtAUZG2DOknBL4Yst3QBLHOFvxfXzQ3AeJVHPQwFiKo+64Af+YcCz+hdQOurvUmB56PQ6PHP45/VWvNG0sfbx3+gF0S0V6oJgM1RHucDSUy49Qh+lvlzevKyHmvkdYAUA3AKWIxYgHhA== 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=LIc8WOGbQqnWuegxZUpyT8c7k0yV0Mb/niYZFvLPTUY=; b=Q6Eb7BW4OyMnvp5WB44dUrRoOgggwvKtscWXnDk0M6DpE7wAj8TW6fT8iEdoZi9MlLcrwCKg6vjPG1iPLab5PzvQGBCbBRjHKFWTWSRuh6oAPO6Ouj3jghKkvlPXJc6p5mn/U0faBFEZNwjMHE0FJgg3kklfcIaaWQMvkJhbrDudaOvUlH9WI/cf/qbBV2+81FDCb/8ftSokF8ORDiOZKha5IRFgyVsX+WZ3w+uPKaFi9bewJW5szhbqXXJvx+P29+KznbvQ0T2UAVTXvOAuGepa4vLRP+ef/1uxfYs7tK7VaKFT5aX88p/rSk8NMnFlqct2ub817+w752D++2Fj/A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=linux.ibm.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=LIc8WOGbQqnWuegxZUpyT8c7k0yV0Mb/niYZFvLPTUY=; b=g3tbaWsqGzRx/cpA0Zxed+T0UfgGObJvdKC1LCXZ6wMMSzQIVf4boW2zp7WF4yVdPwapeNKFCNS9ca+5D6q7xR/V7ckchJ/SfCOsh+Potn/vJxkNICv2L/ZbZfLS9MbcVrnwF+Th1l44Y0sZs5S7lnKp74j2FflP98Gag2jxXeQr7frFKVbpFxjpOPUFeUEEsJL94X4Cp7WEtzL91Zgys/hB1GXEhSmWU5YKyF+h/0HP1+KSvGD9qH91LXQMHdE+ZjOVTfYPONS5com2+3cS7nRHjyaREop+viQMR6lnRdex2OYUr40SvNb0Wqu6+Po2AqgRfycjp7SnQuEdQFMFWw== Received: from MW2PR2101CA0029.namprd21.prod.outlook.com (2603:10b6:302:1::42) by DM6PR12MB4943.namprd12.prod.outlook.com (2603:10b6:5:1bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Wed, 6 Jul 2022 06:28:13 +0000 Received: from CO1NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:302:1:cafe::f2) by MW2PR2101CA0029.outlook.office365.com (2603:10b6:302:1::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.6 via Frontend Transport; Wed, 6 Jul 2022 06:28:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by CO1NAM11FT046.mail.protection.outlook.com (10.13.174.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:13 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 6 Jul 2022 06:28:12 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 5 Jul 2022 23:28:12 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 5 Jul 2022 23:28:10 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [RFT][PATCH v2 1/9] vfio: Make vfio_unpin_pages() return void Date: Tue, 5 Jul 2022 23:27:51 -0700 Message-ID: <20220706062759.24946-2-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220706062759.24946-1-nicolinc@nvidia.com> References: <20220706062759.24946-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2015801d-ce42-4994-4881-08da5f18b42e X-MS-TrafficTypeDiagnostic: DM6PR12MB4943:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tHPA+mE6lo8oAm1gbSzDOKoXBE/pOmxchBHnM84a+lwDa52MZ3Jyg+G2yz/13SswzuT5mNC6djAWUO6JeFNXThqqXa0fZx5X20rJwP0cvjexaikn5WdSzH24jMUH3cS9Xb3XPHJqDP2bsvwoXmHJ0o/MRMsUBld/1kpMMx/sgS19m0tREXpB8WxBE7rf9T0uL8WL6LpTS9J7F3N5AJfcdAEG0N65GkzmQIwdGu6vpjUdLGbz6MiAmmzZgIXfFHPFHi8RR5CBU08cfAUQ7MOzOAgtttyfELIViU0AW2OkpiwAKxKWzPjIkQx4oJVJKdzoSw/44gYBFen014rk7Vn/0jHJCimwNvGE3ObzA00HOM6oXqi6KlouAfMTDcy1WE0zl1f+yKqWylqeEuSm9QdE8yczNAFpQ683KOq0wF0ZzHGB1A/18LOr6I1r6Zxv2J0D/luDLwCiIFHHiVOsOQU+/10/1c6VOpiYmbwmdjsLBm62pCzD6nQxk2TAZX/Uhaub76e8wWuRdzR5c3KLRUVxescGZqm4dN0pgs/NKedFSYO3ParGN5TKAPJrsQ2NOP1oc2qwqAV1eQsx7fTfcQmRfEXBjkYTTEb/9CFQ7owCp1d93WZG7i8bSH+Vk6f0hSPK+ZjoxhA4gpH/Ar3iVmXZDmF1HqqzEGWjZmZzx0Dz1lwSK8RsnJfUqhrll7Cvu3UJzdkBLgOwDFzblo8fFT+yGPtV56Fb8FFYqB/oXKIHsIPNWmZy9RNCn54ECq4n99Hk+9rnT0ihnmE4ICTgjTFY0PFeEvUQt44geTNdpCqy5GfYzvs1LugxlDzEXS7hm7zWyF1pYb51WDJYOigR3D8Zfl7EPlXKibnqxJdKmIHxy+rm259dJheUxcPm2s/XR418ALSSduYbq2RxkNvLnSUCaiP2nP6HsQ7xGsyLtyxiuak= X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(346002)(39860400002)(396003)(376002)(136003)(36840700001)(46966006)(40470700004)(70206006)(478600001)(81166007)(7416002)(7406005)(5660300002)(8676002)(426003)(356005)(921005)(8936002)(110136005)(316002)(82740400003)(86362001)(47076005)(4326008)(40460700003)(70586007)(83380400001)(2616005)(186003)(336012)(1076003)(26005)(2906002)(82310400005)(54906003)(7696005)(36860700001)(6666004)(40480700001)(36756003)(41300700001)(2101003)(36900700001)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2022 06:28:13.2038 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2015801d-ce42-4994-4881-08da5f18b42e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4943 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org There's only one caller that checks its return value with a WARN_ON_ONCE, while all other callers do not check return value at all. So simplify the API to return void by embedding similar WARN_ON_ONCEs. Suggested-by: Christoph Hellwig Signed-off-by: Nicolin Chen Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Kirti Wankhede --- .../driver-api/vfio-mediated-device.rst | 2 +- drivers/gpu/drm/i915/gvt/kvmgt.c | 5 +--- drivers/vfio/vfio.c | 24 ++++++++----------- drivers/vfio/vfio.h | 2 +- drivers/vfio/vfio_iommu_type1.c | 16 ++++++------- include/linux/vfio.h | 4 ++-- 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index 1c57815619fd..b0fdf76b339a 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -265,7 +265,7 @@ driver:: int vfio_pin_pages(struct vfio_device *device, unsigned long *user_pfn, int npage, int prot, unsigned long *phys_pfn); - int vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, + void vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, int npage); These functions call back into the back-end IOMMU module by using the pin_pages diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index e2f6c56ab342..8c67c9aba82d 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -231,18 +231,15 @@ static void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt) static void gvt_unpin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, unsigned long size) { - struct drm_i915_private *i915 = vgpu->gvt->gt->i915; int total_pages; int npage; - int ret; total_pages = roundup(size, PAGE_SIZE) / PAGE_SIZE; for (npage = 0; npage < total_pages; npage++) { unsigned long cur_gfn = gfn + npage; - ret = vfio_unpin_pages(&vgpu->vfio_device, &cur_gfn, 1); - drm_WARN_ON(&i915->drm, ret != 1); + vfio_unpin_pages(&vgpu->vfio_device, &cur_gfn, 1); } } diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 61e71c1154be..01f45ec70a3d 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1959,31 +1959,27 @@ EXPORT_SYMBOL(vfio_pin_pages); * PFNs should not be greater than VFIO_PIN_PAGES_MAX_ENTRIES. * @npage [in] : count of elements in user_pfn array. This count should not * be greater than VFIO_PIN_PAGES_MAX_ENTRIES. - * Return error or number of pages unpinned. */ -int vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, - int npage) +void vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, + int npage) { struct vfio_container *container; struct vfio_iommu_driver *driver; - int ret; - if (!user_pfn || !npage || !vfio_assert_device_open(device)) - return -EINVAL; + if (WARN_ON_ONCE(!user_pfn || !npage || !vfio_assert_device_open(device))) + return; - if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) - return -E2BIG; + if (WARN_ON_ONCE(npage > VFIO_PIN_PAGES_MAX_ENTRIES)) + return; /* group->container cannot change while a vfio device is open */ container = device->group->container; driver = container->iommu_driver; - if (likely(driver && driver->ops->unpin_pages)) - ret = driver->ops->unpin_pages(container->iommu_data, user_pfn, - npage); - else - ret = -ENOTTY; - return ret; + if (WARN_ON_ONCE(unlikely(!driver || !driver->ops->unpin_pages))) + return; + + driver->ops->unpin_pages(container->iommu_data, user_pfn, npage); } EXPORT_SYMBOL(vfio_unpin_pages); diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h index a67130221151..bef4edf58138 100644 --- a/drivers/vfio/vfio.h +++ b/drivers/vfio/vfio.h @@ -53,7 +53,7 @@ struct vfio_iommu_driver_ops { unsigned long *user_pfn, int npage, int prot, unsigned long *phys_pfn); - int (*unpin_pages)(void *iommu_data, + void (*unpin_pages)(void *iommu_data, unsigned long *user_pfn, int npage); int (*register_notifier)(void *iommu_data, unsigned long *events, diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index c13b9290e357..08613edaf722 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -948,20 +948,19 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, return ret; } -static int vfio_iommu_type1_unpin_pages(void *iommu_data, - unsigned long *user_pfn, - int npage) +static void vfio_iommu_type1_unpin_pages(void *iommu_data, + unsigned long *user_pfn, int npage) { struct vfio_iommu *iommu = iommu_data; bool do_accounting; int i; - if (!iommu || !user_pfn || npage <= 0) - return -EINVAL; + if (WARN_ON_ONCE(!iommu || !user_pfn || npage <= 0)) + return; /* Supported for v2 version only */ - if (!iommu->v2) - return -EACCES; + if (WARN_ON_ONCE(!iommu->v2)) + return; mutex_lock(&iommu->lock); @@ -979,7 +978,8 @@ static int vfio_iommu_type1_unpin_pages(void *iommu_data, } mutex_unlock(&iommu->lock); - return i > 0 ? i : -EINVAL; + + WARN_ON_ONCE(i != npage); } static long vfio_sync_unpin(struct vfio_dma *dma, struct vfio_domain *domain, diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 49580fa2073a..d0844ecdc961 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -149,8 +149,8 @@ bool vfio_file_has_dev(struct file *file, struct vfio_device *device); int vfio_pin_pages(struct vfio_device *device, unsigned long *user_pfn, int npage, int prot, unsigned long *phys_pfn); -int vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, - int npage); +void vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, + int npage); int vfio_dma_rw(struct vfio_device *device, dma_addr_t user_iova, void *data, size_t len, bool write); From patchwork Wed Jul 6 06:27:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12907354 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 E743BCCA481 for ; Wed, 6 Jul 2022 06:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbiGFG20 (ORCPT ); Wed, 6 Jul 2022 02:28:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbiGFG2S (ORCPT ); Wed, 6 Jul 2022 02:28:18 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062.outbound.protection.outlook.com [40.107.243.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C657021D; Tue, 5 Jul 2022 23:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c4WaY+e8DSV0hbHsxLFyoN9ggnz5kYfQrdznW6Q7BuvrKK7t0OJMuvaTJx1PAX1tyuRF/wLI2UP2U5rLgGpG+yRN+b3ufO68PnqqstvZi6WbXCMJ2H6pw1pBNpO+VJUUquCEJ6fKnlSmuouZ3yMfkAl09fM4o+Uo77wQDhdeBst3H0MB2iZqHxV5DG7ugryW6IzrBrcKoa68EuZPYiypD162kekfmvD/xeXpNIk2B64KzRxMOw/U1evWNz3d730asCdz3bMYdxAv9lGHojJTYvZykXNDkgcJMKJLxUK3/4t6yCVNPBBuW1j0RwBMuyWFOAlvRoGJqKbLazBvb+XLzw== 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=q4kdBZcskGq8MyJwaD3o+aVa1TdDmCibteJCPIZVVrg=; b=mQsAGv8u9cSyAp0NS7hwDZcRM3goWP+rJ5utgaoOQenXCv5QS/ghgicEgG1AhD931VKGdwkSJNwsBro0H2cmqvsHlslu/+n8KZPg5ILo5pkp66qpozGQ0ax0TsjBHb5UWNwLQNn5UeMOS8y2wybObetIkWBilpS76Bp+HKGbAkCim5gVuDzt0OD/OornRJb+Lt52KQj3p4fHVN9R7FY0Lj9f00ab+LVdV6WL5i54/JQdBcxbGfrqeJiF8I0h+nUEFa25PCPHn+w4UM8Kixs5cmME9sSVRruIYnWbOFAfc8ajHHSEvnpXOiKjD62W1dJ39n6qhQiNK40ifsUq3oNcAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=linux.ibm.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=q4kdBZcskGq8MyJwaD3o+aVa1TdDmCibteJCPIZVVrg=; b=QoUMzUKquSwWHxSE5PMWX7w5HPcfZMVhf95m+A/RY7HuleRvKRgRnhafIHnNSOk3axZdFgtkzsNNlDCF0auLnmFiFruy2TNIz5/1jjSXeo37fM3Nr+K9AuPUwcilbtUhcEVHtlfwADhCRUHH/yKvLmeXPh+ehnX/Mf4Mn2PgEUSO36f8UIdipl7Rew4JwpxPLWLQIdzIJ/OFU3Zc+IDbaNwlH/cMStsPP9cFPxV+3zt0IqVxHpwBJSEek7LUYqM/cQZrHF7YooDR+xkOSW6VyL4PLCuWPuIeKGkWtPvViTXu8CyI7563J3I6qyV5bYAOrpNXL/su7d9SGg6+stF1MA== Received: from MWHPR15CA0066.namprd15.prod.outlook.com (2603:10b6:301:4c::28) by BN6PR1201MB0084.namprd12.prod.outlook.com (2603:10b6:405:57::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Wed, 6 Jul 2022 06:28:16 +0000 Received: from CO1NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::1c) by MWHPR15CA0066.outlook.office365.com (2603:10b6:301:4c::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.22 via Frontend Transport; Wed, 6 Jul 2022 06:28:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by CO1NAM11FT037.mail.protection.outlook.com (10.13.174.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:15 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 6 Jul 2022 06:28:15 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 5 Jul 2022 23:28:14 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 5 Jul 2022 23:28:12 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [RFT][PATCH v2 2/9] vfio/ap: Pass in physical address of ind to ap_aqic() Date: Tue, 5 Jul 2022 23:27:52 -0700 Message-ID: <20220706062759.24946-3-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220706062759.24946-1-nicolinc@nvidia.com> References: <20220706062759.24946-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ce446cac-d94d-49f6-fa14-08da5f18b599 X-MS-TrafficTypeDiagnostic: BN6PR1201MB0084:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +frek4z7uwMs1CJwII+I97Hn5RpjvCHsZXD5RmLQlmsT3f10aE7fSBt2VHoETbhn22ZK6OgV6ekZTrZt8Kj80h5TWkAUcgqXU3ZsRL9LzUz8FN0GKIjxP9tHBSGxfatSRLf6RSGYNUqXMi07+Gd83OuzFvkF93vvbxyOcv2XObL485cBt7WA+7ZThdijW36CLXXz7uHJ0DBdU6TBwdEBFqUNTGRiMn+2s3ETPgd7H4lobHSGYgX5GSMw5vMSHSelpg7sg5NbW5F39WV4pr4hh8/ZoiW701SB0q5Nh45YTqFQzQX/6PsvAUreFvT7iTP5Cx3MB0jAQ0DB8zEVFaRT4Xmrs5KpuBGW2HRCJPIPic8CwvI1FokuZ/26HTggRfoS9qvLOdtMPSHnbtvCfeiAHspMtdR7/R74mDM4Oalb0S4yXuNapqswNCys0CgaEGH9fbhaJgg0lRKUnGY9mFcfoJANdVg2V36jvUyB2rmzybNG0uZaOgYg7smfdLdO5MggNVK1L+P2ojLvNo2XpsgMTZDe3wYhByQGhIFeGJ2mhQCw5w5o3Szmj/chIWNQfhCZQfDHa9Uu+RUGX5CWfah2vfUSVaGBDshCKY2PBhwOpY4d4f9eHbpoyexIhLHIw6CpLrNtTmrE2Q47ue2cwu8nh6es5fWaPs+KG8KGBhjE+CSAqKmo9PK2IqwMUutSxHJrTS298p0ROpfZ+L6YuvJP283UZJSIABiI0m+fZJZmCg2N/RigyduNNGpwd0E4jl5yebgHqCu4uABl9WnDoiccFHB8jjsa+T19h/gEKmw01jeDEbOogSzPal0WgR73ctT560/UrNyRX7D/cVkOZBtteThszs8tYVMR+8xg3q6Vg99G4qXI2N8zOHeJfI9TvbEIS5NujK+kM8rMlj2PPK5MCq3dAhWWO2IX5h3VswdzX+E= X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(346002)(396003)(136003)(39860400002)(376002)(46966006)(36840700001)(40470700004)(54906003)(336012)(186003)(40480700001)(70206006)(70586007)(110136005)(8676002)(426003)(4326008)(1076003)(47076005)(26005)(83380400001)(7696005)(36756003)(2616005)(40460700003)(478600001)(86362001)(36860700001)(82310400005)(41300700001)(6666004)(7406005)(2906002)(7416002)(316002)(8936002)(81166007)(82740400003)(356005)(921005)(5660300002)(83996005)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2022 06:28:15.5873 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ce446cac-d94d-49f6-fa14-08da5f18b599 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0084 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The ap_aqic() is called by vfio_ap_irq_enable() where it passes in a virt value that's casted from a physical address "h_nib". Inside the ap_aqic(), it does virt_to_phys() again. Since ap_aqic() needs a physical address, let's just pass in a pa of ind directly. So change the "ind" to "pa_ind". Reviewed-by: Harald Freudenberger Signed-off-by: Nicolin Chen Reviewed-by: Jason Gunthorpe --- arch/s390/include/asm/ap.h | 6 +++--- drivers/s390/crypto/ap_queue.c | 2 +- drivers/s390/crypto/vfio_ap_ops.c | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/s390/include/asm/ap.h b/arch/s390/include/asm/ap.h index b515cfa62bd9..f508f5025e38 100644 --- a/arch/s390/include/asm/ap.h +++ b/arch/s390/include/asm/ap.h @@ -227,13 +227,13 @@ struct ap_qirq_ctrl { * ap_aqic(): Control interruption for a specific AP. * @qid: The AP queue number * @qirqctrl: struct ap_qirq_ctrl (64 bit value) - * @ind: The notification indicator byte + * @pa_ind: Physical address of the notification indicator byte * * Returns AP queue status. */ static inline struct ap_queue_status ap_aqic(ap_qid_t qid, struct ap_qirq_ctrl qirqctrl, - void *ind) + phys_addr_t pa_ind) { unsigned long reg0 = qid | (3UL << 24); /* fc 3UL is AQIC */ union { @@ -241,7 +241,7 @@ static inline struct ap_queue_status ap_aqic(ap_qid_t qid, struct ap_qirq_ctrl qirqctrl; struct ap_queue_status status; } reg1; - unsigned long reg2 = virt_to_phys(ind); + unsigned long reg2 = pa_ind; reg1.qirqctrl = qirqctrl; diff --git a/drivers/s390/crypto/ap_queue.c b/drivers/s390/crypto/ap_queue.c index c48b0db824e3..a32457b4cbb8 100644 --- a/drivers/s390/crypto/ap_queue.c +++ b/drivers/s390/crypto/ap_queue.c @@ -34,7 +34,7 @@ static int ap_queue_enable_irq(struct ap_queue *aq, void *ind) qirqctrl.ir = 1; qirqctrl.isc = AP_ISC; - status = ap_aqic(aq->qid, qirqctrl, ind); + status = ap_aqic(aq->qid, qirqctrl, virt_to_phys(ind)); switch (status.response_code) { case AP_RESPONSE_NORMAL: case AP_RESPONSE_OTHERWISE_CHANGED: diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index a7d2a95796d3..bb869b28cebd 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -154,7 +154,7 @@ static struct ap_queue_status vfio_ap_irq_disable(struct vfio_ap_queue *q) int retries = 5; do { - status = ap_aqic(q->apqn, aqic_gisa, NULL); + status = ap_aqic(q->apqn, aqic_gisa, 0); switch (status.response_code) { case AP_RESPONSE_OTHERWISE_CHANGED: case AP_RESPONSE_NORMAL: @@ -245,7 +245,8 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, struct kvm_s390_gisa *gisa; int nisc; struct kvm *kvm; - unsigned long h_nib, g_pfn, h_pfn; + unsigned long g_pfn, h_pfn; + phys_addr_t h_nib; int ret; /* Verify that the notification indicator byte address is valid */ @@ -290,7 +291,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, aqic_gisa.ir = 1; aqic_gisa.gisa = (uint64_t)gisa >> 4; - status = ap_aqic(q->apqn, aqic_gisa, (void *)h_nib); + status = ap_aqic(q->apqn, aqic_gisa, h_nib); switch (status.response_code) { case AP_RESPONSE_NORMAL: /* See if we did clear older IRQ configuration */ From patchwork Wed Jul 6 06:27:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12907355 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 47F96C433EF for ; Wed, 6 Jul 2022 06:28:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230149AbiGFG2b (ORCPT ); Wed, 6 Jul 2022 02:28:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbiGFG2Y (ORCPT ); Wed, 6 Jul 2022 02:28:24 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2045.outbound.protection.outlook.com [40.107.244.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7881710D; Tue, 5 Jul 2022 23:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GZxAylzueXYiAwGpRZH21hJQdmKbtm2Tbbd1iIisFvM3n7Cdin5rQP7mvfLGEHVJETb9meE2GI1s8q6ZkrhgcITEddQvWiGwl1YYfxuAFZdYk+QNFJaiBXMix+MMFtmWaIQRS4vEAWUGU8isoqNEDdNcIdzBvOGxlk5+0b49ASBWlDxWUV29MftgUkWvTVwmbzSjzrGFcno7N/xV0Rkqr0IEKym0KJ6lhEe8TuKoekx2SX4vNd6TkilGuBSbEqmnle6ykQL8lEm1iMSm2H8QaWV0/FEYfME5UoA7bZf+zwfrlIO+/L/f4TJImkP1sE2eGe5ODMMKpXwEX2mBlx7TtA== 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=UGzY5kDOuxoOgpgnwFQgvMH+nVw92r80SdTewifgses=; b=cIa26FoRcV6jQ0S5wTiY4t1cJecPzeLWvn02eeaVVIKMcmBHWYOletJggq0GjDTlt4LjEazqZhRz9ssXfxqFgznbfgQjxWQv8MbG29im4vU+EquANorgU7YMH8yCIFv6926YU2pMMZrch8PhqoIRLYSGeUwygsVZK6E1SAhsfHq9JLdr4FspQtwJ0qzTIy3opl3UJda8VgKk//MProQ7w6bzl1lBqIOhcfRJgwQ1JcE0Owh5YybTBBFfALnHfMumMdIC9mL5ySFJgPKjdyzZijvnaKFrHXbaIY99UqJTzPbYfvo29+Y8CI0+tQdz4//mt6NDKHVDGouKi7W4a9RsEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=linux.ibm.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=UGzY5kDOuxoOgpgnwFQgvMH+nVw92r80SdTewifgses=; b=NdCB37UwKQyQCk8DbFHRVJuOZCQ1L5KvRFBM52/0bGNDuelkj2POcrbDT+a81+txWd8HEBeZTuil8v16YTl1w6C5xzfNkT2y+4UIN6hG2xHTtWsEQDEfhFnKQyJn7AvEUcT+r+gyJCFt0KOWEkcuLnYGrUBIVmGJnEsA1TKT9x4UPULRBO/Mks1+RPud7IpOwGIZ9UptBIXB6Iycgn0jo/iaS2Jp/dF/t0Q+LvWTb5vKOiEaeWFPsWj2AXybHo9hXVXMsAA2VwwDZnCNCfMQ7HHLqytIVTShQD2kxZaMdMkh0NEbpN9TP1YeyvoEl2VdPACc7YnBkPm/12p5o3XnVg== Received: from DM6PR12CA0004.namprd12.prod.outlook.com (2603:10b6:5:1c0::17) by BY5PR12MB4114.namprd12.prod.outlook.com (2603:10b6:a03:20c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Wed, 6 Jul 2022 06:28:18 +0000 Received: from DM6NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1c0:cafe::4e) by DM6PR12CA0004.outlook.office365.com (2603:10b6:5:1c0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14 via Frontend Transport; Wed, 6 Jul 2022 06:28:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by DM6NAM11FT016.mail.protection.outlook.com (10.13.173.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:18 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 6 Jul 2022 06:28:17 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 5 Jul 2022 23:28:16 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 5 Jul 2022 23:28:15 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [RFT][PATCH v2 3/9] vfio/ccw: Only pass in contiguous pages Date: Tue, 5 Jul 2022 23:27:53 -0700 Message-ID: <20220706062759.24946-4-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220706062759.24946-1-nicolinc@nvidia.com> References: <20220706062759.24946-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 94d1939b-66a1-4f0f-ffc6-08da5f18b721 X-MS-TrafficTypeDiagnostic: BY5PR12MB4114:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lbEkdFNI2JfjsA6yxocRCLCkrsuoLWtJNjDbZJR0ksPojirBt1G5kthH4tE5dU8IPq46sjERsCLkJg/52NuEtPRto7ixdKxLWcLCf+lJncYo/GbgOrhWlkJaAW9AQcJWMMHJlcYa4RYMPjozrf9DZjvqv101U5FVDNROiJn9sMUiIuYhHkLsBYbUMrXQpGZNbyAGPJYE+dD9xiLL+DtpYpu+W2lNtOd9vvlDJY8ThzimVtcyBsSoqIFJc+JFyz+pLhUX4kLEGB/0SoHFdcvPlEMeZ3+HHCSH9RUukoVeYyLrvg1+ouL5oyqC9c/6/ButhkqL2kGwl/BMoX9l8DXbRuczJMU/1bIFqN+dCu/MsjDWNIeRqeUxRLASYuXNfdCrT2lNnObSgTSIeF63Vp7e95RvvQiSfxPZuhQ90gyrG/W3mjUzU3eS/yCoIB6sdh3njBdsel0d0C+i/ZkFQEFGsQQJeAxDU6nsmzBUhgVL4XHRMXV7OZWCtoAndo/ti6KzqL9NJREwjXJKQtgC/N124pB9OLgDW7vClGyU58pHBwPpuI4MQJTBCY/ai04vhTnlpi38e/aoJcD2d+c988qUCoEHObNEIDYkVQds4qef6MfPSjUqM57VodDaa6I8rs842QGqNOOnE+H+oVbl7AJ2pyD+vngW5r5+HUX9QDNR74itUBqq/AI/Db5lkXzf72CNM7SDlXpFaSmwW6myl1EyHT5bgEPZLiE1Na3nMHlYzZMZGmyUyZ6eEOpfWu1GEZeeIC1gI+3EdqYbrLGIu7ppPX20ekSzSmg3FEXqJ87CcVV/1eKYCEtFr/ywB5yqrur8oFSPKaEZbpl2XegCrSSLYghoFi09R8sCyNMSRRk+Lcj7DmtSAV77IfY6CQHlpW+FgTAkotKqZjG5iY0CNwHTutq2jhiyAD/IuaPbrI6uRs4= X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(376002)(396003)(346002)(136003)(46966006)(36840700001)(40470700004)(5660300002)(7416002)(7406005)(356005)(921005)(8936002)(82740400003)(36860700001)(82310400005)(81166007)(2906002)(54906003)(26005)(7696005)(110136005)(2616005)(316002)(83380400001)(41300700001)(6666004)(478600001)(70586007)(4326008)(70206006)(8676002)(47076005)(336012)(426003)(1076003)(186003)(40460700003)(40480700001)(36756003)(86362001)(83996005)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2022 06:28:18.1409 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94d1939b-66a1-4f0f-ffc6-08da5f18b721 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4114 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This driver is the only caller of vfio_pin/unpin_pages that might pass in a non-contiguous PFN list, but in many cases it has a contiguous PFN list to process. So letting VFIO API handle a non-contiguous PFN list is actually counterproductive. Add a pair of simple loops to pass in contiguous PFNs only, to have an efficient implementation in VFIO. Signed-off-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Reviewed-by: Eric Farman --- drivers/s390/cio/vfio_ccw_cp.c | 70 +++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index 0c2be9421ab7..3b94863ad24e 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -90,6 +90,38 @@ static int pfn_array_alloc(struct pfn_array *pa, u64 iova, unsigned int len) return 0; } +/* + * pfn_array_unpin() - Unpin user pages in memory + * @pa: pfn_array on which to perform the operation + * @vdev: the vfio device to perform the operation + * @pa_nr: number of user pages to unpin + * + * Only unpin if any pages were pinned to begin with, i.e. pa_nr > 0, + * otherwise only clear pa->pa_nr + */ +static void pfn_array_unpin(struct pfn_array *pa, + struct vfio_device *vdev, int pa_nr) +{ + int unpinned = 0, npage = 1; + + while (unpinned < pa_nr) { + unsigned long *first = &pa->pa_iova_pfn[unpinned]; + unsigned long *last = &first[npage]; + + if (unpinned + npage < pa_nr && + *first + npage == *last) { + npage++; + continue; + } + + vfio_unpin_pages(vdev, first, npage); + unpinned += npage; + npage = 1; + } + + pa->pa_nr = 0; +} + /* * pfn_array_pin() - Pin user pages in memory * @pa: pfn_array on which to perform the operation @@ -101,34 +133,44 @@ static int pfn_array_alloc(struct pfn_array *pa, u64 iova, unsigned int len) */ static int pfn_array_pin(struct pfn_array *pa, struct vfio_device *vdev) { + int pinned = 0, npage = 1; int ret = 0; - ret = vfio_pin_pages(vdev, pa->pa_iova_pfn, pa->pa_nr, - IOMMU_READ | IOMMU_WRITE, pa->pa_pfn); + while (pinned < pa->pa_nr) { + unsigned long *first = &pa->pa_iova_pfn[pinned]; + unsigned long *last = &first[npage]; - if (ret < 0) { - goto err_out; - } else if (ret > 0 && ret != pa->pa_nr) { - vfio_unpin_pages(vdev, pa->pa_iova_pfn, ret); - ret = -EINVAL; - goto err_out; + if (pinned + npage < pa->pa_nr && + *first + npage == *last) { + npage++; + continue; + } + + ret = vfio_pin_pages(vdev, first, npage, + IOMMU_READ | IOMMU_WRITE, + &pa->pa_pfn[pinned]); + if (ret < 0) { + goto err_out; + } else if (ret > 0 && ret != npage) { + pinned += ret; + ret = -EINVAL; + goto err_out; + } + pinned += npage; + npage = 1; } return ret; err_out: - pa->pa_nr = 0; - + pfn_array_unpin(pa, vdev, pinned); return ret; } /* Unpin the pages before releasing the memory. */ static void pfn_array_unpin_free(struct pfn_array *pa, struct vfio_device *vdev) { - /* Only unpin if any pages were pinned to begin with */ - if (pa->pa_nr) - vfio_unpin_pages(vdev, pa->pa_iova_pfn, pa->pa_nr); - pa->pa_nr = 0; + pfn_array_unpin(pa, vdev, pa->pa_nr); kfree(pa->pa_iova_pfn); } From patchwork Wed Jul 6 06:27:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12907356 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 0D0B3CCA482 for ; Wed, 6 Jul 2022 06:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbiGFG2g (ORCPT ); Wed, 6 Jul 2022 02:28:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230168AbiGFG23 (ORCPT ); Wed, 6 Jul 2022 02:28:29 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2089.outbound.protection.outlook.com [40.107.95.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ACE41031; Tue, 5 Jul 2022 23:28:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bY2ed4m+DQ1pRWoQoPqFwt4hb2qUakNUpXmLyq8y0WtfOQeNV6zM8ofXCNUD2+cBoNQAzoTaMTfP4ZzfYR0j5VZViK8sfXiUzjWj4/rLW65EAsFfoDzeW6Xiwfz7MMt6kE0D8gv2lGrsfo3OIcO9+OAg713t2FR7LR2wWad1JTmu9IcxPdZP7oQKSpd8D9Re+wWQUh+YxZPPSpLJa50VexYnuC4cbuU1cnRAAZyxT1saKHXYAKBQZChM3eJ9vd8STvITeWeV9bpIpPGRJ6KuHcYZoD8nNL/7+03ybt6WZ23Rpaikz4/KMfBSz6tTkL9WAS7yhD8/DBesNe0dMNIs+A== 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=2BiQJoL7ymSObpOcgIWquvLZbvG51JCYu4HMpuegqrA=; b=BRn+4oz4J1UZZgENKwA7UwQQcg98fBA3FwqraMVF0829d6Lfvaip8U6+Lx5v1PE0RzmREEzhd/6RDRqKepqVk28feLuYT3AS1kAzgH3hfZlWX8zqIx63v0VfWduIAHosNhTVKKBx9a3EWwiHG6ttuPiOxyM/uexbI8Su685wjzSIjHFGWFoHr9oTSM5S9IOv56fpSdsfhPOJtO5nEq7EDpPAY8av8hOmHySMjeOoxJNQwy4j32+aOu744ebk/2eSodzcsH0QPl6gFcSCvTXp0PjRkcIvurh++cBEeNWAEKUfjOzOLAdZ+ufUQX5HWklSXYwit8u3evFk0eGuNrrWWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=linux.ibm.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=2BiQJoL7ymSObpOcgIWquvLZbvG51JCYu4HMpuegqrA=; b=J9RDywYkUsE3t3pYP9DMxWKDAsFjJfKcDzGg+lyGtpB29LzbsaJZJDmSeke2zH8nb9rsoBpioqCXDkghnK03vw+lN8Ede6XHOjKyURu3eZKe7ZCoH8A8/LWdxxDL4l1Kv/pGvcs0xlTX1EVrRq1/Q6TywpvkcO01ISuXA81OGWj6ffsvxjnu0L8yNzP3AHiKHT4mH6mCC1RJ4YOrhASB9/kQJXP30eHbG8DSNsy+5LlhUS2RAASNP/g/FnA6vg1+85ESdgUi6h/2rCrtT0Xr7Wd3LSc/N0eUUQtvoF7y1T+JT6cLWEo6xwvrY0soPlTzGr3w/o/QmIzIWWh7Omt6xA== Received: from DM6PR02CA0077.namprd02.prod.outlook.com (2603:10b6:5:1f4::18) by BYAPR12MB3592.namprd12.prod.outlook.com (2603:10b6:a03:db::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.17; Wed, 6 Jul 2022 06:28:21 +0000 Received: from DM6NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1f4:cafe::e5) by DM6PR02CA0077.outlook.office365.com (2603:10b6:5:1f4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by DM6NAM11FT063.mail.protection.outlook.com (10.13.172.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:20 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 6 Jul 2022 06:28:20 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 5 Jul 2022 23:28:19 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 5 Jul 2022 23:28:17 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [RFT][PATCH v2 4/9] vfio: Pass in starting IOVA to vfio_pin/unpin_pages API Date: Tue, 5 Jul 2022 23:27:54 -0700 Message-ID: <20220706062759.24946-5-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220706062759.24946-1-nicolinc@nvidia.com> References: <20220706062759.24946-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fd0c9b9e-c326-49d6-0003-08da5f18b8c9 X-MS-TrafficTypeDiagnostic: BYAPR12MB3592:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c/b9PyQJ/kLaKoBVlQN8UV8i88J6fPPASKUQYVB376ejoFrOHidvhNnZ5si8qG8R01L9cCj8bp8mYByikC/Uapc+BHNdEocIpsLx2rwa2WEhjIA+WoHT4l9+xx1StVG/ZfhxBt+wt2BASRitTcVaJ3bDcysN6AUGpMXfivQEy9UZJGEvxZvH133ly4bMGt4dYxCF50Ph91x/Tg3jzqbvKq/tpb8ZsXgI6otHH4iObwEkdgF5Znz2GLCQmJBsAI/dnAuyGqbvYJ1FsBmZw3isk7Wq5IsIMrYefBdLpIzbFs+kRjDRvpGTwbz2gWptkyjyRV/d4LrXkH9yFvFZhJSAyvTr20qKjYbNZW+vk/fShNRAZjiPPysu221DNsg9AbAUCU1WSjzvoPP+04JRuK/nUfkQTKuwhf/1xgnICsygWVxZ33SSNbWWJ2DRj8oaYGt3ZwqAtlULGLn5gHM4NldeRIo5AjNFRsXT/DA1961+FdcoNoQwqdqy5YHo5lKV9HO6egX/LllxH35F/7w/Ovp5grpt9+CnkFLo3Qqo+uOyPJTz3swFmE95S1HSyfMtEDZdhgOJ7ljS81G/PHeJHD7gBEHF17okUKEb44xUip6zWmRqobwiUfM5lNwU/qcoDZQPQiZNFybRGY3q9Vlou2Q5pKKebKdNPEx2VtnIfYagOXnc9gYnzYoFRHFf7FSU0gIBtIAF9+bPOBXNSjqYRIvHMEblI3nrqHU7c/TbmFiKi0I/eWXe29mAly7iD8ft7ddP8MmLg402Ddx4q3a3k2M8Wuf5F2X1zTogaFOTvfk7H6YUPo0ySR13xA4CnOH2pL4hXJvQZ1kyElyd9VTfWBHTdFFhsjrsFCIu6TSBhvleOtOOGkwTnGGLcnK/JDkF1N2fyLF4m1d3o+5VmjOTdDUD100DDTbUq/3xxK5yprl2KLo= X-Forefront-Antispam-Report: CIP:12.22.5.236;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(346002)(39860400002)(376002)(136003)(396003)(36840700001)(46966006)(40470700004)(82310400005)(2906002)(83380400001)(70206006)(47076005)(36756003)(70586007)(54906003)(426003)(336012)(8676002)(81166007)(1076003)(2616005)(4326008)(186003)(7696005)(356005)(921005)(82740400003)(6666004)(40480700001)(316002)(40460700003)(30864003)(26005)(110136005)(7406005)(7416002)(478600001)(41300700001)(36860700001)(8936002)(86362001)(5660300002)(2101003)(83996005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2022 06:28:20.8662 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fd0c9b9e-c326-49d6-0003-08da5f18b8c9 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.236];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3592 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The vfio_pin/unpin_pages() so far accepted arrays of PFNs of user IOVA. Among all three callers, there was only one caller possibly passing in a non-contiguous PFN list, which is now ensured to have contiguous PFN inputs too. Pass in the starting address with "iova" alone to simplify things, so callers no longer need to maintain a PFN list or to pin/unpin one page at a time. This also allows VFIO to use more efficient implementations of pin/unpin_pages. For now, also update vfio_iommu_type1 to fit this new parameter too, while keeping its input intact (being user_iova) since we don't want to spend too much effort swapping its parameters and local variables at that level. Signed-off-by: Nicolin Chen Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Acked-by: Eric Farman --- .../driver-api/vfio-mediated-device.rst | 4 +-- drivers/gpu/drm/i915/gvt/kvmgt.c | 24 ++++++----------- drivers/s390/cio/vfio_ccw_cp.c | 4 +-- drivers/s390/crypto/vfio_ap_ops.c | 9 +++---- drivers/vfio/vfio.c | 27 +++++++++---------- drivers/vfio/vfio.h | 4 +-- drivers/vfio/vfio_iommu_type1.c | 17 ++++++------ include/linux/vfio.h | 5 ++-- 8 files changed, 40 insertions(+), 54 deletions(-) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index b0fdf76b339a..ea32a0f13ddb 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -262,10 +262,10 @@ Translation APIs for Mediated Devices The following APIs are provided for translating user pfn to host pfn in a VFIO driver:: - int vfio_pin_pages(struct vfio_device *device, unsigned long *user_pfn, + int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, int npage, int prot, unsigned long *phys_pfn); - void vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, + void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage); These functions call back into the back-end IOMMU module by using the pin_pages diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 8c67c9aba82d..ea6041fa48ac 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -231,16 +231,8 @@ static void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt) static void gvt_unpin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, unsigned long size) { - int total_pages; - int npage; - - total_pages = roundup(size, PAGE_SIZE) / PAGE_SIZE; - - for (npage = 0; npage < total_pages; npage++) { - unsigned long cur_gfn = gfn + npage; - - vfio_unpin_pages(&vgpu->vfio_device, &cur_gfn, 1); - } + vfio_unpin_pages(&vgpu->vfio_device, gfn << PAGE_SHIFT, + roundup(size, PAGE_SIZE) / PAGE_SIZE); } /* Pin a normal or compound guest page for dma. */ @@ -258,14 +250,14 @@ static int gvt_pin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, * on stack to hold pfns. */ for (npage = 0; npage < total_pages; npage++) { - unsigned long cur_gfn = gfn + npage; + dma_addr_t cur_iova = (gfn + npage) << PAGE_SHIFT; unsigned long pfn; - ret = vfio_pin_pages(&vgpu->vfio_device, &cur_gfn, 1, + ret = vfio_pin_pages(&vgpu->vfio_device, cur_iova, 1, IOMMU_READ | IOMMU_WRITE, &pfn); if (ret != 1) { - gvt_vgpu_err("vfio_pin_pages failed for gfn 0x%lx, ret %d\n", - cur_gfn, ret); + gvt_vgpu_err("vfio_pin_pages failed for iova %pad, ret %d\n", + &cur_iova, ret); goto err; } @@ -309,7 +301,7 @@ static int gvt_dma_map_page(struct intel_vgpu *vgpu, unsigned long gfn, if (dma_mapping_error(dev, *dma_addr)) { gvt_vgpu_err("DMA mapping failed for pfn 0x%lx, ret %d\n", page_to_pfn(page), ret); - gvt_unpin_guest_page(vgpu, gfn, size); + gvt_unpin_guest_page(vgpu, gfn << PAGE_SHIFT, size); return -ENOMEM; } @@ -322,7 +314,7 @@ static void gvt_dma_unmap_page(struct intel_vgpu *vgpu, unsigned long gfn, struct device *dev = vgpu->gvt->gt->i915->drm.dev; dma_unmap_page(dev, dma_addr, size, DMA_BIDIRECTIONAL); - gvt_unpin_guest_page(vgpu, gfn, size); + gvt_unpin_guest_page(vgpu, gfn << PAGE_SHIFT, size); } static struct gvt_dma *__gvt_cache_find_dma_addr(struct intel_vgpu *vgpu, diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index 3b94863ad24e..a739262f988d 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -114,7 +114,7 @@ static void pfn_array_unpin(struct pfn_array *pa, continue; } - vfio_unpin_pages(vdev, first, npage); + vfio_unpin_pages(vdev, *first << PAGE_SHIFT, npage); unpinned += npage; npage = 1; } @@ -146,7 +146,7 @@ static int pfn_array_pin(struct pfn_array *pa, struct vfio_device *vdev) continue; } - ret = vfio_pin_pages(vdev, first, npage, + ret = vfio_pin_pages(vdev, *first << PAGE_SHIFT, npage, IOMMU_READ | IOMMU_WRITE, &pa->pa_pfn[pinned]); if (ret < 0) { diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index bb869b28cebd..8a2018ab3cf0 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -124,7 +124,7 @@ static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q) q->saved_isc = VFIO_AP_ISC_INVALID; } if (q->saved_pfn && !WARN_ON(!q->matrix_mdev)) { - vfio_unpin_pages(&q->matrix_mdev->vdev, &q->saved_pfn, 1); + vfio_unpin_pages(&q->matrix_mdev->vdev, q->saved_pfn << PAGE_SHIFT, 1); q->saved_pfn = 0; } } @@ -258,7 +258,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, return status; } - ret = vfio_pin_pages(&q->matrix_mdev->vdev, &g_pfn, 1, + ret = vfio_pin_pages(&q->matrix_mdev->vdev, g_pfn << PAGE_SHIFT, 1, IOMMU_READ | IOMMU_WRITE, &h_pfn); switch (ret) { case 1: @@ -301,7 +301,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, break; case AP_RESPONSE_OTHERWISE_CHANGED: /* We could not modify IRQ setings: clear new configuration */ - vfio_unpin_pages(&q->matrix_mdev->vdev, &g_pfn, 1); + vfio_unpin_pages(&q->matrix_mdev->vdev, g_pfn << PAGE_SHIFT, 1); kvm_s390_gisc_unregister(kvm, isc); break; default: @@ -1248,9 +1248,8 @@ static int vfio_ap_mdev_iommu_notifier(struct notifier_block *nb, if (action == VFIO_IOMMU_NOTIFY_DMA_UNMAP) { struct vfio_iommu_type1_dma_unmap *unmap = data; - unsigned long g_pfn = unmap->iova >> PAGE_SHIFT; - vfio_unpin_pages(&matrix_mdev->vdev, &g_pfn, 1); + vfio_unpin_pages(&matrix_mdev->vdev, unmap->iova, 1); return NOTIFY_OK; } diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 01f45ec70a3d..813b517c973e 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1910,17 +1910,17 @@ int vfio_set_irqs_validate_and_prepare(struct vfio_irq_set *hdr, int num_irqs, EXPORT_SYMBOL(vfio_set_irqs_validate_and_prepare); /* - * Pin a set of guest PFNs and return their associated host PFNs for local + * Pin contiguous guest pages and return their associated host pages for local * domain only. * @device [in] : device - * @user_pfn [in]: array of user/guest PFNs to be pinned. - * @npage [in] : count of elements in user_pfn array. This count should not + * @iova [in] : starting IOVA of user/guest pages to be pinned. + * @npage [in] : count of pages to be pinned. This count should not * be greater VFIO_PIN_PAGES_MAX_ENTRIES. * @prot [in] : protection flags * @phys_pfn[out]: array of host PFNs * Return error or number of pages pinned. */ -int vfio_pin_pages(struct vfio_device *device, unsigned long *user_pfn, +int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, int npage, int prot, unsigned long *phys_pfn) { struct vfio_container *container; @@ -1928,8 +1928,7 @@ int vfio_pin_pages(struct vfio_device *device, unsigned long *user_pfn, struct vfio_iommu_driver *driver; int ret; - if (!user_pfn || !phys_pfn || !npage || - !vfio_assert_device_open(device)) + if (!phys_pfn || !npage || !vfio_assert_device_open(device)) return -EINVAL; if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) @@ -1943,7 +1942,7 @@ int vfio_pin_pages(struct vfio_device *device, unsigned long *user_pfn, driver = container->iommu_driver; if (likely(driver && driver->ops->pin_pages)) ret = driver->ops->pin_pages(container->iommu_data, - group->iommu_group, user_pfn, + group->iommu_group, iova, npage, prot, phys_pfn); else ret = -ENOTTY; @@ -1953,20 +1952,18 @@ int vfio_pin_pages(struct vfio_device *device, unsigned long *user_pfn, EXPORT_SYMBOL(vfio_pin_pages); /* - * Unpin set of host PFNs for local domain only. + * Unpin contiguous host pages for local domain only. * @device [in] : device - * @user_pfn [in]: array of user/guest PFNs to be unpinned. Number of user/guest - * PFNs should not be greater than VFIO_PIN_PAGES_MAX_ENTRIES. - * @npage [in] : count of elements in user_pfn array. This count should not + * @iova [in] : starting address of user/guest pages to be unpinned. + * @npage [in] : count of pages to be unpinned. This count should not * be greater than VFIO_PIN_PAGES_MAX_ENTRIES. */ -void vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, - int npage) +void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage) { struct vfio_container *container; struct vfio_iommu_driver *driver; - if (WARN_ON_ONCE(!user_pfn || !npage || !vfio_assert_device_open(device))) + if (WARN_ON_ONCE(!npage || !vfio_assert_device_open(device))) return; if (WARN_ON_ONCE(npage > VFIO_PIN_PAGES_MAX_ENTRIES)) @@ -1979,7 +1976,7 @@ void vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, if (WARN_ON_ONCE(unlikely(!driver || !driver->ops->unpin_pages))) return; - driver->ops->unpin_pages(container->iommu_data, user_pfn, npage); + driver->ops->unpin_pages(container->iommu_data, iova, npage); } EXPORT_SYMBOL(vfio_unpin_pages); diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h index bef4edf58138..dbcd0e8c031b 100644 --- a/drivers/vfio/vfio.h +++ b/drivers/vfio/vfio.h @@ -50,11 +50,11 @@ struct vfio_iommu_driver_ops { struct iommu_group *group); int (*pin_pages)(void *iommu_data, struct iommu_group *group, - unsigned long *user_pfn, + dma_addr_t user_iova, int npage, int prot, unsigned long *phys_pfn); void (*unpin_pages)(void *iommu_data, - unsigned long *user_pfn, int npage); + dma_addr_t user_iova, int npage); int (*register_notifier)(void *iommu_data, unsigned long *events, struct notifier_block *nb); diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 08613edaf722..f10d0c4b1f26 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -828,7 +828,7 @@ static int vfio_unpin_page_external(struct vfio_dma *dma, dma_addr_t iova, static int vfio_iommu_type1_pin_pages(void *iommu_data, struct iommu_group *iommu_group, - unsigned long *user_pfn, + dma_addr_t user_iova, int npage, int prot, unsigned long *phys_pfn) { @@ -840,7 +840,7 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, bool do_accounting; dma_addr_t iova; - if (!iommu || !user_pfn || !phys_pfn) + if (!iommu || !phys_pfn) return -EINVAL; /* Supported for v2 version only */ @@ -856,7 +856,7 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, again: if (iommu->vaddr_invalid_count) { for (i = 0; i < npage; i++) { - iova = user_pfn[i] << PAGE_SHIFT; + iova = user_iova + PAGE_SIZE * i; ret = vfio_find_dma_valid(iommu, iova, PAGE_SIZE, &dma); if (ret < 0) goto pin_done; @@ -881,7 +881,7 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, for (i = 0; i < npage; i++) { struct vfio_pfn *vpfn; - iova = user_pfn[i] << PAGE_SHIFT; + iova = user_iova + PAGE_SIZE * i; dma = vfio_find_dma(iommu, iova, PAGE_SIZE); if (!dma) { ret = -EINVAL; @@ -938,7 +938,7 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, for (j = 0; j < i; j++) { dma_addr_t iova; - iova = user_pfn[j] << PAGE_SHIFT; + iova = user_iova + PAGE_SIZE * j; dma = vfio_find_dma(iommu, iova, PAGE_SIZE); vfio_unpin_page_external(dma, iova, do_accounting); phys_pfn[j] = 0; @@ -949,13 +949,13 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, } static void vfio_iommu_type1_unpin_pages(void *iommu_data, - unsigned long *user_pfn, int npage) + dma_addr_t user_iova, int npage) { struct vfio_iommu *iommu = iommu_data; bool do_accounting; int i; - if (WARN_ON_ONCE(!iommu || !user_pfn || npage <= 0)) + if (WARN_ON_ONCE(!iommu || npage <= 0)) return; /* Supported for v2 version only */ @@ -966,10 +966,9 @@ static void vfio_iommu_type1_unpin_pages(void *iommu_data, do_accounting = list_empty(&iommu->domain_list); for (i = 0; i < npage; i++) { + dma_addr_t iova = user_iova + PAGE_SIZE * i; struct vfio_dma *dma; - dma_addr_t iova; - iova = user_pfn[i] << PAGE_SHIFT; dma = vfio_find_dma(iommu, iova, PAGE_SIZE); if (!dma) break; diff --git a/include/linux/vfio.h b/include/linux/vfio.h index d0844ecdc961..c3e441c0bf4b 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -147,10 +147,9 @@ bool vfio_file_has_dev(struct file *file, struct vfio_device *device); #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long)) -int vfio_pin_pages(struct vfio_device *device, unsigned long *user_pfn, +int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, int npage, int prot, unsigned long *phys_pfn); -void vfio_unpin_pages(struct vfio_device *device, unsigned long *user_pfn, - int npage); +void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage); int vfio_dma_rw(struct vfio_device *device, dma_addr_t user_iova, void *data, size_t len, bool write); From patchwork Wed Jul 6 06:27:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12907357 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 B6E12CCA481 for ; Wed, 6 Jul 2022 06:28:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230355AbiGFG2i (ORCPT ); Wed, 6 Jul 2022 02:28:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbiGFG23 (ORCPT ); Wed, 6 Jul 2022 02:28:29 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2049.outbound.protection.outlook.com [40.107.223.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E8742BF3; Tue, 5 Jul 2022 23:28:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fenbwA/tX/NUy0Vv9NCZaqbRteehxtGthtgDS69teXXlGMFRJaiwoz0PmkJ7VC8wvO38rSKpMNTC1ddJuwW9aGEXnHv5q8QLneUURs3dYe2XdyD9jF6lz6Y1q0HutfplhC0d5yN8RI6A0xaemlQ81Uj4+wxkfRx3awvD+kQ8EJ9x8UJtJ+Mb+m2VKJLtgphLPL2lLiVgIUVIClJYCExYXI9A4JuicTb/z5L7E4mKlKFWMxccPBX7hcT1YsZ3UDbiR14zrRfjxLEja5nuuF+mLXIlNxE96Egw3jEW+XzzwvKPmJIJV+2wQcZw2H/NDAOQlz9htN8dvkjxU7Z3zNI2mg== 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=LiNkJ6cSD0IHTf0/58352H03VRDa7E+pLlFywZ+J01Y=; b=k72kf852SrA2fG7fUvn79YjRss96RzE9z06t23+A/uKySOn2bHBj4g34dcv0wJBSRC4J2KVq9GWsl212H/PP12v7ud7ViQlXVW1Y54q0xLoTSFZ44AgEAthRdEdbNKHVPb5D2GEoVRaRyTPzl4bEjB5ZnLVXMNvJu8vOqptsNEnzeg3XccTKwCxXh4ralZMhIrglA8ONsXFxI+MdOVpbmMtwWlqbxSU+XFWe/ZLGZGnYomZpZRMuZYho6CIBEeKVVyljm//wjws3GiCg0zLVfZVi6hRK2G4emjAYdE7EeLODHPT7He8cLUR17NXO2iMTXrjyxWHnZ5o4zOtcfYUHJQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=linux.ibm.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=LiNkJ6cSD0IHTf0/58352H03VRDa7E+pLlFywZ+J01Y=; b=nvqSfc1riny2wXnEhAjVG4kJSZRIH4+g1X8fAENC/QT/wZMDa0gBVItnTA040ZrM/9rRWdr8qD9+8lDpM219Tbbidz27UyS/I4cOweL53q20SKDqac8v+T1bQB7I99jI360QZ6zyMgJLvHvGmDS2QZ0fA8D3MDO2ltGQaPP/uJHlsACktpyDNH7WxCRRsyzNQ4RMCs9TlqbgFD6xNmfD8wJ+ppgZBWTGr2J17kXSPHErYufhBRbH8+Fvpdf9U7FQImR9eCFoSeA+/tyno2ymHwICh8KgdChvH0DYR4hLLIMosStMmVEdU7rgG6a5ScfWuJKaR1Nw3l7lJoZizsblsA== Received: from DM6PR02CA0091.namprd02.prod.outlook.com (2603:10b6:5:1f4::32) by DS7PR12MB6007.namprd12.prod.outlook.com (2603:10b6:8:7e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.21; Wed, 6 Jul 2022 06:28:23 +0000 Received: from DM6NAM11FT062.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1f4:cafe::26) by DM6PR02CA0091.outlook.office365.com (2603:10b6:5:1f4::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.17 via Frontend Transport; Wed, 6 Jul 2022 06:28:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT062.mail.protection.outlook.com (10.13.173.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:23 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 6 Jul 2022 06:28:23 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 5 Jul 2022 23:28:22 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 5 Jul 2022 23:28:20 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [RFT][PATCH v2 5/9] vfio/ap: Remove redundant pfn Date: Tue, 5 Jul 2022 23:27:55 -0700 Message-ID: <20220706062759.24946-6-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220706062759.24946-1-nicolinc@nvidia.com> References: <20220706062759.24946-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4fd6811a-e7a0-4442-2363-08da5f18ba42 X-MS-TrafficTypeDiagnostic: DS7PR12MB6007:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QxXHOP4nkRK8lqf/svoz30cGv+sSaODkDIhhy905WyA4ZFu93hIfKONEHeacNQ2MMKIfu3WohGzZVyXrkGCH2mKN6ntpGQ9EQpDN2yQEPzYtaVu6Htk8NUm127wcQbweSGfOba1Y4oGB0HZWZhXd4IR2xOjMpCaKwzLCrijkokPtT2aywtpVnXTjspNLAaeZADFXdNwf7hYVIauUxvybhxbBC4aR4zlJG4GqENc4+qJjiD7gREpt6KKczyeg58TkeSMyj+mIthNoRyskbRuD1nIL5qlg1Eq6qM4ZzoylQUjetfbjIu0uowD4lage9pLve5ewhpJ01XdbTnUU23lMw4oAPHGn1dH7I2SiMoqjEwSjlbdjv6yCrTAPIRaeaEvV64VZsaXEWdZG9Cu/3lQKDg1NrLqv8H4huIKTMZliNkQ289VZMcCtlDDOwyMyISQ0z3uM6zCr61FTSShY+IbHkz+dRGd1XwiiyN45wrCuPvuIJDlvhXpmAky6I3gnFeDkqXEYC4rMPwb3+j27HoemtgW609m+BfyV9JAP/humZSs4mMc1r9GK6ibFo6fUPmQ1tllP4Z8QXGuDyLCKITvKL0u3rB0eqZs2k0VaRXAkIqklAShZcx70eAXYlNpLTNJ3lbZtD8Jn504jDZtmobgCjeAfUx5Nu7bfJUbNEMU0RoZgPPYWzp2FEyKhanMbrZW5gB5p43zmhB2etcN56+pSo+U9IRhLRMB5iLZjgAbV7opTYK+CMYYRf+aFpuv9IG92KQS4KsrrZB9z8QzPpevuFb5D+b2Q5BDinAPiMraupeRI+Itq9mi+B4CftpzRr5sSrCNPc8g70+bJaZiYUNVBgAa8NJNZenJK1yTVqDTgbWeAEKp4maaFWEee3oWCm1soq6vwgGVYjjfk9Z7XqW6Xg+Ft8jOvJMCemgUpo0ROTrY= X-Forefront-Antispam-Report: CIP:12.22.5.235;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(346002)(136003)(396003)(376002)(36840700001)(40470700004)(46966006)(1076003)(26005)(7416002)(7406005)(54906003)(110136005)(5660300002)(8936002)(36756003)(2616005)(41300700001)(7696005)(336012)(426003)(47076005)(83380400001)(186003)(6666004)(82310400005)(356005)(921005)(86362001)(478600001)(2906002)(81166007)(40480700001)(36860700001)(40460700003)(82740400003)(8676002)(4326008)(70206006)(316002)(70586007)(2101003)(83996005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2022 06:28:23.3534 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4fd6811a-e7a0-4442-2363-08da5f18ba42 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.235];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT062.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6007 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The vfio_ap_ops code maintains both nib address and its PFN, which is redundant, merely because vfio_pin/unpin_pages API wanted pfn. Since vfio_pin/unpin_pages() now accept "iova", remove duplicated pfn code in their callers too. Signed-off-by: Nicolin Chen Reviewed-by: Jason Gunthorpe --- drivers/s390/crypto/vfio_ap_ops.c | 42 +++++++++++---------------- drivers/s390/crypto/vfio_ap_private.h | 4 +-- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 8a2018ab3cf0..6945e0ddc08c 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -112,7 +112,7 @@ static void vfio_ap_wait_for_irqclear(int apqn) * * Unregisters the ISC in the GIB when the saved ISC not invalid. * Unpins the guest's page holding the NIB when it exists. - * Resets the saved_pfn and saved_isc to invalid values. + * Resets the saved_iova and saved_isc to invalid values. */ static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q) { @@ -123,9 +123,9 @@ static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q) kvm_s390_gisc_unregister(q->matrix_mdev->kvm, q->saved_isc); q->saved_isc = VFIO_AP_ISC_INVALID; } - if (q->saved_pfn && !WARN_ON(!q->matrix_mdev)) { - vfio_unpin_pages(&q->matrix_mdev->vdev, q->saved_pfn << PAGE_SHIFT, 1); - q->saved_pfn = 0; + if (q->saved_iova && !WARN_ON(!q->matrix_mdev)) { + vfio_unpin_pages(&q->matrix_mdev->vdev, q->saved_iova, 1); + q->saved_iova = 0; } } @@ -189,27 +189,19 @@ static struct ap_queue_status vfio_ap_irq_disable(struct vfio_ap_queue *q) * * @vcpu: the object representing the vcpu executing the PQAP(AQIC) instruction. * @nib: the location for storing the nib address. - * @g_pfn: the location for storing the page frame number of the page containing - * the nib. * * When the PQAP(AQIC) instruction is executed, general register 2 contains the * address of the notification indicator byte (nib) used for IRQ notification. - * This function parses the nib from gr2 and calculates the page frame - * number for the guest of the page containing the nib. The values are - * stored in @nib and @g_pfn respectively. - * - * The g_pfn of the nib is then validated to ensure the nib address is valid. + * This function parses and validate the nib from gr2. * * Return: returns zero if the nib address is a valid; otherwise, returns * -EINVAL. */ -static int vfio_ap_validate_nib(struct kvm_vcpu *vcpu, unsigned long *nib, - unsigned long *g_pfn) +static int vfio_ap_validate_nib(struct kvm_vcpu *vcpu, dma_addr_t *nib) { *nib = vcpu->run->s.regs.gprs[2]; - *g_pfn = *nib >> PAGE_SHIFT; - if (kvm_is_error_hva(gfn_to_hva(vcpu->kvm, *g_pfn))) + if (kvm_is_error_hva(gfn_to_hva(vcpu->kvm, *nib >> PAGE_SHIFT))) return -EINVAL; return 0; @@ -239,34 +231,34 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, int isc, struct kvm_vcpu *vcpu) { - unsigned long nib; struct ap_qirq_ctrl aqic_gisa = {}; struct ap_queue_status status = {}; struct kvm_s390_gisa *gisa; int nisc; struct kvm *kvm; - unsigned long g_pfn, h_pfn; + unsigned long h_pfn; phys_addr_t h_nib; + dma_addr_t nib; int ret; /* Verify that the notification indicator byte address is valid */ - if (vfio_ap_validate_nib(vcpu, &nib, &g_pfn)) { - VFIO_AP_DBF_WARN("%s: invalid NIB address: nib=%#lx, g_pfn=%#lx, apqn=%#04x\n", - __func__, nib, g_pfn, q->apqn); + if (vfio_ap_validate_nib(vcpu, &nib)) { + VFIO_AP_DBF_WARN("%s: invalid NIB address: nib=%pad, apqn=%#04x\n", + __func__, &nib, q->apqn); status.response_code = AP_RESPONSE_INVALID_ADDRESS; return status; } - ret = vfio_pin_pages(&q->matrix_mdev->vdev, g_pfn << PAGE_SHIFT, 1, + ret = vfio_pin_pages(&q->matrix_mdev->vdev, nib, 1, IOMMU_READ | IOMMU_WRITE, &h_pfn); switch (ret) { case 1: break; default: VFIO_AP_DBF_WARN("%s: vfio_pin_pages failed: rc=%d," - "nib=%#lx, g_pfn=%#lx, apqn=%#04x\n", - __func__, ret, nib, g_pfn, q->apqn); + "nib=%pad, apqn=%#04x\n", + __func__, ret, &nib, q->apqn); status.response_code = AP_RESPONSE_INVALID_ADDRESS; return status; @@ -296,12 +288,12 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, case AP_RESPONSE_NORMAL: /* See if we did clear older IRQ configuration */ vfio_ap_free_aqic_resources(q); - q->saved_pfn = g_pfn; + q->saved_iova = nib; q->saved_isc = isc; break; case AP_RESPONSE_OTHERWISE_CHANGED: /* We could not modify IRQ setings: clear new configuration */ - vfio_unpin_pages(&q->matrix_mdev->vdev, g_pfn << PAGE_SHIFT, 1); + vfio_unpin_pages(&q->matrix_mdev->vdev, nib, 1); kvm_s390_gisc_unregister(kvm, isc); break; default: diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h index a26efd804d0d..479b205179bd 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -102,13 +102,13 @@ struct ap_matrix_mdev { * struct vfio_ap_queue - contains the data associated with a queue bound to the * vfio_ap device driver * @matrix_mdev: the matrix mediated device - * @saved_pfn: the guest PFN pinned for the guest + * @saved_iova: the notification indicator byte (nib) address * @apqn: the APQN of the AP queue device * @saved_isc: the guest ISC registered with the GIB interface */ struct vfio_ap_queue { struct ap_matrix_mdev *matrix_mdev; - unsigned long saved_pfn; + dma_addr_t saved_iova; int apqn; #define VFIO_AP_ISC_INVALID 0xff unsigned char saved_isc; From patchwork Wed Jul 6 06:27:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12907358 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 CD55ACCA47F for ; Wed, 6 Jul 2022 06:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230157AbiGFG2q (ORCPT ); Wed, 6 Jul 2022 02:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbiGFG2a (ORCPT ); Wed, 6 Jul 2022 02:28:30 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2055.outbound.protection.outlook.com [40.107.94.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E5613CD6; Tue, 5 Jul 2022 23:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hYRrJDp5UT4QoqUaWyS0KIAojMm2Qlmzo8j4TTi7i31HsDFpdJqGso0scHy8Cf+9FJZwZREgpH2alN8jx17IX7pBZ71LjhgINywD3dHYNV6/pS9j8JzYus0+spbTusr4o34I3gB/v429MBtWj4XjYJgBxbiX1HOsewZXfgrQ70XyBUPtfdfHrP9XZQMlue60BOrYkV9VR+wi0/ZUXZVzU7AbCQ1LvbOwqRzLP6M7Vn/irzw7VeDMQJv5mbvqDzs9rNQuEI1MCns+hN48ihodWd4GywaoT5+ao1LYkkFR/Lx4x5rdIjhu/nbBHTNhNpPJSsaONqT5ynLmFePbQyhvHg== 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=PThk+0QVHEB/PO1WVQi1jrYb+nJRbj/NWoH3jd783B0=; b=WE/+1ns8wktsiuUinvTpQGL3TPAcyxyM8kIyufCIjg31rKCnFfqLg1MmfZwYlKEk+LB2GQ+13fjCYB9xUgZRPeDoXPiFGIT3ZI4S8pOZ4bmYE9AoH0vHXqlNQIVQXZC47JgzmRVV0vqF5PkdpQeAFHIWb17T4T3AO4qOmEUW4n5zpIs53xp3OciopLs1OJqbzHvi709teuHDVIyKNm0ghfCzH39JNj/+PQNC0yi+QZpPzgmkzGbJHApvRgMBd7Pd0gIYu33d1UTnU9lgtVL5l4bIh3c/BIACnt6QpydfRLIob5wTMxApSWqthfYdfMFyvQFB7cCYrZLlt0/NP3Q5ZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=linux.ibm.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=PThk+0QVHEB/PO1WVQi1jrYb+nJRbj/NWoH3jd783B0=; b=oSO31SdCQp2Zn9CZo8byRIcYnBmDEubI2uYl+ohSoyhMztWoVnJwCHQGx/TxDEmWfFdBgRkeqitngmqtp2o9w5Cqb3xRUYO0xCZFIABqpv+kqc3kWASPbq3hG4XhezLZdud+IoNzFVLAZ/9QYAUqoxS61tEWTFsiV1YHeGgc4CpMLqxPgVj8da9hYzSd5fLJtBa/F9IG3MHDJKzNjUgmSiLETkXv5BdJRB0Jvou8dTPwyjd5yYyJTvCh+5HOVawYas+ozFuaxdGaL+rLvWPpSPpJDfdsszZVzlnEiuWyEePLjIhbjE6dQfOEzFotPeWs8qW4Fa2gLxndfb1O2yrqYA== Received: from MWHPR14CA0051.namprd14.prod.outlook.com (2603:10b6:300:81::13) by BN8PR12MB3426.namprd12.prod.outlook.com (2603:10b6:408:4a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Wed, 6 Jul 2022 06:28:26 +0000 Received: from CO1NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:300:81:cafe::7e) by MWHPR14CA0051.outlook.office365.com (2603:10b6:300:81::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by CO1NAM11FT065.mail.protection.outlook.com (10.13.174.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:25 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 6 Jul 2022 06:28:25 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 5 Jul 2022 23:28:24 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 5 Jul 2022 23:28:22 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [RFT][PATCH v2 6/9] vfio/ccw: Change pa_pfn list to pa_iova list Date: Tue, 5 Jul 2022 23:27:56 -0700 Message-ID: <20220706062759.24946-7-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220706062759.24946-1-nicolinc@nvidia.com> References: <20220706062759.24946-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a72f2307-660d-4dc7-10c1-08da5f18bbbe X-MS-TrafficTypeDiagnostic: BN8PR12MB3426:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o/dxZZ2lcYtq39GEZElRRsYjhhO6K+PNbCMEb+Zf/nyDkGVkPQLeVCW0gSCsD7PqY9u2dAm5TZG3v7rH9FYOmduwhjqjQ8aDrRf99pA0itaMfLWH6CSw/DQmP+DgIZNCVgxAkP5AnUaj3C/BV1m/EJMJCwiSB3nKiGebm/SZU91X03RTQ9M3JrMrG+Sw0PJhpvV74jHHz7uoFwbjuWZIDITxh9f6rFHw0kjuw70KzSbzg9udNXgFDRtp2X9akM6TmCqcit+s6LcFtaB7vskGrCk2Ex+4u9rTQUaZOPXs8HbrCyQi8MPupyd4b1fIIkpR+ppKllb/HiAhdqU4cMxfD/r8vOaA/+bmbIbM8GOv4tjpBr+DhlyBbog4Qdwgnd/D0EZnzh88JRrfLdqxWXroPiypinCo5xo0Y1IiM+gjJTZnp1LLcPAuzMTHnWS7zZm50zj+n5n2aYY6VkejprY0xN7yNMzgEgObnQL9oi7dr/Wd/CdfSEkKv3XLPu+2+Bv8e36QIIP0J9HU2i0s9oa0YoNFnPV3MIsxn5vuYjZiI/OuQcmxb9cQLEAEAC07Tr0XV5vtPzdsL7VM6ehAJZ7Y1vn78zwSvI5aTeXQbucX6fm2E33InaUL79pbViqa65BsN3d8QYSpOBCBOyFpAwha0Gfugb25NZ7WcQng0ptifuY63N8Zoij6Nzyrpuu/rgDM+TQE2/2Zi6Z9rDT+fDZuEIlcToyQLerkcDEhS5ThpHjSAUc0OMpynhotczzU9Eoywmbx9r9JAc7QAk2wB3uvGD1uA1fI47wP8N3cNnh0Yvlor+k0NXTiKB3Kbh14M/Jg173Nq2CKUgqbeMK5xPcAz2wxTrMvF6CRFyG9K+NTrFad7PeAtpqpmYNOyl5D43lwv34BnJZ36i6Ty6Emqjqi5vKTd88K+Py6a3UAY+/oi+U= X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(136003)(396003)(346002)(39860400002)(376002)(40470700004)(46966006)(36840700001)(4326008)(8676002)(921005)(81166007)(2616005)(186003)(82310400005)(1076003)(82740400003)(356005)(7696005)(83380400001)(2906002)(36756003)(47076005)(426003)(336012)(70206006)(70586007)(7406005)(7416002)(40480700001)(30864003)(40460700003)(26005)(54906003)(110136005)(478600001)(6666004)(41300700001)(36860700001)(5660300002)(86362001)(316002)(8936002)(36900700001)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2022 06:28:25.8433 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a72f2307-660d-4dc7-10c1-08da5f18bbbe X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3426 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The vfio_ccw_cp code maintains both iova and its PFN list because the vfio_pin/unpin_pages API wanted pfn list. Since vfio_pin/unpin_pages() now accept "iova", change to maintain only pa_iova list and rename all "pfn_array" strings to "page_array", so as to simplify the code. Signed-off-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Reviewed-by: Eric Farman --- drivers/s390/cio/vfio_ccw_cp.c | 135 ++++++++++++++++----------------- 1 file changed, 64 insertions(+), 71 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index a739262f988d..3854c3d573f5 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -18,11 +18,9 @@ #include "vfio_ccw_cp.h" #include "vfio_ccw_private.h" -struct pfn_array { - /* Starting guest physical I/O address. */ - unsigned long pa_iova; - /* Array that stores PFNs of the pages need to pin. */ - unsigned long *pa_iova_pfn; +struct page_array { + /* Array that stores pages need to pin. */ + dma_addr_t *pa_iova; /* Array that receives PFNs of the pages pinned. */ unsigned long *pa_pfn; /* Number of pages pinned from @pa_iova. */ @@ -37,53 +35,50 @@ struct ccwchain { /* Count of the valid ccws in chain. */ int ch_len; /* Pinned PAGEs for the original data. */ - struct pfn_array *ch_pa; + struct page_array *ch_pa; }; /* - * pfn_array_alloc() - alloc memory for PFNs - * @pa: pfn_array on which to perform the operation + * page_array_alloc() - alloc memory for page array + * @pa: page_array on which to perform the operation * @iova: target guest physical address * @len: number of bytes that should be pinned from @iova * - * Attempt to allocate memory for PFNs. + * Attempt to allocate memory for page array. * - * Usage of pfn_array: - * We expect (pa_nr == 0) and (pa_iova_pfn == NULL), any field in + * Usage of page_array: + * We expect (pa_nr == 0) and (pa_iova == NULL), any field in * this structure will be filled in by this function. * * Returns: - * 0 if PFNs are allocated - * -EINVAL if pa->pa_nr is not initially zero, or pa->pa_iova_pfn is not NULL + * 0 if page array is allocated + * -EINVAL if pa->pa_nr is not initially zero, or pa->pa_iova is not NULL * -ENOMEM if alloc failed */ -static int pfn_array_alloc(struct pfn_array *pa, u64 iova, unsigned int len) +static int page_array_alloc(struct page_array *pa, u64 iova, unsigned int len) { int i; - if (pa->pa_nr || pa->pa_iova_pfn) + if (pa->pa_nr || pa->pa_iova) return -EINVAL; - pa->pa_iova = iova; - pa->pa_nr = ((iova & ~PAGE_MASK) + len + (PAGE_SIZE - 1)) >> PAGE_SHIFT; if (!pa->pa_nr) return -EINVAL; - pa->pa_iova_pfn = kcalloc(pa->pa_nr, - sizeof(*pa->pa_iova_pfn) + - sizeof(*pa->pa_pfn), - GFP_KERNEL); - if (unlikely(!pa->pa_iova_pfn)) { + pa->pa_iova = kcalloc(pa->pa_nr, + sizeof(*pa->pa_iova) + sizeof(*pa->pa_pfn), + GFP_KERNEL); + if (unlikely(!pa->pa_iova)) { pa->pa_nr = 0; return -ENOMEM; } - pa->pa_pfn = pa->pa_iova_pfn + pa->pa_nr; + pa->pa_pfn = (unsigned long *)&pa->pa_iova[pa->pa_nr]; - pa->pa_iova_pfn[0] = pa->pa_iova >> PAGE_SHIFT; + pa->pa_iova[0] = iova; pa->pa_pfn[0] = -1ULL; for (i = 1; i < pa->pa_nr; i++) { - pa->pa_iova_pfn[i] = pa->pa_iova_pfn[i - 1] + 1; + pa->pa_iova[i] = pa->pa_iova[i - 1] + PAGE_SIZE; pa->pa_pfn[i] = -1ULL; } @@ -91,30 +86,30 @@ static int pfn_array_alloc(struct pfn_array *pa, u64 iova, unsigned int len) } /* - * pfn_array_unpin() - Unpin user pages in memory - * @pa: pfn_array on which to perform the operation + * page_array_unpin() - Unpin user pages in memory + * @pa: page_array on which to perform the operation * @vdev: the vfio device to perform the operation * @pa_nr: number of user pages to unpin * * Only unpin if any pages were pinned to begin with, i.e. pa_nr > 0, * otherwise only clear pa->pa_nr */ -static void pfn_array_unpin(struct pfn_array *pa, - struct vfio_device *vdev, int pa_nr) +static void page_array_unpin(struct page_array *pa, + struct vfio_device *vdev, int pa_nr) { int unpinned = 0, npage = 1; while (unpinned < pa_nr) { - unsigned long *first = &pa->pa_iova_pfn[unpinned]; - unsigned long *last = &first[npage]; + dma_addr_t *first = &pa->pa_iova[unpinned]; + dma_addr_t *last = &first[npage]; if (unpinned + npage < pa_nr && - *first + npage == *last) { + *first + npage * PAGE_SIZE == *last) { npage++; continue; } - vfio_unpin_pages(vdev, *first << PAGE_SHIFT, npage); + vfio_unpin_pages(vdev, *first, npage); unpinned += npage; npage = 1; } @@ -123,30 +118,30 @@ static void pfn_array_unpin(struct pfn_array *pa, } /* - * pfn_array_pin() - Pin user pages in memory - * @pa: pfn_array on which to perform the operation + * page_array_pin() - Pin user pages in memory + * @pa: page_array on which to perform the operation * @mdev: the mediated device to perform pin operations * * Returns number of pages pinned upon success. * If the pin request partially succeeds, or fails completely, * all pages are left unpinned and a negative error value is returned. */ -static int pfn_array_pin(struct pfn_array *pa, struct vfio_device *vdev) +static int page_array_pin(struct page_array *pa, struct vfio_device *vdev) { int pinned = 0, npage = 1; int ret = 0; while (pinned < pa->pa_nr) { - unsigned long *first = &pa->pa_iova_pfn[pinned]; - unsigned long *last = &first[npage]; + dma_addr_t *first = &pa->pa_iova[pinned]; + dma_addr_t *last = &first[npage]; if (pinned + npage < pa->pa_nr && - *first + npage == *last) { + *first + npage * PAGE_SIZE == *last) { npage++; continue; } - ret = vfio_pin_pages(vdev, *first << PAGE_SHIFT, npage, + ret = vfio_pin_pages(vdev, *first, npage, IOMMU_READ | IOMMU_WRITE, &pa->pa_pfn[pinned]); if (ret < 0) { @@ -163,32 +158,30 @@ static int pfn_array_pin(struct pfn_array *pa, struct vfio_device *vdev) return ret; err_out: - pfn_array_unpin(pa, vdev, pinned); + page_array_unpin(pa, vdev, pinned); return ret; } /* Unpin the pages before releasing the memory. */ -static void pfn_array_unpin_free(struct pfn_array *pa, struct vfio_device *vdev) +static void page_array_unpin_free(struct page_array *pa, struct vfio_device *vdev) { - pfn_array_unpin(pa, vdev, pa->pa_nr); - kfree(pa->pa_iova_pfn); + page_array_unpin(pa, vdev, pa->pa_nr); + kfree(pa->pa_iova); } -static bool pfn_array_iova_pinned(struct pfn_array *pa, unsigned long iova) +static bool page_array_iova_pinned(struct page_array *pa, unsigned long iova) { - unsigned long iova_pfn = iova >> PAGE_SHIFT; int i; for (i = 0; i < pa->pa_nr; i++) - if (pa->pa_iova_pfn[i] == iova_pfn) + if (pa->pa_iova[i] == iova) return true; return false; } -/* Create the list of IDAL words for a pfn_array. */ -static inline void pfn_array_idal_create_words( - struct pfn_array *pa, - unsigned long *idaws) +/* Create the list of IDAL words for a page_array. */ +static inline void page_array_idal_create_words(struct page_array *pa, + unsigned long *idaws) { int i; @@ -204,7 +197,7 @@ static inline void pfn_array_idal_create_words( idaws[i] = pa->pa_pfn[i] << PAGE_SHIFT; /* Adjust the first IDAW, since it may not start on a page boundary */ - idaws[0] += pa->pa_iova & (PAGE_SIZE - 1); + idaws[0] += pa->pa_iova[0] & (PAGE_SIZE - 1); } static void convert_ccw0_to_ccw1(struct ccw1 *source, unsigned long len) @@ -236,18 +229,18 @@ static void convert_ccw0_to_ccw1(struct ccw1 *source, unsigned long len) static long copy_from_iova(struct vfio_device *vdev, void *to, u64 iova, unsigned long n) { - struct pfn_array pa = {0}; + struct page_array pa = {0}; u64 from; int i, ret; unsigned long l, m; - ret = pfn_array_alloc(&pa, iova, n); + ret = page_array_alloc(&pa, iova, n); if (ret < 0) return ret; - ret = pfn_array_pin(&pa, vdev); + ret = page_array_pin(&pa, vdev); if (ret < 0) { - pfn_array_unpin_free(&pa, vdev); + page_array_unpin_free(&pa, vdev); return ret; } @@ -268,7 +261,7 @@ static long copy_from_iova(struct vfio_device *vdev, void *to, u64 iova, break; } - pfn_array_unpin_free(&pa, vdev); + page_array_unpin_free(&pa, vdev); return l; } @@ -371,7 +364,7 @@ static struct ccwchain *ccwchain_alloc(struct channel_program *cp, int len) chain->ch_ccw = (struct ccw1 *)data; data = (u8 *)(chain->ch_ccw) + sizeof(*chain->ch_ccw) * len; - chain->ch_pa = (struct pfn_array *)data; + chain->ch_pa = (struct page_array *)data; chain->ch_len = len; @@ -555,7 +548,7 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, struct vfio_device *vdev = &container_of(cp, struct vfio_ccw_private, cp)->vdev; struct ccw1 *ccw; - struct pfn_array *pa; + struct page_array *pa; u64 iova; unsigned long *idaws; int ret; @@ -589,13 +582,13 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, } /* - * Allocate an array of pfn's for pages to pin/translate. + * Allocate an array of pages to pin/translate. * The number of pages is actually the count of the idaws * required for the data transfer, since we only only support * 4K IDAWs today. */ pa = chain->ch_pa + idx; - ret = pfn_array_alloc(pa, iova, bytes); + ret = page_array_alloc(pa, iova, bytes); if (ret < 0) goto out_free_idaws; @@ -606,21 +599,21 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, goto out_unpin; /* - * Copy guest IDAWs into pfn_array, in case the memory they + * Copy guest IDAWs into page_array, in case the memory they * occupy is not contiguous. */ for (i = 0; i < idaw_nr; i++) - pa->pa_iova_pfn[i] = idaws[i] >> PAGE_SHIFT; + pa->pa_iova[i] = idaws[i]; } else { /* - * No action is required here; the iova addresses in pfn_array - * were initialized sequentially in pfn_array_alloc() beginning + * No action is required here; the iova addresses in page_array + * were initialized sequentially in page_array_alloc() beginning * with the contents of ccw->cda. */ } if (ccw_does_data_transfer(ccw)) { - ret = pfn_array_pin(pa, vdev); + ret = page_array_pin(pa, vdev); if (ret < 0) goto out_unpin; } else { @@ -630,13 +623,13 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, ccw->cda = (__u32) virt_to_phys(idaws); ccw->flags |= CCW_FLAG_IDA; - /* Populate the IDAL with pinned/translated addresses from pfn */ - pfn_array_idal_create_words(pa, idaws); + /* Populate the IDAL with pinned/translated addresses from page */ + page_array_idal_create_words(pa, idaws); return 0; out_unpin: - pfn_array_unpin_free(pa, vdev); + page_array_unpin_free(pa, vdev); out_free_idaws: kfree(idaws); out_init: @@ -742,7 +735,7 @@ void cp_free(struct channel_program *cp) cp->initialized = false; list_for_each_entry_safe(chain, temp, &cp->ccwchain_list, next) { for (i = 0; i < chain->ch_len; i++) { - pfn_array_unpin_free(chain->ch_pa + i, vdev); + page_array_unpin_free(chain->ch_pa + i, vdev); ccwchain_cda_free(chain, i); } ccwchain_free(chain); @@ -918,7 +911,7 @@ bool cp_iova_pinned(struct channel_program *cp, u64 iova) list_for_each_entry(chain, &cp->ccwchain_list, next) { for (i = 0; i < chain->ch_len; i++) - if (pfn_array_iova_pinned(chain->ch_pa + i, iova)) + if (page_array_iova_pinned(chain->ch_pa + i, iova)) return true; } From patchwork Wed Jul 6 06:27:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12907359 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 CD6B7C43334 for ; Wed, 6 Jul 2022 06:28:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbiGFG2s (ORCPT ); Wed, 6 Jul 2022 02:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbiGFG2h (ORCPT ); Wed, 6 Jul 2022 02:28:37 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2081.outbound.protection.outlook.com [40.107.223.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A85015FF6; Tue, 5 Jul 2022 23:28:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nRAGCyGGHwo0rT7nXupMONaIYioE5uR8jaiHKKyfsmLXxfbizEiHu4Q+JhsTGeQ9l3mOyh+KoYcVI7Zo1Pm6i1e07J18+UeP31Fs1DpOUdCn5BQmqDmy4FY8j/jNePC2DbuuN4y3auc4DEqgYnqDAdO+1CuZrXk3s4RPa1CPx3KYlzzF35A38WPqHDSxIYhQf/TFxi+Ye4tA2uA2ycexwlrUf/e/Lv9gcehKsbhpd0PtyKYNEdzufCqsPLFLcgT2/7niEDdKA9gSCVpCGgVo4R8fWfnMS7LC1mTATb/P5NbVGBv8it1zr33HHoD/OktmXRzs5ICsauLR+Tea56kV+g== 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=fg/czNGUYXaRGNcqo40iZSEEded7MYvJjsn8UlI/3Yk=; b=i1YE6xzbEWTyqE3gB1BcKMrDUP2JLmV30TetMrtkk9+w0b910J0ZlGqM8H2aaPEE68Seu2LD9pWZSqtgCOeY+/A/U85OeZ9uHq6heBXo608yQD/VhMzhc9PmIY2iH2Q0CPeStRsx/iWS52qh7DS4e1N18QY1iHj1/YdBFOXDoE8rwRB8iYzqu6sqDIduNb2j8SJGgPEgLPmxBrpfhXg8bgn1Pfzhl8wYPi9N3O2nzbcdu4GHobZnhxHrzn5lFa3YshUBvPA6tLn9EH5GEOdToxtilWz/pKggDP++FtQ5x/h3KLFEVO8f1yDo/uJJG/KvLnkIo49lT2BTVOJkCeuAfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=linux.ibm.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=fg/czNGUYXaRGNcqo40iZSEEded7MYvJjsn8UlI/3Yk=; b=Cg7WokfpJeCbWVU/KTRcl3KhoQGKhUWtIkoai10IEhKHWCzW9Bvl0VzCKlTW1miZN1pE3dtWxt1SH+9wFfV4PltALd+FJxcvyu11lIRmP7Ex7UOvq0uWMOvdsXfRwYMTBA/jgnwd15xyMvH4JILzPX6D6Do/S8DWTSENEY980K/l7KE9S9X5gCj6VEic3rH828ScpIL+6lrtWRaHHylCoNd7VJ4R4JbA5uZvSKzFMcHzKud5T95xz4JxTHpk5B/7RNI0ckbjXd0Eatsv8Zk8ohxlA8aiTQDMnJzA0PDjL3+rSb9gFW8rXRTIL+pfhkLyxsIKYrTpbhzNSPqPWjbiCg== Received: from MW4PR04CA0056.namprd04.prod.outlook.com (2603:10b6:303:6a::31) by MN2PR12MB4424.namprd12.prod.outlook.com (2603:10b6:208:26a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.17; Wed, 6 Jul 2022 06:28:28 +0000 Received: from CO1NAM11FT051.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::94) by MW4PR04CA0056.outlook.office365.com (2603:10b6:303:6a::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by CO1NAM11FT051.mail.protection.outlook.com (10.13.174.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:28 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 6 Jul 2022 06:28:27 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 5 Jul 2022 23:28:27 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 5 Jul 2022 23:28:25 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [RFT][PATCH v2 7/9] vfio: Rename user_iova of vfio_dma_rw() Date: Tue, 5 Jul 2022 23:27:57 -0700 Message-ID: <20220706062759.24946-8-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220706062759.24946-1-nicolinc@nvidia.com> References: <20220706062759.24946-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a11b0835-a98f-46d9-5cf0-08da5f18bd1c X-MS-TrafficTypeDiagnostic: MN2PR12MB4424:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kRLEl4Pl12VvwbEBvVsFSCZBrGKXX2dBRKCe4U+UwN2ZkfqrxorxgxDMqVA0z3LhCtwSii8SIFHtteBkLJLz4l+0gO59hI1WgoFZBPkBVRR5G0eg48iKxPR0LvjJMSwYWCpDl0rYe9AyVp5pvJWzYtv25r0GgbzxPRmJU03afjTUgfIyedOzXBLHgPEa2WOuiH87u0g6fGv44WWJ9GQZq6EOqSllrzwvu6q3OJ/MLQDlDkrMjyNxWH5X/vUucnZeaJFfLQCZuK2pC41KhgqkSskx26fcKBpAQxRYH/rvO9lLn6OYbZ1UsMWtFrJvOBGL/THlmGed13JDroGNiWCcKV+CmuRMlOKdABR/ofB28fPffxiRVH6zW5BYY661dd8tRXjaUxUc7hw+Gk0HDwXgdbhq6kvKH7FWGCbn6ZT0O5cm99Qxpfy0MZKsoWE8LZtq93kgL1QosVD1v/sQute7cdXoRFWV/N/SCSG7ZqQcp+WpnCXZtjckmIagmu9eyJu6YUsHse5L6WgL5ycLgBHBOW/Ky9MDbv3BEX+nm+VE7MY6vQ5znW/0t67pPj2+GoQyXgzNFZcib8jbQgFfcy67DEc3L3emH0U2NkDjwRrst8EzjGif9VsAtKyqVSkivC8Y4vV9niuueeSC5AB3UMF8a+YgTOjk6GphiYdeiTHPhhFdMmhqcJVOIoa5g83Dx11HMIdRZysVsL6HthwNjG6n8ezSjyA3VymGJTGXn6O0QdKOZSUWGZgEytmpWk8HiJfMdYRseAnO8l55fOmmIKdPKSUBiv3HiqsV2tkZRMcbEYMoxOGZa7YvLglCL5RFWCb0H0SM4KeGlMqChyXngbEPLZRun7rkkEvkIirTR6cyI5Od92ynm8r2Yqyc/meHNl5yOtYhFFhKq6LSIJvr4vXpTE7CJJpuVAGxvyKp34l85yc= X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(396003)(346002)(376002)(136003)(40470700004)(46966006)(36840700001)(8936002)(7416002)(81166007)(7406005)(426003)(5660300002)(54906003)(70206006)(70586007)(4326008)(41300700001)(921005)(86362001)(82310400005)(6666004)(316002)(356005)(110136005)(36860700001)(186003)(47076005)(26005)(36756003)(7696005)(2616005)(40460700003)(2906002)(40480700001)(8676002)(336012)(1076003)(82740400003)(83380400001)(478600001)(83996005)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2022 06:28:28.1859 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a11b0835-a98f-46d9-5cf0-08da5f18bd1c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT051.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4424 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Following the updated vfio_pin/unpin_pages(), use the simpler "iova". Signed-off-by: Nicolin Chen Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/vfio/vfio.c | 6 +++--- include/linux/vfio.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 813b517c973e..b95ec2d78966 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1991,13 +1991,13 @@ EXPORT_SYMBOL(vfio_unpin_pages); * not a real device DMA, it is not necessary to pin the user space memory. * * @device [in] : VFIO device - * @user_iova [in] : base IOVA of a user space buffer + * @iova [in] : base IOVA of a user space buffer * @data [in] : pointer to kernel buffer * @len [in] : kernel buffer length * @write : indicate read or write * Return error code on failure or 0 on success. */ -int vfio_dma_rw(struct vfio_device *device, dma_addr_t user_iova, void *data, +int vfio_dma_rw(struct vfio_device *device, dma_addr_t iova, void *data, size_t len, bool write) { struct vfio_container *container; @@ -2013,7 +2013,7 @@ int vfio_dma_rw(struct vfio_device *device, dma_addr_t user_iova, void *data, if (likely(driver && driver->ops->dma_rw)) ret = driver->ops->dma_rw(container->iommu_data, - user_iova, data, len, write); + iova, data, len, write); else ret = -ENOTTY; return ret; diff --git a/include/linux/vfio.h b/include/linux/vfio.h index c3e441c0bf4b..9108de34a79b 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -150,7 +150,7 @@ bool vfio_file_has_dev(struct file *file, struct vfio_device *device); int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, int npage, int prot, unsigned long *phys_pfn); void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage); -int vfio_dma_rw(struct vfio_device *device, dma_addr_t user_iova, +int vfio_dma_rw(struct vfio_device *device, dma_addr_t iova, void *data, size_t len, bool write); /* each type has independent events */ From patchwork Wed Jul 6 06:27:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12907361 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 81E64C43334 for ; Wed, 6 Jul 2022 06:29:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbiGFG3M (ORCPT ); Wed, 6 Jul 2022 02:29:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbiGFG25 (ORCPT ); Wed, 6 Jul 2022 02:28:57 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2051.outbound.protection.outlook.com [40.107.94.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BAD615707; Tue, 5 Jul 2022 23:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z23eb1JslBqFeWb9iCeFKMNj62OUGyMVBjh1bvq1RXLKfaY3Cj5cCIRrypX/1msM5uO+CJogS2w3tOdlgcS9BOquhl4b9xEindA2iuOyV1Q3mqcMteRPMPAj0UAJZRK5DzC6JW+7vxrCNhoRkkKdEd19jtTWFniE0UF2FlYt0XxQQpDMPcSFLq+/kx2J6enGUOQJjsh8nUfG+3heYsUbvL6QXoIPygPlQVa1ExlXHqakSsO21n3IxqQi+x57/swyEohcAz/YjO+DJYQrF0aDLki+ipigjN043CJ1DsXVv14gk9IwiJRth+3+uZI9jfwWpbzSdZYkiB60kGJkdgiIVw== 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=L1NcSO/+32Awp5D+9PDT6tENVBaLW4gKwEHATrIa0cg=; b=AmUdR67KUVrNE8ovS6ZuEbfqGZzkd2kuDxNk4fIAsgO8A9uKKfI889xrfnJ3zpeinmm6wziV7R9PoVx0VBhm9Kav4oZ1qLvBfD+khS0kIV4zrgwLH3pxmjY1vCG7EsUtA29w0EY3wahB4QfWbNmnpHoyhkCiZNX4v8W7iFYtqGMT2cMBn0FG7Uw2I7MsEx8kiVckPbbkBNLl//4kfANjUAyrANr8enxjuf3e4ew7c+6cuKhoIMqBtQ4sVEkrgaglpZlbxrGolMqPEA9T8neD8DUgzR1hsyU6fqCJIdbnI8DcxiMMw1Z537zso/j2lrMkDt6npxhkeGKf++UyOpYPJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=linux.ibm.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=L1NcSO/+32Awp5D+9PDT6tENVBaLW4gKwEHATrIa0cg=; b=nN5HiKQinXLRn4gfmRGNclfpQc2qX4SVL7X3zX9IG9v/VXFpii5ZL6N/r1hA2dIkz6t9TFxYwx3w+QTnIlvleEV6ezdNXW+g4h3k/rH94zi3fASxR2RWy3636ohqs9/tMI1qAhplQwnh0X0EtqW0XaLd2tn4liIIhijQQDLAhrQ1w1ntUCQVSoNZvnL5x4aB4x4DmhddoWGfKiYEGXX5HYnvKK3qbPoSKi+UgmdChHn2K4wXUFeeRTt67pZG5+wfvbEtYFqhsldPcSvoIT5mkFPgJEjTic1l2uPZcM7gX7eewZw1M7zoy2kQYAyvjCo3Cyq8xnNpC2F196cXodyR2g== Received: from DS7PR03CA0188.namprd03.prod.outlook.com (2603:10b6:5:3b6::13) by BL0PR12MB2516.namprd12.prod.outlook.com (2603:10b6:207:4e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.17; Wed, 6 Jul 2022 06:28:39 +0000 Received: from DM6NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b6:cafe::e0) by DS7PR03CA0188.outlook.office365.com (2603:10b6:5:3b6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by DM6NAM11FT048.mail.protection.outlook.com (10.13.173.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:38 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 6 Jul 2022 06:28:30 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 5 Jul 2022 23:28:29 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 5 Jul 2022 23:28:27 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [RFT][PATCH v2 8/9] vfio/ccw: Add kmap_local_page() for memcpy Date: Tue, 5 Jul 2022 23:27:58 -0700 Message-ID: <20220706062759.24946-9-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220706062759.24946-1-nicolinc@nvidia.com> References: <20220706062759.24946-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ff7379f-c94a-46fe-dd21-08da5f18c362 X-MS-TrafficTypeDiagnostic: BL0PR12MB2516:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U5BS7yFagCing3e9lOG2jzWGyeqoWbQLEk7xBTfdlrobfaGtxl1NJttsGLGpaf1VBwAjM3ZFa9m2isdnKA6q353I+TdLGYw4MRO4V/BX7xWd14m7e1xf7fAR7KmsviFSjjfg4n740mkD8WuxqGoHTp1C2b2giHWyhbkPi5plHCBFL2ORQKQn3hnokUih7oj6hGwlqCBMaElIQGus3OxXpL78jtHYb/Wrv5EhTDRUYCfa5h5lP/p8Rx13aJ1rwDXbZ7pMmt0xfmYm8aETANDK+JuMMLWCmy0lgm6ase6LRsMDMBY9WgVuCGDYfkPf96q7j+MCMkkN9VxcxnTncFPEqaoK+QeTFIDpNp9Z4vV58BWvGTaRH5GpXGlm78pBVONt1IwEyhatIZbQx4VLLSQIRKvDJDYinRhpwSmaTvfFT+N5tFcIkZiVP2o28fWguauHm0/wuQNhr75nYMQ4A144H4NZen9xWYlJsoXkXIOdWd58Vu5BYXaUJ+wnIKzJ6EKoe9rQOY+RSiN/d7XLxQAnOkhzhBHaySu1/vHV51IdJq2jyk8gfN9cpGdWZFXgayeppQ2OAsjfRo0J2aWvw1cGeWBKwsPZuOTuxUt6pjQ2GxwV5bacJ1+9R3c5b2Pa5n17Zvj/Zobs0QdBjkDUwSPhemFj/J+zkG7XeZchcPLfK5f+7d8WddRLL7CCRbxPKksrUluCH1y0gLR7NGDEDi3n5rj0r1DUcQ7gdpDtyAQyBfjLEnUJd7NFCOKKLpRkJz8H3GWF9S/Ohwd/A/2yeiqFFM62Zx66E/cjIlSZI+Jubrliamlfahuf+0MA46CErJoNct3tRGSyVvNwOayZYcbkOhCC/AXnTHCNSn/DxZ6jl5ZdSmkDDGWA7L3bW9RRkN39wJzMLZUBi6acdA/yDLTXzbhHkA38wJguty1KHmEpIKXHJLK3KgNw2xyZwLjGByloMVTwrHmhf1POZYKmIK3wsw== X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(376002)(136003)(346002)(396003)(40470700004)(36840700001)(46966006)(81166007)(40480700001)(356005)(921005)(82740400003)(36860700001)(2616005)(186003)(1076003)(47076005)(426003)(336012)(2906002)(8936002)(5660300002)(36756003)(7416002)(7406005)(316002)(70586007)(70206006)(54906003)(8676002)(478600001)(4326008)(82310400005)(7696005)(41300700001)(26005)(6666004)(40460700003)(110136005)(86362001)(83380400001)(2101003)(83996005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2022 06:28:38.7142 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ff7379f-c94a-46fe-dd21-08da5f18c362 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2516 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org A PFN is not secure enough to promise that the memory is not IO. And direct access via memcpy() that only handles CPU memory will crash on S390 if the PFN is an IO PFN, as we have to use the memcpy_to/fromio() that uses the special S390 IO access instructions. On the other hand, a "struct page *" is always a CPU coherent thing that fits memcpy(). Also, casting a PFN to "void *" for memcpy() is not a proper practice, kmap_local_page() is the correct API to call here, though S390 doesn't use highmem, which means kmap_local_page() is a NOP. There's a following patch changing the vfio_pin_pages() API to return a list of "struct page *" instead of PFNs. It will block any IO memory from ever getting into this call path, for such a security purpose. In this patch, add kmap_local_page() to prepare for that. Suggested-by: Jason Gunthorpe Signed-off-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Acked-by: Eric Farman --- drivers/s390/cio/vfio_ccw_cp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index 3854c3d573f5..cd4ec4f6d6ff 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -230,7 +231,6 @@ static long copy_from_iova(struct vfio_device *vdev, void *to, u64 iova, unsigned long n) { struct page_array pa = {0}; - u64 from; int i, ret; unsigned long l, m; @@ -246,7 +246,9 @@ static long copy_from_iova(struct vfio_device *vdev, void *to, u64 iova, l = n; for (i = 0; i < pa.pa_nr; i++) { - from = pa.pa_pfn[i] << PAGE_SHIFT; + struct page *page = pfn_to_page(pa.pa_pfn[i]); + void *from = kmap_local_page(page); + m = PAGE_SIZE; if (i == 0) { from += iova & (PAGE_SIZE - 1); @@ -254,7 +256,8 @@ static long copy_from_iova(struct vfio_device *vdev, void *to, u64 iova, } m = min(l, m); - memcpy(to + (n - l), (void *)from, m); + memcpy(to + (n - l), from, m); + kunmap_local(from); l -= m; if (l == 0) From patchwork Wed Jul 6 06:27:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12907360 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 763ADC433EF for ; Wed, 6 Jul 2022 06:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231270AbiGFG3K (ORCPT ); Wed, 6 Jul 2022 02:29:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbiGFG2q (ORCPT ); Wed, 6 Jul 2022 02:28:46 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2078.outbound.protection.outlook.com [40.107.93.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD64413DC1; Tue, 5 Jul 2022 23:28:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IoW5OKJ5hh3bK6C3Z/9c7KPnKFPNrgMV1Xmy6pW6Oyt4TXA6DqqeoN2MonWOzyXpVT3nbyr9YE/d5aJd2JzhXVxu6XaJgTD3WT7/fva7zCuXtaOrfFrnt4nhRrO/DHPKP9dZSI3Xr2m76UB8h0l7sGzBTMvL/iAD5CvH4pnINxkrRyCFN/5IAflE/FW8TXsCSdHIesgHYkMrXQwN/uOC+Ih/mEC2a/UyI8IjDkCg5/HwNIDpahsx6KGA1Lyu/wMkofEaLaKtVSg1lnrRAsZXi8sKR5YDb3sR08+qD+doPrUESh81BWhT3qH9jUwHR9rv4LY6bAx8fgY4DDDRuuolzA== 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=B6oAcJlJO1+/ppICitkgpCU1cfLnB5wXqQH3i/7mbfM=; b=Rx3m3iIpdmvfvYUoSf8uo7XaHEa7dFiCJouyu99WEBwO5I8eL4UaVgbxCPz/azxG/R2yn9iPiWjHDYgp0FniFi0kCgPiEzhV3RIbt9O/q18UEUEed59vhwJRfh3X8qoZnnMdKu0M/Iz8lC3Xx2Vsd5WVigXqjqCfnZpwV85oQkujIYvegXjDUkf4tkxzADTm2iarZyFJ8H6/vkszRcLJhfXJnqG1mPFm/YTHJaFL0qtK825KHFvbw5YXHQBHdUDS0gb0jiXcAhJkWe5saIWjD1ypdXEMcjlBTDg7HS/9Q9DQbm+9dWgoOL8aQY5W/e+x6cS+oeGpEsXnD0tAXbQp1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=linux.ibm.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=B6oAcJlJO1+/ppICitkgpCU1cfLnB5wXqQH3i/7mbfM=; b=NRBjnvH+zYTRrO/uVzOFqZbUuemUEUhf2q79Os/hLLF1VVyKCYdzYl8t/FU64fDvzMw5MdtUOXOX+yXXfJ9u+Ej6Fv5y4zBJnrRhLz3fXxOd5TsGDFKKR5/sTeAmHhCbzO8n0a7kkdv8FdsrdJu5/6d8wcHSIsC0lH4V3X+IyZ8xSLaF8bBXGcLzvHoB++ppISvWODDoOkIjBStFpKwfBT4nD5ph9VjnogX4lpah9H2BZIFfaKuQh2TdBLo1Bmjjo4GjyfiIB1yutx2m2OBS6IJYPGe/0ZvXK8Yu5iMGW0ZZpHuAKORNnm14yNYIzC5hpF/L0d8Uc/nrPTLiVny1qQ== Received: from DS7PR06CA0051.namprd06.prod.outlook.com (2603:10b6:8:54::21) by BN6PR1201MB0146.namprd12.prod.outlook.com (2603:10b6:405:59::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Wed, 6 Jul 2022 06:28:37 +0000 Received: from DM6NAM11FT049.eop-nam11.prod.protection.outlook.com (2603:10b6:8:54:cafe::53) by DS7PR06CA0051.outlook.office365.com (2603:10b6:8:54::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14 via Frontend Transport; Wed, 6 Jul 2022 06:28:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by DM6NAM11FT049.mail.protection.outlook.com (10.13.172.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 6 Jul 2022 06:28:36 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 6 Jul 2022 06:28:32 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Tue, 5 Jul 2022 23:28:31 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Tue, 5 Jul 2022 23:28:29 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [RFT][PATCH v2 9/9] vfio: Replace phys_pfn with pages for vfio_pin_pages() Date: Tue, 5 Jul 2022 23:27:59 -0700 Message-ID: <20220706062759.24946-10-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220706062759.24946-1-nicolinc@nvidia.com> References: <20220706062759.24946-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4a84798d-e10f-4219-7ee9-08da5f18c249 X-MS-TrafficTypeDiagnostic: BN6PR1201MB0146:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /wKtIgQHIwgKNJzlQZ4DM+OdvQF5R2u1B7rKIAxnt7OhuW2CBC6JV3fssTZusiLKmm7k2a68c5SeIB+UdjhOgZGAL4eD/aWDqIzwaUq94j6Cz36Le8mP82Sh0JZ0Z/l+Duf3YFVFUtKhR6qFYabJxEAxFScfRcrjRusdkeFWe7MnSe72EF6to5nlHzKkIrWr85+0CggEUFIklKHeCwJcdQnJJRO2zqblCh5p6JN6uOD3agdQ18v995BoxE4Vm1wInvVRIvnSPnSB048bsgtH0VtbqTqlZVNjKkUTePR8CLm7n9BfNG2QL+Dep1CORamxKu98IGw2+zXVu6R8BX29hsu4IAAw1qLSfdJJij2fe2n/CQrW/GA+LQzwZYSga2YvW6saRdnEsahLwNeYyBAV0z14dSi0+MVAG7yMCR2ANkKsz4+QnOtIppCLLz8JlDSNPZPDsH4SCKWj4hoKOkwWO0/xEpIjy8X9nUh15mCBeDx4Eg1Ho9BiTIatZXxm76xiJsLdMCzaLUTteMd9jcSjg0arKR/mn8C6kgofqPJ8ZWlM6RTk1HSB2X8eoAIF8dF3r4RlegWvUoaBs9TfRZTU+ZKkvDl8rTQJEsExrCBNh7l4HJVl4cQ3k/rEvGdmn8U9YnkVbfoBqizQ/htykSfgJlPDEnDiVH/4awfLSoNVoDcFGfO9s9G6HO1T+BDOHB4WKGrPIWg9YcskT++1EgoqKobI6Z6JdeKrvPLO+UdO5s2v/MaFup+jcjl6BcVnyXwYvGig4vur4YGRVB2D3Kv0f73O/NXnl2ciJoRY4oLRnmxRHn3A+hELrPEy7sJu/NZ381xW4y4nA1zm40jQiYWrSEInjbOMkEzd7jfexGsGLkV8fF+RVMft5bJbaSoujxsijEjbC+wD1x6pphtfJLnUorMlhrn4StZkf5vi2quUTWc= X-Forefront-Antispam-Report: CIP:12.22.5.236;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(376002)(396003)(39860400002)(136003)(346002)(46966006)(40470700004)(36840700001)(8936002)(336012)(478600001)(86362001)(426003)(7406005)(5660300002)(7416002)(83380400001)(40460700003)(30864003)(2616005)(36756003)(186003)(1076003)(316002)(40480700001)(110136005)(54906003)(36860700001)(26005)(47076005)(82740400003)(921005)(356005)(41300700001)(81166007)(70586007)(2906002)(6666004)(70206006)(4326008)(8676002)(7696005)(82310400005)(36900700001)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2022 06:28:36.8078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a84798d-e10f-4219-7ee9-08da5f18c249 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.236];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT049.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0146 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Most of the callers of vfio_pin_pages() want "struct page *" and the low-level mm code to pin pages returns a list of "struct page *" too. So there's no gain in converting "struct page *" to PFN in between. Replace the output parameter "phys_pfn" list with a "pages" list, to simplify callers. This also allows us to replace the vfio_iommu_type1 implementation with a more efficient one. For now, also update vfio_iommu_type1 to fit this new parameter too. Signed-off-by: Nicolin Chen Reviewed-by: Christoph Hellwig Reviewed-by: Kirti Wankhede Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Acked-by: Eric Farman --- .../driver-api/vfio-mediated-device.rst | 2 +- drivers/gpu/drm/i915/gvt/kvmgt.c | 19 ++++++------------- drivers/s390/cio/vfio_ccw_cp.c | 19 +++++++++---------- drivers/s390/crypto/vfio_ap_ops.c | 6 +++--- drivers/vfio/vfio.c | 8 ++++---- drivers/vfio/vfio.h | 2 +- drivers/vfio/vfio_iommu_type1.c | 19 +++++++++++-------- include/linux/vfio.h | 2 +- 8 files changed, 36 insertions(+), 41 deletions(-) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index ea32a0f13ddb..ba5fefcdae1a 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -263,7 +263,7 @@ The following APIs are provided for translating user pfn to host pfn in a VFIO driver:: int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, - int npage, int prot, unsigned long *phys_pfn); + int npage, int prot, struct page **pages); void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage); diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index ea6041fa48ac..3a49471dcc16 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -239,7 +239,7 @@ static void gvt_unpin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, static int gvt_pin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, unsigned long size, struct page **page) { - unsigned long base_pfn = 0; + struct page *base_page = NULL; int total_pages; int npage; int ret; @@ -251,26 +251,19 @@ static int gvt_pin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, */ for (npage = 0; npage < total_pages; npage++) { dma_addr_t cur_iova = (gfn + npage) << PAGE_SHIFT; - unsigned long pfn; + struct page *cur_page; ret = vfio_pin_pages(&vgpu->vfio_device, cur_iova, 1, - IOMMU_READ | IOMMU_WRITE, &pfn); + IOMMU_READ | IOMMU_WRITE, &cur_page); if (ret != 1) { gvt_vgpu_err("vfio_pin_pages failed for iova %pad, ret %d\n", &cur_iova, ret); goto err; } - if (!pfn_valid(pfn)) { - gvt_vgpu_err("pfn 0x%lx is not mem backed\n", pfn); - npage++; - ret = -EFAULT; - goto err; - } - if (npage == 0) - base_pfn = pfn; - else if (base_pfn + npage != pfn) { + base_page = cur_page; + else if (base_page + npage != cur_page) { gvt_vgpu_err("The pages are not continuous\n"); ret = -EINVAL; npage++; @@ -278,7 +271,7 @@ static int gvt_pin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, } } - *page = pfn_to_page(base_pfn); + *page = base_page; return 0; err: gvt_unpin_guest_page(vgpu, gfn, npage * PAGE_SIZE); diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index cd4ec4f6d6ff..8963f452f963 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -22,8 +22,8 @@ struct page_array { /* Array that stores pages need to pin. */ dma_addr_t *pa_iova; - /* Array that receives PFNs of the pages pinned. */ - unsigned long *pa_pfn; + /* Array that receives the pinned pages. */ + struct page **pa_page; /* Number of pages pinned from @pa_iova. */ int pa_nr; }; @@ -68,19 +68,19 @@ static int page_array_alloc(struct page_array *pa, u64 iova, unsigned int len) return -EINVAL; pa->pa_iova = kcalloc(pa->pa_nr, - sizeof(*pa->pa_iova) + sizeof(*pa->pa_pfn), + sizeof(*pa->pa_iova) + sizeof(*pa->pa_page), GFP_KERNEL); if (unlikely(!pa->pa_iova)) { pa->pa_nr = 0; return -ENOMEM; } - pa->pa_pfn = (unsigned long *)&pa->pa_iova[pa->pa_nr]; + pa->pa_page = (struct page **)&pa->pa_iova[pa->pa_nr]; pa->pa_iova[0] = iova; - pa->pa_pfn[0] = -1ULL; + pa->pa_page[0] = NULL; for (i = 1; i < pa->pa_nr; i++) { pa->pa_iova[i] = pa->pa_iova[i - 1] + PAGE_SIZE; - pa->pa_pfn[i] = -1ULL; + pa->pa_page[i] = NULL; } return 0; @@ -144,7 +144,7 @@ static int page_array_pin(struct page_array *pa, struct vfio_device *vdev) ret = vfio_pin_pages(vdev, *first, npage, IOMMU_READ | IOMMU_WRITE, - &pa->pa_pfn[pinned]); + &pa->pa_page[pinned]); if (ret < 0) { goto err_out; } else if (ret > 0 && ret != npage) { @@ -195,7 +195,7 @@ static inline void page_array_idal_create_words(struct page_array *pa, */ for (i = 0; i < pa->pa_nr; i++) - idaws[i] = pa->pa_pfn[i] << PAGE_SHIFT; + idaws[i] = page_to_phys(pa->pa_page[i]); /* Adjust the first IDAW, since it may not start on a page boundary */ idaws[0] += pa->pa_iova[0] & (PAGE_SIZE - 1); @@ -246,8 +246,7 @@ static long copy_from_iova(struct vfio_device *vdev, void *to, u64 iova, l = n; for (i = 0; i < pa.pa_nr; i++) { - struct page *page = pfn_to_page(pa.pa_pfn[i]); - void *from = kmap_local_page(page); + void *from = kmap_local_page(pa.pa_page[i]); m = PAGE_SIZE; if (i == 0) { diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 6945e0ddc08c..b0972ca0dfa3 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -234,9 +234,9 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, struct ap_qirq_ctrl aqic_gisa = {}; struct ap_queue_status status = {}; struct kvm_s390_gisa *gisa; + struct page *h_page; int nisc; struct kvm *kvm; - unsigned long h_pfn; phys_addr_t h_nib; dma_addr_t nib; int ret; @@ -251,7 +251,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, } ret = vfio_pin_pages(&q->matrix_mdev->vdev, nib, 1, - IOMMU_READ | IOMMU_WRITE, &h_pfn); + IOMMU_READ | IOMMU_WRITE, &h_page); switch (ret) { case 1: break; @@ -267,7 +267,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, kvm = q->matrix_mdev->kvm; gisa = kvm->arch.gisa_int.origin; - h_nib = (h_pfn << PAGE_SHIFT) | (nib & ~PAGE_MASK); + h_nib = page_to_phys(h_page) | (nib & ~PAGE_MASK); aqic_gisa.gisc = isc; nisc = kvm_s390_gisc_register(kvm, isc); diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index b95ec2d78966..96b758e06c4a 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1917,18 +1917,18 @@ EXPORT_SYMBOL(vfio_set_irqs_validate_and_prepare); * @npage [in] : count of pages to be pinned. This count should not * be greater VFIO_PIN_PAGES_MAX_ENTRIES. * @prot [in] : protection flags - * @phys_pfn[out]: array of host PFNs + * @pages[out] : array of host pages * Return error or number of pages pinned. */ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, - int npage, int prot, unsigned long *phys_pfn) + int npage, int prot, struct page **pages) { struct vfio_container *container; struct vfio_group *group = device->group; struct vfio_iommu_driver *driver; int ret; - if (!phys_pfn || !npage || !vfio_assert_device_open(device)) + if (!pages || !npage || !vfio_assert_device_open(device)) return -EINVAL; if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) @@ -1943,7 +1943,7 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, if (likely(driver && driver->ops->pin_pages)) ret = driver->ops->pin_pages(container->iommu_data, group->iommu_group, iova, - npage, prot, phys_pfn); + npage, prot, pages); else ret = -ENOTTY; diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h index dbcd0e8c031b..dbfad8e20581 100644 --- a/drivers/vfio/vfio.h +++ b/drivers/vfio/vfio.h @@ -52,7 +52,7 @@ struct vfio_iommu_driver_ops { struct iommu_group *group, dma_addr_t user_iova, int npage, int prot, - unsigned long *phys_pfn); + struct page **pages); void (*unpin_pages)(void *iommu_data, dma_addr_t user_iova, int npage); int (*register_notifier)(void *iommu_data, diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index f10d0c4b1f26..de342d82b154 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -830,7 +830,7 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, struct iommu_group *iommu_group, dma_addr_t user_iova, int npage, int prot, - unsigned long *phys_pfn) + struct page **pages) { struct vfio_iommu *iommu = iommu_data; struct vfio_iommu_group *group; @@ -840,7 +840,7 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, bool do_accounting; dma_addr_t iova; - if (!iommu || !phys_pfn) + if (!iommu || !pages) return -EINVAL; /* Supported for v2 version only */ @@ -879,6 +879,7 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, do_accounting = list_empty(&iommu->domain_list); for (i = 0; i < npage; i++) { + unsigned long phys_pfn; struct vfio_pfn *vpfn; iova = user_iova + PAGE_SIZE * i; @@ -895,23 +896,25 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, vpfn = vfio_iova_get_vfio_pfn(dma, iova); if (vpfn) { - phys_pfn[i] = vpfn->pfn; + pages[i] = pfn_to_page(vpfn->pfn); continue; } remote_vaddr = dma->vaddr + (iova - dma->iova); - ret = vfio_pin_page_external(dma, remote_vaddr, &phys_pfn[i], + ret = vfio_pin_page_external(dma, remote_vaddr, &phys_pfn, do_accounting); if (ret) goto pin_unwind; - ret = vfio_add_to_pfn_list(dma, iova, phys_pfn[i]); + ret = vfio_add_to_pfn_list(dma, iova, phys_pfn); if (ret) { - if (put_pfn(phys_pfn[i], dma->prot) && do_accounting) + if (put_pfn(phys_pfn, dma->prot) && do_accounting) vfio_lock_acct(dma, -1, true); goto pin_unwind; } + pages[i] = pfn_to_page(phys_pfn); + if (iommu->dirty_page_tracking) { unsigned long pgshift = __ffs(iommu->pgsize_bitmap); @@ -934,14 +937,14 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, goto pin_done; pin_unwind: - phys_pfn[i] = 0; + pages[i] = NULL; for (j = 0; j < i; j++) { dma_addr_t iova; iova = user_iova + PAGE_SIZE * j; dma = vfio_find_dma(iommu, iova, PAGE_SIZE); vfio_unpin_page_external(dma, iova, do_accounting); - phys_pfn[j] = 0; + pages[j] = NULL; } pin_done: mutex_unlock(&iommu->lock); diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 9108de34a79b..c76a2c492bbd 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -148,7 +148,7 @@ bool vfio_file_has_dev(struct file *file, struct vfio_device *device); #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long)) int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, - int npage, int prot, unsigned long *phys_pfn); + int npage, int prot, struct page **pages); void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage); int vfio_dma_rw(struct vfio_device *device, dma_addr_t iova, void *data, size_t len, bool write);