From nobody Tue May 21 08:26:51 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=1596733047; cv=none; d=zohomail.com; s=zohoarc; b=mRJIhS6sVSV/YimSuMeoI5P3wh7l987LJCq9RSOiKUKjwJ03VXz5bq2fSPQWHb9fMUcouPgzJE/URvSmTuIKvt4IgW2DfVsxxlQZlbXWxXZwOt4hr+CyVqlZ+9dGhZ75j+yLdvpjUORlwKgmQ4ZZ2JLZN3i+1ZE+iIcATL+qGK4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596733047; 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=kqmqHI9VGtVi0q0k+jkuOn2RQhNLymFX0k/+cvyPFjw=; b=jy3eWrDy5fR+xBVJj4mU5yZjr6tNVmGpkEzusVBB1OZmmMT6MTggn3ZKQ/tzl938SYwe3ECax+1a9hGMUWY1URTdodtQgu3zTdPdCD6KbMHzSy4P2TKWcUu/zVeLiE4/WrF10Fw3eLSsp+bFBVq7k2stHuzraNNY6JoV9Q2npgo= 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 1596733047666281.30069945403534; Thu, 6 Aug 2020 09:57:27 -0700 (PDT) Received: from localhost ([::1]:38868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3jCo-0002AZ-C3 for importer@patchew.org; Thu, 06 Aug 2020 12:57:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3jBm-0000YG-WC for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:23 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:58857 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k3jBl-00075i-Jg for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:22 -0400 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-19-R_HECKsNOGydOJ88y0zoAg-1; Thu, 06 Aug 2020 12:56:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B57091DE5; Thu, 6 Aug 2020 16:56:07 +0000 (UTC) Received: from bahia.lan (ovpn-112-38.ams2.redhat.com [10.36.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id B865C5F9DC; Thu, 6 Aug 2020 16:56:06 +0000 (UTC) X-MC-Unique: R_HECKsNOGydOJ88y0zoAg-1 Subject: [PATCH v2 for-5.2 1/5] spapr/xive: Fix xive->fd if kvm_create_device() fails From: Greg Kurz To: David Gibson Date: Thu, 06 Aug 2020 18:56:05 +0200 Message-ID: <159673296585.766512.15404407281299745442.stgit@bahia.lan> In-Reply-To: <159673295739.766512.2950380687630225803.stgit@bahia.lan> References: <159673295739.766512.2950380687630225803.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.31.120; envelope-from=groug@kaod.org; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 03:10:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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_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: Daniel Henrique Barboza , qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If the creation of the KVM XIVE device fails for some reasons, the negative errno ends up in xive->fd, but the rest of the code assumes that xive->fd either contains an open fd, ie. positive value, or -1. This doesn't cause any misbehavior except kvmppc_xive_disconnect() that will try to close(xive->fd) during rollback and likely be rewarded with an EBADF. Only set xive->fd with a open fd. Signed-off-by: Greg Kurz --- v2: Already applied to ppc-for-5.2 but not yet visible on github --- hw/intc/spapr_xive_kvm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c index edb7ee0e74f1..d55ea4670e0e 100644 --- a/hw/intc/spapr_xive_kvm.c +++ b/hw/intc/spapr_xive_kvm.c @@ -745,6 +745,7 @@ int kvmppc_xive_connect(SpaprInterruptController *intc,= uint32_t nr_servers, size_t esb_len =3D (1ull << xsrc->esb_shift) * xsrc->nr_irqs; size_t tima_len =3D 4ull << TM_SHIFT; CPUState *cs; + int fd; =20 /* * The KVM XIVE device already in use. This is the case when @@ -760,11 +761,12 @@ int kvmppc_xive_connect(SpaprInterruptController *int= c, uint32_t nr_servers, } =20 /* First, create the KVM XIVE device */ - xive->fd =3D kvm_create_device(kvm_state, KVM_DEV_TYPE_XIVE, false); - if (xive->fd < 0) { - error_setg_errno(errp, -xive->fd, "XIVE: error creating KVM device= "); + fd =3D kvm_create_device(kvm_state, KVM_DEV_TYPE_XIVE, false); + if (fd < 0) { + error_setg_errno(errp, -fd, "XIVE: error creating KVM device"); return -1; } + xive->fd =3D fd; =20 /* Tell KVM about the # of VCPUs we may have */ if (kvm_device_check_attr(xive->fd, KVM_DEV_XIVE_GRP_CTRL, From nobody Tue May 21 08:26:51 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=1596733139; cv=none; d=zohomail.com; s=zohoarc; b=dv5lZF+RFOSgJRAL9hHZ/p8vihWJuMF68Do0bbbXOULUTlv7/7lWD9tpQRafvMMDy4Bzz7Snqrs3qFWVW8DP+XOuPcPB+WMFHLFpss38PP0NKDe2ogMQ/LSy2PHk9Am7El8TlA/D11ZdrPDl5n1NdW2XzhOugrB3iTQbVJcjjqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596733139; 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=Gb/DWS5Y3DUHRmnTXb7O8ofqkUQ/RLciDXl4vFmrftY=; b=W5zfd+y2k2cKhiE4QEBeQTmxF5X4JmhsOaxWCF1Ew+DgQiP8xAUz4jWvliZBq8emJjLF+JdbtWAKQuYisOoMXASoouiEgKhm72OsIfHLuyF+XuYc8T0Uc8OdYMyIgyRyoYsRG9gDJ1O98/TuKK5bWnmUMLh6uMkRvtGpbTtNYSI= 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 1596733139030331.4224725441384; Thu, 6 Aug 2020 09:58:59 -0700 (PDT) Received: from localhost ([::1]:47202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3jEH-0005WB-QS for importer@patchew.org; Thu, 06 Aug 2020 12:58:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3jBo-0000ZF-5H for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:24 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:27538 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k3jBm-00076L-Ra for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:23 -0400 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-341-ii3XWdILPlqHNTkYoBk2ww-1; Thu, 06 Aug 2020 12:56:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA5071DE0; Thu, 6 Aug 2020 16:56:14 +0000 (UTC) Received: from bahia.lan (ovpn-112-38.ams2.redhat.com [10.36.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD83F5DA60; Thu, 6 Aug 2020 16:56:13 +0000 (UTC) X-MC-Unique: ii3XWdILPlqHNTkYoBk2ww-1 Subject: [PATCH v2 for-5.2 2/5] spapr/xive: Simplify kvmppc_xive_disconnect() From: Greg Kurz To: David Gibson Date: Thu, 06 Aug 2020 18:56:13 +0200 Message-ID: <159673297296.766512.14780055521619233656.stgit@bahia.lan> In-Reply-To: <159673295739.766512.2950380687630225803.stgit@bahia.lan> References: <159673295739.766512.2950380687630225803.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.31.81; envelope-from=groug@kaod.org; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 05:03:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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_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: Daniel Henrique Barboza , qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Since this function begins with: /* The KVM XIVE device is not in use */ if (!xive || xive->fd =3D=3D -1) { return; } we obviously don't need to check xive->fd again. Signed-off-by: Greg Kurz --- v2: Already applied to ppc-for-5.2 but not yet visible on github --- hw/intc/spapr_xive_kvm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c index d55ea4670e0e..893a1ee77e70 100644 --- a/hw/intc/spapr_xive_kvm.c +++ b/hw/intc/spapr_xive_kvm.c @@ -873,10 +873,8 @@ void kvmppc_xive_disconnect(SpaprInterruptController *= intc) * and removed from the list of devices of the VM. The VCPU * presenters are also detached from the device. */ - if (xive->fd !=3D -1) { - close(xive->fd); - xive->fd =3D -1; - } + close(xive->fd); + xive->fd =3D -1; =20 kvm_kernel_irqchip =3D false; kvm_msi_via_irqfd_allowed =3D false; From nobody Tue May 21 08:26:51 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=1596733132; cv=none; d=zohomail.com; s=zohoarc; b=fxhYw+4OPOX7qlNksEipia1Oays4SUdnEb00xjgKFbFXDIKoiHENc+MnSwFiwCQCmuLBU4YUiI1ZW2Nurq7M3JUDYsELmsAz6zL49wCtBcaBxf6RIZMl/6MbDIgU6TfqdUKf7smdMquGgOzg1OcpmtJi9TPCnh5wdKoAySQasJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596733132; 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=FMFpR+/Xr04HltacBOP7umKLvGvx4hmSgrj7heWXrVk=; b=BiDRcuOHEY+tG8kBtESMrc6WHGe1btajFBpyAMhlgDiKQWH5iGeOYL3uKayuqSRDuFbZTQgCVkIYDjsZq5zWCS3iqloBhzFmNR6UPleAQL2Iqg+0yxbs6d/nlLA0w75oH3oLgzW9s4EOWXeMyMz1TqgW/3u7MIUJdXw2B/yi5E8= 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 1596733132222202.19257319682902; Thu, 6 Aug 2020 09:58:52 -0700 (PDT) Received: from localhost ([::1]:46560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3jEA-0005FL-UM for importer@patchew.org; Thu, 06 Aug 2020 12:58:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3jBu-0000m0-UX for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:31 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:44150 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k3jBs-000785-VK for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:30 -0400 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-20-DSG-zOfrOru6vlV16axAag-1; Thu, 06 Aug 2020 12:56:24 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B0AF100AA23; Thu, 6 Aug 2020 16:56:22 +0000 (UTC) Received: from bahia.lan (ovpn-112-38.ams2.redhat.com [10.36.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id E49E219C4F; Thu, 6 Aug 2020 16:56:20 +0000 (UTC) X-MC-Unique: DSG-zOfrOru6vlV16axAag-1 Subject: [PATCH v2 for-5.2 3/5] ppc/xive: Introduce dedicated kvm_irqchip_in_kernel() wrappers From: Greg Kurz To: David Gibson Date: Thu, 06 Aug 2020 18:56:20 +0200 Message-ID: <159673298011.766512.17389427967409788911.stgit@bahia.lan> In-Reply-To: <159673295739.766512.2950380687630225803.stgit@bahia.lan> References: <159673295739.766512.2950380687630225803.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.110.61; envelope-from=groug@kaod.org; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 00:07:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 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: Daniel Henrique Barboza , qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Calls to the KVM XIVE device are guarded by kvm_irqchip_in_kernel(). This ensures that QEMU won't try to use the device if KVM is disabled or if an in-kernel irqchip isn't required. When using ic-mode=3Ddual with the pseries machine, we have two possible interrupt controllers: XIVE and XICS. The kvm_irqchip_in_kernel() helper will return true as soon as any of the KVM device is created. It might lure QEMU to think that the other one is also around, while it is not. This is exactly what happens with ic-mode=3Ddual at machine init when claiming IRQ numbers, which must be done on all possible IRQ backends, eg. RTAS event sources or the PHB0 LSI table : only the KVM XICS device is active but we end up calling kvmppc_xive_source_reset_one() anyway, which fails. This doesn't cause any trouble because of another bug : kvmppc_xive_source_reset_one() lacks an error_setg() and callers don't see the failure. Most of the other kvmppc_xive_* functions have similar xive->fd checks to filter out the case when KVM XIVE isn't active. It might look safer to have idempotent functions but it doesn't really help to understand what's going on when debugging. Since we already have all the kvm_irqchip_in_kernel() in place, also have the callers to check xive->fd as well before calling KVM XIVE specific code. This is straight-forward for the spapr specific XIVE code. Some more care is needed for the platform agnostic XIVE code since it cannot access xive->fd directly. Introduce new in_kernel() methods in some base XIVE classes for this purpose and implement them only in spapr. In all cases, we still need to call kvm_irqchip_in_kernel() so that compilers can optimize the kvmppc_xive_* calls away when CONFIG_KVM isn't defined, thus avoiding the need for stubs. Signed-off-by: Greg Kurz --- v2: Introduce in_kernel() abstract methods in the base XIVE classes --- hw/intc/spapr_xive.c | 53 ++++++++++++++++++++++++++++++++++++---------= ---- hw/intc/xive.c | 28 +++++++++++++++++++------- include/hw/ppc/xive.h | 2 ++ 3 files changed, 62 insertions(+), 21 deletions(-) diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c index 89c8cd96670b..cd001c580e89 100644 --- a/hw/intc/spapr_xive.c +++ b/hw/intc/spapr_xive.c @@ -148,12 +148,19 @@ static void spapr_xive_end_pic_print_info(SpaprXive *= xive, XiveEND *end, xive_end_queue_pic_print_info(end, 6, mon); } =20 +/* + * kvm_irqchip_in_kernel() will cause the compiler to turn this + * info a nop if CONFIG_KVM isn't defined. + */ +#define spapr_xive_in_kernel(xive) \ + (kvm_irqchip_in_kernel() && (xive)->fd !=3D -1) + void spapr_xive_pic_print_info(SpaprXive *xive, Monitor *mon) { XiveSource *xsrc =3D &xive->source; int i; =20 - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { Error *local_err =3D NULL; =20 kvmppc_xive_synchronize_state(xive, &local_err); @@ -507,8 +514,10 @@ static const VMStateDescription vmstate_spapr_xive_eas= =3D { =20 static int vmstate_spapr_xive_pre_save(void *opaque) { - if (kvm_irqchip_in_kernel()) { - return kvmppc_xive_pre_save(SPAPR_XIVE(opaque)); + SpaprXive *xive =3D SPAPR_XIVE(opaque); + + if (spapr_xive_in_kernel(xive)) { + return kvmppc_xive_pre_save(xive); } =20 return 0; @@ -520,8 +529,10 @@ static int vmstate_spapr_xive_pre_save(void *opaque) */ static int spapr_xive_post_load(SpaprInterruptController *intc, int versio= n_id) { - if (kvm_irqchip_in_kernel()) { - return kvmppc_xive_post_load(SPAPR_XIVE(intc), version_id); + SpaprXive *xive =3D SPAPR_XIVE(intc); + + if (spapr_xive_in_kernel(xive)) { + return kvmppc_xive_post_load(xive, version_id); } =20 return 0; @@ -564,7 +575,7 @@ static int spapr_xive_claim_irq(SpaprInterruptControlle= r *intc, int lisn, xive_source_irq_set_lsi(xsrc, lisn); } =20 - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { return kvmppc_xive_source_reset_one(xsrc, lisn, errp); } =20 @@ -641,7 +652,7 @@ static void spapr_xive_set_irq(SpaprInterruptController= *intc, int irq, int val) { SpaprXive *xive =3D SPAPR_XIVE(intc); =20 - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { kvmppc_xive_source_set_irq(&xive->source, irq, val); } else { xive_source_set_irq(&xive->source, irq, val); @@ -749,11 +760,21 @@ static void spapr_xive_deactivate(SpaprInterruptContr= oller *intc) =20 spapr_xive_mmio_set_enabled(xive, false); =20 - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { kvmppc_xive_disconnect(intc); } } =20 +static bool spapr_xive_in_kernel_xptr(const XivePresenter *xptr) +{ + return spapr_xive_in_kernel(SPAPR_XIVE(xptr)); +} + +static bool spapr_xive_in_kernel_xn(const XiveNotifier *xn) +{ + return spapr_xive_in_kernel(SPAPR_XIVE(xn)); +} + static void spapr_xive_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -761,6 +782,7 @@ static void spapr_xive_class_init(ObjectClass *klass, v= oid *data) SpaprInterruptControllerClass *sicc =3D SPAPR_INTC_CLASS(klass); XivePresenterClass *xpc =3D XIVE_PRESENTER_CLASS(klass); SpaprXiveClass *sxc =3D SPAPR_XIVE_CLASS(klass); + XiveNotifierClass *xnc =3D XIVE_NOTIFIER_CLASS(klass); =20 dc->desc =3D "sPAPR XIVE Interrupt Controller"; device_class_set_props(dc, spapr_xive_properties); @@ -788,6 +810,9 @@ static void spapr_xive_class_init(ObjectClass *klass, v= oid *data) sicc->post_load =3D spapr_xive_post_load; =20 xpc->match_nvt =3D spapr_xive_match_nvt; + xpc->in_kernel =3D spapr_xive_in_kernel_xptr; + + xnc->in_kernel =3D spapr_xive_in_kernel_xn; } =20 static const TypeInfo spapr_xive_info =3D { @@ -1058,7 +1083,7 @@ static target_ulong h_int_set_source_config(PowerPCCP= U *cpu, new_eas.w =3D xive_set_field64(EAS_END_DATA, new_eas.w, eisn); } =20 - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { Error *local_err =3D NULL; =20 kvmppc_xive_set_source_config(xive, lisn, &new_eas, &local_err); @@ -1379,7 +1404,7 @@ static target_ulong h_int_set_queue_config(PowerPCCPU= *cpu, */ =20 out: - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { Error *local_err =3D NULL; =20 kvmppc_xive_set_queue_config(xive, end_blk, end_idx, &end, &local_= err); @@ -1480,7 +1505,7 @@ static target_ulong h_int_get_queue_config(PowerPCCPU= *cpu, args[2] =3D 0; } =20 - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { Error *local_err =3D NULL; =20 kvmppc_xive_get_queue_config(xive, end_blk, end_idx, end, &local_e= rr); @@ -1642,7 +1667,7 @@ static target_ulong h_int_esb(PowerPCCPU *cpu, return H_P3; } =20 - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { args[0] =3D kvmppc_xive_esb_rw(xsrc, lisn, offset, data, flags & SPAPR_XIVE_ESB_STORE); } else { @@ -1717,7 +1742,7 @@ static target_ulong h_int_sync(PowerPCCPU *cpu, * under KVM */ =20 - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { Error *local_err =3D NULL; =20 kvmppc_xive_sync_source(xive, lisn, &local_err); @@ -1761,7 +1786,7 @@ static target_ulong h_int_reset(PowerPCCPU *cpu, =20 device_legacy_reset(DEVICE(xive)); =20 - if (kvm_irqchip_in_kernel()) { + if (spapr_xive_in_kernel(xive)) { Error *local_err =3D NULL; =20 kvmppc_xive_reset(xive, &local_err); diff --git a/hw/intc/xive.c b/hw/intc/xive.c index 9b55e0356c62..27d27fdc9ee4 100644 --- a/hw/intc/xive.c +++ b/hw/intc/xive.c @@ -592,6 +592,17 @@ static const char * const xive_tctx_ring_names[] =3D { "USER", "OS", "POOL", "PHYS", }; =20 +/* + * kvm_irqchip_in_kernel() will cause the compiler to turn this + * info a nop if CONFIG_KVM isn't defined. + */ +#define xive_in_kernel(xptr) \ + (kvm_irqchip_in_kernel() && \ + ({ \ + XivePresenterClass *xpc =3D XIVE_PRESENTER_GET_CLASS(xptr); \ + xpc->in_kernel ? xpc->in_kernel(xptr) : false; \ + })) + void xive_tctx_pic_print_info(XiveTCTX *tctx, Monitor *mon) { int cpu_index; @@ -606,7 +617,7 @@ void xive_tctx_pic_print_info(XiveTCTX *tctx, Monitor *= mon) =20 cpu_index =3D tctx->cs ? tctx->cs->cpu_index : -1; =20 - if (kvm_irqchip_in_kernel()) { + if (xive_in_kernel(tctx->xptr)) { Error *local_err =3D NULL; =20 kvmppc_xive_cpu_synchronize_state(tctx, &local_err); @@ -671,7 +682,7 @@ static void xive_tctx_realize(DeviceState *dev, Error *= *errp) } =20 /* Connect the presenter to the VCPU (required for CPU hotplug) */ - if (kvm_irqchip_in_kernel()) { + if (xive_in_kernel(tctx->xptr)) { kvmppc_xive_cpu_connect(tctx, &local_err); if (local_err) { error_propagate(errp, local_err); @@ -682,10 +693,11 @@ static void xive_tctx_realize(DeviceState *dev, Error= **errp) =20 static int vmstate_xive_tctx_pre_save(void *opaque) { + XiveTCTX *tctx =3D XIVE_TCTX(opaque); Error *local_err =3D NULL; =20 - if (kvm_irqchip_in_kernel()) { - kvmppc_xive_cpu_get_state(XIVE_TCTX(opaque), &local_err); + if (xive_in_kernel(tctx->xptr)) { + kvmppc_xive_cpu_get_state(tctx, &local_err); if (local_err) { error_report_err(local_err); return -1; @@ -697,14 +709,15 @@ static int vmstate_xive_tctx_pre_save(void *opaque) =20 static int vmstate_xive_tctx_post_load(void *opaque, int version_id) { + XiveTCTX *tctx =3D XIVE_TCTX(opaque); Error *local_err =3D NULL; =20 - if (kvm_irqchip_in_kernel()) { + if (xive_in_kernel(tctx->xptr)) { /* * Required for hotplugged CPU, for which the state comes * after all states of the machine. */ - kvmppc_xive_cpu_set_state(XIVE_TCTX(opaque), &local_err); + kvmppc_xive_cpu_set_state(tctx, &local_err); if (local_err) { error_report_err(local_err); return -1; @@ -1128,6 +1141,7 @@ static void xive_source_reset(void *dev) static void xive_source_realize(DeviceState *dev, Error **errp) { XiveSource *xsrc =3D XIVE_SOURCE(dev); + XiveNotifierClass *xnc =3D XIVE_NOTIFIER_GET_CLASS(xsrc->xive); =20 assert(xsrc->xive); =20 @@ -1147,7 +1161,7 @@ static void xive_source_realize(DeviceState *dev, Err= or **errp) xsrc->status =3D g_malloc0(xsrc->nr_irqs); xsrc->lsi_map =3D bitmap_new(xsrc->nr_irqs); =20 - if (!kvm_irqchip_in_kernel()) { + if (!xnc->in_kernel || !xnc->in_kernel(xsrc->xive)) { memory_region_init_io(&xsrc->esb_mmio, OBJECT(xsrc), &xive_source_esb_ops, xsrc, "xive.esb", (1ull << xsrc->esb_shift) * xsrc->nr_irqs); diff --git a/include/hw/ppc/xive.h b/include/hw/ppc/xive.h index 705cf48176fc..aa46e3fcf512 100644 --- a/include/hw/ppc/xive.h +++ b/include/hw/ppc/xive.h @@ -161,6 +161,7 @@ typedef struct XiveNotifier XiveNotifier; typedef struct XiveNotifierClass { InterfaceClass parent; void (*notify)(XiveNotifier *xn, uint32_t lisn); + bool (*in_kernel)(const XiveNotifier *xn); } XiveNotifierClass; =20 /* @@ -396,6 +397,7 @@ typedef struct XivePresenterClass { uint8_t nvt_blk, uint32_t nvt_idx, bool cam_ignore, uint8_t priority, uint32_t logic_serv, XiveTCTXMatch *match); + bool (*in_kernel)(const XivePresenter *xptr); } XivePresenterClass; =20 int xive_presenter_tctx_match(XivePresenter *xptr, XiveTCTX *tctx, From nobody Tue May 21 08:26:51 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=1596733063; cv=none; d=zohomail.com; s=zohoarc; b=ff1GQcllDzcVWKx7co4IabrXw4kHnNlacpZcwxLBPK2eOjat3Tv1wRcP0n/b0jHFVGHtNRfk8RTewyFX25+4jMX/pR+8mn1ZHsRz/pIqzOuW84CzEf8NobYANl5pKdz7HSZ6+z/DDhdwj9uVw3nx6/t7fAnW08gWCO2aDSk8qRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596733063; 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=lc4KfS3ocn1W2V3e6yS6bkRZai3+cSj7NzoBAcf+EuY=; b=abHpWvGHzymMSNPHc7Ub5rjE6+Q5DDT6xBV0c4ez091oxngyFi1fxPwfIZaN6uMXqksah2HJRVgQMBF4g5fqSG3eP4vfOAYdFPUV1Y0pSqLPgkIiIAwpX68geb4HJlB125gc3QxaA5hXe8cVmAckSPNklZoj6CaBFwS+FdUwZ9g= 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 1596733063214418.0122221890455; Thu, 6 Aug 2020 09:57:43 -0700 (PDT) Received: from localhost ([::1]:40590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3jD4-0002sc-0Y for importer@patchew.org; Thu, 06 Aug 2020 12:57:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3jC1-0000zA-6M for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:37 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:36353 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k3jBz-00078i-I4 for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:36 -0400 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-425-MsC0VUH0MwOEAVL1nRk9wg-1; Thu, 06 Aug 2020 12:56:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3DD5B8014C1; Thu, 6 Aug 2020 16:56:29 +0000 (UTC) Received: from bahia.lan (ovpn-112-38.ams2.redhat.com [10.36.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 421097B904; Thu, 6 Aug 2020 16:56:28 +0000 (UTC) X-MC-Unique: MsC0VUH0MwOEAVL1nRk9wg-1 Subject: [PATCH v2 for-5.2 4/5] spapr/xive: Convert KVM device fd checks to assert() From: Greg Kurz To: David Gibson Date: Thu, 06 Aug 2020 18:56:27 +0200 Message-ID: <159673298746.766512.8609128730730603233.stgit@bahia.lan> In-Reply-To: <159673295739.766512.2950380687630225803.stgit@bahia.lan> References: <159673295739.766512.2950380687630225803.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.31.81; envelope-from=groug@kaod.org; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 05:03:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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_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: Daniel Henrique Barboza , qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" All callers guard these functions with an xive_in_kernel() helper. Make it clear that they are only to be called when the KVM XIVE device exists. Note that the check on xive is dropped in kvmppc_xive_disconnect(). It really cannot be NULL since it comes from set_active_intc() which only passes pointers to allocated objects. Signed-off-by: Greg Kurz Reviewed-by: David Gibson --- v2: Take the helper name change into account in the changelog --- hw/intc/spapr_xive_kvm.c | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c index 893a1ee77e70..1908afb14b9f 100644 --- a/hw/intc/spapr_xive_kvm.c +++ b/hw/intc/spapr_xive_kvm.c @@ -79,10 +79,7 @@ void kvmppc_xive_cpu_set_state(XiveTCTX *tctx, Error **e= rrp) uint64_t state[2]; int ret; =20 - /* The KVM XIVE device is not in use yet */ - if (xive->fd =3D=3D -1) { - return; - } + assert(xive->fd !=3D -1); =20 /* word0 and word1 of the OS ring. */ state[0] =3D *((uint64_t *) &tctx->regs[TM_QW1_OS]); @@ -101,10 +98,7 @@ void kvmppc_xive_cpu_get_state(XiveTCTX *tctx, Error **= errp) uint64_t state[2] =3D { 0 }; int ret; =20 - /* The KVM XIVE device is not in use */ - if (xive->fd =3D=3D -1) { - return; - } + assert(xive->fd !=3D -1); =20 ret =3D kvm_get_one_reg(tctx->cs, KVM_REG_PPC_VP_STATE, state); if (ret !=3D 0) { @@ -156,10 +150,7 @@ void kvmppc_xive_cpu_connect(XiveTCTX *tctx, Error **e= rrp) unsigned long vcpu_id; int ret; =20 - /* The KVM XIVE device is not in use */ - if (xive->fd =3D=3D -1) { - return; - } + assert(xive->fd !=3D -1); =20 /* Check if CPU was hot unplugged and replugged. */ if (kvm_cpu_is_enabled(tctx->cs)) { @@ -245,10 +236,7 @@ int kvmppc_xive_source_reset_one(XiveSource *xsrc, int= srcno, Error **errp) SpaprXive *xive =3D SPAPR_XIVE(xsrc->xive); uint64_t state =3D 0; =20 - /* The KVM XIVE device is not in use */ - if (xive->fd =3D=3D -1) { - return -ENODEV; - } + assert(xive->fd !=3D -1); =20 if (xive_source_irq_is_lsi(xsrc, srcno)) { state |=3D KVM_XIVE_LEVEL_SENSITIVE; @@ -592,10 +580,7 @@ static void kvmppc_xive_change_state_handler(void *opa= que, int running, =20 void kvmppc_xive_synchronize_state(SpaprXive *xive, Error **errp) { - /* The KVM XIVE device is not in use */ - if (xive->fd =3D=3D -1) { - return; - } + assert(xive->fd !=3D -1); =20 /* * When the VM is stopped, the sources are masked and the previous @@ -622,10 +607,7 @@ int kvmppc_xive_pre_save(SpaprXive *xive) { Error *local_err =3D NULL; =20 - /* The KVM XIVE device is not in use */ - if (xive->fd =3D=3D -1) { - return 0; - } + assert(xive->fd !=3D -1); =20 /* EAT: there is no extra state to query from KVM */ =20 @@ -845,10 +827,7 @@ void kvmppc_xive_disconnect(SpaprInterruptController *= intc) XiveSource *xsrc; size_t esb_len; =20 - /* The KVM XIVE device is not in use */ - if (!xive || xive->fd =3D=3D -1) { - return; - } + assert(xive->fd !=3D -1); =20 /* Clear the KVM mapping */ xsrc =3D &xive->source; From nobody Tue May 21 08:26:51 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=1596733066; cv=none; d=zohomail.com; s=zohoarc; b=n36Ttnl8S1v8hTm1hHarFwH1gB4IZge0V7SWd9MFX/YXbZw4V/mI0MEk0KKJSLOkEDDT0DXYUxHRqigCtawF/nxK3iaboZl6ZJ4pMkFkt0p55uSTYSRGbe9H9OoBYLjZPI/bBaqd44zzMmpkIXRpVZPcgTY1hsihe3Kvs60FGAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596733066; 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=0l0SWC7lzDtM+abbvOy1z3dwMFGzq91vNvTqgdD7dgQ=; b=KX3SBrXQitpMqs2jAcH3mAi211HkKIHX108w5S8tqYh9plqcKL9p3sre68yx47YjJWWyWeS00b++fzZZLNU7/srey/feFqchbw+QmKn/4nScO0L+KJHBATBbyXAoMGoHcjpXTi4rB3N+1j40LEOevvlacNXrCUbDDEHbo3vauiI= 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 1596733066636361.24362452167713; Thu, 6 Aug 2020 09:57:46 -0700 (PDT) Received: from localhost ([::1]:40978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3jD7-000320-D0 for importer@patchew.org; Thu, 06 Aug 2020 12:57:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3jC9-0001Ld-VV for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:45 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:52506 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k3jC8-00079D-2z for qemu-devel@nongnu.org; Thu, 06 Aug 2020 12:56:45 -0400 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-481-ZytX8LsQMHOVkxGryd5kbQ-1; Thu, 06 Aug 2020 12:56:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6024C58; Thu, 6 Aug 2020 16:56:36 +0000 (UTC) Received: from bahia.lan (ovpn-112-38.ams2.redhat.com [10.36.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6401887A61; Thu, 6 Aug 2020 16:56:35 +0000 (UTC) X-MC-Unique: ZytX8LsQMHOVkxGryd5kbQ-1 Subject: [PATCH v2 for-5.2 5/5] spapr: Simplify error handling in spapr_phb_realize() From: Greg Kurz To: David Gibson Date: Thu, 06 Aug 2020 18:56:34 +0200 Message-ID: <159673299447.766512.1951478231673831450.stgit@bahia.lan> In-Reply-To: <159673295739.766512.2950380687630225803.stgit@bahia.lan> References: <159673295739.766512.2950380687630225803.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.31.81; envelope-from=groug@kaod.org; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 05:03:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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_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: Daniel Henrique Barboza , qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The spapr_phb_realize() function has a local_err variable which is used to: 1) check failures of spapr_irq_findone() and spapr_irq_claim() 2) prepend extra information to the error message Recent work from Markus Armbruster highlighted we get better code when testing the return value of a function, rather than setting up all the local_err boiler plate. For similar reasons, it is now preferred to use ERRP_GUARD() and error_prepend() rather than error_propagate_prepend(). Since spapr_irq_findone() and spapr_irq_claim() return negative values in case of failure, do both changes. This is just cleanup, no functional impact. Signed-off-by: Greg Kurz Reviewed-by: Markus Armbruster Reviewed-by: David Gibson --- hw/ppc/spapr_pci.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 363cdb3f7b8d..0a418f1e6711 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1796,6 +1796,7 @@ static void spapr_phb_destroy_msi(gpointer opaque) =20 static void spapr_phb_realize(DeviceState *dev, Error **errp) { + ERRP_GUARD(); /* We don't use SPAPR_MACHINE() in order to exit gracefully if the user * tries to add a sPAPR PHB to a non-pseries machine. */ @@ -1813,7 +1814,6 @@ static void spapr_phb_realize(DeviceState *dev, Error= **errp) uint64_t msi_window_size =3D 4096; SpaprTceTable *tcet; const unsigned windows_supported =3D spapr_phb_windows_supported(sphb); - Error *local_err =3D NULL; =20 if (!spapr) { error_setg(errp, TYPE_SPAPR_PCI_HOST_BRIDGE " needs a pseries mach= ine"); @@ -1964,13 +1964,12 @@ static void spapr_phb_realize(DeviceState *dev, Err= or **errp) =20 /* Initialize the LSI table */ for (i =3D 0; i < PCI_NUM_PINS; i++) { - uint32_t irq =3D SPAPR_IRQ_PCI_LSI + sphb->index * PCI_NUM_PINS + = i; + int irq =3D SPAPR_IRQ_PCI_LSI + sphb->index * PCI_NUM_PINS + i; =20 if (smc->legacy_irq_allocation) { - irq =3D spapr_irq_findone(spapr, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "can't allocate LSIs: "); + irq =3D spapr_irq_findone(spapr, errp); + if (irq < 0) { + error_prepend(errp, "can't allocate LSIs: "); /* * Older machines will never support PHB hotplug, ie, this= is an * init only path and QEMU will terminate. No need to roll= back. @@ -1979,9 +1978,8 @@ static void spapr_phb_realize(DeviceState *dev, Error= **errp) } } =20 - spapr_irq_claim(spapr, irq, true, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, "can't allocate LSIs:= "); + if (spapr_irq_claim(spapr, irq, true, errp) < 0) { + error_prepend(errp, "can't allocate LSIs: "); goto unrealize; } =20