From patchwork Mon Jan 23 14:55:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13112323 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 72FC1C38142 for ; Mon, 23 Jan 2023 14:55:31 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.482963.748793 (Exim 4.92) (envelope-from ) id 1pJyEG-0006Cd-LD; Mon, 23 Jan 2023 14:55:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 482963.748793; Mon, 23 Jan 2023 14:55:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJyEG-0006CW-Gu; Mon, 23 Jan 2023 14:55:24 +0000 Received: by outflank-mailman (input) for mailman id 482963; Mon, 23 Jan 2023 14:55:23 +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 1pJyEF-0005Sn-GU for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 14:55:23 +0000 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2044.outbound.protection.outlook.com [40.107.104.44]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f5853384-9b2d-11ed-b8d1-410ff93cb8f0; Mon, 23 Jan 2023 15:55:21 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AM9PR04MB8422.eurprd04.prod.outlook.com (2603:10a6:20b:3ea::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Mon, 23 Jan 2023 14:55:19 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.033; Mon, 23 Jan 2023 14:55:19 +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: f5853384-9b2d-11ed-b8d1-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lzHcLqMRkQoh1rloIw5lkw+1b3GwJaGQIPTIRT/XdgjGkHIGrvL+MiflvntiSSdSi1r2LVB7vHxRGmpCHzdhb294dm+jTgrkp05uOlOwD9OOWB5QLhRiCpX/6CGyyKlDENGVpHzbOdPR/ZCcYyi2XRfAQa2fwPdMiTBbPj0i0+yj4gfnwajQg18O+YjifnP9STrSR/aCubNjP0U23hx0/cqTah4fyiPsc56D1TcxJLC1gG71apwfdquutn3Pl2Xz11E7+A4/poAz8xsIb/w+a92b6kCYkKeh6p7BQeBzjQi2lJiIljrdu5CyZG7sO259JrAj6EsTQ2bOQ758Ln/akw== 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=XBd5rNRYBMnhzTJl9KZ9diTDyGeUkSl/k2wQJ+HyU7U=; b=JYLTn6/+r0RcRmXyskZbbCi+kEtdkN814whmGZUo6b6uMCBmgwevG9IynJhBXf7XPWzZRZvO8k7vuZfqJ49342oMHqLhf7TMXHTultorxfhJwHuRwZpzQmEZLlMc9xQY2L/l90in+bOEDGX3By74oB+yyw6Z1DjuMymS57BSKQi4rUUCvIFcuFBg3maqgm7lVCxfG222sWvaANiFz6mBOEpNxw6oNQREEq7KQejRoVuMMKucSR5bxVYjPxl32JZtzSZ1ANho2fZlhXMQDd4gBBGZ0S3mkRwcSz4b8snDBCMrnDRCGdQUTDxNL8q1BKG8MEgxwWr6++SpSWl6IvPO3Q== 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=XBd5rNRYBMnhzTJl9KZ9diTDyGeUkSl/k2wQJ+HyU7U=; b=jqQ6wd3VAEQhcCF8TG7Q7xxoLFkk9OMsoeDsKZYSXUB8R2j+TLL6OoP5fB855FmpRIidbDmeDUK/1pVCrHthPWLBYboRehk8sV1zx7rg9ipmubwr+erEiNaeLcCYzBLKKTECS50+kwmww0KvZLlvH2GulSC+3IEgszmYNt3Fk62rdeRInBUqHeMx3bmJDLuELcqnkM7KtIAIIax+yL8fElwUYXq4b+wbc9ISHITi9164EuSWXDPgOiThPDyr40fOrBPi/hPU+C5qIJM3rfy6Pw54aWi+MdcfK4lb8JSDpBqmDCWSjf7uYThDqYPJJr+1+jMbtGBi5Mhq3I9rNWTMFg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Mon, 23 Jan 2023 15:55:18 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 4/8] 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?= , Tamas K Lengyel References: <33cd2aba-73fc-6dfe-d0f2-f41883e7cdfa@suse.com> In-Reply-To: <33cd2aba-73fc-6dfe-d0f2-f41883e7cdfa@suse.com> X-ClientProxiedBy: FR2P281CA0106.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9c::18) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AM9PR04MB8422:EE_ X-MS-Office365-Filtering-Correlation-Id: fb2ebd09-5ba0-4ff8-393f-08dafd51d87e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: elneRqC9nPRAGLqIAnJ8y8dJWE78p4dW+sY5KOdnUO3C+D9MHr0ZM58Ve/d1uvjNXyBrKplbFCTDfhvG6NwGmk3BVfGRGQ8LfEVz71SUgT1ydUQvbOlAz6Mi+Isw7PDsmKAfYD1yd5kcQzUFjZYe7Gp+I+lbVYgZri1sAYtkjcpJO5+N0WXzJrN/q8Bz1UVO7WpEHUfV/Bk9wpI63e7YebtTp4To1j4WzyzS4F5cxHiY3qnivdbcJJs9WLoMK4NxzkfI5STtb6Zbqyzi9rPGF0FTN8/TafWOiF6aF1mhOgMuPHlKTwSIdje24QnmovVGDSQFZJWhuInuNhBLdYMyElOrugnZDNfes4eGQRZGEEajoXxU6v95NGEQoetWenD9DebwtLY1082JFRnZTjg53penF/MocJ1+V6zaHVGcz0qArGutfjPN1s0GFLc9BljzXoF0GXvnecY1hO0vH/p2n11p5Ho4r3SzPMOqiEuXsHzSXhc2Atq1hb6PVr7X+bVU7CLrrXUsTndYfon6sn3JSSzVGU8m/5CqFgXYQcQm2MH/hTTP4DVrCzATD4+i7H3IqRcyl1jst2zNIpNTwULOo8K7Wt04Zpm/7nnsp+4jS5yB77sd2xi0c2pNn2c4Qvg9tBXXe+x590iSWkUFAwDRQnnQ6Th5Nia2JNqqVeREhSbrkxOeKeSlhrQ/TWGfugbsv/5wPGm3/pRxCDuimXLqs0L4nlc2R/BTLI9Uz3y1m9c= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(376002)(396003)(136003)(39850400004)(366004)(346002)(451199015)(31686004)(2616005)(38100700002)(31696002)(41300700001)(2906002)(8936002)(5660300002)(4326008)(8676002)(6916009)(6506007)(316002)(54906003)(36756003)(83380400001)(66556008)(66476007)(66946007)(86362001)(478600001)(6486002)(26005)(186003)(6512007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?oDGkqxGAB82yk01E1GCkkLzBLGy3?= =?utf-8?q?WCBVTbd3jnW9NYjsTIg+j86sDyHupkugrwNAkraAXzKN4nD/NlBf9oQWarQ1H8JYl?= =?utf-8?q?bDOWT8CddYXAaR+N6oOczOEOKizONEllK8Q1J2jJxUrCx9pUuGnP2dCdL9jFCE5nm?= =?utf-8?q?53Vjy2iJm8LvF1nT0Ck29cd0YK6IXn2YGA3r6lhC8nqg+Vsfmi5CwkTF30EImDQ0X?= =?utf-8?q?Ht8MctwlSP3+TzmxCY/QSSlbug1Gi1Z+y66r/sN1tN9MSHlfkQyy/CYyQbmZvQnL3?= =?utf-8?q?uB0/7PKv7kyz0gb14iAeePK/upxVEQwdUoc3pdacMEWatuSEjw70tVco8GCXZOmus?= =?utf-8?q?MRVV3I0G/76UMBBpNlctbZMMy0YXuGARJlAk38QSUQhhraLEy9hFsN3vM1U6wuQab?= =?utf-8?q?qrbRmFiiXhB/Qi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9kw7rPhaXTaoQpBfyW4kHAdiLx64srzXiCT9IIzl9P?= =?utf-8?q?Fw9jVKWifGdn8iBqHEP517b2VPXPKYlOfHgptMKXkqTGdKYJWu+hBOlqh/ckq6XIx?= =?utf-8?q?4jt9bGBD/QcO2+VbwWvT+KNGJyFo3kfnycfh0poC6vhTb1uU2eXcT3Eb4nTGXZSG9?= =?utf-8?q?e6Hnsi+I8yMQn5mthUpzAEv0rtogzeRHdRABLvm8dGO76FPxVZnNey5cHqTR99atv?= =?utf-8?q?et/RuZCXciUZ?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb2ebd09-5ba0-4ff8-393f-08dafd51d87e X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jan 2023 14:55:19.5175 (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: EcYAo8zWFAtzPK/kfagqhfAV5xwaJ2vrFjqwf6G6/qTJQIZA0S2bAjEq+GTsCqEXLCb9OeCwRugM8O9kAG3ncA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8422 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 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1653,6 +1653,65 @@ 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; + + /* + * Simply specify the entire range up to the end of the page. All the + * function uses it for is a check for not crossing page boundaries. + */ + 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); @@ -1745,6 +1804,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; @@ -1987,7 +2056,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 @@ -1572,6 +1572,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