From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (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 B175C3B6BFE for ; Wed, 20 May 2026 10:04:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.132 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779271460; cv=none; b=jImOKllKOvwLabiWAn+eKResyEJ2iRK09j9PaGQ5pe9MdwuIfHIP75I6EqEHZRrHLEsTH6T5pEuhkD3/9gggvQOS1jihmfaaSJW7yF7RImWjaih3N3p4THuar2l0EFd3/s4yzVLyGZFayhRw7rtnU4pTRx+REx+J2FS+H4YpTCE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779271460; c=relaxed/simple; bh=iYuDvqEvjvIHMiGVJQCwQMmeTK3PdeX/ZEhJLEABj9w=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rStfF7YuCFs3C0KP7SRLp3oj4Q0ori4FtF8jQnABTCNCUhRp3+WRNZw2JgjKLZn4xoQa8J/qjVHOOqhH7RLVBNAT+kIU0GL/uXoogTdhIXo8RA0VJf5l7uRQnfBc/BPFBYf+pyTE4yn7o7/Q8xsfVUREuTwybnCwjxYExGYIiJI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=DO1U2tUj; arc=none smtp.client-ip=115.124.30.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="DO1U2tUj" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779271453; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=/XSdoqWrkFocuSh6cxq2pbiUwYPICfwv5WO3SOEKurI=; b=DO1U2tUjG3J1mCjEctKLT8bILPfqyEetcJsjGrSqSr41oibBbkXNc76E5MeBojecBhmOGB0h5w7E8LjJV1We0J1ENISBXoU+hPklPbkvOLyO4xeVlEIyOGb5Hqn2SEVhcnKQCoKqm3ljoeV48fsi8ErlasebdqPmz3xZNVJYNCY= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037026112;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0X3IbWOs_1779271452; Received: from 30.74.144.110(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X3IbWOs_1779271452 cluster:ay36) by smtp.aliyun-inc.com; Wed, 20 May 2026 18:04:13 +0800 Message-ID: <72bec63c-09f2-4a97-908d-3e6af8e3e0ae@linux.alibaba.com> Date: Wed, 20 May 2026 18:04:12 +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 RFC v2] mm/shmem: set __GFP_SKIP_KASAN for swap_cluster_readahead To: olvaffe@gmail.com, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , Hugh Dickins , Kairui Song Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Boris Brezillon References: <20260519-panthor-kasan-v2-1-b7384458f076@gmail.com> From: Baolin Wang In-Reply-To: <20260519-panthor-kasan-v2-1-b7384458f076@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit CC Kairui, On 5/20/26 12:31 PM, Chia-I Wu via B4 Relay wrote: > From: Chia-I Wu > > swap_cluster_readahead can allocate folios for other mappings. If the > gfp flags do not have __GFP_SKIP_KASAN, but the other mappings have > PROT_MTE, we can end up with false KASAN errors such as > > BUG: KASAN: invalid-access in swap_writepage+0xb0/0x21c > Read at addr f5ffff81aa71dff8 by task WM.task-4/6956 > Pointer tag: [f5], memory tag: [f9] > > In the above example, because __GFP_SKIP_KASAN was missing, KASAN set > both pointer tag and memory tag to 0xf5 when swap_cluster_readahead > allocated the folio. But the userspace had already set the memory tag to > 0xf9 before swapped out. arch_swap_restore restored the memory tag back > to 0xf9, leading to the mismatch. > > Signed-off-by: Chia-I Wu > --- > Changes in v2: > - set __GFP_SKIP_KASAN for shmem instead of drm/panthor > - Link to v1: https://patch.msgid.link/20260512-panthor-kasan-v1-1-d8d3e275d71b@gmail.com > --- > mm/shmem.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/mm/shmem.c b/mm/shmem.c > index 3b5dc21b323c2..db9130a8c5b76 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -1784,6 +1784,11 @@ static struct folio *shmem_swapin_cluster(swp_entry_t swap, gfp_t gfp, > pgoff_t ilx; > struct folio *folio; > > + /* swap_cluster_readahead might cross the mapping boundary and > + * allocate pages for other mappings. We have to skip KASAN. > + */ > + gfp |= __GFP_SKIP_KASAN; > + > mpol = shmem_get_pgoff_policy(info, index, 0, &ilx); > folio = swap_cluster_readahead(swap, gfp, mpol, ilx); > mpol_cond_put(mpol); If we force __GFP_SKIP_KASAN, would this cause issues for mappings that explicitly should NOT have the flag? and your v1 link already mentions this scenario. Additionally, I'm wondering if we could use shmem_should_replace_folio() to detect such cases where shmem is being prematurely swapped in with incorrect GFP flags (e.g.: __GFP_SKIP_KASAN), and then handle it through shmem_replace_folio()?