From nobody Tue Feb 10 14:33:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1590033341; cv=none; d=zohomail.com; s=zohoarc; b=ToGKhedxg/ZymBQ99/4hd/TdHlrQGFuvRmenj1RBZV3uuwvFlAzpXxHL37mpUvCzlHAe8/imeI3jhjbnKPW6GqBZPuujHK4eyITs7M7lZafESffeZhtzYn2y723vCZ+iUXqY3JseLUVqZVP2pbrnu/ECi/zA/4f5ZiYyc0fLJWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033341; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=psSoeBtEmh44VJzComDreoO6bGBw00d5uh8OFOA+USU=; b=ZttlBfnjgm9rolsKQ8//fOTyGqXkiFD0qQIHf8xilomeItq3Uo1PmZX75yM7Ch0GdzKOXGTwh3OpZImT2cWLVjyyENiPuLaSrNmRBz8koAOQCcMn2EDAJUhJhtW6ZjMnv4UQR40g1Y0q9BDFaVrq0ZKn7BJACReVqp57DpCCEqY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590033341134860.4086547454907; Wed, 20 May 2020 20:55:41 -0700 (PDT) Received: from localhost ([::1]:36078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcJ1-0006nF-TZ for importer@patchew.org; Wed, 20 May 2020 23:55:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7N-0003Hz-FT; Wed, 20 May 2020 23:43:37 -0400 Received: from ozlabs.org ([203.11.71.1]:41131) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7M-0003YT-8D; Wed, 20 May 2020 23:43:37 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnt57zsz9sVF; Thu, 21 May 2020 13:43:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032594; bh=eup3iyYUWnuqB9PIhUENkDwPcTYFDbBI7Pm2SOCB26g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNlximYBa0hlzRkqewPUvqQcL4/R29JENQCQDo/w2gabH//RHCoafExY6olBai97u dBQwRafjSrUt1N7sGl4TCztWSHVjBRgZF3YIvdHrb5leAvrL2fd0eMZZRQFV5J5kPj /BTpeFjCzuO4WBH9PcgTwAQYVEQ4Kou+DlBjYV8c= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 16/18] guest memory protection: Add Error ** to GuestMemoryProtection::kvm_init Date: Thu, 21 May 2020 13:43:02 +1000 Message-Id: <20200521034304.340040-17-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-1-david@gibson.dropbear.id.au> 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=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , Richard Henderson , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This allows failures to be reported richly and idiomatically. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- accel/kvm/kvm-all.c | 4 +++- include/exec/guest-memory-protection.h | 2 +- target/i386/sev.c | 31 +++++++++++++------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 1b10e94222..4011699736 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2079,9 +2079,11 @@ static int kvm_init(MachineState *ms) if (ms->gmpo) { GuestMemoryProtectionClass *gmpc =3D GUEST_MEMORY_PROTECTION_GET_CLASS(ms->gmpo); + Error *local_err =3D NULL; =20 - ret =3D gmpc->kvm_init(ms->gmpo); + ret =3D gmpc->kvm_init(ms->gmpo, &local_err); if (ret < 0) { + error_report_err(local_err); goto err; } } diff --git a/include/exec/guest-memory-protection.h b/include/exec/guest-me= mory-protection.h index 7d959b4910..2a88475136 100644 --- a/include/exec/guest-memory-protection.h +++ b/include/exec/guest-memory-protection.h @@ -32,7 +32,7 @@ typedef struct GuestMemoryProtection GuestMemoryProtectio= n; typedef struct GuestMemoryProtectionClass { InterfaceClass parent; =20 - int (*kvm_init)(GuestMemoryProtection *); + int (*kvm_init)(GuestMemoryProtection *, Error **); int (*encrypt_data)(GuestMemoryProtection *, uint8_t *, uint64_t); } GuestMemoryProtectionClass; =20 diff --git a/target/i386/sev.c b/target/i386/sev.c index 60e9d8c735..6a56ec203b 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -617,7 +617,7 @@ sev_vm_state_change(void *opaque, int running, RunState= state) } } =20 -static int sev_kvm_init(GuestMemoryProtection *gmpo) +static int sev_kvm_init(GuestMemoryProtection *gmpo, Error **errp) { SevGuestState *sev =3D SEV_GUEST(gmpo); char *devname; @@ -633,14 +633,14 @@ static int sev_kvm_init(GuestMemoryProtection *gmpo) host_cbitpos =3D ebx & 0x3f; =20 if (host_cbitpos !=3D sev->cbitpos) { - error_report("%s: cbitpos check failed, host '%d' requested '%d'", - __func__, host_cbitpos, sev->cbitpos); + error_setg(errp, "%s: cbitpos check failed, host '%d' requested '%= d'", + __func__, host_cbitpos, sev->cbitpos); goto err; } =20 if (sev->reduced_phys_bits < 1) { - error_report("%s: reduced_phys_bits check failed, it should be >= =3D1," - " requested '%d'", __func__, sev->reduced_phys_bits); + error_setg(errp, "%s: reduced_phys_bits check failed, it should be= >=3D1," + " requested '%d'", __func__, sev->reduced_phys_bits); goto err; } =20 @@ -649,20 +649,19 @@ static int sev_kvm_init(GuestMemoryProtection *gmpo) devname =3D object_property_get_str(OBJECT(sev), "sev-device", NULL); sev->sev_fd =3D open(devname, O_RDWR); if (sev->sev_fd < 0) { - error_report("%s: Failed to open %s '%s'", __func__, - devname, strerror(errno)); - } - g_free(devname); - if (sev->sev_fd < 0) { + error_setg(errp, "%s: Failed to open %s '%s'", __func__, + devname, strerror(errno)); + g_free(devname); goto err; } + g_free(devname); =20 ret =3D sev_platform_ioctl(sev->sev_fd, SEV_PLATFORM_STATUS, &status, &fw_error); if (ret) { - error_report("%s: failed to get platform status ret=3D%d " - "fw_error=3D'%d: %s'", __func__, ret, fw_error, - fw_error_to_str(fw_error)); + error_setg(errp, "%s: failed to get platform status ret=3D%d " + "fw_error=3D'%d: %s'", __func__, ret, fw_error, + fw_error_to_str(fw_error)); goto err; } sev->build_id =3D status.build; @@ -672,14 +671,14 @@ static int sev_kvm_init(GuestMemoryProtection *gmpo) trace_kvm_sev_init(); ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_INIT, NULL, &fw_error); if (ret) { - error_report("%s: failed to initialize ret=3D%d fw_error=3D%d '%s'= ", - __func__, ret, fw_error, fw_error_to_str(fw_error)); + error_setg(errp, "%s: failed to initialize ret=3D%d fw_error=3D%d = '%s'", + __func__, ret, fw_error, fw_error_to_str(fw_error)); goto err; } =20 ret =3D sev_launch_start(sev); if (ret) { - error_report("%s: failed to create encryption context", __func__); + error_setg(errp, "%s: failed to create encryption context", __func= __); goto err; } =20 --=20 2.26.2