From nobody Sun Nov 24 09:52:30 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1724771518; cv=none; d=zohomail.com; s=zohoarc; b=AOL0+OmOPBd36QG2NAq5A4725qTw8wCL4EVDM3rMnjKvHOBl2+TmCB+iWG6SqOajqoGz54N3NbcMk+LZ2S94XZ4hCKhTXZWLooKiKrRbjq2tpsrQjngDPyUF+YZys/YMpkz4hhLv0AoNelllPsvin6SCUxVonKuy4FfQQii6LGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724771518; 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=M4c8TB2xHXASJ1uR1do61nTZjlIA4R+OAlBc+Ffu1q0=; b=bMU8odCdC+4U1glxqUnQZwnIldBO7TFbqUVf2lPWvBTDPPxu5W5tr1Kc9CZMoPvcnjg1g5mJ+TdRCWj1K15PjKMgB4wQSQJj5TNBbQMywldgDfsbeRD1c8V5LdREeeYr//lqzrl5c0A1OwX2MSNa5fG0nZfJeKvY7bEIX24mu7M= 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 1724771518381758.8058507642336; Tue, 27 Aug 2024 08:11:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sixqN-0004mg-Bq; Tue, 27 Aug 2024 11:10:51 -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 1sixqL-0004dJ-Hp for qemu-devel@nongnu.org; Tue, 27 Aug 2024 11:10:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sixqG-0000WW-3o for qemu-devel@nongnu.org; Tue, 27 Aug 2024 11:10:49 -0400 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-551-KgUyrTdONz62Mi__feg9KA-1; Tue, 27 Aug 2024 11:10:41 -0400 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-71431f47164so5781626b3a.1 for ; Tue, 27 Aug 2024 08:10:41 -0700 (PDT) Received: from localhost.localdomain ([115.96.30.188]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7143430636esm8679062b3a.165.2024.08.27.08.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 08:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724771443; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M4c8TB2xHXASJ1uR1do61nTZjlIA4R+OAlBc+Ffu1q0=; b=Af6xSWlA2JPu7Ie/vNgwU5P6fXx+uS8zKiiotqvisEUf9H6XjsxMV0gSMRQ8/9YIFUjOjC NaRirGpAzwI0gPJa7lo11asXmgmBEVni/OFm9Toso274anmzOU2SFClDpX3ij8NcaCR9zm w5IktSriwXgxjVlq2WDO7GrpVq2mJMg= X-MC-Unique: KgUyrTdONz62Mi__feg9KA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724771440; x=1725376240; 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=M4c8TB2xHXASJ1uR1do61nTZjlIA4R+OAlBc+Ffu1q0=; b=nzX3BXBtQEhs51IMEwugaM9yxavBhvlA9ghtxpqCRnRYIB6E8BY1Dm1E0Z4rjhNzEE Vo2k9Vjg13QFfVg84j1dLUi0t0ae3LKRrwmCjCJOdpaP/fEujWuRFvD98O7bfw+xhklm PZ2JDPVIhNAS/f9cbE2iwioF6I8/hgzDu63kY/VXWE3wguoWlYV6CpexL55KLGEUi2cz SkwWiJw+IujIG9nXUIC7S6yToVqoO7ecdKpurZaA31pnOtH56HT67H1+W0UB/I3D1cMj j7UnwhGKUyLqJruCc617s0hK2IFcqE43NwU0GfBpa/j/Md5RPlQJFoXzwfHJoBVx0mzq lVrA== X-Forwarded-Encrypted: i=1; AJvYcCWFd6AGq+XjSJJIvddCK4cYWimQxa4K5DnyYvVq8y6QwpoXd1jYQ964MOAQCl47CC/M41Vrj6WSf8lQ@nongnu.org X-Gm-Message-State: AOJu0YxjjiqbekoZgEUpXIz0fm+pQMKd/SJPRHCJ56NDeGrlczchOOeI NtcsxKDtEEec2tTzA70ZYXWCJ42nmcV3/ury+AqRRAWlkT9mj3IPhIa5ily2VgIUcwX2G6J5XBa wF3m56HZoqFZskCIFPebPrKj1lFjDcUYoY/I+XzpQBK2c2qZkMyhU X-Received: by 2002:a05:6a00:1805:b0:714:3325:d8e9 with SMTP id d2e1a72fcca58-71445e1153fmr16802146b3a.22.1724771440582; Tue, 27 Aug 2024 08:10:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUEAqtApzRiyNS0JKuFBiyF3z3Asq7TBCcUFBE8fW8JjKPSqwZF7934+py5nk9lIIjydb91g== X-Received: by 2002:a05:6a00:1805:b0:714:3325:d8e9 with SMTP id d2e1a72fcca58-71445e1153fmr16802090b3a.22.1724771439974; Tue, 27 Aug 2024 08:10:39 -0700 (PDT) From: Ani Sinha To: Paolo Bonzini Cc: Ani Sinha , zhao1.liu@intel.com, cfontana@suse.de, armbru@redhat.com, qemu-trivial@nongnu.org, kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v4 2/2] kvm: refactor core virtual machine creation into its own function Date: Tue, 27 Aug 2024 20:40:22 +0530 Message-ID: <20240827151022.37992-3-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240827151022.37992-1-anisinha@redhat.com> References: <20240827151022.37992-1-anisinha@redhat.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=170.10.129.124; envelope-from=anisinha@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1724771519182116600 Content-Type: text/plain; charset="utf-8" Refactoring the core logic around KVM_CREATE_VM into its own separate funct= ion so that it can be called from other functions in subsequent patches. There = is no functional change in this patch. CC: pbonzini@redhat.com CC: zhao1.liu@intel.com CC: cfontana@suse.de CC: armbru@redhat.com CC: qemu-trivial@nongnu.org Reviewed-by: Zhao Liu Reviewed-by: Claudio Fontana Signed-off-by: Ani Sinha --- accel/kvm/kvm-all.c | 86 ++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 33 deletions(-) changelog: v2: s/fprintf/warn_report as suggested by zhao v3: s/warn_report/error_report. function names adjusted to conform to other names. fprintf -> error_report() moved to its own patch. v4: added tags and rebased. diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d9f477bb06..391279c995 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2385,6 +2385,57 @@ uint32_t kvm_dirty_ring_size(void) return kvm_state->kvm_dirty_ring_size; } =20 +static int kvm_create_vm(MachineState *ms, KVMState *s, int type) +{ + int ret; + + do { + ret =3D kvm_ioctl(s, KVM_CREATE_VM, type); + } while (ret =3D=3D -EINTR); + + if (ret < 0) { + error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret, + strerror(-ret)); + +#ifdef TARGET_S390X + if (ret =3D=3D -EINVAL) { + error_printf("Host kernel setup problem detected. Please verif= y:"); + error_printf("\n- for kernels supporting the" + " switch_amode or user_mode parameters, whether"); + error_printf(" user space is running in primary address space\= n"); + error_printf("- for kernels supporting the vm.allocate_pgste " + "sysctl, whether it is enabled\n"); + } +#elif defined(TARGET_PPC) + if (ret =3D=3D -EINVAL) { + error_printf("PPC KVM module is not loaded. Try modprobe kvm_%= s.\n", + (type =3D=3D 2) ? "pr" : "hv"); + } +#endif + } + + return ret; +} + +static int kvm_machine_type(MachineState *ms) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + int type; + + if (object_property_find(OBJECT(current_machine), "kvm-type")) { + g_autofree char *kvm_type; + kvm_type =3D object_property_get_str(OBJECT(current_machine), + "kvm-type", + &error_abort); + type =3D mc->kvm_type(ms, kvm_type); + } else if (mc->kvm_type) { + type =3D mc->kvm_type(ms, NULL); + } else { + type =3D kvm_arch_get_default_type(ms); + } + return type; +} + static int kvm_init(MachineState *ms) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); @@ -2467,45 +2518,14 @@ static int kvm_init(MachineState *ms) } s->as =3D g_new0(struct KVMAs, s->nr_as); =20 - if (object_property_find(OBJECT(current_machine), "kvm-type")) { - g_autofree char *kvm_type =3D object_property_get_str(OBJECT(curre= nt_machine), - "kvm-type", - &error_abort); - type =3D mc->kvm_type(ms, kvm_type); - } else if (mc->kvm_type) { - type =3D mc->kvm_type(ms, NULL); - } else { - type =3D kvm_arch_get_default_type(ms); - } - + type =3D kvm_machine_type(ms); if (type < 0) { ret =3D -EINVAL; goto err; } =20 - do { - ret =3D kvm_ioctl(s, KVM_CREATE_VM, type); - } while (ret =3D=3D -EINTR); - + ret =3D kvm_create_vm(ms, s, type); if (ret < 0) { - error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret, - strerror(-ret)); - -#ifdef TARGET_S390X - if (ret =3D=3D -EINVAL) { - error_printf("Host kernel setup problem detected. Please verif= y:"); - error_printf("\n- for kernels supporting the" - " switch_amode or user_mode parameters, whether"); - error_printf(" user space is running in primary address space\= n"); - error_printf("- for kernels supporting the vm.allocate_pgste " - "sysctl, whether it is enabled\n"); - } -#elif defined(TARGET_PPC) - if (ret =3D=3D -EINVAL) { - error_printf("PPC KVM module is not loaded. Try modprobe kvm_%= s.\n", - (type =3D=3D 2) ? "pr" : "hv"); - } -#endif goto err; } =20 --=20 2.42.0