From patchwork Thu Mar 30 11:30:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13193990 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 96BA9C761A6 for ; Thu, 30 Mar 2023 11:31:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.516651.801123 (Exim 4.92) (envelope-from ) id 1phqUj-0003aH-DR; Thu, 30 Mar 2023 11:31:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 516651.801123; Thu, 30 Mar 2023 11:31:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phqUj-0003aA-9B; Thu, 30 Mar 2023 11:31:05 +0000 Received: by outflank-mailman (input) for mailman id 516651; Thu, 30 Mar 2023 11:31:04 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1phqUh-00017i-Tq for xen-devel@lists.xenproject.org; Thu, 30 Mar 2023 11:31:04 +0000 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2060c.outbound.protection.outlook.com [2a01:111:f400:7eaf::60c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 598ba096-ceee-11ed-b464-930f4c7d94ae; Thu, 30 Mar 2023 13:31:02 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by PAXPR04MB8782.eurprd04.prod.outlook.com (2603:10a6:102:20d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.35; Thu, 30 Mar 2023 11:31:01 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::154e:166d:ec25:531b]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::154e:166d:ec25:531b%6]) with mapi id 15.20.6222.033; Thu, 30 Mar 2023 11:31:00 +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: 598ba096-ceee-11ed-b464-930f4c7d94ae ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YlLFKeR6RaPhYnHgeHi9MiqyGQdzUGh0q2Qywecje3WrA+tU1w5U77WBEGEw2Xeiobf0zpU8bbWtvQxi+nH93oJU3mnvOgf9AOUmoEPhNxrfg+LZyYbdEHOosznCSAGpa6RmToZlrq/vghEztF0x900XZsdRRaCEhAuBhZnylKyayIFdWNaJyMiQREubUgtIUPpBmoSerJczcy4QFcEF7MvpGNVgvYA98S9wyPe3q9kl7KqvoSVRgPYaX93cknWJhl8OuBPcOvLZtPt49ceNAP7JpST+GbIZfHyUrYIsff45510Z+HEsn+wFCU4kLPkuvH30cweOpzoxWPRzIv61kA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8un3XXWErGo1I3D86zB/Aw1v47GFYml06HHbcbR4F10=; b=aXToDlwU6bLjvXIa8bB/Qq/aakYoQ7qmDijW1UbZ8ENPOvfQLMsp9UDgUGO/VxPHK7jaw6Y2FefJ2j6M+gPfre+/a3WNYlBG27Unm/w6tWoIIyBG6W+Ts0xV4exwUALor/7c5Kt0iNdR/vjahQDDn5GxukQ+QR/jfSbkqWLFUbP3D7sn2EEUZ8rfurJFm4LsxO9DeS/Clih9tGdsVM0rQugHiS0Uf9siKJUsyAqwPJlHxThGW+zc5lTmWeov/m33mBjYCpJ2HC6vg7clw6f4gA/rxIzoUzqg67tO7aarrYcxkEsvidAgOiPaN0hTyCfatBjT/HmJSM8if9nmZctFAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8un3XXWErGo1I3D86zB/Aw1v47GFYml06HHbcbR4F10=; b=bwYI92QkfbsiXyVCmwFAdQPFhB0zDLAWld4Qhv7lB4JtLT0LWkxgf8xrsPn/7Mi86ZWVQnKiey0NTKgOmfr8tgnd/hbDXjIhpJJShqsscPmn9FI4baAvxq2zphTVE+mvo/gjxUSFZDgFqunWBC1PapssytRH+NYgX9x39BL91dDOuATv9Gwz0rA/5f5Df9Qw0CvNnS3QLt6fEg2bJLT1LssPUpDTFqAa2sWMTiZ2tGtoMhJDasqOB4/kAylQIF52Dvp82VFw0zRGgZbrwG4EaOn1XZgvX9X0CPpX+Qn6petWykr3RXtGYaf4wyHYssu6kpUNBqXmJdXz1HtxOpkxRA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Thu, 30 Mar 2023 13:30:59 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: [PATCH v2 10/13] x86/shadow: make monitor table create/destroy more consistent Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , George Dunlap , Tim Deegan References: In-Reply-To: X-ClientProxiedBy: FR3P281CA0192.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a4::16) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|PAXPR04MB8782:EE_ X-MS-Office365-Filtering-Correlation-Id: 8132e925-4bdf-4ba7-058a-08db31123d1d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pmFGJKVfiuH0X/TqlRbWLCnJ/kQSgAWMcAYCJ67NT31FdZII4NauL61ohuKLjlfmI1R5ZMXfMqx2p9rQ5dxmaIMDkfrbhD1w2E8Ai71LNMMbm44bjwtFy98Hz7LSqOsGIjx4Tz3YEJV3/idN6eubibPqQ8kFIC7tsLNSBWEN8mUWczM9xHbnLnfdMsK8lDqPXhli1uiqj4+mChlxca7Lv7LaUtQo8exxHLHJv7y8gFerDQgW6e7Yng564s/InEK/MyflWLovOtHrwbuMA+BJ2omvE3qCeB9v6vWU/hePkLk9Eu8rbRzO0L9sbenzVbP53+fpUC7JygRAnf6EnB/1LCUbp8rLiyZnqblD9EYGQKvj1YQsXM0v7ZN3RsWSj/w/Xwh42aQrfkZWDNNTa2aTlAVesim6u8gx5P8BQCGnrjr8+9w+N+jD4DQMbVqqyPRM/cdIUtZfWwhksY6+b0fEE/r7wKuWq9pi2/wAjxYJxQoDSkv9XxB8uWFhj+CkD+0WdeqzdnkyPXuCVFReYvzvssLfbre9OVN+1waqieHFBPxypKQ0cQRp+M9WhyddLuefjB6u5nD2l68wtHMMS0UkVSiSP2frrbXc607vW1wEISu+hRd0MkUHbsvQxBkTIejSbQiGVgWC4DDuHNsrk3ae4oiC+p6SJteP/obP0LcVcnXUEdR778E41Bf2F3L3BwNU X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(366004)(136003)(39860400002)(396003)(376002)(451199021)(316002)(66556008)(8676002)(66476007)(54906003)(6916009)(5660300002)(38100700002)(41300700001)(66946007)(8936002)(186003)(4326008)(2616005)(6506007)(6486002)(6512007)(478600001)(83380400001)(26005)(86362001)(2906002)(31696002)(36756003)(31686004)(66899021)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?4WfyvxtabKAgxW6t/JtI7CoCSlBv?= =?utf-8?q?eo66k1o5W5BKNG8rmpiBT5oZNsQx6HwcKYxfQU4f6/yVbRljk8Qnnm/pAIer+LAzG?= =?utf-8?q?XZJIq8rTtYigshZNZllU4ClNXCgg3jVHomNKKf/ox3AlZgJnKwa7EA3WiUAgI48zY?= =?utf-8?q?S/cUeyu46RYFbhSJ3WVqJ+jfI+bOIZpYUJ+ieXimwwp4rUe0YHfoKl47FqiYtJYkA?= =?utf-8?q?BvF2/Y7ynFLArbtFjU7E8wH5zBvmt5wb4B7BWMGEs4SylTw5nOjHuBFaW3xWIzR/G?= =?utf-8?q?ExctvDivKfXF6v2MAxzAbSkeebgM40NcG1Is6KZQEm6K7GroThhPyauoF1XM3ek6b?= =?utf-8?q?F8vonEoJEZvlf6UgwHRXizekGHSHvI3zLbCvNx4nIzRIBChar8NzwskdiW6U2WGYy?= =?utf-8?q?KaYZ+q/QgiYMxzaXHAPgGkFzlMBwIxUhdDsuGzSFfSDTaMyHRNF/uQ4/SzhfIU8NL?= =?utf-8?q?3mXlyCYrgsqnsgbl+4wlUyja5WQwWSy9jp/FOp2tuS4VlhdKz5yboDH0Dhdv27A9M?= =?utf-8?q?x4Uj2IGhQS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JaGisQNWnEUtm7YgwLZMv/cVSVhxbq/fDAMRDysxq?= =?utf-8?q?Vvcmsjt52nFkvelwPt/XzMwekdb6Gj2I5iSB6IJEJFLKNTevwanUQJr2TZmiCwkzI?= =?utf-8?q?h6fJ72eqn2r4?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8132e925-4bdf-4ba7-058a-08db31123d1d X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2023 11:31:00.9072 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bvNQRdLzgnYkDnoKIuDBaiIzODn/iX4uP33cF6BCbFAEC7ab0Bk50EAODqWAkyFJ/Pkm5ihvBJUaFIilgxutbw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8782 While benign at present, it is still a little fragile to operate on a wrong "old_mode" value in sh_update_paging_modes(). This can happen when no monitor table was present initially - we'd create one for the new mode without updating old_mode. Correct this in two ways, each of which would be sufficient on its own: Once by adding "else" to the second of the involved if()s in the function, and then by setting the correct initial mode for HVM domains in shadow_vcpu_init(). Further use the same predicate (paging_mode_external()) consistently when dealing with shadow mode init/update/cleanup, rather than a mix of is_hvm_vcpu() (init), is_hvm_domain() (update), and paging_mode_external() (cleanup). Finally drop a redundant is_hvm_domain() from inside the bigger if() (which is being converted to paging_mode_external()) in sh_update_paging_modes(). Signed-off-by: Jan Beulich --- v2: Style adjustment. --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -129,9 +129,9 @@ void shadow_vcpu_init(struct vcpu *v) } #endif - v->arch.paging.mode = is_hvm_vcpu(v) ? - &SHADOW_INTERNAL_NAME(sh_paging_mode, 3) : - &SHADOW_INTERNAL_NAME(sh_paging_mode, 4); + v->arch.paging.mode = paging_mode_external(v->domain) + ? &SHADOW_INTERNAL_NAME(sh_paging_mode, 2) + : &SHADOW_INTERNAL_NAME(sh_paging_mode, 4); } #if SHADOW_AUDIT @@ -1811,7 +1811,7 @@ static void sh_update_paging_modes(struc sh_detach_old_tables(v); #ifdef CONFIG_HVM - if ( is_hvm_domain(d) ) + if ( paging_mode_external(d) ) { const struct paging_mode *old_mode = v->arch.paging.mode; @@ -1864,13 +1864,12 @@ static void sh_update_paging_modes(struc make_cr3(v, mmfn); hvm_update_host_cr3(v); } - - if ( v->arch.paging.mode != old_mode ) + else if ( v->arch.paging.mode != old_mode ) { SHADOW_PRINTK("new paging mode: %pv pe=%d gl=%u " "sl=%u (was g=%u s=%u)\n", v, - is_hvm_domain(d) ? hvm_paging_enabled(v) : 1, + hvm_paging_enabled(v), v->arch.paging.mode->guest_levels, v->arch.paging.mode->shadow.shadow_levels, old_mode ? old_mode->guest_levels : 0,