From patchwork Wed Dec 21 13:27:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13078767 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 8DD0DC4332F for ; Wed, 21 Dec 2022 13:27:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.467903.726967 (Exim 4.92) (envelope-from ) id 1p7z86-0005Z5-UX; Wed, 21 Dec 2022 13:27:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 467903.726967; Wed, 21 Dec 2022 13:27:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7z86-0005Yy-QL; Wed, 21 Dec 2022 13:27:30 +0000 Received: by outflank-mailman (input) for mailman id 467903; Wed, 21 Dec 2022 13:27:30 +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 1p7z85-0004I8-Oc for xen-devel@lists.xenproject.org; Wed, 21 Dec 2022 13:27:29 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2089.outbound.protection.outlook.com [40.107.13.89]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 371b1f6f-8133-11ed-8fd4-01056ac49cbb; Wed, 21 Dec 2022 14:27:29 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB8582.eurprd04.prod.outlook.com (2603:10a6:10:2d9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Wed, 21 Dec 2022 13:27:27 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8%4]) with mapi id 15.20.5924.016; Wed, 21 Dec 2022 13:27:27 +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: 371b1f6f-8133-11ed-8fd4-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oFI+7A7bB0bMZXnCezAEFai+PMf+hrNYXFT0H7ajeaeOifwGT4AA6SCHZOURfCbv1R7Zts0iZOkRGj0aflaovT/IxK5eMKyADNv0YXFusrnRUNIoNbS8vSklL4DORAypVrkoep1BXzPmVXseaRabze4odXRYn/l6XgGPyx25Mg51xbUkXmXnfD0kwwvVx77Z5sUB1ocoiTUZ6Ynwm2Y9i3/Xwuv4camQeFMbL/kHUx53nZ8kOcehXPtIFiiLuM09fnrABviZxm0nNYDg16SPCJ9IGmKIIYFA9GRWZTy2h/RPtTq20uGR9aC/sOEtSKWlfrIOteFOQZficjZHPa9eXA== 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=1niUsk5aDtIhCowAMZf6eTqYxpgtxdoRIXxLB3FTKzg=; b=SkrBSxbozIkHxw1vAoemOx7uep0396Lk8DUUrzTuBDZpKjrGUthVOuxVkyA/he4Lz/n73Yd9gv08uI3EwEI+gfzqurn+aFLV55RiwTgYhHtd2SUowYVdyyZTgRDU5Q3YpIdauzg05MXA7P0qr7g21J8bwNATuTIdJRB00ZAyy/lyUYdkCCDf+0ubXFzIzmrxCrgnXHSBGaDoYESjxAYzgILSr6XNz4aqgUc/EXb4f0kbMJiC40ad6S/veiX3K1RmKWzRMPPXwg6t16tAsTgLWiYwfrmiIico2b7z7fcw9vJp9VzvIGG10PGhdvBEVcV1UR0jRESyM4YZrPppcDzSzQ== 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=1niUsk5aDtIhCowAMZf6eTqYxpgtxdoRIXxLB3FTKzg=; b=Z/EDS2AHz+18HMErqIHcvRR7vY/hepriH43FamuB8Q2w26Gx/j5ipuJPKza5x6+JUpRcyjryVLKZYbdLTV//Otdsmc0ICKqTeBIVtFRnKpLzVMnwwcrpPfmilVh6qkzXxs+Igv0wKwI4w0ompsHY1XZH+ZYdfTqaFqGJoUt0EiGxiWyy3S+5o4pt57PPUdsYOzZ1j4RBdVTvspnHJ/kfXxSlPS8cJ/lK8cpd0rEPVxk0quqRqt9ZW425lI4t49KmjQnLaZ8E42MjJZFGSaApscSVjxnmgwRreqBiTaXmxlT6/1+6XBTLs7ko9lTT+5wLHE+iy/2P1Flsj+o0CrYvYg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Wed, 21 Dec 2022 14:27:26 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH 6/8] x86/shadow: adjust and move sh_type_to_size[] 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: FR2P281CA0137.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9e::12) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB8582:EE_ X-MS-Office365-Filtering-Correlation-Id: 8deae829-604d-404a-3840-08dae3571aa7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mxwVCf2q/XZq1IhjlxzsWPgiR0pMcZy81rcjhanZsLc+qnMDcCo6W4jKvrHbJ4gYGUhb334xOJpOdU1eTkUZrxLquR1RvS9y+m49LJ6r6aSert7G0Op3CsEcBTkPnS5gYHWXUPiQV5KfgiFsZrukr9s4fuYrh9lUEiE65e5al3TKI8rJBcL7kUyyZMihtega6Us3L0c8iHKVr0Zd4lB46U/DSb9co4TB8onhVXbvoZlPF7RXWvcYoJEV9o0klnD0KjqVu57fn8ixzDr6fU9Fv0fCIgTS3F+/dvi5VHYUzjuN849NUtXegiSZ1VtBa8p9Pz31dslxYYZHJesGQwn4hGyR+FFcWUAnc7QShcyLeqcXhUuQlhyTsr/wbmJnbIbu3cSyiKQztQ+krZ1LtDOUx1nk/28a5ynT4mnbfolGplS+/mxG5vwhXHnsQ4JRAvJqYBymxLoNxhEmNH1PL+NNO1Yd0wXevofN1bAkhdxl1SJA6KOFDj9XEv7NjIGS5XEjE8y+Yn4pe4FNI9NYhpQ1jdareW71oA5KI8W91BFq5qLgL4KHk9cxdbTQkRKslwKAV85YlFOpFVrxgsuayQewSj8uD51clNGuF60/mmntqK2RmiJljstLui8cCzDvkETcYrbYSQf5StEy14/u5bGt2TitDrxhlV65i6XzUjs4XhSWR4MVM6ufz4HSfuSljHeiXFrKxGDTRrtV3a/S7qu9LkY7xfq654efJN2H2FD7Wk4= 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:(13230022)(366004)(39860400002)(376002)(136003)(396003)(346002)(451199015)(83380400001)(86362001)(31696002)(2616005)(38100700002)(36756003)(478600001)(26005)(186003)(6506007)(6486002)(6512007)(66946007)(66476007)(5660300002)(8676002)(4326008)(316002)(6916009)(31686004)(8936002)(66556008)(41300700001)(2906002)(54906003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Y1a9vBQ5+Tclbj5ZyYR9KKKfLU5Q?= =?utf-8?q?NrndxRyibNcFAGISH3VPXVzx7iDbGgYUtg7ksmO7e6iugoLjsu8C2N5EQe1zyHXCM?= =?utf-8?q?l5X9J33s0MHlND/5TwFxAr9ll8NaIQrnIdIpER8hycNYLqIaVM5a6itRZu+y+fI+/?= =?utf-8?q?REr4u5jo3mL92kpfIXrZx+V0qX4W6VfPo8mmjZDzijomyRTxt0WIYN9SHGZQa1RdF?= =?utf-8?q?vShnfcKxnxI05YlqVcspiwXlUj692UbnjsoLnvJHHwFLPmrm8Phm0v4zKDea023o1?= =?utf-8?q?L7rvDdc5Q7G+uxSGppfakwSSrHWqxO3g8XwAoKNZ/U/HP0H0XRRIrbN+uneVg40Cs?= =?utf-8?q?7yFcmxehZN17GyN3NdcGi1NEjBTax82NVXVKbvWi2S9p2dsjVbGhl/omnvnT2NtFF?= =?utf-8?q?MpxqNh3FnfHZRndBmxC+bfrc8XV79fXL7XI/DC4iSLWebp+YRQJBemGk27bJcpm9C?= =?utf-8?q?ohgDWlWvBjfBJzQ7YaMQA/IIbVnrNuQtKC728P+IqbGz6Nf1FO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mZ0KgffpTbP+Yf?= =?utf-8?q?+0H7Lrv4NFCSCeyhJd8EIw6UIcNoXZJ8vM3EmwbRe5SCJImQNYv+dJo9DGTtaJMTU?= =?utf-8?q?8Osv4+Te6T2iDsyM7fYk045JZC9NPdX/r29FpCmfr/HIUTAXQQ7uKUiKVYhEidOIw?= =?utf-8?q?EPIWpgzeSq6J?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8deae829-604d-404a-3840-08dae3571aa7 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2022 13:27:27.5954 (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: xSSeBqK2mb9DSw1Qdwl7/icqBgZYMmnEEcvXgwjjaN3mXZQf7y4iwWF52Cwu/6k31Sbmn1NGn/hCLDu8xuw+aA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8582 Drop the SH_type_none entry - there are no allocation attempts with this type, and there also shouldn't be any. Adjust the shadow_size() alternative path to match that change. Also generalize two related assertions. While there move the entire table and the respective part of the comment there to hvm.c, resulting in one less #ifdef. In the course of the movement switch to using designated initializers. Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper , although ... --- In principle the SH_type_l2h_64_shadow entry could be dropped here as well (for being a PV32-only thing), but I wasn't sure whether that would be deemed okay right here. --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -838,44 +838,11 @@ sh_validate_guest_entry(struct vcpu *v, * not contiguous in memory; functions for handling offsets into them are * defined in shadow/multi.c (shadow_l1_index() etc.) * - * This table shows the allocation behaviour of the different modes: - * - * Xen paging 64b 64b 64b - * Guest paging 32b pae 64b - * PV or HVM HVM HVM * - * Shadow paging pae pae 64b - * - * sl1 size 8k 4k 4k - * sl2 size 16k 4k 4k - * sl3 size - - 4k - * sl4 size - - 4k - * * In HVM guests, the p2m table is built out of shadow pages, and we provide * a function for the p2m management to steal pages, in max-order chunks, from * the free pool. */ -#ifdef CONFIG_HVM -const u8 sh_type_to_size[] = { - 1, /* SH_type_none */ - 2, /* SH_type_l1_32_shadow */ - 2, /* SH_type_fl1_32_shadow */ - 4, /* SH_type_l2_32_shadow */ - 1, /* SH_type_l1_pae_shadow */ - 1, /* SH_type_fl1_pae_shadow */ - 1, /* SH_type_l2_pae_shadow */ - 1, /* SH_type_l1_64_shadow */ - 1, /* SH_type_fl1_64_shadow */ - 1, /* SH_type_l2_64_shadow */ - 1, /* SH_type_l2h_64_shadow */ - 1, /* SH_type_l3_64_shadow */ - 1, /* SH_type_l4_64_shadow */ - 1, /* SH_type_p2m_table */ - 1, /* SH_type_monitor_table */ - 1 /* SH_type_oos_snapshot */ -}; -#endif - /* * Figure out the least acceptable quantity of shadow memory. * The minimum memory requirement for always being able to free up a @@ -1121,7 +1088,7 @@ mfn_t shadow_alloc(struct domain *d, unsigned int i; ASSERT(paging_locked_by_me(d)); - ASSERT(shadow_type != SH_type_none); + ASSERT(pages); perfc_incr(shadow_alloc); if ( d->arch.paging.free_pages < pages ) @@ -1201,9 +1168,9 @@ void shadow_free(struct domain *d, mfn_t perfc_incr(shadow_free); shadow_type = sp->u.sh.type; - ASSERT(shadow_type != SH_type_none); ASSERT(sp->u.sh.head || (shadow_type > SH_type_max_shadow)); pages = shadow_size(shadow_type); + ASSERT(pages); pin_list = &d->arch.paging.shadow.pinned_shadows; for ( i = 0; i < pages; i++ ) --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -33,6 +33,37 @@ #include "private.h" +/* + * This table shows the allocation behaviour of the different modes: + * + * Xen paging 64b 64b 64b + * Guest paging 32b pae 64b + * PV or HVM HVM HVM * + * Shadow paging pae pae 64b + * + * sl1 size 8k 4k 4k + * sl2 size 16k 4k 4k + * sl3 size - - 4k + * sl4 size - - 4k + */ +const uint8_t sh_type_to_size[] = { + [SH_type_l1_32_shadow] = 2, + [SH_type_fl1_32_shadow] = 2, + [SH_type_l2_32_shadow] = 4, + [SH_type_l1_pae_shadow] = 1, + [SH_type_fl1_pae_shadow] = 1, + [SH_type_l2_pae_shadow] = 1, + [SH_type_l1_64_shadow] = 1, + [SH_type_fl1_64_shadow] = 1, + [SH_type_l2_64_shadow] = 1, + [SH_type_l2h_64_shadow] = 1, + [SH_type_l3_64_shadow] = 1, + [SH_type_l4_64_shadow] = 1, + [SH_type_p2m_table] = 1, + [SH_type_monitor_table] = 1, + [SH_type_oos_snapshot] = 1, +}; + /**************************************************************************/ /* x86 emulator support for the shadow code */ --- a/xen/arch/x86/mm/shadow/private.h +++ b/xen/arch/x86/mm/shadow/private.h @@ -363,7 +363,7 @@ shadow_size(unsigned int shadow_type) return sh_type_to_size[shadow_type]; #else ASSERT(shadow_type < SH_type_unused); - return 1; + return shadow_type != SH_type_none; #endif }