From patchwork Fri Jan 27 11:40:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13118614 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 CB6C2C54EAA for ; Fri, 27 Jan 2023 12:26:30 +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=/rIdcEKjn+gbgN4aV7nJobRP9QWqiJ8ZTYnIunQZB3Q=; b=2ILqiGw9u2hzq2 jdqDl0JqPHEPp7yW/gPqzFTKkH/ljEMHjugNRhslFLPpJTQJ3QV50r1G5g+Dy8yH9+v8sZx3ARFu8 4xIT0O3w2FN8268hqSK0Aen14pOs5KlqVTpTlEh5/9wFvKln1suASyYIsbLNacBJn/Z9SV1JQqgno mpI7NqdwJAHuozlMXlVLqAbA2rdV/Raw/Ki+isi6r57If9/JdZTuBzBDA7pWrK68UZR19ssR2tea1 nlnY0zDzGMmHUtsklNuPcmHsNe5R8K8/48yFZllue4XeuDshm6KXxWc6shO4rp5nCTuM+xkO+EWZz XmpaPgCigNqXPejI8G4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLNmp-00EXGn-MG; Fri, 27 Jan 2023 12:24:59 +0000 Received: from mail-ve1eur01on2081.outbound.protection.outlook.com ([40.107.14.81] helo=EUR01-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLN7s-00EE3T-1k for linux-arm-kernel@lists.infradead.org; Fri, 27 Jan 2023 11:42:37 +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=dcIXZq6ds6bP9ip4JE/j1qNlUvY5S7B0ErdLpFp4kKY=; b=gcTKPFAnKsEzwokxUHMc7fNUJCIcgW/URrg/UKVZsWeyNHbWhCudWBNVZ/JLpzyKlwMAX/58J8FxcAbp2gdElfUesI+GR0TjFy0oL3wOrpglhLY8pTTI/GoW35eCvRtDvUdWwqAelD61kVpWGsp3JPWp8hY658Pbvh4ldppoETw= Received: from DU2P251CA0001.EURP251.PROD.OUTLOOK.COM (2603:10a6:10:230::12) by AS8PR08MB6181.eurprd08.prod.outlook.com (2603:10a6:20b:29a::5) 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:30 +0000 Received: from DBAEUR03FT024.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:230:cafe::fb) by DU2P251CA0001.outlook.office365.com (2603:10a6:10:230::12) 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:30 +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 DBAEUR03FT024.mail.protection.outlook.com (100.127.142.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.21 via Frontend Transport; Fri, 27 Jan 2023 11:42:30 +0000 Received: ("Tessian outbound 6e565e48ed4a:v132"); Fri, 27 Jan 2023 11:42:30 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3bb6f51fcd59317f X-CR-MTA-TID: 64aa7808 Received: from 0919c10c4366.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 528B6F7E-9C34-4A82-84C8-D670B97DE6B8.1; Fri, 27 Jan 2023 11:42:23 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 0919c10c4366.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Jan 2023 11:42:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nKyVCRI1ZmXQagPfhGGMg2dWZH4SDmnP8zoBmgWf7OY/Cj+1Ea2dFoBS6LqJjxZ/m3j+OXK+wndZQJMTPk3cMzJc6ADbdlpJcqZZDJvufm61bkVI6JDQ5j2KsnVsHF2pL7HSS89M0C0+ohmAidvy9HQ6AS226rV+lcqRntgJx+SYpAoY8YHlPtHE67YgnD/7wFTYRIgXc8hKOUNM/wvE7roFPz4bEU9vz8lh+UrZkPHnd08p2g7tpYPS+xrWsyD3PHjElmB4e22pUwbt0uuc1QSHCADYrGGIK7HHN+sQ8Q9Ya2C6sNuIjmtZd+qf0dIDobRCJpomYI1h/OuxVCXvKQ== 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=dcIXZq6ds6bP9ip4JE/j1qNlUvY5S7B0ErdLpFp4kKY=; b=cnRLBERUTO/fWuXiWXqYZ+bhjKK8+d/3L/7Atb/EtLYdxVRfCh6s3wBdoIOyRmVhcSSCoeK/Cvk9jrsOPRExbPabICzJfdIlOehNuTy3vfPDcu2a/sU0NM9cjB4h0pbbkfwEQ7UuCdqkTeZsopRD2Ui+1gR4Gfd94sxMSNkL+0nAnJ5CZiu1T1gD7xS05x0djkJHwvRgu5Qoyf7g4OEUbxaqnnLlXVEJfej8SuyUvXwsC5Zg1gc1cAwi8PFGZtKwJresJg7yRiqtdCFTnYgnNZWxMLUr96PSb0QCgcBV6HkRRza694Z8O6Nts7Tol+YokzJdyOZscN0grVqUr5cn2w== 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=dcIXZq6ds6bP9ip4JE/j1qNlUvY5S7B0ErdLpFp4kKY=; b=gcTKPFAnKsEzwokxUHMc7fNUJCIcgW/URrg/UKVZsWeyNHbWhCudWBNVZ/JLpzyKlwMAX/58J8FxcAbp2gdElfUesI+GR0TjFy0oL3wOrpglhLY8pTTI/GoW35eCvRtDvUdWwqAelD61kVpWGsp3JPWp8hY658Pbvh4ldppoETw= Received: from DBBPR09CA0008.eurprd09.prod.outlook.com (2603:10a6:10:c0::20) by PA4PR08MB6269.eurprd08.prod.outlook.com (2603:10a6:102:ed::14) 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:19 +0000 Received: from DBAEUR03FT012.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:c0:cafe::22) by DBBPR09CA0008.outlook.office365.com (2603:10a6:10:c0::20) 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:19 +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 DBAEUR03FT012.mail.protection.outlook.com (100.127.142.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.21 via Frontend Transport; Fri, 27 Jan 2023 11:42:18 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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.2507.16; Fri, 27 Jan 2023 11:42:18 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:18 +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:12 +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 11/27] arm: realm: Early memory setup Date: Fri, 27 Jan 2023 11:40:52 +0000 Message-ID: <20230127114108.10025-12-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: DBAEUR03FT012:EE_|PA4PR08MB6269:EE_|DBAEUR03FT024:EE_|AS8PR08MB6181:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a369fbf-a804-4227-7134-08db005b929d 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: WPtP+nScV3xsIsPYWNRpZ4Pmab10S9T5ZdEkXtMAiSUnJV6QXnlsaDENYHBGS96TIPhC7N3sEh5FgvLKL2qK3oUcx2eF9ub0+GBsLbQ3R3fRLALP4pKHAqeDWOQYFHItN1gp6nwWSgh4lCY6SvnjhH+qQutAEvDnwTfk8T/YtwTB8WlrP07C36IouBdPxFwwADUkUH9SOxf1V/kHlTxjBde3rAr70HXiHPldGUmTnI4bMgGaEJp7wGY6pHXlJFxAy9bqIcmsS2kZcy2YKd4vJYUjFC0iPK9KzdxyJdMpTTc3lUaS6vL6XnXYs4vE0ODp4RMb0ePlfr/0cP1S55qHBkkWeE1JlTEs4hmILGMRlet8Gk9Jqw/refcmEnjYtzHS9VG6c/c43Bh9Oavw7veconh6mtSSgHXgGVRmrwHSN1IhnLUF8EQa7TZ+f9mfDS2jHttjwh7URT2v4IbI4njTQ6i8VHc+XLAoRKwHHpr8z6RnWabHbJApwxIypjniBwhjK9iLdeKSFvdmW3AYRHRRUku3VsIRrqjZMPk4UX3bzf8HVwffXwjgJ4D0z/N6ai9zwV4IDfPtpHzRt6jZgjL9lbV8SS+lS9N6x+Ph5WsTpHb1tKDKl22w8fbLxqA2LdZYQynMHuRpuyoXqDxbap4HK2A3Iuil8N9ur1g4F0cySLZH1EL7kpslKSC4gT4X6skYxXBSWJ6x5rGtk8rE1DAE13S78Mx0U7uMjzaxEhXDn0gPLPl+LNacMsl5/i5hIpXI 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)(396003)(376002)(39860400002)(136003)(346002)(451199018)(36840700001)(40470700004)(46966006)(478600001)(44832011)(40460700003)(36756003)(70586007)(4326008)(70206006)(83380400001)(36860700001)(54906003)(82740400003)(110136005)(8676002)(316002)(1076003)(186003)(26005)(7696005)(6666004)(7416002)(5660300002)(47076005)(82310400005)(81166007)(426003)(356005)(2616005)(336012)(86362001)(41300700001)(40480700001)(8936002)(2906002)(2101003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6269 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT024.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: f797dcb8-444f-4884-b7c7-08db005b8bbe X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dHm6HybqRRhj/ySoZ6+b+Al6pa2X9iAutDn9NPJZo/TVVyx8+IF1/2aRUNBFIVmbcaBLJQF8GsHvXcAdtWiiuJQDsDHBPvi6FIS1wRBx47Pv1FOzxrb2uDlag133M06a8AZ/iX5iF9lK9B0zLr7yupMnj5BkoXpuhaX4bX2oh9wFT2WIOlDePx17j4NQcgKPH0gnO1QtpVQ7YlnLF1ElU+kjLwIurjVjTSxlz5vEBrS7JmV2lS3Ey56lWT9gEAPRgEjtOz2LZWR2qC8TEdywepCwtZjXkW2sutCKm7hLGY4GWw1M0+KLoPTXqVDcHLAF/gkQrFFIgr52QU/dOGGr2wsyDP1+BccxIwMobmrdoiFPVNykUFuV28wVwlZq9VUwkf9/19Mhnr6Jcsk+TD3gpdy+PiGD1NDg+9YNkX9w/ZCYPFLFMMfksmzT7wzuZ95Ap4tXqxzK59KpU+DG3LP2C4cqGdJX/vNQC5X5of+hk3wGufH6J1ZI4g7U4+s5ao4h+9APtfQ4PvUR/BdNX5kAxPaw63wNmAbzcQgvUe3BnQmcUFsA3eusoL8VvnaNOJMCjtxi9uNeStz43OIuMx5MtKzpwVKEmw23dtPWlgldfDM66f+c2RYmGP5GyjAIqDIzmJ1vquZS5kroyFeSa//uQWNiDLCmgqkhWtp5PkZ7jjX65H690gZp8Fcin1yxd6b6O2AWOlHGlbKJ6Hs+gDlRTs/M1ET+kjoeSxdI/d2DeOM= 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)(376002)(396003)(136003)(39860400002)(346002)(451199018)(40470700004)(36840700001)(46966006)(36756003)(40460700003)(7696005)(54906003)(316002)(1076003)(110136005)(6666004)(107886003)(5660300002)(2906002)(44832011)(70206006)(70586007)(8676002)(4326008)(8936002)(478600001)(41300700001)(26005)(82740400003)(36860700001)(81166007)(86362001)(40480700001)(2616005)(83380400001)(426003)(336012)(186003)(47076005)(82310400005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2023 11:42:30.4872 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a369fbf-a804-4227-7134-08db005b929d 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: DBAEUR03FT024.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6181 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230127_034236_153167_7012AF03 X-CRM114-Status: GOOD ( 15.81 ) 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 mark areas of memory as RIPAS_RAM before an access is made. The binary image is loaded by the VMM and thus the area is converted. However, the file image may not cover tail portion of the "memory" image (e.g, BSS, stack etc.). Convert the area touched by the early boot code to RAM before the access is made in early assembly code. Once, we land in the C code, we take care of converting the entire RAM region to RIPAS_RAM. Please note that this operation doesn't require the host to commit memory to the Realm. Signed-off-by: Suzuki K Poulose Co-developed-by: Jean-Philippe Brucker Signed-off-by: Jean-Philippe Brucker Co-developed-by: Joey Gouly Signed-off-by: Joey Gouly --- arm/cstart64.S | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/arm/cstart64.S b/arm/cstart64.S index b689b132..b0861594 100644 --- a/arm/cstart64.S +++ b/arm/cstart64.S @@ -14,6 +14,7 @@ #include #include #include +#include .macro zero_range, tmp1, tmp2 9998: cmp \tmp1, \tmp2 @@ -61,6 +62,7 @@ start: b 1b 1: + bl __early_mem_setup /* zero BSS */ adrp x4, bss add x4, x4, :lo12:bss @@ -170,6 +172,76 @@ arm_smccc_hvc: arm_smccc_smc: do_smccc_call smc +__early_mem_setup: + /* Preserve x0 - x3 */ + mov x5, x0 + mov x6, x1 + mov x7, x2 + mov x8, x3 + + /* + * Check for EL3, otherwise an SMC instruction + * will cause an UNDEFINED exception. + */ + mrs x9, ID_AA64PFR0_EL1 + lsr x9, x9, #12 + and x9, x9, 0b11 + cbnz x9, 1f + ret + +1: + /* + * Are we a realm? Request the RSI ABI version. + * If KVM is catching SMCs, it returns an error in x0 (~0UL) + */ + ldr x0, =SMC_RSI_ABI_VERSION + smc #0 + + ldr x1, =RSI_ABI_VERSION + cmp x0, x1 + bne 3f + + /* + * For realms, we must mark area from bss + * to the end of stack as memory before it is + * accessed, as they are not populated as part + * of the initial image. As such we can run + * this unconditionally irrespective of whether + * we are a normal VM or Realm. + * + * x1 = bss_start. + */ + adrp x1, bss + + /* x9 = (end of stack - bss_start) */ + adrp x9, (stacktop + PAGE_SIZE) +2: + /* calculate the size as (end - start) */ + sub x2, x9, x1 + + /* x3 = RIPAS_RAM */ + mov x3, #1 + + /* x0 = SMC_RSI_IPA_STATE_SET */ + movz x0, :abs_g2_s:SMC_RSI_IPA_STATE_SET + movk x0, :abs_g1_nc:SMC_RSI_IPA_STATE_SET + movk x0, :abs_g0_nc:SMC_RSI_IPA_STATE_SET + + /* Run the RSI request */ + smc #0 + + /* halt if there is an error */ + cbnz x0, halt + + cmp x1, x9 + bne 2b +3: + mov x3, x8 + mov x2, x7 + mov x1, x6 + mov x0, x5 + ret + get_mmu_off: adrp x0, auxinfo ldr x0, [x0, :lo12:auxinfo + 8]