From patchwork Tue Jul 19 06:51:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12922160 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 CBC2DC43334 for ; Tue, 19 Jul 2022 06:51:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.370388.602124 (Exim 4.92) (envelope-from ) id 1oDh4s-0007Pu-To; Tue, 19 Jul 2022 06:51:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 370388.602124; Tue, 19 Jul 2022 06:51:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oDh4s-0007Pn-R7; Tue, 19 Jul 2022 06:51:30 +0000 Received: by outflank-mailman (input) for mailman id 370388; Tue, 19 Jul 2022 06:51:29 +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 1oDh4r-0007PT-6F for xen-devel@lists.xenproject.org; Tue, 19 Jul 2022 06:51:29 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60040.outbound.protection.outlook.com [40.107.6.40]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 36764033-072f-11ed-924f-1f966e50362f; Tue, 19 Jul 2022 08:51:28 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by VI1PR04MB4864.eurprd04.prod.outlook.com (2603:10a6:803:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.23; Tue, 19 Jul 2022 06:51:26 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::60ad:4d78:a28a:7df4]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::60ad:4d78:a28a:7df4%4]) with mapi id 15.20.5438.023; Tue, 19 Jul 2022 06:51:26 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 36764033-072f-11ed-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KbiE3zWVC5WVler8SD89pel9wCvicZ9R1afzRi8659kChHWxmLiiaYpi3rsRei5wW/QBNodj8k6PXqKHMdHYbSBDW7H+GLBpO2XcoGFb26Zv934WYXq8yOpdK8vMLi0qjfmxiJXYwVenQD8S2KFjv5HIDmfUEgb5UBOM6m2Z39m2ZySD152/aGRdnlHTQ/+Uqc4FWiP3bAyxuheuHt+cRdH/HJrEysdMdZCCBXwoGKyH5JyCglrFaKb/b6Yuy1DSBuVxUtA7v8VuE2Xd07Ado6B4gz+/oF/8P3ZDII5NmpHWoSIvq8H7CNumRGL5JK3yfgXVa5/SNia8K2YPGPx9Qg== 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=paHBxFxNPQQaCR96HVsNx65Tk5J0VvsjBSY4OoT4Sio=; b=Hoh3lq6XiDGPbxbdRPnX4ZUDdj9Bw3XDgWqBsQsBiLHGOXvMMRm+1hRGxU+fXVE11h9gMqFLTXEJdHcXvO+GJ8D/t1nL2Zf3swuS8/yl1NA43RxfDZBDYC6hb98rihtD1dGCLN38rB26jqwp1p6iT9IB2eqL/e/7T+L5ODoIf+YCTxVljja1hgTsSFMv4mr2VI8FA+on2Qs/EfLwq0HzYgdNOuH77j/I65SM3j9+xpgAW/mmPvcSyUmiifS3MaTIpRPO9T6WqRqzCI3v3Cz931Dox/KHvXiGE4+Vie/mDy1CLOj0BtgRFwlUvwpHlC+03/R9m/BpuEeYxyCr6WlUag== 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=paHBxFxNPQQaCR96HVsNx65Tk5J0VvsjBSY4OoT4Sio=; b=1XGyKKJEsBeixiiMEm00aG6kStOlKbmVNdIyRbbTiN6ZfWvygDIfv+nZWP/1TVyt+YnOBXyP1IKgSz2Hq4GKwdTK/ORRu/fwdLOvbDzO9VCDIAoah9bWDN/cB9fHaHOckko3v4CCzHQeIiBKLPLAkn/4szkQ+F+NGjYnXpxcL//fFZJuDwQbYSLAdocZ2pGXs5/Z9TbC7OC8pGE4+Ks5fM4QmsFVs+WTrzNyZDg8jTnon3AXeIedHrjCkKe4Ls/FvFKIB+HwhocMixwzlee8OgnIk9OLtVq9dY9sLdLGZzDDeGyLezpiZCfMBgaPzF6oiwnI2GV0FbAtZacJxltw3Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 19 Jul 2022 08:51:25 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH v2 1/4] x86/shadow: slightly consolidate sh_unshadow_for_p2m_change() (part I) Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Tim Deegan References: <1c14781b-e1a2-e049-c0ea-a12585f74e7e@suse.com> In-Reply-To: <1c14781b-e1a2-e049-c0ea-a12585f74e7e@suse.com> X-ClientProxiedBy: FR3P281CA0177.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a0::14) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 87e014f8-376a-4d6a-631d-08da695319de X-MS-TrafficTypeDiagnostic: VI1PR04MB4864:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mVHgulCKwys5y/cLt2vGebB7vgdTFuGxVRrMhC0FIBsC0ndpq1z4GZ1hqw8RHTEbgxsbMToSK86AkRNiERLLGnCy/m8FfCTWx1aLgKjQ8nonJub/SNI/2/qQF9EcL9whovZuPypyR/JgHx9+3/KAppuHwTncD4JbwchRpNUYTy9GOJLMllrUyw4Dlw17B3lpegYdukwDUH4d8x9+P/cdrVLuOCGGSQZzx/FfXTAnMacATM8vYwwO3TEig9Y/bw+UdfIY1bVkycxjoAhKUzVXF786fnFATYqnq9VhZtfKAxJt3GRDUmBn6Xm0/dj/bhWEXqADVxLj1xsr4RDlevc38PVK/E0f0VTI2W18p+kp3Xra8ttmyt67zLV+3/JYle/AG9nqRAR0oOZ3AhHxhtgprQaz+glnxVJB//JreGOh5Vj3Pt4c7KiDzRZ77HJ/uj0fmpVuRQGFOOqjW8SX/LkzgKAZQVPhPRGpHi48X/1U0nuhrBJVxSR/pGZmzLQS2qwSgLby2mkpXlbRCkNwXrlgaKRU6CzHJ3cmXKS2TOjxQi2FcreiNv+sockyC55xzUCWljrvb9s6mu45t66VAz5InC5jTt5o99Tf+L8uGg2bsHgLp66sCuceDjtV2nvuPODi3ZdmMLrIeDrEmTHesxB3Y6S/r9iyw9qTFXBmTtYyumbWw/378ExHLBFHXMQwcbNwjvHTbqxBZivWIcYBRrOBQyXpdpZYANYKwWeQLMT3PLtYyInVunD5Wa6CDCVFfJjA9cR+EpVTJwYgznT7Q6dH6zPMrr0V0Og++W3gHBTidvpKAqANYb3rfupL2HenqG72YxogLzks4mxFTVpyuEPcem+oQ2LQXlqwAxriwaepu8k= 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:(13230016)(366004)(39860400002)(136003)(396003)(376002)(346002)(316002)(6486002)(478600001)(36756003)(31686004)(41300700001)(6506007)(2616005)(8676002)(6916009)(6512007)(186003)(5660300002)(8936002)(4326008)(4744005)(66946007)(66556008)(66476007)(26005)(38100700002)(2906002)(86362001)(31696002)(54906003)(70780200001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?dF/H04KdDPAn9vZTGK1+wkrC7NLC?= =?utf-8?q?eAEX+FBiS9GDjT1AlB1cBm/YhtQds9bN+xatVoCXRSa0G3sWp55236T7yRu+FAmkI?= =?utf-8?q?RNnScvuq9yuB6xhjVZqT3gKBUaiLjyFYcROTtRTAA4jD9taSbEhnomwaHIE/Pj0wM?= =?utf-8?q?m4l/H6Hxavw/c3iundq02GMDzT7OLB6HV4iJBgdCulS59WKb8Mbw/6FfaCxwU5bPP?= =?utf-8?q?cDivqaYEUlIJkTcXdbUXczk9GJ3J3xF78rBada+rx2avqx40k6FKhZJpPT2v001rA?= =?utf-8?q?IQl7/PqkfiTUslIWCrIahI/jfa6Cu3Bly5jCVqr23Cs+9nDLsQ64Ik/48Skt7MKt1?= =?utf-8?q?kqeGeRjaPZ62puGWqogYEigmy0e+XaBwoGTpzeHpyIhf1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xIVCVkcD?= =?utf-8?q?blFRipH+F/lWmYx0SWn5II3PrFauNDMEWqqmA9/I+lsxYUX+/QZRyLZxSEMKpOzlS?= =?utf-8?q?xLA9J77KhzKTbunwuo7rP6mPggexkxR2WW78vkwUjwXZVNW3h8Ben59EnVNPgvbII?= =?utf-8?q?KOiW45eWv/lM1OT/iAfQu0nb+oz5RIPvLZAONc5dqxHrk0t2JZo7e6OuCVW0JWY5/?= =?utf-8?q?UKsZKZiTWTGNopkWN9JK1O40r4FgphU9Y5J2NbyjBEzQZx4sKva2vbMuBQPf0/u4b?= =?utf-8?q?Ll/afNx6BUYy?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87e014f8-376a-4d6a-631d-08da695319de X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2022 06:51:26.4803 (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: D7k6zspi0qjbCukCaEefeeFZ/JIVbXv7Teb2Mmah6Bbq2fg/eRNNOzyulegGstxpIaEFYQjHs+gV+VtvH/LXKQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4864 Replace a p2m_is_ram() check in the 2M case by an explicit _PAGE_PRESENT one, to make more obvious that the subsequent l1e_get_mfn() actually retrieves something that really is an MFN. It doesn't really matter whether it's RAM, as the subsequent comparison with the original MFN is going to lead to zapping of everything except the "same MFN again" case. Signed-off-by: Jan Beulich --- v2: Split from previous bigger patch. --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -856,7 +856,7 @@ static void cf_check sh_unshadow_for_p2m for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) { if ( !npte || - !p2m_is_ram(p2m_flags_to_type(l1e_get_flags(npte[i]))) || + !(l1e_get_flags(npte[i]) & _PAGE_PRESENT) || !mfn_eq(l1e_get_mfn(npte[i]), omfn) ) { /* This GFN->MFN mapping has gone away */ From patchwork Tue Jul 19 06:51:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12922161 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 7FC47C433EF for ; Tue, 19 Jul 2022 06:52:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.370392.602135 (Exim 4.92) (envelope-from ) id 1oDh5E-0007va-53; Tue, 19 Jul 2022 06:51:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 370392.602135; Tue, 19 Jul 2022 06:51:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oDh5E-0007vO-2M; Tue, 19 Jul 2022 06:51:52 +0000 Received: by outflank-mailman (input) for mailman id 370392; Tue, 19 Jul 2022 06:51:50 +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 1oDh5C-0007PT-20 for xen-devel@lists.xenproject.org; Tue, 19 Jul 2022 06:51:50 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60060.outbound.protection.outlook.com [40.107.6.60]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 430d8ea7-072f-11ed-924f-1f966e50362f; Tue, 19 Jul 2022 08:51:49 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by VI1PR04MB4864.eurprd04.prod.outlook.com (2603:10a6:803:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.23; Tue, 19 Jul 2022 06:51:47 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::60ad:4d78:a28a:7df4]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::60ad:4d78:a28a:7df4%4]) with mapi id 15.20.5438.023; Tue, 19 Jul 2022 06:51:47 +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: 430d8ea7-072f-11ed-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AKXvUG0OV/UPnNhsehUSZ+3S89HUpoWJSBHAe+DpWBSk7ddS/VemjKezEgIqkf1p4E2RRt8pKXCtMtY3+zlNmBNHcSyoL9Sghz2Sr1u9Ce1UExpuwPX8WDf13DyJMtdj/DOEDewcAAoyJrsQMXSWR9W5bth4aNhy67xjt/WeH9yVXmEhD6+vkqXoiHjxOtYREAOk4iWvj4B8IKdmqvRFbH4bkTQ4w0vaqdsgDiHsFbgAUeoNOW/vmpJ4Rmd5lGj9zYE4iTV9se+j6gxIcTI7HPEYiLYuAE6vl6GwKbXkUt6dCXwZNOmxJEmnJ6g9wzlI0Ht31Ojkk1kOdVx0jzK7Vw== 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=n/85LX8vVEsmVTn+P11FrOvSAKeuh/W8CeK3ApKBU1M=; b=fPr19Iy+ho4ZIo93SFtOEwThfKn/m15xv3LYegp1QIw0myQk/r6UYMAh2Azaq34gmgXnWOjRFLc7V9OBp+twtCp+SQPWYuIP0CBJqr6UgOSJBk7NjU8uZCd7fS86P8u/UGAwSixcnyBwElHfqr8pi4n6lWdNcYv4Dw6oSjHOVsFxXIZHntKQT28YVx1FXyNAIlf4XhqRudzQlPbup3kCywzqBqgB5T+CAW9MCWhh/nWD41q0SDNVEDu0nD33apVl7Aql9/DaRXLndnzdqDaq4+ZdA8RIiUklz6+es/y5tPJjf3FNb7KdnQYiHGLuTub+sp/TrMLzKTd37JXtd32AuA== 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=n/85LX8vVEsmVTn+P11FrOvSAKeuh/W8CeK3ApKBU1M=; b=T5R32DcfLrTWi3cXr6J+hYRN5WrWllGMW+QwPsSVxzfoLEjkYx1mHiD+M+VVcHSEiFBOOEEJV78+C6gucdmkJ6VLd/BNn5e+eZ+4J/dHVCRmj1XerZMavw7zq8MW7uWKQyi3DBfqEE9HSILc4JeaUoJf2HYDm4yPernPKlH48JIIMXKwdmo/DKBZgP9Ryl7652POMo/HVr9bAZlDk0gYUmTVZ99Bw/t4QyDXn+1FkybadrXOfMZZBo/m2zPrv6Ge5ctwHDfXtsprNvjEwknZtu4ocUg3hS8DDYXaoELVhpudtOey9D5yiXwKGuAHbtw2Aomd+VgJFSbZVoRJBc6YWg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 19 Jul 2022 08:51:45 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH v2 2/4] x86/shadow: slightly consolidate sh_unshadow_for_p2m_change() (part II) Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Tim Deegan References: <1c14781b-e1a2-e049-c0ea-a12585f74e7e@suse.com> In-Reply-To: <1c14781b-e1a2-e049-c0ea-a12585f74e7e@suse.com> X-ClientProxiedBy: FR3P281CA0166.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a0::9) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3ec5c356-88b5-4d61-efc3-08da69532645 X-MS-TrafficTypeDiagnostic: VI1PR04MB4864:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FYzEQLiY7H9SfWs7udh7/lOXUB6dkmWnNuBjgG7cTACk2DdK/9UHfnF/CH1fvqWVdEpacclTmWJ53+gztzpjiUBWYcjHmA00aVWIn0VeFzS2t0/GrOVWW61Q0JT3Avc3AbOAsPV3rdX4HegOByON+PW/HYD3gvKcdOLKq88YFUBmyzsheyhzi0s4A1X1rFlCn7kcBE5gs960HBdxCDYXdd1FC3h6OiNjddlPgcAcBEzzrszAxJgrrovv9g5EmFkCqvOoJQdl7MNSAnpNBFsr2U+81jVUr2IrboWbS0BhxVpzbFQQ9HkYvclgBc0M68dOle3h63KI7/iDs8OKtTonDemoRdegnk6vY7tzlkg13P5a3WBWmecAGg5uYiGXc/HSLwA5Kqd152atiAqWKSoMeN01t45GgYUPedbpc5xw6BOzSxNhjwJSXPoyMzJ4OpVEi1kSCchd1Lj189pJur9P+T2jFEoa7uhrVyjyGTvspjHY6NagPfRmK/NfUFSj1PZBhEUIt4AMO/jzE+lyCFisHLz9zgSQT71ygN1bmXT/Of8HJZwBnOidVOXmLCYX4hwnii4J759IMeMRf4doL6LElS8fJoCQK7QeSxcAPbGjcvmc3ZUmgC+6nNiTzm8+appehlI3J9dOD25vPrqg4nELyKayn6nWB/ZWbjEQIKntgZ+078ygUAJOXBdLwTBnm4vj02gRLv/VdBWZsj4A2b74rZFbLYsusU5c72pox1OPKlg7w0N6uWH4AKlELEiNCucKoxsuB6nAkKPWxtyMEQX1w1/65a8WU8a6Ag3wyRUfAV0fLWbLV6JT7xSWiIJrZuukzZpE7NnMwNSXhCQun4vUYzoIwXeXzxCbjXGV6kDjeMg= 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:(13230016)(366004)(39860400002)(136003)(396003)(376002)(346002)(83380400001)(316002)(6486002)(478600001)(36756003)(31686004)(41300700001)(6506007)(2616005)(8676002)(6916009)(6512007)(186003)(5660300002)(8936002)(4326008)(66946007)(66556008)(66476007)(26005)(38100700002)(2906002)(86362001)(31696002)(54906003)(70780200001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?m7uRwcXxs/E5NCvv29nhuKqwtx48?= =?utf-8?q?stao0fQME3fFattOKsw4rlEIGAhBp6bgcGPJwrFlgLg3XK59HBcWWtTqDMY+cqeA2?= =?utf-8?q?IRBipgz0xgaIu/de7YHcL5MiqPmrW93NVO3wle0stVnYXSQ+NS5H7ZRsZ7jbc+W00?= =?utf-8?q?VqU/jnekd7rkZixR8aqM1bN0v3nuiKhj1i1PgY6FxZo9LCWTARE2CFiE5noFT+yUX?= =?utf-8?q?nF2mqBbDyMuDEiRAFj7h3597wSuFSwWX+WDbq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Ayystts9d7j1zuXEs4wmpGhUa?= =?utf-8?q?wgQ+fQxdxfCv7uBk8ArX3e765/1c0hGIeufe57e83H3LWMAmP3z9LiMd7H/Lz7u+6?= =?utf-8?q?kWkmSn8oLJPYLBSr851wGGFVdUHKlvUho05VDBC7STSKio/RKQWW8TCQMVW9T0b8i?= =?utf-8?q?KI+1NxNfxxKlTTNDhizofD7q3JtrE9KrgiSmLLH7Pe+fFb51YxJ3Xk6U4yN6RVTj6?= =?utf-8?q?VVWkFmWxEPZ1Zo4urX4TRdoCACxuHvuqIpaM12crUIPxc4KppoxOygidMGTde/xTg?= =?utf-8?q?JJE3gYGkeGPUajqwcVEFUdPq0p5sDZ23TuL9r/+4t2aJTvBwy9/2NFwCRFvBOboev?= =?utf-8?q?EtwH1NM6KE25Y7ZG2hj2eYIoUDjOZQrIpADQ2K0ErmEjDSy5gjDJD5nuBQ3eSJ4vQ?= =?utf-8?q?LlR7yT9x8NQ7?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ec5c356-88b5-4d61-efc3-08da69532645 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2022 06:51:47.2759 (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: ru1h3ajhoveGDcLbf2T0/egZRjZ3z6MI2NEz9nf5UV8q5u3JYz7898SFCrkQdJSZ5jv8Nx1MzOkwaBId0bJTng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4864 Pull common checks out of the switch(). This includes extending a _PAGE_PRESENT check to L1 as well, which presumably was deemed redundant with p2m_is_valid() || p2m_is_grant(), but I think we are better off being explicit in all cases. Note that for L2 (or higher) the grant check isn't strictly necessary, as grants are only ever single pages. Leave a respective assertion. For L1 replace the moved out condition with an MFN comparison: There's no need for any update or flushing when the two match. Signed-off-by: Jan Beulich --- v2: Split from previous bigger patch. Add grant related assertion for L2. --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -798,7 +798,7 @@ static void cf_check sh_unshadow_for_p2m struct domain *d, unsigned long gfn, l1_pgentry_t old, l1_pgentry_t new, unsigned int level) { - mfn_t omfn = l1e_get_mfn(old); + mfn_t omfn = l1e_get_mfn(old), nmfn; unsigned int oflags = l1e_get_flags(old); p2m_type_t p2mt = p2m_flags_to_type(oflags); bool flush = false; @@ -810,19 +810,30 @@ static void cf_check sh_unshadow_for_p2m if ( unlikely(!d->arch.paging.shadow.total_pages) ) return; + /* Only previously present / valid entries need processing. */ + if ( !(oflags & _PAGE_PRESENT) || + (!p2m_is_valid(p2mt) && !p2m_is_grant(p2mt)) || + !mfn_valid(omfn) ) + return; + + nmfn = l1e_get_flags(new) & _PAGE_PRESENT ? l1e_get_mfn(new) : INVALID_MFN; + switch ( level ) { default: /* * The following assertion is to make sure we don't step on 1GB host - * page support of HVM guest. + * page support of HVM guest. Plus we rely on ->set_entry() to never + * be called with orders above PAGE_ORDER_2M, not even to install + * non-present entries (which in principle ought to be fine even + * without respective large page support). */ - ASSERT(!((oflags & _PAGE_PRESENT) && (oflags & _PAGE_PSE))); + ASSERT(!(oflags & _PAGE_PSE)); break; /* If we're removing an MFN from the p2m, remove it from the shadows too */ case 1: - if ( (p2m_is_valid(p2mt) || p2m_is_grant(p2mt)) && mfn_valid(omfn) ) + if ( !mfn_eq(nmfn, omfn) ) { sh_remove_all_shadows_and_parents(d, omfn); if ( sh_remove_all_mappings(d, omfn, _gfn(gfn)) ) @@ -836,13 +847,13 @@ static void cf_check sh_unshadow_for_p2m * scheme, that's OK, but otherwise they must be unshadowed. */ case 2: - if ( !(oflags & _PAGE_PRESENT) || !(oflags & _PAGE_PSE) ) + if ( !(oflags & _PAGE_PSE) ) break; - if ( p2m_is_valid(p2mt) && mfn_valid(omfn) ) + ASSERT(!p2m_is_grant(p2mt)); + { unsigned int i; - mfn_t nmfn = l1e_get_mfn(new); l1_pgentry_t *npte = NULL; /* If we're replacing a superpage with a normal L1 page, map it */ From patchwork Tue Jul 19 06:52:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12922162 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 DC5F4C43334 for ; Tue, 19 Jul 2022 06:52:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.370395.602146 (Exim 4.92) (envelope-from ) id 1oDh5Y-0008Qu-GA; Tue, 19 Jul 2022 06:52:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 370395.602146; Tue, 19 Jul 2022 06:52:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oDh5Y-0008Qn-Bo; Tue, 19 Jul 2022 06:52:12 +0000 Received: by outflank-mailman (input) for mailman id 370395; Tue, 19 Jul 2022 06:52:11 +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 1oDh5X-0008Ov-0X for xen-devel@lists.xenproject.org; Tue, 19 Jul 2022 06:52:11 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60082.outbound.protection.outlook.com [40.107.6.82]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4f7a49cd-072f-11ed-bd2d-47488cf2e6aa; Tue, 19 Jul 2022 08:52:10 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by VI1PR04MB4864.eurprd04.prod.outlook.com (2603:10a6:803:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.23; Tue, 19 Jul 2022 06:52:08 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::60ad:4d78:a28a:7df4]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::60ad:4d78:a28a:7df4%4]) with mapi id 15.20.5438.023; Tue, 19 Jul 2022 06:52:08 +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: 4f7a49cd-072f-11ed-bd2d-47488cf2e6aa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LDe5K/R3ZfIqyr2oCPK9TWvBA+EP3cLt23cytxrAUlvSm5g5T6tZ72QzluKiBiKm1Xm/1A9CYjVN651Jq/QC1Sa5i6jnuVIzApEb5c0Y4APwVsGPFInLnxcNJ/KoCtyP+9JyYFeR71+LuF1Y6as/Wzdqwxf+4UpP/Oj+rT51OYvOJWsqJ6FmQ0Lqa7ql4KB9ww6Nu32UOImgL8QgINJGVFABxeJ6+j8LYyVtVSMQgcOT7M+H0BWWBms6yINB02q6eQddjZUEZwHGvcwjmX0W2uar2gbwW+lb68/myzNxUE9xlBPgX51miSTGQv9+pKCK4A3JubXNzRIJI5yXQdghnQ== 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=MrLpz4xOfSP6s3F5vbYICU8lK4kwS1kPHKk6aMNfEXs=; b=l9pRrY8ivRG0VOWy2y5d8v7+nUGo/VYvm+GiCkAPrvf18vkD0LyR8d/Vr5MvXLjh0cz5oPlQIIaMDNKgYqWWZtUG/cPoqvtqlEQSv3JzCL6mw1PzKArlvaIf3olCMLrMvFiBTBldtbBWXQuInP10AuFFCy+om7OkNsZBGWab9wUOm0/ziOq1N2sXvs5cB5qe0hCRyQkot5ErJWt7UcPYmz7rZeAShw+WfaSfgHybNLcKO/PMSZB7OQTo7Rh2ibIOhQRmqESvVpZVPrCZ/qE5hy9BCN+5LeK3uVdoJls0hIQFSYXh9AXfBupm287UePAVgvMP9+6P1tO599LEDN/PGA== 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=MrLpz4xOfSP6s3F5vbYICU8lK4kwS1kPHKk6aMNfEXs=; b=hOTkYRA6eEm9RqezIcC/K0DmnRO/ljz9KtyC6DKHayzRAkzl8bLXe1Dq63kACn0mTHUGliYRfzcxenR1MFBOEOzA82pukrOkCHEImlW0gsgfeMVi/xR4i7i2eATADbySFEwQyxSLNawFWlqOANYPUFcpojeDA9shaoSRHuYOCNb6TCfT/BY1wpiSVeVeMA9XIYbmiu7nx/2SNWgbaShXt1kSEN58y+Ft5miprmq7/vFczYgwX/ZOIT2/lmb4qMD5Nw/Hd7AGMWZFKkmKIBo9BeIgeNfPP40V0swL+4KHoLqsgNtN8CFCd0JJxAa7Fq8PZEYQRaWGAiHfn38T3T0lbw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <4a13d256-b20c-78a7-54f9-ac094b7b50a5@suse.com> Date: Tue, 19 Jul 2022 08:52:06 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH v2 3/4] x86/shadow: slightly consolidate sh_unshadow_for_p2m_change() (part III) Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Tim Deegan References: <1c14781b-e1a2-e049-c0ea-a12585f74e7e@suse.com> In-Reply-To: <1c14781b-e1a2-e049-c0ea-a12585f74e7e@suse.com> X-ClientProxiedBy: FR3P281CA0173.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a0::15) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 91166a84-8c5f-4dd6-b586-08da695332c7 X-MS-TrafficTypeDiagnostic: VI1PR04MB4864:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bpmdc/ERwLcjploZq4GdqYrfSmTcEzwAbjyPtn6Md+Drw3oOC1aG5PSyMkY2pyYOlKpQdBDl8BHPovzg39br/rguvjJLL28+Is+LCnmCcJk3XfA33GakNDQetqkkIX4thDdh/LB4xrzDpFsBE7tAbqUaakveOzLLH7kTfQmBmTTH1T5rppxuvI6upNu/Sgp1Zjluzcsy88dwVdryz1+j9sgQMGdA4BMFm2SUApOKB4dRkYnXaAAF6iCYcLZhg95nnOEplC4ML29l54F3B/GPTp5Dr1+No83tZwprm7IkzVis6SMMB8xj5izsLElnUGVW47E78bOmNxv0D7pYqwIGsuFBdf1t7IBd7y7oC9CXZcczhLzLn0FxZrXD2vwUQuWPWj0STE4KLZhNQcQAT35AxB1vPer29LUwaI/H39Pn7G23Os1CesUr2e3jNICn27swTsE+EgKjm4TyzQaE4cbYR409JVzeJglfkqZP5n1BZSsNWruoz5OUbMf2rVolGLoeflDLgmCqNFDjeBdlKunygzL5O65lo8uvAH4fEkoMZufGQs3qeHf6O/+Abw0MSqdZ/HG5OdIuuOLt2MtSIzt2lrFMLlYkDVwAl5EhjOQuztMdIb6+Rtf0k6vd+AIygtgAxd0wEChCgVSRehU4mUz3I19KXslXghWRBvkx6R6anuaqupc/hpeYtBoNJBtWMM1apJopK/046coArpo2bnchVC8mpodNsaVYVHoUZpV/X4iIcJI7YwPqt12uuCw24kbrTUaHu7BFuvKClu69sEtlwsSViNXUe2mtFnNMqDsDpslzcQRS9Ff3+GA+/wgGHWD3gfWuMp43VOVc3dZ8cUuVLCMcchzFGFpu4KjOdlWZ1CY= 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:(13230016)(366004)(39860400002)(136003)(396003)(376002)(346002)(316002)(6486002)(478600001)(36756003)(31686004)(41300700001)(6506007)(2616005)(8676002)(6916009)(6512007)(186003)(5660300002)(8936002)(4326008)(66946007)(66556008)(66476007)(26005)(38100700002)(2906002)(86362001)(31696002)(54906003)(70780200001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?sz3qon3v5WqE3vlpTi4CHVbiAR+t?= =?utf-8?q?KSeGp38mlaXsIhZADQlMoxLrCSV3x+7R+CzXCraiYysAL25xVr5/cHvSqsgag4+jd?= =?utf-8?q?iktI6A14qoKqiQCWDUGREbfrfZ5S4lymGYv6XZ2vA8Vhqh4v4/MW4T6vA+MF1UuYf?= =?utf-8?q?jchgjkQSSwhzeemAQfoNMA9Hyy5Ewj7WLncZed2VcRR4OLddtb1Wy/KRDX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=?utf-8?q?ONYCc7Kp4jV5PvcCVhYDu+wliJP9fcrANNsuOOij54JqnAnZ+6V2n/bZT5K9nJ1Nu?= =?utf-8?q?vG/EiCSEUTUEJ4lNy5N612LGROIoY2obA8jIh2svhQyDe29Vtd9tNvE4s3+0m1X9H?= =?utf-8?q?t3A9db3EEwEFH8+gQl/ZwCJH418H6zNGVOu62P1PU8p8uLXTpr37EwsbdPlAwq00O?= =?utf-8?q?wBA86D5pEUBjNY0cEBpANmwZtO/N1QoToZFdAXkKYyNTWeufi+sdhp12Bixe7n8Rf?= =?utf-8?q?9j7S4XpF0YvyU3NowC/kXhjxZZK2WdAwZN8qIyYmG3sSzakmOST2DWgptH0TQ+LzN?= =?utf-8?q?KV/x1En/Gkgn5X9t29C94YHI1jRP11WU4JySsS/ZLTo8ebiWNIWT7pwJPg1Y6zSpE?= =?utf-8?q?l+lmwWOWHr2aeCeigok9Tw7BAfOv4ljS2T4YY/zl+uyeQjW1MsqgLQg7qhwP8ck11?= =?utf-8?q?LEWcbVkV2Wrw?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91166a84-8c5f-4dd6-b586-08da695332c7 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2022 06:52:08.2747 (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: o4cI/4PVXw21SdIx0mi9sPBUHYLZX9lQSbdFPPqtg5EYdeFnRfGrg0Xj8oeJaLPlo5qxzZGblnentF1fccnQxg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4864 In preparation for reactivating the presently dead 2M page path of the function, also deal with the case of replacing an L1 page table all in one go. Signed-off-by: Jan Beulich --- v2: Split from previous bigger patch. --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -847,14 +847,9 @@ static void cf_check sh_unshadow_for_p2m * scheme, that's OK, but otherwise they must be unshadowed. */ case 2: - if ( !(oflags & _PAGE_PSE) ) - break; - - ASSERT(!p2m_is_grant(p2mt)); - { unsigned int i; - l1_pgentry_t *npte = NULL; + l1_pgentry_t *npte = NULL, *opte = NULL; /* If we're replacing a superpage with a normal L1 page, map it */ if ( (l1e_get_flags(new) & _PAGE_PRESENT) && @@ -862,24 +857,39 @@ static void cf_check sh_unshadow_for_p2m mfn_valid(nmfn) ) npte = map_domain_page(nmfn); + /* If we're replacing a normal L1 page, map it as well. */ + if ( !(oflags & _PAGE_PSE) ) + opte = map_domain_page(omfn); + gfn &= ~(L1_PAGETABLE_ENTRIES - 1); for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) { - if ( !npte || - !(l1e_get_flags(npte[i]) & _PAGE_PRESENT) || - !mfn_eq(l1e_get_mfn(npte[i]), omfn) ) + if ( opte ) + { + if ( !(l1e_get_flags(opte[i]) & _PAGE_PRESENT) ) + continue; + omfn = l1e_get_mfn(opte[i]); + } + + if ( npte ) + nmfn = l1e_get_flags(npte[i]) & _PAGE_PRESENT + ? l1e_get_mfn(npte[i]) : INVALID_MFN; + + if ( !mfn_eq(nmfn, omfn) ) { /* This GFN->MFN mapping has gone away */ sh_remove_all_shadows_and_parents(d, omfn); if ( sh_remove_all_mappings(d, omfn, _gfn(gfn + i)) ) flush = true; } + omfn = mfn_add(omfn, 1); + nmfn = mfn_add(nmfn, 1); } - if ( npte ) - unmap_domain_page(npte); + unmap_domain_page(opte); + unmap_domain_page(npte); } break; From patchwork Tue Jul 19 06:53:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12922163 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 B3E3BC433EF for ; Tue, 19 Jul 2022 06:53:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.370404.602157 (Exim 4.92) (envelope-from ) id 1oDh6Z-0000nn-UW; Tue, 19 Jul 2022 06:53:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 370404.602157; Tue, 19 Jul 2022 06:53:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oDh6Z-0000ng-RV; Tue, 19 Jul 2022 06:53:15 +0000 Received: by outflank-mailman (input) for mailman id 370404; Tue, 19 Jul 2022 06:53:14 +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 1oDh6Y-0000nN-CH for xen-devel@lists.xenproject.org; Tue, 19 Jul 2022 06:53:14 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60044.outbound.protection.outlook.com [40.107.6.44]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 753dad94-072f-11ed-bd2d-47488cf2e6aa; Tue, 19 Jul 2022 08:53:13 +0200 (CEST) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by VI1PR04MB4864.eurprd04.prod.outlook.com (2603:10a6:803:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.23; Tue, 19 Jul 2022 06:53:12 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::60ad:4d78:a28a:7df4]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::60ad:4d78:a28a:7df4%4]) with mapi id 15.20.5438.023; Tue, 19 Jul 2022 06:53:12 +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: 753dad94-072f-11ed-bd2d-47488cf2e6aa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cof2+GI8vdZpaohoO4bHksTgSIk7nXYUWbGkWeUQum4/Uo03rAa72EzUXT49YYxRkc4E5nk4OZNzzmjTFUqTdjbL7VTWogbxUc7zdWPkXAwZge3l5E+KK5YGCJr+0NtWfgbePfr/tYjav5+rqlygcnTiK9REgq3Td6ePrYZ4Tcpjq7Z5SORNVe9/r/j1e0T9qXran8mleAY/mjW3dg4LlUb+X4vSTFJHFTrxkb23gdDROh5GP8IGwi+Ew7F8JyDA4MYWKzeV9UheqsZ3M44jkzW/xEnd1iwy/jjrGbwPudV1Sw9VS6/++mLmoelsHAXh8SYHJ5r20bZlWGw6MZa/fA== 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=wMkmvOzz2gve8PQhJ5TEoDWHfH+EBc0eAdwOWdZ75oc=; b=H0QkQ15O6z2hB7d6y5bfj/gQYt2pcScS4iW/Y9ktj0omWg98JNuq7kccpKhzvYndwZYA0aTm9cJFFy0vWfnu6GDGcYpQl1Jiv4D6tqjGY4pqVroJZa3h4ym7hQWuY1RtBLZzVeZrrc4AIH6kHQJpjAMGlGIaOTuGHyQo9FrYV7o4B8c6IBkyloE+kKnOkQASJ5XjUKtS/2VZTcgMEh8y0x+tFHT2nQdeekE3GIt2/fxSkb7UqQmUJdT9PdGLaxbvXkk8sHZkTwpCio8FkKkR241Hztcu+U2d4DDBcdzX8TjPn/GGcZTcxiw5eZoe+FBSO8BnZJMhP8v7MVlTsx5YFA== 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=wMkmvOzz2gve8PQhJ5TEoDWHfH+EBc0eAdwOWdZ75oc=; b=3jPH/gn43Z8h/ZZODxn1/6nWKpuD4N2xETUzh2HVbuw88CB61+hUuMVUO+695BNWHgbMxZysvv5751f3gEwh2KsZhhCB0cxvtdGVIpHVrohoPixdVvDB1kwY2P0frVmls6sXyfZsAbfSZnDAeEbUm02iUT2b7cIJFQGXtM28zuXGxICd43qOXUG/G3712MItp1CE8udezrjGCKgaSD2bsCzoXmT+WAGuJeGiSpMyNU8Ew9XcV9YNWrGAeOrgghLH+AchrAc8vLECQSEVQYZJIGV3Hro08/RDJpBkKxFxR+AjkYxGd8S/lHCVY0noWIe7MDQ9ERlxX51GjEtaoGRX5Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 19 Jul 2022 08:53:10 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH v2 4/4] x86/P2M: allow 2M superpage use for shadowed guests Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Tim Deegan References: <1c14781b-e1a2-e049-c0ea-a12585f74e7e@suse.com> In-Reply-To: <1c14781b-e1a2-e049-c0ea-a12585f74e7e@suse.com> X-ClientProxiedBy: AM6P195CA0079.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:86::20) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 920429f1-9e3c-44b0-d3b0-08da695358e0 X-MS-TrafficTypeDiagnostic: VI1PR04MB4864:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pllr3zMcNAjKGYKwrdZb9/B188Zpm/8+8Zdne288su+2nOgaevmjihyjkyd5e6xGh7aRG2xX80Pr7LTcDk7UEQydUpSLTbv4vRBDq4FKjEsioMiLg1oKrFVScba17JmwGzE+ALhC2oa2ZtUw+PW98cLGO6HvAlm7vJTVDLofD6cVKGjRSfq+f5y1t0i57SWfXADVF5TNKMoH3IhXnUzsGkhjaPbtsLUfeGGmY1I9E6D92CLy99NENMmP/YNrCKcJ29RXWEvUPgRuOIdgFbg9K4m8c+VWpcJsBrGWpZSG/D6bfiIvEzRgeFA66MAXE3xmISAnDkybJIht02hXQFM0i3qL7zsrrvwibZpoXwfhpHQ2njbepGaQ1dGYRtlXYHoKD481RLab8J4GviCVNksXp9+udVP5BqDfg459QJQwhG9t9OOvh4u2WLFelVU1WeaCW1i07xHh1yRki7Qy/mtQblkoY5EF/K2rQxV92poTvj4RSEDBdP2/1teyeIDx31ljMBh2hZshJPKcUKRGYiNsyfJq808FyxwweBjKea6cXHzpKM1CHVIu6Bj86iNJ1xYD+UVKT/EcOhx+TruhqOvss/BXaGMEV6u5NmG6nK9b0MuqunEvX9atJQFZGuyo1H8KVOppY+mtaeOsIhJAzfGGXKc49E1H+Zs0voZHO6nQc2E6/xZOjpYnajCaOSZrPKqj38Jfe0bsHz3u+ggipq9wuwqXLgnfp2AMMl35kw/hxE19ZYPRSD/w+WKqnm4ik7LStCO0CqINE7kIiAYst/5YLwOFiMyupAmL2czxExfa2CntW49Thj7wckwkjQpZedasL5zDa0M/hPR8gmQ/Pj+e3Q== 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:(13230016)(366004)(39860400002)(136003)(396003)(376002)(346002)(83380400001)(316002)(6486002)(478600001)(36756003)(31686004)(41300700001)(6506007)(2616005)(8676002)(6916009)(6512007)(186003)(5660300002)(8936002)(4326008)(66946007)(66556008)(66476007)(26005)(38100700002)(2906002)(86362001)(31696002)(54906003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?iDKe9PeCKPrLRQWPDDJVSJ5yf1C/?= =?utf-8?q?wrXqXPlARELLsAyikDBwm9zxmxrqEVbJ79ufTpxDhIIc7atIEAPkrSDETflPWmV6u?= =?utf-8?q?KhGHeNSlygS3zD38C8ngMjz0HlRCBwz16SEqYN7xu2Xk/mxeg7hMNfZn0dIoHyGgq?= =?utf-8?q?BUkLRekOCPrE0pCtVw70ddjcsrCzr6yVFe9PoBHIhOyKfCX8mzuifAilqBEe5lxKG?= =?utf-8?q?1oz+BQLN1DzHeF+isZkWMKEFlxBMh26CJmm3/kHpShMNk/lammjeT5glRTqRVCfVt?= =?utf-8?q?4KkFGaMQnu+rhQKOQKcqkpzUjRwFBKsx1SL1Uzd6a8JIFZZRNw++p0T2QaLsrrmw/?= =?utf-8?q?8v6/fUsBLWrKlXIsguSCSki8dkp5wO/dEkckxNJndQMImHAX4tz6wTNG3p2e/wOM6?= =?utf-8?q?GhnaNGuprTw9kpPK+6Uth+sOa9SoylEOwtA8HEgm8K1wZs622wDqwPhns8U/aJt+j?= =?utf-8?q?aM7g3g2aQ2wMJT5oLR534q9c/k7tHFJXqfsGA7HohAbWG+DcaWqZI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D4z8g66mZlA3T?= =?utf-8?q?YgmkGHEdcCGB3rb4TEKICg2mJrHQwjiavJohVclHqzzBmOxsgHhlX2lgPHvBktN4Y?= =?utf-8?q?p+Ika4aqhWQpK1v5QJ0G5BdwuY+HPwyBZVoxPlwWBEUirna/HGPzZbu+l9ajSAmLC?= =?utf-8?q?TbXpvKTF2pR6?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 920429f1-9e3c-44b0-d3b0-08da695358e0 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2022 06:53:12.1927 (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: Re0LhPHvqIoW+IecU+zrBprR/+MoqMcl2GuPzkKbrBQRRxAGwFstbUEA7pZ1O/9eFZd5aDCbNKECEm9R5GgeVw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4864 For guests in shadow mode the P2M table gets used only by software. The only place where it matters whether superpages in the P2M can be dealt with is sh_unshadow_for_p2m_change(): The table is never made accessible to hardware for address translation, and the only checks of _PAGE_PSE in P2M entries in shadow code are in this function (all others are against guest page table entries). That function has been capable of handling them even before commit 0ca1669871f8a ("P2M: check whether hap mode is enabled before using 2mb pages") disabled 2M use in this case for dubious reasons ("potential errors when hap is disabled"). While doing this, move "order" into more narrow scope and replace the local variable "d" by a new "hap" one. Signed-off-by: Jan Beulich --- v2: Extend description. --- Strictly speaking "fn_mask" could also be "unsigned int"; I wasn't sure whether changing that would cause objections. While at least sh_unshadow_for_p2m_change() presently relies on this behavior, it is somewhat odd (and inefficient) for p2m_set_entry() to split even non-present mappings. --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -403,28 +403,22 @@ struct page_info *p2m_get_page_from_gfn( int p2m_set_entry(struct p2m_domain *p2m, gfn_t gfn, mfn_t mfn, unsigned int page_order, p2m_type_t p2mt, p2m_access_t p2ma) { - struct domain *d = p2m->domain; + bool hap = hap_enabled(p2m->domain); unsigned long todo = 1ul << page_order; - unsigned int order; int set_rc, rc = 0; ASSERT(gfn_locked_by_me(p2m, gfn)); while ( todo ) { - if ( hap_enabled(d) ) - { - unsigned long fn_mask = !mfn_eq(mfn, INVALID_MFN) ? mfn_x(mfn) : 0; - - fn_mask |= gfn_x(gfn) | todo; - - order = (!(fn_mask & ((1ul << PAGE_ORDER_1G) - 1)) && - hap_has_1gb) ? PAGE_ORDER_1G : - (!(fn_mask & ((1ul << PAGE_ORDER_2M) - 1)) && - hap_has_2mb) ? PAGE_ORDER_2M : PAGE_ORDER_4K; - } - else - order = 0; + unsigned long fn_mask = (!mfn_eq(mfn, INVALID_MFN) ? mfn_x(mfn) : 0) | + gfn_x(gfn) | todo; + unsigned int order = (!(fn_mask & ((1ul << PAGE_ORDER_1G) - 1)) && + hap && hap_has_1gb) + ? PAGE_ORDER_1G + : (!(fn_mask & ((1ul << PAGE_ORDER_2M) - 1)) && + (!hap || hap_has_2mb)) + ? PAGE_ORDER_2M : PAGE_ORDER_4K; set_rc = p2m->set_entry(p2m, gfn, mfn, order, p2mt, p2ma, -1); if ( set_rc )