From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 BC5D32459CF for ; Fri, 21 Aug 2026 14:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787323808; cv=none; b=mZP3A9oCCQYLhgcdaPdR5lAdhGySpQMrX5XdOLS+oWyuABGDLarMd8CxN8FIFumT4BZqd7lISGgprDDxwjASdqJwFXPtbYEHQsr0uDlxL2RJzgkihQeznGrOj8khSjPoQMRztIwiS0useo+Aa/EZ4B17ao5PH4VIq7lj98/lyxs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787323808; c=relaxed/simple; bh=Th05AXV33XUIA6lETcaOxK8fZhRq0/PoWh2QzQCsttc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Rq6Z5avcGsN8j6sHRBjC8AHpbDk19mARMMNLaHQb3XlfcnxyM3daZqr0naLzJ8DnSusD9Ys5+bfO+m0W41zbC6TOLI/ld3aPxvWQ8L2iE/yOhU2HyLsXH7i9T3IGAxg+y0Zk5u122rSHo9chTPTO68UYETZrSwDxHhGT1fWK7Y8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=uCID6uCN; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="uCID6uCN" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-936e8bd9caaso75944585a.2 for ; Fri, 21 Aug 2026 07:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1787323805; x=1787928605; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=CGzie6Qe/X0/cYKzE/v7Y5d2k3Tc6ZI2rClbmVZ2bdM=; b=uCID6uCNKSTVnuF0wdcyC66YrAp8+/UzEptQ94lZvgdVSDu2Q4Nrt+6/U/yfBPH698 Xs80HAGXzXCbFbAwuru44Q4x8r3jrh949leeg2RqrlC7ZkKkuOsYAmit4z+y8UqRFDcs 2S/NeMIQ9Jfw4M/gaqCAvsZGp51RyX1/waUgfz7B11tOfXOtWFBkeDqjoh57zi1gorgp GTzLS59E34pSzwL0DBV2Bw2KJzdDhwnfqHDUB3g8dKpXscrBvibLWwB0UL4Au5XaN0P6 t1PCIlQvQYHYerRhUKRMBffz8fnXfJ5y7VoTQ7rZnWVSvxGWQOAPnDo5piw5AEW/L3GZ rMlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787323805; x=1787928605; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CGzie6Qe/X0/cYKzE/v7Y5d2k3Tc6ZI2rClbmVZ2bdM=; b=l2gkPrKbCOUMSjW+moRuRoA4wthVd8MHjberhLrQabsHM8CRn9DKoRC421F5gM684/ LXq1vvcEG442PaaRNOnAmE+k2QJXfRc0XX3mXX5ZVUnkRnFMfGwQm9mzcZiFMulhfOqr 67CTm7RHw4i5y5XMUKfoZRI+nWOuf5aEAiGaYQIdSZrx4vJAiLCtAKWUFCKhTkiiFhy/ SIZ72KVL/gARePy4iIXsKA9hRUVe//da2htx82ZgtsQ6cM3Jr3KdsHAjUDez9QgYYUDF yj5CAah7FpTau8LrhVBwPyMugjx5IV31GGh9fCoSi4PpTUpjBchvn3M9zPmkFyncUbRJ PqRw== X-Gm-Message-State: AOJu0YzqRXnB3MYWNvY1m3Q9ml+/+c8ZL2a6CERJKviOtk1PxcKW/8C2 +Wl9uG426gHh7VZLLzf6PTCH7ltGA7MTei+1YOvJCp5MXyEJ/d5gTml44q7EXocRoBM= X-Gm-Gg: AR+sD13aGhsF8VjeVqdIU+dqrZhALDDZUP25cymrO7Fsat6ikS5r9IGahkx4KxwP4Sw oGqEzzcRlQm125ktnoZGH1N0qarPnyR/dUzCfcxk+6FOMHxXuDXK3nBM/nJkgRgrImxKeF2y9kt VW4HQfT7MQzU5Xi0XOprlWDWE/v5ZukjCdxHzDrweoTueVLEgrTq2GaE6CZXXwh1OQaQw/bIjF4 li75ZwcN6aj1xE7dodQV5xVZTMu9PtVF01bTNkFILqDvB03P+Mjf2bBYC5UivSUrOxJdyprDjXa buVNAlY7jvC4igIHWaXizl312puQmPcNsUqVVPzb9HTqYcX9yarVOWmRPlvrtwQkCIEqKyl1vP/ ezTvIemvFrQBNiuNL7We7khtxv+ceMhp/HWkI1vTqTLREHEqkLe8rQd3LpvfbT5nAG2TBwIVGtK n6Mrc24eIB33dd50t12qopEHdnfczZcCJfgJt1/IuWiwATWIzRNZ0vWxhFarUzeTkG0EP5tdjq6 XpbUIx9D7fh6SA656AG9oQEPOw223LNoeupNs9ecqU/O7+3iQ== X-Received: by 2002:a05:620a:2591:b0:936:d833:6a35 with SMTP id af79cd13be357-937392bd3abmr583820685a.0.1787323805326; Fri, 21 Aug 2026 07:50:05 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-60-52.washdc.fios.verizon.net. [173.79.60.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-93720493f35sm609512385a.9.2026.08.21.07.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 07:50:04 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, akpm@linux-foundation.org, liam@infradead.org, ljs@kernel.org, david@kernel.org, vbabka@kernel.org, jannh@google.com, ziy@nvidia.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, peterx@redhat.com, jgg@ziepe.ca, sashiko-bot Subject: [PATCH 0/2] mm: stop calling pmd_folio() on special PMDs Date: Fri, 21 Aug 2026 10:49:45 -0400 Message-ID: <20260821144947.167382-1-gourry@gourry.net> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Andrew: the first patch in this series will annoyingly conflict with the zone device fixes (see Closes tag) where Sashiko found these. Ordering on backporting is annoying here, not sure of the best approach. === Two page table walkers resolve the folio behind a PMD with pmd_folio(), which is only valid for a PMD mapping a refcounted struct page: madvise_cold_or_pageout_pte_range() mm/madvise.c queue_folios_pmd() mm/mempolicy.c vmf_insert_pfn_pmd() installs special PMDs holding a raw pfn that need not have a memmap entry at all. Both walkers can reach one and fault on the first folio field read. The PTE halves of both already use vm_normal_folio(); these two patches make the PMD halves match. The four callers of vmf_insert_pfn_pmd(), and which walker each reaches: drivers/vfio/pci/vfio_pci_core.c VM_PFNMAP mempolicy drivers/gpu/drm/drm_gem_shmem_helper.c VM_PFNMAP mempolicy drivers/gpu/drm/panthor/panthor_gem.c VM_PFNMAP mempolicy drivers/hv/mshv_vtl_main.c VM_MIXEDMAP both can_madv_lru_vma() rejects VM_PFNMAP, so only mshv_vtl_low reaches the madvise walker, and that needs CAP_SYS_ADMIN. queue_pages_walk_ops supplies its own ->test_walk, so walk_page_test()'s generic VM_PFNMAP skip never runs and vfio-pci is reachable by any process holding the device fd. Hence the different stable tags. One behaviour change: mbind(MPOL_MF_STRICT) over a PMD mapped VM_PFNMAP region now returns 0 rather than -EIO. The PTE loop already returned 0 there. drm_gem_shmem and panthor are where this is observable, since they PMD map pages that do have a memmap entry and so never faulted. Reproducer ========== No hardware needed. An out of tree module stands in for the drivers above: three misc devices, each with a ->huge_fault calling vmf_insert_pfn_pmd(), plus VM_HUGEPAGE so the fault path takes the PMD branch. /dev/pmdspec_mixed VM_MIXEDMAP, pfn at the 1 TiB mark, no memmap /dev/pmdspec_pfnmap VM_PFNMAP, pfn at the 1 TiB mark, no memmap /dev/pmdspec_real VM_PFNMAP, real alloc_pages(PMD_ORDER) on node 0 Userspace maps the device into a PMD aligned window, reads one byte to fault the PMD in, checks a module parameter to confirm it went in, then issues the operation. vng --run --user root --memory 4G --verbose \ --append "numa=fake=2" \ --exec "insmod pmdspec.ko && ./pmdspec_test " numa=fake=2 gives a node 1 to bind to; the module allocates its real page on node 0, which is what makes queue_folio_required() true. subtest operation parent series -------------------------------------------------------------------- madv_cold madvise(MADV_COLD) oops ret=0 madv_pageout madvise(MADV_PAGEOUT) oops ret=0 mbind_mixed mbind(MPOL_BIND, n1, MPOL_MF_MOVE) oops ret=0 mbind_pfnmap mbind(MPOL_BIND, n1, MPOL_MF_STRICT) oops ret=0 mbind_real mbind(MPOL_BIND, n1, MPOL_MF_STRICT) -EIO ret=0 Two things the table shows that are easy to miss in the code: - mbind_mixed passes only MPOL_MF_MOVE. MPOL_MF_STRICT is not needed for a VM_MIXEDMAP vma: walk_page_test() only skips VM_PFNMAP, and vma_migratable() is true for VM_MIXEDMAP. - mbind_real demonstrates the user visible change (-EIO -> 0) Reported-by: sashiko-bot Closes: https://sashiko.dev/#/patchset/20260817220810.1175596-1-gourry%40gourry.net Assisted-by: Claude:claude-opus-5 Gregory Price (2): mm/mempolicy: use vm_normal_folio_pmd() in queue_folios_pmd() mm/madvise: use vm_normal_folio_pmd() in cold/pageout PMD range mm/madvise.c | 4 +++- mm/mempolicy.c | 15 +++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) -- 2.55.0