From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 425A43DB621 for ; Wed, 15 Apr 2026 15:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776266865; cv=none; b=hAedmXAjr2LVPcFiamhyTNYHMxSu8s51mggl6J3Alipz6FZS2K60WDACXldxFVNK1TvzMvjQINuBecoMHUll+Lpl+iEjaEHulbJfqT1m+wLKKFjVmYL1EI5YaiAVWEz/eD1a3jjYdLJxb0HzqFayZl4h7OZ4cIPYcwOWoXdbxhw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776266865; c=relaxed/simple; bh=Po4knTBaQLAPMjdPI1y4XGYWElG83yxES1PzlsjXidw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qlxhGwOdHhOklq18zJ/yMxVibx1DHDEhM9hZI0iSzTARiEEW2XW8nRE/L+vOHHpEecXvxayAweG3e2C74ZfGMyR7s1l+rckkEvRCC3MMHRJxzhV0cwDoAPVPlb+F9So4b+HxVCMFtw1UCHHHWIGV7Ol6LHJrxbuNK50ZW4yRQVQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=tDtg+Sva; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tDtg+Sva" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-35e563b0ee7so1871849a91.1 for ; Wed, 15 Apr 2026 08:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776266862; x=1776871662; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=wPmlxegNR58V/H7yEEnR40syKnjm++PEkBAfISQyAVg=; b=tDtg+SvaX2bmqunje2yJyyMGUnyHPBVyLDO21+TaxxqN0qid0s+CrJZaRV12NJTnn3 ltYPb04mVQrKhpWhv2n51MxdnOdi6TT1O/qFquGBGslzPyunc2pE43qnKrsNOKXG7edh 1rNjnvdixO6sPGtpNtFwSXlhZUHLINwvFiavjJVJ45AD5R8Zckd0qwq7MCJQdQpkOa3B ae7bLEBn34KbcmmoNiLI+5mBgb8uoXloO1/FSnyW0gujg/Np3hEic79ZznRfQVmCmogp jrGGYMCdCnnHH3ap7tzB3IywR8f1abI1qfclL/23ehHS55TP2nEdIftrg+GXedOPIkDm nN+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776266862; x=1776871662; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wPmlxegNR58V/H7yEEnR40syKnjm++PEkBAfISQyAVg=; b=oiUyNZelZw29aDrePmCiUasfmHFMF+Mb11nB7Kh9gRhyDfs6HsTypUJclMHW1l+Itl 3Qq7UoN2usj7ryN6fsjWKrztFxmM0tlWeLwuYXswf/9Hawg4vyHLp+p53ees0lSiur6i 5SWHpFo5Q3UgSe7VneEYz5AXZSxNczI3xXO+DyUpzWkDzUlB8AuL/kmzjAymjirEWhLB iXYrpoXzr8qbyUCTn41zqvA6G+LLHvcLIZYYHw1Laq/k3dNzLNjbPqyf3UggnS10ZQ+u GQ0tWLdp0iRYa2j8cBUxaVL+lTkJNhip6H5MUJPrRfXt23Pr7W7VkyYMEAAcb0gD7o1C oj6g== X-Forwarded-Encrypted: i=1; AFNElJ8lQOpThb2l9Sr6sALyZ8i2Xa0PUmFAfb0MqfNbcN5iizum1s/dOFnhWuV85QQ+oiSFe/XWoXJ10LBKrO4=@vger.kernel.org X-Gm-Message-State: AOJu0Yweuz/2WQL6dbjEg8oJrFKqf4yP1Bom9KvT6VgbOgBbOA5TdgKY 6GMe8wz0Ptz0TWH/rRwBCJpMQO+QL+7HP7J2QlhYUB1oU+HnT0lpvCGQ X-Gm-Gg: AeBDietVFW6avmey20djNf24Ouk+HgTV/AZ8VhC2zDb0REbdkAj+XDZW5fdxPbEmAg8 7Ps4n24TTFwTi4yMeJkRt0RAo9ImHgu2O4/n1NzT5vUcSFLip7mQ0fZaEgpBUVGMOEnmvWFiy+s iIWVFW4fp5wYDZm1VoEgHvT+D1E8cTsIPMmNfhMQkR6U5Gs8ccmdphYnqbi7E5reFN9OdEfbdre vJxb6pVLmIWLExIf93oJnpavknVMuq9y9eYV4FMwTSe8cEo/jaZWzLzP61xiFimXoQ5YwukkWjX f/RtgssHO64pa9NLLfDkkf20kA+kkmeh2bvgK7CTyivDHIE+hT8nDPUgy3pWuR3+1abEzntIHrQ bSMOrsKHpkk/IQmXNtVEpxfDCyL4ifZXmJM8pcGIAbThJfM1zPajOu3yPAzgT/DnyWZDtLfLKLz a8HqdfytgZIIiDeSyGNXbGVdvcN/mML9x/cz/pqkUu2gI97HPjjMACkxQ5mDL0ho7GpCPTQH/I6 0sBEM/NiM7WAc3YUGDjQP+/+hIGUT8k2qdUk5g5v5qz X-Received: by 2002:a17:90b:5548:b0:35f:c156:a82e with SMTP id 98e67ed59e1d1-35fc156ab7amr7386272a91.9.1776266862425; Wed, 15 Apr 2026 08:27:42 -0700 (PDT) Received: from ?IPV6:2409:8a28:a78:79f1:759a:a9c2:ef40:55eb? ([2409:8a28:a78:79f1:759a:a9c2:ef40:55eb]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35fd20d0e78sm3732072a91.11.2026.04.15.08.27.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Apr 2026 08:27:41 -0700 (PDT) Message-ID: <2987ed25-bba1-4218-a776-0bb98aa87bbc@gmail.com> Date: Wed, 15 Apr 2026 23:27:32 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 13/13] mm/huge_memory: add and use has_deposited_pgtable() To: "David Hildenbrand (Arm)" , Lorenzo Stoakes Cc: Andrew Morton , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kiryl Shutsemau , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <41b1ff54-c120-42ae-8b74-54767abf3554@gmail.com> <2f29f66b-46db-4925-b922-4add61b633bf@gmail.com> <53d748d3-4150-4e7b-8c1f-4c58587e9183@kernel.org> <6125defb-3aa4-494c-abed-982be684f839@gmail.com> <6417587a-7e43-4615-9e2c-50a245842f59@kernel.org> <6edde1e9-0f42-4dae-b0d1-3f2895f2111b@kernel.org> From: Yin Tirui In-Reply-To: <6edde1e9-0f42-4dae-b0d1-3f2895f2111b@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi David, On 4/15/2026 4:13 PM, David Hildenbrand (Arm) wrote: > On 4/15/26 05:50, Yin Tirui wrote: >> Hi David, >> >> On 4/15/26 02:15, David Hildenbrand (Arm) wrote: >>> On 4/14/26 17:14, Yin Tirui wrote: >>>> I did a quick tree-wide grep: >>>> $ git grep -l "remap_pfn_range" | xargs grep -l "\.fault\s*=" >>>> arch/powerpc/platforms/book3s/vas-api.c >>>> drivers/infiniband/hw/hfi1/file_ops.c >>>> drivers/uio/uio.c >>>> drivers/vfio/pci/vfio_pci_core.c >>>> fs/proc/vmcore.c >>>> security/selinux/selinuxfs.c >>>> >>>> It turns out there are two users of this "hybrid" approach in the kernel: >>>> 1. fs/proc/vmcore.c: It pre-maps via remap_pfn_range() but registers >>>> mmap_vmcore_fault(). >>>> 2. arch/powerpc/platforms/book3s/vas-api.c: It pre-maps via >>>> remap_pfn_range(), but registers vas_mmap_fault(). >>>> >>>> >>>> How would you suggest we proceed here? >>> How about we populate PMDs in remap_pfn_range() only if !fault? >> Doing this would at most prevent VMAs with a ->fault() handler from >> getting huge mappings, which seems to have little negative impact. >> >> But wait, dynamic huge mappings are actually created through ->huge_fault(). > If my memory serves me right, also fault() can nowadays install PMD > mappings. > > For example, shmem only implements ->fault through shmem_fault() > > finish_fault() after __do_fault() takes care of that (mapping through a > PMD if possible). Ah, thanks for correcting my blind spot! >> I did a quick grep: >> $ git grep -l "remap_pfn_range" | xargs grep -l "\.huge_fault\s*=" >> drivers/vfio/pci/vfio_pci_core.c >> >> This is a false positive. There is no case in the kernel that mixes >> remap_pfn_range() and ->huge_fault() on the same VMA. >> >> What if we use !huge_fault instead, disallowing remap_pfn_range() from >> populating PMDs if ->huge_fault() is provided? > I think we should just disallow any PMD mappings if we either have > ->fault or ->huge_fault. > > I would assume that ->huge_fault implies >fault, but let's rather be > save than sorry. Agreed. I think I have a clear idea of how to handle this now. >> Then, when we encounter a huge PMD, we know for sure whether it was >> installed through remap_pfn_range() (needs a deposited pgtable) or >> ->huge_fault() (no deposit needed, can be refaulted). >> >>> Then, if we have !fault, we know that the PMD is from remap_pfn_range() >>> and has a disposed page table. >>> >>> Would that work? >>> >> So for Lorenzo's `has_deposited_pgtable()` helper, we could simply use: >> >> /* Huge PFN map without a huge_fault handler must deposit */ >> if (vma_test(vma, VMA_PFNMAP_BIT)) >> return !vma->vm_ops || !vma->vm_ops->huge_fault; > As mentioned above, also considering vma->vm_ops->fault; Will do. > >> >> By the way, while auditing this, I noticed that >> drivers/gpu/drm/drm_gem_shmem_helper.c calls vmf_insert_pfn_pmd() >> directly from its normal ->fault() handler instead of implementing >> ->huge_fault(). >> If we adopt the `!huge_fault` check above, this DRM driver would be >> wrongly classified as needing a deposit. It seems that DRM driver needs >> a minor refactoring to properly use ->huge_fault() to keep the MM >> semantics clean. > No, it's doing something that's allowed. If we call ->fault and there is > not PTE table, it may insert a PMD. Thanks for your clarification. -- Yin Tirui