From nobody Mon Feb 9 04:46:29 2026 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=1710263313; cv=none; d=zohomail.com; s=zohoarc; b=a8XTI7jrjziFDTWBv1GztuIHRPKdrbNz7RWdBV6cgiNEeOqF2F19wVCxn+J5dCSawFdG31BbcEWoV2MRM0su26keI7b44D9t8Ioa2WsJUnm86UuTpI8vTRPOPxeRmEGkctMH4VvqNg8XuLIUPG1eD9WzJ3O7G3UWj1WoMdkq7A8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710263313; 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=ZxAZDNkVeicKPAVy4559sSS+y8z567HqIodOKDjwHAw=; b=EhKsM+sY+wBNp+ie+IpFk+uXGV/lnqFrqWeJgIxRuBPGoGGjXlMKuRp8NKIkiISoN+n0kb5vzBmm7YIdgAPtno454/OE1PL9wluTPa1tN7hpWEnJGbhiapfRNAl2e+qEzgqYBzGslVbsk/2aa7hhhmun1VL73JKDOz6WVQ23BCs= 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 1710263313970196.2577481668809; Tue, 12 Mar 2024 10:08:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk5Wy-0003ij-UJ; Tue, 12 Mar 2024 13:03:13 -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 1rk5Uu-0006e3-JK; Tue, 12 Mar 2024 13:01:10 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk5Us-0008VD-Qe; Tue, 12 Mar 2024 13:01:04 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e6adc557b6so613744b3a.2; Tue, 12 Mar 2024 10:01:01 -0700 (PDT) Received: from wheely.local0.net ([118.208.155.46]) by smtp.gmail.com with ESMTPSA id t34-20020a056a0013a200b006e6a684a6ddsm1362330pfg.220.2024.03.12.10.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 10:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710262860; x=1710867660; 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=ZxAZDNkVeicKPAVy4559sSS+y8z567HqIodOKDjwHAw=; b=KJldXMTckeIWiSdjk/wRV0AlkfgIHt8m/Hd5Iu9d1CBnsmBWUAAluwoVms9HZfMLMG 9rt50ap5z176oN+MBw6vpeyzqEGkhQxbI9K9FzZ+GbbSoMHvxtaYqbWKTXKYh9JiXby8 nitGJCTb+A8sAgtonOM3E4l1P1NyfJAKoJrNq2g+bK70pFo/kNu3xqMUItCCFGlbD5kc FI15c85P1VHHfqpxHTnu36AQID+sEDglCv/dbiQrztUrcXH8+01o+TOIOXKRapX14k3f x1S2KUfy3oZv9eP/VZevDkKA2rrAQZGwcLIGFNLavk7B6BWiFvVpCysORTsE/jzLrWeP FjTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710262860; x=1710867660; 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=ZxAZDNkVeicKPAVy4559sSS+y8z567HqIodOKDjwHAw=; b=Du/gfOyvvuFFnNz6DuS2c+h0SdDTnJ1jQiZeKmY8RYUi9keBz8HDS4Ol/+WiMsBPpa Ul2rTmuEX9VtX2QMPZ5cM+S0ntRcU6o/PJv4rPvo9HxdJmJvf2kTcjJuFD6xaMFvPPjC ZMhLw2QutcYN2s8aSD9xrMjRX7kj4dPCC/dnAUVoqjK9Lxu0xf9odrZw1l1AhU/cElig RlQBoq61mQv9vRzCxTCvpKDNkK3FqHVioZe2ll4qFx4blTi76zSnvND01Yg7fic6AGNG pZVO5qGlg5QTK7OnyYcHYO3pZpLXno79MtsOg6b/aAi+Ss01+pUjseP4g/Lr7LR8aAsx rSHg== X-Forwarded-Encrypted: i=1; AJvYcCXu68DvBYQQfmzGYWeX61h8Sa0R07PftqIOYEn/7h08gKvWNXoN1Exoxdau/ob+dsipvT7JlwpnmUm8POozHUmw09q0 X-Gm-Message-State: AOJu0YzO/XQsTihlJJrAH6qxPf9P/IgRm/hgAvF96tdvQbo2arfG5E78 8nTAALuhwzXT4EbrTKj+NoPS7N5Ppe6AOW10c42z8z+PsuW8AVqxLKRTWw6q5jU= X-Google-Smtp-Source: AGHT+IF+zd89vHLmB71USiPGNDhEL/5CEgsZvqUEXzI4bt/aHFGlpiXKLwsxG77xG1M0sg2LIoPrag== X-Received: by 2002:a05:6a20:1456:b0:1a3:1246:c43e with SMTP id a22-20020a056a20145600b001a31246c43emr956956pzi.28.1710262859946; Tue, 12 Mar 2024 10:00:59 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Daniel Henrique Barboza , Harsh Prateek Bora , Michael Neuling Subject: [PULL 32/38] spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall. Date: Wed, 13 Mar 2024 02:58:43 +1000 Message-ID: <20240312165851.2240242-33-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240312165851.2240242-1-npiggin@gmail.com> References: <20240312165851.2240242-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::42c; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42c.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, 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 @gmail.com) X-ZM-MESSAGEID: 1710263315474100003 Content-Type: text/plain; charset="utf-8" From: Harsh Prateek Bora 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. Reviewed-by: Nicholas Piggin Signed-off-by: Michael Neuling Signed-off-by: Harsh Prateek Bora Signed-off-by: Nicholas Piggin --- hw/ppc/spapr_nested.c | 62 +++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ include/hw/ppc/spapr_nested.h | 8 +++++ 3 files changed, 72 insertions(+) diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c index 1f6eb68b93..72bf3dc6d4 100644 --- a/hw/ppc/spapr_nested.c +++ b/hw/ppc/spapr_nested.c @@ -8,6 +8,7 @@ #include "hw/ppc/spapr_nested.h" #include "mmu-book3s-v3.h" #include "cpu-models.h" +#include "qemu/log.h" =20 void spapr_nested_reset(SpaprMachineState *spapr) { @@ -434,6 +435,16 @@ 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 target_ulong h_guest_get_capabilities(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong opcode, @@ -525,6 +536,7 @@ static void destroy_guest_helper(gpointer value) { struct SpaprMachineStateNestedGuest *guest =3D value; + g_free(guest->vcpus); g_free(guest); } =20 @@ -620,6 +632,54 @@ 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) +{ + 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->nr_vcpus) { + qemu_log_mask(LOG_UNIMP, "vcpuid " TARGET_FMT_ld " already in use.= ", + vcpuid); + return H_IN_USE; + } + /* linear vcpuid allocation only */ + assert(vcpuid =3D=3D guest->nr_vcpus); + + if (guest->nr_vcpus >=3D PAPR_NESTED_GUEST_VCPU_MAX) { + return H_P3; + } + + SpaprMachineStateNestedGuestVcpu *vcpus, *curr_vcpu; + vcpus =3D g_try_renew(struct SpaprMachineStateNestedGuestVcpu, + guest->vcpus, + guest->nr_vcpus + 1); + if (!vcpus) { + return H_NO_MEM; + } + guest->vcpus =3D vcpus; + curr_vcpu =3D &vcpus[guest->nr_vcpus]; + memset(curr_vcpu, 0, sizeof(SpaprMachineStateNestedGuestVcpu)); + + curr_vcpu->enabled =3D true; + guest->nr_vcpus++; + + return H_SUCCESS; +} + void spapr_register_nested_hv(void) { spapr_register_hypercall(KVMPPC_H_SET_PARTITION_TABLE, h_set_ptbl); @@ -644,6 +704,7 @@ void spapr_register_nested_papr(void) h_guest_set_capabilities); 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 void spapr_unregister_nested_papr(void) @@ -652,6 +713,7 @@ void spapr_unregister_nested_papr(void) spapr_unregister_hypercall(H_GUEST_SET_CAPABILITIES); spapr_unregister_hypercall(H_GUEST_CREATE); spapr_unregister_hypercall(H_GUEST_DELETE); + spapr_unregister_hypercall(H_GUEST_CREATE_VCPU); } =20 #else diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 13416fc3d7..070135793a 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 56d43e540b..2ac3076fac 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 nr_vcpus; + struct SpaprMachineStateNestedGuestVcpu *vcpus; } 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. @@ -120,6 +123,11 @@ struct nested_ppc_state { int64_t tb_offset; }; =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, --=20 2.42.0