From patchwork Mon Mar 19 15:47:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132097 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp130546ljb; Mon, 19 Mar 2018 15:38:54 -0700 (PDT) X-Google-Smtp-Source: AG47ELsNrQ9YiDcPRz/Bwexkt4wMkjf8XBaqHghGEOKJyF/o6Uv+E3mxzT86MctU8g1AaLzyUKrV X-Received: by 10.98.32.134 with SMTP id m6mr11675012pfj.27.1521499134131; Mon, 19 Mar 2018 15:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521499134; cv=none; d=google.com; s=arc-20160816; b=EV2Mv7Gp2g95qIpELGyTvqjrl+NJlGTdoHUwvUNl9Fnp4Uc6LUfn8mis6Zis0822Fn f9nfiYrN4Ozz1e7cUCzy0UskTaSu69yR8UJ8zeLYrPl4InDgxsX/5/AgySKosABSbSLH u6wG8wQ/W/M0fVWA8yWbLsfMlQgzwIyelhw/CGkd5KMf8E1repU1dJbSeGCPJHvAzo3n Nu+ysXfUccinf/w4TB9axnBhyLiOvvRC7C20Y/dnSgKFNdYO7UdvV19p1CMihVeKDxy7 23K1GjqZsKvHuSND+3+6hiqCiQ46EYA1MRPISJmyWBgSaVGqkpq1m2Ny/d/ivxp5rmS4 cjLg== 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 :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=DCBVMsMw//Gdt/8M57LnVssVIvYys2kQfkg8NtAXa3g=; b=cdOt5+XYEsp7lf5qwkeXZZGItv66wUtQpeLFomnAdkLzf+RCswVEQPygCaue7oDHKK 6SrjL/ZEgVhXjBT31MMPx9ZM6z4b7MtNDp4CXLAxaTWhIqTRThHeH2/Rx7WiXcAVfjCw ws42V2UCkEEEw3MIPHhHk1QWmSVyW4KZyuj9zQr39wIL0w/AXCvsuFCV56SPvV2zqxOj AzmgBf7wzL9v+nDbXeyvYtc2VmmmB0zSszxkiW8UNpci5DQ6Ns+mSncvH/UFcBzEDfw9 M0YlkzObdIKZAolAoCSbfeukZzqf+rWwFofKeczXqejVtx9wRv5Pj0btvpABLh7G85+y kO2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=e5I3X6xb; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x61-v6si218486plb.741.2018.03.19.15.38.53; Mon, 19 Mar 2018 15:38:54 -0700 (PDT) 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=@microsoft.com header.s=selector1 header.b=e5I3X6xb; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936618AbeCSWiu (ORCPT + 28 others); Mon, 19 Mar 2018 18:38:50 -0400 Received: from mail-co1nam03on0122.outbound.protection.outlook.com ([104.47.40.122]:59200 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933400AbeCSPrb (ORCPT ); Mon, 19 Mar 2018 11:47:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DCBVMsMw//Gdt/8M57LnVssVIvYys2kQfkg8NtAXa3g=; b=e5I3X6xbHKxro0X0B0uVqgnCQaRBqvze34r8ApQNqfPZH0MMQe0FBFPjnMZXKurUW+wcJTFHxGBEtYxxErWSpnty3Yf45Nil2t97liIdVfgMcC8xvsYJ1D4Ygmxau6Yd8YrDfWKyzzT7tgQbaQgG6z0lokXrVxat8eQdu8JyoYg= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0998.namprd21.prod.outlook.com (52.132.133.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.0; Mon, 19 Mar 2018 15:47:27 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:47:27 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Jerome Brunet , Stephen Boyd , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 023/124] clk: divider: fix incorrect usage of container_of Thread-Topic: [PATCH AUTOSEL for 4.15 023/124] clk: divider: fix incorrect usage of container_of Thread-Index: AQHTv5mSP2zHaZ4cq060CURoHsqBPQ== Date: Mon, 19 Mar 2018 15:47:22 +0000 Message-ID: <20180319154645.11350-23-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB0998; 7:t1miwE1ZjwpwO2E2FJJLXOJnxN+zuf2kPEnHJQYOI2SqnV7i1Teqex0sm4oK20iPnFMl82DMmYAcg6wdY/rMtcIeGYHyrFaM05f7eflHip1kgzMH10SJX57L+TaxGBMiNUTzYiEV1JN1EAqfVDh3jSDtbosUnAn6sHFHznQedjVnwzvqhb88FbllTXxxAQ3TZCadSh2V1NE9WRNuGLyyf/TvrUZjbXUn65VtsGygGTovsR8kH+AkdtK0U16JZhA/; 20:wWuNg7qLTd/F/+mUio+NTMkkQPRLd1kUvMvt+IP3qgtJUcHluyQAqehBI7XI4LMWUzyDjJp536FG9JLiTFHSuWjhVujqbUj/grNczxVFflN68RSFttYAzj4VnhMITOR+ndesnBaYwcapse+mNutEy8doI9XF4dKEmib+BYTJm+M= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: c5916d68-80cc-4c36-38ef-08d58db0b791 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:DM5PR2101MB0998; x-ms-traffictypediagnostic: DM5PR2101MB0998: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158)(58145275503218); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231221)(944501300)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:DM5PR2101MB0998; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB0998; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39380400002)(39860400002)(366004)(376002)(396003)(346002)(199004)(189003)(3846002)(6116002)(8936002)(6486002)(102836004)(68736007)(6506007)(2900100001)(22452003)(25786009)(3660700001)(7736002)(76176011)(6512007)(72206003)(86362001)(53936002)(8676002)(81156014)(6436002)(81166006)(305945005)(478600001)(99286004)(2950100002)(14454004)(6666003)(10290500003)(186003)(107886003)(2501003)(106356001)(26005)(86612001)(97736004)(5660300001)(10090500001)(110136005)(54906003)(316002)(2906002)(66066001)(105586002)(4326008)(36756003)(3280700002)(1076002)(5250100002)(59450400001)(22906009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB0998; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 7xYmSaJ3f8UxD+2gU56PcfgdVO+Cos0EnseA84lBwWDhyFiVM5oDxeXTzlC5KYRYv2g5zgwdZA2FWbrmxv2frA7FNxdex7yZXdJFNOFFRHiUDf41qO8JwBhZNAhMKmgns0LoaIUaH1Qszyl2N9LrlMpXDLK8gjtxA6KgH5pM3/yqXkJ62YXs6ydBm42fq7h82dxt3uNwh7KlUEAFWs9+UnJEeYVTgvJtcJ+cKLkEy+QuFu0xcuGCnYKRkPbavc+JX66K0ZmcU13P8b8gwglPMTnbGc/CfQ+R1n0ie3eNOlaReqEEcxGMavPbF9wYBBOK04OeKqY4WDy5sclm7MDwqw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: c5916d68-80cc-4c36-38ef-08d58db0b791 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:47:22.7797 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0998 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jerome Brunet [ Upstream commit 12a26c298d2a8b1cab498533fa65198e49e3afd3 ] divider_recalc_rate() is an helper function used by clock divider of different types, so the structure containing the 'hw' pointer is not always a 'struct clk_divider' At the following line: > div = _get_div(table, val, flags, divider->width); in several cases, the value of 'divider->width' is garbage as the actual structure behind this memory is not a 'struct clk_divider' Fortunately, this width value is used by _get_val() only when CLK_DIVIDER_MAX_AT_ZERO flag is set. This has never been the case so far when the structure is not a 'struct clk_divider'. This is probably why we did not notice this bug before Fixes: afe76c8fd030 ("clk: allow a clk divider with max divisor when zero") Signed-off-by: Jerome Brunet Acked-by: Alexandre Belloni Acked-by: Sylvain Lemieux Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/clk-divider.c | 7 +++---- drivers/clk/hisilicon/clkdivider-hi6220.c | 2 +- drivers/clk/nxp/clk-lpc32xx.c | 2 +- drivers/clk/qcom/clk-regmap-divider.c | 2 +- drivers/clk/sunxi-ng/ccu_div.c | 2 +- drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c | 2 +- drivers/rtc/rtc-ac100.c | 6 ++++-- include/linux/clk-provider.h | 2 +- 8 files changed, 13 insertions(+), 12 deletions(-) -- 2.14.1 diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 4ed516cb7276..b49942b9fe50 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -118,12 +118,11 @@ static unsigned int _get_val(const struct clk_div_table *table, unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate, unsigned int val, const struct clk_div_table *table, - unsigned long flags) + unsigned long flags, unsigned long width) { - struct clk_divider *divider = to_clk_divider(hw); unsigned int div; - div = _get_div(table, val, flags, divider->width); + div = _get_div(table, val, flags, width); if (!div) { WARN(!(flags & CLK_DIVIDER_ALLOW_ZERO), "%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n", @@ -145,7 +144,7 @@ static unsigned long clk_divider_recalc_rate(struct clk_hw *hw, val &= div_mask(divider->width); return divider_recalc_rate(hw, parent_rate, val, divider->table, - divider->flags); + divider->flags, divider->width); } static bool _is_valid_table_div(const struct clk_div_table *table, diff --git a/drivers/clk/hisilicon/clkdivider-hi6220.c b/drivers/clk/hisilicon/clkdivider-hi6220.c index a1c1f684ad58..9f46cf9dcc65 100644 --- a/drivers/clk/hisilicon/clkdivider-hi6220.c +++ b/drivers/clk/hisilicon/clkdivider-hi6220.c @@ -56,7 +56,7 @@ static unsigned long hi6220_clkdiv_recalc_rate(struct clk_hw *hw, val &= div_mask(dclk->width); return divider_recalc_rate(hw, parent_rate, val, dclk->table, - CLK_DIVIDER_ROUND_CLOSEST); + CLK_DIVIDER_ROUND_CLOSEST, dclk->width); } static long hi6220_clkdiv_round_rate(struct clk_hw *hw, unsigned long rate, diff --git a/drivers/clk/nxp/clk-lpc32xx.c b/drivers/clk/nxp/clk-lpc32xx.c index 7b359afd620e..a6438f50e6db 100644 --- a/drivers/clk/nxp/clk-lpc32xx.c +++ b/drivers/clk/nxp/clk-lpc32xx.c @@ -956,7 +956,7 @@ static unsigned long clk_divider_recalc_rate(struct clk_hw *hw, val &= div_mask(divider->width); return divider_recalc_rate(hw, parent_rate, val, divider->table, - divider->flags); + divider->flags, divider->width); } static long clk_divider_round_rate(struct clk_hw *hw, unsigned long rate, diff --git a/drivers/clk/qcom/clk-regmap-divider.c b/drivers/clk/qcom/clk-regmap-divider.c index 53484912301e..928fcc16ee27 100644 --- a/drivers/clk/qcom/clk-regmap-divider.c +++ b/drivers/clk/qcom/clk-regmap-divider.c @@ -59,7 +59,7 @@ static unsigned long div_recalc_rate(struct clk_hw *hw, div &= BIT(divider->width) - 1; return divider_recalc_rate(hw, parent_rate, div, NULL, - CLK_DIVIDER_ROUND_CLOSEST); + CLK_DIVIDER_ROUND_CLOSEST, divider->width); } const struct clk_ops clk_regmap_div_ops = { diff --git a/drivers/clk/sunxi-ng/ccu_div.c b/drivers/clk/sunxi-ng/ccu_div.c index baa3cf96507b..302a18efd39f 100644 --- a/drivers/clk/sunxi-ng/ccu_div.c +++ b/drivers/clk/sunxi-ng/ccu_div.c @@ -71,7 +71,7 @@ static unsigned long ccu_div_recalc_rate(struct clk_hw *hw, parent_rate); val = divider_recalc_rate(hw, parent_rate, val, cd->div.table, - cd->div.flags); + cd->div.flags, cd->div.width); if (cd->common.features & CCU_FEATURE_FIXED_POSTDIV) val /= cd->fixed_post_div; diff --git a/drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c b/drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c index fe15aa64086f..71fe60e5f01f 100644 --- a/drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c +++ b/drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c @@ -698,7 +698,7 @@ static unsigned long dsi_pll_14nm_postdiv_recalc_rate(struct clk_hw *hw, val &= div_mask(width); return divider_recalc_rate(hw, parent_rate, val, NULL, - postdiv->flags); + postdiv->flags, width); } static long dsi_pll_14nm_postdiv_round_rate(struct clk_hw *hw, diff --git a/drivers/rtc/rtc-ac100.c b/drivers/rtc/rtc-ac100.c index 9e336184491c..0282ccc6181c 100644 --- a/drivers/rtc/rtc-ac100.c +++ b/drivers/rtc/rtc-ac100.c @@ -137,13 +137,15 @@ static unsigned long ac100_clkout_recalc_rate(struct clk_hw *hw, div = (reg >> AC100_CLKOUT_PRE_DIV_SHIFT) & ((1 << AC100_CLKOUT_PRE_DIV_WIDTH) - 1); prate = divider_recalc_rate(hw, prate, div, - ac100_clkout_prediv, 0); + ac100_clkout_prediv, 0, + AC100_CLKOUT_PRE_DIV_WIDTH); } div = (reg >> AC100_CLKOUT_DIV_SHIFT) & (BIT(AC100_CLKOUT_DIV_WIDTH) - 1); return divider_recalc_rate(hw, prate, div, NULL, - CLK_DIVIDER_POWER_OF_TWO); + CLK_DIVIDER_POWER_OF_TWO, + AC100_CLKOUT_DIV_WIDTH); } static long ac100_clkout_round_rate(struct clk_hw *hw, unsigned long rate, diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 7c925e6211f1..48171b349b88 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -412,7 +412,7 @@ extern const struct clk_ops clk_divider_ro_ops; unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate, unsigned int val, const struct clk_div_table *table, - unsigned long flags); + unsigned long flags, unsigned long width); long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, unsigned long rate, unsigned long *prate, const struct clk_div_table *table, From patchwork Mon Mar 19 15:48:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132041 Delivered-To: patch@linaro.org Received: by 10.80.152.129 with SMTP id j1csp2968964edb; Mon, 19 Mar 2018 08:50:00 -0700 (PDT) X-Google-Smtp-Source: AG47ELsDQNSuOAjJl1lncWjiBKFXIMyXJlWw0bjOdgi9kx5eJnBNGKwwuHt+iXkNdDDwjp/j4rgV X-Received: by 10.101.93.5 with SMTP id e5mr9241986pgr.82.1521474600099; Mon, 19 Mar 2018 08:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521474600; cv=none; d=google.com; s=arc-20160816; b=QzgDr/8z7hLvRD8kJIxMRoQXQqqHa2AV2ELf7xrzsHE0K1u13Ym3OIEMqmpsEfEjCg Ds7bTwiBrlKe6wTgAhHtLDYCcWRFi9GzQ3n1PhiW4Kb/v4WcLuYOUWCH+NpnJ+abj2PD 5MgJWLQcRnCt6p+tZRmN507lgSBxOozkhgzOxBB2qOqAvXc5oeNo1hYXR7hcEqO2w4hr 1WYZ6TU3J56kwnA72qskM1Ka4K6PZja/yKMUBMPWptG4cDz7XEuC8v/o+aejctC2r3lO vpIqpd7KFdYnmZxetQKFUFDIT4qRupSsQCCtIU7ODz4RpD1wLoiSMnqzsEWDKzE2rALY TxEg== 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-id:spamdiagnosticmetadata:spamdiagnosticoutput :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=A0TcJZyUXzZRiljV1xE1wuQIGTnvPnKiYvOVhQUJxLo=; b=hkPT2VouY831MXa7FaeqAAUOs7CkpdGjUYR4KCXLiFjWuPW5E/5NZsi/XntqdlC/AY oo1DtgUwifbfWrTGSiv7kuH752E72Ur3qn6DbKcU4nD36mFmkCnxG464idwzqu44BH5T lkql15kaY/T/ywYY4tTR5K4nW7efrlAZaJ3H84EZPS1jnA108SqBsfQUewYHNNEU+UdM FbFHAX4n00ikTBEh2GwtkLYUIDuh50JPz9LfIs41I1JVQd4u+EYUNYbmRfgYW6aVDRau 0BW0RO8Tlinu25mCKluszUG4ZsmWGWpziL6gg8GBKUwojGGYnfBsGnr3gUExGNt9Qna8 Y2qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=B/EuLGZC; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg3-v6si211143plb.118.2018.03.19.08.49.59; Mon, 19 Mar 2018 08:50:00 -0700 (PDT) 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=@microsoft.com header.s=selector1 header.b=B/EuLGZC; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934028AbeCSPty (ORCPT + 28 others); Mon, 19 Mar 2018 11:49:54 -0400 Received: from mail-sn1nam01on0129.outbound.protection.outlook.com ([104.47.32.129]:20557 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933855AbeCSPtk (ORCPT ); Mon, 19 Mar 2018 11:49:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=A0TcJZyUXzZRiljV1xE1wuQIGTnvPnKiYvOVhQUJxLo=; b=B/EuLGZCYJAH7/eEvsbZRCcsyEOtgcB3vXu1N35JYn4hw4ftKn2HypXjPjOoY9LaYMZYycrhHd+xrtpWpR0tMSp9ZNkaDgzrZldUqvkdJEkwiKteFq392Qz1flrgjEBqO2Wm87xv7EuHsk7JTzH31YukU2mGzbEpHk4BISsynnM= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0981.namprd21.prod.outlook.com (52.132.133.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 15:49:37 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:49:37 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Paolo Valente , Davide Ferrari , Jens Axboe , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 093/124] block, bfq: put async queues for root bfq groups too Thread-Topic: [PATCH AUTOSEL for 4.15 093/124] block, bfq: put async queues for root bfq groups too Thread-Index: AQHTv5nCLkWSTRGPYUOHds/U6G1Fgw== Date: Mon, 19 Mar 2018 15:48:44 +0000 Message-ID: <20180319154645.11350-93-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB0981; 7:DU/S8+y2gvvZHUAsK9GhDcwR7p6elC1/71bsUu/+RqMXt7NQyYxSBH5mNj3jAdjY5VcTwgN0KfqbOKwwv/zCYbLpMgzDkvm6swaTdH4h4i8BA/BMl8y+hUUJzWcjd+bXUb+r+0ZErN8av9yAbExEMnlvhRTZBQ9ZBZP/caigTg7NFv20jgB6oe0rh6GdyG68oEmj39XU0BswnNadQUG2nKwK64ULOpMBBVr7X9PJzekMhKSbmFKUjg2FAiRHYW4V; 20:8909PVRT5S7yMZSeMWlGiGuTM2y6zJdRGyFsBj28N3IkfVeyzdTNs/mOaZrFeLTtXU9PUBNRdMqFDbm5JX0UrGyCC8tutL/kODYKuNt94tUphLgyMExdCY4ggnZPHeeKECfNmuRbTA7sEBUMnZdoPm8BHfh1lEsHdT16vuS/uAo= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: db45fdb3-1bf2-4007-4540-08d58db10532 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:DM5PR2101MB0981; x-ms-traffictypediagnostic: DM5PR2101MB0981: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR2101MB0981; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB0981; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(346002)(396003)(376002)(366004)(39860400002)(39380400002)(189003)(199004)(66066001)(6486002)(26005)(110136005)(5660300001)(54906003)(3280700002)(6512007)(68736007)(102836004)(6436002)(107886003)(10290500003)(53936002)(186003)(59450400001)(72206003)(14454004)(36756003)(6666003)(2950100002)(316002)(6506007)(22452003)(478600001)(10090500001)(106356001)(105586002)(99286004)(7736002)(3660700001)(86362001)(76176011)(305945005)(86612001)(2501003)(97736004)(5250100002)(39060400002)(4326008)(3846002)(6116002)(1076002)(8936002)(25786009)(81156014)(81166006)(8676002)(2900100001)(2906002)(22906009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB0981; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: nBwPtQtGcmwwebESax6zQHsA6n4t8Jbi6isIg8hFsexPRO3GrbnMZVInScZDVg8GAS03Wp3twFO0NWOZoKDPuhDw73Wcz+ipNedvmRlz197TXe1LEnIvekH3sk/UuH14ndK+zD9KfLPUO59c9ljyJXPVGLHYwRLTmnB1VewaTorehk5XgkXNOtADxj1y6azaRwdsbBEhPDUQjgcIe2yIZXVCIbJTkJ2usAc5ByjN5cA/pXOSV7kITDFh6rNH0N8MV2H4ZalOG+g3kdR2ExMHIk3FD7jgZp7vkYrd4tf3xsJ7E1FhavOw9gDBthixPmpzZIJbhNyNiCSHdbBliUqCHA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <70CA0F2D4A74EB4CAED18D1B31C8472B@namprd21.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: db45fdb3-1bf2-4007-4540-08d58db10532 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:48:44.0915 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0981 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Valente [ Upstream commit 52257ffbfcaf58d247b13fb148e27ed17c33e526 ] For each pair [device for which bfq is selected as I/O scheduler, group in blkio/io], bfq maintains a corresponding bfq group. Each such bfq group contains a set of async queues, with each async queue created on demand, i.e., when some I/O request arrives for it. On creation, an async queue gets an extra reference, to make sure that the queue is not freed as long as its bfq group exists. Accordingly, to allow the queue to be freed after the group exited, this extra reference must released on group exit. The above holds also for a bfq root group, i.e., for the bfq group corresponding to the root blkio/io root for a given device. Yet, by mistake, the references to the existing async queues of a root group are not released when the latter exits. This causes a memory leak when the instance of bfq for a given device exits. In a similar vein, bfqg_stats_xfer_dead is not executed for a root group. This commit fixes bfq_pd_offline so that the latter executes the above missing operations for a root group too. Reported-by: Holger Hoffstätte Reported-by: Guoqing Jiang Tested-by: Holger Hoffstätte Signed-off-by: Davide Ferrari Signed-off-by: Paolo Valente Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bfq-cgroup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.14.1 diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index da1525ec4c87..d819dc77fe65 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -775,10 +775,11 @@ static void bfq_pd_offline(struct blkg_policy_data *pd) unsigned long flags; int i; + spin_lock_irqsave(&bfqd->lock, flags); + if (!entity) /* root group */ - return; + goto put_async_queues; - spin_lock_irqsave(&bfqd->lock, flags); /* * Empty all service_trees belonging to this group before * deactivating the group itself. @@ -809,6 +810,8 @@ static void bfq_pd_offline(struct blkg_policy_data *pd) } __bfq_deactivate_entity(entity, false); + +put_async_queues: bfq_put_async_queues(bfqd, bfqg); spin_unlock_irqrestore(&bfqd->lock, flags); From patchwork Mon Mar 19 15:49:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132043 Delivered-To: patch@linaro.org Received: by 10.80.152.129 with SMTP id j1csp2969619edb; Mon, 19 Mar 2018 08:50:40 -0700 (PDT) X-Google-Smtp-Source: AG47ELvYhHirMJVq+RaC9qnl6iZxVhWgVefauQ+zUzJPwtRkSpAj0J9yYRI3wNDzWNxD+h7MNAU7 X-Received: by 10.101.97.15 with SMTP id z15mr7584338pgu.393.1521474639990; Mon, 19 Mar 2018 08:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521474639; cv=none; d=google.com; s=arc-20160816; b=OilcY9pkzZea/fCyU+TjBclHwramR2UTyhAzm+axxlgvIFLNVmCQSvyJErsIFIbYgZ OON+pKMSv2r+ZygHrIRAyx1Nid+2xSB5He2mYfHF9HtA3bMnFPiPbSSx86O+uEKoZ5Nn WJFAdfd4+vFuIoQrhQ13q3J77UiWLxA6Y9yJ0y60VT7XIsV9Djm6Pwnn2pgUqeF0AOe8 c+jLLdUsgnywodF5Aidha9V0UxPyHp8/y9nwgOvrebbgbOLZ7gf7+xetEGPEh9lCoBTC MGdXQFI22SmmgtB1joEpeyiz/blnprbuqIO00zPHk339/hB0fsyMiHn4D9tDVYpwvwMb h9UA== 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 :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=XjTb+FV6a+ei1GqZhrkj6xRWOwKJxuIEkv0VdfFt09U=; b=nA/mh9HzkPMlPJddPb+x17gtIA/wOIjDgc8OorNzvYT17wtPJoKmBXfmASv/6MHEqK 6o0qYZEtL9Ox4OXaCRUzEESX/ygmnBAB5fu8S2Iw4xnCKfTN/06GUQ3j9TjNXkjmSi7+ C1wVXF3KNnUJPNVayXh+AmLGLyQ+wGmojF0kb1kU+aEsiT8PBE4hCQNn7vuxB+6CoeDr Z1YrQTO/xBaWFIpTTGKSdacMrLqyWbjBPysnHlYldSamodiiq6S2jlW5AdxQtAn4B7cv vbUkBJhOtSY7wGXA6cuD1U/edPRAKNs99zI8edYKfvYEzzytBJgC7sQQ8EWKt8nQt4Si CDYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Ge/24d2t; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r8si157186pgp.468.2018.03.19.08.50.39; Mon, 19 Mar 2018 08:50:39 -0700 (PDT) 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=@microsoft.com header.s=selector1 header.b=Ge/24d2t; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934121AbeCSPuf (ORCPT + 28 others); Mon, 19 Mar 2018 11:50:35 -0400 Received: from mail-by2nam01on0114.outbound.protection.outlook.com ([104.47.34.114]:57771 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934070AbeCSPuP (ORCPT ); Mon, 19 Mar 2018 11:50:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=XjTb+FV6a+ei1GqZhrkj6xRWOwKJxuIEkv0VdfFt09U=; b=Ge/24d2thO9Myr/ddg4U8bUhTKifhEHPbab8nB8A8FObORqRtjTseuUKhRaK6ILhedz+jmPtTiTzePdjDfqhFs158Y2JUnQN5GoFx36fgE+v1mn23xIfI+ThDP7HtE4MNg1xDZHdd4oXCQiTWOXL40wlh0INLNGf/Mk+nd+d8tM= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1109.namprd21.prod.outlook.com (52.132.130.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 15:50:01 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:50:01 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Arnd Bergmann , Richard Biener , Jakub Jelinek , Ard Biesheuvel , Herbert Xu , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 115/124] crypto: aes-generic - build with -Os on gcc-7+ Thread-Topic: [PATCH AUTOSEL for 4.15 115/124] crypto: aes-generic - build with -Os on gcc-7+ Thread-Index: AQHTv5nSHXcUmL9aeUm4bSTOGIaRSA== Date: Mon, 19 Mar 2018 15:49:10 +0000 Message-ID: <20180319154645.11350-115-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB1109; 7:OTKngZ/CJbR2Fc+yZmoB3wnaFLtsWKabse4hQx+q+OgGgu9pADE9ETrNlPknUGQwpKhdEhD0BM0x28hqaV27kfYSmDGeVx1IlXIL//E7fE6JasWmAj/GUTwsSXjBYQ4WZaf0qhvpehsJwdHOhrX6noFtGrpAWMktU+8kg26krteGeda6Z2ElhZX8m/t83PH6a7e2TF0zBinA2yWu7YSgHGzfL3xdKJf7sklY5Lzb84Y1yX12V5mZxEYyebv1Y9Qa; 20:fZOmj1AnYqloz4EAKbdX/cqFheE+Ff/AapMNZqtfPeABi4CgmSfBdcOGjzNaKfXOQn+EsEq6FPWbNfykxp4zsQanjD40Omz/bcxLKQo+PjwJlWtyi8hga42PdWSrza4MIoGi1C7xKwUoZTtopzi8Zcmb+NL7ZUnkn4PvzQLUDX4= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 7c30531d-b251-4c46-8df7-08d58db112fe x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:DM5PR2101MB1109; x-ms-traffictypediagnostic: DM5PR2101MB1109: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(22074186197030)(89211679590171)(183786458502308); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR2101MB1109; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB1109; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(396003)(39860400002)(39380400002)(376002)(346002)(199004)(189003)(81166006)(10290500003)(107886003)(81156014)(106356001)(6506007)(8676002)(3846002)(36756003)(8936002)(97736004)(6116002)(1076002)(102836004)(68736007)(6666003)(3280700002)(2950100002)(3660700001)(478600001)(72206003)(59450400001)(2906002)(14454004)(966005)(76176011)(66066001)(6512007)(6306002)(5250100002)(10090500001)(2501003)(53936002)(6486002)(6436002)(26005)(316002)(22452003)(305945005)(7736002)(4326008)(25786009)(86362001)(86612001)(5660300001)(2900100001)(99286004)(54906003)(186003)(105586002)(110136005)(22906009)(41533002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB1109; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: piRyZvFOhXs4vK6OFS3+WfvUAVWk6IqenPbaBe2QLpFFB9oWxx9zaGM6wIDFP1wYc8vtM/uTCqR8CcIkIe5wCFJEX4QZPG5Fg7MSw5f0uNP9HHStVdRqhjWsnnglVdd7xBHL3vup6gS0X0CKQ/7uxhchphg+B3Vlg6sitVY/gA35yMsk0/YzvxURwN59EpJWfBH+/KXhwIVZ/ZHGwQNN+x/UZ3es29WRyUnC9R/AqjXd1ecWISnP1U/WPibqzErPAqHYEx/SsPLEmqq7OiJVItsiqrAruUwpbltZ73dcfhgshjllFFdJwL4L6G1Upq7PdcGzLQ8BlZ+uAr8Bh79/Vg== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c30531d-b251-4c46-8df7-08d58db112fe X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:49:10.6131 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1109 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann [ Upstream commit 148b974deea927f5dbb6c468af2707b488bfa2de ] While testing other changes, I discovered that gcc-7.2.1 produces badly optimized code for aes_encrypt/aes_decrypt. This is especially true when CONFIG_UBSAN_SANITIZE_ALL is enabled, where it leads to extremely large stack usage that in turn might cause kernel stack overflows: crypto/aes_generic.c: In function 'aes_encrypt': crypto/aes_generic.c:1371:1: warning: the frame size of 4880 bytes is larger than 2048 bytes [-Wframe-larger-than=] crypto/aes_generic.c: In function 'aes_decrypt': crypto/aes_generic.c:1441:1: warning: the frame size of 4864 bytes is larger than 2048 bytes [-Wframe-larger-than=] I verified that this problem exists on all architectures that are supported by gcc-7.2, though arm64 in particular is less affected than the others. I also found that gcc-7.1 and gcc-8 do not show the extreme stack usage but still produce worse code than earlier versions for this file, apparently because of optimization passes that generally provide a substantial improvement in object code quality but understandably fail to find any shortcuts in the AES algorithm. Possible workarounds include a) disabling -ftree-pre and -ftree-sra optimizations, this was an earlier patch I tried, which reliably fixed the stack usage, but caused a serious performance regression in some versions, as later testing found. b) disabling UBSAN on this file or all ciphers, as suggested by Ard Biesheuvel. This would lead to massively better crypto performance in UBSAN-enabled kernels and avoid the stack usage, but there is a concern over whether we should exclude arbitrary files from UBSAN at all. c) Forcing the optimization level in a different way. Similar to a), but rather than deselecting specific optimization stages, this now uses "gcc -Os" for this file, regardless of the CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE/SIZE option. This is a reliable workaround for the stack consumption on all architecture, and I've retested the performance results now on x86, cycles/byte (lower is better) for cbc(aes-generic) with 256 bit keys: -O2 -Os gcc-6.3.1 14.9 15.1 gcc-7.0.1 14.7 15.3 gcc-7.1.1 15.3 14.7 gcc-7.2.1 16.8 15.9 gcc-8.0.0 15.5 15.6 This implements the option c) by enabling forcing -Os on all compiler versions starting with gcc-7.1. As a workaround for PR83356, it would only be needed for gcc-7.2+ with UBSAN enabled, but since it also shows better performance on gcc-7.1 without UBSAN, it seems appropriate to use the faster version here as well. Side note: during testing, I also played with the AES code in libressl, which had a similar performance regression from gcc-6 to gcc-7.2, but was three times slower overall. It might be interesting to investigate that further and possibly port the Linux implementation into that. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83356 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83651 Cc: Richard Biener Cc: Jakub Jelinek Cc: Ard Biesheuvel Signed-off-by: Arnd Bergmann Acked-by: Ard Biesheuvel Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/Makefile | 1 + 1 file changed, 1 insertion(+) -- 2.14.1 diff --git a/crypto/Makefile b/crypto/Makefile index d674884b2d51..daa69360e054 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -99,6 +99,7 @@ obj-$(CONFIG_CRYPTO_TWOFISH_COMMON) += twofish_common.o obj-$(CONFIG_CRYPTO_SERPENT) += serpent_generic.o CFLAGS_serpent_generic.o := $(call cc-option,-fsched-pressure) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149 obj-$(CONFIG_CRYPTO_AES) += aes_generic.o +CFLAGS_aes_generic.o := $(call cc-ifversion, -ge, 0701, -Os) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83356 obj-$(CONFIG_CRYPTO_AES_TI) += aes_ti.o obj-$(CONFIG_CRYPTO_CAMELLIA) += camellia_generic.o obj-$(CONFIG_CRYPTO_CAST_COMMON) += cast_common.o