From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 2002:ac2:4841:0:0:0:0:0 with SMTP id 1csp2857138lfy; Mon, 27 Jul 2020 06:28:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3Wvy2eJDzEEXKjdX8p1Z43MJBSfMc+hpVZZTAj5tkzS1W6MKSqBvRfxm8LtFO3bjMPgLO X-Received: by 2002:adf:f008:: with SMTP id j8mr19425555wro.385.1595856537878; Mon, 27 Jul 2020 06:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595856537; cv=none; d=google.com; s=arc-20160816; b=wtoBYUnHUpTvghAsRt49p09ZaaCaQUiq2UXdkYaMx2z/PrAidZXbJeB1ajPiMo3mtA si7eN2xJmwqzkeUR+2/5zOFMan2cp2iAWHtdl7su787gAhsfdkgLX/Zci4smhDIclcME GGLD2ocAx4cYTCHvhvGwlZB1piwZmAvHh9tvfArhyoJKFs1oRJfW/UVbdaOQxrKwxZN1 sT+TgtvXzIbF5p+Q992yoHmek5jf0fYaYJKimtt/0JWdmAfoTPfpgOvbqVRi1mFdFf6a 4l/PpP4Bu/izB6C3SeZS8WplIs0wHBaChlZFTwFU0p7q+C30mCMVCknxnMl7OL96xivb ShDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date; bh=pWaOpsnrEsgtvooek4yBnxXe8AUAQBtQX+nVpr1u8SA=; b=BskrAnVAvcO+CZ8gWTGL2FZksZBO79L+37NZSkjpR6bcdXPdjilBaO/FeJ5+ClD9Kg geEnwOB3mV+XMmiWXMEWYW6fP7sTCI8CmFd4Z7CbVxEVFHcmE8IfmQ/A3d6ZGGW5xLvu YhfZRX+6CALJJSxAin38Xb0SEG53uew2V9PX6778AyC66R3wTSIoA4l2fe6t5S4o2mpx 4N1Ynn3xrDsXxajY3MsLLQjLnNteqJUhqWuBxF6wG4aDV98ZvT2X5ER9R+0k4ab0ik+F WJOlclTp+1zHWAF9iP96dMYj3J3EDo89Y5ArIhF8cYDFN0gEffzLJS7uV1V1mL6QX3Yu MtwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of groug@kaod.org designates 178.33.42.204 as permitted sender) smtp.mailfrom=groug@kaod.org Return-Path: Received: from 8.mo6.mail-out.ovh.net (8.mo6.mail-out.ovh.net. [178.33.42.204]) by mx.google.com with ESMTPS id d128si10302294wmd.220.2020.07.27.06.28.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jul 2020 06:28:57 -0700 (PDT) Received-SPF: pass (google.com: domain of groug@kaod.org designates 178.33.42.204 as permitted sender) client-ip=178.33.42.204; Authentication-Results: mx.google.com; spf=pass (google.com: domain of groug@kaod.org designates 178.33.42.204 as permitted sender) smtp.mailfrom=groug@kaod.org Received: from player758.ha.ovh.net (unknown [10.108.57.49]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id 770862211B0 for ; Mon, 27 Jul 2020 15:28:57 +0200 (CEST) Received: from kaod.org (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player758.ha.ovh.net (Postfix) with ESMTPSA id 7AC9814BEF0FE; Mon, 27 Jul 2020 13:28:29 +0000 (UTC) Authentication-Results:garm.ovh; auth=pass (GARM-95G001df390063-5d11-49a8-8d69-092e0317f1a0,B7B50C960922AB26A7D550ED897AF9E452A9EBFF) smtp.auth=groug@kaod.org Date: Mon, 27 Jul 2020 15:28:28 +0200 From: Greg Kurz To: Thiago Jung Bauermann Cc: qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-s390x@nongnu.org, qemu-devel@nongnu.org, David Gibson , Paolo Bonzini , Marcel Apfelbaum , Eduardo Habkost , Richard Henderson , Peter Maydell , Aleksandar Markovic , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Mark Cave-Ayland , Artyom Tarasenko , Cornelia Huck , Thomas Huth , David Hildenbrand , Philippe =?UTF-8?B?TWF0aGlldS1EYXVkw6k=?= , Alex =?UTF-8?B?QmVubsOpZQ==?= Subject: Re: [PATCH v3 3/8] ppc/spapr: Use start-powered-off CPUState property Message-ID: <20200727152828.133ee76a@bahia.lan> In-Reply-To: <20200723025657.644724-4-bauerman@linux.ibm.com> References: <20200723025657.644724-1-bauerman@linux.ibm.com> <20200723025657.644724-4-bauerman@linux.ibm.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 15463109323247032622 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduiedriedtgdeijecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvuffkjghfofggtgfgsehtjeertdertddvnecuhfhrohhmpefirhgvghcumfhurhiiuceoghhrohhugheskhgrohgurdhorhhgqeenucggtffrrghtthgvrhhnpeehkefhtdehgeehheejledufeekhfdvleefvdeihefhkefhudffhfeuuedvffdthfenucfkpheptddrtddrtddrtddpkedvrddvheefrddvtdekrddvgeeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepphhlrgihvghrjeehkedrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehgrhhouhhgsehkrghougdrohhrghdprhgtphhtthhopegrlhgvgidrsggvnhhnvggvsehlihhnrghrohdrohhrgh X-TUID: RYTLFQiw0C5E On Wed, 22 Jul 2020 23:56:52 -0300 Thiago Jung Bauermann wrote: > PowerPC sPAPR CPUs start in the halted state, and spapr_reset_vcpu() > attempts to implement this by setting CPUState::halted to 1. But that's too > late for the case of hotplugged CPUs in a machine configure with 2 or more > threads per core. > > By then, other parts of QEMU have already caused the vCPU to run in an > unitialized state a couple of times. For example, ppc_cpu_reset() calls > ppc_tlb_invalidate_all(), which ends up calling async_run_on_cpu(). This > kicks the new vCPU while it has CPUState::halted = 0, causing QEMU to issue > a KVM_RUN ioctl on the new vCPU before the guest is able to make the > start-cpu RTAS call to initialize its register state. > > This problem doesn't seem to cause visible issues for regular guests, but > on a secure guest running under the Ultravisor it does. The Ultravisor > relies on being able to snoop on the start-cpu RTAS call to map vCPUs to > guests, and this issue causes it to see a stray vCPU that doesn't belong to > any guest. > > Fix by setting the start-powered-off CPUState property in > spapr_create_vcpu(), which makes cpu_common_reset() initialize > CPUState::halted to 1 at an earlier moment. > > Suggested-by: Eduardo Habkost > Signed-off-by: Thiago Jung Bauermann > --- Thanks for doing this ! I remember seeing partly initialized CPUs being kicked in the past, which is clearly wrong but I never got time to find a proper fix (especially since it didn't seem to break anything). Reviewed-by: Greg Kurz > hw/ppc/spapr_cpu_core.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > NB: Tested on ppc64le pseries KVM guest with two threads per core. > Hot-plugging additional cores doesn't cause the bug described above > anymore. > > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c > index c4f47dcc04..2125fdac34 100644 > --- a/hw/ppc/spapr_cpu_core.c > +++ b/hw/ppc/spapr_cpu_core.c > @@ -36,11 +36,6 @@ static void spapr_reset_vcpu(PowerPCCPU *cpu) > > cpu_reset(cs); > > - /* All CPUs start halted. CPU0 is unhalted from the machine level > - * reset code and the rest are explicitly started up by the guest > - * using an RTAS call */ > - cs->halted = 1; > - > env->spr[SPR_HIOR] = 0; > > lpcr = env->spr[SPR_LPCR]; > @@ -274,6 +269,11 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp) > > cs = CPU(obj); > cpu = POWERPC_CPU(obj); > + /* > + * All CPUs start halted. CPU0 is unhalted from the machine level reset code > + * and the rest are explicitly started up by the guest using an RTAS call. > + */ > + cs->start_powered_off = true; > cs->cpu_index = cc->core_id + i; > spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err); > if (local_err) { From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65B6DC433DF for ; Mon, 27 Jul 2020 13:30:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36FA32074F for ; Mon, 27 Jul 2020 13:30:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36FA32074F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k03Ce-0005Q9-H4 for qemu-devel@archiver.kernel.org; Mon, 27 Jul 2020 09:30:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k03Bg-0004Vm-Pq for qemu-devel@nongnu.org; Mon, 27 Jul 2020 09:29:04 -0400 Received: from 3.mo179.mail-out.ovh.net ([178.33.251.175]:60345) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k03Bc-0007HG-OO for qemu-devel@nongnu.org; Mon, 27 Jul 2020 09:29:04 -0400 Received: from player758.ha.ovh.net (unknown [10.108.54.52]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id D810117363C for ; Mon, 27 Jul 2020 15:28:57 +0200 (CEST) Received: from kaod.org (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player758.ha.ovh.net (Postfix) with ESMTPSA id 7AC9814BEF0FE; Mon, 27 Jul 2020 13:28:29 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-95G001df390063-5d11-49a8-8d69-092e0317f1a0,B7B50C960922AB26A7D550ED897AF9E452A9EBFF) smtp.auth=groug@kaod.org Date: Mon, 27 Jul 2020 15:28:28 +0200 From: Greg Kurz To: Thiago Jung Bauermann Subject: Re: [PATCH v3 3/8] ppc/spapr: Use start-powered-off CPUState property Message-ID: <20200727152828.133ee76a@bahia.lan> In-Reply-To: <20200723025657.644724-4-bauerman@linux.ibm.com> References: <20200723025657.644724-1-bauerman@linux.ibm.com> <20200723025657.644724-4-bauerman@linux.ibm.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 15463109323247032622 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduiedriedtgdeijecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvuffkjghfofggtgfgsehtjeertdertddvnecuhfhrohhmpefirhgvghcumfhurhiiuceoghhrohhugheskhgrohgurdhorhhgqeenucggtffrrghtthgvrhhnpeehkefhtdehgeehheejledufeekhfdvleefvdeihefhkefhudffhfeuuedvffdthfenucfkpheptddrtddrtddrtddpkedvrddvheefrddvtdekrddvgeeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepphhlrgihvghrjeehkedrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehgrhhouhhgsehkrghougdrohhrghdprhgtphhtthhopehqvghmuhdquggvvhgvlhesnhhonhhgnhhurdhorhhg Received-SPF: pass client-ip=178.33.251.175; envelope-from=groug@kaod.org; helo=3.mo179.mail-out.ovh.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/27 09:28:58 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Rikalo , Eduardo Habkost , Aleksandar Markovic , Alex =?UTF-8?B?QmVubsOpZQ==?= , Cornelia Huck , Mark Cave-Ayland , qemu-devel@nongnu.org, qemu-s390x@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Artyom Tarasenko , Thomas Huth , Paolo Bonzini , David Hildenbrand , Richard Henderson , Philippe =?UTF-8?B?TWF0aGlldS1EYXVkw6k=?= , Aurelien Jarno , David Gibson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Wed, 22 Jul 2020 23:56:52 -0300 Thiago Jung Bauermann wrote: > PowerPC sPAPR CPUs start in the halted state, and spapr_reset_vcpu() > attempts to implement this by setting CPUState::halted to 1. But that's too > late for the case of hotplugged CPUs in a machine configure with 2 or more > threads per core. > > By then, other parts of QEMU have already caused the vCPU to run in an > unitialized state a couple of times. For example, ppc_cpu_reset() calls > ppc_tlb_invalidate_all(), which ends up calling async_run_on_cpu(). This > kicks the new vCPU while it has CPUState::halted = 0, causing QEMU to issue > a KVM_RUN ioctl on the new vCPU before the guest is able to make the > start-cpu RTAS call to initialize its register state. > > This problem doesn't seem to cause visible issues for regular guests, but > on a secure guest running under the Ultravisor it does. The Ultravisor > relies on being able to snoop on the start-cpu RTAS call to map vCPUs to > guests, and this issue causes it to see a stray vCPU that doesn't belong to > any guest. > > Fix by setting the start-powered-off CPUState property in > spapr_create_vcpu(), which makes cpu_common_reset() initialize > CPUState::halted to 1 at an earlier moment. > > Suggested-by: Eduardo Habkost > Signed-off-by: Thiago Jung Bauermann > --- Thanks for doing this ! I remember seeing partly initialized CPUs being kicked in the past, which is clearly wrong but I never got time to find a proper fix (especially since it didn't seem to break anything). Reviewed-by: Greg Kurz > hw/ppc/spapr_cpu_core.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > NB: Tested on ppc64le pseries KVM guest with two threads per core. > Hot-plugging additional cores doesn't cause the bug described above > anymore. > > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c > index c4f47dcc04..2125fdac34 100644 > --- a/hw/ppc/spapr_cpu_core.c > +++ b/hw/ppc/spapr_cpu_core.c > @@ -36,11 +36,6 @@ static void spapr_reset_vcpu(PowerPCCPU *cpu) > > cpu_reset(cs); > > - /* All CPUs start halted. CPU0 is unhalted from the machine level > - * reset code and the rest are explicitly started up by the guest > - * using an RTAS call */ > - cs->halted = 1; > - > env->spr[SPR_HIOR] = 0; > > lpcr = env->spr[SPR_LPCR]; > @@ -274,6 +269,11 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp) > > cs = CPU(obj); > cpu = POWERPC_CPU(obj); > + /* > + * All CPUs start halted. CPU0 is unhalted from the machine level reset code > + * and the rest are explicitly started up by the guest using an RTAS call. > + */ > + cs->start_powered_off = true; > cs->cpu_index = cc->core_id + i; > spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err); > if (local_err) {