From nobody Fri May 17 17:53:52 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=1596800005; cv=none; d=zohomail.com; s=zohoarc; b=QVV3kaG/lUZ38fRqIm5nTN1idK0X890zOH4ySKtEYq2UoVmtBh0OB/oh3QZ0/w2qfOdiGdMiZWnfuI3ttYLGhdAaT405CFN+pnXFPAp/juGdGagKIuDuz7qtdR8cgog28aiTUCFTNtFScpFowGNLsEfRLVe7jAq5yh/1r5gFEso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596800005; 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=q8FbPpGhSZ7x70UG2NBftgWTLOwL0o6/Yd3SnXxGKFA=; b=bwBQzR2RiqxIPGe7TkR5zlSZBOanyeE1TDYV+8CqFiZuLa2nZ8cKVhtchxYrBHw74EnGfrMZ3Of7yGfJzXaa63GcgqBmyLLs6UhlNhusfycoeVp5WgxAJUy73lQWhFV3y4lHQN49WE6VuINlvDScav+6Vb/HH7o3b2To75ZcBio= 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 1596800005034429.87806037242865; Fri, 7 Aug 2020 04:33:25 -0700 (PDT) Received: from localhost ([::1]:59118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k40cl-000623-Em for importer@patchew.org; Fri, 07 Aug 2020 07:33:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k40bj-0004Ra-Vo for qemu-devel@nongnu.org; Fri, 07 Aug 2020 07:32:19 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:51363 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 1k40bg-0000wm-Tc for qemu-devel@nongnu.org; Fri, 07 Aug 2020 07:32:19 -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-93-SM8HD-pAMAKQXHRO0FOeoQ-1; Fri, 07 Aug 2020 07:32:10 -0400 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 287EA8005B0; Fri, 7 Aug 2020 11:32:09 +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 A8DEE60CD0; Fri, 7 Aug 2020 11:32:07 +0000 (UTC) X-MC-Unique: SM8HD-pAMAKQXHRO0FOeoQ-1 Subject: [PATCH v3 for-5.2 1/3] ppc/xive: Rework setup of XiveSource::esb_mmio From: Greg Kurz To: David Gibson Date: Fri, 07 Aug 2020 13:32:06 +0200 Message-ID: <159679992680.876294.7520540158586170894.stgit@bahia.lan> In-Reply-To: <159679991916.876294.8967140647442842745.stgit@bahia.lan> References: <159679991916.876294.8967140647442842745.stgit@bahia.lan> User-Agent: StGit/0.21 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.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/07 04:11:35 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" Depending on whether XIVE is emultated or backed with a KVM XIVE device, the ESB MMIOs of a XIVE source point to an I/O memory region or a mapped memory region. This is currently handled by checking kvm_irqchip_in_kernel() returns false in xive_source_realize(). This is a bit awkward as we usually need to do extra things when we're using the in-kernel backend, not less. But most important, we can do better: turn the existing "xive.esb" memory region into a plain container, introduce an "xive.esb-emulated" I/O subregion and rename the existing "xive.esb" subregion in the KVM code to "xive.esb-kvm". Since "xive.esb-kvm" is added with overlap and a higher priority, it prevails over "xive.esb-emulated" (ie. a guest using KVM XIVE will interact with "xive.esb-kvm" instead of the default "xive.esb-emulated" region. While here, consolidate the computation of the MMIO region size in a common helper. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Greg Kurz Reviewed-by: C=C3=A9dric Le Goater --- hw/intc/spapr_xive_kvm.c | 4 ++-- hw/intc/xive.c | 11 ++++++----- include/hw/ppc/xive.h | 6 ++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c index 893a1ee77e70..6130882be678 100644 --- a/hw/intc/spapr_xive_kvm.c +++ b/hw/intc/spapr_xive_kvm.c @@ -742,7 +742,7 @@ int kvmppc_xive_connect(SpaprInterruptController *intc,= uint32_t nr_servers, SpaprXive *xive =3D SPAPR_XIVE(intc); XiveSource *xsrc =3D &xive->source; Error *local_err =3D NULL; - size_t esb_len =3D (1ull << xsrc->esb_shift) * xsrc->nr_irqs; + size_t esb_len =3D xive_source_esb_len(xsrc); size_t tima_len =3D 4ull << TM_SHIFT; CPUState *cs; int fd; @@ -788,7 +788,7 @@ int kvmppc_xive_connect(SpaprInterruptController *intc,= uint32_t nr_servers, } =20 memory_region_init_ram_device_ptr(&xsrc->esb_mmio_kvm, OBJECT(xsrc), - "xive.esb", esb_len, xsrc->esb_mmap); + "xive.esb-kvm", esb_len, xsrc->esb_m= map); memory_region_add_subregion_overlap(&xsrc->esb_mmio, 0, &xsrc->esb_mmio_kvm, 1); =20 diff --git a/hw/intc/xive.c b/hw/intc/xive.c index 9b55e0356c62..561d746cd1da 100644 --- a/hw/intc/xive.c +++ b/hw/intc/xive.c @@ -1128,6 +1128,7 @@ static void xive_source_reset(void *dev) static void xive_source_realize(DeviceState *dev, Error **errp) { XiveSource *xsrc =3D XIVE_SOURCE(dev); + size_t esb_len =3D xive_source_esb_len(xsrc); =20 assert(xsrc->xive); =20 @@ -1147,11 +1148,11 @@ static void xive_source_realize(DeviceState *dev, E= rror **errp) xsrc->status =3D g_malloc0(xsrc->nr_irqs); xsrc->lsi_map =3D bitmap_new(xsrc->nr_irqs); =20 - if (!kvm_irqchip_in_kernel()) { - memory_region_init_io(&xsrc->esb_mmio, OBJECT(xsrc), - &xive_source_esb_ops, xsrc, "xive.esb", - (1ull << xsrc->esb_shift) * xsrc->nr_irqs); - } + memory_region_init(&xsrc->esb_mmio, OBJECT(xsrc), "xive.esb", esb_len); + memory_region_init_io(&xsrc->esb_mmio_emulated, OBJECT(xsrc), + &xive_source_esb_ops, xsrc, "xive.esb-emulated", + esb_len); + memory_region_add_subregion(&xsrc->esb_mmio, 0, &xsrc->esb_mmio_emulat= ed); =20 qemu_register_reset(xive_source_reset, dev); } diff --git a/include/hw/ppc/xive.h b/include/hw/ppc/xive.h index 705cf48176fc..82a61eaca74f 100644 --- a/include/hw/ppc/xive.h +++ b/include/hw/ppc/xive.h @@ -191,6 +191,7 @@ typedef struct XiveSource { uint64_t esb_flags; uint32_t esb_shift; MemoryRegion esb_mmio; + MemoryRegion esb_mmio_emulated; =20 /* KVM support */ void *esb_mmap; @@ -215,6 +216,11 @@ static inline bool xive_source_esb_has_2page(XiveSourc= e *xsrc) xsrc->esb_shift =3D=3D XIVE_ESB_4K_2PAGE; } =20 +static inline size_t xive_source_esb_len(XiveSource *xsrc) +{ + return (1ull << xsrc->esb_shift) * xsrc->nr_irqs; +} + /* The trigger page is always the first/even page */ static inline hwaddr xive_source_esb_page(XiveSource *xsrc, uint32_t srcno) { From nobody Fri May 17 17:53:52 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=1596800009; cv=none; d=zohomail.com; s=zohoarc; b=OcV7rj8kCMyTMt8y9PD+drp8qjkGXCnaMx5gwmtWHYKCjSJ27u4KQU0VbrmHf3cYWb5Hae6lEP2p88EOhWvSDHrXxXOkIXcAoV5iTqcHXSb89DOno6tpUm/TdrHUSszO/vR2kP/R6ofGSNPEuJU4Jo99AVTBzKXW2Rplj8QtgxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596800009; 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=ya0Hfmi+SV7/psOvbeVKt68iY3OprDL2ewFpZjsPA8g=; b=j2S2A31fgijfIgn4/vX60fqQN2ltuUYkn+fV9vKWwYXoq0iqdDOO8xPn0u3+9dNssjaS6KQ/u3abEWdUO8/eR5egq4Z2JQa8TlLWZhgUW7AbdkRaM/TLj5DnTeya6ddavjy8COV/imHMS6zwJKc6r/2zTnHPWe3qAuM0oi7ACco= 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 1596800009874771.7446855447005; Fri, 7 Aug 2020 04:33:29 -0700 (PDT) Received: from localhost ([::1]:59666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k40cq-0006FM-Iq for importer@patchew.org; Fri, 07 Aug 2020 07:33:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k40bn-0004Zi-RA for qemu-devel@nongnu.org; Fri, 07 Aug 2020 07:32:23 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:54499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k40bm-0000xS-2O for qemu-devel@nongnu.org; Fri, 07 Aug 2020 07:32: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-505-K91spigQPsy-KtddlxJ8JQ-1; Fri, 07 Aug 2020 07:32:17 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 734F6107BEF8; Fri, 7 Aug 2020 11:32:16 +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 4DA7D65C7F; Fri, 7 Aug 2020 11:32:15 +0000 (UTC) X-MC-Unique: K91spigQPsy-KtddlxJ8JQ-1 Subject: [PATCH v3 for-5.2 2/3] ppc/xive: Introduce dedicated kvm_irqchip_in_kernel() wrappers From: Greg Kurz To: David Gibson Date: Fri, 07 Aug 2020 13:32:14 +0200 Message-ID: <159679993438.876294.7285654331498605426.stgit@bahia.lan> In-Reply-To: <159679991916.876294.8967140647442842745.stgit@bahia.lan> References: <159679991916.876294.8967140647442842745.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/07 07:32:14 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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: 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 Reviewed-by: C=C3=A9dric Le Goater --- v3: Method for XiveNotifierClass no longer needed v2: Introduce in_kernel() abstract methods in the base XIVE classes --- hw/intc/spapr_xive.c | 45 +++++++++++++++++++++++++++++++-------------- hw/intc/xive.c | 25 +++++++++++++++++++------ include/hw/ppc/xive.h | 1 + 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c index 89c8cd96670b..3c84f64dc464 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,16 @@ 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 void spapr_xive_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -788,6 +804,7 @@ 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; } =20 static const TypeInfo spapr_xive_info =3D { @@ -1058,7 +1075,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 +1396,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 +1497,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 +1659,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 +1734,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 +1778,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 561d746cd1da..a453e8f4dcbe 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; diff --git a/include/hw/ppc/xive.h b/include/hw/ppc/xive.h index 82a61eaca74f..2f3c5af810bb 100644 --- a/include/hw/ppc/xive.h +++ b/include/hw/ppc/xive.h @@ -402,6 +402,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 Fri May 17 17:53:52 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=1596800019; cv=none; d=zohomail.com; s=zohoarc; b=m5j7vn/psL9DD6ftp3HqEjiJ0KTbBjI+PHObkETAlj0L2iERor+8pb/dl5pGj6eqQZ8rxAzLHon3DnDKlaKGViCJkGpO1lHoePLM30Cpz0bHizFDAxcIw0xcIXA3T5sO0F5vycNMioxwhhEWqiN+DhJS2JCKF+MC9hkWNVmIV/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596800019; 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=1YdgCk2ZtWhpTjxdOmfFnUbyKl77d3K/pGQ5eMKsupg=; b=KYfr8MytOci+bFNxZ1X33XOaUWsuZVKfD/Bl/fNO/5YNh9gTT+mHE0VJouCYLiOhZGatZCWGnNpQlv4LQwA7zqjRX8P+EBpGlgshKdqSpkp7nu8CYTpjlbHhc3LKztdiHDHa7K3CNub0NPpUQg47+t8g5uKCcc8EoL846H67YUs= 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 1596800019455240.08294573581497; Fri, 7 Aug 2020 04:33:39 -0700 (PDT) Received: from localhost ([::1]:60706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k40d0-0006ev-5Y for importer@patchew.org; Fri, 07 Aug 2020 07:33:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k40bu-0004qi-U4 for qemu-devel@nongnu.org; Fri, 07 Aug 2020 07:32:30 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:28296 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 1k40bt-0000yZ-98 for qemu-devel@nongnu.org; Fri, 07 Aug 2020 07:32: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-217-xw6S0ZzGPnO_GuPFDdmsBg-1; Fri, 07 Aug 2020 07:32:24 -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 8F29B1005504; Fri, 7 Aug 2020 11:32:23 +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 8E7C06FEDC; Fri, 7 Aug 2020 11:32:22 +0000 (UTC) X-MC-Unique: xw6S0ZzGPnO_GuPFDdmsBg-1 Subject: [PATCH v3 for-5.2 3/3] spapr/xive: Convert KVM device fd checks to assert() From: Greg Kurz To: David Gibson Date: Fri, 07 Aug 2020 13:32:21 +0200 Message-ID: <159679994169.876294.11026653581505077112.stgit@bahia.lan> In-Reply-To: <159679991916.876294.8967140647442842745.stgit@bahia.lan> References: <159679991916.876294.8967140647442842745.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.120; envelope-from=groug@kaod.org; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/07 02:21:37 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 Reviewed-by: C=C3=A9dric Le Goater --- 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 6130882be678..82a6f99f022d 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;