From mboxrd@z Thu Jan 1 00:00:00 1970 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9689CCF9E3 for ; Mon, 10 Nov 2025 14:39:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1339E8E001C; Mon, 10 Nov 2025 09:39:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BC788E000D; Mon, 10 Nov 2025 09:39:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9E508E001C; Mon, 10 Nov 2025 09:39:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D1C798E000D for ; Mon, 10 Nov 2025 09:39:43 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 561FC12AE63 for ; Mon, 10 Nov 2025 14:39:43 +0000 (UTC) X-FDA: 84094956246.08.9F9496C Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) by imf22.hostedemail.com (Postfix) with ESMTP id 3C96FC0012 for ; Mon, 10 Nov 2025 14:39:40 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b="fq/6bZr3"; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf22.hostedemail.com: domain of loic.molinari@collabora.com designates 148.251.105.195 as permitted sender) smtp.mailfrom=loic.molinari@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1762785581; 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=52h3btDgfApCo4cTARjbeD/+n7ncTe762Z+6oMGl+44=; b=IHJgpa76CUOuGYPoLsFQkdyS7EfODWPGs1vsTyPJoFuNJY54Z4m6ODE/gqjMvGHU+nAw8U BJpBwS6rbX3g4LRueDGCYZRW408oPtXPbXmid3JtUHxiRYny3CysRPPO4hL7GPx3IcYgk0 3TtBJQDRF1dqkbXzNRbIVv6+S3EDTNA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1762785581; a=rsa-sha256; cv=none; b=FjFVXbZOaUFXPzF+Fj5Kyd/ms0Xf8Wq5/Balz9zPSrgMQm1CwxjlfjoQrbnMY4722wVQy6 w6fcxGBykjd2Yv2d/DJuebehTpykTJjIBq5r09qWrV4CgaWMLUWDkX3OL/452/Ajt0Jqzx NZTKD5tQGHVSW+z129lWNCAjxd00MpI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b="fq/6bZr3"; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf22.hostedemail.com: domain of loic.molinari@collabora.com designates 148.251.105.195 as permitted sender) smtp.mailfrom=loic.molinari@collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1762785579; bh=PmfHj5puT5EuJo5jMH3r8sbaCa9NbA7iIIBw3q5tS7U=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=fq/6bZr3AF2h2wkMNGSn1bXsocPuQEeBd+ezF2avzPXvHo/lvHsrcNC+tZbS8E5Iq xkJB4+am2a5IfxqIp+ehb9NPVKFSgvleVHdn4CivlgZRwnuPF9SnL8ajyR0NknfvP2 s7xp9Kqk+2jipyZbRtQfHx9eyAwAhm/ABmTkeAkIjdOiTtc2+8qqtYFcn7QauIky0J qi2AkZfthvSdYWmtrRTHuQs5oTa836l4Rwoz4pKgCE7iGHMIdDFb3F2YXgGACOPt1d jxQdyUfGkeW7/htZh8Ig5e8reM+6vEQVZbJRkW4WM4vf5Ct5o9PibWgvFUQrFyq3hO 0R67ZlTin9JNA== 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)) (No client certificate requested) (Authenticated sender: loicmolinari) by bali.collaboradmins.com (Postfix) with ESMTPSA id 17CAE17E0610; Mon, 10 Nov 2025 15:39:38 +0100 (CET) Message-ID: Date: Mon, 10 Nov 2025 15:39:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 03/13] drm/shmem-helper: Map huge pages in fault handlers To: Matthew Wilcox Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Boris Brezillon , 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 , 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: <20251015153018.43735-1-loic.molinari@collabora.com> <20251015153018.43735-4-loic.molinari@collabora.com> Content-Language: fr From: =?UTF-8?Q?Lo=C3=AFc_Molinari?= Organization: Collabora Ltd In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Stat-Signature: yssnqmo8sh6ximdhh65bey5rxa3s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Zo7WqDdlvt0ESkmO/6lcmPRBgh71kBRy0U0As+8OElRnjhws0eWfWGBALOB79qxb/IjoRRfgF75s80TirqNTif+FOX2BX4GELYeCKfyYGp17daXucIsYrFLHo6IhDOJS8V6hKAKbzEod7hkhHYv3wS8/usbF0NBf0tSuAI1i+nMx0+tOYWzInRS5U+FanVRneAuBoxgeHOESoi5hzGFMiKFPd37875Ekbm0bzNMOmNZ33v+3QQB0U2MJa2+nOfl8jFRXQuajzPU0cY6axCjl9FvxuOw9AGPvA+yvjlLgzDmEU1mK8EBOkNwI6lyQXFmwW8yF02Y5O4lS9zzjqsvJVuSKHKQV+pW3k8uF91JlBIqhMKQK86WzUJrFQySuHUVayfzGYx4gFn7w== 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: List-Subscribe: List-Unsubscribe: Hi Matthew, On 17/10/2025 23:42, Matthew Wilcox wrote: > On Thu, Oct 16, 2025 at 01:17:07PM +0200, Loïc Molinari wrote: >>> It looks to me like we have an opportunity to do better here by >>> adding a vmf_insert_pfns() interface. I don't think we should delay >>> your patch series to add it, but let's not forget to do that; it can >>> have very good performnce effects on ARM to use contptes. >> >> Agreed. I initially wanted to provide such an interface based on set_ptes() >> to benefit from arm64 contptes but thought it'd better be a distinct patch >> series. > > Agreed. > >>> >>>> @@ -617,8 +645,9 @@ static vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf) >>> [...] >>>> - ret = vmf_insert_pfn(vma, vmf->address, page_to_pfn(page)); >>>> + if (drm_gem_shmem_map_pmd(vmf, vmf->address, pages[page_offset])) { >>>> + ret = VM_FAULT_NOPAGE; >>>> + goto out; >>>> } >>> >>> Does this actually work? >> >> Yes, it does. Huge pages are successfully mapped from both map_pages and >> fault handlers. Anything wrong with it? > > No, I just wasn't sure that this would work correctly. > >> There seems to be an another issue thought. There are failures [1], all >> looking like that one [2]. I think it's because map_pages is called with the >> RCU read lock taken and the DRM GEM map_pages handler must lock the GEM >> object before accessing pages with dma_resv_lock(). The locking doc says: >> "If it's not possible to reach a page without blocking, filesystem should >> skip it.". Unlocking the RCU read lock in the handler seems wrong and doing >> without a map_pages implementation would be unfortunate. What would you >> recommend here? > > I'm not familiar with GEM locking, so let me describe briefly how > pagecache locking works. > > Calling mmap bumps the refcount on the inode. That keeps the inode > around while the page fault handler runs. For each folio, we > get a refcount on it, then we trylock it. Then we map each page in the > folio. > > So maybe you can trylock the GEM object? It isn't clear to me whether > you want finer grained locking than that. If the trylock fails, no big > deal, you just fall through to the fault path (with the slightly more > heavy-weight locking that allows you to sleep). I proposed a series v5 using dma_resv_trylock(). This actually fails later because the vmf_insert_pfn*() functions end up locking too. Not sure how to fix that yet so I proposed a v6 with no fault-around path and will get back to it (along with contptes) later. Loïc