From patchwork Tue Jan 24 05:42:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13113492 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 84707C25B4E for ; Tue, 24 Jan 2023 05:45:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F02E6B0089; Tue, 24 Jan 2023 00:45:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 19F8D6B008A; Tue, 24 Jan 2023 00:45:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0403C6B008C; Tue, 24 Jan 2023 00:45:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E85786B0089 for ; Tue, 24 Jan 2023 00:45:42 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BE0FC16010C for ; Tue, 24 Jan 2023 05:45:42 +0000 (UTC) X-FDA: 80388605724.24.B49E1C6 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2077.outbound.protection.outlook.com [40.107.100.77]) by imf15.hostedemail.com (Postfix) with ESMTP id 03272A000B for ; Tue, 24 Jan 2023 05:45:39 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RjSfZx+d; spf=pass (imf15.hostedemail.com: domain of apopple@nvidia.com designates 40.107.100.77 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=1674539140; a=rsa-sha256; cv=pass; b=AeClkoDtDOs4zd3VtcQJ7EaFSOgkZ/mHFUWQJuWsoqkh+gSAqUGsCajANSFFln0Cv4ZrbX Xf+/ffZlWoo49BPWJ3jdwviVWC5pe8NOuscCAqVe0orFsTzqERT4hqH8X8h11mKKJfRHnJ 8El3MK5oGkbJ5u2wCZLfR766llgarQs= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RjSfZx+d; spf=pass (imf15.hostedemail.com: domain of apopple@nvidia.com designates 40.107.100.77 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=1674539140; 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=0W0p5nkXQyU1aX2kot2Ea5g7JV+lHiVX0c1iGBFb/bs=; b=b5JEy1uE8OsR/vtuU4oNnn8kS5NOi3dBqolLPrkInZQjlBgIFgj7xeSUv84DqGRZToArX7 h2XpJ143c2Qh5fi/ElUxzvS2EbJ+9PeJC2QDxZQsh16UgGipDV9AzhvCm/wPfIZRxadc9H bvx9R0GQLLTEU6+hzvtZLi8CLojwPq8= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AjVytcuDJkM/FLk3R8BjbHpvTcr7TGho/0IVTECkIQV7ws4n5jkzi0QArse93uAxRASpSMj+muQ1YpjhpTNkuOzVi/Zm7zPDCWATItTCDw1wFEGbPURqJgHDnSd0Rc+FN0poclOjqdOit7wBP/M25ddWmto6a/KmJUHwhc/pmHepWiWjvrpFsvxWiO8mFY3hNsTbjJtgvSQHOgPBHVZFO704w820TyDx6jgcFraq/qOYau41uNm2PyYaPh/YVOyJCRwz7dHjy2+/BTy3ACmLKQUNYqgwNs2CDUVHl51sR7IgrKF1hKSkl5rnBZi7hfPQbeN9jMukENhxS7FPZLCsVA== 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=0W0p5nkXQyU1aX2kot2Ea5g7JV+lHiVX0c1iGBFb/bs=; b=OEgH1/4ExlDB1ARjKQQZlzDPJ5XLoJhcwkWk7U7lWF9NKXSElVLozOyvFx8X28kCePcut4zphfJOvCmNq6trkwixvINvM3ipIHQZRbWRCAA5kzWUXX2/lLfR2L5IwUFlWDwrvqijm37eBAOr94FSiixahzuGKrBdkLjLgseersArWWEYHgyTafL7hNMLMFNJ+zDs2TalDPEoKlMactVcDbFZ4Lw13Ao3PjBT5cYEOZQHNJZyHvI6Z1pPF6DL8pGde62y8nvUbNrcYV0N3ZYQbKJx7Z8Pcvgj90ANN3a3WKiW6B8hK8T+48o2vjDhfPXjNzXHYfG0NA5nJiTgr3EYbw== 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=0W0p5nkXQyU1aX2kot2Ea5g7JV+lHiVX0c1iGBFb/bs=; b=RjSfZx+dfCzyTOWStKMBo05C3rq/ufLUyctmeYXAYJItlL2INf+LVq9u6BKViV5Q3L6REIxgjzJczv8zHROXTFliHUucL1VYy9lXD8V7A3cZwr3xjyhETc+bpnfPZt9dqD+NtE3sYCijNGZ3XwQlckkcjObSr0E3MXvYVBSnfw+iATTAlNpIX427NYo764b9230nPCtuXSN/xx+4vP2i2RDvRZnQzkh6Tq3o/IWibw7jrKzAca07SqadlRMfegDPNx4ijtPbh9EzUdwUUMsLgFsJGdFfqloCfkSs5t/nR/hEkTXlgR0vxjGQUTeil6EJJb2ayQKhAX6x+uPAo6supw== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by PH7PR12MB7793.namprd12.prod.outlook.com (2603:10b6:510:270::19) 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:45:38 +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:45:38 +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 , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [RFC PATCH 11/19] xdp: convert to use vm_account Date: Tue, 24 Jan 2023 16:42:40 +1100 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: X-ClientProxiedBy: SYBPR01CA0058.ausprd01.prod.outlook.com (2603:10c6:10:2::22) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|PH7PR12MB7793:EE_ X-MS-Office365-Filtering-Correlation-Id: cf49a282-9822-42ab-b0c7-08dafdce382a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: swlTuo9A26qSmZr/qtf5eeHLVNj1itmA/M8Xyd8AkfRqZUC0/zMPXU6/b50hqyh+VxqX0Z+l9ce2YK04WGI6LfXNmwW7KHPD8RMvsCksOp4emgSGy8VbTAMzvG/Rchbbn2aRUlsBcDxX5Ag2T6XPdihZje97ykN8m5j79DVnDlq8ZdStbNt82GR6C0v8oXN2VwkSpPKEZeH/WP5Vo6b2B0h5ggzaOjutL+hMaCOwuLja9i3GaYayqcnN1gaIsWitahQt60lTFS5qoO6kxqKFnaeZiAxlhHHxH+Yc7NZDnFWpRDZBS4b/yEVRqEbKJ9Hyvi88iOI6fDMwssiX5ybXU+Ojl4HVkiIhIovvpX7HElo3reRfPF6zt9ioQIOL8dm8yhBWhduokLVvAtiuHy2e8/VEQqEcv4IKnmoniSZH1SMcoaPlMdrMwySKma+iCjNApb8TnfLzMA+IpZTugVxSaHbFF5kbKKHL1fRKBzeWC2aljnDYHSjWp8+i1Ajo52nFATl/YRxJ3LJyITbp8QVUleqEGQq1tCxZTtnH+FS8SZ4NEe8gMQFRo894bJ3hSPVMzDEW6V5C+oR6ZQFu2cdvJZFy+yvGgvbV4PxHY51YMSmlypnPV3BMKYaTs0aKJliSWcMFX7sW7h+kE8xbg1ebsg== 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)(136003)(396003)(366004)(376002)(39860400002)(451199015)(36756003)(316002)(4326008)(66556008)(66476007)(8676002)(86362001)(66946007)(186003)(54906003)(26005)(6512007)(6506007)(6666004)(83380400001)(6486002)(478600001)(2616005)(7416002)(66574015)(5660300002)(8936002)(41300700001)(2906002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?6dnhumuSLaHNtcx/G9lQdE9Pslt1?= =?utf-8?q?eIaHs39ck4uBGefrvpPzZWy9TM/ODYU+yb+0m/OkViTBfuH9aKsMboMOALweSXrpB?= =?utf-8?q?tDaRStSreRFN0FCsVNbyxp0QdrHZaxT2GTnrj0f6SHgYkh8hWsrSENyutWjyyrlW6?= =?utf-8?q?AKSbtPa81HfRm5ARzJSDZNT1z4OxjRCmgUjLi6VrIAZGqxTIgoIvdy0M3XcY6qEH4?= =?utf-8?q?NYTfa3vAN+Tmy1gqi3lfQvI21vQHlg4sP8yRH3owsDnwuUL4MFgoalLVpEXujPH6X?= =?utf-8?q?oFsg1C/Y5d7ehSFBSqxI6qsArEkb8lEpQNwAY+CojsgAIG9nz5K1yJJKol0Upr/aY?= =?utf-8?q?lwlAOAcNrY2Yp4M0xZGLB7ENd9CVEWzouk5QIJjmpdEW+kVgFeb8Euxeys8lHbr5l?= =?utf-8?q?5ddgt/vGWlDvphr54r2xddat0smcBZLlvZmLolvAM3F7e9UpxaV1km7iL9ut54WN5?= =?utf-8?q?d9XpDcHSIHsr+Z1mla5P02A1ic05ewwBTZUHST1BRiDXK0+xsb+EkEByzbvbbAc/r?= =?utf-8?q?fRgFlT5uGcKKHdx77pgszSKFvWmgWHXgAkX8stERS+qY49qklX/GYxNQNxGnOUJ6q?= =?utf-8?q?dhI5RTsqqz9zBbuac+FY1K+e4q3zSqCtIzPR8FjtHw1OpAZFYSzmXkskk3oORqejh?= =?utf-8?q?V1m//6qzoDdhfIZ4CfV5WNAF41w4KDjTXwUpp8v45mZRlbcj0vfJ1F6JlwvNOEVe9?= =?utf-8?q?uaT0ZtXBCchPNfdt1OUvbxriQOHM9quNPWHWI8OAtN/6CEV056DeJLgUiaGOLvrA/?= =?utf-8?q?PT6Xz5xETyrcJ48LtuV7YGsGXFpYwpVD3+Hs0VR0jL4GWuWEw+xK53xbK7wpa1nD4?= =?utf-8?q?A8+8LN8Kig0wEWdDNRI491QlP3EB/fHPni5HHQJbhycaubQ+s/GVMjmX9thq8hzhd?= =?utf-8?q?pp9SM/62sgsxTwDiuojhtLbSSRNvjNC/2rfWh9SRwOqcF0vsdbjLukoyEwgWx9w7H?= =?utf-8?q?7aJFXBTew3QaSSnntTR02c/ymZJhN1hYEKFh+Jh1HWp9HfG7kp+U75wXjXKk0+R8y?= =?utf-8?q?K3Ows4ScVJXtW6tFppnLjI6PPTereESjUEt3IlEO2TijP+YhEl6BAWeyyHygbi2Dh?= =?utf-8?q?zFXUmRSf+L4tEpIWjnEG9ZrLNm6CXb7bLoLVq/OddpCbSG4HHh+VdaTzEbcaP72D5?= =?utf-8?q?Rhg8FMAb3BrM7dOdSz+vkedFSvtvU5FUaA04cIplsBP3XlAoPMi+n2VaMrb/BKpFK?= =?utf-8?q?1DLfV/nr5/Lr2eC0Ij6S/aUzmaHUdjQRtr9URHDWnWbtSB8ar6pmqkEN68dpuJIyb?= =?utf-8?q?f/ZNWqpHPX8w+myRCovkkg5jQU1p6rKRDA69ouIxAl1sEjZNOwmvPmGz2CEBUfaFu?= =?utf-8?q?VtXgf96TUc1IFptG2m3y2TYQugV2D2qx4SmIyvwXlxic1RJbrDGW3q9g2cOWmesRu?= =?utf-8?q?Q8Qre4gke6qmSkNy+vsh1aG8AMsSoGRWUKwe0yfd7R9bIcpx9kkeItxnQUaktcZ52?= =?utf-8?q?57EE9EYOxOJ2AeRn7yWwx6sfMu6y37PM8wRTlsek7k+QDnlHtfV+OjYtpF9Y468O3?= =?utf-8?q?E+Kns8WSuqfk?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf49a282-9822-42ab-b0c7-08dafdce382a 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:45:37.9539 (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: 1MgMqsKhCJCMsd1D6jWU+xFhtwWJjLx86tJ/pq0DbRkuJbSEVsgnbOZqTlFxEOTRc/Ba/GHQ+wqCB5zpRuCObw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7793 X-Rspam-User: X-Rspamd-Queue-Id: 03272A000B X-Rspamd-Server: rspam01 X-Stat-Signature: 8fh6y9mi6ujsk65xn9b1azmtnrxa8swg X-HE-Tag: 1674539139-408628 X-HE-Meta: U2FsdGVkX18gUz+5AKdWcjkVVoUmGi1NDD86g403U7fScXc0dgP+QTYkCNStHK+wJeKBss64V3BMIuuP3/94pNp5WnoIMfqOVqMbpzlgeP4Z6XAhu/6SJzYdmujNCNCMC291FZw7jc8NGhSV1WdNGMugeewDvdzc1mOFU+HyOj5vrqshIdjGfkOW3A6JLrsQtAhFogoSvbsV6c0U6EHkrTzEEC3ph0hRooQpDOISFQ4VkPrF+PFJ6hUHDHXjE8kX42SHFYrjTfufIW98MzUGlKNKPyrmxH8l0Ud0SZ5weEGbAiH49Y8YL7Q8EvrJIbtmBcpcvZ15k6+3RaJfRRITmkg0urkTFOYkHzadipiPY4YCP6exUjPDBOo4CMf2svcdsZh+Okk/egBYUN8fChIkeyvbaOrsGJeDI555lg2ENXkA333mBJQVFykk9QOw6TZvIe5ui/eu3nMXW/rOfkyx7UTvPeKXyke4zCMempC7mKV9LX7mLbOfbTEiG/U847889F4MshNzTKRmRzStla3R7Z+dQmusa7txtmTAOEz5dPqACUXve7sLev6T1JMcs7Y1IiMXvLfbMo03omCuJJaHNNQch9jqkZbOz2Zy7aEzdSgeDDhKSfWSuhnXmF+pWleRgLhm7ymnvVHIMnTbRcirwceBeconlnQ9EUTD6mqbqQnzvyItDT7G2rcwBXAIa6cC0uWKlqlA5TDJEnSZ+IgEJIW9aNpMi//IXn8+lujX4up2Be7QVm77CwwHPAxzzhFuqSL0HMSb2o7Yky97vT+szMeNtnHTQ+d7Eb1wumHDuN/+0N2yNgzmip4tVEtiHvuQ+NgqT729TX5L2x6SAhu54C/x4RboKKGbAEm9VUqNoUWrBcjyzBu/S+bZlnM6v0O/kC+XT0sTy/0CUWkPi/Kf0TKc9YgH4zgYKpsa3oudLO4jYDZSdZB9/xe/d4u7AVmNrdDriNfYEAb4Co98iQf AMjmz1Dr 0KFI40krg6cGBEN1s2U9L5nAVfczO4HqNQTvYK6xeKgk+Dv8NS5kCDW5R1vm2rr/LWllsX0jL8r7dMw8z9whsoBbSlGo5RHafqLUlLHfotvSYDJm2kyZ9FdivHlkoC9daqAl4bHrXRKk+LrzLhXYnefuyZ7UolD8w6UBHJt6BATq/vEQFy8WlxPSO7GrKqHaJ+OI/bpqpBEQc4OyXXfRPYcmqC5OLxaT2eOuCBMD36wdE7SbmDDFwvG1XVSn5JSIVNbqh5PxyQ1lQccHnEUidK5Qo+0HiSfx1a7vo8M8/SYM1WRE/JKvUYJc3ghxaJfKXOB7LKsnSQ0ZhmZ9TB7xYBb7UiimbzKhftQTX72ajalv+WqRQ/3nNaPOFDSyScF3WoCy9h5xjN6pEC26NmS594GCTV0uHGIZUPgCsh8OUT+j0n4aGlc8PH9s3szxufJZpPRmp9MRQFJnwEO8+AoK2h3zNgS9/EVPBZIaSBMXZ5eS4iKHtjbS6ZyvPl/34jVtCYC8zHT8VfYicHNEIMglKoywRzQ== 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: Switch to using the new vm_account struct to charge pinned pages and enforce the rlimit. This will allow a future change to also charge a cgroup for limiting the number of pinned pages. Signed-off-by: Alistair Popple Cc: "Björn Töpel" Cc: Magnus Karlsson Cc: Maciej Fijalkowski Cc: Jonathan Lemon Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Jesper Dangaard Brouer Cc: John Fastabend Cc: netdev@vger.kernel.org Cc: bpf@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- include/net/xdp_sock.h | 2 +- net/xdp/xdp_umem.c | 38 +++++++++++++------------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h index 3057e1a..b0d3c16 100644 --- a/include/net/xdp_sock.h +++ b/include/net/xdp_sock.h @@ -25,7 +25,7 @@ struct xdp_umem { u32 chunk_size; u32 chunks; u32 npgs; - struct user_struct *user; + struct vm_account vm_account; refcount_t users; u8 flags; bool zc; diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c index 4681e8e..4b5fb2f 100644 --- a/net/xdp/xdp_umem.c +++ b/net/xdp/xdp_umem.c @@ -29,12 +29,10 @@ static void xdp_umem_unpin_pages(struct xdp_umem *umem) umem->pgs = NULL; } -static void xdp_umem_unaccount_pages(struct xdp_umem *umem) +static void xdp_umem_unaccount_pages(struct xdp_umem *umem, u32 npgs) { - if (umem->user) { - atomic_long_sub(umem->npgs, &umem->user->locked_vm); - free_uid(umem->user); - } + vm_unaccount_pinned(&umem->vm_account, npgs); + vm_account_release(&umem->vm_account); } static void xdp_umem_addr_unmap(struct xdp_umem *umem) @@ -54,13 +52,15 @@ static int xdp_umem_addr_map(struct xdp_umem *umem, struct page **pages, static void xdp_umem_release(struct xdp_umem *umem) { + u32 npgs = umem->npgs; + umem->zc = false; ida_free(&umem_ida, umem->id); xdp_umem_addr_unmap(umem); xdp_umem_unpin_pages(umem); - xdp_umem_unaccount_pages(umem); + xdp_umem_unaccount_pages(umem, npgs); kfree(umem); } @@ -127,24 +127,13 @@ static int xdp_umem_pin_pages(struct xdp_umem *umem, unsigned long address) static int xdp_umem_account_pages(struct xdp_umem *umem) { - unsigned long lock_limit, new_npgs, old_npgs; - - if (capable(CAP_IPC_LOCK)) - return 0; - - lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; - umem->user = get_uid(current_user()); + vm_account_init(&umem->vm_account, current, + current_user(), VM_ACCOUNT_USER); + if (vm_account_pinned(&umem->vm_account, umem->npgs)) { + vm_account_release(&umem->vm_account); + return -ENOBUFS; + } - do { - old_npgs = atomic_long_read(&umem->user->locked_vm); - new_npgs = old_npgs + umem->npgs; - if (new_npgs > lock_limit) { - free_uid(umem->user); - umem->user = NULL; - return -ENOBUFS; - } - } while (atomic_long_cmpxchg(&umem->user->locked_vm, old_npgs, - new_npgs) != old_npgs); return 0; } @@ -204,7 +193,6 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) umem->chunks = chunks; umem->npgs = (u32)npgs; umem->pgs = NULL; - umem->user = NULL; umem->flags = mr->flags; INIT_LIST_HEAD(&umem->xsk_dma_list); @@ -227,7 +215,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) out_unpin: xdp_umem_unpin_pages(umem); out_account: - xdp_umem_unaccount_pages(umem); + xdp_umem_unaccount_pages(umem, npgs); return err; }