From mboxrd@z Thu Jan 1 00:00:00 1970 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 961D1E6FE46 for ; Fri, 6 Sep 2024 19:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:Cc:To: Subject:Date:Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=plWktybNHgWPOQxiFBrYkaX9MYfFJUa8ZJDpOyBX7ns=; b=WhphEDYkLaAHW7ouAkZAXV0zAe wbDdZnPDvUtp7m/jfiYrFqsXuozRiuCn9Q04GSKFV0zQndnvnGIjfP89GCdCI8mv/J6YykPie4V2r /OiIUWEQGZuwCUU/RX4eLsfMzlv0YmNGfxDslz5JpGzLDKh6rUo5sxImDJwrDyU4B18aLG0c6a3+h BMh0yZ06hi1rOZjWr3rUmXfTpvAnGO176E+R/253rGVIOrK5D3V+TxDRzO/Lrw0kS5s3Mw9BsaoIo vamTh8dvLWjj+zff//feDoAWXkmRxhjtg43PWmLFP/dYwWwi8AFt15Du7CH73eUG5LGaxkBjKUG4d gjrxniyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smeBU-0000000DMyd-2Kv0; Fri, 06 Sep 2024 18:59:52 +0000 Received: from mail-bn8nam12on2061b.outbound.protection.outlook.com ([2a01:111:f403:2418::61b] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smeAT-0000000DMir-1VlC for linux-arm-kernel@lists.infradead.org; Fri, 06 Sep 2024 18:58:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UxISUllzlr6LTUpcOWU6cHGNz+Ftg4VchDHc4v1Dni08pE8LHA3ERMi4B4BMqkrS8wX8p3uBeF+9Z8I8a/XQtDCZBsuQym11kaWr0uaMMZwT0lWljaABdtG/MrJuVLvrRXVVaTx2/wGnUiBn+u8k0mcdCJozJG7u74xaJifKrQIIvCQ1oDaaJGYrzKXcuMtB5+yhpHIddmgLsaYKat9LYoPyJ7OBSLtZs0PSCqPjMTyKV7IlCfSq/HCTMc18FUBqVZYpbaMWdzBaNg78aSsXR9gxT+N0ui6Y7f61L3ih1fvyZtxzoTB/y8Zp49GONTFXpwWiJzynqQXc8a9crAU0Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=plWktybNHgWPOQxiFBrYkaX9MYfFJUa8ZJDpOyBX7ns=; b=n/gJ1bCt5AvGRejJi4rcLwfvcGUtFiEvCTRtwUSLVTGGbF7+Puq0yHydK43W7WwD4kuXT5f/pvF+iLPhABS7EHaioPX/dR8e8b7OFphMRHTy3W5t8XNvJyJ4PR03qi4wL9xTOcnN/+kPCSb6D4IOw5dOMw/DX9gBI2xHId9ZPh0MuSBdqmnBOZKPgogY5U5tDpOmIaLRM78oiDbh1bXt+mXvBoP6IciNhdnxecWzoY7LZKzl9WmbHvLV4L1boRRpElE8jySwN11sAmsQP3J3+rfvbdg7OqMSVN9VNLCX1kv47TgM7TKsU8mOkFhZD1BVwRlIbrvahjAf5wFugcSE3Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=plWktybNHgWPOQxiFBrYkaX9MYfFJUa8ZJDpOyBX7ns=; b=G+cuLWDuJUaHRb5XFrGhHCablkIzXep5m94eBKVdK/JTzoxQHIUKhKQ5DPvSNawxqy5rzmZparf5m0rdC6wkuvWGB2aIv2jam2IAAuKYCvKiqFMgSTi9xbkia4JEMTD2mGI6nPun1iBhlpnynYM7p0gup3xn+zi5Yks+zMP+VBGSvSS6bWUU6jdBADCaIian8ifOxXexUDc/PHGxw6/4jIbu8OZfluG8puZtcmcmkg3dBbRgLnwT7LO0jOyFLC4MjvqT1iqyVQt5NhzlahQqaAzpCHB3QPaTR5+CWYC0P5UnPKnkTc2qipoOY24hZDWsjmsNgyX47KOtiK9Suv866Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY8PR12MB8194.namprd12.prod.outlook.com (2603:10b6:930:76::5) by SJ2PR12MB8061.namprd12.prod.outlook.com (2603:10b6:a03:4cb::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17; Fri, 6 Sep 2024 18:58:35 +0000 Received: from CY8PR12MB8194.namprd12.prod.outlook.com ([fe80::82b9:9338:947f:fc9]) by CY8PR12MB8194.namprd12.prod.outlook.com ([fe80::82b9:9338:947f:fc9%6]) with mapi id 15.20.7918.024; Fri, 6 Sep 2024 18:58:35 +0000 Message-ID: Date: Fri, 6 Sep 2024 13:58:31 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 05/19] arm64: Detect if in a realm and set RIPAS RAM To: Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Alper Gun , Vikram Sethi References: <20240819131924.372366-1-steven.price@arm.com> <20240819131924.372366-6-steven.price@arm.com> Content-Language: en-US From: Shanker Donthineni In-Reply-To: <20240819131924.372366-6-steven.price@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BL0PR02CA0005.namprd02.prod.outlook.com (2603:10b6:207:3c::18) To CY8PR12MB8194.namprd12.prod.outlook.com (2603:10b6:930:76::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR12MB8194:EE_|SJ2PR12MB8061:EE_ X-MS-Office365-Filtering-Correlation-Id: 10facb15-81c4-4a98-c419-08dccea5e8ec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?V3V3MituNXRYUmZLR3dER0MvKzdYdTVCbGJzcFpmQy8xODRiV0tGU2QyaGRG?= =?utf-8?B?SWgyNHhSbTIrU3VHZ2JXaWNQL2srdUhkOVErTlc4WnV2MnZ5QTIwNnlLZ1ow?= =?utf-8?B?MDcvMnczTzlROHA2Ty9NQnhzT2lEemlIS0diOWdhcEFvbEs0RjFFWWFYWUZE?= =?utf-8?B?ek9tbWNmWHRwWVY2c2RrV1pQdmRkZlpXVUd0cUMydW5jRnBHNTUwSi85Tlpy?= =?utf-8?B?Y01FUlp4ZGJlamxrOTI4QWVpMmRVV0NkZUFwZEJyK1BUTkdPRD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vdnJXZjhwLzl5dm94aWZmRHps?= =?utf-8?B?YXFMRHVYeVVzWmFBdDN5b3pIWDJpYWRoNTVaTC94a00wbkYxTlM4MW9ZNGhP?= =?utf-8?B?TUZRdE9FNlcrdXBVb0g0VksxL212ZUd3am1RUDhQdndsbEhXcFZlbjJoZGtJ?= =?utf-8?B?M3gyYW5MVGRta2Mwd29Vd01KRjhnVlhINmVNMEZkaHYzanlha1l3Sm5DcGsr?= =?utf-8?B?SFBHeTBZWFViNGZDeXRza3FXOFFzNzhvK25pRm5QYnV2d0o2cmNMVVA5dkJS?= =?utf-8?B?SVFLOHNpQ0JvL1ZpTlZoZHJ2SzBBQklTc3czTkRGU2NWc1hJTjlFc0k4dytN?= =?utf-8?B?bVFtZ1VVNXc3MjNza0FPV0toVG16dDUyM1ZCcVJiWE9NR1NhaDJlSUJYUzVI?= =?utf-8?B?QVcyc0NuZnkyWlFnbTY5Sm9DeXBDUzh2UXFudnU1am5BeHh1ZnNlVDdxQlA2?= =?utf-8?B?NmtMZVVCcEw5TnArRGpuTDhQYVhqZFcrKzl3c0VjdE80anM4NXcrci9sdW44?= =?utf-8?B?Z3NsaVZHKzVDdzRya3JUb1MwWVl3R0N0am0xSHBDTEdiZkNNaldiU3lEako2?= =?utf-8?B?SkFQaDQrY3V2REgrdGtIcHlha0VNRWlkdlk4c1ZtQi9icVQ4YWNmOEdFV0xT?= =?utf-8?B?MUU2QWhhRXg2TTd3VnNoQT09?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY8PR12MB8194.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UzBqZ2FKNWNSbEY3Q3JORHJsYnVIZXg0OVJXUVhyQm5kVlhLUXJvckwrdFQ4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mVQK3BYRUdqbk5xaFJEdy9yUUF2?= =?utf-8?B?S2Y2U0plelN6OGxCMnU0RDh3TnhYcW51NE9nZzM3L1lVTTZueW1ibXphZXFy?= =?utf-8?B?eDc0b2UxcTN3Q0FWa2dGRFZSaEtuMUFWZTEyOEVDaUFTaWtGdXJCVWc3ZWg1?= =?utf-8?B?dmR5bysvUTBPVjFzNW4yY1BGOW96aHlRd2VjWm1sOElMbXZ5SFRjcDBhbFA5?= =?utf-8?B?a3dmWlhjWndQTmppT01xYzZPeEZHN3dpWW5UbDJUdU94TVlVWGZlUE8rWTJZ?= =?utf-8?Q?mWvmkpZGhckwquHSLjZZ37aBX?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10facb15-81c4-4a98-c419-08dccea5e8ec X-MS-Exchange-CrossTenant-AuthSource: CY8PR12MB8194.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 18:58:35.4316 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YqdVJjCDGBjROKuXJ7aXvWdznrEfeslHSdpmbZy0pfZaaunfi8BHSFI9aPD/75kqsAIscumEX9PSPqXCQojP0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8061 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_115849_546541_0385DC2E X-CRM114-Status: GOOD ( 29.11 ) 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 Hi Steven, On 8/19/24 08:19, Steven Price wrote: > External email: Use caution opening links or attachments > > > From: Suzuki K Poulose > > Detect that the VM is a realm guest by the presence of the RSI > interface. > > If in a realm then all memory needs to be marked as RIPAS RAM initially, > the loader may or may not have done this for us. To be sure iterate over > all RAM and mark it as such. Any failure is fatal as that implies the > RAM regions passed to Linux are incorrect - which would mean failing > later when attempting to access non-existent RAM. > > Signed-off-by: Suzuki K Poulose > Co-developed-by: Steven Price > Signed-off-by: Steven Price > --- > Changes since v4: > * Minor tidy ups. > Changes since v3: > * Provide safe/unsafe versions for converting memory to protected, > using the safer version only for the early boot. > * Use the new psci_early_test_conduit() function to avoid calling an > SMC if EL3 is not present (or not configured to handle an SMC). > Changes since v2: > * Use DECLARE_STATIC_KEY_FALSE rather than "extern struct > static_key_false". > * Rename set_memory_range() to rsi_set_memory_range(). > * Downgrade some BUG()s to WARN()s and handle the condition by > propagating up the stack. Comment the remaining case that ends in a > BUG() to explain why. > * Rely on the return from rsi_request_version() rather than checking > the version the RMM claims to support. > * Rename the generic sounding arm64_setup_memory() to > arm64_rsi_setup_memory() and move the call site to setup_arch(). > --- > arch/arm64/include/asm/rsi.h | 65 ++++++++++++++++++++++++++++++ > arch/arm64/kernel/Makefile | 3 +- > arch/arm64/kernel/rsi.c | 78 ++++++++++++++++++++++++++++++++++++ > arch/arm64/kernel/setup.c | 8 ++++ > 4 files changed, 153 insertions(+), 1 deletion(-) > create mode 100644 arch/arm64/include/asm/rsi.h > create mode 100644 arch/arm64/kernel/rsi.c > > diff --git a/arch/arm64/include/asm/rsi.h b/arch/arm64/include/asm/rsi.h > new file mode 100644 > index 000000000000..2bc013badbc3 > --- /dev/null > +++ b/arch/arm64/include/asm/rsi.h > @@ -0,0 +1,65 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copyright (C) 2024 ARM Ltd. > + */ > + > +#ifndef __ASM_RSI_H_ > +#define __ASM_RSI_H_ > + > +#include > +#include > + > +DECLARE_STATIC_KEY_FALSE(rsi_present); > + > +void __init arm64_rsi_init(void); > +void __init arm64_rsi_setup_memory(void); > +static inline bool is_realm_world(void) > +{ > + return static_branch_unlikely(&rsi_present); > +} > + > +static inline int rsi_set_memory_range(phys_addr_t start, phys_addr_t end, > + enum ripas state, unsigned long flags) > +{ > + unsigned long ret; > + phys_addr_t top; > + > + while (start != end) { > + ret = rsi_set_addr_range_state(start, end, state, flags, &top); > + if (WARN_ON(ret || top < start || top > end)) > + return -EINVAL; > + start = top; > + } > + > + return 0; > +} > + > +/* > + * Convert the specified range to RAM. Do not use this if you rely on the > + * contents of a page that may already be in RAM state. > + */ > +static inline int rsi_set_memory_range_protected(phys_addr_t start, > + phys_addr_t end) > +{ > + return rsi_set_memory_range(start, end, RSI_RIPAS_RAM, > + RSI_CHANGE_DESTROYED); > +} > + > +/* > + * Convert the specified range to RAM. Do not convert any pages that may have > + * been DESTROYED, without our permission. > + */ > +static inline int rsi_set_memory_range_protected_safe(phys_addr_t start, > + phys_addr_t end) > +{ > + return rsi_set_memory_range(start, end, RSI_RIPAS_RAM, > + RSI_NO_CHANGE_DESTROYED); > +} > + > +static inline int rsi_set_memory_range_shared(phys_addr_t start, > + phys_addr_t end) > +{ > + return rsi_set_memory_range(start, end, RSI_RIPAS_EMPTY, > + RSI_NO_CHANGE_DESTROYED); > +} > +#endif /* __ASM_RSI_H_ */ > diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile > index 2b112f3b7510..71c29a2a2f19 100644 > --- a/arch/arm64/kernel/Makefile > +++ b/arch/arm64/kernel/Makefile > @@ -33,7 +33,8 @@ obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ > return_address.o cpuinfo.o cpu_errata.o \ > cpufeature.o alternative.o cacheinfo.o \ > smp.o smp_spin_table.o topology.o smccc-call.o \ > - syscall.o proton-pack.o idle.o patching.o pi/ > + syscall.o proton-pack.o idle.o patching.o pi/ \ > + rsi.o > > obj-$(CONFIG_COMPAT) += sys32.o signal32.o \ > sys_compat.o > diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c > new file mode 100644 > index 000000000000..128a9a05a96b > --- /dev/null > +++ b/arch/arm64/kernel/rsi.c > @@ -0,0 +1,78 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2023 ARM Ltd. > + */ > + > +#include > +#include > +#include > +#include > + > +DEFINE_STATIC_KEY_FALSE_RO(rsi_present); > +EXPORT_SYMBOL(rsi_present); > + > +static bool rsi_version_matches(void) > +{ > + unsigned long ver_lower, ver_higher; > + unsigned long ret = rsi_request_version(RSI_ABI_VERSION, > + &ver_lower, > + &ver_higher); > + > + if (ret == SMCCC_RET_NOT_SUPPORTED) > + return false; > + > + if (ret != RSI_SUCCESS) { > + pr_err("RME: RMM doesn't support RSI version %lu.%lu. Supported range: %lu.%lu-%lu.%lu\n", > + RSI_ABI_VERSION_MAJOR, RSI_ABI_VERSION_MINOR, > + RSI_ABI_VERSION_GET_MAJOR(ver_lower), > + RSI_ABI_VERSION_GET_MINOR(ver_lower), > + RSI_ABI_VERSION_GET_MAJOR(ver_higher), > + RSI_ABI_VERSION_GET_MINOR(ver_higher)); > + return false; > + } > + > + pr_info("RME: Using RSI version %lu.%lu\n", > + RSI_ABI_VERSION_GET_MAJOR(ver_lower), > + RSI_ABI_VERSION_GET_MINOR(ver_lower)); > + > + return true; > +} > + > +void __init arm64_rsi_setup_memory(void) > +{ > + u64 i; > + phys_addr_t start, end; > + > + if (!is_realm_world()) > + return; > + > + /* > + * Iterate over the available memory ranges and convert the state to > + * protected memory. We should take extra care to ensure that we DO NOT > + * permit any "DESTROYED" pages to be converted to "RAM". > + * > + * BUG_ON is used because if the attempt to switch the memory to > + * protected has failed here, then future accesses to the memory are > + * simply going to be reflected as a SEA (Synchronous External Abort) > + * which we can't handle. Bailing out early prevents the guest limping > + * on and dying later. > + */ > + for_each_mem_range(i, &start, &end) { > + BUG_ON(rsi_set_memory_range_protected_safe(start, end)); > + } > +} > + > +void __init arm64_rsi_init(void) > +{ > + /* > + * If PSCI isn't using SMC, RMM isn't present. Don't try to execute an > + * SMC as it could be UNDEFINED. > + */ > + if (!psci_early_test_conduit(SMCCC_CONDUIT_SMC)) > + return; For ACPI-based kernel boot flow, control never reaches this point because the above function does not check the PSCI conduit method when the kernel is booted via UEFI. As a result, the boot process fails when using ACPI. It works fine with DTB based boot. > + if (!rsi_version_matches()) > + return; > + > + static_branch_enable(&rsi_present); > +} > + > diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c > index a096e2451044..143f87615af0 100644 > --- a/arch/arm64/kernel/setup.c > +++ b/arch/arm64/kernel/setup.c > @@ -43,6 +43,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -293,6 +294,11 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) > * cpufeature code and early parameters. > */ > jump_label_init(); > + /* > + * Init RSI before early param so that "earlycon" console uses the > + * shared alias when in a realm > + */ > + arm64_rsi_init(); > parse_early_param(); > > dynamic_scs_init(); > @@ -328,6 +334,8 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) > > arm64_memblock_init(); > > + arm64_rsi_setup_memory(); > + > paging_init(); > > acpi_table_upgrade(); > -- > 2.34.1 >