From patchwork Thu Sep 12 18:55:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11143681 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF22C76 for ; Thu, 12 Sep 2019 18:57:42 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB2AC2081B for ; Thu, 12 Sep 2019 18:57:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="TP2Nvf6J" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB2AC2081B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8UGB-00036A-Cv; Thu, 12 Sep 2019 18:56:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8UG9-00034p-Pm for xen-devel@lists.xenproject.org; Thu, 12 Sep 2019 18:56:01 +0000 X-Inumbo-ID: f6465aaa-d58e-11e9-b299-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f6465aaa-d58e-11e9-b299-bc764e2007e4; Thu, 12 Sep 2019 18:56:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568314561; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VXhTF/AM4h7nMLziZQXRr8jU37dX02II11U8ivOUCQc=; b=TP2Nvf6JwtPLAugr9eD6NW3S4HzOrGX8Og9+CM+F0UQI2uBGjVQmspdR 1yF1v1b+tzmPUX27XP1PoKEli2qOw2ovjqDlLF6jHasz9grMkEmkKuHGb cMyz5dEK4wFjmYvRyD09lN5E6CLhEbhN7eZuYJb8KRaJaFW/12pOW83lh I=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: k1T2AQqxd7aQxzYjlWN6jW3yz/XIkERzV0DdplUlur8RTZegbTjyE5qLBrBoFVdVizGHUUcIUF eekj3xQZUIbUcFtwS85G+mq/i+eaSbxzz0FDFzM6Wdk+rKFz+K1gRlHjO2SDIhZchmVcxeNPWF wiBV1LhCTmRVE4/1SRl2+r2hCquQEQKFhF8ITYTH+LvIu2ID5F+kQz3XA6YgJWI5zzsG2BQg8v 9+ksIQdWCZpVG03NFnLNREpLQ05l6mfll//JLng6+RLqHRQEx+Goa1ajbC7GYXNydVH7wM4Mm4 0Ok= X-SBRS: 2.7 X-MesageID: 5557408 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,498,1559534400"; d="scan'208";a="5557408" From: Andrew Cooper To: Xen-devel Date: Thu, 12 Sep 2019 19:55:56 +0100 Message-ID: <20190912185556.22173-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 0.5/8] libx86: Proactively initialise error pointers X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This results in better behaviour for the caller. Suggested-by: Jan Beulich Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné v2: * New --- tools/tests/cpu-policy/test-cpu-policy.c | 4 ++-- xen/include/xen/lib/x86/cpuid.h | 6 +++--- xen/include/xen/lib/x86/msr.h | 4 ++-- xen/lib/x86/cpuid.c | 5 +++++ xen/lib/x86/msr.c | 3 +++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c index fe00cd4276..201358d210 100644 --- a/tools/tests/cpu-policy/test-cpu-policy.c +++ b/tools/tests/cpu-policy/test-cpu-policy.c @@ -283,7 +283,7 @@ static void test_cpuid_deserialise_failure(void) for ( size_t i = 0; i < ARRAY_SIZE(tests); ++i ) { const struct test *t = &tests[i]; - uint32_t err_leaf = ~0u, err_subleaf = ~0u; + uint32_t err_leaf, err_subleaf; int rc; /* No writes should occur. Use NULL to catch errors. */ @@ -336,7 +336,7 @@ static void test_msr_deserialise_failure(void) for ( size_t i = 0; i < ARRAY_SIZE(tests); ++i ) { const struct test *t = &tests[i]; - uint32_t err_msr = ~0u; + uint32_t err_msr; int rc; /* No writes should occur. Use NULL to catch errors. */ diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpuid.h index df5946b6b1..79840f99ce 100644 --- a/xen/include/xen/lib/x86/cpuid.h +++ b/xen/include/xen/lib/x86/cpuid.h @@ -376,13 +376,13 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy *policy, * @param policy The cpuid_policy to unserialise into. * @param leaves The array of leaves to unserialise from. * @param nr_entries The number of entries in 'leaves'. - * @param err_leaf Optional hint filled on error. - * @param err_subleaf Optional hint filled on error. + * @param err_leaf Optional hint for error diagnostics. + * @param err_subleaf Optional hint for error diagnostics. * @returns -errno * * Reads at most CPUID_MAX_SERIALISED_LEAVES. May return -ERANGE if an * incoming leaf is out of range of cpuid_policy, in which case the optional - * err_* pointers are filled to aid diagnostics. + * err_* pointers will identify the out-of-range indicies. * * No content validation of in-range leaves is performed. Synthesised data is * recalculated. diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h index e83a8fbb0f..203c713320 100644 --- a/xen/include/xen/lib/x86/msr.h +++ b/xen/include/xen/lib/x86/msr.h @@ -54,14 +54,14 @@ int x86_msr_copy_to_buffer(const struct msr_policy *policy, * @param policy The msr_policy object to unserialise into. * @param msrs The array of msrs to unserialise from. * @param nr_entries The number of entries in 'msrs'. - * @param err_msr Optional hint filled on error. + * @param err_msr Optional hint for error diagnostics. * @returns -errno * * Reads at most MSR_MAX_SERIALISED_ENTRIES. May fail for a number of reasons * based on the content in an individual 'msrs' entry, including the MSR index * not being valid in the policy, the flags field being nonzero, or if the * value provided would truncate when stored in the policy. In such cases, - * the optional err_* pointer is filled in to aid diagnostics. + * the optional err_* pointer will identify the problematic MSR. * * No content validation is performed on the data stored in the policy object. */ diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c index 266084e613..76b8511034 100644 --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -381,6 +381,11 @@ int x86_cpuid_copy_from_buffer(struct cpuid_policy *p, unsigned int i; xen_cpuid_leaf_t data; + if ( err_leaf ) + *err_leaf = -1; + if ( err_subleaf ) + *err_subleaf = -1; + /* * A well formed caller is expected to pass an array with leaves in order, * and without any repetitions. However, due to per-vendor differences, diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c index 256b5ec632..171abf7008 100644 --- a/xen/lib/x86/msr.c +++ b/xen/lib/x86/msr.c @@ -55,6 +55,9 @@ int x86_msr_copy_from_buffer(struct msr_policy *p, xen_msr_entry_t data; int rc; + if ( err_msr ) + *err_msr = -1; + /* * A well formed caller is expected to pass an array with entries in * order, and without any repetitions. However, due to per-vendor