Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751965AbdF2Gee (ORCPT ); Thu, 29 Jun 2017 02:34:34 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:54801 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751890AbdF2Ge1 (ORCPT ); Thu, 29 Jun 2017 02:34:27 -0400 Date: Thu, 29 Jun 2017 08:33:20 +0200 (CEST) From: Thomas Gleixner To: zhong jiang cc: Ingo Molnar , akpm@linux-foundation.org, mingo@redhat.com, minchan@kernel.org, mhocko@suse.com, hpa@zytor.com, x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] futex: avoid undefined behaviour when shift exponent is negative In-Reply-To: <59545DD6.3030508@huawei.com> Message-ID: References: <1498045437-7675-1-git-send-email-zhongjiang@huawei.com> <20170621164036.4findvvz7jj4cvqo@gmail.com> <595331FE.3090700@huawei.com> <59545DD6.3030508@huawei.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 743 Lines: 25 On Thu, 29 Jun 2017, zhong jiang wrote: > On 2017/6/29 6:13, Thomas Gleixner wrote: > > That's simply wrong. If oparg is negative and the SHIFT bit is set then the > > result is undefined today and there is no way that this can be used at > > all. > > > > On x86: > > > > 1 << -1 = 0x80000000 > > 1 << -2048 = 0x00000001 > > 1 << -2047 = 0x00000002 > but I test the cases in x86_64 all is zero. I wonder whether it is related to gcc or not > > zj.c:15:8: warning: left shift count is negative [-Wshift-count-negative] > j = 1 << -2048; > ^ > [root@localhost zhongjiang]# ./zj > j = 0 Which is not a surprise because the compiler can detect it as the shift is a constant. oparg is not so constant ... Thanks, tglx