Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2017190pxm; Thu, 24 Feb 2022 14:23:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwutzRDBClGoh3TQZ+xvq0bh/zXMOpPxa2n5kEV4dubYYb3Zo8ttxe3lFO9lQYDp6m1zJGh X-Received: by 2002:a17:906:2695:b0:6ce:f9c:b476 with SMTP id t21-20020a170906269500b006ce0f9cb476mr4028235ejc.235.1645741419347; Thu, 24 Feb 2022 14:23:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645741419; cv=none; d=google.com; s=arc-20160816; b=X1E3UNtu5PER7SoV97G1+CU94m6jvjnrPXiJB3TJ7UoWn2kVBTon4mNzYarYNR6Ikp Huz55tFQ6Wo4i6z8ZN2RGQQjOixr8fkPxviYR+JlZy2rxKuPrgi71JFzk1w5BKkOoc3n Sw60fOIT52ggAoZOl3b2CNPcMx7vyYKvUcYD5a7j4t8dG5AcokAGaPPqxMDEuo8ycjIu mapKZQ0c+HLvuQHphg+YxvDm/iUlWgYZTBY2IiWXLqBkQ2YYPvZI9+d6C+M3OyaUIrBV /20MnDpPTGDP42K6hFC69azR5HLhxORXD3UdgmrnE22r8IxlMQ44WSCGvDUk349WXrjm vyiQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=VIoQPvwHqFXtMAXE8AKCkLiEbpc0ZIKiqGrsuvIzD+s=; b=FvKD/UjT2b9qmvhm5I9Y3JDv93V0jJgjXvNYjCzAD16KHp0qiIliTV4RbkB8PqzhMy +DXQKCiWNiStybbrf6PJ589P/3GbVQ4CWdRSSIPeDcjbY6UtOyD2947Au4s97mcJ565Y U5YSbA3Pxw0mZQ1EFsP497zFhMdQlXj3jq6C9yvL8l+cOBfDU5qzyd9M6ARI+6duBIiN 7RNK9VzzAl1F/LT2NRBAq6DhDXS85aITOY16wSo3+aqvi6hpz9aszB/t6KUNuFNumtOJ stqGoecy1btFQhM6O+k9JcmxSh7+TvmmLDtOvtH8Nlqdrvxqaj+7rN92fzgCaBXU3f6A 801w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20210112.gappssmtp.com header.s=20210112 header.b=tk7jCJjg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u17-20020aa7db91000000b00413041cd90esi539521edt.315.2022.02.24.14.23.14; Thu, 24 Feb 2022 14:23:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@osandov-com.20210112.gappssmtp.com header.s=20210112 header.b=tk7jCJjg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234300AbiBXUTI (ORCPT + 99 others); Thu, 24 Feb 2022 15:19:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234298AbiBXURq (ORCPT ); Thu, 24 Feb 2022 15:17:46 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DAF077ABD for ; Thu, 24 Feb 2022 12:17:14 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id gl14-20020a17090b120e00b001bc2182c3d5so6105040pjb.1 for ; Thu, 24 Feb 2022 12:17:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=VIoQPvwHqFXtMAXE8AKCkLiEbpc0ZIKiqGrsuvIzD+s=; b=tk7jCJjg1+CUdYaHqNbciARDK8dfm6TepRBLjhUKgQM0CtIrgyTuICuE2Lsn723Gza EXY0qT0hPfDJOuJd/GR0VFQJEcGxj0+VMw8UR9vZJXJ8VIgdAl0cWtet7MraYRn1nCjM rdkvFjsQepqXyglMqp5mXi23JrdltsqogRns4pkN6ZxgE5WitpE+XPlGEHq+u4eIsjnD q6kwVNfqxe3a9xRgdJzR6AOV7qGWFjMwbBiADU0lDjxg6XDS43DZ9KPOo/nOMgLIwJvB +xohKsi/b9O1GaQh1BwCseDhIdkcFhF5vNPr/ySGWV9ynd4hlz/RDBManBb9jcHE42t9 l5XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=VIoQPvwHqFXtMAXE8AKCkLiEbpc0ZIKiqGrsuvIzD+s=; b=uGS5J+wPa4w3WVYJWEG/14xdFBOjSb3NW/BndwC4BfleICMxC2zfjp0QZxxKG+eGm9 IQVnR4OLrvdWlYkYHV+zcLg5MGHH6QTE7HhCqQsxkHca2P/BbOFMAx1oNnZ2ZCznm8yi D5vVaPRti1YXyAobySYWg17Ad8szNSGjylje2Nc0atLs/Iht9UQDsToMEwYx2e5pRHco bIrh1PM/jMUwfL9U2vX/ev8/iMjzJ0zhWgRRTTVpXB2AyOpXGdvpvnbp4EYCj5H7nNv5 S3yvnFu+yRXsRkTgQRYUJbBksO9H2Bl+iubX6TcN4FLtWvCPBgXWJkoAqGRhxOxwjcoo ACRA== X-Gm-Message-State: AOAM533tABugkW2G92taoJ1qBEofhsxuzz8R81njOQygHTr1uQGoyK1b W1zF+1dE9+HXNB7VFI3/nOVnTg== X-Received: by 2002:a17:902:8f96:b0:14e:bd3c:149b with SMTP id z22-20020a1709028f9600b0014ebd3c149bmr4259267plo.172.1645733833457; Thu, 24 Feb 2022 12:17:13 -0800 (PST) Received: from relinquished.localdomain ([2620:10d:c090:400::5:64b1]) by smtp.gmail.com with ESMTPSA id lb4-20020a17090b4a4400b001b9b20eabc4sm181429pjb.5.2022.02.24.12.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 12:17:13 -0800 (PST) Date: Thu, 24 Feb 2022 12:17:11 -0800 From: Omar Sandoval To: Sweet Tea Dorminy Cc: dsterba@suse.cz, Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH v4] btrfs: add fs state details to error messages. Message-ID: References: <20220224132210.GS12643@twin.jikos.cz> <284ccc08-8de7-9188-19d8-20f4eda56cb4@dorminy.me> <20220224184231.GZ12643@twin.jikos.cz> <20f14d85-6a07-e66d-4711-c16c6930c2a3@dorminy.me> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20f14d85-6a07-e66d-4711-c16c6930c2a3@dorminy.me> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 24, 2022 at 03:09:08PM -0500, Sweet Tea Dorminy wrote: > > > All the other interactions with info->fs_state are test/set/clear_bit, > > > which treat the argument as volatile and are therefore safe to do from > > > multiple threads. Without the READ_ONCE (reading it as a volatile), > > > the compiler or cpu could turn the reads of info->fs_state in > > > for_each_set_bit() into writes of random stuff into info->fs_state, > > > potentially clearing the state bits or filling them with garbage. > > I'm not sure I'm missing something, but I find the above hard to > > believe. Concurrent access to a variable from multiple threads may not > > produce consistent results, but random writes should not happen when > > we're just reading. > > Maybe I've been reading too many articles about the things compilers are > technically allowed to do. But as per the following link, the C standard > does permit compilers?inventing writes except to atomics and volatiles: > https://lwn.net/Articles/793253/#Invented%20Stores > > > > > > Even if this is right, it'd be rare, but it would be exceeding weird > > > for a message to be logged listing an error and then future messages > > > be logged without any such state, or with a random collection of > > > garbage states. > > How would that happen? The volatile keyword is only a compiler hint not > > to do optimizations on the variable, what actually happens on the CPU > > level depends if the instruction is locked or not, so different threads > > may read different bits. > > You seem to imply that once a variable is not used with volatile > > semantics, even just for read, the result could lead to random writes > > because it's otherwise undefined. > > Pretty much; once a variable is read without READ_ONCE, it's unsafe to write > a new value on another thread that depends on the old value. Imagine a > compiler which invents stores; then if you are both reading and setting a > variable 'a' on different threads, the following could happen: > > thread 1 (reads) ? ??? thread 2 (modifies) > > reads a into tmp > > stores junk into a > > ??? ??? ??? ??? ??? ??? ??? ??? reads junk from a > > stores tmp into a > > ??? ??? ??? ??? ??? ??? ??? ??? writes junk | 2 to a > > > Now a contains junk indefinitely. > > > But if it's too theoretical, I'm happy to drop it and amend my paranoia > level. I agree with Sweet Tea here. Even if it's very theoretical, it costs us nothing to do the "correct" thing here.