From patchwork Mon Sep 11 14:52:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 13379419 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 1CD25EE7FF4 for ; Mon, 11 Sep 2023 15:02:13 +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: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:In-Reply-To:References: List-Owner; bh=dHBmKq6OL5isS7/legWmSCwDR/DFPeW0H9DWkF45Mno=; b=hFeTgL0Fq83hsz efH2VTEJbSoEja6wMK5khAaJgcrnJFd58p7LNZQLQQc9/d7K/n/I0Ft4pL7g/4L6Bqk7jS48NdDxZ SEnQl0fNEAqYsl/bGnIncvWHc7lgA64kRM2bHKO2g2Au4x4cmYTJfC3uSoxmMEbO0jnKqXqu2qWqy 1eODKPCQEHn8uLpMu/y+ZESkz5cl/4vHfqFIIBlZwbHSvLZYhbMQm9SjgrzXk2G+Lek0FlLSp4CtD xeYqrxF2fpMB7omkUH3RR968jOj0QVPwlNwRyTggDG4cOA7N7q+F/pJMf8d39+hkUOmwA5oKtKdoC ZtmaqCzWooqyUkuBQ4Eg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qfiQ0-000npJ-0W; Mon, 11 Sep 2023 15:01:40 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qfiPw-000nm3-1e for linux-arm-kernel@lists.infradead.org; Mon, 11 Sep 2023 15:01:38 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-402c46c49f4so48914385e9.1 for ; Mon, 11 Sep 2023 08:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694444490; x=1695049290; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XCEOb7WccW67YUIOw67R+Cvx7t9mQ8+KuAnKAOSBIbA=; b=a/okYj+eJSH03ILXqwPjn6cr/HCFE/cLTFYLWmpHpirprGypTB4FW+UEEn0FsuCFOI m8L0TKoK4hUuaJwiaqfiIAFxXAqO60PoKhi62CBRBgYjCZahG7rWKJxK5MaeuggBEd9C gG7M013PB1xuMIEXDQndFc3Udgs9J5RAzULnzizVtDOhU1hZmB+gAhOOufDH3iDSiZN+ 1NcilGCbfBLBkeQ27sBrg1rXGWBQok1dvhLDPrlVCY8kNzRjF1Qkm7KhM2WJ+I+10XQY J6cDldJfIFvWzVAvwy2bsjeXGaDJcM37L/n7/JA3KqS7AqCDstrKd8vlIG5yRb5Mu4ZO FA0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694444490; x=1695049290; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XCEOb7WccW67YUIOw67R+Cvx7t9mQ8+KuAnKAOSBIbA=; b=mGbUf80Zhws/qzZk+Fid9XDExg4A++ljgJc3rpuQW15upN5rRjAyYwkMsGOaiYz/Ff PX1b2EqkpdeyD/3jNLoXFJSqOU4x7EPZ8cHrjsuP3oTOsG5pWZeqtsS3XcoO0iyPJpd2 EDpZy9soZjAJFv7sLJ+I7DF7tHS2nziZztIfxk/q0Lq2u+yZUSm3sozoieGG1KDKNAD9 LkvbNS19eTC1vpIq9fUZ1UVvajad+6JGvIvV8REr+AadZ5YfpY5vgm3/LMtYHEb8C8t5 qLZIHYqiVE2j3ROIRglYdcKbndvN8mJp8Ubq/m53EEZeDv8tfdkGowBO8rk5cYX3rgDP 8wzw== X-Gm-Message-State: AOJu0YzCblUBz2qHPKjU/B4MRcTa2+s80L5h3SpE9pcLzNabqktAKwW7 k3ZzlUPhGSTRDVS23LpgNhKTdA== X-Google-Smtp-Source: AGHT+IGs3SxYXExocX5sgTM4bYzdxVRvEQBoBJnv2MRZBQ3lXA0UXgiTZhsa4PxpOBt7Y18kkfVekw== X-Received: by 2002:adf:e484:0:b0:314:36c5:e4c0 with SMTP id i4-20020adfe484000000b0031436c5e4c0mr7955040wrm.11.1694444490259; Mon, 11 Sep 2023 08:01:30 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7c:7290:b00:fd32:2b31:6755:400c]) by smtp.gmail.com with ESMTPSA id x14-20020aa7dace000000b005257da6be23sm4765010eds.75.2023.09.11.08.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 08:01:29 -0700 (PDT) From: Jean-Philippe Brucker To: maz@kernel.org, oliver.upton@linux.dev Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, lpieralisi@kernel.org, sudeep.holla@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Jean-Philippe Brucker , Ben Horgan Subject: [PATCH] KVM: arm64: nvhe: Ignore SVE hint in SMCCC function ID Date: Mon, 11 Sep 2023 15:52:57 +0100 Message-ID: <20230911145254.934414-4-jean-philippe@linaro.org> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230911_080136_546582_0DF2B5CC X-CRM114-Status: GOOD ( 18.64 ) 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 When SVE is enabled, the host may set bit 16 in SMCCC function IDs, a hint that indicates an unused SVE state. At the moment NVHE doesn't account for this bit when inspecting the function ID, and rejects most calls. Clear the hint bit before comparing function IDs. About version compatibility: the host's PSCI driver initially probes the firmware for a SMCCC version number. If the firmware implements a protocol recent enough (1.3), subsequent SMCCC calls have the hint bit set. Since the hint bit was reserved in earlier versions of the protocol, clearing it is fine regardless of the version in use. When a new hint is added to the protocol in the future, it will be added to ARM_SMCCC_CALL_HINTS and NVHE will handle it straight away. This patch only clears known hints and leaves reserved bits as is, because future SMCCC versions could use reserved bits as modifiers for the function ID, rather than hints. Fixes: cfa7ff959a78 ("arm64: smccc: Support SMCCC v1.3 SVE register saving hint") Reported-by: Ben Horgan Signed-off-by: Jean-Philippe Brucker --- arch/arm64/include/asm/kvm_hyp.h | 2 +- arch/arm64/kvm/hyp/include/nvhe/ffa.h | 2 +- include/linux/arm-smccc.h | 2 ++ arch/arm64/kvm/hyp/nvhe/ffa.c | 3 +-- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 8 ++++++-- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 3 +-- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 1 + 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index b7238c72a04cf..66efd67ea7e8d 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -118,7 +118,7 @@ void deactivate_traps_vhe_put(struct kvm_vcpu *vcpu); u64 __guest_enter(struct kvm_vcpu *vcpu); -bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt); +bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt, u32 func_id); #ifdef __KVM_NVHE_HYPERVISOR__ void __noreturn __hyp_do_panic(struct kvm_cpu_context *host_ctxt, u64 spsr, diff --git a/arch/arm64/kvm/hyp/include/nvhe/ffa.h b/arch/arm64/kvm/hyp/include/nvhe/ffa.h index 1becb10ecd805..d9fd5e6c7d3cc 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/ffa.h +++ b/arch/arm64/kvm/hyp/include/nvhe/ffa.h @@ -12,6 +12,6 @@ #define FFA_MAX_FUNC_NUM 0x7F int hyp_ffa_init(void *pages); -bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt); +bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id); #endif /* __KVM_HYP_FFA_H */ diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 7c67c17321d4c..083f856537161 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -67,6 +67,8 @@ #define ARM_SMCCC_VERSION_1_3 0x10003 #define ARM_SMCCC_1_3_SVE_HINT 0x10000 +#define ARM_SMCCC_CALL_HINTS ARM_SMCCC_1_3_SVE_HINT + #define ARM_SMCCC_VERSION_FUNC_ID \ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index ab4f5d160c58f..6e4dba9eadef5 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -634,9 +634,8 @@ static bool do_ffa_features(struct arm_smccc_res *res, return true; } -bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt) +bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id) { - DECLARE_REG(u64, func_id, host_ctxt, 0); struct arm_smccc_res res; /* diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 857d9bc04fd48..2385fd03ed87c 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -368,6 +368,7 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) if (static_branch_unlikely(&kvm_protected_mode_initialized)) hcall_min = __KVM_HOST_SMCCC_FUNC___pkvm_prot_finalize; + id &= ~ARM_SMCCC_CALL_HINTS; id -= KVM_HOST_SMCCC_ID(0); if (unlikely(id < hcall_min || id >= ARRAY_SIZE(host_hcall))) @@ -392,11 +393,14 @@ static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt) static void handle_host_smc(struct kvm_cpu_context *host_ctxt) { + DECLARE_REG(u64, func_id, host_ctxt, 0); bool handled; - handled = kvm_host_psci_handler(host_ctxt); + func_id &= ~ARM_SMCCC_CALL_HINTS; + + handled = kvm_host_psci_handler(host_ctxt, func_id); if (!handled) - handled = kvm_host_ffa_handler(host_ctxt); + handled = kvm_host_ffa_handler(host_ctxt, func_id); if (!handled) default_host_smc_handler(host_ctxt); diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c index 24543d2a34905..d57bcb6ab94d2 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c @@ -273,9 +273,8 @@ static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context *host_ } } -bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt) +bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt, u32 func_id) { - DECLARE_REG(u64, func_id, host_ctxt, 0); unsigned long ret; switch (kvm_host_psci_config.version) { diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index 90fade1b032e4..1cc06e6797bda 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -57,6 +57,7 @@ __do_hyp_init: cmp x0, #HVC_STUB_HCALL_NR b.lo __kvm_handle_stub_hvc + bic x0, x0, #ARM_SMCCC_CALL_HINTS mov x3, #KVM_HOST_SMCCC_FUNC(__kvm_hyp_init) cmp x0, x3 b.eq 1f