From nobody Sat May 4 01:40:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495031972937116.88320418361286; Wed, 17 May 2017 07:39:32 -0700 (PDT) Received: from localhost ([::1]:49319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB06o-0006h8-7C for importer@patchew.org; Wed, 17 May 2017 10:39:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB05x-0006Jn-Je for qemu-devel@nongnu.org; Wed, 17 May 2017 10:38:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB05u-0008OM-HB for qemu-devel@nongnu.org; Wed, 17 May 2017 10:38:33 -0400 Received: from 18.mo3.mail-out.ovh.net ([87.98.172.162]:46075) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dB05u-0008O2-9l for qemu-devel@nongnu.org; Wed, 17 May 2017 10:38:30 -0400 Received: from player797.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo3.mail-out.ovh.net (Postfix) with ESMTP id 87E3DD2CE1 for ; Wed, 17 May 2017 16:38:27 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player797.ha.ovh.net (Postfix) with ESMTPA id C38222E00A4; Wed, 17 May 2017 16:38:20 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 17 May 2017 16:38:20 +0200 Message-ID: <149503190026.11264.1637374942003022823.stgit@bahia.lan> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 6945395053647272230 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeljedrudejgdejkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.172.162 Subject: [Qemu-devel] [PATCH] xics_kvm: cache already enabled vCPU ids X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , David Gibson , qemu-ppc@nongnu.org, Cedric Le Goater , Bharata B Rao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Since commit a45863bda90d ("xics_kvm: Don't enable KVM_CAP_IRQ_XICS if already enabled"), we were able to re-hotplug a vCPU that had been hot- unplugged ealier, thanks to a boolean flag in ICPState that we set when enabling KVM_CAP_IRQ_XICS. This could work because the lifecycle of all ICPState objects was the same as the machine. Commit 5bc8d26de20c ("spapr: allocate the ICPState object from under sPAPRCPUCore") broke this assumption and now we always pass a freshly allocated ICPState object (ie, with the flag unset) to icp_kvm_cpu_setup(). This cause re-hotplug to fail with: Unable to connect CPU8 to kernel XICS: Device or resource busy Let's fix this by caching all the vCPU ids for which KVM_CAP_IRQ_XICS was enabled. This also drops the now useless boolean flag from ICPState. Reported-by: Laurent Vivier Signed-off-by: Greg Kurz Reviewed-by: C=C3=A9dric Le Goater =20 Reviewed-by: Laurent Vivier Tested-by: Laurent Vivier --- hw/intc/xics_kvm.c | 27 ++++++++++++++++++++------- include/hw/ppc/xics.h | 1 - 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c index dd93531ae376..dd7f29846235 100644 --- a/hw/intc/xics_kvm.c +++ b/hw/intc/xics_kvm.c @@ -42,6 +42,14 @@ =20 static int kernel_xics_fd =3D -1; =20 +typedef struct KVMEnabledICP { + unsigned long vcpu_id; + QLIST_ENTRY(KVMEnabledICP) node; +} KVMEnabledICP; + +static QLIST_HEAD(, KVMEnabledICP) + kvm_enabled_icps =3D QLIST_HEAD_INITIALIZER(&kvm_enabled_icps); + /* * ICP-KVM */ @@ -121,6 +129,8 @@ static void icp_kvm_reset(void *dev) static void icp_kvm_cpu_setup(ICPState *icp, PowerPCCPU *cpu) { CPUState *cs =3D CPU(cpu); + KVMEnabledICP *enabled_icp; + unsigned long vcpu_id =3D kvm_arch_vcpu_id(cs); int ret; =20 if (kernel_xics_fd =3D=3D -1) { @@ -132,18 +142,21 @@ static void icp_kvm_cpu_setup(ICPState *icp, PowerPCC= PU *cpu) * which was hot-removed earlier we don't have to renable * KVM_CAP_IRQ_XICS capability again. */ - if (icp->cap_irq_xics_enabled) { - return; + QLIST_FOREACH(enabled_icp, &kvm_enabled_icps, node) { + if (enabled_icp->vcpu_id =3D=3D vcpu_id) { + return; + } } =20 - ret =3D kvm_vcpu_enable_cap(cs, KVM_CAP_IRQ_XICS, 0, kernel_xics_fd, - kvm_arch_vcpu_id(cs)); + ret =3D kvm_vcpu_enable_cap(cs, KVM_CAP_IRQ_XICS, 0, kernel_xics_fd, v= cpu_id); if (ret < 0) { - error_report("Unable to connect CPU%ld to kernel XICS: %s", - kvm_arch_vcpu_id(cs), strerror(errno)); + error_report("Unable to connect CPU%ld to kernel XICS: %s", vcpu_i= d, + strerror(errno)); exit(1); } - icp->cap_irq_xics_enabled =3D true; + enabled_icp =3D g_malloc(sizeof(*enabled_icp)); + enabled_icp->vcpu_id =3D vcpu_id; + QLIST_INSERT_HEAD(&kvm_enabled_icps, enabled_icp, node); } =20 static void icp_kvm_realize(DeviceState *dev, Error **errp) diff --git a/include/hw/ppc/xics.h b/include/hw/ppc/xics.h index d6cb51f3ad5d..a3073f90533a 100644 --- a/include/hw/ppc/xics.h +++ b/include/hw/ppc/xics.h @@ -81,7 +81,6 @@ struct ICPState { uint8_t pending_priority; uint8_t mfrr; qemu_irq output; - bool cap_irq_xics_enabled; =20 XICSFabric *xics; };