From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 266621F30BB; Mon, 1 Dec 2025 18:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764612377; cv=none; b=Fmm5eKYXLv7ZDUx0tjZGC9FFtWem/xyqHk6V3F5ipCGXTlFL6W9UpQXtEZUmVRVb1WdjUpYrAWvBlJQwJhwT7htoqYyCtgiBq13PRtZYWYbVLlag5JtMgzM7jp3dkYRdQIxJai+TE7RzzE/xfgdik/1hHUU/iGrtFkBNoyx9B8E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764612377; c=relaxed/simple; bh=orbc3nuJhRBtP9HgFH/P7FPSU37dWjp236YX9cJ7qE8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KezIF0xrXiqBSKxP7+P31jUIUlzYLuLOtEI8ilNyeEYRhmCvqr2rqxz/aMbuiWjXkDq1Hf5VJJULSMNTVUsA2vUgpW2mGSum+J6Fl67zt0vMkNEG/MLxgkDNHBQAd7aBCdMXehepExCgDKN6KcfNBcK2D380JwRCp3E+pB+GpHI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=f4PUV0hS; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="f4PUV0hS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1764612372; bh=orbc3nuJhRBtP9HgFH/P7FPSU37dWjp236YX9cJ7qE8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=f4PUV0hSvnZmXOb2ZWccPOP5NEDYIGqGFgBkNrbZyFaHM7AR8XkGmUCu6OnkAodFA lj5NCIdmHu1VugxhaE8lMbzPaT6HbXdt5WZnd5bt3N42gHcTYxhDWAzN9HVwBIwjOs wdh52nnjvww3IORZATNTc/QuBF4ZPRL+RPQm7US6QnUUen3lLtN6Dv1IYOTdi4dcWS AiGsuJvFHisXkpA/o+9Kz0ReKG5F2tmIUDUJW25d4tnP+kt56w/AIqTphtfRva/KiA u6FWll/izQjWEpNlUNWFGTrJo9QZHfBgL6O4c1OlNQ0vK4YGvQYfqiR60p6q1ijFoC QluNngkMsJeTA== Received: from [IPV6:2a01:e0a:5e3:6100:7aed:fe0e:8590:cbaa] (unknown [IPv6:2a01:e0a:5e3:6100:7aed:fe0e:8590:cbaa]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: loicmolinari) by bali.collaboradmins.com (Postfix) with ESMTPSA id DD47317E1157; Mon, 1 Dec 2025 19:06:11 +0100 (CET) Message-ID: Date: Mon, 1 Dec 2025 19:06:11 +0100 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 01/10] drm/shmem-helper: Simplify page offset calculation in fault handler To: Boris Brezillon Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Rob Herring , Steven Price , Liviu Dudau , Melissa Wen , =?UTF-8?Q?Ma=C3=ADra_Canal?= , Hugh Dickins , Baolin Wang , Andrew Morton , Al Viro , =?UTF-8?Q?Miko=C5=82aj_Wasiak?= , Christian Brauner , Nitin Gote , Andi Shyti , Jonathan Corbet , Christopher Healy , Matthew Wilcox , Bagas Sanjaya , 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 References: <20251128185252.3092-1-loic.molinari@collabora.com> <20251128185252.3092-2-loic.molinari@collabora.com> <20251201090507.1ee10c65@fedora> Content-Language: fr From: =?UTF-8?Q?Lo=C3=AFc_Molinari?= Organization: Collabora Ltd In-Reply-To: <20251201090507.1ee10c65@fedora> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Boris, On 01/12/2025 09:05, Boris Brezillon wrote: > On Fri, 28 Nov 2025 19:52:43 +0100 > Loïc Molinari 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 > > Reviewed-by: Boris Brezillon > > 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); >> >