From patchwork Tue Aug 24 09:50:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12454413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA06BC4320E for ; Tue, 24 Aug 2021 09:51:45 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 85C266138B for ; Tue, 24 Aug 2021 09:51:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 85C266138B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.170777.311684 (Exim 4.92) (envelope-from ) id 1mIT5Z-0001Zr-1Y; Tue, 24 Aug 2021 09:51:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 170777.311684; Tue, 24 Aug 2021 09:51: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 1mIT5Y-0001Zk-Un; Tue, 24 Aug 2021 09:51:24 +0000 Received: by outflank-mailman (input) for mailman id 170777; Tue, 24 Aug 2021 09:51:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5X-0001Ze-CJ for xen-devel@lists.xenproject.org; Tue, 24 Aug 2021 09:51:23 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (unknown [40.107.21.57]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e62dad9b-2c11-4df7-840c-2380c947c542; Tue, 24 Aug 2021 09:51:20 +0000 (UTC) Received: from AM6P195CA0079.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:86::20) by VI1PR08MB3389.eurprd08.prod.outlook.com (2603:10a6:803:87::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 09:51:17 +0000 Received: from AM5EUR03FT027.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:86:cafe::24) by AM6P195CA0079.outlook.office365.com (2603:10a6:209:86::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:17 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT027.mail.protection.outlook.com (10.152.16.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:16 +0000 Received: ("Tessian outbound 19a632698c93:v103"); Tue, 24 Aug 2021 09:51:15 +0000 Received: from a5e976017d9c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DF84A7BB-9503-4F41-9C11-AC0F90042E68.1; Tue, 24 Aug 2021 09:51:09 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a5e976017d9c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 24 Aug 2021 09:51:09 +0000 Received: from AM5PR0201CA0011.eurprd02.prod.outlook.com (2603:10a6:203:3d::21) by AM0PR08MB3812.eurprd08.prod.outlook.com (2603:10a6:208:fd::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Tue, 24 Aug 2021 09:51:08 +0000 Received: from VE1EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:3d:cafe::8) by AM5PR0201CA0011.outlook.office365.com (2603:10a6:203:3d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:08 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT044.mail.protection.outlook.com (10.152.19.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:08 +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.14; Tue, 24 Aug 2021 09:51:07 +0000 Received: from penny.shanghai.arm.com (10.169.190.66) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.14 via Frontend Transport; Tue, 24 Aug 2021 09:51:05 +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: e62dad9b-2c11-4df7-840c-2380c947c542 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=jYrQe6x6Dlk8l1vIqTVluKWnc7+Ol0QPjCsq0YGfsUo=; b=IIbgLhG0l+ea15w/s+y2UEVK+TyZYh2PMm/YH7brUklNRkXjrkAZgbU7IRMf119B0l5jPfyj2ntbcoIEfbIrKOPfPkC9D/6n4fBCcxQnhbOhzPkJmVp0Iqb6x7kxp5cpPhKBAs3+LaLWzh/cWT/bXhzUpF+VYN+4lrUJIM2jjGI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.xenproject.org; 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: 05db3f125ba0b9b2 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FQxsA1fRx7Nw3n146ZTnO9dDBVjnyjtyD1s/KsMNpjmO1KhUS5Z0wZrwMy01niUJvIqnjVu5HKRa5PRm6Y/CMFUJpVMS2IXyfnRMb2lE8KJrJhTCrBdYqLiGZbXKMSz0d7TR6EXaPmtnYN40V3jV8U0CiDeYyWV9k4zNPGFqqFE2d9REWhFWJOAGN5VOSYuq5n2kOc1vt9iexlaJUPKfECQYjUCH/f0vl8bByIT4A9PaGbuGr0zSM84MafyHDZovoKsZp/aC3d3nU6Ob5m6gZ1v1FIHLGdk+2siW6puBnfXysBRPffCiAylHL0Jm+WSB7QxGmBJRAhU9cuK0TSRSwg== 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-SenderADCheck; bh=jYrQe6x6Dlk8l1vIqTVluKWnc7+Ol0QPjCsq0YGfsUo=; b=NJfYgo3po9pae2z6fVvKb6ZhwhFgzP8yQvHLTXF2qBRuU7FVu8njGPJXXXX+SOhs4D7KDlX4YaGR/9279D1r8JpPXhB5XvsFP8pyXai+jn0y9N2cPBYrSk8L+MmL0hhqVSCVHvxbwMB3ttP140w3pHS12BsXdwUQDNklsX+GIZTM5gZermGqBpAKw/cpNxwIbM4ycpSqfdDZTViWbwhDrgVipiwc1y1OqmbZR26ntC6Vwjta/F5wMl2FaOEfDBdDAhmQmK0NFWul8waUYsp3pPT7Htx2KikYnlnuVEyTihnVlTpwq8AG7jqQO8fG9kS4PgHQxxBF2Z8XsB5dftzjbg== 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=jYrQe6x6Dlk8l1vIqTVluKWnc7+Ol0QPjCsq0YGfsUo=; b=IIbgLhG0l+ea15w/s+y2UEVK+TyZYh2PMm/YH7brUklNRkXjrkAZgbU7IRMf119B0l5jPfyj2ntbcoIEfbIrKOPfPkC9D/6n4fBCcxQnhbOhzPkJmVp0Iqb6x7kxp5cpPhKBAs3+LaLWzh/cWT/bXhzUpF+VYN+4lrUJIM2jjGI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; 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: , , , Subject: [PATCH v5 1/7] xen/arm: introduce new helper device_tree_get_meminfo Date: Tue, 24 Aug 2021 09:50:39 +0000 Message-ID: <20210824095045.2281500-2-penny.zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824095045.2281500-1-penny.zheng@arm.com> References: <20210824095045.2281500-1-penny.zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5dcdf328-ea6d-4fe2-2d1f-08d966e4b771 X-MS-TrafficTypeDiagnostic: AM0PR08MB3812:|VI1PR08MB3389: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:393;OLM:393; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: jpylx3nyKW4u59+xtGq21UIQ2/R8o0AybQe5KQIi51ZMxAt2qlMyS2AdHwXdnNIXlhl/wuAwnUC0lKZhNjWMMLQJi+j0nxJw+EAxcIiXkQ6daFo4d+r7AnVHoArrzZCu0GbiMmpplB6jXjL+956JVqkAKwgMQTBuBEudP1iTVceKfPAza25ap4cug7bKWccqaKwQZVgEkZBcrzCSiOtk5/Uk7MXDZagCagqiURLcnUJUREKnAOsLIbySk+U7xhD1bQv3P87l11MrhvvTBXRne+iCzCe/4rIX7cRqsSZlYGYU0ipLgP16wL+ct4mQ5k5z/iYW2P5rpigP+/oTwapMdzS5+oFXrow8FxSriL4xOoyjwaZzJ/FfqS/dmmhlap7/dgwwF54Cqz8/DqF5+a4qBxczWxndAhxDQShARdFSydexOjJKEHxXBQ5coiHeYKFsfTpi7TBYrUslqsAVmC2VVHrdOHuuBQ17co4IrpSUNSDfbBaYDWI6EhciOx39VnTcCwmDAbpXi0jmBGYG3jqPim3gI6dEVSnTMlI2F2Wb5kEeIa9o+cQL26bN0cwxzugIYrzxWDNnqRDqkqVZSPCEkI0MNMN7GvuiYp0fg6x9vAFFM/gGRN1jNrxbcyW3wwDBoWKSRM+/ZAcHwA8Byc51wvpEBwJf5GJIqx3kCF1emXN0+Gshl6GG8+LGcQXfzVn0k6doGkE9nDdI+TLJfdGrHycXMkWpSif4nizQ3fnc7yE= 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:(4636009)(39860400002)(376002)(346002)(136003)(396003)(46966006)(36840700001)(336012)(26005)(426003)(186003)(86362001)(7696005)(82310400003)(83380400001)(47076005)(36860700001)(1076003)(2616005)(2906002)(44832011)(4326008)(316002)(70586007)(70206006)(6666004)(36756003)(8676002)(5660300002)(8936002)(478600001)(54906003)(110136005)(356005)(81166007)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3812 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: e79ea3f7-d44d-48ea-0b8b-08d966e4b2b6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iiavaBXD+h6LtUXrFBJKyOqUcRWg1PsfHpio5b+HM5qQCNenZ1ZSYaRqpB4x6jHw2j5k1roh0LxIuePC5S6N++c/sn3FbdTKBncf0Y6vd/RqHnYqy3srUSY+ornD60x/5G0IwPycHNU4iZwT1OYwv3VwjNTcTOKQHb4UNcJtBsVGDpe8AY7f8vY5g256kBxsWjonFRYpAQiLoqWzrKbl2HrrTK4Ya7GzkmdkqhYQV6OX9pAiRjwu9PUDYsch9vVQYcmZyokec1T4iMhZ0GZL768VfQeQHs7vklT5wsYya2fY3VIBaxV9Ad/NB7Zhbw5VQAjEWh7jYIcHt633dBIG3dQuzeCDYtdAsCr66rBO7Hz6u46/z15ZT3+hxNmyVx6p52w0XK4/zrWVoTs7wzkd/A1xaSCrwCVHzILLX+1+6MJbs/bgB8yFct/l0af9N5JJiDHGwWH/3iJ7iIQ+nbwPBTXbM7wajuU2r+/hdIWnppJydk5e2lDr7iaF4ZWmKPphyd5XKC6ZnJVQXO9GGu9roybiSi8cIEUQ6oL1Cjs2BAQrQVal7EpcYh/POab0FZoTdDL4UP8BoWVycgSMI4kF8UMDb4r8rTdiVgulsWvaxij69JTyTrszbNJt8iPFBagawHIlF+Ze56BlEWnVskJf3xsQuEwb3tzdtq0YR0J4lFdsfZX8IPFMbv0UtsNagE+kCiT5rFBQRFt2/pLqJJPM2Q== 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:(4636009)(346002)(376002)(39860400002)(396003)(136003)(46966006)(36840700001)(70586007)(70206006)(26005)(6666004)(336012)(426003)(186003)(5660300002)(478600001)(47076005)(83380400001)(36860700001)(82310400003)(36756003)(8676002)(44832011)(2906002)(82740400003)(316002)(4326008)(8936002)(86362001)(1076003)(7696005)(110136005)(54906003)(2616005)(81166007);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 09:51:16.5290 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5dcdf328-ea6d-4fe2-2d1f-08d966e4b771 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: AM5EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3389 A few functions iterate over the device tree property to get memory info, like "reg" or the later "xen,static-mem", so this commit creates a new helper device_tree_get_meminfo to extract the common codes. Signed-off-by: Penny Zheng --- xen/arch/arm/bootfdt.c | 68 ++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 476e32e0f5..8c81be3379 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -63,6 +63,44 @@ void __init device_tree_get_reg(const __be32 **cell, u32 address_cells, *size = dt_next_cell(size_cells, cell); } +static int __init device_tree_get_meminfo(const void *fdt, int node, + const char *prop_name, + u32 address_cells, u32 size_cells, + void *data) +{ + const struct fdt_property *prop; + unsigned int i, banks; + const __be32 *cell; + u32 reg_cells = address_cells + size_cells; + paddr_t start, size; + struct meminfo *mem = data; + + prop = fdt_get_property(fdt, node, prop_name, NULL); + if ( !prop ) + return -ENOENT; + + cell = (const __be32 *)prop->data; + banks = fdt32_to_cpu(prop->len) / (reg_cells * sizeof (u32)); + + for ( i = 0; i < banks && mem->nr_banks < NR_MEM_BANKS; i++ ) + { + device_tree_get_reg(&cell, address_cells, size_cells, &start, &size); + /* Some DT may describe empty bank, ignore them */ + if ( !size ) + continue; + mem->bank[mem->nr_banks].start = start; + mem->bank[mem->nr_banks].size = size; + mem->nr_banks++; + } + + if ( i < banks ) + { + printk("Warning: Max number of supported memory regions reached.\n"); + return -ENOSPC; + } + return 0; +} + u32 __init device_tree_get_u32(const void *fdt, int node, const char *prop_name, u32 dflt) { @@ -139,14 +177,6 @@ static int __init process_memory_node(const void *fdt, int node, u32 address_cells, u32 size_cells, void *data) { - const struct fdt_property *prop; - int i; - int banks; - const __be32 *cell; - paddr_t start, size; - u32 reg_cells = address_cells + size_cells; - struct meminfo *mem = data; - if ( address_cells < 1 || size_cells < 1 ) { printk("fdt: node `%s': invalid #address-cells or #size-cells", @@ -154,27 +184,7 @@ static int __init process_memory_node(const void *fdt, int node, return -EINVAL; } - prop = fdt_get_property(fdt, node, "reg", NULL); - if ( !prop ) - return -ENOENT; - - cell = (const __be32 *)prop->data; - banks = fdt32_to_cpu(prop->len) / (reg_cells * sizeof (u32)); - - for ( i = 0; i < banks && mem->nr_banks < NR_MEM_BANKS; i++ ) - { - device_tree_get_reg(&cell, address_cells, size_cells, &start, &size); - /* Some DT may describe empty bank, ignore them */ - if ( !size ) - continue; - mem->bank[mem->nr_banks].start = start; - mem->bank[mem->nr_banks].size = size; - mem->nr_banks++; - } - - if ( i < banks ) - return -ENOSPC; - return 0; + return device_tree_get_meminfo(fdt, node, "reg", address_cells, size_cells, data); } static int __init process_reserved_memory_node(const void *fdt, int node, From patchwork Tue Aug 24 09:50:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12454411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30C79C4338F for ; Tue, 24 Aug 2021 09:51:45 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C32336138B for ; Tue, 24 Aug 2021 09:51:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C32336138B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.170778.311695 (Exim 4.92) (envelope-from ) id 1mIT5b-0001pz-Av; Tue, 24 Aug 2021 09:51:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 170778.311695; Tue, 24 Aug 2021 09:51: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 1mIT5b-0001ps-7f; Tue, 24 Aug 2021 09:51:27 +0000 Received: by outflank-mailman (input) for mailman id 170778; Tue, 24 Aug 2021 09:51:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5Z-0001jx-QZ for xen-devel@lists.xenproject.org; Tue, 24 Aug 2021 09:51:25 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (unknown [40.107.3.85]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d6e04b40-04c0-11ec-a8bd-12813bfff9fa; Tue, 24 Aug 2021 09:51:23 +0000 (UTC) Received: from AS8PR04CA0015.eurprd04.prod.outlook.com (2603:10a6:20b:310::20) by DB8PR08MB4089.eurprd08.prod.outlook.com (2603:10a6:10:a7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Tue, 24 Aug 2021 09:51:21 +0000 Received: from VE1EUR03FT027.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:310:cafe::1e) by AS8PR04CA0015.outlook.office365.com (2603:10a6:20b:310::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:21 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT027.mail.protection.outlook.com (10.152.18.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:20 +0000 Received: ("Tessian outbound 5918cb94a4b5:v103"); Tue, 24 Aug 2021 09:51:20 +0000 Received: from 994f709d97c8.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 6900B23F-7D4E-4437-8459-65DD8356B926.1; Tue, 24 Aug 2021 09:51:14 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 994f709d97c8.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 24 Aug 2021 09:51:14 +0000 Received: from AM5PR0201CA0003.eurprd02.prod.outlook.com (2603:10a6:203:3d::13) by PAXPR08MB6333.eurprd08.prod.outlook.com (2603:10a6:102:12c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 09:51:12 +0000 Received: from VE1EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:3d:cafe::5) by AM5PR0201CA0003.outlook.office365.com (2603:10a6:203:3d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.17 via Frontend Transport; Tue, 24 Aug 2021 09:51:12 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT044.mail.protection.outlook.com (10.152.19.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:12 +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.14; Tue, 24 Aug 2021 09:51:09 +0000 Received: from penny.shanghai.arm.com (10.169.190.66) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.14 via Frontend Transport; Tue, 24 Aug 2021 09:51:07 +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: d6e04b40-04c0-11ec-a8bd-12813bfff9fa 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=sgS1Rf3ebomsvnvr/wY+lSEo95uM3e33VHow5395u4k=; b=mibLvdyD7IHZhVLqONO9NMM7qZ1LWJo+KRg8oNxux+bsCzDNWREDoCpLcglV///3924VGe40O4EgAh0d37B4lJQZbnmRmcf9o8ODEAvFjbhnQVBe+fFrqVnsJcEaoQtSf6CBqXAiFVb/fV3aOqB8WGmizgChpYekfUiI7wxDrPo= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.xenproject.org; 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: a7a8e112fc7dfd32 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cr325YzIupOpAOA1/LY2pt7ID9zs6NLcgNrCfbZVv4wrgZcj1EYMCd9XGRn0fcDAOXSCDqKdoaVCh5V7poHmfTm+Dm4j7yRSl7tHPrbe9N4VkDHOpvpOH5UqHflbsDGvsjJBNhHeUOUrR1f1+mOQoEkneyBnGMh1ybMnZXcaVpExGLZlgAHetU2OibXvQeFAbhMo9ClHqfFp8CFqNcpih5luLFRWsqc0P6yyGZXzTuqPff4QVxp67zY7jgIfOrX1aKVmOCqbmyd10Qux6J5rPyiZoGlmrHEiZjDHag3/Apq6vrvjdbdSNshHjUGI6EP41F/3StZCd4ky2lTmmT1TKA== 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-SenderADCheck; bh=sgS1Rf3ebomsvnvr/wY+lSEo95uM3e33VHow5395u4k=; b=nM1s/jzKG1cWuMVzLzHmD5BAy6PhR3an9JalFyXCubi/bmbII2zm86s7oP76GZltNnx/wV1FoizqSrF0XABLFZjYyx2Osmw/zVKVz4oIFX4+wTY82OBY4o/We6/9/G9VFGKM4751s80yE7sS90W3RI/U+Uy0pLyjzk1DhdUIX0qGYvde4LCQ3oeNf8iQkCeBbEuYFw7BWGrpmDK+32wN3LEWzYMVLtDTrSO714sfRMpPlqYqHKHrQL3EUdOHEu7CDWA+EGZd7u0/FHal/6+qSuIVPhY4B6R/obHSHVIlw74M4SxaHT6EjMtqJc2CVRzaqA7jbO370cw0Hd3+0mgN0A== 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=sgS1Rf3ebomsvnvr/wY+lSEo95uM3e33VHow5395u4k=; b=mibLvdyD7IHZhVLqONO9NMM7qZ1LWJo+KRg8oNxux+bsCzDNWREDoCpLcglV///3924VGe40O4EgAh0d37B4lJQZbnmRmcf9o8ODEAvFjbhnQVBe+fFrqVnsJcEaoQtSf6CBqXAiFVb/fV3aOqB8WGmizgChpYekfUiI7wxDrPo= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; 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: , , , Subject: [PATCH v5 2/7] xen/arm: introduce domain on Static Allocation Date: Tue, 24 Aug 2021 09:50:40 +0000 Message-ID: <20210824095045.2281500-3-penny.zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824095045.2281500-1-penny.zheng@arm.com> References: <20210824095045.2281500-1-penny.zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31fd7733-6bd5-41b4-e01a-08d966e4ba08 X-MS-TrafficTypeDiagnostic: PAXPR08MB6333:|DB8PR08MB4089: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:3826;OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: rJ7GmzhwkieSGiYdEyCQEKv50U5jUmAsAk2PqOulPk+2lDcViMtBCZUpC66LzLflzLspz4p0hBStw0H7q1onkiqxWtp+DEj1sMueBC8wbG9zwewLaHVBhPAxr25ZP1QdeYv4KRHZOLR8/Ht7Hd3bIl4TLWz2sSpZ2IFBCxSNe38x0ZknoeGRDN9c8trtysG+735lTHfFlpgElMO7KoNA96nK6u+XGEO2NYeRQJn8e2X+unaLzmyHIfjoH+qdLZLicnBD9Y3uGpgVPpyxx16coEA6AlupbTW3Cr5AH3NHPKBCsP8a9cAkeLcOgQb2UJffo9BUlIXnmucC4YaKS21gCPLVdkWZY1/rX8IcPbPqqILtSjMBMS8SW4AC+eOpTgoVqX613YzIEEGtSizbeMHKy60FpxNlOmUAzs6XYTZbAeAIfHDFecVdPRYKan97I7lcc0PuXVzv6ApbPqlqEjEqVs+fhwsudN5xxceDIWfgZzRf1mJhJ7XcK/lTkvWrQV6yCVH3pviOwnbVkR0EbfiuIDzEZ69VrrDmjQo0kXMD/894L7XmbQZIMH3kHfd78KL4Jv6fFx8MKhm99laWPKfrmWJkDwVSl2BEDMfEkkXZnzYRw1NeQspz5zeeWZX7VKNJcp4nevO+n6B8SazKgGtcImXC+splfh+RTzK6ivB4rov+yjz/A+qax9JxkK56HzgVHuVmFKzqdGVdLL2piQ7M25mmZ+pzDWnRFQWZ56BuyGQ= 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:(4636009)(346002)(396003)(136003)(39860400002)(376002)(36840700001)(46966006)(36860700001)(83380400001)(426003)(36756003)(82310400003)(82740400003)(356005)(81166007)(2616005)(5660300002)(70206006)(47076005)(110136005)(316002)(44832011)(186003)(478600001)(70586007)(4326008)(2906002)(8676002)(6666004)(336012)(7696005)(26005)(86362001)(54906003)(1076003)(8936002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6333 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 8a15d582-71ce-434f-1c9e-08d966e4b51f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MnFmhpuQHPBh2pDyCfar4UvRieuUCaFnXz8VxmFEH4598/Lfgd6rfRpakTzoYnIfOfb7XoaTltz7R+otrG0co1FJytwXS1ERqqgW3v4qsXffUmRhrWm16LCvZ3RppljEDDv2OshiqhyUoOhEap57Paf08GheOG27+CVNrvyqToXxyhUGc1e4HQZvxmJVr2RhR9xE1XCgPDcE5g96bkEtxMfYJBeO+J2zrpHkNL6QqrR9O80kcF14ELqtnedlFvzYiIuLoIBhl62AM7gOzBPqd8A2nQMTmB+5aJJ0fMEFZ61lQsCd/MEcDpigwMOw95sLrajuWHKpzLyCif/cjOhwdrNoq0J++wuG1ExqlUsFWlaUM7evYASjjfqQJXZzOvfodzJdwDO8G4V6/Aix+HGXe+hZwsFkD9WQdcTagBza4/uqWIFLG7Fn3iPP+FdJSeW3rlh5dInjklqcWZAZ9aKSAFxPFESHKoinbrL1oWGOQloaJOO3c+iOEVhsTVaL1YhsICgu4H/mvMPh0K1t9Tb+/etGEf/yJEB5SeIFJMs6vHLHeQETXAT75CZtlaAHLRidFrqMVNdtBkSYKGzSMeHVsOV3tllb3x7bBYULhG2zZpB+5NT5JjCKhOmaCfXGEXvFvTlZIwVE46rrInrr9vV42pw8WG/zCbD4w6EXvi1hwPg4RyYjhfgLW8RzhtrulhPF1PG9cVQCwN1Ut4/Gf8Uh7Q== 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:(4636009)(39860400002)(136003)(346002)(396003)(376002)(36840700001)(46966006)(86362001)(186003)(426003)(336012)(5660300002)(8936002)(36756003)(8676002)(110136005)(83380400001)(54906003)(26005)(82740400003)(70206006)(82310400003)(6666004)(70586007)(316002)(7696005)(36860700001)(47076005)(2906002)(1076003)(4326008)(81166007)(2616005)(44832011)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 09:51:20.8316 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31fd7733-6bd5-41b4-e01a-08d966e4ba08 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: VE1EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB4089 Static Allocation refers to system or sub-system(domains) for which memory areas are pre-defined by configuration using physical address ranges. Those pre-defined memory, -- Static Memory, as parts of RAM reserved in the beginning, shall never go to heap allocator or boot allocator for any use. Memory can be statically allocated to a domain using the property "xen,static- mem" defined in the domain configuration. The number of cells for the address and the size must be defined using respectively the properties "#xen,static-mem-address-cells" and "#xen,static-mem-size-cells". This patch introduces this new `xen,static-mem` feature, and also documents and parses this new attribute at boot time. This patch also introduces a new field "bool xen_domain" in "struct membank" to tell the difference of one memory bank is reserved as the whole hardware resource, or bind to one specific xen domain node, through "xen,static-mem" Signed-off-by: Penny Zheng --- v5 changes: - check the node using the Xen domain binding whether contains the property "xen,static-mem", not the property itself - add "rc = ..." to get the error propagated - introduce new field "bool xen_domain", then static memory shall be also stored as reserved memory(bootinfo.reserved_mem), but being bind to one specific Xen domain node. - doc refinement --- docs/misc/arm/device-tree/booting.txt | 33 ++++++++++++++++++++++++ xen/arch/arm/bootfdt.c | 36 +++++++++++++++++++++++++-- xen/include/asm-arm/setup.h | 1 + 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-tree/booting.txt index 5243bc7fd3..95b20ddc3a 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -268,3 +268,36 @@ The DTB fragment is loaded at 0xc000000 in the example above. It should follow the convention explained in docs/misc/arm/passthrough.txt. The DTB fragment will be added to the guest device tree, so that the guest kernel will be able to discover the device. + + +Static Allocation +============= + +Static Allocation refers to system or sub-system(domains) for which memory +areas are pre-defined by configuration using physical address ranges. + +Memory can be statically allocated to a domain using the property "xen,static- +mem" defined in the domain configuration. The number of cells for the address +and the size must be defined using respectively the properties +"#xen,static-mem-address-cells" and "#xen,static-mem-size-cells". + +Below is an example on how to specify the static memory region in the +device-tree: + + / { + chosen { + domU1 { + compatible = "xen,domain"; + #address-cells = <0x2>; + #size-cells = <0x2>; + cpus = <2>; + #xen,static-mem-address-cells = <0x1>; + #xen,static-mem-size-cells = <0x1>; + xen,static-mem = <0x30000000 0x20000000>; + ... + }; + }; + }; + +This will reserve a 512MB region starting at the host physical address +0x30000000 to be exclusively used by DomU1 diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 8c81be3379..00f34eec58 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -66,7 +66,7 @@ void __init device_tree_get_reg(const __be32 **cell, u32 address_cells, static int __init device_tree_get_meminfo(const void *fdt, int node, const char *prop_name, u32 address_cells, u32 size_cells, - void *data) + void *data, bool xen_domain) { const struct fdt_property *prop; unsigned int i, banks; @@ -90,6 +90,7 @@ static int __init device_tree_get_meminfo(const void *fdt, int node, continue; mem->bank[mem->nr_banks].start = start; mem->bank[mem->nr_banks].size = size; + mem->bank[mem->nr_banks].xen_domain = xen_domain; mem->nr_banks++; } @@ -184,7 +185,8 @@ static int __init process_memory_node(const void *fdt, int node, return -EINVAL; } - return device_tree_get_meminfo(fdt, node, "reg", address_cells, size_cells, data); + return device_tree_get_meminfo(fdt, node, "reg", address_cells, size_cells, + data, false); } static int __init process_reserved_memory_node(const void *fdt, int node, @@ -338,6 +340,34 @@ static void __init process_chosen_node(const void *fdt, int node, add_boot_module(BOOTMOD_RAMDISK, start, end-start, false); } +static int __init process_domain_node(const void *fdt, int node, + const char *name, + u32 address_cells, u32 size_cells) +{ + const struct fdt_property *prop; + + printk("Checking for \"xen,static-mem\" in domain node\n"); + + prop = fdt_get_property(fdt, node, "xen,static-mem", NULL); + if ( !prop ) + /* No "xen,static-mem" present. */ + return 0; + + address_cells = device_tree_get_u32(fdt, node, + "#xen,static-mem-address-cells", 0); + size_cells = device_tree_get_u32(fdt, node, + "#xen,static-mem-size-cells", 0); + if ( address_cells < 1 || size_cells < 1 ) + { + printk("fdt: node `%s': invalid #xen,static-mem-address-cells or #xen,static-mem-size-cells", + name); + return -EINVAL; + } + + return device_tree_get_meminfo(fdt, node, "xen,static-mem", address_cells, + size_cells, &bootinfo.reserved_mem, true); +} + static int __init early_scan_node(const void *fdt, int node, const char *name, int depth, u32 address_cells, u32 size_cells, @@ -356,6 +386,8 @@ static int __init early_scan_node(const void *fdt, process_multiboot_node(fdt, node, name, address_cells, size_cells); else if ( depth == 1 && device_tree_node_matches(fdt, node, "chosen") ) 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); if ( rc < 0 ) printk("fdt: node `%s': parsing failed\n", name); diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h index c4b6af6029..6c3c16294b 100644 --- a/xen/include/asm-arm/setup.h +++ b/xen/include/asm-arm/setup.h @@ -24,6 +24,7 @@ typedef enum { struct membank { paddr_t start; paddr_t size; + bool xen_domain; /* whether memory bank is bind to Xen domain. */ }; struct meminfo { From patchwork Tue Aug 24 09:50:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12454419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CA08C43214 for ; Tue, 24 Aug 2021 09:51:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C1D3C60FD8 for ; Tue, 24 Aug 2021 09:51:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C1D3C60FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.170781.311721 (Exim 4.92) (envelope-from ) id 1mIT5l-0002ZA-CM; Tue, 24 Aug 2021 09:51:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 170781.311721; Tue, 24 Aug 2021 09:51:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5l-0002Yf-8P; Tue, 24 Aug 2021 09:51:37 +0000 Received: by outflank-mailman (input) for mailman id 170781; Tue, 24 Aug 2021 09:51:35 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5j-0001jx-IR for xen-devel@lists.xenproject.org; Tue, 24 Aug 2021 09:51:35 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (unknown [40.107.4.84]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d863c26d-04c0-11ec-a8bd-12813bfff9fa; Tue, 24 Aug 2021 09:51:27 +0000 (UTC) Received: from AM6PR04CA0071.eurprd04.prod.outlook.com (2603:10a6:20b:f0::48) by VI1PR08MB3312.eurprd08.prod.outlook.com (2603:10a6:803:46::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.17; Tue, 24 Aug 2021 09:51:25 +0000 Received: from AM5EUR03FT019.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:f0:cafe::68) by AM6PR04CA0071.outlook.office365.com (2603:10a6:20b:f0::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:25 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT019.mail.protection.outlook.com (10.152.16.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:24 +0000 Received: ("Tessian outbound 1a0c40aa17d8:v103"); Tue, 24 Aug 2021 09:51:24 +0000 Received: from 18d40905e8f9.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4D58BF8A-4FE5-4505-AAFF-1BEBA3EA22FE.1; Tue, 24 Aug 2021 09:51:17 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 18d40905e8f9.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 24 Aug 2021 09:51:17 +0000 Received: from AM5PR0201CA0003.eurprd02.prod.outlook.com (2603:10a6:203:3d::13) by AM7PR08MB5445.eurprd08.prod.outlook.com (2603:10a6:20b:10d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Tue, 24 Aug 2021 09:51:16 +0000 Received: from VE1EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:3d:cafe::18) by AM5PR0201CA0003.outlook.office365.com (2603:10a6:203:3d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.17 via Frontend Transport; Tue, 24 Aug 2021 09:51:16 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT044.mail.protection.outlook.com (10.152.19.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:16 +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.14; Tue, 24 Aug 2021 09:51:12 +0000 Received: from penny.shanghai.arm.com (10.169.190.66) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.14 via Frontend Transport; Tue, 24 Aug 2021 09:51: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: d863c26d-04c0-11ec-a8bd-12813bfff9fa 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=AMCW5xXNqkaV3p45gVg1gz98GeXvw0DWsgYQwmmZLho=; b=5ZRAdd6cAXgBwK/nXdk+hMT/o2xm0O5gJ2dgHPaHTKkyi+OjNEt5Sym5ehlP8A2PKBAC9oUZCgoOvMIEJF783yvoAchpKTfM7z4eNpsVThtx7Z4Ty2TtE+HeHa89Fd6schNKOpIb6CBBntn3eFeJLUxk5TG2cgb8PgXhkbhBu+4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.xenproject.org; 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: 63a0de5792350791 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L0CANS+3Am7tSyU1YmB3Ge8ooBZfY9OUIZnvseDvN50zkmxoQKJhxHfMgufDGLyZG2RORklgALxnKt5lYLDESM0vUTWBpJ/fIfnsPNf/1Px/j57EaJCC7NDWsah6ZSWqd6LUIlOhZK5Nifc+xclSPntROpw7pl3Rx7VYRF1sWu9GJa/LFomPmkRW4isvhdqVUjI0qafCKuMCSAsnxs2oH+2bmqlImToZQcxnmzksQtwc5u6psEyQ+2ONouHj6IcEb1kqwBbO/7+8qKAMUVHVBh3KDsWkrv3zGSLoAqJqzvNa/TV7um6rVA+Sb+x0HT74H3iakqZCt1WwrtkKu+I64w== 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-SenderADCheck; bh=AMCW5xXNqkaV3p45gVg1gz98GeXvw0DWsgYQwmmZLho=; b=XL0yM/S9QBUjyjblxFs64l1gFXj+iLIy6qDcSsgdj9XQ3lClMQirCfe0cxM9wENodT9pGljYdKmp2S0zOS4TOhKbvOJsgh7jqIhLzjzNM8YvGuzURSYobsAFJpDJBizFVmgFXylC1kJcnf138H1h8Tzaq76RlciPPRewPZAoCap7gR+EuKRBUym0TzhmM64rdU7Ham507BkLEq3j/6t5dqRRRlKsXbPJglAXb4jaKQbGiNH+eCh40hNjwZiGKYuFfDj5rCjWSEeDSFHA7Q8Ra6k6FBxDE6XF0852Mr6NMkId+jNBMYMSZeNyksDnmfKuXcAaiMeDnqbbBV5ibLNTSg== 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=AMCW5xXNqkaV3p45gVg1gz98GeXvw0DWsgYQwmmZLho=; b=5ZRAdd6cAXgBwK/nXdk+hMT/o2xm0O5gJ2dgHPaHTKkyi+OjNEt5Sym5ehlP8A2PKBAC9oUZCgoOvMIEJF783yvoAchpKTfM7z4eNpsVThtx7Z4Ty2TtE+HeHa89Fd6schNKOpIb6CBBntn3eFeJLUxk5TG2cgb8PgXhkbhBu+4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; 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: , , , Subject: [PATCH v5 3/7] xen: introduce mark_page_free Date: Tue, 24 Aug 2021 09:50:41 +0000 Message-ID: <20210824095045.2281500-4-penny.zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824095045.2281500-1-penny.zheng@arm.com> References: <20210824095045.2281500-1-penny.zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 696ecbd7-dcb3-4257-7004-08d966e4bc3c X-MS-TrafficTypeDiagnostic: AM7PR08MB5445:|VI1PR08MB3312: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:1051;OLM:1051; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: QcX7D+JbneCSXtwTIyLOQla7fMrnaytAJj+ZCw4VnU46V54AiBk/9HlAdZLkIAKt3Dx3B8dRkeitirVj2EJxHkQ/MW9V9b+Z101Vr1ksWW2lPw++va0o+dLnUZosCv7+lygkHZdGDbPHbdGKzCEENwKlMq3Fc8/1CAcS8Yactee5GSqRUrm2vdYFzxAyiGelwRiVvf01iXC3ZeGweb6qTpMq2C5OuEcGNU6jq6e1Upn1SnvH/iqkq2v18C7bNTUzXpULmuDLahtfiMKZfRUE6bKhmPd3YIW98SML6ssCxFEIc4G9sfqSarvIp2FruXk3zfMUMObkDygY6UmhuWXflF7v2NlNMtp2XDjD0w6jY2hCApvd1xXEs2oAyD1+2uXLHEhhCOls+WKe6ZeJDOuicvHwmw0qRyNp/yfBLSff+Km6jcqFKUkN3ePZy9cENcf63mX4kyzwuzcRSaUzKXlKudNdiGpBKboWyzfe7HX/gGpvHcFQTj8iQLLZMqXDPWzjHPclqC8Q/dcQh9qX16SrZcEeW6J/3M3s945mgVa9p2w2EeUxTDcPiyfNnj/ikc9Db2PFmo7b2IZ4BOJTa0rmn9vo0hCr/rXNd+6GuNoVvAlhD/7u7f0raMgM5dzXUb+s+AInM11FJxeaK6WeEUh4PyI/78oI7wwcPBihiBaoUZTiYY17tzy7XbV7ghKTWs7RJKKZ0JpJglMHX9/qyJFV8r/0hyZ4spdW/2LetvxAcyM= 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:(4636009)(39860400002)(346002)(376002)(396003)(136003)(36840700001)(46966006)(2906002)(2616005)(44832011)(36860700001)(82740400003)(81166007)(356005)(36756003)(7696005)(86362001)(5660300002)(186003)(70206006)(26005)(70586007)(110136005)(1076003)(316002)(478600001)(54906003)(336012)(82310400003)(426003)(83380400001)(8676002)(47076005)(6666004)(8936002)(4326008)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5445 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 3dc5b45b-910c-4b24-72d0-08d966e4b78c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J7rGBK5BCA+uVVFjqjW8klJm0ezvawODyTwVioZMawknNCHk35jFdxG3173RtuqLrdsL+g23zNl2UHmJ6GNEnyN2W6Dbmn7pnsp7pVkM2Pje+XWbGs41d1IKDCL2ULkKSc9G0xw8bh5shQyaeFi0RiPc9j/sauRV7AwLnYXaT+7IcoEJSp0vkU8siYFgfdwSJNHw43MVDQ31IFpF0dTWQP8bXRSmnvxTl1t+etMi6uFj93+pwCcBOWZDpjLzOFxkPz6Y8AQdSTbdD0EIo7u0rZUk/yzQoBFP0NCcTC0OWfUNgmqEsk+c60kF/cPwzT5mVEZcBHOjU7wy0S7QZ0sUOxTG2AXLppxeSpv23hN8MP8hyxg7jzToB+4OcXwyXgyM/vLVLp19ePsetftw4DPd+5DUWyyUhfAtVG6DxZGuGCJ68674OdvT1kOqcnfuTT0HF1vNGEiLS02aJfG2e/mqE+VwFtTd+4F6bJx3K/NptiifFpbRcjJ80h1a4AXBqHKjPgC9AqaUgNF9q6aeJA8sTG2UKf69eybP/2IUVfvVx9e8bh6Y6Mc3gxTt4X+4le0MPbf7NwqN6bAAXiGZMArR/c4BSlsXBclMi8KdlN7Vbg0GV/iXJmt0xpj8N5YEk3ZCWJp0N5HixUb1Fj2Dm2IYcv2vu4NiayvYJzXzJUCiNZ4W/HhebSr0JXcH+irpYeaSrNSCR5bXrjfsZ8PCdK2hYQ== 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:(4636009)(39860400002)(136003)(396003)(376002)(346002)(36840700001)(46966006)(6666004)(336012)(26005)(81166007)(110136005)(7696005)(8936002)(1076003)(186003)(70586007)(2906002)(70206006)(5660300002)(316002)(426003)(54906003)(2616005)(36756003)(47076005)(4326008)(82310400003)(36860700001)(82740400003)(8676002)(44832011)(478600001)(83380400001)(86362001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 09:51:24.5520 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 696ecbd7-dcb3-4257-7004-08d966e4bc3c 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: AM5EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3312 This commit defines a new helper mark_page_free to extract common code, like following the same cache/TLB coherency policy, between free_heap_pages and the new function free_staticmem_pages, which will be introduced later. The PDX compression makes that conversion between the MFN and the page can be potentially non-trivial. As the function is internal, pass the MFN and the page. They are both expected to match. Signed-off-by: Penny Zheng Acked-by: Jan Beulich Reviewed-by: Julien Grall --- xen/common/page_alloc.c | 89 ++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 958ba0cd92..a3ee5eca9e 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1376,6 +1376,53 @@ bool scrub_free_pages(void) return node_to_scrub(false) != NUMA_NO_NODE; } +static void mark_page_free(struct page_info *pg, mfn_t mfn) +{ + ASSERT(mfn_x(mfn) == mfn_x(page_to_mfn(pg))); + + /* + * Cannot assume that count_info == 0, as there are some corner cases + * where it isn't the case and yet it isn't a bug: + * 1. page_get_owner() is NULL + * 2. page_get_owner() is a domain that was never accessible by + * its domid (e.g., failed to fully construct the domain). + * 3. page was never addressable by the guest (e.g., it's an + * auto-translate-physmap guest and the page was never included + * in its pseudophysical address space). + * In all the above cases there can be no guest mappings of this page. + */ + switch ( pg->count_info & PGC_state ) + { + case PGC_state_inuse: + BUG_ON(pg->count_info & PGC_broken); + pg->count_info = PGC_state_free; + break; + + case PGC_state_offlining: + pg->count_info = (pg->count_info & PGC_broken) | + PGC_state_offlined; + tainted = 1; + break; + + default: + printk(XENLOG_ERR + "pg MFN %"PRI_mfn" c=%#lx o=%u v=%#lx t=%#x\n", + mfn_x(mfn), + pg->count_info, pg->v.free.order, + pg->u.free.val, pg->tlbflush_timestamp); + BUG(); + } + + /* If a page has no owner it will need no safety TLB flush. */ + pg->u.free.need_tlbflush = (page_get_owner(pg) != NULL); + if ( pg->u.free.need_tlbflush ) + page_set_tlbflush_timestamp(pg); + + /* This page is not a guest frame any more. */ + page_set_owner(pg, NULL); /* set_gpfn_from_mfn snoops pg owner */ + set_gpfn_from_mfn(mfn_x(mfn), INVALID_M2P_ENTRY); +} + /* Free 2^@order set of pages. */ static void free_heap_pages( struct page_info *pg, unsigned int order, bool need_scrub) @@ -1392,47 +1439,7 @@ static void free_heap_pages( for ( i = 0; i < (1 << order); i++ ) { - /* - * Cannot assume that count_info == 0, as there are some corner cases - * where it isn't the case and yet it isn't a bug: - * 1. page_get_owner() is NULL - * 2. page_get_owner() is a domain that was never accessible by - * its domid (e.g., failed to fully construct the domain). - * 3. page was never addressable by the guest (e.g., it's an - * auto-translate-physmap guest and the page was never included - * in its pseudophysical address space). - * In all the above cases there can be no guest mappings of this page. - */ - switch ( pg[i].count_info & PGC_state ) - { - case PGC_state_inuse: - BUG_ON(pg[i].count_info & PGC_broken); - pg[i].count_info = PGC_state_free; - break; - - case PGC_state_offlining: - pg[i].count_info = (pg[i].count_info & PGC_broken) | - PGC_state_offlined; - tainted = 1; - break; - - default: - printk(XENLOG_ERR - "pg[%u] MFN %"PRI_mfn" c=%#lx o=%u v=%#lx t=%#x\n", - i, mfn_x(mfn) + i, - pg[i].count_info, pg[i].v.free.order, - pg[i].u.free.val, pg[i].tlbflush_timestamp); - BUG(); - } - - /* If a page has no owner it will need no safety TLB flush. */ - pg[i].u.free.need_tlbflush = (page_get_owner(&pg[i]) != NULL); - if ( pg[i].u.free.need_tlbflush ) - page_set_tlbflush_timestamp(&pg[i]); - - /* This page is not a guest frame any more. */ - page_set_owner(&pg[i], NULL); /* set_gpfn_from_mfn snoops pg owner */ - set_gpfn_from_mfn(mfn_x(mfn) + i, INVALID_M2P_ENTRY); + mark_page_free(&pg[i], mfn_add(mfn, i)); if ( need_scrub ) { From patchwork Tue Aug 24 09:50:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12454421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACC11C4338F for ; Tue, 24 Aug 2021 09:51:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 5944F60E52 for ; Tue, 24 Aug 2021 09:51:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5944F60E52 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.170782.311739 (Exim 4.92) (envelope-from ) id 1mIT5p-0003Bi-0P; Tue, 24 Aug 2021 09:51:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 170782.311739; Tue, 24 Aug 2021 09:51: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 1mIT5o-0003BV-PR; Tue, 24 Aug 2021 09:51:40 +0000 Received: by outflank-mailman (input) for mailman id 170782; Tue, 24 Aug 2021 09:51:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5n-0002Tu-RN for xen-devel@lists.xenproject.org; Tue, 24 Aug 2021 09:51:39 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (unknown [40.107.7.47]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 418e4ad9-99d2-4efc-868e-5257f7469a34; Tue, 24 Aug 2021 09:51:37 +0000 (UTC) Received: from AM5PR0601CA0045.eurprd06.prod.outlook.com (2603:10a6:203:68::31) by AM5PR0801MB1923.eurprd08.prod.outlook.com (2603:10a6:203:4c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 09:51:25 +0000 Received: from AM5EUR03FT027.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:68:cafe::6d) by AM5PR0601CA0045.outlook.office365.com (2603:10a6:203:68::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:25 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT027.mail.protection.outlook.com (10.152.16.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:25 +0000 Received: ("Tessian outbound 19a632698c93:v103"); Tue, 24 Aug 2021 09:51:25 +0000 Received: from e619e60a2b94.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 25436489-2F15-4110-B2B4-DE307DDF86E3.1; Tue, 24 Aug 2021 09:51:19 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e619e60a2b94.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 24 Aug 2021 09:51:19 +0000 Received: from AM5PR0201CA0016.eurprd02.prod.outlook.com (2603:10a6:203:3d::26) by AS8PR08MB6198.eurprd08.prod.outlook.com (2603:10a6:20b:29f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 09:51:17 +0000 Received: from VE1EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:3d:cafe::b3) by AM5PR0201CA0016.outlook.office365.com (2603:10a6:203:3d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.17 via Frontend Transport; Tue, 24 Aug 2021 09:51:17 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT044.mail.protection.outlook.com (10.152.19.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:17 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.14; Tue, 24 Aug 2021 09:51:16 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Tue, 24 Aug 2021 09:51:13 +0000 Received: from penny.shanghai.arm.com (10.169.190.66) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.14 via Frontend Transport; Tue, 24 Aug 2021 09:51:13 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 418e4ad9-99d2-4efc-868e-5257f7469a34 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=zA8vK69jWi9elV7ywSF5xfDQGg45S54vXFg9HWwKfbA=; b=nMYTi8fUExyK2GA8yIgPAKUMvhLjkHU8li+A3+yoWD7ifg+MkPLwgotbS+YilJ1+STNR5xq93ZEA6QDfvxLmUO9sQiCvqMHJwZkX/RtYcpmpAan80UFSbOGxP2rBmsxXMzh3Y7qKIy8gtBBgKBxdHNOYeMjzump6vG3FyWk4VLc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.xenproject.org; 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: 7d9a61e54c426259 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q8ktLPRGGRW4fQ6Aa7S7NNSWoWs1VEK2p2hfcf0lRi3z8fdG2gpUGgFE9hQv3NVbdp1zS/KDCo+fijqyst8/QINmhrhoMqVZJdYnHXX/B8jM8tOjx7xRXy7WyBrj4Bmszy2xYhYnUx/yXx0FKF36Pf2RP4uCuqsK6OsxBDS7JuKQBFrVvpzcBn3G6G5aFmIfG7/4Ute+BYOQ3gMlMRKLgtFmA7y6IY/j9tj79qbAws9libcrQ/5jwQMMkSMMkUi3YNMp0j0DUZrupbXFvGIMb38mViAUIkS6RfszEIVxieyJPu2uHV3dcqQxlOMOF5AsJlvbbllzbfQDAAZ7OB5Jkw== 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-SenderADCheck; bh=zA8vK69jWi9elV7ywSF5xfDQGg45S54vXFg9HWwKfbA=; b=YaDuTvjDpZ5y25XMDrBsRcxRsKouJAn6E6FRd3hUjqqcUr/Bw1/YahP4BGcPme5dN68Ne2dUi4QJzT+++dsRTFNZYsRMsBNehhkdRl/qaWdLHGHOFVZDNWLFeFec+ZKTmw63myZStlI7yUaI3Jbzo0Cbj5zAaiA+GNvu6mw1GOjzkLkAGgtTGF8r35YxLo4fn25mTRr2Pgm29zZboIKjLuZm4Gz/R/uOTmr+YWdHGHb1XH3JMWugUADSArWWmRr7OcSoFw3qsub2w5LFyOarGSzTndSipn3J2cBQbhIG2WYGp3C8d8ft/lQHov25pLEUhBmvOPtq5zjtDLbzCYBetA== 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=zA8vK69jWi9elV7ywSF5xfDQGg45S54vXFg9HWwKfbA=; b=nMYTi8fUExyK2GA8yIgPAKUMvhLjkHU8li+A3+yoWD7ifg+MkPLwgotbS+YilJ1+STNR5xq93ZEA6QDfvxLmUO9sQiCvqMHJwZkX/RtYcpmpAan80UFSbOGxP2rBmsxXMzh3Y7qKIy8gtBBgKBxdHNOYeMjzump6vG3FyWk4VLc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; 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: , , , Subject: [PATCH v5 4/7] xen/arm: static memory initialization Date: Tue, 24 Aug 2021 09:50:42 +0000 Message-ID: <20210824095045.2281500-5-penny.zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824095045.2281500-1-penny.zheng@arm.com> References: <20210824095045.2281500-1-penny.zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b8b67c96-e7b6-42cf-5dab-08d966e4bcb2 X-MS-TrafficTypeDiagnostic: AS8PR08MB6198:|AM5PR0801MB1923: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:277;OLM:277; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ijPQoXv5naNyvinRjfwQt8mVYP65oSCUwp61hhsaTBrpUPrIq42lpqkX7zhupf9WdeNrQlLTLopN2Hb/X9obkTqL1RdZ0y1yTxNKMTOaxgzrSD8swQ8hVPLAIMiA6Ylv+8U66rdsBrhK3YnJKoOVTNoaxrpPSR8BjsmI8UfZgstNAHLD91GMbr44wMcCsp0zPfi/VI5KclTbpEpRq83yinoUTlKL35gyJJb86AloJ7QzhpkZ4pozYY9DHemZIyQ3Ew8BLIRlWk378++uh8kwBU4QxfU1GfPPT/gh7OlG1SY56SU48WduEp5//hSHSOUAUKBPUrmyl7ad2x141e4byQebZ6A6moc/o+n1RgPE+CVrXqhYC18w2ZAL0AkjhoxsbWRkDFvOXxJVsP6GWw9qj6RUK9EprgINt3nTISlU/QbY/TC3w+6GsW+sT2avnB+pynCXyV0CUeQ4I2HcNA783DyIEZh4/IER4p3kXdJaXT5pmFe+Sxcg54GPvx+R5VJoyTP5RVV73xGUqpNb5tU8LSM7cs2vfeMg6SZFRRx0xuSXcIFlXnc0ExMGjq00Z3x4de2qPKROuuye4/C1O/dAGuRtwiBVmNxej2OsaG6k1WszX+CYrP7y6u4XdFBxlQgivNnD9GpKzfmCKalPbIwdURL/qtq3phNRvuuWOzIqh4h0+cwXG56//EBzdnFF8YtVvhYEZF0EpG0mrNQVkJ8vB7jl/g3zGUKpbCEagF7Y5ow= 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:(4636009)(136003)(376002)(39860400002)(396003)(346002)(36840700001)(46966006)(47076005)(316002)(83380400001)(82740400003)(110136005)(86362001)(4326008)(6666004)(1076003)(54906003)(36860700001)(7696005)(2906002)(336012)(426003)(70206006)(36756003)(26005)(8676002)(478600001)(2616005)(5660300002)(8936002)(81166007)(82310400003)(44832011)(186003)(356005)(70586007)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6198 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: ddcf9125-94d3-44dd-2dfa-08d966e4b82f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iczQqjcXB3iu09BsSP9rpRJtoa6TVUgENmZgZi6b3j6fuwO6OIRuCZWJ6N+0mJdK5AULk8bdQjS5HtA+Wy/K3BhYHJab7HkkplaepztN4CTdWaGxObwBf1KJcB9hYw8UOU4MI1lHXYyW4u3wt6UZI/cW4nn9MhXQc0/DyQZ6qz/7UNkuUjsIPQh8TAE8euWE1Nxhjf3QIC4DI2S52sZ+I4+Y+DiyJ7YmbKrIKSx+Bsy8gMyPl61sP4uCxs8Hts1QvZG8reBOurLJaw0XX6UUoKW+JUn0qNS2U5U3OgzFpb3izFbZxfk2O7H4ZnYETE6mBKbmj8Igv6y6obtu/TihJjVmEuqvZhECM75yj4XTeSHbP1vZKg+Mme6pMugtzYawM+AuJfsvvBnIOOrCXQuWQt90tLEzFGEinQmZcx/r4HLEyrllFk9GcLXxOhK8x9FPVkwWGZD0sn0bgDqmQLYjbgoCzpa3bs2uLDA9IhZwW4jH/rgxq07HIatGTqlVIsZ04RtGeUvBsIwmDcNOnX9w7YwqNi/CXZW2M+5aDH5CbvLTXkSA54bRbRYTUqSXe1TqjlnVczlWQKsoDaJiLpIGRod18w60cG1Lbuj19D/jc/PsVsaVSS5C4ebrnjalQaPaWjIwfWwzeOeLlAd2oTh7zeRL9QuJgseC18VJka8F9k7BYskesepzBFxJ284E8ixZB0bH3Tz8X0pr+AGpUbETBQ== 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:(4636009)(346002)(396003)(39860400002)(376002)(136003)(46966006)(36840700001)(7696005)(6666004)(5660300002)(86362001)(478600001)(2906002)(44832011)(36860700001)(316002)(1076003)(54906003)(36756003)(110136005)(2616005)(426003)(4326008)(83380400001)(336012)(26005)(82310400003)(47076005)(70206006)(82740400003)(186003)(70586007)(8936002)(81166007)(8676002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 09:51:25.3458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b8b67c96-e7b6-42cf-5dab-08d966e4bcb2 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: AM5EUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1923 This patch introduces static memory initialization, during system boot up. The new function init_staticmem_pages is responsible for static memory initialization. Helper free_staticmem_pages is the equivalent of free_heap_pages, to free nr_mfns pages of static memory. This commit also introduces new CONFIG_STATIC_MEMORY to wrap all static-allocation-related codes. Put asynchronous scrubbing for pages of static memory in TODO list. Signed-off-by: Penny Zheng --- v5 change: - make CONFIG_STATIC_MEMORY user selectable and gated by UNSUPPORTED. - wrap all static-allocation-related codes with CONFIG_STATIC_MEMORY even in arm-specific file. - make bank_start/bank_end type of mfn_t, and rename bank_size to bank_pages. --- xen/arch/arm/setup.c | 31 +++++++++++++++++++++++++++++++ xen/common/Kconfig | 17 +++++++++++++++++ xen/common/page_alloc.c | 22 +++++++++++++++++++++- xen/include/xen/mm.h | 6 ++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 63a908e325..44aca9f1b9 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -609,6 +609,29 @@ static void __init init_pdx(void) } } +#ifdef CONFIG_STATIC_MEMORY +/* Static memory initialization */ +static void __init init_staticmem_pages(void) +{ + unsigned int bank; + + for ( bank = 0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) + { + if ( bootinfo.reserved_mem.bank[bank].xen_domain ) + { + mfn_t bank_start = _mfn(PFN_UP(bootinfo.reserved_mem.bank[bank].start)); + unsigned long bank_pages = PFN_DOWN(bootinfo.reserved_mem.bank[bank].size); + mfn_t bank_end = mfn_add(bank_start, bank_pages); + + if ( mfn_x(bank_end) <= mfn_x(bank_start) ) + return; + + free_staticmem_pages(mfn_to_page(bank_start), bank_pages, false); + } + } +} +#endif + #ifdef CONFIG_ARM_32 static void __init setup_mm(void) { @@ -736,6 +759,10 @@ static void __init setup_mm(void) /* Add xenheap memory that was not already added to the boot allocator. */ init_xenheap_pages(mfn_to_maddr(xenheap_mfn_start), mfn_to_maddr(xenheap_mfn_end)); + +#ifdef CONFIG_STATIC_MEMORY + init_staticmem_pages(); +#endif } #else /* CONFIG_ARM_64 */ static void __init setup_mm(void) @@ -789,6 +816,10 @@ static void __init setup_mm(void) setup_frametable_mappings(ram_start, ram_end); max_page = PFN_DOWN(ram_end); + +#ifdef CONFIG_STATIC_MEMORY + init_staticmem_pages(); +#endif } #endif diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 0ddd18e11a..514a2c9022 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -67,6 +67,23 @@ config MEM_ACCESS config NEEDS_LIBELF bool +config STATIC_MEMORY + bool "Static Allocation Support (UNSUPPORTED)" if UNSUPPORTED + depends on ARM + ---help--- + Static Allocation refers to system or sub-system(domains) for + which memory areas are pre-defined by configuration using physical + address ranges. + + Those pre-defined memory, -- Static Memory, as parts of RAM reserved + during system boot-up, shall never go to heap allocator or boot + allocator for any use. + + When enabled, memory can be statically allocated to a domain using + the property "xen,static-mem" defined in the domain configuration. + + If unsure, say Y. + menu "Speculative hardening" config SPECULATIVE_HARDEN_ARRAY diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index a3ee5eca9e..2b4591bc56 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1519,7 +1519,6 @@ static void free_heap_pages( spin_unlock(&heap_lock); } - /* * Following rules applied for page offline: * Once a page is broken, it can't be assigned anymore @@ -2604,6 +2603,27 @@ struct domain *get_pg_owner(domid_t domid) return pg_owner; } +#ifdef CONFIG_STATIC_MEMORY +/* Equivalent of free_heap_pages to free nr_mfns pages of static memory. */ +void __init free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, + bool need_scrub) +{ + mfn_t mfn = page_to_mfn(pg); + unsigned long i; + + for ( i = 0; i < nr_mfns; i++ ) + { + mark_page_free(&pg[i], mfn_add(mfn, i)); + + if ( need_scrub ) + { + /* TODO: asynchronous scrubbing for pages of static memory. */ + scrub_one_page(pg); + } + } +} +#endif + /* * Local variables: * mode: C diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 667f9dac83..8e8fb5a615 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -85,6 +85,12 @@ bool scrub_free_pages(void); } while ( false ) #define FREE_XENHEAP_PAGE(p) FREE_XENHEAP_PAGES(p, 0) +#ifdef CONFIG_STATIC_MEMORY +/* These functions are for static memory */ +void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, + bool need_scrub); +#endif + /* Map machine page range in Xen virtual address space. */ int map_pages_to_xen( unsigned long virt, From patchwork Tue Aug 24 09:50:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12454423 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3C49C432BE for ; Tue, 24 Aug 2021 09:51:51 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6C9F560E52 for ; Tue, 24 Aug 2021 09:51:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6C9F560E52 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.170783.311750 (Exim 4.92) (envelope-from ) id 1mIT5q-0003WO-Gw; Tue, 24 Aug 2021 09:51:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 170783.311750; Tue, 24 Aug 2021 09:51: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 1mIT5q-0003Vz-Cu; Tue, 24 Aug 2021 09:51:42 +0000 Received: by outflank-mailman (input) for mailman id 170783; Tue, 24 Aug 2021 09:51:40 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5o-0001jx-Io for xen-devel@lists.xenproject.org; Tue, 24 Aug 2021 09:51:40 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (unknown [40.107.2.49]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d972d328-04c0-11ec-a8bd-12813bfff9fa; Tue, 24 Aug 2021 09:51:27 +0000 (UTC) Received: from AM6P191CA0063.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:7f::40) by AS8PR08MB6295.eurprd08.prod.outlook.com (2603:10a6:20b:295::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 09:51:25 +0000 Received: from VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:7f:cafe::4b) by AM6P191CA0063.outlook.office365.com (2603:10a6:209:7f::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:25 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT031.mail.protection.outlook.com (10.152.18.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:25 +0000 Received: ("Tessian outbound 6ba9ec11d42b:v103"); Tue, 24 Aug 2021 09:51:24 +0000 Received: from 2d60cc076f9f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id CCAB6915-C373-4258-A749-48723893509E.1; Tue, 24 Aug 2021 09:51:18 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 2d60cc076f9f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 24 Aug 2021 09:51:18 +0000 Received: from DU2PR04CA0315.eurprd04.prod.outlook.com (2603:10a6:10:2b5::20) by VE1PR08MB5743.eurprd08.prod.outlook.com (2603:10a6:800:1b2::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 09:51:17 +0000 Received: from DB5EUR03FT016.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:2b5:cafe::3f) by DU2PR04CA0315.outlook.office365.com (2603:10a6:10:2b5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.17 via Frontend Transport; Tue, 24 Aug 2021 09:51:17 +0000 Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT016.mail.protection.outlook.com (10.152.20.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:17 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.14; Tue, 24 Aug 2021 09:51:18 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Tue, 24 Aug 2021 09:51:16 +0000 Received: from penny.shanghai.arm.com (10.169.190.66) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.14 via Frontend Transport; Tue, 24 Aug 2021 09:51:15 +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: d972d328-04c0-11ec-a8bd-12813bfff9fa 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=IJALBkaGXtysRE/87767gpew+VdKasYR1FGSjePRRnw=; b=WTpj40YU/+KkiwTkxDcvgROVsnVptdQ07I2CihhfdBzbGmvU1pDMVBpBDU6WmZoQ4pOK+R1nlK0545Nw7whX3JWGUEMriTMWn8rKaVqEzEVB8kl4pZvCgqOfofMsJ+TKMENntjyget4lFk867oEFcIQ14NBdyq4imXSvzxuN5w8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.xenproject.org; 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: 15ab006417afe7aa X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nSu4DArNGnjLz665LvGmlp4ThA5V697BWwc8RWdxDY1XJJ5rfsaRt7CBzH0G22CYc7bUZeLRCZEYpIf1rDPDY2nfRar/gWefmbFJPY+vh2L7lF1LAdp0rFUrHLGl8RAe+M9WOs5TdluZoK2oTQ/RH2oA5iWyRqqg3loYhH5LsnIJ28cI3W3phD3y/NXM/GIw7yf0CzlxJE1Lxtm3hmpR373qRln9RiPOtpHVol2M3HSeTL1SRjTolbGh8ZTvUOVvQczdt5b4AD2Mmq3QE1pAMCfFNf/wFxMzpV+F66Og1ODKoCaBC1O0d3BfRExaA5C7fSgsDoSjAhy/iQshC8DNJw== 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-SenderADCheck; bh=IJALBkaGXtysRE/87767gpew+VdKasYR1FGSjePRRnw=; b=ZdO/EkqaQPIrPgQ+4INlaJ/re8NN8qgjMr/c4ZX1QnpfpX/s64L3I2prAgAx99LRLPvEcVc4vG6lPlWfKbLdduzCaoB7f7KTK3qdWAvorpT29ADCzxWjtz0gKHtdGWYurWX02NUBPcWyphNyCGAZmDRgEiYyxmFbTLXkX+rv/ou8xKn5ybJGJDqL3rpiux6TDESvrDlhNjuhX7mBKk5LuJLnQr9G1+5khppg5HqDjg4ROIGZAbnr0w2DJkG47RuBykvN2rqb76r6Abt8cDV8wMCIGBMbUFofhcAJ7MgBW50PywIqbPE/YjrEpjeorYGH4wgD2tXqOzgUgQPm3NUZhA== 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=IJALBkaGXtysRE/87767gpew+VdKasYR1FGSjePRRnw=; b=WTpj40YU/+KkiwTkxDcvgROVsnVptdQ07I2CihhfdBzbGmvU1pDMVBpBDU6WmZoQ4pOK+R1nlK0545Nw7whX3JWGUEMriTMWn8rKaVqEzEVB8kl4pZvCgqOfofMsJ+TKMENntjyget4lFk867oEFcIQ14NBdyq4imXSvzxuN5w8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; 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: , , , Subject: [PATCH v5 5/7] xen: re-define assign_pages and introduce assign_page Date: Tue, 24 Aug 2021 09:50:43 +0000 Message-ID: <20210824095045.2281500-6-penny.zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824095045.2281500-1-penny.zheng@arm.com> References: <20210824095045.2281500-1-penny.zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 73b428b6-1498-405c-a295-08d966e4bc87 X-MS-TrafficTypeDiagnostic: VE1PR08MB5743:|AS8PR08MB6295: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:288;OLM:288; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: G42+jB7tdPmCqQ9/iz9+hRIFMf004j/j++uru/RSXg6KypYyUrZ41eojCCPCvaTJWdXqejFveCRV8+V7sIXyzKkqt5ec/i3EvYeTNl2xDQLkbSVNlG+DMBYtmStkM9FXpdDQ4EzaoY3YOAYhT+ZQF4+y+VWPymCTN3yAFq4XPGsefdrZD8A/QQEpo1JC6EHJ5l6z50XPojtTvw4KJFMgz6NfVuZv/w+Ryc825iHanbhUEy+ImPQC/61O37wtQRo9M+EfA2svSpMNkJV8LtbtU8uYgDqV4YCQ54OLDLY1+vI1rLPjayeneuXMkNqyizzmtm5mGU2h+lspq9fyQg7mUw3rfyyQ/x8Z2dKc+99vVXRgVtKNzN3fFDa+cGIkJoYLyGk/qfCxiTmtkxEI2+mOzM9TPujBQzevPIigH6OozYid2N8hxl5RtzXJY0lgIBwywx59OWAWSZTRHseRRHkFPZZQaXmbLK62Y/dlBUy3eCs9jK7btmgePD1mXVJ5+XhPPuDXqYE6ha8gW53KS40NGQK0TL9MvVsZ8d6nx9PoHYI99h7gvMyF8oMR0dpbgTe0dybm/QWjMCDYXJlyIVRdKIEfJU8RtCTYjl7rfhvPusOJ1jMauZ1I26Ph0KgI0DtBVvOYmLdZ9wPrg1Ug6DkwPamFE7D5IvuB0tSPKLEQMOPBXXshC3tIpz9x2BzK/yMvj/MgqNmX+EVFiLwbPzajUHJrr37g41r9e845FRG6zEk= 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:(4636009)(396003)(346002)(376002)(136003)(39860400002)(36840700001)(46966006)(70206006)(70586007)(26005)(426003)(6666004)(186003)(5660300002)(478600001)(336012)(47076005)(83380400001)(82310400003)(36860700001)(8676002)(82740400003)(36756003)(356005)(2906002)(316002)(4326008)(8936002)(86362001)(7696005)(1076003)(110136005)(54906003)(81166007)(2616005)(44832011)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5743 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 9ca43312-6b8b-4eca-d05a-08d966e4b811 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OHN6+9rk2RgzVfOnP9xVzyLSUBV9wBdDGneZaLjw8TCxYJu19fXfGYuvRc220JogfUkArzClxUpM7jhgwQF/HhjdVzFPPOA2id3pqISRe5fUi/I/pNK+7YOniwJ7Mtny0M3pBVd+85GSqslg7pTHYh/beCLSsNzmOOBy6e9ryBq2fuTivOuDiHovp+DiN5u6pLbWVdc6sZJ6TsnmZbNSmboZ50FE+pNCR/0x4x3NzM32QY6kEEO/awYa+I3V0uN5GDUt5+a4THkCFLMw70irpJgfAx3ZOZ8PTF21gNROPV9NVBMPPlnFo5Qy7Rn3ONoFLmQ7j8ZfxBHkMTcr26Q+Y0bb4CwMPVt5wADi19c5fqoOwruCojBa8kSFg0iD8kEGXU6WIINch4JGgwIMHH4V8q+YfOzBVDISTp1GVO/xc/XjOJpFEG+Ea8hXm8R/sn6KAOQbDTyc+3lYL6sppcR3xGGkjX0aF6r+Ih+1DFOgGH05ZDCSjLl1EDyfBQGBC0dGxvMdJ0gMnBiPbSvfVBpFwNwmG4Tsb9B+lUP4MMUd0+nw9PcXl9edwDub9H6Bzz9ZmI3MQtJWPedkr0VvLGJcCTPd9m8Kna6qmQwVgkigWRlAv7FgJJ+HLjWX5xAYBre/fgTluwnV3jTaY2yheWy/fVKQBhA5m4c/hwz+6HYxUn7dfgXqLlCG3ZYCjiQQ783fcgcoDIVqmZKWMUmy48HPCw== 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:(4636009)(39860400002)(396003)(376002)(136003)(346002)(46966006)(36840700001)(47076005)(36860700001)(316002)(7696005)(36756003)(110136005)(70206006)(4326008)(70586007)(2616005)(186003)(82310400003)(1076003)(54906003)(8676002)(81166007)(26005)(8936002)(6666004)(86362001)(44832011)(5660300002)(478600001)(336012)(82740400003)(83380400001)(426003)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 09:51:25.0128 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 73b428b6-1498-405c-a295-08d966e4bc87 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: VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6295 In order to deal with the trouble of count-to-order conversion when page number is not in a power-of-two, this commit re-define assign_pages for nr pages and assign_page for original page with a single order. Signed-off-by: Penny Zheng Acked-by: Jan Beulich --- v5 change: - Having both functions assign_pages/assign_page with similar parameter arrangement --- xen/arch/x86/pv/dom0_build.c | 2 +- xen/common/grant_table.c | 2 +- xen/common/memory.c | 4 ++-- xen/common/page_alloc.c | 21 +++++++++++++-------- xen/include/xen/mm.h | 6 ++++++ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index d5a1a6a4e2..ebbafe48f3 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -557,7 +557,7 @@ int __init dom0_construct_pv(struct domain *d, else { while ( count-- ) - if ( assign_pages(d, mfn_to_page(_mfn(mfn++)), 0, 0) ) + if ( assign_pages(d, mfn_to_page(_mfn(mfn++)), 1, 0) ) BUG(); } initrd->mod_end = 0; diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index fab77ab9cc..1e138201a5 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -2342,7 +2342,7 @@ gnttab_transfer( * is respected and speculative execution is blocked accordingly */ if ( unlikely(!evaluate_nospec(okay)) || - unlikely(assign_pages(e, page, 0, MEMF_no_refcount)) ) + unlikely(assign_pages(e, page, 1, MEMF_no_refcount)) ) { bool drop_dom_ref; diff --git a/xen/common/memory.c b/xen/common/memory.c index e07bd9a5ea..e22dad2c37 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -728,7 +728,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg) /* Assign each output page to the domain. */ for ( j = 0; (page = page_list_remove_head(&out_chunk_list)); ++j ) { - if ( assign_pages(d, page, exch.out.extent_order, + if ( assign_page(d, page, exch.out.extent_order, MEMF_no_refcount) ) { unsigned long dec_count; @@ -797,7 +797,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg) * cleared PGC_allocated. */ while ( (page = page_list_remove_head(&in_chunk_list)) ) - if ( assign_pages(d, page, 0, MEMF_no_refcount) ) + if ( assign_pages(d, page, 1, MEMF_no_refcount) ) { BUG_ON(!d->is_dying); free_domheap_page(page); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 2b4591bc56..05c9834dc2 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2260,7 +2260,7 @@ void init_domheap_pages(paddr_t ps, paddr_t pe) int assign_pages( struct domain *d, struct page_info *pg, - unsigned int order, + unsigned long nr, unsigned int memflags) { int rc = 0; @@ -2280,7 +2280,7 @@ int assign_pages( { unsigned int extra_pages = 0; - for ( i = 0; i < (1ul << order); i++ ) + for ( i = 0; i < nr; i++ ) { ASSERT(!(pg[i].count_info & ~PGC_extra)); if ( pg[i].count_info & PGC_extra ) @@ -2289,18 +2289,18 @@ int assign_pages( ASSERT(!extra_pages || ((memflags & MEMF_no_refcount) && - extra_pages == 1u << order)); + extra_pages == nr)); } #endif if ( pg[0].count_info & PGC_extra ) { - d->extra_pages += 1u << order; + d->extra_pages += nr; memflags &= ~MEMF_no_refcount; } else if ( !(memflags & MEMF_no_refcount) ) { - unsigned int tot_pages = domain_tot_pages(d) + (1 << order); + unsigned int tot_pages = domain_tot_pages(d) + nr; if ( unlikely(tot_pages > d->max_pages) ) { @@ -2312,10 +2312,10 @@ int assign_pages( } if ( !(memflags & MEMF_no_refcount) && - unlikely(domain_adjust_tot_pages(d, 1 << order) == (1 << order)) ) + unlikely(domain_adjust_tot_pages(d, nr) == nr) ) get_knownalive_domain(d); - for ( i = 0; i < (1 << order); i++ ) + for ( i = 0; i < nr; i++ ) { ASSERT(page_get_owner(&pg[i]) == NULL); page_set_owner(&pg[i], d); @@ -2330,6 +2330,11 @@ int assign_pages( return rc; } +int assign_page(struct domain *d, struct page_info *pg, unsigned int order, + unsigned int memflags) +{ + return assign_pages(d, pg, 1UL << order, memflags); +} struct page_info *alloc_domheap_pages( struct domain *d, unsigned int order, unsigned int memflags) @@ -2372,7 +2377,7 @@ struct page_info *alloc_domheap_pages( pg[i].count_info = PGC_extra; } } - if ( assign_pages(d, pg, order, memflags) ) + if ( assign_page(d, pg, order, memflags) ) { free_heap_pages(pg, order, memflags & MEMF_no_scrub); return NULL; diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 8e8fb5a615..f243ff88d7 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -132,6 +132,12 @@ int query_page_offline(mfn_t mfn, uint32_t *status); void heap_init_late(void); int assign_pages( + struct domain *d, + struct page_info *pg, + unsigned long nr, + unsigned int memflags); + +int assign_page( struct domain *d, struct page_info *pg, unsigned int order, From patchwork Tue Aug 24 09:50:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12454415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07262C43216 for ; Tue, 24 Aug 2021 09:51:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 948C060E52 for ; Tue, 24 Aug 2021 09:51:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 948C060E52 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.170780.311717 (Exim 4.92) (envelope-from ) id 1mIT5l-0002WL-3T; Tue, 24 Aug 2021 09:51:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 170780.311717; Tue, 24 Aug 2021 09:51:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5k-0002WA-Ua; Tue, 24 Aug 2021 09:51:36 +0000 Received: by outflank-mailman (input) for mailman id 170780; Tue, 24 Aug 2021 09:51:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5i-0002Tu-UE for xen-devel@lists.xenproject.org; Tue, 24 Aug 2021 09:51:34 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (unknown [40.107.21.85]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 84e98b07-5ae5-4789-b99a-3304ca552e00; Tue, 24 Aug 2021 09:51:32 +0000 (UTC) Received: from AM6PR01CA0071.eurprd01.prod.exchangelabs.com (2603:10a6:20b:e0::48) by AM9PR08MB6084.eurprd08.prod.outlook.com (2603:10a6:20b:287::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Tue, 24 Aug 2021 09:51:30 +0000 Received: from AM5EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:e0:cafe::28) by AM6PR01CA0071.outlook.office365.com (2603:10a6:20b:e0::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:30 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT009.mail.protection.outlook.com (10.152.16.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:29 +0000 Received: ("Tessian outbound 6ba9ec11d42b:v103"); Tue, 24 Aug 2021 09:51:29 +0000 Received: from ae5e3912cea3.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 76EB30BB-DB75-4075-9B5C-21EACB5D0EB5.1; Tue, 24 Aug 2021 09:51:23 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ae5e3912cea3.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 24 Aug 2021 09:51:23 +0000 Received: from AM5PR0502CA0004.eurprd05.prod.outlook.com (2603:10a6:203:91::14) by AM0PR08MB4100.eurprd08.prod.outlook.com (2603:10a6:208:130::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Tue, 24 Aug 2021 09:51:21 +0000 Received: from VE1EUR03FT045.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:91:cafe::d3) by AM5PR0502CA0004.outlook.office365.com (2603:10a6:203:91::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:21 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT045.mail.protection.outlook.com (10.152.19.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:21 +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.14; Tue, 24 Aug 2021 09:51:20 +0000 Received: from penny.shanghai.arm.com (10.169.190.66) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.14 via Frontend Transport; Tue, 24 Aug 2021 09:51:18 +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: 84e98b07-5ae5-4789-b99a-3304ca552e00 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=5tPaEnjZ8duvQGcHfvIm9iQd7eKfK7t1x8y/bf8dPDM=; b=neH5ZxEAlrPgjrWBPKsxX8fgE6fYz+X2byIiM4i02gRQ+JP2ctXg3T81K6clhXNvfuX7EG0ydFptJaLHuTsgXXyQxdK6MC0+GOEFO/tu2W4/0hkJe0vhp69fad+Q6P74QrouBNezy+TCTB6RmKwGbXBn2JRQtTFmDSowLEzuqhk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.xenproject.org; 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: c1c509608f450f34 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M4aAitWHamHigfugvBqAzFNe1rruW2Z+rXmbcJpEmFLx9HQayjmGuD9A8atJsfvUC17QmA/v+nEa4EK8M3/RorgyMrgGWO+ONhwJ8oyEarPm+hh3TrPR8QQjv+DcqG2wl/0OwsqTQwMaY6mjGQuIVHxvTja9OkvxJH5dLYBJHEshlOlj8qs9g+MNL+HwkNNZJ3IEoKToa9kMjjQuit1qj5BFmqPm7R69O+BHuL0vdeIXTj875ENSpDQqHv91M095dyVIgAl9/hnn1BWCO/19edVDYjy+hykE6zyw4wT3lBiGwtY5UFKqvretngTP+kEIJG2KbraWDPY5fqGPe51QUQ== 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-SenderADCheck; bh=5tPaEnjZ8duvQGcHfvIm9iQd7eKfK7t1x8y/bf8dPDM=; b=lZo7BSP+VzqaQwoYOPTQBdQE6dNDhz+qghL1ZYKdaKL+W1R8ZBo/DAYskBYin1r7VfgvJc7y1nC2pJkqTXu0s9SYI6ShkZZDRJ6K/De+Ai6HXgf9+8KMfU4KG3HpeCdHItb4mEcmBbsqPYJaT0AKgm3gd9VOa/+Zmg+96Tg0BoQI/2HWBgOEBgtGAjcWEp1r+XXfSqH8a/d1aEE09BRZGpdhxK/03bGbv1RzENVFy376pFjYgmPts2b73P+VoxneAE1OfF0kF3AyfXuSFANO0XUkE3+VLK3xmU2QP2FivDQx4wBLtMraXJJZ3kFAawQ5UiXbVrSJJcaBgRbYCIMgXw== 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=5tPaEnjZ8duvQGcHfvIm9iQd7eKfK7t1x8y/bf8dPDM=; b=neH5ZxEAlrPgjrWBPKsxX8fgE6fYz+X2byIiM4i02gRQ+JP2ctXg3T81K6clhXNvfuX7EG0ydFptJaLHuTsgXXyQxdK6MC0+GOEFO/tu2W4/0hkJe0vhp69fad+Q6P74QrouBNezy+TCTB6RmKwGbXBn2JRQtTFmDSowLEzuqhk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; 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: , , , Subject: [PATCH v5 6/7] xen/arm: introduce acquire_staticmem_pages and acquire_domstatic_pages Date: Tue, 24 Aug 2021 09:50:44 +0000 Message-ID: <20210824095045.2281500-7-penny.zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824095045.2281500-1-penny.zheng@arm.com> References: <20210824095045.2281500-1-penny.zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 39683ef3-ba77-4b49-071d-08d966e4bf5c X-MS-TrafficTypeDiagnostic: AM0PR08MB4100:|AM9PR08MB6084: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:655;OLM:655; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: a0aSYMKOnVupwcwSsODyeDk+NBE9MwtsGoZ8RVEuZ0vB/1Gb1iKnfmXAfvJm5NI2PYRRG8oF8YPTOj2ImkRhvwFsSnIFquQMtxbx/6WLYsmQCv3mYOqGNgicpK7EMq8Twb9foG/pUxuf8Jd/ImyxsBdqjO0UlX9rBlnoc/NFqi8Din3dwjkTa79p3PB+cm/c51FL5ICgICOIIFC1nEoiQlIo7OLX8VuFIyySiTBlKJ4zBPn+uLkRfX3HSEG19wM8kIgp45GC2ibNC222nlbRpEP7XlsBvmawY53FuD5Xhr+mLmT0vET6p81AM8iTyFoLialygjD3SOLLfZZvBnxajkyRMW4m55rJgiMBqVtO/MVetYbNQPvgfyHh06phsz+M9fNRW76tTiKFQbk7HZw0rV/eWFeap3RitCR5QfD7nKsJ7O2v+3j5Rn/N52vSZylEsonbE+Fr2YI0i83MqdlZWP9yKULfzXBHdoqPvaTdsDWu0vt2ffZghXZCglhHNy/lf1hjPc2hYJMGJJJOPVSxy8EGfwesS16pbaJIpWHkqvMrh5GG/LFq5C7+HtK5FGBDa94oaghMDb5bohXKCgyqQsOjUvh6dAFxSSRpXvzOZx5U1iqpOKs2koB5O80QEq5UWNdelrWxOJCyiwkB5S9lAlGRglMe5YR6mDtcOspLg0uh7iI8Fc8U1nu+3l6sM7uomhac6P00pAgxge2s4Kf+Hg6Uq80ThKb7Z8QBZy6ZSdE= 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:(4636009)(376002)(136003)(396003)(39860400002)(346002)(46966006)(36840700001)(36860700001)(186003)(5660300002)(7696005)(70206006)(70586007)(2906002)(8936002)(2616005)(26005)(82740400003)(44832011)(82310400003)(86362001)(83380400001)(478600001)(36756003)(316002)(6666004)(47076005)(54906003)(110136005)(81166007)(336012)(1076003)(356005)(4326008)(426003)(8676002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4100 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: d79a5212-9a33-40dd-6252-08d966e4ba3f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WVi8kR3Z7tZe08nKZXo8X1UdsmUZagHM9kq8CGWWP58Mc5AQSoLAvNUqvk12G6zIORvU5YcOzY/tfK/LxPRa3cQKYHa69FpjsrnuYshyx0duFY7E0nUGlW0OoYJ6nGL4jM1TjthoONCbv8cR8lja68xUrK8A8kjnAJdpjJ+St5dSxVSsUSk5gX9FE0De/91fNwJieGVoLq+FKeSn/+LJQZY/r9kb+BIziySsyeu8KTu+M2QfMWjPNnrkFlQLHZr02ms4sgH2yVc3y01+AdWTsN+LCkO0w0IO24nFFwb7EfEEdt64V/PjImi5UOgRhBHrA+Y1Lx5PXlhosf8iUGctnvyYXpouw0sGxbqsvuG83T9YEB2DkN22EZioh6mviU+p0hJV5GlFpJOEgEHvVT9RO3n8Fqk7CRF9azhFCocweMBZj4gyBo/NDZsF4Q8/PAuC0gXZVS7Q5xWbd9GRGaNCX++ndfc2nFn18iFZKUhvadNapVeplei5U9HWdN6tSQ5v/8uR3WWE9BZrggkaLaSbA0sCwBQmgTViJHjrKxRVGHFpT6Ry47thsOw31fKH5LDxkY7j3+MlUXoT/wr9FD/FdsDfwE/VaEoL3z9OtRzSGG90PRx0jgr9naPiGct7rukB3cs1MIwU38GgEKwLZPWhXnMKD8bb5YFnLOYMtbx+F866Ta5Bw/pMlaq97ZxVuI93EYQC34NnOxOdyuKykE+pcw== 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:(4636009)(39860400002)(376002)(136003)(346002)(396003)(36840700001)(46966006)(8676002)(70206006)(6666004)(8936002)(5660300002)(36756003)(70586007)(82740400003)(81166007)(316002)(110136005)(54906003)(478600001)(426003)(7696005)(82310400003)(26005)(86362001)(336012)(186003)(36860700001)(44832011)(2906002)(2616005)(4326008)(47076005)(1076003)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 09:51:29.7952 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 39683ef3-ba77-4b49-071d-08d966e4bf5c 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: AM5EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6084 acquire_staticmem_pages aims to acquire nr_mfns contiguous pages of static memory, starting at smfn. And it is the equivalent of alloc_heap_pages for static memory. For each page, it shall check if the page is reserved(PGC_reserved) and free. It shall also do a set of necessary initialization, which are mostly the same ones in alloc_heap_pages, like, following the same cache-coherency policy and turning page status into PGC_state_inuse, etc. acquire_domstatic_pages is the equivalent of alloc_domheap_pages for static memory, and it is to acquire nr_mfns contiguous pages of static memory and assign them to one specific domain. It uses acquire_staticmem_pages to acquire nr_mfns pages of static memory, then on success, it will use assign_pages to assign those pages to one specific domain. In order to differentiate pages of static memory from those allocated from heap, this patch introduces a new page flag PGC_reserved, then mark pages of static memory PGC_reserved when initializing them. Signed-off-by: Penny Zheng --- v5 changes - bundle all the functions for static allocation in a single place - return an error and revert the changes, when the page is not free and reserved. - check the MFN is valid for every page and also add a comment to warn that this function needs to be reworked if used outside of boot. - use less of mfn_to_page/page_to_mfn - use ASSERT_UNREACHABLE() to also check that the two flags are clear - pass the start MFN first and then the number of pages in both acquire_staticmem_pages and acquire_domstatic_pages - make acquire_domstatic_pages() to return an errno - combine the commit of "xen/arm: introduce PGC_reserved" --- xen/common/page_alloc.c | 118 ++++++++++++++++++++++++++++++++++++++- xen/include/asm-arm/mm.h | 3 + xen/include/xen/mm.h | 2 + 3 files changed, 121 insertions(+), 2 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 05c9834dc2..c0a8898502 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -151,6 +151,10 @@ #define p2m_pod_offline_or_broken_replace(pg) BUG_ON(pg != NULL) #endif +#ifndef PGC_reserved +#define PGC_reserved 0 +#endif + /* * Comma-separated list of hexadecimal page numbers containing bad bytes. * e.g. 'badpage=0x3f45,0x8a321'. @@ -2282,7 +2286,7 @@ int assign_pages( for ( i = 0; i < nr; i++ ) { - ASSERT(!(pg[i].count_info & ~PGC_extra)); + ASSERT(!(pg[i].count_info & ~(PGC_extra | PGC_reserved))); if ( pg[i].count_info & PGC_extra ) extra_pages++; } @@ -2321,7 +2325,8 @@ int assign_pages( page_set_owner(&pg[i], d); smp_wmb(); /* Domain pointer must be visible before updating refcnt. */ pg[i].count_info = - (pg[i].count_info & PGC_extra) | PGC_allocated | 1; + (pg[i].count_info & (PGC_extra | PGC_reserved)) | PGC_allocated | 1; + page_list_add_tail(&pg[i], page_to_list(d, &pg[i])); } @@ -2625,7 +2630,116 @@ void __init free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, /* TODO: asynchronous scrubbing for pages of static memory. */ scrub_one_page(pg); } + + /* In case initializing page of static memory, mark it PGC_reserved. */ + pg[i].count_info |= PGC_reserved; + } +} + +/* + * Acquire nr_mfns contiguous reserved pages, starting at #smfn, of + * static memory. + * This function needs to be reworked if used outside of boot. + */ +static struct page_info * __init acquire_staticmem_pages(mfn_t smfn, + unsigned long nr_mfns, + unsigned int memflags) +{ + bool need_tlbflush = false; + uint32_t tlbflush_timestamp = 0; + unsigned long i; + struct page_info *pg; + + ASSERT(nr_mfns); + for ( unsigned long i = 0; i < nr_mfns; i++ ) + if ( !mfn_valid(mfn_add(smfn, i)) ) + return NULL; + + pg = mfn_to_page(smfn); + + spin_lock(&heap_lock); + + for ( i = 0; i < nr_mfns; i++ ) + { + /* The page should be reserved and not yet allocated. */ + if ( pg[i].count_info != (PGC_state_free | PGC_reserved) ) + { + printk(XENLOG_ERR + "pg[%lu] Static MFN %"PRI_mfn" c=%#lx t=%#x\n", + i, mfn_x(smfn) + i, + pg[i].count_info, pg[i].tlbflush_timestamp); + goto out_err; + } + + if ( !(memflags & MEMF_no_tlbflush) ) + accumulate_tlbflush(&need_tlbflush, &pg[i], + &tlbflush_timestamp); + + /* + * Preserve flag PGC_reserved and change page state + * to PGC_state_inuse. + */ + pg[i].count_info = PGC_reserved | PGC_state_inuse; + /* Initialise fields which have other uses for free pages. */ + pg[i].u.inuse.type_info = 0; + page_set_owner(&pg[i], NULL); } + + spin_unlock(&heap_lock); + + if ( need_tlbflush ) + filtered_flush_tlb_mask(tlbflush_timestamp); + + /* + * Ensure cache and RAM are consistent for platforms where the guest + * can control its own visibility of/through the cache. + */ + for ( i = 0; i < nr_mfns; i++ ) + flush_page_to_ram(mfn_x(smfn) + i, !(memflags & MEMF_no_icache_flush)); + + return pg; + +out_err: + for ( unsigned long j = 0; j < i; j++ ) + pg[j].count_info = PGC_reserved | PGC_state_free; + + spin_unlock(&heap_lock); + + return NULL; +} + +/* + * Acquire nr_mfns contiguous pages, starting at #smfn, of static memory, + * then assign them to one specific domain #d. + */ +int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, + unsigned long nr_mfns, unsigned int memflags) +{ + struct page_info *pg; + + ASSERT(!in_irq()); + + pg = acquire_staticmem_pages(smfn, nr_mfns, memflags); + if ( !pg ) + return -ENOENT; + + if ( !d || (memflags & (MEMF_no_owner | MEMF_no_refcount)) ) + { + /* + * Respective handling omitted here because right now + * acquired static memory is only for guest RAM. + */ + ASSERT_UNREACHABLE(); + return -EINVAL; + } + + if ( assign_pages(d, pg, nr_mfns, memflags) ) + { + free_staticmem_pages(pg, nr_mfns, memflags & MEMF_no_scrub); + return -EINVAL; + } + + return 0; } #endif diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index ded74d29da..7b5e7b7f69 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -108,6 +108,9 @@ struct page_info /* Page is Xen heap? */ #define _PGC_xen_heap PG_shift(2) #define PGC_xen_heap PG_mask(1, 2) + /* Page is reserved */ +#define _PGC_reserved PG_shift(3) +#define PGC_reserved PG_mask(1, 3) /* ... */ /* Page is broken? */ #define _PGC_broken PG_shift(7) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index f243ff88d7..6d83b7894b 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -89,6 +89,8 @@ bool scrub_free_pages(void); /* These functions are for static memory */ void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns, bool need_scrub); +int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned long nr_mfns, + unsigned int memflags); #endif /* Map machine page range in Xen virtual address space. */ From patchwork Tue Aug 24 09:50:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 12454425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16FEEC4338F for ; Tue, 24 Aug 2021 09:51:57 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AC1D560FD8 for ; Tue, 24 Aug 2021 09:51:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AC1D560FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.170786.311761 (Exim 4.92) (envelope-from ) id 1mIT5u-000487-Ue; Tue, 24 Aug 2021 09:51:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 170786.311761; Tue, 24 Aug 2021 09:51:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5u-00047m-QH; Tue, 24 Aug 2021 09:51:46 +0000 Received: by outflank-mailman (input) for mailman id 170786; Tue, 24 Aug 2021 09:51:45 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mIT5t-0001jx-Ik for xen-devel@lists.xenproject.org; Tue, 24 Aug 2021 09:51:45 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (unknown [40.107.20.52]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id dd066ed2-04c0-11ec-a8bd-12813bfff9fa; Tue, 24 Aug 2021 09:51:33 +0000 (UTC) Received: from DB3PR08CA0027.eurprd08.prod.outlook.com (2603:10a6:8::40) by PA4PR08MB6013.eurprd08.prod.outlook.com (2603:10a6:102:eb::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 09:51:31 +0000 Received: from DB5EUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:8:0:cafe::92) by DB3PR08CA0027.outlook.office365.com (2603:10a6:8::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:31 +0000 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT059.mail.protection.outlook.com (10.152.21.175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:31 +0000 Received: ("Tessian outbound 1a0c40aa17d8:v103"); Tue, 24 Aug 2021 09:51:31 +0000 Received: from c95121f8b9ec.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7B45D01B-342F-4C4A-B795-CCD275B590C5.1; Tue, 24 Aug 2021 09:51:24 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c95121f8b9ec.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 24 Aug 2021 09:51:24 +0000 Received: from PR1P264CA0007.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:19e::12) by AS8PR08MB6262.eurprd08.prod.outlook.com (2603:10a6:20b:23e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.23; Tue, 24 Aug 2021 09:51:23 +0000 Received: from VE1EUR03FT047.eop-EUR03.prod.protection.outlook.com (2603:10a6:102:19e:cafe::33) by PR1P264CA0007.outlook.office365.com (2603:10a6:102:19e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:23 +0000 Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT047.mail.protection.outlook.com (10.152.19.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 09:51:23 +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.14; Tue, 24 Aug 2021 09:51:23 +0000 Received: from penny.shanghai.arm.com (10.169.190.66) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.14 via Frontend Transport; Tue, 24 Aug 2021 09:51:21 +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: dd066ed2-04c0-11ec-a8bd-12813bfff9fa 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=jCR1N5VD61Zz4i/4bAQFFEqhtNhHdIyamLBbOXBLKh0=; b=kVvxkvaFY4c6slOekkJJde7mVfQy0vZO/JY/YMYu9rZxl4qZxFL/mtQWC0FsQbnmYHhkkUiLZFroTLrE03XXaLdbkaKWzCkkpyZ1JyeVNfhOwievoMTfHxEbVBQnsDxL4Dxzo2RpbX3zQQXKp5TC0kRIX84/N1CHHBB0ThaRapU= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.xenproject.org; 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: 47d3cdf982d824b1 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TYBGFN2OhbQBfw65VdFUirKULboshgBsVJOvDcGta8LYTUWpQkViGDKTOEJbvVsn2UpQYY/jclDfvB36XSbPoFeXO73z5iL3HE6fyiUp8kJ+NqOJpvx88+d03eo0pIpng4EScyfzMhMHzYNBOGOQBUWJCyw5gm4djq9hmLqSouVTbncrmfLakbHnA6pZUTvVRplyM2O6EwuOiTfuFMZSlUOfWocW+TQV1uDqZjWdXbSNuDxrUxrGEq32C6KOSyOorXK6rpPQLCQN5vMVswjPZieRL2dwwKir3w3Kezs6TXfYaBu8ZlbMHbtGB9A5pogqlRnzMmRqxxO+BkIng/OsPw== 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-SenderADCheck; bh=jCR1N5VD61Zz4i/4bAQFFEqhtNhHdIyamLBbOXBLKh0=; b=HTS+zuNpDQRiQ8EBixACfsiDon5J/BfJVG2ztAzFCtI8HrenxNEZO9GIn8iw+TyeaucQpp1lipUllLtbnxrtc38VZpQN9ho573DZBRyJ4R36pYaqDGdM2fPnk9TmNeDjYJnpxyn684MGK2UAl7H21b1XyCDfjQsmJ9nIOfpBhsrYhuZlBiSD5ht70zzNlotVqye/WekGqPNSIVxUmur/w60J1BIMG3ynY1zIcbzrz/C4JukeneYXXhYaSGbRvhwv1HuBNSnx1wL9RWo32Kk7LLHsMcDxfcDxvUVRZZke6yJVRRnLgxgc0Two47QTsgCKkrQhWWazoFXLuKldPFQJOg== 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=jCR1N5VD61Zz4i/4bAQFFEqhtNhHdIyamLBbOXBLKh0=; b=kVvxkvaFY4c6slOekkJJde7mVfQy0vZO/JY/YMYu9rZxl4qZxFL/mtQWC0FsQbnmYHhkkUiLZFroTLrE03XXaLdbkaKWzCkkpyZ1JyeVNfhOwievoMTfHxEbVBQnsDxL4Dxzo2RpbX3zQQXKp5TC0kRIX84/N1CHHBB0ThaRapU= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; 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: , , , Subject: [PATCH v5 7/7] xen/arm: introduce allocate_static_memory Date: Tue, 24 Aug 2021 09:50:45 +0000 Message-ID: <20210824095045.2281500-8-penny.zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824095045.2281500-1-penny.zheng@arm.com> References: <20210824095045.2281500-1-penny.zheng@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dba16fa7-e07d-4d4d-6e8d-08d966e4c06f X-MS-TrafficTypeDiagnostic: AS8PR08MB6262:|PA4PR08MB6013: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:6108;OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: zGMIJDRfuXJz65eLzr+ldrdYHcy8jVzGYa5pMn8bo2YSG7JIzRQGDH+Lg4QFnjk5VEEjFlg32PXvrpw5D+wI4mc9RGpfV5KDH03BXDbtNTWSn0gdoh8ioQhSKKsAKKVHCPXukxlhdswYjB/yTZ9M3CI5XRWMYjcuqI3KOpGb526uAklFqEazc7s+ppHCDfNucArBaISYwU8euDfdx2uR5I7b9hg/RCOjkPkNBW29HuaopC1DH6pbs8JdagSqJnzAKm0ZmJ29ei3LytlUS2y+qj4bo+3QcezQqMbD+Yv1dKeuBOYOGl/LnFNT6RtCo01FAEiHtPYehTfU9p4ooAXZKfoUMqB3aspwpxXla2+ECXakvZnYnaikclJktsAoqmmznCrlbCeTvb1vN7+OS1i2Y20TBu95HKR+WZpSx2ok3W+q94FAT1CTzMya/niLtqPnjRy0tJJIWxMtiHLBqGqFSPpGwCKp66o54N8jlDEZLrqD5d6AA+8xU3bJx0Z+owCkJXBK3YIRlz+oQ671B1T9jFURg8OApl0PHwYKOUrp708SPw4psCz2RpV0Vn8cejkMke9vCwHLqcL9QQxdmucfN4dBn1S4StlbLW/RDKVX2GGG/pTWGdmhICVL6KFnqw6iAbq8SSgvOjPWtLSL9y033hyFvGwMv2f8sfE0jZjFnxr6rhWF3Hq0FAyokG1OApJssvA9RCL/P7qiFYSDq5M16XwARWi4o0feKNnKEZufwD4= 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:(4636009)(136003)(376002)(346002)(396003)(39860400002)(36840700001)(46966006)(4326008)(7696005)(44832011)(8936002)(356005)(83380400001)(47076005)(82310400003)(2906002)(426003)(26005)(1076003)(54906003)(316002)(8676002)(110136005)(478600001)(336012)(70586007)(70206006)(36860700001)(36756003)(81166007)(5660300002)(86362001)(82740400003)(186003)(6666004)(2616005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6262 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: f29032cb-0e61-4620-099e-08d966e4bb7d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +LcbmH3+uw1igaMzw8yG+tNzx1Si5pu5bO224trezPuDR3q7uo3E0NmhXrWsNVQa/JFBEGEjb0Hz/N6/GyNnLxM4lx8pyB8noa2duEndgYXkFJ+8qkExTpNRFOYgEGZinm7KV6FM2249nyfpDGDrY9ITJUHkxYuq+GzmKUDPCmh/kQyv+2VszUOcLbPaSq/9Hm5avzJcMBkVn8E0bUPvu+tA/I/0BdcmRFpuFIxbSF3bXZKeOiu8WMMXHP73TYPgd7vulYQ3Q88CphAKlgsgyyRzAMoAEvKrG5HpohuDsyrlZEFawl8XZ2irXOU1HJc7OUrQKaIA60appjQHk2siQRDAn9nOwAHLiubOydXfDX6hfp/oXgXWf9yElhHREbGtunSLKLxNu9tI3KGuM07z2fKEvGSFIObokf9a/roqoc9YXVMdXYsKBv6aiJaONslawnMAHM9invi/JMLWXnqK8IpDEhJwXcQhjxO4yBQ9PzbiLEssubznuEh8/yiwYO4mwD/Oe/W6mWmxtweOu68b6jSF8eys4tesJVvwQCAeb6CUDNULsAUsOPLodXbsH8HST/zUlLM+AsvrRmcmXCCBvODX0APhKJUbr39gxkaTO6E5DJg1rp8W83h8zkt1enixkqwrNGoCB4pyYZvKtFRhwk2YfRD0VEqwWQ2v/c3A/tSCB9o7YzZei8qvRGrKWGLiem4LMu2gZ+Xciwa4EtJVsw== 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:(4636009)(36840700001)(46966006)(54906003)(36756003)(26005)(4326008)(8676002)(336012)(8936002)(316002)(7696005)(1076003)(44832011)(508600001)(47076005)(2616005)(5660300002)(110136005)(186003)(70206006)(83380400001)(82310400003)(6666004)(81166007)(86362001)(70586007)(426003)(36860700001)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 09:51:31.6650 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dba16fa7-e07d-4d4d-6e8d-08d966e4c06f 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: DB5EUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6013 This commit introduces allocate_static_memory to allocate static memory as guest RAM for Domain on Static Allocation. It uses acquire_domstatic_pages to acquire pre-configured static memory for this domain, and uses guest_physmap_add_pages to set up P2M table. These pre-defined static memory banks shall be mapped to the fixed guest RAM banks. And only when they exhausts the current guest RAM bank, it will seek to the next one. In order to deal with the trouble of count-to-order conversion when page number is not in a power-of-two, this commit exports p2m_insert_mapping and introduce a new function guest_physmap_add_pages to cope with adding guest RAM p2m mapping with nr_pages. Signed-off-by: Penny Zheng --- v5 changes: - don't split comment over multi-line (even they are more than 80 characters) - simply use dt_find_property(node, "xen,static-mem", NULL) to tell whether using allocate_static_memory, and add error comment when "xen,static-mem" is used but CONFIG_STATIC_MEMORY is not enabled. - exporting p2m_insert_mapping() and introduce guest_physmap_add_pages to cope with adding guest RAM p2m mapping with nr_pages. - check both pbase and psize are page aligned - simplify the code in the loops by moving append_static_memory_to_bank() outside of the if/else. --- xen/arch/arm/domain_build.c | 156 +++++++++++++++++++++++++++++++++++- xen/arch/arm/p2m.c | 7 +- xen/include/asm-arm/p2m.h | 11 +++ 3 files changed, 168 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 6c86d52781..843b8514c7 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -480,6 +480,148 @@ fail: (unsigned long)kinfo->unassigned_mem >> 10); } +#ifdef CONFIG_STATIC_MEMORY +static bool __init append_static_memory_to_bank(struct domain *d, + struct membank *bank, + mfn_t smfn, + paddr_t size) +{ + int res; + unsigned int nr_pages = size >> PAGE_SHIFT; + /* Infer next GFN. */ + gfn_t sgfn = gaddr_to_gfn(bank->start + bank->size); + + res = guest_physmap_add_pages(d, sgfn, smfn, nr_pages); + if ( res ) + { + dprintk(XENLOG_ERR, "Failed to map pages to DOMU: %d", res); + return false; + } + + bank->size = bank->size + size; + + return true; +} + +/* Allocate memory from static memory as RAM for one specific domain d. */ +static void __init allocate_static_memory(struct domain *d, + struct kernel_info *kinfo, + const struct dt_device_node *node) +{ + const struct dt_property *prop; + u32 addr_cells, size_cells, reg_cells; + unsigned int nr_banks, gbank = 0, bank = 0; + const uint64_t rambase[] = GUEST_RAM_BANK_BASES; + const uint64_t ramsize[] = GUEST_RAM_BANK_SIZES; + const __be32 *cell; + u64 tot_size = 0; + paddr_t pbase, psize, gsize; + mfn_t smfn; + int res; + + prop = dt_find_property(node, "xen,static-mem", NULL); + if ( !dt_property_read_u32(node, "#xen,static-mem-address-cells", + &addr_cells) ) + { + printk(XENLOG_ERR + "%pd: failed to read \"#xen,static-mem-address-cells\".\n", d); + goto fail; + } + + if ( !dt_property_read_u32(node, "#xen,static-mem-size-cells", + &size_cells) ) + { + printk(XENLOG_ERR + "%pd: failed to read \"#xen,static-mem-size-cells\".\n", d); + goto fail; + } + reg_cells = addr_cells + size_cells; + + /* Start with GUEST_RAM0. */ + gsize = ramsize[gbank]; + kinfo->mem.bank[gbank].start = rambase[gbank]; + + cell = (const __be32 *)prop->value; + nr_banks = (prop->length) / (reg_cells * sizeof (u32)); + + for ( ; bank < nr_banks; bank++ ) + { + device_tree_get_reg(&cell, addr_cells, size_cells, &pbase, &psize); + ASSERT(IS_ALIGNED(pbase, PAGE_SIZE) && IS_ALIGNED(psize, PAGE_SIZE)); + + smfn = maddr_to_mfn(pbase); + res = acquire_domstatic_pages(d, smfn, psize >> PAGE_SHIFT, 0); + if ( res ) + { + printk(XENLOG_ERR + "%pd: failed to acquire static memory: %d.\n", d, res); + goto fail; + } + + printk(XENLOG_INFO "%pd: STATIC BANK[%u] %#"PRIpaddr"-%#"PRIpaddr"\n", + d, bank, pbase, pbase + psize); + + /* + * It shall be mapped to the fixed guest RAM banks(GUEST_RAM_BANK_BASES), + * And only when it exhausts the current guest RAM bank, it will seek + * to the next. + */ + while ( 1 ) + { + /* Map as much as possible the static range to the guest bank */ + if ( !append_static_memory_to_bank(d, &kinfo->mem.bank[gbank], smfn, + min(psize, gsize)) ) + goto fail; + + /* + * The current physical bank is fully mapped. + * Handle the next physical bank. + */ + if ( gsize >= psize ) + { + gsize = gsize - psize; + break; + } + /* + * When current guest bank size is not enough to map. + * Before seeking to the next, check if we still have available + * guest bank. + */ + else if ( (gbank + 1) >= GUEST_RAM_BANKS ) + { + printk(XENLOG_ERR "Exhausted all fixed guest banks.\n"); + goto fail; + } + else + { + psize = psize - gsize; + smfn = mfn_add(smfn, gsize >> PAGE_SHIFT); + /* Update to the next guest bank. */ + gbank++; + gsize = ramsize[gbank]; + kinfo->mem.bank[gbank].start = rambase[gbank]; + } + } + + tot_size += psize; + } + + kinfo->mem.nr_banks = ++gbank; + kinfo->unassigned_mem -= tot_size; + if ( kinfo->unassigned_mem ) + { + printk(XENLOG_ERR + "Size of \"memory\" property doesn't match up with the sum-up of \"xen,static-mem\".\n"); + goto fail; + } + + return; + +fail: + panic("Failed to allocate requested static memory for domain %pd.", d); +} +#endif + static int __init write_properties(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node) { @@ -2452,7 +2594,19 @@ static int __init construct_domU(struct domain *d, /* type must be set before allocate memory */ d->arch.type = kinfo.type; #endif - allocate_memory(d, &kinfo); + if ( !dt_find_property(node, "xen,static-mem", NULL) ) + allocate_memory(d, &kinfo); +#ifdef CONFIG_STATIC_MEMORY + else + allocate_static_memory(d, &kinfo, node); +#else + else + { + printk(XENLOG_ERR + "CONFIG_STATIC_MEMORY must be enabled to use \"xen,static-mem\".\n"); + return -EINVAL; + } +#endif rc = prepare_dtb_domU(d, &kinfo); if ( rc < 0 ) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index eff9a105e7..6e01e83967 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1293,11 +1293,8 @@ out: return resolved; } -static inline int p2m_insert_mapping(struct domain *d, - gfn_t start_gfn, - unsigned long nr, - mfn_t mfn, - p2m_type_t t) +int p2m_insert_mapping(struct domain *d, gfn_t start_gfn, unsigned long nr, + mfn_t mfn, p2m_type_t t) { struct p2m_domain *p2m = p2m_get_hostp2m(d); int rc; diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 6a2108398f..f885cc522b 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -300,6 +300,9 @@ int map_dev_mmio_region(struct domain *d, unsigned long nr, mfn_t mfn); +int p2m_insert_mapping(struct domain *d, gfn_t start_gfn, unsigned long nr, + mfn_t mfn, p2m_type_t t); + int guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn, @@ -315,6 +318,14 @@ static inline int guest_physmap_add_page(struct domain *d, return guest_physmap_add_entry(d, gfn, mfn, page_order, p2m_ram_rw); } +static inline int guest_physmap_add_pages(struct domain *d, + gfn_t gfn, + mfn_t mfn, + unsigned int nr_pages) +{ + return p2m_insert_mapping(d, gfn, nr_pages, mfn, p2m_ram_rw); +} + mfn_t gfn_to_mfn(struct domain *d, gfn_t gfn); /* Look up a GFN and take a reference count on the backing page. */