From nobody Tue May 7 00:55:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610051737; cv=none; d=zohomail.com; s=zohoarc; b=KfFAomsHpCS/WkzJ3oCZ68UIXBe0cNyiLrsIdx869xvRBSaV6yjStlXiG4e3cSAHxwan6k0L83ZXjdbo+R3gsHJJr/AqM+5rqWuHmJOZR+78NnLyey20ep2uVmv5i4W2eXEK2KfRVKUGprEawqkzAhB7zPrK9EZFwZ9071lDw9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610051737; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=/KFniBUDgE1CDZR+wKbl9DuVufi1j0rCzyWZxtuLZVc=; b=C5FHVKkPTJuwG4nGxSlADUts04o0NALlzyzSttArGaJTkDlBLvukiP/W+HitAKlVse9qSh8TcG3abdNFCEHeKVgTFRsitZqdiNjLGqSyU/DeYgj6EK+zo+8EVdC/NK0VYY2M1Ugqx1LbexAAskSs3TDkWVFjOcvSk1BcZFx+Kc0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610051737741630.1530525931553; Thu, 7 Jan 2021 12:35:37 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =20 -=3Dback=20 +=3Dover + +=3Ditem B + +Determine hypervisor behavior on accesses to MSRs that are not emulated by= the hypervisor. + +=3Dover 4 + +=3Ditem B + +Issue a warning to the log and #GP to the guest. This is default. + +=3Ditem B + +MSR reads return 0, MSR writes are ignored. No warnings to the log. + +=3Ditem B + +Similar to B but a warning is written. =20 =3Dhead3 Guest Virtual Time Controls =20 diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.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 =3D Enumeration("tee_type", [ (1, "optee") ], init_val =3D "LIBXL_TEE_TYPE_NONE") =20 +libxl_ignore_msrs =3D Enumeration("ignore_msrs", [ + (0, "never"), + (1, "silent"), + (2, "verbose"), + ], init_val =3D "LIBXL_IGNORE_MSRS_NEVER") + libxl_rdm_reserve =3D Struct("rdm_reserve", [ ("strategy", libxl_rdm_reserve_strategy), ("policy", libxl_rdm_reserve_policy), @@ -559,6 +565,7 @@ libxl_domain_build_info =3D 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_typ= e), 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: } } =20 + 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); =20 xlu_cfg_get_defbool(config, "xend_suspend_evtchn_compat", --=20 1.8.3.1 From nobody Tue May 7 00:55:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610051736; cv=none; d=zohomail.com; s=zohoarc; b=iboIwA6A6h0aQpwgI4bo2QrqSjhs1XJMcAl1J15OJPt8L+76oXegQoFSRNq0upj+QShtipkMWZFFTv/SnEuLk/GyYCSZ7BS9JnM4gMR13hLp/yrCGr0EKuDUEsGGyusfQHZQ68K4BdEpKoM0+wjNBdkAs5Npga5DVhY6IMZJkcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610051736; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=e5kvjTNHNZ5bZzwKzEgSd2kZPMSBlSOmboG8wtJ3sfg=; b=k3gZQYFiLDR4u00t5SFqSH3jROkpVo2AqHhE+GFD0kVPDN8qbgW7+el6TG0nbqXKdLaYdXWht3n3Y6DqnLF0mN71J4GWzJHL8rxktMyY2/sBE86c3xvoWk33V3JanFttpSpLfBckC+v0kEq9Vx0rTogPihhoowXFqPa0MS98zLQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610051736800878.2581848388945; Thu, 7 Jan 2021 12:35:36 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =20 +/* + * Behavior on accesses to MSRs that are not handled by emulation: + * 0 =3D return #GP, warning emitted + * 1 =3D read as 0, writes are dropped, no warning + * 2 =3D 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 =20 /* 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; }; =20 #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, performi= ng 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_entr= ies) { - const xen_msr_entry_t ent =3D { .idx =3D idx, .val =3D val }; + const xen_msr_entry_t ent =3D { .idx =3D idx, .val =3D val, .flags =3D= flags }; =20 if ( *curr_entry =3D=3D nr_entries ) return -ENOBUFS; @@ -29,17 +29,18 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p, const uint32_t nr_entries =3D *nr_entries_p; uint32_t curr_entry =3D 0; =20 -#define COPY_MSR(idx, val) \ +#define COPY_MSR(idx, val, flags) \ ({ \ int ret; \ \ if ( (ret =3D copy_msr_to_buffer( \ - idx, val, msrs, &curr_entry, nr_entries)) ) \ + idx, val, flags, msrs, &curr_entry, nr_entries)) ) \ return ret; \ }) =20 - 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); =20 #undef COPY_MSR =20 @@ -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; =20 - if ( data.flags ) /* .flags MBZ */ + if ( data.idx !=3D MSR_UNHANDLED && data.flags ) { rc =3D -EINVAL; goto err; @@ -101,6 +102,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p, =20 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 =3D data.flags & 0xff= ; break; =20 #undef ASSIGN =20 --=20 1.8.3.1 From nobody Tue May 7 00:55:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610051737; cv=none; d=zohomail.com; s=zohoarc; b=EOvqp4DdIfk6gGG0znfU8x9+VN+WkBw6ZAjp3f85m01dq4ZiKXq03ZPLwtWCxDsQcaURTX5t/SePSo4fX0xMNGDk+w7UbCuaJkH10sygkLNfTOO2UVzklPkUw7Ny4G1UMfQzWEyLT5Rc4gVock3fOdgT1QrrSp90oYBg/4VWOBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610051737; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Bhn1XpcYtMjdOpy5EowmGrcJmomV82yzTHtsIJQu40A=; b=D07Y23t5XD+xBBAY5ZDV1uOL0EbPuMTR7gbkTpkv32BLd6T4NXRpd0COdnO4Uszcdhp+CH5jYV4rd8A3NFZxIJ2xc7P+hRWkge371P1Nb96YQK9vdb0wk3N8ODYkstbulC3IulCW68JSS+1vmV08ocnIOBImBkR6HC7/jKQeLbA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610051737589867.3845278928003; Thu, 7 Jan 2021 12:35:37 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Starting with commit 84e848fd7a16 ("x86/hvm: disallow access to unknown MSR= s") 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, u= int64_t *msr_content) break; =20 default: - gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", msr); - goto gpf; + if ( guest_unhandled_msr(v, msr, msr_content, false) ) + goto gpf; } =20 HVM_DBG_LOG(DBG_LEVEL_MSR, "returns: ecx=3D%x, msr_value=3D%"PRIx64, @@ -2151,10 +2151,8 @@ static int svm_msr_write_intercept(unsigned int msr,= uint64_t msr_content) break; =20 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; } =20 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, u= int64_t *msr_content) break; } =20 - gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", msr); - goto gp_fault; + if ( guest_unhandled_msr(curr, msr, msr_content, false) ) + goto gp_fault; } =20 done: @@ -3319,10 +3319,8 @@ static int vmx_msr_write_intercept(unsigned int msr,= uint64_t msr_content) is_last_branch_msr(msr) ) break; =20 - 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; } =20 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; } =20 +/* 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 =3D v->domain->arch.msr; + + if ( unlikely(mp->ignore_msrs !=3D MSR_UNHANDLED_NEVER) && !is_write ) + *val =3D 0; + + if ( likely(mp->ignore_msrs !=3D 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 =3D=3D MSR_UNHANDLED_NEVER); +} + int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) { const struct vcpu *curr =3D 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; =20 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; =20 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 */ --=20 1.8.3.1 From nobody Tue May 7 00:55:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610051851; cv=none; d=zohomail.com; s=zohoarc; b=Gmorzn/4uUgkOYOmfhiZFLD20D90WV7VVBfGCduHWTeXtJfKxXqbcgwg7OypgpCFKOznCGuirjqCzcxb/szYq3mlf1wutUMYvyXHBklYeNTK6PaVv4Vo2TWwkS7IhnYiejSU9t+s8+5UAR9BaaYnwgZ+JKu/7BgIS2cnAkA46Yc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610051851; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Nd9FgzdDJHVDkvYwI1BHZjOCLONh5hp3MW2VXCsHVvg=; b=EkIRz70qcvHKFVMaOy9y7QHGl2YcpLSL5Su8KdA9dTiofckmDeNj+Uj/kFjCoGlqq8/R9/HkFJw35J4HSCu/OFKlVVnudj8bZfeWvhorzzMno33XQn1OkxuKXr4cRYP6m64JIbA1qrzSh8iPXUYLbYK4DjBONkFS5YMx3v1v0og= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610051851491709.6290075112904; Thu, 7 Jan 2021 12:37:31 -0800 (PST) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 *xe= nd); +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 +=3D xg_dom_compat_linux.c =20 SRCS-$(CONFIG_X86) +=3D xg_dom_x86.c SRCS-$(CONFIG_X86) +=3D xg_cpuid_x86.c +SRCS-$(CONFIG_X86) +=3D xg_msrs_x86.c SRCS-$(CONFIG_ARM) +=3D xg_dom_arm.c =20 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 ig= nore_msr) +{ + int rc; + unsigned int nr_leaves, nr_msrs; + xen_msr_entry_t *msrs =3D NULL; + struct msr_policy *p =3D NULL; + xc_dominfo_t di; + unsigned int err_leaf, err_subleaf, err_msr; + + if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || + di.domid !=3D domid ) + { + ERROR("Failed to obtain d%d info", domid); + rc =3D -ESRCH; + goto out; + } + + rc =3D xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs); + if ( rc ) + { + PERROR("Failed to obtain policy info size"); + rc =3D -errno; + goto out; + } + + rc =3D -ENOMEM; + if ( (msrs =3D calloc(nr_msrs, sizeof(*msrs))) =3D=3D NULL || + (p =3D calloc(1, sizeof(*p))) =3D=3D NULL ) + goto out; + + /* Get the domain's default policy. */ + nr_leaves =3D 0; + rc =3D xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hv= m_default + : XEN_SYSCTL_cpu_policy_pv_d= efault, + &nr_leaves, NULL, &nr_msrs, msrs); + if ( rc ) + { + PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv"= ); + rc =3D -errno; + goto out; + } + + rc =3D x86_msr_copy_from_buffer(p, msrs, nr_msrs, &err_msr); + if ( rc ) + { + ERROR("Failed to deserialise MSR (err msr %#x) (%d =3D %s)", + err_msr, -rc, strerror(-rc)); + goto out; + } + + p->ignore_msrs =3D ignore_msr; + + rc =3D x86_msr_copy_to_buffer(p, msrs, &nr_msrs); + if ( rc ) + { + ERROR("Failed to serialise MSR (%d =3D %s)", -rc, strerror(-rc)); + goto out; + } + + nr_leaves =3D 0; + rc =3D 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 =3D -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; } =20 diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.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, c= onst char *type, =20 _hidden void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool reto= re, libxl_domain_build_info *info); +_hidden void libxl__msr_policy(libxl_ctx *ctx, uint32_t domid, + libxl_domain_build_info *info); =20 /* 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" =20 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; } =20 +void libxl__msr_policy(libxl_ctx *ctx, uint32_t domid, + libxl_domain_build_info *info) +{ + if (info->ignore_msrs !=3D LIBXL_IGNORE_MSRS_NEVER) + xc_msr_apply_policy(ctx->xch, domid, info->ignore_msrs); +} =20 /* * Local variables: --=20 1.8.3.1