Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4859722imu; Sat, 19 Jan 2019 21:12:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN5cSHmIyO3IncHilQQ94b7YkblfFlupOBH6usGKp93ihivjtEoBhZC6QNW2auXt4UZU39X5 X-Received: by 2002:a63:68c4:: with SMTP id d187mr23324835pgc.11.1547961172836; Sat, 19 Jan 2019 21:12:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547961172; cv=none; d=google.com; s=arc-20160816; b=rDCQB5xeLacnG9QOwoXZ1DFF7WQnLUNkXFEUI/UCtMCmPciYn9fRrHf+JykLADmCGa EzAZkOvODn5pCX9b6HuYsLgLdI6EGYo8ZIxKWWnRlwFtcJPOwdvszpAXCohJ2p2TqKOv 86cXYJQEGrMGmgmIk6bXRXk3pZ+wdLt2Qbf2C1Fcw87DGDFBfm34Maa9WhjM2uEAktI1 6/UWZbtlaUmdvZXPXNzn4OFdSLiTO6YprLO9zvVU/Gi1kTU34hlvkz4s6C2ahcK/MiJd TpagYUwcgFNJk5E/BoDmSmHQ/3FxJn/OdO/MeseD+uWKDsVPAjBmVzjcAP0/JU6A7Xs1 McSw== 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=i4j2/vVvcJi3rETqZUhpc+ncR58zk37mkzeG2NhCK74=; b=RsGsbqGue0K1KUt8tXr/yGRTSNACRWCqKLv9mC6MqFyHot5mrmTCmubpYJQkyjgoEG Ag163F+2NQ1UtRh44jtcJc+C8DRGpX+WYaoHgDUHQVx2YwWIFzRfipBFnRDSOEkvC+M8 ycg8vcXbTKn+SkyrMnP/A5N2/y5md8B8iQKWoi+n07UExErJ2Nkrqma/2+BHvVrO0hNQ rp40gUkY+ytiGWm5H4h0L7D4gHjwFCgoQr6XM8bNUlVEeZ81/H8az8o8cSi5FF2qVaew l+BpAMCdcXJnkIoJ6UORYNF5wOQAq1ZC93vRCA0/8IDRwt+bSxjami7i43j558ty3fff F7Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QqY94NTo; 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 z123si59537pfc.97.2019.01.19.21.12.36; Sat, 19 Jan 2019 21:12:52 -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=QqY94NTo; 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 S1726133AbfATFLf (ORCPT + 99 others); Sun, 20 Jan 2019 00:11:35 -0500 Received: from mail-lj1-f180.google.com ([209.85.208.180]:42464 "EHLO mail-lj1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725923AbfATFLe (ORCPT ); Sun, 20 Jan 2019 00:11:34 -0500 Received: by mail-lj1-f180.google.com with SMTP id l15-v6so14823764lja.9 for ; Sat, 19 Jan 2019 21:11:33 -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=i4j2/vVvcJi3rETqZUhpc+ncR58zk37mkzeG2NhCK74=; b=QqY94NTo+rm3rhGMAvPfgFk+TDVb7XF5eX2FpPwsP64JmaQ5g/rLWBQBUAElC6kdGI AIlWBoj8VZJj3QQ53yVucSnDmBl31EpRtou3IeQ+o6dVbs7QtForxRhooF1OLpKGgRVH RoTsFygLKvxJrOqa7TOqLmjzM39x3P6Fi3UCg= 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=i4j2/vVvcJi3rETqZUhpc+ncR58zk37mkzeG2NhCK74=; b=anp+7x840vrQ3e/MhOeVbxR5kodVZMpJGIa/zz0dvf0Jaj3hYgj6tJrw55cCOwKoEl UDozm72FguDoHSOMXexYH83b1iEcqLf3+Ice+wA/vx7k/kLxje27FG14S7I4amb8lI64 GJ5NoBX2wV8OMjrvHIx1h01tQQQtU52E0uaX33uZU1oIWtN3sdKPaNI+WTzP2ennWpJS vNWxO4Diifq8BMfTqxZGO4uezXd3f5UShaxjYlmAEOTO0PAjLMQfypzYX/gxE/D5EzKK GOJLXI329tc/yK+G2ALEf9JYznMe/2/Pg2FLXLRkuwrj8qVXPbVbJsg08NTHvBirF4BG ISnA== X-Gm-Message-State: AJcUukfdw8elCm7TLk0xFoNiHx0GOaqvsnA+w2OlJSAYDuGculUP3u61 jYGz5GrRHCahrufIoYpYsZOAoadwSsTGYQ== X-Received: by 2002:a2e:9107:: with SMTP id m7-v6mr15109378ljg.23.1547961092252; Sat, 19 Jan 2019 21:11:32 -0800 (PST) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com. [209.85.208.178]) by smtp.gmail.com with ESMTPSA id u65sm1650982lff.54.2019.01.19.21.11.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Jan 2019 21:11:31 -0800 (PST) Received: by mail-lj1-f178.google.com with SMTP id t9-v6so14843409ljh.6 for ; Sat, 19 Jan 2019 21:11:31 -0800 (PST) X-Received: by 2002:a2e:2416:: with SMTP id k22-v6mr16448752ljk.80.1547961090973; Sat, 19 Jan 2019 21:11:30 -0800 (PST) MIME-Version: 1.0 References: <20190119151450.26879-1-Florian.LaRoche@googlemail.com> <20190120000138.GI26876@brain-police> In-Reply-To: From: Linus Torvalds Date: Sun, 20 Jan 2019 17:11:14 +1200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: fix int_sqrt() for very large numbers To: Florian La Roche Cc: Will Deacon , Linux List Kernel Mailing , Crt Mori , Joe Perches , Davidlohr Bueso , 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 5:03 PM Florian La Roche wrote: > > The real bug is that we compute 1 to 64 for bit 0 to bit 63, whereas > the algorithm expects 0 to 63 for the value of m. Florian, you seem to be in denial. __fls() returns 0-63. Your patch is *wrong* for the __fls() use, because when you subtract 1, you get -1 to 62, and the -1 now introduces the very undefined behavior you claim your patch fixes. So your patch fixes one real case (int_sqrt64(), that has one user that doesn't care) but it *BREAKS* the other case that is actually much more widely used (int_sqrt()). See what Will and I are complainig about? Linus