Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5920120imu; Sun, 20 Jan 2019 23:27:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN49F/jwBfZeUIbrDSc9CauJ2zzaGFp4uDvJtQRXkJodGsfpdP/KmeTBu//xRZCfGzleCZ+a X-Received: by 2002:a62:6047:: with SMTP id u68mr28422649pfb.239.1548055623766; Sun, 20 Jan 2019 23:27:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548055623; cv=none; d=google.com; s=arc-20160816; b=HLKebZe9QwdFKDum6zSnD57CxOjqCFTKyBoSzHd9U7/BlbLOQRO8fCOtOjGgjHhm7/ 9jW9PGLoBZlRC06hdcxbxoK3f7ffnH0bYQMF87XhmgGfOESZjGogDGtlE4lAphyRNhVN EoTsJ9ZaYjjZy5Xolqh7dzYO6YSYiStPIltuzCl9inH5/lvbI2p5Do6Qs3dhW6QGY2ZZ CxEvJlIthJG/PlctDwV8zCd5DhvnjZQpsF6FPf/Yv4Oc31YCZ63QZvzHeFnUdYPaRwb5 1a3Oi07333+8FS5tqkOlSYfqfH8S+Hpc16EKeLQVoYMs6O2wF0xnkhAcDNJiFi4/75EG 4uSw== 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=uQDXfJo7O5/gGYsKedHfd/nh8URHDQGpNW0T5zwmORk=; b=Zw+WI5DTSQdmFFRNxlmZ+lMKmVLrguDLhIBNENqVHrmiLD5pFjDW1Ne+XM5PNQI06a Su3ozomfYeNV43atTFMfKjCxRwzxm9XnNEf776lJCRu8c0eJg7pnJkyO9XRgq8ET878/ A+HWnJUMwY+IPm9ooEtGPj1QOlS59iSfVuvUOR+AIKlAUXQfEnnQIxiamIPuM1xw49lx 0qOnadecs5S9Wr98dLWVg45hRxX3cJsE/1xXW1L+zbVnjYhQ5yjhlsBilKyupSe48sak o0FYswCQZT/Ypbx0K+MNxhx410NknyAUNfyqyXN0GLnz4/PvSVMYeDGW1EycstnV45HN LoZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=GIlNGDnw; 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 z12si11788483plk.90.2019.01.20.23.26.48; Sun, 20 Jan 2019 23:27:03 -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=@linux-foundation.org header.s=google header.b=GIlNGDnw; 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 S1728014AbfAUHZA (ORCPT + 99 others); Mon, 21 Jan 2019 02:25:00 -0500 Received: from mail-lf1-f47.google.com ([209.85.167.47]:43079 "EHLO mail-lf1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbfAUHZA (ORCPT ); Mon, 21 Jan 2019 02:25:00 -0500 Received: by mail-lf1-f47.google.com with SMTP id u18so14693349lff.10 for ; Sun, 20 Jan 2019 23:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uQDXfJo7O5/gGYsKedHfd/nh8URHDQGpNW0T5zwmORk=; b=GIlNGDnwwUVWobI/4+XIOJWuys3rT2e4nwv6+epSQbLR6ou/krTEHjcLw1yBQxOTTY IL3bEexmAlXVEGQciXJ9/uvKwx6asT3RK7SXsljF9HomNvcFTOTE3OwFbIQtbpeciiAI zsbyI7BiXGP1+SD75edqoCS38WUX9hyeaqXCA= 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=uQDXfJo7O5/gGYsKedHfd/nh8URHDQGpNW0T5zwmORk=; b=esPdQv4ct0m7+u8Kp21nSuB7DfS1CwyNwJTp0EDQdS6gCwv3hCb6RRwgjwFkU3CS/V j9FaPBpfo8CdetIZDyYX5FK5bnzpH5lyZ3ndn0PYmZadfsh7cSKeTFJFmFuC9XgIelVn eSo/z209CPmwG6FPJDV3iLgPavAhJByDCx8QLNTFIX1e8jbDUi/5qPufvWBRmi97Q/xS Dft53Iln3Ebu0SGUvya8KmS5OWGAq2J/rkYOjZWQ1nVj6frnDsGsshviGlGJgncCbA33 agLhkTxytzuN3Xu7HnBqT/XziQ63TxUKzjaNxBh+xmpwlpbBvQ0nTJJ0f4hxE6hdk8gF uSlw== X-Gm-Message-State: AJcUukckBY0MWP4yW4lID4dt/Q4+Z+v4XAJEquOtXocDzhCtL7nNtN9w 8GoQAPZOHtoiYBFAdazLZJVRR4V0WNkBSA== X-Received: by 2002:a19:280f:: with SMTP id o15mr16591330lfo.0.1548030051585; Sun, 20 Jan 2019 16:20:51 -0800 (PST) Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com. [209.85.167.44]) by smtp.gmail.com with ESMTPSA id v19sm1959214lfe.69.2019.01.20.16.20.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 16:20:50 -0800 (PST) Received: by mail-lf1-f44.google.com with SMTP id e26so14239321lfc.2 for ; Sun, 20 Jan 2019 16:20:50 -0800 (PST) X-Received: by 2002:a19:cbcc:: with SMTP id b195mr17728493lfg.117.1548030049631; Sun, 20 Jan 2019 16:20:49 -0800 (PST) MIME-Version: 1.0 References: <20190119151450.26879-1-Florian.LaRoche@googlemail.com> In-Reply-To: <20190119151450.26879-1-Florian.LaRoche@googlemail.com> From: Linus Torvalds Date: Mon, 21 Jan 2019 13:20:33 +1300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: fix int_sqrt() for very large numbers To: Florian La Roche Cc: Linux List Kernel Mailing , Crt Mori , 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 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. 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. 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". But I didn't actually start micro-editing the patch, and just did that one-liner off-by-one fix. Linus