From patchwork Thu Sep 28 07:01:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13402084 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 32822CE7B07 for ; Thu, 28 Sep 2023 07:02:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.609295.948292 (Exim 4.92) (envelope-from ) id 1qll2A-0003qx-U4; Thu, 28 Sep 2023 07:02:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 609295.948292; Thu, 28 Sep 2023 07:02: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 1qll2A-0003qq-RZ; Thu, 28 Sep 2023 07:02:02 +0000 Received: by outflank-mailman (input) for mailman id 609295; Thu, 28 Sep 2023 07:02:01 +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 1qll29-0003qa-C3 for xen-devel@lists.xenproject.org; Thu, 28 Sep 2023 07:02:01 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on060f.outbound.protection.outlook.com [2a01:111:f400:fe02::60f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id eb772a1b-5dcc-11ee-878a-cb3800f73035; Thu, 28 Sep 2023 09:02:00 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AS8PR04MB8055.eurprd04.prod.outlook.com (2603:10a6:20b:2a4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Thu, 28 Sep 2023 07:01:56 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a%6]) with mapi id 15.20.6838.016; Thu, 28 Sep 2023 07:01: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: eb772a1b-5dcc-11ee-878a-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F8OP2uujbZjt2hEsXLa1W7apm8GJO4oJtqTVfK+aZycEEMZ8CkGKN8lYfbds6ONfng1eyRbsNPt+bCEU3M5Bf5k5eb8B5MqEbx+ifr9JGuRKiXupWZiY+dO157MkRYMsNws9jzIpspO+Sz99mVPoKyBkUgn+L6cB0uO4HSVZgsrl5NMDV6rJJY5rHBRbb1xJ1Dk/A8kU5QsHCF2OHY597PuIAmnReNfir7qeLBllbtSvMcDWz7RTzrQP1GT9qpKySqzjXcR0cTxgrdJH+0YwI+Wmu0Vsr8B5U4IMQT0j2JcT5CGanumJ/8p/HgpiBvt0AjZJiQL6yarUTWITTMdyoQ== 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=oufazdANeZ9w0vDBuU2Z3ztqUcCD/UC60JbgAsH595s=; b=fnQEwAcdIkG/EshODfg5GrHITaUesvJiyX7YeVFq2mRziu/3KfZ3d4TCMbydFqbiYN9m8DSfHqFwqtnIjYH+wH6PAUyuBHCWY7eKXi0aMiKHxDMPRoylW5CLOzs0/mZFXQAhiFvVkTMYz5PesJhPJKOgu2vZUVKK1JqNjJfmhJnvG2WNpi72vbaRvzm4RgwnaZs+OZObQfV18icoXo5AgQur2GgVAO7wZ8DA0S1IU1eY2+RxwGiF8rMpRpAQb0Ljg9FBEmqNTaJaQ+x92tLCozPOpggr4YSh+Z6zU/icFUk2ES3CwmZRTrml0xLA9ADUf/XvD8f4g3s41VBxfR6A7g== 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=oufazdANeZ9w0vDBuU2Z3ztqUcCD/UC60JbgAsH595s=; b=IpV/id5KLZYwoYKkNSQ4Ip9Y2u6eRuDZ8xZGSKz0dZxv2nD31t26Y5rUdvyMtStTAGJZ6/W2Y4xHBQbNdbe5IKvuZXj+aOo8o5Oe1s+FdKSathp5O3C6s7JJdQRGzfOlBg/Gzb71ZfqRhV+kDGr6ycjBI5QNRzwuw5o2Ak7JhMKrTtbmPOLK+u/7M48SPfIgAPYBK48FVlfeF6g+JIVUxqr71lmNSdMfiBZRKW/X21PsiDehyDA49/3Gqq4GZF4bH7RdwaL1AwuaPZ6LZLq0BQfKK7CpkpFXku8RMRephKC+TiBI/JbYdVxA82tI9aJ5Dy5aXqNDKOU/92vs/URdKA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <91db0bae-5485-680c-ef95-7316328583a2@suse.com> Date: Thu, 28 Sep 2023 09:01:53 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PATCH v4 1/9] x86/shim: zap runstate and time area handles during shutdown 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?= , Henry Wang References: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> In-Reply-To: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> X-ClientProxiedBy: FR3P281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1d::12) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AS8PR04MB8055:EE_ X-MS-Office365-Filtering-Correlation-Id: f4e029f9-ed97-408c-69a5-08dbbff0cd32 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RYqK8H6rY6EzbPVxVvqpyqnyHuSytJvO4Mir0baMGr6All2k0KTFc5nxAzDcqEcxK75vCcqa+bGWbDuttcibrwL39+ZUr8FEhZuNl5/FQ7GT+15gAhGwyWLziZDCZPwwBA0Q75vWUH6zI43orgYdzfIVFtA2Ty0zmblee7IWbV22RhCzPE+/bI1slTqFlMug554Qh2Besn4mdFmPQnTtSAlF7qZWBUWPz6CsEquHFPCvX8TsmqbnedhSdbIES2s/Damk7/icFCLFCmcIMOenf8nvJdjyUjg4NDoL70p2r70fUhGYaRxVc3iQB9KZxl5rU6+JbSdJ1GvN1WCtwN5+K6df7Nnv/VGzkJnpTO8TJ4RDcE4kXvIt9ux4Ahhm7sdssOTLv/IH8p+im1y8iC/O9cY911kJIHO5a/MXw9y3eLUiKGyM0z8Jk+zge7+Ozezm93VUoJsiakeNkSGTQ1hlGr5s9U2VdNmTxY6+GTTvG4mbYrdL9iY51eKAIwehK1j1lTxUUFaRlTu+c5lGFXMvsfToJpLi151A+R2pt9i4l1X07eUVfXg3v72cM1/UNd27T+KnBoSj4X3DW7umPCneX/8Uz2zS+jDLcqXlW/97ZyjVi9SUoxeTivPneLRA0THj0lk7z0Njb+c4qzKSlfhDVg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(376002)(366004)(396003)(39860400002)(136003)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(6512007)(8676002)(5660300002)(4744005)(83380400001)(36756003)(6666004)(38100700002)(8936002)(66946007)(66556008)(41300700001)(6916009)(54906003)(316002)(86362001)(31696002)(6506007)(6486002)(478600001)(66476007)(4326008)(31686004)(2906002)(26005)(2616005)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SvISO51YHKntbLpf2KSPJYAAJKjW?= =?utf-8?q?tSyza3sCwRXrZG9O273qIw219gKSF44+NemL881jwJZo8UBt4pmp6eBcheE3ZE6aA?= =?utf-8?q?w5dQnrgxudWxNGMgLMFyLXW3dazhblyznMo6aIHhkj6lMDezEMjxle7gh4s3pf14A?= =?utf-8?q?n1XLBxlac58cPs7ZiujTjSXNsu6gIHFfRQv+SxmKnfCjd1H/JDX3VAokOg850oy4R?= =?utf-8?q?Dp6s9wr/++IoqPMYKG0CrS0zUsfdmPiMQdwdIiFaN3+2jhcTBLAVS1NOys/rvlgoJ?= =?utf-8?q?KqODcOfxW5Nk+sKc8/orVeFABjYjkRfKFp6MwTTA2oJgIdH2FDCnPnejw3KxITzWh?= =?utf-8?q?P/sm6cnGPUJ9zWsWirZ+6M/YkZ2SlG0l8oujFxtPlWMQcQZo+9zhQ/HVlS6znPmYt?= =?utf-8?q?23bg1aK6BiKLp3QYQjghwpYZhRPkAzl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sVPlbWaolvhbPvYW9CPa5+yJvJL6YtR8h?= =?utf-8?q?pXTWSbqMoN+IdzIqozhMrRj4UvI6Hln8QO8/mow3LsbKOt0ZzQ58Gec91CNRWrVtQ?= =?utf-8?q?pVC4wAv71c9444eBfTg5Ki/qK7vELq0RJ8UpN/bYnNzMjQSz8QD6ttjcUSy+l5qvN?= =?utf-8?q?bEwRhnjjDg1ki+9BJHMAxgF+fWdKKaXdEOowzJzel968wF7ML8bhpTwGS3wyNmuAt?= =?utf-8?q?q4dguDp5b18z?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4e029f9-ed97-408c-69a5-08dbbff0cd32 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 07:01:55.9954 (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: Vla3gW6qXsUybVXOSVathxtW092U7TdCTTC0XvghvES5JMaRzMSMGj0wyqlad+J71Dx0DMnGdVqRRoslHg+tnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8055 While likely the guest would just re-register the same areas after a possible resume, let's not take this for granted and avoid the risk of otherwise corrupting guest memory. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- v4: New. --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -385,6 +385,10 @@ int pv_shim_shutdown(uint8_t reason) /* Unmap guest vcpu_info pages. */ unmap_vcpu_info(v); + /* Zap runstate and time area handles. */ + set_xen_guest_handle(runstate_guest(v), NULL); + set_xen_guest_handle(v->arch.time_info_guest, NULL); + /* Reset the periodic timer to the default value. */ vcpu_set_periodic_timer(v, MILLISECS(10)); /* Stop the singleshot timer. */ From patchwork Thu Sep 28 07:14:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13402175 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 5BB9FCE7B04 for ; Thu, 28 Sep 2023 07:15:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.609301.948302 (Exim 4.92) (envelope-from ) id 1qllEi-0005tY-0I; Thu, 28 Sep 2023 07:15:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 609301.948302; Thu, 28 Sep 2023 07:14: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 1qllEh-0005tR-Tx; Thu, 28 Sep 2023 07:14:59 +0000 Received: by outflank-mailman (input) for mailman id 609301; Thu, 28 Sep 2023 07:14: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 1qllEg-0005tI-Ag for xen-devel@lists.xenproject.org; Thu, 28 Sep 2023 07:14:58 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on20613.outbound.protection.outlook.com [2a01:111:f400:7d00::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b925a907-5dce-11ee-9b0d-b553b5be7939; Thu, 28 Sep 2023 09:14:54 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AM8PR04MB7811.eurprd04.prod.outlook.com (2603:10a6:20b:236::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.25; Thu, 28 Sep 2023 07:14:53 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a%6]) with mapi id 15.20.6838.016; Thu, 28 Sep 2023 07:14:53 +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: b925a907-5dce-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XncfQc0sIzeHxi+64sRriMtsouf4h/fYcmpMckmZdPL10dfHqwhGShMnvoGaEWz5sETszq5daV+UltXJoBtfSo5YaVMHAL3VhEj8NOgcOJ5OZNBbIvVUzezH+gt6tgOhRcCg+rqogAxQwkPoWklZOOk/aGzxOhOnfPSjk1dHZ/fGIWWmoxop/SwQGBABeEErOT0NBg48JjZknm87BXPMi3ykbAWQC8faoemC7tUUTNycoL6u7yMgFmDTjkhzaoJNHEUK7fhSzSTifrxnBG3D6fLKfVlV13GHnCWQbalwWVvZT/ud4i/bw02FRbZW2suW3ccCakVNztRx6nVxE9/RwQ== 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=INAcouYCwzSE0qAgMcfbHm4G+IYIvkxnPJ/SO/FIaKw=; b=S6eEd8eVwE9QNavKmcg3jn+G1qd+otdGxFUCqA0njVNLRc1TWC9aJTiOBjq128G9QG4L/t81EQXh7rChKwL26gedZydD2xt2Z0O0ZFgHxj/2ypUx8tMnLQZBKF8lU4ytsY/p/rdwsuzWm4TueqP23rTAcrhwOfCRBuezRa4uzzvCJbFVjfYvhwlKPi/rh5dQPZ/32sOf2PPiF9ZGwaQ7YQpCwDTmtXMzxWrVC1GgAvFXv505HR6NhVqKymvNY/jkU1bzB2cm3hWzmQQXsMsNiu6zeFvksQz0BTM2pIEUC25xH48GXxgTvXryKg58UQmGcE5t93APOa8921VXfx9Lhg== 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=INAcouYCwzSE0qAgMcfbHm4G+IYIvkxnPJ/SO/FIaKw=; b=zAdYvV1esiUOdqVmqfP71NVuZ+EHT0buBkBhIe1mNJ7Y6EBiwIl9LMDLVrGmHiJvIvT3P4OLsxrZB0dvSWVr5ns+ksVcaCZYWOZhmzQZWsnA7OtKhIauLxG/mYUpW5LcHffyGCHF5MWUJ0wPKuxp/UeD8iIXiwsPWvR2NvgmkPrNQs2IJrlgrP0dTWezOSYLfJ6Tc4sky0eDX5GGARn0y2gmL/1l9QF67xKqgzliymiTq93cJew0dN7hvWc17Rmt8SA3oRgVZOQd6elNyjRkycNEBHyvH1HeiPRJQIIvwT8bYbu3EoKR23d/5rnsdOIjJG0+16eCQrf8kErhfMrg9Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <298c3470-643c-5f73-ceb0-4b0fc2441952@suse.com> Date: Thu, 28 Sep 2023 09:14:50 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PATCH v4 2/9] domain: GADDR based shared guest area registration alternative - teardown 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?= , Henry Wang References: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> In-Reply-To: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> X-ClientProxiedBy: FR2P281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::12) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AM8PR04MB7811:EE_ X-MS-Office365-Filtering-Correlation-Id: d7dde82e-15e3-4663-599f-08dbbff29c79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7uNXY13Zzk0PNbxDT05wIo/eyG7s+4xY2whxeWqYE0RZdsruVNZJyngvxCnIt0NRMIDYIRnlnIC9Sxm5hAxsaGRwcJYcXMzKvMpqDlChVA+Gadvlg7yO0xXpIoDRGVX3BwFhK/1ufZVd0kDSbD+tkJ12igoJUdZjiZrjhwizeQbyx5+Yw5SsgVd+eUrKWgyVECFl64Mw81hDJ5cePZBd7XlYYK4PFSDwvipzU/OrlDlLZEblIl7/2jYnW8uBYlFpQqZqwdNthkc7AxMKJ8xpVxcm9p1nDLz9M3Dtx2GqySjvv81c8FdmFl2HFlCQNlcVue5J3ZLvQAaLLecC3KHuLo4RE5SeKkw8NKCgLhnU537YoxC07/Ggl07vWMel3y5QUYeSY3PlxEmDraqbmAK9ofrVghw+WeJbI4IyZgz5UUtUMS+wR7YEn/DrZz3XILW5/Ri4/NSKrC3swW+j5cusi1yCvIMsKvz4mGeN1McNNeUs3EtlX+fu+n5JhyJhgPqWKUVeciNW8UNtr6RTUgiPcatYaOtivKRSY0/bmeHB6wF2qBaevLCtPWN2MA4N4UzsgRvRKRP3rPXfdQyOX47neIfSxcRx8sJ6K2UufG0+M4RALYp/FYvwrT52e0h68A86dIMSnB4z4QbwSJ5a1Or7Kw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(186009)(64100799003)(1800799009)(26005)(6512007)(6486002)(6506007)(478600001)(2616005)(2906002)(316002)(6916009)(66556008)(54906003)(66476007)(66946007)(8936002)(41300700001)(8676002)(5660300002)(4326008)(36756003)(38100700002)(31696002)(86362001)(31686004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?0hTjyhThXsJTq9FA5O2/vg2fOXZq?= =?utf-8?q?CBqHrfLjIyfqIc8Se7DhEhH5yleoG+1Z1Zh8y0sJFCNx704dJrTA/y7pQEi7mi/kt?= =?utf-8?q?B1qFM4TilC/f7AgiTOX188ZHOnFpnQLBBdF/TY+Vv6TEEDtcMWFpb+ixomm/Scp0B?= =?utf-8?q?maWffjQZl4nHoknzPnZXrH6gozUfiGnemaydflsYxIWZBhnxSE1fGLSPO/Xv/ABEx?= =?utf-8?q?zNPJ0bOnD3D2yaW7i9huGcq6t0mosl0wfnYjX5Hj7NrXDNQHJhDeM2oagW5LXW8+l?= =?utf-8?q?VnX8mQkTs1qb02l3M+WyYbjCOVKVTSDCf6LATSrjLO3JFq2cggtx0D2YeSSUKgyG0?= =?utf-8?q?V+i/OQAzUalCQbLEfbT1h+QSBlzHAJpIhKiovEB9flnc/oR7BK7UVxYn45HGUDr0b?= =?utf-8?q?XkLw2flb5HHkyf6A7AzZW3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EMzOXJbxaCGLyr8V7GAMC9tJUu4hp+qQhYY8F1bHRlbE?= =?utf-8?q?ee0oEslapoIhd7CWIMmaCdpggJpSxzi2+zjWs3vf4yrj+cNIvi8FBgIR4vG7LMw6t?= =?utf-8?q?RowQ1cTzL38wz6hofY6RbJyZTg93tV7X5prswSdIRZlq5MYON2fS+xHDI/rbU11mX?= =?utf-8?q?Ukz662Mq0rj5oiVbycFXlEi3GzOGRr3LUdxXX5pAoCwCA8B8+JU/pi4PmRnP6A6S5?= =?utf-8?q?s4aXf67qw/YP?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7dde82e-15e3-4663-599f-08dbbff29c79 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 07:14:53.2770 (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: yrrNK5DkDPLi0kbA3ws+huJTiC35quKfi8mjyvT0ijM2904QdPXSecx3HxMZTd3WO9RPu3a29/4NbZRBWfiipQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7811 In preparation of the introduction of new vCPU operations allowing to register the respective areas (one of the two is x86-specific) by guest-physical address, add the necessary domain cleanup hooks. Signed-off-by: Jan Beulich Reviewed-by: Julien Grall --- v4: Re-base. v2: Add assertion in unmap_guest_area(). --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1024,7 +1024,10 @@ int arch_domain_soft_reset(struct domain } for_each_vcpu ( d, v ) + { set_xen_guest_handle(v->arch.time_info_guest, NULL); + unmap_guest_area(v, &v->arch.time_guest_area); + } exit_put_gfn: put_gfn(d, gfn_x(gfn)); @@ -2381,6 +2384,8 @@ int domain_relinquish_resources(struct d if ( ret ) return ret; + unmap_guest_area(v, &v->arch.time_guest_area); + vpmu_destroy(v); } --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -669,6 +669,7 @@ struct arch_vcpu /* A secondary copy of the vcpu time info. */ XEN_GUEST_HANDLE(vcpu_time_info_t) time_info_guest; + struct guest_area time_guest_area; struct arch_vm_event *vm_event; --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -382,8 +382,10 @@ int pv_shim_shutdown(uint8_t reason) for_each_vcpu ( d, v ) { - /* Unmap guest vcpu_info pages. */ + /* Unmap guest vcpu_info page and runstate/time areas. */ unmap_vcpu_info(v); + unmap_guest_area(v, &v->runstate_guest_area); + unmap_guest_area(v, &v->arch.time_guest_area); /* Zap runstate and time area handles. */ set_xen_guest_handle(runstate_guest(v), NULL); --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -992,7 +992,10 @@ int domain_kill(struct domain *d) if ( cpupool_move_domain(d, cpupool0) ) return -ERESTART; for_each_vcpu ( d, v ) + { unmap_vcpu_info(v); + unmap_guest_area(v, &v->runstate_guest_area); + } d->is_dying = DOMDYING_dead; /* Mem event cleanup has to go here because the rings * have to be put before we call put_domain. */ @@ -1446,6 +1449,7 @@ int domain_soft_reset(struct domain *d, { set_xen_guest_handle(runstate_guest(v), NULL); unmap_vcpu_info(v); + unmap_guest_area(v, &v->runstate_guest_area); } rc = arch_domain_soft_reset(d); @@ -1597,6 +1601,19 @@ void unmap_vcpu_info(struct vcpu *v) put_page_and_type(mfn_to_page(mfn)); } +/* + * This is only intended to be used for domain cleanup (or more generally only + * with at least the respective vCPU, if it's not the current one, reliably + * paused). + */ +void unmap_guest_area(struct vcpu *v, struct guest_area *area) +{ + struct domain *d = v->domain; + + if ( v != current ) + ASSERT(atomic_read(&v->pause_count) | atomic_read(&d->pause_count)); +} + int default_initialise_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) { struct vcpu_guest_context *ctxt; --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -5,6 +5,12 @@ #include #include + +struct guest_area { + struct page_info *pg; + void *map; +}; + #include #include @@ -77,6 +83,11 @@ void arch_vcpu_destroy(struct vcpu *v); int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned int offset); void unmap_vcpu_info(struct vcpu *v); +int map_guest_area(struct vcpu *v, paddr_t gaddr, unsigned int size, + struct guest_area *area, + void (*populate)(void *dst, struct vcpu *v)); +void unmap_guest_area(struct vcpu *v, struct guest_area *area); + struct xen_domctl_createdomain; int arch_domain_create(struct domain *d, struct xen_domctl_createdomain *config, --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -203,6 +203,7 @@ struct vcpu XEN_GUEST_HANDLE(vcpu_runstate_info_compat_t) compat; } runstate_guest; /* guest address */ #endif + struct guest_area runstate_guest_area; unsigned int new_state; /* Has the FPU been initialised? */ From patchwork Thu Sep 28 07:15:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13402176 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 84240CE7B07 for ; Thu, 28 Sep 2023 07:15:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.609304.948312 (Exim 4.92) (envelope-from ) id 1qllFC-0006K3-A1; Thu, 28 Sep 2023 07:15:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 609304.948312; Thu, 28 Sep 2023 07:15: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 1qllFC-0006Jw-7F; Thu, 28 Sep 2023 07:15:30 +0000 Received: by outflank-mailman (input) for mailman id 609304; Thu, 28 Sep 2023 07:15: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 1qllFA-0005tI-6R for xen-devel@lists.xenproject.org; Thu, 28 Sep 2023 07:15:28 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on20606.outbound.protection.outlook.com [2a01:111:f400:7d00::606]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cb1fc30e-5dce-11ee-9b0d-b553b5be7939; Thu, 28 Sep 2023 09:15:25 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AM8PR04MB7811.eurprd04.prod.outlook.com (2603:10a6:20b:236::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.25; Thu, 28 Sep 2023 07:15:24 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a%6]) with mapi id 15.20.6838.016; Thu, 28 Sep 2023 07:15:23 +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: cb1fc30e-5dce-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VbFPiYwOhifIbt1NM1mxTVIVbqPV564zTdle3GTgCkVgU0nZCvYU2HA0PMfbCF9baKqMAY8BnMke/o2ZAJR5m3tbGPKOO51EaOZkxdTx4wNZXlZkeztdXwqYjJnSe0/28Qs00GuBg3r7BwIZqWVTMk47As+oo32b70g0HSwUVW/t1xGOyPj5Br3grw/miIVsAUqZoBUfrsz7U4fA/qtnHRvLIEKHqJkTiEJi+r7MEzVeppuso8YZYz5pI7K5kOTJ8/GhyPYlKWi6NJT9LordX+/2aKPOQHfwqk7ISd7ot08SDmjBCurfRt+c9ojls9xEfK7yCu59JiPPRWYpOuTSkg== 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=nDhjKzeHPCvDjdSeahyLl9mEZAFQA0ykwX0ENFaYkNo=; b=Cxfqu6SS2JvIR3NbA7R7/NOpK593g54EuZWe/waNav6pyCHp4kheHcbLJ7yeMR9JlE/1pJ/054x+sKTqDIchP9iiSpfpu389J8SLyUEqROcnDqT0d+8RHh5eWqSd454taSLUgE9loPgGx8NF389P4SKj6IystqnUq2Rnrf9Naz5gIUwOmliISuX8+zB4+0EMcWUMT4avl1rqm7by86CS782mnMBYuReZLuFL+FPmtgG9sM+oPx1JDqrTGWKm5DvFsfp4XNKrzIvUdb+uXSGPM2C0NN0n+EYYvnnQJm486+Ob1rG2dslcW9E2mM3ApSfM+DfZavpOP3Dl/LNLjTUhzQ== 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=nDhjKzeHPCvDjdSeahyLl9mEZAFQA0ykwX0ENFaYkNo=; b=pTBEjckrWHD8y5a4iKJwF3dZEg6coFR5XVHWBqTxZB0CPkA5kqm84SDeKC6ozIxA26xXjYL26P9FFVjvbczwuCO6bqmfADhr+URs6IklN223MNCQv5LI5sEcSEJTo5OTtx858qJFpAX0QgO8g+4gwD2z+FKP+U34X0HrTRXVNy8dOI+m2SsyNaLvNe8lJAtEmyo2tbmBM9mVtYB1EbPzLBIYHdlQnm8H5sB0gZTj0C/EuByWH3uRjTluxCsNx/cg22A8+Rt8JUXE3WQz9TGVdewR1AL8pOPARbPtQ7c1OMSGZIbS340xzNNt0is8pMzrXAHsqoGcu20Ghh3lkfUQ2A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Thu, 28 Sep 2023 09:15:21 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PATCH v4 3/9] 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?= , Henry Wang References: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> In-Reply-To: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> X-ClientProxiedBy: FR2P281CA0016.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::26) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AM8PR04MB7811:EE_ X-MS-Office365-Filtering-Correlation-Id: 838047bd-c25e-44fd-be17-08dbbff2aeb4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9BVXjzIc2LxQVKyzzFgSelRPBXdrqMLRb4emBmmANbpCh3ksbsZ16QoHm4VZ0497VapLb8IvVirgT4xcEPwSRBBPvEchHFJv6pCOLfQTgs8C1GScZXYZqIiPUD8E9Ypa0ahzcf51Mb2dJix/JP+OVcPAAnUI6ESA2+5t9xXuPMBJ7jUYxanPa3nDFwLdvLkg+JSTVGPvv6VCUcf7CDqQLnzYaPorHBlQVAQXT8wb+cLb3H1auqiVzWJM20nWP5g9/4Tb4q6OscYyZwKXMkIa9hpaOnMnkPqQEePrYaNkHSnAiKvGFU5z4PbP6XLNSDCSc5Ve1g0kETILuweS5W1e0whq6x1tyOLs582cCKViYUr8G5ZY69VqssVAfPWsfVgSZ77hcngG5p1MU0FeG7nKPvnVD7zSNuhxRyZRqzCJ6mKfAocVhTjR1Ht61FVd3iGdPDRRZtgVZiO5Ny1eM0HkgoeS3V/BvkTsnN0OD3AzWneJ7YRVWb4H9dbuy3LCXlOZ28SBrotpSUihxcM6AtHSaLirclpKZ86kqo9p2W+evJNv5FfSsk9ytwh84Ok9+xk3uH4NPsa/rfanwKcd6qZzs40wEQDA9Kn4MsLN9tZ3cyAx9ogiVE/FUFdp8rQT5bdbOc4Z2CyPMr01nWh+DJZjjQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(186009)(64100799003)(1800799009)(26005)(6512007)(6486002)(6506007)(478600001)(83380400001)(2616005)(2906002)(15650500001)(316002)(6916009)(66556008)(54906003)(66476007)(66946007)(8936002)(41300700001)(8676002)(5660300002)(4326008)(36756003)(38100700002)(31696002)(86362001)(31686004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bddRoLSTHAIM/hCQrlnnb/ZilXgG?= =?utf-8?q?OnyK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Cz1Sb3hrr/L5ZnX9fjQ6DzeYejuPUjFi/oAnfDAz7HUFU7XVeLrs4?= =?utf-8?q?lavAy4ELsyk1LakJAhsOgVLVdwpDyULIPku05K/93Ex+3locyPMC1V5/0AzZFhyG0?= =?utf-8?q?Xxohqxpyn9QXgUENBH7/gHJnLFz+tEqcS6uk+hUOOo5zJgXnhjqJR6VBClWz2fcuV?= =?utf-8?q?GnCqp3n3thAH0HPPIojcW6hBXvWgWw1tifmVKKngLK7481l48aABR0XMNbzqfNCUA?= =?utf-8?q?P7pMtj5dTjSdbIbwMJx9m/e2ysFR6I1olg0NDjQAQGuioym/XLg3G8OscdZ5LHJdk?= =?utf-8?q?UXKS6TicVyNCnLekEnNZJsUFDrGY6k9FwfqPPp7xClm7h07Gn1vEo101gJopkYymk?= =?utf-8?q?NB9NjRp3s0wsYINqmmEswEWX6RPHer9IHUUCkU7ceB6H4vSACwfQrwK3DMnBRlqDW?= =?utf-8?q?VCCDG+J6+rWRsZwkK39yrMqeDbUcLAU6Lc1xBMYahQ+NSSuVPQzqOoJcxZUTadrW/?= =?utf-8?q?9fvC38VwTsxXvewmNbq1CouRFFpkdBpRHyzloWiJwrAGhLzS0XjXellJYHSsM0rsn?= =?utf-8?q?axq5wlmlADbpN2mwtNs/iyEOJM8UlJ1XvIxEpqA3p5+U6awv8nRaoVu6WkIDdOfCL?= =?utf-8?q?/82LQFviB1DE?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 838047bd-c25e-44fd-be17-08dbbff2aeb4 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 07:15:23.8086 (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: NNEER+3DpGt6wAojgTSRaD4UAu57IMTtOgV+nN7JzMY3Set5DM3ac+Xo8FvzHjYGBC/EikupuihNyqAGOUR/dw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7811 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é Reviewed-by: Julien Grall --- 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 @@ -1644,15 +1644,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 @@ -232,6 +232,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 From patchwork Thu Sep 28 07:15:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13402177 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 9BE12CE7B04 for ; Thu, 28 Sep 2023 07:16:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.609308.948321 (Exim 4.92) (envelope-from ) id 1qllFc-0006uG-LW; Thu, 28 Sep 2023 07:15:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 609308.948321; Thu, 28 Sep 2023 07:15:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qllFc-0006u9-Iv; Thu, 28 Sep 2023 07:15:56 +0000 Received: by outflank-mailman (input) for mailman id 609308; Thu, 28 Sep 2023 07:15:56 +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 1qllFc-0005tI-4r for xen-devel@lists.xenproject.org; Thu, 28 Sep 2023 07:15:56 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2062f.outbound.protection.outlook.com [2a01:111:f400:7d00::62f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dc5530f7-5dce-11ee-9b0d-b553b5be7939; Thu, 28 Sep 2023 09:15:53 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AM8PR04MB7811.eurprd04.prod.outlook.com (2603:10a6:20b:236::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.25; Thu, 28 Sep 2023 07:15:53 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a%6]) with mapi id 15.20.6838.016; Thu, 28 Sep 2023 07:15:53 +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: dc5530f7-5dce-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ak/6LZXoGblaIYV1cb9K7e4Cjj7CbkKgr+dJxzx4e4bnDmAmRrZxJJ/5g3B+oZ7KQw/OTku7OO2l48MdWM2L/bhd8zV7oE/XhA7ljKFQSk3d1MBwuSz5iz2CJaWuhqEUwP1GywiuMUCW5ceSQBPT3zgZF5LPEeevkX5eEyzrLUnrL6sRcWKmQUCojbqgoYPyPHRlWPwNfKHiRbNvVAN6YHAz9Lt1YJWfnYFyKcXHiHwCmqAURgWPq1vYVRCOeaCYF2dZOoeZ3pfuY2nNefZEUTklQ9bSiYO7TWKzAIuF9qAW7rNbYDkNuH7e/MXfscdDyYZZpyhdegGILfxaQV8UnQ== 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=+s4DsrfFOHtuNkr1T98TjoML0TVrNHd1UjKvdCbUR0U=; b=bMSubdvkgcWfmCe9chRcwCNNKuVDfwi11y23lgtZKaWK6vZ7wcNCMnOkM4k7jZjgT6dAyB0DQi7YDlTAv5BJTfEYvw4Xtw4VDRi4V+KDX1nHe5d6Ipa9zEEwxOnwiC5ArrKjwnE+gGa984rb8ODGaR8snt6y+52+wbbRzjlbQPGy3M0g90Euy9XZTRDgG67/gL2pBW539EcF9zT/8zotT3n/NBsj8iztwLHuV6jmqBwednAfnyi8EZEdA4W5Y572JsqiKbwNWsCCPn/HQMN6IM1a3OjXeUeXAhCuj7Cv6QSQzzE5yUDDuYz5tDuoxqpUaxZNYmiqGUg3P1y/sKtkeQ== 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=+s4DsrfFOHtuNkr1T98TjoML0TVrNHd1UjKvdCbUR0U=; b=SKXXc2drqLOCEIf0MRa6CIRJ+nTtaQN6aolcerelsiNFPcgqrbGSY1N41z5l9s1eHI2W/mXUowUq0LVBqVYYK2lLwT8+GpQVYIJjkkzKNLe7NVJIERWM6o/L0/aloogmjnOe1mKZhilhhkt+aDdU5dWXglNYR2y1/sD1/r6EElnOVSMyS8ToeAxmil8hhCFk5JMDCR3CtrwPgQQvQ88A56fbn1nVhqrIX7CzUD0k/9FV9TrtI/2wETLDxS9CSDPy/l06T1ydBqzR3I56iy4TzDZn4lIRVWtfH1DLX/sp6XWbWPa+9VTC62zVJ4LkRY9qvRgUnOHIivnOiseDm9myng== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Thu, 28 Sep 2023 09:15:51 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PATCH v4 4/9] x86: update GADDR based secondary time area Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Wei Liu , =?utf-8?q?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= , Henry Wang References: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> In-Reply-To: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> X-ClientProxiedBy: FR4P281CA0098.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:cb::15) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AM8PR04MB7811:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d5b67e4-77d0-4c18-2d55-08dbbff2c074 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XWdqj1YJTXyQU+plhk3Ibcidbb8+7f1pfuqtwLiduD1x5ZTHYOxs5GWQk5+gWilHhvhIAnzQDiq2qRF6MZYc9WmRVJweWEGjdpRKBSDKLNYWJ59mfH4LDabq9FGGbuP5g910i4Ov/Dz1hN4W8saBYhTH3EJcB1QgX5gqwZToWlIToh0O/f/ff4JZC5Y+YTGKxt6VcboIWMTMCQG+HWzuCeTsCNmtJN25Ul2LL31mpJXhVbU7ZfD8Jgar7zmAL5OgnkzucNWiZpDQRHo6Gz0mMSUsyiZUyHASksOEYplFrD0nI/70LDTb8AYRhL70S6nBuOw4QVHrzmpTp1I8VVXwUKPVq5uc51BLu1wobzbwrnICVxu39twFeH+AbtAUFdqZRDeRuP2jGG9zb3+Ad78iXFX0NTI0DQYdreqPziKTUcyWnq6NrlhwAhTAGyz0/wYoPBVrIzf/ekz6FyL4mc2ac4FK1eSMarShNSYyhdl4FQtgl2XBRMVYFDmUadtWGBMLtGHXIB50OHVqgmyWjDrd1JABDr2mHTLEyNRejedKBLI7kprZ6yH/79V0qPzRk45BY3COf35vOT4NPZEBUoR/EqniHuRWLnWt2wKQmfs4iWB0ru7p4pmKXtGByUNbnc+6QVSbXVFfC7wKyrglONFDNA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(186009)(64100799003)(1800799009)(26005)(6512007)(6486002)(6506007)(478600001)(83380400001)(2616005)(2906002)(15650500001)(316002)(6916009)(66556008)(54906003)(66476007)(66946007)(8936002)(41300700001)(8676002)(5660300002)(4326008)(36756003)(38100700002)(31696002)(86362001)(31686004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?dWdbdmZ8UCOMRpZt5s6gynjGOgtI?= =?utf-8?q?xANhepB4l7Ip0w/h3XjPnIfKNl8lYtk2/qpMsb4nOUDm9y+Hbc1jR7Zc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SDXVMwPytBoCA0vPXYJ/xXRT+1kfIOmRS?= =?utf-8?q?Lag5YPUkKiaZg2+Y9FZhQdP9y6qhJQtauSwpZ4mQz6UBdESARCc7qL4FsNl6FWI8t?= =?utf-8?q?gkOthof7acH41a2PGjE7NiqN8VAhF5iOtzBxE2uOd73tH2NSmxtdFF0hQr0RbWNtf?= =?utf-8?q?kPW0fewBPkX6mKppAepI+AqbXOI35v4RLMtaAZRA7SnFRVB1FnSIo6F1BvHDPzX9Z?= =?utf-8?q?ZHzMglfbSedBKcPUocumlpZtKw/jJ07P3rKAv8sOklpgr1MPrAnJa1l4Rkua+fx6E?= =?utf-8?q?CPCHumcHvRzqh5hvcCdbtMMmrpyiTHJtr/ZTeT6tp1Qs0Ww/tSeVQcwxr6UUp7Ngq?= =?utf-8?q?k3trULl1VGdnqy569kaS4I32o5S8ZM3sTAAwMVM9ROY7EHr6CfJPWWmt+0wZf3+jo?= =?utf-8?q?QmkzSeJfk2uVU33T4pxMOkZfNIPpXqAMwNlFa8+ddtTY2Fm9y1VxeGurvAj+q3X78?= =?utf-8?q?64pfvK2UAt3HP30+tHqfgOcbZRR0e820Ci21EJEOHcT2lZ8cqvjOshiaepv+VR0R+?= =?utf-8?q?yvA5i1C4a66arXij131VUEvM/tREsHy3qvitnfz4qVNWrOLMDy75mfhRrpGix1fgq?= =?utf-8?q?7NrDeXgEXDQb?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d5b67e4-77d0-4c18-2d55-08dbbff2c074 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 07:15:53.5863 (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: GYmXnp8Xua0tmrZz+wnjNR5Da1Riso1lvfEcMRGM+zcanixt6eEqcJhSzE+UPT0ne/YDNU4rw2un/PK04Fo9YA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7811 Before adding a new vCPU operation to register the secondary time area by guest-physical address, add code to actually keep such areas up-to- date. Note 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é --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1566,12 +1566,34 @@ static void __update_vcpu_system_time(st v->arch.pv.pending_system_time = _u; } +static void write_time_guest_area(struct vcpu_time_info *map, + const struct vcpu_time_info *src) +{ + /* 1. Update userspace version. */ + write_atomic(&map->version, src->version); + smp_wmb(); + + /* 2. Update all other userspace fields. */ + *map = *src; + + /* 3. Update userspace version again. */ + smp_wmb(); + write_atomic(&map->version, version_update_end(src->version)); +} + bool update_secondary_system_time(struct vcpu *v, struct vcpu_time_info *u) { XEN_GUEST_HANDLE(vcpu_time_info_t) user_u = v->arch.time_info_guest; + struct vcpu_time_info *map = v->arch.time_guest_area.map; struct guest_memory_policy policy = { .nested_guest_mode = false }; + if ( map ) + { + write_time_guest_area(map, u); + return true; + } + if ( guest_handle_is_null(user_u) ) return true; From patchwork Thu Sep 28 07:16:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13402178 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 9BDB1CE7B04 for ; Thu, 28 Sep 2023 07:16:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.609313.948332 (Exim 4.92) (envelope-from ) id 1qllG5-0007V4-Tf; Thu, 28 Sep 2023 07:16:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 609313.948332; Thu, 28 Sep 2023 07:16:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qllG5-0007Ux-Qk; Thu, 28 Sep 2023 07:16:25 +0000 Received: by outflank-mailman (input) for mailman id 609313; Thu, 28 Sep 2023 07:16:24 +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 1qllG4-0006Ef-U4 for xen-devel@lists.xenproject.org; Thu, 28 Sep 2023 07:16:24 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0608.outbound.protection.outlook.com [2a01:111:f400:fe0e::608]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ee869f12-5dce-11ee-878a-cb3800f73035; Thu, 28 Sep 2023 09:16:24 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AM8PR04MB7811.eurprd04.prod.outlook.com (2603:10a6:20b:236::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.25; Thu, 28 Sep 2023 07:16:22 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a%6]) with mapi id 15.20.6838.016; Thu, 28 Sep 2023 07:16:22 +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: ee869f12-5dce-11ee-878a-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ik1Z6SGZniPoadUy6Y0iWT4IO0fJ1XKLeQiEnbqV3rjvfjheCFhjBC+k91SFFBBzIDV7hzsC4KN25flVa0X/augInjT77x6AW3eLxsCjrUQ3MMG2W6ZSIpZca7xfXkDXgVPxKW2mupA+YcWSb8/fVXPI1jUBED6GowTxsEV4CYZCersute0eQLp1eyvtVP82BFG+gaGVZ5z/k0OTzFcyztHD/LAIUk5ypVKJbcFiuZx6+JzK9r8ezVCjpnOKk3GKIFpOIhQMnwM6Rclv88QFCmSr7RHTa+mVJFJK/HW62v/5ZlwhAjHQDRhxm+5OaIifKBYMIVs2CtSBOFW1e3J2Lw== 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=hFNzhnlZYLwd/kWq59whthOZS8He4sxkxz1sCnsgnuY=; b=FGPrfC9tV4zDrLJL6INjalDVWRRx2OQ+eG1Xqv+/4UZnd3UAwwhgt2/rfTo49x0mrsPAQUUJwZUpNUiufexaoTg+AtxBClEOMvzWGiijrXonFK1MYWOaaNAXHqz2HWxzVQzhlKvwlbSvs0VcRuE76zFk0MJdYbVh0O4crm2iHIHVx5PpiK37bu7utJx3YYpQxueIZ0ahFW9NYAeBOc3uqXqIsDAhthKSZ0rahfNhPUtcHjz+2PQcwhMB+buWCLI1D/SXPXhNepvwKHOBBtE6kWuQW0YX4DKIoWJobZk1dqIBv9yKTqTnYIsxmAlhOBYGJyf1vKQBt1SZF91kOG/uHA== 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=hFNzhnlZYLwd/kWq59whthOZS8He4sxkxz1sCnsgnuY=; b=lbo+5WCqr4bx1tvr4RZC0s8w+6nKwwDCnlGX3duH8aAW9Z8/bQEvqsBwjLVj2k3XVJ1XN+2dfej9+12HjA1ZGHpMFwYfdkYxvZQnb555BmkLAAHPeo7SCikoMoiTwSP5Ko3/FQJXI5y7fPlnp1xIKXz3BqTnu7kNS/Y9F+s2M7Llz56zh6mTB+5aq88i0JW12eVFVL4pONqQA077QKEqYlTlAhWHk0kQTY0KRrV9eahdSKLj5R4a13r0xiX9kHiD7HW6IknBR8DwVXGHYZxOS/L4UxHHlLRZwrYXHW3Z91z3oTrIs82SIMVgdeXPWxBbt5oi5Iyjo8x/SWgR1xasUw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <6047c192-0f37-e4ff-5980-fd137b3f1869@suse.com> Date: Thu, 28 Sep 2023 09:16:20 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PATCH v4 5/9] x86/mem-sharing: copy GADDR based shared guest areas 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?= , Henry Wang , Tamas K Lengyel References: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> In-Reply-To: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> X-ClientProxiedBy: FR4P281CA0086.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:cd::13) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AM8PR04MB7811:EE_ X-MS-Office365-Filtering-Correlation-Id: e5f8ad04-a696-43e7-6917-08dbbff2d1db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7p0C3hssJFP850737gbIlelIBFP0p0NUm31GL6kYHINl+i6jDv+25PwdehQAwyKYBMFzO3rX3wHg/bAIUU3bqvinbGuef6PDYb5UUVSdoH/hi+OYYKmAdHDKwEo6mV/FrSw461L/MBYtvVyWyOqowWyQML4tHCgarBocTKEBE7oZhovYb6vRgmRkKSuWD4pamq/iArh1J5NUx2/hEfNhuiFoyMjpWVCcFjh34m+19lRWrmPoppdNkM6sLpmLXjyPS8fOVuzrPhWlI9il+FsDJlVe6Ng8TjQqabhQAghkznYbd6wKlTsAcoB8PW6zgHQ2wB3NdCFVcWZ1p6SHa6+L2jC7HoEO2bCh/wui+1Sz7DQixcDXuLIyEMlr/N8AlZw9oxh1eURi2xXrF+YkfF0q34NWO86tsGQJZY8smRXb4HWJJmZj5qFfIBjKNuNjP1AvB6pjBW/G2b8QtIXbcAV8Y1mUi8jyBqcbFhwCetezFgYElbVJzkeI+8C+CLV6BqC+//IE99C5O3d+QUJLM4IKrm0z80sfD/20wvq/4SeAyucFwyLZ8CEZ6yyuFMDOyhPLSkpl/Eb4wije0/77StQ4WtRCJMkxujw+P5NB35cqBzOT7d3MVKD7xWYSOWcj+5E4JmFYlHpZYy3jy1byg3Hqnw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(376002)(39860400002)(136003)(366004)(230922051799003)(451199024)(186009)(64100799003)(1800799009)(26005)(6512007)(6486002)(6506007)(478600001)(83380400001)(2616005)(2906002)(316002)(6916009)(66556008)(54906003)(66476007)(66946007)(8936002)(41300700001)(8676002)(5660300002)(4326008)(36756003)(38100700002)(31696002)(86362001)(31686004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?lDNKjEEA0fUu31WfHt6shB3gwwGr?= =?utf-8?q?E+ZkJ7BO14U8obeFt00FYooKr3xvh5eBakw4+0zybAlsVdbBfGl4HSbO12Z277lvp?= =?utf-8?q?sVbotOZqBh6F2nHHk9kSWAoZ/GbJxKPP1BkLu0uLEW+m9gOfm3RvZlTU5tyM4UMIu?= =?utf-8?q?QfiO0m77X18Pi7VxLgzLg5AoG3tHPTKNI1NZw3A6XMsOS31PFx4PCWSmgNfEWuN3T?= =?utf-8?q?XwhOqE+RTXHc8ImICY5YVn+bbEYU76Dh32i7l4wcFT62a+cCzyhjITcNib9pmdB84?= =?utf-8?q?uXfCStWt2DKQGOKj3jjkebOsCq+yYhkuAcsv1w6h3L1NIUSMC1htfamTMw3jZ8b/l?= =?utf-8?q?9IIlxMNsay39ql/0J5gHfVilv/ciWkSZtGYzHVm/c1tj5jBrKl1y3ew7GZaFAOEB3?= =?utf-8?q?DnCmoSoU8+seDsVFP9E+BfwX+D2oaTyWJptrVVtCBqRqqb4S1Iv1DQq51mabQXFAQ?= =?utf-8?q?DQwTGAt0VeI5jq6Wpjvii5EjOdRwu1fkglEbtCXWyG8YRjOaP5+qumR42t4MP6rhH?= =?utf-8?q?woM938KRyvNk4giv1ZxNg0Z3EC/EnEe6QCJ547iKUgj2cbV5kO6IBwjXtHEAcarxx?= =?utf-8?q?ednivC8cK7Yy2lRwow8x7xLovWlty1rqNorIM2Q8IFSTgSpV3wzPuD1TNrQ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mVPQlD9R5SDaxw?= =?utf-8?q?B+10zekcW+ok?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5f8ad04-a696-43e7-6917-08dbbff2d1db X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 07:16:22.7935 (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: AjGjRS0/cBXs0oO7XXpCO/PCxNz5XcYsTOtkwV5FEpgoXJvIwwMarxJjSLNmsLs5zX3L8yhKgLxC1DdXPS5kdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7811 In preparation of the introduction of new vCPU operations allowing to register the respective areas (one of the two is x86-specific) by guest-physical address, add the necessary fork handling (with the backing function yet to be filled in). Signed-off-by: Jan Beulich --- v3: Extend comment. --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1641,6 +1641,68 @@ static void copy_vcpu_nonreg_state(struc hvm_set_nonreg_state(cd_vcpu, &nrs); } +static int copy_guest_area(struct guest_area *cd_area, + const struct guest_area *d_area, + struct vcpu *cd_vcpu, + const struct domain *d) +{ + mfn_t d_mfn, cd_mfn; + + if ( !d_area->pg ) + return 0; + + d_mfn = page_to_mfn(d_area->pg); + + /* Allocate & map a page for the area if it hasn't been already. */ + if ( !cd_area->pg ) + { + gfn_t gfn = mfn_to_gfn(d, d_mfn); + struct p2m_domain *p2m = p2m_get_hostp2m(cd_vcpu->domain); + p2m_type_t p2mt; + p2m_access_t p2ma; + unsigned int offset; + int ret; + + cd_mfn = p2m->get_entry(p2m, gfn, &p2mt, &p2ma, 0, NULL, NULL); + if ( mfn_eq(cd_mfn, INVALID_MFN) ) + { + struct page_info *pg = alloc_domheap_page(cd_vcpu->domain, 0); + + if ( !pg ) + return -ENOMEM; + + cd_mfn = page_to_mfn(pg); + set_gpfn_from_mfn(mfn_x(cd_mfn), gfn_x(gfn)); + + ret = p2m->set_entry(p2m, gfn, cd_mfn, PAGE_ORDER_4K, p2m_ram_rw, + p2m->default_access, -1); + if ( ret ) + return ret; + } + else if ( p2mt != p2m_ram_rw ) + return -EBUSY; + + /* + * Map the area into the guest. For simplicity specify the entire range + * up to the end of the page: All the function uses it for is to check + * that the range doesn't cross page boundaries. Having the area mapped + * in the original domain implies that it fits there and therefore will + * also fit in the clone. + */ + offset = PAGE_OFFSET(d_area->map); + ret = map_guest_area(cd_vcpu, gfn_to_gaddr(gfn) + offset, + PAGE_SIZE - offset, cd_area, NULL); + if ( ret ) + return ret; + } + else + cd_mfn = page_to_mfn(cd_area->pg); + + copy_domain_page(cd_mfn, d_mfn); + + return 0; +} + static int copy_vpmu(struct vcpu *d_vcpu, struct vcpu *cd_vcpu) { struct vpmu_struct *d_vpmu = vcpu_vpmu(d_vcpu); @@ -1733,6 +1795,16 @@ static int copy_vcpu_settings(struct dom copy_domain_page(new_vcpu_info_mfn, vcpu_info_mfn); } + /* Same for the (physically registered) runstate and time info areas. */ + ret = copy_guest_area(&cd_vcpu->runstate_guest_area, + &d_vcpu->runstate_guest_area, cd_vcpu, d); + if ( ret ) + return ret; + ret = copy_guest_area(&cd_vcpu->arch.time_guest_area, + &d_vcpu->arch.time_guest_area, cd_vcpu, d); + if ( ret ) + return ret; + ret = copy_vpmu(d_vcpu, cd_vcpu); if ( ret ) return ret; @@ -1974,7 +2046,10 @@ int mem_sharing_fork_reset(struct domain state: if ( reset_state ) + { rc = copy_settings(d, pd); + /* TBD: What to do here with -ERESTART? */ + } domain_unpause(d); --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1601,6 +1601,13 @@ void unmap_vcpu_info(struct vcpu *v) put_page_and_type(mfn_to_page(mfn)); } +int map_guest_area(struct vcpu *v, paddr_t gaddr, unsigned int size, + struct guest_area *area, + void (*populate)(void *dst, struct vcpu *v)) +{ + return -EOPNOTSUPP; +} + /* * This is only intended to be used for domain cleanup (or more generally only * with at least the respective vCPU, if it's not the current one, reliably From patchwork Thu Sep 28 07:16:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13402179 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 61B70CE7B08 for ; Thu, 28 Sep 2023 07:17:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.609317.948342 (Exim 4.92) (envelope-from ) id 1qllGZ-00082o-5M; Thu, 28 Sep 2023 07:16:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 609317.948342; Thu, 28 Sep 2023 07:16:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qllGZ-00082h-2m; Thu, 28 Sep 2023 07:16:55 +0000 Received: by outflank-mailman (input) for mailman id 609317; Thu, 28 Sep 2023 07:16:53 +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 1qllGX-0006Ef-Ka for xen-devel@lists.xenproject.org; Thu, 28 Sep 2023 07:16:53 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0630.outbound.protection.outlook.com [2a01:111:f400:fe02::630]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ff87a13e-5dce-11ee-878a-cb3800f73035; Thu, 28 Sep 2023 09:16:53 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AS8PR04MB8884.eurprd04.prod.outlook.com (2603:10a6:20b:42f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21; Thu, 28 Sep 2023 07:16:50 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a%6]) with mapi id 15.20.6838.016; Thu, 28 Sep 2023 07:16:50 +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: ff87a13e-5dce-11ee-878a-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IRdCXcFMZD/dDg2QepxbmOXYN383dBovQj7Qf2G2B+Yr3w/vRoTXgd+Bg4fHclfW7zfkB13XYbvTvVGBfzZ1RWRA/DXLiMFaPL4u5O4w/wGAPHedSzA0ofUhUf+yhobqosd+Pc5LBV0vulx6MiAR7E2LQPkASNXYMMlMQqbA6x0KI9ML3x+WWfvgfFluDNs4rlQ4rm3MO8UHpnIUC0uFDW/28Sr4pYsK/5wzuE2FuVQaaEvM8naM8ZvF78qGAhYvjzIwv0vrDwaVVPSTmumW6QEOPcZrJbyVQLqSVHJidk3WZ0cNa7MMZqt17kHYj/a41UNvL8kLK9t9ioOor7XXqQ== 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=OdVm0Th937N+vCPEHX+Fu1YV+tgza1dfXYx9xJHohDc=; b=Vc0c6IlTEEWGFNwmGAmgRWOG8lxHlxqo6Fdw/W2K4ptxYPFiNNI6rp8vkuhGHJSdAEscfCbIWXW0c/HuhrKk45vDLkUGaFwMT9nqUdLnRgcjFxbuXPiBlj+RA0fldk7X2+i5mXeqeMO9jZMghUMJeLpJaEG/pNgua8wx8Yexr4JX9M0D+3Q/GNhjKXA21j7XnW03x0CGRYp9xP5F9QNq6091R/ggGzobCOIrejB4EtFvaWYqQCTOVwRvAe618ZjFCfRz2ucDzQucGYkM1Zxp3WApVMErmBSKvl/f3vvYk5Cohgr7CTlpNGk6h8AUZVzZyZaiRFkF7WozB4f8Uzq1Tw== 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=OdVm0Th937N+vCPEHX+Fu1YV+tgza1dfXYx9xJHohDc=; b=vvK/cUQW5B84WIIKvJ0Vu/0pZpjuTBvczb1JL97KLnUWO7Qc3azK+GUtEoKSHLDoD5L28urNOfXGnK/I88uWZL/94awiWqBFV1ZEGzW/EgPLfWPlcusH59W33x/Rb78LMQGAaCfPmSs3g1eY9T0t7aECLNSE9+nt2e0HxWtS3dPL8byhtF5PV8e043ni4CUiIeTLn6MyDp3rvcX5CWMDv5K5JbYGOeN0Qh20RiIO0EeJ58uFqw72wPBv8l7suZqhnznp92H61JSDH2P4O2R+FgRJKcpxWxM2D0CCDTkYHmyoJDUtIlh53pey639fTsozrdZiU+ZTTU1QcobSGkBJ7Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Thu, 28 Sep 2023 09:16:48 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PATCH v4 6/9] domain: map/unmap GADDR based shared guest areas 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?= , Henry Wang References: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> In-Reply-To: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> X-ClientProxiedBy: FR4P281CA0174.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b7::20) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AS8PR04MB8884:EE_ X-MS-Office365-Filtering-Correlation-Id: 27b1300c-26e7-422e-445a-08dbbff2e254 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PmZ41yt+6DG856FdpwT8OaP3ILcSwVYtrwbmb4kXDTjqk68qKFQPyxxe2BqyGZDRJ9ToMwJ1kd+NrhAOVK7EDTA7rIQyfWhCM+pujl13VKRwLv+KUkWvR6JEDsm3TR8uZV+zpC9YXosaiT9Uc5hhkv2CLqT2VKUqAS3u/Eex54ETdSTlQqjSYSDJ96fUR2ah2yM5HOPkKgdklrB8W+A1EyTu9vXJYer2HdkS3v/o3C6Q6PSNURlkluvbKUGIuIW85g01digsSL0ZTnU1vxrJqjW5zuPZTlZKNmhdFscUnDifd3Fz82xLNwGhF5NtN2bNvzhVhGWQtZ+f/syty96X9etGzd4r3sDQdsVgoUW0ob2iDDfAfV5ZGGHjkikqgHgDnBxSM+fhUqNrGl5cVre8TT+IdKtj7/br0xRnJEFo8QQJe+UIGOhK9Hodni4TwcZ+UzD/RSCDcBFbiOioNUgKQl3dL02WuNNtv7Hbteoss8YH4qZ/thN20G6trM/X37O/Ax8aqjXXRk3C4FZOxRf1icjnaQTR3fXd7wkr9RTJdZeGAB8/u9Jnzj7/hvxhuPsHYEiwTMJMau20qXvC6gueiOkQXxM/LpK1v+EHWp3ojpqWi39nV5QxKoYUAXhMC+41ETF+DmGIcmBn95W1t/qDjw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(346002)(376002)(396003)(136003)(230922051799003)(64100799003)(451199024)(186009)(1800799009)(2616005)(83380400001)(26005)(31686004)(478600001)(36756003)(6512007)(6506007)(6486002)(66946007)(66476007)(316002)(66556008)(54906003)(6916009)(8676002)(41300700001)(8936002)(4326008)(86362001)(5660300002)(31696002)(38100700002)(2906002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?UH8guojGmgKe9TQ3JJv3XyrsDkbS?= =?utf-8?q?NoU0Crtt2bDYwHn25Z+vhouSarVW340m1o7fiCYr4WuZX3w2lYoRJgL/r2lfQmhZw?= =?utf-8?q?uX3uevLbK2+YEW8ve/pDm4JWNNtH0ImdOFeWXpHwD7NJrJpkUbcGa+0S2KDnTDVIt?= =?utf-8?q?mjZeqVAKLJFXfl23vJbY44Iexl1eDue0hniQON+ZQShah+E1sHJzgCFxRYzGcuhMz?= =?utf-8?q?lrvIxOx8XI66TlJDXJrBcVV+9JETxVbRGzXzvTJoRvsViqnA6VstXtSqhiHFQhTXJ?= =?utf-8?q?tiz6OcVo/ZNn5unZrsrHZmFDn/NW+6Xl670U9LE3Mwzlww5astocchwnTcF6F3MDl?= =?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aPbuS9pFpuqDRiG4gJOcHTd9NLcLInX5uTYIvNSs4CR3SM4bzQWf8xv7cs95?= =?utf-8?q?K8TlXufj+qQU+6ZqksAjCPODm0CN6xncUtfWbEosH30CwkQOkW5h//04TZBqVlntw?= =?utf-8?q?daJPMAKgNszIWpwJCodZtoa/FRr542qQVhq5T5wXsSdEFupRFbey1YzX9u2PLexER?= =?utf-8?q?jlVQi+gum7hMoux5zh3lflHsokzNTVoygGapUh3CESjPTQB+0/cDJOY+X0fH+o56X?= =?utf-8?q?EW4F5AXtD17zY7Zfmbx9Mm4/G1/xXpf0YKngFQ+fsB5+RqC91Oyh/NESz3i3iKqbu?= =?utf-8?q?Xo8P6VPgQ2HA?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 27b1300c-26e7-422e-445a-08dbbff2e254 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 07:16:50.4452 (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: m2N6kSdbpwh4Rp0vk+49qovBzPiq/Gu1xyKIaWk4qyliFiRkt1Nlr1WL8QlfPRiabOHh1+CNBqh3aX5DdLmTaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8884 The registration by virtual/linear address has downsides: At least on x86 the access is expensive for HVM/PVH domains. Furthermore for 64-bit PV domains the areas are inaccessible (and hence cannot be updated by Xen) when in guest-user mode, and for HVM guests they may be inaccessible when Meltdown mitigations are in place. (There are yet more issues.) In preparation of the introduction of new vCPU operations allowing to register the respective areas (one of the two is x86-specific) by guest-physical address, flesh out the map/unmap functions. Noteworthy differences from map_vcpu_info(): - areas can be registered more than once (and de-registered), - remote vCPU-s are paused rather than checked for being down (which in principle can change right after the check), - the domain lock is taken for a much smaller region. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné Reviewed-by: Roger Pau Monné --- RFC: By using global domain page mappings the demand on the underlying VA range may increase significantly. I did consider to use per- domain mappings instead, but they exist for x86 only. Of course we could have arch_{,un}map_guest_area() aliasing global domain page mapping functions on Arm and using per-domain mappings on x86. Yet then again map_vcpu_info() doesn't (and can't) do so. RFC: In map_guest_area() I'm not checking the P2M type, instead - just like map_vcpu_info() - solely relying on the type ref acquisition. Checking for p2m_ram_rw alone would be wrong, as at least p2m_ram_logdirty ought to also be okay to use here (and in similar cases, e.g. in Argo's find_ring_mfn()). p2m_is_pageable() could be used here (like altp2m_vcpu_enable_ve() does) as well as in map_vcpu_info(), yet then again the P2M type is stale by the time it is being looked at anyway without the P2M lock held. --- v4: Add another comment. Use IS_ALIGNED(). Add another NULL check. v2: currd -> d, to cover mem-sharing's copy_guest_area(). Re-base over change(s) earlier in the series. Use ~0 as "unmap" request indicator. --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1605,7 +1605,82 @@ int map_guest_area(struct vcpu *v, paddr struct guest_area *area, void (*populate)(void *dst, struct vcpu *v)) { - return -EOPNOTSUPP; + struct domain *d = v->domain; + void *map = NULL; + struct page_info *pg = NULL; + int rc = 0; + + if ( ~gaddr ) /* Map (i.e. not just unmap)? */ + { + unsigned long gfn = PFN_DOWN(gaddr); + unsigned int align; + p2m_type_t p2mt; + + if ( gfn != PFN_DOWN(gaddr + size - 1) ) + return -ENXIO; + +#ifdef CONFIG_COMPAT + if ( has_32bit_shinfo(d) ) + align = alignof(compat_ulong_t); + else +#endif + align = alignof(xen_ulong_t); + if ( !IS_ALIGNED(gaddr, align) ) + return -ENXIO; + + rc = check_get_page_from_gfn(d, _gfn(gfn), false, &p2mt, &pg); + if ( rc ) + return rc; + + if ( !get_page_type(pg, PGT_writable_page) ) + { + put_page(pg); + return -EACCES; + } + + map = __map_domain_page_global(pg); + if ( !map ) + { + put_page_and_type(pg); + return -ENOMEM; + } + map += PAGE_OFFSET(gaddr); + } + + if ( v != current ) + { + if ( !spin_trylock(&d->hypercall_deadlock_mutex) ) + { + rc = -ERESTART; + goto unmap; + } + + vcpu_pause(v); + + spin_unlock(&d->hypercall_deadlock_mutex); + } + + domain_lock(d); + + if ( map && populate ) + populate(map, v); + + SWAP(area->pg, pg); + SWAP(area->map, map); + + domain_unlock(d); + + if ( v != current ) + vcpu_unpause(v); + + unmap: + if ( pg ) + { + unmap_domain_page_global(map); + put_page_and_type(pg); + } + + return rc; } /* @@ -1616,9 +1691,24 @@ int map_guest_area(struct vcpu *v, paddr void unmap_guest_area(struct vcpu *v, struct guest_area *area) { struct domain *d = v->domain; + void *map; + struct page_info *pg; if ( v != current ) ASSERT(atomic_read(&v->pause_count) | atomic_read(&d->pause_count)); + + domain_lock(d); + map = area->map; + area->map = NULL; + pg = area->pg; + area->pg = NULL; + domain_unlock(d); + + if ( pg ) + { + unmap_domain_page_global(map); + put_page_and_type(pg); + } } int default_initialise_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) From patchwork Thu Sep 28 07:17:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13402180 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 416C5CE7B07 for ; Thu, 28 Sep 2023 07:17:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.609323.948352 (Exim 4.92) (envelope-from ) id 1qllHF-0000IV-Gx; Thu, 28 Sep 2023 07:17:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 609323.948352; Thu, 28 Sep 2023 07:17: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 1qllHF-0000IK-EG; Thu, 28 Sep 2023 07:17:37 +0000 Received: by outflank-mailman (input) for mailman id 609323; Thu, 28 Sep 2023 07:17: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 1qllHE-0007vD-DA for xen-devel@lists.xenproject.org; Thu, 28 Sep 2023 07:17:36 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0605.outbound.protection.outlook.com [2a01:111:f400:fe0e::605]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1804ff52-5dcf-11ee-9b0d-b553b5be7939; Thu, 28 Sep 2023 09:17:34 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AS8PR04MB8884.eurprd04.prod.outlook.com (2603:10a6:20b:42f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21; Thu, 28 Sep 2023 07:17:32 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a%6]) with mapi id 15.20.6838.016; Thu, 28 Sep 2023 07:17:32 +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: 1804ff52-5dcf-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gBH63qH2I2T1kLmiH0qUjmap+t0DXcgR0/Gke2lrwyxN7P9CEt3kig/Wn6wio1R08Grgjpln/+7+io/Tn70jayxGXF6CM7LPCMaWRRxH3Z9OSO14GrJynwZigbkCT4peXcvfEVpJreH+WetEcW4AqoXn2z6DXBRg0MX+IjyN+Me+oiJS6Q4VLJPpO31+RX9RKB0j9AdLhthe4iW1XshFFxmjiY7zKf51m+cM2I6DRvooJMaEg0F93jCmzjEMIYZ74IyGDF708luzUYv7MpiXFXI7Q49u1V5XiEvzlwPoVaNKBSXUkQofc3nzAirOKR0SzshgWph1fuIlnHG6jkVzFQ== 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=iHe12jYFCsixkC+lD66ZJrCoQJgG2Et89o2kOEOZydg=; b=VpJyExhxKzCC6rUcM0D0xGEMdMNIGXhkOFOLzmreoRDT6HyNGiGLB+6nZP1IeSeSl+/ZR+MJdEfCyolo4c4RsqRfX8yg+4BcR5jb+gzBNiOfdjqonfAY2pHGMiIomkNpoo6ReZTGhXIjTDHEZHVUmITovklisR9Hf7yuuWtt0hirxD5hHiLNGy5AnetZbKf/+pXvPVZ7A9su3z3ei66S5npeCUbWM0VVMWodylBoKS83mpKrUUmTmRV48WEDZkHdChLxVHCyuuQaS6EZNvJj7TMN/90YrD5bU19V4w77nQMFFu3VC5DOYIpLMjIRhXhGdnsER1B/cCKuHVpgml7DWQ== 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=iHe12jYFCsixkC+lD66ZJrCoQJgG2Et89o2kOEOZydg=; b=xFMu8r8JuEU2YjKCWjdIKRzeWtqXG7RFR6oDic0x0/Lxk1o824jCSL/Wp3tvoSbfi+d1yQD0BVAg2DXtQE3cdSzGc3MGl3QCWmGanvwxlbeh+JC3zj1+RPP3sdRgvA7eaGVC/YfqQTeU8gDWN+aO5wkP6+PdGvfL+K+7u8T3Q/M9dgbWikpioM4vIqGurfKGvXbNCHTOeBr363R158XAu68cX5kVo5zeJa0kR2Wl0tztgOPlFV62WXIkXNiTXXBRAFSHHi8vXb1A2dso9/0bj7Mk6JsYsI2SRaHiMmIoFXu+G3GC6rhRr1EncxWcz83D5RqodoKyWVomNctMcevA4w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <00736f1f-6a0e-f368-194c-edca196ec577@suse.com> Date: Thu, 28 Sep 2023 09:17:30 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PATCH v4 7/9] domain: introduce GADDR based runstate area registration alternative 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?= , Henry Wang References: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> In-Reply-To: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> X-ClientProxiedBy: FR4P281CA0177.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b7::14) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AS8PR04MB8884:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c8b28f6-3851-4203-ffa3-08dbbff2fb94 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mM5aKLELW8bAnciazI5LknkegWzpP6f4wYSpqcqQ/TF5LwllXCOmkEeRdVvP7XaXnMWtxe08yWdHUO3O0jAR9hpFI8rPzCHblKu0WDb8aFVhvPIZWSYmb/Y3zNOSlyUODb2i0fajShQif9QIP1R5MFEMA3KuAUdPEbDXALmcr42Vbi+AJ90EojVilTyyxu4H4+0g4hK62clSDNjbYa2J8nKo6b1hB/kLZAVPyocKDBWQupSnRNcPnQJUfwWd+U5bsVeFQUacKDvq7Awc2bVA5cKJs3xpStCcv1fVeIHdHsv+e/hRB0UfBIVMoOP38SGnePGHP822qk51pcq55g8eEYxQC1Fqd+sWgBrH3c15XUzCKm/ESroEG8AA0l1pQqpL4wyKgQi1R6/qP6KBayu55Uh/NruRTy0O414rQNmF5/HPnHXQq+Y3ksqRCALV5fh1bogjx3ABtsqtyjdPr21ebl8Is3q3JMyphAxDqTzMCbJrCWppYLRiqwwy+MXsOWIUcwrELMA5OQ2VkCClWxlFXOjzqJbyFcxfsnWKMQ3Nb/+g82QApxaGnjW56Biz9c67iMTvprUQTzdczFOL0hwJncbEmntkURC2nzFrSE3s9Z1lTvzvpaDDvP1h7H7VTp4QuFdBZXj9UCEMcl+qwhBEPQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(346002)(376002)(396003)(136003)(230922051799003)(64100799003)(451199024)(186009)(1800799009)(2616005)(83380400001)(26005)(31686004)(478600001)(36756003)(6512007)(6506007)(6486002)(66946007)(66476007)(316002)(66556008)(54906003)(6916009)(8676002)(41300700001)(8936002)(4326008)(86362001)(5660300002)(31696002)(38100700002)(2906002)(45980500001)(43740500002);DIR:OUT;SFP:1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+eyx/DVC8wm+R0E/tOX2rPxM4ut?= =?utf-8?q?KHYtZ8DoZl5hg1ZwvM3TwcqC+E4vcWp6LKOmwqgcgesAZhuaiROx9HMZh6wLHI6di?= =?utf-8?q?BfqqBNzFi5K+lX2+QzEFq4unIhxSCo2DyRAXYPxupEAOiTYmskVvgiOwUhRgEtVSQ?= =?utf-8?q?gFVgs2iZDB+ERGiy8DdBkrxRHJwDECy9h/Pb92SJwlUsbfWS61EYcJ/7xeOifG0Tt?= =?utf-8?q?dJvPj1/FLoLycR4TLvL/67IcGtwGkG3n9FBAGSU8TODZ2fDDHiJylv/uqkNiz1o4i?= =?utf-8?q?KiEcO8llbdyUJtStjOVphdUw5OzZGvxEXU7D5QKHeQn4kcdU1FBWWggwQPJbTYlHE?= =?utf-8?q?dDZQ0zkI1ML99BPyDlsxC70zQUVBmNGV7RYhgXnx7vU4UW/odzTbLMyNKurwFg3I9?= =?utf-8?q?jVCVFiLTyutCzDFvnMowYIrFjX60aj4kQuywoApweHggEu/X4y4IrZ9pv+iEarDR2?= =?utf-8?q?GfhK/9bBy7c7K3jvPub78BAxoKLnZMzS+wdR4Wr2bS/146EL3+o77V/45NFSO2hM3?= =?utf-8?q?xiFtmmlt4VpwGaIRehYStflwWtDLDyMNpitmfokkUiRa+Va/vg+AjmouMQdih3Gwo?= =?utf-8?q?l3iWRpaclpXZwGxNwqkltY5H4+86oobunZUGP92/ajeOf4uaCysdA0/p32mVVgW2N?= =?utf-8?q?ApO5mFmnd0ZwrVi4U03Ycy30virsdt7wnTNIfHFNjsRFC9yyjGlbYRTs8bV6u+i2J?= =?utf-8?q?iZr9cBCRLYtn?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c8b28f6-3851-4203-ffa3-08dbbff2fb94 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 07:17:32.7990 (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: nlRg5ig4Xhl20PRt6+MguBjWK/7mIxaqEzfUVvwN9mu9HpjgqU9X9pTou3BHPlTgwYbHFmbjiPQWvDavD6bo1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8884 The registration by virtual/linear address has downsides: At least on x86 the access is expensive for HVM/PVH domains. Furthermore for 64-bit PV domains the area is inaccessible (and hence cannot be updated by Xen) when in guest-user mode. Introduce a new vCPU operation allowing to register the runstate area by guest-physical address. An at least theoretical downside to using physically registered areas is that PV then won't see dirty (and perhaps also accessed) bits set in its respective page table entries. Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- v4: Add xref in public header. v2: Extend comment in public header. --- a/xen/arch/x86/x86_64/domain.c +++ b/xen/arch/x86/x86_64/domain.c @@ -12,6 +12,22 @@ CHECK_vcpu_get_physid; #undef xen_vcpu_get_physid +static void cf_check +runstate_area_populate(void *map, struct vcpu *v) +{ + if ( is_pv_vcpu(v) ) + v->arch.pv.need_update_runstate_area = false; + + v->runstate_guest_area_compat = true; + + if ( v == current ) + { + struct compat_vcpu_runstate_info *info = map; + + XLAT_vcpu_runstate_info(info, &v->runstate); + } +} + int compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg) { @@ -57,6 +73,25 @@ compat_vcpu_op(int cmd, unsigned int vcp break; } + + case VCPUOP_register_runstate_phys_area: + { + struct compat_vcpu_register_runstate_memory_area area; + + rc = -EFAULT; + if ( copy_from_guest(&area.addr.p, arg, 1) ) + break; + + rc = map_guest_area(v, area.addr.p, + sizeof(struct compat_vcpu_runstate_info), + &v->runstate_guest_area, + runstate_area_populate); + if ( rc == -ERESTART ) + rc = hypercall_create_continuation(__HYPERVISOR_vcpu_op, "iih", + cmd, vcpuid, arg); + + break; + } case VCPUOP_register_vcpu_time_memory_area: { --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1830,6 +1830,26 @@ bool update_runstate_area(struct vcpu *v return rc; } +static void cf_check +runstate_area_populate(void *map, struct vcpu *v) +{ +#ifdef CONFIG_PV + if ( is_pv_vcpu(v) ) + v->arch.pv.need_update_runstate_area = false; +#endif + +#ifdef CONFIG_COMPAT + v->runstate_guest_area_compat = false; +#endif + + if ( v == current ) + { + struct vcpu_runstate_info *info = map; + + *info = v->runstate; + } +} + long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) { long rc = 0; @@ -2011,6 +2031,25 @@ long common_vcpu_op(int cmd, struct vcpu break; } + + case VCPUOP_register_runstate_phys_area: + { + struct vcpu_register_runstate_memory_area area; + + rc = -EFAULT; + if ( copy_from_guest(&area.addr.p, arg, 1) ) + break; + + rc = map_guest_area(v, area.addr.p, + sizeof(struct vcpu_runstate_info), + &v->runstate_guest_area, + runstate_area_populate); + if ( rc == -ERESTART ) + rc = hypercall_create_continuation(__HYPERVISOR_vcpu_op, "iih", + cmd, vcpuid, arg); + + break; + } default: rc = -ENOSYS; --- a/xen/include/public/vcpu.h +++ b/xen/include/public/vcpu.h @@ -110,6 +110,8 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_in * runstate.state will always be RUNSTATE_running and * runstate.state_entry_time will indicate the system time at which the * VCPU was last scheduled to run. + * 3. New code wants to prefer VCPUOP_register_runstate_phys_area, and only + * fall back to the operation here for backwards compatibility. * @extra_arg == pointer to vcpu_register_runstate_memory_area structure. */ #define VCPUOP_register_runstate_memory_area 5 @@ -221,6 +223,19 @@ struct vcpu_register_time_memory_area { typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t; DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t); +/* + * Like the respective VCPUOP_register_*_memory_area, just using the "addr.p" + * field of the supplied struct as a guest physical address (i.e. in GFN space). + * The respective area may not cross a page boundary. Pass ~0 to unregister an + * area. Note that as long as an area is registered by physical address, the + * linear address based area will not be serviced (updated) by the hypervisor. + * + * Note that the area registered via VCPUOP_register_runstate_memory_area will + * be updated in the same manner as the one registered via virtual address PLUS + * VMASST_TYPE_runstate_update_flag engaged by the domain. + */ +#define VCPUOP_register_runstate_phys_area 14 + #endif /* __XEN_PUBLIC_VCPU_H__ */ /* From patchwork Thu Sep 28 07:17:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13402181 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 40CFECE7B04 for ; Thu, 28 Sep 2023 07:18:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.609325.948362 (Exim 4.92) (envelope-from ) id 1qllHe-0000mu-Pi; Thu, 28 Sep 2023 07:18:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 609325.948362; Thu, 28 Sep 2023 07:18: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 1qllHe-0000mn-Mr; Thu, 28 Sep 2023 07:18:02 +0000 Received: by outflank-mailman (input) for mailman id 609325; Thu, 28 Sep 2023 07:18:02 +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 1qllHe-0007vD-1U for xen-devel@lists.xenproject.org; Thu, 28 Sep 2023 07:18:02 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0614.outbound.protection.outlook.com [2a01:111:f400:fe0e::614]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 27434696-5dcf-11ee-9b0d-b553b5be7939; Thu, 28 Sep 2023 09:17:59 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AS8PR04MB8884.eurprd04.prod.outlook.com (2603:10a6:20b:42f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21; Thu, 28 Sep 2023 07:17:58 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a%6]) with mapi id 15.20.6838.016; Thu, 28 Sep 2023 07:17:58 +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: 27434696-5dcf-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EPkMsnabufSmpbx6QIx/y3RCccc5Paton0OJnj41bAN3dXbHTFSqGkgYG3Qi4+PloxpwDoYGO/dbEF9egUO/C0d1E5IM0lxQE95p69cTcu8P4VjNDOVImzOVVnz5YAnSpLEljluTmQnL3PLZ2j+n7rZ3+kDvNBeo3OfWA52GsTc+DtTyr0SHtbzfa9alblHD3HNMLsZg63uMb8wVxTnTu4rBq9hh25js3Ca1dsxrAK34SSKISKvxTGKlTS5w7GN1sUOxdM6LRI9AYf7Fr5Eap3PPz2GtSAbToolwgwnSp/HQXM6WTWIKG0CYLKaG9CnRu0rET/IPoEpp8PFHydQ/Zw== 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=I+OV0nhX0WwhrZMdhQwtKb70aws/RhTWdhHwFYCofOM=; b=mrhqEjHRXtJUxmNvp9wW1MEkvphEqWFqav8h2IB52p62ZHDI4UW9kSpYAyuVeXqPgaOHJJ8sY/x/kCmc3ZC5/JZruS+BYNTqvRXsKOzOr3XwUVijA8Ho9aK4wVqw/CwZJtUFAm6XXRxAMg4+t8TVse+lbbp1070ad/Wu2ALEvvS/O38TLhZp8UVHWZHXqtIRAOphaOOyvCKSW2LTa7ypAcWGttpOuLnm0+hF5xaoFk7lNoy6zTqmF+Z0HsNoFBjmlEeTorJEF4DOyiSmvCo5dxSFbaYZUoG19r7WdXHdEUQSWSDstG3oTGlibYI/v3tPBiYCDJ29EeLaccysfpS7JA== 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=I+OV0nhX0WwhrZMdhQwtKb70aws/RhTWdhHwFYCofOM=; b=Pmr6EypQ4XsfLWOElSTKZltr/62Zn0TLRMewjFu65Pq2x/s3iJWloW+PjKLCsqPZITw9LO/AR6LeTpX5Vuko8v8pnCJToVd5bOAXLJjU0esbuHBzoKEsDruJSv8+AdaTQQg+xzbdVJj2wAT6hK5UwRRDrDxzOK0lyZTJhhu3TvFsc9PoIQW2T39EFWIU1eb8Askmyib8AHJPd83m/7pmb/WwZZ3YYt2rx1cxG5/pug5I7rsE6jbfCAfknkvasxTOvLiTxFAoyYl32qwCFagQsxSo7Oucc5bqTdoaXKj+jazPhj6YRWKFIMvYij2i701wYjw0OuSXiCbN7bnrQC7WMw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <4f28ae35-031a-461a-4be2-b24a057ea20b@suse.com> Date: Thu, 28 Sep 2023 09:17:55 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PATCH v4 8/9] x86: introduce GADDR based secondary time area registration alternative 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?= , Henry Wang References: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> In-Reply-To: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> X-ClientProxiedBy: FR4P281CA0163.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:ba::8) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AS8PR04MB8884:EE_ X-MS-Office365-Filtering-Correlation-Id: 264fa25e-f1c8-4ea0-23aa-08dbbff30ac0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ept45ednt5cbtDXb7ICCfhgIFUH+r7U7YPlm4uROa/5tKfzn/QiurLtb0tSYg3CEs8wyT+EvZm+534IbU+MpixjtbL6vruaKBZzkfs4GRYUI/n3JmGx3sf9sDT7KbH4dgRXyhvxgrL3i58d9ZZM0ggBtGzuo+bM7yjQgnJisIjoQxORzvWKJ4bOLM4Ag7dIOL4+m0OFOhj/DfvDhkb0wlUoYOwIclVD1eO7qpu9noOL9GIHLE/BWhV1gzRdJlVq9h8iTy5W39CHa+66ZjRoDF1RLUu9gj/H8pGSAN2BTnq0gy6lNrLmKS8J+ud3EwV8XuvzZA7TIBLv5BKZugy1vNAavgJ63EXQEQGHWIcBUMNc0LPaSYqy/h43baUeajoSWNmfe/La6QYLIRiW3FyG9/quCG6w58447VWO6iEZHPp8LEW6qNLF22w38QGNbABk+lqQRx2RB/Ntf/KVRnzw4EXv6RpVebLfB7ujK4GKp4vTiUEANYvboZ4SKDNA5hBuf6PKUGsCVGs4cK3KEyy+0izfX7YBGX1Cun0cHhvwOx0ME66TBie2U4JSEmAV+XGFcFKMw7jfcwnEGr0cJTJ20+3sD/psc6NQO/olfunkyG1Ul3toi+7PAE53TtSacNprvFK7eE8CLvy6sjxYXqK/tlg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(346002)(376002)(396003)(136003)(230922051799003)(64100799003)(451199024)(186009)(1800799009)(2616005)(83380400001)(26005)(31686004)(478600001)(36756003)(6666004)(6512007)(6506007)(6486002)(66946007)(66476007)(316002)(66556008)(54906003)(6916009)(8676002)(41300700001)(8936002)(4326008)(86362001)(5660300002)(31696002)(38100700002)(2906002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?FEAyhnKWCPHYaK9qj+ZBwao+sjU0?= =?utf-8?q?/wBIvWQy2iZsOYJWgGliAn+E6Q5bmbChddi8/A2/EYGvjia6RB+RDxvGROoE17OWd?= =?utf-8?q?KXLwUq373akkVyL+3dCelLDuG7ALEH/x8LKSI0TaTLaBZEwj/1LXtEvEUnur3IB3x?= =?utf-8?q?pSFMN5P1+EKBHb2GMwjt6hEVY446JOQElyOVBPjD6uMCYj8iOgLn7ZTnLSk4YuVbt?= =?utf-8?q?Vf5fO2ImXNGQ6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vDQdq22CxFSy3/G1qv0nTebAz5n9PCY2A86PFguVIO5pQnxyITSpwr3lh?= =?utf-8?q?SQIbQJ6tGq9VkKtii3xv5LqloPC7HhGa4CpZHM6YjGOKOBitX7lB9TV+LBDlwfZsl?= =?utf-8?q?bhMKn/OkRzwz4gssnlKTee+kCQ8GoA6l9YbCLF4dEkF4xZ0q+V/Cot9w6TcPGif+C?= =?utf-8?q?GCnfNUv2MG1de13d9LueiJpZEPy6CDL2RNroUS1F5B+YrnncNu3p3gaa++htG3XEI?= =?utf-8?q?FugS+s5EzTsxdlkgwWug3S+81ORv44MVbMc3e5LRfBoA+Td23lnWEnC7COIQphEzY?= =?utf-8?q?DUaGNzJIbq6hqsxNDXwdCjNyN6NfLdVwjKOg54UxhhsYCu9nQxB721toiPAZOBjZW?= =?utf-8?q?GrJ4LHkHXzbir/EzivqpYuiF7YqeMUiAoj9xNMPmOQYgfAAfhjmUnAFyjuRJ3gEnH?= =?utf-8?q?SmBLxB08sQ+k?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 264fa25e-f1c8-4ea0-23aa-08dbbff30ac0 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 07:17:58.2340 (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: zE0Oa4A0aBCKJbQ/T7En8QNEbcdI/pLyRESvOf5uR7byHXgr9WLhlZZBvr6avDMSYPT6X0yDfjU03E+HPBWRlw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8884 The registration by virtual/linear address has downsides: The access is expensive for HVM/PVH domains. Furthermore for 64-bit PV domains the area is inaccessible (and hence cannot be updated by Xen) when in guest-user mode. Introduce a new vCPU operation allowing to register the secondary time area by guest-physical address. An at least theoretical downside to using physically registered areas is that PV then won't see dirty (and perhaps also accessed) bits set in its respective page table entries. Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- v4: Add xref in public header. v3: Re-base. v2: Forge version in force_update_secondary_system_time(). --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1529,6 +1529,15 @@ int arch_vcpu_reset(struct vcpu *v) return 0; } +static void cf_check +time_area_populate(void *map, struct vcpu *v) +{ + if ( is_pv_vcpu(v) ) + v->arch.pv.pending_system_time.version = 0; + + force_update_secondary_system_time(v, map); +} + long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg) { long rc = 0; @@ -1566,6 +1575,25 @@ long do_vcpu_op(int cmd, unsigned int vc break; } + + case VCPUOP_register_vcpu_time_phys_area: + { + struct vcpu_register_time_memory_area area; + + rc = -EFAULT; + if ( copy_from_guest(&area.addr.p, arg, 1) ) + break; + + rc = map_guest_area(v, area.addr.p, + sizeof(vcpu_time_info_t), + &v->arch.time_guest_area, + time_area_populate); + if ( rc == -ERESTART ) + rc = hypercall_create_continuation(__HYPERVISOR_vcpu_op, "iih", + cmd, vcpuid, arg); + + break; + } case VCPUOP_get_physid: { --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -692,6 +692,8 @@ void domain_cpu_policy_changed(struct do bool update_secondary_system_time(struct vcpu *, struct vcpu_time_info *); +void force_update_secondary_system_time(struct vcpu *, + struct vcpu_time_info *); void vcpu_show_registers(const struct vcpu *); --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1628,6 +1628,16 @@ void force_update_vcpu_system_time(struc __update_vcpu_system_time(v, 1); } +void force_update_secondary_system_time(struct vcpu *v, + struct vcpu_time_info *map) +{ + struct vcpu_time_info u; + + collect_time_info(v, &u); + u.version = -1; /* Compensate for version_update_end(). */ + write_time_guest_area(map, &u); +} + static void update_domain_rtc(void) { struct domain *d; --- a/xen/arch/x86/x86_64/domain.c +++ b/xen/arch/x86/x86_64/domain.c @@ -115,6 +115,7 @@ compat_vcpu_op(int cmd, unsigned int vcp case VCPUOP_send_nmi: case VCPUOP_get_physid: + case VCPUOP_register_vcpu_time_phys_area: rc = do_vcpu_op(cmd, vcpuid, arg); break; --- a/xen/include/public/vcpu.h +++ b/xen/include/public/vcpu.h @@ -209,6 +209,9 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_get_physid_ * segment limit). It can then apply the normal algorithm to compute * system time from the tsc. * + * New code wants to prefer VCPUOP_register_vcpu_time_phys_area, and only + * fall back to the operation here for backwards compatibility. + * * @extra_arg == pointer to vcpu_register_time_info_memory_area structure. */ #define VCPUOP_register_vcpu_time_memory_area 13 @@ -235,6 +238,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_register_ti * VMASST_TYPE_runstate_update_flag engaged by the domain. */ #define VCPUOP_register_runstate_phys_area 14 +#define VCPUOP_register_vcpu_time_phys_area 15 #endif /* __XEN_PUBLIC_VCPU_H__ */ From patchwork Thu Sep 28 07:18:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13402204 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 A86BBCE7B04 for ; Thu, 28 Sep 2023 07:22:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.609330.948371 (Exim 4.92) (envelope-from ) id 1qllLX-0002hO-9z; Thu, 28 Sep 2023 07:22:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 609330.948371; Thu, 28 Sep 2023 07:22:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qllLX-0002hH-7K; Thu, 28 Sep 2023 07:22:03 +0000 Received: by outflank-mailman (input) for mailman id 609330; Thu, 28 Sep 2023 07:22:02 +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 1qllI0-0006Ef-EX for xen-devel@lists.xenproject.org; Thu, 28 Sep 2023 07:18:24 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on062a.outbound.protection.outlook.com [2a01:111:f400:fe02::62a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3579f611-5dcf-11ee-878a-cb3800f73035; Thu, 28 Sep 2023 09:18:23 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AS8PR04MB8884.eurprd04.prod.outlook.com (2603:10a6:20b:42f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21; Thu, 28 Sep 2023 07:18:22 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::9f5d:8bed:7a5b:e75a%6]) with mapi id 15.20.6838.016; Thu, 28 Sep 2023 07:18:22 +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: 3579f611-5dcf-11ee-878a-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SSW9KEgqBO+SWH32jJ4Eccxs48NNvf1VhDfFCnezm2+Io+UmO4FOLuLDfCWT2jqm+NsQXZtd2XKIEnpzjaBdNqLw7jkmO3ah0ekzetrW9dGzGpcVEKp7rf/5YfoOGZK+/VQlgF6kKvPNV+onET44tt9Kp1qaOBrtRW/YWicmFErgNff7fr/U3lXgvabFu3YrjM0HiPP7LWoz8oIqKQ9TPwI5OYPOCFYTqhEVuT5VpZjrkVzawohPR1O1wnhrlwAHwzZbiNlMWhyUQFN2LVyIYZapFRCakwo6nTDdUpuloFn2Fmsx9bIyjoP1lO6YWeUycAo21fxQkA0Zyl/GNbionQ== 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=Q6heSYFw3PZWXqBzIsXffgtlNiPmiim8ZkFs/SFPCFs=; b=gysA0cNKlbKivDWhRxGfOYCmbiXbd/m4xj+b7KyKyZTS52XuT7uAKFtPRDX/elURjGqHFe2pIb8Fo7o6NRbTt5Q80BAg2inVhrhVR8TL9EVQuZOoCKYXaqUwJQdsPLNHbpKgfsMLUjk961dIO5F8aQcEUKucNDp2HuYsX0yvXerw/eVMfbTK4qidlhxu2ay83aL20NBAIpWSi2QJaeDHxbYO9kbPaDqq0ZGambpAClLP2g6Q02JWCw2MGgxWK27/00XJbEbcVvCrcC7gYn0TtlV6mve6Q0MtT6vz1RED8Jr77GvMUfffla50yEQPxSOQOqyZMP3kodD7SA2MFXDonA== 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=Q6heSYFw3PZWXqBzIsXffgtlNiPmiim8ZkFs/SFPCFs=; b=o5bf5PNj6onGkKiC+FYf2tLtKGhOBDmw2s+1wUKLA84o3VqJn1dl7k88xopnuMvHz/1RnmIK1mKuKqf95haRvKXp01FqWmMJL8Vefr1ZhH5SB7AwcyXSIFurCCpGTfI+nwqrI1I5i7cFj3WhBC2MGky1MRb4JDV59Q7vMxxQPBukFLlzajkKN12bwsN4eQbsrkxnN3Mg0HFddvyBYPVGW2xbdUchOoKZcODDxsxadUSv/NXx0fLnauGloJqv6PxO1hkCl22APngZY749olXqPXnDHyvmx3heORSwIB7wxu9bn5eWQpEFru82+5JERoxr7F+44QodB3wQdu8helaP2w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <3e8c1577-783b-ece2-3302-b1a85a2f53fb@suse.com> Date: Thu, 28 Sep 2023 09:18:19 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: [PATCH v4 9/9] common: convert vCPU info area registration 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?= , Henry Wang References: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> In-Reply-To: <3ba59868-101d-b68a-d8b7-767ee94910ec@suse.com> X-ClientProxiedBy: FR0P281CA0164.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b3::6) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AS8PR04MB8884:EE_ X-MS-Office365-Filtering-Correlation-Id: bfda5261-4595-48f0-0a90-08dbbff318e5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nDxN0hqlgVbkRULRYvsnh/lYwr16uuYUcxKyN4xFQ6pvfun8UJIu3a4UlEl3+lPxamp9xuzrX+AakXkZNoPyKrS4Lcdluy14P91eAzTZUfy9h1Hsl0NV+CxZUJvbQxDHuKmHzwT52sS/K/Xza4XThp0H3Mkmf0wwGYRbwJ28Mjj8YKwkJbCJg/Q5ZQcBny4RCpw2oe5VK9pHH/0HhyQUgMRFKqaCt3CtWbR6srX1i/m9+ucHqGe770RABRF74DYMI24N1U3Mlv7fWIdqG9mKa4H0qXIm35vZ7Va4hpQogze9Z93TnrFFW5m/5d7Pz/x4bvMHEm0cj0kV0yRrqDR0LHN0HqxzotmxfSNCh6b+MFszppGEC0R6puphoETws9jF0cWb4UyTB+Bwkke5ikzd0u1f05MOESYSiwe4hdHtTkW6dOdPXtKJ1lqrQsPzKu6zs104u3vLyAtYGzc8wIU7yn/TsqJ9Nx4fMILeD9sugHT9H6FIYm2k7JJe8K4oJENs9v+7vwDc+XzqNRtxXOjyM3p6cunLoQm8Ho8/ygFTTt+rAm7AfkM3geeS7gF6AyzYqP1aAKpQHDOYy9dqw+2JPKaviMcFaRoAt3YaucV9oy7W/ACP8zk6LzDt2+aDflrST3hwXCW/ULiINg2YD9z/nLlVmi3vYPSkVhi+vtz12Y1Jtro9UlEQVkW2dExBC946 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(346002)(376002)(396003)(136003)(230922051799003)(64100799003)(451199024)(186009)(1800799009)(2616005)(83380400001)(26005)(31686004)(478600001)(36756003)(6666004)(6512007)(6506007)(6486002)(66946007)(66476007)(316002)(66556008)(54906003)(6916009)(8676002)(41300700001)(8936002)(4326008)(86362001)(5660300002)(31696002)(38100700002)(2906002)(30864003)(45980500001)(43740500002)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?NxZNjC+x49DcgMEU0XFuR7cYXodU?= =?utf-8?q?C+UIG4hM7LATr5tFJXBiHqq2cx8cCaoDyHHLGEAI/PD/OzwKUxZGfNfU5zz2MyurL?= =?utf-8?q?wjJn6EFQb+if2GfidT6P/CZ4bsTCW8byhHQ1sVEVmUf9HdGK0mvqq/gzwDzVK2yGt?= =?utf-8?q?KS9lMovszAxgVP0GJ+GxvECa3SBP2QHcWEua3rVBiEynk7JqJquc7HkplhNTJ2vGe?= =?utf-8?q?G25IPPcZsc5yJEspWWf1+4ovPhisqBzQ2jfev4JYqgTK1j/mIiYMMl1or/6+2KwRB?= =?utf-8?q?cVcLMuCHzYM0lMBhQ90CXs/xZe/i41FIUFBP5DhySGkIohV6s5jJwtZmJdNfPETM6?= =?utf-8?q?WcW8iojP9tQT3wmNUkF64guOkLn3NSnmGhI3V5BOMy7iHXi/ITZbe4RjcfOobFyAV?= =?utf-8?q?QANdcFvVFX/h1ZBtYIEVfrPC1Y+sztuINgVjD+ZCaUqz4FNherZpe8tviDqQ4Cr0H?= =?utf-8?q?1XDHWL25Hxu4kZhJoqamiKvoaRxBoZqCxO7FefmwVMWghr6/10wgeSq/t0p+AfeiV?= =?utf-8?q?UwFrK/wvO/Qba+I6rQtsYdWMbgpzfOruFHDPVnhFgZ2ZywepPk7T2Bd79i2P5mLSy?= =?utf-8?q?AzxiOD2IgAfAdHrobexPtnsgDBG728g9RzYD2VZqfnBQ3s7zyTR3sS/khs/lMa2iI?= =?utf-8?q?k7uir0KxTRjSeHOQo/YCOjQePTzgheJsEdXkAa6YnUUXX6nOlaEL6Ol0NiimvcKxU?= =?utf-8?q?pPECrcxzPBzoH4Yc1kZOTLpYdz/yHQzDPPLJGNZNIKqH0ec+hUzht145oFQenqWHU?= =?utf-8?q?ppeBYJFwzyqDMgado4Ecx6agN1NgDycSMxH0aCcCfR1DXLqC2zsK8mfnOvc1Gikte?= =?utf-8?q?hvVyl65WuV57A8mD36HAmo7QLoJ2V/J3B6HZpuG57o5eigEJyjwiUUCoHtHnzBw6d?= =?utf-8?q?c/kOg76FpEWzGKHL7qU2+T2wBzhriQ27eUACXV79uCLu3IpywBl0Yox3JOLLvKz7B?= =?utf-8?q?3dEEuLNDR8nWOiJLKwR0ZFL+JQYL/ItO0VFXzXjZUplTINvzFeqeUGjfnXutq6FVs?= =?utf-8?q?F3sH+2vlB+WnOJTmoJ3/feE49XFtCiUeoKpVPijFjXB2DmapStSDksf85Rth7y26M?= =?utf-8?q?NdOJ6b4yXjY1H/wc8hfxAUB2PxGEdUjpwmGWaQyDJT5Ny7yClBCsWQnJIicMC+RPW?= =?utf-8?q?Uv8OFu4HK5UQL1i0FooXEjAbk662AzDDTI73IXxViIy/CWymOAvSELYUEFj1NZ3x6?= =?utf-8?q?XIaIkxHMTOVyzfdHKXpAmIdrOU0kPT36y3hu5eyn/ZfUeOLvv/7+JGIOI5Dv/3mES?= =?utf-8?q?LhQVW5+EdPe4O98fA0CrNoV6VJlK8FY7Hxx67dFlkXcsY3AQaOeVRVY9O2EGo2ibq?= =?utf-8?q?9dlr5cjgSS/tcp8YJ0xOuBt7FtuXOFyzqcnYqOOn32CriMb5mnH5qTJ44ewIF0JXF?= =?utf-8?q?TmLenrZezczi7IT7wCe4ARo1YAlV8+XMTPfm5U14/hEm3i8F7I/z0MpJ5jsi6Dmx2?= =?utf-8?q?kbgej1/dIKWC5OZH8L5hW+8TkqNYS8i2qMiwLim4nx5sbiRg7UWqMcrH/bV0RXIfn?= =?utf-8?q?FOXKeWPPiTKu?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: bfda5261-4595-48f0-0a90-08dbbff318e5 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 07:18:22.0098 (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: k0oxxg3k/dNKwDq0kzhsXNJF99TL+zfgCP4tLJDeQsm6mv1bfDASCdw8PWZol43DzwLGGZHBYq9f2KgZ5TDbkw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8884 Switch to using map_guest_area(). Noteworthy differences from map_vcpu_info(): - remote vCPU-s are paused rather than checked for being down (which in principle can change right after the check), - the domain lock is taken for a much smaller region, - the error code for an attempt to re-register the area is now -EBUSY, - we could in principle permit de-registration when no area was previously registered (which would permit "probing", if necessary for anything). Note that this eliminates a bug in copy_vcpu_settings(): The function did allocate a new page regardless of the GFN already having a mapping, thus in particular breaking the case of two vCPU-s having their info areas on the same page. Signed-off-by: Jan Beulich --- RFC: I'm not really certain whether the preliminary check (ahead of calling map_guest_area()) is worthwhile to have. --- v4: Re-base over changes earlier in the series. v2: Re-base over changes earlier in the series. Properly enforce no re- registration. Avoid several casts by introducing local variables. --- a/xen/arch/x86/include/asm/shared.h +++ b/xen/arch/x86/include/asm/shared.h @@ -26,17 +26,20 @@ static inline void arch_set_##field(stru #define GET_SET_VCPU(type, field) \ static inline type arch_get_##field(const struct vcpu *v) \ { \ + const vcpu_info_t *vi = v->vcpu_info_area.map; \ + \ return !has_32bit_shinfo(v->domain) ? \ - v->vcpu_info->native.arch.field : \ - v->vcpu_info->compat.arch.field; \ + vi->native.arch.field : vi->compat.arch.field; \ } \ static inline void arch_set_##field(struct vcpu *v, \ type val) \ { \ + vcpu_info_t *vi = v->vcpu_info_area.map; \ + \ if ( !has_32bit_shinfo(v->domain) ) \ - v->vcpu_info->native.arch.field = val; \ + vi->native.arch.field = val; \ else \ - v->vcpu_info->compat.arch.field = val; \ + vi->compat.arch.field = val; \ } #else @@ -57,12 +60,16 @@ static inline void arch_set_##field(stru #define GET_SET_VCPU(type, field) \ static inline type arch_get_##field(const struct vcpu *v) \ { \ - return v->vcpu_info->arch.field; \ + const vcpu_info_t *vi = v->vcpu_info_area.map; \ + \ + return vi->arch.field; \ } \ static inline void arch_set_##field(struct vcpu *v, \ type val) \ { \ - v->vcpu_info->arch.field = val; \ + vcpu_info_t *vi = v->vcpu_info_area.map; \ + \ + vi->arch.field = val; \ } #endif --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1749,53 +1749,24 @@ static int copy_vpmu(struct vcpu *d_vcpu static int copy_vcpu_settings(struct domain *cd, const struct domain *d) { unsigned int i; - struct p2m_domain *p2m = p2m_get_hostp2m(cd); int ret = -EINVAL; for ( i = 0; i < cd->max_vcpus; i++ ) { struct vcpu *d_vcpu = d->vcpu[i]; struct vcpu *cd_vcpu = cd->vcpu[i]; - mfn_t vcpu_info_mfn; if ( !d_vcpu || !cd_vcpu ) continue; - /* Copy & map in the vcpu_info page if the guest uses one */ - vcpu_info_mfn = d_vcpu->vcpu_info_mfn; - if ( !mfn_eq(vcpu_info_mfn, INVALID_MFN) ) - { - mfn_t new_vcpu_info_mfn = cd_vcpu->vcpu_info_mfn; - - /* Allocate & map the page for it if it hasn't been already */ - if ( mfn_eq(new_vcpu_info_mfn, INVALID_MFN) ) - { - gfn_t gfn = mfn_to_gfn(d, vcpu_info_mfn); - unsigned long gfn_l = gfn_x(gfn); - struct page_info *page; - - if ( !(page = alloc_domheap_page(cd, 0)) ) - return -ENOMEM; - - new_vcpu_info_mfn = page_to_mfn(page); - set_gpfn_from_mfn(mfn_x(new_vcpu_info_mfn), gfn_l); - - ret = p2m->set_entry(p2m, gfn, new_vcpu_info_mfn, - PAGE_ORDER_4K, p2m_ram_rw, - p2m->default_access, -1); - if ( ret ) - return ret; - - ret = map_vcpu_info(cd_vcpu, gfn_l, - PAGE_OFFSET(d_vcpu->vcpu_info)); - if ( ret ) - return ret; - } - - copy_domain_page(new_vcpu_info_mfn, vcpu_info_mfn); - } - - /* Same for the (physically registered) runstate and time info areas. */ + /* + * Copy and map the vcpu_info page and the (physically registered) + * runstate and time info areas. + */ + ret = copy_guest_area(&cd_vcpu->vcpu_info_area, + &d_vcpu->vcpu_info_area, cd_vcpu, d); + if ( ret ) + return ret; ret = copy_guest_area(&cd_vcpu->runstate_guest_area, &d_vcpu->runstate_guest_area, cd_vcpu, d); if ( ret ) --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -383,7 +383,7 @@ int pv_shim_shutdown(uint8_t reason) for_each_vcpu ( d, v ) { /* Unmap guest vcpu_info page and runstate/time areas. */ - unmap_vcpu_info(v); + unmap_guest_area(v, &v->vcpu_info_area); unmap_guest_area(v, &v->runstate_guest_area); unmap_guest_area(v, &v->arch.time_guest_area); --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1542,7 +1542,7 @@ static void __update_vcpu_system_time(st struct vcpu_time_info *u = &vcpu_info(v, time), _u; const struct domain *d = v->domain; - if ( v->vcpu_info == NULL ) + if ( !v->vcpu_info_area.map ) return; collect_time_info(v, &_u); --- a/xen/arch/x86/x86_64/asm-offsets.c +++ b/xen/arch/x86/x86_64/asm-offsets.c @@ -53,7 +53,7 @@ void __dummy__(void) OFFSET(VCPU_processor, struct vcpu, processor); OFFSET(VCPU_domain, struct vcpu, domain); - OFFSET(VCPU_vcpu_info, struct vcpu, vcpu_info); + OFFSET(VCPU_vcpu_info, struct vcpu, vcpu_info_area.map); OFFSET(VCPU_trap_bounce, struct vcpu, arch.pv.trap_bounce); OFFSET(VCPU_thread_flags, struct vcpu, arch.flags); OFFSET(VCPU_event_addr, struct vcpu, arch.pv.event_callback_eip); --- a/xen/arch/x86/x86_64/traps.c +++ b/xen/arch/x86/x86_64/traps.c @@ -96,7 +96,7 @@ static void _show_registers( if ( context == CTXT_hypervisor ) printk(" %pS", _p(regs->rip)); printk("\nRFLAGS: %016lx ", regs->rflags); - if ( (context == CTXT_pv_guest) && v && v->vcpu_info ) + if ( (context == CTXT_pv_guest) && v && v->vcpu_info_area.map ) printk("EM: %d ", !!vcpu_info(v, evtchn_upcall_mask)); printk("CONTEXT: %s", context_names[context]); if ( v && !is_idle_vcpu(v) ) --- a/xen/common/compat/domain.c +++ b/xen/common/compat/domain.c @@ -49,7 +49,7 @@ int compat_common_vcpu_op(int cmd, struc { case VCPUOP_initialise: { - if ( v->vcpu_info == &dummy_vcpu_info ) + if ( v->vcpu_info_area.map == &dummy_vcpu_info ) return -EINVAL; #ifdef CONFIG_HVM --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -127,10 +127,10 @@ static void vcpu_info_reset(struct vcpu { struct domain *d = v->domain; - v->vcpu_info = ((v->vcpu_id < XEN_LEGACY_MAX_VCPUS) - ? (vcpu_info_t *)&shared_info(d, vcpu_info[v->vcpu_id]) - : &dummy_vcpu_info); - v->vcpu_info_mfn = INVALID_MFN; + v->vcpu_info_area.map = + ((v->vcpu_id < XEN_LEGACY_MAX_VCPUS) + ? (vcpu_info_t *)&shared_info(d, vcpu_info[v->vcpu_id]) + : &dummy_vcpu_info); } static void vmtrace_free_buffer(struct vcpu *v) @@ -993,7 +993,7 @@ int domain_kill(struct domain *d) return -ERESTART; for_each_vcpu ( d, v ) { - unmap_vcpu_info(v); + unmap_guest_area(v, &v->vcpu_info_area); unmap_guest_area(v, &v->runstate_guest_area); } d->is_dying = DOMDYING_dead; @@ -1448,7 +1448,7 @@ int domain_soft_reset(struct domain *d, for_each_vcpu ( d, v ) { set_xen_guest_handle(runstate_guest(v), NULL); - unmap_vcpu_info(v); + unmap_guest_area(v, &v->vcpu_info_area); unmap_guest_area(v, &v->runstate_guest_area); } @@ -1496,111 +1496,6 @@ int vcpu_reset(struct vcpu *v) return rc; } -/* - * Map a guest page in and point the vcpu_info pointer at it. This - * makes sure that the vcpu_info is always pointing at a valid piece - * of memory, and it sets a pending event to make sure that a pending - * event doesn't get missed. - */ -int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned int offset) -{ - struct domain *d = v->domain; - void *mapping; - vcpu_info_t *new_info; - struct page_info *page; - unsigned int align; - - if ( offset > (PAGE_SIZE - sizeof(*new_info)) ) - return -ENXIO; - -#ifdef CONFIG_COMPAT - BUILD_BUG_ON(sizeof(*new_info) != sizeof(new_info->compat)); - if ( has_32bit_shinfo(d) ) - align = alignof(new_info->compat); - else -#endif - align = alignof(*new_info); - if ( offset & (align - 1) ) - return -ENXIO; - - if ( !mfn_eq(v->vcpu_info_mfn, INVALID_MFN) ) - return -EINVAL; - - /* Run this command on yourself or on other offline VCPUS. */ - if ( (v != current) && !(v->pause_flags & VPF_down) ) - return -EINVAL; - - page = get_page_from_gfn(d, gfn, NULL, P2M_UNSHARE); - if ( !page ) - return -EINVAL; - - if ( !get_page_type(page, PGT_writable_page) ) - { - put_page(page); - return -EINVAL; - } - - mapping = __map_domain_page_global(page); - if ( mapping == NULL ) - { - put_page_and_type(page); - return -ENOMEM; - } - - new_info = (vcpu_info_t *)(mapping + offset); - - if ( v->vcpu_info == &dummy_vcpu_info ) - { - memset(new_info, 0, sizeof(*new_info)); -#ifdef XEN_HAVE_PV_UPCALL_MASK - __vcpu_info(v, new_info, evtchn_upcall_mask) = 1; -#endif - } - else - { - memcpy(new_info, v->vcpu_info, sizeof(*new_info)); - } - - v->vcpu_info = new_info; - v->vcpu_info_mfn = page_to_mfn(page); - - /* Set new vcpu_info pointer /before/ setting pending flags. */ - smp_wmb(); - - /* - * Mark everything as being pending just to make sure nothing gets - * lost. The domain will get a spurious event, but it can cope. - */ -#ifdef CONFIG_COMPAT - if ( !has_32bit_shinfo(d) ) - write_atomic(&new_info->native.evtchn_pending_sel, ~0); - else -#endif - write_atomic(&vcpu_info(v, evtchn_pending_sel), ~0); - vcpu_mark_events_pending(v); - - return 0; -} - -/* - * Unmap the vcpu info page if the guest decided to place it somewhere - * else. This is used from domain_kill() and domain_soft_reset(). - */ -void unmap_vcpu_info(struct vcpu *v) -{ - mfn_t mfn = v->vcpu_info_mfn; - - if ( mfn_eq(mfn, INVALID_MFN) ) - return; - - unmap_domain_page_global((void *) - ((unsigned long)v->vcpu_info & PAGE_MASK)); - - vcpu_info_reset(v); /* NB: Clobbers v->vcpu_info_mfn */ - - put_page_and_type(mfn_to_page(mfn)); -} - int map_guest_area(struct vcpu *v, paddr_t gaddr, unsigned int size, struct guest_area *area, void (*populate)(void *dst, struct vcpu *v)) @@ -1662,14 +1557,44 @@ int map_guest_area(struct vcpu *v, paddr domain_lock(d); - if ( map && populate ) - populate(map, v); + /* No re-registration of the vCPU info area. */ + if ( area != &v->vcpu_info_area || !area->pg ) + { + if ( map && populate ) + populate(map, v); - SWAP(area->pg, pg); - SWAP(area->map, map); + SWAP(area->pg, pg); + SWAP(area->map, map); + } + else + rc = -EBUSY; domain_unlock(d); + /* Set pending flags /after/ new vcpu_info pointer was set. */ + if ( area == &v->vcpu_info_area && !rc ) + { + /* + * Mark everything as being pending just to make sure nothing gets + * lost. The domain will get a spurious event, but it can cope. + */ +#ifdef CONFIG_COMPAT + if ( !has_32bit_shinfo(d) ) + { + vcpu_info_t *info = area->map; + + /* For VCPUOP_register_vcpu_info handling in common_vcpu_op(). */ + BUILD_BUG_ON(sizeof(*info) != sizeof(info->compat)); + write_atomic(&info->native.evtchn_pending_sel, ~0); + } + else +#endif + write_atomic(&vcpu_info(v, evtchn_pending_sel), ~0); + vcpu_mark_events_pending(v); + + force_update_vcpu_system_time(v); + } + if ( v != current ) vcpu_unpause(v); @@ -1699,7 +1624,10 @@ void unmap_guest_area(struct vcpu *v, st domain_lock(d); map = area->map; - area->map = NULL; + if ( area == &v->vcpu_info_area ) + vcpu_info_reset(v); + else + area->map = NULL; pg = area->pg; area->pg = NULL; domain_unlock(d); @@ -1830,6 +1758,27 @@ bool update_runstate_area(struct vcpu *v return rc; } +/* + * This makes sure that the vcpu_info is always pointing at a valid piece of + * memory, and it sets a pending event to make sure that a pending event + * doesn't get missed. + */ +static void cf_check +vcpu_info_populate(void *map, struct vcpu *v) +{ + vcpu_info_t *info = map; + + if ( v->vcpu_info_area.map == &dummy_vcpu_info ) + { + memset(info, 0, sizeof(*info)); +#ifdef XEN_HAVE_PV_UPCALL_MASK + __vcpu_info(v, info, evtchn_upcall_mask) = 1; +#endif + } + else + memcpy(info, v->vcpu_info_area.map, sizeof(*info)); +} + static void cf_check runstate_area_populate(void *map, struct vcpu *v) { @@ -1859,7 +1808,7 @@ long common_vcpu_op(int cmd, struct vcpu switch ( cmd ) { case VCPUOP_initialise: - if ( v->vcpu_info == &dummy_vcpu_info ) + if ( v->vcpu_info_area.map == &dummy_vcpu_info ) return -EINVAL; rc = arch_initialise_vcpu(v, arg); @@ -1990,16 +1939,29 @@ long common_vcpu_op(int cmd, struct vcpu case VCPUOP_register_vcpu_info: { struct vcpu_register_vcpu_info info; + paddr_t gaddr; rc = -EFAULT; if ( copy_from_guest(&info, arg, 1) ) break; - domain_lock(d); - rc = map_vcpu_info(v, info.mfn, info.offset); - domain_unlock(d); + rc = -EINVAL; + gaddr = gfn_to_gaddr(_gfn(info.mfn)) + info.offset; + if ( !~gaddr || + gfn_x(gaddr_to_gfn(gaddr)) != info.mfn ) + break; - force_update_vcpu_system_time(v); + /* Preliminary check only; see map_guest_area(). */ + rc = -EBUSY; + if ( v->vcpu_info_area.pg ) + break; + + /* See the BUILD_BUG_ON() in vcpu_info_populate(). */ + rc = map_guest_area(v, gaddr, sizeof(vcpu_info_t), + &v->vcpu_info_area, vcpu_info_populate); + if ( rc == -ERESTART ) + rc = hypercall_create_continuation(__HYPERVISOR_vcpu_op, "iih", + cmd, vcpuid, arg); break; } --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -80,9 +80,6 @@ void cf_check free_pirq_struct(void *); int arch_vcpu_create(struct vcpu *v); void arch_vcpu_destroy(struct vcpu *v); -int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned int offset); -void unmap_vcpu_info(struct vcpu *v); - int map_guest_area(struct vcpu *v, paddr_t gaddr, unsigned int size, struct guest_area *area, void (*populate)(void *dst, struct vcpu *v)); --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -176,7 +176,7 @@ struct vcpu int processor; - vcpu_info_t *vcpu_info; + struct guest_area vcpu_info_area; struct domain *domain; @@ -289,9 +289,6 @@ struct vcpu struct waitqueue_vcpu *waitqueue_vcpu; - /* Guest-specified relocation of vcpu_info. */ - mfn_t vcpu_info_mfn; - struct evtchn_fifo_vcpu *evtchn_fifo; /* vPCI per-vCPU area, used to store data for long running operations. */ --- a/xen/include/xen/shared.h +++ b/xen/include/xen/shared.h @@ -44,6 +44,7 @@ typedef struct vcpu_info vcpu_info_t; extern vcpu_info_t dummy_vcpu_info; #define shared_info(d, field) __shared_info(d, (d)->shared_info, field) -#define vcpu_info(v, field) __vcpu_info(v, (v)->vcpu_info, field) +#define vcpu_info(v, field) \ + __vcpu_info(v, (vcpu_info_t *)(v)->vcpu_info_area.map, field) #endif /* __XEN_SHARED_H__ */