From patchwork Tue Jan 24 05:42:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13113484 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 B2AD3C25B4E for ; Tue, 24 Jan 2023 05:44:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2173E6B0078; Tue, 24 Jan 2023 00:44:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C7FF6B007B; Tue, 24 Jan 2023 00:44:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 041686B007D; Tue, 24 Jan 2023 00:44:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E924E6B0078 for ; Tue, 24 Jan 2023 00:44:06 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CD84F403F2 for ; Tue, 24 Jan 2023 05:44:06 +0000 (UTC) X-FDA: 80388601692.16.8B3CC11 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2074.outbound.protection.outlook.com [40.107.95.74]) by imf04.hostedemail.com (Postfix) with ESMTP id 1311340016 for ; Tue, 24 Jan 2023 05:44:03 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=LzeyY9O0; spf=pass (imf04.hostedemail.com: domain of apopple@nvidia.com designates 40.107.95.74 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674539044; 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=Lj03mWpjbAOXnJWeiB3fprYyHO3IklPc7NSwtjAmNx4=; b=68Tax8rHaD2t/7o6tk6K+6RHgtwZQO01622DzS7gzL9ASMjr5E+ku65nyw/qT7cjRRam3s R0U15vzDrYj01vzsHSLJyJTTeewIE2BF6mFsdRsZA2COdJAHk3ly9VY/EUOgNybFsWJues gK0eKdlV0lfqbieYSqnakoc3sdt1iJE= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=LzeyY9O0; spf=pass (imf04.hostedemail.com: domain of apopple@nvidia.com designates 40.107.95.74 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1674539044; a=rsa-sha256; cv=pass; b=CCH+o3d+EbSHLMgjhbJmhjVHPRzD040RG5yYiqPYU1RvjG2O3MUUS4MM0UlJO+t3pDZoeH PH2OZuBRoFWKbq50IfzcG0c+HKQTfFHDt02w8QXKy89gXsZtZlcQN3Mi5jV8TOrrCgaaEc EwhbJt1od2mOqDGDLle+Fh2wIwCnvJk= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JUGDgmtl8dsT/u9CvbmSWFgb7U3oMh5dpC/CL9vTtLijmPBCNyUaKalNxiaDwx+U3gGUQjHslA8lca2fx4GPMSW/ceFgArZtfi5JFMRzp3zKTQ8d//DasO2csAGMKPa7MIoTMKoGqHZT1CjACVCqwJNUNlM7tCTzp6d4R8qn7OdMuTFhS9XVxeJi9ZCixH3Lhn13RIu9Z+bOO1X7g4w8zRoNY0ROmkYbLGNI/dh9TIbBezhyUDOyhi3qrYgghUcBPo8ErIghrdZAJYsq93cuvscKm1pobq/A7DWhs0QKse16kZ2g7oA53DJ0HqlCGZ1FWSsSRonyuUOQyKE+/mbgrg== 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=Lj03mWpjbAOXnJWeiB3fprYyHO3IklPc7NSwtjAmNx4=; b=MBtJ7D3DkQ+7V4GjhmwEI5eSaKA8rPxVSgHC7hN0bOncNlO/m4QHHH6S0RgcP/SZsgMlIhxP1sWzhY9k1mSGKRFZXqlMMTOIZzrk0pj3G/VhgRNoV3xUobhegPaiLwllNMCUsuWLIuqjunHbs5gP2SYribCvtt42iOGA4TyPjsQHgAELeq9X6pe6j8UBh6v+VmbQj/IYXXGCZNqzftiSdcP+4FroE0+xeIJ5rE/Ir3kEQo9OmSDwcnlIBZ84ipKwPZR9BLWUNmP3O0o59GR1/jI143JrTvITwMIHASbM3xCxoqPZXMG6V4S4C8Vtlottbupdk+OYVl/XRTPxSbxeOQ== 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=Lj03mWpjbAOXnJWeiB3fprYyHO3IklPc7NSwtjAmNx4=; b=LzeyY9O0+J+Ac/U78/4IatA7OJOeOWnXD//j74OXheYmfCQ9eT/hMwCD/3nPYnMZ4zpWMZrcvyMdpoaIT/0vM7OaYlTpkl1JMvO+1I2wrTSusoKtk1COMCzG7LOx7yscRyYRF8XIgMDYs3MyVDTKXlEup8RaYOgF2v8vMHgnrAfd0rzd1UB7Lnm+/MZqpQjdh8vN3h4WnZjuuf6yVvWBXii2iHHvXVmlctRAweN9qN6BvGuiA6gM5huoPUNg8qH+tvekIyb5i4hrAsAlSiTJgtUXxo5fehQU8E0YIgv1KoGQFk2zx4oBYpyAU1KEgOR0h8M0PslFl0ju5WJKj5QzCA== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by MW3PR12MB4540.namprd12.prod.outlook.com (2603:10b6:303:52::12) 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:02 +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:02 +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 , "Michael S. Tsirkin" , Jason Wang , virtualization@lists.linux-foundation.org Subject: [RFC PATCH 03/19] drivers/vdpa: Convert vdpa to use the new vm_structure Date: Tue, 24 Jan 2023 16:42:32 +1100 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: X-ClientProxiedBy: SYCP282CA0017.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:80::29) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|MW3PR12MB4540:EE_ X-MS-Office365-Filtering-Correlation-Id: 24006492-bfad-41e4-3b6f-08dafdcdff55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qtu5lNwzDpfFSTZfcYElaRJuqPb+FfsC7U+LCaFWASikDq+74jIAFIeYZ4pF8NehbZANRomB0wbU3i3hm7buJFJwUl2kORfQymkvtAjL0GMSA7114n06rO5J3iAvPKrzMTqzrWMRcer1kwdoU9gQGOpJu5Uz8BfMMAByr3RySGYSl8HSCcs4rprPlDt6YseBCnuYiaKkwd3uFtfjy7eC1nPwn7PTQcMx8AvklFHs6+/oRM+85srmwpNs666NBXk3pQ/3u+fTcGx/E7/nFKvUNPf//0aWh6Z3Sd17+sNlYQUBtBHD5epB74h7E+c+mKQFZ9t1VUkmDOfH+smvC5NuhqfmhckjBWLe6mAUAYa8X4fjCp6g2u8HN4JKZGs2GEqRywsCOsuWOnWeuOuwp6NbkIvRJzdUfVpqx0gR90lnQnmjtxpKrZkd9R3pOs7kmCRb+bHTK5zI1YJ97AEuFO301Bhma40tJ0JeqlbX5XyavRmnFpUx0p6TupohTFh3Lh1+NmmxV05SpjJ57B5CSI0j03bhmvKWmQ4sBUcZrhDxqsAzoWO6Uw+/msVJA3Mbn+5VdkJQvHOTAalIV3YIXa1Oxnh9vIzonfbu5XCY9Mynvfawb4rkfzT7HkzMFJ5avVQT5THg0Dp+6ja8LqMEtEPPgg== 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)(376002)(136003)(396003)(39860400002)(451199015)(36756003)(86362001)(5660300002)(38100700002)(2906002)(4326008)(8936002)(7416002)(83380400001)(41300700001)(66476007)(478600001)(6486002)(66556008)(6506007)(6512007)(8676002)(26005)(186003)(316002)(66946007)(2616005)(54906003)(6666004);DIR:OU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cv3LW77la7RXZ1IHVv3Z2H9LRswzJdk23LjqN9mt/7sviePGHxvR18oluPx9hw7BTaNiPVJIxCaEHk8tbssju1T3/cnkz2mD4XmIznIjTksLsTLrWDTRWiAiF1Tfzwzb5g+yVFbGCMoygp9DDeBM/Bsk3Pm8mYKsI7pGG2TBrHcp9Ny+I2mnZv+5k1+C89ezxXVoEtLFEQ1Yx9/OrXJIniTaQEN3ZTlPB8r5WVhDEXzEa5E1etWBa+EzCuDvLus4CimprWb26Tmy097Npg2SIlK5KhSewS/4lFtu4We+1lhccAxAfPyN86gHgmXik2Lsyc/DaRBcnfqt3vMy0uk59nrdGTwyBBP7f3Tro1WenmemEXHGgtvI89a6pZWEE4gwMmgBPau0HATidbWMRha/6Wz8S7j1/RgDLtvt4LogZnAPJjbnH+4bSxEPYE6KbJFBRyGS5DvIFcU3e5brSll3emglpCE6Oc9UYYGTe4pT+yfP8Riy0LKuJRX+74N/Kc76zrjvKzJ6v3Zz5T5meJaqGwn4wfTyNnjwBApULOiMHqX/yh9yF9L2B8/T8IJqNNbu62pUvuBE4x X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24006492-bfad-41e4-3b6f-08dafdcdff55 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:02.1963 (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: r4VZpmcdkvheaXLTWXT5dYSDMcC4hIHru8WPmM/kXvTHe/xFHI7/3hanI9zuHmZSP9tKv4v17io7kN11YXB23Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4540 X-Rspamd-Queue-Id: 1311340016 X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ur id1jlfT0 xffXcMRXNohasjFt3R1u8GLlfZE+5NW29t6U+ZRwwB7CsdYaZWiV8fZIT1tsxN5ScoBNEAOyrvnAIpQ7j7Zgdr0ceGPrblCQQOibySZRzOmz71bIZcnHCs9M5ihsUVv3TNvwABWtii+ewfBmGyrfx6IxZUpDh+dntj7AS5t+/XOAoByajZeY0hu9G2LywvKQndRrwk+N6JDuizJTnn2Q1Ut0s3yqDHLyitMRI6Ski0Va1aMv8VQsrUKRMRY0XaEc9K/C08yg5sMnPqKC9wVsM5h+L+4dg9msDD2j2AhoZE5vNvTGrqWi8oYcPZt3mgEdb5tFL+YwmCT2ArcRXBJMX4gGyO+UDovZkVFB1ffTg76Mv9FCh4amQvvI79jmHDM8zpHeLw63IfCF1nVcLEqrxNlTao0K+jnoml/3CF2xz2pERnx2W/XxVXc82JA== 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 vdpa to use the new vm_structure and associated account_pinned_vm() functions. Signed-off-by: Alistair Popple Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: virtualization@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org --- drivers/vdpa/vdpa_user/vduse_dev.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 0c3b486..bd87b58 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -70,7 +70,7 @@ struct vduse_umem { unsigned long iova; unsigned long npages; struct page **pages; - struct mm_struct *mm; + struct vm_account vm_account; }; struct vduse_dev { @@ -950,8 +950,7 @@ static int vduse_dev_dereg_umem(struct vduse_dev *dev, vduse_domain_remove_user_bounce_pages(dev->domain); unpin_user_pages_dirty_lock(dev->umem->pages, dev->umem->npages, true); - atomic64_sub(dev->umem->npages, &dev->umem->mm->pinned_vm); - mmdrop(dev->umem->mm); + vm_unaccount_pinned(&dev->umem->vm_account, dev->umem->npages); vfree(dev->umem->pages); kfree(dev->umem); dev->umem = NULL; @@ -967,7 +966,7 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, struct page **page_list = NULL; struct vduse_umem *umem = NULL; long pinned = 0; - unsigned long npages, lock_limit; + unsigned long npages; int ret; if (!dev->domain->bounce_map || @@ -990,8 +989,8 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, mmap_read_lock(current->mm); - lock_limit = PFN_DOWN(rlimit(RLIMIT_MEMLOCK)); - if (npages + atomic64_read(¤t->mm->pinned_vm) > lock_limit) + vm_account_init_current(&umem->vm_account); + if (vm_account_pinned(&umem->vm_account, npages)) goto out; pinned = pin_user_pages(uaddr, npages, FOLL_LONGTERM | FOLL_WRITE, @@ -1006,22 +1005,21 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, if (ret) goto out; - atomic64_add(npages, ¤t->mm->pinned_vm); - umem->pages = page_list; umem->npages = pinned; umem->iova = iova; - umem->mm = current->mm; - mmgrab(current->mm); dev->umem = umem; out: - if (ret && pinned > 0) + if (ret && pinned > 0) { unpin_user_pages(page_list, pinned); + vm_unaccount_pinned(&umem->vm_account, npages); + } mmap_read_unlock(current->mm); unlock: if (ret) { + vm_account_release(&umem->vm_account); vfree(page_list); kfree(umem); }