From patchwork Tue Jan 24 05:42:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13113494 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 40ED2C25B4E for ; Tue, 24 Jan 2023 05:47:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F6CD6B0085; Tue, 24 Jan 2023 00:47:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A2DC6B008A; Tue, 24 Jan 2023 00:47:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DC986B0085; Tue, 24 Jan 2023 00:47:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4BDA76B0089 for ; Tue, 24 Jan 2023 00:47:52 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1BF6BA05F2 for ; Tue, 24 Jan 2023 05:47:52 +0000 (UTC) X-FDA: 80388611184.27.D8F4FC2 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2069.outbound.protection.outlook.com [40.107.93.69]) by imf04.hostedemail.com (Postfix) with ESMTP id 5C39140012 for ; Tue, 24 Jan 2023 05:47:48 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=OkXIWNgx; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf04.hostedemail.com: domain of apopple@nvidia.com designates 40.107.93.69 as permitted sender) smtp.mailfrom=apopple@nvidia.com; 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=1674539268; 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=JHkCArMXy0OdvLO0RAQFjr57zAUQQNccPb96BhM7l+4=; b=7o9VZfQi3SkPN3nGgYCWqKtbQlrvBKAsZk1D8dC0zu8QZclUYpzHsFKpqWwhgBIvqShttF fNgeecbP1jV6NEoRQO7+DXdXu7NcovEpkw680K6a5/vZU0jV/o+Dqhp9MqXzenOrnZPVKL JJczLAmA+hTOCbaTgol94RkH5MIpUnw= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=OkXIWNgx; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf04.hostedemail.com: domain of apopple@nvidia.com designates 40.107.93.69 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1674539268; a=rsa-sha256; cv=pass; b=EiPwpgX7wM5huksdZwOhuxuoHf1V78YgExD+IFedh4tvL35YbriNVJtmnmJv9a81qrSBfn o4uyL2KaMRtEmffaJ5WV4XdHWfENfEtJWeL6l9wpOMQHgMUS/6q20oOlzKOw+fUomN76VH pzJ2qpfPn6NNNQFgPdpC0Rvdi/WjF6M= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nVqeVIchqhUITUKkoCUTolmxFecSRzVJZDvyy/ZDkH2/IGyl1z+Lp9QpW9tfHapgXFAuAJlUcaUtHuD8XlUd6QDmQjxOQhgiAsiQDv68pgFa5V2b7Sm50VOBhXu7K+2DoTVjjJllZTkX47pfxiAOhKojHqpnB+RF08hm3q60pvEAmAmFbkgA3e15zOA+VDLQZOaYGkuKcBPmperjcQlodhTNaFNqnzpdz1bWz+VJVcrmxcvOX2aHRiGoTGChnwsMhGAi4G8BF+bRCpHFQdhVfXuylLjG955vFtJ+kchMAg+oEmUQhE1mh99viLHoSAUR/8CLsvoElhFnJcSgwnW0jw== 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=JHkCArMXy0OdvLO0RAQFjr57zAUQQNccPb96BhM7l+4=; b=Bz9+IR2B11qVnhOMtNVdOUdnxuv55O84hSKQSIZxrTOdjqL29LPDt0X6VW6pe3vCaimEWeEoBx5pYcvZVeB+fN1YdOAMmAQrfs/SKabBk+Hw6NsZ4Zv91orhdN+ibu8tj42/9VQM/lEa1XxthG6EdZQ/kBzotkZE02jdrDgbIUh6N9+MSGoxz35DFFbVLABd6/YnqVc6XH54DNwj7RXvMGUmq5icx7QAP4HsnxiWXPR5No/ZCmWBj/zsAHa9Blw0cuSnxZ9ZWKw5BsxWPiJ7c31jvxfM9iN60wGIgabh4CaVw2q+rMYNd7aCYSvVxjb52EVRglV5awH7GCmpELghUw== 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=JHkCArMXy0OdvLO0RAQFjr57zAUQQNccPb96BhM7l+4=; b=OkXIWNgxDiDGgLHMtSXGhlKxx0DPyHdvKoo49YG7qSKBVhYDH7Jtf/cYs2RfT4U6O176yq+tfUybhgU98BeBOSnKW8EMf+NhWXp89QLNQhE9d6v19q0GBmTVyQaGNZ21AmS0Pm5J1lUc8uRpV2+AYq2oxyJzG7ljaEHxgdUzPqxx3IOXGPyXhs5GN7OI5HaFG8igNzgTxI6cg+3KJNaM7ehzmpYXV4IzFbmbZETJyM4p4uNW0xQtnhxPnfypsAFvgtPbmJXiU5tkyo8S+qfbCTqA7rF7JFrRQwXPy0Lnhig8hG1GkHE4s/xSAWw6/N1DD4+J1Hf74Gh//3INslQcbQ== 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:47:46 +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:47:46 +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 , Wu Hao , Tom Rix , Moritz Fischer , Xu Yilun , linux-fpga@vger.kernel.org Subject: [RFC PATCH 13/19] fpga: dfl: afu: convert to use vm_account Date: Tue, 24 Jan 2023 16:42:42 +1100 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: X-ClientProxiedBy: SYXPR01CA0110.ausprd01.prod.outlook.com (2603:10c6:0:2d::19) 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: dce7c2be-5135-40c5-3e67-08dafdce8503 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xx0ryKRawWeSDLJ1jfK2YfejLjG2YGUuJIFGocK9qFPO6LFXIQa6pGyWvAteg3TyAjGb9QDAIoET8ZHzwoJK5UKnLm6zwgR1BtNb/IQ8CZIBBxSedQMbF9fBTDEeigXhbNBh5SDfNOMXzkdCPyY9vPhbSOgtnLqPfH3Hok+nLBpV834cVNTfcO79tDVWTLjWibg6661F/wu64nlbeoD0pdISPfHC/BvIx6R3qKrjFqGD6Lvw0GS2WZMmXgs9YI422xAVHq62ix2/UEj1zhuRk/8h2vD9pCFjBbeLXHyY6nwzsB+OfyacNkY01z9hjksk3X9rn3QYQMTg7gQ9279pKPwdqY1/ri2f4Rkdzu+BUw+t5qj+qTThDURT4hvuh04UQEY6cXIdVANkkxICM+swzFBvP14j2kEHCufaG3Q0AXFS9G0whourcFL2yi5FwRqLtvXCZ0iRQPZxilCuxIWfDAHvnbaTQXArAxtVodpwMCTXeCH4yt6qcMn97/wm0YvVD5Ui9bwGZBrxUoJEsJkmmhnJE8nLMamEsNRr4nxbSZL2IjC5oSOHjTCtO0bxHSHUGv86p2OjkuEIDx8qx2oCE1tb5F1qUR/n+AiuQijIPUTTBZ3CyjqDaA/8UbFGQq1CnZCNZtcgHTB8+2yeouzF+Q== 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)(5660300002)(8936002)(41300700001)(2906002)(38100700002);DIR:OUT;S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Vkma/XC3RGzFByPyDm5PFy4gPCsg3Mj6yllmW099rLBc7aiH0rg3NQFddsdNn06b0F5K25kUQ9v/YlyjdwqoCCekvydxBY7XBBxtJQ6eGoOSIzlNzCNJei0FZPQAyeQWJmiVXslP8hpWzM0hQULaPaFRqFZRa/Ojp5aDFycaWm3nqRn/Y0Vqht8geaqXa3MccYSUO0upskWcGEmbh0k68iafYKAqgqFpm7CBRiI1K8TVxxgMeW83bzpWCaxGwSOD3ozlhuJoScG1mBQhFJTDjQGI4eeqPT42UBU/dCjv18jwSZ2YiHOWR6QmHT3w4MCY+DZ4uTNMF9UbTkB/v49ccAOk3sRRHFxj9WEMGz1xr9Fg4TEzE6dwzPrObi8MmRKX8zZsrfK76d9UGXLZ166CNjXzxeI7vpqfIXEAtVQyIpmJwREa+lO/u7gqnEJ776XLxlG4/h6wD+D8iK3gsxUx6JlL4ZtG0q8EWPypBPeP/ev6XYcXZJ9N4pOdECcBeYFzCwU7O9TdcnpGTmzdLvGzFj+re8+MIjLq+7tOMx1qNwAz8177nmTeFUYPRUh X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: dce7c2be-5135-40c5-3e67-08dafdce8503 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:47:46.4737 (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: 4bUO7RKaOO6s4F4e1iuGBwzHgY6c56ikphacUw6tEg55g8qiUZhyhJ5szsNdzx7+4LaiP2JM4fwr7+DRYiellw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7793 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-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met98GtDSquDAf3ILZ3I5fCV/XArFg+zG1HKoz/k3t3BbUsOpK/AFsOzlqRxHdTyouJgSFgij+WYrjbxVYoHuKWh4iKQ6d4lbqpsDyuaX0upDvdFVnP5g2A6/5em5Go95jbfw8BcwJI+ijrP3qaKOh/ioj07JswBr9/v9b4pORhzMmJ4SH3F+obBY4RuKCf7wU0H/n1MRn8L0GRcmMvxcpT92b3BTyn+Xgk7b2h42taxubiGrK3p8QeNDaMSfz8YKB5VPCjD6TN/2e+JaWUw6y5siE2aE+tXWsbOKtZ6JRTPnTmYNRZkkaS03lI8OloRVh0I5N9lENtDnMRbpWkxU8pUGUBMnAv31uDtNqIKF5juf9nmSO4yeKmF7bGEO1OlufPYKV//w= 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: To charge pinned pages against the pins cgroup drivers must use the vm_account_pinned() functions which requires initialisation of a struct vm_account. Convert the dfl-afu-region code to do this and charge any pins to the pins cgroup. Signed-off-by: Alistair Popple Cc: Wu Hao Cc: Tom Rix Cc: Moritz Fischer Cc: Xu Yilun Cc: linux-fpga@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/fpga/dfl-afu-dma-region.c | 11 ++++++++--- drivers/fpga/dfl-afu.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/fpga/dfl-afu-dma-region.c b/drivers/fpga/dfl-afu-dma-region.c index 02b60fd..3b99784 100644 --- a/drivers/fpga/dfl-afu-dma-region.c +++ b/drivers/fpga/dfl-afu-dma-region.c @@ -38,7 +38,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata, struct device *dev = &pdata->dev->dev; int ret, pinned; - ret = account_locked_vm(current->mm, npages, true); + ret = vm_account_pinned(®ion->vm_account, npages); if (ret) return ret; @@ -67,7 +67,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata, free_pages: kfree(region->pages); unlock_vm: - account_locked_vm(current->mm, npages, false); + vm_unaccount_pinned(®ion->vm_account, npages); return ret; } @@ -87,7 +87,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata, unpin_user_pages(region->pages, npages); kfree(region->pages); - account_locked_vm(current->mm, npages, false); + vm_unaccount_pinned(®ion->vm_account, npages); dev_dbg(dev, "%ld pages unpinned\n", npages); } @@ -223,6 +223,7 @@ void afu_dma_region_destroy(struct dfl_feature_platform_data *pdata) afu_dma_unpin_pages(pdata, region); node = rb_next(node); + vm_account_release(®ion->vm_account); kfree(region); } } @@ -322,6 +323,8 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata, region->user_addr = user_addr; region->length = length; + vm_account_init_current(®ion->vm_account); + /* Pin the user memory region */ ret = afu_dma_pin_pages(pdata, region); if (ret) { @@ -365,6 +368,7 @@ int afu_dma_map_region(struct dfl_feature_platform_data *pdata, unpin_pages: afu_dma_unpin_pages(pdata, region); free_region: + vm_account_release(®ion->vm_account); kfree(region); return ret; } @@ -399,6 +403,7 @@ int afu_dma_unmap_region(struct dfl_feature_platform_data *pdata, u64 iova) dma_unmap_page(dfl_fpga_pdata_to_parent(pdata), region->iova, region->length, DMA_BIDIRECTIONAL); afu_dma_unpin_pages(pdata, region); + vm_account_release(®ion->vm_account); kfree(region); return 0; diff --git a/drivers/fpga/dfl-afu.h b/drivers/fpga/dfl-afu.h index e5020e2..b1554e0 100644 --- a/drivers/fpga/dfl-afu.h +++ b/drivers/fpga/dfl-afu.h @@ -51,6 +51,7 @@ struct dfl_afu_mmio_region { * @in_use: flag to indicate if this region is in_use. */ struct dfl_afu_dma_region { + struct vm_account vm_account; u64 user_addr; u64 length; u64 iova;