Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp174511rwi; Wed, 2 Nov 2022 10:33:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM53/CfipmIQRgsWEelYq2QCfzs69mI3NW4SAhw6/S65jQ5araG7lDcpEfECiGB0gMyPVGr1 X-Received: by 2002:a17:903:494:b0:186:a227:436f with SMTP id jj20-20020a170903049400b00186a227436fmr25836966plb.133.1667410435406; Wed, 02 Nov 2022 10:33:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667410435; cv=none; d=google.com; s=arc-20160816; b=JM9FHH2J3Z9s1jL+qE6WSPucs71tPGSrnhLIbXpw2ygssE4OzVghvJrTaCOdbkpWEk AvOf+oC/IdsqepeBgX1mIYrlQmTGczw39zPIQqX6zK85xctlJcprd/UYqqgGUZ4u6lBY Oz1eIae2hwhXSIegO5wIsNwi9mEB6T4cip1ko627iuNNIb8v/ISkBY3xAt1BWKQ9ckpg 2gpatHGiYNYjxr//hgYV2+q5KD25RmQi77GwGa6tmjubDn1OpkMSTJZLRbyAkLeTA7UP N+evMHkKvDuUk8gktjM8iL3zHzfFQh6pgxxndnnpyHNCU/vAynjuZprDhLWZhKD493zN /W3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=Hwlkw4yAnCdRiQ+TM46iAZW7QPfAAgCdGvGqNHRyplo=; b=TjAkge/CBbpWOj6L0bYUu7HHufFAsbpDGTJD0lpUdJBJCFRVrgYJMmRN74U+fkYabf BSyEKdUwsJFI9SE4rFa8mHztgKOd9dlbfmSAN6TjLfJE5HkTZlexobtMZtGeIdBaQVVu aTa7mDptqOthYtDJOtXFdSzZ4YVtqqgwsQsklk1MlbEZWZfeXLH3SXatBsCkgYDmAL17 axBTLb+hatsg32UU41jAP5THflpcSZd2q5+yYmQX2GLiJIvbeqgOppLhlHkhMoS7IPzi 95spigvdd9KhbWiLotU2SkUjShunAudXEGVBFHMNdUAp33pjtwty00SDMSUnQnR8+t4K bZFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=H5UvIVYT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a17090332c600b00175430821b1si21562703plr.430.2022.11.02.10.33.41; Wed, 02 Nov 2022 10:33:55 -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=@inria.fr header.s=dc header.b=H5UvIVYT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbiKBRRK (ORCPT + 98 others); Wed, 2 Nov 2022 13:17:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbiKBRRI (ORCPT ); Wed, 2 Nov 2022 13:17:08 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0BBE21E0A; Wed, 2 Nov 2022 10:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=Hwlkw4yAnCdRiQ+TM46iAZW7QPfAAgCdGvGqNHRyplo=; b=H5UvIVYTfCSfCsJKvK0mipZhvhRzj9y8kKLh86gNspOg4Ze7Dcy8Ys3O gldI0+jMNErr2iMaqtJsOvJMVxpQuEpIvlRQr3v01N3cdqZLlz+mS7Gjt C7nPoQRkj62ttpQ5YKEv4lrhBw4Sk+sBcGeOL2bLmUuZwcB8fjjU6FoCK M=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="5.95,234,1661810400"; d="scan'208";a="72701514" Received: from dt-lawall.paris.inria.fr ([128.93.67.65]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2022 18:17:04 +0100 Date: Wed, 2 Nov 2022 18:17:04 +0100 (CET) From: Julia Lawall To: "Jason A. Donenfeld" cc: Kees Cook , cocci@inria.fr, Linus Torvalds , Alexey Dobriyan , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, mm-commits@vger.kernel.org, masahiroy@kernel.org, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, Stephen Rothwell Subject: Re: [cocci] [PATCH -mm] -funsigned-char, x86: make struct p4_event_bind::cntr signed array In-Reply-To: Message-ID: References: <20221020000356.177CDC433C1@smtp.kernel.org> <202210201151.ECC19BC97A@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 26 Oct 2022, Jason A. Donenfeld wrote: > On Wed, Oct 26, 2022 at 03:50:25AM +0200, Jason A. Donenfeld wrote: > > The traditional objdump comparison does work, though. It produces a good > > Another thing that appears to work well is just using Coccinelle > scripts. I've had some success just scrolling through the results of: > > @@ > char c; > expression E; > @@ > ( > * E > c > | > * E >= c > | > * E < c > | > * E <= c > ) > > That also triggers on explicitly signed chars, and examining those > reveals that quite a bit of code in the tree already does do the right > thing, which is good. > > From looking at this and objdump output, it looks like most naked-char > usage that isn't for strings is actually already assuming it's unsigned, > using it as a byte. I'll continue to churn, and I'm sure I'll miss a few > things here and there, but all and all, I don't think this is looking as > terrible as I initially feared. > > I'm CC'ing the Coccinelle people to see if they have any nice ideas on > improvements. Specifically, the thing we're trying to identify is: > > - Usage of vanilla `char`, without a `signed` or `unsigned` qualifier, > where: Try putting disable optional_qualifier between the initial @@, to avoid the implicit matching of signed and unsigned. > - It's not being used for characters; and > - It's doing something that assumes it is signed, such as various > types of comparisons or decrements. I took a quick look at the article, but I'm not completely sure what you are getting at here. Could you give some examples of what you do and don't want to find? You don't want the case where c is 'x', for some x? julia > LWN wrote a summary of the general problem, in case that helps describe > what would be useful: https://lwn.net/SubscriberLink/911914/f90c2ed1af23cbc4/ > > Any nice Cocci tricks for this? > > Jason >