Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754420AbbGTB6M (ORCPT ); Sun, 19 Jul 2015 21:58:12 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:36432 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753729AbbGTB6K (ORCPT ); Sun, 19 Jul 2015 21:58:10 -0400 Message-ID: <55AC55AD.6070608@roeck-us.net> Date: Sun, 19 Jul 2015 18:58:05 -0700 From: Guenter Roeck User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Rasmus Villemoes CC: Sowmini Varadhan , linux-kernel@vger.kernel.org, akpm@linux-foundation.org, benh@kernel.crashing.org, davem@davemloft.net Subject: Re: [PATCH] iommu-common: Do not use 64 bit constant 0xffffffffffffffffl for computing align_mask References: <20150719121653.GA30645@oracle.com> <20150719152724.GB3729@roeck-us.net> <874mkzevz4.fsf@rasmusvillemoes.dk> In-Reply-To: <874mkzevz4.fsf@rasmusvillemoes.dk> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated_sender: linux@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: linux@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2328 Lines: 67 On 07/19/2015 01:25 PM, Rasmus Villemoes wrote: > On Sun, Jul 19 2015, Guenter Roeck wrote: > >> On Sun, Jul 19, 2015 at 02:20:14PM +0200, Sowmini Varadhan wrote: >>> >>> Using a 64 bit constant generates "warning: integer constant is too >>> large for 'long' type" on 32 bit platforms. Instead use ~0l to get >>> the desired effect. >>> >>> Detected by Andrew Morton who has confirmed that this patch >>> fixes the warning on i386/gcc-4.4.3, i386/gcc-4.4.0 and arm/gcc-4.4.4. >>> >>> Signed-off-by: Sowmini Varadhan >>> --- >>> lib/iommu-common.c | 2 +- >>> 1 files changed, 1 insertions(+), 1 deletions(-) >>> >>> diff --git a/lib/iommu-common.c b/lib/iommu-common.c >>> index df30632..fd1297d 100644 >>> --- a/lib/iommu-common.c >>> +++ b/lib/iommu-common.c >>> @@ -119,7 +119,7 @@ unsigned long iommu_tbl_range_alloc(struct device *dev, >>> unsigned long align_mask = 0; >>> >>> if (align_order > 0) >>> - align_mask = 0xffffffffffffffffl >> (64 - align_order); >>> + align_mask = ~0l >> (64 - align_order); >>> >> Wonder if this just hides the real problem. Unless align_order >> is very large, the resulting mask on 32 bit systems may be 0. >> Is this really the idea ? > > Probably not, but that's not what would happen on x86: the shift > only depends on the lower 5 or 6 bits - I don't know if other platforms > also has that behaviour. So for align_order == 2 and x86_32 we'd > effectively end up with a shift of 62 & 31 == 30 (though technically > undefined behaviour), and the desired mask of 0x3. > #include main(int argc, char **argv) { unsigned long am1, am2, am3; int align_order = 2; am1 = 0xffffffffffffffffl >> (64 - align_order); am2 = ~0l >> (64 - align_order); am3 = ~0ul >> (64 - align_order); printf("0x%lx 0x%lx 0x%lx\n", am1, am2, am3); } yields an output of 0x3 0xffffffffffffffff 0x3 So either case ~0l appears to be wrong; it should be ~0ul. I don't know if ~0ull makes a difference for some architectures. Guenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/