From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 A0D353793A7 for ; Fri, 20 Mar 2026 22:27:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774045625; cv=none; b=tqAWxNecnT15Zika2UjGFRlhTFMxjsjF/bP7E01P8NwH6BpLYCf+dNz1BM9Bw6CQqvGe+ZWO4B0YeXLsDI5B0C6L9P7DwV5litp7xnpuc+aMfBsmat/d97/X0+CXMArWcgvwi/x1sDOd86guzj9zL1Afn1nHVJ8RsvSlog77O7g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774045625; c=relaxed/simple; bh=RrHWtNjmagPjo+xiCvixUOMsXB6SF6mT110kYLVQQCg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UJEHq9awzZlgcWlzk8KEwW3X427JxKZ2x+IJo0mTOH8DHr+4a/78ZB9bE9jfb0Sr5H+uy7YU1mkUS+7yY04LX1XjAS0mYej/76m4vQUmyW38VUhm79xYxrbYb9YLNkH8vDN5lSvbjtRzy/Cp2d4j27PI4P1+XEh6tsEjW6va6fw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=a9s+Kxrv; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="a9s+Kxrv" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-486507134e4so28887735e9.0 for ; Fri, 20 Mar 2026 15:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1774045620; x=1774650420; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=oZMf+n+2UaLqD15BKFxgwMFWBdH7VTMfFKDNbfbyD1E=; b=a9s+Kxrvs8gbzkMF8sDvevyDPjRblE9GA1/hM8VCp3Axt3KVX0dhqV9wdr6VgoSVuw JtKihII0Y2IUZatUU19rh2bmiwrvpQjgonoH8v56NRisoZOEGLgvVtSSxr3PfpX9NI9/ v0LsG6xTN3/AyL0CL983xRTIhIvWGql5ouwcclUbKrcz9B5PmwSj6a8wdZJJpWaoEmzD hpWFYS7jwBu98vqaZmOZ4sG9fmYihcZteYbw9hpYIyf3UqKN8FVt/1tm59x44imGtENr TFSVNpxM8o6Exn0irAMKZrDoABN20rFjYisZy+VBK2vNghbgkVkiUs87179Pk9Kqr21u C4cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774045620; x=1774650420; h=content-transfer-encoding:in-reply-to:autocrypt: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=oZMf+n+2UaLqD15BKFxgwMFWBdH7VTMfFKDNbfbyD1E=; b=SA9a9I0+EaQheQ6OKb4iTx5ehvKuwXu76h22eL96Wf7lz4IXnBw70kIiJspTqKvPYt lTTY95ItkuDkA/1FdYPC+ng2eTCKGbxbrgWE3jYND9QVF3wYm3KI9oAE1mywIwGp/cuf BOBQIa8eIfeZm4AAqK8f1VHGMrVbvQvD0bT7rE7toBJDK9lb8uN4LdUG1A9NKNPNzxKQ gWU3DNBmSNYdI7qBQcXz8ngacUjr8ZWW0t34vrdJOs3c1Uy9eN+WCcNEv36+K4cX4bxM bgXXdrmnLcpv+IVVO/F0pW2eo3zX/WPKeRSLAnXMKtTp9Gov9mT9H0rT8EIaMgzgLh7o zFhQ== X-Forwarded-Encrypted: i=1; AJvYcCV2LDbwzOXJO8Fvf+AB1lCcq58Jt4xOqGQ385ePJhx9MS902sB0dHhIRetCp94lTTBroSad4jpdYSxDrOY=@vger.kernel.org X-Gm-Message-State: AOJu0YzrWXzLHS+FEPs+oOMYzkFPdPCtyacmkxeJfus4GL2aBhJemf9c OB7KPRRWXFKSMbWUTcR6AxtCyWACwEwbMSH60yF8jqrfrR/X+v0RE2qMlka5SnkffdQ= X-Gm-Gg: ATEYQzyaEQDDuSGEHrtvPfOTHmnHuR6ycVkwMHNe5a4POlx54+4tOZWEsAS2f5Bqoxw ypxRvp1DUGtakMbDhtL/HLljYDE8sL2SHX0OgBW7wGHGD4iQB9vI72MSRtscQ1oDt6JiY55n18i lfP3YLCcZ+kPVdLV33/2XxLy889MIG+EzOQcRrJHrl6j7zjT2XJB/qorfc/Tad2XXBQrftEvZD+ y9obx39LzDo2AkLIFuShwlJGRZ1HkW2OYonrL4B3c+6SPGUSnlb8CcCeNjHfvzytPzhnAVSpo4G omxIfMeQt7Qn6N+gMEdfovH3xO89n87DzXxWpTPluS8+2Xxgi8zwOxRcAN/WWHAogx7Vynpxssc VjE4c+LDnNbQ0InRGauViYnLgWVwUfKCCaMwT1OqqOM/utREE7aa7VxessHKkV1zjoGu9+429HX Y+Jgmrn9hESFg4+H67vRyeBUFss78QWDs20pBWiL4kg2jaG0gKKuk= X-Received: by 2002:a05:600c:548e:b0:485:40c6:f51a with SMTP id 5b1f17b1804b1-486ff028ff2mr67823685e9.31.1774045619752; Fri, 20 Mar 2026 15:26:59 -0700 (PDT) Received: from ?IPV6:2403:580d:fda1::299? (2403-580d-fda1--299.ip6.aussiebb.net. [2403:580d:fda1::299]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b08352a17asm32327585ad.24.2026.03.20.15.26.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Mar 2026 15:26:58 -0700 (PDT) Message-ID: <33164dbf-ab81-4611-ba1a-e6e187bfaf51@suse.com> Date: Sat, 21 Mar 2026 08:56:52 +1030 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] btrfs: Fix BTRFS arm64 tagged KASAN false-positive To: dsterba@suse.cz Cc: Daniel J Blueman , Chris Mason , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com References: <20260319053413.14771-1-daniel@quora.org> <4d6f78d3-f274-43e1-adc8-c4fff4f85e24@suse.com> <20260320220137.GI5735@twin.jikos.cz> Content-Language: en-US From: Qu Wenruo Autocrypt: addr=wqu@suse.com; keydata= xsBNBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEdHvN0Kov3CtWA+R1iNN0RCeVun7rmOrrjBK573aWC5sgP7YsBOLK79H3tmUtz6b 9Imuj0ZyEsa76Xg9PX9Hn2myKj1hfWGS+5og9Va4hrwQC8ipjXik6NKR5GDV+hOZkktU81G5 gkQtGB9jOAYRs86QG/b7PtIlbd3+pppT0gaS+wvwMs8cuNG+Pu6KO1oC4jgdseFLu7NpABEB AAHNGFF1IFdlbnJ1byA8d3F1QHN1c2UuY29tPsLAlAQTAQgAPgIbAwULCQgHAgYVCAkKCwIE FgIDAQIeAQIXgBYhBC3fcuWlpVuonapC4cI9kfOhJf6oBQJnEXVgBQkQ/lqxAAoJ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wO JoAXek8MF37R8gpLoGWl41FIUb3hFiu3zhDDvslYM4BmzI18QgQTQnotJH8= In-Reply-To: <20260320220137.GI5735@twin.jikos.cz> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2026/3/21 08:31, David Sterba 写道: > On Thu, Mar 19, 2026 at 07:26:34PM +1030, Qu Wenruo wrote: >> >> >> 在 2026/3/19 16:04, Daniel J Blueman 写道: >>> When booting Linux 7.0-rc4 on a Qualcomm Snapdragon X1 with KASAN >>> software tagging with a BTRFS filesystem, we see: >>> >>> BUG: KASAN: invalid-access in xxh64_update (lib/xxhash.c:143 lib/xxhash.c:283) >>> Read of size 8 at addr 7bff000804fe1000 by task kworker/u49:2/138 >>> Pointer tag: [7b], memory tag: [b2] >>> >>> CPU: 0 UID: 0 PID: 138 Comm: kworker/u49:2 Not tainted 7.0.0-rc4+ #34 PREEMPTLAZY >>> Hardware name: LENOVO 83ED/LNVNB161216, BIOS NHCN60WW 09/11/2025 >>> Workqueue: btrfs-endio-meta simple_end_io_work >>> Call trace: >>> show_stack (arch/arm64/kernel/stacktrace.c:501) (C) >>> dump_stack_lvl (lib/dump_stack.c:122) >>> print_report (mm/kasan/report.c:379 mm/kasan/report.c:482) >>> kasan_report (mm/kasan/report.c:597) >>> kasan_check_range (mm/kasan/sw_tags.c:86 (discriminator 1)) >>> __hwasan_loadN_noabort (mm/kasan/sw_tags.c:158) >>> xxh64_update (lib/xxhash.c:143 lib/xxhash.c:283) >>> btrfs_csum_update (fs/btrfs/fs.c:106) >>> csum_tree_block (fs/btrfs/disk-io.c:103 (discriminator 3)) >>> btrfs_validate_extent_buffer (fs/btrfs/disk-io.c:389) >>> end_bbio_meta_read (fs/btrfs/extent_io.c:3853 (discriminator 1)) >>> btrfs_bio_end_io (fs/btrfs/bio.c:152) >>> simple_end_io_work (fs/btrfs/bio.c:388) >>> process_one_work (./arch/arm64/include/asm/jump_label.h:36 ./include/trace/events/workqueue.h:110 kernel/workqueue.c:3281) >>> worker_thread (kernel/workqueue.c:3353 (discriminator 2) kernel/workqueue.c:3440 (discriminator 2)) >>> kthread (kernel/kthread.c:436) >>> ret_from_fork (arch/arm64/kernel/entry.S:861) >>> >>> The buggy address belongs to the physical page: >>> page: refcount:3 mapcount:0 mapping:f1ff00080055dee8 index:0x2467bd pfn:0x884fe1 >>> memcg:51ff000800e68ec0 aops:btree_aops ino:1 >>> flags: 0x9340000000004000(private|zone=2|kasantag=0x4d) >>> raw: 9340000000004000 0000000000000000 dead000000000122 f1ff00080055dee8 >>> raw: 00000000002467bd 43ff00081d0cc6f0 00000003ffffffff 51ff000800e68ec0 >>> page dumped because: kasan: bad access detected >>> >>> Memory state around the buggy address: >>> ffff000804fe0e00: 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b >>> ffff000804fe0f00: 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b 7b >>>> ffff000804fe1000: b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 >>> ^ >>> ffff000804fe1100: b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 >>> ffff000804fe1200: b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 b2 >>> >>> This occurs as contiguous pages may have different KASAN tags in the upper address >>> bits, leading to a tag mismatch if linear addressing is used. >>> >>> Fix this by treating them as discontiguous. >>> >>> Signed-off-by: Daniel J Blueman >>> Fixes: 397239ed6a6c ("btrfs: allow extent buffer helpers to skip cross-page handling") >>> >>> --- >>> fs/btrfs/extent_io.c | 12 ++++++++++-- >>> 1 file changed, 10 insertions(+), 2 deletions(-) >>> >>> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c >>> index 5f97a3d2a8d7..e2b241fb6c0e 100644 >>> --- a/fs/btrfs/extent_io.c >>> +++ b/fs/btrfs/extent_io.c >>> @@ -3517,8 +3517,16 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, >>> * At this stage, either we allocated a large folio, thus @i >>> * would only be 0, or we fall back to per-page allocation. >>> */ >>> - if (i && folio_page(eb->folios[i - 1], 0) + 1 != folio_page(folio, 0)) >>> - page_contig = false; >>> + if (i > 0) { >>> + struct page *prev = folio_page(eb->folios[i - 1], 0); >>> + struct page *curr = folio_page(folio, 0); >>> + >>> + /* >>> + * Contiguous pages may have different tags; can't be treated as contiguous >>> + */ >>> + if (curr != prev + 1 || page_kasan_tag(curr) != page_kasan_tag(prev)) >>> + page_contig = false; >> >> I am not a fan of this solution. >> >> Although it doesn't affect end users who don't have KASAN soft tag >> enabled, I don't get what we can really get from the different tags. >> >> I mean all those pages are already contig in physical addresses, why we >> can not access the range in one go? >> >> Maybe it will be better to set all pages with the same random tag if >> page_contig is true? > > I don't know if there's an interface how to change the tags but adding > one condition that enables a sanitizer to work on some platform does not > sound like a terrible thing. The contiguous pages on our side is an > optimization so it's a special case, I'd rather adapt to the sanitizers > than to let people ignore a warning or have to read a warning that that > one is harmless. There is the interface, page_kasan_tag_set()/page_kasan_tag_reset(), and is already utilized inside MM. And the deeper problem is, if this is a false alert, shouldn't we fix the sanitizer? Especially in this case I didn't see any problem accessing properly allocated and physically adjacent pages. If this is really a problem, I think a lot of bio accesses are also going to cause problems, as one bvec can have multiple physically adjacent pages, and if they have different tags then drivers copying a large bvec should lead to the same tag difference. So to the reporter/KASAN people, what's the problem of accessing different tags in the first place? Thanks, Qu