From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932380AbcK3Vmk (ORCPT ); Wed, 30 Nov 2016 16:42:40 -0500 Received: from mga09.intel.com ([134.134.136.24]:37810 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753929AbcK3Vmi (ORCPT ); Wed, 30 Nov 2016 16:42:38 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,574,1473145200"; d="scan'208";a="37394322" From: "Fenghua Yu" To: "Thomas Gleixner" Cc: "H. Peter Anvin" , "Ingo Molnar" , "Marcelo Tosatti" , "Tony Luck" , "Ravi V Shankar" , "Sai Prakhya" , "Vikas Shivappa" , "linux-kernel" , "x86" , "Fenghua Yu" Subject: [PATCH] x86/intel_rdt.c: Disable preempt for intel_rdt_sched_in() in move_myself() Date: Wed, 30 Nov 2016 13:41:43 -0800 Message-Id: <1480542103-44892-1-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 1.8.0.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fenghua Yu intel_rdt_sched_in() calls this_cpu_ptr() read and write pqr_state and update PQR_ASSOC on current cpu. If execution of the function is preempted and switched to another CPU, the results are wrong. If CONFIG_DEBUG_PREEMPT is turned on, the issue is reported as "BUG: smp_processor_id() running in preemptible code." when moving a task to a rdtgroup in move_myself(). Disable preempt before intel_rdt_sched_in() and eanble preempt after the function in move_myself() to solve the issue. Signed-off-by: Fenghua Yu --- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/include/asm/intel_rdt.h b/arch/x86/include/asm/intel_rdt.h index 6e90e87..eaaa765 100644 --- a/arch/x86/include/asm/intel_rdt.h +++ b/arch/x86/include/asm/intel_rdt.h @@ -192,6 +192,9 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, * resctrl file system. * - Caches the per cpu CLOSid values and does the MSR write only * when a task with a different CLOSid is scheduled in. + * - Caller needs to disable preempt before calling this function. + * The function doesn't check preemptible. Scheduler hot path + * disables preempt already. */ static inline void intel_rdt_sched_in(void) { diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c index fb8e03e..9c6f732 100644 --- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c @@ -326,8 +326,10 @@ static void move_myself(struct callback_head *head) kfree(rdtgrp); } + get_cpu(); /* update PQR_ASSOC MSR to make resource group go into effect */ intel_rdt_sched_in(); + put_cpu(); kfree(callback); }