Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2106488imw; Tue, 5 Jul 2022 23:29:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uv11A115azqedObHAvQmMibd+GiGJRRog88uJIVMENkNvkT3jvOhzlx6KoBfLyoE9M/dUO X-Received: by 2002:a17:90b:3b52:b0:1ec:db2a:b946 with SMTP id ot18-20020a17090b3b5200b001ecdb2ab946mr46549837pjb.229.1657088996860; Tue, 05 Jul 2022 23:29:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657088996; cv=pass; d=google.com; s=arc-20160816; b=0t3dhMFhAl4RsFiWqsBt6VOwVj8wf2j72bcVtMfHILFvs0mWrGQ+5Xp+hyUdkDBtI8 HBeie5xvZfldZ37tFTf+uZjpJUz5kGMDVA+VoPbd556qVyIsawEAS00ci+1CFszhj5tw lM3yKNNTsNB5cswAvH7cdTx2ga3VVcn1pIMTll0ptOOSWvFz2nZDikXoemRu1HcO9iB9 68f8oqrfgmcw7rtcpiwk4QKk5VVq350OFBDCz2or5kAxW5dotloaNz9Z5mwAEasuub5x VXLzRnIBz6sCL2JwJYxsbBlP70Jrp29cvWCZG+l9N5jSopXNGcqEw+HPwGidF3r9xrtq 3Igg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=LIc8WOGbQqnWuegxZUpyT8c7k0yV0Mb/niYZFvLPTUY=; b=sUsQke3InSi6v97ZJgaaYF3VlKvYhXiuoI1ggCmRBGwV0a4JvRSgZLnkoycZrXB/Bn KqP705j9i/d3T9XqnNRVjrV9p1UXTuqAn3mkdKL1Xv7luGxPh9iFvomtBBxwxPjvnt+z h/YSxQFTANOAx1jXIri3AYvvKYsAJSLq6Rzvj/hgQldH4XGoSyhUeUYYtOtHM+8oSk0I cKEHbHMyxoD41MjxUU4K8p0FYu+YO1FZcs46fzRubzMy55qbXPU9qKHdv+2KISEe0adG Odf2MkAmlHTI4iS7h9k8D4Lx3OknXESWjo+kxNZtNDvyObTX+MXFb4PUEOjFWdOJDpOq Yyow== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=g3tbaWsq; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i11-20020a170902cf0b00b0016bd8071da6si14530412plg.473.2022.07.05.23.29.43; Tue, 05 Jul 2022 23:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=g3tbaWsq; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbiGFG2T (ORCPT + 99 others); Wed, 6 Jul 2022 02:28:19 -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 Content-Type: text/plain 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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400002)(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 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- .../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); -- 2.17.1