From nobody Fri Oct 18 08:39:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1721951977; cv=none; d=zohomail.com; s=zohoarc; b=FYbsSfwl7WcP+FSOt3YjeKgge9HbM/BJAjGQNGkO5uPHdZwEp3d3kYsiPKxBUwzG/GJec+JZVpbpALR9skV47CkxyRknWxfDqmZnh+hy+kqecP+v+JzYaFGIlTr+UOZiMwIvX1Tmd2XpW90YvgRJ0HrTHDMMw+KtNT/S5U9NQXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721951977; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zbylTCKtEz0fZhsc8131n5s5SygNd8gxPxzcYetS3m0=; b=eEtZJWT/ugvvYnr+CXak/nO09GG2ZzusJ+6wy0bMTadsBnASUCJvrgbwh6ewA/jFbyrcS7PV4d9AUeNp0mNYBhMMyczaTj1QGn5pMw0tv76vPqQIDbWEkp29INhJqL6x3SElCS0Bx1dMkopnO/FM6r5vT4vsYwY3COF2NT6K2uQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1721951977221855.365436628603; Thu, 25 Jul 2024 16:59:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sX8IY-00042n-Af; Thu, 25 Jul 2024 19:55:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sX8IW-0003vl-BR; Thu, 25 Jul 2024 19:55:00 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sX8IU-0000aW-KI; Thu, 25 Jul 2024 19:55:00 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-70d2e68f5a8so337710b3a.3; Thu, 25 Jul 2024 16:54:57 -0700 (PDT) Received: from wheely.local0.net ([203.220.44.216]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c7fef3sm2142060a91.16.2024.07.25.16.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 16:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721951696; x=1722556496; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zbylTCKtEz0fZhsc8131n5s5SygNd8gxPxzcYetS3m0=; b=hVlDijA62WnUDtqAA4o55si8mB7BGebnBVqoVvI4AvBpUtiZbHXwy4sQGSw0ubShn4 h6UnHxopUgRt2zrl6wWB4N77CFPqUu5VS1oYWQB91dQg5gvbqv9gaXYVjxUopXTjui9g hc2qALSUvXicVqfxstPlFumU/KpHvcopKa4oFiqjdNtFywIv6RAZUv2SD149i6SqTsv1 5waVQeXuDLa1rormgp7ZPdAgqwpnNNuAawjp8qbdGsWacG2FgfmQdcDZL/FPbLfzq/1d iO/ZFzCfJPj+bHtfEUK9WmpT8LDAa7S8AUHDfN2cPpAzAHTToeNExwnsjDNeWzBeIRhk f12A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721951696; x=1722556496; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zbylTCKtEz0fZhsc8131n5s5SygNd8gxPxzcYetS3m0=; b=WL1jsT46Hooknqgg30DHyki1vSMwnFA/A5Xybg7UV+DqTwE9tVolyflq/TPmzn7+bE FM6QC7bW1eoD0hwrMPzONuGyuIdvLmuvsBln6pA8llc3wMFQqbarKe99TGxvgM6ABFjf nLdpzb9h2YmNoWExleAB9eAGH69RJA6ikUvmude7ZDHSCQqb1qIEx26A2zQrHVzxhOa7 aAr5XABBYgLTy71dIi+CKWj0tHJmcz1Kk2R206zYsBDlQXVgmOlckiZfIwa0iH4O0Eij qlRhfm8sKIRYQa3kitslzHMZ9X0uFPsuv6nt2Aaqk3pApEPDZl51F8xAK1PrNIvy5bFd sRhg== X-Forwarded-Encrypted: i=1; AJvYcCVIGt9is1R8KWgL2PSybpdpUkQ2XQUZW/8I5tkBS00Z7pfpXBbWHvV1zfazWntgM37oQnJnzcQVFJYnfd3vyOa7/9y+ X-Gm-Message-State: AOJu0Ywrzguzw1eIxuh6pRDjMYRLojv6MmOZ/1AeJuc4UBKBJEd8izr4 /FM/sere4Q4IrBZW2gc1qNujaHHsg3VpHE/t5zd/LmPoeGMfmsBbndS//g== X-Google-Smtp-Source: AGHT+IFbR2//Ftm9MMKLp9dGcgFDW9l0yfsnBxrPqLgr/FQxVOX7WMc54xQ9FPgou0gaeArzNIz6Cw== X-Received: by 2002:a05:6a21:3987:b0:1af:66aa:7fc7 with SMTP id adf61e73a8af0-1c47b167d0emr4669600637.3.1721951696456; Thu, 25 Jul 2024 16:54:56 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Harsh Prateek Bora , Anushree Mathur , Shivaprasad G Bhat , Vaibhav Jain Subject: [PULL 07/96] target/ppc: handle vcpu hotplug failure gracefully Date: Fri, 26 Jul 2024 09:52:40 +1000 Message-ID: <20240725235410.451624-8-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240725235410.451624-1-npiggin@gmail.com> References: <20240725235410.451624-1-npiggin@gmail.com> MIME-Version: 1.0 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: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1721951978791116600 Content-Type: text/plain; charset="utf-8" From: Harsh Prateek Bora On ppc64, the PowerVM hypervisor runs with limited memory and a VCPU creation during hotplug may fail during kvm_ioctl for KVM_CREATE_VCPU, leading to termination of guest since errp is set to &error_fatal while calling kvm_init_vcpu. This unexpected behaviour can be avoided by pre-creating and parking vcpu on success or return error otherwise. This enables graceful error delivery for any vcpu hotplug failures while the guest can keep running. Also introducing KVM AccelCPUClass to init cpu_target_realize for kvm. Tested OK by repeatedly doing a hotplug/unplug of vcpus as below: #virsh setvcpus hotplug 40 #virsh setvcpus hotplug 70 error: internal error: unable to execute QEMU command 'device_add': kvmppc_cpu_realize: vcpu hotplug failed with -12 Signed-off by: Harsh Prateek Bora Reported-by: Anushree Mathur Suggested-by: Shivaprasad G Bhat Suggested-by: Vaibhav Jain Tested-by: Anushree Mathur Reviewed-by: Nicholas Piggin Signed-off-by: Nicholas Piggin --- target/ppc/kvm.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 2c3932200b..907dba60d1 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -48,6 +48,8 @@ #include "qemu/mmap-alloc.h" #include "elf.h" #include "sysemu/kvm_int.h" +#include "sysemu/kvm.h" +#include "hw/core/accel-cpu.h" =20 #include CONFIG_DEVICES =20 @@ -2346,6 +2348,30 @@ static void alter_insns(uint64_t *word, uint64_t fla= gs, bool on) } } =20 +static bool kvmppc_cpu_realize(CPUState *cs, Error **errp) +{ + int ret; + const char *vcpu_str =3D (cs->parent_obj.hotplugged =3D=3D true) ? + "hotplug" : "create"; + cs->cpu_index =3D cpu_get_free_index(); + + POWERPC_CPU(cs)->vcpu_id =3D cs->cpu_index; + + /* create and park to fail gracefully in case vcpu hotplug fails */ + ret =3D kvm_create_and_park_vcpu(cs); + if (ret) { + /* + * This causes QEMU to terminate if initial CPU creation + * fails, and only CPU hotplug failure if the error happens + * there. + */ + error_setg(errp, "%s: vcpu %s failed with %d", + __func__, vcpu_str, ret); + return false; + } + return true; +} + static void kvmppc_host_cpu_class_init(ObjectClass *oc, void *data) { PowerPCCPUClass *pcc =3D POWERPC_CPU_CLASS(oc); @@ -2966,3 +2992,23 @@ void kvmppc_set_reg_tb_offset(PowerPCCPU *cpu, int64= _t tb_offset) void kvm_arch_accel_class_init(ObjectClass *oc) { } + +static void kvm_cpu_accel_class_init(ObjectClass *oc, void *data) +{ + AccelCPUClass *acc =3D ACCEL_CPU_CLASS(oc); + + acc->cpu_target_realize =3D kvmppc_cpu_realize; +} + +static const TypeInfo kvm_cpu_accel_type_info =3D { + .name =3D ACCEL_CPU_NAME("kvm"), + + .parent =3D TYPE_ACCEL_CPU, + .class_init =3D kvm_cpu_accel_class_init, + .abstract =3D true, +}; +static void kvm_cpu_accel_register_types(void) +{ + type_register_static(&kvm_cpu_accel_type_info); +} +type_init(kvm_cpu_accel_register_types); --=20 2.45.2