From patchwork Wed Jan 11 13:52:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096701 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 B8612C46467 for ; Wed, 11 Jan 2023 13:52:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475325.736975 (Exim 4.92) (envelope-from ) id 1pFbWn-0003dJ-3s; Wed, 11 Jan 2023 13:52:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475325.736975; Wed, 11 Jan 2023 13:52:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbWn-0003dC-12; Wed, 11 Jan 2023 13:52:29 +0000 Received: by outflank-mailman (input) for mailman id 475325; Wed, 11 Jan 2023 13:52:28 +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 1pFbWl-0003d2-Vu for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:52:27 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2081.outbound.protection.outlook.com [40.107.13.81]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2db852a9-91b7-11ed-b8d0-410ff93cb8f0; Wed, 11 Jan 2023 14:52:25 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB8551.eurprd04.prod.outlook.com (2603:10a6:10:2d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:52:24 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Wed, 11 Jan 2023 13:52: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: 2db852a9-91b7-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PnJXs/RCFzWvUfIZrzXsIUTiCGrHr6jla1sdXi42MvSxY3MQAvpBGTIER/bnW4Hi5ytmrbHEpHM50/qAl7LaQzNhto4LVcKMd41+EiCKXZ0I4rQfOHZhgYeccEboBEY459Cj7O1DKpKIyYP4VcyQ9cYzaChZ4sLmwWbtl8dbvru+GrOlGNpvpX4QzQiJJjiw9uD7m1+mbr/1tVcpb7hj0k2L14e9KaQRpuIvDFS/CqYH5VuZ38QnhyHRQQOvk3JRHS1kg5RQJRKzWw8nf6wG7WI+e1mKEAHoq/egIo5JhAXz+UmIN+RmtLitzn8ysfMkP0g313xyZ9eWHSiS1L59xg== 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=KK/uRlwbYcJhgv6CUBJFcIfHjTvH5M/RQaJchWkIy70=; b=MBCyyS5Ey085RxPJypzjAQCj2Yb0n/K4ZU6ceMTQFiXncVyeZhSiJdrioXyqjpzimOtdRLoWje5xaxE/cEiRwg3vPJTVlBSmN7xlZ/4fjFcDGeMJ701mEduSMVEHN6afcv67s6e2/rVHByDrK2MCXKwXkXv+HJgSR2vKbeJGKbobLIeoNXCsUoiVh5XiXr//78XWscH9VXMkiPBAwWf+H74k/egUrtU7R52DtOz67SGxR4CWHd9aeskIm7gGZaRQnbREj6/IRxD0BwFiVLuQYexTed5VIu2636UX04qRktdpPHbWsJ4QdCSGdNfDHybxYHdKrxLz6XJJeibbvOh+1g== 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=KK/uRlwbYcJhgv6CUBJFcIfHjTvH5M/RQaJchWkIy70=; b=zTZ3dJEnc4LIasDhgH0+ZFcgb088WgxZGxR1ih5Ddihv/4ynuTkzfMQOdNgtwMbwx+JPt1OWrPZS+B/3ES0zCAiZtSwLGtliXWkj47uK+tS0PyiiaSFqgGaiH0WUlzKijD8R+fDYHz7PjmkO5QbpOZmUStqPKGypaBrLJUzmr+VIDvo5ETjXJkPPxOxvs/r0+vqANr2/frYRF3m1S8P2rPH9zYsJaRs7xr3TzDxzxeQzqei7kVTt8qffp1ZUh3DOWzTxxan3sVmJ38v4BLvUWoscdzVGrgppVC4Kp1iZnC49dMUEdklIXQ/ZMGfPhurLjMvMB6icqWnO6oQh0cQgRA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Wed, 11 Jan 2023 14:52:22 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 1/9] x86/shadow: replace sh_reset_l3_up_pointers() 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?= , Tim Deegan , George Dunlap References: In-Reply-To: X-ClientProxiedBy: FR0P281CA0063.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::11) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB8551:EE_ X-MS-Office365-Filtering-Correlation-Id: dfc66c8c-e5ab-4393-7521-08daf3db113f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FAg/V3ol1FxL1GfqhAbdhCjB4B35KZL+j52JNj0TaLBgflCBP1Ix6ERrGgelSlRmnY8H5o/yYVhoKj4FW5QojGsNNNvTgzGZaBscoGuXgSCxZP+qwKL435daBOGcGHMb+fDX1OUg6P/82nvpqBKorVY3LZ1hyvSSTjW6pyeHrzhSr4YYeZtvZzkjZU3dVKlulV2tmzaovBPOjJRbtuD3CnqCVpuMe8up2X5ysjx9Ma36M26CSp5IMShlPVl2QZ8UHjxDPnT5Yu/Ua1jZwLUTL0utjr3poNDaF6gMh3PBpZb/mhbz1SQrCoUoQu3ZQ4yQabXqT9+1Ex4gwnMFSyndmXAbba53thJVAzeD7vLX39toVUH8pW0qbLcpLUEiGUswEP9R+xqAOa0lZPSG9BU74jvemnnJqARFTSylDbDU0a5Ww0gA2ndUOnmm8e/Z1Zboam5xBn2OT+r9rFdIKLkHV758IlvaHTW6IOEqO9R4RkjLwEhZm+6XGV2hm56eSNtl+8+xhBAXGE4+kDVNBqz87unFy+y4EvUaL32JhWExqKy/4n0qqO2lNOZyMTA51x6jboqhwS2qynHgzPoBOj/XkjliuzxGjrZBTm3dwLbTGHKa+ZyH/mjcqmhQDA94vGFRkQnN4F4OLmksR7X3ygeZi9miopC3g/3a2HHCrnjCX5iWrzBgndXcl0UPQLqMBr8BZLJGGYpMsxdxhxwz/gHy5T+g+l0aFF5rLBA3ehcW/vA= 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)(346002)(39860400002)(366004)(376002)(136003)(396003)(451199015)(8936002)(2906002)(5660300002)(41300700001)(316002)(4326008)(66556008)(8676002)(6916009)(66476007)(66946007)(54906003)(26005)(6512007)(38100700002)(2616005)(31686004)(86362001)(186003)(31696002)(83380400001)(36756003)(6506007)(478600001)(6486002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?dmfgfMAZRm6qmHjjSa+XkN/pdyOH?= =?utf-8?q?nqf9TWLAxXLormtnHq6mkH3RHBorLy5b/PnxW7n4+w6QSWdjpSBLicAol3/OhgBLR?= =?utf-8?q?NYBZG41O7b69ETEIgOz+YdjwsUDVnmnJ/yZY5JdTIW8eN8XIBp31+L7XpsRXyXghZ?= =?utf-8?q?cPhwqRqCUIo7tciGU6SJGB/pOQeG1XEtq835+qaBqC6iAm1GEyXjJa94aq+oVGB+y?= =?utf-8?q?s402vEOwMK+xzxCVgpg8+MDYgTCCTtYZEn31PGQTpNwGfWQb5ox6rAgIQapY8V3m/?= =?utf-8?q?ScJWzkRXGFlTYzBevCQTOt6hq68q1EuH8iX40hQ5MPJHsGM1DGOR6iGRczqcDAs+0?= =?utf-8?q?9WfzmWuVqVoGMR5J1uUm9KuRoQuQYz9uWo7M+DdkzYtx5M1OXQZ37iWfP+FKIQs+S?= =?utf-8?q?m8GDMmdhFlbxm0+eVzFJHy+bjm/Zp3FLaHdhOslJFj9BI5dnqRIJ0xjZLU/NWRPaG?= =?utf-8?q?QbZw1pyDDzdpJP8azRARmpkY6Np8q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4m0NJxG7Tycfis504GA+caJGjEeymMMlqjkx?= =?utf-8?q?xa9DDCe0urX3VAbVRnfpzQMWFJc9Yx8Eb07jnW4hVNecCLVppA8YmxQiCnXpGI5L8?= =?utf-8?q?VH2XBmigrQvwZWZulvmkaf5nCqLy2BQm+hCJGosCSiHF6lep5S0Or7K6LbkkbedpD?= =?utf-8?q?lsGwErrqgxUj?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: dfc66c8c-e5ab-4393-7521-08daf3db113f X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:52:24.0355 (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: /U09tZ0oVetiutgyIdihm2DyfKHPO/w6U5ml9c+X/+ZicL/95qDaPBMkt1HZ0THp0BBZ33yXwVlA5/KkecZJYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8551 Rather than doing a separate hash walk (and then even using the vCPU variant, which is to go away), do the up-pointer-clearing right in sh_unpin(), as an alternative to the (now further limited) enlisting on a "free floating" list fragment. This utilizes the fact that such list fragments are traversed only for multi-page shadows (in shadow_free()). Furthermore sh_terminate_list() is a safe guard only anyway, which isn't in use in the common case (it actually does anything only for BIGMEM configurations). Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -116,6 +116,9 @@ struct shadow_domain { /* OOS */ bool_t oos_active; + /* Domain is in the process of leaving SHOPT_LINUX_L3_TOPLEVEL mode. */ + bool unpinning_l3; + #ifdef CONFIG_HVM /* Has this domain ever used HVMOP_pagetable_dying? */ bool_t pagetable_dying_op; --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -2302,29 +2302,6 @@ void shadow_prepare_page_type_change(str /**************************************************************************/ -/* Reset the up-pointers of every L3 shadow to 0. - * This is called when l3 shadows stop being pinnable, to clear out all - * the list-head bits so the up-pointer field is properly inititalised. */ -static int cf_check sh_clear_up_pointer( - struct vcpu *v, mfn_t smfn, mfn_t unused) -{ - mfn_to_page(smfn)->up = 0; - return 0; -} - -void sh_reset_l3_up_pointers(struct vcpu *v) -{ - static const hash_vcpu_callback_t callbacks[SH_type_unused] = { - [SH_type_l3_64_shadow] = sh_clear_up_pointer, - }; - - HASH_CALLBACKS_CHECK(SHF_L3_64); - hash_vcpu_foreach(v, SHF_L3_64, callbacks, INVALID_MFN); -} - - -/**************************************************************************/ - static void sh_update_paging_modes(struct vcpu *v) { struct domain *d = v->domain; --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -960,6 +960,8 @@ sh_make_shadow(struct vcpu *v, mfn_t gmf } if ( l4count > 2 * d->max_vcpus ) { + d->arch.paging.shadow.unpinning_l3 = true; + /* Unpin all the pinned l3 tables, and don't pin any more. */ page_list_for_each_safe(sp, t, &d->arch.paging.shadow.pinned_shadows) { @@ -967,7 +969,8 @@ sh_make_shadow(struct vcpu *v, mfn_t gmf sh_unpin(d, page_to_mfn(sp)); } d->arch.paging.shadow.opt_flags &= ~SHOPT_LINUX_L3_TOPLEVEL; - sh_reset_l3_up_pointers(v); + + d->arch.paging.shadow.unpinning_l3 = false; } } #endif --- a/xen/arch/x86/mm/shadow/private.h +++ b/xen/arch/x86/mm/shadow/private.h @@ -497,11 +497,6 @@ void shadow_blow_tables(struct domain *d */ int sh_remove_all_mappings(struct domain *d, mfn_t gmfn, gfn_t gfn); -/* Reset the up-pointers of every L3 shadow to 0. - * This is called when l3 shadows stop being pinnable, to clear out all - * the list-head bits so the up-pointer field is properly inititalised. */ -void sh_reset_l3_up_pointers(struct vcpu *v); - /****************************************************************************** * Flags used in the return value of the shadow_set_lXe() functions... */ @@ -721,7 +716,7 @@ static inline void sh_unpin(struct domai { struct page_list_head tmp_list, *pin_list; struct page_info *sp, *next; - unsigned int i, head_type; + unsigned int i, head_type, sz; ASSERT(mfn_valid(smfn)); sp = mfn_to_page(smfn); @@ -733,20 +728,30 @@ static inline void sh_unpin(struct domai return; sp->u.sh.pinned = 0; - /* Cut the sub-list out of the list of pinned shadows, - * stitching it back into a list fragment of its own. */ + sz = shadow_size(head_type); + + /* + * Cut the sub-list out of the list of pinned shadows, stitching + * multi-page shadows back into a list fragment of their own. + */ pin_list = &d->arch.paging.shadow.pinned_shadows; INIT_PAGE_LIST_HEAD(&tmp_list); - for ( i = 0; i < shadow_size(head_type); i++ ) + for ( i = 0; i < sz; i++ ) { ASSERT(sp->u.sh.type == head_type); ASSERT(!i || !sp->u.sh.head); next = page_list_next(sp, pin_list); page_list_del(sp, pin_list); - page_list_add_tail(sp, &tmp_list); + if ( sz > 1 ) + page_list_add_tail(sp, &tmp_list); + else if ( head_type == SH_type_l3_64_shadow && + d->arch.paging.shadow.unpinning_l3 ) + sp->up = 0; sp = next; } - sh_terminate_list(&tmp_list); + + if ( sz > 1 ) + sh_terminate_list(&tmp_list); sh_put_ref(d, smfn, 0); } From patchwork Wed Jan 11 13:52:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096702 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 E7DA0C54EBC for ; Wed, 11 Jan 2023 13:53:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475332.736997 (Exim 4.92) (envelope-from ) id 1pFbXH-0004RR-RI; Wed, 11 Jan 2023 13:52:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475332.736997; Wed, 11 Jan 2023 13:52:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbXH-0004RJ-Nm; Wed, 11 Jan 2023 13:52:59 +0000 Received: by outflank-mailman (input) for mailman id 475332; Wed, 11 Jan 2023 13:52:58 +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 1pFbXG-0004QI-Lp for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:52:58 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2084.outbound.protection.outlook.com [40.107.13.84]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3fde7629-91b7-11ed-b8d0-410ff93cb8f0; Wed, 11 Jan 2023 14:52:55 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB8551.eurprd04.prod.outlook.com (2603:10a6:10:2d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:52:54 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Wed, 11 Jan 2023 13:52:54 +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: 3fde7629-91b7-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xs5ktteQeAbjbF3OaY6w1lsapMxtJ+FEdx2EF+KXaa6Hg8XKaz4GOvsnsyPutwzKL8aBDDw44EXosht5S/FQ+QhYD4utSdOypESW8XhogJpvymhla8IqWakzLsoJJk9aGJ04BPGwkBtdgoncLruUdf2KbkfESdvI6xGg1PmAQSAlWPCqrYORBbG9DVtqovdIRMk1/RdlQcvkBmXTEp1E0/QAwqU7lxGhKXUmRl+qgWVd91lnWc/a6+FjNTo/de8A1txd5uPhv3cJuBESO0nxsxQ2s5Rtzv7jVAiZpHUrLT5bNZ2+zxkzYRnpl88U/YrSV9HLXGXgEDAouBWYyOG3Bw== 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=rQVzcV/aXrmtFWKLwSeA0Wp+ghnodUCv9vHrPOZHrwE=; b=HczbtIbvSt7k/ToZ2QyGMzLYTX9L5rNUgcvNfo5aRLIBiXrVya3bu6RTir5TLbcl9FSmIhfursO2Flk5MJLqd3U2cb2NwEER4+rM9t+PvMgv/zzTLkJc8vZ0P2sJ1usGsVjGOde5El+njYW4JvXkEsFL0E0U908xNJXZigyYFi9Fb5va4jhC+n2LyDD2RNHnFDGQKn3EYwDjfvDJkSVumavXa+exn3r9DBkbcGCYggSxRjooUjUdiOvkD/EzF/kIESR6eb5UnccqyPMjRisjLXCyZIHXbJ1GqgIPQriTKbEMpUgiEVVR/e1NE6/mPqeLiKl4OAXzXNGnT0OILwL7Zw== 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=rQVzcV/aXrmtFWKLwSeA0Wp+ghnodUCv9vHrPOZHrwE=; b=uuLYYp2LtOXjuTjT8YtjEvA90DwT0rzNHs1DifEbBz+1TlOpIeHmxxoelpKhRWFbZUbdEUbCDrU5+CwkPh8Rm6FFcBtp1UsGk/IIv3/khk6nC7kz7oFlB+LUoqmcOlYnS6mFfWRm1sC+9pB81XW3dM82Kw9Hi5LUOSE0pABS8MNgcpyxsigTlOqyNBRkdGpN8M05Uj8nLw2v29JWFz9pwMMqCn2x2DUfAnlXB8TLA1s2w5pzo+cbKc4GNk0dT8E4mWDOwe6SwjP/PDipBbDLEKPIdMBT4uZbmrUAbBuM4f+oPz8zZZ7ohuW78AZU5khiQnxWW5B3JI+cJziZ7/6Gqg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <17d7ca95-4c94-93e3-9a42-cc95512a66cc@suse.com> Date: Wed, 11 Jan 2023 14:52:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 2/9] x86/shadow: drop hash_vcpu_foreach() 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?= , Tim Deegan , George Dunlap References: In-Reply-To: X-ClientProxiedBy: FR0P281CA0064.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::8) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB8551:EE_ X-MS-Office365-Filtering-Correlation-Id: d6b15711-5617-4149-eee7-08daf3db2365 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: //0zVOYkBlk+vQJ/HfhyC1nKEJ73BQcACHluRZQHwt1COJ1q0xHggOfsLK1du3af0W586iGfWutDDVxt/dJhPlg3nZPHpys3cR7DpoD4wjwQQBqN6fCreliMMlY3OmagV0nibsPrGP8EYEibCDNHG1+3BcRxvgLiYHACzXYWbsG/qNEDefVQxeu0FzX/98T3OkaJ6xwxtXC5zx9M8P/TkYv2Vpr42fVhziSHviHt3N3kvUK0q5Nu0XNJP3lOTkdQZswYf1Gqunj+xIbkR0iqTIlPKeTPC8h25xA0SJEltAEdHzu4jcXmB6s6h8ez2RG3lDnbrQTFe3rqMuoUKJFwlSqzoZB4h99FNIzvU7PvG3Wm4Puiu3svE7nUTNhxEsGEajhevxaGZM9cL7d9YWCl1bSvYROkrZk+0Xe+PpW+ApDQ4QcKUeTX8ddvvESG+sBp3OzI9sMW8aKPRhv+oEbEFaDlzyCwKX0mdfi4/MytrB3KKEq+VfsLWhly6PqabYM4uXcY33rsoNN+vtpbd5YQ2KaaZUpciHt4Q91431y9QbkyYWQhdgl3+b4IrsN7UrR5uI6pmcbSiTe4Yj9POB6YL0cu7vKRvgD5VFYwPQZ2S3mv/vTRahc1NRsGiYtekAm22W2XTlrx0XsU/FTcIFd+/uOIv1iux/VXBA1//PUlijP5DLi7hHORhDG2MlofUwpgxAlBa03qfbW2Qje/KZ4p9RRtTirloIYOol5/1YL68DsWV5M7HNzEtSN+4E7xL3STdMSkfzd5ekK1uXaI+XCLAavq0+aSE4OVUYNE9Q6FiPBwoIfwzLDwmidvv/MMOmhS 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)(346002)(39860400002)(366004)(376002)(136003)(396003)(451199015)(8936002)(2906002)(5660300002)(41300700001)(316002)(4326008)(66556008)(8676002)(6916009)(66476007)(66946007)(54906003)(26005)(6512007)(38100700002)(2616005)(31686004)(86362001)(186003)(31696002)(83380400001)(36756003)(6506007)(478600001)(6486002)(43740500002)(45980500001)(414714003)(473944003)(357404004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ov+UvY74Wnuvx4XcQfO/BJ8xP5O+?= =?utf-8?q?Ioo4JXyKIz3gDa20iz17QbaAzuTEf9u6vaaBfRJvLtYkrV++RrW8ArGvQP/saRpoL?= =?utf-8?q?sQ16SIfn3Z0mvknO1Oer637ftJYR3utbiTt1evNLz0AwgNW2fP0e/EAvXKE7Hwizo?= =?utf-8?q?pDYdwddS2x8arukTJdxPC7ItUfFDiyt6U1s8hMEMXkbZZGW3vKnUZDNrfVeBbAoEb?= =?utf-8?q?pUmtsFli0E89lUPx63bZjJFHY/2cBJzkPEgUg6n3FWvU8SMMFS8RCxo+w7mxD2yt8?= =?utf-8?q?HN9BcnFEbED5K+h8Ew3o7HZTzaUNTOBrLbSJwsTq+RlBGaY/+wphjDkmgR09g393J?= =?utf-8?q?oINPdjX9PaDbX1E2TzUXBTndNtKPZZ+F0Kgac7d5bHqsEKUZ1SZ8fW24Sjk2aXWcH?= =?utf-8?q?TpYNpoUq3FmxrmFt7nEUopIN6SSjWpMPE7ak5oVU8mktLVfGnYhpNekQlYRTyf4Ct?= =?utf-8?q?H6x/NCXgf500jzSGVNimktZjnOKAowXPqoKCHFhm8d4jQ/2/xV5TFvhcO0kD6LCDT?= =?utf-8?q?mfsT+6FSF8MkdMhi9wNUtn67h4wYpzF5KoK8F6AfHB3Tv0i9HK+xarkLKm8wBE6O8?= =?utf-8?q?odD7uw7iN2fQYc6imIryj1qBHW8holILBgOa0P+VgRzu7Qc/nVcWm8J+nhvd3IWd/?= =?utf-8?q?FzUEB67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suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6b15711-5617-4149-eee7-08daf3db2365 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:52:54.5335 (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: MS4y41vVZFF7t+NIy7x67Bf84MUqL61ubBx1bn82Z+aeb1Av2lyXupvPjeLD7C/kV6tyqgUnrbHL7/F55l8tPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8551 The domain based variant is easily usable by shadow_audit_tables(); all that's needed is conversion of the callback functions. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -1640,59 +1640,11 @@ bool shadow_hash_delete(struct domain *d return true; } -typedef int (*hash_vcpu_callback_t)(struct vcpu *v, mfn_t smfn, mfn_t other_mfn); typedef int (*hash_domain_callback_t)(struct domain *d, mfn_t smfn, mfn_t other_mfn); #define HASH_CALLBACKS_CHECK(mask) \ BUILD_BUG_ON((mask) > (1U << ARRAY_SIZE(callbacks)) - 1) -static void hash_vcpu_foreach(struct vcpu *v, unsigned int callback_mask, - const hash_vcpu_callback_t callbacks[], - mfn_t callback_mfn) -/* Walk the hash table looking at the types of the entries and - * calling the appropriate callback function for each entry. - * The mask determines which shadow types we call back for, and the array - * of callbacks tells us which function to call. - * Any callback may return non-zero to let us skip the rest of the scan. - * - * WARNING: Callbacks MUST NOT add or remove hash entries unless they - * then return non-zero to terminate the scan. */ -{ - int i, done = 0; - struct domain *d = v->domain; - struct page_info *x; - - ASSERT(paging_locked_by_me(d)); - - /* Can be called via p2m code &c after shadow teardown. */ - if ( unlikely(!d->arch.paging.shadow.hash_table) ) - return; - - /* Say we're here, to stop hash-lookups reordering the chains */ - ASSERT(d->arch.paging.shadow.hash_walking == 0); - d->arch.paging.shadow.hash_walking = 1; - - for ( i = 0; i < SHADOW_HASH_BUCKETS; i++ ) - { - /* WARNING: This is not safe against changes to the hash table. - * The callback *must* return non-zero if it has inserted or - * deleted anything from the hash (lookups are OK, though). */ - for ( x = d->arch.paging.shadow.hash_table[i]; x; x = next_shadow(x) ) - { - if ( callback_mask & (1 << x->u.sh.type) ) - { - ASSERT(x->u.sh.type <= SH_type_max_shadow); - ASSERT(callbacks[x->u.sh.type] != NULL); - done = callbacks[x->u.sh.type](v, page_to_mfn(x), - callback_mfn); - if ( done ) break; - } - } - if ( done ) break; - } - d->arch.paging.shadow.hash_walking = 0; -} - static void hash_domain_foreach(struct domain *d, unsigned int callback_mask, const hash_domain_callback_t callbacks[], @@ -3211,7 +3163,7 @@ int shadow_domctl(struct domain *d, void shadow_audit_tables(struct vcpu *v) { /* Dispatch table for getting per-type functions */ - static const hash_vcpu_callback_t callbacks[SH_type_unused] = { + static const hash_domain_callback_t callbacks[SH_type_unused] = { #if SHADOW_AUDIT & (SHADOW_AUDIT_ENTRIES | SHADOW_AUDIT_ENTRIES_FULL) # ifdef CONFIG_HVM [SH_type_l1_32_shadow] = SHADOW_INTERNAL_NAME(sh_audit_l1_table, 2), @@ -3258,7 +3210,7 @@ void shadow_audit_tables(struct vcpu *v) HASH_CALLBACKS_CHECK(SHADOW_AUDIT & (SHADOW_AUDIT_ENTRIES | SHADOW_AUDIT_ENTRIES_FULL) ? SHF_page_type_mask : 0); - hash_vcpu_foreach(v, mask, callbacks, INVALID_MFN); + hash_domain_foreach(v->domain, mask, callbacks, INVALID_MFN); } #ifdef CONFIG_PV --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -326,32 +326,32 @@ static void sh_audit_gw(struct vcpu *v, if ( mfn_valid(gw->l4mfn) && mfn_valid((smfn = get_shadow_status(d, gw->l4mfn, SH_type_l4_shadow))) ) - (void) sh_audit_l4_table(v, smfn, INVALID_MFN); + sh_audit_l4_table(d, smfn, INVALID_MFN); if ( mfn_valid(gw->l3mfn) && mfn_valid((smfn = get_shadow_status(d, gw->l3mfn, SH_type_l3_shadow))) ) - (void) sh_audit_l3_table(v, smfn, INVALID_MFN); + sh_audit_l3_table(d, smfn, INVALID_MFN); #endif /* PAE or 64... */ if ( mfn_valid(gw->l2mfn) ) { if ( mfn_valid((smfn = get_shadow_status(d, gw->l2mfn, SH_type_l2_shadow))) ) - (void) sh_audit_l2_table(v, smfn, INVALID_MFN); + sh_audit_l2_table(d, smfn, INVALID_MFN); #if GUEST_PAGING_LEVELS >= 4 /* 32-bit PV only */ if ( mfn_valid((smfn = get_shadow_status(d, gw->l2mfn, SH_type_l2h_shadow))) ) - (void) sh_audit_l2_table(v, smfn, INVALID_MFN); + sh_audit_l2_table(d, smfn, INVALID_MFN); #endif } if ( mfn_valid(gw->l1mfn) && mfn_valid((smfn = get_shadow_status(d, gw->l1mfn, SH_type_l1_shadow))) ) - (void) sh_audit_l1_table(v, smfn, INVALID_MFN); + sh_audit_l1_table(d, smfn, INVALID_MFN); else if ( (guest_l2e_get_flags(gw->l2e) & _PAGE_PRESENT) && (guest_l2e_get_flags(gw->l2e) & _PAGE_PSE) && mfn_valid( (smfn = get_fl1_shadow_status(d, guest_l2e_get_gfn(gw->l2e)))) ) - (void) sh_audit_fl1_table(v, smfn, INVALID_MFN); + sh_audit_fl1_table(d, smfn, INVALID_MFN); #endif /* SHADOW_AUDIT & SHADOW_AUDIT_ENTRIES */ } @@ -3950,9 +3950,8 @@ static const char *sh_audit_flags(const return NULL; } -int cf_check sh_audit_l1_table(struct vcpu *v, mfn_t sl1mfn, mfn_t x) +int cf_check sh_audit_l1_table(struct domain *d, mfn_t sl1mfn, mfn_t x) { - struct domain *d = v->domain; guest_l1e_t *gl1e, *gp; shadow_l1e_t *sl1e; mfn_t mfn, gmfn, gl1mfn; @@ -4019,7 +4018,7 @@ int cf_check sh_audit_l1_table(struct vc return done; } -int cf_check sh_audit_fl1_table(struct vcpu *v, mfn_t sl1mfn, mfn_t x) +int cf_check sh_audit_fl1_table(struct domain *d, mfn_t sl1mfn, mfn_t x) { guest_l1e_t *gl1e, e; shadow_l1e_t *sl1e; @@ -4045,9 +4044,8 @@ int cf_check sh_audit_fl1_table(struct v return 0; } -int cf_check sh_audit_l2_table(struct vcpu *v, mfn_t sl2mfn, mfn_t x) +int cf_check sh_audit_l2_table(struct domain *d, mfn_t sl2mfn, mfn_t x) { - struct domain *d = v->domain; guest_l2e_t *gl2e, *gp; shadow_l2e_t *sl2e; mfn_t mfn, gmfn, gl2mfn; @@ -4097,9 +4095,8 @@ int cf_check sh_audit_l2_table(struct vc } #if GUEST_PAGING_LEVELS >= 4 -int cf_check sh_audit_l3_table(struct vcpu *v, mfn_t sl3mfn, mfn_t x) +int cf_check sh_audit_l3_table(struct domain *d, mfn_t sl3mfn, mfn_t x) { - struct domain *d = v->domain; guest_l3e_t *gl3e, *gp; shadow_l3e_t *sl3e; mfn_t mfn, gmfn, gl3mfn; @@ -4145,9 +4142,8 @@ int cf_check sh_audit_l3_table(struct vc return 0; } -int cf_check sh_audit_l4_table(struct vcpu *v, mfn_t sl4mfn, mfn_t x) +int cf_check sh_audit_l4_table(struct domain *d, mfn_t sl4mfn, mfn_t x) { - struct domain *d = v->domain; guest_l4e_t *gl4e, *gp; shadow_l4e_t *sl4e; mfn_t mfn, gmfn, gl4mfn; --- a/xen/arch/x86/mm/shadow/multi.h +++ b/xen/arch/x86/mm/shadow/multi.h @@ -83,19 +83,19 @@ SHADOW_INTERNAL_NAME(sh_remove_l3_shadow #if SHADOW_AUDIT & SHADOW_AUDIT_ENTRIES int cf_check SHADOW_INTERNAL_NAME(sh_audit_l1_table, GUEST_LEVELS) - (struct vcpu *v, mfn_t sl1mfn, mfn_t x); + (struct domain *d, mfn_t sl1mfn, mfn_t x); int cf_check SHADOW_INTERNAL_NAME(sh_audit_fl1_table, GUEST_LEVELS) - (struct vcpu *v, mfn_t sl1mfn, mfn_t x); + (struct domain *d, mfn_t sl1mfn, mfn_t x); int cf_check SHADOW_INTERNAL_NAME(sh_audit_l2_table, GUEST_LEVELS) - (struct vcpu *v, mfn_t sl2mfn, mfn_t x); + (struct domain *d, mfn_t sl2mfn, mfn_t x); int cf_check SHADOW_INTERNAL_NAME(sh_audit_l3_table, GUEST_LEVELS) - (struct vcpu *v, mfn_t sl3mfn, mfn_t x); + (struct domain *d, mfn_t sl3mfn, mfn_t x); int cf_check SHADOW_INTERNAL_NAME(sh_audit_l4_table, GUEST_LEVELS) - (struct vcpu *v, mfn_t sl4mfn, mfn_t x); + (struct domain *d, mfn_t sl4mfn, mfn_t x); #endif extern const struct paging_mode From patchwork Wed Jan 11 13:53:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096703 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 6D365C5479D for ; Wed, 11 Jan 2023 13:53:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475344.737008 (Exim 4.92) (envelope-from ) id 1pFbXr-0005IV-6M; Wed, 11 Jan 2023 13:53:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475344.737008; Wed, 11 Jan 2023 13:53:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbXr-0005II-2H; Wed, 11 Jan 2023 13:53:35 +0000 Received: by outflank-mailman (input) for mailman id 475344; Wed, 11 Jan 2023 13:53:33 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbXp-00047w-ET for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:53:33 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2048.outbound.protection.outlook.com [40.107.13.48]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 55891915-91b7-11ed-91b6-6bf2151ebd3b; Wed, 11 Jan 2023 14:53:32 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB8551.eurprd04.prod.outlook.com (2603:10a6:10:2d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:53:30 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Wed, 11 Jan 2023 13:53:30 +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: 55891915-91b7-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=URIUJvBUnhD4gku6qib2sVtrZYoKIBmoNUghFiwwgyeCoScB/mUwsrbzK8K5W4tyzqxwCr7zhRYfIpyZ8wMjLAjydK0/g42FepxwPItjpLnwUxtlHE5B8zWKCQSe1rl+StcCTQ2ryrmWj4K1nibMoXRGtdXpcRhlFYWvjSntKPo0gr/iFVEjLXj6o0XCP2NYW7o1YF+LhZ3DIc7wdbvBHCtMygtMAUo0bLZB9kmYbhCrLqpW65Tjigt6uQny5XOLok3DNLR3aCscbI8T/ylM5XWRxjMwbuotsWwjcR9Mqs41iCKajdhRCaelFc96sKMnDHZjTqa89u+iEyh6y332zw== 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=zfV7FH4PlbLPIPiG+PzMORtLnBIDSYzDeJCNwEUQtis=; b=Ow+4oszuWC7+szzZOqmusakF1TkHARoostoEZWy7tldhwsEl6s3oM/wYm8fxzaUljzfMcDTC3MsJuoFlmbvzWUeRpmfdB/k+w51kAf4CsAWCi7WkjYzpMPAImpqx8hNwm9Qr5odM7Y5vv7TGUVqeeY/ULR/wKW5aN8god6ck7GQv46oeqzlVP+QUbooE1XVIhAbkm4GsJMbcnoUABlJtUGzxP+oXcBS6La2nlT3DMbrX6oFQuM4OynXvqO5t9az6MlVcL6yX0NXI1CVBNn0+5VGB7C41FNcBaUvP40rMlz+C2YSQebaW3saoDDuVZ2FQ/xJzDUokzqlqNIW551Dgag== 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=zfV7FH4PlbLPIPiG+PzMORtLnBIDSYzDeJCNwEUQtis=; b=bIS/MneUtTtRjQmNLzGJJdMBFWtz09BScvbX22KDROsyUmACdCZLYqsDabtUbLqaXt1rZlVpwtbXq0OK5TOzEyHLI0dfwpngM6eMsWqQQeAyk0YgGIniXBikGDzPDr7UfTFPdLml9TovrdhahCyBhx3IC+NZMhBNErmIg/GXxux1axKJJYJFd1EP3IreZc+CWZ1SauoCHQ/RiWl7VORU/JyQAzH0cEQVdoFV6ZvXhNO6lrJP5vEp3JX71aRPxiHcP5Q+zHpjs005pyMK3uOLfYnkOgiPcLpmDExMsIBZ/VL3L/zffCyt+fURzlqkIfsxoW2Ripa7FmJqw3p4BvKC4g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Wed, 11 Jan 2023 14:53:29 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 3/9] x86/shadow: rename hash_domain_foreach() 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?= , Tim Deegan , George Dunlap References: In-Reply-To: X-ClientProxiedBy: FR2P281CA0181.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9f::17) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB8551:EE_ X-MS-Office365-Filtering-Correlation-Id: c4b00fea-09ab-4c99-1dbb-08daf3db38fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yBVUELvVhxkKF3Wuker5LK7J1dyVEsyW9Q4c9eq63mJ2ZH1TnGw4BFsN1AVle+6wVMvk7SGA19QkRtSD2Sv0//rRMDp7P5BAirODYFkmyebvRJ/kbuRTkU9OXNhog7Bbmm3EC3oMjPRvL8I0J/shA2AcOoSt5HLdqY55x2IZTMlX/Bll6TBCEg+6WyWx7VHs5dR9HBDWLRQtviiUYoXYmXqxGVLhZrYC6Ex7x8gTYEXcWUh/7iI+s+LIkARol2eDFvrMZr0dkSEMUtLqMFoSiq4W4rKwm3tQaTxyi649bQOQO1WiAkKhPisQxCsTLCcfgWb8hiwC0H1s/MaRZkMWvAhOPuU7Xg0wCbs8wi7HiIpbWSEy9TAteJzhDcRz3G1cgjMounCr5GEW5Z3RajbpA8bIHRSJvPmI13QorIopYNiOii0oDSkInNAZ1B3OAnPpyGbTW0BBTcweogFkkhQv8x16Gu2sHVXWkCju70XkvdRKcxVEoiP6XOok876JTkwiPt7OESPuQUCb3LJ0ewXDvrBU8a+EFQveFIfwbIB3Fo9coxUeupWWYdhv3qWYOuax6xmrzk8TLPWymSZex0S/APoN9nGBrTPz54J8wjtPu+zeT6nwKrVrk7KODxnwk0zPeVW8aXEr7VNWL3FDiQedMJdmpU2zcvSMVHsLhvlqpNWxBF9rGJf/onHqtLlpFG5FW6W9m7kax+tyKjMuF2O6DB5ythyxloNmrkn1Esr9cbs= 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)(346002)(39860400002)(366004)(376002)(136003)(396003)(451199015)(8936002)(2906002)(5660300002)(41300700001)(316002)(4326008)(66556008)(8676002)(6916009)(66476007)(66946007)(54906003)(26005)(6512007)(38100700002)(2616005)(31686004)(86362001)(186003)(31696002)(83380400001)(36756003)(6506007)(478600001)(6486002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Guhg3kXnmv05cKyxXUyrtmMjyRnf?= =?utf-8?q?Yy/UIWO7A1l7tLqQo9F7MWmBxDHOmxjIIPMs2RFpuEqPQ7JkWOzljcqhFTdRHxT0T?= =?utf-8?q?X/PWstXcEOQM1t3FX1er6PnSU/KloUKyIKiIBdq8N/DWRMz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= =?utf-8?q?7o7yYqL3ECoEt36nci8sPosc76FEFYI5W2Use0MuoX7vQJs2VVy5LllmW95E9eSms?= =?utf-8?q?XghVdmYac1hCueUlFsBfXYyGXaV/5qAFJ1wzwQvTbbvJ88+XSLzJpI0aAAsupslUs?= =?utf-8?q?13YuUHHN+/jlPMTCyl5hUYB5XKKflVq7p/Huhio2byiAsEBJRQdXhqNT8erlqWFOt?= =?utf-8?q?pamsmUdp0HcqHjR4nX4uPiAtgqbxwSZELFa/vWPsHlRto8OgcGBvSMoRpkBwkXgVK?= =?utf-8?q?PD2hXtujpWp1BfYDaQ1WL2ahspfuJFewkaXARCzt0bgYKwCsLLmo9lBltealEz5co?= =?utf-8?q?2SQJFFRCNmJVYYiExPyTvUlHidVnnQjwyAg56clmanxmf8icx9zNGZCxX3mrceoDq?= =?utf-8?q?h3nAyvBKTemqcs6p63kForfOIFHKjhwOLyeG1ccyiY5zGMfHvyqf7lPM2iUqtv8Fh?= =?utf-8?q?0PaUdVzv10Ss7IeJbDOvFg6jV2Tl8iXGb0Tc1HoYPCWwCgcK/rOn0jl1o2m0kv+2T?= =?utf-8?q?pFP5dz5Yx7CQ?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c4b00fea-09ab-4c99-1dbb-08daf3db38fc X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:53:30.6874 (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: 2tjwHUZPplVPns/+4HE8dfFY4HNDs2WIGua3tH8rxVltNrEzsV+Q6b/lnKvCSeZ2tvlqx2kXoT2cSzZs5DH/eQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8551 The "domain" in there has become meaningless; drop it. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -1640,15 +1640,15 @@ bool shadow_hash_delete(struct domain *d return true; } -typedef int (*hash_domain_callback_t)(struct domain *d, mfn_t smfn, mfn_t other_mfn); +typedef int (*hash_callback_t)(struct domain *d, mfn_t smfn, mfn_t other_mfn); #define HASH_CALLBACKS_CHECK(mask) \ BUILD_BUG_ON((mask) > (1U << ARRAY_SIZE(callbacks)) - 1) -static void hash_domain_foreach(struct domain *d, - unsigned int callback_mask, - const hash_domain_callback_t callbacks[], - mfn_t callback_mfn) +static void hash_foreach(struct domain *d, + unsigned int callback_mask, + const hash_callback_t callbacks[], + mfn_t callback_mfn) /* Walk the hash table looking at the types of the entries and * calling the appropriate callback function for each entry. * The mask determines which shadow types we call back for, and the array @@ -1784,7 +1784,7 @@ int sh_remove_write_access(struct domain unsigned long fault_addr) { /* Dispatch table for getting per-type functions */ - static const hash_domain_callback_t callbacks[SH_type_unused] = { + static const hash_callback_t callbacks[SH_type_unused] = { #ifdef CONFIG_HVM [SH_type_l1_32_shadow] = SHADOW_INTERNAL_NAME(sh_rm_write_access_from_l1, 2), [SH_type_fl1_32_shadow] = SHADOW_INTERNAL_NAME(sh_rm_write_access_from_l1, 2), @@ -1969,7 +1969,7 @@ int sh_remove_write_access(struct domain else perfc_incr(shadow_writeable_bf); HASH_CALLBACKS_CHECK(SHF_L1_ANY | SHF_FL1_ANY); - hash_domain_foreach(d, SHF_L1_ANY | SHF_FL1_ANY, callbacks, gmfn); + hash_foreach(d, SHF_L1_ANY | SHF_FL1_ANY, callbacks, gmfn); /* If that didn't catch the mapping, then there's some non-pagetable * mapping -- ioreq page, grant mapping, &c. */ @@ -1997,7 +1997,7 @@ int sh_remove_all_mappings(struct domain struct page_info *page = mfn_to_page(gmfn); /* Dispatch table for getting per-type functions */ - static const hash_domain_callback_t callbacks[SH_type_unused] = { + static const hash_callback_t callbacks[SH_type_unused] = { [SH_type_l1_32_shadow] = SHADOW_INTERNAL_NAME(sh_rm_mappings_from_l1, 2), [SH_type_fl1_32_shadow] = SHADOW_INTERNAL_NAME(sh_rm_mappings_from_l1, 2), [SH_type_l1_pae_shadow] = SHADOW_INTERNAL_NAME(sh_rm_mappings_from_l1, 3), @@ -2021,7 +2021,7 @@ int sh_remove_all_mappings(struct domain /* Brute-force search of all the shadows, by walking the hash */ perfc_incr(shadow_mappings_bf); HASH_CALLBACKS_CHECK(SHF_L1_ANY | SHF_FL1_ANY); - hash_domain_foreach(d, SHF_L1_ANY | SHF_FL1_ANY, callbacks, gmfn); + hash_foreach(d, SHF_L1_ANY | SHF_FL1_ANY, callbacks, gmfn); /* If that didn't catch the mapping, something is very wrong */ if ( !sh_check_page_has_no_refs(page) ) @@ -2128,7 +2128,7 @@ void sh_remove_shadows(struct domain *d, /* Dispatch table for getting per-type functions: each level must * be called with the function to remove a lower-level shadow. */ - static const hash_domain_callback_t callbacks[SH_type_unused] = { + static const hash_callback_t callbacks[SH_type_unused] = { #ifdef CONFIG_HVM [SH_type_l2_32_shadow] = SHADOW_INTERNAL_NAME(sh_remove_l1_shadow, 2), [SH_type_l2_pae_shadow] = SHADOW_INTERNAL_NAME(sh_remove_l1_shadow, 3), @@ -2173,9 +2173,9 @@ void sh_remove_shadows(struct domain *d, /* * Lower-level shadows need to be excised from upper-level shadows. This - * call to hash_domain_foreach() looks dangerous but is in fact OK: each - * call will remove at most one shadow, and terminate immediately when - * it does remove it, so we never walk the hash after doing a deletion. + * call to hash_foreach() looks dangerous but is in fact OK: each call + * will remove at most one shadow, and terminate immediately when it does + * remove it, so we never walk the hash after doing a deletion. */ #define DO_UNSHADOW(_type) do { \ t = (_type); \ @@ -2199,7 +2199,7 @@ void sh_remove_shadows(struct domain *d, (pg->shadow_flags & (1 << t)) ) \ { \ HASH_CALLBACKS_CHECK(SHF_page_type_mask); \ - hash_domain_foreach(d, masks[t], callbacks, smfn); \ + hash_foreach(d, masks[t], callbacks, smfn); \ } \ } while (0) @@ -3163,7 +3163,7 @@ int shadow_domctl(struct domain *d, void shadow_audit_tables(struct vcpu *v) { /* Dispatch table for getting per-type functions */ - static const hash_domain_callback_t callbacks[SH_type_unused] = { + static const hash_callback_t callbacks[SH_type_unused] = { #if SHADOW_AUDIT & (SHADOW_AUDIT_ENTRIES | SHADOW_AUDIT_ENTRIES_FULL) # ifdef CONFIG_HVM [SH_type_l1_32_shadow] = SHADOW_INTERNAL_NAME(sh_audit_l1_table, 2), @@ -3210,7 +3210,7 @@ void shadow_audit_tables(struct vcpu *v) HASH_CALLBACKS_CHECK(SHADOW_AUDIT & (SHADOW_AUDIT_ENTRIES | SHADOW_AUDIT_ENTRIES_FULL) ? SHF_page_type_mask : 0); - hash_domain_foreach(v->domain, mask, callbacks, INVALID_MFN); + hash_foreach(v->domain, mask, callbacks, INVALID_MFN); } #ifdef CONFIG_PV From patchwork Wed Jan 11 13:53:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096704 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 90343C46467 for ; Wed, 11 Jan 2023 13:54:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475351.737019 (Exim 4.92) (envelope-from ) id 1pFbYI-0005tG-H2; Wed, 11 Jan 2023 13:54:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475351.737019; Wed, 11 Jan 2023 13:54:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbYI-0005t9-E7; Wed, 11 Jan 2023 13:54:02 +0000 Received: by outflank-mailman (input) for mailman id 475351; Wed, 11 Jan 2023 13:54:01 +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 1pFbYG-0004QI-RZ for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:54:01 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2051.outbound.protection.outlook.com [40.107.13.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 653476f0-91b7-11ed-b8d0-410ff93cb8f0; Wed, 11 Jan 2023 14:53:58 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB8551.eurprd04.prod.outlook.com (2603:10a6:10:2d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:53:57 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Wed, 11 Jan 2023 13:53:57 +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: 653476f0-91b7-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T0w5MUipcezPpMUOlCjSz2ReCrpCgkG9lPNmv3iD7VmzNEWNdmJLYZtq+XQLEOkOlFXpEI9Hei1gleUCfdjCcgeV+2QtyWyFhdhGlxSOmsE7DIQ/3TTW5rnEadV+sG8sp+ahqRpvmiOoVndK3M6eD4o+YEVMTCFhMLgqbf0OxmRB/q0tZxSJdF9Uo3nDr0wOX7kyGxhmORKbrxYUAYBXrd2m4N8fNgR1MjwAiMn7vSvi1ktJwPldr/z9mDoP8qo29HW7YYADRyPm79vtciKYE2EWuzzFoscOKVXHYsf/7LjoAY60TuENiJdHygt3Dzpc58O2PAmwPnlp0gixrgcJuA== 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=I0kOuEOlEby+rFnQkiCiFwCOaJzxSnerJCBJ3RDmWQU=; b=Z6ElVhyAMUi/UwJCJs0O1u01DefWMHCUB6Orz4joRz3nsuR+7CSxK48xhD1mD28p+VrJ+yeTxgQyDIyxoWJhXBAgRT8WXr/MGmqcjMsbFCcebXkS03u8RXwtxpz82tQz46+96qqZNlKeBI5KEILWpcNCymTESy7jLHDAQBcHKQa2+hK2qoL3LRJuiQTVHD161KIm8RcKA7cKo+XuzcGeabWUIXaePO8kwDzhCvBps/d7Qa3aXgReAO79veKISZbe6wFWU85y8B8S6yyDoFeZ7KXDsJH0S87eK5nsbEqcsjc77YYSa+jPdF9R9gF6TlQ5tX0brDIpOxHQ2nRV4+RvEw== 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=I0kOuEOlEby+rFnQkiCiFwCOaJzxSnerJCBJ3RDmWQU=; b=D+iPzFj9uOvdTyzl/BAlIXp31Pl3eVfEUU3POWmMLcWWE0UDYEutYc2eyAsDd/peGUk91ys93mLbgvkQsoyJrrP9idcDJT09Tq9f7d0z/mFQA9kBn5R7gM0p8BeWrQ8iJ3KII1rdM3kuyq/S1VNsLQqdK6/OovgD+0EgD883JmubfcbeeZ4+BI3ddE7zWhuRP5xE+BnfnqF65O8cnjnpT3uHscJj3OEz6MXv3+gJR76/CBNiLxapS3mjNQ/dGdUG0kJcH+pDgFNquheRhx44ZLnruPY55/seIrfrf9vIncUTeXycddt2kPj+FVNZkhU8SSpZbHbI7SPO2zzAQCLQCA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Wed, 11 Jan 2023 14:53:55 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 4/9] x86/shadow: drop a few uses of mfn_valid() 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?= , Tim Deegan , George Dunlap References: In-Reply-To: X-ClientProxiedBy: FR0P281CA0119.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a8::17) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB8551:EE_ X-MS-Office365-Filtering-Correlation-Id: ceb18629-2864-4b6a-72c9-08daf3db48e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HeLBCjs5tZLaz/qQDn4lvkeEN/9Cdqa8kSMhZ4egsF5HzfvJUHan2fT2Qr2uW4F6Dg06aUVRBT0md5Ubu2dE2dbt7XY2M+fgJBuPHjg7S6Zt84zfkma2wQX7kf5dkk9zmjryw2srlxX6OUUvOi3/C4tHIubAfX9Nc7gYEYMrMOIGUroUcHHkzd9Ipqd92wM3PDgQ61tNY981XLpk5nqgJiXJAQQdWCuVs4LdWCZsP9Z+CK1aEmmmFyLUplg7YTkyORoZsgvYBoFiMrD9mS/UVe3zRjsRq76eIbPKKwwgfC0mkGkcsS/eGA3/QugG5SHukS88rL0zU7ZLoQaFnr7Sv4KiWbSpQNnNc3+KvHMcAqaSJ+N4rGxZRpqmWH6ifWlKN2Jr7ZtKa3cIVZmer+p3AlktquNgHDle7PoLt2T4rCuMBhGnFjyMO6YW6aksn55wT6npZ4g+6FbI/5RIwHU7Kw4c7zq0SzPROkvYn5/2rn+wUo7YLzRZMmQ2DAmcgkNVnKjBd2gU96wxDUngSy05ydKGwS0RoqLBomr24MudNBgBLl/FCFrqCQ8V10iaey80GgpULBzDokB1iZ4YBotoH3w/uPv/IVV17aby4cTf4c/8eY2sBcL9+GPS4Y/HSo5bR9wiRvKSIbjH6ueTw9CnyVaJEHIITnpTUPfkd7IiAzufF4VX362Moy1aWdaacuHQFmLFkC+f8EUbW7DnonXvHCL+Prq/Be8TkMdc0RoSQJk= 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)(346002)(39860400002)(366004)(376002)(136003)(396003)(451199015)(8936002)(2906002)(5660300002)(41300700001)(316002)(4326008)(66556008)(8676002)(6916009)(66476007)(66946007)(54906003)(26005)(6512007)(38100700002)(2616005)(31686004)(86362001)(186003)(31696002)(36756003)(6506007)(478600001)(6486002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?vyvbGyeIbNXwqMFnAnCheq2C/Rg1?= =?utf-8?q?GFTsmT+9HnLKhkcH1NDwYdwHhMY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61pxMdNQT8TZVJdw7XDC6dmaL+7wp9v4ge35+kYnoSF6?= =?utf-8?q?aSavu+0jJ1QA8Qpt232VrROssobcsxnrxkecNPvMjnPRMx71paTsoA4lKWjr2HSwX?= =?utf-8?q?okB7T+N2X73xMMp9/Djzp4dhBXnJnKAqNDKFwuOdyWOqpzdor2t5ikUzZEf62h+yr?= =?utf-8?q?qb+ZWNWtpvNj7bfZus2fW1ixrpyRXv+iIMtDBHetLZYUxcSigY+5bWMzoMEem/Dbi?= =?utf-8?q?NkkyuXZy3Bp7hZQoryL7yasfV8CGRBI+WYq1sVlkPVfa2BGMyKIxjFLrgl0QiPSDS?= =?utf-8?q?jmuCM1XuH0viqiU2KlUFl1la9OeOt4HDJQXhWdAKw9fAEhNLVDJP4GyCtq1FI1oHU?= =?utf-8?q?2v/QZoCBjW9TWkGNVlqHort49kQsOg4WPTDElX4hS2xpJsbIglP9BcBrEw5noGI8r?= =?utf-8?q?We8dbR9G3o2B/LhfIiXevYe/bOQF+2s1h+K6Q1zzgSa/fhb9EzBDG/VGKiMXJgWvR?= =?utf-8?q?4pcP6C5FmHBzkdwSF+D+bJgj/2J0xrpSl55GYHeYMAe+g662JXf73g5JqBck0MWhJ?= =?utf-8?q?W6P26q5et4LbZkuO5C/04jn7BPMPUN0d6706cANECMid9C02Dn0kwb8CzMJUXneG6?= =?utf-8?q?IIDT0sm82yoL?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ceb18629-2864-4b6a-72c9-08daf3db48e6 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:53:57.3733 (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: EdZUxOQLlrgiCcJthcHQjk82pY9X6E/noJvMiC7aCIPAwcRaIVAlDxqWnDHzLPf60dASdU8f+U646z5H7AyNeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8551 v->arch.paging.shadow.shadow_table[], v->arch.paging.shadow.oos[], v->arch.paging.shadow.oos_{snapshot[],fixup[].smfn[]} as well as the hash table are all only ever written with valid MFNs or INVALID_MFN. Avoid the somewhat expensive mfn_valid() when checking MFNs coming from these arrays. Signed-off-by: Jan Beulich --- There are many more uses which can likely be replaced, but I think we're better off doing this in piecemeal fashion. --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -171,7 +171,7 @@ static void sh_oos_audit(struct domain * for ( idx = 0; idx < SHADOW_OOS_PAGES; idx++ ) { mfn_t *oos = v->arch.paging.shadow.oos; - if ( !mfn_valid(oos[idx]) ) + if ( mfn_eq(oos[idx], INVALID_MFN) ) continue; expected_idx = mfn_x(oos[idx]) % SHADOW_OOS_PAGES; @@ -327,8 +327,7 @@ void oos_fixup_add(struct domain *d, mfn int i; for ( i = 0; i < SHADOW_OOS_FIXUPS; i++ ) { - if ( mfn_valid(oos_fixup[idx].smfn[i]) - && mfn_eq(oos_fixup[idx].smfn[i], smfn) + if ( mfn_eq(oos_fixup[idx].smfn[i], smfn) && (oos_fixup[idx].off[i] == off) ) return; } @@ -461,7 +460,7 @@ static void oos_hash_add(struct vcpu *v, idx = mfn_x(gmfn) % SHADOW_OOS_PAGES; oidx = idx; - if ( mfn_valid(oos[idx]) + if ( !mfn_eq(oos[idx], INVALID_MFN) && (mfn_x(oos[idx]) % SHADOW_OOS_PAGES) == idx ) { /* Punt the current occupant into the next slot */ @@ -470,8 +469,8 @@ static void oos_hash_add(struct vcpu *v, swap = 1; idx = (idx + 1) % SHADOW_OOS_PAGES; } - if ( mfn_valid(oos[idx]) ) - { + if ( !mfn_eq(oos[idx], INVALID_MFN) ) + { /* Crush the current occupant. */ _sh_resync(v, oos[idx], &oos_fixup[idx], oos_snapshot[idx]); perfc_incr(shadow_unsync_evict); @@ -607,7 +606,7 @@ void sh_resync_all(struct vcpu *v, int s /* First: resync all of this vcpu's oos pages */ for ( idx = 0; idx < SHADOW_OOS_PAGES; idx++ ) - if ( mfn_valid(oos[idx]) ) + if ( !mfn_eq(oos[idx], INVALID_MFN) ) { /* Write-protect and sync contents */ _sh_resync(v, oos[idx], &oos_fixup[idx], oos_snapshot[idx]); @@ -630,7 +629,7 @@ void sh_resync_all(struct vcpu *v, int s for ( idx = 0; idx < SHADOW_OOS_PAGES; idx++ ) { - if ( !mfn_valid(oos[idx]) ) + if ( mfn_eq(oos[idx], INVALID_MFN) ) continue; if ( skip ) @@ -2183,7 +2182,7 @@ void sh_remove_shadows(struct domain *d, !(pg->shadow_flags & (1 << t)) ) \ break; \ smfn = shadow_hash_lookup(d, mfn_x(gmfn), t); \ - if ( unlikely(!mfn_valid(smfn)) ) \ + if ( unlikely(mfn_eq(smfn, INVALID_MFN)) ) \ { \ printk(XENLOG_G_ERR "gmfn %"PRI_mfn" has flags %#x" \ " but no type-%#x shadow\n", \ @@ -2751,7 +2750,7 @@ void shadow_teardown(struct domain *d, b int i; mfn_t *oos_snapshot = v->arch.paging.shadow.oos_snapshot; for ( i = 0; i < SHADOW_OOS_PAGES; i++ ) - if ( mfn_valid(oos_snapshot[i]) ) + if ( !mfn_eq(oos_snapshot[i], INVALID_MFN) ) { shadow_free(d, oos_snapshot[i]); oos_snapshot[i] = INVALID_MFN; @@ -2934,7 +2933,7 @@ static int shadow_one_bit_disable(struct int i; mfn_t *oos_snapshot = v->arch.paging.shadow.oos_snapshot; for ( i = 0; i < SHADOW_OOS_PAGES; i++ ) - if ( mfn_valid(oos_snapshot[i]) ) + if ( !mfn_eq(oos_snapshot[i], INVALID_MFN) ) { shadow_free(d, oos_snapshot[i]); oos_snapshot[i] = INVALID_MFN; --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -110,7 +110,7 @@ get_fl1_shadow_status(struct domain *d, /* Look for FL1 shadows in the hash table */ { mfn_t smfn = shadow_hash_lookup(d, gfn_x(gfn), SH_type_fl1_shadow); - ASSERT(!mfn_valid(smfn) || mfn_to_page(smfn)->u.sh.head); + ASSERT(mfn_eq(smfn, INVALID_MFN) || mfn_to_page(smfn)->u.sh.head); return smfn; } @@ -2680,7 +2680,7 @@ static int cf_check sh_page_fault( mfn_t smfn = pagetable_get_mfn( v->arch.paging.shadow.shadow_table[i]); - if ( mfn_valid(smfn) && (mfn_x(smfn) != 0) ) + if ( mfn_x(smfn) ) { used |= (mfn_to_page(smfn)->v.sh.back == mfn_x(gmfn)); @@ -3824,7 +3824,7 @@ static void cf_check sh_pagetable_dying( : shadow_hash_lookup(d, mfn_x(gmfn), SH_type_l2_pae_shadow); } - if ( mfn_valid(smfn) ) + if ( !mfn_eq(smfn, INVALID_MFN) ) { gmfn = _mfn(mfn_to_page(smfn)->v.sh.back); mfn_to_page(gmfn)->pagetable_dying = true; @@ -3867,7 +3867,7 @@ static void cf_check sh_pagetable_dying( smfn = shadow_hash_lookup(d, mfn_x(gmfn), SH_type_l4_64_shadow); #endif - if ( mfn_valid(smfn) ) + if ( !mfn_eq(smfn, INVALID_MFN) ) { mfn_to_page(gmfn)->pagetable_dying = true; shadow_unhook_mappings(d, smfn, 1/* user pages only */); --- a/xen/arch/x86/mm/shadow/private.h +++ b/xen/arch/x86/mm/shadow/private.h @@ -769,8 +769,10 @@ get_shadow_status(struct domain *d, mfn_ /* Look for shadows in the hash table */ { mfn_t smfn = shadow_hash_lookup(d, mfn_x(gmfn), shadow_type); - ASSERT(!mfn_valid(smfn) || mfn_to_page(smfn)->u.sh.head); + + ASSERT(mfn_eq(smfn, INVALID_MFN) || mfn_to_page(smfn)->u.sh.head); perfc_incr(shadow_get_shadow_status); + return smfn; } From patchwork Wed Jan 11 13:54:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096705 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 E4FF6C46467 for ; Wed, 11 Jan 2023 13:54:31 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475355.737030 (Exim 4.92) (envelope-from ) id 1pFbYc-0006Of-SR; Wed, 11 Jan 2023 13:54:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475355.737030; Wed, 11 Jan 2023 13:54:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbYc-0006OY-Nz; Wed, 11 Jan 2023 13:54:22 +0000 Received: by outflank-mailman (input) for mailman id 475355; Wed, 11 Jan 2023 13:54:21 +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 1pFbYb-0004QI-0J for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:54:21 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2085.outbound.protection.outlook.com [40.107.13.85]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 711636b6-91b7-11ed-b8d0-410ff93cb8f0; Wed, 11 Jan 2023 14:54:18 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB8551.eurprd04.prod.outlook.com (2603:10a6:10:2d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:54:17 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Wed, 11 Jan 2023 13:54:17 +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: 711636b6-91b7-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z/X6hsId14TLdqMovZn6xfbBMq9Vy09EQsW1KtOfE2uZQDRAyfmaFzLkyz3ViIM9A4QhMuDNDyTatk7lgQVqwG/pVCRsBf98lIbuOkmrlLCxHZU4w8rZqVKWu64hR4X/Qpua7y5EGND5muVzYm4UmopsNZl7V0t3Ae2dSxmYKPdc9o2oG0GO7L3h6yYw71BWgxaSn15KxyGmIuwC8ZYOhLV5crDK1M9ctSP3kPMSIaFzrEaVKsrUSXuZml4Vkn5wT0yGQYG73ExU+nui66hoEE4LPM/OAUvjp8yasAlSzqeQyxXqt672K0XwcFejgfZPwt7z4numTwZvT+czRSkxeA== 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=rzqulTEtucE5QZgMYqiUHlGTP59ie28OePbEzibohCE=; b=bfrmh5bfC8MStwAB4C97185IwRk+kJrSjopibru4g4Q0kOZwASoaireZ6dJmnbMNyOgEQJJYQALADPzukl38VdYun6Lorpq8LdlpygLEejqMNh03ewDRt12YU2oq9JRos+qqck1MMuawxxU8v4Ufw9JADOJ8UroPdVuZzdDsvq85SEW42CK0vtdKxTz4QYvmNvHM4FGLlsNaIur81DkvDc9kgx4LUt5b9YsrGKM4ta3v89T2po8mDaCT/8YsX+0hjy5reZ2aCiVGJDC/75YsETO/mCQcvYF/xwTHj041VkFQZ9XvniJv0BnmyZTSwS2w04PNKCDiB5QNYkIHOu6IbA== 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=rzqulTEtucE5QZgMYqiUHlGTP59ie28OePbEzibohCE=; b=wCS9rReg0rpAQ9wiZ7XZRXdBoF/mZkkw+nJC/tq9uC7yQwZq6rUez8dJsa1odzHCxvhrx4YbJwMhOmcFTIEU2f40HUIGkq1Cyl6eXiT9QzAnL5b07Qy1jTBMqVJDIwA8MitB3yjnX4Idd7uo9SpwiK4d1eryLFR0lKRp8I2X0wHb8ynN4ox79woRaghbMNznGo9ZB+6wlPrVwekVy7K1NBaAhMopvP0cpLOzvNQrFLyDcisHAi8q9UCOtm/OY7RdzkY6HMjEzd7RMzR2jUBySg811E+A0nXMS+hrEF8Lhxg/8CBMnR1H7s/e3VWVEd+f6uYjRzFaFQLmb61qHozDiw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Wed, 11 Jan 2023 14:54:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 5/9] x86/shadow: L2H shadow type is PV32-only 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?= , Tim Deegan , George Dunlap References: In-Reply-To: X-ClientProxiedBy: FR2P281CA0017.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::27) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB8551:EE_ X-MS-Office365-Filtering-Correlation-Id: b48130e9-32de-49a3-54e3-08daf3db54e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QhQC/dFlDo4JO9JDWJrG26/1RoDmxezYZQwk3Tp7EvGVrpjotE8XQ1cvkWp36KUSxrgiT2t1paRU1980GqV2OzyoSIPpdViL1aoyXSRFZOCOPbUqFm925eV1CQ0i4l3U5G0o0EM3Ywk+VyEw4RjL1bNyzYDvXdrv+AVqEqVvUg/HO5DcN3Km9STK51lh/6YrI2dSvpmMn/+A/RSVmklO6VvQhcV2zYsF/JRsrogDporW4N8WhaGTKgsiwTLstrg29tGggBUb/BJBVrDOlOvsyANhs3HlOPehYlG0wJ5HH2TAW1opRzBdGvmvuprBXmGhmIORhqQZyUY50szDysVrpGYzQ0CyF04fksBvkct9XcN79Zw9hS4Myk//NC8W5mGGti+LSdqt6+IR+7gz2jFubQEfXLPI7+FkkHT0Tgn9lTkWoTgUluzZntIKapiJJ/I4Toz8WEIj80P+gJGW/aGpmAivVctgodpdqfWPMKKDo2aZKwXdei1hk/NO/7Fl69Eh+JvK4jq5OCtTmz1YfJJc1QC+Gd3kVfuHWTx7Kk/2QG4VkpN9mlFZrRSGjnrcujcY5eqUviySqewL/3hAx7qxRs4VNlY/1C/yD8lYYhZR66rDKz2B0L1NKoMRiHsjQWSx94fBUNdOFVJu44UX0AXRiEWunTH7ZVJYcXXr5sclcDGuzcQa3Bq4KXh6elBVpSVEe2ERodGjxzbXw3wvBAk0C17UP3sP/a6Q+CLdTzj/QVY= 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)(346002)(39860400002)(366004)(376002)(136003)(396003)(451199015)(8936002)(2906002)(5660300002)(41300700001)(316002)(4326008)(66556008)(8676002)(6916009)(66476007)(66946007)(54906003)(26005)(6512007)(38100700002)(2616005)(31686004)(86362001)(186003)(31696002)(83380400001)(36756003)(6506007)(478600001)(6486002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fxTUpTV3uHruJ48V7SdcehpSsr3I?= =?utf-8?q?JXQDSoxjS8YuFZqhonXkDRHSD/mTygxY9CMNDvl6Ao3czRdV9s+wzqvzD8PtIq0uy?= =?utf-8?q?wTmv3mfw2psd/fIcS1/1PlfSo6c1XJnO10AKA1eEUsuwjMZibMMLPfBild4H0JIp+?= =?utf-8?q?PnLO7NqIakY5JafD1qGzc/RJwimeO70tHkCGBnn9xDw2McGifPf8m4LGB8/yprAVh?= =?utf-8?q?f0KR5oMnM1mo57P3b+SQCqKRYMAnpKb48KwIzPqpN7cRSQvCkPMz2lokBrCEtTho7?= =?utf-8?q?5zoG5/RX1q9V1bHP5+0pr33xWXDFmnNC4AV2ZBp7jT6u5VYRW5BLtrbA8HVxrWunu?= =?utf-8?q?de3rcMqkaCVOTmuC4EL++kohiIRhidOMVIdfaSsEfhilN0q7UsqER3Rbs3BUuRBXA?= =?utf-8?q?RZmkaD/j70+ayCTH45SA/DZ7kFjO7BgYTmB7Kx/UJNSppTNyp5+0Ocobytgt4V1kb?= =?utf-8?q?H1oqcPQ4ca7wQV5suLC59GLpGKHajfPUqAAQcMTJVszwDvAQXAwaZ98gHqEb6SAaR?= =?utf-8?q?h3SCr/0lBIRjP2oMp8S2mBhE59OKwZm2DNX7YZ1AS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hUHS1mGflmKTdN?= =?utf-8?q?KCcWr2k06CzD98XRTaFybeiyE6ifpOvyr3vjkh0JUQH1pmb0OUavU19HL2/vndxWd?= =?utf-8?q?WVUXBwToLwbs?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: b48130e9-32de-49a3-54e3-08daf3db54e0 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:54:17.4815 (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: BuP8aE6jpW9NB/8eKpEaOGtNz9K0RdyoeXP/NdoOeawDu7gh95jKzC66swtjXMssOA0sexxtBgIh0rUQ7t8Ahw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8551 Like for the various HVM-only types, save a little bit of code by suitably "masking" this type out when !PV32. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- I wasn't really sure whether it would be worthwhile to also update the "#else" part of shadow_size(). Doing so would be a little tricky, as the type to return 0 for has no name right now; I'd need to move down the #undef to allow for that. Thoughts? --- v2: Merely comment out the sh_type_to_size[] entry. --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -1740,9 +1740,11 @@ void sh_destroy_shadow(struct domain *d, case SH_type_fl1_64_shadow: SHADOW_INTERNAL_NAME(sh_destroy_l1_shadow, 4)(d, smfn); break; +#ifdef CONFIG_PV32 case SH_type_l2h_64_shadow: ASSERT(is_pv_32bit_domain(d)); /* Fall through... */ +#endif case SH_type_l2_64_shadow: SHADOW_INTERNAL_NAME(sh_destroy_l2_shadow, 4)(d, smfn); break; @@ -2095,7 +2097,9 @@ static int sh_remove_shadow_via_pointer( #endif case SH_type_l1_64_shadow: case SH_type_l2_64_shadow: +#ifdef CONFIG_PV32 case SH_type_l2h_64_shadow: +#endif case SH_type_l3_64_shadow: case SH_type_l4_64_shadow: SHADOW_INTERNAL_NAME(sh_clear_shadow_entry, 4)(d, vaddr, pmfn); @@ -2133,7 +2137,9 @@ void sh_remove_shadows(struct domain *d, [SH_type_l2_pae_shadow] = SHADOW_INTERNAL_NAME(sh_remove_l1_shadow, 3), #endif [SH_type_l2_64_shadow] = SHADOW_INTERNAL_NAME(sh_remove_l1_shadow, 4), +#ifdef CONFIG_PV32 [SH_type_l2h_64_shadow] = SHADOW_INTERNAL_NAME(sh_remove_l1_shadow, 4), +#endif [SH_type_l3_64_shadow] = SHADOW_INTERNAL_NAME(sh_remove_l2_shadow, 4), [SH_type_l4_64_shadow] = SHADOW_INTERNAL_NAME(sh_remove_l3_shadow, 4), }; @@ -2146,7 +2152,9 @@ void sh_remove_shadows(struct domain *d, #endif [SH_type_l1_64_shadow] = SHF_L2H_64 | SHF_L2_64, [SH_type_l2_64_shadow] = SHF_L3_64, +#ifdef CONFIG_PV32 [SH_type_l2h_64_shadow] = SHF_L3_64, +#endif [SH_type_l3_64_shadow] = SHF_L4_64, }; @@ -2210,7 +2218,9 @@ void sh_remove_shadows(struct domain *d, #endif DO_UNSHADOW(SH_type_l4_64_shadow); DO_UNSHADOW(SH_type_l3_64_shadow); +#ifdef CONFIG_PV32 DO_UNSHADOW(SH_type_l2h_64_shadow); +#endif DO_UNSHADOW(SH_type_l2_64_shadow); DO_UNSHADOW(SH_type_l1_64_shadow); @@ -3175,7 +3185,9 @@ void shadow_audit_tables(struct vcpu *v) [SH_type_l1_64_shadow] = SHADOW_INTERNAL_NAME(sh_audit_l1_table, 4), [SH_type_fl1_64_shadow] = SHADOW_INTERNAL_NAME(sh_audit_fl1_table, 4), [SH_type_l2_64_shadow] = SHADOW_INTERNAL_NAME(sh_audit_l2_table, 4), +# ifdef CONFIG_PV32 [SH_type_l2h_64_shadow] = SHADOW_INTERNAL_NAME(sh_audit_l2_table, 4), +# endif [SH_type_l3_64_shadow] = SHADOW_INTERNAL_NAME(sh_audit_l3_table, 4), [SH_type_l4_64_shadow] = SHADOW_INTERNAL_NAME(sh_audit_l4_table, 4), #endif --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -56,7 +56,7 @@ const uint8_t sh_type_to_size[] = { [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_l2h_64_shadow] = 1, PV32-only */ [SH_type_l3_64_shadow] = 1, [SH_type_l4_64_shadow] = 1, [SH_type_p2m_table] = 1, --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -97,6 +97,13 @@ static void sh_flush_local(const struct flush_local(guest_flush_tlb_flags(d)); } +#if GUEST_PAGING_LEVELS >= 4 && defined(CONFIG_PV32) +#define ASSERT_VALID_L2(t) \ + ASSERT((t) == SH_type_l2_shadow || (t) == SH_type_l2h_shadow) +#else +#define ASSERT_VALID_L2(t) ASSERT((t) == SH_type_l2_shadow) +#endif + /**************************************************************************/ /* Hash table mapping from guest pagetables to shadows * @@ -337,7 +344,7 @@ static void sh_audit_gw(struct vcpu *v, if ( mfn_valid((smfn = get_shadow_status(d, gw->l2mfn, SH_type_l2_shadow))) ) sh_audit_l2_table(d, smfn, INVALID_MFN); -#if GUEST_PAGING_LEVELS >= 4 /* 32-bit PV only */ +#if GUEST_PAGING_LEVELS >= 4 && defined(CONFIG_PV32) if ( mfn_valid((smfn = get_shadow_status(d, gw->l2mfn, SH_type_l2h_shadow))) ) sh_audit_l2_table(d, smfn, INVALID_MFN); @@ -859,13 +866,12 @@ do { int _i; \ int _xen = !shadow_mode_external(_dom); \ shadow_l2e_t *_sp = map_domain_page((_sl2mfn)); \ - ASSERT(mfn_to_page(_sl2mfn)->u.sh.type == SH_type_l2_64_shadow ||\ - mfn_to_page(_sl2mfn)->u.sh.type == SH_type_l2h_64_shadow);\ + ASSERT_VALID_L2(mfn_to_page(_sl2mfn)->u.sh.type); \ for ( _i = 0; _i < SHADOW_L2_PAGETABLE_ENTRIES; _i++ ) \ { \ if ( (!(_xen)) \ || !is_pv_32bit_domain(_dom) \ - || mfn_to_page(_sl2mfn)->u.sh.type != SH_type_l2h_64_shadow \ + || mfn_to_page(_sl2mfn)->u.sh.type == SH_type_l2_64_shadow \ || (_i < COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(_dom)) ) \ { \ (_sl2e) = _sp + _i; \ @@ -992,6 +998,7 @@ sh_make_shadow(struct vcpu *v, mfn_t gmf } break; +#ifdef CONFIG_PV32 case SH_type_l2h_shadow: BUILD_BUG_ON(sizeof(l2_pgentry_t) != sizeof(shadow_l2e_t)); if ( is_pv_32bit_domain(d) ) @@ -1002,6 +1009,8 @@ sh_make_shadow(struct vcpu *v, mfn_t gmf unmap_domain_page(l2t); } break; +#endif + default: /* Do nothing */ break; } } @@ -1123,11 +1132,13 @@ static shadow_l2e_t * shadow_get_and_cre shadow_l3e_t new_sl3e; unsigned int t = SH_type_l2_shadow; +#ifdef CONFIG_PV32 /* Tag compat L2 containing hypervisor (m2p) mappings */ if ( is_pv_32bit_domain(d) && guest_l4_table_offset(gw->va) == 0 && guest_l3_table_offset(gw->va) == 3 ) t = SH_type_l2h_shadow; +#endif /* No l2 shadow installed: find and install it. */ *sl2mfn = get_shadow_status(d, gw->l2mfn, t); @@ -1337,11 +1348,7 @@ void sh_destroy_l2_shadow(struct domain SHADOW_DEBUG(DESTROY_SHADOW, "%"PRI_mfn"\n", mfn_x(smfn)); -#if GUEST_PAGING_LEVELS >= 4 - ASSERT(t == SH_type_l2_shadow || t == SH_type_l2h_shadow); -#else - ASSERT(t == SH_type_l2_shadow); -#endif + ASSERT_VALID_L2(t); ASSERT(sp->u.sh.head); /* Record that the guest page isn't shadowed any more (in this type) */ @@ -1865,7 +1872,7 @@ int sh_map_and_validate_gl2he(struct vcpu *v, mfn_t gl2mfn, void *new_gl2p, u32 size) { -#if GUEST_PAGING_LEVELS >= 4 +#if GUEST_PAGING_LEVELS >= 4 && defined(CONFIG_PV32) return sh_map_and_validate(v, gl2mfn, new_gl2p, size, SH_type_l2h_shadow, shadow_l2_index, @@ -3674,7 +3681,7 @@ void sh_clear_shadow_entry(struct domain shadow_set_l1e(d, ep, shadow_l1e_empty(), p2m_invalid, smfn); break; case SH_type_l2_shadow: -#if GUEST_PAGING_LEVELS >= 4 +#if GUEST_PAGING_LEVELS >= 4 && defined(CONFIG_PV32) case SH_type_l2h_shadow: #endif shadow_set_l2e(d, ep, shadow_l2e_empty(), smfn); @@ -4124,14 +4131,16 @@ int cf_check sh_audit_l3_table(struct do if ( SHADOW_AUDIT & SHADOW_AUDIT_ENTRIES_MFNS ) { + unsigned int t = SH_type_l2_shadow; + gfn = guest_l3e_get_gfn(*gl3e); mfn = shadow_l3e_get_mfn(*sl3e); - gmfn = get_shadow_status(d, get_gfn_query_unlocked( - d, gfn_x(gfn), &p2mt), - (is_pv_32bit_domain(d) && - guest_index(gl3e) == 3) - ? SH_type_l2h_shadow - : SH_type_l2_shadow); +#ifdef CONFIG_PV32 + if ( guest_index(gl3e) == 3 && is_pv_32bit_domain(d) ) + t = SH_type_l2h_shadow; +#endif + gmfn = get_shadow_status( + d, get_gfn_query_unlocked(d, gfn_x(gfn), &p2mt), t); if ( !mfn_eq(gmfn, mfn) ) AUDIT_FAIL(3, "bad translation: gfn %" SH_PRI_gfn " --> %" PRI_mfn " != mfn %" PRI_mfn, --- a/xen/arch/x86/mm/shadow/private.h +++ b/xen/arch/x86/mm/shadow/private.h @@ -209,6 +209,10 @@ extern void shadow_audit_tables(struct v #define SH_type_unused 10U #endif +#ifndef CONFIG_PV32 /* Unused (but uglier to #ifdef above): */ +#undef SH_type_l2h_64_shadow +#endif + /* * What counts as a pinnable shadow? */ @@ -286,7 +290,11 @@ static inline void sh_terminate_list(str #define SHF_L1_64 (1u << SH_type_l1_64_shadow) #define SHF_FL1_64 (1u << SH_type_fl1_64_shadow) #define SHF_L2_64 (1u << SH_type_l2_64_shadow) +#ifdef CONFIG_PV32 #define SHF_L2H_64 (1u << SH_type_l2h_64_shadow) +#else +#define SHF_L2H_64 0 +#endif #define SHF_L3_64 (1u << SH_type_l3_64_shadow) #define SHF_L4_64 (1u << SH_type_l4_64_shadow) From patchwork Wed Jan 11 13:54:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096706 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 A9C2DC5479D for ; Wed, 11 Jan 2023 13:55:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475361.737043 (Exim 4.92) (envelope-from ) id 1pFbZP-00079L-B0; Wed, 11 Jan 2023 13:55:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475361.737043; Wed, 11 Jan 2023 13:55:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbZP-00079E-7w; Wed, 11 Jan 2023 13:55:11 +0000 Received: by outflank-mailman (input) for mailman id 475361; Wed, 11 Jan 2023 13:55:10 +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 1pFbYy-0004QI-Bw for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:54:44 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2059.outbound.protection.outlook.com [40.107.13.59]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7f31bd34-91b7-11ed-b8d0-410ff93cb8f0; Wed, 11 Jan 2023 14:54:42 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB8551.eurprd04.prod.outlook.com (2603:10a6:10:2d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:54:40 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Wed, 11 Jan 2023 13:54:40 +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: 7f31bd34-91b7-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ef4eBs+AKiiy090udEb1VC+i9u//RYUJ5ou3mdLgQ9b6v0NqFQZm3eOYB/2LvKMsMQza4tj4RkVFhV1PXHJI6VJyJbiFPAKMAcfnEFsuSCbco8F3PbSaUozDvVb5GKQdJvFGCu1Z2pwb3GNsS7dIy3CT85Fh4sw2nG95zVepUBfHQaVQORMxlIlmAvrRf5Zcm7DQdiwoVMzH58trVcID0Hw8LTQgpDs8SNBs9tpusHwuXTL8ZCnUGq4SUHdHDWUkJ3ZG9avyKxF4OUWIxAEZQUX5TS+/pQ2oIDcsrrRXfxrr8+LwuC+hr2fo4NY+jAiENdlTLFlnfI/TDt2mfR4Tlg== 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=+A1uJIX8hCVYxMZpSUyJ3UOaNSMYMDBoFU6vGM6iCfg=; b=ZFVuMt3mAXTXntaYkgz/BRN3GtdwR7DDbyo2AL6oRH8Nz3lP/fUHEYmmmsqY0TPv5Qgz4oyTfc+ruFgX6WTZe66E85NXPcWKELzZ0oYWL7xhC0RnF1VUPQG2dYiG9u9Q+dCd5sYctXVmvKOkDo/pdwhYRsAylsYc3uFTxkOldJsVX8B283OMV9bt1aiQDQE6FzRc2mMnfF2Ocnp/0IRt9ucbYoUVVZfAWvuu89fLs8V7dev7MywsglWEgu2aQU9VHvt1ov/SWqkXRysPZCg/Kf9w6+YhtWkUpHVll9euzK4k76P70I9e7eY7kcO2mnwdt4jFaRsraGXrGedM2DWBhg== 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=+A1uJIX8hCVYxMZpSUyJ3UOaNSMYMDBoFU6vGM6iCfg=; b=nzbKpI3XMAKMvios3Vn76ZE44+K5Hsg4OavvTdiW5CyfvFWOqTD41O8F6Ty6dj1xx9bJdhHbg3SaKGZugR4SaR3w9et0Y3glkIcZYXjHK4px8ctLZs1IfBNaO5RkR8HVOLAt7tnVny9YXj3m/R8dQ79PAcMQF/OJWF2X/T0YTl7QQMWVUIFy0Q8sHJB2C1FLf17L9yu4Xj7/LShwjNeLWartGKQKXozKXLBtPVEXJtSo/Bvkqq2IT3xD9Cf96KW5TwCjI4Fi7dIlOTfdj5q4FX8sgTltaiTMskUg4D63GiGiFUMqji4n7BjlpZ9kt/hNSsN41d25q0A8EiMFUTr4LA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <27a7245c-f933-5b2b-5685-d9ba2dbd4a8c@suse.com> Date: Wed, 11 Jan 2023 14:54:38 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 6/9] x86/shadow: re-work 4-level SHADOW_FOREACH_L2E() 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?= , Tim Deegan , George Dunlap References: In-Reply-To: X-ClientProxiedBy: FR3P281CA0032.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::13) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB8551:EE_ X-MS-Office365-Filtering-Correlation-Id: 77f40980-f1c7-40ad-5378-08daf3db62c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x4WqpYgLr3iqSQJb/MamaeokYvbenoEW649EYtu+cuhH/ix4DTkhY1/cFxm4HRpMoKnPwrg+C6hIZnq4G9IOr/UChdZwWP01Tp4cTifMGmiJMzGy/s/TO1o1HXFQrdXwqWX9l/XGRLRn16DufIJtg+ugZYq3OM85llPVxZlCIQbnHtHp6ehipwDi01Qv7MG/PcorOqHey/gJPI8U/vTdjoT+hb7ig2NDjs1jikpb+AkEPvGaofjoQMO1jURtIaCrbBsJsuqsaI3TJjYHVOwd3xDvWPa0eZtpMAlcgXBUsk7JVraBvi4G1PS1y3jYMjc9BkGTK0QfceRDovUheuY3v6V0c/332dtcsxgfcOw0W3jIxcQqqET5zJl+gaDzP5AYw7wI6xbBWlbeKdVYlSLpKJnB5hyAtao+N4g6gMmfKTpyvhRMA4q4t3t+HAeb2Yryh6w0aisnvTIFjhC7AoBpMlDvq+OkfmpcCbFSSTfrOXwweEATVTVdmEURl0BRI2RB3v+4zQ7oy0Bv5KUvkih3hpWgcR2LLxgSx+2LhsXlMfdH0Oiw9WKoyX2dhuwgZV0dl1b440+hre6yNtz7Rrf5/UVV/KJXZewMbISD7h9bH8TM52J8vZyMLO/7Yce38egF8yi14dUhr4uXq66/UovksTI/oZ0aGwVO2sA3m41Ic6vMf47yCkIlVNTY4cZ5Ng2L8a5JHGmfvRL0Lp+GdsGBg99RlRrSAOxQlWDMQWlZ1Hk= 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)(346002)(39860400002)(366004)(376002)(136003)(396003)(451199015)(8936002)(2906002)(5660300002)(41300700001)(316002)(4326008)(66556008)(8676002)(6916009)(66476007)(66946007)(54906003)(26005)(6512007)(38100700002)(2616005)(31686004)(86362001)(186003)(31696002)(36756003)(6506007)(478600001)(6486002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?HySK/f3979eetEtBWxOYiAe3GhJ1?= =?utf-8?q?Mleo9iUcj5frLo5qqIj0SOrHLhbzcXLep9MkngFezAoMUTLOFMm/WZJofPuKEBIQX?= =?utf-8?q?hd/jT2yxXsufCmEiVWy3CfGKBy6GFlAwL8H2r8L6FPxkMPocFSyqukPnZKZc66fml?= =?utf-8?q?eYZ5CMc3wnPomabAjVCaPXPiD+WMBiMn4pE3cuPisyqRPg1CZjCk978PFX4Sjmj0L?= =?utf-8?q?sikGZWaZ11TsrdlKerG092GEah89UGpDTY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cGtGFQ0F3uBPuHfcnQ3SRelE6HTSUoK?= =?utf-8?q?gcSa9F611VSyccamVM44M7QnIMJt37trE6h6tc6YmA9HAfwF3mKxTH1y0lpngkham?= =?utf-8?q?EaCEnhqEHtMc/JBttoGg6FwjNNi8i5eAPr8+1fE2GP5dcO09XnIL7dupCvhVhCw1c?= =?utf-8?q?ZnsnedEDYwRJ+jUDb4ksjVngEf1blP69C3oz56GSvooN/uXGSPy/APoldDzfCwggI?= =?utf-8?q?Tibj0c+H0BwfyQHz+mOnQVz9mIjI0SSMq9qhZCPYhqGLNCabhreFvG1cGlqaUNVzI?= =?utf-8?q?qY8GVao1ZKw1ASEAoOsP0AfMCUwXzLUCUx79naAT5ioAS41A/Bbtv70WTu14YpArF?= =?utf-8?q?PUlKt/i9634MyeTEqdpdvm6cJ1BWHSqR49krrZO7ruqMD3pBOC8Q0uW1LtPf4c5X2?= =?utf-8?q?e8Z9EKRI8Tce?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77f40980-f1c7-40ad-5378-08daf3db62c5 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:54:40.7770 (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: PcxIjW7TFPzjrc9g8815cBO2A4qjBvxhFlPsiatNZj4DNwJVkZuZ0bA+2/8dbTMDDQC6owX1dFRB+ogtiIVF4A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8551 First of all move the almost loop-invariant condition out of the loop; transform it into an altered loop boundary. Since the new local variable wants to be "unsigned int" and named without violating name space rules, convert the loop induction variable accordingly. Signed-off-by: Jan Beulich --- v2: New. --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -863,23 +863,20 @@ do { /* 64-bit l2: touch all entries except for PAE compat guests. */ #define SHADOW_FOREACH_L2E(_sl2mfn, _sl2e, _gl2p, _done, _dom, _code) \ do { \ - int _i; \ - int _xen = !shadow_mode_external(_dom); \ + unsigned int i_, end_ = SHADOW_L2_PAGETABLE_ENTRIES; \ shadow_l2e_t *_sp = map_domain_page((_sl2mfn)); \ ASSERT_VALID_L2(mfn_to_page(_sl2mfn)->u.sh.type); \ - for ( _i = 0; _i < SHADOW_L2_PAGETABLE_ENTRIES; _i++ ) \ + if ( !shadow_mode_external(_dom) && \ + is_pv_32bit_domain(_dom) && \ + mfn_to_page(_sl2mfn)->u.sh.type != SH_type_l2_64_shadow ) \ + end_ = COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(_dom); \ + for ( i_ = 0; i_ < end_; ++i_ ) \ { \ - if ( (!(_xen)) \ - || !is_pv_32bit_domain(_dom) \ - || mfn_to_page(_sl2mfn)->u.sh.type == SH_type_l2_64_shadow \ - || (_i < COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(_dom)) ) \ - { \ - (_sl2e) = _sp + _i; \ - if ( shadow_l2e_get_flags(*(_sl2e)) & _PAGE_PRESENT ) \ - {_code} \ - if ( _done ) break; \ - increment_ptr_to_guest_entry(_gl2p); \ - } \ + (_sl2e) = _sp + i_; \ + if ( shadow_l2e_get_flags(*(_sl2e)) & _PAGE_PRESENT ) \ + { _code } \ + if ( _done ) break; \ + increment_ptr_to_guest_entry(_gl2p); \ } \ unmap_domain_page(_sp); \ } while (0) From patchwork Wed Jan 11 13:56:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096709 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 A5632C5479D for ; Wed, 11 Jan 2023 13:56:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475373.737055 (Exim 4.92) (envelope-from ) id 1pFban-0007nf-LO; Wed, 11 Jan 2023 13:56:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475373.737055; Wed, 11 Jan 2023 13:56:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFban-0007nY-IS; Wed, 11 Jan 2023 13:56:37 +0000 Received: by outflank-mailman (input) for mailman id 475373; Wed, 11 Jan 2023 13:56:36 +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 1pFbam-0007nL-CY for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:56:36 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2079.outbound.protection.outlook.com [40.107.6.79]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c1f28ee2-91b7-11ed-b8d0-410ff93cb8f0; Wed, 11 Jan 2023 14:56:34 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB9116.eurprd04.prod.outlook.com (2603:10a6:10:2f7::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:56:33 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Wed, 11 Jan 2023 13:56:33 +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: c1f28ee2-91b7-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z953bz3nFFFaQ8kRRDXismk0G7je/7A7feBoknxMk94W9dqBDDOXX4mEzejOYUSw3B7Gm2NMmgpZukW2t5lpVPYGUkCSlCelD7rN6bMJjHwC0llDL8OBOh1OQnYWbEJYX3kTM82iRHqLLv27sjzLtwosLtL7qO688g9QjzxwGDIgHN+uqUP6cJqF8Dr9iDGYliahGOBv/59fat9luHaLFVVhkqBiClnw5Nk+OmtbAfPTLo32/WmnTN02h8x/k6NUmfa1zGvMXUY3G2Q/hwdd8zYVJQS6pWwR5dq9jDVtYOJRPC98z9xfdZWiXLrAP4BJZLkQ8h8PAmtbxeylI0Gqaw== 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=dOlBxwttZ7/+xseKnKOuiqz4kR/3+d88oza4XKWQx5c=; b=Q1F0GUfzbx8Z7UvU8AP+nNyj1rjYDxJ1ByQvE6awNcYfvdXADwXV1/RYwBNikqX8XWKMepjsSwsLiFqbPKOa+ulf5x5FLjtUjYC3gDHMSzCcmmAOSE1RwugoCnXY+pzcc1ekm1JZFeDYQMqHLCEgGaP2XheeW0HbSL0GfS4P7XmOzUVv6viabhuHXXtXQR+gW+8YmCLLB4lmW6lwGdLqxBrdopLfKRTW4DEonhELpNlONWyca/sU8ZJvHVkzUWjpWEK8GWQ8VCSNrg817ewABmRVY4ivcr6e2fI6JSgyqF+jT715XW8F/2sHT5eChtkneZu7tJXAUPi/qxbzW1D19g== 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=dOlBxwttZ7/+xseKnKOuiqz4kR/3+d88oza4XKWQx5c=; b=zoh4veZ5PfqSLe389B4cbTUw2GjeL30lAIp39GgmDuMjqPaDGQwXQ3n6Mya3x+aZe8aKg2gEIrmsKi+DI0EFlcUwDuEotmelba3NFWnbj/DyGovZyCBm3aw4Bip+8VOsGS5vyaUNZxKyplNQmNKsUOnL16yVwDIhGcTY0+r+tFoRcHygdPQ3+qQ67U3XCKuPLElbHZODMf6PuVaZWVx0FuzLmLwP1fHQZXqg0sqHt4my+ptl4fs1vOzAzJpD937p/TexMbUCXPb7NQY76kZNRK/5l769OhKspd8VFjEoeUZkYmDd3RTaBuWLeBVPnFWlCLSdOomfw/VLhOmTbuxeIw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <4785b34b-2672-e3a8-8096-df1365b6b7b8@suse.com> Date: Wed, 11 Jan 2023 14:56:30 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 7/9] x86/shadow: reduce effort of hash calculation 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?= , Tim Deegan , George Dunlap References: In-Reply-To: X-ClientProxiedBy: FR2P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::28) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB9116:EE_ X-MS-Office365-Filtering-Correlation-Id: 91fef956-0412-4031-5c15-08daf3dba5a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5D8H1G5oecUJkQHviGT+zZZ6KmsDOeRgaOgDikazts7wgSrYXYRltyRh9cP9HxiWIYeayePzRP0CpZgDpExaPme0fTXXW1HpPT6LUJEiIuh7MlrmbRh64+QUeaDKZdeFUDAgBcRWVLK0IOmOajbGy0nbxleD84HcoVq24l0R8s8WhbrnU+QCNAJvYh6bUDWt9PH3wfXJBHklpmNTqSA9/ZRnnYAgaZgo3cWlQ92MzUuVoxqQ3gwsIan2omIxKU+8SycGAAtT/zJ1o4I8NqMZyfRgFcW6qN+3vMuLSvTh8c0Nl6Oj8UipEL4Yu8IR24id1bWMECkSdRBIZMg4JA+x8eOvIUWNDFwl36paZftkxmQryqtCVcRNHMmWLMz6ZNaBh/M2Pvcbw5iq7GBKidkhh/PZcR28PJXqwk5O42yeCdE2O7AG3N5qmdhbkBYMWLN8N/PewCioNlfPTIAlOoTBgwH/z/Ure7Plg8FcWj7uTx0M6RYuV8Tp3OvJ9JzR3QMX45SEfgVTN/k660eAvAjO1WlNrS20lJ6100fED/3se3k8ShIcbmA57eOdkoQpHX3h9oIUE7jJj/cMML4kGQmvLS7B3ULSQBkRpHSviY5EWPKXapIvvJf3vMP9Yn2FVK83mCUfhQJ7f1qFJK3RycR+Hz/0z3B6CGKFPhhIPpMfgG7+j+6kwMBo71I8afZOm5sVmo9DXmzDZlQq8PYg3Wtu57JY1P0Rn6t3ugCWc00aM0g= 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)(136003)(346002)(39860400002)(366004)(376002)(396003)(451199015)(8676002)(66946007)(31686004)(41300700001)(2906002)(8936002)(5660300002)(36756003)(6916009)(66476007)(316002)(6512007)(66556008)(54906003)(478600001)(6486002)(6506007)(4326008)(26005)(186003)(2616005)(31696002)(86362001)(38100700002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?LWfzM6LLXkhx7jDQqMknnMbAWlex?= =?utf-8?q?PPDtcEbMr9uJck2A+OcNjtRmlwCpm/HM+UdVWgzbSaJaK67zmp8YzJ+x0lfXcysgQ?= =?utf-8?q?Jq5WAYiXMqGaOeu5S/qaJ98AualM6LFxxBVFMUIAdAtgOeYMlUFQl7xchY043bnG/?= =?utf-8?q?Oh2FQeT9vgIfL18Ylg52eajhuXfWUG4MW2w9bdHCPaJTtxIN3+jML4QMNuSUdrSMT?= =?utf-8?q?HZA1rbcn051S06oqB6uy9oUijc9EnY2qqvd9ybgbLABUHhQVxgHepmITQbL+o0qHr?= =?utf-8?q?s5tklQI4ps1AMEjzQxbsDqKZvaZa7HUyh+gU8S3lWAJNWjm83qRdbI7WJ48nJg0X3?= =?utf-8?q?GSQ3VkewPJnNe34roZNHaojo9f8twsnKXFZHDrqUF1fjyCFSfl5lVaRpW2YbBMddT?= =?utf-8?q?elQZxHt+qx7qaDh8OnTBhWv1+AuCEd2Jw8t7PKJolPqXzu+w0oB20lnB8xE5AOD1k?= =?utf-8?q?ZnzYK3f8YaWMqnhjLQFsomt2Ps/52aysOiX1CGenk3zZ9MBGoAggh90iPYvMLZjhS?= =?utf-8?q?e08fWmbOD5WxixCxz2bPjcBf+26ja4hLdGS3VdSAbH8gNyTVUpbR82l76N5TC4ek8?= =?utf-8?q?ypfjJWVlGpcSKPq6BhjGu4QnJVwZ58nAHZn9YxSnVFC7z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TD2PBzy?= =?utf-8?q?j1aXfaRBETlv?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91fef956-0412-4031-5c15-08daf3dba5a0 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:56:32.9577 (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: tHszxTT8ffrBZ8Z8eMdO5NeCQq5truvEfqlaFWhfwO2foFKWTbPB/zn+tpAyS9Sk9fDjwYbs/fR/TedndyqQ/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB9116 The "n" input is a GFN/MFN value and hence bounded by the physical address bits in use on a system. The hash quality won't improve by also including the upper always-zero bits in the calculation. To keep things as compile-time-constant as they were before, use PADDR_BITS (not paddr_bits) for loop bounding. This reduces loop iterations from 8 to 5. While there also drop the unnecessary conversion to an array of unsigned char, moving the value off the stack altogether (at least with optimization enabled). Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- I was tempted to also change the type "i" (unsigned) right here, but then thought this might be going too far ... --- v2: Also eliminate the unsigned char * alias of "n". --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -1397,10 +1397,13 @@ static unsigned int shadow_get_allocatio typedef u32 key_t; static inline key_t sh_hash(unsigned long n, unsigned int t) { - unsigned char *p = (unsigned char *)&n; key_t k = t; int i; - for ( i = 0; i < sizeof(n) ; i++ ) k = (u32)p[i] + (k<<6) + (k<<16) - k; + + BUILD_BUG_ON(PADDR_BITS > BITS_PER_LONG + PAGE_SHIFT); + for ( i = 0; i < (PADDR_BITS - PAGE_SHIFT + 7) / 8; i++, n >>= 8 ) + k = (uint8_t)n + (k << 6) + (k << 16) - k; + return k % SHADOW_HASH_BUCKETS; } From patchwork Wed Jan 11 13:57:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096710 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 76A56C46467 for ; Wed, 11 Jan 2023 13:57:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475378.737066 (Exim 4.92) (envelope-from ) id 1pFbbQ-0008LM-V4; Wed, 11 Jan 2023 13:57:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475378.737066; Wed, 11 Jan 2023 13:57:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbbQ-0008LF-Re; Wed, 11 Jan 2023 13:57:16 +0000 Received: by outflank-mailman (input) for mailman id 475378; Wed, 11 Jan 2023 13:57:15 +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 1pFbbP-0008Kv-Ik for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:57:15 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2046.outbound.protection.outlook.com [40.107.6.46]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d904d9cd-91b7-11ed-b8d0-410ff93cb8f0; Wed, 11 Jan 2023 14:57:13 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DB9PR04MB8073.eurprd04.prod.outlook.com (2603:10a6:10:24d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:57:10 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Wed, 11 Jan 2023 13:57:10 +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: d904d9cd-91b7-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WkxdgB88KE20zyOORVTy4RosbNtgrxGjpkEM4pysQbT6Xyuok9jeYshiM5nlk1quYhhnR/AfPYh+iLgpZESwSSe0eTOtGfz+cEimMVJEnSRjIy8t4wAMp+z0OgQDDLOAk2vDr7NRSa/MfljoqUB/7I8Wj8LPHO9PPvFd3N35vkppXmRQPNURGKz7m4SbjKz4CTvW0RlHD58+Ye1QaR2uSdszSG3RpNUpWF6P8/BKJanme3WMkc171FwXK90CDfktz08xJj30uslkkx1cedVju1E082c5NVM8hPnvwj5Ea5y1OXOQbhfeEVP3gIryZ1YINutue9mRIb54p6mkPL5Oaw== 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=4uJicMk7KMO3J5OufWXUur+3R2HmbLQ7mvJAVkX8lh8=; b=oMaoI6rCBCF4h4BIMNx5AZVZaysitmIpl4TslSq3cA9CRJuaJGk2K1hpEbet1TY6Ww2SYu4QXKUkA8994sbkVYCBbCQFi0rK1ye6W9Mzk77h9zpO3zWFx97KSDdl1Pl5KDOz4JTuc0REUnlkhA9ir0NGxThmGwGYIGPW2Mdjz8qA6bhXKvM3OPj9IojyY2iCHBbrSj9LxCxVPeHBCfPeJjczUozxgUjNHSPAzEESz61nk7sKAXviTYM9xjOv0HabjZV5+okcXg7pouU6IBDkY+SD9tkhq5jtvCs/KeRhxqyeQy1PHp27dsfzb2j8EE457wduSTwBHauezRNEYUPGgg== 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=4uJicMk7KMO3J5OufWXUur+3R2HmbLQ7mvJAVkX8lh8=; b=nqmqe3S8mTfCKPnKooPJn3xO7qpQ2zgZehLK8bKuRblnamQ4eY2+ube8v+U3MCnVCpySm83FwL4HNEW/bJ4adUvaIhvHGOBeCTp44bBSsjd/zslBzK2UfljntcWeVIgjz3n08Xaqmd2T3Kei62q1umZ0ypAILWfY0E9+KlIhRviEbqBmewGlaLmPPd4CkLEIwlk84SbPtN15FQkxjjoqP7CGvu0uG13ZDvi2zr/lgOfpkW+SZc4Y1BxOLd46s6lpYBAOTcEUhettJzN6waR0HjTlSXy9HD8IQdQX985Qz1E0AV9RiFFuB0yrAvBs/XBdzAMyL+/NQW7V22i1bwb/RQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <8ed7a628-f64e-5512-efdb-4116a7b88a1d@suse.com> Date: Wed, 11 Jan 2023 14:57:08 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 8/9] x86/shadow: call sh_detach_old_tables() directly 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?= , Tim Deegan , George Dunlap References: In-Reply-To: X-ClientProxiedBy: FR2P281CA0013.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::23) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DB9PR04MB8073:EE_ X-MS-Office365-Filtering-Correlation-Id: 20e7719b-0f12-4f63-25a1-08daf3dbbbb0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZgIDrbmRswtSGvu6MoAAcu7vvOSz/wPQRTry08dJSX3634u1ry+j3My45I9rbrN8h+cYbw+JkOoE7FEvS5jcIwWc9vdviTyT+9+oBWj6XV3Ngbc5fq7EqluLonco25s3apsYZ4jO1BvXC/DjH62lpQ7QSJfA02D1axIsluS17jXRnPwsA/XDrrQSCANTsKcMCavjfaJwcZBoQGHtNtXB/DOw42bwMAi3/7GZ8q5zIalYF9ENQUwJqyiIp/Ed+HmrbFc9B9hbjQIyHSaXlcfOV+vGc20a1uOzJKJCRknaQvFLWKj4NYXL2jIKuAZaeg5eW4mQ2J+huNtXdS/saTeGUQr99gTSwNRBZ3pFz3LMi1/R3vbO6g1Bs/pI+3o99sHJsL6qqojXUTribFiZh+R7XMmOpZ5LiukOcmnmeqIKKSe34M/owp1EizLyrc6kAnQVLl8NcjCcOQaBDwxUfMpazEHJytXzaWjuTgXFQFZVa/21R1zDEqZA9Bfd0ykzgUwfxGNVqItNQPWb/GKX0e8D4zZhESYo7ipJ5wheM3OlybAwo2+kv0tu4De48TsehZBRWg9SCoOywZUbRSeCuTx2OI3l3kFVfimbs5DRvd7rTyelb+6aM3GHUYricboHX+yXgQuE2OnYvD9K99xCejeVOP0E3LEfUJ8/NcIgnzcVkVgzi2yHUFyH+eL+yqmyPzr3eNTPNA/yU3xdS8SlEo4yoZuEu3k9tIhnQlmWlCvj8tY= 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)(136003)(346002)(39860400002)(366004)(376002)(396003)(451199015)(8676002)(66946007)(66899015)(31686004)(41300700001)(2906002)(8936002)(5660300002)(36756003)(6916009)(66476007)(316002)(6512007)(66556008)(54906003)(478600001)(6486002)(6506007)(4326008)(26005)(186003)(2616005)(31696002)(83380400001)(86362001)(38100700002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fKr0MALs2qxNI2mI2o5wsbxfIg9Z?= =?utf-8?q?XqNPYC1kLO035pEaewCmiOI8dfWNCe8z8GRveHBl2xU/Vy1cJbJfOA+WryERy+pSS?= =?utf-8?q?peBcgkQSg7jDYIVEMpblB6s96wLPW+LOUkesNsUkyDiR0QI1CTLvHm8hsQvu8Xsgs?= =?utf-8?q?dhrvcC13i2e06AjkToUe/o4hybrfs/aDGF4nR9iy3mxP3M/fck8WdFJGzLWBI6IB6?= =?utf-8?q?57p0HaFiZe6JL7CSgbag9NG94J3MfH31o44ysncp8UFxpPsRg55glSmOSON5a5tgi?= =?utf-8?q?VmL9zWHq01LtB5r0KUJQGORNCQc/9H+HYoaXEeWU4dJRjMgOJzEqFmxJutcreuTj9?= =?utf-8?q?wJXBXyaKBo8fK3FxnYTEE+Q4FnlT0/XjXSZKcUILFWi1EDOuSGsDvgdeqp2R5kguQ?= =?utf-8?q?1yFx06IfRUwyHDYStQ9LLKDtW7M+TDt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LwqHgmvwnsdrRedmqmWVSXDNU7Kzm8CCTHEIeDxmqm?= =?utf-8?q?Ai91Oh8TNU2z/2Z7WvvNXwAzeDxot7s6reYgAUfCe/NHseFnmZU10EpDm0dxHANr8?= =?utf-8?q?EmilzXTZ9FLiiZ+gvwDtliaIHSqC95de2ZgE6FDirDDAik4rf2b4FbFjnP6is88+r?= =?utf-8?q?AYLVmkxta7QUnN5vIx/R8dOZBemZIaLwfR8dNQXrVXZqd6TqqlWorlnuLGjl/kkkM?= =?utf-8?q?qVKnBFdTycSf?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20e7719b-0f12-4f63-25a1-08daf3dbbbb0 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:57:09.9710 (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: +Vq5kjVN7hzmzI0kfPp2Xo60nZXLZRWRwkdQFhwAZ+gM4VOpt2VsS7kUEHIVAUs+Jf4so/fkWL3tyupUAX3Z7g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB8073 There's nothing really mode specific in this function anymore (the varying number of valid entries in v->arch.paging.shadow.shadow_table[] is dealt with fine by the zero check, and we have other similar cases of iterating through the full array in common.c), and hence there's neither a need to have multiple instances of it, nor does it need calling through a function pointer. Signed-off-by: Jan Beulich --- I've retained the C++-style comment in the function as this style is used elsewhere as well in shadow code. I wouldn't mind changing the comment to conform to ./CODING_STYLE. --- v2: New. --- a/xen/arch/x86/include/asm/paging.h +++ b/xen/arch/x86/include/asm/paging.h @@ -98,7 +98,6 @@ struct shadow_paging_mode { #ifdef CONFIG_SHADOW_PAGING - void (*detach_old_tables )(struct vcpu *v); #ifdef CONFIG_PV void (*write_guest_entry )(struct vcpu *v, intpte_t *p, intpte_t new, mfn_t gmfn); --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -2264,6 +2264,29 @@ void shadow_prepare_page_type_change(str shadow_remove_all_shadows(d, page_to_mfn(page)); } +/* + * Removes v->arch.paging.shadow.shadow_table[]. + * Does all appropriate management/bookkeeping/refcounting/etc... + */ +static void sh_detach_old_tables(struct vcpu *v) +{ + struct domain *d = v->domain; + unsigned int i; + + //// + //// vcpu->arch.paging.shadow.shadow_table[] + //// + + for ( i = 0; i < ARRAY_SIZE(v->arch.paging.shadow.shadow_table); ++i ) + { + mfn_t smfn = pagetable_get_mfn(v->arch.paging.shadow.shadow_table[i]); + + if ( mfn_x(smfn) ) + sh_put_ref(d, smfn, 0); + v->arch.paging.shadow.shadow_table[i] = pagetable_null(); + } +} + /**************************************************************************/ static void sh_update_paging_modes(struct vcpu *v) @@ -2312,7 +2335,7 @@ static void sh_update_paging_modes(struc // First, tear down any old shadow tables held by this vcpu. // if ( v->arch.paging.mode ) - v->arch.paging.mode->shadow.detach_old_tables(v); + sh_detach_old_tables(v); #ifdef CONFIG_HVM if ( is_hvm_domain(d) ) @@ -2700,7 +2723,7 @@ void shadow_vcpu_teardown(struct vcpu *v if ( !paging_mode_shadow(d) || !v->arch.paging.mode ) goto out; - v->arch.paging.mode->shadow.detach_old_tables(v); + sh_detach_old_tables(v); #ifdef CONFIG_HVM if ( shadow_mode_external(d) ) { @@ -2935,7 +2958,7 @@ static int shadow_one_bit_disable(struct for_each_vcpu(d, v) { if ( v->arch.paging.mode ) - v->arch.paging.mode->shadow.detach_old_tables(v); + sh_detach_old_tables(v); if ( !(v->arch.flags & TF_kernel_mode) ) make_cr3(v, pagetable_get_mfn(v->arch.guest_table_user)); else --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -3207,30 +3207,6 @@ sh_update_linear_entries(struct vcpu *v) sh_flush_local(d); } - -/* - * Removes v->arch.paging.shadow.shadow_table[]. - * Does all appropriate management/bookkeeping/refcounting/etc... - */ -static void cf_check sh_detach_old_tables(struct vcpu *v) -{ - struct domain *d = v->domain; - mfn_t smfn; - unsigned int i; - - //// - //// vcpu->arch.paging.shadow.shadow_table[] - //// - - for_each_shadow_table(v, i) - { - smfn = pagetable_get_mfn(v->arch.paging.shadow.shadow_table[i]); - if ( mfn_x(smfn) ) - sh_put_ref(d, smfn, 0); - v->arch.paging.shadow.shadow_table[i] = pagetable_null(); - } -} - static void cf_check sh_update_cr3(struct vcpu *v, int do_locking, bool noflush) /* Updates vcpu->arch.cr3 after the guest has changed CR3. * Paravirtual guests should set v->arch.guest_table (and guest_table_user, @@ -4211,7 +4187,6 @@ const struct paging_mode sh_paging_mode .update_paging_modes = shadow_update_paging_modes, .flush_tlb = shadow_flush_tlb, .guest_levels = GUEST_PAGING_LEVELS, - .shadow.detach_old_tables = sh_detach_old_tables, #ifdef CONFIG_PV .shadow.write_guest_entry = sh_write_guest_entry, .shadow.cmpxchg_guest_entry = sh_cmpxchg_guest_entry, --- a/xen/arch/x86/mm/shadow/types.h +++ b/xen/arch/x86/mm/shadow/types.h @@ -236,7 +236,6 @@ static inline shadow_l4e_t shadow_l4e_fr #define sh_unhook_pae_mappings INTERNAL_NAME(sh_unhook_pae_mappings) #define sh_unhook_64b_mappings INTERNAL_NAME(sh_unhook_64b_mappings) #define sh_paging_mode INTERNAL_NAME(sh_paging_mode) -#define sh_detach_old_tables INTERNAL_NAME(sh_detach_old_tables) #define sh_audit_l1_table INTERNAL_NAME(sh_audit_l1_table) #define sh_audit_fl1_table INTERNAL_NAME(sh_audit_fl1_table) #define sh_audit_l2_table INTERNAL_NAME(sh_audit_l2_table) From patchwork Wed Jan 11 13:57:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096711 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 70856C46467 for ; Wed, 11 Jan 2023 13:58:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475386.737077 (Exim 4.92) (envelope-from ) id 1pFbc8-0000YC-9I; Wed, 11 Jan 2023 13:58:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475386.737077; Wed, 11 Jan 2023 13:58:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbc8-0000Y5-6b; Wed, 11 Jan 2023 13:58:00 +0000 Received: by outflank-mailman (input) for mailman id 475386; Wed, 11 Jan 2023 13:57:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFbc6-0008Co-5B for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:57:58 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2068.outbound.protection.outlook.com [40.107.6.68]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f3a98656-91b7-11ed-91b6-6bf2151ebd3b; Wed, 11 Jan 2023 14:57:57 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DB9PR04MB8073.eurprd04.prod.outlook.com (2603:10a6:10:24d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:57:56 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Wed, 11 Jan 2023 13:57:56 +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: f3a98656-91b7-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TSRKM4oRF64gC77pPF7nUVgW9tf0uMUPNbvDdzwKSND6YmoJUfF0iuVSTtzSaYmNkSCX8TEHXa68Pm+0oRj5ciyS3hRsvNMdR30ao483g5gPf0bv8VwRtd1qWPszc7w9Sx47PS8kzY37oluYMRNkVQR243c0L7F+z+063GgedLF5tncE9JUitRgzKj0gAftE5TG1HmoDiJcdPEsrmUDYHyVTRlIc5bKCiojTWN8S//Pi4enidjmE5yxRv5TCt3lbi19HZnTkGrgaVZp8xvbGrmsl5vtYE6vvs/fTuqN4vHT9bRAKZsZ0F9DvEnXZ4FP75tVihJVYkZgsAudVgKZM4w== 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=bY7YXGCVxaLa3//TMr+/cVinLxzirB14/tYwJGkYJjk=; b=hNLalCz4m6o2ykOlQQqlaXVOBukHG/SzuXvBpL6I5w0hkkZ8sND+rODYbJhiH9fxxfgQ/JDfZdI1Jb/uXidSrHCMLL/J68l3rxrOaYX+e04eKqR1WRMiU52Bw3/ezmfgpcKdbBBzD9M0+TYeYyknAx/uHbPpLAVxjHhNSwvgPPT2PfDvp0Y/A0mO13PFupLAeVeMNEOA2cI0n1fEsjr8BluLqHsOXlQm/SPKilIAdpbNIMJ542CfeV0x6x0DvQ9Wz1Io2X8U7TamTKAf+w1bxySpLgQ/rDQo0iHKZZ9OlmCZkpObocl2jBmameezeLH9uSUbAQiLlzaq1AWGH5QUFQ== 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=bY7YXGCVxaLa3//TMr+/cVinLxzirB14/tYwJGkYJjk=; b=N15A5ATS7ywjuhcOKx2GNBO/I77JMKDUY5NiRnwW0ihxCok6GzCNdKVxNM+UKRew7PFspHLI6Ke7RKwxnEAXRxrcDhh90l2HIk1ez3oVS4BmNYys3Quna7BcUZGlW/rPUbh9xX/1nz7jkEVw/KwMrpuKLJQymjoAmxq+qtdyaVnP0aD6h2bTGiFbEATGwNDQMaVVIis+CA0L5gFTygdC5MJQc/9Pyi+M62Pm3GnEwaqKpPoXWKIscq4OymCv+OVllyrvZos45eYzSOt6NDQenUy2e56RQWu+mVAmyh5YBZ5HmBrUcTmnwzVIUKwHX031ShxldS7rDUbcfOEoGgLfrA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <9bea51eb-4fbd-b061-52d7-c6c234d060a1@suse.com> Date: Wed, 11 Jan 2023 14:57:54 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 9/9] x86/shadow: harden shadow_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?= , Tim Deegan , George Dunlap References: In-Reply-To: X-ClientProxiedBy: FR3P281CA0175.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a0::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_|DB9PR04MB8073:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e217842-588d-493e-9601-08daf3dbd751 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VZsiGfwYLcPJVSOfMGpKtPDMqAtgpCG3tRjXgraxkoxOwP/vfVnUVrOWXD7eA7crR7rcnHAJsbW6QxV49Y29YxfC51Eez7ATGuh8k7UclifmXlunV8HIHe9tdMWqEjQ/FkPVz3zGBI64PRG/uS6ae6U4/aT80Ck+D9fsnoaolM1HxUk7hNZYZQbXyTtK+zIocV5MIjvcvsbvCyKB8vLZQXVrmh6WFMFiunp16NHmlTnTzM42pRoZlOVNBFmzm38ajohznsS10rEomS6bL4nZWbUC6JcbYtHhef/TBapRrYGubtJCkJYryaGBiBh12QmB/QzeWMReX+16YhQgzXknWnskOsJBN75ogglRB7TSwi+7jjBGT4cVmcFUMuQe3PeM4Wr+OWmeN/ywSxdgLsc0d51P87UwAIPoISZ/OA1bEGJJu4NH8qP3AwBVmSt17+wI7Y9WvUsQKgfx2/rK8+TA+NEpvnUt9FRdEjV7hD32TNTUMUKxF0sTJknXaVsW/AH4I6CfHOnNFs1STYQybiVRhYmq81dNEl8832LKn0Nh1SVsotRpyuboolVqf2+I4pQxJgHCH5Po752CQ0f7V50ZRRaMXveI+ejZ77OUDAdCIqEttnFcx3eqgtjG1OTj6QEP2SyMqPDWcJK9WPhcZIudEq7mch0/xLfRKcngvOGoX870MgMCZ4HERAZVI0+hw5U3/p4bc7D5O8kmLi93aVMNbZNeV7PaqWLI7asoaooh1Nk= 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)(136003)(346002)(39860400002)(366004)(376002)(396003)(451199015)(8676002)(66946007)(31686004)(41300700001)(2906002)(8936002)(5660300002)(36756003)(4744005)(6916009)(66476007)(316002)(6512007)(66556008)(54906003)(478600001)(6486002)(6506007)(4326008)(26005)(186003)(2616005)(31696002)(83380400001)(86362001)(38100700002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?JIWIsK0cfHTVaGh6kx4RQoMZaSUV?= =?utf-8?q?9SiwQ2ibaF8TwMdIctPgcN6wNDCLMS4qq+x2iwiV5CLZyREXDhPzjB5bTVA7klUFk?= =?utf-8?q?r3H8mKg9exQ2foQ0oC/DNrDSizNBnCnhbxA0TAqV8cXCiHuJFjZdNByGtEcqvdwXA?= =?utf-8?q?CdmHP5U+p/Owclg11REqb6L/VnxQZ2k4L2e7NYOi66EFRFVbqm/SPyBRwA+TAtdgM?= =?utf-8?q?AFJguOJZGlW6GKZjjMd4qG+GyLiz2Gf8hgdOekwqVysQG3xixLr1+ha8A4fh3itWc?= =?utf-8?q?Ubflsym3Du6OIjqGv4AT5cceellzCfpsUhs/IUfDPD5r5cNpwVEAlVUfBhJu1LC7L?= =?utf-8?q?hvFbWLVDz0EN33VlOQQnFFgWkTykzxJmUnhH4HMcsmY4ULwPX+M62G77V4243UxDw?= =?utf-8?q?xZJZmKBqWhAhzy6rnGa/kaWsXQmsRKwVwBUveVIvLjWACyoIoLUmKJ8x3tE5uu8vY?= =?utf-8?q?7JyW7BtmrIxFxHqbGt6csVU/WqRKGMFl77LPCxyffFk3H1RPNOwL1gawh4TEvadyH?= =?utf-8?q?rN+vevOmC7K8wh6uVKaOuQpieyilfQsv661mcK4Xwl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lT61dFmbglkwte?= =?utf-8?q?fHHZR3CqHEqHSjVN3sPO5sJ6F02o4gdULbBQ0/9uIw4xKkldU/TzYLX1ZvyxHW57h?= =?utf-8?q?GX7+O2wCHpOf?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e217842-588d-493e-9601-08daf3dbd751 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:57:56.3119 (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: pNl8/x3onggPgJYTTXZSXr9YCczCD1KgrwhkC/lBGac3cJeF+R61O/ju2UbgrjpkCx/Jb9QOq1oFBgqWWxTkVw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB8073 Make HVM=y release build behavior prone against array overrun, by (ab)using array_access_nospec(). This is in particular to guard against e.g. SH_type_unused making it here unintentionally. Signed-off-by: Jan Beulich --- v2: New. --- a/xen/arch/x86/mm/shadow/private.h +++ b/xen/arch/x86/mm/shadow/private.h @@ -27,6 +27,7 @@ // been included... #include #include +#include #include #include #include @@ -368,7 +369,7 @@ shadow_size(unsigned int shadow_type) { #ifdef CONFIG_HVM ASSERT(shadow_type < ARRAY_SIZE(sh_type_to_size)); - return sh_type_to_size[shadow_type]; + return array_access_nospec(sh_type_to_size, shadow_type); #else ASSERT(shadow_type < SH_type_unused); return shadow_type != SH_type_none;