From nobody Sun May 19 10:14:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=1591882904; cv=none; d=zohomail.com; s=zohoarc; b=iNVcH9KXPr9hs6vkX2UIbuBuz5PkhZKtR94s/RIoOktb4Bg1pKImJsy1beF06B7MZ2qN/RZsf3WaFDdrPvHBH45b8VTbfxToIYTIl50u9O4+8+ad3kpXTB3JmvQh4C+OonzYAVfEon2MWJ10hBxp/VhAfMKBsI4BDgwZ59KikJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591882904; 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=UKG1gbU2iNMLl9RWoI0+wrWwalfs7xcl9epiYQyUK+w=; b=OCaFuGimsNiuB0eFApl2+vrZnF+yArXNz/h9ttw2x1mnOHeYzc1rqiVha2oeXxHJOp7C6iyK8g7K4dEBZN/Gg1PxNdY4RE+LsBEglOER+HfxosqpJ8uT7bUVWYoOvO3Gqgfu7nTL5qWkpm1cxI8/bTz0NKq4RsF0B6PyauurYTI= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1591882904229372.24193945458364; Thu, 11 Jun 2020 06:41:44 -0700 (PDT) Received: from localhost ([::1]:59258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjNSg-0006Hb-VC for importer@patchew.org; Thu, 11 Jun 2020 09:41:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjNRP-0004Vz-Qv for qemu-devel@nongnu.org; Thu, 11 Jun 2020 09:40:23 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:39375 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jjNRO-0005sV-UV for qemu-devel@nongnu.org; Thu, 11 Jun 2020 09:40:23 -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-225-FnKNYJrHPC6zL4zbAWh8AQ-1; Thu, 11 Jun 2020 09:40:14 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B689805730; Thu, 11 Jun 2020 13:40:13 +0000 (UTC) Received: from bahia.lan (ovpn-114-202.ams2.redhat.com [10.36.114.202]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEAAA19931; Thu, 11 Jun 2020 13:40:11 +0000 (UTC) X-MC-Unique: FnKNYJrHPC6zL4zbAWh8AQ-1 Subject: [PATCH v3 1/4] spapr: Simplify some warning printing paths in spapr_caps.c From: Greg Kurz To: David Gibson Date: Thu, 11 Jun 2020 15:40:11 +0200 Message-ID: <159188281098.70166.18387926536399257573.stgit@bahia.lan> In-Reply-To: <159188280345.70166.14940592691021389043.stgit@bahia.lan> References: <159188280345.70166.14940592691021389043.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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: softfail client-ip=207.211.31.120; envelope-from=groug@kaod.org; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 08:37:10 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 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: Laurent Vivier , Vladimir Sementsov-Ogievskiy , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We obviously only want to print a warning in these cases, but this is done in a rather convoluted manner. Just use warn_report() instead. Signed-off-by: Greg Kurz Reviewed-by: Laurent Vivier Reviewed-by: Vladimir Sementsov-Ogievskiy --- hw/ppc/spapr_caps.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index efdc0dbbcfc0..0c2bc8e06e44 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -248,23 +248,18 @@ SpaprCapPossible cap_cfpc_possible =3D { static void cap_safe_cache_apply(SpaprMachineState *spapr, uint8_t val, Error **errp) { - Error *local_err =3D NULL; uint8_t kvm_val =3D kvmppc_get_cap_safe_cache(); =20 if (tcg_enabled() && val) { /* TCG only supports broken, allow other values and print a warnin= g */ - error_setg(&local_err, - "TCG doesn't support requested feature, cap-cfpc=3D%s", - cap_cfpc_possible.vals[val]); + warn_report("TCG doesn't support requested feature, cap-cfpc=3D%s", + cap_cfpc_possible.vals[val]); } else if (kvm_enabled() && (val > kvm_val)) { error_setg(errp, "Requested safe cache capability level not supported by= kvm," " try appending -machine cap-cfpc=3D%s", cap_cfpc_possible.vals[kvm_val]); } - - if (local_err !=3D NULL) - warn_report_err(local_err); } =20 SpaprCapPossible cap_sbbc_possible =3D { @@ -277,23 +272,18 @@ SpaprCapPossible cap_sbbc_possible =3D { static void cap_safe_bounds_check_apply(SpaprMachineState *spapr, uint8_t = val, Error **errp) { - Error *local_err =3D NULL; uint8_t kvm_val =3D kvmppc_get_cap_safe_bounds_check(); =20 if (tcg_enabled() && val) { /* TCG only supports broken, allow other values and print a warnin= g */ - error_setg(&local_err, - "TCG doesn't support requested feature, cap-sbbc=3D%s", - cap_sbbc_possible.vals[val]); + warn_report("TCG doesn't support requested feature, cap-sbbc=3D%s", + cap_sbbc_possible.vals[val]); } else if (kvm_enabled() && (val > kvm_val)) { error_setg(errp, "Requested safe bounds check capability level not supported by kvm," " try appending -machine cap-sbbc=3D%s", cap_sbbc_possible.vals[kvm_val]); } - - if (local_err !=3D NULL) - warn_report_err(local_err); } =20 SpaprCapPossible cap_ibs_possible =3D { @@ -309,24 +299,18 @@ SpaprCapPossible cap_ibs_possible =3D { static void cap_safe_indirect_branch_apply(SpaprMachineState *spapr, uint8_t val, Error **errp) { - Error *local_err =3D NULL; uint8_t kvm_val =3D kvmppc_get_cap_safe_indirect_branch(); =20 if (tcg_enabled() && val) { /* TCG only supports broken, allow other values and print a warnin= g */ - error_setg(&local_err, - "TCG doesn't support requested feature, cap-ibs=3D%s", - cap_ibs_possible.vals[val]); + warn_report("TCG doesn't support requested feature, cap-ibs=3D%s", + cap_ibs_possible.vals[val]); } else if (kvm_enabled() && (val > kvm_val)) { error_setg(errp, "Requested safe indirect branch capability level not supported by kvm," " try appending -machine cap-ibs=3D%s", cap_ibs_possible.vals[kvm_val]); } - - if (local_err !=3D NULL) { - warn_report_err(local_err); - } } =20 #define VALUE_DESC_TRISTATE " (broken, workaround, fixed)" From nobody Sun May 19 10:14:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=1591882978; cv=none; d=zohomail.com; s=zohoarc; b=PMToyMe7zedbKEnHLKY/XSJReT9gIP3QbHYQoRQMZQa29esPC196nde2GT6i5rN0ou5mc4CZpycsDcy7tQkM66VzItwrZdJd3HGCg8XUCoifpW7y+g7eKdBKOcJnDt7KkNzyAKe81axjyDpfGY9hr/NW6tClrPsu+QUC72cBNeo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591882978; 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=eoFQarK+8aR4AlWDjN1p1ScpWvQc+zhpUB+vVvJD/B8=; b=jI0dFM7clN47oKdFwlSxCEknr3K1+AeeG7zgUm3+cxxId1KTMD7/hOya3ANhMa/Gdzt0/j8b6duP9ZIWPdT3Aw/hAJ/4huyGrZdcqaLkua6+Kjf26b59+30LA4BuZxxuzArhSwHH/poXVJipXcktWyThiQ9EMhbouI0sQlgCk54= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1591882978286617.0355427350189; Thu, 11 Jun 2020 06:42:58 -0700 (PDT) Received: from localhost ([::1]:35932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjNTs-0008Fj-Uy for importer@patchew.org; Thu, 11 Jun 2020 09:42:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjNRU-0004fC-V2 for qemu-devel@nongnu.org; Thu, 11 Jun 2020 09:40:29 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:25977 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jjNRT-0005ul-5T for qemu-devel@nongnu.org; Thu, 11 Jun 2020 09:40: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-331-v6diorN9MTKptvK-riFzzA-1; Thu, 11 Jun 2020 09:40:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 345C5107ACCD; Thu, 11 Jun 2020 13:40:21 +0000 (UTC) Received: from bahia.lan (ovpn-114-202.ams2.redhat.com [10.36.114.202]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D8BB60BF3; Thu, 11 Jun 2020 13:40:19 +0000 (UTC) X-MC-Unique: v6diorN9MTKptvK-riFzzA-1 Subject: [PATCH v3 2/4] error: auto propagated local_err From: Greg Kurz To: David Gibson Date: Thu, 11 Jun 2020 15:40:18 +0200 Message-ID: <159188281846.70166.15436662596881222119.stgit@bahia.lan> In-Reply-To: <159188280345.70166.14940592691021389043.stgit@bahia.lan> References: <159188280345.70166.14940592691021389043.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Type: text/plain; charset="utf-8" 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: softfail client-ip=207.211.31.81; envelope-from=groug@kaod.org; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 03:29:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 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: Laurent Vivier , Vladimir Sementsov-Ogievskiy , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Vladimir Sementsov-Ogievskiy Introduce a new ERRP_AUTO_PROPAGATE macro, to be used at start of functions with an errp OUT parameter. It has three goals: 1. Fix issue with error_fatal and error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz] 2. Fix issue with error_abort and error_propagate: when we wrap error_abort by local_err+error_propagate, the resulting coredump will refer to error_propagate and not to the place where error happened. (the macro itself doesn't fix the issue, but it allows us to [3.] drop the local_err+error_propagate pattern, which will definitely fix the issue) [Reported by Kevin Wolf] 3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code). To achieve these goals, later patches will add invocations of this macro at the start of functions with either use error_prepend/error_append_hint (solving 1) or which use local_err+error_propagate to check errors, switching those functions to use *errp instead (solving 2 and 3). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Paul Durrant Reviewed-by: Greg Kurz Reviewed-by: Eric Blake Signed-off-by: Greg Kurz Reviewed-by: Laurent Vivier --- include/qapi/error.h | 205 ++++++++++++++++++++++++++++++++++++++++++----= ---- 1 file changed, 173 insertions(+), 32 deletions(-) diff --git a/include/qapi/error.h b/include/qapi/error.h index ad5b6e896ded..30140d9bfea9 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -15,6 +15,8 @@ /* * Error reporting system loosely patterned after Glib's GError. * + * =3D Deal with Error object =3D + * * Create an error: * error_setg(&err, "situation normal, all fouled up"); * @@ -47,28 +49,91 @@ * reporting it (primarily useful in testsuites): * error_free_or_abort(&err); * - * Pass an existing error to the caller: - * error_propagate(errp, err); - * where Error **errp is a parameter, by convention the last one. + * =3D Deal with Error ** function parameter =3D * - * Pass an existing error to the caller with the message modified: - * error_propagate_prepend(errp, err); + * A function may use the error system to return errors. In this case, the + * function defines an Error **errp parameter, by convention the last one = (with + * exceptions for functions using ... or va_list). * - * Avoid - * error_propagate(errp, err); - * error_prepend(errp, "Could not frobnicate '%s': ", name); - * because this fails to prepend when @errp is &error_fatal. + * The caller may then pass in the following errp values: * - * Create a new error and pass it to the caller: + * 1. &error_abort + * Any error will result in abort(). + * 2. &error_fatal + * Any error will result in exit() with a non-zero status. + * 3. NULL + * No error reporting through errp parameter. + * 4. The address of a NULL-initialized Error *err + * Any error will populate errp with an error object. + * + * The following rules then implement the correct semantics desired by the + * caller. + * + * Create a new error to pass to the caller: * error_setg(errp, "situation normal, all fouled up"); * - * Call a function and receive an error from it: + * Calling another errp-based function: + * f(..., errp); + * + * =3D=3D Checking success of subcall =3D=3D + * + * If a function returns a value indicating an error in addition to setting + * errp (which is recommended), then you don't need any additional code, j= ust + * do: + * + * int ret =3D f(..., errp); + * if (ret < 0) { + * ... handle error ... + * return ret; + * } + * + * If a function returns nothing (not recommended for new code), the only = way + * to check success is by consulting errp; doing this safely requires the = use + * of the ERRP_AUTO_PROPAGATE macro, like this: + * + * int our_func(..., Error **errp) { + * ERRP_AUTO_PROPAGATE(); + * ... + * subcall(..., errp); + * if (*errp) { + * ... + * return -EINVAL; + * } + * ... + * } + * + * ERRP_AUTO_PROPAGATE takes care of wrapping the original errp as needed,= so + * that the rest of the function can directly use errp (including + * dereferencing), where any errors will then be propagated on to the orig= inal + * errp when leaving the function. + * + * In some cases, we need to check result of subcall, but do not want to + * propagate the Error object to our caller. In such cases we don't need + * ERRP_AUTO_PROPAGATE, but just a local Error object: + * + * Receive an error and not pass it: * Error *err =3D NULL; - * foo(arg, &err); + * subcall(arg, &err); * if (err) { * handle the error... + * error_free(err); * } * + * Note that older code that did not use ERRP_AUTO_PROPAGATE would instead= need + * a local Error * variable and the use of error_propagate() to properly h= andle + * all possible caller values of errp. Now this is DEPRECATED* (see below). + * + * Note that any function that wants to modify an error object, such as by + * calling error_append_hint or error_prepend, must use ERRP_AUTO_PROPAGAT= E, in + * order for a caller's use of &error_fatal to see the additional informat= ion. + * + * In rare cases, we need to pass existing Error object to the caller by h= and: + * error_propagate(errp, err); + * + * Pass an existing error to the caller with the message modified: + * error_propagate_prepend(errp, err); + * + * * Call a function ignoring errors: * foo(arg, NULL); * @@ -78,26 +143,6 @@ * Call a function treating errors as fatal: * foo(arg, &error_fatal); * - * Receive an error and pass it on to the caller: - * Error *err =3D NULL; - * foo(arg, &err); - * if (err) { - * handle the error... - * error_propagate(errp, err); - * } - * where Error **errp is a parameter, by convention the last one. - * - * Do *not* "optimize" this to - * foo(arg, errp); - * if (*errp) { // WRONG! - * handle the error... - * } - * because errp may be NULL! - * - * But when all you do with the error is pass it on, please use - * foo(arg, errp); - * for readability. - * * Receive and accumulate multiple errors (first one wins): * Error *err =3D NULL, *local_err =3D NULL; * foo(arg, &err); @@ -114,6 +159,61 @@ * handle the error... * } * because this may pass a non-null err to bar(). + * + * DEPRECATED* + * + * The following pattern of receiving, checking, and then forwarding an er= ror + * to the caller by hand is now deprecated: + * + * Error *err =3D NULL; + * foo(arg, &err); + * if (err) { + * handle the error... + * error_propagate(errp, err); + * } + * + * Instead, use ERRP_AUTO_PROPAGATE macro. + * + * The old pattern is deprecated because of two things: + * + * 1. Issue with error_abort and error_propagate: when we wrap error_abort= by + * local_err+error_propagate, the resulting coredump will refer to + * error_propagate and not to the place where error happened. + * + * 2. A lot of extra code of the same pattern + * + * How to update old code to use ERRP_AUTO_PROPAGATE? + * + * All you need is to add ERRP_AUTO_PROPAGATE() invocation at function sta= rt, + * than you may safely dereference errp to check errors and do not need any + * additional local Error variables or calls to error_propagate(). + * + * Example: + * + * old code + * + * void fn(..., Error **errp) { + * Error *err =3D NULL; + * foo(arg, &err); + * if (err) { + * handle the error... + * error_propagate(errp, err); + * return; + * } + * ... + * } + * + * updated code + * + * void fn(..., Error **errp) { + * ERRP_AUTO_PROPAGATE(); + * foo(arg, errp); + * if (*errp) { + * handle the error... + * return; + * } + * ... + * } */ =20 #ifndef ERROR_H @@ -322,6 +422,47 @@ void error_set_internal(Error **errp, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(6, 7); =20 +typedef struct ErrorPropagator { + Error *local_err; + Error **errp; +} ErrorPropagator; + +static inline void error_propagator_cleanup(ErrorPropagator *prop) +{ + error_propagate(prop->errp, prop->local_err); +} + +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup= ); + +/* + * ERRP_AUTO_PROPAGATE + * + * This macro exists to assist with proper error handling in a function wh= ich + * uses an Error **errp parameter. It must be used as the first line of a + * function which modifies an error (with error_prepend, error_append_hint= , or + * similar) or which wants to dereference *errp. It is still safe (but + * useless) to use in other functions. + * + * If errp is NULL or points to error_fatal, it is rewritten to point to a + * local Error object, which will be automatically propagated to the origi= nal + * errp on function exit (see error_propagator_cleanup). + * + * After invocation of this macro it is always safe to dereference errp + * (as it's not NULL anymore) and to add information by error_prepend or + * error_append_hint (as, if it was error_fatal, we swapped it with a + * local_error to be propagated on cleanup). + * + * Note: we don't wrap the error_abort case, as we want resulting coredump + * to point to the place where the error happened, not to error_propagate. + */ +#define ERRP_AUTO_PROPAGATE() \ + g_auto(ErrorPropagator) _auto_errp_prop =3D {.errp =3D errp}; \ + do { \ + if (!errp || errp =3D=3D &error_fatal) { \ + errp =3D &_auto_errp_prop.local_err; \ + } \ + } while (0) + /* * Special error destination to abort on error. * See error_setg() and error_propagate() for details. From nobody Sun May 19 10:14:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=1591882913; cv=none; d=zohomail.com; s=zohoarc; b=CeGPxhrYpxD01qF3UPVBbkPB/K3/vxTm8eZNkWltPj/EcWISylEXunE8hDAoqrkKz8kHFOeHEWZ03m6+ttitE3b36rO2TosGoWI2cgIoLPp0uQ+mZuAm5EqEGHwYFBv+X4R1GLHJFUE9mP7iQ6HHsQbSjJUCxpthsfcL+wEVlCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591882913; 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=+xsfZZrELXZZwQ4NU3T9MA+h9LVGyBO9YSZXUFmM4lk=; b=U968w3ACMMNMnAzPw4Dx78wZRS2RRygz0L32r0CNsjd6fGmB95BF3pO01oeoQo2ZAkyD69Tw69oN5MR2G0meu3xXs/eBX7ss5z2BQ521e29f+jmc3CwAStq0AQ5R3elCR6U2tq9fiNbPYoXpOj+IWfNxh3p9SPy4yyj+CyLy3eM= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1591882913095445.6346884286371; Thu, 11 Jun 2020 06:41:53 -0700 (PDT) Received: from localhost ([::1]:59826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjNSp-0006Vk-IE for importer@patchew.org; Thu, 11 Jun 2020 09:41:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjNRZ-0004lf-Hh for qemu-devel@nongnu.org; Thu, 11 Jun 2020 09:40:33 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:55224 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jjNRY-0005yx-AJ for qemu-devel@nongnu.org; Thu, 11 Jun 2020 09:40:33 -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-483-JZXuzSynOcyNxy12RrlcUA-1; Thu, 11 Jun 2020 09:40:29 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A88C81005513; Thu, 11 Jun 2020 13:40:28 +0000 (UTC) Received: from bahia.lan (ovpn-114-202.ams2.redhat.com [10.36.114.202]) by smtp.corp.redhat.com (Postfix) with ESMTP id 570A710013C2; Thu, 11 Jun 2020 13:40:27 +0000 (UTC) X-MC-Unique: JZXuzSynOcyNxy12RrlcUA-1 Subject: [PATCH v3 3/4] spapr: Use error_append_hint() in spapr_caps.c From: Greg Kurz To: David Gibson Date: Thu, 11 Jun 2020 15:40:26 +0200 Message-ID: <159188282644.70166.8098075112034429343.stgit@bahia.lan> In-Reply-To: <159188280345.70166.14940592691021389043.stgit@bahia.lan> References: <159188280345.70166.14940592691021389043.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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: softfail client-ip=207.211.31.81; envelope-from=groug@kaod.org; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 03:29:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 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: Laurent Vivier , Vladimir Sementsov-Ogievskiy , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We have a dedicated error API for hints. Use it instead of embedding the hint in the error message, as recommanded in the "qapi/error.h" header file. Since spapr_caps_apply() passes &error_fatal, all functions must also call the ERRP_AUTO_PROPAGATE() macro for error_append_hint() to be functional. While here, have cap_fwnmi_apply(), which already uses error_append_hint(), to call ERRP_AUTO_PROPAGATE() as well. Signed-off-by: Greg Kurz Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Laurent Vivier --- hw/ppc/spapr_caps.c | 89 +++++++++++++++++++++++++++++------------------= ---- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 0c2bc8e06e44..27cf2b38af27 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -189,24 +189,24 @@ static void spapr_cap_set_pagesize(Object *obj, Visit= or *v, const char *name, =20 static void cap_htm_apply(SpaprMachineState *spapr, uint8_t val, Error **e= rrp) { + ERRP_AUTO_PROPAGATE(); if (!val) { /* TODO: We don't support disabling htm yet */ return; } if (tcg_enabled()) { - error_setg(errp, - "No Transactional Memory support in TCG," - " try appending -machine cap-htm=3Doff"); + error_setg(errp, "No Transactional Memory support in TCG"); + error_append_hint(errp, "Try appending -machine cap-htm=3Doff\n"); } else if (kvm_enabled() && !kvmppc_has_cap_htm()) { error_setg(errp, -"KVM implementation does not support Transactional Memory," - " try appending -machine cap-htm=3Doff" - ); + "KVM implementation does not support Transactional Memo= ry"); + error_append_hint(errp, "Try appending -machine cap-htm=3Doff\n"); } } =20 static void cap_vsx_apply(SpaprMachineState *spapr, uint8_t val, Error **e= rrp) { + ERRP_AUTO_PROPAGATE(); PowerPCCPU *cpu =3D POWERPC_CPU(first_cpu); CPUPPCState *env =3D &cpu->env; =20 @@ -218,13 +218,14 @@ static void cap_vsx_apply(SpaprMachineState *spapr, u= int8_t val, Error **errp) * rid of anything that doesn't do VMX */ g_assert(env->insns_flags & PPC_ALTIVEC); if (!(env->insns_flags2 & PPC2_VSX)) { - error_setg(errp, "VSX support not available," - " try appending -machine cap-vsx=3Doff"); + error_setg(errp, "VSX support not available"); + error_append_hint(errp, "Try appending -machine cap-vsx=3Doff\n"); } } =20 static void cap_dfp_apply(SpaprMachineState *spapr, uint8_t val, Error **e= rrp) { + ERRP_AUTO_PROPAGATE(); PowerPCCPU *cpu =3D POWERPC_CPU(first_cpu); CPUPPCState *env =3D &cpu->env; =20 @@ -233,8 +234,8 @@ static void cap_dfp_apply(SpaprMachineState *spapr, uin= t8_t val, Error **errp) return; } if (!(env->insns_flags2 & PPC2_DFP)) { - error_setg(errp, "DFP support not available," - " try appending -machine cap-dfp=3Doff"); + error_setg(errp, "DFP support not available"); + error_append_hint(errp, "Try appending -machine cap-dfp=3Doff\n"); } } =20 @@ -248,6 +249,7 @@ SpaprCapPossible cap_cfpc_possible =3D { static void cap_safe_cache_apply(SpaprMachineState *spapr, uint8_t val, Error **errp) { + ERRP_AUTO_PROPAGATE(); uint8_t kvm_val =3D kvmppc_get_cap_safe_cache(); =20 if (tcg_enabled() && val) { @@ -256,9 +258,9 @@ static void cap_safe_cache_apply(SpaprMachineState *spa= pr, uint8_t val, cap_cfpc_possible.vals[val]); } else if (kvm_enabled() && (val > kvm_val)) { error_setg(errp, - "Requested safe cache capability level not supported by= kvm," - " try appending -machine cap-cfpc=3D%s", - cap_cfpc_possible.vals[kvm_val]); + "Requested safe cache capability level not supported by= KVM"); + error_append_hint(errp, "Try appending -machine cap-cfpc=3D%s\n", + cap_cfpc_possible.vals[kvm_val]); } } =20 @@ -272,6 +274,7 @@ SpaprCapPossible cap_sbbc_possible =3D { static void cap_safe_bounds_check_apply(SpaprMachineState *spapr, uint8_t = val, Error **errp) { + ERRP_AUTO_PROPAGATE(); uint8_t kvm_val =3D kvmppc_get_cap_safe_bounds_check(); =20 if (tcg_enabled() && val) { @@ -280,9 +283,9 @@ static void cap_safe_bounds_check_apply(SpaprMachineSta= te *spapr, uint8_t val, cap_sbbc_possible.vals[val]); } else if (kvm_enabled() && (val > kvm_val)) { error_setg(errp, -"Requested safe bounds check capability level not supported by kvm," - " try appending -machine cap-sbbc=3D%s", - cap_sbbc_possible.vals[kvm_val]); +"Requested safe bounds check capability level not supported by KVM"); + error_append_hint(errp, "Try appending -machine cap-sbbc=3D%s\n", + cap_sbbc_possible.vals[kvm_val]); } } =20 @@ -299,6 +302,7 @@ SpaprCapPossible cap_ibs_possible =3D { static void cap_safe_indirect_branch_apply(SpaprMachineState *spapr, uint8_t val, Error **errp) { + ERRP_AUTO_PROPAGATE(); uint8_t kvm_val =3D kvmppc_get_cap_safe_indirect_branch(); =20 if (tcg_enabled() && val) { @@ -307,9 +311,9 @@ static void cap_safe_indirect_branch_apply(SpaprMachine= State *spapr, cap_ibs_possible.vals[val]); } else if (kvm_enabled() && (val > kvm_val)) { error_setg(errp, -"Requested safe indirect branch capability level not supported by kvm," - " try appending -machine cap-ibs=3D%s", - cap_ibs_possible.vals[kvm_val]); +"Requested safe indirect branch capability level not supported by KVM"); + error_append_hint(errp, "Try appending -machine cap-ibs=3D%s\n", + cap_ibs_possible.vals[kvm_val]); } } =20 @@ -386,23 +390,25 @@ static void cap_hpt_maxpagesize_cpu_apply(SpaprMachin= eState *spapr, static void cap_nested_kvm_hv_apply(SpaprMachineState *spapr, uint8_t val, Error **errp) { + ERRP_AUTO_PROPAGATE(); if (!val) { /* capability disabled by default */ return; } =20 if (tcg_enabled()) { - error_setg(errp, - "No Nested KVM-HV support in tcg," - " try appending -machine cap-nested-hv=3Doff"); + error_setg(errp, "No Nested KVM-HV support in TCG"); + error_append_hint(errp, "Try appending -machine cap-nested-hv=3Dof= f\n"); } else if (kvm_enabled()) { if (!kvmppc_has_cap_nested_kvm_hv()) { error_setg(errp, -"KVM implementation does not support Nested KVM-HV," - " try appending -machine cap-nested-hv=3Doff"); + "KVM implementation does not support Nested KVM-HV"= ); + error_append_hint(errp, + "Try appending -machine cap-nested-hv=3Doff\= n"); } else if (kvmppc_set_cap_nested_kvm_hv(val) < 0) { - error_setg(errp, -"Error enabling cap-nested-hv with KVM, try cap-nested-hv=3Doff"); + error_setg(errp, "Error enabling cap-nested-hv with KVM"); + error_append_hint(errp, + "Try appending -machine cap-nested-hv=3D= off\n"); } } } @@ -410,6 +416,7 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState *= spapr, static void cap_large_decr_apply(SpaprMachineState *spapr, uint8_t val, Error **errp) { + ERRP_AUTO_PROPAGATE(); PowerPCCPU *cpu =3D POWERPC_CPU(first_cpu); PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); =20 @@ -420,22 +427,23 @@ static void cap_large_decr_apply(SpaprMachineState *s= papr, if (tcg_enabled()) { if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_00, 0, spapr->max_compat_pvr)) { - error_setg(errp, - "Large decrementer only supported on POWER9, try -cpu POWE= R9"); + error_setg(errp, "Large decrementer only supported on POWER9"); + error_append_hint(errp, "Try -cpu POWER9\n"); return; } } else if (kvm_enabled()) { int kvm_nr_bits =3D kvmppc_get_cap_large_decr(); =20 if (!kvm_nr_bits) { - error_setg(errp, - "No large decrementer support," - " try appending -machine cap-large-decr=3Doff"); + error_setg(errp, "No large decrementer support"); + error_append_hint(errp, + "Try appending -machine cap-large-decr=3Doff= \n"); } else if (pcc->lrg_decr_bits !=3D kvm_nr_bits) { error_setg(errp, -"KVM large decrementer size (%d) differs to model (%d)," - " try appending -machine cap-large-decr=3Doff", - kvm_nr_bits, pcc->lrg_decr_bits); + "KVM large decrementer size (%d) differs to model (= %d)", + kvm_nr_bits, pcc->lrg_decr_bits); + error_append_hint(errp, + "Try appending -machine cap-large-decr=3Doff= \n"); } } } @@ -444,14 +452,15 @@ static void cap_large_decr_cpu_apply(SpaprMachineStat= e *spapr, PowerPCCPU *cpu, uint8_t val, Error **errp) { + ERRP_AUTO_PROPAGATE(); CPUPPCState *env =3D &cpu->env; target_ulong lpcr =3D env->spr[SPR_LPCR]; =20 if (kvm_enabled()) { if (kvmppc_enable_cap_large_decr(cpu, val)) { - error_setg(errp, - "No large decrementer support," - " try appending -machine cap-large-decr=3Doff"); + error_setg(errp, "No large decrementer support"); + error_append_hint(errp, + "Try appending -machine cap-large-decr=3Doff= \n"); } } =20 @@ -466,6 +475,7 @@ static void cap_large_decr_cpu_apply(SpaprMachineState = *spapr, static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val, Error **errp) { + ERRP_AUTO_PROPAGATE(); uint8_t kvm_val =3D kvmppc_get_cap_count_cache_flush_assist(); =20 if (tcg_enabled() && val) { @@ -488,14 +498,15 @@ static void cap_ccf_assist_apply(SpaprMachineState *s= papr, uint8_t val, return; } error_setg(errp, -"Requested count cache flush assist capability level not supported by kvm," - " try appending -machine cap-ccf-assist=3Doff"); + "Requested count cache flush assist capability level no= t supported by KVM"); + error_append_hint(errp, "Try appending -machine cap-ccf-assist=3Do= ff\n"); } } =20 static void cap_fwnmi_apply(SpaprMachineState *spapr, uint8_t val, Error **errp) { + ERRP_AUTO_PROPAGATE(); if (!val) { return; /* Disabled by default */ } From nobody Sun May 19 10:14:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=1591883065; cv=none; d=zohomail.com; s=zohoarc; b=KqOb/LhMfPSHS937bh4rma6lvNqdT7OsQG05XMmguSgOwioqYkV7EIRkN8KzmSgGZHfWc4TQkELkyAz2hm441jqBPALfgUqP/KQnKte4qNc19tS6Djw4rzhZnGfANjjCzZ4ji7kfK33k+JLEH87oxlSMejgNPixh1vPxUjZLCzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591883065; 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=vbGiDNQ2B759BL+2eA0Cw1mecNF9B53X8HJmsEMEbYM=; b=lj1/lw1D5dprgzghLo85yp69v7fzaIBcf1y9Rd8JcOLoNqfRMRNUOIfOpMoySlotxMIALMdxiFIYrEViVp15e/WHF9+S0wSaG3vst2dd96bEQpS95HPmSM/wA7oCaMfbnu0hMfKsYqS/laWxighNT+t4zzQUHlkySKsbgUCGxdA= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1591883065010899.799355027374; Thu, 11 Jun 2020 06:44:25 -0700 (PDT) Received: from localhost ([::1]:38868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjNVH-0001Ns-Q3 for importer@patchew.org; Thu, 11 Jun 2020 09:44:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjNRi-0004yc-Qj for qemu-devel@nongnu.org; Thu, 11 Jun 2020 09:40:42 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:59483 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jjNRh-00060e-L3 for qemu-devel@nongnu.org; Thu, 11 Jun 2020 09:40:42 -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-381-5sshILfPNXGGpo34YEVvhw-1; Thu, 11 Jun 2020 09:40:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EE53F106B243; Thu, 11 Jun 2020 13:40:35 +0000 (UTC) Received: from bahia.lan (ovpn-114-202.ams2.redhat.com [10.36.114.202]) by smtp.corp.redhat.com (Postfix) with ESMTP id C67CB512FE; Thu, 11 Jun 2020 13:40:34 +0000 (UTC) X-MC-Unique: 5sshILfPNXGGpo34YEVvhw-1 Subject: [PATCH v3 4/4] spapr: Forbid nested KVM-HV in pre-power9 compat mode From: Greg Kurz To: David Gibson Date: Thu, 11 Jun 2020 15:40:33 +0200 Message-ID: <159188283391.70166.16995399489383620172.stgit@bahia.lan> In-Reply-To: <159188280345.70166.14940592691021389043.stgit@bahia.lan> References: <159188280345.70166.14940592691021389043.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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: softfail client-ip=207.211.31.81; envelope-from=groug@kaod.org; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 03:29:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 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: Laurent Vivier , Vladimir Sementsov-Ogievskiy , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Nested KVM-HV only works on POWER9. Signed-off-by: Greg Kurz Reviewed-by: Laurent Vivier --- hw/ppc/spapr_caps.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 27cf2b38af27..dfe3b419daaa 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -391,6 +391,8 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState *= spapr, uint8_t val, Error **errp) { ERRP_AUTO_PROPAGATE(); + PowerPCCPU *cpu =3D POWERPC_CPU(first_cpu); + if (!val) { /* capability disabled by default */ return; @@ -400,6 +402,14 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState = *spapr, error_setg(errp, "No Nested KVM-HV support in TCG"); error_append_hint(errp, "Try appending -machine cap-nested-hv=3Dof= f\n"); } else if (kvm_enabled()) { + if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_00, 0, + spapr->max_compat_pvr)) { + error_setg(errp, "Nested KVM-HV only supported on POWER9"); + error_append_hint(errp, + "Try appending -machine max-cpu-compat=3Dpow= er9\n"); + return; + } + if (!kvmppc_has_cap_nested_kvm_hv()) { error_setg(errp, "KVM implementation does not support Nested KVM-HV"= );