From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E25C3C6FA8F for ; Wed, 30 Aug 2023 11:44:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 79AA1280053; Wed, 30 Aug 2023 07:44:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74A5A28002F; Wed, 30 Aug 2023 07:44:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61294280053; Wed, 30 Aug 2023 07:44:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5137E28002F for ; Wed, 30 Aug 2023 07:44:09 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1ECE2140432 for ; Wed, 30 Aug 2023 11:44:09 +0000 (UTC) X-FDA: 81180587418.25.451B6E8 Received: from domac.alu.hr (domac.alu.unizg.hr [161.53.235.3]) by imf17.hostedemail.com (Postfix) with ESMTP id 8D1F740018 for ; Wed, 30 Aug 2023 11:44:06 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=alu.unizg.hr header.s=mail header.b=FyoJGKJ9; dkim=pass header.d=alu.unizg.hr header.s=mail header.b=SeNisTkO; spf=pass (imf17.hostedemail.com: domain of mirsad.todorovac@alu.unizg.hr designates 161.53.235.3 as permitted sender) smtp.mailfrom=mirsad.todorovac@alu.unizg.hr; dmarc=pass (policy=none) header.from=alu.unizg.hr ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693395847; h=from:from:sender: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:dkim-signature; bh=D+SKLSjIrUhG/yJzuQsudNvw4yLrUmJcnc14uQ2TabQ=; b=27jgZE0cQQ3rL2QPtZFni03pMm2157XUQwMydanFM44kCSiMg6xU77AG/XT+gxG+glqcO+ Yu/T6nSRKWhCbJ/I3QwpVClWO4asVOUuW+YmCnI8M0U1IwKB0Wiv9gTfoRV0eLn0jv5/H8 UFoR1JnUoApOacpLsdYZb497XZW63S0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693395847; a=rsa-sha256; cv=none; b=O7YNugFy1m3YbgkFqJ/KSgM/qzkryxGMxvroAEzorCLoCknJBKmGz33y6D/0EjABpjy86Y 0OSjYw8M0TegnY6I1uA14+mu6yVPzDtYtlEpiVSx4CidQIyttR91AkfW4eZR1Slz4hXvL+ RtJzzzZQSQPnhvh1uJaWscZxM1609Wc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=alu.unizg.hr header.s=mail header.b=FyoJGKJ9; dkim=pass header.d=alu.unizg.hr header.s=mail header.b=SeNisTkO; spf=pass (imf17.hostedemail.com: domain of mirsad.todorovac@alu.unizg.hr designates 161.53.235.3 as permitted sender) smtp.mailfrom=mirsad.todorovac@alu.unizg.hr; dmarc=pass (policy=none) header.from=alu.unizg.hr Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id 99CBC60177; Wed, 30 Aug 2023 13:44:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1693395843; bh=tEdH1idTYBbHaHmPL3gnS486jO30KAsWxS0zmHdrN0A=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=FyoJGKJ98vdSLyMjbWGqlJo4Sei/CTW2K7E1I4n8MneRzZWZaejnuhVYHd4ai5Nf4 Lo5t+rZ30+GBkWPZxe5G2AilVl7vqeWhO1BVpa0lyBZa9LwKLcQ7XjGNqg76KW6+LI MhHTnBo6J2lAftRyaPoXRLlOrNtpd0TPZzWox9oQsIdPMRGR8n0KgFXAv+UqaCJZHK Um98QnPPANf3NGEZrv0C3iNUMoeQEqF8YpQR1JZi2LeQBa3llHA7Vcnv2AKUk1hQcP levF8P//WDxAiXsYDO4IHTwg3AK7dV1CilVnIUiQuMCpHCnnkXvQx4Qq3W9JQTboGk uXabybBcfJQuA== X-Virus-Scanned: Debian amavisd-new at domac.alu.hr Received: from domac.alu.hr ([127.0.0.1]) by localhost (domac.alu.hr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Am_AuITKUZps; Wed, 30 Aug 2023 13:44:00 +0200 (CEST) Received: from [193.198.186.200] (pc-mtodorov.slava.alu.hr [193.198.186.200]) by domac.alu.hr (Postfix) with ESMTPSA id 22CA060173; Wed, 30 Aug 2023 13:43:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1693395840; bh=tEdH1idTYBbHaHmPL3gnS486jO30KAsWxS0zmHdrN0A=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=SeNisTkOyy3GlhutJ3fqlMq8IByeHD1bRuJ9C81CbagGMDLccOSpyOePAWzqWvi6E 6FOe+IitTIs/6zypyQIbL9iyeqHw2zd5D/IJXoNk3QwJhWHCN7E2phI65I745cUUoM 9eHZ87sHVuMAT1hEMM6jJ55/cWGxGytn8uMlfU818OhKun/eroO/lkrJDmhk30/xRX 1bd1ccsyLzxVeYn+v6jl/W8OdKa7pYAks1N8d5Cj4l9woZqYFn0wsgBD7lPrM3jEKk N9VHxD90Beoe2WMRo1o/FyDfIxYo2keA20sn28uDLAwJ1MNmt9nv2YyNz9vAktPDfF lxs4kSf8rjm9Q== Message-ID: <5f60813c-c52b-5c08-27c7-490b7d28c598@alu.unizg.hr> Date: Wed, 30 Aug 2023 13:43:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: BUG: KCSAN: data-race in folio_batch_move_lru / mpage_read_end_io To: Matthew Wilcox Cc: linux-kernel@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org References: Content-Language: en-US, hr From: Mirsad Todorovac In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8D1F740018 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: c8i691r3nykcfppky6hyfd134njaobn1 X-HE-Tag: 1693395846-857087 X-HE-Meta: U2FsdGVkX1+tBW7qWV9rKsb4MsObFwafxrocx278yy8ppXs9E5EahVJ2TcKJYFDzZj4ezprN3Nzt2BQCoROQ0+ynaGM5xcPiBsygSLKtsKU7CCkgXN2gDKLSaW1U3U60mphX15Ydav3NCf9fLj7xZJogd23Ao9gLmbZJY04eafIwl6xegk4e+XuybVUCjnXxPILJD7REBUPFa8vDH5MIxjnecJIIDkMXU48Z1IKoyGllrc0IgrfbLBr3A94ARoENE7/LeSKmtuVWE+V/AZ1Jh7+x3nfkuYGXjuZDTaCb9j/W6CNyrVP5MfU4yJe31ftH/di2u0eWg4PWiBAu730YJfl/pmzMqphkyEqD3q+QAd75g8GysAdmmquTh3HCd4730BcMP47bY+uUXXRAxZqwLfsfSW9Ptawt9+7yADUhcUAduoQu1/BHXrG9noijkN4dKw1Nui8JrRVjNpyDUDLQxo69CautJMbEK/CYfEHNPx3oifaFJfnDE9wcEXb/k+rEvjZ6zyTA9LykqFhooYcqVOW3zuFRFporXpK3NZxIcvyeeF4bBMJyWXoCyOUb/cz7+6KDkGefPY2YUkRGCJ/3VoSnxlsS6CDUIJ+fWam+9bofdM+eqk6iXoCSa95d2Vfj+sZeWGxonhCEmA54FNGQ/szNIA/p1a3KSYyyeLZrcK0MJM8E9HdwLAOIzM6i4LR3ie+oMCfFL2/sym0Hdff7xQWQl9qJoMahwAUHNlRrBRYuxIpUCtsE5tO20iFYVBEswLEsQAFlhp+Pglku+oyG0V+E/D2GVDpE/h1dybHWSesDMLqpfqnFyum0xYIbEzV5VTF/gxzkt8OgV5qvxTXxBEZEQxqQS7b5zvHFFWk+YbPq6WY/xAVNIfOxuRgpJMpT/7Lml21T0ttX305ped41VSRWBiVVq3fZExjrrLXTeTc08unFQOiCJdJx2X5cKrfRr+4+6ikOJyF5U+5F3Bc Oe4C7e+e nbu+lv+uo5aAoI62Ml7UaVk4abGpaKnW9othYcmz0VUaTlK7XbqIL0sUftaiY3Y6Xuj40UzhBEwCIDlb+eK4PcAXddgpGhQWxbVAv+piERA+Q6isfdgjK7dyA3VYlKsd5CYE3zigjsZvzgqRzUAGkax0gsG5InQ0IQK5O16F4BLxSWWaBIxQxUL05CJk9zQuO3fJriVMPip990AtCLysPEhbf3S9wFRpX/oaW X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi, Mr. Matthew, On 8/29/23 21:13, Matthew Wilcox wrote: > On Mon, Aug 28, 2023 at 11:14:23PM +0200, Mirsad Todorovac wrote: >> In the vanilla torvalds tree 6.5 kernel on the Ubuntu 22.04 system, KCSAN found another data race: > > KCSAN is wrong. Thank you for evaluating this bug report to such a detail. Well, I ain't giving up on KCSAN anyway, because it found some real life data races. To express it more graphically, it is very unpleasant when the other core changes the data from underneath you or it magically and unexpectedly changes in the course of some work ... :-( >> [ 34.102069] write (marked) to 0xffffef9a44978bc0 of 8 bytes by interrupt on cpu 28: >> [ 34.108569] mpage_read_end_io (/home/marvin/linux/kernel/linux_torvalds/./arch/x86/include/asm/bitops.h:55 /home/marvin/linux/kernel/linux_torvalds/./include/asm-generic/bitops/instrumented-atomic.h:29 /home/marvin/linux/kernel/linux_torvalds/./include/linux/page-flags.h:739 /home/marvin/linux/kernel/linux_torvalds/fs/mpage.c:55) > > bio_for_each_folio_all(fi, bio) { > if (err) > folio_set_error(fi.folio); > else > folio_mark_uptodate(fi.folio); > folio_unlock(fi.folio); > } > It's noting the write to folio->flags in folio_mark_uptodate(). You can > see it's locked. Also, the folio is under I/O. Yes, from folio_unlock(fi.folio), it appears that somewhere it was locked. But finding where it was locked is beyond my understanding ATM. I see folio_put() in other places, but it seems to increase refcount only, I did not where it is locked, but this is probably just me ... >> [ 34.115221] read to 0xffffef9a44978bc0 of 8 bytes by task 348 on cpu 12: >> [ 34.121702] folio_batch_move_lru (/home/marvin/linux/kernel/linux_torvalds/./include/linux/mm.h:1814 /home/marvin/linux/kernel/linux_torvalds/./include/linux/mm.h:1824 /home/marvin/linux/kernel/linux_torvalds/./include/linux/memcontrol.h:1636 /home/marvin/linux/kernel/linux_torvalds/./include/linux/memcontrol.h:1659 /home/marvin/linux/kernel/linux_torvalds/mm/swap.c:216) > > Here, it's noting the read to folio->flags that's part of page_to_nid(). > >> [ 34.121713] folio_batch_add_and_move (/home/marvin/linux/kernel/linux_torvalds/mm/swap.c:235) >> [ 34.121724] folio_add_lru (/home/marvin/linux/kernel/linux_torvalds/./arch/x86/include/asm/preempt.h:95 /home/marvin/linux/kernel/linux_torvalds/mm/swap.c:518) >> [ 34.121735] folio_add_lru_vma (/home/marvin/linux/kernel/linux_torvalds/mm/swap.c:538) >> [ 34.121746] do_anonymous_page (/home/marvin/linux/kernel/linux_torvalds/mm/memory.c:4146) > > Here we can see the page is freshly allocated. > > So KCSAN has three things wrong here. One is that the write to > folio_mark_uptodate() is setting a bit, that is nowhere near the bits > that are used for the node ID. It can't know that; it doesn't track > writes at that granularity. > > The second thing is that the node bits in folio->flags are immutable. > They're set at boot (or memory hotplug). There is never a race risk when > reading them. Presumably there needs to be some kind of annotation to > tell KCSAN that this is always safe. > > The third thing is that these two accesses cannot race. The write is > to a folio which is under I/O, so cannot be freed. The read is to a > folio which has just been allocated, so cannot be under I/O. This is > some kind of failure of KCSAN. Based on your insight, I will assume that the bug report is resolved. Thank you again for your time. Best regards, Mirsad Todorovac -- Mirsad Todorovac Sistem inženjer Grafički fakultet | Akademija likovnih umjetnosti Sveučilište u Zagrebu System engineer Faculty of Graphic Arts | Academy of Fine Arts University of Zagreb, Republic of Croatia