From patchwork Thu Jan 7 20:34:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 12004835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58FE3C433DB for ; Thu, 7 Jan 2021 20:35:32 +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 EE4F22343F for ; Thu, 7 Jan 2021 20:35:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE4F22343F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.63098.112011 (Exim 4.92) (envelope-from ) id 1kxc02-0002O7-IS; Thu, 07 Jan 2021 20:35:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 63098.112011; Thu, 07 Jan 2021 20:35:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxc02-0002O0-E3; Thu, 07 Jan 2021 20:35:14 +0000 Received: by outflank-mailman (input) for mailman id 63098; Thu, 07 Jan 2021 20:35:12 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxc00-0002Nv-QZ for xen-devel@lists.xenproject.org; Thu, 07 Jan 2021 20:35:12 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 019ee519-bf30-4fa5-bc3d-8f3e75502bcf; Thu, 07 Jan 2021 20:35:10 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107KZ4ia043536; Thu, 7 Jan 2021 20:35:08 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 35wcuxxk0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 20:35:08 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107KYsLA125134; Thu, 7 Jan 2021 20:35:07 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 35v1fbpd7y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 20:35:07 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 107KZ7u5010978; Thu, 7 Jan 2021 20:35:07 GMT Received: from ovs104.us.oracle.com (/10.149.224.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 20:35:06 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 019ee519-bf30-4fa5-bc3d-8f3e75502bcf DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=/KFniBUDgE1CDZR+wKbl9DuVufi1j0rCzyWZxtuLZVc=; b=BkQmxWkEdLXm+ZicbxPVP4fXpOVV9Ek305Jt2RERYKhRu3oj2qbJj8NpTreCKcyNC5nb 7MVA2BzzSjsPHxr1eOJ9j/+2kBhNvLWd5VGBLpwIjNx0/MyhR1+9aZwL4Dlu9mZ03XFj 0yuX4pcsW8o+BC5Xe1c9vaEBq3evtWInvVf4Cn7HGbxq3kpU3eoL+jITfrntKdGF4pWC Nc4xaLhEPg7VS8cOr7LTE/ILswqiA5rbrcHJUjpqKCwgCvQPEpXH5PdnmBmF+c/32eSA zDZq5Rr/9A6ylcIb93GOrvZdRnJVnLsjziIj6cthW7MaJoQI6zd+kJ1V9paCiYFi0w1t uw== From: Boris Ostrovsky To: xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, anthony.perard@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, jun.nakajima@intel.com, kevin.tian@intel.com, boris.ostrvsky@oracle.com Subject: [PATCH 1/4] xl: Add support for ignore_msrs option Date: Thu, 7 Jan 2021 15:34:55 -0500 Message-Id: <1610051698-23675-2-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1610051698-23675-1-git-send-email-boris.ostrovsky@oracle.com> References: <1610051698-23675-1-git-send-email-boris.ostrovsky@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070120 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 clxscore=1011 spamscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070120 This option allows guest administrator specify what should happen when guest accesses an MSR which is not explicitly emulated by the hypervisor. Signed-off-by: Boris Ostrovsky --- docs/man/xl.cfg.5.pod.in | 20 +++++++++++++++++++- tools/libs/light/libxl_types.idl | 7 +++++++ tools/xl/xl_parse.c | 7 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index c8e017f950de..96ce97c42cab 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -2044,7 +2044,25 @@ Do not provide a VM generation ID. See also "Virtual Machine Generation ID" by Microsoft: L -=back +=over + +=item B + +Determine hypervisor behavior on accesses to MSRs that are not emulated by the hypervisor. + +=over 4 + +=item B + +Issue a warning to the log and #GP to the guest. This is default. + +=item B + +MSR reads return 0, MSR writes are ignored. No warnings to the log. + +=item B + +Similar to B but a warning is written. =head3 Guest Virtual Time Controls diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl index 05324736b744..7b5fef771ee8 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -477,6 +477,12 @@ libxl_tee_type = Enumeration("tee_type", [ (1, "optee") ], init_val = "LIBXL_TEE_TYPE_NONE") +libxl_ignore_msrs = Enumeration("ignore_msrs", [ + (0, "never"), + (1, "silent"), + (2, "verbose"), + ], init_val = "LIBXL_IGNORE_MSRS_NEVER") + libxl_rdm_reserve = Struct("rdm_reserve", [ ("strategy", libxl_rdm_reserve_strategy), ("policy", libxl_rdm_reserve_policy), @@ -559,6 +565,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("apic", libxl_defbool), ("dm_restrict", libxl_defbool), ("tee", libxl_tee_type), + ("ignore_msrs", libxl_ignore_msrs), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), ("bios", libxl_bios_type), diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 4ebf39620ae7..942086c3f41d 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2732,6 +2732,13 @@ skip_usbdev: } } + if (!xlu_cfg_get_string(config, "ignore_msrs", &buf, 0)) { + if (libxl_ignore_msrs_from_string(buf, &b_info->ignore_msrs)) { + fprintf(stderr, "ERROR: invalid value \"%s\" for \"ignore_msrs\"\n", buf); + exit(1); + } + } + parse_vkb_list(config, d_config); xlu_cfg_get_defbool(config, "xend_suspend_evtchn_compat", From patchwork Thu Jan 7 20:34:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 12004833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3C93C433DB for ; Thu, 7 Jan 2021 20:35:29 +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 8A5632343F for ; Thu, 7 Jan 2021 20:35:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A5632343F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.63099.112023 (Exim 4.92) (envelope-from ) id 1kxc06-0002Pc-RT; Thu, 07 Jan 2021 20:35:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 63099.112023; Thu, 07 Jan 2021 20:35:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxc06-0002PV-NL; Thu, 07 Jan 2021 20:35:18 +0000 Received: by outflank-mailman (input) for mailman id 63099; Thu, 07 Jan 2021 20:35:17 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxc05-0002Nv-Gz for xen-devel@lists.xenproject.org; Thu, 07 Jan 2021 20:35:17 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id dc58d9c1-b043-48ec-8ac7-10de9cae0e9a; Thu, 07 Jan 2021 20:35:12 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107KZ0FX043493; Thu, 7 Jan 2021 20:35:09 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 35wcuxxk13-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 20:35:09 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107KYSkl084920; Thu, 7 Jan 2021 20:35:09 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 35w3qu7dqg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 20:35:08 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 107KZ7Be030848; Thu, 7 Jan 2021 20:35:07 GMT Received: from ovs104.us.oracle.com (/10.149.224.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 20:35:07 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dc58d9c1-b043-48ec-8ac7-10de9cae0e9a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=e5kvjTNHNZ5bZzwKzEgSd2kZPMSBlSOmboG8wtJ3sfg=; b=cN4Dx+o3/OP0VaT3D9MWwzuLuQMBERnsYuO0VksUB1jyDZ8v8z5N8Vts54r8gzw7ph0k h8/u39QXHtgTIhFbJXLH50WvxmniWdq7qhBzRobOCXbFgk0RSHsB7+0JbAYM6eK63EEc zbIy22RYAgXfeycoZ3wR8HR+U0fsuoq1yOOhHX9omSd+Ncpbz5eWXdh2ocLZi4QOmBy7 iJf8WcRj6Icuso+Ncxr7eXce8ZpOrrPpa/Oup+XwhCgiUhLxgEyDNbNFDJ76914FfISN piv4nl4f4xkFyoI9htnL8HGH/aIA6dtVrqRPL7/BOBYRIuWp4Aot8ogCmMR9I5PjJ1ww EQ== From: Boris Ostrovsky To: xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, anthony.perard@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, jun.nakajima@intel.com, kevin.tian@intel.com, boris.ostrvsky@oracle.com Subject: [PATCH 2/4] x86: Introduce MSR_UNHANDLED Date: Thu, 7 Jan 2021 15:34:56 -0500 Message-Id: <1610051698-23675-3-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1610051698-23675-1-git-send-email-boris.ostrovsky@oracle.com> References: <1610051698-23675-1-git-send-email-boris.ostrovsky@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070120 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 clxscore=1015 spamscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070120 When toolstack updates MSR policy, this MSR offset (which is an invalid MSR index) is used to indicate hypervisor behavior when a guest accesses an MSR which is not explicitly emulated. Signed-off-by: Boris Ostrovsky --- xen/include/xen/lib/x86/msr.h | 17 ++++++++++++++++- xen/lib/x86/msr.c | 16 +++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h index 48ba4a59c036..7911ae31eb48 100644 --- a/xen/include/xen/lib/x86/msr.h +++ b/xen/include/xen/lib/x86/msr.h @@ -2,8 +2,21 @@ #ifndef XEN_LIB_X86_MSR_H #define XEN_LIB_X86_MSR_H +/* + * Behavior on accesses to MSRs that are not handled by emulation: + * 0 = return #GP, warning emitted + * 1 = read as 0, writes are dropped, no warning + * 2 = read as 0, writes are dropped, warning emitted + */ +#define MSR_UNHANDLED_NEVER 0 +#define MSR_UNHANDLED_SILENT 1 +#define MSR_UNHANDLED_VERBOSE 2 + +/* MSR that is not explicitly processed by emulation */ +#define MSR_UNHANDLED -1 + /* Maximum number of MSRs written when serialising msr_policy. */ -#define MSR_MAX_SERIALISED_ENTRIES 2 +#define MSR_MAX_SERIALISED_ENTRIES 3 /* MSR policy object for shared per-domain MSRs */ struct msr_policy @@ -45,6 +58,8 @@ struct msr_policy bool taa_no:1; }; } arch_caps; + + uint8_t ignore_msrs; }; #ifdef __XEN__ diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c index 7d71e92a380a..cf53768dfa4e 100644 --- a/xen/lib/x86/msr.c +++ b/xen/lib/x86/msr.c @@ -6,11 +6,11 @@ * Copy a single MSR into the provided msr_entry_buffer_t buffer, performing a * boundary check against the buffer size. */ -static int copy_msr_to_buffer(uint32_t idx, uint64_t val, +static int copy_msr_to_buffer(uint32_t idx, uint64_t val, uint32_t flags, msr_entry_buffer_t msrs, uint32_t *curr_entry, const uint32_t nr_entries) { - const xen_msr_entry_t ent = { .idx = idx, .val = val }; + const xen_msr_entry_t ent = { .idx = idx, .val = val, .flags = flags }; if ( *curr_entry == nr_entries ) return -ENOBUFS; @@ -29,17 +29,18 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p, const uint32_t nr_entries = *nr_entries_p; uint32_t curr_entry = 0; -#define COPY_MSR(idx, val) \ +#define COPY_MSR(idx, val, flags) \ ({ \ int ret; \ \ if ( (ret = copy_msr_to_buffer( \ - idx, val, msrs, &curr_entry, nr_entries)) ) \ + idx, val, flags, msrs, &curr_entry, nr_entries)) ) \ return ret; \ }) - COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw); - COPY_MSR(MSR_ARCH_CAPABILITIES, p->arch_caps.raw); + COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw, 0); + COPY_MSR(MSR_ARCH_CAPABILITIES, p->arch_caps.raw, 0); + COPY_MSR(MSR_UNHANDLED, 0, p->ignore_msrs); #undef COPY_MSR @@ -77,7 +78,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p, if ( copy_from_buffer_offset(&data, msrs, i, 1) ) return -EFAULT; - if ( data.flags ) /* .flags MBZ */ + if ( data.idx != MSR_UNHANDLED && data.flags ) { rc = -EINVAL; goto err; @@ -101,6 +102,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p, case MSR_INTEL_PLATFORM_INFO: ASSIGN(platform_info.raw); break; case MSR_ARCH_CAPABILITIES: ASSIGN(arch_caps.raw); break; + case MSR_UNHANDLED: p->ignore_msrs = data.flags & 0xff; break; #undef ASSIGN From patchwork Thu Jan 7 20:34:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 12004837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1B70C433E0 for ; Thu, 7 Jan 2021 20:35:32 +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 46C2E23443 for ; Thu, 7 Jan 2021 20:35:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 46C2E23443 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.63101.112035 (Exim 4.92) (envelope-from ) id 1kxc0B-0002TT-AE; Thu, 07 Jan 2021 20:35:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 63101.112035; Thu, 07 Jan 2021 20:35:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxc0B-0002TJ-5c; Thu, 07 Jan 2021 20:35:23 +0000 Received: by outflank-mailman (input) for mailman id 63101; Thu, 07 Jan 2021 20:35:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxc0A-0002Nv-H6 for xen-devel@lists.xenproject.org; Thu, 07 Jan 2021 20:35:22 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 046297dd-aae7-4367-bbc6-18123069346c; Thu, 07 Jan 2021 20:35:13 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107KZ0FY043493; Thu, 7 Jan 2021 20:35:10 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 35wcuxxk16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 20:35:10 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107KYTNd084995; Thu, 7 Jan 2021 20:35:10 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 35w3qu7dqw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 20:35:09 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 107KZ8Yu030852; Thu, 7 Jan 2021 20:35:08 GMT Received: from ovs104.us.oracle.com (/10.149.224.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 20:35:08 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 046297dd-aae7-4367-bbc6-18123069346c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=Bhn1XpcYtMjdOpy5EowmGrcJmomV82yzTHtsIJQu40A=; b=LNkPhjN/1mKq6dcW9CcPaSO7HXu8CtViKdQ9RgoO9FhFnEGnTw5eCvYCvQFCFsbnyfRs /r2JBsJleBpbknC1KwZxNnOoech2/uVnR6mGHBMmSFIBdHQBah+Ut6kVvLlUSm0PKJ8l wIThNXauAPWMMUbmN6SVilTI2e4dT06Sqyq/YBeMt5rKtR7yG+JJW+Mk5wC97XT+PhzB 0liLoxp78FJvIaL/Nh2kMb9yng0xeUK0N03gFDk3KxZI3Oc/iKW8I8ABt8WOcYljoHR0 BbwBUSPU5L6zGh4AN+4hFT1o1pgJjFGjiZ2N8LZLYKhWel9Dxg3rCkXL9MjEjgJbGWuA ew== From: Boris Ostrovsky To: xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, anthony.perard@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, jun.nakajima@intel.com, kevin.tian@intel.com, boris.ostrvsky@oracle.com Subject: [PATCH 3/4] x86: Allow non-faulting accesses to non-emulated MSRs if policy permits this Date: Thu, 7 Jan 2021 15:34:57 -0500 Message-Id: <1610051698-23675-4-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1610051698-23675-1-git-send-email-boris.ostrovsky@oracle.com> References: <1610051698-23675-1-git-send-email-boris.ostrovsky@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070120 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 clxscore=1015 spamscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070120 Starting with commit 84e848fd7a16 ("x86/hvm: disallow access to unknown MSRs") accesses to unhandled MSRs result in #GP sent to the guest. This caused a regression for Solaris who tries to acccess MSR_RAPL_POWER_UNIT and (unlike, for example, Linux) does not catch exceptions when accessing MSRs that potentially may not be present. Instead of special-casing RAPL registers we decide what to do when any non-emulated MSR is accessed based on ignore_msrs field of msr_policy. Signed-off-by: Boris Ostrovsky --- xen/arch/x86/hvm/svm/svm.c | 10 ++++------ xen/arch/x86/hvm/vmx/vmx.c | 10 ++++------ xen/arch/x86/msr.c | 20 ++++++++++++++++++++ xen/arch/x86/pv/emul-priv-op.c | 8 ++++---- xen/include/asm-x86/msr.h | 3 ++- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index b819897a4a9f..c9a93448f071 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -1965,8 +1965,8 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) break; default: - gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", msr); - goto gpf; + if ( guest_unhandled_msr(v, msr, msr_content, false) ) + goto gpf; } HVM_DBG_LOG(DBG_LEVEL_MSR, "returns: ecx=%x, msr_value=%"PRIx64, @@ -2151,10 +2151,8 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) break; default: - gdprintk(XENLOG_WARNING, - "WRMSR 0x%08x val 0x%016"PRIx64" unimplemented\n", - msr, msr_content); - goto gpf; + if ( guest_unhandled_msr(v, msr, &msr_content, true) ) + goto gpf; } return X86EMUL_OKAY; diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 2d4475ee3de2..34524c7a6f00 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -3017,8 +3017,8 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content) break; } - gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", msr); - goto gp_fault; + if ( guest_unhandled_msr(curr, msr, msr_content, false) ) + goto gp_fault; } done: @@ -3319,10 +3319,8 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) is_last_branch_msr(msr) ) break; - gdprintk(XENLOG_WARNING, - "WRMSR 0x%08x val 0x%016"PRIx64" unimplemented\n", - msr, msr_content); - goto gp_fault; + if ( guest_unhandled_msr(v, msr, &msr_content, true) ) + goto gp_fault; } return X86EMUL_OKAY; diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c index be8e36386250..e624fc8694bf 100644 --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -164,6 +164,26 @@ int init_vcpu_msr_policy(struct vcpu *v) return 0; } +/* Returns true if policy requires #GP to the guest. */ +bool guest_unhandled_msr(const struct vcpu *v, uint32_t msr, + uint64_t *val, bool is_write) +{ + const struct msr_policy *mp = v->domain->arch.msr; + + if ( unlikely(mp->ignore_msrs != MSR_UNHANDLED_NEVER) && !is_write ) + *val = 0; + + if ( likely(mp->ignore_msrs != MSR_UNHANDLED_SILENT) ) { + if ( is_write ) + gdprintk(XENLOG_WARNING, "WRMSR 0x%08x val 0x%016"PRIx64 + " unimplemented\n", msr, *val); + else + gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", msr); + } + + return (mp->ignore_msrs == MSR_UNHANDLED_NEVER); +} + int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) { const struct vcpu *curr = current; diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index dbceed8a05fd..96d90eb30adc 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -984,7 +984,8 @@ static int read_msr(unsigned int reg, uint64_t *val, } /* fall through */ default: - gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", reg); + if ( !guest_unhandled_msr(curr, reg, val, false) ) + return X86EMUL_OKAY; break; normal: @@ -1146,9 +1147,8 @@ static int write_msr(unsigned int reg, uint64_t val, } /* fall through */ default: - gdprintk(XENLOG_WARNING, - "WRMSR 0x%08x val 0x%016"PRIx64" unimplemented\n", - reg, val); + if ( !guest_unhandled_msr(curr, reg, &val, true) ) + return X86EMUL_OKAY; break; invalid: diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h index 16f95e734428..43a48e1a50ce 100644 --- a/xen/include/asm-x86/msr.h +++ b/xen/include/asm-x86/msr.h @@ -345,5 +345,6 @@ int init_vcpu_msr_policy(struct vcpu *v); */ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val); int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val); - +bool guest_unhandled_msr(const struct vcpu *v, uint32_t msr, + uint64_t *val, bool is_write); #endif /* __ASM_MSR_H */ From patchwork Thu Jan 7 20:34:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 12004841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD84FC433E0 for ; Thu, 7 Jan 2021 20:37:26 +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 941A323441 for ; Thu, 7 Jan 2021 20:37:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 941A323441 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.63111.112059 (Exim 4.92) (envelope-from ) id 1kxc20-0002od-1U; Thu, 07 Jan 2021 20:37:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 63111.112059; Thu, 07 Jan 2021 20:37:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxc1z-0002oW-TW; Thu, 07 Jan 2021 20:37:15 +0000 Received: by outflank-mailman (input) for mailman id 63111; Thu, 07 Jan 2021 20:37:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxc1y-0002nT-A0 for xen-devel@lists.xenproject.org; Thu, 07 Jan 2021 20:37:14 +0000 Received: from userp2130.oracle.com (unknown [156.151.31.86]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ddceb0db-16f4-4455-9777-5fe10b7c2522; Thu, 07 Jan 2021 20:37:13 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107KZUcw089093; Thu, 7 Jan 2021 20:37:11 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 35wftxdsxt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 20:37:11 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107KPSxN184454; Thu, 7 Jan 2021 20:35:10 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 35w3g39gc1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 20:35:10 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 107KZ9Ir010984; Thu, 7 Jan 2021 20:35:09 GMT Received: from ovs104.us.oracle.com (/10.149.224.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 20:35:09 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ddceb0db-16f4-4455-9777-5fe10b7c2522 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=Nd9FgzdDJHVDkvYwI1BHZjOCLONh5hp3MW2VXCsHVvg=; b=0IL0ZeeSDJ9DrvNbrr+UCKRgoq+n2Rk4ARshakUOFq9xUl1DbhC/NrPI7pJ0t5SAh7dY vnlUqfELcP2aN0rLDigCfPk/zYRIfh3Zo++n6+bT5ScQz9qSEEknJkB7hWKCozaHZklo SmPTKoxwM2haxpb47gF4rncXbNfGKSzWaGdyreHNLose8zdvNVapV5ajHq5Kj2ulKYsQ E3P6uzM86C9GG1t068bIAKc9OJ9mZ03+PCL4Y9lLdp10Cxv2TM7xH6ANIQpEgFl/ku5Q kg4OGK7fE/Sc/EFVRkSkmrwlMWE/IpERYhfw82zmtQcwxPD+l9fkCGeK39yJPzFIhD8q aA== From: Boris Ostrovsky To: xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, wl@xen.org, anthony.perard@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, jun.nakajima@intel.com, kevin.tian@intel.com, boris.ostrvsky@oracle.com Subject: [PATCH 4/4] tools/libs: Apply MSR policy to a guest Date: Thu, 7 Jan 2021 15:34:58 -0500 Message-Id: <1610051698-23675-5-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1610051698-23675-1-git-send-email-boris.ostrovsky@oracle.com> References: <1610051698-23675-1-git-send-email-boris.ostrovsky@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 adultscore=0 phishscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070120 When creating a guest, if ignore_msrs option has been specified, apply it to guest's MSR policy. Signed-off-by: Boris Ostrovsky --- tools/include/xenctrl.h | 2 + tools/libs/guest/Makefile | 1 + tools/libs/guest/xg_msrs_x86.c | 110 ++++++++++++++++++++++++++++++++++++++ tools/libs/light/libxl_dom.c | 5 +- tools/libs/light/libxl_internal.h | 2 + tools/libs/light/libxl_x86.c | 7 +++ 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 tools/libs/guest/xg_msrs_x86.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 3796425e1eca..1d6a38e73dcf 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1835,6 +1835,8 @@ int xc_cpuid_apply_policy(xc_interface *xch, const uint32_t *featureset, unsigned int nr_features, bool pae, bool itsc, bool nested_virt, const struct xc_xend_cpuid *xend); +int xc_msr_apply_policy(xc_interface *xch, uint32_t domid, + unsigned int ignore_msr); int xc_mca_op(xc_interface *xch, struct xen_mc *mc); int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags, xc_cpumap_t cpumap, unsigned int nr_cpus); diff --git a/tools/libs/guest/Makefile b/tools/libs/guest/Makefile index 1c729040b337..452155ea0385 100644 --- a/tools/libs/guest/Makefile +++ b/tools/libs/guest/Makefile @@ -56,6 +56,7 @@ SRCS-y += xg_dom_compat_linux.c SRCS-$(CONFIG_X86) += xg_dom_x86.c SRCS-$(CONFIG_X86) += xg_cpuid_x86.c +SRCS-$(CONFIG_X86) += xg_msrs_x86.c SRCS-$(CONFIG_ARM) += xg_dom_arm.c ifeq ($(CONFIG_LIBXC_MINIOS),y) diff --git a/tools/libs/guest/xg_msrs_x86.c b/tools/libs/guest/xg_msrs_x86.c new file mode 100644 index 000000000000..464ce9292ad8 --- /dev/null +++ b/tools/libs/guest/xg_msrs_x86.c @@ -0,0 +1,110 @@ +/****************************************************************************** + * xc_msrs_x86.c + * + * Update MSR policy of a domain. + * + * Copyright (c) 2021, Oracle and/or its affiliates. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_private.h" +#include "xen/lib/x86/msr.h" + + + +int xc_msr_apply_policy(xc_interface *xch, uint32_t domid, unsigned int ignore_msr) +{ + int rc; + unsigned int nr_leaves, nr_msrs; + xen_msr_entry_t *msrs = NULL; + struct msr_policy *p = NULL; + xc_dominfo_t di; + unsigned int err_leaf, err_subleaf, err_msr; + + if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 || + di.domid != domid ) + { + ERROR("Failed to obtain d%d info", domid); + rc = -ESRCH; + goto out; + } + + rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs); + if ( rc ) + { + PERROR("Failed to obtain policy info size"); + rc = -errno; + goto out; + } + + rc = -ENOMEM; + if ( (msrs = calloc(nr_msrs, sizeof(*msrs))) == NULL || + (p = calloc(1, sizeof(*p))) == NULL ) + goto out; + + /* Get the domain's default policy. */ + nr_leaves = 0; + rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_default + : XEN_SYSCTL_cpu_policy_pv_default, + &nr_leaves, NULL, &nr_msrs, msrs); + if ( rc ) + { + PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv"); + rc = -errno; + goto out; + } + + rc = x86_msr_copy_from_buffer(p, msrs, nr_msrs, &err_msr); + if ( rc ) + { + ERROR("Failed to deserialise MSR (err msr %#x) (%d = %s)", + err_msr, -rc, strerror(-rc)); + goto out; + } + + p->ignore_msrs = ignore_msr; + + rc = x86_msr_copy_to_buffer(p, msrs, &nr_msrs); + if ( rc ) + { + ERROR("Failed to serialise MSR (%d = %s)", -rc, strerror(-rc)); + goto out; + } + + nr_leaves = 0; + rc = xc_set_domain_cpu_policy(xch, domid, nr_leaves, NULL, nr_msrs, msrs, + &err_leaf, &err_subleaf, &err_msr); + if ( rc ) + { + PERROR("Failed to set d%d's MSR policy (err leaf %#x, subleaf %#x, msr %#x)", + domid, err_leaf, err_subleaf, err_msr); + rc = -errno; + } + +out: + free(msrs); + free(p); + + return rc; +} + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ + diff --git a/tools/libs/light/libxl_dom.c b/tools/libs/light/libxl_dom.c index 19168572fd3e..1f2abf6679d7 100644 --- a/tools/libs/light/libxl_dom.c +++ b/tools/libs/light/libxl_dom.c @@ -383,9 +383,10 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, /* Construct a CPUID policy, but only for brand new domains. Domains * being migrated-in/restored have CPUID handled during the * static_data_done() callback. */ - if (!state->restore) + if (!state->restore) { libxl__cpuid_legacy(ctx, domid, false, info); - + libxl__msr_policy(ctx, domid, info); + } return rc; } diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index c79523ba9248..4f369e6a6f14 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -2054,6 +2054,8 @@ _hidden char *libxl__object_to_json(libxl_ctx *ctx, const char *type, _hidden void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool retore, libxl_domain_build_info *info); +_hidden void libxl__msr_policy(libxl_ctx *ctx, uint32_t domid, + libxl_domain_build_info *info); /* Calls poll() again - useful to check whether a signaled condition * is still true. Cannot fail. Returns currently-true revents. */ diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c index 86d272999d67..92ec1da77139 100644 --- a/tools/libs/light/libxl_x86.c +++ b/tools/libs/light/libxl_x86.c @@ -1,5 +1,6 @@ #include "libxl_internal.h" #include "libxl_arch.h" +#include "xen/lib/x86/msr.h" int libxl__arch_domain_prepare_config(libxl__gc *gc, libxl_domain_config *d_config, @@ -838,6 +839,12 @@ int libxl__arch_passthrough_mode_setdefault(libxl__gc *gc, return rc; } +void libxl__msr_policy(libxl_ctx *ctx, uint32_t domid, + libxl_domain_build_info *info) +{ + if (info->ignore_msrs != LIBXL_IGNORE_MSRS_NEVER) + xc_msr_apply_policy(ctx->xch, domid, info->ignore_msrs); +} /* * Local variables: