From patchwork Tue Jan 24 05:42:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13113487 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A896C25B4E for ; Tue, 24 Jan 2023 05:44:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAF8A6B0081; Tue, 24 Jan 2023 00:44:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D5FB06B0082; Tue, 24 Jan 2023 00:44:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD9686B0083; Tue, 24 Jan 2023 00:44:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AB90C6B0081 for ; Tue, 24 Jan 2023 00:44:45 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8443AC05DD for ; Tue, 24 Jan 2023 05:44:45 +0000 (UTC) X-FDA: 80388603330.25.C683331 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2082.outbound.protection.outlook.com [40.107.243.82]) by imf11.hostedemail.com (Postfix) with ESMTP id CB14F40005 for ; Tue, 24 Jan 2023 05:44:42 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=g6blWCgO; spf=pass (imf11.hostedemail.com: domain of apopple@nvidia.com designates 40.107.243.82 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1674539082; a=rsa-sha256; cv=pass; b=10wbi1sHSNNw+ximO8g4+Q5GIXqcjznmA17gaKugwO5sSWdBTMNk/jM+Eo4sMhgWTNmQH2 6eL98+TDJbAdzwqsDOYYaW8Ev0FjsRdezwmaWUExmUMFbopOoGXyPSkVdAtfXzEBVhuIHR XJ6tEfBziqIY490/w2TGWW4v9BUY0Vw= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=g6blWCgO; spf=pass (imf11.hostedemail.com: domain of apopple@nvidia.com designates 40.107.243.82 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674539082; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xVSTTv9ijFATl+Jf+OCS62NKLjuBKLo0e271Utsbdkw=; b=bmJea+H2nWmeWouBJYZRYPeTae2cs1O4yP3sxMo6uQWIU1j3BNyRMZ7nhJC6IhFfrGhqWU WiIAvl5oPCrEHprvk+Mek7tEWyR/bWk+M7qlY+/RXOddX4V/yZO7c1IWn2lLvB9kfEhQhJ DtYgL/K8YpP51uZ1bOouX9fRfN9UE3g= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lqmD3Rpm28y2RWwRFZGqVCsa7JVofEmG9+7vMC8/3em1LeutbRYHlIiAYitZQVNNXOe7h1fCU229mkbFExwhIuQctBwxIJOQSWAa76VwY9VVm9VSnqxczChzCumh1K7MTK+VIhJeL0vpwjwLPb96t8fTCt7ucFYFgm+fDl50DaFggcY1rUwVevrIKB5PBkf14cOTvYb6vc4II/O8Io7H4ipWGHMt8DJbCyxirkRnq7I2VLJfcixCZPv8tvW6mHo+cz65KNzb0K1A9ST3iLXUKotChGrOXlp0tAso6+o9bFFg6xFv2mSejOIN8OERe3NwV3PXTtVowNQ80jiS88RStA== 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=xVSTTv9ijFATl+Jf+OCS62NKLjuBKLo0e271Utsbdkw=; b=GMhqHZ30CKDgpv63T0QUgee2Wk0qR5+vJh3tsMAoYRyH2M9iidJ/HXwRSje1HHQ+7DBg9g7lS2KujpmMtnTVoz1kkqYQmVl8Tzf/kyLaxiJZEikNJ1da7U+WL820WsESMWxnb2KFfW7P09M1KJNoSQPliylQlzQiQtzOV54+SYEsCMiqWGFQqs3IHzXCiXSSk3o2mQdLokGa2NpNV94GetF9/1YpBk2vSLZN25xnP8bv580SDKirmDd9uy5/z4OTtZ4YWsN2oVqAiDqMiPCkpq5/6RRT3Fhx6sSK3H6zDTy3AX2P25+mzduNqFkjuiPEmnLo9UUpswPqnfdM/POaQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=xVSTTv9ijFATl+Jf+OCS62NKLjuBKLo0e271Utsbdkw=; b=g6blWCgOw4iUL8iy6QPPIj9lyTmJs/dnfznW6R32Pmeru+gzBRXTerouGEqb7Z+3HZTfJnkY5dnd3tbrbOpFNGOlbpnijc87LlwZ5WL5u180Dalp1pgYj652yQ+DAJM5b5npClD9Xx9LD3Kw63lMR/ejDDl+FzkumRXJpgOjgG1klrGzgjNHW5QWAnZSvTqmIsokLExwf8MpAb16PIUQeip8FWzu5VXlJy5wQ8MLo28oBcCt7HsiOvb5phBbNs6/fSWYSmqAkWqj4awByCyxSGE4I01+waUt8CbOZ4ickPz61GsaKXaZqoQjuIV2l4Pl5VC/NDVJ63HGPGfW81C2zg== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by IA0PR12MB7507.namprd12.prod.outlook.com (2603:10b6:208:441::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 05:44:40 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::465a:6564:6198:2f4e]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::465a:6564:6198:2f4e%4]) with mapi id 15.20.6002.033; Tue, 24 Jan 2023 05:44:39 +0000 From: Alistair Popple To: linux-mm@kvack.org, cgroups@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jgg@nvidia.com, jhubbard@nvidia.com, tjmercier@google.com, hannes@cmpxchg.org, surenb@google.com, mkoutny@suse.com, daniel@ffwll.ch, Alistair Popple , Christian Benvenuti , Nelson Escobar , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org Subject: [RFC PATCH 06/19] RDMA/usnic: convert to use vm_account Date: Tue, 24 Jan 2023 16:42:35 +1100 Message-Id: <03ed2d166826cd7055810c66a175e20fa2153c52.1674538665.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: X-ClientProxiedBy: SYCPR01CA0019.ausprd01.prod.outlook.com (2603:10c6:10:31::31) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|IA0PR12MB7507:EE_ X-MS-Office365-Filtering-Correlation-Id: 58502a66-ecb1-4092-f3a6-08dafdce1583 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MY1gXIJLTFkqkhadHxZi5X+pDcRr+i4Yj0KNEWMYFe/Lz7wyEznPlryhZ7i9earuwU3RgTCbBJbxJZh3Cy9eRkuzcEvZzNRgK07/Q4vbbjnesKtWPEwqQ4gAMhUoOX6JjPrC3s/3MtSd4kMug6WveXXt3z0mZ8+ggxB0e6nejHMWHE+nkJdNhZbtvFInYFnSF5jV/LnJFd92VcYWhhYI86QeKM9A/QaJo33Hs9OyeLHuuch/i0uxmSWhC4vzve4MFjbXXoN+eqah002aiPwTF9XLDsiTL7xKeLQWguHM6rX4o2Kba+yikE4EK4zEQ2PJsFZacW/+2esVbvd24othnTPRm+CHQFAfgTv5Ga7Mz0p8NL1md5hvhgboNSV8bAS6JdHMOZLB90gwjgjr/bgI6PC/YUlYp8AcjIpza1NE/XCWnpDmSHBc5WBFv6EwA90CvGzeUYjF2TF/j3LEIshOE84X/2fMnnSLbdNqvDMZu2pvdUX/RX9TUYQC6c8wSsPyEgHxwkFjK28Y1RUjYInRJ4ygrrHwwHLpmurXMLZTGtlllWkHPec/0TKcTWNE2C7SJLCUUthJHPmKy52Q07lGSXXWf1I92R5LvKA8ThxVMgSba7AomTiyDHxjJUaYcLGJUZhva7MwTus5Yi8y6ET6Pw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(396003)(39860400002)(136003)(376002)(451199015)(2906002)(41300700001)(8936002)(66946007)(66476007)(66556008)(7416002)(5660300002)(54906003)(316002)(6512007)(478600001)(6486002)(6666004)(6506007)(26005)(186003)(2616005)(83380400001)(38100700002)(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uELsXaR73JEPDOT20ezwon88uXr71jMpnkmubW1/sF5gc6ux/o2Bl8NzR+tIHVtwNE7ZHg/BK1gWU3mGNWS3r2Rd7TqjbcrfA20s6SixSERQkHAqnkcsuXKudbmplCsSQeiPhd3aPWbx41WiPSQ+mV4cctKrmeEChM1hkPYDUYasn4g4yT6+8ahJCYfyE6qJHEtVf5Gpa9iNfUeDy+6jsj/108x2K7d7RnF8oHL4jlj3fYWm5YPGk9MJkM4g/yWx1Eou6r95dCu5hIG5DILuIWyjGSC7eEak64Jfc70rVR4WoN3P8LZiUlUNCGQOAWR/xIdzRuFKGcxtrBaboEF5basRsGwVb3jT9bHEITXFBvt43q3Ive7KJSUZ+Auadt8LxK5wxnA39MVNncdn6VjHHkADO7SdlN3GVfySNQWOf+oLYIfRKYf4ls697sZRVCNStuI5C4Rpe1UKPiaKq3sg8taw07O0ynzjIA5vz+cRdP0rLFqDTI5+9o9oZFIilQ/WKcmnsYk0ejhB29+QrE3bIBkZHs1xN5QeqAu/munHwV8PSHn7bxrx2u1aCSiXYBs8abipnXRdEbLp5UHXpVDtLxn/P/RK0aZx19/vc8xEzKVnXPJx+4q8WyGFkg1rNfl1Fdj X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58502a66-ecb1-4092-f3a6-08dafdce1583 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 05:44:39.4280 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: imSbUZwV9HUvtiRCcJ3HUSILYWMUenFLV2egkLFBu52lqOJzgY65CbSSEnx1zofFfPtwPTEMLpq73ZrQcRmxzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7507 X-Rspam-User: X-Rspamd-Queue-Id: CB14F40005 X-Rspamd-Server: rspam01 X-Stat-Signature: mqn4xx3i35qrah9kp6eecapse34c1i74 X-HE-Tag: 1674539082-222915 X-HE-Meta: U2FsdGVkX18I6e5+xEg41aiSKPkl42LybMdf5ojVt8iuSx4x6HNT/7I9mZNAm37onAgzi8T/uCjzQTpYX8OeoGoLUGR7qJyJNsVBKJhrdiu6NSvKjG6pdNp7E66pqzKcIZGKAOJgzZYeZ7qKgu+DnOESfHd4dIx6sWRgdaIegY2uKMjH1uFvHujF+BTlCu24+AbhQuUy9D3iOekFmDnQQrgoZLDa1za34ANaRqpUDno6GDl7MCGcrkyItWNiZ950XffcZPjcT8DG1qd7qGRcIq4v/lHWQLiT3UoK1hOzFWaCp5/5BHZOEQSJUxJx581PS6yQ+Iq0G19evGKwe1HmWVOaGh6LQuVaX4tIqD8BA2whUoIZkgZiFLgi7ax0V58P7ht1mgUtSBERrycs61CTEX5JkhgaRVAHbIDoGTNk2Dp6gxMGw7hK5I6Ss6/Eepzn6fwXI9iUJB8eqYBzbgH1TOfi4iJ++XTIriaIK/vyyHpNmIkvG6mUEzCUM65Q5b8qsBdaK+G8UbFeZQB/AyYE8qM6LNXe/a8h7MEsU5yfDM1X4oQuR6TClAdg02pINrjfpyGk9T0q879TgKLQjBv5qigTI90uyIDTPhEsLd4nLB3UdfPO+9kpqXY8G8H7BTP78ICyALvwyYbDhPA1fEpKL1/LPkCpMU1Acqd7RoJZvbUarzyQI/FJzHNfy+vj3ZFI0gKK+CfdNaceX7sW7O3Km6rcbSajmmcRmsziK12pvUCkur0ZSXQ7xuqZp9S6ZOHvqNLcqrCKZsKXuCtrmVN8RbA3tY2qHfUwvov3NLQTVwrevCAhPqgyKkcfqRioWTeGbNztm7pCtSM06YdGaEgoe7ni+qmBJpgUPctLR+9RsN2oOZZ+PkveXm6KyPMmExBgz/JM7EA90LNNPRjlUXn+Zhj8JQNSoDfqY3+km4gEsUO6eLxLcmYYXi+6GedcPsULgZlWGD1jWvQJj+sf0JT HblWW2Jk HvlNO4DRQvY1l42DEI5kq/Ccb69ZPSBhDQEgGxkkeYL8qpeA8052AifIAcpW3c34tasLpvL160mWHIh8HGIslEP0cjdN3A4CmKvOvAJ8J9OWaRW/QIbKg/GsBaWB5AR0oLGMVrn2o6egCs4TyG3fW/HRwTPbMfbA8waJCKxWVCxaloxvpoRaOAx3BDrtLO4Mcbye5e56zrjgx4voE8t2p0uSeoT2PsJhR0cahNx2auStRhE842azE1JCEjQlXS1jQkDyqDrqc5VFGWB/JdH6riT8eYxReASqvqegQPidw6kqIQHr6giinNgU8PR6XV4B21jbXosVhqYZ+8rPBnTAMe7UGNlREfJNAqygr50VPzD4EcU2xBJct5HzhGS/W0V+fB99lyPP8NrnFnDhVD8Bu+oCAoxQmPSgOO7/ObxYjvCbi31vNoV7o1LI/Xg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Convert to using a vm_account structure to account pinned memory to both the mm and the pins cgroup. Signed-off-by: Alistair Popple Cc: Christian Benvenuti Cc: Nelson Escobar Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/infiniband/hw/usnic/usnic_uiom.c | 13 +++++-------- drivers/infiniband/hw/usnic/usnic_uiom.h | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.c b/drivers/infiniband/hw/usnic/usnic_uiom.c index c301b3b..250276e 100644 --- a/drivers/infiniband/hw/usnic/usnic_uiom.c +++ b/drivers/infiniband/hw/usnic/usnic_uiom.c @@ -89,8 +89,6 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, struct page **page_list; struct scatterlist *sg; struct usnic_uiom_chunk *chunk; - unsigned long locked; - unsigned long lock_limit; unsigned long cur_base; unsigned long npages; int ret; @@ -123,10 +121,8 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, uiomr->owning_mm = mm = current->mm; mmap_read_lock(mm); - locked = atomic64_add_return(npages, ¤t->mm->pinned_vm); - lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; - - if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) { + vm_account_init_current(&uiomr->vm_account); + if (vm_account_pinned(&uiomr->vm_account, npages)) { ret = -ENOMEM; goto out; } @@ -178,7 +174,8 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable, out: if (ret < 0) { usnic_uiom_put_pages(chunk_list, 0); - atomic64_sub(npages, ¤t->mm->pinned_vm); + vm_unaccount_pinned(&uiomr->vm_account, npages); + vm_account_release(&uiomr->vm_account); } else mmgrab(uiomr->owning_mm); @@ -430,7 +427,7 @@ void usnic_uiom_reg_release(struct usnic_uiom_reg *uiomr) { __usnic_uiom_reg_release(uiomr->pd, uiomr, 1); - atomic64_sub(usnic_uiom_num_pages(uiomr), &uiomr->owning_mm->pinned_vm); + vm_unaccount_pinned(&uiomr->vm_account, usnic_uiom_num_pages(uiomr)); __usnic_uiom_release_tail(uiomr); } diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.h b/drivers/infiniband/hw/usnic/usnic_uiom.h index 5a9acf9..5c296a7 100644 --- a/drivers/infiniband/hw/usnic/usnic_uiom.h +++ b/drivers/infiniband/hw/usnic/usnic_uiom.h @@ -72,6 +72,7 @@ struct usnic_uiom_reg { struct list_head chunk_list; struct work_struct work; struct mm_struct *owning_mm; + struct vm_account vm_account; }; struct usnic_uiom_chunk {