From patchwork Thu Jul 27 20:24:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 127161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:d09a:b0:134:c3fc:3153 with SMTP id jc26csp189036rwb; Thu, 27 Jul 2023 13:47:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlH26VlV+Zj7GNTHlenzWsdWtOT56KfcqsUldYUSumLMD7eGmmSQaZgFupLO5sG06G/HkM71 X-Received: by 2002:a05:6300:800a:b0:10f:f672:6e88 with SMTP id an10-20020a056300800a00b0010ff6726e88mr192290pzc.4.1690490838170; Thu, 27 Jul 2023 13:47:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690490838; cv=pass; d=google.com; s=arc-20160816; b=RLyzklPn0l/PgybOmiJtGv0SWpF5Z6Xkm43UHe/Bvr3QyiO9egx/q8wj9t0Qfj4jD5 CxsVZ1HxYse/yxCp0H5snQ1Q2PTYb/2oVgpNaiPg+I2UDp3+NYCs3YQFmjB6ohTLxqX0 bwn92wn1LRh0PQ7kQ6abC8sr/7QIuxe6qYutqneboj6k8tDLmQjklyJ3dQPFZGWe5xOU c9O7oJ/1+s8AhXMqFF1q1UVEDluvjyFpbAyu2weTLx1Mvd1LrxXsUwGTsA2LNn4uSiZ8 +02Hi0iLj0Jn50ZPWLxGD/PKMuSHUlPGCJeOvIoYHDhe8YCCn6G/Ea7HGPlBcqZAfxES EnCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mUc06e5xx4kTwBKEnoGTOSehjX6v5imRbufbXUgPcoU=; fh=qC2Tv3KKwVGixY6WZei9zODHRrUJaQPqzd5TxSwHSnU=; b=w5NR9nNjmj0D3F6X+xBdNxUp6oCTjp6bHPjnGDgr+mUR/ElmZEiyW0hxXdyRQd69zb PtlFdOjhjVhNq6frhMpvMClEORxphCvbq8/E+lfyZIYZplFO40qUYQGkOOXbsBswFJYG Zc13OepJKVJ+Z0cY+JQabaseXyr50XPoaQDMxhkAfV1nXMc7M+nB217vXaLCwM4rZGgE tuRnNBkT866Mw0rgyYfcQmjxmFBQx8qCYdc1mMrdTJ7LahEm/KCoNvQ29F9Ua6V/W1Id z5nnyhiV2lWpsd5r2gSI0abNqBfRdbBzh/j0q7030iFALsNfdtKeZv64J0j8BuRhdz5k NbQQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=HMAvO2Wi; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 185-20020a6301c2000000b00553854417d8si1677383pgb.617.2023.07.27.13.47.04; Thu, 27 Jul 2023 13:47:18 -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=HMAvO2Wi; 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 S232852AbjG0UZN (ORCPT + 99 others); Thu, 27 Jul 2023 16:25:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjG0UZJ (ORCPT ); Thu, 27 Jul 2023 16:25:09 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2073.outbound.protection.outlook.com [40.107.92.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14DD02688; Thu, 27 Jul 2023 13:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PBqTn31NYP5zyDmVy7sHJxxbxCBcfCiylutNyVGdwHl0ZQTzLNs755P36n+vHF/DsXgEm0QjdPIBHI4qrukC77yAGTd+X6+eQb4u59ip3xUXWYepzyIsnrEkVadpEGsD5o3C+xKDGSNFTTJbGY/xhU0pZEc0JEIp3HyL4/nK6gsZd2TvlNmBWXDC0qkUBJ/tFc5JduWtvKeGU1qdJYM6qihNH//bsRVUZ3I0Fu28JI5HNbzdqlNmkEq/nisJ4ORUL6ShxgoybVGL1G91iZA8M4Q6WIiE371JqgV4Xl3r71gcs4tIMUa00Sgxio4eU0ywwgONV1vB/g+dtB3PI5Q3TQ== 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=mUc06e5xx4kTwBKEnoGTOSehjX6v5imRbufbXUgPcoU=; b=j+9xxVsWZQ9Og6dfpE1LffT4SNNK2fz+kZV2zqwHUHlD8f3pJw9eSwez5/28h6SfCBsVInxyHmD+j8I1C50AIZR3l6wsbJ699biy0UCzTxlDmf/jAIKvuNIPurFvzMhSEwvuX87yoVM7YiXXEVJqmEBneFGAHtqVVh3+LCx2SWV+2g5Sv6bhGEBbl5r+pqt+sH9MUjMSHqVyXzvlvdaU4yo0KlobVExZeYDAfmUA4hHyLHQRDO4rkeCTjPg1A1g1bI6ZDb7AH+qH9acp1Uxcy9dvTWs3s3DGNSkID7G5K6f+Z9kOVTizTFozD0EtdTzyH1XQjpoHjEyEfxLat2Hwug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mUc06e5xx4kTwBKEnoGTOSehjX6v5imRbufbXUgPcoU=; b=HMAvO2WimyySL6ACQ8QeYZ6YCg9rOXVOyjZcG81hGIuMtxNGraGLwnvlB4YYrJsyerL7JsqVvQH3tONg8ag567oIKMzzNIBG9dU6s+at9kUIMf3Eko9qoIj3MmWeaOxUZP6mcVBAxsMDdOK5XQpzOWmzSLgzI849cBfynfGi00rtXlYSixqnIkDq+3yg/pbpPRg4p5CHgHdW3cTX/IaPJ2xqkiWJWvain1CbtrQJcHjUXV0F0TalUnu2NDhtoNVfhKPciz7Qz4ist6KDogF5wLzSism/pGsqjBNI7j+vmIcysX5qICq90/DQGLQiyjbjRmm+TIvNWdY+99MjGY6Ygg== Received: from DM6PR02CA0045.namprd02.prod.outlook.com (2603:10b6:5:177::22) by LV2PR12MB5821.namprd12.prod.outlook.com (2603:10b6:408:17a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Thu, 27 Jul 2023 20:25:06 +0000 Received: from DM6NAM11FT099.eop-nam11.prod.protection.outlook.com (2603:10b6:5:177:cafe::74) by DM6PR02CA0045.outlook.office365.com (2603:10b6:5:177::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 20:25:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DM6NAM11FT099.mail.protection.outlook.com (10.13.172.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 20:25:05 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Thu, 27 Jul 2023 13:24:49 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.37; Thu, 27 Jul 2023 13:24:48 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Thu, 27 Jul 2023 13:24:47 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , , Subject: [PATCH v10 1/6] vfio: Do not allow !ops->dma_unmap in vfio_pin/unpin_pages() Date: Thu, 27 Jul 2023 13:24:32 -0700 Message-ID: <85d622729d8f2334b35d42f1c568df1ededb9171.1690488745.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT099:EE_|LV2PR12MB5821:EE_ X-MS-Office365-Filtering-Correlation-Id: 75a4fe6d-af71-4ac9-1d1a-08db8edf90a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +3TVDUsm9Cvvb5fY03/qivz5KhcM02XQgTaolmfv1LvaOnNtWaIwO5QyeM+ulohizXXlnNwx0kc1ZUrMOE0JDP+Q7yF8kfoTbUYohlq9cFeO/Ejtq46HVq2gShEUEpTDSihdbybbZkoWblXZVCx3G1m1TJpD9G2p+FzMkBA7s+NN+9aMNhgnoKPktudhMPgVjkdOVcNCrZY2EOIlI8L9lF9tonYpYjGA88gwgg/brsof/gr45uB3wtWpxM/uIJh8AHAw3l5w3rXJLoy+qkcLu7Ets30BKK7u9iQWJkoVc9PaJDfecwO5RIw6UREY9dUlVuRAHkNvigTGdn4jiOqSW1Jv0aZydedzkQIvOfbA/E5l7NL2OUAkoKWG5mkLaC1+gWOU4wPKgqoprWhf8a8pc87mebX8CAmpAHpPmBhICAmGxMEBYvtKlkCOjb3uTgu3MB36tZz8q9xEZG1+W/HNDUtj2YdCq4Z9xuCCj0z6se9Q+g9Y314qpkY2D0cXDS0Z11Sx+pLMUl7otO3/elnQTwm2kdBK+o+sFZn2DHUYGuYu4Y3uUYcVqXUdPrVxx0Z6ooHhqcHv+SBgx8j4jTJutGYQ4xYSp4P+35t0QDwD1Ke+dQqwW7hbmprKdpxQdN5zZFDr9y7i9y/dM143UUOmjb2bcK6vCcdwyYEO9CBYlFcDw0ahwDOTnLvjNMz5U7e+mX7F1bzWm6JHys9nGN5bBAAJvMMvFY+/6ijz83n/9GP0slFgP1AZsweCFIrXncy1 X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(376002)(39860400002)(136003)(396003)(346002)(82310400008)(451199021)(46966006)(36840700001)(40470700004)(2906002)(316002)(8936002)(8676002)(7416002)(40460700003)(5660300002)(41300700001)(36756003)(86362001)(40480700001)(426003)(7696005)(6666004)(54906003)(478600001)(82740400003)(7636003)(356005)(26005)(186003)(336012)(110136005)(2616005)(83380400001)(70586007)(70206006)(36860700001)(47076005)(4326008);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2023 20:25:05.7045 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 75a4fe6d-af71-4ac9-1d1a-08db8edf90a2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT099.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5821 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772608121100443637 X-GMAIL-MSGID: 1772608121100443637 A driver that doesn't implement ops->dma_unmap shouldn't be allowed to do vfio_pin/unpin_pages(), though it can use vfio_dma_rw() to access an iova range. Deny !ops->dma_unmap cases in vfio_pin/unpin_pages(). Suggested-by: Kevin Tian Reviewed-by: Kevin Tian Reviewed-by: Yi Liu Reviewed-by: Jason Gunthorpe Reviewed-by: Alex Williamson Signed-off-by: Nicolin Chen --- drivers/vfio/vfio_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 902f06e52c48..0da8ed81a97d 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1483,6 +1483,8 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, /* group->container cannot change while a vfio device is open */ if (!pages || !npage || WARN_ON(!vfio_assert_device_open(device))) return -EINVAL; + if (!device->ops->dma_unmap) + return -EINVAL; if (vfio_device_has_container(device)) return vfio_device_container_pin_pages(device, iova, npage, prot, pages); @@ -1520,6 +1522,8 @@ void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage) { if (WARN_ON(!vfio_assert_device_open(device))) return; + if (WARN_ON(!device->ops->dma_unmap)) + return; if (vfio_device_has_container(device)) { vfio_device_container_unpin_pages(device, iova, npage);