From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D9B239281E for ; Wed, 22 Apr 2026 02:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776826080; cv=none; b=rbznUW8Rs/Obu6vyc7HLZzMJ+7Wlvi6aan3Y2t90wmIf4pY/M3Z8WlMC42bZeefKhT8P8cj4QLUmVjsMmkcQAUq7/G/1jp+d4TzCsJJVVwpN4SshfiguftWywF1SzAth2AsH035zNKpeM1Ej1MN9Rm80O53tKod5C9wZQDbUsDA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776826080; c=relaxed/simple; bh=EOmXBM6YQ0kkaif3U+KbihqEFu7AXqzlgz9NvMUxLmk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=shh3ivtBdYdiVpXFbutv1fbPRozQkQwbcD2qoTHqu40PL7NxJcdZeVyDOFxesmz4n93k7sBGrP6VvDsVOB9/3fm0Obo0QkgEZNBVJJ6zJaFG1HRqiETHmUasoTsP4QNQa49dtX9OgC3X6TBVr02YfBrdmN7BGG51lk8imFCVSjg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cGZM44r4; arc=none smtp.client-ip=95.215.58.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cGZM44r4" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776826068; h=from:from: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; bh=GZQT0s2wUO2WZ6VaxUd4q0Cex0JTnd7JiwzgE6NWCYE=; b=cGZM44r49NJUlLAuQ8Aw4WQthcwoCIfYOTdFUY/tOEqlyLmYeIQaniKeQUZ40a4/uPKL23 ZKmWPRhyBQ0+zHs2xqUsv61Pg9+2NPLCnnWS80pkxlYxtLKg1D7OSRkW9qy6+8zhbw9Pg9 vOmcRT9UVY5pER/ELSwk++RheXdwOfk= From: Lance Yang To: david@kernel.org Cc: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, ljs@kernel.org, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, lance.yang@linux.dev, ryan.roberts@arm.com, broonie@kernel.org, dev.jain@arm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: Re: [PATCH v2] mm/page_alloc: fix initialization of tags of the huge zero folio with init_on_free Date: Wed, 22 Apr 2026 10:47:33 +0800 Message-Id: <20260422024733.70662-1-lance.yang@linux.dev> In-Reply-To: <20260421-zerotags-v2-1-05cb1035482e@kernel.org> References: <20260421-zerotags-v2-1-05cb1035482e@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On Tue, Apr 21, 2026 at 05:39:07PM +0200, David Hildenbrand (Arm) wrote: >__GFP_ZEROTAGS semantics are currently a bit weird, but effectively this >flag is only ever set alongside __GFP_ZERO and __GFP_SKIP_KASAN. > >If we run with init_on_free, we will zero out pages during >__free_pages_prepare(), to skip zeroing on the allocation path. > >However, when allocating with __GFP_ZEROTAG set, post_alloc_hook() will >consequently not only skip clearing page content, but also skip >clearing tag memory. > >Not clearing tags through __GFP_ZEROTAGS is irrelevant for most pages that >will get mapped to user space through set_pte_at() later: set_pte_at() and >friends will detect that the tags have not been initialized yet >(PG_mte_tagged not set), and initialize them. > >However, for the huge zero folio, which will be mapped through a PMD >marked as special, this initialization will not be performed, ending up >exposing whatever tags were still set for the pages. > >The docs (Documentation/arch/arm64/memory-tagging-extension.rst) state >that allocation tags are set to 0 when a page is first mapped to user >space. That no longer holds with the huge zero folio when init_on_free >is enabled. > >Fix it by decoupling __GFP_ZEROTAGS from __GFP_ZERO, passing to >tag_clear_highpages() whether we want to also clear page content. > >Invert the meaning of the tag_clear_highpages() return value to have >clearer semantics. > >Reproduced with the huge zero folio by modifying the check_buffer_fill >arm64/mte selftest to use a 2 MiB area, after making sure that pages have >a non-0 tag set when freeing (note that, during boot, we will not >actually initialize tags, but only set KASAN_TAG_KERNEL in the page >flags). > > $ ./check_buffer_fill > 1..20 > ... > not ok 17 Check initial tags with private mapping, sync error mode and mmap memory > not ok 18 Check initial tags with private mapping, sync error mode and mmap/mprotect memory > ... > >This code needs more cleanups; we'll tackle that next, like >decoupling __GFP_ZEROTAGS from __GFP_SKIP_KASAN. > >Fixes: adfb6609c680 ("mm/huge_memory: initialise the tags of the huge zero folio") >Cc: stable@vger.kernel.org >Signed-off-by: David Hildenbrand (Arm) >--- Tested this fix on MTE with both kasan=on and kasan=off. Works as expected in both cases. Nothing jumped out at me, LGTM! Tested-by: Lance Yang