Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2185715rwi; Tue, 1 Nov 2022 05:03:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5gi+KJkxqY2ZlVZQoEXnMW3bMPfO3b0LsGXV3NMEtNK2LOWQcNCiYt6NJEBQsppJoOSbtB X-Received: by 2002:a17:906:58c9:b0:7a7:dcba:a987 with SMTP id e9-20020a17090658c900b007a7dcbaa987mr17907477ejs.88.1667304197175; Tue, 01 Nov 2022 05:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667304197; cv=none; d=google.com; s=arc-20160816; b=oCFYUmmAu7BXvo6OZCFfD1rPnpFRyDGK28OVT73LyR0o1X2EvMJT77Pn5poUzmoiDy j0g5RbunMWYuUVj8LGra6Xm66iXE2Vx2W80bwAxTCvP5m6qyLxx+ryeevTYRYA/u2Kls wMbguIMqshjjZc3lsY1fl9JCGggm/qQBKOGS2cZVgVgIrRy0cd9ruMjfEICBN+V1ON70 49Ex+Nf9IMvqA09Stnz1+r9N/ZML/EckqKaMWF18xVfA/s/j665LBQPcqZ+05D3/DmZE gwctUEHkOiaZdYAJLRSVDZcvjtM3Mw/A+3+/WnHTqj/2hMwUC+wiW0TmJwA/8Hgf+4oF Drzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=U4zyEzr8v+Rg0JC+zjXMRygQCc1g8xAGUvKbQz8kAoc=; b=Iuv0mnwTd4KkrMxdjwBJq6YfE00R+0TapGkGzyDtyzekYh8/DhTI3SrnV4vwg3TV/m GXS5HWz7m+Ont3DFkus4sueyD325Ddyq0fXLfxLc6h5R0VbWynAgx8+c3OjXHbs78zkE tWBT6Ta5JC1F+scOJ1m2J/nUVHsexXPPi8pfNWlsfLNnYy1p21Kb/CE0fg9qThL5e+zG rr4xmiIMw9IweMT+K63pgwT6dK3DSdF1m0mwR4eo6ZNH1n5yCE4nrwFWb81Y57tzDR1o mXCgJ53jXluEmFAGHDAD1D0cYxsWppuCPXIVK4VbEABk3KcG8uQr4na/KpMuPfGzKBCC dwnw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e2-20020a170906314200b0078df1c345dasi10087486eje.534.2022.11.01.05.02.50; Tue, 01 Nov 2022 05:03:17 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229929AbiKALvM (ORCPT + 97 others); Tue, 1 Nov 2022 07:51:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231500AbiKALuo (ORCPT ); Tue, 1 Nov 2022 07:50:44 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E62B71B1 for ; Tue, 1 Nov 2022 04:48:10 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N1p8h5wdvzpVTF; Tue, 1 Nov 2022 19:44:36 +0800 (CST) Received: from [10.67.110.176] (10.67.110.176) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 1 Nov 2022 19:48:08 +0800 Subject: Re: [PATCH] x86/cpu: fix undefined behavior in bit shift for intel_detect_tlb To: Peter Zijlstra CC: , , , , , , , , , , , , References: <20221031114340.4185587-1-cuigaosheng1@huawei.com> From: cuigaosheng Message-ID: Date: Tue, 1 Nov 2022 19:48:07 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.110.176] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,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 We don't need to add UBSAN calltrace, so I have merged the patch with another patch("x86/cpu: replacing the open-coded shift with BIT(x)"), please ignore this patch,thanks for review this patch! On 2022/10/31 20:32, Peter Zijlstra wrote: > On Mon, Oct 31, 2022 at 01:30:57PM +0100, Peter Zijlstra wrote: >> On Mon, Oct 31, 2022 at 07:43:40PM +0800, Gaosheng Cui wrote: >>> Shifting signed 32-bit value by 31 bits is undefined, so changing >>> significant bit to unsigned. The UBSAN warning calltrace like below: >>> >>> UBSAN: shift-out-of-bounds in arch/x86/kernel/cpu/intel.c:948:21 >>> left shift of 1 by 31 places cannot be represented in type 'int' >> Is it really? Shouldn't -fstrict-overflow define this case? > -fno-strict-overflow that is, which implies -fwrapv which ensures 2s > complement, at which point shifting signed numbers is fully defined. > > .