Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6629762imu; Mon, 21 Jan 2019 12:28:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN6ViDXkMDjXLRpv2Uuz79tF6QCAd8Es3082yb9vMztJ93Z2rTUPfLza/ti5N4KzgGArf4T1 X-Received: by 2002:a17:902:680f:: with SMTP id h15mr31025592plk.40.1548102522258; Mon, 21 Jan 2019 12:28:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548102522; cv=none; d=google.com; s=arc-20160816; b=opasrUMz6h4IXKxPAC+DxljrZA8p/PBl5C86zTzWZkdRQV67TxvD4sJBIhqd57v4ck t4X04oUBhQJnBz/LOMzsziu4TE/lavn1ml+f3fO2Hqplode4jQtjfTT3qJG7gL0gVaQC /Ccd2Q1ZWrJB+u9UKcdhGUhVMBjN1MiDWC9kfs/UK4rYeaBKW7IMowwbtbUMZjCnDRXc OEeNfL8jy03EAaR7EqnJM+B+pNQwIYfEoPIulciCSyFH1IRZnlT1ekLv9Q8cuTpkTqlO kclrUMVLpZeThhk1IYqoZ84r/U03/y+pJYUBgR7HkhECfnTqo+HBj5b+IDA9yT6/VJHe xUdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=wVMi40kJJBnZyDdlQUsJhig7OCy1+OLmvOMehMVnCgk=; b=CHViOeyE4LHOZSNtBl9x1zoNnLQbO5WfKDyN10+Ht2t7HxU8ovWMPyd4aUtJ9Nizvn ZdC1Hloerg4w20F61LOyB4g4YngTpPd68rzlfzdNR54xeL8Sc1HB3lLaQ+P/AsQiWemN 5pugCX9NnELbz+76WkEI5PLg9hmIUO081/YFejPrJiEjAldpYLKmoXd0gFOvUuVIB2c4 2HDd3/6ImBQ/ZzZ1aU2vOf0zeU1WXrlmNUXQi/Qy67VV/3lmUIWWeMBuuYyPvYjt5RrX nDQ3p6BgJ5EUUQrePmiQe61knNfjXn9P2TH4xKG14WoeseEXy3qi1++HdK4ULx/+I3dO i+9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@melexis.com header.s=google header.b=duNSyzCn; 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 z129si9020047pfz.13.2019.01.21.12.28.25; Mon, 21 Jan 2019 12:28:42 -0800 (PST) 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; dkim=pass header.i=@melexis.com header.s=google header.b=duNSyzCn; 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 S1728194AbfAUUZi (ORCPT + 99 others); Mon, 21 Jan 2019 15:25:38 -0500 Received: from mail-vk1-f196.google.com ([209.85.221.196]:45079 "EHLO mail-vk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727012AbfAUUZh (ORCPT ); Mon, 21 Jan 2019 15:25:37 -0500 Received: by mail-vk1-f196.google.com with SMTP id n126so4846947vke.12 for ; Mon, 21 Jan 2019 12:25:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wVMi40kJJBnZyDdlQUsJhig7OCy1+OLmvOMehMVnCgk=; b=duNSyzCnehl4IWXlHY9/nwFXPPbRsApqPg96nwTBFXqJ9F0hyyQAIP9EMtqeXoubV3 wqhdcEYvOQwydFBL/FCbTe4WXvYZ8459t51T/Bnfax/n91nJsDDa+CRiE+MDHzY30Udo B0wbVWGPy+082BrAeYxKisee1gPKusjvmB0yu6uTez2rwqKZYH3fpbMJTfOUqiEKeBoT r6YNFKX0YqAWqINc+iX3cO30P+64Rzk+nzt6DO9wjcSSsh3fXpa/vugkHWV/FASuaQij ZEjPh7Qf0w9RhCiLPba2mH8B7FLNtZA35yXXXIqhFf3D4SsRA5cfu+h6jnBO5szsYlT4 Srjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wVMi40kJJBnZyDdlQUsJhig7OCy1+OLmvOMehMVnCgk=; b=HTcqJq4N8+RULUmNrz+p1pdG+O+pwPDartPjlWVRbZXh8NkKJxcecW6xHX7FGSGUxv IQxKa9fJ0YOtMcvHmF21xLzUR4nNMjqcMAEp8hVB0Ln3MqcOBGmQ8iFVKS4Ib4N1w9dL xPhN7ht3JDCXy0IXH2nQkPSHE9hxLQqOQKAl5EKul4syH3OREWlvxAfmNRkrWg556IMy hlJAcUoxTlgOtA8tDXGKh5D0EiegnDz8fViK2HVqlBAxlN3FQ9SA+3jOvSNd+as/I3Cd v108g2knWK/LRxBR29rxTk56hAJREsIY7NvUKGDDy7E43zW+YjAhCqtxmGiDh99OvXWJ R8Og== X-Gm-Message-State: AJcUukfN87eq7irYuJNCWI5RYQ9cf5Uve3GDbxEB+W9WBxlxbcZcfKr3 4WnjV6TXxE5mfQu6u0JbUx2UabG3lvkdXwXzGjbJtA== X-Received: by 2002:a1f:4d47:: with SMTP id a68mr12083806vkb.34.1548102336281; Mon, 21 Jan 2019 12:25:36 -0800 (PST) MIME-Version: 1.0 References: <20190119151450.26879-1-Florian.LaRoche@googlemail.com> In-Reply-To: From: Crt Mori Date: Mon, 21 Jan 2019 21:25:00 +0100 Message-ID: Subject: Re: fix int_sqrt() for very large numbers To: Linus Torvalds Cc: Florian La Roche , Linux List Kernel Mailing , Joe Perches , Davidlohr Bueso , Will Deacon , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 21 Jan 2019 at 01:20, Linus Torvalds wrote: > > On Sun, Jan 20, 2019 at 4:15 AM Florian La Roche > wrote: > > > > @@ -52,7 +52,7 @@ u32 int_sqrt64(u64 x) > > if (x <= ULONG_MAX) > > return int_sqrt((unsigned long) x); > > > > - m = 1ULL << (fls64(x) & ~1ULL); > > + m = 1ULL << ((fls64(x) - 1) & ~1ULL); > > I've applied this part of the patch as commit fbfaf851902c ("fix > int_sqrt64() for very large numbers") with slightly edited commit > log. > Thanks for the patch - I its indeed my copy-paste error, because __fls64 does not exist on 32bit CPU, but the fls64 is not "equal" replacement. I am very sorry for the bug. > I still think there are some oddities in here in the types. I > mentioned the caller that unnecessarily does the int_sqrt64() twice, > even though the outer one doesn't actually take a 64-bit value. > True. This is oddity is originating from time where mlx90632 used its own function for int_sqrt64 on 32bit. > But in the very line above, there's another type oddity: the "& ~1ULL" > is entirely the wrong type. The shift *count* shouldn't be an unsigned > long long, so that type doesn't make much sense. It should be just a > ~1, or even just "62". > This was also inline with above copy-paste and variable expansion to force the 64bit everywhere. I will prepare a patch to clean this line to ~1, question is why does the int_sqrt is having UL if this should just be "62". I was thinking because we want to cast to the type before we shift. > But I didn't actually start micro-editing the patch, and just did that > one-liner off-by-one fix. > > Linus