From: Alistair Popple <apopple@nvidia.com> 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 <apopple@nvidia.com>, Wu Hao <hao.wu@intel.com>, Tom Rix <trix@redhat.com>, Moritz Fischer <mdf@kernel.org>, Xu Yilun <yilun.xu@intel.com>, 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 [thread overview] Message-ID: <ab87fe6056db226f92cff3dc76ad215d33fee1c7.1674538665.git-series.apopple@nvidia.com> (raw) In-Reply-To: <cover.f52b9eb2792bccb8a9ecd6bc95055705cfe2ae03.1674538665.git-series.apopple@nvidia.com> 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 <apopple@nvidia.com> Cc: Wu Hao <hao.wu@intel.com> Cc: Tom Rix <trix@redhat.com> Cc: Moritz Fischer <mdf@kernel.org> Cc: Xu Yilun <yilun.xu@intel.com> 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; -- git-series 0.9.1
next prev parent reply other threads:[~2023-01-24 5:50 UTC|newest] Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-01-24 5:42 [RFC PATCH 00/19] mm: Introduce a cgroup to limit the amount of locked and pinned memory Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 01/19] mm: Introduce vm_account Alistair Popple 2023-01-24 6:29 ` Christoph Hellwig 2023-01-24 14:32 ` Jason Gunthorpe 2023-01-24 5:42 ` [RFC PATCH 02/19] drivers/vhost: Convert to use vm_account Alistair Popple 2023-01-24 5:55 ` Michael S. Tsirkin 2023-01-24 14:34 ` Jason Gunthorpe 2023-01-24 5:42 ` [RFC PATCH 03/19] drivers/vdpa: Convert vdpa to use the new vm_structure Alistair Popple 2023-01-24 14:35 ` Jason Gunthorpe 2023-01-24 5:42 ` [RFC PATCH 04/19] infiniband/umem: Convert to use vm_account Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 05/19] RMDA/siw: " Alistair Popple 2023-01-24 14:37 ` Jason Gunthorpe 2023-01-24 15:22 ` Bernard Metzler 2023-01-24 15:56 ` Bernard Metzler 2023-01-24 5:42 ` [RFC PATCH 06/19] RDMA/usnic: convert " Alistair Popple 2023-01-24 14:41 ` Jason Gunthorpe 2023-01-24 5:42 ` [RFC PATCH 07/19] vfio/type1: Charge pinned pages to pinned_vm instead of locked_vm Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 08/19] vfio/spapr_tce: Convert accounting to pinned_vm Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 09/19] io_uring: convert to use vm_account Alistair Popple 2023-01-24 14:44 ` Jason Gunthorpe 2023-01-24 5:42 ` [RFC PATCH 10/19] net: skb: Switch to using vm_account Alistair Popple 2023-01-24 14:51 ` Jason Gunthorpe 2023-01-24 5:42 ` [RFC PATCH 11/19] xdp: convert to use vm_account Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 12/19] kvm/book3s_64_vio: Convert account_locked_vm() to vm_account_pinned() Alistair Popple 2023-01-24 5:42 ` Alistair Popple [this message] 2023-01-24 5:42 ` [RFC PATCH 14/19] mm: Introduce a cgroup for pinned memory Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 15/19] mm/util: Extend vm_account to charge pages against the pin cgroup Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 16/19] mm/util: Refactor account_locked_vm Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 17/19] mm: Convert mmap and mlock to use account_locked_vm Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 18/19] mm/mmap: Charge locked memory to pins cgroup Alistair Popple 2023-01-24 5:42 ` [RFC PATCH 19/19] selftests/vm: Add pins-cgroup selftest for mlock/mmap Alistair Popple 2023-01-24 18:26 ` [RFC PATCH 00/19] mm: Introduce a cgroup to limit the amount of locked and pinned memory Yosry Ahmed 2023-01-24 20:12 ` Jason Gunthorpe
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=ab87fe6056db226f92cff3dc76ad215d33fee1c7.1674538665.git-series.apopple@nvidia.com \ --to=apopple@nvidia.com \ --cc=cgroups@vger.kernel.org \ --cc=daniel@ffwll.ch \ --cc=hannes@cmpxchg.org \ --cc=hao.wu@intel.com \ --cc=jgg@nvidia.com \ --cc=jhubbard@nvidia.com \ --cc=linux-fpga@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mdf@kernel.org \ --cc=mkoutny@suse.com \ --cc=surenb@google.com \ --cc=tjmercier@google.com \ --cc=trix@redhat.com \ --cc=yilun.xu@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).
Read more here: Source link