From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 283C73AB282 for ; Mon, 25 May 2026 06:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779692349; cv=none; b=DcpJCNrkfBhuv48sIK1ESAoC48H0aDx0p/pM5ewKH2FPFlwblILm6EkNYQiEYa7tSR7cWXfnthhaGpUeT9nMYddyk91VPQmspQ42qu7GAN7zW3S6nrbw80no9AMqhtasI3nJhESoMreI3ZYUMBVKRT7JzyCRKp9gL6uUU2rCcRk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779692349; c=relaxed/simple; bh=f3dsqInXFwi6ogPU7F9goitGLppUKRtIMT3SF9UiJXA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OC3RJPgjfFoE3AluhWuSfT1fD43fWWldd9S/W1eE1kbI6N6gANE+IU9pSjzdX07QQixOYr4Y3nwuzq50gJRJDgwK0FJEFUmNDhVoYsXqj3knDGXymeAAsCAsGf/ixklT+VEmVnZaPzqwG2CxFHPcpYi7hix5jd7BzsUNIZZkUEA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=co0zKW4G; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="co0zKW4G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779692343; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YKzbzsmYYSmbqPFZ4+On8kOHavD4IAbzLAjB1X3xbfQ=; b=co0zKW4G24l/6wM6QAaVJUH3NzJS9lExIEP9nLKgD4JLY5CUwqs9tZQM3WT507BEdxP/rm puMkEC6KzlykOk1U8mdxtAT3Bu0YuMYE/Jfs3TzwKQdMNy5TpPa49cScr/6aSKvaMF5VE0 HNxEFlb94iduOSRh20+UKmj4yrgHy1o= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-49u6gml7MOi_1fk5TsErbw-1; Mon, 25 May 2026 02:59:01 -0400 X-MC-Unique: 49u6gml7MOi_1fk5TsErbw-1 X-Mimecast-MFC-AGG-ID: 49u6gml7MOi_1fk5TsErbw_1779692340 Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-365d4d2fa04so8561360a91.3 for ; Sun, 24 May 2026 23:59:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779692340; x=1780297140; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YKzbzsmYYSmbqPFZ4+On8kOHavD4IAbzLAjB1X3xbfQ=; b=JLEzrG9ojCo6yfvYwmd0SpYzagSc/EGDSPeZCR2aswYXo+h7PbjMxZck/uNFEgRHHW sSsT/LwQ3a1SVjBxEOrDi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P id 98e67ed59e1d1-36add29da45mr2445576a91.15.1779692340147; Sun, 24 May 2026 23:59:00 -0700 (PDT) X-Received: by 2002:a17:90b:264a:b0:36a:dd29:d7f5 with SMTP id 98e67ed59e1d1-36add29da45mr2445545a91.15.1779692339628; Sun, 24 May 2026 23:58:59 -0700 (PDT) Received: from [192.168.68.51] (n175-34-8-244.mrk21.qld.optusnet.com.au. [175.34.8.244]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36a6ec5a287sm4863571a91.0.2026.05.24.23.58.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 24 May 2026 23:58:59 -0700 (PDT) Message-ID: <3a0f6277-2b68-45db-a07f-16a177b0586d@redhat.com> Date: Mon, 25 May 2026 16:58:44 +1000 Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v14 06/44] arm64: RMI: Check for RMI support at init 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 , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" , Emi Kisanuki , Vishal Annapurve , WeiLin.Chang@arm.com, Lorenzo.Pieralisi2@arm.com References: <20260513131757.116630-1-steven.price@arm.com> <20260513131757.116630-7-steven.price@arm.com> <78425c0d-86c5-457f-b171-a4c8dd3acb7d@arm.com> From: Gavin Shan In-Reply-To: <78425c0d-86c5-457f-b171-a4c8dd3acb7d@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: F_L_b-k-JBAbQ_daJ9dDJCa4W9oZq6o4Wij7pf4wUwA_1779692340 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Steve, On 5/22/26 1:49 AM, Steven Price wrote: > On 21/05/2026 01:39, Gavin Shan wrote: >> On 5/13/26 11:17 PM, Steven Price wrote: >>> Query the RMI version number and check if it is a compatible version. >>> The first two feature registers are read and exposed for future code to >>> use. >>> >>> Signed-off-by: Steven Price >>> --- >>> v14: >>>   * This moves the basic RMI setup into the 'kernel' directory. This is >>>     because RMI will be used for some features outside of KVM so should >>>     be available even if KVM isn't compiled in. >>> --- >>>   arch/arm64/include/asm/rmi_cmds.h |  3 ++ >>>   arch/arm64/kernel/Makefile        |  2 +- >>>   arch/arm64/kernel/cpufeature.c    |  1 + >>>   arch/arm64/kernel/rmi.c           | 65 +++++++++++++++++++++++++++++++ >>>   4 files changed, 70 insertions(+), 1 deletion(-) >>>   create mode 100644 arch/arm64/kernel/rmi.c >>> >> >> [...] >> >>> diff --git a/arch/arm64/kernel/rmi.c b/arch/arm64/kernel/rmi.c >>> new file mode 100644 >>> index 000000000000..99c1ccc35c11 >>> --- /dev/null >>> +++ b/arch/arm64/kernel/rmi.c >>> @@ -0,0 +1,65 @@ >>> +// SPDX-License-Identifier: GPL-2.0 >>> +/* >>> + * Copyright (C) 2023-2025 ARM Ltd. >>> + */ >>> + >>> +#include >>> + >>> +#include >>> + >>> +unsigned long rmm_feat_reg0; >>> +unsigned long rmm_feat_reg1; >>> + >>> +static int rmi_check_version(void) >>> +{ >>> +    struct arm_smccc_res res; >>> +    unsigned short version_major, version_minor; >>> +    unsigned long host_version = RMI_ABI_VERSION(RMI_ABI_MAJOR_VERSION, >>> +                             RMI_ABI_MINOR_VERSION); >>> +    unsigned long aa64pfr0 = >>> read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); >>> + >>> +    /* If RME isn't supported, then RMI can't be */ >>> +    if (cpuid_feature_extract_unsigned_field(aa64pfr0, >>> ID_AA64PFR0_EL1_RME_SHIFT) == 0) >>> +        return -ENXIO; >>> + >>> +    arm_smccc_1_1_invoke(SMC_RMI_VERSION, host_version, &res); >>> + >>> +    if (res.a0 == SMCCC_RET_NOT_SUPPORTED) >>> +        return -ENXIO; >>> + >>> +    version_major = RMI_ABI_VERSION_GET_MAJOR(res.a1); >>> +    version_minor = RMI_ABI_VERSION_GET_MINOR(res.a1); >>> + >>> +    if (res.a0 != RMI_SUCCESS) { >>> +        unsigned short high_version_major, high_version_minor; >>> + >>> +        high_version_major = RMI_ABI_VERSION_GET_MAJOR(res.a2); >>> +        high_version_minor = RMI_ABI_VERSION_GET_MINOR(res.a2); >>> + >>> +        pr_err("Unsupported RMI ABI (v%d.%d - v%d.%d) we want v%d.%d\n", >>> +               version_major, version_minor, >>> +               high_version_major, high_version_minor, >>> +               RMI_ABI_MAJOR_VERSION, >>> +               RMI_ABI_MINOR_VERSION); >>> +        return -ENXIO; >>> +    } >>> + >>> +    pr_info("RMI ABI version %d.%d\n", version_major, version_minor); >>> + >>> +    return 0; >>> +} >>> + >>> +static int __init arm64_init_rmi(void) >>> +{ >>> +    /* Continue without realm support if we can't agree on a version */ >>> +    if (rmi_check_version()) >>> +        return 0; >> >> Is this still a valid point that we have to return zero on errors returned >> from rmi_check_version() or other other function calls like rmi_features()? >> arm64_init_rmi() is triggered by subsys_initcall() where the return value >> needs to indicate success or failure. It's fine to return error code from >> arm64_init_rmi() in the path. > > Hmm, I guess now this is moved to arm64 code this indeed doesn't need > to. Within a module I believe an error return can fail the module loading. > > I'm not sure it really makes much difference though - if this > initialisation fails then it's not really an error - it just means the > feature is unavailable. > I think the return value would be consistent to the value of 'arm64_rmi_is_available'. 'arm64_rmi_is_available' is true when zero is returned, otherwise, 'arm64_rmi_is_available' is false. With the consistency between the return value and 'arm64_rmi_is_available', users are able to know the value of 'arm64_rmi_is_available' through kernel parameter 'initcall_debug'. With the kernel parameter, the initcalls including arm64_init_rmi() are traced and its return value is outputted in the traced messages, seeing do_trace_initcall_start(). > Thanks, > Steve > >>> + >>> +    if (WARN_ON(rmi_features(0, &rmm_feat_reg0))) >>> +        return 0; >>> +    if (WARN_ON(rmi_features(1, &rmm_feat_reg1))) >>> +        return 0; >>> + >>> +    return 0; >>> +} >>> +subsys_initcall(arm64_init_rmi); >> Thanks, Gavin