From nobody Fri May 3 00:41:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1563967692; cv=none; d=zoho.com; s=zohoarc; b=dvSoOEqKrAWXCAeFfczgDpSo2B45JhLnnYCn/gN6AqLaA/dhc+1R70j+C3aTTN3IBZgEuo+Eekfudc1mMnn+01FiDfEiIDmsBSlRxAi/c/5Fe1YOG2u7b6afy/gBsOSr+MhBlWLBwyUhER0a5XAAkfMRu+Q9BExTLsLAWQm2xpE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563967692; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=WMchNJG+MULOFSAs7ajhZmnQAVeZIfWQDUzoSyoaYGE=; b=krkQiOQ5tBUmE93Tt7+rwHY+Kh4jApjb5cxVhEaXd4rFyZoQHmxMCt9SY6BuB0Wd2oPwoLf9GOhpLXnzTJqhw5H1g66qoLkp2hXbU5Qf6bOVwaY0Cd1kPCT8BADH2tPghccf9iJKuh3CY5l62YYGEoeHgABXjOD7rmly4CDZ9Kg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 15639676926369.065812406163332; Wed, 24 Jul 2019 04:28:12 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hqFQJ-00029h-19; Wed, 24 Jul 2019 11:27:07 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hqFQI-00029N-7S for xen-devel@lists.xenproject.org; Wed, 24 Jul 2019 11:27:06 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f540560c-ae05-11e9-a615-67bc0ce62ab3; Wed, 24 Jul 2019 11:27:03 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id EAA0EAF26; Wed, 24 Jul 2019 11:27:01 +0000 (UTC) X-Inumbo-ID: f540560c-ae05-11e9-a615-67bc0ce62ab3 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Wed, 24 Jul 2019 13:26:57 +0200 Message-Id: <20190724112658.31495-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190724112658.31495-1-jgross@suse.com> References: <20190724112658.31495-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v3 1/2] xen/x86: cleanup unused NMI/MCE code X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" pv_raise_interrupt() is only called for NMIs these days, so the MCE specific part can be removed. Rename pv_raise_interrupt() to pv_raise_nmi() and NMI_MCE_SOFTIRQ to NMI_SOFTIRQ. Additionally there is no need to pin the vcpu the NMI is delivered to, that is a leftover of (already removed) MCE handling. So remove the pinning, too. Note that pinning was introduced by commit 355b0469a8 adding MCE support (with NMI support existing already). MCE using that pinning was removed with commit 3a91769d6e again without cleaning up the code. Signed-off-by: Juergen Gross Reviewed-by: Andrew Cooper --- xen/arch/x86/pv/traps.c | 93 ++++++++++----------------------------= ---- xen/arch/x86/traps.c | 10 +---- xen/common/domain.c | 3 -- xen/include/asm-x86/pv/traps.h | 6 +-- xen/include/asm-x86/softirq.h | 2 +- xen/include/xen/sched.h | 2 - 6 files changed, 25 insertions(+), 91 deletions(-) diff --git a/xen/arch/x86/pv/traps.c b/xen/arch/x86/pv/traps.c index 1740784ff2..aa26e7171a 100644 --- a/xen/arch/x86/pv/traps.c +++ b/xen/arch/x86/pv/traps.c @@ -136,47 +136,20 @@ bool set_guest_nmi_trapbounce(void) return !null_trap_bounce(curr, tb); } =20 -struct softirq_trap { - struct domain *domain; /* domain to inject trap */ - struct vcpu *vcpu; /* vcpu to inject trap */ - unsigned int processor; /* physical cpu to inject trap */ -}; +static DEFINE_PER_CPU(struct vcpu *, softirq_nmi_vcpu); =20 -static DEFINE_PER_CPU(struct softirq_trap, softirq_trap); - -static void nmi_mce_softirq(void) +static void nmi_softirq(void) { - unsigned int cpu =3D smp_processor_id(); - struct softirq_trap *st =3D &per_cpu(softirq_trap, cpu); + struct vcpu **v_ptr =3D &this_cpu(softirq_nmi_vcpu); =20 - BUG_ON(st->vcpu =3D=3D NULL); + BUG_ON(*v_ptr =3D=3D NULL); =20 /* - * Set the tmp value unconditionally, so that the check in the iret - * hypercall works. - */ - cpumask_copy(st->vcpu->cpu_hard_affinity_tmp, - st->vcpu->cpu_hard_affinity); - - if ( (cpu !=3D st->processor) || - (st->processor !=3D st->vcpu->processor) ) - { - - /* - * We are on a different physical cpu. Make sure to wakeup the vc= pu on - * the specified processor. - */ - vcpu_set_hard_affinity(st->vcpu, cpumask_of(st->processor)); - - /* Affinity is restored in the iret hypercall. */ - } - - /* - * Only used to defer wakeup of domain/vcpu to a safe (non-NMI/MCE) + * Only used to defer wakeup of domain/vcpu to a safe (non-NMI) * context. */ - vcpu_kick(st->vcpu); - st->vcpu =3D NULL; + vcpu_kick(*v_ptr); + *v_ptr =3D NULL; } =20 void __init pv_trap_init(void) @@ -189,50 +162,26 @@ void __init pv_trap_init(void) _set_gate(idt_table + LEGACY_SYSCALL_VECTOR, SYS_DESC_trap_gate, 3, &int80_direct_trap); =20 - open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq); + open_softirq(NMI_SOFTIRQ, nmi_softirq); } =20 -int pv_raise_interrupt(struct vcpu *v, uint8_t vector) +/* + * Deliver NMI to PV guest. Return 0 on success. + * Called in NMI context, so no use of printk(). + */ +int pv_raise_nmi(struct vcpu *v) { - struct softirq_trap *st =3D &per_cpu(softirq_trap, smp_processor_id()); + struct vcpu **v_ptr =3D &per_cpu(softirq_nmi_vcpu, smp_processor_id()); =20 - switch ( vector ) + if ( cmpxchgptr(v_ptr, NULL, v) ) + return -EBUSY; + if ( !test_and_set_bool(v->nmi_pending) ) { - case TRAP_nmi: - if ( cmpxchgptr(&st->vcpu, NULL, v) ) - return -EBUSY; - if ( !test_and_set_bool(v->nmi_pending) ) - { - st->domain =3D v->domain; - st->processor =3D v->processor; - - /* Not safe to wake up a vcpu here */ - raise_softirq(NMI_MCE_SOFTIRQ); - return 0; - } - st->vcpu =3D NULL; - break; - - case TRAP_machine_check: - if ( cmpxchgptr(&st->vcpu, NULL, v) ) - return -EBUSY; - - /* - * We are called by the machine check (exception or polling) handl= ers - * on the physical CPU that reported a machine check error. - */ - if ( !test_and_set_bool(v->mce_pending) ) - { - st->domain =3D v->domain; - st->processor =3D v->processor; - - /* not safe to wake up a vcpu here */ - raise_softirq(NMI_MCE_SOFTIRQ); - return 0; - } - st->vcpu =3D NULL; - break; + /* Not safe to wake up a vcpu here */ + raise_softirq(NMI_SOFTIRQ); + return 0; } + *v_ptr =3D NULL; =20 /* Delivery failed */ return -EIO; diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 25b4b47e5e..08d7edc568 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1600,14 +1600,6 @@ void async_exception_cleanup(struct vcpu *curr) if ( !curr->async_exception_mask ) return; =20 - /* Restore affinity. */ - if ( !cpumask_empty(curr->cpu_hard_affinity_tmp) && - !cpumask_equal(curr->cpu_hard_affinity_tmp, curr->cpu_hard_affini= ty) ) - { - vcpu_set_hard_affinity(curr, curr->cpu_hard_affinity_tmp); - cpumask_clear(curr->cpu_hard_affinity_tmp); - } - if ( !(curr->async_exception_mask & (curr->async_exception_mask - 1)) ) trap =3D __scanbit(curr->async_exception_mask, VCPU_TRAP_NONE); else @@ -1634,7 +1626,7 @@ static void nmi_hwdom_report(unsigned int reason_idx) =20 set_bit(reason_idx, nmi_reason(d)); =20 - pv_raise_interrupt(d->vcpu[0], TRAP_nmi); + pv_raise_nmi(d->vcpu[0]); } =20 static void pci_serr_error(const struct cpu_user_regs *regs) diff --git a/xen/common/domain.c b/xen/common/domain.c index 55aa759b75..bc56a51815 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -133,7 +133,6 @@ static void vcpu_info_reset(struct vcpu *v) static void vcpu_destroy(struct vcpu *v) { free_cpumask_var(v->cpu_hard_affinity); - free_cpumask_var(v->cpu_hard_affinity_tmp); free_cpumask_var(v->cpu_hard_affinity_saved); free_cpumask_var(v->cpu_soft_affinity); =20 @@ -161,7 +160,6 @@ struct vcpu *vcpu_create( grant_table_init_vcpu(v); =20 if ( !zalloc_cpumask_var(&v->cpu_hard_affinity) || - !zalloc_cpumask_var(&v->cpu_hard_affinity_tmp) || !zalloc_cpumask_var(&v->cpu_hard_affinity_saved) || !zalloc_cpumask_var(&v->cpu_soft_affinity) ) goto fail; @@ -1269,7 +1267,6 @@ int vcpu_reset(struct vcpu *v) v->async_exception_mask =3D 0; memset(v->async_exception_state, 0, sizeof(v->async_exception_state)); #endif - cpumask_clear(v->cpu_hard_affinity_tmp); clear_bit(_VPF_blocked, &v->pause_flags); clear_bit(_VPF_in_reset, &v->pause_flags); =20 diff --git a/xen/include/asm-x86/pv/traps.h b/xen/include/asm-x86/pv/traps.h index fcc75f5e9a..855203c4e2 100644 --- a/xen/include/asm-x86/pv/traps.h +++ b/xen/include/asm-x86/pv/traps.h @@ -27,8 +27,7 @@ =20 void pv_trap_init(void); =20 -/* Deliver interrupt to PV guest. Return 0 on success. */ -int pv_raise_interrupt(struct vcpu *v, uint8_t vector); +int pv_raise_nmi(struct vcpu *v); =20 int pv_emulate_privileged_op(struct cpu_user_regs *regs); void pv_emulate_gate_op(struct cpu_user_regs *regs); @@ -46,8 +45,7 @@ static inline bool pv_trap_callback_registered(const stru= ct vcpu *v, =20 static inline void pv_trap_init(void) {} =20 -/* Deliver interrupt to PV guest. Return 0 on success. */ -static inline int pv_raise_interrupt(struct vcpu *v, uint8_t vector) { ret= urn -EOPNOTSUPP; } +static inline int pv_raise_nmi(struct vcpu *v) { return -EOPNOTSUPP; } =20 static inline int pv_emulate_privileged_op(struct cpu_user_regs *regs) { r= eturn 0; } static inline void pv_emulate_gate_op(struct cpu_user_regs *regs) {} diff --git a/xen/include/asm-x86/softirq.h b/xen/include/asm-x86/softirq.h index 5c1a7db566..0b7a77f11f 100644 --- a/xen/include/asm-x86/softirq.h +++ b/xen/include/asm-x86/softirq.h @@ -1,7 +1,7 @@ #ifndef __ASM_SOFTIRQ_H__ #define __ASM_SOFTIRQ_H__ =20 -#define NMI_MCE_SOFTIRQ (NR_COMMON_SOFTIRQS + 0) +#define NMI_SOFTIRQ (NR_COMMON_SOFTIRQS + 0) #define TIME_CALIBRATE_SOFTIRQ (NR_COMMON_SOFTIRQS + 1) #define VCPU_KICK_SOFTIRQ (NR_COMMON_SOFTIRQS + 2) =20 diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index b40c8fd138..c197e93d73 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -245,8 +245,6 @@ struct vcpu =20 /* Bitmask of CPUs on which this VCPU may run. */ cpumask_var_t cpu_hard_affinity; - /* Used to change affinity temporarily. */ - cpumask_var_t cpu_hard_affinity_tmp; /* Used to restore affinity across S3. */ cpumask_var_t cpu_hard_affinity_saved; =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri May 3 00:41:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1563967693; cv=none; d=zoho.com; s=zohoarc; b=DUP8DWtD1pzCzQPd+Hzz2KoZ+52446Vr19uZb5UuiReqLCI7osPaF1zfMplziG/vTXAXTD31kA8mPDsMcV0FDCHBPG6I0DypGt4W/C4GZC05G8H8r4VZXLxNgX9jOzuXlhcn09MxNDk+9aUNkYdItdWtXmM9GSOre9N1s55EoEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563967693; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=a9Mb2UBqaM6rYfaapBc+eX2C58MauIzuQN7Skkm+hHk=; b=mHGFLpq3U7tR7/Fk+2TF9i8yQ0hiM80pEKJHvrWoxb/jOowF9fFdaGyddeE4LWVatB8EzC9Xki9vOiBrkSTq3tnw8UFqTc9CODWwBdDhvsoL7EivWgArqY/VNIfgg45DGaTtaIF0VYlV6A0tOUrXvo5E4vspNqlT+5ddTzvwBMM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1563967693408900.9587789541603; Wed, 24 Jul 2019 04:28:13 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hqFQH-00029H-KU; Wed, 24 Jul 2019 11:27:05 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hqFQG-00029C-NB for xen-devel@lists.xenproject.org; Wed, 24 Jul 2019 11:27:04 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id f557fda0-ae05-11e9-8980-bc764e045a96; Wed, 24 Jul 2019 11:27:03 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 48925AF7E; Wed, 24 Jul 2019 11:27:02 +0000 (UTC) X-Inumbo-ID: f557fda0-ae05-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Wed, 24 Jul 2019 13:26:58 +0200 Message-Id: <20190724112658.31495-3-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190724112658.31495-1-jgross@suse.com> References: <20190724112658.31495-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v3 2/2] xen: merge temporary vcpu pinning scenarios X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Today there are two scenarios which are pinning vcpus temporarily to a single physical cpu: - wait_event() handling - SCHEDOP_pin_override handling Each of those cases are handled independently today using their own temporary cpumask to save the old affinity settings. The two cases can be combined as the first case will only pin a vcpu to the physical cpu it is already running on, while SCHEDOP_pin_override is allowed to fail. So merge the two temporary pinning scenarios by only using one cpumask and a per-vcpu bitmask for specifying which of the scenarios is currently active (they are both allowed to be active for the same vcpu). Note that we don't need to call domain_update_node_affinity() as we are only pinning for a brief period of time. Signed-off-by: Juergen Gross Reviewed-by: Andrew Cooper Reviewed-by: Dario Faggioli --- V2: - removed the NMI/MCE case - rename vcpu_set_tmp_affinity() (Jan Beulich) - remove vcpu_pin_override() wrapper (Andrew Cooper) - current -> curr (Jan Beulich, Andrew Cooper) - make cpu parameter unsigned int (Jan Beulich) - add comment (Dario Faggioli) V3: - reject SCHEDOP_pin_override with NR_CPUS (Jan Beulich) --- xen/common/domain.c | 1 + xen/common/domctl.c | 2 +- xen/common/schedule.c | 50 +++++++++++++++++++++++++++++++++++----------= ---- xen/common/wait.c | 30 ++++++++++------------------- xen/include/xen/sched.h | 8 +++++--- 5 files changed, 53 insertions(+), 38 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index bc56a51815..e8e850796e 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1267,6 +1267,7 @@ int vcpu_reset(struct vcpu *v) v->async_exception_mask =3D 0; memset(v->async_exception_state, 0, sizeof(v->async_exception_state)); #endif + v->affinity_broken =3D 0; clear_bit(_VPF_blocked, &v->pause_flags); clear_bit(_VPF_in_reset, &v->pause_flags); =20 diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 72a44953d0..fa260ce5fb 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -654,7 +654,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) =20 /* Undo a stuck SCHED_pin_override? */ if ( vcpuaff->flags & XEN_VCPUAFFINITY_FORCE ) - vcpu_pin_override(v, -1); + vcpu_temporary_affinity(v, NR_CPUS, VCPU_AFFINITY_OVERRIDE= ); =20 ret =3D 0; =20 diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 349f9624f5..130b97d875 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -1106,43 +1106,59 @@ void watchdog_domain_destroy(struct domain *d) kill_timer(&d->watchdog_timer[i]); } =20 -int vcpu_pin_override(struct vcpu *v, int cpu) +/* + * Pin a vcpu temporarily to a specific CPU (or restore old pinning state = if + * cpu is NR_CPUS). + * Temporary pinning can be done due to two reasons, which may be nested: + * - VCPU_AFFINITY_OVERRIDE (requested by guest): is allowed to fail in ca= se + * of a conflict (e.g. in case cpupool doesn't include requested CPU, or + * another conflicting temporary pinning is already in effect. + * - VCPU_AFFINITY_WAIT (called by wait_event()): only used to pin vcpu to= the + * CPU it is just running on. Can't fail if used properly. + */ +int vcpu_temporary_affinity(struct vcpu *v, unsigned int cpu, uint8_t reas= on) { spinlock_t *lock; int ret =3D -EINVAL; + bool migrate; =20 lock =3D vcpu_schedule_lock_irq(v); =20 - if ( cpu < 0 ) + if ( cpu =3D=3D NR_CPUS ) { - if ( v->affinity_broken ) + if ( v->affinity_broken & reason ) { - sched_set_affinity(v, v->cpu_hard_affinity_saved, NULL); - v->affinity_broken =3D 0; ret =3D 0; + v->affinity_broken &=3D ~reason; } + if ( !ret && !v->affinity_broken ) + sched_set_affinity(v, v->cpu_hard_affinity_saved, NULL); } else if ( cpu < nr_cpu_ids ) { - if ( v->affinity_broken ) + if ( (v->affinity_broken & reason) || + (v->affinity_broken && v->processor !=3D cpu) ) ret =3D -EBUSY; else if ( cpumask_test_cpu(cpu, VCPU2ONLINE(v)) ) { - cpumask_copy(v->cpu_hard_affinity_saved, v->cpu_hard_affinity); - v->affinity_broken =3D 1; - sched_set_affinity(v, cpumask_of(cpu), NULL); + if ( !v->affinity_broken ) + { + cpumask_copy(v->cpu_hard_affinity_saved, v->cpu_hard_affin= ity); + sched_set_affinity(v, cpumask_of(cpu), NULL); + } + v->affinity_broken |=3D reason; ret =3D 0; } } =20 - if ( ret =3D=3D 0 ) + migrate =3D !ret && !cpumask_test_cpu(v->processor, v->cpu_hard_affini= ty); + if ( migrate ) vcpu_migrate_start(v); =20 vcpu_schedule_unlock_irq(lock, v); =20 - domain_update_node_affinity(v->domain); - - vcpu_migrate_finish(v); + if ( migrate ) + vcpu_migrate_finish(v); =20 return ret; } @@ -1258,6 +1274,7 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(voi= d) arg) case SCHEDOP_pin_override: { struct sched_pin_override sched_pin_override; + unsigned int cpu; =20 ret =3D -EPERM; if ( !is_hardware_domain(current->domain) ) @@ -1267,7 +1284,12 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(vo= id) arg) if ( copy_from_guest(&sched_pin_override, arg, 1) ) break; =20 - ret =3D vcpu_pin_override(current, sched_pin_override.pcpu); + ret =3D -EINVAL; + if ( sched_pin_override.pcpu >=3D NR_CPUS ) + break; + + cpu =3D sched_pin_override.pcpu < 0 ? NR_CPUS : sched_pin_override= .pcpu; + ret =3D vcpu_temporary_affinity(current, cpu, VCPU_AFFINITY_OVERRI= DE); =20 break; } diff --git a/xen/common/wait.c b/xen/common/wait.c index 4f830a14e8..3fc5f68611 100644 --- a/xen/common/wait.c +++ b/xen/common/wait.c @@ -34,8 +34,6 @@ struct waitqueue_vcpu { */ void *esp; char *stack; - cpumask_t saved_affinity; - unsigned int wakeup_cpu; #endif }; =20 @@ -131,12 +129,10 @@ static void __prepare_to_wait(struct waitqueue_vcpu *= wqv) ASSERT(wqv->esp =3D=3D 0); =20 /* Save current VCPU affinity; force wakeup on *this* CPU only. */ - wqv->wakeup_cpu =3D smp_processor_id(); - cpumask_copy(&wqv->saved_affinity, curr->cpu_hard_affinity); - if ( vcpu_set_hard_affinity(curr, cpumask_of(wqv->wakeup_cpu)) ) + if ( vcpu_temporary_affinity(curr, smp_processor_id(), VCPU_AFFINITY_W= AIT) ) { gdprintk(XENLOG_ERR, "Unable to set vcpu affinity\n"); - domain_crash(current->domain); + domain_crash(curr->domain); =20 for ( ; ; ) do_softirq(); @@ -170,7 +166,7 @@ static void __prepare_to_wait(struct waitqueue_vcpu *wq= v) if ( unlikely(wqv->esp =3D=3D 0) ) { gdprintk(XENLOG_ERR, "Stack too large in %s\n", __func__); - domain_crash(current->domain); + domain_crash(curr->domain); =20 for ( ; ; ) do_softirq(); @@ -182,30 +178,24 @@ static void __prepare_to_wait(struct waitqueue_vcpu *= wqv) static void __finish_wait(struct waitqueue_vcpu *wqv) { wqv->esp =3D NULL; - (void)vcpu_set_hard_affinity(current, &wqv->saved_affinity); + vcpu_temporary_affinity(current, NR_CPUS, VCPU_AFFINITY_WAIT); } =20 void check_wakeup_from_wait(void) { - struct waitqueue_vcpu *wqv =3D current->waitqueue_vcpu; + struct vcpu *curr =3D current; + struct waitqueue_vcpu *wqv =3D curr->waitqueue_vcpu; =20 ASSERT(list_empty(&wqv->list)); =20 if ( likely(wqv->esp =3D=3D NULL) ) return; =20 - /* Check if we woke up on the wrong CPU. */ - if ( unlikely(smp_processor_id() !=3D wqv->wakeup_cpu) ) + /* Check if we are still pinned. */ + if ( unlikely(!(curr->affinity_broken & VCPU_AFFINITY_WAIT)) ) { - /* Re-set VCPU affinity and re-enter the scheduler. */ - struct vcpu *curr =3D current; - cpumask_copy(&wqv->saved_affinity, curr->cpu_hard_affinity); - if ( vcpu_set_hard_affinity(curr, cpumask_of(wqv->wakeup_cpu)) ) - { - gdprintk(XENLOG_ERR, "Unable to set vcpu affinity\n"); - domain_crash(current->domain); - } - wait(); /* takes us back into the scheduler */ + gdprintk(XENLOG_ERR, "vcpu affinity lost\n"); + domain_crash(curr->domain); } =20 /* diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index c197e93d73..9578628c6a 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -200,7 +200,9 @@ struct vcpu /* VCPU is paused following shutdown request (d->is_shutting_down)? */ bool paused_for_shutdown; /* VCPU need affinity restored */ - bool affinity_broken; + uint8_t affinity_broken; +#define VCPU_AFFINITY_OVERRIDE 0x01 +#define VCPU_AFFINITY_WAIT 0x02 =20 /* A hypercall has been preempted. */ bool hcall_preempted; @@ -245,7 +247,7 @@ struct vcpu =20 /* Bitmask of CPUs on which this VCPU may run. */ cpumask_var_t cpu_hard_affinity; - /* Used to restore affinity across S3. */ + /* Used to save affinity during temporary pinning. */ cpumask_var_t cpu_hard_affinity_saved; =20 /* Bitmask of CPUs on which this VCPU prefers to run. */ @@ -873,10 +875,10 @@ int cpu_disable_scheduler(unsigned int cpu); /* We need it in dom0_setup_vcpu */ void sched_set_affinity(struct vcpu *v, const cpumask_t *hard, const cpumask_t *soft); +int vcpu_temporary_affinity(struct vcpu *v, unsigned int cpu, uint8_t reas= on); int vcpu_set_hard_affinity(struct vcpu *v, const cpumask_t *affinity); int vcpu_set_soft_affinity(struct vcpu *v, const cpumask_t *affinity); void restore_vcpu_affinity(struct domain *d); -int vcpu_pin_override(struct vcpu *v, int cpu); =20 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate= ); uint64_t get_cpu_idle_time(unsigned int cpu); --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel