From patchwork Fri Mar 11 06:11:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777483 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 A1E77C433FE for ; Fri, 11 Mar 2022 06:13:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288720.489746 (Exim 4.92) (envelope-from ) id 1nSYWE-0002SY-DD; Fri, 11 Mar 2022 06:12:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288720.489746; Fri, 11 Mar 2022 06:12:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYWE-0002Qy-10; Fri, 11 Mar 2022 06:12:54 +0000 Received: by outflank-mailman (input) for mailman id 288720; Fri, 11 Mar 2022 06:12:52 +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 1nSYWC-0008Q3-Kk for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:52 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-he1eur02on062e.outbound.protection.outlook.com [2a01:111:f400:fe05::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 47ad5f6c-a102-11ec-853a-5f4723681683; Fri, 11 Mar 2022 07:12:51 +0100 (CET) Received: from AS9PR06CA0215.eurprd06.prod.outlook.com (2603:10a6:20b:45e::22) by AM8PR08MB6339.eurprd08.prod.outlook.com (2603:10a6:20b:317::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Fri, 11 Mar 2022 06:12:24 +0000 Received: from AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45e:cafe::87) by AS9PR06CA0215.outlook.office365.com (2603:10a6:20b:45e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Fri, 11 Mar 2022 06:12:24 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT007.mail.protection.outlook.com (10.152.16.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:23 +0000 Received: ("Tessian outbound 741ca6c82739:v113"); Fri, 11 Mar 2022 06:12:23 +0000 Received: from ae69decf3fdd.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C2D83D3B-8822-4D16-9F53-9D9A93EEF755.1; Fri, 11 Mar 2022 06:12:17 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ae69decf3fdd.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:17 +0000 Received: from AS8PR04CA0001.eurprd04.prod.outlook.com (2603:10a6:20b:310::6) by VI1PR0802MB2207.eurprd08.prod.outlook.com (2603:10a6:800:9c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.20; Fri, 11 Mar 2022 06:12:14 +0000 Received: from AM5EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:310:cafe::a4) by AS8PR04CA0001.outlook.office365.com (2603:10a6:20b:310::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Fri, 11 Mar 2022 06:12:13 +0000 Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT044.mail.protection.outlook.com (10.152.17.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:13 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:12 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:10 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 47ad5f6c-a102-11ec-853a-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bU8NQceo5M7S7uNB+SFlZP2PMMWPBqpC6eRiMideGyc=; b=DoqDXPA0eJHypZxGSfKZbJTh+MXH310v6E6lz3ap1acAK2fCW8VbITDEJmARSzk8HS7RDu894g/dZwZd+AS0Nf8Q/P4cddpjbqfiED1bY2X7RO/6rkWwfwaCWfIg760mhaKW+DV0lYR55t6Qi1DaK/ByC01f1YitzfZXuNcq3ic= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 9d83c625b8f15de6 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O9pdQ7chCVD8BMA8INgpDupFWsWqQNUfq7QUWufHDz+QR8LCsnaF/yU2E2ZlbCeh4FpLdHopebq9VQ/TO/H5Q8iN9ztFzCWUpFxTH+oZR8PdZt7pNBYb5k8/XzBjCLiEuubKpv5Fe7p1xJdP1aeqazzpq2qcq7EpQULst9FlJoztnaFQ/0up+isbsmGek917Rw5dDDHqGpnulTdXou+okWAAR0UaUHYCeajXuk47nvL3pUb3IfqQ5RMuacK1aCEtt+upj3/Nr3hFap1ouKY/PnZO3WycdOc7LLV8JFFnw4cV4TGnUrX/2PQKGhBWIZ5KrOJC0OAJKy/xzaV5FF1vrw== 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=bU8NQceo5M7S7uNB+SFlZP2PMMWPBqpC6eRiMideGyc=; b=VHh9/W1KYNP0zTrtMoSHnaKiBAV0yrrjDuVTviVfYjJIIdUxAN8xhOCIMulGSvGUO7L/jYKS0p92HCBvKvqrJ72Wole4B1Wa1rH/wncnHa03USP8zqjLJWMhTtJbFBw7g8aV67Z53ZX0mtpfDiJATT69aMD2oK+s1hFaIy/oRWb3VmjKghJelJOvYRcTijiSm2HCJN5RnOsvY/lam1yBI8SYIBrbansTsALgIMFqx/aiYvLgTzQCuPlI2xmeo+f5PmkfZyNI6tKzQHYsW20GoxYYyPgVkIcSgTze4IwyWQGTV6r8EQZkTpbUoM6MpLIBfJQ7vgQig9OiIYiTs90c1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bU8NQceo5M7S7uNB+SFlZP2PMMWPBqpC6eRiMideGyc=; b=DoqDXPA0eJHypZxGSfKZbJTh+MXH310v6E6lz3ap1acAK2fCW8VbITDEJmARSzk8HS7RDu894g/dZwZd+AS0Nf8Q/P4cddpjbqfiED1bY2X7RO/6rkWwfwaCWfIg760mhaKW+DV0lYR55t6Qi1DaK/ByC01f1YitzfZXuNcq3ic= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 01/13] xen/arm: introduce static shared memory Date: Fri, 11 Mar 2022 14:11:11 +0800 Message-ID: <20220311061123.1883189-2-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 070ca016-3acc-4d1f-c401-08da03261bff X-MS-TrafficTypeDiagnostic: VI1PR0802MB2207:EE_|AM5EUR03FT007:EE_|AM8PR08MB6339:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: TOwcCHJ+mhaf8ew7f+NJbY3YrymNNZXPh5I+RUnSGsWEGLDpS0/g4+a/pBbHozyX+CulP8PShD3oSFQEMuYYC+zwgJN9+ZGuiu4FDP70efirkgSaRn8fjFinwFZFB3I81falTKZ+CYFASmHiW0WElVMXzQk0/Tjf5CrJQ5r+U5OvhywppuXnO/TZNNFHvF93Blu7/lmUKoC0adL9CM7E/fXQApiFcGKhQ64nAo79tmTc2jh7Oc8yFMDQtYGcc/Q3hAyPRaNEaltwhTyx4ZICCRhB8dakTTOAI2htLF4Ux4/Y0gymqAU7ppMGdaoAbHdP/m4S2Xmr3a5Mo7CKuwh/H3eBF+2SPWb0nJPZDyFpxUv9BuSWkYSmvK1o832vEEE79yov/snWKg3CfeF3s2fls3hKV5tNNd8rIeeCQu0sCDZUsQcGni4REQcpkqYLg58fjrufupoE7SE91ng2StbEi5+B6rhNkVdg7bv4nJ1lOdMxBjdeHiUwOFr0PfFctjiUCWnBF+7J+O+9fPd4FOJMm7Nf2kt5LpZvv/NaeR/9nTtunWcrLUKNgvTFjpOQSlyei8mZd6zsOcISxn7tQNAZrQ2GIffBbY3oK1kR4AGMiFy9EB8MpZr9NsZlfKFEGFcDXwPgdOxvhFOWlQe819dMucxFTvajQw0sAwQfyLwaMRZ3OgxUCVP1Za85JOCVC1G4IDXhnORUSC3/60BLtbxWsg== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(83380400001)(186003)(26005)(316002)(8936002)(81166007)(54906003)(336012)(36860700001)(7696005)(356005)(47076005)(40460700003)(82310400004)(426003)(70206006)(4326008)(2906002)(70586007)(86362001)(5660300002)(36756003)(1076003)(2616005)(508600001)(6916009)(8676002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2207 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 167916f2-5630-48c5-bfbc-08da032615c8 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MnPzKIL2dyU5GwQ5gnZLVSPcsOGgnpCxgieXKOhWLCqlBoJwHnJmnayiLvIwSMg5mure9Ju/NB+gi1dnWeOYApFHNqH2yw2B5CCAI9FvMxNoNxv9u2+EYmSU0B26P308eY2Qyt2HdhV50sUKMLmzMDNBeikDSPHNaAuiEn7ATiZAHp/aORV4aw4PW1FZj++sqnh5dEoWQCUgJfFHrtR9OyQP8ORo+r5oLUXjsA4V2wyCIRCYHNQA5manwXz7/AjimGiMD0j2wS3Va80jqMQIgiOJ4TT0eTSQ1vPL1Wa62RcqkmtM/Gt/dxLMjR2ClstDKS3JLBC6eNNjMRU76adSophwamu6UA6wKdRQjebdEGtCMYBzwk7FjT4AGom75n0NEXYCw9P9fEsqgyhU4QO53fvrs+JyG6MdLsfYlXIyAMzkWXeYsDd/z0OLCY3zfWZPWkRWAiociF1PD03MwjW+VtKqexJgIrl+/Ihu3QVRXnn/2YABCgK9JL5CuEmfBiddpNpBSadgBqo4/EzQvzFckDalMpJpcK4i00Bh2TZFskI7aKiRvW1BwVOPpWWDiuOkepDoo0ZaTyc+WeH3wlcxIwcefUPjhCfJPlW3QXpyJWhjMJMHXRG43nm56KfzBpgmdZHq7pVBjgmLbZmh+OU1wHjbSdgcDrJknViOavz8nb9H6x+II3sU4TAkfIN6gaLB X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(47076005)(83380400001)(508600001)(54906003)(5660300002)(82310400004)(8936002)(7696005)(70206006)(36860700001)(2906002)(107886003)(426003)(70586007)(1076003)(8676002)(4326008)(2616005)(336012)(26005)(186003)(86362001)(36756003)(40460700003)(316002)(6916009)(81166007);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:23.8796 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 070ca016-3acc-4d1f-c401-08da03261bff X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6339 From: Penny Zheng This patch serie introduces a new feature: setting up static shared memory on a dom0less system, through device tree configuration. This commit parses shared memory node at boot-time, and reserve it in bootinfo.reserved_mem to avoid other use. Signed-off-by: Penny Zheng --- docs/misc/arm/device-tree/booting.txt | 118 ++++++++++++++++++++++++++ xen/arch/arm/bootfdt.c | 52 ++++++++++++ 2 files changed, 170 insertions(+) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-tree/booting.txt index a94125394e..f702ade817 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -355,3 +355,121 @@ device-tree: This will reserve a 512MB region starting at the host physical address 0x30000000 to be exclusively used by DomU1. + +Static Shared Memory +============= + +The static shared memory device tree nodes allow users to statically set up +shared memory on dom0less system, enabling domains to do shm-based +communication. + +- compatible + + "xen,domain-shared-memory-v1" + +- xen,shm-id + + An u8 value represents the unique identifier of the shared memory region. + The maximum identifier shall be "xen,shm-id = <0xff>". + +- xen,shared-mem + + An array takes a physical address, which is the base address of the + shared memory region in host physical address space, a size, and a guest + physical address, as the target address of the mapping. + +- role (Optional) + + A string property specifying the ownership of a shared memory region, + the value must be one of the following: "owner", or "borrower" + A shared memory region could be explicitly backed by one domain, which is + called "owner domain", and all the other domains who are also sharing + this region are called "borrower domain". + If not specified, the default value is "borrower" and owner is + "dom_shared", a system domain. + +As an example: + +chosen { + #address-cells = <0x1>; + #size-cells = <0x1>; + xen,xen-bootargs = "console=dtuart dtuart=serial0 bootscrub=0"; + + ...... + + /* this is for Dom0 */ + dom0-shared-mem@10000000 { + compatible = "xen,domain-shared-memory-v1"; + role = "owner"; + xen,shm-id = <0x0>; + xen,shared-mem = <0x10000000 0x10000000 0x10000000>; + } + + domU1 { + compatible = "xen,domain"; + #address-cells = <0x1>; + #size-cells = <0x1>; + memory = <0 131072>; + cpus = <2>; + vpl011; + + /* + * shared memory region identified as 0x0(xen,shm-id = <0x0>) + * is shared between Dom0 and DomU1. + */ + domU1-shared-mem@10000000 { + compatible = "xen,domain-shared-memory-v1"; + role = "borrower"; + xen,shm-id = <0x0>; + xen,shared-mem = <0x10000000 0x10000000 0x50000000>; + } + + /* + * shared memory region identified as 0x1(xen,shm-id = <0x1>) + * is shared between DomU1 and DomU2. + */ + domU1-shared-mem@50000000 { + compatible = "xen,domain-shared-memory-v1"; + xen,shm-id = <0x1>; + xen,shared-mem = <0x50000000 0x20000000 0x60000000>; + } + + ...... + + }; + + domU2 { + compatible = "xen,domain"; + #address-cells = <0x1>; + #size-cells = <0x1>; + memory = <0 65536>; + cpus = <1>; + + /* + * shared memory region identified as 0x1(xen,shm-id = <0x1>) + * is shared between domU1 and domU2. + */ + domU2-shared-mem@50000000 { + compatible = "xen,domain-shared-memory-v1"; + xen,shm-id = <0x1>; + xen,shared-mem = <0x50000000 0x20000000 0x70000000>; + } + + ...... + }; +}; + +This is an example with two static shared memory regions. + +For the static shared memory region identified as 0x0, host physical +address starting at 0x10000000 of 256MB will be reserved to be shared between +Dom0 and DomU1.It will get mapped at 0x10000000 in Dom0 guest physical address +space, and at 0x50000000 in DomU1 guest physical address space. Dom0 is +explicitly defined as the owner domain, and DomU1 is the borrower domain. + +For the static shared memory region identified as 0x1, host physical +address starting at 0x50000000 of 512MB will be reserved to be shared between +DomU1 and DomU2. It will get mapped at 0x60000000 in DomU1 guest physical +address space, and at 0x70000000 in DomU2 guest physical address space. DomU1 +and DomU2 are both the borrower domain, the owner domain is the default owner +domain dom_shared. diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index afaa0e249b..7de0f8cea9 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -363,6 +363,56 @@ static int __init process_domain_node(const void *fdt, int node, size_cells, &bootinfo.reserved_mem, true); } +static __initdata DECLARE_BITMAP(shm_mask, NR_MEM_BANKS); +static int __init process_shm_node(const void *fdt, int node, + u32 address_cells, u32 size_cells) +{ + const struct fdt_property *prop; + const __be32 *cell; + paddr_t paddr, size; + struct meminfo *mem = &bootinfo.reserved_mem; + u32 id; + + if ( address_cells < 1 || size_cells < 1 ) + { + printk("fdt: invalid #address-cells or #size-cells for static shared memory node.\n"); + return -EINVAL; + } + + prop = fdt_get_property(fdt, node, "xen,shared-mem", NULL); + if ( !prop ) + return -ENOENT; + + id = device_tree_get_u32(fdt, node, "xen,shm-id", NR_MEM_BANKS); + if ( id >= NR_MEM_BANKS ) + return -EINVAL; + + /* + * A shared memory region could be shared between multiple domains. We + * use the shm_mask bitmask to prevent iterating over all reserved memory + * regions each time. + */ + if ( !test_bit(id, shm_mask) ) + { + /* + * xen,shared-mem = ; + * Memory region starting from physical address #paddr of #size shall + * be mapped to guest physical address #gaddr as shared memory region. + */ + cell = (const __be32 *)prop->data; + device_tree_get_reg(&cell, address_cells, size_cells, &paddr, &size); + + /* shared memory shall be reserved from other use. */ + mem->bank[mem->nr_banks].start = paddr; + mem->bank[mem->nr_banks].size = size; + mem->bank[mem->nr_banks].xen_domain = true; + mem->nr_banks++; + set_bit(id, shm_mask); + } + + return 0; +} + static int __init early_scan_node(const void *fdt, int node, const char *name, int depth, u32 address_cells, u32 size_cells, @@ -383,6 +433,8 @@ static int __init early_scan_node(const void *fdt, process_chosen_node(fdt, node, name, address_cells, size_cells); else if ( depth == 2 && device_tree_node_compatible(fdt, node, "xen,domain") ) rc = process_domain_node(fdt, node, name, address_cells, size_cells); + else if ( depth <= 3 && device_tree_node_compatible(fdt, node, "xen,domain-shared-memory-v1") ) + rc = process_shm_node(fdt, node, address_cells, size_cells); if ( rc < 0 ) printk("fdt: node `%s': parsing failed\n", name); From patchwork Fri Mar 11 06:11:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777478 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 01AB5C433FE for ; Fri, 11 Mar 2022 06:13:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288710.489674 (Exim 4.92) (envelope-from ) id 1nSYVy-0000Gg-Ut; Fri, 11 Mar 2022 06:12:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288710.489674; Fri, 11 Mar 2022 06:12:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYVy-0000GX-QL; Fri, 11 Mar 2022 06:12:38 +0000 Received: by outflank-mailman (input) for mailman id 288710; Fri, 11 Mar 2022 06:12:37 +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 1nSYVx-0000Fh-8t for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:37 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0616.outbound.protection.outlook.com [2a01:111:f400:fe1f::616]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3e508a72-a102-11ec-8eba-a37418f5ba1a; Fri, 11 Mar 2022 07:12:35 +0100 (CET) Received: from DB6PR0301CA0014.eurprd03.prod.outlook.com (2603:10a6:4:3e::24) by DU2PR08MB7270.eurprd08.prod.outlook.com (2603:10a6:10:2d5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.16; Fri, 11 Mar 2022 06:12:32 +0000 Received: from DB5EUR03FT047.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:3e:cafe::84) by DB6PR0301CA0014.outlook.office365.com (2603:10a6:4:3e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Fri, 11 Mar 2022 06:12:32 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT047.mail.protection.outlook.com (10.152.21.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:31 +0000 Received: ("Tessian outbound 1f399c739551:v113"); Fri, 11 Mar 2022 06:12:31 +0000 Received: from 1ad56a869f2f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 875CF326-78E1-410B-B6BF-F90B7F3BCA75.1; Fri, 11 Mar 2022 06:12:25 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 1ad56a869f2f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:25 +0000 Received: from AM6P193CA0085.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::26) by AM6PR08MB4133.eurprd08.prod.outlook.com (2603:10a6:20b:ab::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.19; Fri, 11 Mar 2022 06:12:23 +0000 Received: from AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:88:cafe::f1) by AM6P193CA0085.outlook.office365.com (2603:10a6:209:88::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:18 +0000 Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT021.mail.protection.outlook.com (10.152.16.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:18 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:16 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:12 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3e508a72-a102-11ec-8eba-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pjd0pcH7ozHk3VDSlSokBSzHTlMY1j1l8m/2mk3WqSg=; b=DmhPXjw758sy9rxwSWVWGLnny5SXk3oCf9q8p+wAHt5l+50+VWB+ui0sJZb4AtP8wlePs0dPvc/ghwHadl9w1ctKX+Mw4gNxU/QzXiXOogxq60NItugc1dhX2E93cahGKiK3NF2IAw/jNMiamOTyaIRTuxIllHvQ0C3C72Wz5gQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 3c6a9fa71984e4f1 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oGyhsi3QuCqAosuWtKxzwRl4UbYa6hV0HSiEIWfOZRW8Ww23wdy6uMvv5NROqaVPTFGyGucyEN0Gzj0atY21nouWyR/FlAjc25VTm8Xdih//8zbyWrEkyx3ncFCKrs2mpSY7Z9YsPtA8S6OgYJJl1ez0CTO8St3nSSOJ3gdk8mSztvNDjMF4BWfA3INp0DeLuV8niMURUcKuUtdA35JPvI7h4f9HBg70CcqPZnHEyw7NS3FRw8ySuuEOjJbrg+RFISO+GiMJtZE9jGebb0jEDD2CKpsQ2hw74x/ropKTPwC+xqAHqN0I3noVCLbvsTSTwKQmgISImta7Y9hJru+J3A== 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=pjd0pcH7ozHk3VDSlSokBSzHTlMY1j1l8m/2mk3WqSg=; b=bQqJZ97SwLM9ZcL/sALB0xTsekeMYV17Gxf7RhmKDFSlnuUeR9dxFcHmbYUeATCd+2JQOxR3a/DPOWBoPX5doWvjgA2OFjO53l2IAfgqwHnsWAguqYhcUKXpCLeR2yUpvf3TagPvFGQXCz/cbTvMlsp+3RS26pO855N6xy87IarkBObe2hLIU2Srhp3PhNo8bfvcY3+EeQ8Rn/47XHubJs2cqXiweC7Am1nSgGUTTiATJmLpmFvOq7ZZBmAm6fJeZnmNMEZkb5Tdk4SFZxd6sVx7yBqfIG+99UTwBjo/UV5bovZuTxl88GE+nV4T0fXQszMssaJ6oWtxKuAn8sugsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pjd0pcH7ozHk3VDSlSokBSzHTlMY1j1l8m/2mk3WqSg=; b=DmhPXjw758sy9rxwSWVWGLnny5SXk3oCf9q8p+wAHt5l+50+VWB+ui0sJZb4AtP8wlePs0dPvc/ghwHadl9w1ctKX+Mw4gNxU/QzXiXOogxq60NItugc1dhX2E93cahGKiK3NF2IAw/jNMiamOTyaIRTuxIllHvQ0C3C72Wz5gQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , "Stefano Stabellini" , Julien Grall , "Bertrand Marquis" , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Penny Zheng Subject: [PATCH v1 02/13] xen/arm: introduce a special domain DOMID_SHARED Date: Fri, 11 Mar 2022 14:11:12 +0800 Message-ID: <20220311061123.1883189-3-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 513da211-a7df-49b6-41bf-08da032620b1 X-MS-TrafficTypeDiagnostic: AM6PR08MB4133:EE_|DB5EUR03FT047:EE_|DU2PR08MB7270:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: P/hsLU3xNMcr1w4ZnHynUL0R+VLd0/7EHAHcPJo8FHCncdq2R2mM1HcZJEuu0XvQKkSydmhMkoWdtZRaNM0M0QEM/xuMMbw0PvCOUXCkg/3F9hSmrELWjZ4YUymG4/2KpW5o8pvkzYW2X4CVewpW5830+HjgT+Mvq/S3hSX+UcWhcO9SwjGbrW5tjP38xpq9MgRWPvZGdaKk7n5sRWw3hdSi5WXotYFg2jFSY/jwek6hyMSj+b3/Ga8HtVQscuGNxJa46AVw9a9luKEmyKuCXljYi0k+KC88PfT5fa1GsSQMdvA44d+aLl7HQk2V/WeWtzlGJ5uFFqAt3NEjhx7EOlShRBgaXuekSEUIGnEl4OrxyN7HkD9u9hd+w4pBqbh1wLqOaFKS5g1vpvzbOm/ZPlCUYPirT1qGzXrpyLhPZ9pjVzMBT9JPXx7dKv8oMQXcaXhYUevxY0/gTEfgQh98se0x/sHyiKkVrur3iorPyFa08iiovXxCbwmyI1wlgXMHzNyYPeLgFCy/inmzn0p0PQeYE9sEFlLb6xtEgX29FNfpgkIW/QE83bXhGCaGUJ6f580ykQ9Js/4paSvoWt3EE6CWAYMSF5x+wBMUjjwT7HvtqpbhWsv0yLNVZizxBERgBTBv5DbPw1LvRq9rmGjGVYpD1NXZFoAUgCcNFX1vBI329AT4tjLFTREUZ/dHAV6HuSrthkZGiK48cwYTLpLVTQ== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(54906003)(1076003)(2906002)(36756003)(8936002)(316002)(6916009)(186003)(83380400001)(2616005)(86362001)(26005)(81166007)(36860700001)(356005)(70206006)(70586007)(7696005)(4326008)(8676002)(47076005)(336012)(508600001)(426003)(40460700003)(82310400004)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4133 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 92d2a486-5316-4327-fd24-08da032618af X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: laOn+NenWd6aZySIAVlfu2OLrjgF574+x3sceZzFKlProsyp1sCzFX4AdcUMGUQh7TkO63Wh2P2F3OF1bXItM0PSKei486Sxs+bhX7sj2+F3tgndTiu5dBbwh5Zj6RxWETj+EJg1gpFqM7NZuLmLvBVzi0D0/kFmH1LfeZvPVCS96oTVBXZ/Exz3fRnck4/JYVGdSomYtI3yzfw1rI3E3ijIR0OxWmZgLsXEQy7nGSdcLLCWFgGaC/NRaAaspSSNAM8PFszpr6BSazo79oBTt0tfaeHfb4OnTThUF8u5M2X6eD+F7PZTMjcKvRu2FaUCY25Jtd4GFmSDuMqyQfJpiNewYO2rmq9ZM0PIn4miLm8Qm99kBCIHlLZQvEiFK4lJ3BmCEn3AGQq8Rj2N8t1njE+Zbe9kNnW5OhZcm7aXn610s4lrFk8QYD3deFXVwy1X8Y543QvBlx3oXbf7CL+pTPoKV8ew/nMWIXdVP0MpIU5tQLvvsLIuohN5WVw5HM7zciSrUwAesH3zfMHt8j0khC25KCwBBReA+CQGf8MPzdWWIsnpUz8TXuuOR+SS+EeRDgLQPoSS84WYK/IZKhnpNgKcA69sdN9RpfOTLpWY8t9iGFkbZVePf8yNrT5tUx+fCsq6XGgx/NrxAsqH0EIRAjGG+d+eeXb1hvwmKz0KJjtK2g4p10jiHoprkz4E2DBp X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(40460700003)(6916009)(70206006)(70586007)(8936002)(5660300002)(86362001)(2906002)(8676002)(316002)(82310400004)(4326008)(47076005)(81166007)(54906003)(36756003)(7696005)(83380400001)(426003)(1076003)(186003)(336012)(26005)(508600001)(36860700001)(2616005);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:31.8474 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 513da211-a7df-49b6-41bf-08da032620b1 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR08MB7270 From: Penny Zheng In case to own statically shared pages when owner domain is not explicitly defined, this commits propose a special domain DOMID_SHARED, and we assign it 0x7FF5, as one of the system domains. Statically shared memory reuses the same way of initialization with static memory, hence this commits proposes a new Kconfig CONFIG_STATIC_SHM to wrap related codes, and this option depends on static memory(CONFIG_STATIC_MEMORY). We intends to do shared domain creation after setup_virt_paging so shared domain could successfully do p2m initialization. Signed-off-by: Penny Zheng --- xen/arch/arm/Kconfig | 7 +++++++ xen/arch/arm/domain.c | 12 ++++++++++-- xen/arch/arm/include/asm/domain.h | 6 ++++++ xen/arch/arm/setup.c | 22 ++++++++++++++++++++++ xen/common/domain.c | 11 +++++++---- xen/common/page_alloc.c | 5 +++++ xen/common/vsprintf.c | 9 +++++---- xen/include/public/xen.h | 6 ++++++ xen/include/xen/sched.h | 2 ++ 9 files changed, 70 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index ecfa6822e4..c54accefb1 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -106,6 +106,13 @@ config TEE source "arch/arm/tee/Kconfig" +config STATIC_SHM + bool "Statically shared memory on a dom0less system" if UNSUPPORTED + depends on STATIC_MEMORY + default n + help + This option enables statically shared memory on a dom0less system. + endmenu menu "ARM errata workaround via the alternative framework" diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 8110c1df86..1ff1df5d3f 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -44,6 +44,10 @@ DEFINE_PER_CPU(struct vcpu *, curr_vcpu); +#ifdef CONFIG_STATIC_SHM +struct domain *__read_mostly dom_shared; +#endif + static void do_idle(void) { unsigned int cpu = smp_processor_id(); @@ -703,7 +707,7 @@ int arch_domain_create(struct domain *d, if ( is_idle_domain(d) ) return 0; - ASSERT(config != NULL); + ASSERT(is_shared_domain(d) ? config == NULL : config != NULL); #ifdef CONFIG_IOREQ_SERVER ioreq_domain_init(d); @@ -712,12 +716,16 @@ int arch_domain_create(struct domain *d, d->arch.directmap = flags & CDF_directmap; /* p2m_init relies on some value initialized by the IOMMU subsystem */ - if ( (rc = iommu_domain_init(d, config->iommu_opts)) != 0 ) + if ( (rc = iommu_domain_init(d, is_shared_domain(d) ? 0 : config->iommu_opts)) != 0 ) goto fail; if ( (rc = p2m_init(d)) != 0 ) goto fail; + /* DOMID_shared is sufficiently constructed after p2m initialization. */ + if ( is_shared_domain(d) ) + return 0; + rc = -ENOMEM; if ( (d->shared_info = alloc_xenheap_pages(0, 0)) == NULL ) goto fail; diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index c56f6e4398..ea7a7219a3 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -31,6 +31,12 @@ enum domain_type { #define is_domain_direct_mapped(d) (d)->arch.directmap +#ifdef CONFIG_STATIC_SHM +extern struct domain *dom_shared; +#else +#define dom_shared NULL +#endif + /* * Is the domain using the host memory layout? * diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index d5d0792ed4..f6a3b04958 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -855,6 +855,20 @@ static bool __init is_dom0less_mode(void) return ( !dom0found && domUfound ); } +#ifdef CONFIG_STATIC_SHM +static void __init setup_shared_domain(void) +{ + /* + * Initialise our DOMID_SHARED domain. + * This domain owns statically shared pages when owner domain is not + * explicitly defined. + */ + dom_shared = domain_create(DOMID_SHARED, NULL, CDF_directmap); + if ( IS_ERR(dom_shared) ) + panic("Failed to create d[SHARED]: %ld\n", PTR_ERR(dom_shared)); +} +#endif + size_t __read_mostly dcache_line_bytes; /* C entry point for boot CPU */ @@ -1022,6 +1036,14 @@ void __init start_xen(unsigned long boot_phys_offset, apply_alternatives_all(); enable_errata_workarounds(); +#ifdef CONFIG_STATIC_SHM + /* + * This needs to be called **after** setup_virt_paging so shared + * domains could successfully do p2m initialization. + */ + setup_shared_domain(); +#endif + /* Create initial domain 0. */ if ( !is_dom0less_mode() ) create_dom0(); diff --git a/xen/common/domain.c b/xen/common/domain.c index 3742322d22..5cdd0b9f5b 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -643,11 +643,14 @@ struct domain *domain_create(domid_t domid, rangeset_domain_initialise(d); - /* DOMID_{XEN,IO,etc} (other than IDLE) are sufficiently constructed. */ - if ( is_system_domain(d) && !is_idle_domain(d) ) + /* + * DOMID_{XEN,IO,etc} (other than IDLE and DOMID_shared) are + * sufficiently constructed. + */ + if ( is_system_domain(d) && !is_idle_domain(d) && !is_shared_domain(d) ) return d; - if ( !is_idle_domain(d) ) + if ( !is_idle_domain(d) && !is_shared_domain(d) ) { if ( !is_hardware_domain(d) ) d->nr_pirqs = nr_static_irqs + extra_domU_irqs; @@ -663,7 +666,7 @@ struct domain *domain_create(domid_t domid, goto fail; init_status |= INIT_arch; - if ( !is_idle_domain(d) ) + if ( !is_idle_domain(d) && !is_shared_domain(d) ) { watchdog_domain_init(d); init_status |= INIT_watchdog; diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index f8749b0787..e5e357969d 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2616,6 +2616,11 @@ struct domain *get_pg_owner(domid_t domid) switch ( domid ) { +#ifdef CONFIG_STATIC_SHM + case DOMID_SHARED: + pg_owner = rcu_lock_domain(dom_shared); + break; +#endif case DOMID_IO: pg_owner = rcu_lock_domain(dom_io); break; diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index b278961cc3..a22854001b 100644 --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -359,10 +359,11 @@ static char *print_domain(char *str, const char *end, const struct domain *d) switch ( d->domain_id ) { - case DOMID_IO: name = "[IO]"; break; - case DOMID_XEN: name = "[XEN]"; break; - case DOMID_COW: name = "[COW]"; break; - case DOMID_IDLE: name = "[IDLE]"; break; + case DOMID_IO: name = "[IO]"; break; + case DOMID_XEN: name = "[XEN]"; break; + case DOMID_COW: name = "[COW]"; break; + case DOMID_IDLE: name = "[IDLE]"; break; + case DOMID_SHARED: name = "[SHARED]"; break; /* * In principle, we could ASSERT_UNREACHABLE() in the default case. * However, this path is used to print out crash information, which diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index e373592c33..2e00741f09 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -612,6 +612,12 @@ DEFINE_XEN_GUEST_HANDLE(mmuext_op_t); /* DOMID_INVALID is used to identify pages with unknown owner. */ #define DOMID_INVALID xen_mk_uint(0x7FF4) +/* + * DOMID_SHARED is used as the owner of statically shared pages, when + * owner is not explicitly defined. + */ +#define DOMID_SHARED xen_mk_uint(0x7FF5) + /* Idle domain. */ #define DOMID_IDLE xen_mk_uint(0x7FFF) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 24a9a87f83..2fb236f4ea 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -618,6 +618,8 @@ static inline bool is_system_domain(const struct domain *d) return d->domain_id >= DOMID_FIRST_RESERVED; } +#define is_shared_domain(d) ((d)->domain_id == DOMID_SHARED) + #define DOMAIN_DESTROYED (1u << 31) /* assumes atomic_t is >= 32 bits */ #define put_domain(_d) \ if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destroy(_d) From patchwork Fri Mar 11 06:11:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777476 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 504FDC43219 for ; Fri, 11 Mar 2022 06:13:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288714.489717 (Exim 4.92) (envelope-from ) id 1nSYW4-0001Pw-IH; Fri, 11 Mar 2022 06:12:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288714.489717; Fri, 11 Mar 2022 06:12:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYW4-0001Pd-DP; Fri, 11 Mar 2022 06:12:44 +0000 Received: by outflank-mailman (input) for mailman id 288714; Fri, 11 Mar 2022 06:12:42 +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 1nSYW2-0000Fh-49 for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:42 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2062e.outbound.protection.outlook.com [2a01:111:f400:7d00::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4200c9dc-a102-11ec-8eba-a37418f5ba1a; Fri, 11 Mar 2022 07:12:41 +0100 (CET) Received: from AM6PR10CA0093.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::34) by DBAPR08MB5719.eurprd08.prod.outlook.com (2603:10a6:10:1a6::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Fri, 11 Mar 2022 06:12:34 +0000 Received: from AM5EUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8c:cafe::57) by AM6PR10CA0093.outlook.office365.com (2603:10a6:209:8c::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Fri, 11 Mar 2022 06:12:34 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT043.mail.protection.outlook.com (10.152.17.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:33 +0000 Received: ("Tessian outbound 2877e54fe176:v113"); Fri, 11 Mar 2022 06:12:32 +0000 Received: from 33cc58f73ad5.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id BFEBA997-4473-4E5C-95AF-94CE27DFF97C.1; Fri, 11 Mar 2022 06:12:26 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 33cc58f73ad5.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:26 +0000 Received: from AM6P193CA0098.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::39) by AM6PR08MB3880.eurprd08.prod.outlook.com (2603:10a6:20b:86::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.20; Fri, 11 Mar 2022 06:12:24 +0000 Received: from AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:88:cafe::1d) by AM6P193CA0098.outlook.office365.com (2603:10a6:209:88::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Fri, 11 Mar 2022 06:12:24 +0000 Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT021.mail.protection.outlook.com (10.152.16.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:24 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:18 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:16 +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: 4200c9dc-a102-11ec-8eba-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=91p2GRq5kBZZuDWk4lf3po8ltidBgbVkId9fQw4+bdE=; b=A4nd4mmwyY85RQToWZ3KddKo3t7LB0y92Ix0cmJcNgG6CL9qUEyNQYnKBSbUFENY3xxAmy9/EtPVeuufm1GC6+IS11aZkkFx2wlZPMB6AsmJ0PKbL8e1vmGNqCUElptzMn9RWP9S/+iBsMsIMm8JNK4g4/qaYclSseY0AP4BaQc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 13f0d65bc3c1ec0e X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZYelD2S5agAVL35WbK2fxtx2CI2Tpd25vM3omDZZVoG4dneHUNOHwTlkv6nX7F1w6sg/O024/uMACdjcVD6WBgWHevheaXlkPmEBRa6WPA2RF4J9sfFYf7jqWbSKSD8wlSdI5c2Xc3Fs5qyLQh8LQ8PyQA+a9rbMTaR336/6uoPUmssl9tPH07jgf4psBb42+bk/XUYkkeTpmkO5ZSpDKqlRh79oSBXse8s1MDDDpqRmuf1XG1+Csdv7wtYrPB0q5WIt6areXK6uuumYywYJe3gDNCMDyIuZFjC25v8jSYEB9FDzr++ETRfJYxyfMyL+HTH7g9O/5Na2THh6TopRpQ== 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=91p2GRq5kBZZuDWk4lf3po8ltidBgbVkId9fQw4+bdE=; b=RF0OzEN+KnmqOdFEFQ8w+NgnCr5yxONPQzh/BWf5DGDTPWB90Ut00Pf8kmWE7OW8qQNdKn0NBTt1seviWICBzf2i1S2rHAf6ewJaMmTqtiAzYuu3i86dO5wjft+iWGr3sRhHu6IBL4mpqcCSIC43cu0bnnOsPiQDG3YQPtWysdBpcNxMHWlW5wNdNQxhEtLJbhp8icErTh+2GwAWChia7ZCAENryzwqXaj76LUUIKTnpmfMyXQwAYZPas7FgCFKsrqTDr6hFZ2Dj1C1RW3WKVL63JHilIsmQddgeps90MxWAGDvYrVkjuNDQXw6bgo8HtgTD9Fh/0y/eAE0KlHnrGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=91p2GRq5kBZZuDWk4lf3po8ltidBgbVkId9fQw4+bdE=; b=A4nd4mmwyY85RQToWZ3KddKo3t7LB0y92Ix0cmJcNgG6CL9qUEyNQYnKBSbUFENY3xxAmy9/EtPVeuufm1GC6+IS11aZkkFx2wlZPMB6AsmJ0PKbL8e1vmGNqCUElptzMn9RWP9S/+iBsMsIMm8JNK4g4/qaYclSseY0AP4BaQc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 03/13] xen/arm: allocate static shared memory to dom_shared Date: Fri, 11 Mar 2022 14:11:13 +0800 Message-ID: <20220311061123.1883189-4-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 049b94ea-7735-445a-5c1c-08da032621a6 X-MS-TrafficTypeDiagnostic: AM6PR08MB3880:EE_|AM5EUR03FT043:EE_|DBAPR08MB5719:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 9gUABD4unzlPK0n5bgmqPSGpvMufjcfPSFn1Le8hqVv8dMCipCdkuye/c+HDLj9MrJPt0eGYpFoyFxEHPfwl3mpw6T16SI4tyR9yqa49iA0zww6kMzNlNjKYVJpBe7Cw7BaKpb3i5t5e4KSTlvVEG6HqudYDl1bhXHAJsula0cnh3AugoSOvRX3XeXCwGc3y7rQgCcxSP7M57Nl66CkMS2ZU4z/yChIGTuQ+po60BdtWdjYmqSi9ACFr8FsLG1lwbZff9R1a3kindFzAJLP90AeE1NLsFjvKQKhh1/VQTpRBEXyhF/8wDyryordE3mzq55WqaXUM2pK60W4YfYMA8g7OGdSMSMc9b/RiQ+7V0P40QreoZ8yz2CDXcseidrVWJj9bnTDvEmrwwahdSb1zX6LIcTQMln57eZqojFBRIIpTFsG6mOCmVDDxwSN3LuoWrq1ITKTakU/ztQb5YhHd6dTAjCGjuw/bVRv+wxNEjYO47TS9Tga1diuYN7bM6b2JlMDOWUGVFK69gwz+P6jg8Uf30Bl7/fX7aOpMPf0rxIS6P4Y13wRnsjlChP9cDGBaTolT6ke8Dqhys9PZPyw1oRCwkR7+U6jpT6dfrYl2JHGV/RlKaH+Y7IxAEzp8JvtMcfzZDiNVReZV5V6Be81lgsikbw9duoRCVOPvkE9pb50zkG08TLE0RcGH0d0n7LqLnOdNDWypXgI0nu5yM2DhZQ== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(1076003)(82310400004)(2616005)(86362001)(426003)(83380400001)(26005)(186003)(336012)(2906002)(47076005)(36860700001)(8936002)(70586007)(81166007)(40460700003)(356005)(54906003)(5660300002)(6666004)(316002)(508600001)(70206006)(4326008)(6916009)(8676002)(36756003)(7696005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3880 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 05a25351-5397-450d-f8ee-08da03261c8a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CNOf+/AaVXiibGEj3AyW4ln2CKNCi6QsjuHvw7av+ZxxKTyjdF+jzamA162AaA16v4UXi3XNjZMK7BdrSMQ4Zj+PkXhg0X8jaI1WKCf4kFm+TebMeM8SjANZ0sxxgfiikzg4QHDUzXoKm1ABbPt0JYzZxlrPvV+3Q3akWWT97gVlx0+NTnK0GxWVnFhW/VDD6X3+vm/uvlMqVR2YrHmY2c1MWsDwClMuRXKuWCPfPRG3m73KGyUqHqobkat7acYju0Z46eL0pbvioLOWmsb55mlg1X9qn4PbMuiW5cVnomoYITRXyPt9Q3NcaRhKB/gxyZft9T0dcd/yrdKS7ZTVj2/Dj9RUhqSSCfPI6znhyKw0thOqxpq3bXqUvBXmwmIxd1OfcUiDLbSgPdlUnsVlrkO0xZMPEaWhVE1onOVGFp8P4ROEUIvjVvrVNdRs/6QRCKw7FaT0KXSZwWi/rRha9uK469qu/k1XxJgchvs+buLn/w5ooJnHKWZM/sgbt501ubmVLHNlyWu2cB2Av9n1derDiSa855GQc+xH/+6Net79EdYJxjWUP3vxjAAn2ZGek/87dmfaYhUwM0cs0HqT1kDy39xSgjgYXgir0KCYZ2fANKI8ravc196ANuzg3nnX4/lNiFpMf0Di3EPJH7R9siN6MIWUeKQIb73WCS9i0xZ1d7VucloiH9hKgRJs9N6n X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(7696005)(6666004)(5660300002)(4326008)(47076005)(36860700001)(508600001)(8676002)(70206006)(70586007)(54906003)(8936002)(6916009)(316002)(2616005)(107886003)(186003)(26005)(36756003)(40460700003)(336012)(426003)(86362001)(83380400001)(81166007)(82310400004)(1076003)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:33.3912 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 049b94ea-7735-445a-5c1c-08da032621a6 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5719 From: Penny Zheng This commit introduces process_shm to cope with static shared memory in domain construction. This commit only considers allocating static shared memory to dom_shared when owner domain is not explicitly defined in device tree, the other scenario will be covered in the following patches. Static shared memory could reuse acquire_static_memory_bank() to acquire and allocate static memory. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 116 +++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 8be01678de..6e6349caac 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -527,7 +527,8 @@ static mfn_t __init acquire_static_memory_bank(struct domain *d, mfn_t smfn; int res; - device_tree_get_reg(cell, addr_cells, size_cells, pbase, psize); + if ( cell ) + device_tree_get_reg(cell, addr_cells, size_cells, pbase, psize); ASSERT(IS_ALIGNED(*pbase, PAGE_SIZE) && IS_ALIGNED(*psize, PAGE_SIZE)); if ( PFN_DOWN(*psize) > UINT_MAX ) { @@ -751,6 +752,113 @@ static void __init assign_static_memory_11(struct domain *d, panic("Failed to assign requested static memory for direct-map domain %pd.", d); } + +#ifdef CONFIG_STATIC_SHM +static __initdata DECLARE_BITMAP(shm_mask, NR_MEM_BANKS); + +static mfn_t __init acquire_shared_memory_bank(struct domain *d, + u32 addr_cells, u32 size_cells, + paddr_t *pbase, paddr_t *psize) +{ + /* + * Pages of statically shared memory shall be included + * in domain_tot_pages(). + */ + d->max_pages += PFN_DOWN(*psize); + + return acquire_static_memory_bank(d, NULL, addr_cells, size_cells, + pbase, psize); + +} + +static int __init allocate_shared_memory(struct domain *d, + u32 addr_cells, u32 size_cells, + paddr_t pbase, paddr_t psize, + paddr_t gbase) +{ + mfn_t smfn; + int ret = 0; + + printk(XENLOG_INFO "Allocate static shared memory BANK %#"PRIpaddr"-%#"PRIpaddr"\n", + pbase, pbase + psize); + + smfn = acquire_shared_memory_bank(d, addr_cells, size_cells, &pbase, + &psize); + if ( mfn_eq(smfn, INVALID_MFN) ) + return -EINVAL; + + ret = guest_physmap_add_pages(d, gaddr_to_gfn(gbase), smfn, PFN_DOWN(psize)); + if ( ret ) + { + dprintk(XENLOG_ERR, "Failed to map shared memory to %pd.\n", d); + return ret; + } + + return ret; +} + +static int __init process_shm(struct domain *d, + const struct dt_device_node *node) +{ + struct dt_device_node *shm_node; + int ret = 0; + const struct dt_property *prop; + const __be32 *cells; + u32 shm_id; + u32 addr_cells, size_cells; + paddr_t gbase, pbase, psize; + + dt_for_each_child_node(node, shm_node) + { + if ( !dt_device_is_compatible(shm_node, "xen,domain-shared-memory-v1") ) + continue; + + if ( !dt_property_read_u32(shm_node, "xen,shm-id", &shm_id) ) + { + printk("Shared memory node does not provide \"xen,shm-id\" property.\n"); + return -ENOENT; + } + + addr_cells = dt_n_addr_cells(shm_node); + size_cells = dt_n_size_cells(shm_node); + prop = dt_find_property(shm_node, "xen,shared-mem", NULL); + if ( !prop ) + { + printk("Shared memory node does not provide \"xen,shared-mem\" property.\n"); + return -ENOENT; + } + cells = (const __be32 *)prop->value; + /* xen,shared-mem = ; */ + device_tree_get_reg(&cells, addr_cells, size_cells, &pbase, &psize); + ASSERT(IS_ALIGNED(pbase, PAGE_SIZE) && IS_ALIGNED(psize, PAGE_SIZE)); + gbase = dt_read_number(cells, addr_cells); + + /* TODO: Consider owner domain is not the default dom_shared. */ + /* + * Per shared memory region could be shared between multiple domains. + * In case re-allocating the same shared memory region, we use bitmask + * shm_mask to record whether this shared memory region has ever been + * allocated already. + */ + if ( !test_bit(shm_id, shm_mask) ) + { + /* + * Allocate statically shared pages to the default dom_shared. + * Set up P2M, and dom_shared is a direct-map domain, + * so GFN == PFN. + */ + ret = allocate_shared_memory(dom_shared, addr_cells, size_cells, + pbase, psize, pbase); + if ( ret ) + return ret; + + set_bit(shm_id, shm_mask); + } + } + + return 0; +} +#endif /* CONFIG_STATIC_SHM */ #else static void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo, @@ -3150,6 +3258,12 @@ static int __init construct_domU(struct domain *d, else assign_static_memory_11(d, &kinfo, node); +#ifdef CONFIG_STATIC_SHM + rc = process_shm(d, node); + if ( rc < 0 ) + return rc; +#endif + /* * Base address and irq number are needed when creating vpl011 device * tree node in prepare_dtb_domU, so initialization on related variables From patchwork Fri Mar 11 06:11:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777474 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 69815C433EF for ; Fri, 11 Mar 2022 06:13:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288711.489685 (Exim 4.92) (envelope-from ) id 1nSYW0-0000XY-5i; Fri, 11 Mar 2022 06:12:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288711.489685; Fri, 11 Mar 2022 06:12:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYW0-0000XP-2U; Fri, 11 Mar 2022 06:12:40 +0000 Received: by outflank-mailman (input) for mailman id 288711; Fri, 11 Mar 2022 06:12:38 +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 1nSYVy-0000Fh-7Q for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:38 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0607.outbound.protection.outlook.com [2a01:111:f400:fe0d::607]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3fa8371d-a102-11ec-8eba-a37418f5ba1a; Fri, 11 Mar 2022 07:12:37 +0100 (CET) Received: from DB9PR06CA0014.eurprd06.prod.outlook.com (2603:10a6:10:1db::19) by AM8PR08MB6545.eurprd08.prod.outlook.com (2603:10a6:20b:368::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 06:12:35 +0000 Received: from DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:1db:cafe::d) by DB9PR06CA0014.outlook.office365.com (2603:10a6:10:1db::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:35 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT064.mail.protection.outlook.com (10.152.21.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:34 +0000 Received: ("Tessian outbound 31aeb3346a45:v113"); Fri, 11 Mar 2022 06:12:34 +0000 Received: from f51cbd4cabcd.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 451891ED-868A-47FA-B37C-DD139D17B140.1; Fri, 11 Mar 2022 06:12:27 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f51cbd4cabcd.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:27 +0000 Received: from AM6P193CA0100.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::41) by VI1PR08MB3533.eurprd08.prod.outlook.com (2603:10a6:803:84::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.16; Fri, 11 Mar 2022 06:12:25 +0000 Received: from AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:88:cafe::34) by AM6P193CA0100.outlook.office365.com (2603:10a6:209:88::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Fri, 11 Mar 2022 06:12:25 +0000 Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT021.mail.protection.outlook.com (10.152.16.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:25 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:21 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12: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: 3fa8371d-a102-11ec-8eba-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6aEzTY0gaHMjQiSKvKT0k3TGTcpG97yqj0yEvdhiK8g=; b=cKCTShhTjRm4L6NeW2sDcWp8QTAraL/IiRUWGeIWkiNBIQXllmkJ0w1OJQg6kEH4ZMQxu4s43zSyGYVVQJY+5oMU/b69c0693ITcEid0QHvwHcK1BmOANsrDFG6XnB8EWP1WUUsrFr8S4P9AG5kVLMctTwkO962dgNvi3vPXeGQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 315f15bcb692ff6d X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O0O/fDEOT+ohxNpGx+e9A4Ok9MonqvvjUxtDEYbEB4gMEz0rXKlZoDpCr3CT2qbDixsI8oC6eZWrzjM6imYkp/dWYf6wfX3l2UY78zGHT1kwMApESI5wI7SLfgv8HyRmGX4TzOXW4JGb7iI9BR1xl9I/f72VjnHXjfrRqEyVZ9CdDn1aO1Up70ZvDcMn7x54juMm6mz+rjUZ3rQ+4xnuho+G4aZF+LKnoYWTAT/Loi2Ei0FDN66dk1ZPSeutogC7y8CcGpcSuBfLB6VAeYSQ8gWO0ZbLp1WNcNZHUjkS54fV2Edat4hmwwduPJ7a63XyFVSMgP4J+xuSGg6eWVeTlQ== 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=6aEzTY0gaHMjQiSKvKT0k3TGTcpG97yqj0yEvdhiK8g=; b=HIQWdE76JSyEuz974EBLEy0YR6SEmcCZbuze2cjEMHAqDTPb8qO0s6Za/Lq5NgqJUnvPjQ2f2oeuDc6CQYHZwGV8zReRswxQ5WBDqnm3FTtrKlmgNIi8Ig6FEWfIGEE7ejh/awzxVFDI4LlmV82YqJ6C6fFmVNbBuoYTOMZwlyWewkalyWzOofFFjHRqY00qtzBuYNlVYydchIY5BTiipsqSloS5esgAwl6vPesZTQgXcFlGcMAW4qT2nLhcuSVm3bCkusaWPmfvXDKzrcbfjAJN9ZeO11z3Mabm14qoLZnTdZ7kgS0YTS9w+NT5CqZp0MjFGlnWdnAjjsCDpe81Sw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6aEzTY0gaHMjQiSKvKT0k3TGTcpG97yqj0yEvdhiK8g=; b=cKCTShhTjRm4L6NeW2sDcWp8QTAraL/IiRUWGeIWkiNBIQXllmkJ0w1OJQg6kEH4ZMQxu4s43zSyGYVVQJY+5oMU/b69c0693ITcEid0QHvwHcK1BmOANsrDFG6XnB8EWP1WUUsrFr8S4P9AG5kVLMctTwkO962dgNvi3vPXeGQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 04/13] xen/arm: add P2M type parameter in guest_physmap_add_pages Date: Fri, 11 Mar 2022 14:11:14 +0800 Message-ID: <20220311061123.1883189-5-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 9f78ee7a-cd3b-403e-bb11-08da0326226c X-MS-TrafficTypeDiagnostic: VI1PR08MB3533:EE_|DB5EUR03FT064:EE_|AM8PR08MB6545:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: vFMZkg8duRlCN/nAZqSeeN4hD1KwoOPcf91HUb6YDarLEYwVgKoV/DFluh6QGndX9HH3RCQ5l3Ca1rVWGvM1AIBiXkym/jIGWv5soZsOu5DWUG+Ga+3eVxuyg69Sa2N1E1NpiErbn2aggMSTV5NSm8SBVFYvqwD893X3mLDQdJf7cChM8PpACFR/I1T/1ZD592FfSud+jn+CHdBp5eKu98NmhIDLGMqx41gqVw3zQYCZmXU6v1RLkRf1bi3QCqhFCvNOOpBvyvVAwbYhE7IOIaLv3M55q17qfUFB246aunHKMyHXUKlIPF5j9hoIFESHN2WAWMkIS3Cf7TwCT1hdZXYQhfwFPb4TcckfjWZoRu7Ofa7RqK/RflRasU3p20RFJ91wBFVg+bK1LhfdkUZZ5gWN55uCWZ7vQgmp0Tii3YOPTD8bvNbCzcbbWlRl80/vg4HbjebE05N0ZizPS/+SG8Pi8PlwCG2MLcq+2di+UJZOhIYFod6TB3xaH+USS2TYJcMu/FoF6vWEtnba/K2qCSaEsKMOVnveDzGdMSCCkRPKmU5JVP0iEQglSEr74MjWPCc3+Kug4pR7UTQe6CSvlBWo6Pz1q/Ir9KuI2ZPo5RkEkuQ9VMLy6aSYAlk+jq1lI/giFQn5q0aVIKMTpewisB6hQ4SEwE357X1vwEDp259tbvMraoIRU/TSkzhhBvuMngoiPh2xVMIrT/xy2mL66g== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(508600001)(336012)(186003)(426003)(1076003)(26005)(2616005)(86362001)(82310400004)(7696005)(6666004)(5660300002)(54906003)(316002)(6916009)(4326008)(70206006)(70586007)(40460700003)(8676002)(81166007)(83380400001)(36756003)(356005)(8936002)(2906002)(36860700001)(47076005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3533 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 7f5cbd13-1e96-4283-5542-08da03261cea X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rY7nI8NIP764s0bItiGCSIveTj/p23vh81wfv9On73eTCkUvsZ6zdD64oWDI2nEj7xXAVauQy2ff7CAXBxf9Z+TfA7RK5Lc2zxC80fnNp1CpRbYMoE8ZlAEBEob3hLP7Y1FHmhxbcSVBGh2jBRGR+pAkMkHDnWabbs9kYDrSrU6YkcKr9HD1BTeZYpgc0hkVO29NsdF/L3Eu5TQDK7xP66ti2PdbdIvH8bHdslVaTxarNOdPcq5PUBCzcsmNHNqZVgTWvOVncX5pRcEohh+Povi4df0jMTvVW6nu55ZhokwWW5lKfbzkq6PFwnLsmUIcKsoOZJ8LfzJh08RcepSVi4bwWkpyUE+SKin/Xaysc+chr1Mu4fjp4//PBRlNxP4v76JQX5sNXutPQm53ckb0U+69zZ/scWu7WSA43ytxvSy/y42e0ZZDKdfEaBxrFJmNgTz5EXdIqC/wS015AfUe7zeVqIAuoFi2rK5+sndSQ6XLyhyAwAg7Wti53WLfeNTUyJbVhHyNt5wMp0W9Z5e3NiYzblMaCMh5aRI/BImlFFf9shIVtb1ek6G8z4tRUiqEpBSkHrvx6aUR+T60H4VDKGH5ChcZxbgNFyn1fPELei4ktfx3wL1KE6ZIxyN0Y9vyFZRZuK6Bs9ufddT4lrMmNlmkyUvzR1NKCWx0AOFYEihEuzDfb4VGnmhStM+y3Vej X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(336012)(426003)(508600001)(83380400001)(40460700003)(186003)(1076003)(26005)(2906002)(2616005)(107886003)(36756003)(36860700001)(47076005)(7696005)(82310400004)(6666004)(81166007)(5660300002)(70586007)(70206006)(8936002)(316002)(54906003)(4326008)(86362001)(8676002)(6916009);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:34.7381 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f78ee7a-cd3b-403e-bb11-08da0326226c X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6545 From: Penny Zheng In order to cover the scenario where users intend to set up guest p2m foreign mapping with nr_pages, this commit adds a new P2M type parameter in guest_physmap_add_pages. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 5 +++-- xen/arch/arm/include/asm/p2m.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 6e6349caac..984e70e5fc 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -507,7 +507,7 @@ static bool __init append_static_memory_to_bank(struct domain *d, else sgfn = gaddr_to_gfn(mfn_to_maddr(smfn)); - res = guest_physmap_add_pages(d, sgfn, smfn, nr_pages); + res = guest_physmap_add_pages(d, sgfn, smfn, nr_pages, p2m_ram_rw); if ( res ) { dprintk(XENLOG_ERR, "Failed to map pages to DOMU: %d", res); @@ -787,7 +787,8 @@ static int __init allocate_shared_memory(struct domain *d, if ( mfn_eq(smfn, INVALID_MFN) ) return -EINVAL; - ret = guest_physmap_add_pages(d, gaddr_to_gfn(gbase), smfn, PFN_DOWN(psize)); + ret = guest_physmap_add_pages(d, gaddr_to_gfn(gbase), smfn, PFN_DOWN(psize), + p2m_ram_rw); if ( ret ) { dprintk(XENLOG_ERR, "Failed to map shared memory to %pd.\n", d); diff --git a/xen/arch/arm/include/asm/p2m.h b/xen/arch/arm/include/asm/p2m.h index 8cce459b67..58590145b0 100644 --- a/xen/arch/arm/include/asm/p2m.h +++ b/xen/arch/arm/include/asm/p2m.h @@ -317,9 +317,10 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn, static inline int guest_physmap_add_pages(struct domain *d, gfn_t gfn, mfn_t mfn, - unsigned int nr_pages) + unsigned int nr_pages, + p2m_type_t t) { - return p2m_insert_mapping(d, gfn, nr_pages, mfn, p2m_ram_rw); + return p2m_insert_mapping(d, gfn, nr_pages, mfn, t); } mfn_t gfn_to_mfn(struct domain *d, gfn_t gfn); From patchwork Fri Mar 11 06:11:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777473 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 1DC93C433F5 for ; Fri, 11 Mar 2022 06:13:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288712.489691 (Exim 4.92) (envelope-from ) id 1nSYW0-0000fU-QL; Fri, 11 Mar 2022 06:12:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288712.489691; Fri, 11 Mar 2022 06:12:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYW0-0000ek-Lp; Fri, 11 Mar 2022 06:12:40 +0000 Received: by outflank-mailman (input) for mailman id 288712; Fri, 11 Mar 2022 06:12:39 +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 1nSYVz-0008Q3-48 for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:39 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03on0626.outbound.protection.outlook.com [2a01:111:f400:fe09::626]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 401d07cd-a102-11ec-853a-5f4723681683; Fri, 11 Mar 2022 07:12:38 +0100 (CET) Received: from DB9PR06CA0007.eurprd06.prod.outlook.com (2603:10a6:10:1db::12) by PR2PR08MB4763.eurprd08.prod.outlook.com (2603:10a6:101:20::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 06:12:35 +0000 Received: from DB5EUR03FT050.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:1db:cafe::3d) by DB9PR06CA0007.outlook.office365.com (2603:10a6:10:1db::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Fri, 11 Mar 2022 06:12:35 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT050.mail.protection.outlook.com (10.152.21.128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:35 +0000 Received: ("Tessian outbound 826a6d8e58c3:v113"); Fri, 11 Mar 2022 06:12:35 +0000 Received: from ee42f0a71c79.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 52173E03-777A-4219-8A16-B8A7E30F730C.1; Fri, 11 Mar 2022 06:12:29 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ee42f0a71c79.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:29 +0000 Received: from AM6P193CA0100.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::41) by AM6PR08MB4785.eurprd08.prod.outlook.com (2603:10a6:20b:d2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.29; Fri, 11 Mar 2022 06:12:27 +0000 Received: from AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:88:cafe::34) by AM6P193CA0100.outlook.office365.com (2603:10a6:209:88::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Fri, 11 Mar 2022 06:12:27 +0000 Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT021.mail.protection.outlook.com (10.152.16.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:27 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:24 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12: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: 401d07cd-a102-11ec-853a-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2tUy/0RXwgpLcKCk4dgzOJCVdOMJ/pIH58P1Z/r+6Ms=; b=8AAxO/XQZbs9mKqqiBvUKePnRIfdB97MlrofFNBffhBA419DgSdnSlErgygiJxfJO7FY7eTe/M0okFsyvZ0aUnJp5Ub7aFYummkfyhqdaGleklTBixAoCFYKwi80fOYWFbpbt8kA+7YLVehfRYSokcfrsEp9dHUAAsh79tXwINE= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 2fe5afede2149a2a X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nz2IqV+9TTz6sdPjRlH6hcPMppdkxe4txsu3HLjSwiekouz6gLpEj7GXg46Ym04eq7myHhRRIsBbAeiFqd6aIfNXOFRulb/KlKiyI6YB20kScu6ZxuqE9Q+jgAJz8b8wyCM/i5MovcbnOTog8L+P1ox1dNNSfdp0aIS9PEwWbhEysRufraSGZQpnOv5Q0LOgA+WQEV2Zko077JEjjXUO2dAfbWdNjhPwMKgk417O/Nogn5f1JzsU/XQCd/G00UfIkaDVtJZAMiMaxLrkWZ36h3ckT+WzU6rXckGyd8rY+osF7RUMvyrmYI6i0WISujIhPQcG7vp57hABTfJDXDoxNQ== 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=2tUy/0RXwgpLcKCk4dgzOJCVdOMJ/pIH58P1Z/r+6Ms=; b=m/k3EKXbeVect56qh7hRMes04UP22AwB/5bsntYqaFi+jkxxNdh9zYBVHWLg9t6R80nFi2AIK3WdvRn5fwu9TQn4OCVNIH1iAw6d1K1dv3bXDwr/GRLoOsj+6SZrV+0hsKcuSGQXvAMCG91dvoT7e88qLzX7XHx7puMpN+cw5XPUsMO6FeIu0racbAC2rlBjAe1SSPgwoNEHTN46g24vDY21kCmqbdBYH7cPY9QmlwA5aaAfB2KabJPUdRint8w18UUa/8ebuFBbvYGZaKCqe3bFVYDXrEk7xfKC8HA8SdkmaaO9Qbyla6Adsm1N4+6LgYCHR4w8/+VIGfeIBIMGcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2tUy/0RXwgpLcKCk4dgzOJCVdOMJ/pIH58P1Z/r+6Ms=; b=8AAxO/XQZbs9mKqqiBvUKePnRIfdB97MlrofFNBffhBA419DgSdnSlErgygiJxfJO7FY7eTe/M0okFsyvZ0aUnJp5Ub7aFYummkfyhqdaGleklTBixAoCFYKwi80fOYWFbpbt8kA+7YLVehfRYSokcfrsEp9dHUAAsh79tXwINE= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 05/13] xen/arm: introduce get_pages_from_gfn Date: Fri, 11 Mar 2022 14:11:15 +0800 Message-ID: <20220311061123.1883189-6-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: d51735c1-b30d-4373-cc63-08da032622e3 X-MS-TrafficTypeDiagnostic: AM6PR08MB4785:EE_|DB5EUR03FT050:EE_|PR2PR08MB4763:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: DUBojstnuxMuYIKIy30FD3+PUuUGNekrPc2JEaanLlZNB5/fiwOHqMnUMjsxq/BPYy3Kank6ds6ftjhRYEELp8/kTvRJAcZMc7nOrGQUs6NuwaagF6XpL2jvSH0oxkciCcBDSEDi3SjBQ3Z5UmHVKAqOCBK6Wyw1JeEtV29ldq5bfCTTNUBHulIjTjm4wcFOpPW6cd6x4cE9FtvRc9wX6EUfKWXkNlP+rewGGQJ9rw9D9lY/+1LYS1bEQEu1UaeqcXHbudicy63EDSKQnRHkPVUhLmXGct36x6UJyu4MkgA2fIc5EGOF/M7pbeZKPjRpgamG6cn6tGT9rFT6fbit9xeGMOKLHEpedtXpaDVjv3SjXhfLidSW++ESZPlyLP3dAN0w2u28zCgzUfujMN8vlhNRbXLh9bIekh1xApMFfcJasklX8t2OLPT/ft3Ql2C1UB9bNrlM/yP3kbKh4tX88KyHmZ0liQTkbLhBCudOuBLHguycU52EvgEa1E6TFbEhSlsHousm4h0zgfkynt+Sw64xpdZaEmMvFORbsbUYM6y8TW1bqV/P82rcyNbP0Jyb0YgJrJ9c2wOUYA4TxSPiZfUieTrxftoA1LwTZfz4U2vcKJJW5C+A62DhI+rhfLx7Hg44hweW7alLMvVOyQB/lTOGkQUfA9/O/8oYfG8PdaY3TZ8HFaIYBJnUnY5eBqyU0w9EC91T9X3Mlnn629iQ/A== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(508600001)(356005)(6916009)(54906003)(5660300002)(316002)(8936002)(81166007)(47076005)(8676002)(70586007)(36860700001)(4326008)(70206006)(83380400001)(186003)(26005)(1076003)(336012)(2616005)(40460700003)(7696005)(6666004)(36756003)(82310400004)(86362001)(2906002)(426003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4785 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT050.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 73a9ee89-54eb-4df2-f584-08da03261df2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QuOUcR3KkLiURbcG5aYIBY+MzhYnTx0tbRlB5FHx3mfvo/HZIZl6EZ2I29npLK5zihY8i7zlieGy5RfkgjYExjh2W9fyqi7pLGzVdU+APL+fm7hqW8Kw7MF0EtJnmHbhtRKuKAiNP4USkOUSX0bylxn+yiMxNADp0xy74YAXt7PA2exvxapw9lMh5HiePyTJSycdNuxsiewDoGvYqk3lhRrVklENAsprNMsEjSYV0BcqAntqVv5YZGJRAHPk5vFgAOP12kzMfnfVPz/m/Y+cYDpou4V83Op8kbrsw8nTyU+oMYgavmVEbhBWBGIttdkvoi5geo5dWIdy9Q/0NGwLbguqYTrlvazEuUsyh6/YLtsw9M9fNogTQFJSGZzjVZQMh0O9v7dS0mXQ5mCSO9l5aSlNAhhrIkcK7TQk2pAEwaFJJwC/0tqzJyR68M6ah3Sv4i1kIHY4ofMgaY688niL8j+NeDfkVvQ5cGLIeaEhHaNikOvyS9OCOA4jxVwqoMIyhp8rQ7TXDnWCisTwgPlMUnDrmXrRzJS8LcRvi0xeE7Q8Bl0cWxwHLtcQK40it8yj+Uhe5BW6AxX/ZFY5zr+jLyrfsWsPF/phQEF9gnGTox6nYFqqaMQwwzpzj/ZsphhTyGRhTprK70ybcpjvp4ytOyr8mY/W2qtRyienaDdDBQpHU8t6kr4WXlYrnW6oFZs/ X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(2906002)(47076005)(36860700001)(5660300002)(86362001)(83380400001)(8936002)(4326008)(8676002)(36756003)(1076003)(70586007)(2616005)(426003)(26005)(186003)(81166007)(336012)(82310400004)(316002)(54906003)(6666004)(7696005)(40460700003)(508600001)(107886003)(6916009)(70206006);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:35.5341 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d51735c1-b30d-4373-cc63-08da032622e3 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT050.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR2PR08MB4763 From: Penny Zheng In order to getting statically shared pages based on gfn with nr_pages, this commit introduces a new helper get_pages_from_gfn to acquire a set of pages based on [gfn, gfn + nr_gfns), with the same P2M type. Signed-off-by: Penny Zheng --- xen/arch/arm/include/asm/p2m.h | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/xen/arch/arm/include/asm/p2m.h b/xen/arch/arm/include/asm/p2m.h index 58590145b0..b23024b9a1 100644 --- a/xen/arch/arm/include/asm/p2m.h +++ b/xen/arch/arm/include/asm/p2m.h @@ -370,6 +370,43 @@ static inline struct page_info *get_page_from_gfn( return page; } +static inline int get_pages_from_gfn(struct domain *d, unsigned long gfn, + unsigned long nr_gfns, + struct page_info **pages, p2m_type_t *t, + p2m_query_t q) +{ + p2m_type_t _t; + unsigned long i = 0; + int ret = 0; + + for ( ; i < nr_gfns; i++ ) + { + pages[i] = get_page_from_gfn(d, gfn + i, t, q); + + if ( !pages[i] ) + { + ret = -ENOENT; + goto fail_get; + } + + if ( i == 0 ) + _t = *t; + /* Check if all pages share the same p2m type. */ + else if ( *t != _t ) + { + ret = -EINVAL; + goto fail_get; + } + } + + return ret; + + fail_get: + while( --i >= 0 ) + put_page(pages[i]); + return ret; +} + int get_page_type(struct page_info *page, unsigned long type); bool is_iomem_page(mfn_t mfn); static inline int get_page_and_type(struct page_info *page, From patchwork Fri Mar 11 06:11:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777475 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 1AAB1C4332F for ; Fri, 11 Mar 2022 06:13:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288713.489707 (Exim 4.92) (envelope-from ) id 1nSYW2-00013i-6p; Fri, 11 Mar 2022 06:12:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288713.489707; Fri, 11 Mar 2022 06:12:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYW2-00013Z-16; Fri, 11 Mar 2022 06:12:42 +0000 Received: by outflank-mailman (input) for mailman id 288713; Fri, 11 Mar 2022 06:12:40 +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 1nSYVz-0000Fh-Tx for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:40 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on061a.outbound.protection.outlook.com [2a01:111:f400:fe0e::61a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4086729b-a102-11ec-8eba-a37418f5ba1a; Fri, 11 Mar 2022 07:12:39 +0100 (CET) Received: from DB6PR07CA0075.eurprd07.prod.outlook.com (2603:10a6:6:2b::13) by DBBPR08MB4725.eurprd08.prod.outlook.com (2603:10a6:10:f5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Fri, 11 Mar 2022 06:12:37 +0000 Received: from DB5EUR03FT035.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2b:cafe::d4) by DB6PR07CA0075.outlook.office365.com (2603:10a6:6:2b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.9 via Frontend Transport; Fri, 11 Mar 2022 06:12:37 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT035.mail.protection.outlook.com (10.152.20.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:36 +0000 Received: ("Tessian outbound 1f399c739551:v113"); Fri, 11 Mar 2022 06:12:36 +0000 Received: from 901fda6444bd.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id B0B78372-B243-4C01-BB65-1CF05B3ED5F1.1; Fri, 11 Mar 2022 06:12:30 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 901fda6444bd.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:30 +0000 Received: from AM6P194CA0023.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::36) by DB6PR0801MB1990.eurprd08.prod.outlook.com (2603:10a6:4:6c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Fri, 11 Mar 2022 06:12:28 +0000 Received: from AM5EUR03FT051.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:90:cafe::9c) by AM6P194CA0023.outlook.office365.com (2603:10a6:209:90::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Fri, 11 Mar 2022 06:12:28 +0000 Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT051.mail.protection.outlook.com (10.152.16.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:28 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:27 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:24 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4086729b-a102-11ec-8eba-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M1TXqrctcdUtGEYuF9ixd4KtwFZVaadgy8ENe9JSK4o=; b=7LtzVGt6Mv6MBe5WM7Vr44ZZexiXvpI5zua5vzRckIU96fil+oKTsxznRp85A9qmw15tpUeUJqn56ZlHzWfvtdl94wz05TiR++qd61/Rh+QIUbn3111719TjHBrTj7bWuEcpU8FgtY/WxxuK/UtptXIEegz60skzJYOvFg3faWQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: a242202be340aa9d X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NcBL3IvWw1tRx2VjBREMxVo7+VsJ4jt+rZjRD4XhkEXjdx1HEB35TAszNwbZX5/S8wKhm0SWRdgV6yi4d2kW45l9PotuMpqipoLAvjUCYt4lFB3AVzgFqmlg+QhfDm93weRAW4eR2RDNXmLCa3SZlLhVR2EuuQXpIOE8YNpjS2R+U0s2d8YiSl54fuByeShdEfSspOKELppQyNvVQeWt8mDsOYpCFl3T1Rz/JTGLEVaZs599UrCrBKbiXEADcxE7v5wZr6Y6D7kVx+WHFuH8dMRs3BAtLP42xWQ9UiAcHtWkm1v2F6v0/Es0J9IJyJdq1B06RcJevVJE2vOysl9UTA== 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=M1TXqrctcdUtGEYuF9ixd4KtwFZVaadgy8ENe9JSK4o=; b=BiOurEmGP0PA/pzA9GhezVuc+DM8ZTDdwbBDNS+lFp3yKj+6jafA6QuxrMj0yseOukyydi6tj/GCRNsxix8xWlG94hoqY9Ait493RZySDVYyllo+RmbMt6Wbkw15+DJwE7VgJOlxutr6MFjHHvh1KpK05ZSe6VwLGCO5JYd+YEioZ08+kpqwk++/ej5ZazNeG/FVyicabJ1z6WJNjppmutCNIAWiiEEmfeGuBBF0BRS5Y4g6sDqoazQojTPX4QCPLa9hp5NNgflkKWhYbtrVmUTOsJnkt3gcHOiN6Jkl7N9z7/sS2Wx89YDo0qkRQOkDMwhNvdNmqkZWA2fTUZZnuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M1TXqrctcdUtGEYuF9ixd4KtwFZVaadgy8ENe9JSK4o=; b=7LtzVGt6Mv6MBe5WM7Vr44ZZexiXvpI5zua5vzRckIU96fil+oKTsxznRp85A9qmw15tpUeUJqn56ZlHzWfvtdl94wz05TiR++qd61/Rh+QIUbn3111719TjHBrTj7bWuEcpU8FgtY/WxxuK/UtptXIEegz60skzJYOvFg3faWQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 06/13] xen/arm: set up shared memory foreign mapping for borrower domain Date: Fri, 11 Mar 2022 14:11:16 +0800 Message-ID: <20220311061123.1883189-7-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 04f4c9b9-4c8b-4eaf-987c-08da032623b7 X-MS-TrafficTypeDiagnostic: DB6PR0801MB1990:EE_|DB5EUR03FT035:EE_|DBBPR08MB4725:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: LF4XwB9XyzA8qZy0E69YgQwKFLxmp/aAItZajSauBOZVgv4gNkqozkzMPm3Jf2ehAZx7VfgrArpICQT0I3rvD4F9ejV5kBXxy1ZZI8OU2oSd4fwOrkP+7AR93iPysdHFiY9qY62pPXd1oCxnLT4QBYQSUhha712KHo0tZrRKX9Eac5VT8UClOGhuJsDr1RsVwDHk1LqE8nsstdGrCKBXSplvFdQNnUOrIXKM8CPgEORl9NNcJSJmT+vFQ98+kbNkQ2LdQPAb7ejjvLLcrvJLYJc8RdKnp8UictxDKVUsz2QxNJ8n5vviwHvMkgPACoeYJknA1OPXDkHHVwFCJux3izIA2StL+MWTvTUpjkWAXFRbxEycjeV/9ZsecEBl7FjeV3D8wXZgZvlusup2lbsePkJIwqm2ZNReUF5SLZNctPy6GETXZNofamVD5F+U/Slg5Oj/wU5QXTkKgL7WHToN9C9LMxnZcWTiBtg97fNNPCJFpQFcCM5XOUuABQTsulRsfy12+6jjeTEqsxHJ3alC3ZONu6QuWwaoTdJIaecG67o/9yvFQGtWZDmAb1+P/518TmBSxvEt/vG+p4CAcKPjTxPuTxQJYt+tR+Li7lH4qShLAG3UMEUl3HuvQEq7X74jolVsYotGQNe02ZtnpzscGD0CqwQ/Rmp35MJU/ZBWzvmaVQOZ6iDDBhqruwbu4aikRUmfepO60fp8fjN3QLfIWQ== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(316002)(4326008)(82310400004)(8676002)(70586007)(70206006)(5660300002)(36860700001)(2616005)(1076003)(86362001)(336012)(83380400001)(40460700003)(26005)(186003)(426003)(6916009)(54906003)(8936002)(6666004)(7696005)(81166007)(508600001)(356005)(36756003)(2906002)(47076005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1990 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT035.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 31699b1f-39aa-49cd-d14d-08da03261eaa X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DdcUM91qwGrJJkmBHYpAnPwCUP5/boXUaJNpS1zgY9usTBiF+QXisFUpaDyasdr07do2Uh77Kitb8tGEk9FyFjAB2Qr0kYXZRJUxmmDs2dZnOXfdR6DYEf3TCwtfmkLl+GwuinQJWggXiG3qM1vg+wMMBUtPbMF6KjJTtS+alcACaKNwEJT47Qi2QUcb1SyqZBPty5lliXtW7JyVsyNjF6fWulkkBM8ec6m2MBT1md+8G6dNEyjMyw7yDwm8mbv+4UcQ6XN9eAQO3Mx5+GGQgflwyMUMt0nlfe4IRldAGp/8nVFd2TWZemdH8sotlCndMyevG2SYFmj5FRTKmfJgdVo+HcoGDgyFsIWvRzP5JyoiqHYlV9wq9b6xSaSoBdp3xkKtYyh7Ed683Mnc0xWXmeAY4ZxoWj9xwCzKh+9GkXM/Ox92CEEM2hQeTQSKmYbBC2DTL7e0xfGrC84fKprvI2MF/GzatH1n1OsyB/O6ePVD9R1iMNorybwduN1LxWCcM2QPuZRgpDQDqMk5AvKiVEGtXtXlxnVm4oD/iU0E0qZBVkrEGFwoaWvfc8LIoumICn+ZeZlHKMay3ZWUrD7THGR04vOZVEsXq64ux3VANaY+MmZI5F6uVFX/6NH9CZfo1J2Yfi7MeYU6JU+Vk1ToX88MpOGSAbaGgNgt062XO0egTiBBn92+fy/yUV3m7N9L X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(8676002)(47076005)(70586007)(4326008)(70206006)(36860700001)(186003)(2616005)(26005)(107886003)(426003)(336012)(1076003)(83380400001)(81166007)(40460700003)(8936002)(5660300002)(6666004)(508600001)(7696005)(36756003)(82310400004)(316002)(6916009)(86362001)(2906002)(54906003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:36.9065 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04f4c9b9-4c8b-4eaf-987c-08da032623b7 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT035.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4725 From: Penny Zheng This commits introduces a new helper guest_physmap_add_shm to set up shared memory foreign mapping for borrower domain. Firstly it should get and take reference of statically shared pages from owner dom_shared. Then it will setup P2M foreign memory map of these statically shared pages for borrower domain. This commits only considers owner domain is the default dom_shared, the other scenario will be covered in the following patches. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 984e70e5fc..8cee5ffbd1 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -798,6 +798,48 @@ static int __init allocate_shared_memory(struct domain *d, return ret; } +static int __init guest_physmap_add_shm(struct domain *od, struct domain *bd, + unsigned long o_gfn, + unsigned long b_gfn, + unsigned long nr_gfns) +{ + struct page_info **pages = NULL; + p2m_type_t p2mt, t; + int ret = 0; + + pages = xmalloc_array(struct page_info *, nr_gfns); + if ( !pages ) + return -ENOMEM; + + /* + * Take reference of statically shared pages from owner domain. + * Reference will be released when destroying shared memory region. + */ + ret = get_pages_from_gfn(od, o_gfn, nr_gfns, pages, &p2mt, P2M_ALLOC); + if ( ret ) + { + ret = -EINVAL; + goto fail_pages; + } + + if ( p2m_is_ram(p2mt) ) + t = (p2mt == p2m_ram_rw) ? p2m_map_foreign_rw : p2m_map_foreign_ro; + else + { + ret = -EINVAL; + goto fail_pages; + } + + /* Set up guest foreign map. */ + ret = guest_physmap_add_pages(bd, _gfn(b_gfn), page_to_mfn(pages[0]), + nr_gfns, t); + + fail_pages: + xfree(pages); + + return ret; +} + static int __init process_shm(struct domain *d, const struct dt_device_node *node) { @@ -855,6 +897,16 @@ static int __init process_shm(struct domain *d, set_bit(shm_id, shm_mask); } + + /* + * All domains are borrower domains when owner domain is the + * default dom_shared, so here we could just set up P2M foreign + * mapping for borrower domain immediately. + */ + ret = guest_physmap_add_shm(dom_shared, d, PFN_DOWN(pbase), + PFN_DOWN(gbase), PFN_DOWN(psize)); + if ( ret ) + return ret; } return 0; From patchwork Fri Mar 11 06:11:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777481 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 11EC3C433F5 for ; Fri, 11 Mar 2022 06:13:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288717.489740 (Exim 4.92) (envelope-from ) id 1nSYWD-0002L1-G6; Fri, 11 Mar 2022 06:12:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288717.489740; Fri, 11 Mar 2022 06:12:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYWD-0002Kl-9b; Fri, 11 Mar 2022 06:12:53 +0000 Received: by outflank-mailman (input) for mailman id 288717; Fri, 11 Mar 2022 06:12:51 +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 1nSYWB-0000Fh-3y for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:51 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0624.outbound.protection.outlook.com [2a01:111:f400:fe0d::624]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 46ea25c8-a102-11ec-8eba-a37418f5ba1a; Fri, 11 Mar 2022 07:12:50 +0100 (CET) Received: from AM6PR10CA0008.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:89::21) by DB6PR0801MB1960.eurprd08.prod.outlook.com (2603:10a6:4:76::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.19; Fri, 11 Mar 2022 06:12:42 +0000 Received: from AM5EUR03FT031.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:89:cafe::a4) by AM6PR10CA0008.outlook.office365.com (2603:10a6:209:89::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:42 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT031.mail.protection.outlook.com (10.152.16.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:41 +0000 Received: ("Tessian outbound 63bb5eb69ee8:v113"); Fri, 11 Mar 2022 06:12:41 +0000 Received: from ffade54445f8.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 1368B86B-9193-41CD-8161-E823D5739779.1; Fri, 11 Mar 2022 06:12:34 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ffade54445f8.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:34 +0000 Received: from AM6PR10CA0089.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::30) by DB8PR08MB5401.eurprd08.prod.outlook.com (2603:10a6:10:f9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Fri, 11 Mar 2022 06:12:32 +0000 Received: from AM5EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8c:cafe::d2) by AM6PR10CA0089.outlook.office365.com (2603:10a6:209:8c::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Fri, 11 Mar 2022 06:12:32 +0000 Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT060.mail.protection.outlook.com (10.152.16.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.24 via Frontend Transport; Fri, 11 Mar 2022 06:12:31 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:29 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:27 +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: 46ea25c8-a102-11ec-8eba-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=umdxaC9M1LCNOYH4ZpD5ACrl2y60yzal5ReM8dSmiFw=; b=v1V6XNf72S4ItEfdsoAAHY49IK1Fuvm/OQIHJUjVWD1kviXgF8xHrxDV2aUzmBDZMB8HZ3R3ukUhKFSPmQCH8ew1vzGiVWyiAMEo2Hrb2krnTN37wWnoZ5SIKURokGfkK9pCoM+hL4gOM1muyNjFKdWUfTQlFQTRfYFi9uHBuQg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 0a46b8f13a50568b X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fTzOncaUWmi+9/BwTptUX8m9Z5SjS4Ni5WKs/96YjHCwQh/r63kAEbtW2s40+3QbmIeKSWB1eb0Y75MjK7bwBHWfAEfFwKUvurMHHk3eFN3YxFd8lhYsh41xKxuhrOK2PKpdhZF62/c22ijG7l+FSvXfOISps5uOvcf4oz5AETnmpyLlTqqkckdcwsvk962GY1cWfNudm1RLOnU1t5TA5YByI3eOWcatQhwvijLVojQXR0r2NmVWJ53XMzLBwJnNfVwbxFoRjjyY/pnGdH3oKgXPjydN2mWVJh9CIkRE17e9B1hmtos7YJ+ap5S8cfZiCZcHZLf2Qi9QSCsFgCdfZQ== 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=umdxaC9M1LCNOYH4ZpD5ACrl2y60yzal5ReM8dSmiFw=; b=R7Ci329X43kgDR0HmX/5yjIkk7jFayhIQYVd7SqdjarX9yuKKZ5sqqI7rQM81ac7IdrQuqKvtAxk75k9Q9W8+GzrZ6Xd1qHy3ApzQhy0TzELqazUhQy5/exNmkznU3iFjsNHiGRENZDmpTzI+YEIOfbcgSgoWMopD93/hrQpt/bDgg3ItStFL/kr6fXOxu6KLwCybXIdMwqAe7VtoAIpqaNX/9Q+H+wi21y5VTfuiJgBYFK2HCXo/HHjjyeexcrkkHKT57H+CxckDtZXXssBJXJ412taxfoUKjGDt+YYORHYUjmInup78tLLHyXq6i2CnY47exnAoCFG1pDY+UDf0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=umdxaC9M1LCNOYH4ZpD5ACrl2y60yzal5ReM8dSmiFw=; b=v1V6XNf72S4ItEfdsoAAHY49IK1Fuvm/OQIHJUjVWD1kviXgF8xHrxDV2aUzmBDZMB8HZ3R3ukUhKFSPmQCH8ew1vzGiVWyiAMEo2Hrb2krnTN37wWnoZ5SIKURokGfkK9pCoM+hL4gOM1muyNjFKdWUfTQlFQTRfYFi9uHBuQg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 07/13] xen/arm: create shared memory nodes in guest device tree Date: Fri, 11 Mar 2022 14:11:17 +0800 Message-ID: <20220311061123.1883189-8-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: fca68a2e-c460-4a49-24d4-08da03262698 X-MS-TrafficTypeDiagnostic: DB8PR08MB5401:EE_|AM5EUR03FT031:EE_|DB6PR0801MB1960:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: NqVCI8Py2Tl/YEmEjbM6954+uln1tCMjbDp/6ADeJisYK8oJ7EcoiGKkeGSRfoO4/iFPhUWiaaj8z4mF4zFfbvXodW6SeVVRtZQR9zRkktFnQIbXz4pGK48vV8+rCpiWPGy7O10gFCm9LQczN6iVQzrN4Bk+KB4s8HbhC0ZCI4vCwCozyt8NejT9tLw9Fh24xCLswXjI0IBEU5fXX6Hiv8sG/O9/nTBAQeJ1nRWSJ5vHZQCGEngOpl9HWIt+6/NCxoIH0igMIfMjmuSi81ImD+qXV60dFlJUxwIipy8e27cORcB9Jhkq+wRYxEK/YeC2xSZ0LcilA0uMHQ+GIjEyU5Rvh9MIe0LbZ07sFuAhgCVrT3BsJ9KX/In9nyjXK6Qn0kY3LguED2WzU78oHnBB0lYgIczJr/MAldTzMGv0O55rkWw74TdfTQU6JUtm4JKXaUj3Lz1aMJUN/YyT6VjPmffqc16OvD6NEQT+W+5w/6NZkWO0mlHa/oV1iuSpFKCWlA47cwUxu1P7RTAcwzkD9ie6Mz16PIsqvLb80+tv3WQ8iY2n4a7fBpMdi1P6Sj7vYgbK+UsNlg93h8J0POouRdXEvZKEI2K3jn7qNsZYzoD9Ikk9PfHqIORFSDXaJWXKYHZul/IKCJXgsIlfKRezfAl+wcKSbP/YXHmgreIcBe/+njXQlB41KDkWhTtpp+I3gEnzdyW/8nTYDie1+/s8SA== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(1076003)(7696005)(26005)(186003)(8676002)(5660300002)(6666004)(54906003)(70206006)(70586007)(316002)(36756003)(36860700001)(47076005)(82310400004)(508600001)(6916009)(2906002)(4326008)(336012)(426003)(8936002)(2616005)(86362001)(40460700003)(356005)(83380400001)(81166007)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5401 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: d6bf2f15-1bfd-4e8a-a11d-08da03262088 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ea9hoodo56SHdeurQPQ31QV+IXccKAk9oHlcgXovKQNk9IVTybhuyolc7R2J4qbbCzluUu/o+vIS6k6l5UVfkCfozaRGDqMnMqMHiwt/re8NvUkGiTX+mZQ02UhaqYwQB58Kvcb3m9t7ohgNbjzXAS41MaACangvCzEqUU2fWmdVLSs72NGe+LvJ8s1EnFngn6Nzju4KrdVkA+heJGPv6w86FZs/Iv7rNgEwg7a7Ds93Gz+nMq3LF5alyCPX3Obf7//qUzPJDd0M90juyXt/XceZFegadwgdGnmF/3NdnWIlNFyxDg8oyzkajdUP/VB2byMe54wvD2EyFIgTYuZe40ju8TCN8ZOLXoTYyV5JZwfb0Dl95WwVN2xymaVCw+ktj08jllPPI5dmJqr6BCKvWKUti7RvCvNiqszBZk6s0uNBxLMyjQ5bX+uqnRfIql4PE42dOVG99huceBEXKpwHXRYPdVPef4mRzkk4RNlFwFez9pZYSdBWAPkdW9J+cAvpGQXA9+9sPJUgs6Yj5v3vvkbPo0GQYFtJaxormS2UJC99EsnRzFaDib5GJIJW86LhS2P571tG7sdkkcB0IcTrUw6A95em7PVGeIyi5pKmOd+zVDDCAzXfpzgXtMbfPGJpOSD7ZdIhE7ZSea5SwMa7j6EupK/LBhMKnorv51dABH3tQ61Ns7dX7cmlZfjalzvW X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(86362001)(6666004)(40460700003)(47076005)(8936002)(36860700001)(336012)(508600001)(4326008)(2906002)(81166007)(8676002)(7696005)(1076003)(82310400004)(83380400001)(36756003)(186003)(426003)(26005)(6916009)(2616005)(316002)(107886003)(70586007)(70206006)(5660300002)(54906003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:41.6710 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fca68a2e-c460-4a49-24d4-08da03262698 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1960 From: Penny Zheng We expose the shared memory to the domU using the "xen,shared-memory-v1" reserved-memory binding. See Documentation/devicetree/bindings/reserved-memory/xen,shared-memory.txt in Linux for the corresponding device tree binding. To save the cost of re-parsing shared memory device tree configuration when creating shared memory nodes in guest device tree, this commit adds new field "shm_mem" to store shm-info per domain. For each shared memory region, a range is exposed under the /reserved-memory node as a child node. Each range sub-node is named xen-shmem@
and has the following properties: - compatible: compatible = "xen,shared-memory-v1" - reg: the base guest physical address and size of the shared memory region - xen,id: a string that identifies the shared memory region. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 144 ++++++++++++++++++++++++++++++ xen/arch/arm/include/asm/domain.h | 1 + xen/arch/arm/include/asm/setup.h | 3 + 3 files changed, 148 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 8cee5ffbd1..997df46ddd 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -840,6 +840,28 @@ static int __init guest_physmap_add_shm(struct domain *od, struct domain *bd, return ret; } +static int __init append_shm_bank_to_domain(struct domain *d, + paddr_t start, paddr_t size, + u32 shm_id) +{ + /* Allocate memory at first insertion. */ + if ( d->arch.shm_mem == NULL ) + { + d->arch.shm_mem = xmalloc_bytes(sizeof(struct meminfo)); + if ( d->arch.shm_mem == NULL ) + return -ENOMEM; + + memset(d->arch.shm_mem, 0, sizeof(struct meminfo)); + } + + d->arch.shm_mem->bank[d->arch.shm_mem->nr_banks].start = start; + d->arch.shm_mem->bank[d->arch.shm_mem->nr_banks].size = size; + d->arch.shm_mem->bank[d->arch.shm_mem->nr_banks].shm_id = shm_id; + d->arch.shm_mem->nr_banks++; + + return 0; +} + static int __init process_shm(struct domain *d, const struct dt_device_node *node) { @@ -907,6 +929,14 @@ static int __init process_shm(struct domain *d, PFN_DOWN(gbase), PFN_DOWN(psize)); if ( ret ) return ret; + + /* + * Record static shared memory region info for later setting + * up shm-node in guest device tree. + */ + ret = append_shm_bank_to_domain(d, gbase, psize, shm_id); + if ( ret ) + return ret; } return 0; @@ -1237,6 +1267,115 @@ static int __init make_memory_node(const struct domain *d, return res; } +#ifdef CONFIG_STATIC_SHM +static int __init make_shm_memory_node(const struct domain *d, + void *fdt, + int addrcells, int sizecells, + struct meminfo *mem) +{ + unsigned long i = 0; + int res = 0; + int reg_size = addrcells + sizecells; + + if ( mem->nr_banks == 0 ) + return -ENOENT; + + /* + * For each shared memory region, a range is exposed under + * the /reserved-memory node as a child node. Each range sub-node is + * named xen-shmem@
. + */ + dt_dprintk("Create xen-shmem node\n"); + + for ( ; i < mem->nr_banks; i++ ) + { + u64 start = mem->bank[i].start; + u64 size = mem->bank[i].size; + u32 shm_id = mem->bank[i].shm_id; + /* Placeholder for xen-shmem@ + a 64-bit number + \0 */ + char buf[27]; + const char compat[] = "xen,shared-memory-v1"; + __be32 *reg, *cells; + unsigned int len; + + snprintf(buf, sizeof(buf), "xen-shmem@%"PRIx64, mem->bank[i].start); + res = fdt_begin_node(fdt, buf); + if ( res ) + return res; + + res = fdt_property(fdt, "compatible", compat, sizeof(compat)); + if ( res ) + return res; + + len = reg_size * sizeof(__be32); + reg = xmalloc_bytes(len); + if ( reg == NULL ) + return -ENOMEM; + cells = reg; + + dt_child_set_range(&cells, addrcells, sizecells, start, size); + + res = fdt_property(fdt, "reg", reg, len); + xfree(reg); + if (res) + return res; + + dt_dprintk("Shared memory bank %lu: %#"PRIx64"->%#"PRIx64"\n", + i, start, start + size); + + res = fdt_property_cell(fdt, "xen,id", shm_id); + if (res) + return res; + + res = fdt_end_node(fdt); + if (res) + return res; + } + + return res; +} +#else +static int __init make_shm_memory_node(const struct domain *d, + void *fdt, + int addrcells, int sizecells, + struct meminfo *mem) +{ + ASSERT_UNREACHABLE(); +} +#endif + +static int __init make_resv_memory_node(const struct domain *d, + void *fdt, + int addrcells, int sizecells, + struct meminfo *mem) +{ + int res = 0; + /* Placeholder for reserved-memory\0 */ + char resvbuf[16] = "reserved-mem"; + + if ( mem == NULL ) + /* No shared memory provided. */ + return 0; + + dt_dprintk("Create reserved-memory node\n"); + + res = fdt_begin_node(fdt, resvbuf); + if ( res ) + return res; + + res = fdt_property(fdt, "ranges", NULL, 0); + if ( res ) + return res; + + res = make_shm_memory_node(d, fdt, addrcells, sizecells, mem); + if ( res ) + return res; + + res = fdt_end_node(fdt); + + return res; +} + static int __init add_ext_regions(unsigned long s, unsigned long e, void *data) { struct meminfo *ext_regions = data; @@ -2974,6 +3113,11 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) if ( ret ) goto err; + ret = make_resv_memory_node(d, kinfo->fdt, addrcells, sizecells, + d->arch.shm_mem); + if ( ret ) + goto err; + /* * domain_handle_dtb_bootmodule has to be called before the rest of * the device tree is generated because it depends on the value of diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index ea7a7219a3..6df37d2c46 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -110,6 +110,7 @@ struct arch_domain #endif bool directmap; + struct meminfo *shm_mem; } __cacheline_aligned; struct arch_vcpu diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 7a1e1d6798..b6ff04889c 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -27,6 +27,9 @@ struct membank { paddr_t start; paddr_t size; bool xen_domain; /* whether the memory bank is bound to a Xen domain. */ +#ifdef CONFIG_STATIC_SHM + u32 shm_id ; /* ID identifier of a static shared memory bank. */ +#endif }; struct meminfo { From patchwork Fri Mar 11 06:11:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777479 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 2CC47C433F5 for ; Fri, 11 Mar 2022 06:13:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288715.489729 (Exim 4.92) (envelope-from ) id 1nSYW8-0001pN-1b; Fri, 11 Mar 2022 06:12:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288715.489729; Fri, 11 Mar 2022 06:12:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYW7-0001or-Th; Fri, 11 Mar 2022 06:12:47 +0000 Received: by outflank-mailman (input) for mailman id 288715; Fri, 11 Mar 2022 06:12:46 +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 1nSYW6-0008Q3-7v for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:46 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2061a.outbound.protection.outlook.com [2a01:111:f400:7e1b::61a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 444708df-a102-11ec-853a-5f4723681683; Fri, 11 Mar 2022 07:12:45 +0100 (CET) Received: from DB6PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:6:2c::18) by DBBPR08MB4679.eurprd08.prod.outlook.com (2603:10a6:10:db::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Fri, 11 Mar 2022 06:12:43 +0000 Received: from DB5EUR03FT023.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2c:cafe::9a) by DB6PR07CA0104.outlook.office365.com (2603:10a6:6:2c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.7 via Frontend Transport; Fri, 11 Mar 2022 06:12:43 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT023.mail.protection.outlook.com (10.152.20.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:42 +0000 Received: ("Tessian outbound 2877e54fe176:v113"); Fri, 11 Mar 2022 06:12:42 +0000 Received: from 060b85e9f54f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 51A1884C-C79B-4AE8-BF64-A32FC44677CE.1; Fri, 11 Mar 2022 06:12:36 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 060b85e9f54f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:36 +0000 Received: from AS9PR05CA0024.eurprd05.prod.outlook.com (2603:10a6:20b:488::23) by AM4PR08MB2625.eurprd08.prod.outlook.com (2603:10a6:205:e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.25; Fri, 11 Mar 2022 06:12:34 +0000 Received: from AM5EUR03FT019.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:488:cafe::b) by AS9PR05CA0024.outlook.office365.com (2603:10a6:20b:488::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.24 via Frontend Transport; Fri, 11 Mar 2022 06:12:34 +0000 Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT019.mail.protection.outlook.com (10.152.16.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:33 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:32 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:30 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 444708df-a102-11ec-853a-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mDvbp4DWU9mwuztP7cNd08kpIm//piVnKYKpsaKT7q8=; b=ptmRVisctFiB0GYfoxUw6QCjvksNPDZwlzYpffxwd/y2M+0LxK5wgcjsEvRTHP7ObbZOAksfGH12kcA+EQ9xbkQ5Te1NzmH0dZwYv2ejGHDGaHD6JomCM37fyTHmk+mRQNl2z7JA4raqcPmgFI2dA4rWkSv6NtMstqJr+T6ixG4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 6e9c82cd63a216ba X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HKHQZU6BAEOFCsnxBMCyKsL17PtI+Md3T+LB1G+doaikcmSsbXJ3eYoHokzbK0JWyFkQsmLBNRQIQXpZrD4tqd52zoitnILETlWkakfQVHJNPrJ25iz8EcqpDYCjak/sL9FCrrL93kl4W8IfHKSeyQoTV+8fa+zMgR66yEN2Cy+HatKSgG2xg4Ac11JGEkwdKhlVyl5bnIsZ8Fc/Wzmk4KHgVx9B5wg05XJWc270BgmLWL452iSUB3FsQQghvAYLZomB/wm76RnZyJTFnW5rRU6lg4SFZ66rdO9EzJimjCoYPNMgXkRXoePsu0yAH4qX0Szw1eDRgQDOax/SuG65UQ== 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=mDvbp4DWU9mwuztP7cNd08kpIm//piVnKYKpsaKT7q8=; b=dZ3iZHGSP4q7ttNnwAg4fE+gm6bcAkNIajYBh5FO6KpfIpNOvDACDpt2YZHPHHrfCg1Bnjh6hyjREuiDfgdPHKN/Vs/4lPaOSCF0iTHlHIte+8MZEkStgzaJT7SSSYuvaiPG/ZpjkrtIBnU8+qA7VuAB2K02cNMEjTxrWbnpqGqE0W708ZJchckzixd2Kj5B01KyBbnx+FG6Z8LwVR3eyoXFZZ4K0LZgXSrt1LIL8VZW40Hdr6bbcjIa/GRKeXGQ0iotAK/fnIZsnISjKZjvglHi0ZgMaUOVijRXuAExTlAlhG41OO1ppyVU1FWjPDFSlXUqQXN5Yez1MTI+c+e4oQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mDvbp4DWU9mwuztP7cNd08kpIm//piVnKYKpsaKT7q8=; b=ptmRVisctFiB0GYfoxUw6QCjvksNPDZwlzYpffxwd/y2M+0LxK5wgcjsEvRTHP7ObbZOAksfGH12kcA+EQ9xbkQ5Te1NzmH0dZwYv2ejGHDGaHD6JomCM37fyTHmk+mRQNl2z7JA4raqcPmgFI2dA4rWkSv6NtMstqJr+T6ixG4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 08/13] xen/arm: destroy static shared memory when de-construct domain Date: Fri, 11 Mar 2022 14:11:18 +0800 Message-ID: <20220311061123.1883189-9-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: fb207d42-330f-4a15-2948-08da0326274a X-MS-TrafficTypeDiagnostic: AM4PR08MB2625:EE_|DB5EUR03FT023:EE_|DBBPR08MB4679:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: TGbSpeEIE5VRNA00n3Pu4vG9jZX/A0Aj/LJmSqmHF7pHstx8IddaWYs79hs6jm8UFFQMgGY+XUu4JLaPpbFg10Yz2THgCzmO86ox4WLVkoGV9KXKdn/t64WK3l4qwAUoGVX+XK6QXHu7ElPrt7/ifYY9Jj4IBArk2Et0FrEiFJ+aMqzFppO5619xZ2K1QZWHfYZM5ny92Qghw2MLQfivGN0kwUPzla4IUI5zEGjbAYZZXweyUF+bGlT8omeJ28OsHwYizA3brlBInlrTy5wA7a+/NLelYdLGpK9lmftUPIpklVyWoP3sHt21o2BqYzdvfoWZKperyComTGWEo013uqY0ovn6firrosSIXdeR7EctuatLiESvZNec+KqrCnbWI3UFhU0VfbvtQaJmL3U1UQl33SLdaUuBaRKwaSyt4+rqu16LCcltCtOPI75Qcy2TVk5fpJNqVR/MRERZmFvub133r+qX+gwploySiAu76jm3EwMUtu7yVfGcZONE39sofTvV/aLGixsy48ZFzdZ+jHtZSV4FUP1bIJ15UW/4UQGB8chrWDh22bE8q5HlchvXJ90vubAGVxsre5+qbRxHrX2UVb6hVbOerq1ZQ2Rt3VW1LqTFqqiw9CcNYWyYLXFXzeHuAMrLerfAqvH1McKFZGPn9hmv0BD9Y7LYHobn62/8p6ME/FbqMMPZKT1V0i8UST0Y2CTqTCjGz+gK5J9xMg== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(5660300002)(8936002)(2906002)(54906003)(316002)(81166007)(40460700003)(356005)(83380400001)(7696005)(2616005)(1076003)(426003)(186003)(36756003)(336012)(26005)(82310400004)(508600001)(70206006)(4326008)(6666004)(70586007)(36860700001)(86362001)(47076005)(8676002)(6916009)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2625 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 529e58f3-8e77-4d09-657b-08da032621e0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9g5BuyN90jesS9tXOrly9HRYy+u0rQqTurTVmzQMUtFiX3SWo3Fox9ENYo53N+LZAGiQO7j7LA1Uf/L8RdJS7r0SG0FXmzA8T+TNHR/OsPj/G1L/kDWagFi1Y6CoklY+yesF097smG3SHFsR0En+ff2+anLMUbzkZ6Kn25Atk1F2aTcGR+HbtFxv8jKdKejHD1c+/oWZVDnQ1OIDlrkfx2/32eGh+kjveJCDAknnXyqo6eONqo67P1/t/H+Xmc9Nde8VXNi87qH31zronrFGt77ttmxbyZnK3eBmYyGzuFRH6n8z2vaxnXs5vOCJGl5MJCFhObaSotx5qASTWBMmnVv8woKr249/BFDKkomUFXUKHueCXfcPKWf3uU0OvPokkvyXRmkEexwgBb0bj+fXrK547T4PraUb4xB24629Bne0wDhjyFbW0daXsXSp25vH9lt4mDZTepJlDZixdYsJU43ZH8fbCCLqBraSzy7dDA05LJXJLO4L1e+Q87ceYLTERMXDa1XQPZ9hyP0Pw7NghRW7RXwroOh5erJk63Wb+2fATAoBlAsMI+KFhRENaxobeWVMRcrMKncRF0xJu6DU9O/WYJM5rKEj5NOEwFYYSWxnzZ6PaF2lsYY93BGLo9dcyy7L5u2GT1C3icRo9ePYsNK+tBybN7Sfofo7lskocz5gCJbw3PuDMTUlkedEW21I X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(4326008)(83380400001)(107886003)(2616005)(70586007)(70206006)(6916009)(82310400004)(2906002)(81166007)(40460700003)(86362001)(47076005)(8676002)(6666004)(7696005)(316002)(336012)(26005)(186003)(426003)(1076003)(54906003)(36756003)(5660300002)(8936002)(508600001)(36860700001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:42.9158 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fb207d42-330f-4a15-2948-08da0326274a X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4679 From: Penny Zheng This commit introduces a new helper destroy_domain_shm to destroy static shared memory at domain de-construction. This patch only considers the scenario where the owner domain is the default dom_shared, for user-defined owner domain, it will be covered in the following patches. Since all domains are borrower domains, we could simply remove guest P2M foreign mapping of statically shared memory region and drop the reference added at guest_physmap_add_shm. Signed-off-by: Penny Zheng --- xen/arch/arm/domain.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 1ff1df5d3f..f0bfd67fe5 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -993,6 +994,48 @@ static int relinquish_memory(struct domain *d, struct page_list_head *list) return ret; } +#ifdef CONFIG_STATIC_SHM +static int domain_destroy_shm(struct domain *d) +{ + int ret = 0; + unsigned long i = 0UL, j; + + if ( d->arch.shm_mem == NULL ) + return ret; + else + { + for ( ; i < d->arch.shm_mem->nr_banks; i++ ) + { + unsigned long nr_gfns = PFN_DOWN(d->arch.shm_mem->bank[i].size); + gfn_t gfn = gaddr_to_gfn(d->arch.shm_mem->bank[i].start); + + for ( j = 0; j < nr_gfns; j++ ) + { + mfn_t mfn; + + mfn = gfn_to_mfn(d, gfn_add(gfn, j)); + if ( !mfn_valid(mfn) ) + { + dprintk(XENLOG_ERR, + "Domain %pd page number %lx invalid.\n", + d, gfn_x(gfn) + i); + return -EINVAL; + } + + ret = guest_physmap_remove_page(d, gfn_add(gfn, j), mfn, 0); + if ( ret ) + return ret; + + /* Drop the reference. */ + put_page(mfn_to_page(mfn)); + } + } + } + + return ret; +} +#endif + /* * Record the current progress. Subsequent hypercall continuations will * logically restart work from this point. @@ -1039,6 +1082,11 @@ int domain_relinquish_resources(struct domain *d) */ domain_vpl011_deinit(d); +#ifdef CONFIG_STATIC_SHM + ret = domain_destroy_shm(d); + if ( ret ) + return ret; +#endif #ifdef CONFIG_IOREQ_SERVER ioreq_server_destroy_all(d); #endif From patchwork Fri Mar 11 06:11:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777480 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 A1EA2C4332F for ; Fri, 11 Mar 2022 06:13:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288728.489761 (Exim 4.92) (envelope-from ) id 1nSYWI-0003Hp-Jp; Fri, 11 Mar 2022 06:12:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288728.489761; Fri, 11 Mar 2022 06:12:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYWI-0003HY-EK; Fri, 11 Mar 2022 06:12:58 +0000 Received: by outflank-mailman (input) for mailman id 288728; Fri, 11 Mar 2022 06:12: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 1nSYWG-0008Q3-M2 for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:56 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0631.outbound.protection.outlook.com [2a01:111:f400:fe0e::631]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4a2db3e8-a102-11ec-853a-5f4723681683; Fri, 11 Mar 2022 07:12:55 +0100 (CET) Received: from AS8PR04CA0063.eurprd04.prod.outlook.com (2603:10a6:20b:313::8) by VI1PR0801MB1935.eurprd08.prod.outlook.com (2603:10a6:800:87::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Fri, 11 Mar 2022 06:12:51 +0000 Received: from AM5EUR03FT037.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:313:cafe::94) by AS8PR04CA0063.outlook.office365.com (2603:10a6:20b:313::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.18 via Frontend Transport; Fri, 11 Mar 2022 06:12:51 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT037.mail.protection.outlook.com (10.152.17.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:49 +0000 Received: ("Tessian outbound 341d209a0e52:v113"); Fri, 11 Mar 2022 06:12:49 +0000 Received: from 28280eae6570.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 6511A843-2DD5-4832-869F-DB913DB77101.1; Fri, 11 Mar 2022 06:12:43 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 28280eae6570.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:43 +0000 Received: from AM5PR0101CA0030.eurprd01.prod.exchangelabs.com (2603:10a6:206:16::43) by VI1PR08MB3823.eurprd08.prod.outlook.com (2603:10a6:803:c2::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.19; Fri, 11 Mar 2022 06:12:41 +0000 Received: from AM5EUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:16:cafe::be) by AM5PR0101CA0030.outlook.office365.com (2603:10a6:206:16::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Fri, 11 Mar 2022 06:12:41 +0000 Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT059.mail.protection.outlook.com (10.152.17.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.24 via Frontend Transport; Fri, 11 Mar 2022 06:12:38 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:35 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:33 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4a2db3e8-a102-11ec-853a-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6bSp5tvM7rKX9UVcthkuPyrtsBk3BRPoTnoVQ5rFyO8=; b=vokE7VE9Pe134rWz6CfxUcU9dgqMNWt8V4d/IHH/G/qj+rD5RyEO8cWnImnV7SOIKqVIRwOu2f6/bjcrBqwcjbMGMM6jobYUdKmtmDf2YaS/Z1Pmr2QHm3cvy9X7RKqlZBpGJND7DNw8CcwxWz/6U1Qw5jBBuq8tCI3Ds4WBSLk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 74e58dee669366f6 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y+AgXP+2vOov0PBeexjTZBfM7Lp0yQd/i7BkCh8Fn0pvEFIHW4HFq57koUCFabsd7U1lQTGaPjISXsrFKJriRtFnKjNE2kYE1uAFEH/0UYxIwtVTxNUepST5PFREeZLheiHSqHW957yd2q2wuXn84NZLnmBhMBPnwmhILILG5djCSZ6CN+PjrYYoeWdQyIWqH2giHcyx5kknVkxMelkjhT+oT45ApGkixWrqx1X7NIfn4Bb2C5vs2Q4Haap3j/LM8809TP5vC4UJSDekyyG5NcR8eVzQFYt9PJ+5vxCOwKequAnzyFsQv6030oKYZjYfcxa3yHl7lFi4x4al4SYzQg== 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=6bSp5tvM7rKX9UVcthkuPyrtsBk3BRPoTnoVQ5rFyO8=; b=F2yg9B852m+q4m1S0YubZTQMElumoTKR0Js9werY5VLYTopQnvkTRExEsawQ7XPMxIM2f0ytttUf7L3U5zfMVc+f1OuxMk6pOi0NRKHmHgAyYfkC0uunQOVAB+pZySydHmdR4YxLShwljm9sCVXhmZIkO4tIzec7vCoLfjlPSAx45BxGVxzBuSiw6UNmi43F9IoII/Zhj0IbCkAglfjmBvwnXgoRyn/KNK+AIy7DWGhXb3Fq6m4DasouDd83YEckbaHqGDmUKd0ZtwzBbyUqUq+1vTCQkbIifBq4faUoTGPh4bK+4XhSaYHTNwL86sOyyISe2XdelrAW0tG7SkfFkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6bSp5tvM7rKX9UVcthkuPyrtsBk3BRPoTnoVQ5rFyO8=; b=vokE7VE9Pe134rWz6CfxUcU9dgqMNWt8V4d/IHH/G/qj+rD5RyEO8cWnImnV7SOIKqVIRwOu2f6/bjcrBqwcjbMGMM6jobYUdKmtmDf2YaS/Z1Pmr2QHm3cvy9X7RKqlZBpGJND7DNw8CcwxWz/6U1Qw5jBBuq8tCI3Ds4WBSLk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 09/13] xen/arm: enable statically shared memory on Dom0 Date: Fri, 11 Mar 2022 14:11:19 +0800 Message-ID: <20220311061123.1883189-10-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 67d17d15-7a52-4646-f820-08da03262b7c X-MS-TrafficTypeDiagnostic: VI1PR08MB3823:EE_|AM5EUR03FT037:EE_|VI1PR0801MB1935:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: hI7RjNMXdFV6mZWsfP+ofJDy8dmiS5Gpi4U8thMTMpmWBDwO3o/sE2D137AHhecPOhzLQp+7M4mHvhpJBoXk/SeiLgFdIneFuAnf9PP4BZXTl8a+/R5ZcP399oijlwYGPK8vMlJrz855wncZ99FzT327atmW+VGFyDEwngLNdy8AzMMk4JAXui5sAEw7B1lFaFT2sfLX2dRTCH7jehgqC+N66/odRiFUgoWp7hyICvHmycE9NMHYWjbhIdfWNgyBsKIyoG7R3S0+yFi8K6cT9FcDb2muMAEgGGTsPriOnwkaKZix0ajWInk43nL8PfbKc3h1j4gb8xHEH9Og+SaLv5xTyIOK2gXkZKmfgaHL01j7Q2Noysiig7vCtjtpJjdiiDp83JQuJwtLNTMAQmnRRzDNyTqWNAH8i1VKe0Ow+y/hAD1pI4VOH5/ezR2Sc2bs1X4kdrdRyA5bN7qLzNIUUpr446XPCAGMPwQrTkZmHDvgVBLuTHbWA2QVu80F8ip5a8VXOQAuFgI8VxHt3VgSkR4uYsvXXyvav7lx51Gdb0wAaSju0Mi9BOtY4S/rUPLaezmlbb5LcG8aYpVidfYo2r6em7PgtNBe4CS1SDOOWUE6T0IJo2OclYLWLaWx08HTS9fSViz89qdj4qA3/4SMGxCgsRvRTe15VD+Ie0tA892Yrqz8RuW/QIye6cvZ+vuD6fhCcRVxaxbNIzMdtK0mEw== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(86362001)(26005)(336012)(70586007)(426003)(82310400004)(8936002)(186003)(8676002)(316002)(4326008)(508600001)(6666004)(70206006)(356005)(36756003)(1076003)(7696005)(81166007)(36860700001)(5660300002)(2906002)(2616005)(40460700003)(6916009)(54906003)(47076005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3823 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT037.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: ef85de60-c0ba-4312-c22c-08da032624d0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OK8XyJTcI9oA0J33lcHPhn10QNiU6zCb9sfmf7W/wIlRwXJx0SbgDY857oWZGYgiGB3Im6Y8KTqjy5yUp5isWemZnRRiQQqcAKs3HTP66SYRHrx+hDmW8uBf4b9fKWCYjpAcPzwLpLrUfEItSpvM+y1Va0vmPoAxecwJO/L2nnTLWoMV/LN5h1H/l/Th9XhqFEPk+0iKhm/bKre8kHB9PjtM+CoudwmUOZe9NvDZgt1FiD23DWGVcff5yvpwbfOaKsItubGr7qUFcu92eYN6Y3qF5cM6Z0cFgtrAieXYBIpXB5n5eX3sm6cPPhTV2MFijLhrLfWAaO0HBRMF4HDLJZYmflByIHUFobmLL+t+AOi9Tx0UaKfEI3gqE2bCY1tvzHBJAnkQBLTXTyPpeHfrmPsg8M56UyY8hSGQ+6YOdArhyyLzC5HuCNXzowsvvl2J5gJR3MIbi7nMXbRbL2eCVhnvG0rVJQBt5GkkdFvaxcdC/cl51kYI17szes/xRwaohPxUMzfGjwA187F99vHx0HeQoFm9YnqjAxLepdggm0ySx0MXWGb7MNF54UtDziNfIlaQSd3kiyBQFIESpbuUvEn/XwJucUF0yMy7BGmpDu1ldEDtXG9O2uFvF/L529WBjOk1OSEshdqtPao/6fmI33v0YokhbDe5edoE01zZvCLnMnR/AWf0/a/0cMzqRURU X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(70206006)(70586007)(8676002)(36756003)(4326008)(86362001)(54906003)(6916009)(316002)(82310400004)(81166007)(2906002)(8936002)(426003)(186003)(336012)(26005)(40460700003)(1076003)(2616005)(6666004)(508600001)(7696005)(36860700001)(47076005)(107886003)(5660300002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:49.8863 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 67d17d15-7a52-4646-f820-08da03262b7c X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT037.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1935 From: Penny Zheng To add statically shared memory nodes in Dom0, user shall put according static shared memory configuration under /chosen node. This commit adds shm-processing function process_shm in construct_dom0 to enable statically shared memory on Dom0. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 997df46ddd..d35f98ff9c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2561,6 +2561,11 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo, if ( res ) return res; } + + res = make_resv_memory_node(d, kinfo->fdt, addrcells, sizecells, + d->arch.shm_mem); + if ( res ) + return res; } res = fdt_end_node(kinfo->fdt); @@ -3572,6 +3577,9 @@ static int __init construct_dom0(struct domain *d) { struct kernel_info kinfo = {}; int rc; +#ifdef CONFIG_STATIC_SHM + const struct dt_device_node *chosen = dt_find_node_by_path("/chosen"); +#endif /* Sanity! */ BUG_ON(d->domain_id != 0); @@ -3606,6 +3614,12 @@ static int __init construct_dom0(struct domain *d) allocate_memory_11(d, &kinfo); find_gnttab_region(d, &kinfo); +#ifdef CONFIG_STATIC_SHM + rc = process_shm(d, chosen); + if ( rc < 0 ) + return rc; +#endif + /* Map extra GIC MMIO, irqs and other hw stuffs to dom0. */ rc = gic_map_hwdom_extra_mappings(d); if ( rc < 0 ) From patchwork Fri Mar 11 06:11:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777482 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 DEDB0C433EF for ; Fri, 11 Mar 2022 06:13:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288730.489766 (Exim 4.92) (envelope-from ) id 1nSYWJ-0003Qq-CV; Fri, 11 Mar 2022 06:12:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288730.489766; Fri, 11 Mar 2022 06:12: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 1nSYWJ-0003Og-3G; Fri, 11 Mar 2022 06:12:59 +0000 Received: by outflank-mailman (input) for mailman id 288730; Fri, 11 Mar 2022 06:12:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYWI-0000Fh-2k for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:12:58 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on062b.outbound.protection.outlook.com [2a01:111:f400:fe0c::62b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4b9893b1-a102-11ec-8eba-a37418f5ba1a; Fri, 11 Mar 2022 07:12:57 +0100 (CET) Received: from AS9PR0301CA0029.eurprd03.prod.outlook.com (2603:10a6:20b:468::10) by AM9PR08MB7242.eurprd08.prod.outlook.com (2603:10a6:20b:431::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 06:12:55 +0000 Received: from VE1EUR03FT055.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:468:cafe::9c) by AS9PR0301CA0029.outlook.office365.com (2603:10a6:20b:468::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.23 via Frontend Transport; Fri, 11 Mar 2022 06:12:55 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT055.mail.protection.outlook.com (10.152.19.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:54 +0000 Received: ("Tessian outbound 18e50a6f0513:v113"); Fri, 11 Mar 2022 06:12:54 +0000 Received: from 94a5c30b510f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 62079C2C-621B-4092-BC66-B8A5B84068C8.1; Fri, 11 Mar 2022 06:12:48 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 94a5c30b510f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:48 +0000 Received: from AS9PR06CA0202.eurprd06.prod.outlook.com (2603:10a6:20b:45d::32) by AM0PR08MB3538.eurprd08.prod.outlook.com (2603:10a6:208:de::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.19; Fri, 11 Mar 2022 06:12:45 +0000 Received: from VE1EUR03FT029.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45d:cafe::35) by AS9PR06CA0202.outlook.office365.com (2603:10a6:20b:45d::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Fri, 11 Mar 2022 06:12:45 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT029.mail.protection.outlook.com (10.152.18.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:40 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:37 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:35 +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: 4b9893b1-a102-11ec-8eba-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QR0uJjdb78Gry1GYCYAG5IJdQ9AYTo5LJTpZNi0Eqhs=; b=FYgLgsUZUv+JJpq18/N0tth/RcX5GPbaGpcKI74v4AC5yJWrmuy3PH9/7FvPTiBo97d91FbqhuyJn5uaNx0SliX3BIyG66gUr+ozFJQm12dYjo/Wza0tbhcnQwaFj/hR+dw7RtGafNDbLz164L/QDPRG+m89NhoDDx0jy0i0/O8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 4548e821d9660e39 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oHu5dKgOJ+pgs8bNfw/cSrIDupk6kfjdTGZDEyT/Wl9H7QUCSOZvzEPvy4KZ6djM90bskw67q3fuNIm/g2Q3Yi9zteaWZR2M02ryl8utJR40ooJoWoEW5wbnOFaC4F2XYQSh/ytqM1agPb1QSiZWPlU1QALOjkqMmeg9wLcwRvh18ajfs40ifSL8kXWWMkDgT4ZvcCFwDVZyKsHMqA4U1yOfGlPDzJRXiW4Q4tqFg4t9E74vK/GnFoX+0x+xn5m2yY0Ozooh0qo11GUAOKcL3nZQpQx9DAz1Ck+1FEuF45AnntY8xOx4z62IG8nAglLDVQXWwBMly2VBcyQdKc5ZCw== 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=QR0uJjdb78Gry1GYCYAG5IJdQ9AYTo5LJTpZNi0Eqhs=; b=XraXeDJXZ/zfLgwdOHGgrydQjBK7N2CXPqdy5XwAGnccLRNcaOWO/EkRSRzZM1VnB0E5Ui/1IZ8T+GrHkPi2zkXnybtw2wN1231xEgmYrfkv7zWgXoLAmJQyZKimMDtDYSidvK07DZvM1pXlNWrTpd6ro9GDh6ACtFVf/0HGv8lUPvb8ATguRaih7o0uqZIQvRlkBIDtDoEerL7TthysMqXXgLWXuRBOSBX6FFf4L9dslSAcYSM0w7Uu+AvQSVYmylXsuaNRh8XdCtiW8q1uPkGN/3PNHOFIF9I2Y6fP1q705quWnHNUeEwcoU/ErWKnZN8A2EdAbAaZRSYpO5gA3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QR0uJjdb78Gry1GYCYAG5IJdQ9AYTo5LJTpZNi0Eqhs=; b=FYgLgsUZUv+JJpq18/N0tth/RcX5GPbaGpcKI74v4AC5yJWrmuy3PH9/7FvPTiBo97d91FbqhuyJn5uaNx0SliX3BIyG66gUr+ozFJQm12dYjo/Wza0tbhcnQwaFj/hR+dw7RtGafNDbLz164L/QDPRG+m89NhoDDx0jy0i0/O8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 10/13] xen/arm: allocate static shared memory to a specific owner domain Date: Fri, 11 Mar 2022 14:11:20 +0800 Message-ID: <20220311061123.1883189-11-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: b5f6e165-4fe1-48a7-322f-08da03262e71 X-MS-TrafficTypeDiagnostic: AM0PR08MB3538:EE_|VE1EUR03FT055:EE_|AM9PR08MB7242:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Hwd/enHFjuwu92cp1BUG45IWh3ykmfgLmPkLJvxytDl4KiW1LL142jjZrrIoQ42oFAkDgAi4PTyDVkVqKMYzM6qNMH+S7hzSZNCkpExGFiAV7Omam61I20QgbuYcfPWF0JkUa0csnOvO45CiwTP1Tny+AroC5uUs0jvR/5Tqs2u1BBJ6JNEqZYRrwFXyfwfqQEVUg5VjgT1/kIpZthSlpKx24ec/aNMmA1XsaOp9pLWeEdBMJ2h+EWM9RLTjtUzrdIKPaV/kT8xVJLSbUm+AN73wGYy2PIdqY7+8clVsNDP+s+1U1emO744bptIAOVGp0KXUaKaJOYMlsKAfBGFhDqkqyutBjqVkadpGZ8YcMR2+trmraAViptdgLVwpLpui7TN9Oi+uetU7RkFvYpK84IAd3Ds6w/z4+28lQdsYvsIT8FKKXJdsaGWlMRu5ZIj8v2ELPgrMiQ9JCOkXxp9710DKSLmbIY07Ops09Y+/lJLPJAyYat1BWIE0aIX3zcjmLhdr4HzG6f/85FK0yYya6S8QDOm87wHi+hu5NrnGDTtrVrUH42lxsnTkCUPJbbqrvOvH602xUK4W4ny2hH65hnwU+Sfx+GCxJUbTUGKIFb9PUEucs+D1KgqS5HsF8c7ezlwJ9n5TeSpJ1zJyVKtW5bDetNCesotF2gounNqezkV3U8kCnrXcL6PpOC9RQEmLHogVIQt7rfAeqFXMUTctQw== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(54906003)(1076003)(356005)(82310400004)(6916009)(316002)(2616005)(7696005)(5660300002)(81166007)(8676002)(83380400001)(8936002)(6666004)(336012)(426003)(508600001)(86362001)(47076005)(4326008)(36860700001)(36756003)(40460700003)(186003)(2906002)(70586007)(26005)(70206006)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3538 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 3bd64e54-2636-42ae-3e63-08da032625a7 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YGl2/V5IRFTiy03csL5xcXQg4/CMlY/fhdx2D23vRQD95Z7h4syvNiUsqA/oSqQnzRZdGrb+IUdjmVBLGSkH1cQZhr019IAFFS9Ayw4V3nHUnXuqV/UpM++1p+WP3F9jCaB77CtrxCeA8mjMlqsP81YfIrqk732wqorZokT7Kry1jRZvOwfMUsReJM6sCJySCyRgonxtnGMR3WFiMxndsUeQPD0f0Be+lm/k/5/zo3AcTzISF/24HdQS5QOJS89fdbYl3REFbNnCE88eiz8cg1KtGOE9PPItkI6CTY2+FjFq2U3ouXdQ5CuWObVkycciKx0Juu4BM+k7fRnYF1YMuTAbrsmk8FQleQyntvrFc6oaRu6ZxqH0EHInZ8Ki/s8TqmCt4R2MOnvuGb5axWnDqJLTEEODmfymyLaDIMMqYfGzNdtBfDOVlUd1rF7DhJn4n5MH9YkI2J6jooss9ad8ypzfInJW1OywiPko+RIodFD2kodtO99ykIzoTxN62Flot1WqbXefZ+OXnBfNqDIAF+Xm4Q5yui6S3O4A/4QECYK63uKT/h0hNo2Xdhd3Fn1esYf1d5Fcc6IRhbndeE5Zh/qZpjBiVUcryAfVvnEOXrzIVAi4Rxm4e3crdoWE41LI0AkhnSf1f9rUIuOVUXkjCbOKUtIVCdYp5BTxUVOZnS2u1mvykXYzvxe99gwhbjTuHVauZXBuF0JeQFHf8SdfAihKCDtlCrn5QGVubhQ2TFo= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(8936002)(70586007)(2906002)(508600001)(316002)(36756003)(186003)(82310400004)(426003)(6666004)(7696005)(2616005)(26005)(1076003)(107886003)(47076005)(40460700003)(83380400001)(336012)(8676002)(70206006)(54906003)(4326008)(6916009)(36860700001)(5660300002)(81166007)(86362001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:54.8063 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5f6e165-4fe1-48a7-322f-08da03262e71 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB7242 From: Penny Zheng If owner property is defined, then owner domain of a static shared memory region is not the default dom_shared anymore, but a specific domain. This commit implements allocating static shared memory to a specific domain when owner property is defined. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 63 ++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d35f98ff9c..7ee4d33e0b 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -872,6 +872,8 @@ static int __init process_shm(struct domain *d, u32 shm_id; u32 addr_cells, size_cells; paddr_t gbase, pbase, psize; + const char *role_str; + bool owner_dom_shared = true; dt_for_each_child_node(node, shm_node) { @@ -899,6 +901,13 @@ static int __init process_shm(struct domain *d, gbase = dt_read_number(cells, addr_cells); /* TODO: Consider owner domain is not the default dom_shared. */ + /* + * "role" property is optional and if it is defined explicitly, + * so the owner domain is not the default "dom_shared" domain. + */ + if ( dt_property_read_string(shm_node, "role", &role_str) == 0 ) + owner_dom_shared = false; + /* * Per shared memory region could be shared between multiple domains. * In case re-allocating the same shared memory region, we use bitmask @@ -907,17 +916,38 @@ static int __init process_shm(struct domain *d, */ if ( !test_bit(shm_id, shm_mask) ) { - /* - * Allocate statically shared pages to the default dom_shared. - * Set up P2M, and dom_shared is a direct-map domain, - * so GFN == PFN. - */ - ret = allocate_shared_memory(dom_shared, addr_cells, size_cells, - pbase, psize, pbase); - if ( ret ) - return ret; - - set_bit(shm_id, shm_mask); + if ( !owner_dom_shared ) + { + if ( strcmp(role_str, "owner") == 0 ) + { + /* + * Allocate statically shared pages to a specific owner + * domain. + */ + ret = allocate_shared_memory(d, shm_id, addr_cells, + size_cells, pbase, psize, + gbase); + if ( ret ) + return ret; + + set_bit(shm_id, shm_mask); + } + } + else + { + /* + * Allocate statically shared pages to the default dom_shared. + * Set up P2M, and dom_shared is a direct-map domain, + * so GFN == PFN. + */ + ret = allocate_shared_memory(dom_shared, shm_id, + addr_cells, size_cells, pbase, + psize, pbase); + if ( ret ) + return ret; + + set_bit(shm_id, shm_mask); + } } /* @@ -925,10 +955,13 @@ static int __init process_shm(struct domain *d, * default dom_shared, so here we could just set up P2M foreign * mapping for borrower domain immediately. */ - ret = guest_physmap_add_shm(dom_shared, d, PFN_DOWN(pbase), - PFN_DOWN(gbase), PFN_DOWN(psize)); - if ( ret ) - return ret; + if ( owner_dom_shared ) + { + ret = guest_physmap_add_shm(dom_shared, d, PFN_DOWN(pbase), + PFN_DOWN(gbase), PFN_DOWN(psize)); + if ( ret ) + return ret; + } /* * Record static shared memory region info for later setting From patchwork Fri Mar 11 06:11:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777485 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 2A616C433F5 for ; Fri, 11 Mar 2022 06:16:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288759.489795 (Exim 4.92) (envelope-from ) id 1nSYZf-00072M-Do; Fri, 11 Mar 2022 06:16:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288759.489795; Fri, 11 Mar 2022 06:16:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYZf-00072D-AU; Fri, 11 Mar 2022 06:16:27 +0000 Received: by outflank-mailman (input) for mailman id 288759; Fri, 11 Mar 2022 06:16:26 +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 1nSYWO-0008Q3-Gn for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:13:04 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on20605.outbound.protection.outlook.com [2a01:111:f400:7d00::605]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4ea01581-a102-11ec-853a-5f4723681683; Fri, 11 Mar 2022 07:13:02 +0100 (CET) Received: from AS9PR04CA0107.eurprd04.prod.outlook.com (2603:10a6:20b:50e::19) by AM8PR08MB6433.eurprd08.prod.outlook.com (2603:10a6:20b:36b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Fri, 11 Mar 2022 06:12:58 +0000 Received: from VE1EUR03FT010.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:50e:cafe::fc) by AS9PR04CA0107.outlook.office365.com (2603:10a6:20b:50e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.24 via Frontend Transport; Fri, 11 Mar 2022 06:12:58 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT010.mail.protection.outlook.com (10.152.18.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:57 +0000 Received: ("Tessian outbound 341d209a0e52:v113"); Fri, 11 Mar 2022 06:12:57 +0000 Received: from 72911b43b740.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D503CA3B-063E-4A24-9456-542ADE790B96.1; Fri, 11 Mar 2022 06:12:50 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 72911b43b740.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:50 +0000 Received: from AS9PR06CA0209.eurprd06.prod.outlook.com (2603:10a6:20b:45d::14) by AS8PR08MB6744.eurprd08.prod.outlook.com (2603:10a6:20b:397::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Fri, 11 Mar 2022 06:12:49 +0000 Received: from VE1EUR03FT029.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45d:cafe::a2) by AS9PR06CA0209.outlook.office365.com (2603:10a6:20b:45d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:49 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT029.mail.protection.outlook.com (10.152.18.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:49 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:40 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:38 +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: 4ea01581-a102-11ec-853a-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GHzNODlA8XFx6CtjhuogInLZztAvYsmJNbcr6OVan/s=; b=Y/1NVxZ1E5Mc/sCB41/i3FsXtlVVTLHavshd+Mc28BQ3lzYpVWz9Cfd4V0zTI7zxBZ+3hFl6hidGH+kQEFIRfbxtL9o0Kqa+u4ph90tF81ZiuqJCOzv9Jorb3OjYs9oU5FGtENR1IVCFqQMtkakuxX8Tz1SBIxQMPnkcPxn877M= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 1c88ce1e8792f6c7 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nHjZnPQGR6vT2b//6gT3RJ7a4mApyEWbIMoiX1lBiyY+gDhxj9IPlgL8z0nB0qGetNlZFWcjqRg7N/EFkXdQ/+U2hGzbwf2PZc3TdZBgIXltredigv+hDI19Ny7KsI9pGBk5V41kST4m/vkRDUVRSY63T8u+8QBcbyvvbvkuAaQGoUu94kqGztXUygIrO6/PdTcnBj+V2olKy7Wbj4UYyRkb5GCiif/ELydsoxZ/2ujh6C7gnmYDKWgB6Q15iTvQD/1ikgjZCMcYYkcuP6zBLhgAgDfrP3Hmg1Jm98PdcAjy9ZCRePbMcVC0q3oKP3WPblK0+q3DVzwnZkvlmxeQ9g== 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=GHzNODlA8XFx6CtjhuogInLZztAvYsmJNbcr6OVan/s=; b=PvLWA++5/l1ZqLySqabS7OTUcUqYWPpp4t1aAdJdDY7A+YfYZXFckd1V7HkbrhU1qtf3Q/dzQDNEuf4mOO12QRRDM6ihljz6AxsdEYECOu7eDwYZh3aJ7dnNT0sQRH0c7gxI68YUrhpeNTJVrQsj0KHfs154iKo4fpuHEvamzOErEhDKkiHSUobl1c2NhprPVum8SeIasiJKLLaTgir85K6iV4Chz6TcDOm+fDO7iLQTGE/z3EMVxxYnRT0H/ihKb+hYEIfXoyPUu260vBAs09eNXdQyCVmSfhB+sa6FELZu1LDK5wJpgbzyugoSPJ9fshyl6iFrvvCTMmbADHj1PQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GHzNODlA8XFx6CtjhuogInLZztAvYsmJNbcr6OVan/s=; b=Y/1NVxZ1E5Mc/sCB41/i3FsXtlVVTLHavshd+Mc28BQ3lzYpVWz9Cfd4V0zTI7zxBZ+3hFl6hidGH+kQEFIRfbxtL9o0Kqa+u4ph90tF81ZiuqJCOzv9Jorb3OjYs9oU5FGtENR1IVCFqQMtkakuxX8Tz1SBIxQMPnkcPxn877M= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 11/13] xen/arm: store shm-info for deferred foreign memory map Date: Fri, 11 Mar 2022 14:11:21 +0800 Message-ID: <20220311061123.1883189-12-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 6d96fbbe-a24b-4f3d-ed69-08da03263036 X-MS-TrafficTypeDiagnostic: AS8PR08MB6744:EE_|VE1EUR03FT010:EE_|AM8PR08MB6433:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: JEBS0f4v+iM5xNbUs+L13Q4fX4gPJ4ixcOZfmaM9IB1fvyMu3W3t51Biave4BCG44IwjgtinSjoy7Bi1MQpBxJjHQ07CyE/kYqk01g+wV8K+NFwL5ZmFFSrWj4q1CXK6HKtjHl0ENvF/ElAKsPivP+/POQ+3mIIzNX80ha+bwF4y1EL8rDUEw3imnc1CEFl8ycBjXnDu0GVxcRyMGc08v3hnpL86mgr8aiMfyUpkIzOGIN1JfEGwOs3rjrFD2lk6OvLcKwMA/TV3jZpNeroC1u2gJyE7jAnnY+N3Q64IwZSjRboyvULFffkE5eoEIha+5q+jKnZ1vOu+DN7GMK3KbqiQ7Uh8z8IVsqUjbigd60XZzi580S/ZHzvKsapyC6lMstOM4uWNHfpUjetWA1AO5ELTOPwaw++AhtWRtT8kb5twe9V0JNTG5wNQI87MmTGejvVNyk27+Y+GOzq/kLhA2uPdeZpZPc3GltPudp9Zua4QuhSP2BMJAjMq6LrmTd7AYvapMk/xk2tYCMiLL7Plidx7M1e2wZ24OwSBayJS/ib/0KW/73UR5P7zAw4RgWJ3DKXymTq/fnQGvtY60GdtIfNcJ6vbsZHeCo6IiAFlhijyz3/yAFM+Eu4usmm5xpoJ5LJOxBmz2SbOKhovDpq7zlei235Q5ieV81a7s6Yb6Yxh1Y0Idgd7mdM2Vx4YETUe2b1dNNKcqfJCvnNHzM/pQg== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(47076005)(83380400001)(508600001)(5660300002)(82310400004)(8936002)(6666004)(7696005)(70206006)(36860700001)(2906002)(70586007)(426003)(4326008)(8676002)(1076003)(2616005)(336012)(186003)(26005)(86362001)(36756003)(40460700003)(316002)(356005)(81166007)(6916009)(54906003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6744 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT010.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: efc1c244-41de-4514-78b9-08da03262b04 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vz5PxjbypBpLD4FIRVZDURRwxw0w3Ty81Mpn9SyTEo+/cjwL7lLYh/Cm3n79s2wYGc7yw7rsneatr0k7p7xTM07NZp8vfj2XO/nAgs/Eq6ea/wp6cpOwMhavyO30w9kPFIpqid5zPgQEdzFUpaLS8Qo+QrgCwBNe1R0Juoz550Fdknv1HEAL6rUEWJ9NSaAVTUZ9UxJiLF99pYQQ7zQ77UkKsLna6bwJY9UZF8Vp3LAeVY4pVViCEEQnrg2LqcHm65qfT5nmWdJbh7+6C32FZEp/F1Uoh6BJ70fuOz9HqYF1O6miPEbfgNACEj0FKVr9qUWF7RJfd7icHlFfZWCMoiCV8sWdhYSE0r1DFVdU4NtwrseaH7RD9AH3yE9Tul/Exs94+iDu/5k5ngOkjuqyrMV384ZvWk4Qlm3FbzNOJQMcW2c2f59BDM/xKoxOQPnv356aKUohD/l3oCUXXLGUtiCaA9vCXNXs80JD1noU5eJcxqo4rKZpCSoCY1x6nDhkvkgfUZ/1mkIjmjH+/CcGjcJYOYW3n9WDpzZRnTGpkNoEW6XXdmoQg6vPYJjWn0cx7+HiBbCXspgP+f+1CTsqGUl8H4A4IgFJQiofhYqMfiTYKxpIqjnKKvwv5TAX/IMXPy3zCl3mKWwS4xPRjjZwxYZDXPTTiWBoPPgE9vphgOPoIicxW40Y/gtI6XiZyiM8 X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(7696005)(6666004)(2616005)(186003)(36860700001)(107886003)(26005)(1076003)(426003)(82310400004)(336012)(83380400001)(36756003)(2906002)(8936002)(5660300002)(40460700003)(8676002)(47076005)(4326008)(54906003)(6916009)(316002)(508600001)(70206006)(70586007)(86362001)(81166007);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:12:57.7799 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d96fbbe-a24b-4f3d-ed69-08da03263036 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT010.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6433 From: Penny Zheng In a few scenarios where owner domain, is defined after borrower domain in device tree configuration, then statically shared pages haven't been properly allocated if borrower domain tries to do foreign memory map during domain construction. In order to cover such scenario, we defer all borrower domains' foreign memory map after all domain construction finished, then only need to store shm-info during domain construction. Signed-off-by: Penny Zheng --- xen/arch/arm/domain.c | 3 +++ xen/arch/arm/domain_build.c | 34 ++++++++++++++++++++++++++++++- xen/arch/arm/include/asm/domain.h | 25 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index f0bfd67fe5..73ffbfb918 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -47,6 +47,9 @@ DEFINE_PER_CPU(struct vcpu *, curr_vcpu); #ifdef CONFIG_STATIC_SHM struct domain *__read_mostly dom_shared; + +shm_info_t shm_list[NR_MEM_BANKS]; +DECLARE_BITMAP(shm_list_mask, NR_MEM_BANKS); #endif static void do_idle(void) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 7ee4d33e0b..4b19160674 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -771,7 +771,7 @@ static mfn_t __init acquire_shared_memory_bank(struct domain *d, } -static int __init allocate_shared_memory(struct domain *d, +static int __init allocate_shared_memory(struct domain *d, u32 shm_id, u32 addr_cells, u32 size_cells, paddr_t pbase, paddr_t psize, paddr_t gbase) @@ -795,6 +795,18 @@ static int __init allocate_shared_memory(struct domain *d, return ret; } + /* + * If owner domain is not default dom_shared, shm-info of owner domain + * shall also be recorded for later deferred foreign memory map. + */ + if ( d != dom_shared ) + { + shm_list[shm_id].owner_dom = d->domain_id; + shm_list[shm_id].owner_gbase = gbase; + shm_list[shm_id].size = psize; + set_bit(shm_id, shm_list_mask); + } + return ret; } @@ -962,6 +974,26 @@ static int __init process_shm(struct domain *d, if ( ret ) return ret; } + else + { + if ( strcmp(role_str, "borrower") == 0 ) + { + /* + * In a few scenarios where owner domain, is defined after + * borrower domain in device tree configuration, statically + * shared pages haven't been properly allocated if borrower + * domain here tries to do foreign memory map. + * In order to cover such scenario, we defer all borrower + * domains'foreign memory map after all domain construction + * finished, and only store shm-info here for later use. + */ + shm_list[shm_id].borrower_dom[shm_list[shm_id].nr_borrower] = + d->domain_id; + shm_list[shm_id].borrower_gbase[shm_list[shm_id].nr_borrower] = + gbase; + shm_list[shm_id].nr_borrower++; + } + } /* * Record static shared memory region info for later setting diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index 6df37d2c46..1c0f2e22ca 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -10,6 +10,7 @@ #include #include #include +#include #include struct hvm_domain @@ -33,6 +34,30 @@ enum domain_type { #ifdef CONFIG_STATIC_SHM extern struct domain *dom_shared; + +/* Maximum number of borrower domains. */ +#define NR_SHM_DOMAIN 32 +/* + * shm_list is indexed by unique identifier "xen,shm-id", but it only stores + * a subset of static shared memory regions, of which owner domain is not the + * default dom_shared. + * shm_list_mask bitmask is to record the position of these static shared + * memory regions. + * Per bit represents a entry in shm_list, and setting it 1 means the + * static shared memory region here is owned by a specific domain, then bit 0 + * means the static shared memory region here is either owned by the default + * dom_shared or no static shared memory region here at all. + */ +typedef struct { + domid_t owner_dom; + paddr_t owner_gbase; + paddr_t size; + domid_t borrower_dom[NR_SHM_DOMAIN]; + paddr_t borrower_gbase[NR_SHM_DOMAIN]; + unsigned long nr_borrower; +} shm_info_t; +extern shm_info_t shm_list[NR_MEM_BANKS]; +extern unsigned long shm_list_mask[BITS_TO_LONGS(NR_MEM_BANKS)]; #else #define dom_shared NULL #endif From patchwork Fri Mar 11 06:11:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777486 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 DFCA5C433EF for ; Fri, 11 Mar 2022 06:16:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288773.489806 (Exim 4.92) (envelope-from ) id 1nSYZx-0007lo-Nz; Fri, 11 Mar 2022 06:16:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288773.489806; Fri, 11 Mar 2022 06:16:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nSYZx-0007lD-K9; Fri, 11 Mar 2022 06:16:45 +0000 Received: by outflank-mailman (input) for mailman id 288773; Fri, 11 Mar 2022 06:16:44 +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 1nSYWS-0008Q3-Cy for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:13:08 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2062b.outbound.protection.outlook.com [2a01:111:f400:7d00::62b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 511f6752-a102-11ec-853a-5f4723681683; Fri, 11 Mar 2022 07:13:07 +0100 (CET) Received: from AM5PR1001CA0021.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:2::34) by DB7PR08MB3067.eurprd08.prod.outlook.com (2603:10a6:5:1d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.16; Fri, 11 Mar 2022 06:13:02 +0000 Received: from VE1EUR03FT019.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:2:cafe::10) by AM5PR1001CA0021.outlook.office365.com (2603:10a6:206:2::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Fri, 11 Mar 2022 06:13:02 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT019.mail.protection.outlook.com (10.152.18.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:13:01 +0000 Received: ("Tessian outbound 18e50a6f0513:v113"); Fri, 11 Mar 2022 06:13:01 +0000 Received: from e580bba4a969.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id B64F63F4-0DB4-4524-AAEA-BA24E649C067.1; Fri, 11 Mar 2022 06:12:54 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e580bba4a969.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:12:54 +0000 Received: from AS9PR06CA0188.eurprd06.prod.outlook.com (2603:10a6:20b:45d::15) by DB9PR08MB7493.eurprd08.prod.outlook.com (2603:10a6:10:36e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 06:12:53 +0000 Received: from VE1EUR03FT029.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45d:cafe::c1) by AS9PR06CA0188.outlook.office365.com (2603:10a6:20b:45d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Fri, 11 Mar 2022 06:12:53 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT029.mail.protection.outlook.com (10.152.18.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:12:52 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:43 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:41 +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: 511f6752-a102-11ec-853a-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JPsPOvzho2nUCB0RDRsUprWjaTqQDf6F4G+auSec2gA=; b=zEXBBooENPXWwekxMPsivO4mQ9vcO7ewOle//u+gAAEZcndROf8GcjflzM9v9jm/hXGZHT2tQUZynTKLhv2GOddP7J2NpQox/+p9BYkvPy0/R+pg/wCYH71YBN/lT7e3Ly+YP0kBpIRU1ph/aa6xBtthRHm/Czs5BhKAltRJvUk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 08a5aae35ab4c662 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lp16z6s2RNHzOatsFZZSsANhotpnk41e3Gd5cV9oIOJx4xPonMx+e3y83lKDganBe4i0CFQ8xLL+uHANPQCr3Z+kHQV+8wSdStHS66Sztd5qtEvZU2NFBPdeEknIqnS7RnhKDuWiggrVAojux34RUZMmCYQE/kIYjZ/BuLPStxHIfpBLcVJwNEy8l45hglxkqxJlC5dh5audxcksB06gh35cCPbhjz4h630qFaYt14DxfD1uIBdGV0hl1NQhMq3knDpA8dgaICxkbWEKIFn2V/zmGgOoZAV995Hzo6H40YI/DxwQEsaJkz3z5e1RgD04XmrMo8ZshQF7sXOvomcHRQ== 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=JPsPOvzho2nUCB0RDRsUprWjaTqQDf6F4G+auSec2gA=; b=TpDq0G5H+cW6Zig2cadDJLIAc6WBP/xVoy+at+5Okb7G8wLhbHkYHBs8jDPY1+NSs1YoGXyFpcpdDCHfLKo/+J6+LLX3q3OR1vbmBevHc1ZLIMcYaHBlU/wKc6PAa3HP+Te/ZuPkH4SrnkmYLaYdjJCQvX7RqxOvkJKanyUXJrrPlBdc9OZzP6Lb+5rrTfk3w/zVKUofRnO0IQ4WWeU5ce3M2roM0qxBNU3CkjFPQ0LcRWmKAiDPxarBQF0fLMU5hitOunH106AgKmbRiy2TURjPXz6FZvbV2GJHyMJpFD2jfh01RaM0gdNPrM3Z/jPtbTG1Gd552KQAMgrfdvTaNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JPsPOvzho2nUCB0RDRsUprWjaTqQDf6F4G+auSec2gA=; b=zEXBBooENPXWwekxMPsivO4mQ9vcO7ewOle//u+gAAEZcndROf8GcjflzM9v9jm/hXGZHT2tQUZynTKLhv2GOddP7J2NpQox/+p9BYkvPy0/R+pg/wCYH71YBN/lT7e3Ly+YP0kBpIRU1ph/aa6xBtthRHm/Czs5BhKAltRJvUk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 12/13] xen/arm: defer foreign memory map in shm_init_late Date: Fri, 11 Mar 2022 14:11:22 +0800 Message-ID: <20220311061123.1883189-13-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 293c8bf2-dbcb-4bb9-54d6-08da032632aa X-MS-TrafficTypeDiagnostic: DB9PR08MB7493:EE_|VE1EUR03FT019:EE_|DB7PR08MB3067:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: JPxrKIaAFxGmKKwyp7HDtTYaiXV0KAtgUsLrD72CHRJYc4WPaS40DtYbPIJFkUNwgadegv3IWkIvXNJxzW60osx9njTD4hAcBVPdgsJJZPnLJwdvH4bGWKqouzFUSHcPNqXrfzbH5zFFowHk2KKk9m33/Md7Q87NytkhtwgSkE9dl5ZG+0YA+/I0AWEv0uHQXslwr6Qc85Rnnk5hGdNbcwQSxOe+XWqyl8jYWrfTij/du5uLcb/cvTuzGvFFcrpb9HAyUNNKqrInZ4BqkBJVngjqeYBsIRToRS0eAbTH9+3nDwSuZRDQfiOU7HcNzmwneAEuWyzBHNmz+qfrtdIDFGdW+7KUy4FoOLnmKYAIOSC8h8tOikE+GbWtHJftvnKPt9MSPEt+JyAQTzYK7fhrhDGarlp3yOgOL5Jw/tWedU1hxDS+ViRxmLSlTC7XyjlW97wG9AbW8yhuKhW6pQBdsEM/c0o83PeK4GTkAkSye5ePdUP8mJId/As+C/on7IXr9SxItuseHYTGTBSXtyGTqxU9laH0s9KgZ7sRVaEPbkVRKQAvKZs9x5VH8prFSZc5M4L8ROFLHDrz5z3bg8YA4+I2JsUF8LD0K/970MFh6zIdtBZZiqtBU39Xvjt/qJNGAJMkWRzpiMZuJHvVfTcCndKuarUbzXaCsfUB8HxSH4aCEBGOCQNapAuKZa39zc0zzdjlqvk2cBNsvdyu9BRJ9g== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(336012)(1076003)(2616005)(426003)(83380400001)(186003)(26005)(356005)(36756003)(81166007)(82310400004)(36860700001)(47076005)(8676002)(4326008)(508600001)(70206006)(70586007)(40460700003)(316002)(6916009)(54906003)(2906002)(5660300002)(8936002)(6666004)(7696005)(86362001)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB7493 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 01a6c042-a16b-44b8-ce6d-08da03262d47 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YxTMMdNC3aoe+Gv3nlYhY/9/8KhZimixGHuxAdOmoMcY6iMGmprDsn9rw5HFMXNtDn8TwJetcvVVcSPII0N3ZIuRetrBMIgWoxlOOFOwAaVowQjAcM/63mQGkVCgO02ccHAT+xnwY+cL87IZ8ClO0LH1Abaq3E1LMLJ4koL3KMcIq8QZWOsBWioPO6yNh0UGpruZFHRI7d93tuhvpZZ2I8h2yGH2MFyO9DJSQdv/6xh/LoC6iS+EMLmcKBHoxRYZvF/7eBScO68Ri1TrS7XV3IDdp4bw38jJdMcMo7CTTE6XWBvB/b/eIgLfFhr5TzoaN6MELuBthD3sL+OYYkn0faDIu7qYPd7PAecLRG5sC/LVMUdvLc7fWRXUwQ6iTZwRlUwGHh89DB/pISSbFzqkWik+vxZ8PuYNzCKjNUKgjWK3Ywv9b1TresMT5r12DzzYUkYl4hioeXL8uh7kzKkDpwdCiVN70tI3moNDXDQMzLuADkm2Sq8qqCIGz1zeYYSvjEZINWapaMxB5kT+KILTYp7vkN7LnJsXxnLTeJJOyaqhCC14lfD3npW3wMS4rk804tgSiQzXMSUGWqHwZxnG3SWtgBUthS6X1UYmSVbmkOo9XEs21iaMrbrH1Vb6jXlYdMbGbhx+qnV+pOHBfLjnCY0w3Q+TR/f3kf7xT3G/1n7ow+iTQ+2ejC/NtywKmu19 X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(36756003)(8936002)(4326008)(508600001)(8676002)(5660300002)(36860700001)(7696005)(6666004)(107886003)(70206006)(1076003)(26005)(186003)(426003)(83380400001)(336012)(2616005)(70586007)(54906003)(81166007)(86362001)(47076005)(40460700003)(2906002)(82310400004)(316002)(6916009);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:13:01.8917 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 293c8bf2-dbcb-4bb9-54d6-08da032632aa X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3067 From: Penny Zheng This commit introduces a new helper shm_init_late to implement deferred foreign memory mapping of static shared memory. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 51 +++++++++++++++++++++++++++++++ xen/arch/arm/include/asm/domain.h | 1 + xen/arch/arm/setup.c | 6 ++++ 3 files changed, 58 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 4b19160674..f6ef5a702f 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1006,6 +1006,57 @@ static int __init process_shm(struct domain *d, return 0; } + +int __init shm_init_late(void) +{ + unsigned long i = 0UL, shm_id; + int ret = 0; + struct domain *od, **bd = NULL; + unsigned long o_gfn, b_gfn, nr_gfns; + + for ( shm_id = find_first_bit(shm_list_mask, NR_MEM_BANKS); + shm_id < NR_MEM_BANKS; + shm_id = find_next_bit(shm_list_mask, NR_MEM_BANKS, shm_id + 1) ) + + { + /* Acquire the only owner domain. */ + od = get_domain_by_id(shm_list[shm_id].owner_dom); + if ( od == NULL ) + return -ESRCH; + o_gfn = PFN_DOWN(shm_list[shm_id].owner_gbase); + nr_gfns = PFN_DOWN(shm_list[shm_id].size); + + bd = xmalloc_array(struct domain *, shm_list[shm_id].nr_borrower); + if ( !bd ) + return -ENOMEM; + /* Set up foreign memory map for all borrower domains. */ + for ( i = 0; i < shm_list[shm_id].nr_borrower; i++ ) + { + bd[i] = get_domain_by_id(shm_list[shm_id].borrower_dom[i]); + if ( bd[i] == NULL ) + { + return -ESRCH; + goto fail; + } + + b_gfn = PFN_DOWN(shm_list[shm_id].borrower_gbase[i]); + ret = guest_physmap_add_shm(od, bd[i], o_gfn, b_gfn, nr_gfns); + if ( ret ) + { + ret = -EINVAL; + goto fail; + } + } + + xfree(bd); + } + return ret; + + fail: + xfree(bd); + + return ret; +} #endif /* CONFIG_STATIC_SHM */ #else static void __init allocate_static_memory(struct domain *d, diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index 1c0f2e22ca..c3f2155f5c 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -58,6 +58,7 @@ typedef struct { } shm_info_t; extern shm_info_t shm_list[NR_MEM_BANKS]; extern unsigned long shm_list_mask[BITS_TO_LONGS(NR_MEM_BANKS)]; +extern int shm_init_late(void); #else #define dom_shared NULL #endif diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index f6a3b04958..4987b71111 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -1051,7 +1051,13 @@ void __init start_xen(unsigned long boot_phys_offset, printk(XENLOG_INFO "Xen dom0less mode detected\n"); if ( acpi_disabled ) + { create_domUs(); +#ifdef CONFIG_STATIC_SHM + if ( shm_init_late() ) + panic("Failed to set up deferred foreign memory mapping of static shared memory.\n"); +#endif + } /* * This needs to be called **before** heap_init_late() so modules From patchwork Fri Mar 11 06:11:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12777484 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 ADDF3C433EF for ; Fri, 11 Mar 2022 06:16:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.288754.489784 (Exim 4.92) (envelope-from ) id 1nSYZd-0006lF-1Q; Fri, 11 Mar 2022 06:16:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 288754.489784; Fri, 11 Mar 2022 06: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 1nSYZc-0006l8-Ua; Fri, 11 Mar 2022 06:16:24 +0000 Received: by outflank-mailman (input) for mailman id 288754; Fri, 11 Mar 2022 06:16:23 +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 1nSYWf-0000Fh-78 for xen-devel@lists.xenproject.org; Fri, 11 Mar 2022 06:13:21 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2062b.outbound.protection.outlook.com [2a01:111:f400:7e1b::62b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 592b729e-a102-11ec-8eba-a37418f5ba1a; Fri, 11 Mar 2022 07:13:20 +0100 (CET) Received: from AM6P194CA0013.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::26) by AM5PR0801MB2066.eurprd08.prod.outlook.com (2603:10a6:203:4d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.21; Fri, 11 Mar 2022 06:13:18 +0000 Received: from AM5EUR03FT056.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:90:cafe::cb) by AM6P194CA0013.outlook.office365.com (2603:10a6:209:90::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:13:18 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT056.mail.protection.outlook.com (10.152.17.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:13:17 +0000 Received: ("Tessian outbound 826a6d8e58c3:v113"); Fri, 11 Mar 2022 06:13:17 +0000 Received: from 27ab5dd389c2.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4DE4BD2A-E33F-4D7F-AFC3-710EB1AAD2E0.1; Fri, 11 Mar 2022 06:13:11 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 27ab5dd389c2.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Mar 2022 06:13:11 +0000 Received: from AS9PR0301CA0019.eurprd03.prod.outlook.com (2603:10a6:20b:468::29) by PR2PR08MB4828.eurprd08.prod.outlook.com (2603:10a6:101:1d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Fri, 11 Mar 2022 06:13:08 +0000 Received: from VE1EUR03FT055.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:468:cafe::68) by AS9PR0301CA0019.outlook.office365.com (2603:10a6:20b:468::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:13:08 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT055.mail.protection.outlook.com (10.152.19.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Fri, 11 Mar 2022 06:13:08 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 11 Mar 2022 06:12:46 +0000 Received: from a011292.shanghai.arm.com (10.169.190.94) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Fri, 11 Mar 2022 06:12:43 +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: 592b729e-a102-11ec-8eba-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a4JLEIb5PBTxY4a54x6twnAqTQYE+B3WX7UNftnFy/Y=; b=dj9yzVYyBVjCMIERbmslJLiETmw0UyMzqzZbme4El0PaZDLXw/DAZL71uJ+7S29XDaHbs1FJBrPpoK8JbeQuz5R0bEB2+Kc61nAmkKnev0lbOvtpgZVGzmsvRvZlCEuvEhATPmnfsWtSIjyhFc0DIyDCBGOHgiizswE+lMSkWj4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: 93567b3a7281382f X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AiKndQNN58ZHsVaj3z8ySMKYedS5Vl9IFXeO8xgYkdV5gsnODpGJpvIn+CcdefVsmByU6tWfS9j6Htghq7vLSPh5A2YB1ZD7wRwnoGBkAP8bhLyRIqhAmEhYuSQeCGgfWMweWRr25/DFh/BmQUuaxcZl6X5A8lXYKXur+HbSiwzG4OI72BgF+AOODq3+VfrdRY+d7fM90HsArq+vysOTUqiTRsFUiz6HjSMIEPl9n/CnM6iYgwmy3PAlF3txB+CsImJvN41jyDSseB6e8OIZdH/pBeydy1FpNnUY5juo8LCarDKtOxXALpnxJ6MgTQIoiwnU5QC5r9/Z7ok8iKVUZQ== 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=a4JLEIb5PBTxY4a54x6twnAqTQYE+B3WX7UNftnFy/Y=; b=CnDeoL7KRuf3AES+KHlb8NEtpPl4OykRncA5pUO+Dql6iWpYiuH1Hr+n+va+wIjo65guJvg0b9NdDg4966XYss+OyCeKop7rIVZqmW2ulSsXiz8lcWHvrDEEW67hNyNIMfVI/yvpFYHwHxT9wGEPELjraE9fnRNYBo6uBCUHcf2CF2BUXbwnEpcfH7XASJq1sEqjy/ImZr115DcBcc2muhe20u53fAeWaefXAvFcZOnwhQrGMDusFAviDpt0YYbkzICzJE8z6HJlOzF+ZAvySsYm+0fJuUplXiy2Npzi8oZTR76NUjsgeA69AQLF5t2OXFgNxhWltkoEFEz+7LsKxA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a4JLEIb5PBTxY4a54x6twnAqTQYE+B3WX7UNftnFy/Y=; b=dj9yzVYyBVjCMIERbmslJLiETmw0UyMzqzZbme4El0PaZDLXw/DAZL71uJ+7S29XDaHbs1FJBrPpoK8JbeQuz5R0bEB2+Kc61nAmkKnev0lbOvtpgZVGzmsvRvZlCEuvEhATPmnfsWtSIjyhFc0DIyDCBGOHgiizswE+lMSkWj4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; From: Penny Zheng To: CC: , Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v1 13/13] xen/arm: unmap foreign memory mapping when destroyed domain is owner domain Date: Fri, 11 Mar 2022 14:11:23 +0800 Message-ID: <20220311061123.1883189-14-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311061123.1883189-1-Penny.Zheng@arm.com> References: <20220311061123.1883189-1-Penny.Zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 964922e8-f03b-4b19-64b4-08da03263c04 X-MS-TrafficTypeDiagnostic: PR2PR08MB4828:EE_|AM5EUR03FT056:EE_|AM5PR0801MB2066:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: HtjVt0+HCLCfVDGuDhahL6RrjKLT9SvmwePmYfF7Hs5OhNktH5rhWc+hPHxbl6j9jmfLX3Zy9fMaq/QlUjjAjfk0MVf8bP+H56ePyPMWZiBKYeIRhh9tNtRTKosiGjdKu3yAsUlvoIYiulUaaJRNYk+eiNu/AU7WTVRT4mw6ZLsoazeSAGg9CEi46Omvj6wIHJv0aFTdixaiU3E6qZOG9IoDVzBQammyRPb6ZCqaSlx0+Bx1b2VhlfZlWBVlgumtiV/UfrOJjdR+n4O2AsmBoYp+wVwu6s2eIofqnRF1wd+i6CJAYDhddGgkAzuxLbdu1CYYj/z0pRIqwCTRfG0Fm72IQWK3QAEmSZMNfK5g5fMQLi5gMlaw6xJu7U81CY2mqFDeYguEebPAM5u5MXSdmhQbWEeP/rix5j8SyJRarlkDLQr0ke1LswzrKiub8RcLl7LZMjU7xsaN6f468Wfbc8JVRoJoOAX6KL9d4SgbX715ClbRH/R//SqNo9fDC4ynJzvVRsoCPZfyNzH2Hkfl+QKqde3JAzdFTk3W2QRZWnUsBWLlXlYoBOV7g4PmBtU9ajNOKUb+XILahtiGqKKWydUuPKPol0Y/Y9/RkeyDKsYiBuvR0+HGVNBL4mg4qrptWAoJZKHPGRS1kPIatDEzPsign4E6gZK4yiOMCLaHLYCE58fAOfnBJwOmm0OQGfuL9H4tjx12klU6mr8CZJWy5g== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(70586007)(8676002)(70206006)(7696005)(6666004)(508600001)(4326008)(6916009)(316002)(54906003)(83380400001)(36860700001)(82310400004)(336012)(26005)(40460700003)(186003)(1076003)(2616005)(2906002)(356005)(426003)(81166007)(47076005)(8936002)(86362001)(5660300002)(36756003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR2PR08MB4828 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT056.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 7f97ff42-c75f-49ee-5d59-08da0326364d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OrGYKo6xbJRnZvAqKAkBAaHFrdXS4EuD49P7/U/uUAjteU42Xrlecw2lsKDTJcoCRQKPLlW12W7ZeyOPUEFX/qb8w+ukAs6CjAaVObyupHTYkZDM75PLxrKW6+sIgPi740xwaEyQkQj4jSCD0sfuaY55P944IdCh5G9Vm0q4iWnNdRXFEaSc87OWFhOvTRVP1/Md7L0TirrNkjFvR8tf8mEVICDVDEXiKWI3Yth/xKOG9PgplwOM5s45Tk68SnW1f8StI7bQ9aTaxID9IJ4bJBqG+QUGGACuhdJ1XSdd17zgyJ4WZ8T45/OU4a3I7ONvkNFo3rjt3pmCdf8rz1+kL/c0xuf9NTscnoyVyRu/dsNOInxLmzt7uoBd0qr1/5FPzmpwfYZMWE64GCHifvNCen4Sk9MF7XDXzLRf3ahd09yxHdsA/Qz7ENQR8lYvT0LX9nzfmloBqqO+6DebjiN4ixKe41KvSKMkbYCSceGIXWJpTtn7naYinWA2oSqvWM98OpIkZTJ6oXiXkP8Hk/+uujHQG3MGfVEHotH1Q0vhFe7psryuV7haWLPi41K8P8IQr6EBza3/AaW8pS9wJ0BoGV1fKWHgwUrWjtNuuTHQAL4kYdf3i38jcLtPKtdWLPqCfY35gIrIXfWQk7dYETPV53X+clFfioIVPtUauqH1t4k2bhBiEtYaWiKkZ5xMFnPL X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(7696005)(6916009)(186003)(2616005)(70586007)(316002)(36756003)(26005)(40460700003)(86362001)(1076003)(54906003)(107886003)(8936002)(5660300002)(336012)(83380400001)(426003)(2906002)(508600001)(6666004)(47076005)(36860700001)(8676002)(4326008)(82310400004)(70206006)(81166007);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 06:13:17.6254 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 964922e8-f03b-4b19-64b4-08da03263c04 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT056.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB2066 From: Penny Zheng When destroyed domain is an owner domain of a static shared memory region, then we need to ensure that all according borrower domains shall not have the access to this static shared memory region too. This commit covers above scenario through unmapping all borrowers' according foreign memory mapping when destroyed domain is a owner domain of a static shared memory region. NOTE: It will best for users to destroy all borrowers before the owner domain in case encountering data abort when accidentally accessing the static shared memory region. Signed-off-by: Penny Zheng --- xen/arch/arm/domain.c | 88 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 17 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 73ffbfb918..8f4a8dcbfc 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -998,10 +998,39 @@ static int relinquish_memory(struct domain *d, struct page_list_head *list) } #ifdef CONFIG_STATIC_SHM +static int destroy_shm(struct domain *d, gfn_t gfn, unsigned long nr_gfns) +{ + unsigned long i = 0; + int ret = 0; + + for ( ; i < nr_gfns; i++ ) + { + mfn_t mfn; + + mfn = gfn_to_mfn(d, gfn_add(gfn, i)); + if ( !mfn_valid(mfn) ) + { + dprintk(XENLOG_ERR, + "Domain %pd page number %lx invalid.\n", + d, gfn_x(gfn) + i); + return -EINVAL; + } + + ret = guest_physmap_remove_page(d, gfn_add(gfn, i), mfn, 0); + if ( ret ) + return ret; + + /* Drop the reference. */ + put_page(mfn_to_page(mfn)); + } + + return ret; +} + static int domain_destroy_shm(struct domain *d) { int ret = 0; - unsigned long i = 0UL, j; + unsigned long i = 0UL; if ( d->arch.shm_mem == NULL ) return ret; @@ -1009,29 +1038,54 @@ static int domain_destroy_shm(struct domain *d) { for ( ; i < d->arch.shm_mem->nr_banks; i++ ) { + u32 shm_id = d->arch.shm_mem->bank[i].shm_id; unsigned long nr_gfns = PFN_DOWN(d->arch.shm_mem->bank[i].size); gfn_t gfn = gaddr_to_gfn(d->arch.shm_mem->bank[i].start); - for ( j = 0; j < nr_gfns; j++ ) + if ( test_bit(shm_id, shm_list_mask) ) { - mfn_t mfn; - - mfn = gfn_to_mfn(d, gfn_add(gfn, j)); - if ( !mfn_valid(mfn) ) + domid_t od = shm_list[shm_id].owner_dom; + unsigned long j; + /* + * If it is a owner domain, then after it gets destroyed, + * static shared memory region shall be unaccessible to all + * borrower domains too. + */ + if ( d->domain_id == od ) { - dprintk(XENLOG_ERR, - "Domain %pd page number %lx invalid.\n", - d, gfn_x(gfn) + i); - return -EINVAL; + struct domain *bd; + + for ( j = 0; j < shm_list[shm_id].nr_borrower; j++ ) + { + bd = get_domain_by_id(shm_list[shm_id].borrower_dom[j]); + /* + * borrower domain could be dead already, in such case + * no need to do the unmapping. + */ + if ( bd != NULL ) + { + gfn_t b_gfn = gaddr_to_gfn( + shm_list[shm_id].borrower_gbase[j]); + ret = destroy_shm(bd, b_gfn, nr_gfns); + if ( ret ) + dprintk(XENLOG_ERR, + "Domain %pd: failed to destroy static shared memory.\n", + bd); + } + } + + continue; } - - ret = guest_physmap_remove_page(d, gfn_add(gfn, j), mfn, 0); - if ( ret ) - return ret; - - /* Drop the reference. */ - put_page(mfn_to_page(mfn)); } + /* + * As borrower domain, remove foreign memory mapping and drop the + * reference count. + */ + ret = destroy_shm(d, gfn, nr_gfns); + if ( ret ) + dprintk(XENLOG_ERR, + "Domain %pd: failed to destroy static shared memory.\n", + d); } }