From nobody Mon Nov 17 01:25:50 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602247193; cv=none; d=zohomail.com; s=zohoarc; b=c9wvHqP85GNHHOto1ZlGMQuYSKecYTnjqZ2tKIm3QcHa/7c0nQxiVBMGPB74z8DNsFawU5nbahjzh9W7knhJA1FwiD7J3N9mFScztBLXU5VFQhSqfbijlOz4ExosMpCRnoSOFhZDLSzLW2NWWTgFsBMGotXpjP5eyaBcxF6lMTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602247193; h=Content-Type: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=2zkz2SEKDwDKngOS2g2FJBlJQ/tGTWTMzrwYb9qJdhk=; b=Vuo5ybmvyo7uMcDHJPF6qDE1S5prpffzm1rpPis/fcNMII0a+en6ZJ2llj8TTiEkAeLh852sm2Dphaztk7/AdWfDnvLlgD++1xNcp+U/p3a2llfeYJxgpJzjEM2mVzzIGstOZnnxPZzyHgF26xS4FCPHKBrp7PA732L3lpZqtO4= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160224719375258.15580546063052; Fri, 9 Oct 2020 05:39:53 -0700 (PDT) Received: from localhost ([::1]:34112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrge-0004ZT-EG for importer@patchew.org; Fri, 09 Oct 2020 08:39:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMu-0000Dp-PV for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45709) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMs-0007zV-PY for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-549-xOtzICMpPfeobKMH4iPIEw-1; Fri, 09 Oct 2020 08:19:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0140108E1A0 for ; Fri, 9 Oct 2020 12:19:23 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 904F45C1BB; Fri, 9 Oct 2020 12:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2zkz2SEKDwDKngOS2g2FJBlJQ/tGTWTMzrwYb9qJdhk=; b=LR0AcQvp5cPzUyWfYNX7sSy1vle2u6WaRbVlW0cC2TgYQdDyyHdEXJfZkPqIBcmPqWIabG 1yL/lP6nfnl1PckqRwKzMzcDNzdXS/TlOr19eNrw8DdbUopYJENE2F/YTVKw0dHFC0j6p6 z8QWNOUbgNHAlCYbxtj4RRaVfycm43U= X-MC-Unique: xOtzICMpPfeobKMH4iPIEw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 18/23] i386: switch hyperv_expand_features() to using error_setg() Date: Fri, 9 Oct 2020 14:18:37 +0200 Message-Id: <20201009121842.1938010-19-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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_H4=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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" Use standard error_setg() mechanism in hyperv_expand_features(). Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 101 ++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 06f78a09304e..1c1fa04b7c02 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1134,7 +1134,7 @@ static bool hyperv_feature_supported(CPUState *cs, in= t feature) return true; } =20 -static int hv_cpuid_check_and_set(CPUState *cs, int feature) +static int hv_cpuid_check_and_set(CPUState *cs, int feature, Error **errp) { X86CPU *cpu =3D X86_CPU(cs); uint64_t deps; @@ -1148,20 +1148,18 @@ static int hv_cpuid_check_and_set(CPUState *cs, int= feature) while (deps) { dep_feat =3D ctz64(deps); if (!(hyperv_feat_enabled(cpu, dep_feat))) { - fprintf(stderr, - "Hyper-V %s requires Hyper-V %s\n", - kvm_hyperv_properties[feature].desc, - kvm_hyperv_properties[dep_feat].desc); - return 1; + error_setg(errp, "Hyper-V %s requires Hyper-V %s", + kvm_hyperv_properties[feature].desc, + kvm_hyperv_properties[dep_feat].desc); + return 1; } deps &=3D ~(1ull << dep_feat); } =20 if (!hyperv_feature_supported(cs, feature)) { if (hyperv_feat_enabled(cpu, feature)) { - fprintf(stderr, - "Hyper-V %s is not supported by kernel\n", - kvm_hyperv_properties[feature].desc); + error_setg(errp, "Hyper-V %s is not supported by kernel", + kvm_hyperv_properties[feature].desc); return 1; } else { return 0; @@ -1208,13 +1206,12 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, u= int32_t func, int reg) * of 'hv_passthrough' mode and fills the environment with all supported * Hyper-V features. */ -static int hyperv_expand_features(CPUState *cs) +static void hyperv_expand_features(CPUState *cs, Error **errp) { X86CPU *cpu =3D X86_CPU(cs); - int r; =20 if (!hyperv_enabled(cpu)) - return 0; + return; =20 if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D @@ -1260,37 +1257,60 @@ static int hyperv_expand_features(CPUState *cs) } =20 /* Features */ - r =3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT); + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT, errp)) { + return; + } =20 /* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) && !cpu->hyperv_synic_kvm_only && !hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX)) { - fprintf(stderr, "Hyper-V %s requires Hyper-V %s\n", - kvm_hyperv_properties[HYPERV_FEAT_SYNIC].desc, - kvm_hyperv_properties[HYPERV_FEAT_VPINDEX].desc); - r |=3D 1; - } - - if (r) { - return -ENOSYS; + error_setg(errp, "Hyper-V %s requires Hyper-V %s", + kvm_hyperv_properties[HYPERV_FEAT_SYNIC].desc, + kvm_hyperv_properties[HYPERV_FEAT_VPINDEX].desc); } - - return 0; } =20 /* @@ -1525,9 +1545,10 @@ int kvm_arch_init_vcpu(CPUState *cs) env->apic_bus_freq =3D KVM_APIC_BUS_FREQUENCY; =20 /* Paravirtualization CPUIDs */ - r =3D hyperv_expand_features(cs); - if (r < 0) { - return r; + hyperv_expand_features(cs, &local_err); + if (local_err) { + error_report_err(local_err); + return -ENOSYS; } =20 if (hyperv_enabled(cpu)) { --=20 2.25.4