[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aFHc3UujzDIfmKeT@nvidia.com>
Date: Tue, 17 Jun 2025 14:23:41 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: Jason Gunthorpe <jgg@...dia.com>
CC: <kevin.tian@...el.com>, <shuah@...nel.org>, <joao.m.martins@...cle.com>,
<steven.sistare@...cle.com>, <iommu@...ts.linux.dev>,
<linux-kselftest@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<thomas.weissschuh@...utronix.de>
Subject: Re: [PATCH rc 1/4] iommufd/selftest: Fix iommufd_dirty_tracking with
large hugepage sizes
On Tue, Jun 17, 2025 at 08:59:48AM -0300, Jason Gunthorpe wrote:
> On Mon, Jun 16, 2025 at 07:02:08PM -0700, Nicolin Chen wrote:
> > ---breakdown---
> > After `posix_memalign()`:
> > [ posix_memalign() memory ] ← malloc thinks it owns this
> >
> > Then `mmap(aligned_ptr, ..., MAP_FIXED)`:
> > [ anonymous mmap region ] ← malloc still thinks it owns this (!)
> > ↑ mapped
> > ---end---
>
> Yes, this is correct and what we are doing here. The allocator always
> owns it and we are just replacing the memory with a different mmap.
Hmm, if allocator always owns it. Does that mean the munmap() [3]
will release what [1] and [2] do (allocating and replacing)?
[1] posix_memalign()
[2] mmap()
[3] munmap()
> > // Step 1: Use posix_memalign to get an aligned pointer
> > if (posix_memalign(&ptr, alignment, size) != 0) {
> > perror("posix_memalign");
> > return -1;
> > }
>
> Also no, the main point of this is to inject MAP_SHARED which
> posix_memalign cannot not do.
I see.
> > Instead, it suggests a cleaner version without posix_memalign():
> > ---code---
> > void *addr = mmap(NULL, variant->buffer_size, PROT_READ | PROT_WRITE,
> > MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE,
> > -1, 0);
> > if (addr == MAP_FAILED) { perror("mmap"); return -1; }
> > ---end---
>
> Yes, we could do this only for MAP_HUGETLB, but it doesn't help the
> normal case with MAP_SHARED.
>
> So I would leave it alone, use the version I showed.
OK. Will respin a v2 with that.
Thanks
Nicolin
Powered by blists - more mailing lists