From nobody Fri Apr 19 21:42:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1568209299; cv=none; d=zoho.com; s=zohoarc; b=AgJulHwPQpEPqbn2ntsZPaOTiu9yPXhnhWXVWWhvpZNoPVeujT6q51GNhccD1VKXPphV2ttplleWcRrawJAd0ESps0nkEFwJJpIOMiatz5BezPcvzRiVD7lYVq0J9I8U6+sb4MWR03XE25oeJj+xZxeeHsEYchrvWw22LXb40nY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568209299; 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:ARC-Authentication-Results; bh=Gpin4qoIUU+WP1rcL9ui0CAqBACLgGJDFN6h8rEkgms=; b=CU0ECRp6TYFZ/vSXTeW0rSVVGTy6jWVrpiXMRs9YqCbdeu3rZPb7CZY2kAjWLLkwLnLgrB8iWPTuUR7ynWRIOMAGkOdsmmBmww/z2GZjpJpPrkJQCxH+SJENRnT3L2L94GDcOVuIw6lSXln/sDMuApqX75yt3SGM5VrxuI3W7OU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1568209299727246.21274113024697; Wed, 11 Sep 2019 06:41:39 -0700 (PDT) Received: from localhost ([::1]:51192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82sI-0000Wd-KW for importer@patchew.org; Wed, 11 Sep 2019 09:41:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34091) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82qn-0007bY-8S for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:40:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i82qm-0006QN-4H for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:40:01 -0400 Received: from 19.mo1.mail-out.ovh.net ([178.32.97.206]:54793) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i82ql-0006Pc-VH for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:40:00 -0400 Received: from player792.ha.ovh.net (unknown [10.109.146.122]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id 50B0C18D526 for ; Wed, 11 Sep 2019 15:39:58 +0200 (CEST) Received: from kaod.org (lfbn-1-2240-157.w90-76.abo.wanadoo.fr [90.76.60.157]) (Authenticated sender: clg@kaod.org) by player792.ha.ovh.net (Postfix) with ESMTPSA id 661879C4DEE8; Wed, 11 Sep 2019 13:39:51 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Date: Wed, 11 Sep 2019 15:39:36 +0200 Message-Id: <20190911133937.2716-2-clg@kaod.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190911133937.2716-1-clg@kaod.org> References: <20190911133937.2716-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 17955288766735289318 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedufedrtdefgdegtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.32.97.206 Subject: [Qemu-devel] [PATCH v2 1/2] spapr/irq: Introduce an ics_irq_free() helper 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: Satheesh Rajendran , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" It will help us to discard interrupt numbers which have not been claimed in the next patch. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- include/hw/ppc/xics.h | 5 +++++ hw/ppc/spapr_irq.c | 9 +++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/hw/ppc/xics.h b/include/hw/ppc/xics.h index f2a8d6a4b4f9..64a2c8862a72 100644 --- a/include/hw/ppc/xics.h +++ b/include/hw/ppc/xics.h @@ -179,6 +179,11 @@ void ics_simple_write_xive(ICSState *ics, int nr, int = server, uint8_t priority, uint8_t saved_priority); void ics_simple_set_irq(void *opaque, int srcno, int val); =20 +static inline bool ics_irq_free(ICSState *ics, uint32_t srcno) +{ + return !(ics->irqs[srcno].flags & XICS_FLAGS_IRQ_MASK); +} + void ics_set_irq_type(ICSState *ics, int srcno, bool lsi); void icp_pic_print_info(ICPState *icp, Monitor *mon); void ics_pic_print_info(ICSState *ics, Monitor *mon); diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c index 06fe2432bae5..d8f46b6797f8 100644 --- a/hw/ppc/spapr_irq.c +++ b/hw/ppc/spapr_irq.c @@ -114,9 +114,6 @@ static void spapr_irq_init_xics(SpaprMachineState *spap= r, int nr_irqs, xics_spapr_init(spapr); } =20 -#define ICS_IRQ_FREE(ics, srcno) \ - (!((ics)->irqs[(srcno)].flags & (XICS_FLAGS_IRQ_MASK))) - static int spapr_irq_claim_xics(SpaprMachineState *spapr, int irq, bool ls= i, Error **errp) { @@ -129,7 +126,7 @@ static int spapr_irq_claim_xics(SpaprMachineState *spap= r, int irq, bool lsi, return -1; } =20 - if (!ICS_IRQ_FREE(ics, irq - ics->offset)) { + if (!ics_irq_free(ics, irq - ics->offset)) { error_setg(errp, "IRQ %d is not free", irq); return -1; } @@ -147,7 +144,7 @@ static void spapr_irq_free_xics(SpaprMachineState *spap= r, int irq, int num) if (ics_valid_irq(ics, irq)) { trace_spapr_irq_free(0, irq, num); for (i =3D srcno; i < srcno + num; ++i) { - if (ICS_IRQ_FREE(ics, i)) { + if (ics_irq_free(ics, i)) { trace_spapr_irq_free_warn(0, i); } memset(&ics->irqs[i], 0, sizeof(ICSIRQState)); @@ -767,7 +764,7 @@ static int ics_find_free_block(ICSState *ics, int num, = int alignnum) return -1; } for (i =3D first; i < first + num; ++i) { - if (!ICS_IRQ_FREE(ics, i)) { + if (!ics_irq_free(ics, i)) { break; } } --=20 2.21.0 From nobody Fri Apr 19 21:42:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1568209389; cv=none; d=zoho.com; s=zohoarc; b=AiQunDJioujnVcSYmlkRVXx2INWovRNd/U1hmfc7ViwNDXHHGH9QggazLuhc7E8WfrFFsQuVnsbGwv662WaMmpdOdMkDZ/YyUX2ScE9o/u7YoEb0gO7q2rV+HWkKS9E7LHjsVDT3Ke9suYcTSV314/51jz5mBfi6dmVvMr3V/ww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568209389; 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:ARC-Authentication-Results; bh=5gTfgj6zPtJRHehKfXwo9WKq5VCG564WJYTuofRkaSk=; b=f5T7q0AiMIVbDzMQG6PEy/FVrHoHSy9GvDGDejYeJK8MeE6LpvfH94U3Yn4cETOiF+wlzexJL/FOrg4jmONOf9+h3rnhZzI5he0f/MkyehbwvB0kodE+0RAN619J3l4ZHPc2yUq06KGcP7rO+l3rNbKpiLQa0wMMlKMy0Dwd78s= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1568209388998491.79039932284354; Wed, 11 Sep 2019 06:43:08 -0700 (PDT) Received: from localhost ([::1]:51214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82tn-0002NR-Or for importer@patchew.org; Wed, 11 Sep 2019 09:43:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34115) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82qv-0007l8-Cd for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:40:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i82qu-0006T0-17 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:40:09 -0400 Received: from 18.mo1.mail-out.ovh.net ([46.105.35.72]:59567) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i82qt-0006SW-S6 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:40:07 -0400 Received: from player792.ha.ovh.net (unknown [10.109.146.213]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id 0B90D18DC01 for ; Wed, 11 Sep 2019 15:40:06 +0200 (CEST) Received: from kaod.org (lfbn-1-2240-157.w90-76.abo.wanadoo.fr [90.76.60.157]) (Authenticated sender: clg@kaod.org) by player792.ha.ovh.net (Postfix) with ESMTPSA id 2731A9C4DFE2; Wed, 11 Sep 2019 13:39:58 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Date: Wed, 11 Sep 2019 15:39:37 +0200 Message-Id: <20190911133937.2716-3-clg@kaod.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190911133937.2716-1-clg@kaod.org> References: <20190911133937.2716-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 17957259091022220262 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedufedrtdefgdegtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 46.105.35.72 Subject: [Qemu-devel] [PATCH v2 2/2] spapr/irq: Only claim VALID interrupts at the KVM level 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: Satheesh Rajendran , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" A typical pseries VM with 16 vCPUs, one disk, one network adapater uses less than 100 interrupts but the whole IRQ number space of the QEMU machine is allocated at reset time and it is 8K wide. This is wasting a considerable amount of interrupt numbers in the global IRQ space which has 1M interrupts per socket on a POWER9. To optimise the HW resources, only request at the KVM level interrupts which have been claimed by the guest. This will help to increase the maximum number of VMs per system and also help supporting nested guests using the XIVE interrupt mode. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- hw/intc/spapr_xive_kvm.c | 29 ++++++++++++++++++++++++++--- hw/intc/xics_kvm.c | 8 ++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c index 17af4d19f54e..71b88d7797bc 100644 --- a/hw/intc/spapr_xive_kvm.c +++ b/hw/intc/spapr_xive_kvm.c @@ -255,11 +255,16 @@ void kvmppc_xive_source_reset_one(XiveSource *xsrc, i= nt srcno, Error **errp) =20 static void kvmppc_xive_source_reset(XiveSource *xsrc, Error **errp) { + SpaprXive *xive =3D SPAPR_XIVE(xsrc->xive); int i; =20 for (i =3D 0; i < xsrc->nr_irqs; i++) { Error *local_err =3D NULL; =20 + if (!xive_eas_is_valid(&xive->eat[i])) { + continue; + } + kvmppc_xive_source_reset_one(xsrc, i, &local_err); if (local_err) { error_propagate(errp, local_err); @@ -328,11 +333,18 @@ uint64_t kvmppc_xive_esb_rw(XiveSource *xsrc, int src= no, uint32_t offset, =20 static void kvmppc_xive_source_get_state(XiveSource *xsrc) { + SpaprXive *xive =3D SPAPR_XIVE(xsrc->xive); int i; =20 for (i =3D 0; i < xsrc->nr_irqs; i++) { + uint8_t pq; + + if (!xive_eas_is_valid(&xive->eat[i])) { + continue; + } + /* Perform a load without side effect to retrieve the PQ bits */ - uint8_t pq =3D xive_esb_read(xsrc, i, XIVE_ESB_GET); + pq =3D xive_esb_read(xsrc, i, XIVE_ESB_GET); =20 /* and save PQ locally */ xive_source_esb_set(xsrc, i, pq); @@ -521,9 +533,14 @@ static void kvmppc_xive_change_state_handler(void *opa= que, int running, */ if (running) { for (i =3D 0; i < xsrc->nr_irqs; i++) { - uint8_t pq =3D xive_source_esb_get(xsrc, i); + uint8_t pq; uint8_t old_pq; =20 + if (!xive_eas_is_valid(&xive->eat[i])) { + continue; + } + + pq =3D xive_source_esb_get(xsrc, i); old_pq =3D xive_esb_read(xsrc, i, XIVE_ESB_SET_PQ_00 + (pq << = 8)); =20 /* @@ -545,7 +562,13 @@ static void kvmppc_xive_change_state_handler(void *opa= que, int running, * migration is in progress. */ for (i =3D 0; i < xsrc->nr_irqs; i++) { - uint8_t pq =3D xive_esb_read(xsrc, i, XIVE_ESB_GET); + uint8_t pq; + + if (!xive_eas_is_valid(&xive->eat[i])) { + continue; + } + + pq =3D xive_esb_read(xsrc, i, XIVE_ESB_GET); =20 /* * PQ is set to PENDING to possibly catch a triggered diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c index a4d2e876cc5f..ba90d6dc966c 100644 --- a/hw/intc/xics_kvm.c +++ b/hw/intc/xics_kvm.c @@ -190,6 +190,10 @@ void ics_get_kvm_state(ICSState *ics) for (i =3D 0; i < ics->nr_irqs; i++) { ICSIRQState *irq =3D &ics->irqs[i]; =20 + if (ics_irq_free(ics, i)) { + continue; + } + kvm_device_access(kernel_xics_fd, KVM_DEV_XICS_GRP_SOURCES, i + ics->offset, &state, false, &error_fatal); =20 @@ -301,6 +305,10 @@ int ics_set_kvm_state(ICSState *ics, Error **errp) Error *local_err =3D NULL; int ret; =20 + if (ics_irq_free(ics, i)) { + continue; + } + ret =3D ics_set_kvm_state_one(ics, i, &local_err); if (ret < 0) { error_propagate(errp, local_err); --=20 2.21.0