From patchwork Wed Jan 20 22:49:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 12033825 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 A3A97C433E0 for ; Wed, 20 Jan 2021 22:49:49 +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 394FE235DD for ; Wed, 20 Jan 2021 22:49:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 394FE235DD 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.71800.128888 (Exim 4.92) (envelope-from ) id 1l2MIC-00039D-85; Wed, 20 Jan 2021 22:49:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 71800.128888; Wed, 20 Jan 2021 22:49:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2MIC-000395-4z; Wed, 20 Jan 2021 22:49:36 +0000 Received: by outflank-mailman (input) for mailman id 71800; Wed, 20 Jan 2021 22:49:34 +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 1l2MIA-00035p-IH for xen-devel@lists.xenproject.org; Wed, 20 Jan 2021 22:49:34 +0000 Received: from aserp2120.oracle.com (unknown [141.146.126.78]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 123af9f4-1e61-4648-86ad-41892f1c7ed8; Wed, 20 Jan 2021 22:49:27 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10KMiw4s105583; Wed, 20 Jan 2021 22:49:24 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 3668qmvta7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 22:49:24 +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 10KMdirL148865; Wed, 20 Jan 2021 22:49:23 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2176.outbound.protection.outlook.com [104.47.56.176]) by userp3030.oracle.com with ESMTP id 3668rdxwkt-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 22:49:23 +0000 Received: from SA2PR10MB4572.namprd10.prod.outlook.com (2603:10b6:806:f9::18) by SA2PR10MB4441.namprd10.prod.outlook.com (2603:10b6:806:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.14; Wed, 20 Jan 2021 22:49:22 +0000 Received: from SA2PR10MB4572.namprd10.prod.outlook.com ([fe80::4c5b:9cf:616d:b140]) by SA2PR10MB4572.namprd10.prod.outlook.com ([fe80::4c5b:9cf:616d:b140%6]) with mapi id 15.20.3784.011; Wed, 20 Jan 2021 22:49:22 +0000 Received: from ovs104.us.oracle.com (209.17.40.41) by BYAPR03CA0002.namprd03.prod.outlook.com (2603:10b6:a02:a8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Wed, 20 Jan 2021 22:49:20 +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: 123af9f4-1e61-4648-86ad-41892f1c7ed8 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 : content-type : mime-version; s=corp-2020-01-29; bh=/KFniBUDgE1CDZR+wKbl9DuVufi1j0rCzyWZxtuLZVc=; b=SmsjzpZNeD7mH8STV6JNrrv8x9v8qIP6SDleovo2/mBhHZvW81ts5G63lk3zJR5t2et1 eONGlr4xL1uGBT5ubZoUkYS5lBBbekPufGWXzjstQ8SlYExtCccxbLaS663EzySQrlIl /vLYeJFiIUXhhtunZ23uuQ1xNKY9PPM3tppGy9as2MYp0kTrOKFcpdZR/SBvs+MRsmuJ OwKwLosgt9YSYPXtvvgkMWuOO/bV8mnApjkfVPTpqhu6HuglXQ6x9Bioz67KSsiORlIx HTCnOJiBsa39TqIMBVVrFwTODUSYVKAbIT3csBzrfQsa/+3/aOf4GQNVzLg3OHIVnHVv OA== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gR3aDEfUkzvkWyx17nOr+LJTZ6m8hevURX1j50cPoYjT7HgtpEZo/+d0es/W1I8uD7J9KZETgpJ0kQ2ciS5Mhl1YWEPR6a5CpywVw00jtHP4uk1cedvClaqasnvQ2fMt8FbRTd4eujIQjkP0ChF75p/mAQBlT6dDu6S8Giciyj0eotWMsI+gCdTVn2YKTzAETmVl72CYIZRB/xplWYrPLqo32GC2ygLUvr6xjKRZItjV5KX7Xi102cpwvVYLGyfKq8IGc6VZlaBK3VabJ01CotrBSsFzB5pvP6Nd3eOZu/3TbjKGtEE1etl0t/SsGvxwgMVqrNUFj15VqciBxHlJZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/KFniBUDgE1CDZR+wKbl9DuVufi1j0rCzyWZxtuLZVc=; b=Na94HtgWBs1I5noDZiUdttMfNRnSmMfyE0ZcyRirkX3bIK/o9TPEYb4SmF94EdHN+KL91af8zXsWyGlGw1hp1/6Mg35ZeybJWarIhrIL23AKTXNjwfWEgkzsbRbnD5flcCvnGPjHFEaLtic1thvbmVVuERYqgep6wEK3dL1/cK9W5ENpkq2TZxn7alDPaJNh8U/hveC7BYxWSuOJgj4iPC/E+fcNIcBorPTvE03E1hpcFtFzTOEEGn89l9Nfs6UEx0qmSV4uO7c8G2npl472oFS9Ow/Mv1MZmYf4exoyvR5HiuBUrJVwYE/AoPASBy9Q7M486nDBvC48BUnoff1+wA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/KFniBUDgE1CDZR+wKbl9DuVufi1j0rCzyWZxtuLZVc=; b=S2VBcvJtuR3NuQGu3urNGv1Jo+VI5Tq46zjYyYJdlPO+6GcoX+EkqLwZqQlnd3WoEbQ8l/2dvnw7hujDW7CZNt8w6JX7+53A/sRXVXGE8lSUfEq6yFfbkK6yT8+0YmiO3AHM4ZnfU1UHuz0PzgftW7wf+l0WZtCgoBK/ULoe4ks= Authentication-Results: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=oracle.com; 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.ostrovsky@oracle.com Subject: [PATCH v2 1/4] xl: Add support for ignore_msrs option Date: Wed, 20 Jan 2021 17:49:09 -0500 Message-Id: <1611182952-9941-2-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1611182952-9941-1-git-send-email-boris.ostrovsky@oracle.com> References: <1611182952-9941-1-git-send-email-boris.ostrovsky@oracle.com> X-Originating-IP: [209.17.40.41] X-ClientProxiedBy: BYAPR03CA0002.namprd03.prod.outlook.com (2603:10b6:a02:a8::15) To SA2PR10MB4572.namprd10.prod.outlook.com (2603:10b6:806:f9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d46894b6-99d2-4b5d-ca46-08d8bd95a0e4 X-MS-TrafficTypeDiagnostic: SA2PR10MB4441: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XuXPECJxCHc+vXFSmAGMjFd9UqQr0JWvta+fuul3KqEdjvD+AOk+2XLYIOTT0fb8SCufqjc2HNkLeV9ozElECEj7uG1GwiGFUMJhUGJCHkwcDW5pKVGqN6j5sFjqQU/PvHYDv6yASG1tY4XiU8OoR8kwdowOymLVRNKjFVdF5BfLNK4/dzet1F15QuOzsj0czMXtF47+fWxhafakcAUkcRMWXV83/52BBIEC6ZaTHSZk1Etmcg2KLR3KK66YsdbNLXbx60D+hwzc2KvMDv1N1OUF82RPiUy9oWDY17nJdmEUQ18r2JzGI1SeYARx0FpWvQGFyQDH3VOml75e7MBTd7CmR2hJFL2t92gH9n3wSFwmHm/wgQELx8pyY6JzXybHXmhKRuzXs9t6WOAOn3y+64DSONSAF8HQF3+N3zTUUzS+h9ojE3tgrPqHd5tIhW9igfkOqGzRTYOfvhenByBtQA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA2PR10MB4572.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(346002)(136003)(396003)(39860400002)(376002)(316002)(2906002)(52116002)(5660300002)(26005)(45080400002)(4326008)(86362001)(66556008)(36756003)(7696005)(508600001)(186003)(44832011)(6916009)(2616005)(8936002)(66946007)(6666004)(16526019)(956004)(6486002)(107886003)(66476007)(83380400001)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: +2wdBPH7jNxFYYbXOT4rfz710VDzt6fXZYfAVv2U9HQ+V2KY1p9uvSLNCfezd2lpHb6nh4xLVyWZ7s49ju7NXUmlRt4A2i8Q1ybA5qoNZUZpvh2aOz6Dfj3H7+6ECvq09YDHld8I6bhCcLrjoc6+kch15cwzB7K/MoJPDEuHkT+9w8sfLjABSp5ZdIDTRJJJmZ9CIZ44d/3KScUnLa+zvWMbH3opDNN7QtwJ0TB+uQiN56kqeTIRdY1Zpn7oCKooCisQa6rHxbrrLDHKe+MohMfFYrNLUtFU/RlARXJ7H8z8MXmMqN6V8bCxK7krClw9s4HbLYOVrvv5OZlr6jUMbuIK7xu4ho9p54eMEOAcRIGcWZVqcF7SZgSlanRv4kKyZdAma9rw6YwfryJe2F2hOhQA75CXfoUyFLfFaACATdtZPeCkJ2DFSDswo+cnUWfY6vbJkciaRSoyfXQMgU/8vOQ/bl2anX/QlF9/B/kGRNkicIMyAzZq9MmqA5fLzJoabvLLzqOXBiqEvHTcSo4q/GNXKCic56E/3ch7qJuTyuYC3WgRN1j2NljD/jGHcdFTxLiG5cOScqskT1uJ91Ely4Gmn5a9X0eExyuIl7yQShYYrtVKeY/O+JqenpjPpsOYovNx2X1yhIa3HyGNU+P5mWpcl6NFxKQZEOsZ16klxEV3LtvZindTt0UlGarpuQwnk5ZpHtFLYMjMF+kNQ0CPZQcDIsYchtn+Lx4GnVJXcTM5S2+CWuwVvuR1HoaQzLlE+1+GX1OtEqQPUUuvqZjjghYHXz6o6QMzmYgy0lov7pBsNGR6CR0w7vdfbA3d4IpE64mhqApO1ZsylA+k33zeOxLNpyOHn/8s7i27NhKdjuuS+co5PA454Nabq/b5/eUB6qUoNTffAToesZ11qwSKR9BWPuDUFiz/ODaEEY2Qp8QqUVPUdTzntS9v0GC6Mbc+ySuAcTW18CTDU7TSZPkJbURRStW5aHBXMAxTp8fkaYtqUPpEwajPF3+PfQs7M5eEmV9eheSDiLXE6qORg0CyqpPMzI/3NKW667xtdzYZIzqHXHboNTSObbOQU4Zm1QuO X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d46894b6-99d2-4b5d-ca46-08d8bd95a0e4 X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4572.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2021 22:49:22.2121 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YQjA7CnbBIh6ZhiEcQ3r0uBmB9ZNHMWAOtqk2XlfZ9qfoL2IAQSnCxV8fwdljfBQBGVqJfec6l2XLWpnM5T4BoSjrKZ9fJZnUe2yMWBPM+I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4441 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9870 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101200130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9870 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 priorityscore=1501 adultscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 phishscore=0 clxscore=1015 bulkscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101200130 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 Wed Jan 20 22:49:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 12033839 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 57DA6C433E0 for ; Wed, 20 Jan 2021 22:51:39 +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 06A80235DD for ; Wed, 20 Jan 2021 22:51:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06A80235DD 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.71811.128913 (Exim 4.92) (envelope-from ) id 1l2MK4-0004EN-3t; Wed, 20 Jan 2021 22:51:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 71811.128913; Wed, 20 Jan 2021 22:51:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2MK4-0004EG-0j; Wed, 20 Jan 2021 22:51:32 +0000 Received: by outflank-mailman (input) for mailman id 71811; Wed, 20 Jan 2021 22:51:31 +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 1l2MK3-0004EA-74 for xen-devel@lists.xenproject.org; Wed, 20 Jan 2021 22:51:31 +0000 Received: from aserp2120.oracle.com (unknown [141.146.126.78]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e69168c8-f7ea-44e8-80e7-4af8a8318284; Wed, 20 Jan 2021 22:51:30 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10KMoF5A110042; Wed, 20 Jan 2021 22:51:27 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 3668qmvtfk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 22:51:27 +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 10KMei61150786; Wed, 20 Jan 2021 22:49:26 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by userp3020.oracle.com with ESMTP id 3668qx3dcw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 22:49:26 +0000 Received: from SA2PR10MB4572.namprd10.prod.outlook.com (2603:10b6:806:f9::18) by SA2PR10MB4441.namprd10.prod.outlook.com (2603:10b6:806:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.14; Wed, 20 Jan 2021 22:49:24 +0000 Received: from SA2PR10MB4572.namprd10.prod.outlook.com ([fe80::4c5b:9cf:616d:b140]) by SA2PR10MB4572.namprd10.prod.outlook.com ([fe80::4c5b:9cf:616d:b140%6]) with mapi id 15.20.3784.011; Wed, 20 Jan 2021 22:49:24 +0000 Received: from ovs104.us.oracle.com (209.17.40.41) by BYAPR03CA0002.namprd03.prod.outlook.com (2603:10b6:a02:a8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Wed, 20 Jan 2021 22:49:22 +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: e69168c8-f7ea-44e8-80e7-4af8a8318284 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 : content-type : mime-version; s=corp-2020-01-29; bh=BW+rJtflc9PuVgftQd4YzA261OfzZZgz35MQdhpNXNg=; b=gSIABrviQfEEUc6re0vNe0/n8KZc33zhLuO2fUs74aOwrB23f5eNk+pKn9zTYKCshrTo EgYtqUXFbwTwzv/fIOPW0pYinZhARRZ7OIhHGNU+ksg9WU2HSIA3bT1Kk1ueSKW2ebKL y22vAkgXlgkj+Tw8zPrB2FcjeAvtGK0co4+/tObWqlqSiT5AZMOTjc9GToj4qUE3Lbtp iyxIpGDpct8zHqmCtaoiXRQ2rpZi9XRz3RzNAOmg7Mf2zxiFNVCCKyKowHS8EwC2tEMo SvhaW2FsHH0iL127ZxX2WiPNL/vi3gF58Pbo/EMmiSizC0j4hewDGLApYX/i2rtm0SfB dg== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AjWsE5MJ3TE7FYHyliceupau9blOwav3sHj5FhDrhaJ8oQstMJqoGfZ37GrYu9iCYc0q/brqw1nA7Q6x/lFYpPY2+lCBA9WeW01fcdgadvFOHmnhSNpkXUV/toGDohM0+5zTFpEBSzMk04J/r5s6mZdyLwJh+ORqh9fJDFtoZDEQI19y9mMdbjMOCkNcv+vKKouSZaTbrjkGjQA+/eYWVZq3xpK5j/K1p7J/tOXXV75jYG5DfvNNUb/G74sfp39G1mlk2RCFFL6/BPi5VRNcT0drYLndduMynRghAWK1t2EL7aSm6VvZGfPTF266GmrH5QKhPr6/GEyudi7jSNw6Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BW+rJtflc9PuVgftQd4YzA261OfzZZgz35MQdhpNXNg=; b=J7vV9+MNL29ice0rReANM9774mEQ0A8EXgyBOaHjriM/B7yDfHklUmnSc2SJ1JTFs501kXFAfLdeNNABB0iVsAdUPf5H5OxEApM9Q4TxFuaOkpSyIqCbLROLN2kFv1OriYZLsLiBFxcs1i7HXUuJLwZjA6Ja01Pjls6JI1o8rpM68XQDbsFqlWuQu75Dlfp+WM3OvGrVzQaj9Ecp5UxXP5biZ7/ffpTRHZ7o8yvsFvYcxI8N9TKH+DI3eAPt4CGu/+3zLehebkGo6hZcd68ucxGbadkREWF8NR4kGt9x0Ti2zZjwPBEURfG9pzKJoIMyBpT7hKtrEFgx1cPiaF6V+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BW+rJtflc9PuVgftQd4YzA261OfzZZgz35MQdhpNXNg=; b=WlmZOGFw7Gd5W4r0ZGBuqAJFXzO0XVyAufqfLmvkwbYbCYlv+HRbOTwuot2u5KhNgKMd26Go/7sbofqQgt67GnIIVXn8sv6svJPs/Bl2N39gnZ/YtK1/HLaMFyuukazHVAF2yl8fIT76AUE6BJ4/5pFhtpb1ifkbZKsjIFQfrGs= Authentication-Results: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=oracle.com; 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.ostrovsky@oracle.com Subject: [PATCH v2 2/4] x86: Introduce MSR_UNHANDLED Date: Wed, 20 Jan 2021 17:49:10 -0500 Message-Id: <1611182952-9941-3-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1611182952-9941-1-git-send-email-boris.ostrovsky@oracle.com> References: <1611182952-9941-1-git-send-email-boris.ostrovsky@oracle.com> X-Originating-IP: [209.17.40.41] X-ClientProxiedBy: BYAPR03CA0002.namprd03.prod.outlook.com (2603:10b6:a02:a8::15) To SA2PR10MB4572.namprd10.prod.outlook.com (2603:10b6:806:f9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9b4537ef-6994-45b5-d2f3-08d8bd95a1f8 X-MS-TrafficTypeDiagnostic: SA2PR10MB4441: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:935; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fVimmvSDgaO8CrG8tDVxDhU61aXb1woSWx7mZciXxD/fFDqidZGgZMxKibadU0+M4VpHl4hb0HWK0PVP+i6fhHWNeo0mQnYkUmB7h+3rBPZZNl99yd32edALrZPdsMP+gfWTCx01AnAVmL/GQj8W3n2GbKc6qGn7k/h9MorEDXJLP7gn6/2LB5g9AcDQ/YgIkajHtLYyqnBG+/sIh0RG9xDfEuV6IJwiYOsEAyewT2t8HJOgId7cfiSEc1sFxdkTTPJKoc6yp/9adFWPSanVxK2mjbbQSvNejN80zkT2Qc/BkGN0Ucj3O+k1+zZPbwH+dEa82cZA0wH9ogfNy3MOZfZHxb8Rko2bbv3gO5w/MbOxOMNtoS6AEQaRttzGFlgvSppABF1v/ETTJrqIoO6ogw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA2PR10MB4572.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(346002)(136003)(396003)(39860400002)(376002)(316002)(2906002)(52116002)(5660300002)(26005)(4326008)(86362001)(66556008)(36756003)(7696005)(508600001)(186003)(44832011)(6916009)(2616005)(8936002)(66946007)(6666004)(16526019)(956004)(6486002)(107886003)(66476007)(83380400001)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 9huH2WJBrUoPGPS9hPi7tfvnlDnLZ+KwWj5BfRr9Xex4YRwHLOi1Ithmy9bLimKwJbX9SpUCK9Rfmmc+WzmbUgJYMHIPxct91tcDb7Y9LWL89X/7yojWkJdhw1goPWitvLL2zHetiToC/IX4JGyIQTdZespuegoNE8VQoU45AYL0oXQn0zIPUXs0xHm9OKFcMmSoPIJ2xLmyK+jLlE3RquSqkpkgXhOBwMoNmqBrhKhkg99DJXchOTq5LDWfeK061FMu5D3UxwU9hAvqi5Ufi8GLxs8kHCPwjNBLHe9u0fejIaBme2TyPJjggY5NA61ayAwm8FVB7Xva1Mrh9NJX3xcGEMQXHSokPDz9onVR8ya5ACy6Fjt79GhAhdLJdG0Z6Kh0iuDsfY/1odvkUmtod/vkE63bVbikNgHxGLY9XaAJO4GqZZl7O7C8farEa+cEDgrdJNVjotXlmSoZFDc2QcaQ3WAYvPuJLMXF6xxAUU3cAj7/DNNEoBh6Uv00Gk/PD4WAohwclsZX9/P3Y+pKWytOhRz8r+nMeCMekwB9KwqD1a+KOqMX8Iom13ALwVTvBS0mXRjCkDrsYaxHoKhDNol4uJByOX49ymVO1t9HlCf9Ola5iIBaTEDF56S3lsrTSXjKbdbolvRMecSlPZ64MFmqnReY45ZBE5w2Aym2JoS9hdDl12G2Htgyzn0mnI/x91xemYHzvANmrk8NUb2A+PxsfAufRWMqDQrQ+OKOAzlkWENnnJ9CqQhDa48k1ubHIW5R62mP6h21iR0BAn4dFCdgwYqV+9Bhau2C7zK7ZSwwQ/c1zryGMKdS68+jIFnyGEtCQ+657KMv8uUrck2ce7klSCsXXCzB5IrTrbRViOmNtz/o+eloqANixCqGiCFxwhM/xi0p9jHGrtA77whzrZ3n2SKy7c8tkene/PdZr4ZvQIm4d3rkUQ0fc9VnJJE8++eyXsarXKbKDX/7S/opjrik0kEYvQuLMY0KwOgQXRAFJDMdJE4BkomaQLZoDRevfjpPDkz1R2ooY6abawhajMYM3kuUZVJyAX/X7DnPJeqtIQIgAOyuxL84VedOwVn9 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b4537ef-6994-45b5-d2f3-08d8bd95a1f8 X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4572.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2021 22:49:23.9763 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SfWvBVTOyiuqz0JCYRei2SJmYhzibiIVMck8rHFxZZU4uOlffgHbT2eMTDc85lZMS91OTh8nI9yhUu9qRSntNYBYSF++WKNSt7u18jZG/NI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4441 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9870 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101200130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9870 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 priorityscore=1501 adultscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 phishscore=0 clxscore=1015 bulkscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101200131 When toolstack updates MSR policy, this MSR offset (which is the last index in the hypervisor MSR range) is used to indicate hypervisor behavior when guest accesses an MSR which is not explicitly emulated. Signed-off-by: Boris Ostrovsky --- Changes in v2: * Use 0x400002ff for MSR_UNHANDLED * Pass ignore_msrs in msr_policy.value xen/arch/x86/msr.c | 4 ++-- xen/include/xen/lib/x86/msr.h | 17 ++++++++++++++++- xen/lib/x86/msr.c | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c index be8e36386250..433d16c80728 100644 --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -295,7 +295,7 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) } /* Fallthrough. */ - case 0x40000200 ... 0x400002ff: + case 0x40000200 ... 0x400002fe: ret = guest_rdmsr_xen(v, msr, val); break; @@ -514,7 +514,7 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val) } /* Fallthrough. */ - case 0x40000200 ... 0x400002ff: + case 0x40000200 ... 0x400002fe: ret = guest_wrmsr_xen(v, msr, val); break; diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h index 48ba4a59c036..fbbb3b7ba870 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 0x400002ff + /* 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..178203803946 100644 --- a/xen/lib/x86/msr.c +++ b/xen/lib/x86/msr.c @@ -40,6 +40,7 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p, COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw); COPY_MSR(MSR_ARCH_CAPABILITIES, p->arch_caps.raw); + COPY_MSR(MSR_UNHANDLED, p->ignore_msrs); #undef COPY_MSR @@ -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: ASSIGN(ignore_msrs); break; #undef ASSIGN From patchwork Wed Jan 20 22:49:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 12033829 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 E4669C433DB for ; Wed, 20 Jan 2021 22:49:53 +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 9660F235DD for ; Wed, 20 Jan 2021 22:49:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9660F235DD 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.71799.128877 (Exim 4.92) (envelope-from ) id 1l2MI8-000371-VY; Wed, 20 Jan 2021 22:49:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 71799.128877; Wed, 20 Jan 2021 22:49:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2MI8-00036u-SB; Wed, 20 Jan 2021 22:49:32 +0000 Received: by outflank-mailman (input) for mailman id 71799; Wed, 20 Jan 2021 22:49:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2MI8-00036p-2O for xen-devel@lists.xenproject.org; Wed, 20 Jan 2021 22:49:32 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3385a017-774e-43ac-ba07-acc6b5d7a700; Wed, 20 Jan 2021 22:49:30 +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 10KMmZHW108569; Wed, 20 Jan 2021 22:49:28 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 3668qrctw3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 22:49:28 +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 10KMei62150786; Wed, 20 Jan 2021 22:49:27 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by userp3020.oracle.com with ESMTP id 3668qx3dcw-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 22:49:27 +0000 Received: from SA2PR10MB4572.namprd10.prod.outlook.com (2603:10b6:806:f9::18) by SA2PR10MB4441.namprd10.prod.outlook.com (2603:10b6:806:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.14; Wed, 20 Jan 2021 22:49:25 +0000 Received: from SA2PR10MB4572.namprd10.prod.outlook.com ([fe80::4c5b:9cf:616d:b140]) by SA2PR10MB4572.namprd10.prod.outlook.com ([fe80::4c5b:9cf:616d:b140%6]) with mapi id 15.20.3784.011; Wed, 20 Jan 2021 22:49:25 +0000 Received: from ovs104.us.oracle.com (209.17.40.41) by BYAPR03CA0002.namprd03.prod.outlook.com (2603:10b6:a02:a8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Wed, 20 Jan 2021 22:49:24 +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: 3385a017-774e-43ac-ba07-acc6b5d7a700 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 : content-type : mime-version; s=corp-2020-01-29; bh=dCXkXSta+TTp5MqacSTXoq1rfECu1lT3kCVoJmd6hDA=; b=tcRmiUQ0F19LuHVDdAMR5/CM3NXQL7spHgWFGxLsB0CmlD3VPm0qgMtI4oYOQ98tGuDQ K2XcGk88D032goW9agTHzwYsqxDTOvjf144FGM4OQDEqBH08jhATIoVYF2APPcOOAAgY sduXhmPV8SXH7zUOkE9l3fMQ36zJmA4M9Knb9dn8hgev6/I7wUm+AZSK6sycgYXMAKpP m+yWvKCEkMsmMJpDs3/DLByb2TaiN/JTeb7o9rx83SiPdVcL4hPMBGYCJHoMhudhm9CC Q0/tARhEk80CP3j/bEKbTucweDfKEUz9Caqv7BKSMInlpjk5S9BA6fLt1l7D/5DEn5K3 ZQ== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hE2SOXghGeHsyNcoK1XZkmskvD7M8v5bXR9M0yRl47/lkfgoOYI9kDdOyGrDrxic7C4U+1+z8Fic39ujVCACXuTRH61le7W+vGfx94nVeJUgeCqgJenhiaygNytiInx0QlWpZScObtP8AzQ1fo2vyGHJb0HmwaApi5wVK4hwDvogzdtfQm2qZpN4lP9b29ZQgnt37nr1V3vpzzv6ywgzDuRMXnfFyYLGh6197IkejvJwKZPgIKUZgXMbwJf88gYZvBS6ry7tO+rU+lZuiccqBbrKYooVvHh2ci1yuHo3xAS0aLvBF6KrOxWvf/pe0awTXOT8QpFgTzDX93RwZA9blg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dCXkXSta+TTp5MqacSTXoq1rfECu1lT3kCVoJmd6hDA=; b=Uef6ywOxhlEpLqt+Ltva+/oA9tHDR3jAOQ4jmDLTXdpk3usN6wPUxWUkwT449r6v8UPMWXGK20/pBlWKIbWqBTSfKQFOZQuj+TKv5h5F2p7ikTuzcNLWEGCOifTjXWqVX1KsBSYJGVO23IXEMQoRsXgkM8Qh/d6DjgWfaHYa/A0cxqfMc1JxN23su40u25dKrJ8BE/guBYPiC5rPRDSwfnMFJDFuBpZFafJw/Ejn/o0YxM6+Ha7HOupSaf0HxleYCBPqllIHAdUJZe4vfg/dF9alzhoFGsR38mzTrYn/N6yoQyz5oSshE9KHZjHlirHLChHewbpTw8mt7D5cAJRpmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dCXkXSta+TTp5MqacSTXoq1rfECu1lT3kCVoJmd6hDA=; b=o1w1mdaiN0vrrKHvOQJgayjIXNpThRJJPf2Ggw/SE635dj5sy15Xi9THALK+CATy64Cob8m2Chpz2DGFbCPRqReeR5OcZSixwVgNx+WuMZFSwwROFy9ol19tjNu5eHqk5NKw41v4e5lhLyZTf8NiYtXwo2viSD02VENInNCGNgE= Authentication-Results: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=oracle.com; 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.ostrovsky@oracle.com Subject: [PATCH v2 3/4] x86: Allow non-faulting accesses to non-emulated MSRs if policy permits this Date: Wed, 20 Jan 2021 17:49:11 -0500 Message-Id: <1611182952-9941-4-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1611182952-9941-1-git-send-email-boris.ostrovsky@oracle.com> References: <1611182952-9941-1-git-send-email-boris.ostrovsky@oracle.com> X-Originating-IP: [209.17.40.41] X-ClientProxiedBy: BYAPR03CA0002.namprd03.prod.outlook.com (2603:10b6:a02:a8::15) To SA2PR10MB4572.namprd10.prod.outlook.com (2603:10b6:806:f9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 77d7f799-3921-46e2-a7a1-08d8bd95a304 X-MS-TrafficTypeDiagnostic: SA2PR10MB4441: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1186; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1K5vKl67xC4MlDEofZ+oa83UTVz9k8vs36TZTxr4ohEWjUU573Cq/l1fLA8HLZHYlbRhNzVElVuKlQULgQb25JhblrgV6FbKR/eL0Z4jHoaDo0bxQCx9eDVmfhsM+eMJQFcgrGd45rplwn2r+qeTvU1S1s7RuRh2Qt2MvBqEqbLFawk98TOoT+9dPDLJRlpREEud/SN9e83nPTL086P9eK9HwDKN8ljknyAf4Udrj7KY+4zgYIBKUuAQuGLJSo3P+fIjIi8gZlSxNQe2nMmJoBOthB4cHJE3SQqYtqhJ4Ah2g6Ai08TERUhIuVv/WZ42VBwWSQLeCHFNAwtC8wm+7p1PtqZqBqb3vPv2Q5c/8N/Wh2U2YKz8Wi6qe12aw8pqyQkZ1QAT/PPZqrsOVkZm+Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA2PR10MB4572.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(346002)(136003)(396003)(39860400002)(376002)(316002)(2906002)(52116002)(5660300002)(26005)(4326008)(86362001)(66556008)(36756003)(7696005)(508600001)(186003)(44832011)(6916009)(2616005)(8936002)(66946007)(6666004)(16526019)(956004)(6486002)(107886003)(66476007)(83380400001)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: f0r9v+GbN2MwVeBf0w8J2zTUuHjXyGFP2x8w6DFokhiG4dQ0aY0hTFXKLCVX/KKtEqFZo6zcY88Bd6CmmXYlckmLVkbgh13vE7Ia5W3mS1CTjL6gKhYJ9adDEprdM6jKLb7rNxs6OE5p0eQokNvVG+RfheLW3xwNiaOnORwXT8gGvqbVJ8xdDBpHthEx9VPGXBzXPFD7YXKti2vOpwbh7KkWn66o8u2AaO2R3agRvIe9Oh9l7O4GjhmTra7DnBuPtjEJybjaJCVjshBDT/mKcHZgPrrNZ27WXLMWw0OZabSoJc3M/LHachReyipZKd690ipysoTm0eF98KIpBUgpoQTjw6dkaGllXrRtgEAUS51mLSY6eFXKW/chL1VQqw3RhkKFLkrCd9H6+/ctpTbeLAEoWLtw0eswhEmae4YWczwoEg4m+kXT6q3BA5Ku4Smq0ulMzBD0bYmnP8jcGweEPCY4U1DXIRVMC1VKfrNkKIuXwy96w4y9QFuuGMkinK64hP5Qcdg1uVbVxuF+Jd/RI/sF2t9frbOoYsCFfw3Ajt8B4Iorl6YbtOkSHbu8HG2SySEMc6AHY/aRQl37Be+/aY5iY8DnWVAqCN45BVs9b8DMJ14MI5D2lp51V0QDiYvKwfVI2d4LiR4U5Xji9RQ7118CixHJ8AexOFJkRwHGEPmphRZoSAqvjZ82RC4aMd4a64wH/niRx0IfVfUEg7q1XTKiwMpfcQJPTWNjdirfkS6Oh8u2FhjnxFIffr3MmnNarj7BtY61So1hVf8nKhgHMvSciZAfQGl52opVdJbZ43YeaA3vMimoRQN8GAlKq+Am+J41nYhQ7r0M/2WnFMuDempPE+KJgYOO9XI2tMihsHw1Qxt0CRdRgwJNK1zqZHriVjPbvcOTcLR6yoeiyPsaxAthFmbiGkRubpPTrn8m/PuBgIUx2WiKuHAh3O7vtc6NWsr8s2N0FGt7SIiS21fjTgXgPAhg3FfLfCudU66fAUv92U87XlNYlY6nNPFmEbUxOk7FZIXYx4KoSvgIp53MXi9N4aTESbsaytUTlH09lNcXZ0Ga84GJdIU70E6/0P09 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77d7f799-3921-46e2-a7a1-08d8bd95a304 X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4572.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2021 22:49:25.7146 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: c/0kJfC+7nrAVGBOjI3a3L4m+XOAt3Drj5LrolztTwOe7LRmfLLxpzpNyh/sI2+DwPI4A5/jGvLEtCuoWIIlzZ/yk9wN4PSeIeRWsfr4sDw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4441 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9870 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101200130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9870 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 spamscore=0 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101200131 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 --- Changes in v2: * define x86_emul_guest_msr_access() and use it to determine whether emulated instruction is rd/wrmsr. * Don't use ignore_msrs for MSR accesses that are not guest's rd/wrmsr. * Clear @val for writes too in guest_unhandled_msr() xen/arch/x86/hvm/svm/svm.c | 10 ++++------ xen/arch/x86/hvm/vmx/vmx.c | 10 ++++------ xen/arch/x86/msr.c | 28 ++++++++++++++++++++++++++++ xen/arch/x86/pv/emul-priv-op.c | 10 ++++++---- xen/arch/x86/x86_emulate/x86_emulate.h | 6 ++++++ xen/include/asm-x86/msr.h | 3 +++ 6 files changed, 51 insertions(+), 16 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index b819897a4a9f..7b59885b2619 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, true) ) + 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, 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..87baca57d33f 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, true) ) + 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, true) ) + goto gp_fault; } return X86EMUL_OKAY; diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c index 433d16c80728..a57d838f642b 100644 --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -164,6 +164,34 @@ 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, bool is_guest_msr_access) +{ + u8 ignore_msrs = v->domain->arch.msr->ignore_msrs; + + /* + * Accesses to unimplemented MSRs as part of emulation of instructions + * other than guest's RDMSR/WRMSR should never succeed. + */ + if ( !is_guest_msr_access ) + ignore_msrs = MSR_UNHANDLED_NEVER; + + if ( unlikely(ignore_msrs != MSR_UNHANDLED_NEVER) ) + *val = 0; + + if ( likely(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 (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..6b378dbe2239 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -984,7 +984,9 @@ 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, + x86_emul_guest_msr_access(ctxt)) ) + return X86EMUL_OKAY; break; normal: @@ -1146,9 +1148,9 @@ 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, + x86_emul_guest_msr_access(ctxt)) ) + return X86EMUL_OKAY; break; invalid: diff --git a/xen/arch/x86/x86_emulate/x86_emulate.h b/xen/arch/x86/x86_emulate/x86_emulate.h index d8fb3a990933..06e6b7479f37 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.h +++ b/xen/arch/x86/x86_emulate/x86_emulate.h @@ -850,4 +850,10 @@ static inline void x86_emul_reset_event(struct x86_emulate_ctxt *ctxt) ctxt->event = (struct x86_event){}; } +static inline bool x86_emul_guest_msr_access(struct x86_emulate_ctxt *ctxt) +{ + return ctxt->opcode == X86EMUL_OPC(0x0f, 0x32) || /* RDMSR */ + ctxt->opcode == X86EMUL_OPC(0x0f, 0x30); /* WRMSR */ +} + #endif /* __X86_EMULATE_H__ */ diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h index 16f95e734428..e7d69ad5bf29 100644 --- a/xen/include/asm-x86/msr.h +++ b/xen/include/asm-x86/msr.h @@ -345,5 +345,8 @@ 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, + bool is_guest_msr_access); #endif /* __ASM_MSR_H */ From patchwork Wed Jan 20 22:49:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 12033831 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 4F571C433E0 for ; Wed, 20 Jan 2021 22:49:55 +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 E20BC235DD for ; Wed, 20 Jan 2021 22:49:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E20BC235DD 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.71801.128901 (Exim 4.92) (envelope-from ) id 1l2MIE-0003By-Kv; Wed, 20 Jan 2021 22:49:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 71801.128901; Wed, 20 Jan 2021 22:49:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2MIE-0003Br-HA; Wed, 20 Jan 2021 22:49:38 +0000 Received: by outflank-mailman (input) for mailman id 71801; Wed, 20 Jan 2021 22:49:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2MIC-00036p-Un for xen-devel@lists.xenproject.org; Wed, 20 Jan 2021 22:49:36 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id aef0beba-4a20-47e6-8d6d-8b02c1af16b5; Wed, 20 Jan 2021 22:49:33 +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 10KMmwgN109063; Wed, 20 Jan 2021 22:49:31 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 3668qrctwc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 22:49:31 +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 10KMeh5Z150753; Wed, 20 Jan 2021 22:49:30 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by userp3020.oracle.com with ESMTP id 3668qx3deg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 22:49:30 +0000 Received: from SA2PR10MB4572.namprd10.prod.outlook.com (2603:10b6:806:f9::18) by SA2PR10MB4441.namprd10.prod.outlook.com (2603:10b6:806:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.14; Wed, 20 Jan 2021 22:49:27 +0000 Received: from SA2PR10MB4572.namprd10.prod.outlook.com ([fe80::4c5b:9cf:616d:b140]) by SA2PR10MB4572.namprd10.prod.outlook.com ([fe80::4c5b:9cf:616d:b140%6]) with mapi id 15.20.3784.011; Wed, 20 Jan 2021 22:49:27 +0000 Received: from ovs104.us.oracle.com (209.17.40.41) by BYAPR03CA0002.namprd03.prod.outlook.com (2603:10b6:a02:a8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Wed, 20 Jan 2021 22:49:26 +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: aef0beba-4a20-47e6-8d6d-8b02c1af16b5 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 : content-type : mime-version; s=corp-2020-01-29; bh=Oj10fCSZwO/WpTZ8RIssk6cUWjwKr9DC0gs2ITsGH3s=; b=zwuPQYXN5PQ6X5aZkvt+mwS+BTwJEYYbxZQqHAYMD84LuOiJHIqFECuu2P1IrnXxt9WP fNfwWXOg2wgV3/QTcpqlmF3sJYVcqW6qmL93gyJVh8GviwU5j3oV/80GD+bPihqkSPF7 cNtrEyBbzC+qs4hZRvSbYP5e+POkef8X817zmpGMI0nzsoBgNvy2cQ7lLbuUQho12Clv +5eI3cO12ebS9zqemyeuazuZ7hZUyfF19b2jp2pfYjU8gJ1L8QrvCYbV2TkY3aIEgqZy Qz7HEquRRTNrmJh7b1pQH+Y+DhHZNRQvBVJ8T3pFmwrxx37ogQ6lhOKZ7rgFOROd89UF bw== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NmnnoGFtaY4BQWSHjDG1gHOR1LmrsMsUbs/RZM4e70atfciBH0N2RZox9TO3TanIn+siqdJqM0RTsd6tJ9Fzj1kUWuDf66B6VW5rXbGsXq87Y7rJLOgGBOuxqva499cgcn+1/QtsQ370AmImCXZwwuibF3ESjdkOSUmd3MK68vIU1sq62RodUsTpEOVIsUvfhQ5mZG4ltYlzJuNOzUqXWrVYDv5+nPg/xnWDW7gViYyAHjIDpNeB5axStrKPZ6RN8FAjDNkDKxMBLmaSHGECCJa2vpYbxvbdUGMRjADMPlavOhByDopp2pgDwjynEDt4+xdmGr/a/nSNJgLUvO2S7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Oj10fCSZwO/WpTZ8RIssk6cUWjwKr9DC0gs2ITsGH3s=; b=fFiulH10inlrgaYcvufe+jNX81eP6R3YjauHQHGC9y6MQU7tt913tUunrL4fWtVodFdq/4LjPFhiaO4d6muHo64PZabPFKSG9asBvwuD6qzoPm+xJqyJBipDjbln5Jw8KT3UPBpefOEGlT/cBARhrjs2kGX+jihrrtalovHz1I2dUdt7noc0vr5iRdapgbbvL2tiHvs0gUUIAcsUpqRqcoQJPmtQgcL+9nvCBN+mIwdHeYSOwi3ZNqXmD4sPvHiUeRmy7MPaeMC1iEiwURuJVvAkj8rkR6nH1YHQRwD7e6oeftCbjHJFTc6A1CiAzbXFpYOhvdj7wOJsUFzA/kZStw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Oj10fCSZwO/WpTZ8RIssk6cUWjwKr9DC0gs2ITsGH3s=; b=R7GaKCHgfA3VfTPDsPGR3RQXOaOmYewTkrUpXFSm2Msw/2cF9SclA1hYHRIm7vODkOMlnGJ3BpmMAVYDkDZe29SYfgNEqXvn1ObnFBc3ZlOuZ9zgjW/xAJBfqi+mXaPwEajE2ubhqDZgOttaSeFlWjsCUkraHU+5YRfNtPzI88Q= Authentication-Results: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=oracle.com; 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.ostrovsky@oracle.com Subject: [PATCH v2 4/4] tools/libs: Apply MSR policy to a guest Date: Wed, 20 Jan 2021 17:49:12 -0500 Message-Id: <1611182952-9941-5-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1611182952-9941-1-git-send-email-boris.ostrovsky@oracle.com> References: <1611182952-9941-1-git-send-email-boris.ostrovsky@oracle.com> X-Originating-IP: [209.17.40.41] X-ClientProxiedBy: BYAPR03CA0002.namprd03.prod.outlook.com (2603:10b6:a02:a8::15) To SA2PR10MB4572.namprd10.prod.outlook.com (2603:10b6:806:f9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 36d4a4a2-07f3-4142-6296-08d8bd95a418 X-MS-TrafficTypeDiagnostic: SA2PR10MB4441: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:843; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FcgBnX9irMxE/1wNEXqHvGpGSPLmGc+THehLl3bk3a/ZGa7sjGvltG8lCB3oIUp0B64xX6/ZhVul6ARr9vfIbWxFy09HlqyZRJYsfUfogIxNvbly73CrgRBH+kbBRRRXf6g0/eoqNwd0oUju5/ejToq86s8WOXaxHSjqZ5pY/i7zeE9uOqr7PXw91tUdX8U6FI+7IXvRq0ggxvQ2s2YA93HQeUpLRhZH0Y6XIJlqpX+JCPeHxVXOrHNzhMw+dt3jqzKNUClmYJVWeR9axanLNYDLxRe78/3v41CkF23DyncaFXtfqKUrwKKc2pSkt4G5aMoOmyMGVRxZbrozshj98sPf/81uoVnDt98FziZeKTzTdQEqaw2dl1UANRdLXb6ypoIQoVNCWxM/KkP/Y6+jPk8Nw9OX3RsZ2DxuPd7odKkGj9SigCPqJUuHvOVJxpRvT53vHSvT06oFG5D3MPERB2C9iEGUvdxrlfmjZLTkRbZS2hW5lqHvvbsA/E9Vo9ZgKsq+51faUPZOKUeX7+aCVA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA2PR10MB4572.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(346002)(136003)(396003)(39860400002)(376002)(316002)(2906002)(52116002)(5660300002)(26005)(4326008)(86362001)(66556008)(36756003)(7696005)(508600001)(186003)(44832011)(6916009)(2616005)(8936002)(66946007)(6666004)(16526019)(956004)(6486002)(107886003)(66476007)(83380400001)(8676002)(2004002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: hAWrZxLWJlQO5G1J7MBE5Yk9JqVbO0B66YMtMPqV31+XVtE57xEsAGfZT/Q2AaruZwmHUVf1+WDPkj+EjF4YQkhhNukr32dV1resjRs5oHG3Pvd5Tu/l7BKu0tp5Rg18xyqXXFv4P6DC4s+PEruqm8euofBBOytHxoaksKNkqCC6WPU04nWOFMMv+Etw1LTsuwc6Pwl9AKUD5MKFyHXld6XqYf6s1cVRwekpVzNhkRAyRptUSl0gzFoTUiCD/wci3+zdaukMcR190PPsRbEkiEXkdHkohvafTStij7qg2svkVC448OQlq25135kuBoacSV/h9Q3S11DCmtpQfrhJVcCt+EzPRLlqYygMxlPuqkO5/PiStbXkGnSePvLy8moB66bDKD5zuCAgZdkTu7OyA1V/l43fhnbHlO4zmdAzDGe4hAcGovtFYtfYz8ODiu3xCNIXDSuedRD4D9BtDArjvKykFfE/sc3Ynq4l9zjQkl9yZXmQs/H7hTMpEdBHjC7SKnEA26yt8ErpGWeS+gvdSXuT2noOokZdOzi1s4tjq1BguzWhMKMkzJCruo++h79Ynj/hW7qWzM3OuVeTyXdw7TX0nLtlPa+VxLcEVE9UclKoIkFAjUbtLKM8FMoI6uZ+jOgyrmXwrnrT4kiZc/5soSrTLtOLVxmKdE9wFyUIWVUuUVIsTg/gNxbBEkRtVw3q0S8r+5mTCpdRrM3UmMxL6b23WhuFk11zSgJg1LbCweOKpcufzBFWd3zGPIjvTZ2XPmj0NakzlOtIcj29q4DDJQMNkJHyvZVCwB7nStO2qAprg3XDU0F3D2RFZi96mcmEDYMf3H2VycJhQXNH4NLaxElwVwyUJs6wo8kx24jQe7kYNaN7DobCKywwYxp04b1KsUtC89OUu8Q0QAccIpaPBHVJPOKSSbrGlfNEqrEoRMP4Xg9PCBoFaRD4TMKhyxRV0mDkoR1DWtYpM/J550o5++GHtB4UrIgIJjcXD93U9bV8zHfWvs06yiWO2OdwutaL8apS94MjP4E0Wt7L3Kd7bcpv7VORAssBmbMB8vBZ60Of0E16yIfQDWAvsY4C8XtJ X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36d4a4a2-07f3-4142-6296-08d8bd95a418 X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4572.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2021 22:49:27.6282 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lC+1Z/YlEHc6Wc4zIjb+97iDzwfvdriZJ8YqgTdv90WWl+dZu3nHYukzR0iDsAQXWwOl6YBVSpmeG3i4vknfL+Ul9MTOcODIQzWz9Ow3zlk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4441 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9870 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101200130 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9870 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 spamscore=0 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101200131 When creating a guest, if ignore_msrs option has been specified, apply it to guest's MSR policy. Signed-off-by: Boris Ostrovsky Acked-by: Wei Liu --- 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: