Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2107042imw; Tue, 5 Jul 2022 23:30:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sEJDtM+61GCVkoBc1Ay7HNOGKVMdUgSxKox3mEmj89smDr6Kt4fudrMoE94QDchOwk8y2L X-Received: by 2002:a17:90b:4a8e:b0:1ec:b561:43b5 with SMTP id lp14-20020a17090b4a8e00b001ecb56143b5mr48572597pjb.239.1657089044619; Tue, 05 Jul 2022 23:30:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657089044; cv=pass; d=google.com; s=arc-20160816; b=TkrRprET9hob7WcXfxhwMPva+UGXZGsFL8DBuG0v2nB/SHw9PqpqPHYgPjTnbhmmBo 48KGQSfRueFQmfTgNjlfXINKATAR6qBNeoQYyLJOwdJixg8YTgUAmO94aYkA2vYDnAq6 Ci5+MVvtAzRBc+faGJtdcm+uM/on2hOgX5Ul3iTlv9cnse238tl5ExycuigFs2Xxg2e8 By9k1p++d9LupqhGYAnUlaDuQHZMrWSTNuzdOwGWANgBd2mlYAtQmlaY89wJjzVOOiNP Vy6g77JmASuHUCp6X2b7dPxxblf7CsRicgHGHdkyAHRBwENiRFJlcz6gg/coBEvFxv5i u6Xw== 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=L1NcSO/+32Awp5D+9PDT6tENVBaLW4gKwEHATrIa0cg=; b=fzp2Lols+/4qGqg0CCnc6JdKCH92dAxcEq3gDxUcquX4By9X96zlDAzzOEh4PvcvKQ JPaZdhZ3uDYTD/kla4SbP5Pses1DoHAugM7ZNC3QHqiWW2JhToH6lWV9R4lugj/ppGm0 jHRE/AYIoxr4y4GxkUttIm9QS1KENRZwDCx8KXoU5H8AX3H+Aq6iiIQ5ehV6HigP9pdS bwyAAB9Lab5hmZxCfo2ZCbLgK0+R7tLXLns8njo9mv4aGnhnGRJoQ/tMLiF94Mbv8Id9 gPl75NsSjesKUihs4zyr6qLyxfCQcNjrOZ6lgHSZnt6IgEtdq0GEi7K3bXKm3SwDn+Zs 3LBA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=nN5HiKQi; 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 v71-20020a63894a000000b00412747e431fsi4670498pgd.38.2022.07.05.23.30.25; Tue, 05 Jul 2022 23:30:44 -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=nN5HiKQi; 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 S230107AbiGFG3O (ORCPT + 99 others); Wed, 6 Jul 2022 02:29:14 -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 Content-Type: text/plain 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-Micro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/AXnTHCNSn/DxZ6jl5ZdSmkDDGWA7L3bW9RRkN39wJzM?= =?us-ascii?Q?LZUBi6acdA/yDLTXzbhHkA38wJguty1KHmEpIKXHJLK3KgNw2xyZwLjGBylo?= =?us-ascii?Q?MVTwrHmhf1POZYKmIK3wsw=3D=3D?= 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 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 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 --- 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) -- 2.17.1