Message ID | 80bae984fd5ca49b691bb35f2fd8f345f8bb67f1.1682405206.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3214403vqo; Mon, 24 Apr 2023 23:55:45 -0700 (PDT) X-Google-Smtp-Source: AKy350bFQJ/xxu/WDvPUPF5qqH4aBwGceztf1Z9Zo2Tfrf9lomz5bBEnXWw0+Rn8LIPCi2dWsRT1 X-Received: by 2002:a17:902:f7d6:b0:19e:2fb0:a5d9 with SMTP id h22-20020a170902f7d600b0019e2fb0a5d9mr17941902plw.32.1682405745385; Mon, 24 Apr 2023 23:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682405745; cv=none; d=google.com; s=arc-20160816; b=wq2+9Ew/ZNo5xc3e6Y5lh7V2gl9bC0Y8rf32KSPmp+RvE9wLhEccuZbs02ANonVPys lahfopnTW2byz69F573nv6cmB+rdgAMW/5YHlV3pRc5FjvMzp2JrsBP++K8t2jkwCYZE XPa8ms4NQDqBxk86Vw2ERk95hROaYxDb94lKOws/yXWVMYSxicgEzyX2C7ZJ53gQfqaF tM+/WS5iNvPS4/YovGLgMcFJ6H3OOzgs3hWZvFW4QMRwbHhkhKfAW8x43MAsYi6f8FPt c1eePnr75Xj9CDu4ILH7C+PRW0yygL1F4bh4qPxVOsx6LbOg/43IDAnLQGOQmu7jWvBn GNdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xSNUhNscxEqVyr5Wkr8JJ5bNbQGHTG7dlAH1ZVdGGxI=; b=J97wA8LFZl9/Zz09tE7t6bF0hokCTLAOW0XaopJnzhPzctehfRMZ77UCC1JIc22D/w SN5X6T6679DApUIPG33gSzvlAguIlkbshAvi4e06U8jk4gaWadO2Va6rb7175voUVjyg I0CoFa/Ey20yzahPsnZiFOpvC3KFmAWzKrA1IkftRvX3r2BGERkBCuF2oAoOjItoRjZQ 2mZbumrrWQjrJ2aoOLcfv7aikwY3MMZx2VFQ6RBcrmGMhsMWWIwpk2bYpmtjhEf/hcFa gQKPchg1FMJ3Ff1YHmrLUkl/t2M1Ex0VJRwtksTAWd0QkdLPJH65waTIv1y05B39WjEv hN3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Nw6mZSkY; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s190-20020a632cc7000000b00524d6d0a4acsi10949661pgs.654.2023.04.24.23.55.30; Mon, 24 Apr 2023 23:55:45 -0700 (PDT) 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=@wanadoo.fr header.s=t20230301 header.b=Nw6mZSkY; 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 S233255AbjDYGrh (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Tue, 25 Apr 2023 02:47:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232617AbjDYGrf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Apr 2023 02:47:35 -0400 Received: from smtp.smtpout.orange.fr (smtp-28.smtpout.orange.fr [80.12.242.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46D4130CF for <linux-kernel@vger.kernel.org>; Mon, 24 Apr 2023 23:47:33 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id rCSWpcq9sDWp7rCSXpOke8; Tue, 25 Apr 2023 08:47:31 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1682405251; bh=xSNUhNscxEqVyr5Wkr8JJ5bNbQGHTG7dlAH1ZVdGGxI=; h=From:To:Cc:Subject:Date; b=Nw6mZSkYmqbR8DzTe0qATHJxdNCoJ2gaAENwPMxB70pbs2cD4zwXyPJC+RhvtWI8M jJ1yeE5sYoUUQP8rAZmfYjMpJMcHavsiDcGRNdJ1J8yGVRq6k7SqJPfFAO6+ZmAgi1 1KuRbXiH+JkmNeZpp5pzShHo5lhGnW7FqFpUlBnPX6TUALps2hNzPRYLdJtFR8FSta jOlXI3E4EL9JIU6OlPcbO9T9rk3N8WraSZeVZQniIcen58IO3fFzAvJFCR0pyZpTZI QDOWvg0AJliSCA3NB5SlKQ1G1J8onJmmePwqFgOV2RYJyDIXXe2TqefrAEMGIo+M6F gfwiaFfcU01Jg== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 25 Apr 2023 08:47:31 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: Eric Van Hensbergen <ericvh@kernel.org>, Latchesar Ionkov <lucho@ionkov.net>, Dominique Martinet <asmadeus@codewreck.org>, Christian Schoenebeck <linux_oss@crudebyte.com> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, v9fs@lists.linux.dev Subject: [PATCH] fs/9p: Fix a datatype used with V9FS_DIRECT_IO Date: Tue, 25 Apr 2023 08:47:27 +0200 Message-Id: <80bae984fd5ca49b691bb35f2fd8f345f8bb67f1.1682405206.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764130286776211834?= X-GMAIL-MSGID: =?utf-8?q?1764130286776211834?= |
Series |
fs/9p: Fix a datatype used with V9FS_DIRECT_IO
|
|
Commit Message
Christophe JAILLET
April 25, 2023, 6:47 a.m. UTC
The commit in Fixes has introduced some "enum p9_session_flags" values
larger than a char.
Such values are stored in "v9fs_session_info->flags" which is a char only.
Turn it into an int so that the "enum p9_session_flags" values can fit in
it.
Fixes: 6deffc8924b5 ("fs/9p: Add new mount modes")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Un-tested
---
fs/9p/v9fs.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Christophe JAILLET wrote on Tue, Apr 25, 2023 at 08:47:27AM +0200: > The commit in Fixes has introduced some "enum p9_session_flags" values > larger than a char. > Such values are stored in "v9fs_session_info->flags" which is a char only. > > Turn it into an int so that the "enum p9_session_flags" values can fit in > it. Good catch, thanks! I'm surprised W=1 doesn't catch this... and now I'm checking higher (noisy) W=, or even clang doesn't seem to print anything about e.g. 'v9ses->flags & V9FS_DIRECT_IO is never true' or other warnings I'd have expected to come up -- out of curiosity how did you find this? Would probably be interesting to run some form of the same in our automation. > Fixes: 6deffc8924b5 ("fs/9p: Add new mount modes") (Not a problem per se: but note this commit hasn't been merged yet, so using commit IDs is a bit dangerous. Might want to remark this in the free comment section so Eric pays attention to not break that when applying) > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Reviewed-by: Dominique Martinet <asmadeus@codewreck.org>
On Tuesday, April 25, 2023 9:08:39 AM CEST Dominique Martinet wrote: > Christophe JAILLET wrote on Tue, Apr 25, 2023 at 08:47:27AM +0200: > > The commit in Fixes has introduced some "enum p9_session_flags" values > > larger than a char. > > Such values are stored in "v9fs_session_info->flags" which is a char only. > > > > Turn it into an int so that the "enum p9_session_flags" values can fit in > > it. > > Good catch, thanks! Indeed! Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com> > I'm surprised W=1 doesn't catch this... and now I'm checking higher > (noisy) W=, or even clang doesn't seem to print anything about e.g. > 'v9ses->flags & V9FS_DIRECT_IO is never true' or other warnings I'd have > expected to come up -- out of curiosity how did you find this? Both gcc and clang only trigger an implicit conversion warning if the value of the expression can be evaluated at compile time (i.e. all operands are constant), then compiler realizes that the compile-time evaluated constant value is too big for the assignment destination and triggers the warning. However as soon as any variable is involved in the expression, like in this code, then the final value of the expression cannot be evaluated at compile- time. Small operands (e.g. `char` types) in the expression are auto-promoted to `int`, hence no warning at this stage, and finally you have an assignment with unknown `int` value. This could certainly be improved by carrying along the information that an expression evaluates to at least x bits at runtime (when the compiler reduces the expression). > Would probably be interesting to run some form of the same in our > automation. If there is any ATM? I als tried this issue with clang's undefined behaviour sanitizer and with the clang static analyzer. Both did not detect it. > > > Fixes: 6deffc8924b5 ("fs/9p: Add new mount modes") > > (Not a problem per se: but note this commit hasn't been merged yet, so > using commit IDs is a bit dangerous. Might want to remark this in the > free comment section so Eric pays attention to not break that when applying) > > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > > Reviewed-by: Dominique Martinet <asmadeus@codewreck.org> > >
Christian Schoenebeck wrote on Tue, Apr 25, 2023 at 11:18:37AM +0200: > > I'm surprised W=1 doesn't catch this... and now I'm checking higher > > (noisy) W=, or even clang doesn't seem to print anything about e.g. > > 'v9ses->flags & V9FS_DIRECT_IO is never true' or other warnings I'd have > > expected to come up -- out of curiosity how did you find this? > > Both gcc and clang only trigger an implicit conversion warning if the value of > the expression can be evaluated at compile time (i.e. all operands are > constant), then compiler realizes that the compile-time evaluated constant > value is too big for the assignment destination and triggers the warning. Right, `v9ses->flags = V9FS_DIRECT_IO` would have triggered it but not with `|=` -- but in this case I was also expecting the check `v9ses->flags & V9fs_DIRECT_IO` to flag something odd... But nothing seems to care; testing with this snippet: --- int foo(char x) { if (x & 0x200) return 1; return 0; } int foo2(unsigned char x) { if (x < 0) return 1; return 0; } --- gcc warns that the x < 0 is always false (clang actually doesn't, even with scan-build, I must be missing a flag?), but I didn't find anything complaining about the &. I'd expect something like coverity to perform a bit better here but it's a pain to use the "free for open source" version (... I just requested access to https://scan.coverity.com/projects/128 but I have no idea if they build next or not) Oh, well; glad Christophe noticed anyway. > > Would probably be interesting to run some form of the same in our > > automation. > > If there is any ATM? I als tried this issue with clang's undefined behaviour > sanitizer and with the clang static analyzer. Both did not detect it. There's at least the intel bot building with W=1 and warning if any new such warning pops up (and I'd like to say I check myself, but I probably forget about half the time; I looked at making W=1 default for our part of the tree but it didn't look trivial? I'll try to have another look); but I'm not aware of anyone testing with scan-build or something else that'd contact us on new defects.
On Tuesday, April 25, 2023 12:40:22 PM CEST Dominique Martinet wrote: > Christian Schoenebeck wrote on Tue, Apr 25, 2023 at 11:18:37AM +0200: > > > I'm surprised W=1 doesn't catch this... and now I'm checking higher > > > (noisy) W=, or even clang doesn't seem to print anything about e.g. > > > 'v9ses->flags & V9FS_DIRECT_IO is never true' or other warnings I'd have > > > expected to come up -- out of curiosity how did you find this? > > > > Both gcc and clang only trigger an implicit conversion warning if the value of > > the expression can be evaluated at compile time (i.e. all operands are > > constant), then compiler realizes that the compile-time evaluated constant > > value is too big for the assignment destination and triggers the warning. > > Right, `v9ses->flags = V9FS_DIRECT_IO` would have triggered it but not > with `|=` -- but in this case I was also expecting the check > `v9ses->flags & V9fs_DIRECT_IO` to flag something odd... No, because before that binary expression is "reduced" by the compiler, `v9ses->flags` is already auto-promoted from `char` to `int`. So it is effectively: INT_RVALUE BITWISE_AND INT_LITERAL And not: CHAR_LVALUE BITWISE_AND INT_LITERAL And up to this parser state that's absolutely valid. The compiler would only able to detect this issue if it would carry the information (min. used bits at runtime) along over multiple reductions, up to the parser state where it eventually reduces the assignment, which is apparently not implemented ATM. I am however more suprised that neither clang's sanitizer, nor static analyzer detect this issue either. > But nothing seems to care; testing with this snippet: > --- > int foo(char x) { > if (x & 0x200) > return 1; > return 0; > } > int foo2(unsigned char x) { > if (x < 0) > return 1; > return 0; > } > --- > gcc warns that the x < 0 is always false (clang actually doesn't, even > with scan-build, I must be missing a flag?), but I didn't find anything > complaining about the &. -Wtype-limits (or specifically -Wtautological-unsigned-zero-compare) does it. > I'd expect something like coverity to perform a bit better here but it's > a pain to use the "free for open source" version (... I just requested > access to https://scan.coverity.com/projects/128 but I have no idea if > they build next or not) > > Oh, well; glad Christophe noticed anyway. > > > > Would probably be interesting to run some form of the same in our > > > automation. > > > > If there is any ATM? I als tried this issue with clang's undefined behaviour > > sanitizer and with the clang static analyzer. Both did not detect it. > > There's at least the intel bot building with W=1 and warning if any new > such warning pops up (and I'd like to say I check myself, but I probably > forget about half the time; I looked at making W=1 default for our part > of the tree but it didn't look trivial? I'll try to have another look); > but I'm not aware of anyone testing with scan-build or something else > that'd contact us on new defects. > >
On Tue, Apr 25, 2023 at 8:12 AM Dominique Martinet <asmadeus@codewreck.org> wrote: > > Christophe JAILLET wrote on Tue, Apr 25, 2023 at 08:47:27AM +0200: > > Fixes: 6deffc8924b5 ("fs/9p: Add new mount modes") > > (Not a problem per se: but note this commit hasn't been merged yet, so > using commit IDs is a bit dangerous. Might want to remark this in the > free comment section so Eric pays attention to not break that when applying) This is fine. The hash is constant unless Eric does a rebase. When a maintainer rebases then updating the fixes tags is just part of the process. Often they end up folding the fix into the original patch at that point so the Fixes tag is not required. If a maintainer doesn't update the tags then the linux-next maintainers will notice and complain. #GitMagic regards, dan carpenter
Dan Carpenter wrote on Tue, Apr 25, 2023 at 02:14:52PM +0100: > The hash is constant unless Eric does a rebase. When a maintainer rebases > then updating the fixes tags is just part of the process. Often they end up > folding the fix into the original patch at that point so the Fixes tag is not > required. If a maintainer doesn't update the tags then the linux-next > maintainers will notice and complain. Good to know this is checked as part of the linux-next tree checks. > #GitMagic This isn't magic, this is painful to update manually and easy to forget, which is why as a maintainer I'd appreciate having a heads up here and why I mentioned it. (I'm sure Eric would have noticed anyway given this is fixing one of the patchs he really wants to get in this merge window... But, well, in general) Re: folding into the original patch or not is also tricky as it weakens recognition to the contributor, so I tend to keep such fixes separate unless the tree becomes completely unusable (e.g. doesn't build) for bisectability. (I really, really wish there was a more mainlined maintainer process though, so each maintainer wouldn't have to come up with their own rules and tricks for everything... But I think that's a lost battle at this point)
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index 06a2514f0d88..698c43dd5dc8 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h @@ -108,7 +108,7 @@ enum p9_cache_bits { struct v9fs_session_info { /* options */ - unsigned char flags; + unsigned int flags; unsigned char nodev; unsigned short debug; unsigned int afid;