From patchwork Wed May 3 15:55:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13230296 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 C9882C77B7F for ; Wed, 3 May 2023 15:55:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.529326.823627 (Exim 4.92) (envelope-from ) id 1puEp9-0002cn-GK; Wed, 03 May 2023 15:55:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 529326.823627; Wed, 03 May 2023 15:55:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1puEp9-0002cg-Cl; Wed, 03 May 2023 15:55:23 +0000 Received: by outflank-mailman (input) for mailman id 529326; Wed, 03 May 2023 15:55: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 1puEp7-0002MD-Cz for xen-devel@lists.xenproject.org; Wed, 03 May 2023 15:55:21 +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 e783c349-e9ca-11ed-8611-37d641c3527e; Wed, 03 May 2023 17:55:19 +0200 (CEST) Received: from AM6PR04MB6551.eurprd04.prod.outlook.com (2603:10a6:20b:fa::20) by DU0PR04MB9658.eurprd04.prod.outlook.com (2603:10a6:10:31f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 15:55:13 +0000 Received: from AM6PR04MB6551.eurprd04.prod.outlook.com ([fe80::768c:6df7:9afb:acd7]) by AM6PR04MB6551.eurprd04.prod.outlook.com ([fe80::768c:6df7:9afb:acd7%6]) with mapi id 15.20.6340.031; Wed, 3 May 2023 15:55:13 +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: e783c349-e9ca-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BEn3SZamiUh+LaSGxz7RnHnIzh7e18dlWlHCy6dICRCUkgBM67J5anVsw931BjnKX8w6H//1huTXHaVGCrETzaU8iCB8BnGBYf5CKCHOJJtHOlSvq6fSMBCVPQ1dPLsBggoDbDnebGqreSCtdlEGCkYSFCN1daVdyQiILjqWCnmfys425MrGCfxubl+Rvq402iZ1BgOAfU+TPF0yAZszO+E+ARa0EnFd3el7zYAjuRoXGvAwbzVIfczwjA7BIqnp5RqH6VgfyREUulfmvevLsMGgJZz6MVyFZFE8e0Xgcri5jcdFDH8aZZpXyVdeaqX9SiFXWl5ZUA2SPvYAXJOupA== 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=j6yjHr0PfftdPO6Ee88aaSu+J8Pv7p1vKjlZEcGgTTw=; b=Dm7r90AHXe+maGSyqlOiRafIFF2DFnW0tjdci60DDSWPXn1M/7k+oxTXOv8Q9x8NgbZFAv3BSStJ7LNwzU4QqrPE3Qy7kPe0otAn27OIOaYaouyMKz97IfSpI1fPs9giMnwyDOhzr52YCKS7V01tVEmjxNHJLg+Qyz/F0TmxKsEGQNQOeC0Sc83RpTHWFPDVp74egokb6Hudpzv0C2DjJ3q9SlTVLAc1orgA7MDgtU98NixXr3Ua4JCuTCjpWBjHXvPIVRP9E9VCSGQNf/RnpoLksRInNSBDW/nwtx6QTklvj+F0/h3s8LTSb0cUuC9fT53v0tJyvnzRJTDANe0BcQ== 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=j6yjHr0PfftdPO6Ee88aaSu+J8Pv7p1vKjlZEcGgTTw=; b=D1GYqkZTkOLEKzzmIi9q5uEAvCEJvrZ4Ee7Vz9DOw+kX+RMHfUlVqsRkRtyletxBp5UEcr4QNT10qq74FJ/C4t7cM+PEKMCB0S548RE7Dc1eRF+bb7Cx3QQkIihY0kiWME6gpwOGqgJB1iIxNnFN6ppbYEWjf3KG9+N3egQvkfPNCMXa3jTcfxw8MPOzVPQrnkR5OztHV9rPcv0hBcB1HbFugURuKzEMUECBX1P/CtMt4ocFKKd/Y/crFfAJ6UPUgnZjQFpDwu9byx7mTgxmzt1bQXusauj4LbSfHMBUxJBoVeL0BSY2HwbNVJoEK07JXCBFB5PQbabyqFKN+SW9bw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <65893a9e-e2ae-6853-7c4d-54f2bf19b17b@suse.com> Date: Wed, 3 May 2023 17:55:11 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: [PATCH v3 2/8] domain: update GADDR based runstate guest area Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: <472f8314-9ad7-523a-32dc-d5c2138c2c8c@suse.com> In-Reply-To: <472f8314-9ad7-523a-32dc-d5c2138c2c8c@suse.com> X-ClientProxiedBy: FR2P281CA0012.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::22) To AM6PR04MB6551.eurprd04.prod.outlook.com (2603:10a6:20b:fa::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB6551:EE_|DU0PR04MB9658:EE_ X-MS-Office365-Filtering-Correlation-Id: 595c3862-ac38-43d7-4e5b-08db4beec7fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tEUd3Jv42yDnr32vQG7G5osjlauYf2E+lSNMeMo3iDIKhunZm7E5ZTcJlYbLwPoQg6rojBIuVrR03F4KMm2Hm54eE3yrDet0U8jPMV/LkOypAxJvfmPFFujWDyZZL/49O8W8+XIEdyhunFKKcP8vvqSFEVk47N2XMJZoSwFZfZwLNnsBYfvblWBYsTOjFDqLg+0P8pSekEOYoRUp3dbIPiM3e9kobI2IPkIvA+m23wDVYO7rvGxnufNgjJjI8+3+RsbM6SsBUu4RmHmKVgF+r31hfeuFphD4GfSRvZDmflSk3SXJ281ELse1YcsFXXWGLgM4lKxupQzrh/rdbG51eTPHELC64ycV5145CkHpTn7eP3uX0JfuLbaRrY2+ORI0xWc3mBnqkhZh85Mtk7qAoeX+1JPGqnFTVdcJDTFGoDx2RfVpZZH042Ciq9FQoK673hrwx+1Pun8L88P4LLroQuNPj/gMA1bkp9WLUD2MBxyXSrVWrY/lTIYBjV6snkLeN/BOZAmBKM25qpvplSF2+9zE3LfbMDSaW87DBjTLs6yShAR35soTP5Ta1BzaDZgFBsHE6kITp0dJj+uLBD5Ttk0EQ97LJk2/0O3hDUEsZljBYS2/Gh83/5IYjsBDtPaQkl4No9twnHINvF5z4AxyCQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB6551.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(396003)(366004)(39860400002)(346002)(136003)(376002)(451199021)(31686004)(66946007)(6916009)(66476007)(6486002)(316002)(66556008)(41300700001)(54906003)(4326008)(86362001)(31696002)(36756003)(5660300002)(83380400001)(26005)(6512007)(6506007)(2616005)(15650500001)(8676002)(2906002)(38100700002)(186003)(8936002)(478600001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?CGmZBwRpah4exGExYqTiZlTz5YSq?= =?utf-8?q?0LtlxNwj+IS8ZZQZtAYUjGUbP+rtdjsazvUQ0ebqBOY+dzHKgUthkWbAFg+LQtKUx?= =?utf-8?q?iCn8/jkYBowVL2/gxPiYdJCxDxDiPyLjSskGVys4G0ns6totugdTxer+U9IjOwsyX?= =?utf-8?q?1IjTSmrzD8n6dHwiwtAyIzGCdDtZ13S5ekIGxALlNwKjH9jFtiJs3lRROhEOSP2Og?= =?utf-8?q?t9+dc0BsQYauFPVT6dE4RqivWibloAjgakRak236ArY75P6tmUz7Luq80X1wUHRa3?= =?utf-8?q?r/UJ2SAOEH/jMwYqD9BCgPgbkV0Ly+s5iTSEyE5xFycwnK40+Qiub5pFqCmDOgsKv?= =?utf-8?q?PkT4nXEehmRT3Dr6cVcFXFFHi0fmx5RuR67XuHCt+aGbodgWWJUYbKu6LU901I2H3?= =?utf-8?q?Hh07bjlM1MGylzKYLmLtf6dkv6PmGrzMW7sArYxrXDlmHJ5YJASlkzrTyR15s1i2j?= =?utf-8?q?0/buxtId+mpb/1JHGnLJEMjtMFkqK6kg91lLCigBcLUL8/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/VDu02l6bpd+jz1RmmfK?= =?utf-8?q?/elBZI4WlGqrfekHk77SH/ZDPusxPsOAwW0/nUkCEcr8rtiQits1mVWkW4pPe6dXr?= =?utf-8?q?OVBDUZ1hE+QfeR3Gi7dQOXGQj7EIX2tBg3XvjhwlnIAr4QCRCxZlY8F2vNbsBwPE3?= =?utf-8?q?QPpkzYckBWo3?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 595c3862-ac38-43d7-4e5b-08db4beec7fc X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6551.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 15:55:13.3717 (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: XqEp816xcAml/2VFrs3XPNY+k5XyBRnNeAN8RSnOPqHEHmWcbOuoQRbm2ZtlHRJWzMgL/6gPcyul4t3ZhVhkgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9658 Before adding a new vCPU operation to register the runstate area by guest-physical address, add code to actually keep such areas up-to-date. Note that updating of the area will be done exclusively following the model enabled by VMASST_TYPE_runstate_update_flag for virtual-address based registered areas. Note further that pages aren't marked dirty when written to (matching the handling of space mapped by map_vcpu_info()), on the basis that the registrations are lost anyway across migration (or would need re- populating at the target for transparent migration). Plus the contents of the areas in question have to be deemed volatile in the first place (so saving a "most recent" value is pretty meaningless even for e.g. snapshotting). Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- RFC: HVM guests (on x86) can change bitness and hence layout (and size! and alignment) of the runstate area. I don't think it is an option to require 32-bit code to pass a range such that even the 64-bit layout wouldn't cross a page boundary (and be suitably aligned). I also don't see any other good solution, so for now a crude approach with an extra boolean is used (using has_32bit_shinfo() isn't race free and could hence lead to overrunning the mapped space). --- v3: Use assignment instead of memcpy(). v2: Drop VM-assist conditionals. --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1615,15 +1615,52 @@ bool update_runstate_area(struct vcpu *v bool rc; struct guest_memory_policy policy = { }; void __user *guest_handle = NULL; - struct vcpu_runstate_info runstate; + struct vcpu_runstate_info runstate = v->runstate; + struct vcpu_runstate_info *map = v->runstate_guest_area.map; + + if ( map ) + { + uint64_t *pset; +#ifdef CONFIG_COMPAT + struct compat_vcpu_runstate_info *cmap = NULL; + + if ( v->runstate_guest_area_compat ) + cmap = (void *)map; +#endif + + /* + * NB: No VM_ASSIST(v->domain, runstate_update_flag) check here. + * Always using that updating model. + */ +#ifdef CONFIG_COMPAT + if ( cmap ) + pset = &cmap->state_entry_time; + else +#endif + pset = &map->state_entry_time; + runstate.state_entry_time |= XEN_RUNSTATE_UPDATE; + write_atomic(pset, runstate.state_entry_time); + smp_wmb(); + +#ifdef CONFIG_COMPAT + if ( cmap ) + XLAT_vcpu_runstate_info(cmap, &runstate); + else +#endif + *map = runstate; + + smp_wmb(); + runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE; + write_atomic(pset, runstate.state_entry_time); + + return true; + } if ( guest_handle_is_null(runstate_guest(v)) ) return true; update_guest_memory_policy(v, &policy); - memcpy(&runstate, &v->runstate, sizeof(runstate)); - if ( VM_ASSIST(v->domain, runstate_update_flag) ) { #ifdef CONFIG_COMPAT --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -231,6 +231,8 @@ struct vcpu #ifdef CONFIG_COMPAT /* A hypercall is using the compat ABI? */ bool hcall_compat; + /* Physical runstate area registered via compat ABI? */ + bool runstate_guest_area_compat; #endif #ifdef CONFIG_IOREQ_SERVER