From patchwork Thu Dec 29 10:07:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 13083398 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 1166DC53210 for ; Thu, 29 Dec 2022 10:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233205AbiL2KQM (ORCPT ); Thu, 29 Dec 2022 05:16:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233214AbiL2KNp (ORCPT ); Thu, 29 Dec 2022 05:13:45 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2055.outbound.protection.outlook.com [40.107.237.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1C3BD11F for ; Thu, 29 Dec 2022 02:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f6sU7rC8rO9MH5W+s4eTLuxdnfNcZeJRI663A+omR0BawZBT5dqyTcBb1D0dxSeE7fdmOARsrYb3jKY87YMwEoBV+W71ODDPvw5Z1TOr32kJbra8QgsRjAIVWE1qI3LNmzbDxw9xrRLGvIKflcyrmOxNCwmurHQR+uqpCfocq+4anCF4mNUraCCOdP6ev4vXCV8NnH65MycD5MJ7p9ZL2h9cM7DexlFBCMXxpy7OWVfghVYmKUMgLUQwRTPPTlNr10Gj5xIyZwkZfonGbCLxyk0icwuYbSlda1XHyN5aMaRuUlhE83n8xP6M3Z6SL0cG4bqjJ7F2NAb3UcJaIMeb3g== 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=+TcsfW/dp/8PqsCSSvTuVvqWyYIokfo7N8BoKIYBpKE=; b=ABSu9g1wueaFyW8KQSHteUxDgF7GEs9ARLzHGaycPxfZ9U7FWUCnV+kv+lwsA9QydeZCbp6/vtb9Ez/LUv5tWqaRBJvvZrTl+ITEKanmK2mmrcCZdMtUTxpyEW4beK94jrAbVIAhiD8dhYZSewHKd/CynabSVyYPi7gUI0n//B7Dx3RbAkjd26AMzAaS2Kk6RPeOQ16qVJHcf7A6ldkNoLLSn+M400eawmREkGHBuLy7XLDDkWgg/hGRfmowStrSTDZYERildnUXB9ZkNRfRRo9ySX7GJXUT2O6m7Z/rbs0W1nFebA7dD12VBeKzgyeJCYYRZ09cMNY+4t6xxywnrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=+TcsfW/dp/8PqsCSSvTuVvqWyYIokfo7N8BoKIYBpKE=; b=iU4SNqBFUKZl+O7APPo54R/BpFZ9B7onpXKQtb1S/+spnRHUAWVemxDUZJeRUwDC7lHKaYGsg2LdkvB2K4s9jWai0NC9hPnKs/qwjUAVgbgeyeFHsnDXAbTZi/YC2EXpy9jAhxHHELGN1WwI62rGaLrhbV+aGqP32/Ovu6bWKd80PE1Q/y6z9oTHO8e9wJ7qWZXNquBt+3O2dOzjiKru+NEUnJSpNeVE4h1lJLRz5FzROIiT69gQhzyJ+RPHHKpIFW1434x7UACBXLcpTOZJVs0gycmYpq2x+lM+dwEySfDMAC8HDFy1JToMhxGbh0gsa0QjL/TF4vKZZw38BPbSZA== Received: from MW4P220CA0008.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::13) by BY5PR12MB4998.namprd12.prod.outlook.com (2603:10b6:a03:1d4::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16; Thu, 29 Dec 2022 10:08:26 +0000 Received: from CO1NAM11FT081.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::17) by MW4P220CA0008.outlook.office365.com (2603:10b6:303:115::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16 via Frontend Transport; Thu, 29 Dec 2022 10:08:26 +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 CO1NAM11FT081.mail.protection.outlook.com (10.13.174.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.17 via Frontend Transport; Thu, 29 Dec 2022 10:08:26 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.36; Thu, 29 Dec 2022 02:08:20 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.36; Thu, 29 Dec 2022 02:08:20 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Thu, 29 Dec 2022 02:08:16 -0800 From: Yishai Hadas To: , CC: , , , , , , , , , Subject: [PATCH vfio 1/6] vfio/mlx5: Fix UBSAN note Date: Thu, 29 Dec 2022 12:07:29 +0200 Message-ID: <20221229100734.224388-2-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20221229100734.224388-1-yishaih@nvidia.com> References: <20221229100734.224388-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT081:EE_|BY5PR12MB4998:EE_ X-MS-Office365-Filtering-Correlation-Id: 510d0b7d-4684-495d-7e1d-08dae984a0ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c6wxsdHxCzVK4nIyHMwNtbWWE9dJdiuTZEzfV/3p+asmzSJCofS8nMNeHqJqqEhy4XRes5KlT9M1Lw9P6OcKCIigEp80MSJFOhZqxS5a6P0dj4LH5SQxOnY6nszXKbfNvPtLjr0pylL61kW7ZtRDsYlXc+XJh1Q7zR+LGyUANsJ04q/40+MPkUTZWkrlpryRRvLLZhaLB7ZlcJuXugcTEJvAD/fmGeytMtf/yqlBzcUcXh7YLJFdy9mK699FQqFCdCYlIj+P33hbizqIuOmJTxBXKOzq6rcwQsYQhq7jsyXDQK3sD6vbHj0jmvGouxykwOWxhjo+uB4JJrZQ6A8zysaXa6r08OJmMPvVZk5G9/ufxuRYOuCddSjntV/V2LELbUXfBqkcdcxfiqx5+AoqJlBh+5a1hlbTM2FTh4dSREhnVivdBdqzmwptANvV9pF+XeCejoNvRB09GZfV/kQHuSqEKkvONB6QdidoMwIGjSnHVbUJtzPUNc9A03GBc3smG1DhFh0qtENuxaYUZLNfKG0TYn745/3hqcVWkz+a8D7RddTR2m5jkmAndhplW6ms0ocvNv5H7BfrQWTfugxnE+HXdDXeUIXfT25rlt7JssYbfkeNaqDk1jYLhLHGaogJp+R1gTyhvDTY9mee+9BpZWLK6OT9WBxwkKvJhIhtMK6VHH4z8gJl/FouqW9AhOkQZ3qfa9UVdkNWeY2A6x2wNA== 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:(13230022)(4636009)(376002)(346002)(396003)(39860400002)(136003)(451199015)(36840700001)(40470700004)(46966006)(426003)(83380400001)(36860700001)(47076005)(336012)(86362001)(8936002)(356005)(2906002)(41300700001)(5660300002)(70206006)(82740400003)(40460700003)(82310400005)(7696005)(40480700001)(6666004)(478600001)(1076003)(26005)(2616005)(4326008)(186003)(70586007)(54906003)(6636002)(316002)(110136005)(7636003)(8676002)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2022 10:08:26.6088 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 510d0b7d-4684-495d-7e1d-08dae984a0ad 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: CO1NAM11FT081.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4998 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Prevent calling roundup_pow_of_two() with value of 0 as it causes the below UBSAN note. Move this code and its few extra related lines to be called only when it's really applicable. UBSAN: shift-out-of-bounds in ./include/linux/log2.h:57:13 shift exponent 64 is too large for 64-bit type 'long unsigned int' CPU: 15 PID: 1639 Comm: live_migration Not tainted 6.1.0-rc4 #1116 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 Call Trace: dump_stack_lvl+0x45/0x59 ubsan_epilogue+0x5/0x36 __ubsan_handle_shift_out_of_bounds.cold+0x61/0xef ? lock_is_held_type+0x98/0x110 ? rcu_read_lock_sched_held+0x3f/0x70 mlx5vf_create_rc_qp.cold+0xe4/0xf2 [mlx5_vfio_pci] mlx5vf_start_page_tracker+0x769/0xcd0 [mlx5_vfio_pci] vfio_device_fops_unl_ioctl+0x63f/0x700 [vfio] __x64_sys_ioctl+0x433/0x9a0 do_syscall_64+0x3d/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd Fixes: 79c3cf279926 ("vfio/mlx5: Init QP based resources for dirty tracking") Signed-off-by: Yishai Hadas --- drivers/vfio/pci/mlx5/cmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/pci/mlx5/cmd.c b/drivers/vfio/pci/mlx5/cmd.c index 64e68d13cb98..c5dcddbc4126 100644 --- a/drivers/vfio/pci/mlx5/cmd.c +++ b/drivers/vfio/pci/mlx5/cmd.c @@ -1036,14 +1036,14 @@ mlx5vf_create_rc_qp(struct mlx5_core_dev *mdev, if (!qp) return ERR_PTR(-ENOMEM); - qp->rq.wqe_cnt = roundup_pow_of_two(max_recv_wr); - log_rq_stride = ilog2(MLX5_SEND_WQE_DS); - log_rq_sz = ilog2(qp->rq.wqe_cnt); err = mlx5_db_alloc_node(mdev, &qp->db, mdev->priv.numa_node); if (err) goto err_free; if (max_recv_wr) { + qp->rq.wqe_cnt = roundup_pow_of_two(max_recv_wr); + log_rq_stride = ilog2(MLX5_SEND_WQE_DS); + log_rq_sz = ilog2(qp->rq.wqe_cnt); err = mlx5_frag_buf_alloc_node(mdev, wq_get_byte_sz(log_rq_sz, log_rq_stride), &qp->buf, mdev->priv.numa_node); From patchwork Thu Dec 29 10:07:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 13083400 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 21159C4708E for ; Thu, 29 Dec 2022 10:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233357AbiL2KQO (ORCPT ); Thu, 29 Dec 2022 05:16:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233232AbiL2KNp (ORCPT ); Thu, 29 Dec 2022 05:13:45 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2060.outbound.protection.outlook.com [40.107.237.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3CBEE0D0 for ; Thu, 29 Dec 2022 02:08:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CMh/mhvyMVFGSucNo6Pi4g3tIP1i0staiizsJmD0eFwyJ5vhi0vuUWihvAzkxtkwsHi0Nyj4cK/4+UuiUCF4uTw5AJc7VumbbDKsrSIya/flE/mnnWc5H0Ma+tlF9LYIlIvuvbDne8AfeURGiyibN63QlWucDTjislk+3l9NhKicMxcf2d12I6kMy+OyuG+wnBy8RUlaApdhmECZBU67Pepe1zmFH3MYrpI/rpWfgyXohnvKOal7L2QjP4xvz8zqw1Bzcep1N007qqSiFCt5bCiKM8Frgze4WteMHxzTpDjA0D4GxbZDPRcPnjqHRnsm7HvjZfFTa+QnY452idPz5Q== 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=FRwQek0anxxy0zZiASG8tv0VCq12SKcFXfGRel+KhjQ=; b=krLUUS3dWBdWKCkvtkBPiL9na3GvMbcWMelQogNNJ2yQJ8jNKlYqQ4pPMiFKcex2p0u8S3lIMjIqAB0EefkZNaDp4IRcgdhkylzWhfrjRWWr3te8hXciV/bt1VtK4aQlKmNfbGcnMQyC0HgzGZTpGXW93cwsTua6CCgqMnkCVgl0PRILHtnivSc9xgo6HnhmdRaPNnn2fjPqhqw+ArYGhZp57XPljwEg5QFkHrIzqBypLItmuvEkmEmMNW2yZnCZsSLoL9YAMfAlShjoAk6P8NZso0YcWOJcM86mvJkkn871xN88l1tfDP3QliouL7rHK7XGqIgOY+UBdo0SNY6Umw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=FRwQek0anxxy0zZiASG8tv0VCq12SKcFXfGRel+KhjQ=; b=a0hS99hgT19MWd9RdTYvkemFueXsWRYZ4Mkx8KK5MnB1Eg9PMRePvRu4D/mDOVODi/fj84IY8bbH5Ml9X1CSSAy6OTQjzqczazqpSXEClH0yfUXab1q+6qB8RMfYtsAMQWSerGMhEQ6RtkpEQEmcq4NNG+OFr0KYyUKi8aDrOkmWdKJBXDz8AymyV1pYNR9vG16vmtdRaJANV9mFsGrP92LLOKtXINE2JZIhF1lCwkFy0sBhjjWRi3GMPkguOXbWsf/YEUXibyibvCTFFX33g4+XSANHd5sCa95iTraKzGwJUT+Cspgixx4hANdavc1rmrntSbHT49IPvrSS8A6xRw== Received: from BN1PR13CA0014.namprd13.prod.outlook.com (2603:10b6:408:e2::19) by PH8PR12MB7135.namprd12.prod.outlook.com (2603:10b6:510:22c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16; Thu, 29 Dec 2022 10:08:33 +0000 Received: from BN8NAM11FT071.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::e9) by BN1PR13CA0014.outlook.office365.com (2603:10b6:408:e2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.7 via Frontend Transport; Thu, 29 Dec 2022 10:08:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT071.mail.protection.outlook.com (10.13.177.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.17 via Frontend Transport; Thu, 29 Dec 2022 10:08:33 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Thu, 29 Dec 2022 02:08:24 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.36; Thu, 29 Dec 2022 02:08:23 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Thu, 29 Dec 2022 02:08:20 -0800 From: Yishai Hadas To: , CC: , , , , , , , , , Subject: [PATCH vfio 2/6] vfio/mlx5: Allow loading of larger images than 512 MB Date: Thu, 29 Dec 2022 12:07:30 +0200 Message-ID: <20221229100734.224388-3-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20221229100734.224388-1-yishaih@nvidia.com> References: <20221229100734.224388-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT071:EE_|PH8PR12MB7135:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e01960c-569e-4a03-45ad-08dae984a4ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u8lkVbHHFTf41HzfVYxlzUhw6ryAG5ZzVbucih8WZNMWHrthXDnEZ0udzkMcMsaV5yOdlSDku2mJY5+Y1PXNktuKaisJMf/GOrZWKTjfDvDTTdNOOUDv0hIpzy+UA8bzhxl+41HMnvvaJAIiZSLu3F2cUDWnKCHjC35s7mOpqh4SufqyaB78B8FpKyGtFhfIQxOqyK4ZDGUNH9PhZvUYJWyBGPBmwArvBuRNKTY3VmA2Izx0I1Ut3VLaWMETfBM2C3Kjr7ErEhLDddzEguKBz6GzyizGRFkNBN933TXB9H26RVxUYuW6gnw9JykjVKV2Z6CrPCrSwJiuzxDZpLEkcwzNehIMo+E6DA/QWk+8jJRLfcQWNfZIy8aTKJuGSVhmBxSXc1hDdA3Bdeu4WxKqo5XE92bbgxQWzPA2wueir6ol8xo5LZLvqPzmXFXQ4jgqaqj9Fc5NVL1/3cju5qpRSeZtZ8PHrLU3G1BKC7XVUnSDveS0331pQ3CLo6SIV0qOYcioqARUzdqnHZxfO3/F0QASY0dz4ytNPTWI4Ii0ZzA7GOjEeg4vfEmKXJ4bJh39agKb1wUzkOx7rJjkidBc/34W7KEq8aUMOf7Lx5F1UWyPHei1m2TavFYsqfEcO77X4IgtQdXgKORt2xvORj4pYAxoEl8PaDsjOIAXJ/iKyji9SeM3RNUQYAzrsI7wO9APAtkJiL305quLKl8gbcwKtg== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199015)(46966006)(40470700004)(36840700001)(478600001)(6666004)(26005)(186003)(7696005)(83380400001)(2616005)(1076003)(47076005)(41300700001)(336012)(426003)(82310400005)(36860700001)(4326008)(8676002)(7636003)(6636002)(54906003)(110136005)(82740400003)(36756003)(40480700001)(86362001)(8936002)(40460700003)(70586007)(5660300002)(316002)(356005)(70206006)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2022 10:08:33.2089 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e01960c-569e-4a03-45ad-08dae984a4ad 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT071.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7135 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Allow loading of larger images than 512 MB by dropping the arbitrary hard-coded value that we have today and move to use the max device loading value which is for now 4GB. As part of that we move to use the GFP_KERNEL_ACCOUNT option upon allocating the persistent data of mlx5 and rely on the cgroup to provide the memory limit for the given user. The GFP_KERNEL_ACCOUNT option lets the memory allocator know that this is untrusted allocation triggered from userspace and should be a subject of kmem accountingis, and as such it is controlled by the cgroup mechanism. Signed-off-by: Yishai Hadas --- drivers/vfio/pci/mlx5/cmd.c | 11 ++++++----- drivers/vfio/pci/mlx5/main.c | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/vfio/pci/mlx5/cmd.c b/drivers/vfio/pci/mlx5/cmd.c index c5dcddbc4126..0586f09c69af 100644 --- a/drivers/vfio/pci/mlx5/cmd.c +++ b/drivers/vfio/pci/mlx5/cmd.c @@ -373,7 +373,7 @@ mlx5vf_alloc_data_buffer(struct mlx5_vf_migration_file *migf, struct mlx5_vhca_data_buffer *buf; int ret; - buf = kzalloc(sizeof(*buf), GFP_KERNEL); + buf = kzalloc(sizeof(*buf), GFP_KERNEL_ACCOUNT); if (!buf) return ERR_PTR(-ENOMEM); @@ -1032,7 +1032,7 @@ mlx5vf_create_rc_qp(struct mlx5_core_dev *mdev, void *in; int err; - qp = kzalloc(sizeof(*qp), GFP_KERNEL); + qp = kzalloc(sizeof(*qp), GFP_KERNEL_ACCOUNT); if (!qp) return ERR_PTR(-ENOMEM); @@ -1213,12 +1213,13 @@ static int alloc_recv_pages(struct mlx5_vhca_recv_buf *recv_buf, int i; recv_buf->page_list = kvcalloc(npages, sizeof(*recv_buf->page_list), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!recv_buf->page_list) return -ENOMEM; for (;;) { - filled = alloc_pages_bulk_array(GFP_KERNEL, npages - done, + filled = alloc_pages_bulk_array(GFP_KERNEL_ACCOUNT, + npages - done, recv_buf->page_list + done); if (!filled) goto err; @@ -1248,7 +1249,7 @@ static int register_dma_recv_pages(struct mlx5_core_dev *mdev, recv_buf->dma_addrs = kvcalloc(recv_buf->npages, sizeof(*recv_buf->dma_addrs), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!recv_buf->dma_addrs) return -ENOMEM; diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c index 9feb89c6d939..79de38931d24 100644 --- a/drivers/vfio/pci/mlx5/main.c +++ b/drivers/vfio/pci/mlx5/main.c @@ -21,8 +21,8 @@ #include "cmd.h" -/* Arbitrary to prevent userspace from consuming endless memory */ -#define MAX_MIGRATION_SIZE (512*1024*1024) +/* Device specification max LOAD size */ +#define MAX_LOAD_SIZE (BIT(__mlx5_bit_sz(load_vhca_state_in, size)) - 1) static struct mlx5vf_pci_core_device *mlx5vf_drvdata(struct pci_dev *pdev) { @@ -73,12 +73,13 @@ int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf, int ret; to_fill = min_t(unsigned int, npages, PAGE_SIZE / sizeof(*page_list)); - page_list = kvzalloc(to_fill * sizeof(*page_list), GFP_KERNEL); + page_list = kvzalloc(to_fill * sizeof(*page_list), GFP_KERNEL_ACCOUNT); if (!page_list) return -ENOMEM; do { - filled = alloc_pages_bulk_array(GFP_KERNEL, to_fill, page_list); + filled = alloc_pages_bulk_array(GFP_KERNEL_ACCOUNT, to_fill, + page_list); if (!filled) { ret = -ENOMEM; goto err; @@ -87,7 +88,7 @@ int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf, ret = sg_alloc_append_table_from_pages( &buf->table, page_list, filled, 0, filled << PAGE_SHIFT, UINT_MAX, SG_MAX_SINGLE_ALLOC, - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (ret) goto err; @@ -467,7 +468,7 @@ mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev, bool track) size_t length; int ret; - migf = kzalloc(sizeof(*migf), GFP_KERNEL); + migf = kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT); if (!migf) return ERR_PTR(-ENOMEM); @@ -564,7 +565,7 @@ mlx5vf_resume_read_image_no_header(struct mlx5_vhca_data_buffer *vhca_buf, { int ret; - if (requested_length > MAX_MIGRATION_SIZE) + if (requested_length > MAX_LOAD_SIZE) return -ENOMEM; if (vhca_buf->allocated_length < requested_length) { @@ -648,7 +649,7 @@ mlx5vf_resume_read_header(struct mlx5_vf_migration_file *migf, u64 flags; vhca_buf->header_image_size = le64_to_cpup((__le64 *)to_buff); - if (vhca_buf->header_image_size > MAX_MIGRATION_SIZE) { + if (vhca_buf->header_image_size > MAX_LOAD_SIZE) { ret = -ENOMEM; goto end; } @@ -781,7 +782,7 @@ mlx5vf_pci_resume_device_data(struct mlx5vf_pci_core_device *mvdev) struct mlx5_vhca_data_buffer *buf; int ret; - migf = kzalloc(sizeof(*migf), GFP_KERNEL); + migf = kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT); if (!migf) return ERR_PTR(-ENOMEM); From patchwork Thu Dec 29 10:07:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 13083401 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 41E9AC5479D for ; Thu, 29 Dec 2022 10:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233364AbiL2KQQ (ORCPT ); Thu, 29 Dec 2022 05:16:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233231AbiL2KNp (ORCPT ); Thu, 29 Dec 2022 05:13:45 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2041.outbound.protection.outlook.com [40.107.244.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02045DE8E for ; Thu, 29 Dec 2022 02:08:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j1KzeAZGubVzFzf/mzZZAu3N0UfUNytUtL9Rl1z5vbUNdxe0ayKbIAS4q4oibsA+jezjs7KX7wVrFsFGi4p+jk0EeCl5cQ2l+V7+DGCnKcNnZx8Rn76c2gvd5beVU8OHo6sx+feeTLgcU3yvVhJ4HaD15Br31F+RAFoYQtSxONlMU0YoEmMD9mCC1nJQD/5ysTwABmLzmWfsNGioVJGOnJyeqWL6Y0x4+OyXTsvbL5lbjh6ukAmFyECDgau9e5ZcIsTde0iCiOYDnxzk70CUTWF4EXaPsRNkSfpjnGFspOMT6hvqLgMSA2eNy6GcTbFSMT1Z6M0N1yEusYP5E7TX8g== 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=iB+wwZESLnJeV0tnBePwfhYaT1OSc27ioTbYMJScf8g=; b=l4qWBsgSRtbxGLvhlTRR4w2qLJVQgP+uyyoZZgVnF4BFan7ORlcX1HFp83LcoJ0FqBMUcghwonnmHMDHIEq5a44Y1quXJQba33HdDgz6JPttc0PYFxYbyuBHpQCHdRUE6n1vyNkXDgwaVkUJFWu3mT+QNreSLRnlpBRpeYssg0J1/WWIj4zo/Biau6NPX3kJxORCWQqQezqKIVXMGjbslcHLoWJsj6GiE+DApD8LuPeByt9/qdfgYMDwCtsZzRTtzxKtJ6jqEXVfmm6i/N7abuNtyvgcQd7AlyKaClznVYBqMCnIf+IO1hh7J29l6m5uk33ZYRdwul0tPo1lOYSVJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=iB+wwZESLnJeV0tnBePwfhYaT1OSc27ioTbYMJScf8g=; b=Q/dVHW4BguFTb+mTDC5SHGq/94k5FugYmsXHEhde4HPn2bhgz+7jhsr2pRlNgbyxNEbsXOiGPT9by0VFL06N5iYGaieu7RGxr2Yp4rowCDgyso91KUxXF42RIauDnDh65fPq09As5oN5AOwGtqiOt7N/vIxjDs1aF9XQlvYmCQvOMdwS4JvLU2euVYUNsM/a4RWJlu5QRJbiJ5Jy8nU3Yp1dbI28F7q1pQRmTEDc86MCM8CWSs4Miokc8W/ughPk04xKYu7VlwD2jkcfwoAn2/QBckmZl9vsTe2Z1XHX5sRPbPkKRaj76W+M+FgA3LFP0uU5LHBLWKnU72rbw0GNSg== Received: from MW4P220CA0015.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::20) by DM6PR12MB4091.namprd12.prod.outlook.com (2603:10b6:5:222::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16; Thu, 29 Dec 2022 10:08:34 +0000 Received: from CO1NAM11FT081.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::db) by MW4P220CA0015.outlook.office365.com (2603:10b6:303:115::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.17 via Frontend Transport; Thu, 29 Dec 2022 10:08:34 +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 CO1NAM11FT081.mail.protection.outlook.com (10.13.174.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.17 via Frontend Transport; Thu, 29 Dec 2022 10:08:34 +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.36; Thu, 29 Dec 2022 02:08:27 -0800 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.36; Thu, 29 Dec 2022 02:08:27 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Thu, 29 Dec 2022 02:08:24 -0800 From: Yishai Hadas To: , CC: , , , , , , , , , Subject: [PATCH vfio 3/6] vfio: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations Date: Thu, 29 Dec 2022 12:07:31 +0200 Message-ID: <20221229100734.224388-4-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20221229100734.224388-1-yishaih@nvidia.com> References: <20221229100734.224388-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT081:EE_|DM6PR12MB4091:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ff366ef-0d0a-439e-1f1c-08dae984a534 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mtJgBeEiC0U3BYOgb1R3FTAac88Y/+z7mncDuABm1+xi9mfge7Z56vLSI3ZpOPALqYJlaHnw7ROzQvA+1Um6Mr/8DK4AdeTDSWZmtZvp/E642FV+alb7vj9dYYuVQMeDOLarUrpr7tDq3OflIzkGg9B1kU2rhufl1GjCQN8NOvUhf6eFvME+PNeCGNV+Ez8owdoSzYJlT7fLydtRoFrr9BmFr5mBbbz+hSgisb3uLPDZzN4MSkJ9bdbfX60mHwGpho9nJ5+wpVPyZ2mVNr/hcup2GQ2RMP3W0dVNtPcQrkpor/NsdPrzasxCQxY28LJiJ7lp+Zzd6cnNnYDeuqkHXnu0FZ9e0nTL+wRxA5qT1hShYM5zBxWxDCXoCENCv9eKJP3TY0GRb8asAEy1JsIuvEPbyy8LUzP8Zh4M0Ta6/oZvM8kUtEO6f9UycDHIz/TygeBx9VLMVZyxEMv911lDdIHCCQipD5+hUtmeEScigo2v+B7HV7cPgA2AUYSpiCOY/cxv+Mx3GX0ePQBHFIHhrq2/ILrgAS7tBs03pbPlBPzgdqoiboksu13uZUMyGxzNA/gn9CGaaG4gbN26Qpestu68+wsIIDOLkblLEzNAk0IofAQmkuXFPcPSxks9bw8Z2hHUUyfk7hvGRE1AI6NZbNaFNZkZnigr/rO9e2nMOcB5H81/ntgLQxd8PX09JGKG2xmpmEY5+Qt6TeRUeGo0RQ== 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:(13230022)(4636009)(376002)(346002)(396003)(39860400002)(136003)(451199015)(36840700001)(40470700004)(46966006)(426003)(83380400001)(36860700001)(47076005)(336012)(86362001)(8936002)(356005)(2906002)(41300700001)(5660300002)(70206006)(82740400003)(40460700003)(82310400005)(7696005)(40480700001)(6666004)(478600001)(1076003)(26005)(2616005)(4326008)(186003)(70586007)(54906003)(6636002)(316002)(110136005)(7636003)(8676002)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2022 10:08:34.2020 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ff366ef-0d0a-439e-1f1c-08dae984a534 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: CO1NAM11FT081.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4091 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Jason Gunthorpe Use GFP_KERNEL_ACCOUNT for userspace persistent allocations. The GFP_KERNEL_ACCOUNT option lets the memory allocator know that this is untrusted allocation triggered from userspace and should be a subject of kmem accountingis, and as such it is controlled by the cgroup mechanism. The way to find the relevant allocations was for example to look at the close_device function and trace back all the kfrees to their allocations. Signed-off-by: Jason Gunthorpe Signed-off-by: Yishai Hadas --- drivers/vfio/container.c | 2 +- drivers/vfio/pci/vfio_pci_config.c | 6 +++--- drivers/vfio/pci/vfio_pci_core.c | 7 ++++--- drivers/vfio/pci/vfio_pci_igd.c | 2 +- drivers/vfio/pci/vfio_pci_intrs.c | 10 ++++++---- drivers/vfio/pci/vfio_pci_rdwr.c | 2 +- drivers/vfio/virqfd.c | 2 +- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/vfio/container.c b/drivers/vfio/container.c index b7a9560ab25e..5f398c493a1b 100644 --- a/drivers/vfio/container.c +++ b/drivers/vfio/container.c @@ -367,7 +367,7 @@ static int vfio_fops_open(struct inode *inode, struct file *filep) { struct vfio_container *container; - container = kzalloc(sizeof(*container), GFP_KERNEL); + container = kzalloc(sizeof(*container), GFP_KERNEL_ACCOUNT); if (!container) return -ENOMEM; diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 4a350421c5f6..523e0144c86f 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -1244,7 +1244,7 @@ static int vfio_msi_cap_len(struct vfio_pci_core_device *vdev, u8 pos) if (vdev->msi_perm) return len; - vdev->msi_perm = kmalloc(sizeof(struct perm_bits), GFP_KERNEL); + vdev->msi_perm = kmalloc(sizeof(struct perm_bits), GFP_KERNEL_ACCOUNT); if (!vdev->msi_perm) return -ENOMEM; @@ -1731,11 +1731,11 @@ int vfio_config_init(struct vfio_pci_core_device *vdev) * no requirements on the length of a capability, so the gap between * capabilities needs byte granularity. */ - map = kmalloc(pdev->cfg_size, GFP_KERNEL); + map = kmalloc(pdev->cfg_size, GFP_KERNEL_ACCOUNT); if (!map) return -ENOMEM; - vconfig = kmalloc(pdev->cfg_size, GFP_KERNEL); + vconfig = kmalloc(pdev->cfg_size, GFP_KERNEL_ACCOUNT); if (!vconfig) { kfree(map); return -ENOMEM; diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 26a541cc64d1..a6492a25ff6a 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -144,7 +144,8 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev) * of the exclusive page in case that hot-add * device's bar is assigned into it. */ - dummy_res = kzalloc(sizeof(*dummy_res), GFP_KERNEL); + dummy_res = + kzalloc(sizeof(*dummy_res), GFP_KERNEL_ACCOUNT); if (dummy_res == NULL) goto no_mmap; @@ -863,7 +864,7 @@ int vfio_pci_core_register_dev_region(struct vfio_pci_core_device *vdev, region = krealloc(vdev->region, (vdev->num_regions + 1) * sizeof(*region), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!region) return -ENOMEM; @@ -1644,7 +1645,7 @@ static int __vfio_pci_add_vma(struct vfio_pci_core_device *vdev, { struct vfio_pci_mmap_vma *mmap_vma; - mmap_vma = kmalloc(sizeof(*mmap_vma), GFP_KERNEL); + mmap_vma = kmalloc(sizeof(*mmap_vma), GFP_KERNEL_ACCOUNT); if (!mmap_vma) return -ENOMEM; diff --git a/drivers/vfio/pci/vfio_pci_igd.c b/drivers/vfio/pci/vfio_pci_igd.c index 5e6ca5926954..dd70e2431bd7 100644 --- a/drivers/vfio/pci/vfio_pci_igd.c +++ b/drivers/vfio/pci/vfio_pci_igd.c @@ -180,7 +180,7 @@ static int vfio_pci_igd_opregion_init(struct vfio_pci_core_device *vdev) if (!addr || !(~addr)) return -ENODEV; - opregionvbt = kzalloc(sizeof(*opregionvbt), GFP_KERNEL); + opregionvbt = kzalloc(sizeof(*opregionvbt), GFP_KERNEL_ACCOUNT); if (!opregionvbt) return -ENOMEM; diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 40c3d7cf163f..bffb0741518b 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -177,7 +177,7 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev) if (!vdev->pdev->irq) return -ENODEV; - vdev->ctx = kzalloc(sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL); + vdev->ctx = kzalloc(sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL_ACCOUNT); if (!vdev->ctx) return -ENOMEM; @@ -216,7 +216,7 @@ static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, int fd) if (fd < 0) /* Disable only */ return 0; - vdev->ctx[0].name = kasprintf(GFP_KERNEL, "vfio-intx(%s)", + vdev->ctx[0].name = kasprintf(GFP_KERNEL_ACCOUNT, "vfio-intx(%s)", pci_name(pdev)); if (!vdev->ctx[0].name) return -ENOMEM; @@ -284,7 +284,8 @@ static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msi if (!is_irq_none(vdev)) return -EINVAL; - vdev->ctx = kcalloc(nvec, sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL); + vdev->ctx = kcalloc(nvec, sizeof(struct vfio_pci_irq_ctx), + GFP_KERNEL_ACCOUNT); if (!vdev->ctx) return -ENOMEM; @@ -343,7 +344,8 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, if (fd < 0) return 0; - vdev->ctx[vector].name = kasprintf(GFP_KERNEL, "vfio-msi%s[%d](%s)", + vdev->ctx[vector].name = kasprintf(GFP_KERNEL_ACCOUNT, + "vfio-msi%s[%d](%s)", msix ? "x" : "", vector, pci_name(pdev)); if (!vdev->ctx[vector].name) diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c index e352a033b4ae..e27de61ac9fe 100644 --- a/drivers/vfio/pci/vfio_pci_rdwr.c +++ b/drivers/vfio/pci/vfio_pci_rdwr.c @@ -470,7 +470,7 @@ int vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset, goto out_unlock; } - ioeventfd = kzalloc(sizeof(*ioeventfd), GFP_KERNEL); + ioeventfd = kzalloc(sizeof(*ioeventfd), GFP_KERNEL_ACCOUNT); if (!ioeventfd) { ret = -ENOMEM; goto out_unlock; diff --git a/drivers/vfio/virqfd.c b/drivers/vfio/virqfd.c index 497a17b37865..29c564b7a6e1 100644 --- a/drivers/vfio/virqfd.c +++ b/drivers/vfio/virqfd.c @@ -112,7 +112,7 @@ int vfio_virqfd_enable(void *opaque, int ret = 0; __poll_t events; - virqfd = kzalloc(sizeof(*virqfd), GFP_KERNEL); + virqfd = kzalloc(sizeof(*virqfd), GFP_KERNEL_ACCOUNT); if (!virqfd) return -ENOMEM; From patchwork Thu Dec 29 10:07:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 13083399 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 B4C72C4708D for ; Thu, 29 Dec 2022 10:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232749AbiL2KQI (ORCPT ); Thu, 29 Dec 2022 05:16:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233237AbiL2KNp (ORCPT ); Thu, 29 Dec 2022 05:13:45 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2046.outbound.protection.outlook.com [40.107.220.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3D871260D for ; Thu, 29 Dec 2022 02:08:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HtXx5G9Rrb3XSpzBY7B/43lD/E1GctgbEZSwiia08r+eJsnBZxU1kEeLsR5EFltQ0KC4JRd/AeFb8fUjFZ14bEA36FnhDorO2Y8OBbfoAApGwLFy4y6POK4Ruc25QXuGOg9x6Ni55I/u2rq7Pc/swChsJosaKrcpk00ONSIih+VKdaag2H0MSZwIzH3bUIuR8fTbMFEQkP6TQfqz/Rwb3d1iGeUO5rgAGB4zmRmw8M2W/HAbdIhm1mHY4ipMdnCSI48ih/YTUB0Cd7B0t59R/8yGNTbhY3lXnpH6wDg/osDXk1vpkRxBkpHx0v/2IosYAPhkpGXrSz+067EXMmdxnw== 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=4oJOaRRrzNvtr8kjofNopJWbe597DxfGmksah0Zx548=; b=NyNUF/G8J43gY4W9pNwIf3bYP+CU/qLvquU/WNuVSim4HHnEjKRYPVSOMJZj4dYSaKRK97lUsRk2HL9mq84hoL/JoAqt0C2rGVM//3iEsH43+EwnNqF9KG2OMvgXEHHqQ3s9GN9NaqBvHKnVM9ClKToop034OvYEpzijhBeo/bXftIbozhW1Gn7/m/3lOklYOHfcRQ+ySRpNAeDmj2IiVHIr0+1lxsWczTcRoELDwVkm5Z0fy2iJQKBekmv/UuQoRNrvGr2OCc1SmcMFNhYodZbYrcrLC34kDo50LGF8chlPa5yh13lg/c+p4qctPt5X35qUFsw88k1MZ3cBUxrxpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=4oJOaRRrzNvtr8kjofNopJWbe597DxfGmksah0Zx548=; b=dgaLsd+E35XKZRigYWToAvUKA3YsdFspJDsCYN/6xYy5XzdxuHTbxO8sowmfz6KsqO2wqXGiCMNfoE2iAe47isj41Pq/uylQGZZuVDNWOGvUgs6cIq6hDSkslGcomNohLdNVyGPYkZWRdq5CrtsI/6bqrG7F2sIvs8MKYNCCBkABAATcKIYdSSlkIIL7GsGGPCynj6Qtqwp5W6Ps2QDB4UcZzS4liYaZ+FUVGJQKHoyi4VSnQkakUJdqdsybI2ANFR+uYGOuL7yIA8EarrsJK4xMq8acetZ6vCTHDYyt6F74IAm9LjzbEVwY/KRH6CijntCToGLUrF/CB3XP6wFfTQ== Received: from BN1PR13CA0030.namprd13.prod.outlook.com (2603:10b6:408:e2::35) by MN2PR12MB4221.namprd12.prod.outlook.com (2603:10b6:208:1d2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16; Thu, 29 Dec 2022 10:08:41 +0000 Received: from BN8NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::c8) by BN1PR13CA0030.outlook.office365.com (2603:10b6:408:e2::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5966.17 via Frontend Transport; Thu, 29 Dec 2022 10:08:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT005.mail.protection.outlook.com (10.13.176.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5966.18 via Frontend Transport; Thu, 29 Dec 2022 10:08:41 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Thu, 29 Dec 2022 02:08:31 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.36; Thu, 29 Dec 2022 02:08:31 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Thu, 29 Dec 2022 02:08:27 -0800 From: Yishai Hadas To: , CC: , , , , , , , , , Subject: [PATCH vfio 4/6] vfio/hisi: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations Date: Thu, 29 Dec 2022 12:07:32 +0200 Message-ID: <20221229100734.224388-5-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20221229100734.224388-1-yishaih@nvidia.com> References: <20221229100734.224388-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT005:EE_|MN2PR12MB4221:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ab6674c-75ec-482e-bd32-08dae984a95e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /KnRhZ71JZnCPzpViQ8U9cuoWIRlbCsJmzmZqpAnMgJHtH165I196QJMIzub3Z79+1Md9n7F5ux+MUfUTUTp5SBB15FLuY62/y6FJmq3zARE0Jy1Mswa3+pfq37/h2uNo73p7nLzTI+x/Z8df3Yj50MlxzZdAULSy4ELY0FzhNT4++9UPKnU5NBjcDlaI9UoiE6Yo13iIwuRRZHYoeqv3GdG1MpJah237gk7cwfE14lqdJkDeFVYq5U/uCIIjbePZehZ2tYVWs0M9diX8yRGe/ENQCDgjDAKDkB3Yrz/GtA5z3UkOeQIeRXGFpMUaDojLsi72hgj0QHasKLdTJa2RRWYhTpGF5kgfdwRLaJazAtusqQuJ34eX4nF1gVF9pVn3ubw359TxZIhCzsh/C/jc3uUZMSUU9gHoedPFBq01gH+HsmIcZYGDYkY2GtZwMDMy3RBtg66MMlwMDQfnT3VzYSk+L3VnXUpEOrSGVnW2CaaWYy7t9G91i4/HgPv89X/goG9qHGI5h4YvLAzyC5uNbcKaNdiSTEl1tU6bx+/LD7QMTmygfHkoFPW6ExalHBGuq9PYOOlNcn7ldTlbWyxLlHRgSWSdWjUQHTU1rakzyom8iFSfsG1s/lUtAjaIO9b29AYrzTdaTVW2q9VMgwvfdjcCJCeboCSIfPu1TTDHg7ZPbsJhCsNIlLlCrGFbo8aZ1eAKtxjwA+NT1vEBh5b+g== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(376002)(136003)(396003)(346002)(451199015)(40470700004)(46966006)(36840700001)(82310400005)(36756003)(41300700001)(5660300002)(8936002)(70206006)(4326008)(8676002)(70586007)(86362001)(40480700001)(2906002)(336012)(6636002)(54906003)(356005)(7636003)(7696005)(110136005)(36860700001)(316002)(82740400003)(478600001)(47076005)(83380400001)(1076003)(186003)(40460700003)(426003)(26005)(2616005)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2022 10:08:41.0828 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ab6674c-75ec-482e-bd32-08dae984a95e 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4221 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use GFP_KERNEL_ACCOUNT for userspace persistent allocations. The GFP_KERNEL_ACCOUNT option lets the memory allocator know that this is untrusted allocation triggered from userspace and should be a subject of kmem accountingis, and as such it is controlled by the cgroup mechanism. Signed-off-by: Yishai Hadas --- drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c index 0bba3b05c6c7..a117eaf21c14 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -744,7 +744,7 @@ hisi_acc_vf_pci_resume(struct hisi_acc_vf_core_device *hisi_acc_vdev) { struct hisi_acc_vf_migration_file *migf; - migf = kzalloc(sizeof(*migf), GFP_KERNEL); + migf = kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT); if (!migf) return ERR_PTR(-ENOMEM); @@ -863,7 +863,7 @@ hisi_acc_open_saving_migf(struct hisi_acc_vf_core_device *hisi_acc_vdev) struct hisi_acc_vf_migration_file *migf; int ret; - migf = kzalloc(sizeof(*migf), GFP_KERNEL); + migf = kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT); if (!migf) return ERR_PTR(-ENOMEM); From patchwork Thu Dec 29 10:07:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 13083404 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 A1F44C54EF0 for ; Thu, 29 Dec 2022 10:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233378AbiL2KQ0 (ORCPT ); Thu, 29 Dec 2022 05:16:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbiL2KNp (ORCPT ); Thu, 29 Dec 2022 05:13:45 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2042.outbound.protection.outlook.com [40.107.100.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 803BE12D3C for ; Thu, 29 Dec 2022 02:08:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YS1BA+HbOhpr0yzcPX4wAZ3gGTaRaQhC+TF5nf0kcsKSk4nyq0w8xYVkkbUMmGP4Ma555YiBgYqFj3lnyLuP1NmobHAbCZghvEDs4VCpGSTOaBM/70PkuVYc15aWMG5sUD+e5ACd6McAJemvIEKeZbkQGbo0HqNACFK565sq7f0hSykVL6NHpq298j/bFubn7sgrTJDZTXCsEs5N37QwUJQ0Jp6HThUXNiNxvXCfVM88/0viM/kcM2gKla09yFaeYrXrXpD8fFKklVW4btdXiEoEgDy4Z5K9ETchnNhFaGu9/90uKcDdosghCIdf9n9ekxgPNuw2h4JKpc/8fcklEg== 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=G0XGCOkgyuv8m0nwvRX4wOpn+ZvdjTqENu8sAo2WW1M=; b=aIqNIdx4ALIHB2ElRJKXBekjdXpIzLWlnNIP18eS2zfodPuukb2uMLAY21fMC07sMiPsdpNg7bYRks01xeAR/h+wo0zfWTb+hj0yVyFQtLjs6EnXE53ahXuZwXGkC9vilRn1e6XK6evZ/d9r00+YxGg6x71SxTK9J8t3XpoGYaFMTdSg0rMKDCidezCKDfDB/TCNcRLjAqW/4y0OJEXSI1PEt11aAvrYNkyY2R3LE96llhfjEQeKv2AFw2u6IFIF7gqvWdMUQSlJPz/yuPizcnMDzg+4WZAeiT3agYCx6ovjp5jVYETg7mgR9p5/kpP3xwXJ2gskox6J//Pd1KjytA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=G0XGCOkgyuv8m0nwvRX4wOpn+ZvdjTqENu8sAo2WW1M=; b=FbIw/rDBU7XGZ/ltCUZt7Erfr1xok99AG8s+FCW11ltQKQMln6U048f/5bkLYsMvEo7p3bRXeeCZtDzSB8IxSga4d0v+hqO0C8IzBR+yjAxEWucHMK20uDA05KMsYVPCQ8oyONootyCEWoP8uomQavvVsy9LUacUidFiB+IGOG9lPMmVRSAyqgFGNBDtUHiQpiljOp7BlztJjL965by/xX6v4DOKafFFLdkh0DkmoYao5dYdQvhjkW6oxavjMUqciE/mM1Q/DXZxXQ5ZD3MHAvDB+mhpQnreIYb7UCPevqqgdLrhoCpfANi7kTJ09aVTaWf9enLK8GM+8OIBlpcuVQ== Received: from BN1PR13CA0024.namprd13.prod.outlook.com (2603:10b6:408:e2::29) by DM4PR12MB6011.namprd12.prod.outlook.com (2603:10b6:8:6b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16; Thu, 29 Dec 2022 10:08:47 +0000 Received: from BN8NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::aa) by BN1PR13CA0024.outlook.office365.com (2603:10b6:408:e2::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.7 via Frontend Transport; Thu, 29 Dec 2022 10:08:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT005.mail.protection.outlook.com (10.13.176.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5966.18 via Frontend Transport; Thu, 29 Dec 2022 10:08:47 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Thu, 29 Dec 2022 02:08:35 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Thu, 29 Dec 2022 02:08:34 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Thu, 29 Dec 2022 02:08:31 -0800 From: Yishai Hadas To: , CC: , , , , , , , , , Subject: [PATCH vfio 5/6] vfio/fsl-mc: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations Date: Thu, 29 Dec 2022 12:07:33 +0200 Message-ID: <20221229100734.224388-6-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20221229100734.224388-1-yishaih@nvidia.com> References: <20221229100734.224388-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT005:EE_|DM4PR12MB6011:EE_ X-MS-Office365-Filtering-Correlation-Id: f57d3ce2-fc01-4106-ec79-08dae984ad0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0pJQCoRIyXhS/9lsmAkS6Zu1JvWZ+BHqD6lIIWHg0h4TI01clkNAdqnfFMWnXrbf51xy6qqCFcBaZipBo5MmnlxVcijok1k6L5ngsaNBx8bs8NjL4eTblgEBM3xtRYS7yQe6iVnd71DlaLxYRoPalyo3WQT/6rdC+7Uxs0qip0KTcaID/FQerkvf6RviLOej3EGALdjwalftiDijZ8VxwEVJVuuFFBF8wqEfkxQRkYKUihuZDohNN0LIEKk521WfwyNVJvZ5EDV76iLxg7jXBjXNuBUCPuA5E8SgyhP8bzMYoMLuKp7auevCiD7M7E4R8QpyQ604pmYDEHBvU9rmfzYtk/0sD6wRAcXzbUdpz2ySAyzUhO1uuZJkBe5wdhk+yA+IbTy3pQANkkQxRD9hLWUkC/ugKoQUOo431XzVF9oS5P07/vDFS6EQT9EZg46d5U/PTZevT1kotWQLGrpkMM/X1+bQ+QQYxaVSgFCCLrw32PXvigLakzNW5FLfbrciLqrsAUCmt5/EppvGwbbk6zfSOM1jTK6cy72wuRW9WaG8Ye0sZvz9yHefet8ujnU9Erf7LxhfhI9Wsn+Msjtrelaarjjgn9Ro5NoRAfaDs2RsGj/S51mgChXczReBvSsdafobH2t4RNV+0klytrPsdZm3zJHKW+/GoH0xe1BpWlpez/unjrTG3XRvhCZgjNQOHTf+zS+AGxMF5PrvV1XARA== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(396003)(376002)(39860400002)(346002)(136003)(451199015)(36840700001)(40470700004)(46966006)(6636002)(54906003)(316002)(110136005)(40460700003)(36756003)(186003)(26005)(356005)(5660300002)(2906002)(83380400001)(82310400005)(36860700001)(82740400003)(7636003)(70586007)(4326008)(8676002)(70206006)(2616005)(336012)(40480700001)(1076003)(426003)(47076005)(8936002)(41300700001)(86362001)(478600001)(7696005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2022 10:08:47.2706 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f57d3ce2-fc01-4106-ec79-08dae984ad0e 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6011 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use GFP_KERNEL_ACCOUNT for userspace persistent allocations. The GFP_KERNEL_ACCOUNT option lets the memory allocator know that this is untrusted allocation triggered from userspace and should be a subject of kmem accountingis, and as such it is controlled by the cgroup mechanism. Signed-off-by: Yishai Hadas --- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 2 +- drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c index defeb8510ace..c89a047a4cd8 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c @@ -28,7 +28,7 @@ static int vfio_fsl_mc_open_device(struct vfio_device *core_vdev) int i; vdev->regions = kcalloc(count, sizeof(struct vfio_fsl_mc_region), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!vdev->regions) return -ENOMEM; diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c index 64d01f3fb13d..c51229fccbd6 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c @@ -29,7 +29,7 @@ static int vfio_fsl_mc_irqs_allocate(struct vfio_fsl_mc_device *vdev) irq_count = mc_dev->obj_desc.irq_count; - mc_irq = kcalloc(irq_count, sizeof(*mc_irq), GFP_KERNEL); + mc_irq = kcalloc(irq_count, sizeof(*mc_irq), GFP_KERNEL_ACCOUNT); if (!mc_irq) return -ENOMEM; @@ -77,7 +77,7 @@ static int vfio_set_trigger(struct vfio_fsl_mc_device *vdev, if (fd < 0) /* Disable only */ return 0; - irq->name = kasprintf(GFP_KERNEL, "vfio-irq[%d](%s)", + irq->name = kasprintf(GFP_KERNEL_ACCOUNT, "vfio-irq[%d](%s)", hwirq, dev_name(&vdev->mc_dev->dev)); if (!irq->name) return -ENOMEM; From patchwork Thu Dec 29 10:07:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 13083403 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 92928C54EBD for ; Thu, 29 Dec 2022 10:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233045AbiL2KQY (ORCPT ); Thu, 29 Dec 2022 05:16:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230166AbiL2KNq (ORCPT ); Thu, 29 Dec 2022 05:13:46 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2067.outbound.protection.outlook.com [40.107.223.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C55513D5B for ; Thu, 29 Dec 2022 02:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Po+bmBhqEZiDNE6l/Uo7vDqSP2qBTJniehmkvOZfOaR+FX+NnAD38m+haLHTPssocahi17iBY1kCK9WOu6ujrTb2EsnjGdBxGp+8QVyfvuqi+P0AZREdGZtVL6MhiK8bjL+NjH0QjJ4Jm9FPm3UrSViP1xx9LsWefS7NWiKDcPBxfmcvFmKxf98MOx2M73BhrHqeHRLdfLVB0pwX0ODu6WrtXQFoUwVxurDl1TsIYlXz8kmqaCERJiUSVzy3dnKU3FjtH8Ax/8U7OZVnWeA8YsNxGhjw+mw7oY18s4yuC9XJPJz11z7/3KTUNmRqYacXx+ySbHzQ9Z5tB2ehPLqghg== 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=yVl5ZCxDwtAQIqnOXSYR5+CBDbOPiF+dzxqRUGVZgaQ=; b=meJw6vbMozUUKRno1ty14q81YG3c0ivWMR8XorIAnSd+M3rsSQsZswHv8EY2kkCEdRIBkIGSPTn1adoPlrepMjIWGgk3wJN8Osub9KWS3dP5dxWGlyoIX9v1xsf0HKywa1YXzvI6KZxAiMjQSC3Xe6f5UHmAwBL6lJ2GdsicAT6EpElwzhClskY8gSmy6dZakKlhGFHtqROFWYjg8NpuRmbc9ItL4poabyhmVQF6m201PdOXM6Hflih40/NXY0GI0YkblLeE2IogE/ps8uvohga9B0R9ha8aUVByT9FJ2Ud/+TBYENeUKIVch/vTD9t+qg+u9ZfMLE7Z60gP6n3Kfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=yVl5ZCxDwtAQIqnOXSYR5+CBDbOPiF+dzxqRUGVZgaQ=; b=kpMVxRpbehvrgOVfnGKuyr6mOMrdyraovOjidYGLhElAFXu2FxHARQVNUVHBMJdRUpPvD4Fuc8Ec/NuqxAM6PhqOTHF+1egScJ56dmJDVztXnRCkp5dNS6u4Jd3AwOSs3WrRSURYPYkmbL6MtFcy5LYt2dxYLYPrbjbPGLq5Q4DbqJMlyFK8+6OFCTXpCEY9THkLygcJyx485zZ6zJ7F3Zisn2cYUv6BpQMQZWanFZD2WvZDP/OISPow3wG4UgtewE5Y0sr9i4OL2RpNCOUAw2Cj7QCTetH1F0GvCqe3g69X3B+r6F8H74JhUI7vY3dkZGUOgQ74icpSxW01BwJ+kQ== Received: from MW4PR04CA0092.namprd04.prod.outlook.com (2603:10b6:303:83::7) by MN0PR12MB5908.namprd12.prod.outlook.com (2603:10b6:208:37c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16; Thu, 29 Dec 2022 10:08:52 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:83:cafe::f5) by MW4PR04CA0092.outlook.office365.com (2603:10b6:303:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.16 via Frontend Transport; Thu, 29 Dec 2022 10:08:52 +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 CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5966.17 via Frontend Transport; Thu, 29 Dec 2022 10:08:51 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.36; Thu, 29 Dec 2022 02:08:38 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.36; Thu, 29 Dec 2022 02:08:38 -0800 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Thu, 29 Dec 2022 02:08:35 -0800 From: Yishai Hadas To: , CC: , , , , , , , , , Subject: [PATCH vfio 6/6] vfio/platform: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations Date: Thu, 29 Dec 2022 12:07:34 +0200 Message-ID: <20221229100734.224388-7-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20221229100734.224388-1-yishaih@nvidia.com> References: <20221229100734.224388-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT066:EE_|MN0PR12MB5908:EE_ X-MS-Office365-Filtering-Correlation-Id: f0c67505-5760-4c54-ba02-08dae984afcf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OnArHT5JIjR/Bzq++pBRQO7kzTx6iVa/aJ7FOkUyPO2pmwiUK3OXBlfRWHAB5OWqFQFhxNAlD7DqxxvkPqh3KS3Frv5lK1x/bm4Xh+HggtlZH5xRAJ9BvT3r6xvBlzns51luqqBFkHmBJ7uX2WpnJsZvGkKwFPvfrzkVTpYDLH7PFtTsn0E1in6H+LHLSCQwLb8V5mg4KvxuCJV2MWOjYEUu3pWAhMVgw0IdjIEvuaDPfgKZi1tyY3t8xjbSkll0ii5sDSkJ3RMGngVy5+zrg87lBEGuU9C9Mw93//FHKyDnXXBwV2bgZ32Xqh1VzbaIKhJwlEMzhopjXEgEAKnzU7oPSjZFfyAizG5JClwSQ9uCHdSdG+E0Sl5AFp8QqVqujfEJJ9BKKv5Is5e3eSn3bEAWQwOwUaag9cz7rJ+/2Axjam3EnJvHOUiS+/HezQ5ZRiONCb1ynTCVK9RFeFsz2bbHyLxyePh6KSRTDvGKbQpsvEQcZU5QtNF2Kqh2rhyz20eyCqO5t4zYtHztQjxY8Bax12Ma44jjeLjvZpD79/OFwoU+bxEIc8NYLB3DXhsl8zJqGTxKNk3nG75PmTO7Fd4BAlatnF9SVpUvsIHSFUafUctvF0vwMbY1xXDz5fEC3w7WN9eJ3qMB69xcHpPpKhyVCcbt9bvxwRDBGgOMjPYpsCuJfMdlKuGmthbfy3tiM9i5FDJl3MJy8Qf5A2o7/Q== 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:(13230022)(4636009)(376002)(346002)(136003)(396003)(39860400002)(451199015)(36840700001)(46966006)(40470700004)(36756003)(70206006)(41300700001)(70586007)(54906003)(6636002)(86362001)(8676002)(4326008)(83380400001)(7636003)(82740400003)(356005)(36860700001)(7696005)(47076005)(426003)(478600001)(110136005)(5660300002)(8936002)(2906002)(40460700003)(316002)(40480700001)(2616005)(186003)(336012)(26005)(1076003)(82310400005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2022 10:08:51.9990 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f0c67505-5760-4c54-ba02-08dae984afcf 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: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5908 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use GFP_KERNEL_ACCOUNT for userspace persistent allocations. The GFP_KERNEL_ACCOUNT option lets the memory allocator know that this is untrusted allocation triggered from userspace and should be a subject of kmem accountingis, and as such it is controlled by the cgroup mechanism. Signed-off-by: Yishai Hadas --- drivers/vfio/platform/vfio_platform_common.c | 2 +- drivers/vfio/platform/vfio_platform_irq.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 1a0a238ffa35..278c92cde555 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -142,7 +142,7 @@ static int vfio_platform_regions_init(struct vfio_platform_device *vdev) cnt++; vdev->regions = kcalloc(cnt, sizeof(struct vfio_platform_region), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!vdev->regions) return -ENOMEM; diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c index c5b09ec0a3c9..665197caed89 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -186,9 +186,8 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index, if (fd < 0) /* Disable only */ return 0; - - irq->name = kasprintf(GFP_KERNEL, "vfio-irq[%d](%s)", - irq->hwirq, vdev->name); + irq->name = kasprintf(GFP_KERNEL_ACCOUNT, "vfio-irq[%d](%s)", + irq->hwirq, vdev->name); if (!irq->name) return -ENOMEM; @@ -286,7 +285,8 @@ int vfio_platform_irq_init(struct vfio_platform_device *vdev) while (vdev->get_irq(vdev, cnt) >= 0) cnt++; - vdev->irqs = kcalloc(cnt, sizeof(struct vfio_platform_irq), GFP_KERNEL); + vdev->irqs = kcalloc(cnt, sizeof(struct vfio_platform_irq), + GFP_KERNEL_ACCOUNT); if (!vdev->irqs) return -ENOMEM;