Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5863561rwb; Tue, 17 Jan 2023 20:35:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXvb2iVxAg7u4NFdWuXA4blVIvadYpAqTYcGWUeVXM3QtI7cSAo7pX5LERaJ+GYYs7HT68fM X-Received: by 2002:a17:907:76e1:b0:7c0:e7a8:bc41 with SMTP id kg1-20020a17090776e100b007c0e7a8bc41mr19564714ejc.74.1674016518294; Tue, 17 Jan 2023 20:35:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674016518; cv=none; d=google.com; s=arc-20160816; b=aoRdrxIIXP92I6kGm640HJ3/EZNBc/6Oc3CvSQPSS98sDUWgF+nDC381gU8SdJ5c1B qoa4tR6aO5bD1OUXzLMcYI/nUFDt+p9kfdZvns09jWbPeU4CGR6mTLh2WySDCwg3NW5H y3sfuvwFJddjt1s9DK6gukjf0fBgZFgxA90MJnIXxdENQJjSE1DtaTJ0wt8gskzWGNLr sT5fg836tG47zHmELosOcs0MpI0KIBole10lLnSiwI9GLKfX+vgrytyd7FfnVtm5BB3Z 3pVxEz+OU+vGBrQ7al2bKkk3UwB0NmL2DjgiO+tjBA7waMPYrqiY4fudwwgCYfXT+A+i hDxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qAth6cUkdo5cj913OjjogBmB6+0SV0aQJTrezUW/6nA=; b=sPE/3vojFqSqAfLxodVMLyEn98D1dOaED5yMVFZksQlb02k9kNH6xXyF86fGmpEmzK N3wkCOEkB1QLUJ+Zy4h8jhQlYqKTXG/kMOONwXaWYkp1nkVXMmjf5wYs61ktjs4OwNJN kjaqAbKy4MpnUzdIZEGOiQkq2S7B1jPSPdF08oxXQJTsJvIaotZ9EfHXuK//kpJInt02 A3YD6YwM5rR78THdINmI577lqXCiOewlal+3mwA9AsZpHriQNftp03G8D078j+Y0IEfc TMCpG8HnFyB6xyNxbZCRD5OYCE1AFvfYatgGNz0vx5DtGYqdQlJkJooENd+1VAt0wmtw +5uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=XloxRaFo; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 dn18-20020a17090794d200b008775625ced7si1451133ejc.611.2023.01.17.20.34.53; Tue, 17 Jan 2023 20:35:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=@linux-foundation.org header.s=google header.b=XloxRaFo; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229511AbjARE1o (ORCPT + 99 others); Tue, 17 Jan 2023 23:27:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjARE1n (ORCPT ); Tue, 17 Jan 2023 23:27:43 -0500 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71498196BC for ; Tue, 17 Jan 2023 20:27:41 -0800 (PST) Received: by mail-qv1-xf31.google.com with SMTP id i12so23090430qvs.2 for ; Tue, 17 Jan 2023 20:27:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=qAth6cUkdo5cj913OjjogBmB6+0SV0aQJTrezUW/6nA=; b=XloxRaFo8tA83mEkCX4VnQb/z4BWFnCM30wQV53IsBml75NKFmne2+Kk2kUYoZyxTg 9WgtMS5wo0xkSvmnQJXEh6v2cqr7/MyNg6Raj8CIeLBJraQoWQdvksF/r2V1lsuhd8bf AHEnNo9axQaqsf0D3Wt9UbMtPmSYruOM35MuE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qAth6cUkdo5cj913OjjogBmB6+0SV0aQJTrezUW/6nA=; b=RCGS7UMebY6LsiywgCJGBSfxi5SV9uyZK1l71LftdjutZf2FRnUGB7aDTGrpWW4IjH XsqyGYiUvi6W+BLnOrhkUbfg+jxxDWb0GfYcEnpEEiVF0HZAGcRCzyIeVVTB8lC5LUPN bEFxVZawp0zaKppUfgBO03FHB4zXtNCtjgzBWSxmKp+W+v+NpDj/A7lyQxpIaybgQ8Lr bcMKZrCoRFupGySuTrUojwYWt86b5Ku2XiJ/c1PGJw90erjl94/agvSXFQG0FaT7Kx/l jlWR+/GW7r1VQE/AFCOnhoicuBhOTvBrLOV+X3K2J4coNN/1jeztUrphxLfCsIfDk9Ry JkkQ== X-Gm-Message-State: AFqh2ko48LLhEPiMByJWW/GwQN/pDSCLova8GXCzPyGTOhPQH+L30sVw 9B3WeMW0BViVL2pLbRwgJleIyZ9M61l6kXa7 X-Received: by 2002:a05:6214:3185:b0:532:32b7:b7e4 with SMTP id lb5-20020a056214318500b0053232b7b7e4mr8130414qvb.29.1674016060258; Tue, 17 Jan 2023 20:27:40 -0800 (PST) Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com. [209.85.222.169]) by smtp.gmail.com with ESMTPSA id q13-20020a37f70d000000b006f9ddaaf01esm5651875qkj.102.2023.01.17.20.27.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 20:27:39 -0800 (PST) Received: by mail-qk1-f169.google.com with SMTP id l1so17279417qkg.11 for ; Tue, 17 Jan 2023 20:27:39 -0800 (PST) X-Received: by 2002:a05:620a:99d:b0:705:efa8:524c with SMTP id x29-20020a05620a099d00b00705efa8524cmr273401qkx.594.1674016059391; Tue, 17 Jan 2023 20:27:39 -0800 (PST) MIME-Version: 1.0 References: <7DE6598D-B60D-466F-8771-5FEC0FDEC57F@dilger.ca> In-Reply-To: From: Linus Torvalds Date: Tue, 17 Jan 2023 20:27:23 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Detecting default signedness of char in ext4 (despite -funsigned-char) To: Eric Biggers Cc: Ext4 Developers List , Andreas Dilger , Eric Whitney , "Jason A. Donenfeld" , Masahiro Yamada Content-Type: multipart/mixed; boundary="00000000000091ddf705f2823c4d" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no 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-ext4@vger.kernel.org --00000000000091ddf705f2823c4d Content-Type: text/plain; charset="UTF-8" On Tue, Jan 17, 2023 at 7:56 PM Eric Biggers wrote: > > [Added some Cc's, and updated subject to reflect what this is really about] Hmm. I really hate this. > On Tue, Jan 17, 2023 at 05:10:55PM -0700, Andreas Dilger wrote: > > > > > > My 6.2-rc1 regression run on the current x86-64 test appliance revealed a new > > > failure for generic/454 on the 4k file system configuration and all other > > > configurations using a 4k block size. This failure reproduces with 100% > > > reliability and continues to appear as of 6.2-rc4. > > > > > > The test output indicates that the file system under test is inconsistent. > > > > There is actually support in the superblock for both signed and unsigned char > > hash calculations, exactly because there was a bug like this in the past. > > It looks like the ext4 code/build is still using the signed hash functions: So clearly ext4 is completely buggy in this respect, but this is exactly what would happen if you just mount a disk that was written to on (old, pre-funsigned-char) x86, and then mount it on, say, an arm machine that has always been unsigned-char. That was always supposed to work. So switching to a new kernel really should just be *exactly* the same as moving the disk to a different machine. And that's still "supposed to just work". And this whole "let's get it wrong, and make x86 act as if 'char' is signed, even when it isn't" seems entirely the wrong way around. So the bug here is that __ext4_fill_super() seems to not look at the actual on-disk thing, but instead do > > static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) > > { ... > > else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) { > > #ifdef __CHAR_UNSIGNED__ but at the same time this code is *exactly* the code that is trying to deal with "oh, you moved the disk from a signed architecture to an unsigned one". So the above code is literally what should fix up that movement - taking the *actual* new signedness (or lack thereof, in this case) into account. Now, it apparently doesn't work very well, and I suspect the reason it doesn't work is that the xattr code doesn't actually test these EXT2_FLAGS_SIGNED_HASH bits (and the s_hash_unsigned field value that goes along with it). But we should *fix* that. Instead, the patch is self-admittedly very ugly: > Below is one very ugly solution. It seems to work [..] but I really don't think it works. It just perpetuates the bug that you can't move a filesystem from one architecture to another. So I really think that the solution is either (a) just admit that ext4 was buggy, and say "char is now unsigned", and know that generic/454 will fail when you switch from a buggy kernel to a new one that no longer has this signedness bug. (b) fix ext4_xattr_hash_entry() to actually see "oh, this filesystem was created with signed chars, and so we'll use that algorithm even though our chars are always unsigned". Honestly, the only actual case of breakage I have heard of is that test, so I was hoping that (a) is simply the acceptable and simplest solution. It basically says "nobody really cares, we're now always unsigned, real people didn't use non-ASCII xattr names". Anyway, here's a TOTALLY UNTESTED patch to do (b). Maybe it's entirely broken, but I think you can see what I'm aiming for. Comments? Linus --00000000000091ddf705f2823c4d Content-Type: text/x-patch; charset="US-ASCII"; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-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