From patchwork Tue Feb 25 17:31:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11404329 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 9ED2014BC for ; Tue, 25 Feb 2020 17:32:45 +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 7A7702084E for ; Tue, 25 Feb 2020 17:32:45 +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="Cv2VxJbk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A7702084E Authentication-Results: mail.kernel.org; dmarc=fail (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 1j6e3X-0006wR-6W; Tue, 25 Feb 2020 17:31:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6e3W-0006wE-I8 for xen-devel@lists.xenproject.org; Tue, 25 Feb 2020 17:31:38 +0000 X-Inumbo-ID: acda6404-57f4-11ea-a490-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id acda6404-57f4-11ea-a490-bc764e2007e4; Tue, 25 Feb 2020 17:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1582651897; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=cNlO/PBRWz4sAvTFEtAoZ5fHdc7j8xdF8DKNOxjwkDc=; b=Cv2VxJbk+qwT9NfIbt+fLmi6vssfgmFyp8GagSp6T6e0M8lMiVCPjFTo FKNa1L+QIiSa9EQAaGUAOT5DDuutuAnP9KZ7TWMVSTyvHdjgdFH5nW7P7 WNNGO95aIcwOGcf9TGYdfhJXIWcg7qRfrZanDvJBGcoMhsKLGzpo7r5KY I=; Authentication-Results: esa4.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 (esa4.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=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.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=esa4.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 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.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=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 58j0mvkJ9QG9wy00ore+90V72X8y/PX4MzBCjuK2YolR52+jokV4hG2LYFc7yKQZT8+5Sf+GMC h2oqpWGRwPpmGkAZVOFLK7Q8x+nbcWGqI43n+cRucLx9fUxYzXGXhTxN1Bic/ApLGjamFHQpEJ bTOoOWuOWe3IKKy6XQfTbP14d8GhNA6E2QYcRaiJwxSd38sBCKWYNBfmUjAC7WY6Ug1z/7RAih z7VDBbGb8Wu9BzZzoKRVKdvYz/CcqOK1bo0g3viSaz0rb5sn9AYiuhGqkcEkfr8yv1YElyBEnq S/c= X-SBRS: 2.7 X-MesageID: 13614986 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,484,1574139600"; d="scan'208";a="13614986" From: Andrew Cooper To: Xen-devel Date: Tue, 25 Feb 2020 17:31:33 +0000 Message-ID: <20200225173133.3632-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/sysctl: Don't return cpu policy data for compiled-out support 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" Policy objects aren't tiny, and the derivation logic isn't trivial. We are about to increase the number of policy objects, so take this opportunity to drop logic and storage space based on CONFIG_{PV,HVM}. Start by causing XEN_SYSCTL_get_cpu_policy to fail with -EOPNOTSUPP when requesting data for a compiled-out subsystem. Update xen-cpuid to cope and continue to further system policies, seeing as the indicies are interleaved. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné --- tools/misc/xen-cpuid.c | 9 +++++++++ xen/arch/x86/sysctl.c | 20 +++++++++++++++----- xen/include/public/sysctl.h | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/misc/xen-cpuid.c b/tools/misc/xen-cpuid.c index 7726c4ed3c..f55b67640a 100644 --- a/tools/misc/xen-cpuid.c +++ b/tools/misc/xen-cpuid.c @@ -480,7 +480,16 @@ int main(int argc, char **argv) if ( xc_get_system_cpu_policy(xch, i, &nr_leaves, leaves, &nr_msrs, msrs) ) + { + if ( errno == EOPNOTSUPP ) + { + printf("%s policy not supported by Xen\n", + sys_policies[i]); + continue; + } + err(1, "xc_get_system_cpu_policy(, %s,,)", sys_policies[i]); + } print_policy(sys_policies[i], leaves, nr_leaves, msrs, nr_msrs); diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index 4a76f0f47f..59a384023b 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -33,7 +33,7 @@ #include #include -const struct cpu_policy system_policies[] = { +const struct cpu_policy system_policies[6] = { [ XEN_SYSCTL_cpu_policy_raw ] = { &raw_cpuid_policy, &raw_msr_policy, @@ -42,22 +42,26 @@ const struct cpu_policy system_policies[] = { &host_cpuid_policy, &host_msr_policy, }, +#ifdef CONFIG_PV [ XEN_SYSCTL_cpu_policy_pv_max ] = { &pv_max_cpuid_policy, &pv_max_msr_policy, }, - [ XEN_SYSCTL_cpu_policy_hvm_max ] = { - &hvm_max_cpuid_policy, - &hvm_max_msr_policy, - }, [ XEN_SYSCTL_cpu_policy_pv_default ] = { &pv_max_cpuid_policy, &pv_max_msr_policy, }, +#endif +#ifdef CONFIG_HVM + [ XEN_SYSCTL_cpu_policy_hvm_max ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy, + }, [ XEN_SYSCTL_cpu_policy_hvm_default ] = { &hvm_max_cpuid_policy, &hvm_max_msr_policy, }, +#endif }; struct l3_cache_info { @@ -426,6 +430,12 @@ long arch_do_sysctl( array_index_nospec(sysctl->u.cpu_policy.index, ARRAY_SIZE(system_policies))]; + if ( !policy->cpuid || !policy->msr ) + { + ret = -EOPNOTSUPP; + break; + } + /* Process the CPUID leaves. */ if ( guest_handle_is_null(sysctl->u.cpu_policy.cpuid_policy) ) sysctl->u.cpu_policy.nr_leaves = CPUID_MAX_SERIALISED_LEAVES; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 7e43bfe1bd..4dfba39ed8 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1051,6 +1051,8 @@ struct xen_sysctl_set_parameter { * experimental features outside of security support. * - Default_*: Default set of features a PV or HVM guest can use. This is * the security supported set. + * May fail with -EOPNOTSUPP if querying for PV or HVM data when support is + * compiled out of Xen. */ struct xen_sysctl_cpu_policy { #define XEN_SYSCTL_cpu_policy_raw 0