From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (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 63E743D904C for ; Tue, 28 Jul 2026 19:47:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785268047; cv=none; b=cK0ATOLIUF3g6w7Z4KTGoCkeuhn9EQUILoy7DFLMW1yOPiBCVpmBmhpOvakT9nXSnZZB4bgO5+7BeG38T3Z77oiwWWDeKJbzhvjNNIQb3CNgB7rtzBJPfGIXyKQ9lsh6mw5N5Q2ixDj8ggmnoUwMVaIK9w028Inh3l3VU2Gwcf0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785268047; c=relaxed/simple; bh=QMZ7J7lKfDME8A5FG6nzVSk2RlwEU5lJAgsrB/UXl7A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oknqFRd5VHICfSy8g1cdI02bTvp57wlc8HIOftXY8+1ZvJ5YpfyDm6MA0Mt1iL7DiS8T9YWbF2mxQbRlfF0NOLOx7kDc51urX1jCtNCSwY+Y3Rkla4zO2Vids9Gs0+zNgjJccPAUTsEe974K730tKtgOKf5Rf7OYGw2d01IAv1M= 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=QFgWFY5r; arc=none smtp.client-ip=209.85.160.178 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="QFgWFY5r" Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-51a868b6962so2194161cf.2 for ; Tue, 28 Jul 2026 12:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1785268044; x=1785872844; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pqmZmonnGKuyrTzlO9IdYf4JadmrLNGgv2eh0Lztbm8=; b=QFgWFY5rplJgBTZ0DUBT/7aUmAmnCaGim61StbqxE7tL1euejovrRBURSgxKM6EC58 +236Uh1HUg5NZ0lSWrKP2FTH0DA4UmrcNxUPres1mrIeItBxvXqXxq0BTCvEPUriIMNr 7zMOg3Aicxw30peaKP3nSZWm011dIyBmlT1Cg0SyirHviOsrFlohIa5Kze08Jc1GnNO/ qVnDRABNw/PTY6A8WKisTIig6B9Vrghim79bCheyuQOwMukWv+MAybKQY3iwQyISA8BW KCN33JMtJuz6SjWNfEPoSGfcqI3l8TlKh4RwqLBDdGtF8kBNYQSgAKByS2zpefU4xYa8 4dCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785268044; x=1785872844; h=content-transfer-encoding:mime-version:references:in-reply-to :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=pqmZmonnGKuyrTzlO9IdYf4JadmrLNGgv2eh0Lztbm8=; b=pDeV3c4yMzT5XPPY6mP/GyL39L0KpFzRZ+V2Zk27YVEjgNkeqsdB/nX6YmP8rKM/Pl nDnrP5+UTQgeAUz23wva+Nk53Xx8lfGV2A3FDKxTdPnS5YILjh1ODvxgvVL32nK4Rd44 2L529dXPY44Uww6LsWSECoqQPZDVcAeWwmZapW3ReT/rlGbnayBTOadKjOnDOPcSgQQp xviMYEXGqdT8K20z63Mc8PIGP72tcK+KG6QzAaQYDoQtxUi3GeLVbeWGgdJHctkWjYED Ud3p3cbKztTYAsGcDgwG1Hr+j4JiaQEdKAg++QCiOu7l5KnOGe5T6WHA47ZuOsG8wfdB qc2g== X-Forwarded-Encrypted: i=1; AHgh+RqWkk/ysVzH0obwP535JcrFDGVb6JKzUF/YG76AADjCUYXReH8Dx3q+XIrnWYli8h7Zl1KaAk+fZ/WU68M=@vger.kernel.org X-Gm-Message-State: AOJu0YymB4AoIG5YgkZjSIf1wS+bwnPq6pIWfl6a2uvrnoPJqxk2DT7q e/mFHMMlc0Il6fCT+/vipJazL7tfoCG4GPshfwO8nfLnmnanRwpuGvPOW43D13FmHxo= X-Gm-Gg: AR+sD107J7vabpCCrzd7+YL3vXsYAczUc30LvrCqf+iGu8xL4TyMv0SPcGdXpQnckFF yVDcgwNJUWL0BZB3WQAxvKqWHJI4ELGSLwcmYd0Wpd9FiZUVk986C4KxSySUGWfd6mk7s6Z++tI aY59SE5ej4bJJepDlCuQcFDiK3H8DamWkDS5yjenzX18x9VQnLISoZFr9li+qgRDaT4lAupT+4E KnpGfGXeG2RqaMOOszVYTEJT5TwpGEklvJYfmzhjbAbMWZKUUqY8UM2DMwp/lYndxdnp0TXr/yE rFrXCaVh3RCq3xiD5lSJynon1ufFrt/qn+toaiA5rY9XN2J1IL8r1pxlCOtdSrvpyDyTtFUNp61 skmc6hyFh9G8U7Ck3FiSm8j3JHhxzg4wR0koubQqrn+nI1OfH9Cehgb6a6IZqOyUTMZw6Yb0cGK 0Fxh/4PtfRqXfgjRdBc5SOlGV9VY3Rs10SiXIIerGwtanoW42du0dp+XLy99aN9cUyjk8h9qGKp g== X-Received: by 2002:a05:622a:2c6:b0:528:3b83:3483 with SMTP id d75a77b69052e-529d70fc0aemr38942701cf.23.1785268044243; Tue, 28 Jul 2026 12:47:24 -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 6a1803df08f44-9081dd6b539sm6700176d6.41.2026.07.28.12.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 12:47:23 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: damon@lists.linux.dev, linux-kernel@vger.kernel.org, kernel-team@meta.com, sj@kernel.org, akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, liam@infradead.org, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, vbabka@kernel.org, jannh@google.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, stable@vger.kernel.org Subject: [PATCH 2/4] mm/huge_memory: skip zone device folios in madvise_free_huge_pmd() Date: Tue, 28 Jul 2026 15:47:12 -0400 Message-ID: <20260728194714.3713735-3-gourry@gourry.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260728194714.3713735-1-gourry@gourry.net> References: <20260728194714.3713735-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit madvise_free_huge_pmd() resolves the folio backing a PMD via pmd_folio() and marks it lazyfree without checking for zone device memory. The surrounding guards do not cover every zone device case: - MADV_FREE only operates on anonymous VMAs (DAX mappings are excluded) - !pmd_present() branch rejects device-private and migration entries - present zone device PMD (device coherent THP) is not filtered. Unlike vm_normal_page_pmd(), it performs no special/pfnmap check, and would be marked lazyfree here. Bail out when the folio is a zone device folio. Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations") Cc: Signed-off-by: Gregory Price (Meta) --- mm/huge_memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 5bd8d4f59a7b..e0ffdeeb3077 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2338,6 +2338,10 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, } folio = pmd_folio(orig_pmd); + + if (folio_is_zone_device(folio)) + goto out; + /* * If other processes are mapping this folio, we couldn't discard * the folio unless they all do MADV_FREE so let's skip the folio. -- 2.55.0