From patchwork Sun Jun 4 08:12:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Levin, Alexander \(Sasha Levin\)" X-Patchwork-Id: 101348 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp439844qgd; Sun, 4 Jun 2017 01:13:31 -0700 (PDT) X-Received: by 10.84.231.16 with SMTP id f16mr8465374plk.259.1496564011140; Sun, 04 Jun 2017 01:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496564011; cv=none; d=google.com; s=arc-20160816; b=t7HdeqSAMOCnMCQbyz48pzCtj6mXH2JKhLeFGb7prBAPmoIDpk+4dKEVdU/bona96S BPjfhAwP5Ka0TAszkFDhGYc6jovzkMjipRXsx+cBf4P5YqNVyFRzZNBT91AJHHRJhcCY Hz3tqSlRwCqZK+ohFo7PH0ZXK04jw0s2thcWeYmaYmhTTBxlZRO3sVINiwUYXXSimy4r yVf+4B34ufAVNTaCnUd90j3IKS7nRh8Mh9cIlFNL0TaObbLa3s+X0uRDUtRmXrZhLe+Q h/k4DismMUNYWOPF+K5f6I0v3hilv6j2m9l6GfEaKfR6y/LOzyb+PtBKwRw4MgHbiv/z 6JAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:to:dkim-signature:cc:from :dkim-signature:arc-authentication-results; bh=FecJ+OBXfirWyUjNX/yMTspJ9cTYxYijisTOjh97bl4=; b=tU4mpyqZdUK/wQn96Otp16JYNmHsfYUwe/jTwiUxbFuuzq01CaHbCvK1xKeaYp9bj9 Zt8qXNn26iG1WjP6Fkc69ibdQigOnt6cba7X+A4v0jOFnjGH+XkEH1jClRb4nmEBRLsl kHplyIij5MqUl3Doo7ADRzTm85fc9CPRasdSLJwVXOt05c23EnVz0BzW+4o6Ffr5D67b f73RUwb1gMmePw78u9GCjNHyGjORCs3FqdeOWmzNOjwkm4Uh2MUKB+S0mvslvEN4u0Nu hzENSHjkgr8xy0K/MZHcZ5HGK8xnNEVPGCbWmgYLGKOB6olCYO9VL1B7GIxb9QNICptP ORDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@verizon.com; dkim=fail header.i=@verizon.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j17si27669684pfj.239.2017.06.04.01.13.30; Sun, 04 Jun 2017 01:13:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@verizon.com; dkim=fail header.i=@verizon.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=verizon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751258AbdFDINa (ORCPT + 6 others); Sun, 4 Jun 2017 04:13:30 -0400 Received: from omzsmtpe02.verizonbusiness.com ([199.249.25.209]:40917 "EHLO omzsmtpe02.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751213AbdFDINM (ORCPT ); Sun, 4 Jun 2017 04:13:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1496563992; x=1528099992; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=U6PeU6FB2gA2USq6uChQHLsZd5iTk8wVh8RLiQFW5Dk=; b=n9uGVeqeykyYLq7OPdxgrZRhRqGd/NANHIYeErMvJBNYlSkI0MBJ/eY7 S27aj+tF0t0BY/dWV9Sq89UZRFkpl3sL5OPW5qEcs6dzTszK6ck3O3Zqa uH9syEqjIpLFvQUKBsAKugEy3daaNvqq0Lexn4kqNARGXbB/O0ywjVuxh g=; X-IronPort-Anti-Spam-Filtered: false Received: from unknown (HELO fldsmtpi03.verizon.com) ([166.68.71.145]) by omzsmtpe02.verizonbusiness.com with ESMTP; 04 Jun 2017 08:13:00 +0000 From: "Levin, Alexander (Sasha Levin)" Cc: Ard Biesheuvel , Linus Torvalds , "Levin, Alexander (Sasha Levin)" X-IronPort-AV: E=Sophos;i="5.39,295,1493683200"; d="scan'208";a="364211578" Received: from nord.tdc.vzwcorp.com (HELO Nord.verizonwireless.com) ([10.254.88.187]) by fldsmtpi03.verizon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 04 Jun 2017 08:12:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1496563961; x=1528099961; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=U6PeU6FB2gA2USq6uChQHLsZd5iTk8wVh8RLiQFW5Dk=; b=ogZGBcB4V+39YcM/OYE/AyerryU1/NwRzgIT1dqK8t1+QsChsrXOeqYf Oduko25sevhLGAcpQBfhuH2FYAJzo+RY0rdzT2nJJ83j8T4KIiDgc7R49 l0pfemXN/Vp3BtEaSxJsVcDC6atrH4oIrEPmpxWkI1/WijGSRoI845fuF E=; Received: from gaalpexhub4.uswin.ad.vzwcorp.com ([10.191.138.113]) by Nord.verizonwireless.com with ESMTP/TLS/AES256-SHA; 04 Jun 2017 04:12:40 -0400 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) by gaalpexhub4.uswin.ad.vzwcorp.com (10.191.138.113) with Microsoft SMTP Server (TLS) id 8.3.406.0; Sun, 4 Jun 2017 04:12:40 -0400 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) by OMZP1LUMXCA17.uswin.ad.vzwcorp.com (144.8.22.195) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Sun, 4 Jun 2017 03:12:38 -0500 Received: from OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) by OMZP1LUMXCA17.uswin.ad.vzwcorp.com ([144.8.22.195]) with mapi id 15.00.1263.000; Sun, 4 Jun 2017 03:12:38 -0500 To: "stable@vger.kernel.org" Subject: [PATCH for v4.9 LTS 033/111] log2: make order_base_2() behave correctly on const input value zero Thread-Topic: [PATCH for v4.9 LTS 033/111] log2: make order_base_2() behave correctly on const input value zero Thread-Index: AQHS3QpCM7uDYJwyBE6gckDfYqKQkA== Date: Sun, 4 Jun 2017 08:12:08 +0000 Message-ID: <20170604081123.19462-33-alexander.levin@verizon.com> References: <20170604081123.19462-1-alexander.levin@verizon.com> In-Reply-To: <20170604081123.19462-1-alexander.levin@verizon.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.144.60.250] MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ard Biesheuvel [ Upstream commit 29905b52fad0854351f57bab867647e4982285bf ] The function order_base_2() is defined (according to the comment block) as returning zero on input zero, but subsequently passes the input into roundup_pow_of_two(), which is explicitly undefined for input zero. This has gone unnoticed until now, but optimization passes in GCC 7 may produce constant folded function instances where a constant value of zero is passed into order_base_2(), resulting in link errors against the deliberately undefined '____ilog2_NaN'. So update order_base_2() to adhere to its own documented interface. [ See http://marc.info/?l=linux-kernel&m=147672952517795&w=2 and follow-up discussion for more background. The gcc "optimization pass" is really just broken, but now the GCC trunk problem seems to have escaped out of just specially built daily images, so we need to work around it in mainline. - Linus ] Signed-off-by: Ard Biesheuvel Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/log2.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/include/linux/log2.h b/include/linux/log2.h index f38fae23bdac..c373295f359f 100644 --- a/include/linux/log2.h +++ b/include/linux/log2.h @@ -194,6 +194,17 @@ unsigned long __rounddown_pow_of_two(unsigned long n) * ... and so on. */ -#define order_base_2(n) ilog2(roundup_pow_of_two(n)) +static inline __attribute_const__ +int __order_base_2(unsigned long n) +{ + return n > 1 ? ilog2(n - 1) + 1 : 0; +} +#define order_base_2(n) \ +( \ + __builtin_constant_p(n) ? ( \ + ((n) == 0 || (n) == 1) ? 0 : \ + ilog2((n) - 1) + 1) : \ + __order_base_2(n) \ +) #endif /* _LINUX_LOG2_H */