From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (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 E02D5235C01 for ; Thu, 2 Apr 2026 07:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775116188; cv=none; b=AMTIlKQanZya9syeTl21IRw/KSTbenMl+2d6rW2wzWaXj5dJGCOG064LxBCKJXpwWxA3k+D8u3Pvfokz+3oKzwSnenwLhEGwAJ0MowiBrWiPk79qfxUGXqgxYA5p8225kc2WWInNx6ppxUoA44aUY1is1uUFL/Ol8SDeG4pVStg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775116188; c=relaxed/simple; bh=c9x8jefmbnfQY7OBpqXIVwUMFMJSzuUgTi8QnKgQPM0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZoWkGMunD8jgcntTCwnX4S79jDYIv9nH/TkWPW9MarJoGQPmY1M100OsmvRPYQDh1WpXs1RIWsGwtERHCqYC6quWgWtRHQ4CClP1o7qsVa1xe1yw7nlX2Gb99RcP3muC0UewPM58JfJXEJhEhRkRy772cyxbmncCF/CU/tt5ySw= 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=F10j8xV3; arc=none smtp.client-ip=74.125.82.180 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="F10j8xV3" Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-2c7e5f38b37so882580eec.0 for ; Thu, 02 Apr 2026 00:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775116186; x=1775720986; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=hr2k/7x2iF+eHeC+QDLgLpQnsMX7glQGr6i0KUtTTkQ=; b=F10j8xV34R5EbDWZpc4ne58D2fz7O3ppnZPMBAq1fk7ncv+9S2CkGHxsLPZD+eBV5C MKkm+A/xRWK8dYcPPK+/N6QoV/+iMSlf8J/HUb1KscUOUQ9Zh1PfWPpB4n8Vz+BtL68k DMTacSTQLxFyePEQ9p0SPAh3k24TVsCX+ApLiLupv1JXwMCXoPvjEYi0KQN+jfgHVJMN urVgBin+HFkO9RP7NZFHFSywT4F2+jng2V3y4FqcAHQDCpl2dU3ptqhIYdiOAgI5zh8J mu704Ybp+gf6LMOyck/wBhj9AL+D5a3DfrSOyc7nDCtPpjTFGMS918c4sxvxnJriVgeA qsmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775116186; x=1775720986; h=content-transfer-encoding:in-reply-to:from:content-language :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=hr2k/7x2iF+eHeC+QDLgLpQnsMX7glQGr6i0KUtTTkQ=; b=oY5kvRxVq3tFWexUK96LhRcB8GffS5VFOmiY1s6JXP8fF4g86qw+rsTAJd+d/9Udit F+KeKQL6Wa2nxFphVt6aYQ/7gMkwWEzDXGw8iI7RdLGMD6s9royWaC8MSpKKw41Fp7h3 WiduHgJ6eTy/Kwa7g17KIdKBwHhDlpB+eHIazqDmDSrTqfTHTQJNDkOGxGcyqEa9XBcj PqNvmW9+6Cdv0RPjbqAa6Mim4GhWm+MRiXYERERUSpkmq162lvHhn9WZs5kneAPr1ofI WxLIIMmsUloBTtLsQ/h1+o4hYOVMOkFJIZg+xtHXrqdY1iZh2Fym95Z60ILsZHOr6nlF 36JA== X-Forwarded-Encrypted: i=1; AJvYcCV5EGMjzb87XhLpb4qXtLynCg9uzx+DCEIWpUwC03GpvoH2ji0Gu4Mn35lnHM0e7YW2hPeMEv4LGwBecTQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzoG3Z3FBWnaS8ok0oUqRHfrpMLw5VpbmfnsjeuR3BHGlFUoxv3 xrfDh8+6HkMFhqfJPeYvRcXeD8zV5dnZNWY0y/tzEvgbk8DbzfPYDQyO X-Gm-Gg: ATEYQzyEaNjef6QuFoLbDKEEnLm2+VF/wEpViHKCF9Q3BLF/549m/AMaNogpa3hnTQ1 5Y2xvYcSkDqk4QTJP1Idg98ROy4fIzITqMSSM/aBcgS5G2rJXoLGLsR3GnBIp+v/REW/thPPhtJ TgGVQWUhseOceyPyxrt0O0wwvIu5CVj7yPxQ0sR8IVmcLz68sA7vUsx4RYB2HlNm0w67mUUNNHz CKbLa9Az3KiJEBnh7HeUza3JLuKPk0c2MyuvggFknrGEAEfQGd1xL1IENMzh8H4drphwON/Uj/X PenukjnHXqT26UmbBjVOZEj/lH36PJPavtfSraHpgpADT7Cm3psml9h7tJdrZj16AGqQ7uAkrLV zy+WSrhrIZ6LhzZ84dG64Nr2eCfKIUVNMEEAuNWSEzG8dFgI+v3Zd0ebXxz2CjslLw6H6881vaa ziTfkXw56ysXh2VsLm5/9reCICoExfrdpeG7OIp/AstoWq6PudjXEPXSehbK4mZ7Frq/ZpRAjkM fUg3g== X-Received: by 2002:a05:693c:2b15:b0:2c8:7172:3b97 with SMTP id 5a478bee46e88-2c931170d0dmr3594312eec.13.1775116185778; Thu, 02 Apr 2026 00:49:45 -0700 (PDT) Received: from [127.0.0.1] ([154.17.3.126]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca7c9df90asm1650202eec.21.2026.04.02.00.49.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Apr 2026 00:49:44 -0700 (PDT) Message-ID: Date: Thu, 2 Apr 2026 15:49:35 +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: "Lorenzo Stoakes (Oracle)" Cc: Andrew Morton , David Hildenbrand , 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> Content-Language: en-US From: Yin Tirui In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 4/2/26 14:46, Lorenzo Stoakes (Oracle) wrote: > > I mean you would have needed to handle this case in any event, since this change > is strictly an equivalent reworking of zap_huge_pmd(). > > But it seems that doing so has clarified the requirements somewhat here :) > > I haven't had a look at that series yet (please cc this email if you weren't > already, I do filter a lot of stuff due to how much mail I get daily) Hi Lorenzo, Thanks for the quick reply. I will definitely CC you on the v4 series. > > So if this is a PMD leaf entry it will be present and PFN map, so I'd have > thought simply adding: > > /* Huge PFN map must deposit, as cannot refault. */ > if (vma_test(vma, VMA_PFNMAP_BIT)) > return true; > > Would suffice? Here is the dilemma: Currently, VFIO uses vmf_insert_pfn_pmd() to create huge pfnmaps on page faults. This sets VM_PFNMAP in vfio_pci_core_mmap(), but it does not deposit a pgtable (unless arch_needs_pgtable_deposit() is true). To resolve this, Option A: Force VFIO (vmf_insert_pfn_pmd) to also deposit pgtables. This unifies the VM_PFNMAP lifecycle. However, since VFIO can refault, depositing pgtables here incurs unnecessary memory overhead. Option B: Introduce a new VMA flag set during remap_pfn_range(), which we can explicitly check in has_deposited_pgtable(). Option C: Check vma->vm_ops->fault (and huge_fault). We would only deposit pgtables for mappings without fault handlers. However, this is fragile because a driver might still register a .fault() handler that simply returns VM_FAULT_SIGBUS. Do you have a preference among these, or perhaps another idea? > > By the way, I am wondering if the prot bits are correctly preserved on page > table deposit, as this is key for pfn map (e.g. if the range is uncached, for > instance). That's something to check and ensure is correct. > > I _suspect_ they will be, as we have pretty well established mechanisms for that > (propagate vma->vm_page_prot etc.) but definitely worth making sure. > Yes, they are correctly preserved! During a PMD split in __split_huge_pmd_locked(), we populate the deposited pgtable like this: entry = pfn_pte(pmd_pfn(old_pmd), pmd_pgprot(old_pmd)); set_ptes(mm, haddr, pte, entry, HPAGE_PMD_NR); The newly refactored pmd_pgprot() correctly extracts the exact protection bits (including crucial cache modes like UC/WC for device memory) from the huge PMD, strips the hardware-specific huge bit, and returns a pure PTE-level pgprot_t. >> >> [1] >> https://lore.kernel.org/linux-mm/20260228070906.1418911-5-yintirui@huawei.com/ >> >> -- >> Yin Tirui >> > > Cheers, Lorenzo -- Yin Tirui