From nobody Sat Feb 14 05:39:05 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 577234CB4B for ; Wed, 15 May 2024 17:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715793794; cv=none; b=h4hu7+4ZzXRVpTnywgAh7zVRxSef97DPAVZfLjXWUWx9BHryBz/LEYGtOCGtX3y5zrJg2Hx78iE7bkqaPuywa6ta5tsyVwfJ3OtRI/6KTOaIq1or6n95D+UN8Mnp7LNQZaoW/r8En7XirAN4Wz1l6KZDDZ2/PGkk7x+rzT6E0bQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715793794; c=relaxed/simple; bh=QYil/6bNPDyLFlt/IP4iXiqn4VhW5HCAEKor3jRfRXs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HceAza/yvVXezVorxsnomzNFtDNerN+vmmGFLYSgqEbB5XSQNEdXIJVWHvp9fDE3Eb6KrApNnrJpEa+dprr8kpgGqNdWP0LokKKvS5OqFfNi/TjHJbJDcs2ne6GQxb5yQqtEA1xQiXC5JJh9Mb9fVpf2+tl4jv9WIFqq5WOyQRk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tvQDi612; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tvQDi612" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-622ce716ceaso47313057b3.0 for ; Wed, 15 May 2024 10:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715793790; x=1716398590; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WQNv0L9f8Ur9QycJthQG4bmvCcJmqN/f24s1YQ7H6/M=; b=tvQDi612Ipa88MK2QxJUWJ/nhiJ7zfNUiSVs6JfJbJ1q2ufXfmGXNVPAr04CLrK5QY jJ3ooBQvMhrNSVJ3g6emQvtAsMf0UEi3nuVKILxsDh0u5jagd+D0PmxftqJbLsr6yavI 8MRNwbXXxvkitciCxr0O+rV09JV2LKM8gs6juL9I5pk6oTANS5/QEZZIdMjhf6V+4yS0 OqaHtRPxBWVgi3rEbh/Rld+S/vJhHs1xE3i7JVqVEQJ5iZHeVkzzMhYJfmoCCOnTrfnu vUMXtSSWGs0SdJJWLQGeq/nNjeLRBlKhIQoCruWgWtEAEwp83H9A8fA7M01tlgKGl6jB rLRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715793790; x=1716398590; 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=WQNv0L9f8Ur9QycJthQG4bmvCcJmqN/f24s1YQ7H6/M=; b=F8BI8jRIJKu94ApetpkCYZ5zwutPM1jIws1dW8R3ezhvMD63X9jDNpyFPWvLr9St80 wedhSzKFWdCYeUQw76B5uCxDtKuog2zXQ1F7XKLiM7qCDMw19uXb/2aphrGg8jQ8VUiv nkOBIgHNUvKLRBC/OjOfG213S78w0DcnlK0gy3Bi1LICadGM0K8EoafN+dSaXfd6yVG5 WVgI/VYNSosW7FSterlossq7erXs7dAD7CZVxLU9wb367FIle4cLxg/S9AUxQL0S595N 1Q8xfzsL0ROvzJFntCQjp9T7Gtab4HM38AT6kw7Tvog97NemtZQjxnlpOyCaNbMDusMw cKzg== X-Forwarded-Encrypted: i=1; AJvYcCVC48StlQKflokKXHvqLMCWG4l9LvQlbn8yqP0GqvdOUDp2sOkNvKysqYdT9hHU3K6o0GZzdlbFr2itIIdb/ilp4dezNphu2UxAZh5J X-Gm-Message-State: AOJu0YxyXTndLbWSrlcpCAF2mBmz4QAhsumZABcyVkNDLVuNCC34MMQC IL297dT0o8r5D7vVWMIeyT3yhpA333U/kWwm404asND2xFNG7dG4IDAd2iNOh7sNJBapyqmOb4A VVsG/cxP12BN5KeF2D6OAdzfFEQ== X-Google-Smtp-Source: AGHT+IFWj0CPWZNjkZCa8D6KDWXhJ9Flvad+9yi5Xs81Nbt0wNqI/d2+oXKWmpATfuUhMILUHaW60rmoGvWSagTvTps= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:690c:6904:b0:611:6f24:62b1 with SMTP id 00721157ae682-622af7a98aamr44278057b3.1.1715793790276; Wed, 15 May 2024 10:23:10 -0700 (PDT) Date: Wed, 15 May 2024 17:22:55 +0000 In-Reply-To: <20240515172258.1680881-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240515172258.1680881-1-sebastianene@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240515172258.1680881-2-sebastianene@google.com> Subject: [PATCH v2 1/4] KVM: arm64: Trap FFA_VERSION host call in pKVM From: Sebastian Ene To: catalin.marinas@arm.com, james.morse@arm.com, jean-philippe@linaro.org, maz@kernel.org, oliver.upton@linux.dev, qperret@google.com, qwandor@google.com, sudeep.holla@arm.com, suzuki.poulose@arm.com, tabba@google.com, will@kernel.org, yuzenghui@huawei.com, lpieralisi@kernel.org Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Sebastian Ene Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The pKVM hypervisor initializes with FF-A version 1.0. The spec requires that no other FF-A calls to be issued before the version negotiation phase is complete. Split the hypervisor proxy initialization code in two parts so that we can move the later one after the host negotiates its version. Without trapping the call, the host drivers can negotiate a higher version number with TEE which can result in a different memory layout described during the memory sharing calls. Signed-off-by: Sebastian Ene Reviewed-by: Sudeep Holla Tested-by: Sudeep Holla --- arch/arm64/kvm/hyp/nvhe/ffa.c | 123 +++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 31 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 320f2eaa14a9..72f1206c85fb 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only +// /* * FF-A v1.0 proxy to filter out invalid memory-sharing SMC calls issued by * the host. FF-A is a slightly more palatable abbreviation of "Arm Firmwa= re @@ -67,6 +68,9 @@ struct kvm_ffa_buffers { */ static struct kvm_ffa_buffers hyp_buffers; static struct kvm_ffa_buffers host_buffers; +static u32 hyp_ffa_version; +static bool has_version_negotiated; +static hyp_spinlock_t version_lock; =20 static void ffa_to_smccc_error(struct arm_smccc_res *res, u64 ffa_errno) { @@ -640,6 +644,83 @@ static bool do_ffa_features(struct arm_smccc_res *res, return true; } =20 +static int hyp_ffa_post_init(void) +{ + size_t min_rxtx_sz; + struct arm_smccc_res res; + + arm_smccc_1_1_smc(FFA_ID_GET, 0, 0, 0, 0, 0, 0, 0, &res); + if (res.a0 !=3D FFA_SUCCESS) + return -EOPNOTSUPP; + + if (res.a2 !=3D HOST_FFA_ID) + return -EINVAL; + + arm_smccc_1_1_smc(FFA_FEATURES, FFA_FN64_RXTX_MAP, + 0, 0, 0, 0, 0, 0, &res); + if (res.a0 !=3D FFA_SUCCESS) + return -EOPNOTSUPP; + + switch (res.a2) { + case FFA_FEAT_RXTX_MIN_SZ_4K: + min_rxtx_sz =3D SZ_4K; + break; + case FFA_FEAT_RXTX_MIN_SZ_16K: + min_rxtx_sz =3D SZ_16K; + break; + case FFA_FEAT_RXTX_MIN_SZ_64K: + min_rxtx_sz =3D SZ_64K; + break; + default: + return -EINVAL; + } + + if (min_rxtx_sz > PAGE_SIZE) + return -EOPNOTSUPP; + + return 0; +} + +static void do_ffa_version(struct arm_smccc_res *res, + struct kvm_cpu_context *ctxt) +{ + DECLARE_REG(u32, ffa_req_version, ctxt, 1); + + if (FFA_MAJOR_VERSION(ffa_req_version) !=3D 1) { + res->a0 =3D FFA_RET_NOT_SUPPORTED; + return; + } + + hyp_spin_lock(&version_lock); + if (has_version_negotiated) { + res->a0 =3D hyp_ffa_version; + goto unlock; + } + + /* + * If the client driver tries to downgrade the version, we need to ask + * first if TEE supports it. + */ + if (FFA_MINOR_VERSION(ffa_req_version) < FFA_MINOR_VERSION(hyp_ffa_versio= n)) { + arm_smccc_1_1_smc(FFA_VERSION, ffa_req_version, 0, + 0, 0, 0, 0, 0, + res); + if (res->a0 =3D=3D FFA_RET_NOT_SUPPORTED) + goto unlock; + + hyp_ffa_version =3D ffa_req_version; + } + + if (hyp_ffa_post_init()) + res->a0 =3D FFA_RET_NOT_SUPPORTED; + else { + has_version_negotiated =3D true; + res->a0 =3D hyp_ffa_version; + } +unlock: + hyp_spin_unlock(&version_lock); +} + bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id) { struct arm_smccc_res res; @@ -660,6 +741,11 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host= _ctxt, u32 func_id) if (!is_ffa_call(func_id)) return false; =20 + if (!has_version_negotiated && func_id !=3D FFA_VERSION) { + ffa_to_smccc_error(&res, FFA_RET_INVALID_PARAMETERS); + goto out_handled; + } + switch (func_id) { case FFA_FEATURES: if (!do_ffa_features(&res, host_ctxt)) @@ -686,6 +772,9 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_= ctxt, u32 func_id) case FFA_MEM_FRAG_TX: do_ffa_mem_frag_tx(&res, host_ctxt); goto out_handled; + case FFA_VERSION: + do_ffa_version(&res, host_ctxt); + goto out_handled; } =20 if (ffa_call_supported(func_id)) @@ -700,7 +789,6 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_= ctxt, u32 func_id) int hyp_ffa_init(void *pages) { struct arm_smccc_res res; - size_t min_rxtx_sz; void *tx, *rx; =20 if (kvm_host_psci_config.smccc_version < ARM_SMCCC_VERSION_1_2) @@ -726,35 +814,7 @@ int hyp_ffa_init(void *pages) if (FFA_MAJOR_VERSION(res.a0) !=3D 1) return -EOPNOTSUPP; =20 - arm_smccc_1_1_smc(FFA_ID_GET, 0, 0, 0, 0, 0, 0, 0, &res); - if (res.a0 !=3D FFA_SUCCESS) - return -EOPNOTSUPP; - - if (res.a2 !=3D HOST_FFA_ID) - return -EINVAL; - - arm_smccc_1_1_smc(FFA_FEATURES, FFA_FN64_RXTX_MAP, - 0, 0, 0, 0, 0, 0, &res); - if (res.a0 !=3D FFA_SUCCESS) - return -EOPNOTSUPP; - - switch (res.a2) { - case FFA_FEAT_RXTX_MIN_SZ_4K: - min_rxtx_sz =3D SZ_4K; - break; - case FFA_FEAT_RXTX_MIN_SZ_16K: - min_rxtx_sz =3D SZ_16K; - break; - case FFA_FEAT_RXTX_MIN_SZ_64K: - min_rxtx_sz =3D SZ_64K; - break; - default: - return -EINVAL; - } - - if (min_rxtx_sz > PAGE_SIZE) - return -EOPNOTSUPP; - + hyp_ffa_version =3D FFA_VERSION_1_0; tx =3D pages; pages +=3D KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE; rx =3D pages; @@ -773,8 +833,9 @@ int hyp_ffa_init(void *pages) }; =20 host_buffers =3D (struct kvm_ffa_buffers) { - .lock =3D __HYP_SPIN_LOCK_UNLOCKED, + .lock =3D __HYP_SPIN_LOCK_UNLOCKED, }; =20 + version_lock =3D __HYP_SPIN_LOCK_UNLOCKED; return 0; } --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Sat Feb 14 05:39:05 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D528156674 for ; Wed, 15 May 2024 17:23:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715793795; cv=none; b=dpIXoFNp2FiMJ66AFKpb0SgjooZsAvA4eY0bCS7HLETzXfLfYlYZCBr9DpcZm/aLUfW1fSQGYpkO4ua2a8rUq02UtWfHk43wC+Weqq6Jk84ku1gpPR+M5xsubtkLw3U3XFtk+oNU2UY/1IixM6/XQk/pDlCt1Jn0VDC5c9DKENQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715793795; c=relaxed/simple; bh=VaTIobEA8JkI6Wa8oziZkFqV/LwUPyiZSfvuV+7j/LA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TYGZKqvjHSvDWUWqhRUi4MPPvWKPfVl8pTOU4m7G5eA8OHvJ35kuDLNO3kHskON3SaEJ0VZIEGHDLUO50uNg7YK+fzLVEKqyf5xTWX3IgIbJ6P+kLaIyhoiyYSL5TO/7vylPkaYTGJZYZtKH9Q+5PJ3Eg6Md3+L9iVirkcL+iq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hs1ieU/I; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hs1ieU/I" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-41fe329e720so33008085e9.2 for ; Wed, 15 May 2024 10:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715793792; x=1716398592; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PcqaauEjDoHXh8ji52zP7N4xCK0LJvzWgGd8bzIHFvQ=; b=hs1ieU/IwWgOW+yAhflV5c2nGEjIjIUzFkdcOrNvET/sVazNQfcOkwjrRreyKzCsgk dBTeRL448vCBvhtbPBmYsTmZr5MeBSUuOKmalKYMzR6khj74pq52v4dGW4Kym5A+z8Yu NjpJAXFRAg/lxiMsJdHdqz7aJrtCEXJ8NiOYS5zUamV3RoTXrsmyqUeUHFX9kW69wUzc zOwkROTOkH9I3/z+FuzDOGe3oAFBCXD1bknjcySbXuWN5ubv3LGA/0af5diJOPJ+kSV4 DlOM+W1MxjpTmob2yNYYk6f50xhLHfiK2xecJEaBuyBjnw4FPiQ6quWydF2vsaQ1fpVg BvRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715793792; x=1716398592; 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=PcqaauEjDoHXh8ji52zP7N4xCK0LJvzWgGd8bzIHFvQ=; b=K8jbnxGppHTdKk2Kal8VaT5sCGLNxGEpPZKFu58v6NNSCiodBsaWCadJunEjYu5tBo U1U0h50+28yq88tRTc4bjcRAgcKC9HjkeHN40FKTIYdV5xlGp5tl1r4ObhonrFVgR3kz NuixQ8MUREA/piACw6mdo5uhKzVMNiM0xyfv7OBWQdLomADbkmi7CmbBV11+lNRBwEzE LeuJg5jSgRxXSsNChIhE02rm+IfoVA0y4jIfAZojERM6WfDGphXJyTMlD1Tl0+X6Io0n vFo1CDXz4UqWrhHcnswnvBHdqtgc/OSCRLQeu6qnACQ+0RPmubVuj+XIHP+X+zKeWOVQ h5CQ== X-Forwarded-Encrypted: i=1; AJvYcCWrSs3SO6FA8pYTPr6m8Z0F7lgkIwE1enSBDErlLKCdkh6Rk7WSFe/XdT4YPBKzLDGA6UXDSIwNjBjfuZUjPLWkdygE38BgYUfCa/Jx X-Gm-Message-State: AOJu0Ywq1yky9gh2HJa+xVn7yuR1zURX1sMNq1J/3BU1mZnUXAwtAoR+ u+KQPCKbiIN7Dv1Jsp1mfSD1JOAJHLrSHqRlK+34XWqMcZ8VVIx6kCdnIMSudLDqIlog+6ReklB o0md/65ekwQblYFWQAc0FQxH6sQ== X-Google-Smtp-Source: AGHT+IGGUIJb5pGjjG4rjRgqRcd958BlLvK0rXB3oHHp6PSS+i2nJgNusaT1TQYCxhhQR4CzKLUcSXY1cFz2pqMA+h8= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:600c:502b:b0:420:217f:4f7 with SMTP id 5b1f17b1804b1-420217f0761mr367455e9.6.1715793792652; Wed, 15 May 2024 10:23:12 -0700 (PDT) Date: Wed, 15 May 2024 17:22:56 +0000 In-Reply-To: <20240515172258.1680881-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240515172258.1680881-1-sebastianene@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240515172258.1680881-3-sebastianene@google.com> Subject: [PATCH v2 2/4] KVM: arm64: Add support for FFA_PARTITION_INFO_GET From: Sebastian Ene To: catalin.marinas@arm.com, james.morse@arm.com, jean-philippe@linaro.org, maz@kernel.org, oliver.upton@linux.dev, qperret@google.com, qwandor@google.com, sudeep.holla@arm.com, suzuki.poulose@arm.com, tabba@google.com, will@kernel.org, yuzenghui@huawei.com, lpieralisi@kernel.org Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Sebastian Ene Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Handle the FFA_PARTITION_INFO_GET host call inside the pKVM hypervisor and copy the response message back to the host buffers. Save the returned FF-A version as we will need it later to interpret the response from the TEE. Signed-off-by: Sebastian Ene Reviewed-by: Sudeep Holla Tested-by: Sudeep Holla --- arch/arm64/kvm/hyp/nvhe/ffa.c | 52 +++++++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 3 ++ 2 files changed, 55 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 72f1206c85fb..f9664c4a348e 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -721,6 +721,55 @@ static void do_ffa_version(struct arm_smccc_res *res, hyp_spin_unlock(&version_lock); } =20 +static void do_ffa_part_get(struct arm_smccc_res *res, + struct kvm_cpu_context *ctxt) +{ + DECLARE_REG(u32, uuid0, ctxt, 1); + DECLARE_REG(u32, uuid1, ctxt, 2); + DECLARE_REG(u32, uuid2, ctxt, 3); + DECLARE_REG(u32, uuid3, ctxt, 4); + DECLARE_REG(u32, flags, ctxt, 5); + u32 count, partition_sz, copy_sz; + + hyp_spin_lock(&host_buffers.lock); + if (!host_buffers.rx) { + ffa_to_smccc_res(res, FFA_RET_BUSY); + goto out_unlock; + } + + arm_smccc_1_1_smc(FFA_PARTITION_INFO_GET, uuid0, uuid1, + uuid2, uuid3, flags, 0, 0, + res); + + if (res->a0 !=3D FFA_SUCCESS) + goto out_unlock; + + count =3D res->a2; + if (!count) + goto out_unlock; + + if (hyp_ffa_version > FFA_VERSION_1_0) { + /* Get the number of partitions deployed in the system */ + if (flags & 0x1) + goto out_unlock; + + partition_sz =3D res->a3; + } else { + /* FFA_VERSION_1_0 lacks the size in the response */ + partition_sz =3D FFA_1_0_PARTITON_INFO_SZ; + } + + copy_sz =3D partition_sz * count; + if (copy_sz > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) { + ffa_to_smccc_res(res, FFA_RET_ABORTED); + goto out_unlock; + } + + memcpy(host_buffers.rx, hyp_buffers.rx, copy_sz); +out_unlock: + hyp_spin_unlock(&host_buffers.lock); +} + bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id) { struct arm_smccc_res res; @@ -775,6 +824,9 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_= ctxt, u32 func_id) case FFA_VERSION: do_ffa_version(&res, host_ctxt); goto out_handled; + case FFA_PARTITION_INFO_GET: + do_ffa_part_get(&res, host_ctxt); + goto out_handled; } =20 if (ffa_call_supported(func_id)) diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index c906f666ff5d..12a7fa2d6550 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -211,6 +211,9 @@ bool ffa_device_is_valid(struct ffa_device *ffa_dev) { = return false; } =20 extern const struct bus_type ffa_bus_type; =20 +/* The FF-A 1.0 partition structure lacks the uuid[4] */ +#define FFA_1_0_PARTITON_INFO_SZ (8) + /* FFA transport related */ struct ffa_partition_info { u16 id; --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Sat Feb 14 05:39:05 2026 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96A2F156C5E for ; Wed, 15 May 2024 17:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715793798; cv=none; b=ufNXCG3kg+83CTrsnf66oBu131d2Qir1B+FNCA7E8/zC/tYykmGpSASHrPnvILitCnGYt4Tvxpzsi8EcBWqPmFvlDGcxIsL4DJE1eUP/5IfClNREKuAtiLWl7qqqPAIlfSznlfPlJFsKG1YfxDfLtd9TiLyJb1cPRHasQ8rJ+DI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715793798; c=relaxed/simple; bh=27Ez01frh80qv0dCLE2nqGawXWJ0QpQYbc9jTyic+yQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Do3p64NrTAlqsZBYqinPMSsfgEjnHJT0GinbgCgjYP8aVs3rvRBpkuag1HWlUYFgdk5KeNolDQtt9XakdFN7qCMqukiZTGU4gYT/lSpGXqjezXhrTN9BtVuyv2LA25wYOoLg7Ge7ukqvg6nYCl8wP65wNo4UFTa6ziUNCaQQj9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=F6H06BBm; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F6H06BBm" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-351c67dbc8dso1280406f8f.2 for ; Wed, 15 May 2024 10:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715793795; x=1716398595; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=B0DAehK5iEGC7D6F2LaIGrwd7yaT6oZGo7c2srRK8ao=; b=F6H06BBmgGJtySJAGTI9CstNC2TckiLx4wv3qBKhisv2fNSudkvaWQgxh0BE3k9xfK f5pMf3YT9VuyfyA7UedpYgZmYsUOAqSh2AAvkL4EnutSsesyaYEm5omxYTdir/WXXs8+ 6GW1e/b6HvA9aBd0HiN2QQjwP6olXAwyCGn8hEDqon4pl/8U2v07F+3bA6qA3yrQuOyZ IzYyIwOu4EGkq3QX4IP9DGql0vhF6Bx6+2qLygLT2k3NycNpf9q/9yKNq6UFFsXLjIVW GRp7q8Bmokkkw1JZHxByoG2vuJKDatbrFsbpBVMM9o2Rxk84KMYoaMWYzw58EOSCQpHa 65kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715793795; x=1716398595; 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=B0DAehK5iEGC7D6F2LaIGrwd7yaT6oZGo7c2srRK8ao=; b=l/ycjB3o0KMxxZUxNvlPzQFVliaXCEYfwo8aCnuNx/qzn4KzkEEnA3WvpxTy+FiA5B E17Ub4+MHgIJ5gWYAwCpm06hHLaasXC0U/EuF/hdikxbxPv9xPQf5eInmcoRru1hOd+F JUovF/0rTA2r5/S5lORGsjjtpIhYFnQkJUFTP3A1KVFOKn5gZkpak63Gz/azXXr25qUx HxDJR0sSbtYk6IPPiV509IGtNIsEJYjr8VE2af1TOQ2chvwKeSQ0fAXDqOpqQb4mqjk1 xlIXl/L4C1fPw121IyiN+aMETL8kPUeq7kXtTqTx8SUKHt6aFp3qgW+g2e+gPHw0MGvf 6Ehg== X-Forwarded-Encrypted: i=1; AJvYcCW4wWghVB7o5ozx7azYhoaj+Ey+XVGeGiGeEaBZVqCwNcYJO+Q4V9EaKrwsLZ03a6CboUeapm8iQiWxAqnGDSMMODgutbqkWMaflioO X-Gm-Message-State: AOJu0YwTdhuntMA2xAw64z4LrTRU33K4ohqOLbHLbC8aTl9HakVQORfp G3KJCBx2tfWbWwiJj8vQVI2UXxpFnlqt3ydBa4bHCa2k5Wes9mWGHYnvwvofhFEeNtth0+QKMm5 hfWhVVTXu8g9wcTQUZz2NfC5EbQ== X-Google-Smtp-Source: AGHT+IH03ZoGLJfBqC8Eh4MTyJx29qZ/mRDItFO9N0niAZcln5o7llsonWFoglyUwHcG4HXvFRo52sD+v+QqQnvnw4k= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a5d:4750:0:b0:34d:a979:e99b with SMTP id ffacd0b85a97d-3504a10f83dmr32508f8f.0.1715793794931; Wed, 15 May 2024 10:23:14 -0700 (PDT) Date: Wed, 15 May 2024 17:22:57 +0000 In-Reply-To: <20240515172258.1680881-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240515172258.1680881-1-sebastianene@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240515172258.1680881-4-sebastianene@google.com> Subject: [PATCH v2 3/4] KVM: arm64: Fix the identification range for the FF-A smcs From: Sebastian Ene To: catalin.marinas@arm.com, james.morse@arm.com, jean-philippe@linaro.org, maz@kernel.org, oliver.upton@linux.dev, qperret@google.com, qwandor@google.com, sudeep.holla@arm.com, suzuki.poulose@arm.com, tabba@google.com, will@kernel.org, yuzenghui@huawei.com, lpieralisi@kernel.org Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Sebastian Ene Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The FF-A spec 1.2 reserves the following ranges for identifying FF-A calls: 0x84000060-0x840000FF: FF-A 32-bit calls 0xC4000060-0xC40000FF: FF-A 64-bit calls. Use the range identification according to the spec and allow calls that are currently out of the range(eg. FFA_MSG_SEND_DIRECT_REQ2) to be identified correctly. Acked-by: Will Deacon Signed-off-by: Sebastian Ene Reviewed-by: Sudeep Holla Tested-by: Sudeep Holla --- arch/arm64/kvm/hyp/include/nvhe/ffa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/ffa.h b/arch/arm64/kvm/hyp/inc= lude/nvhe/ffa.h index d9fd5e6c7d3c..146e0aebfa1c 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/ffa.h +++ b/arch/arm64/kvm/hyp/include/nvhe/ffa.h @@ -9,7 +9,7 @@ #include =20 #define FFA_MIN_FUNC_NUM 0x60 -#define FFA_MAX_FUNC_NUM 0x7F +#define FFA_MAX_FUNC_NUM 0xFF =20 int hyp_ffa_init(void *pages); bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id); --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Sat Feb 14 05:39:05 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6BA7156F53 for ; Wed, 15 May 2024 17:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715793800; cv=none; b=dYo3bcG8zVS2T853U2hX8shCviwoa8IObaC99D1G6gcVcf/uwbE9jFOGP3uAY5gx6+YYOcnV01X1a6BjHmBSZoyb3+4qShW7NBIjdJ51t8Ukiv1/20lTDu7tWa5SM6NykiX9VRbEqXoGfJ3Sos2GWOo5DBX5B4+z5IJzRZswb78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715793800; c=relaxed/simple; bh=Mmpk3cTXYb9Cytx2OXyWdNPcR2iwoJfjJ8SD4AaSDlM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fq4HwSpYwBDzzyMI+4UXnOV8b+v8wd5nuBflix6cA7tJqE8hN/UMr3Z+Ev8OCeQMx9UE7gC5h/S4HjY/6YqbhQJP23VvVcmyOYTSsvbVkBVUNQAGQJrE9/w/7ltnlYztvUcWuTvU00ooPOyC2IQw0sO37w2mBDfinzVLi2pPveQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wiVAIdKE; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wiVAIdKE" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-41dc9c831acso38466745e9.0 for ; Wed, 15 May 2024 10:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715793797; x=1716398597; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9HVNMjO2akSMcTTiBfbdxnnFw0wMMSm8FW4gVmT1QRI=; b=wiVAIdKEAU9n4Ac4/Fu8IcH5llGe9EE5a2z71co+UoqlwZDcvuBA2Gs5A61Fz6foGh zTN4bLnrt2piQEAC0dPNQakXyoWTj8uwKJgurnGMLcOasJHMCtJzgdlAlU+v38f1+FwQ pUxQUlwjzkKKnKDd/pYhJEY8kQ12fdMtiI933hQYPESdV6gM2cBGaH+js9EVbmrbWheY xitpRJ9fnvuXR3999B/t6y31n4uKprk7k6JER3+q9W3/HUg/9o+kR0FtsQ9GA//ypb0q N48ZrfTVB727pDNur+gXs8D78iw2vIfpv7a6BQCHePNJlmYg/kOrM1INpGLdC2Uzc5hR AK6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715793797; x=1716398597; 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=9HVNMjO2akSMcTTiBfbdxnnFw0wMMSm8FW4gVmT1QRI=; b=SgSMh2VufTdt5suP4vrdqG96SszpDDlYQcegUzqKrY9f5A/XJkv1fhMGLFWp7+N5LO XhPmc2bk+XEIQ1Uxja0Xs4Lf8IghFYdY0PZ15X7E9Sg6naXTvIg77sm3CYf5BfYAqVAf Pwm1pZx5rfswzQvZv9/mDzfl8mXt7LrxC7L6rO04rtrJSv6NacgnZaYERx02RTb5Y/3x oWsQxYVuFQ0+2mRv/OwesFGgiBdOlHWHW84Iqi1taolaB8pJdK7KDWxPSAqkzcYKJ7T5 ziBvk/6AXyav+OC5Wt37ubZfxDFgvhIs8GF+VWWHt3lZo0NnkpRoEySJTobRpJl1/pA1 umTw== X-Forwarded-Encrypted: i=1; AJvYcCUAQAhE5+8vXRWEah/HgOMFZntpMzD5nzJXu2w1VieiQkqNyHJg1QfGXQohUimZPgh/g3GM81clWkYEr/UrT4mc1n+IMymRrLQVLJ+e X-Gm-Message-State: AOJu0YxOpKsbT/O6NzDs+99m2wzbbZ97Fw7DB42LaViXu0O++xQekK0z FRU+x+1uPEC4m9XozY0SoKg48RXEn6mW4djYFyxOapXs33mWYP2ITpUIZI3YLOMOaA2XvJu95s8 x0G0HfsJjKrJ8Ezbp3xVLj0L/dw== X-Google-Smtp-Source: AGHT+IF2+ZdhABrnKPyUROWJCaWhOUajRbqGLHWL21MZQxT/ip0TW6XIGdVRzaMZh4Ur0gPZC6lIS0u4//WU4M/kut0= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:600c:511d:b0:41e:8c00:94a4 with SMTP id 5b1f17b1804b1-41fead6accamr2395155e9.3.1715793797270; Wed, 15 May 2024 10:23:17 -0700 (PDT) Date: Wed, 15 May 2024 17:22:58 +0000 In-Reply-To: <20240515172258.1680881-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240515172258.1680881-1-sebastianene@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240515172258.1680881-5-sebastianene@google.com> Subject: [PATCH v2 4/4] KVM: arm64: Use FF-A 1.1 with pKVM From: Sebastian Ene To: catalin.marinas@arm.com, james.morse@arm.com, jean-philippe@linaro.org, maz@kernel.org, oliver.upton@linux.dev, qperret@google.com, qwandor@google.com, sudeep.holla@arm.com, suzuki.poulose@arm.com, tabba@google.com, will@kernel.org, yuzenghui@huawei.com, lpieralisi@kernel.org Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Sebastian Ene Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the layout of the structures is compatible with 1.1 it is time to probe the 1.1 version of the FF-A protocol inside the hypervisor. If the TEE doesn't support it, it should return the minimum supported version. Signed-off-by: Sebastian Ene Reviewed-by: Sudeep Holla Tested-by: Sudeep Holla --- arch/arm64/kvm/hyp/nvhe/ffa.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index f9664c4a348e..bdd70eb4114e 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -458,7 +458,7 @@ static __always_inline void do_ffa_mem_xfer(const u64 f= unc_id, memcpy(buf, host_buffers.tx, fraglen); =20 ep_mem_access =3D (void *)buf + - ffa_mem_desc_offset(buf, 0, FFA_VERSION_1_0); + ffa_mem_desc_offset(buf, 0, hyp_ffa_version); offset =3D ep_mem_access->composite_off; if (!offset || buf->ep_count !=3D 1 || buf->sender_id !=3D HOST_FFA_ID) { ret =3D FFA_RET_INVALID_PARAMETERS; @@ -537,7 +537,7 @@ static void do_ffa_mem_reclaim(struct arm_smccc_res *re= s, fraglen =3D res->a2; =20 ep_mem_access =3D (void *)buf + - ffa_mem_desc_offset(buf, 0, FFA_VERSION_1_0); + ffa_mem_desc_offset(buf, 0, hyp_ffa_version); offset =3D ep_mem_access->composite_off; /* * We can trust the SPMD to get this right, but let's at least @@ -846,7 +846,7 @@ int hyp_ffa_init(void *pages) if (kvm_host_psci_config.smccc_version < ARM_SMCCC_VERSION_1_2) return 0; =20 - arm_smccc_1_1_smc(FFA_VERSION, FFA_VERSION_1_0, 0, 0, 0, 0, 0, 0, &res); + arm_smccc_1_1_smc(FFA_VERSION, FFA_VERSION_1_1, 0, 0, 0, 0, 0, 0, &res); if (res.a0 =3D=3D FFA_RET_NOT_SUPPORTED) return 0; =20 @@ -866,7 +866,11 @@ int hyp_ffa_init(void *pages) if (FFA_MAJOR_VERSION(res.a0) !=3D 1) return -EOPNOTSUPP; =20 - hyp_ffa_version =3D FFA_VERSION_1_0; + if (FFA_MINOR_VERSION(res.a0) < FFA_MINOR_VERSION(FFA_VERSION_1_1)) + hyp_ffa_version =3D res.a0; + else + hyp_ffa_version =3D FFA_VERSION_1_1; + tx =3D pages; pages +=3D KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE; rx =3D pages; --=20 2.45.0.rc1.225.g2a3ae87e7f-goog