Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4505027rwr; Mon, 8 May 2023 08:34:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4tbZ3ouiY64ezykZtODKhG5jeqQy8XQF8/4n8HOZe56piMDMwOUHD5wO7CiHdvKEc8mMED X-Received: by 2002:a17:903:1249:b0:1a9:5aef:1aea with SMTP id u9-20020a170903124900b001a95aef1aeamr12988527plh.66.1683560052232; Mon, 08 May 2023 08:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683560052; cv=none; d=google.com; s=arc-20160816; b=LDsDvc7eeELmRhcYewUj5l9bZl7+sx3qBB4MQFbQkSeZr353xjdRYMB8eBn9trfaTq 0ip63pWUk95fWUINKPlhlAQVRGMTYCIbiOVittKFrfozUs+JGk63V/B584MQbFuVtjPd Fs8o9RIGSrqRow5qpoJp5SEzUen8HzrtSrdZehqv3JuTt2kgzqi6m7xzfMT2Yx4bYn4c LdPJIlcFRYh2hdG0BYRh8gm4F8u9vcO02nLe8mqntuWtzAwVWj9EaYqjd2vjCXxm7MOt wImsTSI1Nlp50an/qOu3CFEmACKuEfRs/sqMvONQ+WvobSABYedsTcaZ5QmSPLlEXpgt 38ZA== 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=YghYJS8doYl08TEnAbE0b5oCAApvaGIShQswctorh5Y=; b=uZXoBdmm+xU90T7PGTAsv2dyk71+q4YAbrnpRqWFlYc6NMIQYHQ883VPCRBZvjtCMD Gj29Q0VaAowcLX/LK9IdHjwm0Ro1XZAa79cceaz/s59LCdKl/7qCf33fJsO0piZkUZJf XX2PvjxVcL9hJKfGqDITypJZzTLoyxG95Ey9s2IpAd2aJ2R9uxB5iL9brVJqlAnnTqbm ja8uAsArvbPLgnPQ1TTglC9X0HfXixnV4zw/BfzLx6Z0hGbs+G4ec2Ny5ttHtkKrxw4K 6o1ECkXFeUx/NK3n4PnABPw3jY7cEWSigxRUkJIuEXRmZ7QxxkcxRlPtdjNY7LhuxeoF t3lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PM3Y6cvO; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a17090ac90d00b00244a45cb5c0si3170644pjt.42.2023.05.08.08.33.57; Mon, 08 May 2023 08:34:12 -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=@kernel.org header.s=k20201202 header.b=PM3Y6cvO; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234024AbjEHPaO (ORCPT + 99 others); Mon, 8 May 2023 11:30:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233625AbjEHP3z (ORCPT ); Mon, 8 May 2023 11:29:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1009691; Mon, 8 May 2023 08:29:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 98D8A61DFF; Mon, 8 May 2023 15:29:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBA21C433D2; Mon, 8 May 2023 15:29:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683559793; bh=OmU/svdFtbjVNgVAsdOkNUGzGdzCuBkqJ74yv6PqUeI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PM3Y6cvOHXVo097NkR2gMxxZekPAAMO+tETbMAW5XyvilNuWYDhqy5wZzBNdVRyzA MeFKNeF7c/o/9XaQej+r39g6KYMdnowHOj6/XS5onGLn75Cf5vxrJ0kY9rA5Tko1Bv c2vsVfWk06pyJZojxP9BafHN6o0jgPvwa57mfe3JWVNXIo/yaAJlpgQoCuSDIFV81V mGwK13zhfqCeXZ+l86i80bH5TdOi4cXDjc6fQ4j7tHDMX2IRzZynFFwDuDhUNXuhTk EuT/uktkPmST8rBufECiNLa5nGXl9OFZvFXTuB1Z72bUBH4pb/i4tMn8gch91BxsVe tUpuJk3uYHXLw== Date: Mon, 8 May 2023 08:29:52 -0700 From: "Darrick J. Wong" To: Geert Uytterhoeven Cc: Dave Chinner , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xfs: Fix undefined behavior of shift into sign bit Message-ID: <20230508152952.GA858799@frogsfrogsfrogs> References: <20230508120634.2598765-1-geert+renesas@glider.be> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230508120634.2598765-1-geert+renesas@glider.be> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 08, 2023 at 02:06:34PM +0200, Geert Uytterhoeven wrote: > With gcc-5: > > In file included from ./include/trace/define_trace.h:102:0, > from ./fs/xfs/scrub/trace.h:988, > from fs/xfs/scrub/trace.c:40: > ./fs/xfs/./scrub/trace.h: In function ‘trace_raw_output_xchk_fsgate_class’: > ./fs/xfs/scrub/scrub.h:111:28: error: initializer element is not constant > #define XREP_ALREADY_FIXED (1 << 31) /* checking our repair work */ > ^ > > Shifting the (signed) value 1 into the sign bit is undefined behavior. > > Fix this for all definitions in the file by shifting "1U" instead of > "1". > > This was exposed by the first user added in commit 466c525d6d35e691 > ("xfs: minimize overhead of drain wakeups by using jump labels"). > > Fixes: 160b5a784525e8a4 ("xfs: hoist the already_fixed variable to the scrub context") > Signed-off-by: Geert Uytterhoeven > --- > fs/xfs/scrub/scrub.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/fs/xfs/scrub/scrub.h b/fs/xfs/scrub/scrub.h > index b38e93830ddea2b0..e113f2f5c254b085 100644 > --- a/fs/xfs/scrub/scrub.h > +++ b/fs/xfs/scrub/scrub.h > @@ -105,10 +105,10 @@ struct xfs_scrub { > }; > > /* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */ > -#define XCHK_TRY_HARDER (1 << 0) /* can't get resources, try again */ > -#define XCHK_FSGATES_DRAIN (1 << 2) /* defer ops draining enabled */ > -#define XCHK_NEED_DRAIN (1 << 3) /* scrub needs to drain defer ops */ > -#define XREP_ALREADY_FIXED (1 << 31) /* checking our repair work */ > +#define XCHK_TRY_HARDER (1U << 0) /* can't get resources, try again */ > +#define XCHK_FSGATES_DRAIN (1U << 2) /* defer ops draining enabled */ > +#define XCHK_NEED_DRAIN (1U << 3) /* scrub needs to drain defer ops */ > +#define XREP_ALREADY_FIXED (1U << 31) /* checking our repair work */ DOH. My mistake. :( Does gcc have an explicit warning for that? I turned on W=12e on gcc 11.3 and UBSAN and neither complain about this. Reviewed-by: Darrick J. Wong --D > > /* > * The XCHK_FSGATES* flags reflect functionality in the main filesystem that > -- > 2.34.1 >