From patchwork Fri Mar 11 11:59:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 8565171 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 31BA69FDD5 for ; Fri, 11 Mar 2016 12:02:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4497C20154 for ; Fri, 11 Mar 2016 12:02:31 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D6BB20373 for ; Fri, 11 Mar 2016 12:02:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aeLjL-0004eB-08; Fri, 11 Mar 2016 11:59:43 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aeLjJ-0004cT-73 for xen-devel@lists.xenproject.org; Fri, 11 Mar 2016 11:59:41 +0000 Received: from [193.109.254.147] by server-6.bemta-14.messagelabs.com id 52/E5-03497-C23B2E65; Fri, 11 Mar 2016 11:59:40 +0000 X-Env-Sender: jgross@suse.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1457697579!30455620!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24851 invoked from network); 11 Mar 2016 11:59:39 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-7.tower-27.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 11 Mar 2016 11:59:39 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A5FF9ACC6; Fri, 11 Mar 2016 11:59:38 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Date: Fri, 11 Mar 2016 12:59:33 +0100 Message-Id: <1457697574-6710-6-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1457697574-6710-1-git-send-email-jgross@suse.com> References: <1457697574-6710-1-git-send-email-jgross@suse.com> Cc: Juergen Gross , jdelvare@suse.com, peterz@infradead.org, hpa@zytor.com, x86@kernel.org, mingo@redhat.com, david.vrabel@citrix.com, Douglas_Warzecha@dell.com, pali.rohar@gmail.com, boris.ostrovsky@oracle.com, tglx@linutronix.de, linux@roeck-us.net Subject: [Xen-devel] [PATCH 5/6] virt, sched: add cpu pinning to call_sync_on_phys_cpu() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add generic virtualization support for pinning the current vcpu to a specified physical cpu. As this operation isn't performance critical (a very limited set of operations like BIOS calls and SMIs is expected to need this) just add a hypervisor specific indirection. Such a pinning should last as short as possible as it might block sensible vcpu scheduling and maybe other hypervisor functions like suspending the system which rely on scheduling. To ensure this don't let the current thread be preempted while the vcpu is pinned in call_sync_on_phys_cpu(). Signed-off-by: Juergen Gross --- arch/x86/include/asm/hypervisor.h | 9 +++++++++ include/linux/sched.h | 24 +++++++++++++++++++++++- kernel/sched/core.c | 4 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h index 055ea99..13f80a2 100644 --- a/arch/x86/include/asm/hypervisor.h +++ b/arch/x86/include/asm/hypervisor.h @@ -43,6 +43,9 @@ struct hypervisor_x86 { /* X2APIC detection (run once per boot) */ bool (*x2apic_available)(void); + + /* pin current vcpu to specified physical cpu (run rarely) */ + void (*pin_vcpu)(int); }; extern const struct hypervisor_x86 *x86_hyper; @@ -56,6 +59,12 @@ extern const struct hypervisor_x86 x86_hyper_kvm; extern void init_hypervisor(struct cpuinfo_x86 *c); extern void init_hypervisor_platform(void); extern bool hypervisor_x2apic_available(void); + +static inline void hypervisor_pin_vcpu(int cpu) +{ + if (x86_hyper->pin_vcpu) + x86_hyper->pin_vcpu(cpu); +} #else static inline void init_hypervisor(struct cpuinfo_x86 *c) { } static inline void init_hypervisor_platform(void) { } diff --git a/include/linux/sched.h b/include/linux/sched.h index dfadf1a..53b33d5 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -61,6 +61,9 @@ struct sched_param { #include #include +#ifdef CONFIG_HYPERVISOR_GUEST +#include +#endif #define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */ @@ -2230,6 +2233,17 @@ static inline void rcu_copy_process(struct task_struct *p) #endif /* #ifdef CONFIG_TASKS_RCU */ } +#ifdef CONFIG_HYPERVISOR_GUEST +static inline void pin_vcpu(int cpu) +{ + hypervisor_pin_vcpu(cpu); +} +#else +static inline void pin_vcpu(int cpu) +{ +} +#endif + static inline void tsk_restore_flags(struct task_struct *task, unsigned long orig_flags, unsigned long flags) { @@ -2263,10 +2277,18 @@ static inline int set_cpus_allowed_ptr(struct task_struct *p, static inline int call_sync_on_phys_cpu(unsigned cpu, int (*func)(void *), void *par) { + int ret; + if (cpu != 0) return -EINVAL; - return func(par); + preempt_disable(); + pin_vcpu(0); + ret = func(par); + pin_vcpu(-1); + preempt_enable(); + + return ret; } #endif diff --git a/kernel/sched/core.c b/kernel/sched/core.c index cb9955f..2dc27ca 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1281,7 +1281,11 @@ int call_sync_on_phys_cpu(unsigned cpu, int (*func)(void *), void *par) if (ret) goto out; + preempt_disable(); + pin_vcpu(cpu); ret = func(par); + pin_vcpu(-1); + preempt_enable(); set_cpus_allowed_ptr(current, old_mask);