Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4143642rdb; Thu, 14 Sep 2023 13:09:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnCeALClpZDISzFlr7x15Q/X9pTsAMYbbR6OS7XNy39RZsuH72cZR4elis5ojAbi6txn7N X-Received: by 2002:a05:6a00:2d9e:b0:68f:bbc3:df44 with SMTP id fb30-20020a056a002d9e00b0068fbbc3df44mr7507817pfb.0.1694722147997; Thu, 14 Sep 2023 13:09:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694722147; cv=none; d=google.com; s=arc-20160816; b=cny1cgPzkXYLr6DPc3IRkw+O00oXrd6OG2WI5Lvi4prjp+4/DzSV+ceXZYJDdsu2bm 63LUKeP5GcQxTJR2cV02txKMwexljjrqUREvvhyd5HLIzzpfQJqWE9nJ+RtphtJPGDS0 /dvw2gsPDixOw1ynq5+/VmJSsZRyL8yAjvyLgcNMRYqAwhsrTLqjln8pTqfOvsHtVzTU +y5UPYDYbqVU6pbau8AY+/UJHsbEyReDWSPvaokTjqSazslnX6xqjeujL649aI684e/s 8k+6N9vdoB5bdVSnO5g4XnRFzc5Y6PEJZqNVj684HaY1vA92Nvw/LX+Xxp4juOJDp1tp 6ZEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=E/ecNnDz5zq7YMrO/wGOI+Yrvu8MsC3RqtEZg7CpzAM=; fh=/A3TzlxXJydb/2/WhkZ+ZBeXXjCjQjzuA3JsWozfPkQ=; b=SG1Lz0P0rLJhjnetjVnz0Kv0JKcU45j8rtdH3v1/gHqYplRcyDEmNvcs6KhTKeJktx zYPZWo3EAEtzpM0YmSjAQM8Z66zgttqsM8OpwdodRI1TzC2HigXwXaHy8hdbqh4hw3y6 FYtKJ/D8oG5KXIlRBQimNwsrKtYKgR5rR0VS7dbD4LEO9y4IRddFLyBiqUhlkQQ2yL3s ZbP+NRoYR5lUbgDQs3frwYS1fx9D9/NPl72+TA7jcKdbSKWctdKArCo/AwTyTTJi8e/D 6Qedjlw+gSwa8SigIX4y4mM6McP56h4OYqhw0gknepEAN1M/QG9MzdJMHLGf4mu+mozb vIXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=iXF2lvqe; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id cn7-20020a056a00340700b0068fac3509a9si2051796pfb.350.2023.09.14.13.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:09:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=iXF2lvqe; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9CD7781352A7; Thu, 14 Sep 2023 01:08:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236184AbjINIIS (ORCPT + 99 others); Thu, 14 Sep 2023 04:08:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235931AbjINIIQ (ORCPT ); Thu, 14 Sep 2023 04:08:16 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7949DF; Thu, 14 Sep 2023 01:08:12 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 84B541F74A; Thu, 14 Sep 2023 08:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1694678891; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=E/ecNnDz5zq7YMrO/wGOI+Yrvu8MsC3RqtEZg7CpzAM=; b=iXF2lvqeeTY41pqwpGIemAJn92B8uB5HcwimMF79k17rki4IDOuG1/fmhxDgQ3kC61Bp+x yxyEUd5bebZABOd1QmuX0W2vqETPHVFlnso1SBeRTQ3ApaSYDX1pbLbTa/BKf3mAqIvwUI v+BIRzsZwQeJMjS/Q01Pr60A6dWISbI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1694678891; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=E/ecNnDz5zq7YMrO/wGOI+Yrvu8MsC3RqtEZg7CpzAM=; b=Fv6WEmj+HG5HKo9vjKsLPyeE94ke481HEVXYKrauseWBxcq4Ov02zl13ywJRyZL6ZLfhaG IuFuzeoj2CZPnlCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 72EB813580; Thu, 14 Sep 2023 08:08:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 1nsCHGu/AmVpIQAAMHmgww (envelope-from ); Thu, 14 Sep 2023 08:08:11 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 0D158A07C2; Thu, 14 Sep 2023 10:08:11 +0200 (CEST) Date: Thu, 14 Sep 2023 10:08:11 +0200 From: Jan Kara To: Matthew Wilcox Cc: Mirsad Todorovac , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: Re: [BUG] KCSAN: data-race in xas_clear_mark / xas_find_marked Message-ID: <20230914080811.465zw662sus4uznq@quack3> References: <06645d2b-a964-1c4c-15cf-42ccc6c6e19b@alu.unizg.hr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 01:08:17 -0700 (PDT) On Fri 18-08-23 13:21:17, Matthew Wilcox wrote: > On Fri, Aug 18, 2023 at 10:01:32AM +0200, Mirsad Todorovac wrote: > > [ 206.510010] ================================================================== > > [ 206.510035] BUG: KCSAN: data-race in xas_clear_mark / xas_find_marked > > > > [ 206.510067] write to 0xffff963df6a90fe0 of 8 bytes by interrupt on cpu 22: > > [ 206.510081] xas_clear_mark+0xd5/0x180 > > [ 206.510097] __xa_clear_mark+0xd1/0x100 > > [ 206.510114] __folio_end_writeback+0x293/0x5a0 > > [ 206.520722] read to 0xffff963df6a90fe0 of 8 bytes by task 2793 on cpu 6: > > [ 206.520735] xas_find_marked+0xe5/0x600 > > [ 206.520750] filemap_get_folios_tag+0xf9/0x3d0 > Also, before submitting this kind of report, you should run the > trace through scripts/decode_stacktrace.sh to give us line numbers > instead of hex offsets, which are useless to anyone who doesn't have > your exact kernel build. > > > [ 206.510010] ================================================================== > > [ 206.510035] BUG: KCSAN: data-race in xas_clear_mark / xas_find_marked > > > > [ 206.510067] write to 0xffff963df6a90fe0 of 8 bytes by interrupt on cpu 22: > > [ 206.510081] xas_clear_mark (./arch/x86/include/asm/bitops.h:178 ./include/asm-generic/bitops/instrumented-non-atomic.h:115 lib/xarray.c:102 lib/xarray.c:914) > > [ 206.510097] __xa_clear_mark (lib/xarray.c:1923) > > [ 206.510114] __folio_end_writeback (mm/page-writeback.c:2981) > > This path is properly using xa_lock_irqsave() before calling > __xa_clear_mark(). > > > [ 206.520722] read to 0xffff963df6a90fe0 of 8 bytes by task 2793 on cpu 6: > > [ 206.520735] xas_find_marked (./include/linux/xarray.h:1706 lib/xarray.c:1354) > > [ 206.520750] filemap_get_folios_tag (mm/filemap.c:1975 mm/filemap.c:2273) > > This takes the RCU read lock before calling xas_find_marked() as it's > supposed to. > > What garbage do I have to write to tell KCSAN it's wrong? The line > that's probably triggering it is currently: > > unsigned long data = *addr & (~0UL << offset); I don't think it is actually wrong in this case. You're accessing xarray only with RCU protection so it can be changing under your hands. For example the code in xas_find_chunk(): unsigned long data = *addr & (~0UL << offset); if (data) return __ffs(data); is prone to the compiler refetching 'data' from *addr after checking for data != 0 and getting 0 the second time which would trigger undefined behavior of __ffs(). So that code should definitely use READ_ONCE() to make things safe. BTW, find_next_bit() seems to need a similar treatment and in fact I'm not sure why xas_find_chunk() has a special case for XA_CHUNK_SIZE == BITS_PER_LONG because find_next_bit() checks for that and handles that in a fast path in the same way. Honza -- Jan Kara SUSE Labs, CR