Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp569073lqo; Thu, 16 May 2024 14:52:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKt3Ci3qMm6k9V8rnjA9rKN0ukwewFBPz0vX3D5B21Ji1zU4cNQjkLbCquCdCYo0fAz0wS17Q/tJcNt5G3o737b9SOqeIWtGQHiCgyaA== X-Google-Smtp-Source: AGHT+IGOjR78UwjfuiEIqr3Z94zM6YO4bv6+87kWSY9njfRjMvhT1lPs6nGv63FgJ9xUmnSKj3Yo X-Received: by 2002:a05:6a00:1415:b0:6f4:b6fc:dfc7 with SMTP id d2e1a72fcca58-6f4e02ab7d0mr20779116b3a.9.1715896337616; Thu, 16 May 2024 14:52:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715896337; cv=pass; d=google.com; s=arc-20160816; b=rquhNLIotLuzm3wU7q2Bbr+QqgRfSnieJmR3KyAi+i+KZeQbsA5LqLpNQ/8tai+jaM S5aOz39cuHGDoe7FhgqdG8dKez7cfXfa0dt2TIrY83N2AnugtsU1IlfJ0GDqP2sOgiK/ kM0zHDLb1/BelHJI0D8XGn3Oj5Uk0k1AqXxyS9TtkJwYs70bVU3b0CUjdljmfKvCDNSr q8QypTuZOqES1E+ZmRcrlEJE+G0QYqNMUEhwhaFF+242yc3yXf9stbxCNNCS8dl+Vzse psr8tNU0DRZDpchfImVI/qraqmJggkNUwtaKdjPKqlU23UjT9R7kzUAh7IFDGGUZZjhI NBqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Bj5eq4OL55W+rSK34Om4WapAHrhBgkSRR4zqYMOa1zs=; fh=Z0LYSW3AAEQgrBnypOOfQis+MWJ37xAXFryi67hUEWk=; b=m3G7BbE/bcuqlB9EoPldXavrC7biHpk9E+JmOBRZDg0gmFdCbkyovEeOQuVupMbtKt /4GBs7lk0/C85Rgamj370BHOmWSvSqiJYLCpH6Hn3UvwmfXbr1PrCqpt2GJpiplmubwE fjESGLZupXZ2ODXuzhMu7o1OGs9sF6/iydT2rclry2k/ZIyjRBPHDOffQXm6gT1oHNDm YsYdb49IS0TH9x/x75jEx6aRKTX+2Ygi1iTI9sxMg1eb9zGFEZGFSHnwX4n+9qIz+ijA p8xd/oyGUk4Q2LhkQwqbcoMOtpNStMGipNGK6Hs96sPKyjZM7aaGbyKKKh579L/1wga7 8M7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@acm.org header.s=mr01 header.b=g28s2P68; arc=pass (i=1 spf=pass spfdomain=acm.org dkim=pass dkdomain=acm.org dmarc=pass fromdomain=acm.org); spf=pass (google.com: domain of linux-kernel+bounces-181599-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181599-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=acm.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-654bc4094a1si4407789a12.789.2024.05.16.14.52.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 14:52:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181599-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@acm.org header.s=mr01 header.b=g28s2P68; arc=pass (i=1 spf=pass spfdomain=acm.org dkim=pass dkdomain=acm.org dmarc=pass fromdomain=acm.org); spf=pass (google.com: domain of linux-kernel+bounces-181599-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181599-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=acm.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5B1ECB21898 for ; Thu, 16 May 2024 21:52:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 556E0158217; Thu, 16 May 2024 21:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="g28s2P68" Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2D4B156F2A; Thu, 16 May 2024 21:52:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715896326; cv=none; b=RpRbn9OVLM12wEvx+q86CAKucJOaIqKN1keO+ZUE5bW17T5fkfyoRzU2Kfhz0y20xAgjbgxwh453F1Nz4+WzK5/+YZHhivZ7Azq2+Os2E3pvQBcz4BAbbnE7AVdEeP+patpeRFBHC7oNiyyTeYZZQQH0u/luMnJTA3IzZIxQg2U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715896326; c=relaxed/simple; bh=AJ+oje2i3UVqPU/z/dt3ZEHV3byJ0YBoiG6SDi/9wvY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Rh+Aa4HALpPrPxcjKYV7KmtNL/edyV4Ql7VhQYYnbmQYnYN2jJd/HIC3EcDT2vMBG4Ukq2Gv3J8MzU+bMePzDdan7sqI4Hhl3WWyHgyZQ8EPOgIxsgQtDCmh592sVqHwhiPlg2bOsDWAldE1OhakHQD+UsaKddKZJAKtN356V5U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=g28s2P68; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VgP2C1Wb3z6Cnk8t; Thu, 16 May 2024 21:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:content-language:references:subject:subject :user-agent:mime-version:date:date:message-id:received:received; s=mr01; t=1715896318; x=1718488319; bh=Bj5eq4OL55W+rSK34Om4WapA HrhBgkSRR4zqYMOa1zs=; b=g28s2P68w6nddG6TXyHYAcas2m9OfthI/sezG3gI V98hD0ogSxI6tDZ86MfOBqf/FrGTEEGxlGpDUbJmfclilROt/u2QQIdfGJaIxKST vWLUTLHwlVPtmA5twqSrt+1VkOpEWJ4hmTwF4cw6mux7HENLEmg0bAZQrXnY3fML 2Gaw6XNWclnKAJSZz7Etw8pi8+DE0C/WYVpaci+7cBBi1RAnMu6aQSDnVwz8JFct xiJG2dfN8fpYauv4lT6IjMyf2hcHakxNkHSh/y1Xj5PGah0FnV+U5zkb9ehKtH8F xgbVXlvuVYo28ZxCaZ1I8KmzoDtCjHgeUZO9InPLznuciA== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 0YZ5q-mvcmGY; Thu, 16 May 2024 21:51:58 +0000 (UTC) Received: from [192.168.51.14] (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VgP242XHVz6Cnk8s; Thu, 16 May 2024 21:51:55 +0000 (UTC) Message-ID: <4a5cf233-a4e6-48ce-b9ba-f1014f452892@acm.org> Date: Thu, 16 May 2024 15:51:54 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH -mm] nilfs2: Use __field_struct() for a bitwise field To: Linus Torvalds Cc: Andrew Morton , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, Rasmus Villemoes , Steven Rostedt , Ryusuke Konishi References: <20240507142454.3344-1-konishi.ryusuke@gmail.com> Content-Language: en-US From: Bart Van Assche In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/7/24 10:25, Linus Torvalds wrote: > On Tue, 7 May 2024 at 07:25, Ryusuke Konishi wrote: >> >> Despite that change, sparse complains when >> passing a bitwise type to is_signed_type(). It is not clear to me why. > > Bah. The reason is this: > > #define is_signed_type(type) (((type)(-1)) < (__force type)1) > > Basically, the way "is_signed_type()" works is that it casts a > negative integer to the type, and checks to see if the value has now > become a large value. > > Now, it looks odd, because only one of those casts has a "__force" on > it, but the reason for that is that casting all-ones and all-zeroes is > ok for bitwise types (think of bitwise types as being a "collection of > bits" - so all bits set or all bits clear are sane concepts regardless > of any other semantics). > > So it's not the casts themselves that are problematic: that part works fine. > > But you cannot compare a random collection of bits for greater than or > lesser than. > > Think of things like byte orders: you can compare two values for > _equality_ even if they are in the wrong byte order, but you can't > compare them for "larger than" unless you turn them into the right CPU > byte order. > > Basically, a "collection of bits" doesn't have an ordering in itself, > even if equality comparisons are ok. > > So yeah, is_signed_type() doesn't work for bitwise types. > > And I don't see a sane way to make "is_signed_type()" to work for > bitwise types - the whole concept of signedness of "bunch of bits" is > kind of nonsensical - so I suspect your workaround is the best we can > do (alternatively, tracing would have to figure out a different way to > test for signedness). (replying to an email from ten days ago) Thanks Linus for the detailed analysis. I tried the patch below but unfortunately it is not sufficient to suppress sparse warnings about bitwise types (all enum req_op values have the type __bitwise __u32): diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 8c252e073bd8..940563438b87 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -287,7 +287,14 @@ static inline void *offset_to_ptr(const int *off) * Whether 'type' is a signed type or an unsigned type. Supports scalar types, * bool and also pointer types. */ -#define is_signed_type(type) (((type)(-1)) < (__force type)1) +#define is_signed_type(type) \ + (_Generic((__force type)1, \ + unsigned char: 0, \ + unsigned short: 0, \ + unsigned int: 0, \ + unsigned long: 0, \ + unsigned long long: 0, \ + default: ((type)(-1)) < (type)1)) #define is_unsigned_type(type) (!is_signed_type(type)) /* It seems like sparse verifies the types of all expressions in a _Generic() argument list instead of only the expression for which the type matches. Could this indicate a bug in sparse? On https://en.cppreference.com/w/c/language/generic I found the following (I'm not sure whether that website is a good reference): "The controlling-expression and the expressions of the selections that are not chosen are never evaluated." Thanks, Bart.