Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3329181yba; Mon, 8 Apr 2019 16:36:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvnDg81MhlwqcIN38rZncYhQgvcl4RRiH++uKL6hVPBGzqhg5pgj0iUV4KGQ9L8qRRNubC X-Received: by 2002:a63:c10d:: with SMTP id w13mr31228553pgf.311.1554766570926; Mon, 08 Apr 2019 16:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554766570; cv=none; d=google.com; s=arc-20160816; b=yKhK857zMovQ3cES0eLArBDdDXhBWLHt2M44nkG6R83ZEi05kpNrQHwpX1ofD2ruRn Ihl9Q+E91DfvkwoS5dj8F83v+oQbLitWCZWmARXxVivY+3RHOHrsuN9V7bLuXzzk8DfV JPFIZZzsfGGSz6n0reQN3H53+Amh0CtGgCacRZc5AVgoZUyvHIVZZbQbxmlIw2+uzJlF Xxt5llCVdCN+lOPUvGQVRmC/aA8ncq0CSBTYnT94+BKeYAc1pHfH+WYfnbhe4mhpEtJX i0E3SPUeGhpsBcNrhQxwAKxgwGWIM7Kj9l/8RTu+8K7N/EdMmtM8S+7E8F/g3EhLdvT5 XgwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=1nYnsBY0jmM/je+McvS3TxLY6xuZOYR3/JgqIjwk1pI=; b=N2xy+7/esVq+BUhHyprMTjRRgO2g0CMhKMcQXsiG22jFrKe9LoYCWtXqaOJRC6U7VY mTcOyyxbA4WyGIQscY2nhj2HrixGlnjLiwJ8zXTyGrKZ4KTsyLQdFP/FIZBkJ2vFq9Yr 8noD3AxV0ESuZD+wVZF0Y4TB/bTT493H3/lyb4ba7e5HZSQ9ff8K3Bly+eyT3AofPnXC 54dxajQYKSyuFUhX62SlNs/RhILWHb5bH6/bD3/+gDI7oOQknUgijd5uK2+q7HzmDWs/ RsUUuaxVw3CDxutlQdISjIroJyLQV0EmxB0v/kOXEn0iiiNS1N+qRiDb+evZJb1aOgTd +g/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a82si15047519pfj.255.2019.04.08.16.35.41; Mon, 08 Apr 2019 16:36:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727064AbfDHWwU (ORCPT + 99 others); Mon, 8 Apr 2019 18:52:20 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43744 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726188AbfDHWwT (ORCPT ); Mon, 8 Apr 2019 18:52:19 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E70E0CB7; Mon, 8 Apr 2019 22:52:18 +0000 (UTC) Date: Mon, 8 Apr 2019 15:52:17 -0700 From: Andrew Morton To: Vadim Pasternak Cc: jacek.anaszewski@gmail.com, pavel@ucw.cz, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, idosch@mellanox.com, Andrey Ryabinin Subject: Re: [PATCH v1 bitops] bitops: Fix UBSAN undefined behavior warning for rotation right Message-Id: <20190408155217.3f723554ae7fbcb34eeacb30@linux-foundation.org> In-Reply-To: <20190407125325.24440-1-vadimp@mellanox.com> References: <20190407125325.24440-1-vadimp@mellanox.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (resend, cc Andrey) On Sun, 7 Apr 2019 12:53:25 +0000 Vadim Pasternak wrote: > The warning is caused by call to rorXX(), if the second parameters of > this function "shift" is zero. In such case UBSAN reports the warning > for the next expression: (word << (XX - shift), where XX is > 64, 32, 16, 8 for respectively ror64, ror32, ror16, ror8. > Fix adds validation of this parameter - in case it's equal zero, no > need to rotate, just original "word" is to be returned to caller. > > The UBSAN undefined behavior warning has been reported for call to > ror32(): > [ 11.426543] UBSAN: Undefined behaviour in ./include/linux/bitops.h:93:33 > [ 11.434045] shift exponent 32 is too large for 32-bit type 'unsigned int' hm, do we care? > ... > > --- a/include/linux/bitops.h > +++ b/include/linux/bitops.h > @@ -70,6 +70,9 @@ static inline __u64 rol64(__u64 word, unsigned int shift) > */ > static inline __u64 ror64(__u64 word, unsigned int shift) > { > + if (!shift) > + return word; > + > return (word >> shift) | (word << (64 - shift)); > } Is there any known architecture or compiler for which UL<<64 doesn't reliably produce zero? Is there any prospect that this will become a problem in the future?