From nobody Thu Nov 14 18:12:25 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=1708418369; cv=none; d=zohomail.com; s=zohoarc; b=RlOIcI0ZNvyCUK/3BZE5oiP7SxkkRozPwEW2MureOGAH4Ir66+aax/c4Lja4OdiINp3oDWYb0LPfMlvmOKw+BwJRB9FJTjrISTz6zs+49rmtfcXXgn6c04pG3ki66MIbpcHGjHYO8ZMeSbIdKjc6s/yAA94WCym7UMZFDzBm4s0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708418369; 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=6jps+aY1PetzDdZ/4d+uAZfFQCxF4IF3LiCKWjKulRU=; b=dwF0I4LGtcG4Xb0lWqYW015oAjMX6YRgjZmbaDF6WiN6MQs0Z/dhCbYOV5buvoUOOtjo6YsxrphvhG65qreb++sLQTFlLfJOIQ4ETH/XCRc9ZGofml+ujaHbgpLHc+LDABd1vQQvgASjBEjFlY6EJHxyi3VjGIx0eeHSiyw/+7E= 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 1708418369549268.5523567315943; Tue, 20 Feb 2024 00:39:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcLcT-0003Aj-BI; Tue, 20 Feb 2024 03:36:53 -0500 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 1rcLcO-00036b-C0; Tue, 20 Feb 2024 03:36:49 -0500 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 1rcLcK-00056h-N7; Tue, 20 Feb 2024 03:36:46 -0500 Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41K7VAhj005047; Tue, 20 Feb 2024 08:36:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wcpf7ubrv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Feb 2024 08:36:40 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 41K8UGRW004343; Tue, 20 Feb 2024 08:36:40 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 3wcpf7ubrf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Feb 2024 08:36:40 +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 41K7s076003623; Tue, 20 Feb 2024 08:36:39 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wb74tf9a4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Feb 2024 08:36:39 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41K8aX8o6030020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Feb 2024 08:36:36 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF0FF2004D; Tue, 20 Feb 2024 08:36:33 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4459C20040; Tue, 20 Feb 2024 08:36:32 +0000 (GMT) Received: from li-1901474c-32f3-11b2-a85c-fc5ff2c001f3.in.ibm.com (unknown [9.109.243.35]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 20 Feb 2024 08:36:32 +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=6jps+aY1PetzDdZ/4d+uAZfFQCxF4IF3LiCKWjKulRU=; b=MT8mcu35oIVgcrBYs0OnxbgBhkedOmSMmID5sjEVO25ZjlnP5cs0PpR6jFeKIB4fDS1y e6GxH4B1JU3QApwXqpilu5inlPdR3qN+WAcfpzVY3WFC+Kvkxl1k/xRZr7CTLP9hvfmo rR0WYydorKF3ShtzXSi/BavtDkSYgOMjiHeht2EM5LmOgmtLcV3/Wn/mQ/ipkk137O+8 YGqLlHR6pHoiN9GAsh5D+NwDi8Us5UtjcmpAvrwsddz3oDpxPRwM+MIV5CQIo3mc1yx6 AKJ+mNpxypGAayGjrYKhItBP4E2QAhxJo/ufi4Ai/UWPJXyQOiu7+a9CSg8oHx6cmh97 fA== From: Harsh Prateek Bora To: npiggin@gmail.com, qemu-ppc@nongnu.org Cc: clegoate@redhat.com, mikey@neuling.org, amachhiw@linux.vnet.ibm.com, vaibhav@linux.ibm.com, sbhat@linux.ibm.com, danielhb413@gmail.com, qemu-devel@nongnu.org Subject: [PATCH v4 08/15] spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall. Date: Tue, 20 Feb 2024 14:06:02 +0530 Message-Id: <20240220083609.748325-9-harshpb@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240220083609.748325-1-harshpb@linux.ibm.com> References: <20240220083609.748325-1-harshpb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Yns1nqgYpwzinUqJMrbaBHmRcoFsqnqJ X-Proofpoint-GUID: nwFHQLZPAYqMq0ElYqW7nhEPr29yRaki X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-20_06,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 mlxlogscore=826 phishscore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402200061 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1708418370889100003 Content-Type: text/plain; charset="utf-8" Introduce the nested PAPR hcall H_GUEST_CREATE_VCPU which is used to create and initialize the specified VCPU resource for the previously created guest. Each guest can have multiple VCPUs upto max 2048. All VCPUs for a guest gets deallocated on guest delete. Signed-off-by: Michael Neuling Signed-off-by: Harsh Prateek Bora --- include/hw/ppc/spapr.h | 2 + include/hw/ppc/spapr_nested.h | 10 ++++ hw/ppc/spapr_nested.c | 96 +++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index c4a79a1785..82b077bdd2 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -365,6 +365,7 @@ struct SpaprMachineState { #define H_UNSUPPORTED -67 #define H_OVERLAP -68 #define H_STATE -75 +#define H_IN_USE -77 #define H_UNSUPPORTED_FLAG -256 #define H_MULTI_THREADS_ACTIVE -9005 =20 @@ -587,6 +588,7 @@ struct SpaprMachineState { #define H_GUEST_GET_CAPABILITIES 0x460 #define H_GUEST_SET_CAPABILITIES 0x464 #define H_GUEST_CREATE 0x470 +#define H_GUEST_CREATE_VCPU 0x474 #define H_GUEST_DELETE 0x488 =20 #define MAX_HCALL_OPCODE H_GUEST_DELETE diff --git a/include/hw/ppc/spapr_nested.h b/include/hw/ppc/spapr_nested.h index f282479275..24e87bca08 100644 --- a/include/hw/ppc/spapr_nested.h +++ b/include/hw/ppc/spapr_nested.h @@ -14,6 +14,8 @@ typedef struct SpaprMachineStateNested { =20 typedef struct SpaprMachineStateNestedGuest { uint32_t pvr_logical; + unsigned long vcpus; + struct SpaprMachineStateNestedGuestVcpu *vcpu; } SpaprMachineStateNestedGuest; =20 /* Nested PAPR API related macros */ @@ -27,6 +29,7 @@ typedef struct SpaprMachineStateNestedGuest { #define H_GUEST_CAP_P10_MODE_BMAP 2 #define PAPR_NESTED_GUEST_MAX 4096 #define H_GUEST_DELETE_ALL_FLAG 0x8000000000000000ULL +#define PAPR_NESTED_GUEST_VCPU_MAX 2048 =20 /* * Register state for entering a nested guest with H_ENTER_NESTED. @@ -118,8 +121,15 @@ struct nested_ppc_state { uint64_t ppr; =20 int64_t tb_offset; + /* Nested PAPR API */ + uint64_t pvr; }; =20 +typedef struct SpaprMachineStateNestedGuestVcpu { + bool enabled; + struct nested_ppc_state state; +} SpaprMachineStateNestedGuestVcpu; + void spapr_exit_nested(PowerPCCPU *cpu, int excp); typedef struct SpaprMachineState SpaprMachineState; bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu, diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c index 09c4a35908..3cc704adda 100644 --- a/hw/ppc/spapr_nested.c +++ b/hw/ppc/spapr_nested.c @@ -428,6 +428,41 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp) } } =20 +static +SpaprMachineStateNestedGuest *spapr_get_nested_guest(SpaprMachineState *sp= apr, + target_ulong guestid) +{ + SpaprMachineStateNestedGuest *guest; + + guest =3D g_hash_table_lookup(spapr->nested.guests, GINT_TO_POINTER(gu= estid)); + return guest; +} + +static bool spapr_nested_vcpu_check(SpaprMachineStateNestedGuest *guest, + target_ulong vcpuid) +{ + struct SpaprMachineStateNestedGuestVcpu *vcpu; + /* + * Perform sanity checks for the provided vcpuid of a guest. + * For now, ensure its valid, allocated and enabled for use. + */ + + if (vcpuid >=3D PAPR_NESTED_GUEST_VCPU_MAX) { + return false; + } + + if (!(vcpuid < guest->vcpus)) { + return false; + } + + vcpu =3D &guest->vcpu[vcpuid]; + if (!vcpu->enabled) { + return false; + } + + return true; +} + static target_ulong h_guest_get_capabilities(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong opcode, @@ -518,6 +553,7 @@ static void destroy_guest_helper(gpointer value) { struct SpaprMachineStateNestedGuest *guest =3D value; + g_free(guest->vcpu); g_free(guest); } =20 @@ -613,6 +649,65 @@ static target_ulong h_guest_delete(PowerPCCPU *cpu, return H_SUCCESS; } =20 +static target_ulong h_guest_create_vcpu(PowerPCCPU *cpu, + SpaprMachineState *spapr, + target_ulong opcode, + target_ulong *args) +{ + CPUPPCState *env =3D &cpu->env; + struct nested_ppc_state *l2_state; + target_ulong flags =3D args[0]; + target_ulong guestid =3D args[1]; + target_ulong vcpuid =3D args[2]; + SpaprMachineStateNestedGuest *guest; + + if (flags) { /* don't handle any flags for now */ + return H_UNSUPPORTED_FLAG; + } + + guest =3D spapr_get_nested_guest(spapr, guestid); + if (!guest) { + return H_P2; + } + + if (vcpuid < guest->vcpus) { + return H_IN_USE; + } + + if (guest->vcpus >=3D PAPR_NESTED_GUEST_VCPU_MAX) { + return H_P3; + } + + if (guest->vcpus) { + SpaprMachineStateNestedGuestVcpu *vcpus; + vcpus =3D g_try_renew(struct SpaprMachineStateNestedGuestVcpu, + guest->vcpu, + guest->vcpus + 1); + if (!vcpus) { + return H_NO_MEM; + } + memset(&vcpus[guest->vcpus], 0, + sizeof(SpaprMachineStateNestedGuestVcpu)); + guest->vcpu =3D vcpus; + } else { + guest->vcpu =3D g_try_new0(SpaprMachineStateNestedGuestVcpu, 1); + if (guest->vcpu =3D=3D NULL) { + return H_NO_MEM; + } + } + l2_state =3D &guest->vcpu[guest->vcpus].state; + guest->vcpus++; + assert(vcpuid < guest->vcpus); /* linear vcpuid allocation only */ + /* Set L1 PVR as L2 default */ + l2_state->pvr =3D env->spr[SPR_PVR]; + guest->vcpu[vcpuid].enabled =3D true; + + if (!spapr_nested_vcpu_check(guest, vcpuid)) { + return H_PARAMETER; + } + return H_SUCCESS; +} + void spapr_register_nested_hv(void) { spapr_register_hypercall(KVMPPC_H_SET_PARTITION_TABLE, h_set_ptbl); @@ -635,6 +730,7 @@ void spapr_register_nested_papr(void) spapr_register_hypercall(H_GUEST_SET_CAPABILITIES, h_guest_set_capabil= ities); spapr_register_hypercall(H_GUEST_CREATE , h_guest_create); spapr_register_hypercall(H_GUEST_DELETE , h_guest_delete); + spapr_register_hypercall(H_GUEST_CREATE_VCPU , h_guest_create_vcpu= ); } =20 #else --=20 2.39.3