From nobody Mon Nov 25 07:28:07 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1716449271; cv=none; d=zohomail.com; s=zohoarc; b=bB92tZ2SfDUgWYL4MpSZ9+84pB7B7Tlq2Q0e/87Nxm5QKsl8S00hDEglL6FKTQHYmSpOxTA7o4gxl+x3mUAUruilB0MBxuP2mkaiQjC3RIgPvbfzKY4S6A98MuVeesUWVpJNsOEe9/f/kNgywzCVTfStTPGNIgYNxJUlMlOp4x4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716449271; 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=eecTpgF0LB4D8lp1qu8Okw+yAaPhKYcSM4E7YMX+HOw=; b=LqHF4BjWGAwdsnOpBSgL0It7NM/9itZYsUBZnqKioUybfVokHYdVU+sPR45nvxV0M1Jg/1gDc9704ZE80R9vcxU568NtAMk0IlmNLwS7LE+NyT8AxuqzF6WeE4xRYwFtyKtF/ks1QJQi1zMBpQQ/aNOx46d3iqNvFY8qOCcj2TI= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716449271687825.672346941098; Thu, 23 May 2024 00:27:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA2qz-0007IP-NU; Thu, 23 May 2024 03:27:14 -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 1sA2qr-0007Ee-1u; Thu, 23 May 2024 03:27:02 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA2qp-0000Dw-6s; Thu, 23 May 2024 03:27:00 -0400 Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44N7QuSd012832; Thu, 23 May 2024 07:26:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ya0b685ba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 07:26:57 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44N7QvmI012860; Thu, 23 May 2024 07:26:57 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ya0b685aw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 07:26:57 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 44N63EAJ008226; Thu, 23 May 2024 07:26:43 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3y78vm899m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 07:26:43 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 44N7QbWs57540978 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2024 07:26:39 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A8B672004B; Thu, 23 May 2024 07:26:37 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7656920040; Thu, 23 May 2024 07:26:36 +0000 (GMT) Received: from li-1901474c-32f3-11b2-a85c-fc5ff2c001f3.in.ibm.com (unknown [9.109.242.165]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 23 May 2024 07:26:36 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=eecTpgF0LB4D8lp1qu8Okw+yAaPhKYcSM4E7YMX+HOw=; b=AiCRisWkCwDZn7ia30QpxzVyYbkgp9Kreq4iRlTY2Zu4BDlw13ZH0oZhURMkj6+bdeHC 8uc4VVVoHW1DUjhShtEicAYdjxhF7KEE24e6bZ0IgfqFpYUB/m/xUxFIVPclQm9ERWyO 49kO93QAzhDR1d8GtSaQbhfLLwfmFGZbuAI/iZOCmcXZPuEhOv350nNfIxu7pFBS/i9y drkS3BwoYL+28PkTli1XwIdp9mX6mgd1DkLuAyekCR6dl1ZtzJsq2N31aFuTM5O1a0YF eAjkWr8JgU303kJt6cNigmzqLhH//hgDzMQFU54LlqFWGq2Cm7VodYVp35whpCX1IzO+ SA== From: Harsh Prateek Bora To: npiggin@gmail.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org Cc: danielhb413@gmail.com, vaibhav@linux.ibm.com, sbhat@linux.ibm.com Subject: [PATCH v3 1/3] accel/kvm: Introduce kvm_create_and_park_vcpu() helper Date: Thu, 23 May 2024 12:56:12 +0530 Message-Id: <20240523072614.256172-2-harshpb@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240523072614.256172-1-harshpb@linux.ibm.com> References: <20240523072614.256172-1-harshpb@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: R8BVU_kRMjXwObOhj4gUOZl-aVEgpols X-Proofpoint-ORIG-GUID: pJZtvgS-jiIU4JlhmrkkPEIco5AmrGJd Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-23_04,2024-05-22_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405230048 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=148.163.158.5; envelope-from=harshpb@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @ibm.com) X-ZM-MESSAGEID: 1716449272036100005 Content-Type: text/plain; charset="utf-8" There are distinct helpers for creating and parking a KVM vCPU. However, there can be cases where a platform needs to create and immediately park the vCPU during early stages of vcpu init which can later be reused when vcpu thread gets initialized. This would help detect failures with kvm_create_vcpu at an early stage. Based on api refactoring to create/park vcpus introduced in 1/8 of patch se= ries: https://lore.kernel.org/qemu-devel/20240522211111.232114-1-salil.mehta@huaw= ei.com/ Suggested-by: Nicholas Piggin Signed-off-by: Harsh Prateek Bora Reviewed-by: Nicholas Piggin --- accel/kvm/kvm-cpus.h | 8 ++++++++ accel/kvm/kvm-all.c | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/accel/kvm/kvm-cpus.h b/accel/kvm/kvm-cpus.h index 2e6bb38b5d..00e534b3b9 100644 --- a/accel/kvm/kvm-cpus.h +++ b/accel/kvm/kvm-cpus.h @@ -46,4 +46,12 @@ void kvm_park_vcpu(CPUState *cpu); * @returns: KVM fd */ int kvm_unpark_vcpu(KVMState *s, unsigned long vcpu_id); + +/** + * * kvm_create_and_park_vcpu - Create and park a KVM vCPU + * * @cpu: QOM CPUState object for which KVM vCPU has to be created and = parked. + * * + * * @returns: 0 when success, errno (<0) when failed. + * */ +int kvm_create_and_park_vcpu(CPUState *cpu); #endif /* KVM_CPUS_H */ diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index fc30e5d5b8..d70ca62ff5 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -398,6 +398,18 @@ int kvm_create_vcpu(CPUState *cpu) return 0; } =20 +int kvm_create_and_park_vcpu(CPUState *cpu) +{ + int ret =3D 0; + + ret =3D kvm_create_vcpu(cpu); + if (!ret) { + kvm_park_vcpu(cpu); + } + + return ret; +} + static int do_kvm_destroy_vcpu(CPUState *cpu) { KVMState *s =3D kvm_state; --=20 2.39.3 From nobody Mon Nov 25 07:28:07 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1716449242; cv=none; d=zohomail.com; s=zohoarc; b=fx4vCTbZ+Wg1I089d7ftmNyDCUbeD74mOCQd6LGElYEzeWu3zFCdgXlHToo8jPJ/+vSblFwT3M0eT5u4sTCiKBto0v1ieUuFz0k7Swpn+iv2E1JOgpjNL/PUhNhRedRTIjpNLDs1R/rVrWZ5zQ3KiFWsrkVUzIx8VCGw45UmCMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716449242; 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=u5nUcOOzm7QvDOlxuhR8wow1ilAy/PMO5KzzFNCX8P8=; b=hdnMwB3xyFK7eIM5L6LUhvpfQGEge9OOS8jUBAe+p8rXiDVkbFvquf4or0/INy9jtHii9MZwDtHv/kv2f4qwih0XzZIuNsHjGuRCVk7OTDtexEpoxaTlCAsbHnJXFMHR6JRG/Ey53bHCE5tYbOygHKiaXT7nUS+5JnEgsjZPdKc= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716449242937435.07547920238324; Thu, 23 May 2024 00:27:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA2qi-00079R-U2; Thu, 23 May 2024 03:26:52 -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 1sA2qf-000781-R5; Thu, 23 May 2024 03:26:50 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA2qe-0008WP-4z; Thu, 23 May 2024 03:26:49 -0400 Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44N7H0pQ019045; Thu, 23 May 2024 07:26:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ya19a00mj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 07:26:45 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44N7QjfW002920; Thu, 23 May 2024 07:26:45 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ya19a00mg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 07:26:45 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 44N6pQmU022240; Thu, 23 May 2024 07:26:44 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3y76nu0x3f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 07:26:44 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 44N7QddZ47251824 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2024 07:26:41 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 315082004E; Thu, 23 May 2024 07:26:39 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EFCB32004F; Thu, 23 May 2024 07:26:37 +0000 (GMT) Received: from li-1901474c-32f3-11b2-a85c-fc5ff2c001f3.in.ibm.com (unknown [9.109.242.165]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 23 May 2024 07:26:37 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=u5nUcOOzm7QvDOlxuhR8wow1ilAy/PMO5KzzFNCX8P8=; b=Ii2tTRiwgE8mt5rqjKLKmC6aT62xZpp/7/Wa9Ezv7m2xtZWPDMAlWsDdecU9JAvTi1KD Yeiz9GW+NkRLEzN5uRUssUWPq1HT70GmkFTvA9QOFDCWHTSFOeochmZc0jP1CsverysF Ff1jiimeh89XHwZ13aOPPEudLC+H9+1Ge1IXzZZ7g/sjni2W1wcxZ3/QhgPLCspa2N5a sy4VIhZ5I/PrRAXOvVD/4nePUaJ50dczQ8QuFqwIZeXghB9L5i4MU71U2iOvs6gw9Uzb 0ECaWezsrktc6lBzeC0fV/4Gkse4ceFEhM3vOjIrcO8yNRfQCW+CnTxiTW9r+lB+ER1V yQ== From: Harsh Prateek Bora To: npiggin@gmail.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org Cc: danielhb413@gmail.com, vaibhav@linux.ibm.com, sbhat@linux.ibm.com Subject: [PATCH v3 2/3] cpu-common.c: export cpu_get_free_index to be reused later Date: Thu, 23 May 2024 12:56:13 +0530 Message-Id: <20240523072614.256172-3-harshpb@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240523072614.256172-1-harshpb@linux.ibm.com> References: <20240523072614.256172-1-harshpb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Ebpd97Z2WhbLbssW1b6qTgjAqlwLOrgO X-Proofpoint-GUID: CHA-0NvsxazuG7A0h7XEz23cQXP62JZP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-23_04,2024-05-22_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 bulkscore=0 clxscore=1015 impostorscore=0 spamscore=0 mlxscore=0 mlxlogscore=846 malwarescore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405230048 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=148.163.156.1; envelope-from=harshpb@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @ibm.com) X-ZM-MESSAGEID: 1716449243764100001 Content-Type: text/plain; charset="utf-8" This helper provides an easy way to identify the next available free cpu index which can be used for vcpu creation. Until now, this is being called at a very later stage and there is a need to be able to call it earlier (for now, with ppc64) hence the need to export. Suggested-by: Nicholas Piggin Signed-off-by: Harsh Prateek Bora Reviewed-by: Nicholas Piggin --- include/exec/cpu-common.h | 2 ++ cpu-common.c | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 6d5318895a..0386f1ab29 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -29,6 +29,8 @@ void cpu_list_lock(void); void cpu_list_unlock(void); unsigned int cpu_list_generation_id_get(void); =20 +int cpu_get_free_index(void); + void tcg_iommu_init_notifier_list(CPUState *cpu); void tcg_iommu_free_notifier_list(CPUState *cpu); =20 diff --git a/cpu-common.c b/cpu-common.c index ce78273af5..82bd1b432d 100644 --- a/cpu-common.c +++ b/cpu-common.c @@ -57,14 +57,12 @@ void cpu_list_unlock(void) qemu_mutex_unlock(&qemu_cpu_list_lock); } =20 -static bool cpu_index_auto_assigned; =20 -static int cpu_get_free_index(void) +int cpu_get_free_index(void) { CPUState *some_cpu; int max_cpu_index =3D 0; =20 - cpu_index_auto_assigned =3D true; CPU_FOREACH(some_cpu) { if (some_cpu->cpu_index >=3D max_cpu_index) { max_cpu_index =3D some_cpu->cpu_index + 1; @@ -83,8 +81,11 @@ unsigned int cpu_list_generation_id_get(void) =20 void cpu_list_add(CPUState *cpu) { + static bool cpu_index_auto_assigned; + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); if (cpu->cpu_index =3D=3D UNASSIGNED_CPU_INDEX) { + cpu_index_auto_assigned =3D true; cpu->cpu_index =3D cpu_get_free_index(); assert(cpu->cpu_index !=3D UNASSIGNED_CPU_INDEX); } else { --=20 2.39.3 From nobody Mon Nov 25 07:28:07 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1716449269; cv=none; d=zohomail.com; s=zohoarc; b=ZY4/1ynHZEkCqP8k+jJobuUtbBtTp6V+IVIrxP+iCxViGzEuHpvF1UDdsOQ4VS4q+UwDm28De4+BDNUULh80aCxnx6yWWKydKLoIWhAwShkkARxoZSe79LnaileVClZcJxYaFZWnXBKIvX8WmhGfsAvRgJjO3lNN0JttBU8yIGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716449269; 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=u7t5/AqU71PS3fk3TudCv8Nw3kUnartbBsM+VxyIwOY=; b=IOUr3RmKpPmfqrnZxXhgAc4bzz/m70C0mc/UqG7tTmQuCVRgWKXHjqcLNI1ODAh2pj1ma08VjmJsB4tArSJTla1DxIW/p8V3j9adYF4UHsV6VmLRTqAhJw8LYTSirKqN19cytYVBdLZMO/PvqKDcTRzXKJOM38HdQr0VtZ5JnBg= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716449269713238.09889174991713; Thu, 23 May 2024 00:27:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA2ql-0007AL-6Z; Thu, 23 May 2024 03:26:55 -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 1sA2qj-00079T-3K; Thu, 23 May 2024 03:26:53 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA2qh-00008d-BB; Thu, 23 May 2024 03:26:52 -0400 Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44N7IUGB022733; Thu, 23 May 2024 07:26:49 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ya19a00mr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 07:26:49 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44N7QnD4002962; Thu, 23 May 2024 07:26:49 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ya19a00mn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 07:26:49 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 44N6bZQ4000923; Thu, 23 May 2024 07:26:46 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3y7720gugq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 07:26:46 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 44N7QeXo30212854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2024 07:26:42 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA2CF20043; Thu, 23 May 2024 07:26:40 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 787302004F; Thu, 23 May 2024 07:26:39 +0000 (GMT) Received: from li-1901474c-32f3-11b2-a85c-fc5ff2c001f3.in.ibm.com (unknown [9.109.242.165]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 23 May 2024 07:26:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=u7t5/AqU71PS3fk3TudCv8Nw3kUnartbBsM+VxyIwOY=; b=R0jBpLGV8Cb0yPx96foUdxNd/iiej3JeX18dfWl2rKUZUB4QuryUBPLi0CCqd6fZV6Rh mzrRNDx/PXx8XHtB6CMFtAFTUevuIdWnVAUqvdylZwO71C+rlXL59vzzcvuNKvVHb3EZ OFTlD4D9wWqPZXc8No5AdImIwf9eSlxLo4h0rv/krhw6Mvrvrcb+L3NcRo6NXLytK6Uw ozKM2Y7IXnxKzJHhgxh0kLuSSP0eILsUPR3OpO3J9J2CIuD0dVFBNUmFDFumWfqHtX7W KbbLVDb08DXf88WaQ/KafcUpqY+F76ppHtdEIg0ygrt/SbnPB+2YytPPRixNQGyqkiCr Hw== From: Harsh Prateek Bora To: npiggin@gmail.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org Cc: danielhb413@gmail.com, vaibhav@linux.ibm.com, sbhat@linux.ibm.com Subject: [PATCH v3 3/3] target/ppc: handle vcpu hotplug failure gracefully Date: Thu, 23 May 2024 12:56:14 +0530 Message-Id: <20240523072614.256172-4-harshpb@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240523072614.256172-1-harshpb@linux.ibm.com> References: <20240523072614.256172-1-harshpb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: klkwyRq9VPNrSXLz3V2t5tJrskE6seTZ X-Proofpoint-GUID: cW-4UysHJjP57rj4rWzhdX-bTD2FarjR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-23_04,2024-05-22_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 bulkscore=0 clxscore=1015 impostorscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405230048 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=148.163.156.1; envelope-from=harshpb@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @ibm.com) X-ZM-MESSAGEID: 1716449269854100001 Content-Type: text/plain; charset="utf-8" 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 Reported-by: Anushree Mathur Suggested-by: Shivaprasad G Bhat Suggested-by: Vaibhav Jain Signed-off by: Harsh Prateek Bora Tested-by: Anushree Mathur Reviewed-by: Nicholas Piggin --- target/ppc/kvm.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 63930d4a77..8e5a7c3d2d 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 "accel/kvm/kvm-cpus.h" +#include "hw/core/accel-cpu.h" =20 #define PROC_DEVTREE_CPU "/proc/device-tree/cpus/" =20 @@ -2339,6 +2341,25 @@ 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) { + 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); @@ -2959,3 +2980,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.39.3