From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-1086562-1520490342-2-16553377375006353702 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.25, RCVD_IN_DNSWL_HI -5, T_RP_MATCHES_RCVD -0.01, LANGUAGES en, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='CN', FromHeader='com', MailFrom='org', XOriginatingCountry='US' X-Spam-charsets: plain='iso-8859-1' X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: stable-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=arctest; t=1520490341; b=RgNfDAjPWa7Dk6WwsKdLDaFNxJTyajDECwF8bTnisQKltsI n/3m2FuEFegmSMG5J7MZfuKfoK/KUfpNDFHBbThw/i0qmGoDxD9XSlvwhMx3lA0h wTiJV+Ok7zXV2OTPNngchWBP3ItewDzkt0D/cmt+0lbJ0HC6IRdGrAI05pt1Lw2d YP5mLDEALxu73gyRFIy/MjSVfWLU9dWGKzqmG2jMRVouzHbkiFn/bajjdE0MyObK yCiPjGjfbMX3PmzYlIIbT06Yz40Ueg9FeStQ0hgi71SFp5U3EH7s+BAjZeMZfUNn 31Ws7P9n3KObK/cZw9pJn4T6wrvuS1LznuDQVJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=from:to:cc:subject:date:message-id :references:in-reply-to:content-type:content-transfer-encoding :mime-version:sender:list-id; s=arctest; t=1520490341; bh=K1AFXK S/Lg8WeVDplcZ4v00PzpoCrLIe0WiWrHVepsA=; b=hEAbjhoh9EqT40ABgvIjVI YpXIJmLhX4KtPpOAL52dsD8AVBc/9rw1aparzwjg0JOUfynOPwvoowLwp0X+jO4s RHF55elDuJH8tCPjJIHUrA45hEpRsGHRRpxNFloHWZqw3zRz9t+2G9kqZ2bp7u5L 4knAPV7dCWlZ/QzsPuwl+LHkO2embV/cXI8oTQKK1euwd/xZwjM0GijxPdjdfzQ+ pCYULraFjzWYA2s1SCE/Wg679sVjBebb4GsZojM/a37lECQ/uKlw3xou41T0rcWS CqgL/TfkESKHx09v2+uPN8SIJL3ngChp6TC8ganbWlwl3GRHEh+gVVl3jwKosbyw == ARC-Authentication-Results: i=1; mx2.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=j1lB6PpD x-bits=1024 x-keytype=rsa x-algorithm=sha256 x-selector=selector1; dmarc=pass (p=reject,has-list-id=yes,d=none) header.from=microsoft.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-category=clean score=-100 state=0; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=microsoft.com header.result=pass header_is_org_domain=yes Authentication-Results: mx2.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=j1lB6PpD x-bits=1024 x-keytype=rsa x-algorithm=sha256 x-selector=selector1; dmarc=pass (p=reject,has-list-id=yes,d=none) header.from=microsoft.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-category=clean score=-100 state=0; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=microsoft.com header.result=pass header_is_org_domain=yes Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965968AbeCHGZi (ORCPT ); Thu, 8 Mar 2018 01:25:38 -0500 Received: from mail-sn1nam01on0111.outbound.protection.outlook.com ([104.47.32.111]:53598 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751111AbeCHFAm (ORCPT ); Thu, 8 Mar 2018 00:00:42 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Thomas Gleixner , Fenghua Yu , Tony Luck , Herbert Xu , "Rafael J. Wysocki" , Peter Zijlstra , Benjamin Herrenschmidt , Sebastian Siewior , "linux-pm@vger.kernel.org" , Lai Jiangshan , Michael Ellerman , Tejun Heo , "David S. Miller" , Len Brown , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 035/190] cpufreq/sh: Replace racy task affinity logic Thread-Topic: [PATCH AUTOSEL for 4.9 035/190] cpufreq/sh: Replace racy task affinity logic Thread-Index: AQHTtpovaBL6t+aHekKvdLGUc41K4w== Date: Thu, 8 Mar 2018 04:59:06 +0000 Message-ID: <20180308045810.8041-35-alexander.levin@microsoft.com> References: <20180308045810.8041-1-alexander.levin@microsoft.com> In-Reply-To: <20180308045810.8041-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;DM5PR2101MB1112;20:81XaMUAWgCLy//ZZlAY+/4WuFs4E60MP4+VrOO5T3tt8I+4hR1mg/Ag5z6/LmkFHgfiKBIjh0ERmDOVYlpxEsPd0cPpsksXrWDCQk4drN0IaUAY2WNXMAF+8aqoLNUN84UmOBx8L7yeJ2J7ICv2E9WcwR0S6c543yYzFdksQPR4= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 3e52a50a-1eae-4c5c-f394-08d584b188b8 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1112; x-ms-traffictypediagnostic: DM5PR2101MB1112: 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)(9452136761055)(85827821059158)(788757137089)(42068640409301)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231220)(944501244)(52105095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB1112;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1112; x-forefront-prvs: 060503E79B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(346002)(376002)(39380400002)(366004)(396003)(189003)(199004)(54906003)(81156014)(7736002)(86612001)(25786009)(81166006)(6512007)(6486002)(4326008)(3846002)(1076002)(39060400002)(6436002)(6306002)(36756003)(305945005)(6116002)(8936002)(2900100001)(6666003)(97736004)(966005)(66066001)(2950100002)(105586002)(68736007)(14454004)(72206003)(3660700001)(478600001)(10290500003)(3280700002)(53936002)(106356001)(10090500001)(5660300001)(102836004)(107886003)(316002)(59450400001)(110136005)(22452003)(86362001)(2501003)(5250100002)(6506007)(76176011)(99286004)(2906002)(26005)(186003)(7416002)(8676002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1112;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; x-microsoft-antispam-message-info: vELmvd8wsglJwoxaOesyUpS6Sv2bvVQAE6wv/SuIRW21riRVBBE2968Mj1AvJO8SCxdw1edzFgci3gUZIxmTX4A7H6dxEbsi0mDHeLXsOGscBn/TzniQYRLRrZycCfWKL3+7WrBoT1hB1orwku9qRhEpGQcJKkvdKg5n4iAgnL+KSOd8mKvwPalah9ZBA8aueuaZOZJPnxWrJHloysKD+Vf4FeVbG40qo3VZfZzpSTG4Am/O/PmrQIJOXbsul/K7x/bguW7UC+SKIljuVDyhkb5CU6L+ATReEXSNhXAesoXZrX2phrwtHC2c9uusWXoWwLsgI535rH5ljTFsS6+ygQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e52a50a-1eae-4c5c-f394-08d584b188b8 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2018 04:59:06.8047 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1112 Sender: stable-owner@vger.kernel.org X-Mailing-List: stable@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: From: Thomas Gleixner [ Upstream commit 205dcc1ecbc566cbc20acf246e68de3b080b3ecf ] The target() callback must run on the affected cpu. This is achieved by temporarily setting the affinity of the calling thread to the requested CPU and reset it to the original affinity afterwards. That's racy vs. concurrent affinity settings for that thread resulting in code executing on the wrong CPU. Replace it by work_on_cpu(). All call pathes which invoke the callbacks are already protected against CPU hotplug. Signed-off-by: Thomas Gleixner Acked-by: Viresh Kumar Cc: Fenghua Yu Cc: Tony Luck Cc: Herbert Xu Cc: "Rafael J. Wysocki" Cc: Peter Zijlstra Cc: Benjamin Herrenschmidt Cc: Sebastian Siewior Cc: linux-pm@vger.kernel.org Cc: Lai Jiangshan Cc: Michael Ellerman Cc: Tejun Heo Cc: "David S. Miller" Cc: Len Brown Link: http://lkml.kernel.org/r/20170412201042.958216363@linutronix.de Signed-off-by: Thomas Gleixner Signed-off-by: Sasha Levin --- drivers/cpufreq/sh-cpufreq.c | 45 ++++++++++++++++++++++++++--------------= ---- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/drivers/cpufreq/sh-cpufreq.c b/drivers/cpufreq/sh-cpufreq.c index 86628e22b2a3..719c3d9f07fb 100644 --- a/drivers/cpufreq/sh-cpufreq.c +++ b/drivers/cpufreq/sh-cpufreq.c @@ -30,54 +30,63 @@ =20 static DEFINE_PER_CPU(struct clk, sh_cpuclk); =20 +struct cpufreq_target { + struct cpufreq_policy *policy; + unsigned int freq; +}; + static unsigned int sh_cpufreq_get(unsigned int cpu) { return (clk_get_rate(&per_cpu(sh_cpuclk, cpu)) + 500) / 1000; } =20 -/* - * Here we notify other drivers of the proposed change and the final chang= e. - */ -static int sh_cpufreq_target(struct cpufreq_policy *policy, - unsigned int target_freq, - unsigned int relation) +static long __sh_cpufreq_target(void *arg) { - unsigned int cpu =3D policy->cpu; + struct cpufreq_target *target =3D arg; + struct cpufreq_policy *policy =3D target->policy; + int cpu =3D policy->cpu; struct clk *cpuclk =3D &per_cpu(sh_cpuclk, cpu); - cpumask_t cpus_allowed; struct cpufreq_freqs freqs; struct device *dev; long freq; =20 - cpus_allowed =3D current->cpus_allowed; - set_cpus_allowed_ptr(current, cpumask_of(cpu)); - - BUG_ON(smp_processor_id() !=3D cpu); + if (smp_processor_id() !=3D cpu) + return -ENODEV; =20 dev =3D get_cpu_device(cpu); =20 /* Convert target_freq from kHz to Hz */ - freq =3D clk_round_rate(cpuclk, target_freq * 1000); + freq =3D clk_round_rate(cpuclk, target->freq * 1000); =20 if (freq < (policy->min * 1000) || freq > (policy->max * 1000)) return -EINVAL; =20 - dev_dbg(dev, "requested frequency %u Hz\n", target_freq * 1000); + dev_dbg(dev, "requested frequency %u Hz\n", target->freq * 1000); =20 freqs.old =3D sh_cpufreq_get(cpu); freqs.new =3D (freq + 500) / 1000; freqs.flags =3D 0; =20 - cpufreq_freq_transition_begin(policy, &freqs); - set_cpus_allowed_ptr(current, &cpus_allowed); + cpufreq_freq_transition_begin(target->policy, &freqs); clk_set_rate(cpuclk, freq); - cpufreq_freq_transition_end(policy, &freqs, 0); + cpufreq_freq_transition_end(target->policy, &freqs, 0); =20 dev_dbg(dev, "set frequency %lu Hz\n", freq); - return 0; } =20 +/* + * Here we notify other drivers of the proposed change and the final chang= e. + */ +static int sh_cpufreq_target(struct cpufreq_policy *policy, + unsigned int target_freq, + unsigned int relation) +{ + struct cpufreq_target data =3D { .policy =3D policy, .freq =3D target_fre= q }; + + return work_on_cpu(policy->cpu, __sh_cpufreq_target, &data); +} + static int sh_cpufreq_verify(struct cpufreq_policy *policy) { struct clk *cpuclk =3D &per_cpu(sh_cpuclk, policy->cpu); --=20 2.14.1