From nobody Sat May 18 12:47:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606822832; cv=none; d=zohomail.com; s=zohoarc; b=nIp0a+qK94Sc6LFj0+tPVFO06X7P+/dbexFARirEsD9uGCz2TpySxLgIu8Oe9NoTojUDiQ//H3o/EBOGcEkzKT51tmuPdDqTSTSMqnf4hAb8o1W6Xsoei740RjRkEof2Sp4vgK6+vo6kMcwR+xxqQ7SBrAmWUgt2sDht2k8jqYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606822832; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=er04T710sqhiAAi3A1pCpWEvIaAHhtS1wD1odbCFb3o=; b=IT01xZv7ZEQJ+qjjimeq58RdDr6e+u+6casW0Gahe2FpXTuMj0RQBvGYF4JQHITEb0/h4z1E6nnofAlGLe/+libPYgKqVPhOh8P7cjkSs1Z8m1JDM+GOw6HoER9ybyhe1ZCIfgsF173ttOOXZ6yDxHNmnrnIsTwUN2sZVGmGI6E= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606822832325616.4097443074075; Tue, 1 Dec 2020 03:40:32 -0800 (PST) Received: from localhost ([::1]:36338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kk41H-000182-9w for importer@patchew.org; Tue, 01 Dec 2020 06:40:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kk3yX-0007AO-1M for qemu-devel@nongnu.org; Tue, 01 Dec 2020 06:37:41 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:38610) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kk3yU-0000mo-24 for qemu-devel@nongnu.org; Tue, 01 Dec 2020 06:37:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-496-UqDkPzuDNwqKyT-_csGFhQ-1; Tue, 01 Dec 2020 06:37:33 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E581107B457; Tue, 1 Dec 2020 11:37:32 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-87.ams2.redhat.com [10.36.112.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B17660BE5; Tue, 1 Dec 2020 11:37:31 +0000 (UTC) X-MC-Unique: UqDkPzuDNwqKyT-_csGFhQ-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 v2 1/4] spapr: Fix pre-2.10 dummy ICP hack Date: Tue, 1 Dec 2020 12:37:25 +0100 Message-Id: <20201201113728.885700-2-groug@kaod.org> In-Reply-To: <20201201113728.885700-1-groug@kaod.org> References: <20201201113728.885700-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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: Igor Mammedov , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This hack registers dummy VMState entries of ICPs in order to support migration of old pseries machine types that used to create all smp.max_cpus possible ICPs at machine init. Part of the work is to unregister the dummy entries when plugging an actual vCPU core, and to register them back when unplugging the core. The code that unregisters the dummy ICPs in spapr_core_plug() is misplaced: if ppc_set_compat() fails afterwards, the hotplug operation will be cancelled and the dummy ICPs won't be registered back since the unplug handler isn't called. Unregister the dummy ICPs at the end of spapr_core_plug(). Signed-off-by: Greg Kurz --- The next patch makes this patch a bit useless. I post it anyway for the records because it is a programming error. --- hw/ppc/spapr.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index e8b236a8313b..57c6eecc56d6 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3785,13 +3785,6 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, =20 core_slot->cpu =3D OBJECT(dev); =20 - if (smc->pre_2_10_has_unused_icps) { - for (i =3D 0; i < cc->nr_threads; i++) { - cs =3D CPU(core->threads[i]); - pre_2_10_vmstate_unregister_dummy_icp(cs->cpu_index); - } - } - /* * Set compatibility mode to match the boot CPU, which was either set * by the machine reset code or by CAS. @@ -3805,6 +3798,13 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, } } } + + if (smc->pre_2_10_has_unused_icps) { + for (i =3D 0; i < cc->nr_threads; i++) { + cs =3D CPU(core->threads[i]); + pre_2_10_vmstate_unregister_dummy_icp(cs->cpu_index); + } + } } =20 static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *= dev, --=20 2.26.2 From nobody Sat May 18 12:47:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606822899; cv=none; d=zohomail.com; s=zohoarc; b=OWLiNfFe2OSGgcI6lzEEYenK+cdzNhYSQrLzBjx/gPVl3yHyBWsmhj7eRXdR+b9XZwKyL2doIZqHqVuXA5KFKk3mqzKFN7qRUVcWi7lgMa6I14/c7QPy2hZz41PSkCDLGuZpkLg/C0L8TyeplT26M65UooYrs7hW9JTRbKeNUj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606822899; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QlvjEizF0KM8Gj1WOKaBZQ3tEdnyboGaVOzveT9EZAo=; b=cY7un19A6Hzwx3vUANuKQjeJGG/pa8C8gRuT/ywLZG/AdDvCAu7cx2yFyJjQpoTRei2GZgWBKXvNCRa7cunZ3Jl9IK+7aIzCgL8bgP8TmkpKPG8BaUcGZhdesqHjWUM5WrRTFkQEuG2eQtCGZAs3UPzqdkjkg4FZxKXiy2Pi+Ro= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606822899549432.17177115684524; Tue, 1 Dec 2020 03:41:39 -0800 (PST) Received: from localhost ([::1]:38922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kk42M-0002Md-EK for importer@patchew.org; Tue, 01 Dec 2020 06:41:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kk3yY-0007BE-MS for qemu-devel@nongnu.org; Tue, 01 Dec 2020 06:37:42 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:40369) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kk3yW-0000o6-Q6 for qemu-devel@nongnu.org; Tue, 01 Dec 2020 06:37:41 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-35-US-GbGezNwCoydBl52mYQQ-1; Tue, 01 Dec 2020 06:37:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C1A91005E45; Tue, 1 Dec 2020 11:37:36 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-87.ams2.redhat.com [10.36.112.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A35B60BE5; Tue, 1 Dec 2020 11:37:32 +0000 (UTC) X-MC-Unique: US-GbGezNwCoydBl52mYQQ-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 v2 2/4] spapr: Abort if ppc_set_compat() fails for hot-plugged CPUs Date: Tue, 1 Dec 2020 12:37:26 +0100 Message-Id: <20201201113728.885700-3-groug@kaod.org> In-Reply-To: <20201201113728.885700-1-groug@kaod.org> References: <20201201113728.885700-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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: Igor Mammedov , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When a CPU is hot-plugged, we set its compat mode to match the boot CPU, which was either set by machine reset or by CAS. This is currently handled in the plug handler after the core got realized. Potential errors of ppc_set_compat() are propagated to the hot-plug logic. Handling errors this late in the hot-plug sequence is generally frown upon. Ideally, we should do sanity checks in a pre-plug handler and pass &error_abort to ppc_set_compat() in the plug handler. We can filter out some error cases of ppc_set_compat() by calling ppc_check_compat() at pre-plug. But ppc_set_compat() also sets the compat register in KVM, and KVM doesn't provide any API that would allow to check valid compat mode settings beforehand. However, at this point we know that the compat mode was already successfully set for the boot CPU. Since this all boils down to setting a register with the very same value that was valid for the boot CPU, it should definitely not fail for hot-plugged CPUS. Pass &error_abort to ppc_set_compat(). Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 57c6eecc56d6..3a32918dd9a9 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3787,15 +3787,13 @@ static void spapr_core_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, =20 /* * Set compatibility mode to match the boot CPU, which was either set - * by the machine reset code or by CAS. + * by the machine reset code or by CAS. This really shouldn't fail at + * this point. */ if (hotplugged) { for (i =3D 0; i < cc->nr_threads; i++) { - if (ppc_set_compat(core->threads[i], - POWERPC_CPU(first_cpu)->compat_pvr, - errp) < 0) { - return; - } + ppc_set_compat(core->threads[i], POWERPC_CPU(first_cpu)->compa= t_pvr, + &error_abort); } } =20 --=20 2.26.2 From nobody Sat May 18 12:47:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606823001; cv=none; d=zohomail.com; s=zohoarc; b=RXWYSSSe1NTk9YuCOz0DBBJI1VCvdJymaUat0VntHKGD+kHXCu33eG2TUjR4Ux3li+OI/nOHlgZ5PqMZMcKfTn/4DH2AoUZSJRo3Cg/SR3bl7F4XP5NhWrHoNCSe+PnBil7aGGjp12wTrnoT+YWJ59J8t9ULCRs1hgWsam8qT/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606823001; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kTIHSpyG5eALbY2Xyfa+sa8P09rnBNULO0CzqBdAt78=; b=aEy2mL9fU2IT30NlntGYEUepnZcocNwNsa0yu3AkqXO+lBgvfi4PQnsbE5fgYYyWPNhIXX3tQoTNfSArk5bVWDUOt3QWzmtXuHGXqZCcaz2bZMwHU2I1h1lpQIpteFLTl0gYpJ0uPjtEFP1ywk1aaNjHucK/QGURuBnHLOdkqMU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606823001160334.35863802622896; Tue, 1 Dec 2020 03:43:21 -0800 (PST) Received: from localhost ([::1]:41056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kk43z-0003IW-VR for importer@patchew.org; Tue, 01 Dec 2020 06:43:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kk3yZ-0007Bk-Bm for qemu-devel@nongnu.org; Tue, 01 Dec 2020 06:37:44 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:43335) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kk3yX-0000oF-2O for qemu-devel@nongnu.org; Tue, 01 Dec 2020 06:37:43 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-256-wt_5bDwdOoS3bOHTMZMOgQ-1; Tue, 01 Dec 2020 06:37:38 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB3AB107B457; Tue, 1 Dec 2020 11:37:37 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-87.ams2.redhat.com [10.36.112.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9769D60BE5; Tue, 1 Dec 2020 11:37:36 +0000 (UTC) X-MC-Unique: wt_5bDwdOoS3bOHTMZMOgQ-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 v2 3/4] spapr: Simplify error path of spapr_core_plug() Date: Tue, 1 Dec 2020 12:37:27 +0100 Message-Id: <20201201113728.885700-4-groug@kaod.org> In-Reply-To: <20201201113728.885700-1-groug@kaod.org> References: <20201201113728.885700-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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: Igor Mammedov , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" spapr_core_pre_plug() already guarantees that the slot for the given core ID is available. It is thus safe to assume that spapr_find_cpu_slot() returns a slot during plug. Turn the error path into an assertion. It is also safe to assume that no device is attached to the corresponding DRC and that spapr_drc_attach() shouldn't fail. Pass &error_abort to spapr_drc_attach() and simplify error handling. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 3a32918dd9a9..6707fafdd313 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3741,8 +3741,7 @@ int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachin= eState *spapr, return 0; } =20 -static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, - Error **errp) +static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev) { SpaprMachineState *spapr =3D SPAPR_MACHINE(OBJECT(hotplug_dev)); MachineClass *mc =3D MACHINE_GET_CLASS(spapr); @@ -3757,20 +3756,20 @@ static void spapr_core_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, int i; =20 core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &= index); - if (!core_slot) { - error_setg(errp, "Unable to find CPU core with core-id: %d", - cc->core_id); - return; - } + g_assert(core_slot); /* Already checked in spapr_core_pre_plug() */ + drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, spapr_vcpu_id(spapr, cc->core_id)); =20 g_assert(drc || !mc->has_hotpluggable_cpus); =20 if (drc) { - if (!spapr_drc_attach(drc, dev, errp)) { - return; - } + /* + * spapr_core_pre_plug() already buys us this is a brand new + * core being plugged into a free slot. Nothing should already + * be attached to the corresponding DRC. + */ + spapr_drc_attach(drc, dev, &error_abort); =20 if (hotplugged) { /* @@ -4012,7 +4011,7 @@ static void spapr_machine_device_plug(HotplugHandler = *hotplug_dev, if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { spapr_memory_plug(hotplug_dev, dev); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { - spapr_core_plug(hotplug_dev, dev, errp); + spapr_core_plug(hotplug_dev, dev); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE= )) { spapr_phb_plug(hotplug_dev, dev); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_TPM_PROXY)) { --=20 2.26.2 From nobody Sat May 18 12:47:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606823082; cv=none; d=zohomail.com; s=zohoarc; b=QcNJzf0BOHKfTXD6ma7+cmxvNM+ASN/EwM9ZbfiTQ2UXkqA16n+Wz4G3ivHgYHik4Ob1YErddoASirZsS/arzm7GKLvl4GsVFEivh7pAmGG04TeK3EcBgxBikKKS4tGvN/FmpWq5J6ROf1iek1RHBEug0tOtSu7n2r/nVbj2HMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606823082; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YDZdMyNgkH2FVunhi/Xnojs29G5fFUSg49m357S+hrw=; b=KppZix5dIqRKBNTeiO8jMBYdWPW4j/RLfkLzXPH2zhrGPrpw/Djay0ByPU5sgCqNbf76VLFsiE045+XehYBQey+VywVyLzvms4C3+wkn1lvTKavWuWTotukqPUOonvyeGlWbnKnretgVhqVhld//1BQrU/buIqjnlH/QXB1xZbI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606823082395200.7181438130251; Tue, 1 Dec 2020 03:44:42 -0800 (PST) Received: from localhost ([::1]:45388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kk45J-000527-1F for importer@patchew.org; Tue, 01 Dec 2020 06:44:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kk3yd-0007HM-Pi for qemu-devel@nongnu.org; Tue, 01 Dec 2020 06:37:47 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:41242) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kk3yb-0000q7-4L for qemu-devel@nongnu.org; Tue, 01 Dec 2020 06:37:47 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-509-xqIY-lvoMLqt_ptSJaOY7g-1; Tue, 01 Dec 2020 06:37:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 383EA1842141; Tue, 1 Dec 2020 11:37:39 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-87.ams2.redhat.com [10.36.112.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12E5260BE5; Tue, 1 Dec 2020 11:37:37 +0000 (UTC) X-MC-Unique: xqIY-lvoMLqt_ptSJaOY7g-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH for-6.0 v2 4/4] spapr: spapr_drc_attach() cannot fail Date: Tue, 1 Dec 2020 12:37:28 +0100 Message-Id: <20201201113728.885700-5-groug@kaod.org> In-Reply-To: <20201201113728.885700-1-groug@kaod.org> References: <20201201113728.885700-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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: Igor Mammedov , qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" All users are passing &error_abort already. Document the fact that spapr_drc_attach() should only be passed a free DRC, which is supposedly the case if appropriate checking is done earlier. Signed-off-by: Greg Kurz --- include/hw/ppc/spapr_drc.h | 8 +++++++- hw/ppc/spapr.c | 6 +++--- hw/ppc/spapr_drc.c | 8 ++------ hw/ppc/spapr_nvdimm.c | 2 +- hw/ppc/spapr_pci.c | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 165b281496bb..def3593adc8b 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -235,7 +235,13 @@ SpaprDrc *spapr_drc_by_index(uint32_t index); SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id); int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_m= ask); =20 -bool spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp); +/* + * These functions respectively abort if called with a device already + * attached or no device attached. In the case of spapr_drc_attach(), + * this means that the attachability of the DRC *must* be checked + * beforehand (eg. check drc->dev at pre-plug). + */ +void spapr_drc_attach(SpaprDrc *drc, DeviceState *d); void spapr_drc_detach(SpaprDrc *drc); =20 /* Returns true if a hot plug/unplug request is pending */ diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 6707fafdd313..d1dcf3ab2c94 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3401,7 +3401,7 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, * that doesn't overlap with any existing mapping at pre-plug. The * corresponding LMB DRCs are thus assumed to be all attachable. */ - spapr_drc_attach(drc, dev, &error_abort); + spapr_drc_attach(drc, dev); if (!hotplugged) { spapr_drc_reset(drc); } @@ -3769,7 +3769,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev) * core being plugged into a free slot. Nothing should already * be attached to the corresponding DRC. */ - spapr_drc_attach(drc, dev, &error_abort); + spapr_drc_attach(drc, dev); =20 if (hotplugged) { /* @@ -3934,7 +3934,7 @@ static void spapr_phb_plug(HotplugHandler *hotplug_de= v, DeviceState *dev) assert(drc); =20 /* spapr_phb_pre_plug() already checked the DRC is attachable */ - spapr_drc_attach(drc, dev, &error_abort); + spapr_drc_attach(drc, dev); =20 if (hotplugged) { spapr_hotplug_req_add_by_index(drc); diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 77718cde1ff2..f991cf89a08a 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -369,14 +369,11 @@ static void prop_get_fdt(Object *obj, Visitor *v, con= st char *name, } while (fdt_depth !=3D 0); } =20 -bool spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp) +void spapr_drc_attach(SpaprDrc *drc, DeviceState *d) { trace_spapr_drc_attach(spapr_drc_index(drc)); =20 - if (drc->dev) { - error_setg(errp, "an attached device is still awaiting release"); - return false; - } + g_assert(!drc->dev); g_assert((drc->state =3D=3D SPAPR_DRC_STATE_LOGICAL_UNUSABLE) || (drc->state =3D=3D SPAPR_DRC_STATE_PHYSICAL_POWERON)); =20 @@ -386,7 +383,6 @@ bool spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Er= ror **errp) object_get_typename(OBJECT(drc->dev)), (Object **)(&drc->dev), NULL, 0); - return true; } =20 static void spapr_drc_release(SpaprDrc *drc) diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c index 2f1c196e1b76..73ee006541a6 100644 --- a/hw/ppc/spapr_nvdimm.c +++ b/hw/ppc/spapr_nvdimm.c @@ -101,7 +101,7 @@ void spapr_add_nvdimm(DeviceState *dev, uint64_t slot) * pc_dimm_get_free_slot() provided a free slot at pre-plug. The * corresponding DRC is thus assumed to be attachable. */ - spapr_drc_attach(drc, dev, &error_abort); + spapr_drc_attach(drc, dev); =20 if (hotplugged) { spapr_hotplug_req_add_by_index(drc); diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 2829f298d9c1..e946bd5055cc 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1601,7 +1601,7 @@ static void spapr_pci_plug(HotplugHandler *plug_handl= er, } =20 /* spapr_pci_pre_plug() already checked the DRC is attachable */ - spapr_drc_attach(drc, DEVICE(pdev), &error_abort); + spapr_drc_attach(drc, DEVICE(pdev)); =20 /* If this is function 0, signal hotplug for all the device functions. * Otherwise defer sending the hotplug event. --=20 2.26.2