From patchwork Fri Jan 27 11:40:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13118612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1189CC54EAA for ; Fri, 27 Jan 2023 12:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ria76qr5atf6DBe4Qyl8dr29MMQWnnXlBTkthmoE1ho=; b=TjXrCaNpR1/aMu /sDeLuMlP1NA3vzXDfAooP//mcSmO059Dnkh/gzrq07R4dT11gjnO2wbbxioRALnjmVKsWJpjpqUU 9LOVgNj+pBBXI26bF4u0Ojz2n/LvBVlQrrGWJzmGM+hcENnnxky5wLhXiSrVT+XOaSUi5qMtnkgnh +HGeiGRE7WlOK8o0NSJpbd46dIhofAFSwSLlVTDcXXojjVoMWcopx47mg8RYVU+hepBYLbdAgGYcM bjRyTIujTWdzmYTvQmjD8/9Z+440uhu2y5DyBiKDYgsUSIJVpu5PGBVRuYh3IBNYW9lhdAO2O79T9 Y/Q6CL00IVBKk1Bmh0Ww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLNkm-00EWRe-8B; Fri, 27 Jan 2023 12:22:48 +0000 Received: from mail-vi1eur05on2085.outbound.protection.outlook.com ([40.107.21.85] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLN7j-00EDze-UH for linux-arm-kernel@lists.infradead.org; Fri, 27 Jan 2023 11:42:29 +0000 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=BKUc6k5BydLVdfAhCZDW2BV1A+Pf2tNjyrVVfOkNRBk=; b=SAvWSnN98f2hb9mw6rrD+Z8Q8+BgvgYk8FPgwqjl+d0IpFb2GFkQnh0bJraTYGz2Tv00EHHaJeOHV+MnhbCWsR3MXuXUVQuz75S3MmtAWbJJUJU3ML+Xx3lRRxcI8OQkPloDNjggRQt86Y66Xt+0o4br182JegpjmeuOlI/tUCQ= Received: from AS9PR04CA0031.eurprd04.prod.outlook.com (2603:10a6:20b:46a::10) by PAWPR08MB9830.eurprd08.prod.outlook.com (2603:10a6:102:2e2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.23; Fri, 27 Jan 2023 11:42:22 +0000 Received: from AM7EUR03FT025.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:46a:cafe::34) by AS9PR04CA0031.outlook.office365.com (2603:10a6:20b:46a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.23 via Frontend Transport; Fri, 27 Jan 2023 11:42:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT025.mail.protection.outlook.com (100.127.140.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.22 via Frontend Transport; Fri, 27 Jan 2023 11:42:21 +0000 Received: ("Tessian outbound baf1b7a96f25:v132"); Fri, 27 Jan 2023 11:42:21 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 6c64ba3becf4f171 X-CR-MTA-TID: 64aa7808 Received: from b0a773cadefd.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 448B61F0-7F96-44A2-A403-35D6918DEF7C.1; Fri, 27 Jan 2023 11:42:14 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b0a773cadefd.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Jan 2023 11:42:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MhXKrKTOXLunmpbCtIdiL/niGVW2nmU9SPyzCWwQAFliHuFsRjS+7KX4mxb24cgljXUcdStWgSC2jIuKWLHPfZwZT0gSSIii/rXa0Ca7kSYED7BFFVXLCuLX+gaejOcFuhBqwd7p3HzlkSNmXckq9yzn0sGbn+8pw4EskrmJ+nckKBYpzmiL2TfMcYK+5NrX4aMaCr5Hoig3Aj9ehr2X0hxv9sJBMikHsK3ZxSsC6P6sdfqekyFHCY0CUloDEhYYLlYEqGlMB8H/HxGQrX6MAbKdVsHN/t8LSje/oy5RvaJP+qyhWHZPXLMI/Ffp9DF0exW/ZuZdCoNOHJMlQ1HIBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BKUc6k5BydLVdfAhCZDW2BV1A+Pf2tNjyrVVfOkNRBk=; b=mC94RW0PfzLraKBdD/pO2kqjRt6y+f+EgeIm6VugklubWGFTfqPqxZKcBN01d+DXQ3QlDW01uo9vBl0n4IppfuxtfdjYWixru0DQVDz6TxNtWTUPsKuSmh7I2zL1sIQnv5P+8FAR8CW8/aYEIaHE0iw3EcI7i4puKr9ALYI0diYEm5ObOi+TEXtgRYEH7juyCyVvTY5HbvlxJqFkJ7SO/d9WJfHczVka9oEBOugZXI6cfUJ5VHETrKHs8IGuSkPrLJLHLMGJ45c84kaikMULnCtIJBHUTCeG3XtjzmfCDbSg59HY/RXs6rO+CWql8OTtpD5LZVR0zg5LLc1N6jLRTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=linux.dev 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=BKUc6k5BydLVdfAhCZDW2BV1A+Pf2tNjyrVVfOkNRBk=; b=SAvWSnN98f2hb9mw6rrD+Z8Q8+BgvgYk8FPgwqjl+d0IpFb2GFkQnh0bJraTYGz2Tv00EHHaJeOHV+MnhbCWsR3MXuXUVQuz75S3MmtAWbJJUJU3ML+Xx3lRRxcI8OQkPloDNjggRQt86Y66Xt+0o4br182JegpjmeuOlI/tUCQ= Received: from AS9PR0301CA0043.eurprd03.prod.outlook.com (2603:10a6:20b:469::35) by DU0PR08MB8422.eurprd08.prod.outlook.com (2603:10a6:10:406::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Fri, 27 Jan 2023 11:42:13 +0000 Received: from AM7EUR03FT029.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:469:cafe::6b) by AS9PR0301CA0043.outlook.office365.com (2603:10a6:20b:469::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.22 via Frontend Transport; Fri, 27 Jan 2023 11:42:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT029.mail.protection.outlook.com (100.127.140.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.22 via Frontend Transport; Fri, 27 Jan 2023 11:42:13 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 27 Jan 2023 11:42:12 +0000 Received: from e124191.cambridge.arm.com (10.1.197.45) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Fri, 27 Jan 2023 11:42:07 +0000 From: Joey Gouly To: Andrew Jones , , CC: , Alexandru Elisei , Christoffer Dall , Fuad Tabba , Jean-Philippe Brucker , Joey Gouly , Marc Zyngier , Mark Rutland , Oliver Upton , Paolo Bonzini , Quentin Perret , Steven Price , Suzuki K Poulose , "Thomas Huth" , Will Deacon , Zenghui Yu , , , , Subject: [RFC kvm-unit-tests 10/27] arm: realm: Set RIPAS state for RAM Date: Fri, 27 Jan 2023 11:40:51 +0000 Message-ID: <20230127114108.10025-11-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230127114108.10025-1-joey.gouly@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127114108.10025-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT029:EE_|DU0PR08MB8422:EE_|AM7EUR03FT025:EE_|PAWPR08MB9830:EE_ X-MS-Office365-Filtering-Correlation-Id: c312bbe2-96ca-4157-54aa-08db005b8d59 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: hhtDTy6STJ9a9QEZL8zimAoI431SQb3ajffRVUwOzB2azBv+DpuOUmqM+RiuF3PS1oYf9egQTcmaOmeUGK/TsGedqJvL0rt0jf+mEy3HpHwoFV0OVsgkVsF/gdt6qfgcr5XW8FdU9CqNJpshXKN9VaKmHimY+WLgbM1SEmF1fhE3AYaPzofWgRyO4T+/4/kukYHyhpKkdZ9ImwfWL/+iCxEaYdR5YZPDKxWlZR1PY8etGHY1JEROMdeeSyu/2ESSK0NjuQSKYi3iYJyzcrV52y9gupsTIcD8HlIH0LL00cn7QRyPKzQltircLKMVmm5SAqMlJ1NMfE0H94w5ttFNEINA4h+WFsgi/zzLLgTnExUjyy+lFNR3ge4TMElHf/f1R1ex2zvWH3MSaC8qaWgb0LkFiYyV28a2b7SXnt57cuKHsfwdJrnfRGklWBuxeuheykeHwqa8o+tTXZlImScG6tZZI+7RY3TAsvb8t5qOzPL9WpNqBHPr9r6d3xhRCq67WSpGfXGprxgG7rLCa/sPz471SOvhs9FoUfE5VDW6X4N5fGNz6yW8kkBiaZgZlw35zkn7lx7ry422F+zSrfZBIb8x5rMY/3uXj+0x3r8X5CkNKLQT5/M7NfLY2nbdKXoKshS/fABOxxdWWAczM+BxuqZV8C6fkEu/1+8BThjHjJtP7vQ0k9bOaV0z08XukMzAbdy/lhJ1w3pZvBru4hqey0IC/HSFWasxtAntWH39sX6DKHswIOxYAaa/Z6ftsPCY 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:(13230025)(4636009)(136003)(396003)(376002)(346002)(39860400002)(451199018)(36840700001)(46966006)(40470700004)(7416002)(316002)(426003)(47076005)(82740400003)(336012)(40460700003)(6666004)(40480700001)(478600001)(82310400005)(70586007)(8676002)(186003)(54906003)(26005)(8936002)(1076003)(7696005)(2616005)(2906002)(41300700001)(36756003)(86362001)(5660300002)(81166007)(70206006)(4326008)(110136005)(36860700001)(356005)(44832011)(83380400001)(36900700001)(2101003);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8422 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 93c97a55-017d-4a7d-2a0c-08db005b888a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5AmYDtOwghlm/n8iCq5069zkpAvz4zdTyDemMuLtIOHzfhg2ZjD3tdg7xJM+oTHv/3AU7CHhcrcmR83hBCNUnmdRtinWHMJ83rnA8f88+JnsTZsVTbrgqL5oP37XkupT7YZhZ0d/TrVk94udRYF0fhVPMUB+bzR/YBgVXxDe0mISMCeyra+4hWfpAybAy0os1oyISnTbCQyFnbpEjI9HlHgCGzJFXnTHw66QOFusD8NLa/TH2ZPMBc6BjXp6+mRhDRp2S7S06nzjK0CkKOF6K18h6ATWyLGOu3BjcBFXZjX1Lc7xno+MSeXWEq+N0qrN4zWLUJINHGQWLJd2XjWfGdC2a5U4IsR6P7+Xle/4gMZK23eswXRkeXGWRIHTAd0wpY//FlvwH2gLMix+RDC6XetoghQ+WfTJWkjeT0wh/HdZR3uV2Guy94LfrpG/J0/qAqLTuVGFymQ0FUx3IWBKjJEQVGL3y5szl4TC+GEQUry62zYsLz1Kh+T95gIzQgR1/6b8vK4tt4UYjn9SDCWSxc1Dskr/kbKnlkcAThb+RYRxg7zUqIUOtDXrCVuxe0hrQfov8hb9LCUzpCHhv1GBpp9Rg9FU1MLv8NbyUxWGCnywHXyuJzmZkuJExuxtU8dLWJRaZfjkl3MT7Ogwlyfr+rzU3XPho9WslnHtHCrUbh2t4/jlARYTRx/nOHIBWobuIZTczTwqe4mh2HB0PVQAJ+eFuqCGwjyYjStamR3Kq9I= 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:(13230025)(4636009)(346002)(376002)(39860400002)(396003)(136003)(451199018)(40470700004)(36840700001)(46966006)(83380400001)(336012)(36860700001)(36756003)(82310400005)(40460700003)(82740400003)(47076005)(426003)(110136005)(5660300002)(54906003)(316002)(2616005)(86362001)(40480700001)(186003)(81166007)(26005)(107886003)(7696005)(478600001)(6666004)(2906002)(8936002)(44832011)(8676002)(70206006)(4326008)(70586007)(1076003)(41300700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2023 11:42:21.5897 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c312bbe2-96ca-4157-54aa-08db005b8d59 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: AM7EUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB9830 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230127_034228_042393_197CB601 X-CRM114-Status: GOOD ( 15.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Suzuki K Poulose A Realm must ensure that the "RAM" region is set to RIPAS_RAM, before any access is made. This patch makes sure that all memory blocks are marked as RIPAS_RAM. Also, before we relocate the "FDT" and "initrd", make sure the target location is marked too. This happens before we parse the memory blocks. It is OK to do this operation on a given IPA multiple times. So, we don't exclude the inital image areas from the "target" list. Also, this operation doesn't require the host to commit physical memory to back the IPAs yet. It can be done on demand via fault handling. Signed-off-by: Suzuki K Poulose Signed-off-by: Joey Gouly --- lib/arm/setup.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/arm/setup.c b/lib/arm/setup.c index 36d4d826..7b3dc0b8 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -181,6 +181,7 @@ static void mem_init(phys_addr_t freemem_start) while (r && r->end != mem.end) r = mem_region_find(r->end); assert(r); + arm_set_memory_protected(r->start, r->end - r->start); /* Ensure our selected freemem range is somewhere in our full range */ assert(freemem_start >= mem.start && freemem->end <= mem.end); @@ -252,6 +253,11 @@ void setup(const void *fdt, phys_addr_t freemem_start) /* Move the FDT to the base of free memory */ fdt_size = fdt_totalsize(fdt); + /* + * Before we touch the memory @freemem, make sure it + * is set to protected for Realms. + */ + arm_set_memory_protected((unsigned long)freemem, fdt_size); ret = fdt_move(fdt, freemem, fdt_size); assert(ret == 0); ret = dt_init(freemem); @@ -263,6 +269,7 @@ void setup(const void *fdt, phys_addr_t freemem_start) assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); if (ret == 0) { initrd = freemem; + arm_set_memory_protected((unsigned long)initrd, initrd_size); memmove(initrd, tmp, initrd_size); freemem += initrd_size; }