From nobody Sun May 5 23:49:09 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.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 (zohomail.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=1582910078; cv=none; d=zohomail.com; s=zohoarc; b=fou0Kyba1UI7CJTVi6JIcc83pj0iaSOTt6AB3lxyQdP/RGCs65DIirmrqztNsmFb5RL0cbAcLOlkUqC8fsoxRKUXCz6l2L4cLGzpy2307wYZq6ovP77tFoPJRkA3sW1c59q8IlMuEdoNn1ncf+lnO1Cr2Y+r4D/H2A+l4rqrC9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582910078; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=0Qwy/zONFwEf8EhgPJ4McH0koSEE0S5eBVSy9d12JqA=; b=Ztd7ICEiA65qAuONr7uGVX54MRp7YN/YzbqaLemOTuA+cfQzKS9wpeYGaDOwu8UHZyGn6Phr0nIQE/pdKeI8VhL6pMCX/NbKtxUFlELcybXoveO1ldOGOuqUlhhjF+O2A22rZP8PiVDqYDeNeNsngJT8ixoRf1VkLIl1gIt20+0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.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 1582910078951613.141142732989; Fri, 28 Feb 2020 09:14:38 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j7jD0-0003Ik-18; Fri, 28 Feb 2020 17:13:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j7jCy-0003If-NB for xen-devel@lists.xenproject.org; Fri, 28 Feb 2020 17:13:52 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b0e99d66-5a4d-11ea-b472-bc764e2007e4; Fri, 28 Feb 2020 17:13:52 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 744CFAAF1; Fri, 28 Feb 2020 17:13:50 +0000 (UTC) X-Inumbo-ID: b0e99d66-5a4d-11ea-b472-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 28 Feb 2020 18:13:48 +0100 Message-Id: <20200228171348.21864-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Subject: [Xen-devel] [PATCH v3] xen: make sure stop_machine_run() is always called in a tasklet 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 , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Ian Jackson , George Dunlap , 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" With core scheduling active it is mandatory for stop_machine_run() to be called in idle context only (so either during boot or in a tasklet), as otherwise a scheduling deadlock would occur: stop_machine_run() does a cpu rendezvous by activating a tasklet on all other cpus. In case stop_machine_run() was not called in an idle vcpu it would block scheduling the idle vcpu on its siblings with core scheduling being active, resulting in a hang. Put a BUG_ON() into stop_machine_run() to test for being called in an idle vcpu only and adapt the missing call site (ucode loading) to use a tasklet for calling stop_machine_run(). Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - rephrase commit message (Julien Grall) V3: - add comments (Jan Beulich) --- xen/arch/x86/microcode.c | 54 +++++++++++++++++++++++++++++--------------= ---- xen/common/rcupdate.c | 4 ++++ xen/common/stop_machine.c | 7 ++++++ 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index 35c1d36cdc..4cf4e66b18 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -562,30 +562,18 @@ static int do_microcode_update(void *patch) return ret; } =20 -int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long= len) +struct ucode_buf { + unsigned int len; + char buffer[]; +}; + +static long microcode_update_helper(void *data) { int ret; - void *buffer; + struct ucode_buf *buffer =3D data; unsigned int cpu, updated; struct microcode_patch *patch; =20 - if ( len !=3D (uint32_t)len ) - return -E2BIG; - - if ( microcode_ops =3D=3D NULL ) - return -EINVAL; - - buffer =3D xmalloc_bytes(len); - if ( !buffer ) - return -ENOMEM; - - ret =3D copy_from_guest(buffer, buf, len); - if ( ret ) - { - xfree(buffer); - return -EFAULT; - } - /* cpu_online_map must not change during update */ if ( !get_cpu_maps() ) { @@ -607,7 +595,7 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void)= buf, unsigned long len) return -EPERM; } =20 - patch =3D parse_blob(buffer, len); + patch =3D parse_blob(buffer->buffer, buffer->len); xfree(buffer); if ( IS_ERR(patch) ) { @@ -700,6 +688,32 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void= ) buf, unsigned long len) return ret; } =20 +int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long= len) +{ + int ret; + struct ucode_buf *buffer; + + if ( len !=3D (uint32_t)len ) + return -E2BIG; + + if ( microcode_ops =3D=3D NULL ) + return -EINVAL; + + buffer =3D xmalloc_flex_struct(struct ucode_buf, buffer, len); + if ( !buffer ) + return -ENOMEM; + + ret =3D copy_from_guest(buffer->buffer, buf, len); + if ( ret ) + { + xfree(buffer); + return -EFAULT; + } + buffer->len =3D len; + + return continue_hypercall_on_cpu(0, microcode_update_helper, buffer); +} + static int __init microcode_init(void) { /* diff --git a/xen/common/rcupdate.c b/xen/common/rcupdate.c index 91d4ad0fd8..d76b991627 100644 --- a/xen/common/rcupdate.c +++ b/xen/common/rcupdate.c @@ -178,6 +178,10 @@ static int rcu_barrier_action(void *_cpu_count) return 0; } =20 +/* + * As rcu_barrier() is using stop_machine_run() it is allowed to be used in + * idle context only (see comment for stop_machine_run()). + */ int rcu_barrier(void) { atomic_t cpu_count =3D ATOMIC_INIT(0); diff --git a/xen/common/stop_machine.c b/xen/common/stop_machine.c index 33d9602217..2d5f6aef61 100644 --- a/xen/common/stop_machine.c +++ b/xen/common/stop_machine.c @@ -67,6 +67,12 @@ static void stopmachine_wait_state(void) cpu_relax(); } =20 +/* + * Sync all processors and call a function on one or all of them. + * As stop_machine_run() is using a tasklet for syncing the processors it = is + * mandatory to be called only on an idle vcpu, as otherwise active core + * scheduling might hang. + */ int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu) { unsigned int i, nr_cpus; @@ -74,6 +80,7 @@ int stop_machine_run(int (*fn)(void *), void *data, unsig= ned int cpu) int ret; =20 BUG_ON(!local_irq_is_enabled()); + BUG_ON(!is_idle_vcpu(current)); =20 /* cpu_online_map must not change. */ if ( !get_cpu_maps() ) --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel