From patchwork Fri Jul 21 08:39:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 108464 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp531587qge; Fri, 21 Jul 2017 01:41:22 -0700 (PDT) X-Received: by 10.84.239.8 with SMTP id w8mr7095274plk.73.1500626481912; Fri, 21 Jul 2017 01:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500626481; cv=none; d=google.com; s=arc-20160816; b=bqQP+/6seVRmxjSpZWsps+YjWVR6ceTWCI8E4UTUtLR41aDkejTemW1f776JrHdUoP h6a4XpSWEv8+VMx9esWLvT4qNKuUFmdoLD28iXnzFEpwVBGH/pGAgnSdC3WOYQiHq38l +jTzMhBmazJpNA+JaJY0tyhpmVp2B0HhP/Wq7CnGM32I360nQ/MKqNRulrKL/P0KQgrg /M9ljgUW12nghjGoHRak1jjtTgMt2zQ6TLLvOCtNF0q+ymi/f+sZwXR+x3oFkGJYZ0jj oGouQLfEcxhdA7w78pXOPayoLIHbmUSKdqZRmf9mpHE4Try+fB+tWRLLzaE6Xyu3iQjw VDzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=ogwrMEM+qydIgEMhR9J6Cj+1Wy1EfSCR5nDQEaYTer4=; b=mCDST+6VrsBG9yoKS6I9AMoOUWIkKC5eZewpioFZxxejMxHr/qcVYKcDO5mxBacbgG QvlaY2tNfZr7omayTENPsH3BjTH2IXd13MwwXyp+kOHlmue3Yc6zo5k5irY8dzZ5HWIc QBs6A2uu72uQxZ5Vtf07KDCjRL8atbs/0OQK6lHnJynYoNeA31FNk+sXsdUC8dY3HOr2 c0MWnZVdtTr4CeLRj5pRoormQsKEu/Dt6TDEzH+N4l2PZ0L3Lgpo90/tldAPcFp89Vco 2bXjHnjUD44VTYluLPAjkTC4xqf8JhIXZeFmBgglPZxbWww7kNXjKOsG4+G8rFdABnkM sn2g== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 98si1480660pls.501.2017.07.21.01.41.21; Fri, 21 Jul 2017 01:41:21 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753449AbdGUIlV (ORCPT + 6 others); Fri, 21 Jul 2017 04:41:21 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:10239 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753435AbdGUIlU (ORCPT ); Fri, 21 Jul 2017 04:41:20 -0400 Received: from 172.30.72.57 (EHLO DGGEML401-HUB.china.huawei.com) ([172.30.72.57]) by dggrg01-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id ASP42086; Fri, 21 Jul 2017 16:41:17 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEML401-HUB.china.huawei.com (10.3.17.32) with Microsoft SMTP Server id 14.3.301.0; Fri, 21 Jul 2017 16:41:11 +0800 From: Kefeng Wang To: , CC: , , Catalin Marinas , "4.5+" , "Rafael J. Wysocki" , Kefeng Wang Subject: [hulk-4.1-next 1/2] cpuidle: Do not access cpuidle_devices when !CONFIG_CPU_IDLE Date: Fri, 21 Jul 2017 16:39:05 +0800 Message-ID: <1500626346-34316-1-git-send-email-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.5971BE2E.005B, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 2c7c1941f2c5cef6f4d80bee8dfa6138 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Catalin Marinas mainline inclusion from mainline-4.7 commit 9bd616e3dbedfc103f158197c8ad93678849b1ed category: bugfix bugzilla: 3312 DTS: NA CVE: NA ------------------------------------------------- The cpuidle_devices per-CPU variable is only defined when CPU_IDLE is enabled. Commit c8cc7d4de7a4 ("sched/idle: Reorganize the idle loop") removed the #ifdef CONFIG_CPU_IDLE around cpuidle_idle_call() with the compiler optimising away __this_cpu_read(cpuidle_devices). However, with CONFIG_UBSAN && !CONFIG_CPU_IDLE, this optimisation no longer happens and the kernel fails to link since cpuidle_devices is not defined. This patch introduces an accessor function for the current CPU cpuidle device (returning NULL when !CONFIG_CPU_IDLE) and uses it in cpuidle_idle_call(). Signed-off-by: Catalin Marinas Cc: 4.5+ # 4.5+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Kefeng Wang Conflicts: include/linux/cpuidle.h --- include/linux/cpuidle.h | 3 +++ kernel/sched/idle.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) -- 1.8.3.1 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 9c5e892..111ead2 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -157,6 +157,8 @@ extern int cpuidle_enter_freeze(struct cpuidle_driver *drv, struct cpuidle_device *dev); extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev); +static inline struct cpuidle_device *cpuidle_get_device(void) +{return __this_cpu_read(cpuidle_devices); } #else static inline void disable_cpuidle(void) { } static inline bool cpuidle_not_available(struct cpuidle_driver *drv, @@ -198,6 +200,7 @@ static inline int cpuidle_enter_freeze(struct cpuidle_driver *drv, {return -ENODEV; } static inline struct cpuidle_driver *cpuidle_get_cpu_driver( struct cpuidle_device *dev) {return NULL; } +static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; } #endif #ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index fefcb1f..437d577e 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -78,7 +78,7 @@ void __weak arch_cpu_idle(void) */ static void cpuidle_idle_call(void) { - struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); + struct cpuidle_device *dev = cpuidle_get_device(); struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); int next_state, entered_state; bool reflect;