From patchwork Wed Nov 16 17:03:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 13045597 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 197EDC433FE for ; Wed, 16 Nov 2022 17:06:25 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=qLcSc/JZFkDnmvYAqVL+c3ZcCJXPrImIS2d2NVNkDIM=; b=2sHQ+OIKMRB5vFefIKZ/8Dy0vV IOFRw30w10+XFvU5eVL5CBuFw5/6zSxHuqA/Ydu3BWVgJR9tbNT41OeA993Fbxov5mBUKISwKqbBP NGNVT7Fi/H8wMMeYquPMPYChEN/0qhLgdfg+RZVWI3x1gJ1g/l+R3JskKAVelc4w07lAgqthqMPWk Sni5ZvQPThgkomrGdcSMUfLKWhkPeqYBs49hs8YnRRGp7vMjF117fnZ+LaFYmg7GNU4+5fa6jBwmk AyAtDIRsD8DU6F560bhhOhXH+rP5jwdOO97rE+lXTIf1xY0wsWf7zbHaVzpaOAfq1RCJp8kg8rfH7 3vz6DxaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovLqd-006Elo-D7; Wed, 16 Nov 2022 17:05:15 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovLpI-006DxJ-98 for linux-arm-kernel@lists.infradead.org; Wed, 16 Nov 2022 17:03:53 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id j132-20020a25238a000000b006da635e2073so16462842ybj.2 for ; Wed, 16 Nov 2022 09:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/bRkqjyelCT2BwKXDL2kk3eM+ea/9WF6lbhTPLqyzQs=; b=OdTGpYZuNgCXakLh2Jk72rtpCkaN4uXEYVgleL325j12+NmpV15XjX8JS6kVtFnDwK PNhAWspY5fLWyh0Xj8g3+lafmWa+eNTSAWQNZ6ONYvy50LpLKB4FdqVaYvmgtJW2AQwQ 3xyBTOFq4CD0fbhlimpa8mukamYs6e4YSrieqiuW60AY/G/B7EQ2yfIjZd0LkShAI6L6 AdgQri5c8YZwdv8W2uBFogmXjDGJjZ5thbMVabQnwE3E5hk6ShehMMeEGgcGHCmDZLeW itubJ4CVgFw6aN3xSYppKJyDs5NU7h2q0H+C5Jh9Gqse5HdJu4x5tknbHrNbOaZ/CoAS +7pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/bRkqjyelCT2BwKXDL2kk3eM+ea/9WF6lbhTPLqyzQs=; b=jmzgjj5NiYwetSL6ePdOTImnw5f4eI0uKi679h5Kiw/yHugqjgLQT7F4nLhSl4BLiF 9aw2KFUyntHlbRdSfzmP90RKHiTF3tygyNv+fgSHcxcbF3z/i+WUCIOxR58ozkdbzh31 eQWhIcDNdypG64n4DfAZSkQ2G1nDtgohwBIsbD9Vpyn6YF+jMsyRC+JsKjm4Wz/aIXxQ xuikbgY3O879vsgECbQ+l+q7OD7u+C30rJWcdB22LJw+SxukhPnhjEHRtjUPEk/uo1z4 NJd3e/6/i2ljMlMCNc/GsH38QlcZR05VBAUHMQtVpR2rnCJMu/4NkYfdqDNFEMwpbs+5 RswA== X-Gm-Message-State: ACrzQf1JuGYTzOETNyVa8PIEjllUKmNurhPinB1KXXd3ytVlW1VM07h8 NfKKv1n8YZSgwPmKHDJB3FlxH8QQaLSi X-Google-Smtp-Source: AMsMyM6kz2VVfMezIhOWhcHrz/hGAETOYwjma0z07Lmtkc6uNWWu17KZrnMVkVuR1GhaX/Tp0luYpM2CFjFt X-Received: from big-boi.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:129]) (user=qperret job=sendgmr) by 2002:a05:6902:1206:b0:6c0:2863:c15c with SMTP id s6-20020a056902120600b006c02863c15cmr68406659ybu.117.1668618227919; Wed, 16 Nov 2022 09:03:47 -0800 (PST) Date: Wed, 16 Nov 2022 17:03:27 +0000 In-Reply-To: <20221116170335.2341003-1-qperret@google.com> Mime-Version: 1.0 References: <20221116170335.2341003-1-qperret@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221116170335.2341003-5-qperret@google.com> Subject: [PATCH 04/12] KVM: arm64: Probe FF-A version and host/hyp partition ID during init From: Quentin Perret To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Catalin Marinas , Will Deacon , Sudeep Holla , Andrew Walbran Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221116_090352_375955_5387CB4A X-CRM114-Status: GOOD ( 15.28 ) 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: Will Deacon Probe FF-A during pKVM initialisation so that we can detect any inconsistencies in the version or partition ID early on. Signed-off-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/hyp/include/nvhe/ffa.h | 1 + arch/arm64/kvm/hyp/nvhe/ffa.c | 30 +++++++++++++++++++++++++++ arch/arm64/kvm/hyp/nvhe/setup.c | 5 +++++ 5 files changed, 38 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 63307e7dc9c5..ab5ccf47c05f 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -347,6 +347,7 @@ struct kvm_host_data { struct kvm_host_psci_config { /* PSCI version used by host. */ u32 version; + u32 smccc_version; /* Function IDs used by host if version is v0.1. */ struct psci_0_1_function_ids function_ids_0_1; diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 1d1a3b93a3de..8b93af23f327 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1780,6 +1780,7 @@ static bool init_psci_relay(void) } kvm_host_psci_config.version = psci_ops.get_version(); + kvm_host_psci_config.smccc_version = arm_smccc_get_version(); if (kvm_host_psci_config.version == PSCI_VERSION(0, 1)) { kvm_host_psci_config.function_ids_0_1 = get_psci_0_1_function_ids(); diff --git a/arch/arm64/kvm/hyp/include/nvhe/ffa.h b/arch/arm64/kvm/hyp/include/nvhe/ffa.h index fc09ec671e24..5c9b92430ff3 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/ffa.h +++ b/arch/arm64/kvm/hyp/include/nvhe/ffa.h @@ -11,6 +11,7 @@ #define FFA_MIN_FUNC_NUM 0x60 #define FFA_MAX_FUNC_NUM 0x7F +int hyp_ffa_init(void); bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt); #endif /* __KVM_HYP_FFA_H */ diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 6ccf935d3b41..969d72390844 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -31,6 +31,12 @@ #include #include +/* + * "ID value 0 must be returned at the Non-secure physical FF-A instance" + * We share this ID with the host. + */ +#define HOST_FFA_ID 0 + static void ffa_to_smccc_error(struct arm_smccc_res *res, u64 ffa_errno) { *res = (struct arm_smccc_res) { @@ -111,3 +117,27 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt) ffa_set_retval(host_ctxt, &res); return true; } + +int hyp_ffa_init(void) +{ + struct arm_smccc_res res; + + if (kvm_host_psci_config.smccc_version < ARM_SMCCC_VERSION_1_2) + return 0; + + arm_smccc_1_1_smc(FFA_VERSION, FFA_VERSION_1_0, 0, 0, 0, 0, 0, 0, &res); + if (res.a0 == FFA_RET_NOT_SUPPORTED) + return 0; + + if (res.a0 != FFA_VERSION_1_0) + return -EOPNOTSUPP; + + arm_smccc_1_1_smc(FFA_ID_GET, 0, 0, 0, 0, 0, 0, 0, &res); + if (res.a0 != FFA_SUCCESS) + return -EOPNOTSUPP; + + if (res.a2 != HOST_FFA_ID) + return -EINVAL; + + return 0; +} diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 110f04627785..c4ca174a0592 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -314,6 +315,10 @@ void __noreturn __pkvm_init_finalise(void) if (ret) goto out; + ret = hyp_ffa_init(); + if (ret) + goto out; + pkvm_hyp_vm_table_init(vm_table_base); out: /*