From nobody Thu Sep 24 19:28:54 2026 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (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 202EF4DEC37 for ; Mon, 21 Sep 2026 16:48:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790009290; cv=none; b=iGzB/yK/SXIDJr7A0orteXCg9CARsUeeNF/aa811whhmV1xNWasoyIOrEE7hfWqSeHbGBC/QnVm5/7se8AqapOJgDH/9ygF400gCO8wSwnWWTFkwo06sfxXdv+b7qOOd+5CWIAMX2TnLIz0S/RXYAUPKp2Pswbs0xMLYsR0T830= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790009290; c=relaxed/simple; bh=Tv2EYCjkKjWE0I+S4Qhzl4FRcnMQDBTtZC0liA4U2PE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VNqwWIn3KTIs7wYMwC9I9NGKq88zGXhP+PIOaPoUI4DCBoHmRx9DcTZkFLrzjFByWaLAC9/DhcMe+V/H+dx9/+bDvb+nRr0eVZs1azREAowAsipPc3wpUpFAEOfsg+BXZtIu6lvUUvBNc52RXfLYVcf/uK/G/09l+o5+O2qEQkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--snehalreddy.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nkK22faf; arc=none smtp.client-ip=209.85.128.70 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--snehalreddy.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nkK22faf" Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-49e735659b7so26463475e9.3 for ; Mon, 21 Sep 2026 09:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790009287; x=1790614087; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FMNXFwmnx5s7vUZ96ZeGip3cvNMdnWK8inpODzkfR5o=; b=nkK22fafC+7jAZ7qMjTSpqZ4cgRoptozn56cjpvXOANJo7nlUH4KAtsiNH1gO3Znvw FaX4u8lB5xD4WIW/Mhfm1BZprVzPtoVwYS45+RR4lnSb40jc2NaFyOhLspxgmdgcWP2G 2QwCnVnZjoFnqbnS1vIsAmiGRF88JICNSWwtBOuIgYgknUYfm/6L/dDUjiLVhT0jKCcd +JpI8xMvFY28lo4mb29Y5+GuTtcLt71dmzuknpvVTAdBkjEMha9kvFF76T65saFpErTD MVZseOaT4hPSxhT+ZJpmAqCL1icte906lQbEsBN7s5zYrXLPMAfjvohc8Unx+nA+f3tH R7cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790009287; x=1790614087; h=content-type: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:content-type; bh=FMNXFwmnx5s7vUZ96ZeGip3cvNMdnWK8inpODzkfR5o=; b=U7MgzXmJA//rWBm5Ext7Bw542GS41+kqz47qoHNTIdXlfk4uQMV8Gm4zJsHM7RgrVj HwKONIHcwD7BTZ+q1p/1oCHvgtxe2SYl//DlzmtuH+nz8F8ztWcufiKlctE+nTN+L+kU WEWB7qNF2kwtv4TiHgOFOb0jLDORB71HGkmIQ9j9UKSWsK0ODd9YpQUoR3mmow+X5bYi N4IaVGgIR8ry8JoqSzYGVhxgdgMy2ZX2u0PSkTb/eVrjPustlgbm3125Ivwxr799rmWH hANW4shM/kRG3zFwqnC5EXs3N1c4B4/d5Fp6ifm5IOvyNBEhu+6jIDQBSiizjOH93UUh JGwA== X-Forwarded-Encrypted: i=1; AKwUvBxOAEgFnFTQsM4JFnxuaTR6g60ZhhIgh5E77TOGIPzZj6tN5mzYNmLsK+6wEzAMxyuqXQdTHg1gxt8U0XI=@vger.kernel.org X-Gm-Message-State: AFuF++l6kAHOk39Zi+cCS/wDsmS88YpFqQZwhvjlWjCCXetu5QWB8y3X pqy578fy5Gmw/huz/HEPg2xYNxv5A3BYH+TwBxpk7+TX2tdTSaIFLIeIvdDAWIKg+nHcYbJEf4q oV9yvklTn6+mQCzNLlozDxhrizg== X-Received: from wmber9.prod.google.com ([2002:a05:600c:84c9:b0:499:b8f0:3186]) (user=snehalreddy job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:314a:b0:49f:ce73:7aa with SMTP id 5b1f17b1804b1-49fce730865mr103151975e9.35.1790009286746; Mon, 21 Sep 2026 09:48:06 -0700 (PDT) Date: Mon, 21 Sep 2026 16:47:47 +0000 In-Reply-To: <20260921164748.2958578-1-snehalreddy@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260921164748.2958578-1-snehalreddy@google.com> X-Mailer: git-send-email 2.55.0.1082.g2b9226bbc0-goog Message-ID: <20260921164748.2958578-2-snehalreddy@google.com> Subject: [PATCH 1/2] firmware: arm_ffa: Add FFA_FN64_MEM_RECLAIM2 function ID From: Snehal Koukuntla To: Marc Zyngier , Oliver Upton , Catalin Marinas , Will Deacon , Sudeep Holla Cc: Vincent Donnefort , Fuad Tabba , Joey Gouly , Suzuki K Poulose , Mark Rutland , Sebastian Ene , Mostafa Saleh , Snehal Koukuntla , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" FF-A v1.3 ALP5 (DEN0140 rev J) introduces the optional FFA_MEM_RECLAIM2 (0xC4000091) ABI, which enables an Owner to reclaim exclusive access to a subset of pages of a memory region without requiring the Relayer to maintain intermediate transaction state. Add the FFA_FN64_MEM_RECLAIM2 function ID definition to arm_ffa.h. Link: https://support.arm.com/documentation/den0140/j Signed-off-by: Snehal Koukuntla --- include/linux/arm_ffa.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index e71d83ee0aef..c78cfd72832a 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -78,6 +78,7 @@ #define FFA_EL3_INTR_HANDLE FFA_SMC_32(0x8C) #define FFA_MSG_SEND_DIRECT_REQ2 FFA_SMC_64(0x8D) #define FFA_MSG_SEND_DIRECT_RESP2 FFA_SMC_64(0x8E) +#define FFA_FN64_MEM_RECLAIM2 FFA_SMC_64(0x91) =20 /* * For some calls it is necessary to use SMC64 to pass or return 64-bit va= lues. --=20 2.55.0.1082.g2b9226bbc0-goog From nobody Thu Sep 24 19:28:54 2026 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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 467C64D7954 for ; Mon, 21 Sep 2026 16:48:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790009299; cv=none; b=okO9WFjYoEHr28K9XyYPQhfa4Xz3bv6gDzEE9p76hCx212MJBd4DqvSGIWGyUvdAsFqPT2nuRv/LPlnZWMKNLJrTlG4D0BjvxX+fBEZTqH0mLUxHHO5gazHu1iPDq5vVmavV5Pd4pjvk2dhikkxG+3rm0J78IO5n+vnIP18nLJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790009299; c=relaxed/simple; bh=E9l9/OzmnC+8t7QEGgstq55nV1kKkLSE68Bl7z3n0+8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XCgc3PBN27TjRQRtNqq8W4Nfhldx70UfV5fzdijL2PLpUH65Le+Bc9N/rlhHheSbY0jMELMQ/GSk1A2e0g6q343rO62isnvWPZbs3YUwbKIvGxClsbJZG2mUlr7s909Hd/OLENqYzglx+jAgm0Up9anId2m1Ow9U+xp2zmf+6jA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--snehalreddy.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IYtlezYo; arc=none smtp.client-ip=209.85.128.71 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--snehalreddy.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IYtlezYo" Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-49cdc4080ddso512815e9.1 for ; Mon, 21 Sep 2026 09:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790009295; x=1790614095; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SRMphI5T1L64WHuwz6aodMyAcWwTtLqR1TEhwEfUsrw=; b=IYtlezYoh8/RA62BjJXblt5gMAtrV+N94v0bpCpEHVuVyhLkB9eTd4y8xIVqOE+RBn 97jN/boSNFkpfIYeaG35xvuTmIYJOGqPU/WEEff/589hxp/4C4lfa79eVeen8om7VHIh 9styZ6mbPKfDbSPD0Exe9DMyAOt52gPzDlfJmYDKzIQUl4YEhym5Y0s/d9nf/jS26Zxk W10ow6wFiPazW7sRV2FRIr6ntdkkmyw/YiP7Aqzx9P5WCOFB1ESiKZk9XVpPGj7CU4/G nsuMssMD5xmMYLSWZ3EWTNGnltcjoNdNzBX03yMOiVxltoA0dnIU0esfHHJUeqjnVMRW VVSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790009295; x=1790614095; h=content-type: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:content-type; bh=SRMphI5T1L64WHuwz6aodMyAcWwTtLqR1TEhwEfUsrw=; b=ItlXhZ1lDKS32kY9g7TgR9PkRIBkIrKFUhwkiVK8hyHiOMtwBF6f4m+eWgTYm3rXM8 M/btb1miJnVgXYOKb1Z03+j2RQxK10n6pjxGPSdss5jUK9SfyLAkPQtUJ3xOLtNJtrwi HCwkZO8TEIbTJZ42jEVn8SlCtnmCbnSqNIbSV77M95md5lHD0atdGaBa7dR/Dtasz4ie IWKuPix+yMz6LeoIJ5UKM1G0VRbrQYH2xhOML7ixQ1ttDZrFlGWuzvfiXEHhsMl5YlLp RW95CoI5m2qJ614K+mdWzpNvThmp/EXoAi7l5VHEbS/IYl9Aj/LNAW0759TZ0dkC9WBC E0+g== X-Forwarded-Encrypted: i=1; AKwUvByVG9t92a4su+RmGGUN7NY7HNSYx3Mo6NCe3wQ3yvztVRDAwnEXzKzAwPIn88yMGox5WmZFgtf4CQcN1Wc=@vger.kernel.org X-Gm-Message-State: AFuF++naUjXUFiOmZzYrw395XHd+kfU1pFPy+rJvp36U8MQUhLKXi8HJ MQ9QyqBWMQeXa+x/mgnS9szVWS8dIdLA2S7G1bPXWLa57Ec3MnO5Ueor+u+zKAbxFvozMmUsgfy nlfnn4KwLoTnMV2zd3C8ZPUj0nw== X-Received: from wrbfm9.prod.google.com ([2002:a05:6000:2809:b0:488:5e25:c0aa]) (user=snehalreddy job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600d:4443:20b0:49f:bb49:9cca with SMTP id 5b1f17b1804b1-49fd883ccd1mr3241865e9.5.1790009295199; Mon, 21 Sep 2026 09:48:15 -0700 (PDT) Date: Mon, 21 Sep 2026 16:47:48 +0000 In-Reply-To: <20260921164748.2958578-1-snehalreddy@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260921164748.2958578-1-snehalreddy@google.com> X-Mailer: git-send-email 2.55.0.1082.g2b9226bbc0-goog Message-ID: <20260921164748.2958578-3-snehalreddy@google.com> Subject: [PATCH 2/2] KVM: arm64: Support FFA_FN64_MEM_RECLAIM2 in host handler From: Snehal Koukuntla To: Marc Zyngier , Oliver Upton , Catalin Marinas , Will Deacon , Sudeep Holla Cc: Vincent Donnefort , Fuad Tabba , Joey Gouly , Suzuki K Poulose , Mark Rutland , Sebastian Ene , Mostafa Saleh , Snehal Koukuntla , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" FF-A v1.3 ALP5 (DEN0140 rev J) adds the FFA_MEM_RECLAIM2 interface, allowing an Owner to reclaim a subset of pages from a shared or lent memory region by populating constituent memory region descriptors in its TX buffer along with a starting descriptor byte offset and initial page index. Upon completion, the Relayer returns the number of 4K pages reclaimed in x3. Support FFA_FN64_MEM_RECLAIM2 in the host FF-A proxy handler. Validate the register arguments, descriptor bounds, and initial page index against the host TX buffer before forwarding the SMC call to the SPMD, and unshare the reclaimed page ranges in the host stage-2 page tables. Link: https://support.arm.com/documentation/den0140/j Signed-off-by: Snehal Koukuntla --- arch/arm64/kvm/hyp/nvhe/ffa.c | 117 ++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 5ad74ab265b5..e0fba07a67bc 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -232,6 +232,19 @@ static void ffa_mem_reclaim(struct arm_smccc_1_2_regs = *res, u32 handle_lo, }, res); } =20 +static void ffa_mem_reclaim2(struct arm_smccc_1_2_regs *res, u64 handle, + u64 flags, u64 x3, u64 x4, u64 x5) +{ + hyp_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { + .a0 =3D FFA_FN64_MEM_RECLAIM2, + .a1 =3D handle, + .a2 =3D flags, + .a3 =3D x3, + .a4 =3D x4, + .a5 =3D x5, + }, res); +} + static void ffa_retrieve_req(struct arm_smccc_1_2_regs *res, u32 len) { hyp_smccc_1_2_smc(&(struct arm_smccc_1_2_regs) { @@ -611,6 +624,107 @@ static void __do_ffa_mem_xfer(const u64 func_id, __do_ffa_mem_xfer((fid), (res), (ctxt)); \ } while (0); =20 +static void do_ffa_mem_reclaim2(struct arm_smccc_1_2_regs *res, + struct kvm_cpu_context *ctxt) +{ + DECLARE_REG(u64, handle, ctxt, 1); + DECLARE_REG(u64, flags, ctxt, 2); + DECLARE_REG(u64, x3, ctxt, 3); + DECLARE_REG(u64, x4, ctxt, 4); + DECLARE_REG(u64, x5, ctxt, 5); + u32 req_desc_cnt =3D (u32)(x3 >> 32); + u32 total_pages =3D (u32)x3; + u32 desc_size =3D (u32)x4; + u32 offset =3D (u32)x5; + u32 page_index =3D (u32)(x5 >> 32); + struct ffa_mem_region_addr_range *range; + u32 reclaimed_pages; + u32 reclaimed_count =3D 0; + u32 in_idx; + int ret =3D 0; + + if (ffa_check_unused_args_sbz(ctxt, 6) || (flags & ~1ULL) || (x4 >> 32)) { + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); + return; + } + + if (!req_desc_cnt || !total_pages) { + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); + return; + } + + if (desc_size !=3D sizeof(struct ffa_mem_region_addr_range)) { + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); + return; + } + + if ((u64)req_desc_cnt * desc_size > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) { + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); + return; + } + + if (offset % desc_size !=3D 0) { + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); + return; + } + + if (offset >=3D (u64)req_desc_cnt * desc_size) { + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); + return; + } + + hyp_spin_lock(&host_buffers.lock); + if (!host_buffers.tx) { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out_unlock; + } + + memcpy(hyp_buffers.tx, host_buffers.tx, (u64)req_desc_cnt * desc_size); + + range =3D (void *)hyp_buffers.tx + offset; + if (page_index >=3D range->pg_cnt) { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out_unlock; + } + + ffa_mem_reclaim2(res, handle, flags, x3, x4, x5); + if (res->a0 !=3D FFA_SUCCESS) + goto out_unlock; + + reclaimed_pages =3D res->a3; + + for (in_idx =3D offset / desc_size; in_idx < req_desc_cnt; in_idx++) { + struct ffa_mem_region_addr_range temp; + u32 pg_cnt, to_reclaim; + + if (reclaimed_count >=3D reclaimed_pages) + break; + + range =3D (void *)hyp_buffers.tx + in_idx * desc_size; + if (!range->pg_cnt) + continue; + + pg_cnt =3D range->pg_cnt - page_index; + to_reclaim =3D min(pg_cnt, reclaimed_pages - reclaimed_count); + + temp =3D (struct ffa_mem_region_addr_range) { + .address =3D range->address + (u64)page_index * FFA_PAGE_SIZE, + .pg_cnt =3D to_reclaim, + }; + + WARN_ON(ffa_host_unshare_ranges(&temp, 1)); + + reclaimed_count +=3D to_reclaim; + page_index =3D 0; + } + +out_unlock: + hyp_spin_unlock(&host_buffers.lock); + + if (ret) + ffa_to_smccc_res(res, ret); +} + static void do_ffa_mem_reclaim(struct arm_smccc_1_2_regs *res, struct kvm_cpu_context *ctxt) { @@ -1107,6 +1221,9 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *hos= t_ctxt, u32 func_id) case FFA_MEM_RECLAIM: do_ffa_mem_reclaim(&res, host_ctxt); goto out_handled; + case FFA_FN64_MEM_RECLAIM2: + do_ffa_mem_reclaim2(&res, host_ctxt); + goto out_handled; case FFA_MEM_LEND: case FFA_FN64_MEM_LEND: do_ffa_mem_xfer(FFA_FN64_MEM_LEND, &res, host_ctxt); --=20 2.55.0.1082.g2b9226bbc0-goog