From patchwork Tue Nov 4 10:03:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime COQUELIN X-Patchwork-Id: 40099 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0EE4121894 for ; Tue, 4 Nov 2014 10:05:04 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id e51sf3869593eek.10 for ; Tue, 04 Nov 2014 02:05:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=FYe/WymcrAuZRjPxLl/X9be47Hh2sOqgDrrvMEVvgkA=; b=ZBoPwp2nadxvKP0k08ppMiGjGewsB6wFDzevzII2vQYMg1MX6duKm6ImFCmzKXeYE4 AEZU/jhpvF4MMcV5x83R+phCVAatLk539BdbVq0y2fy1SHnC/QJgG80c08BIA4ZFQJXi 1dWXEv+s1bX1VQ29bWslfORRQ/UxtzuA+256/A23Myw45tNkH4N4SkwMs+XK8bs53YxS sjsyfN2OA4NrWqvMiNRxVDRO3Y2HUAOo/ANyc+eanHWnwddFn+TvV5B7p9Mt1jmSicha zveuBUVhsFizFp6WpKlug8oHD1D/S8zAbgAMJy15ELuFQ4LI0ldVA+zBmPOgVxwFc9HG ud5g== X-Gm-Message-State: ALoCoQkfkkRx/jNKO4h/FVxsy5apB+wLOS94N1tYVGqg+EtVdVJAMVwZ7w435om06rVw8I7LS3YB X-Received: by 10.194.242.36 with SMTP id wn4mr400831wjc.4.1415095503239; Tue, 04 Nov 2014 02:05:03 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.177 with SMTP id k17ls39183laa.56.gmail; Tue, 04 Nov 2014 02:05:02 -0800 (PST) X-Received: by 10.112.125.33 with SMTP id mn1mr19637674lbb.99.1415095502460; Tue, 04 Nov 2014 02:05:02 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id kh7si36814760lbc.17.2014.11.04.02.05.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Nov 2014 02:05:02 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id z11so8726894lbi.5 for ; Tue, 04 Nov 2014 02:05:02 -0800 (PST) X-Received: by 10.152.29.8 with SMTP id f8mr58022183lah.56.1415095502297; Tue, 04 Nov 2014 02:05:02 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp90963lbc; Tue, 4 Nov 2014 02:05:01 -0800 (PST) X-Received: by 10.68.209.230 with SMTP id mp6mr48689909pbc.27.1415095500496; Tue, 04 Nov 2014 02:05:00 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qe9si17549643pac.199.2014.11.04.02.04.59 for ; Tue, 04 Nov 2014 02:05:00 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752947AbaKDKE5 (ORCPT + 25 others); Tue, 4 Nov 2014 05:04:57 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:58746 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751155AbaKDKEu (ORCPT ); Tue, 4 Nov 2014 05:04:50 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.14.5/8.14.5) with SMTP id sA49u3UY019439; Tue, 4 Nov 2014 11:04:11 +0100 Received: from beta.dmz-us.st.com (beta.dmz-us.st.com [167.4.1.35]) by mx07-00178001.pphosted.com with ESMTP id 1qeqj01bpf-1 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 04 Nov 2014 11:04:11 +0100 Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id D4D6526; Tue, 4 Nov 2014 10:04:01 +0000 (GMT) Received: from mail7.sgp.st.com (unknown [164.129.223.81]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id CA2283F; Tue, 4 Nov 2014 10:03:59 +0000 (GMT) Received: from lmecul0520.lme.st.com (lmecul0520.lme.st.com [10.201.23.80]) by mail7.sgp.st.com (MOS 4.3.3-GA) with ESMTP id BZR62628 (AUTH lme00137); Tue, 4 Nov 2014 11:03:49 +0100 From: Maxime COQUELIN To: gong.chen@linux.intel.com, Peter Zijlstra , Ingo Molnar , " Paul E. McKenney" , tytso@mit.edu, linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: kernel@stlinux.com, maxime.coquelin@st.com, eric.paire@st.com Subject: [PATCH v2] bitops: Fix shift overflow in GENMASK macros Date: Tue, 4 Nov 2014 11:03:57 +0100 Message-Id: <1415095437-28723-1-git-send-email-maxime.coquelin@st.com> X-Mailer: git-send-email 1.9.1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.12.52, 1.0.28, 0.0.0000 definitions=2014-11-04_05:2014-11-03, 2014-11-04, 1970-01-01 signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxime.coquelin@st.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On some 32 bits architectures, including x86, GENMASK(31, 0) returns 0 instead of the expected ~0UL. This is the same on some 64 bits architectures with GENMASK_ULL(63, 0). This is due to an overflow in the shift operand, 1 << 32 for GENMASK, 1 << 64 for GENMASK_ULL. Fixes: 10ef6b0dffe404bcc54e94cb2ca1a5b18445a66b Cc: #v3.13+ Reported-by: Eric Paire Suggested-by: Peter Zijlstra Signed-off-by: Maxime Coquelin --- include/linux/bitops.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index be5fd38..a49d7b7 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -18,8 +18,8 @@ * position @h. For example * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. */ -#define GENMASK(h, l) (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l)) -#define GENMASK_ULL(h, l) (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l)) +#define GENMASK(h, l) ((~0UL >> (BITS_PER_LONG - (h - l + 1))) << l) +#define GENMASK_ULL(h, l) ((~0ULL >> (BITS_PER_LONG_LONG - (h - l + 1))) << l) extern unsigned int __sw_hweight8(unsigned int w); extern unsigned int __sw_hweight16(unsigned int w);