From: "Loïc Molinari" <loic.molinari@collabora.com>
To: Boris Brezillon <boris.brezillon@collabora.com>
Cc: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
"Rob Herring" <robh@kernel.org>,
"Steven Price" <steven.price@arm.com>,
"Liviu Dudau" <liviu.dudau@arm.com>,
"Melissa Wen" <mwen@igalia.com>,
"Maíra Canal" <mcanal@igalia.com>,
"Hugh Dickins" <hughd@google.com>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Al Viro" <viro@zeniv.linux.org.uk>,
"Mikołaj Wasiak" <mikolaj.wasiak@intel.com>,
"Christian Brauner" <brauner@kernel.org>,
"Nitin Gote" <nitin.r.gote@intel.com>,
"Andi Shyti" <andi.shyti@linux.intel.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Christopher Healy" <healych@amazon.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Bagas Sanjaya" <bagasdotme@gmail.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, linux-mm@kvack.org,
linux-doc@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCH v10 01/10] drm/shmem-helper: Simplify page offset calculation in fault handler
Date: Mon, 1 Dec 2025 19:06:11 +0100 [thread overview]
Message-ID: <e2102c82-6b8f-4f6e-80ea-ee185bb1e52e@collabora.com> (raw)
In-Reply-To: <20251201090507.1ee10c65@fedora>
Hi Boris,
On 01/12/2025 09:05, Boris Brezillon wrote:
> On Fri, 28 Nov 2025 19:52:43 +0100
> Loïc Molinari <loic.molinari@collabora.com> wrote:
>
>> For a fault at address addr, the page offset is
>> page_offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT
>> = ((addr & PAGE_MASK) - vma->vm_start) >> PAGE_SHIFT
>> = (addr - vma->vm_start) >> PAGE_SHIFT
>>
>> Since the faulty logical page offset based on VMA is
>> vmf->pgoff = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT)
>>
>> We can slightly simplify the calculation using
>> page_offset = vmf->pgoff - vma->vm_pgoff
>>
>> Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
>
> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
>
> One nit below
>
>> ---
>> drivers/gpu/drm/drm_gem_shmem_helper.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
>> index dc94a27710e5..be89be1c804c 100644
>> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
>> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
>> @@ -577,8 +577,8 @@ static vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf)
>> struct page *page;
>> pgoff_t page_offset;
>>
>> - /* We don't use vmf->pgoff since that has the fake offset */
>> - page_offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
>> + /* Offset to faulty address in the VMA (without the fake offset). */
>
> It's weird to say "without the fake offset" here, because IIUC, both
> vmf->pgoff and vma->vm_pgoff contain the fake offset. And that's fine,
> the problem really is when one of the subtraction operand is not
> relative to the fake offset.
Yes, both values contain the fake offset. vma->vm_pgoff is the actual
fake offset (mmap offset in the GEM context). vmf->pgoff is the fake
offset added to the offset we're looking for (offset from start of VMA
to faulty address). So the difference just gets rid of it, hence the
precision, but now that I read it again after a few weeks, it's a bit
misleading so I'll just remove it.
Regards,
Loïc
>> + page_offset = vmf->pgoff - vma->vm_pgoff;
>>
>> dma_resv_lock(shmem->base.resv, NULL);
>>
>
next prev parent reply other threads:[~2025-12-01 18:06 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-28 18:52 [PATCH v10 00/10] drm: Reduce page tables overhead with THP Loïc Molinari
2025-11-28 18:52 ` [PATCH v10 01/10] drm/shmem-helper: Simplify page offset calculation in fault handler Loïc Molinari
2025-12-01 8:05 ` Boris Brezillon
2025-12-01 18:06 ` Loïc Molinari [this message]
2025-11-28 18:52 ` [PATCH v10 02/10] drm/shmem-helper: Map huge pages " Loïc Molinari
2025-12-01 8:16 ` Boris Brezillon
2025-11-28 18:52 ` [PATCH v10 03/10] drm/gem: Introduce drm_gem_get_unmapped_area() fop Loïc Molinari
2025-12-01 8:33 ` Boris Brezillon
2025-11-28 18:52 ` [PATCH v10 04/10] drm/gem: Add huge tmpfs mountpoint helpers Loïc Molinari
2025-12-01 8:34 ` Boris Brezillon
2025-12-01 13:06 ` Maíra Canal
2025-11-28 18:52 ` [PATCH v10 05/10] drm/i915: Use " Loïc Molinari
2025-11-28 18:52 ` [PATCH v10 06/10] drm/v3d: " Loïc Molinari
2025-12-01 8:37 ` Boris Brezillon
2025-12-01 13:16 ` Maíra Canal
2025-11-28 18:52 ` [PATCH v10 07/10] drm/gem: Get rid of *_with_mnt helpers Loïc Molinari
2025-11-28 18:52 ` [PATCH v10 08/10] drm/panthor: Introduce huge tmpfs mountpoint option Loïc Molinari
2025-12-01 8:45 ` Boris Brezillon
2025-12-02 9:14 ` Loïc Molinari
2025-11-28 18:52 ` [PATCH v10 09/10] drm/panfrost: " Loïc Molinari
2025-12-01 8:47 ` Boris Brezillon
2025-11-28 18:52 ` [PATCH v10 10/10] Documentation/gpu/drm-mm: Add THP paragraph to GEM mapping section Loïc Molinari
2025-12-01 8:39 ` Boris Brezillon
2025-12-01 13:27 ` Maíra Canal
2025-12-02 10:26 ` Loïc Molinari
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=e2102c82-6b8f-4f6e-80ea-ee185bb1e52e@collabora.com \
--to=loic.molinari@collabora.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andi.shyti@linux.intel.com \
--cc=bagasdotme@gmail.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=boris.brezillon@collabora.com \
--cc=brauner@kernel.org \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=healych@amazon.com \
--cc=hughd@google.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kernel@collabora.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liviu.dudau@arm.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mcanal@igalia.com \
--cc=mikolaj.wasiak@intel.com \
--cc=mripard@kernel.org \
--cc=mwen@igalia.com \
--cc=nitin.r.gote@intel.com \
--cc=robh@kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=steven.price@arm.com \
--cc=tursulin@ursulin.net \
--cc=tzimmermann@suse.de \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/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