From nobody Sun Nov 24 10:44:03 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=1723180346; cv=none; d=zohomail.com; s=zohoarc; b=RyQHOpjXE+lcNwj89JaVxqscG8xWGl+cGvK1KXgZ/aA1qMJCzbr0GiDcQltVydIaHCOaRpnQICqYdNRdrq4ijHPWChfwIYVbmX46qilGRbDDOL8zpXHxWdRCEL+lscoZwGQQCFlu1l6s108yVKjob6YIKvIHm5imBVT0ZSvGAmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723180346; 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=cqMbqqTDoxkH4lSjzfRzKJ8KXs/o+RTOSJGbYKXw66A=; b=UaFTjA1+4yR8NkDNL621KpGP6R8gIxEgAGJK11HcZuyRZPWFNQrL/DjjtwIRZ5fozMvMZVQjE38lnm/mqQgyqap8+umzQvzlnMsFju6m+74vD7mH7r9Q1uQHyQMCyVEoKkkmPWRKZczC/TYcNWj+FVKrtYlRR8XxtmjC+leFfgA= 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 1723180346639800.9447744973061; Thu, 8 Aug 2024 22:12:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1scHuT-00023w-IJ; Fri, 09 Aug 2024 01:11:29 -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 1scHuR-00020y-Tc for qemu-devel@nongnu.org; Fri, 09 Aug 2024 01:11:27 -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 1scHuQ-0002lw-8j for qemu-devel@nongnu.org; Fri, 09 Aug 2024 01:11:27 -0400 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-295-wNizktVnN_iY5Q7CpcFOkQ-1; Fri, 09 Aug 2024 01:11:23 -0400 Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-70d24aead3eso1823355b3a.0 for ; Thu, 08 Aug 2024 22:11:23 -0700 (PDT) Received: from localhost.localdomain ([115.96.114.241]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710cb2e52bfsm1961777b3a.145.2024.08.08.22.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 22:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723180285; 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=cqMbqqTDoxkH4lSjzfRzKJ8KXs/o+RTOSJGbYKXw66A=; b=WOAgv/2R84uy4DDXiqEyK8e2yCaeQAXvh21pkl1J6iWQpZ+s9cxwG9xg8U6qOTD7tfiq9Q hSmrbfgmWdLFh0GXlRP/4CItnxH9x1cY7FUDOrXy/m9Po/wzbsnnK3RQV3/mZwie/BCyqc 28fLTf5aKdhs1/blRsY3YU0OeM+JSco= X-MC-Unique: wNizktVnN_iY5Q7CpcFOkQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723180282; x=1723785082; 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=cqMbqqTDoxkH4lSjzfRzKJ8KXs/o+RTOSJGbYKXw66A=; b=cHnlHBSFloMX4LkyxtX248ZhYrNeZssIv+OJyPsHTop323YNxwnwvkjsvyeV+oCwtj 6WLJDEbDhcLHlZAdRKNIR9OzWtVCeCw7JpB4VwBmXuhr3LdDvvAwXr56rl+VCTKP5ZSS zNMcQeHSxDDYxKV1TXZlrYMY3oEOIOtYG2ZSWmpNuqH/B4hwwIUuePsx65xJbSpn/isU glnzilEIvdGFn6vfCKGyuC2OGyOsGGIACS4bEymSYbi+lUwbIO9kVk4PJD36S1mA1cuG n2CG0M8UCRY+Bf478ROPMr0Aqg/ZLdIMu3IIy++mInFfl0jNixpWu8Q/F+XK0dB+r3F7 fe/Q== X-Forwarded-Encrypted: i=1; AJvYcCUC8J6a6OzA9zpSM30l9XcccFjltpipTdT+aOInhjC5KecB++mB0pyLAuH2taVnZNkcl/ydMa+nCWJrYHmwNavIDO0oXtE= X-Gm-Message-State: AOJu0Ywm5aCc3qwT6Kr06Ze+VmnQcQPD6B0Y7vqOowxmxSdRD2jWLppe CQ3+hgmLm/biugSzY/dL1dEOievHI0Gs7l1fC51fufyrBvktMu4dw6si0SbQ97hl5GdtFKV4g/7 NH6eSb1540TC3O+UC6EeK2okKHWkWL5hgTncZfrl3HbMTEXymlNOs X-Received: by 2002:a05:6a00:855:b0:710:6e83:cd5e with SMTP id d2e1a72fcca58-710dc2ccebfmr516744b3a.0.1723180282429; Thu, 08 Aug 2024 22:11:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8t0EAoP7cgCq1cRFAtmK6Tr42nsp3je6iK76kbLnen1NCNIOlxzNdQMxqQhXKXDPa/XxChA== X-Received: by 2002:a05:6a00:855:b0:710:6e83:cd5e with SMTP id d2e1a72fcca58-710dc2ccebfmr516717b3a.0.1723180281966; Thu, 08 Aug 2024 22:11:21 -0700 (PDT) From: Ani Sinha To: Paolo Bonzini Cc: Ani Sinha , qemu-trivial@nongnu.org, zhao1.liu@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v2 1/2] kvm: replace fprintf with error_report() in kvm_init() for error conditions Date: Fri, 9 Aug 2024 10:40:53 +0530 Message-ID: <20240809051054.1745641-2-anisinha@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240809051054.1745641-1-anisinha@redhat.com> References: <20240809051054.1745641-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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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, 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 @redhat.com) X-ZM-MESSAGEID: 1723180348084116600 Content-Type: text/plain; charset="utf-8" error_report() is more appropriate for error situations. Replace fprintf wi= th error_report. Cosmetic. No functional change. CC: qemu-trivial@nongnu.org CC: zhao1.liu@intel.com Signed-off-by: Ani Sinha Reviewed-by: Zhao Liu --- accel/kvm/kvm-all.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) changelog: v2: fix a bug. diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 75d11a07b2..ac168b9663 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms) QLIST_INIT(&s->kvm_parked_vcpus); s->fd =3D qemu_open_old(s->device ?: "/dev/kvm", O_RDWR); if (s->fd =3D=3D -1) { - fprintf(stderr, "Could not access KVM kernel module: %m\n"); + error_report("Could not access KVM kernel module: %m"); ret =3D -errno; goto err; } @@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms) if (ret >=3D 0) { ret =3D -EINVAL; } - fprintf(stderr, "kvm version too old\n"); + error_report("kvm version too old"); goto err; } =20 if (ret > KVM_API_VERSION) { ret =3D -EINVAL; - fprintf(stderr, "kvm version not supported\n"); + error_report("kvm version not supported"); goto err; } =20 @@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms) } while (ret =3D=3D -EINTR); =20 if (ret < 0) { - fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -ret, - strerror(-ret)); + error_report("ioctl(KVM_CREATE_VM) failed: %d %s", -ret, + strerror(-ret)); =20 #ifdef TARGET_S390X if (ret =3D=3D -EINVAL) { - fprintf(stderr, - "Host kernel setup problem detected. Please verify:\n"= ); - fprintf(stderr, "- for kernels supporting the switch_amode or" - " user_mode parameters, whether\n"); - fprintf(stderr, - " user space is running in primary address space\n"); - fprintf(stderr, - "- for kernels supporting the vm.allocate_pgste sysctl= , " - "whether it is enabled\n"); + error_report("Host kernel setup problem detected. Please verif= y:"); + error_report("- for kernels supporting the switch_amode or" + " user_mode parameters, whether"); + error_report(" user space is running in primary address space= "); + error_report("- for kernels supporting the vm.allocate_pgste " + "sysctl, whether it is enabled"); } #elif defined(TARGET_PPC) if (ret =3D=3D -EINVAL) { - fprintf(stderr, - "PPC KVM module is not loaded. Try modprobe kvm_%s.\n", - (type =3D=3D 2) ? "pr" : "hv"); + error_report("PPC KVM module is not loaded. Try modprobe kvm_%= s.", + (type =3D=3D 2) ? "pr" : "hv"); } #endif goto err; @@ -2526,9 +2522,9 @@ static int kvm_init(MachineState *ms) nc->name, nc->num, soft_vcpus_limit); =20 if (nc->num > hard_vcpus_limit) { - fprintf(stderr, "Number of %s cpus requested (%d) exceeds " - "the maximum cpus supported by KVM (%d)\n", - nc->name, nc->num, hard_vcpus_limit); + error_report("Number of %s cpus requested (%d) exceeds " + "the maximum cpus supported by KVM (%d)", + nc->name, nc->num, hard_vcpus_limit); exit(1); } } @@ -2542,8 +2538,8 @@ static int kvm_init(MachineState *ms) } if (missing_cap) { ret =3D -EINVAL; - fprintf(stderr, "kvm does not support %s\n%s", - missing_cap->name, upgrade_note); + error_report("kvm does not support %s", missing_cap->name); + error_report("%s", upgrade_note); goto err; } =20 --=20 2.45.2 From nobody Sun Nov 24 10:44:03 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=1723180330; cv=none; d=zohomail.com; s=zohoarc; b=X5Nhx1I8YTS7qWU9bfTu9BPwSfgvl3+LUUQu7aWZze+OLMvTjXpxiFMOQDO06DgFApCAp7cJ035YqMCEnii8K4ZXdnfI5WagVc+VQ3qB9hIBoNo12W6U7pSpQwRz+GO4bR/XlN1UidKE0IJqlxf8dsw/RUvnuwomkGY5hmwHbow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723180330; 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=VFVzUlNsVsXQ/Du+Ve53FGF58OzF7Hoq8mZruS9vw88=; b=PNPrlwx4uyDBxDbyUN1hZ+/R3O+gJb18oj+UvfryTiY25ezVDVqrcOx3PenmX6xCTURWcdaF9ZC72IEOl7GOwYH2zVratFsxNHKFdjM2DJs0TkDpTKGmsqCE0eooqPrJ76TfvDOp4hfHf7aMM5DS8aCwbetHybuoOXow0gpGYCY= 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 1723180330119779.0243649732012; Thu, 8 Aug 2024 22:12:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1scHuV-0002DV-Sw; Fri, 09 Aug 2024 01:11:31 -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 1scHuU-00028t-Pp for qemu-devel@nongnu.org; Fri, 09 Aug 2024 01:11:30 -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 1scHuT-0002mS-9d for qemu-devel@nongnu.org; Fri, 09 Aug 2024 01:11:30 -0400 Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-483-VUAcvqvAOd6m8yV9mU7MxA-1; Fri, 09 Aug 2024 01:11:26 -0400 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-66628e9ec89so35926707b3.1 for ; Thu, 08 Aug 2024 22:11:26 -0700 (PDT) Received: from localhost.localdomain ([115.96.114.241]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-710cb2e52bfsm1961777b3a.145.2024.08.08.22.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 22:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723180288; 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=VFVzUlNsVsXQ/Du+Ve53FGF58OzF7Hoq8mZruS9vw88=; b=WJ4TFMDfjVrmFSUwBIM8yJwl5FZI6lmZgGP1x7WQVcFrgTS4YVBGtAUT2sBroOnFrbPNU8 xjVbPmAvvKzNB4sKJJ1cea7gK8ktGgrN3Z3WL71fnX++MtfJxXAm3M8l/3Ifih4IlNe1GV 6PWlfnhveaRqdMV02oR+s9MeclcXQro= X-MC-Unique: VUAcvqvAOd6m8yV9mU7MxA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723180285; x=1723785085; 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=VFVzUlNsVsXQ/Du+Ve53FGF58OzF7Hoq8mZruS9vw88=; b=GpzCm41MPpDDHrsSViOb/6JslohfnTFtixEwKiswLX6jlhJZTzp1AUVI42+MXso8aq PDPLM+ObH2cqLwp7dqEW1qZOdlYlW7a9r+c7Z9CgVQPIDJnj4pXm8KtKhJlqjihvqa3s T773z2dkMN0THHMSZG1+70IMrl7oIlISti+XqC3UpxChW5HwhuboB1DUKXHewbkNwz7j qAFh8cvwBXXhh2iW1AAg5vtlP+hZXR/MuM+k0U9JkRyP5wt952naig5R/EWu9ZW/Ffq/ W35MtcjCkDG9Ys6l6TKchn3sDFavIjtvLV6LcZ44GXBb9Q2TYabEvRwTQVMyDFfIDyzg enrw== X-Forwarded-Encrypted: i=1; AJvYcCUPeqlcFMEeJzFbjNA8SvyJU9AuEYIGVUNI2asMCWhBIcOywFTmX5XH6ioFWnHhnA78bf9sCkkU2GsdumnVwyRLTYn2wpc= X-Gm-Message-State: AOJu0YxcrdIwFZdf9sTlVkwoAqKC1Y9EtVnfIMiu5EEIv3pQXwG5EYfT btITVJO4iFDrW//MrnxXAEOUjsIdpFJ2MlCjHJEqXXXjclAlbAMmsm3Wqbvrm3vcQBkxZCwoXNs rEJebqxLXZup1pWvYAPwQSH0bqHtCXmx7UZyarNFcg2RsSo5Cr6sg X-Received: by 2002:a05:690c:4292:b0:651:6888:a018 with SMTP id 00721157ae682-69ec5f414d7mr4786067b3.26.1723180285575; Thu, 08 Aug 2024 22:11:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESxQ+gkuExf9qc7vHUqL759aFOHOfgP2U0oqXC1HAlKJzIsPV8FKQvsxiLnMad+g7fVVCucA== X-Received: by 2002:a05:690c:4292:b0:651:6888:a018 with SMTP id 00721157ae682-69ec5f414d7mr4785867b3.26.1723180285247; Thu, 08 Aug 2024 22:11:25 -0700 (PDT) From: Ani Sinha To: Paolo Bonzini Cc: Ani Sinha , zhao1.liu@intel.com, cfontana@suse.de, qemu-trivial@nongnu.org, kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v3 2/2] kvm: refactor core virtual machine creation into its own function Date: Fri, 9 Aug 2024 10:40:54 +0530 Message-ID: <20240809051054.1745641-3-anisinha@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240809051054.1745641-1-anisinha@redhat.com> References: <20240809051054.1745641-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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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, 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 @redhat.com) X-ZM-MESSAGEID: 1723180332060116600 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: qemu-trivial@nongnu.org Signed-off-by: Ani Sinha Reviewed-by: Claudio Fontana Reviewed-by: Zhao Liu --- 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. diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index ac168b9663..610b3ead32 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_report("Host kernel setup problem detected. Please verif= y:"); + error_report("- for kernels supporting the switch_amode or" + " user_mode parameters, whether"); + error_report(" user space is running in primary address space= "); + error_report("- for kernels supporting the vm.allocate_pgste " + "sysctl, whether it is enabled"); + } +#elif defined(TARGET_PPC) + if (ret =3D=3D -EINVAL) { + error_report("PPC KVM module is not loaded. Try modprobe kvm_%= s.", + (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_report("Host kernel setup problem detected. Please verif= y:"); - error_report("- for kernels supporting the switch_amode or" - " user_mode parameters, whether"); - error_report(" user space is running in primary address space= "); - error_report("- for kernels supporting the vm.allocate_pgste " - "sysctl, whether it is enabled"); - } -#elif defined(TARGET_PPC) - if (ret =3D=3D -EINVAL) { - error_report("PPC KVM module is not loaded. Try modprobe kvm_%= s.", - (type =3D=3D 2) ? "pr" : "hv"); - } -#endif goto err; } =20 --=20 2.45.2