From nobody Sun Feb 8 05:23:43 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 81A7225B68E for ; Wed, 26 Feb 2025 21:49:01 +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=1740606543; cv=none; b=lyUQRu+xu9+to/AUXqiT0t9KgmsYDp04WZdbjuWCfo42L6JAW8qBQ0ckA2iVQRFImzTDrwVEMf1nu2kEnuifYx1BKFvOksmCBbxQx11oZD0zyQvZBGNlmVNa+P1DEJMS20kUVLzBdko0UVIDZz4eLOJfm9VgBMsG8GWtIj9emS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740606543; c=relaxed/simple; bh=susFi+HTLhMiXge6xuA23CvYjFDj7xjmElPFv39hxTo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RShsqSqj7sQutDqDkE2Qxol1Wyrx86aRWtxblKsdrV+plw2XRj/2+jyR4ShOhi+pf7NqBLCNKORbIZBYtMfz+qTJFDrGbXC/PQcCIa1StwntAlGLveLeGavXFaavS/oI79n3O/PO6APa/K+ZeNenCN2etQ7NCmMFJY+otGmYu/I= 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=tHcyn65e; 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="tHcyn65e" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-43988b9ecfbso1370045e9.0 for ; Wed, 26 Feb 2025 13:49:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740606540; x=1741211340; 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=xEVZ05L77YjD9i0FV4RPZx+ynfSX0ZTLa/fS8nUdHrQ=; b=tHcyn65ebxji3ikCnYH96DlI/1KrDmqtsRvWB1DMvWty77T7zbytZug9a6UhwBi9O6 c4CAfOMMEg9XkAlmd09a2iTV99ggmHZUvbKm2suzWHkx/KpYGI9ae57VMaTpaZ+l6Xj0 65lLHWyOF2RNb4E7zzju52whITRleXN3SWuz/NG8S1MxdCZd5o7woN0UvW0JrSDFc+Fv zXFwU2NHgWWkBrgNMJEsn64TtllSXfK4zZ0VYZvmVp2i7YGDwngZWEFDum5KJzTxEJzz mERhWLme9jnp5rj48UQNoyHuePF7URzAavkucMjosC3EJqHW5iQW8bNH+62dLkHpguHb 8vIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740606540; x=1741211340; 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=xEVZ05L77YjD9i0FV4RPZx+ynfSX0ZTLa/fS8nUdHrQ=; b=ChLvKWzSs6AUA2i3h2yIiEY1VbWRAD9wFSEA7LBqkwem3gbE/LkySnJHlfoLCkxWRr Q8fGnVvzpjP5CnSRgW+dxmEBCpDD4hS/onq57C5g8T5fVaRzqzGxFwq7O7sjAOJQk9zP 6NULlVGw3Jn/mEBRQotAw81FCJI8It5/jAj6eFIJXH87MMSb6XWsFnlSttfbFeBl5D0c bZWk1oDdaYrQCJjkEtnZbNYGtZtKXIC88Qyo2Pi3M+W7Iu2pSmY7HF15Uim6rZRhhFAb NVYhoR9JlTmZb33vBTtOHaR9SCbXBtub+t9fsnmvxhqgIn8vaOT6JHZByLfTqtnHUAzJ pmAA== X-Forwarded-Encrypted: i=1; AJvYcCUN6pc4dBw1yP8F6lPQJhSTx0nLJwyimw5nTkVOZyT4Mp9PiVdV5gYbsy1EoAGwFVEXzF2gJGdOICj+0B8=@vger.kernel.org X-Gm-Message-State: AOJu0YyKokOmjqTfL2hiHQqXb4/QIFHYZoedckDqVzejr45b8GKWAVEl Gvgbz2e5/g+t8ElSW7lEZSGg8EY6fQ4RDfcB9vipiksJG0Cc9Co05AZEg/w4ngVQMyFaPaI3xfM L+XZtv/Dsd3mjqeYS2znSU7o/cQ== X-Google-Smtp-Source: AGHT+IHPl9CpNA4ye6HGWodohtg7w7nq3kIEmHB83VCNwiFw4/jBDdSe7IDZ/dv5OLUf4FF1pq99Aao3VGjq0FuCrDU= X-Received: from wmbfl9.prod.google.com ([2002:a05:600c:b89:b0:439:9985:3882]) (user=sebastianene job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:19d1:b0:439:9225:2f50 with SMTP id 5b1f17b1804b1-43ab8fe957dmr50990375e9.16.1740606540005; Wed, 26 Feb 2025 13:49:00 -0800 (PST) Date: Wed, 26 Feb 2025 21:48:51 +0000 In-Reply-To: <20250226214853.3267057-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: <20250226214853.3267057-1-sebastianene@google.com> X-Mailer: git-send-email 2.48.1.658.g4767266eb4-goog Message-ID: <20250226214853.3267057-2-sebastianene@google.com> Subject: [PATCH 1/3] KVM: arm64: Use the static initializer for the vesion lock From: Sebastian Ene To: catalin.marinas@arm.com, joey.gouly@arm.com, maz@kernel.org, oliver.upton@linux.dev, sebastianene@google.com, snehalreddy@google.com, sudeep.holla@arm.com, suzuki.poulose@arm.com, vdonnefort@google.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the definition of the hypervisor version lock with a static initializer. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/hyp/nvhe/ffa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index e433dfab882a..6df6131f1107 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -69,7 +69,7 @@ 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; +static DEFINE_HYP_SPINLOCK(version_lock); =20 static void ffa_to_smccc_error(struct arm_smccc_res *res, u64 ffa_errno) { @@ -911,6 +911,5 @@ int hyp_ffa_init(void *pages) .lock =3D __HYP_SPIN_LOCK_UNLOCKED, }; =20 - version_lock =3D __HYP_SPIN_LOCK_UNLOCKED; return 0; } --=20 2.48.1.658.g4767266eb4-goog From nobody Sun Feb 8 05:23:43 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 92FF425E47B for ; Wed, 26 Feb 2025 21:49:03 +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=1740606545; cv=none; b=c+9azNy9Dv1e1sndnSEDumOwmnbH5XlzHTBiQFuWFPyfvnOyplRSukh1NrTfap6IMapL8yKu9WlUGx76P3WnJL69HH8mGzkRQ7HgjPKXJExl5RUHXUcM8Qet3bmsBOw0KIhQI6e9+zLETjXJyVLI0klZ+javBMIjbie34ws8WjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740606545; c=relaxed/simple; bh=AJ0aL67MNMHWLCnIV5QRMRwoPhcRZaFh4TPbk9b014Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GRk/Al1Crz6f8vDnLWIgT0PJWhP/SiIa4Gey2w6x/mzSk2efBij5HJKNnTK2sV0cqbj5TEHejt5xcMywXgBM0yC0v0s5NA6PCIj5IlUPfL6/RVPuMcDXCHR5gCxv7mvuK4Lo2wUWeTiNifsB4SDcB4FfRBkBJvie9pJWHxsY378= 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=GOskMSO/; 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="GOskMSO/" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-438e180821aso1343785e9.1 for ; Wed, 26 Feb 2025 13:49:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740606542; x=1741211342; 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=nn7NkfdNisHNgNHd+oe9siIm1ilJ5hL+n/oLHca/4xQ=; b=GOskMSO/0/aC9zQyDb3NI7mtJqzW+ShO+os+PbfDrGad8l/GghuUs6J9dHjRkXW6Mk APfFz9RBX0+w/aMJjtzEDSQYVMGfH1FaTBMCzR6NHcZZJzYXGQcUIsgJR8n6t0Ve0PXA ERL7Ql5H8/khSqcqLQYzlDR3DmujLBk3bCVabt9O5HroaoUyMAuFEOlG1BbiPG/5dvbz i/5/RfD0cDRjihK5dBmiGACv9fn8/bUxBcvpXKU47ErIf7KQLJ1AYyHhDdEB7v8KlUtD 8rUU6In1jUaaCunn4Ke6b/pgYFnAFahqfYSRVEYW7w87iRHwOrQ5FwnCVhHrWFW64ytW rwng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740606542; x=1741211342; 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=nn7NkfdNisHNgNHd+oe9siIm1ilJ5hL+n/oLHca/4xQ=; b=Ti06gYUDFcCTTNtXDPgCMuxYzzeK21mxX7qPSHQ8Dd/lDCEScT2HDQiGXEV1yxPIlR 0dZHyz4I2SeaeOtBdSswF69MJ1E/KNeErKzgLyUjwef2bESdzA+pY3+9Pw9PfCzevpxq 046f5ioLzt/NiNwO7pMoXdHc3a+KgJLuuQI0SJDjfgzT0YyVPGlnNj9KOwJWn/89Qs3g z1RAoDQeetxpiWfCsXt+FilifzEZl6u6IiB5H60dcdqQtAiELb8RGsQE7JEAGvN/uxtU DizP9/b9WdGay3fipI6dxY6p8KgWJLQO5BIzV6DIR54JcrDBgi6gdyCsZquBK32n49tB sABQ== X-Forwarded-Encrypted: i=1; AJvYcCXGoa86CeOi7nhgNobLXf2aTO+woq/BIG2T7hRBekK4RB/KY7qNyAhBQWPRJ9WNDIyOhME5izz5bQJZmwY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywr88VkNNL9TEoLWGyqquG/QD+p6LpUk3hD0xtfzppJZJsLHVBA +9kS5rUQ+BI6uLxY2eiwXZmT7N25HVJTZwwX6IJt88xuX4Vfg1QXMuxusTIukIcFn9AZ0KoXqRh SnMaHVKA6Nbq9oSJnqnbbYprS9g== X-Google-Smtp-Source: AGHT+IHCoOc2i86YMCnuvttEGcDUZYoM+8yWhiEKuZWCun/eyz4ldBIl5B6mMe4Xqk2ObldseXeE2fv9uBC+67uQ47I= X-Received: from wmbgw7.prod.google.com ([2002:a05:600c:8507:b0:439:4293:c575]) (user=sebastianene job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3111:b0:439:9f42:c137 with SMTP id 5b1f17b1804b1-43ab0f31010mr85525335e9.11.1740606542287; Wed, 26 Feb 2025 13:49:02 -0800 (PST) Date: Wed, 26 Feb 2025 21:48:52 +0000 In-Reply-To: <20250226214853.3267057-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: <20250226214853.3267057-1-sebastianene@google.com> X-Mailer: git-send-email 2.48.1.658.g4767266eb4-goog Message-ID: <20250226214853.3267057-3-sebastianene@google.com> Subject: [PATCH 2/3] KVM: arm64: Map the hypervisor FF-A buffers on ffa init From: Sebastian Ene To: catalin.marinas@arm.com, joey.gouly@arm.com, maz@kernel.org, oliver.upton@linux.dev, sebastianene@google.com, snehalreddy@google.com, sudeep.holla@arm.com, suzuki.poulose@arm.com, vdonnefort@google.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Map the hypervisor's buffers irrespective to the host and return a linux error code from the FF-A error code on failure. Remove the unmap ff-a buffers calls from the hypervisor as it will never be called and move the definition of the ffa_to_linux_error map in the header where it should belong to. Prevent the host from using FF-A if the hypervisor could not map its own buffers with Trustzone. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/hyp/nvhe/ffa.c | 46 ++++++++++++------------------- drivers/firmware/arm_ffa/driver.c | 24 ---------------- include/linux/arm_ffa.h | 24 ++++++++++++++++ 3 files changed, 41 insertions(+), 53 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 6df6131f1107..861f24de97cb 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -69,6 +69,7 @@ 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 bool has_ffa_supported; static DEFINE_HYP_SPINLOCK(version_lock); =20 static void ffa_to_smccc_error(struct arm_smccc_res *res, u64 ffa_errno) @@ -111,30 +112,18 @@ static bool is_ffa_call(u64 func_id) ARM_SMCCC_FUNC_NUM(func_id) <=3D FFA_MAX_FUNC_NUM; } =20 -static int ffa_map_hyp_buffers(u64 ffa_page_count) +static int ffa_map_hyp_buffers(void) { struct arm_smccc_res res; =20 arm_smccc_1_1_smc(FFA_FN64_RXTX_MAP, hyp_virt_to_phys(hyp_buffers.tx), hyp_virt_to_phys(hyp_buffers.rx), - ffa_page_count, + KVM_FFA_MBOX_NR_PAGES, 0, 0, 0, 0, &res); =20 - return res.a0 =3D=3D FFA_SUCCESS ? FFA_RET_SUCCESS : res.a2; -} - -static int ffa_unmap_hyp_buffers(void) -{ - struct arm_smccc_res res; - - arm_smccc_1_1_smc(FFA_RXTX_UNMAP, - HOST_FFA_ID, - 0, 0, 0, 0, 0, 0, - &res); - - return res.a0 =3D=3D FFA_SUCCESS ? FFA_RET_SUCCESS : res.a2; + return res.a0 =3D=3D FFA_SUCCESS ? 0 : ffa_to_linux_errno(res.a2); } =20 static void ffa_mem_frag_tx(struct arm_smccc_res *res, u32 handle_lo, @@ -213,18 +202,10 @@ static void do_ffa_rxtx_map(struct arm_smccc_res *res, goto out_unlock; } =20 - /* - * Map our hypervisor buffers into the SPMD before mapping and - * pinning the host buffers in our own address space. - */ - ret =3D ffa_map_hyp_buffers(npages); - if (ret) - goto out_unlock; - ret =3D __pkvm_host_share_hyp(hyp_phys_to_pfn(tx)); if (ret) { ret =3D FFA_RET_INVALID_PARAMETERS; - goto err_unmap; + goto out_unlock; } =20 ret =3D __pkvm_host_share_hyp(hyp_phys_to_pfn(rx)); @@ -262,8 +243,6 @@ static void do_ffa_rxtx_map(struct arm_smccc_res *res, __pkvm_host_unshare_hyp(hyp_phys_to_pfn(rx)); err_unshare_tx: __pkvm_host_unshare_hyp(hyp_phys_to_pfn(tx)); -err_unmap: - ffa_unmap_hyp_buffers(); goto out_unlock; } =20 @@ -291,9 +270,6 @@ static void do_ffa_rxtx_unmap(struct arm_smccc_res *res, hyp_unpin_shared_mem(host_buffers.rx, host_buffers.rx + 1); WARN_ON(__pkvm_host_unshare_hyp(hyp_virt_to_pfn(host_buffers.rx))); host_buffers.rx =3D NULL; - - ffa_unmap_hyp_buffers(); - out_unlock: hyp_spin_unlock(&host_buffers.lock); out: @@ -809,6 +785,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_ffa_supported) { + ffa_to_smccc_error(&res, FFA_RET_NOT_SUPPORTED); + goto out_handled; + } + if (!has_version_negotiated && func_id !=3D FFA_VERSION) { ffa_to_smccc_error(&res, FFA_RET_INVALID_PARAMETERS); goto out_handled; @@ -861,6 +842,7 @@ int hyp_ffa_init(void *pages) { struct arm_smccc_res res; void *tx, *rx; + int ret; =20 if (kvm_host_psci_config.smccc_version < ARM_SMCCC_VERSION_1_2) return 0; @@ -911,5 +893,11 @@ int hyp_ffa_init(void *pages) .lock =3D __HYP_SPIN_LOCK_UNLOCKED, }; =20 + /* Map our hypervisor buffers into the SPMD */ + ret =3D ffa_map_hyp_buffers(); + if (ret) + return ret; + + has_ffa_supported =3D true; return 0; } diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/d= river.c index 2c2ec3c35f15..b02b80f3dfe8 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -61,30 +61,6 @@ =20 static ffa_fn *invoke_ffa_fn; =20 -static const int ffa_linux_errmap[] =3D { - /* better than switch case as long as return value is continuous */ - 0, /* FFA_RET_SUCCESS */ - -EOPNOTSUPP, /* FFA_RET_NOT_SUPPORTED */ - -EINVAL, /* FFA_RET_INVALID_PARAMETERS */ - -ENOMEM, /* FFA_RET_NO_MEMORY */ - -EBUSY, /* FFA_RET_BUSY */ - -EINTR, /* FFA_RET_INTERRUPTED */ - -EACCES, /* FFA_RET_DENIED */ - -EAGAIN, /* FFA_RET_RETRY */ - -ECANCELED, /* FFA_RET_ABORTED */ - -ENODATA, /* FFA_RET_NO_DATA */ - -EAGAIN, /* FFA_RET_NOT_READY */ -}; - -static inline int ffa_to_linux_errno(int errno) -{ - int err_idx =3D -errno; - - if (err_idx >=3D 0 && err_idx < ARRAY_SIZE(ffa_linux_errmap)) - return ffa_linux_errmap[err_idx]; - return -EINVAL; -} - struct ffa_pcpu_irq { struct ffa_drv_info *info; }; diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 74169dd0f659..850577edadbc 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -475,4 +475,28 @@ struct ffa_ops { const struct ffa_notifier_ops *notifier_ops; }; =20 +static const int ffa_linux_errmap[] =3D { + /* better than switch case as long as return value is continuous */ + 0, /* FFA_RET_SUCCESS */ + -EOPNOTSUPP, /* FFA_RET_NOT_SUPPORTED */ + -EINVAL, /* FFA_RET_INVALID_PARAMETERS */ + -ENOMEM, /* FFA_RET_NO_MEMORY */ + -EBUSY, /* FFA_RET_BUSY */ + -EINTR, /* FFA_RET_INTERRUPTED */ + -EACCES, /* FFA_RET_DENIED */ + -EAGAIN, /* FFA_RET_RETRY */ + -ECANCELED, /* FFA_RET_ABORTED */ + -ENODATA, /* FFA_RET_NO_DATA */ + -EAGAIN, /* FFA_RET_NOT_READY */ +}; + +static inline int ffa_to_linux_errno(int errno) +{ + int err_idx =3D -errno; + + if (err_idx >=3D 0 && err_idx < ARRAY_SIZE(ffa_linux_errmap)) + return ffa_linux_errmap[err_idx]; + return -EINVAL; +} + #endif /* _LINUX_ARM_FFA_H */ --=20 2.48.1.658.g4767266eb4-goog From nobody Sun Feb 8 05:23:43 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 D12D226138F for ; Wed, 26 Feb 2025 21:49:05 +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=1740606547; cv=none; b=Nlv+qAvsjJLaxtifYhALL769bJl1hLca5esRqyu0OZ+u3lPxLkBIG4d+jYBPod8JzGF7a+v2MT1I0T/oMzrtWAfCoIgQHzUpI/xHzhowRLWU52Fwny++X0uSk5IHxI0RN4YMlXqY4hN9f8fwmg/dGEeNFZMcX4z/90Foy/Z1C+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740606547; c=relaxed/simple; bh=FR9O3f+FzonphJjEwi5+VpVYgFi8WH7raVXQy1pKg8k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZjCtJo3FELf5gYkFvHjsR6rRanI0ZfRWfhchC1acUMSEmIayn3y8AtApaRlZtThLf4bBIeuwzRcB32aiOh0sWzM6cyNBF8qJA/0bAT016LN1i3NgiXC9VyGRO1trO4t3jm6YU/JV38c1Dd468yTAITuDBkOWKfsk/lxMLFJwHT8= 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=qX71ExfZ; 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="qX71ExfZ" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-43935e09897so2402135e9.1 for ; Wed, 26 Feb 2025 13:49:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740606544; x=1741211344; 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=jElUUP1cXmmGkWA/+GnRTo6wT5X97muVU936DPVGfcc=; b=qX71ExfZTBV8I/aFvcOXedPbP5Pf5eeQk6T1G80T5a77tbviN2R87Ujk7k8YDt2kOA jRRceCrYJwQASrn39vYnvqBQ7m1NgACpbY8I3lb7Yt7OMeOhPauRGJ09AoyfjYYLnUSc 3uuapTk6fWJxlsUxhoId+5PKUgnF4R20PU8MiQuzXHbsFThaBCSIqOuBmLGGiMHwvfOk mFdk4hhwmLqpUPFvxIyzJnS2FSHRe+bwZGToS35nrSDY4EcvoylE3bcIkzyULJHJD07I q+QWos5+DAnzhwD2DfTnF5d5WIZ9F0FXnx/g6UV/Q+nyKE0iy1HZj4/ZgIr03PYIXUQx cF2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740606544; x=1741211344; 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=jElUUP1cXmmGkWA/+GnRTo6wT5X97muVU936DPVGfcc=; b=KpDGuhJdnsibd9rjquRw00nbAzek9eometHyIL+OusXh7itpFv9BTkC7vSGOZOpWLg h/qX7vrvOQjfk3FB7hjUWq0rb46f2Kz0nMz2NstNg+YgVDjTkj7q5jg5AMYH9PcDDo3h f8VIuyRRDvfpT4xo3qn5oHSLNuz7ft2OrBPUhTdHE92nAd9Cuwwr9SHLI95eGBl+RViY UBxCYofPL61DCTZlVdjS/qJcRmJhrVljGkvSiDjiEil4CSrMlxcnCsFnssnFfbnHTMsI iqyu+4nNubZDRvibtpf3yQAruLF2eDoTLqNxxLN0aqbaav4WZBnRRWPiGOjUfVsBB0jA 4AUQ== X-Forwarded-Encrypted: i=1; AJvYcCXA+QPKhFHmG1+5oNYGd2RHAeO1K+7BmkLzd9a0s5aL76FM2wARUAvQPcuNGr04n6DjoIquCvslJC5sWuI=@vger.kernel.org X-Gm-Message-State: AOJu0YyDjhVNR08JEBbkl+qTaRCeuxbrnOafZbxhUVNiEwO/Uz8zK58g KKjttDtTyTa2OFKOU8WbD3LQcT5HDrfb0204x9x+ybzRcDwPKVDlbt82FmvFgzwPmQreqoUoAwZ 5ewXYGsDaCqZ7cW+ui6QfsXSSAA== X-Google-Smtp-Source: AGHT+IFMNilNm63tpaGE1Thx+63/zfmAmfVfjbx1vaV84Aa8shwCpD7h0mmGQaUHETfocmAdjgNyNEVh/DYceyRboA4= X-Received: from wmbfm16.prod.google.com ([2002:a05:600c:c10:b0:439:850b:8080]) (user=sebastianene job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3506:b0:439:6dba:adf2 with SMTP id 5b1f17b1804b1-43ab8fe7734mr46217465e9.15.1740606544357; Wed, 26 Feb 2025 13:49:04 -0800 (PST) Date: Wed, 26 Feb 2025 21:48:53 +0000 In-Reply-To: <20250226214853.3267057-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: <20250226214853.3267057-1-sebastianene@google.com> X-Mailer: git-send-email 2.48.1.658.g4767266eb4-goog Message-ID: <20250226214853.3267057-4-sebastianene@google.com> Subject: [PATCH 3/3] KVM: arm64: Release the ownership of the hyp rx buffer to Trustzone From: Sebastian Ene To: catalin.marinas@arm.com, joey.gouly@arm.com, maz@kernel.org, oliver.upton@linux.dev, sebastianene@google.com, snehalreddy@google.com, sudeep.holla@arm.com, suzuki.poulose@arm.com, vdonnefort@google.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Andrei Homescu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce the release FF-A call to notify Trustzone that the hypervisor has finished copying the data from the buffer shared with Trustzone to the non-secure partition. Reported-by: Andrei Homescu Signed-off-by: Sebastian Ene --- arch/arm64/kvm/hyp/nvhe/ffa.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 861f24de97cb..7da0203f1ee9 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -725,6 +725,7 @@ static void do_ffa_part_get(struct arm_smccc_res *res, DECLARE_REG(u32, uuid3, ctxt, 4); DECLARE_REG(u32, flags, ctxt, 5); u32 count, partition_sz, copy_sz; + struct arm_smccc_res _res; =20 hyp_spin_lock(&host_buffers.lock); if (!host_buffers.rx) { @@ -741,7 +742,7 @@ static void do_ffa_part_get(struct arm_smccc_res *res, =20 count =3D res->a2; if (!count) - goto out_unlock; + goto release_rx; =20 if (hyp_ffa_version > FFA_VERSION_1_0) { /* Get the number of partitions deployed in the system */ @@ -757,10 +758,12 @@ static void do_ffa_part_get(struct arm_smccc_res *res, 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; + goto release_rx; } =20 memcpy(host_buffers.rx, hyp_buffers.rx, copy_sz); +release_rx: + ffa_rx_release(&_res); out_unlock: hyp_spin_unlock(&host_buffers.lock); } --=20 2.48.1.658.g4767266eb4-goog