From nobody Mon Feb 9 13:35:43 2026 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) (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 F33CF22CBD9 for ; Fri, 2 May 2025 09:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746177676; cv=none; b=Vhi4FnoIRtviTKmVK0+nAkXR+Qr7eg5FvUP1E5Hw/aKUTmlEA9SS4nRYmBxeMW1POXxdM8XucnmRVAMp1O8nhEJPUziKdZxFH9kmAOa+Lw2F5saoO6mrkhVyXhFo8/tPhwkmZxLyt2CnFYjMOSe9gwuFR2qRIPWAeues35GxW0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746177676; c=relaxed/simple; bh=x8jU5cm1Fg5jhmw7TvC9ZyDUI9BUMgu95TARNLub1z8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iXgfAHAuXE6aemBGLVz1RpXFf0umv/erAmPtn02IN1jbOZ7+wKnRiEt1QlcjT5ANRtMxAHO4otDiM/L4jOrfs1VwLFsobAPA9765QMcAIHuO/TuNrNu5ipetFj5sRSkXy7J03oIBbhyAqW4l+08ngJD4U1azBFngUv7fPatmifc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=immunant.com; spf=none smtp.mailfrom=immunant.com; dkim=pass (2048-bit key) header.d=immunant-com.20230601.gappssmtp.com header.i=@immunant-com.20230601.gappssmtp.com header.b=CksqR2Hf; arc=none smtp.client-ip=209.85.219.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=immunant.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=immunant.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=immunant-com.20230601.gappssmtp.com header.i=@immunant-com.20230601.gappssmtp.com header.b="CksqR2Hf" Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e732386e4b7so1719806276.1 for ; Fri, 02 May 2025 02:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=immunant-com.20230601.gappssmtp.com; s=20230601; t=1746177673; x=1746782473; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9fB5WC809wTl4CZgtJWZZ9LIth3xEsvGA35RJbEoV80=; b=CksqR2HfSZUug6RWSTKogsV7fnzNo+kkR6pWNAzdSjm+e5tJUNm/iq7LKZrgqfT99j 3Eoq90fKaYOi+7/vKpCWVmF+mJlJVd2ZH6kUMe5sPXlz1Ygnn1H71AFP3s+QkKgQSD53 ZxLCxQacaX0/fjeCUbMidFtVl1VJnpUHIWsPuR3sCVNQOkmKqB8mavyPLysBJpOqn83e wuuN6II7aaRl740aVOFENf578hyhzgiwYLOW+o43Gx1qAvrN6ODGoY0o+fpXd3vIt27I XnwSuQJpmBDkeai/igw/YblJB4MkASiBpvsXERX3KL05la1tjrKxWCVW12CM4LTbkhR7 hJUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746177673; x=1746782473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9fB5WC809wTl4CZgtJWZZ9LIth3xEsvGA35RJbEoV80=; b=YDQP1cfmw4spwiQM5m3q9fzplnPaXodE2Ie5tsdgkz7Gy4d3aZ4lxZsYBJXdrjeWve g1VLaBDmvQP7p1dYBHf+cm+2xed35ykOs7dir2LA677/bDoR21hS7iJSx4W9CfhwRxkz AQ/rnis09xNuHfRZOulFQLuBFHpWDiyQu7W8MrRiGPex1qTm40ejVSVVw3my+sN6fgCY YcF48twnikStEIXGJzHytHaS6s3dPAbUc1lS2W+Tgyk8Izbry7uDIs21Zqb1XuyAh4hO tHWCvHVtaTiiIAfG6cSySpbDQWaIMALogo6jGkPNB6p35ne4HtqCUe/kOwJgYKgap/HQ nG0A== X-Gm-Message-State: AOJu0Yz0H6jIcywZyHcXDhCck7yRCocEl5kPbpFS+uDh4I/Y37x6Hqf5 FgzxeSH19I0MrontLzBl3wKuBEV4G5EKYcl0L7tbCEMTz3QwPwJRJNa3fmbYWvBo3tEIk08qIZs 8lx0= X-Gm-Gg: ASbGnctvgWf0k2X7sjGVYCEkB0ddYaOyIEDeDg1OaMjo2888gdqquuGRYWgbfQdwGn7 u5Dd/90Ik+dEz0bj+E4+0tFeLZZE2mSrIVD6thLVew11c/vvxxBnwUCxHnRxBniy01LnrDWF72/ rWTRjoDIBr1lpTqlM97lEy5v0eQfRIvydnKAiVVjAL4kp9uD4Esec8K1KUWZWq8y6yiyQd4SiMk gLGneb6FuMav8n2zZgYPTVhgmTlOvScy9/jj3uoDg4g0D9sdua5Ks98tDtOAyPfVvM4xxhXSZyK zBe9w9++TpmDBciAKU1f3pcLh/MX5hQJB9S94xlVaR0tVO4AyjWR X-Google-Smtp-Source: AGHT+IGQUPnvqf/qgEgSqRGNA98GCO3ipomvK0QEj746mMZOPYN8VysAcht5q3HIlb1fWVBbhO3x6w== X-Received: by 2002:a05:6902:2085:b0:e63:ecdf:4d6b with SMTP id 3f1490d57ef6-e75655490b5mr3096136276.13.1746177673505; Fri, 02 May 2025 02:21:13 -0700 (PDT) Received: from donna.immunant.com ([12.9.190.3]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e755e7d92d0sm556427276.55.2025.05.02.02.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 02:21:13 -0700 (PDT) From: Per Larsen To: linux-kernel@vger.kernel.org Cc: sebastianene@google.com, catalin.marinas@arm.com, james.morse@arm.com, jean-philippe@linaro.org, kernel-team@android.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, lpieralisi@kernel.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, armellel@google.com, arve@android.com, ahomescu@google.com, Per Larsen , Per Larsen Subject: [PATCH 1/3] KVM: arm64: Restrict FF-A host version renegotiation Date: Fri, 2 May 2025 02:21:06 -0700 Message-ID: <20250502092108.3224341-2-perl@immunant.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502092108.3224341-1-perl@immunant.com> References: <20250502092108.3224341-1-perl@immunant.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Per Larsen FF-A implementations with the same major version must interoperate with earlier minor versions per DEN0077A 1.2 REL0 13.2.1 but FF-A version 1.1 broke the ABI on several structures and 1.2 relies on SMCCC 1.2 is not backwards compatible with SMCCC 1.2 (see DEN0028 1.6 G BET0 Appendix F). If we return the negotiated hypervisor version when the host requests a lesser minor version, the host will rely on the FF-A interoperability rules. Since the hypervisor does not currently have the necessary compatibility paths (e.g. to handle breaking changes to the SMC calling convention), return NOT_SUPPORTED. Signed-off-by: Per Larsen Signed-off-by: Per Larsen --- arch/arm64/kvm/hyp/nvhe/ffa.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 3369dd0c4009..10e88207b78e 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -712,7 +712,24 @@ static void do_ffa_version(struct arm_smccc_res *res, =20 hyp_spin_lock(&version_lock); if (has_version_negotiated) { - res->a0 =3D hyp_ffa_version; + /* + * FF-A implementations with the same major version must + * interoperate with earlier minor versions per DEN0077A 1.2 + * REL0 13.2.1 but FF-A version 1.1 broke the ABI on several + * structures and 1.2 relies on SMCCC 1.2 is not backwards + * compatible with SMCCC 1.2 (see DEN0028 1.6 G BET0 Appendix F). + * + * If we return the negotiated hypervisor version when the host + * requests a lesser minor version, the host will rely on the + * aforementioned FF-A interoperability rules. Since the + * hypervisor does not currently have the necessary compatibility + * paths (e.g. to paper over the above-mentioned calling + * convention changes), return NOT_SUPPORTED. + */ + if (FFA_MINOR_VERSION(ffa_req_version) < FFA_MINOR_VERSION(hyp_ffa_versi= on)) + res->a0 =3D FFA_RET_NOT_SUPPORTED; + else + res->a0 =3D hyp_ffa_version; goto unlock; } =20 --=20 2.49.0 From nobody Mon Feb 9 13:35:43 2026 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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 6099622F164 for ; Fri, 2 May 2025 09:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746177679; cv=none; b=mayAhsAiunGAIFiUAAskpukUvix+CIpiMdLbEbYJVKpshHyQosHkQ4MHHAGkcL8Bmtg78kKnZgwlLCmSNmDUw6OLYMdriVxKioT/42lN/RM1B47IgMO4XaK9mXzHlr4DXWO9AWGZJzkiNCclYVP5tLCs50QRHRWgTLSoUKunwK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746177679; c=relaxed/simple; bh=x3YslSjU5tvUmUt5iGgoju+7VYZR8TyTUN0NvDyd0EU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gx0xav3CRKXqYcK72ZWjBtJNKNrtCC9N8QzpJ1U2S+aBCVdNLN8XD6/QkV+WmvtNUMDf61k2eHR5BVhJDXS9gSjbz3IyRaUz5wUEhNLAgLTspMztly6W23bmyXziP5bGkh/4+kZttn7jPkPQ9U3z/JTb2cxEkaUuvkfs3S9Kuxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=immunant.com; spf=none smtp.mailfrom=immunant.com; dkim=pass (2048-bit key) header.d=immunant-com.20230601.gappssmtp.com header.i=@immunant-com.20230601.gappssmtp.com header.b=VjJ4oWQN; arc=none smtp.client-ip=209.85.219.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=immunant.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=immunant.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=immunant-com.20230601.gappssmtp.com header.i=@immunant-com.20230601.gappssmtp.com header.b="VjJ4oWQN" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e7329792c6eso1541287276.1 for ; Fri, 02 May 2025 02:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=immunant-com.20230601.gappssmtp.com; s=20230601; t=1746177676; x=1746782476; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wXTVqSuS6Nru86md+gL/FG45+whJF/sIYExDwh5sAUg=; b=VjJ4oWQN8YnS4Lc6nAZRI2HZrvfH4TbnW4kEbE6nujKKlspqKUdAJOj2rdXDvfi7wr n2uRr5dOm6TEY/YzetZbx7KhdRpxNlOmdZL6ZPxf1yoQCYoM6d5NHJ5bj5MtAooRoHfn x//K1XCrrc4xFulE4rdjqT+oErRihu2B6UfgpQOf9qsA0eHX6WUofnbhoZLgisAF1YHw oYGHZNCtlt5z8229P1eRlzNhQtWhVDx5L+PzVuLcCiocLYJhWBm3Udax1MhgJkuyzAHz mCvonFrmgSCAMBpzeSyj1KYyCza4v1nFdfhIoxAhVGsqzCEX/1n07OXp5bRIL4FozKnP gKqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746177676; x=1746782476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wXTVqSuS6Nru86md+gL/FG45+whJF/sIYExDwh5sAUg=; b=sZsCCqc7wMLTwQMDqLlhIvBdFyVAWszGilV6zZcOA78GTPbq3O5+6BpJHvtJ0cV3s/ IM1pINRKCPPsk0ohyh5UsaTas94Hu1SRL1MNLsSMWrDNVhsC9Zac5jKVNSRoelu6thrb XcThLTOoT6WiGc4DRna+jZ11maz9ZtDd1PBrhCuaEcVJhmySMJEIgxjvdAwmsfea09r2 GE+TMgNPRvKMpF3s8+tj5lNtDSB/90dA6u0kD9G/fxKZWfNw/OvNI8eGXUH6z+dEBcx8 16uyEs3zT9Vm6pbJSW68gecC0oa4LgFgjHmwQTLLMDtHdYd7eovYTe1Vh1Y6DrW17Bx4 5KuA== X-Gm-Message-State: AOJu0Yzf40Y0KNQfKWzbAPp9FpU1rdSlV1jM1VpGGa/b5Jrwu4sy+sPp qkrfBlY0QavuFWRpC8uoCdNEysJ08UDGhwRkRc1yweKL+vwtbnoBkSUZ3an3II0XqZUpRWo3T5x ixtk= X-Gm-Gg: ASbGncuiJl4PZeD+lklSHwBgO6uPz1BqoENTty+hW1+9gGs+nnG9wJ8x6PKudZm1tQB NxQ4MYr2ioCujYXtR7fGV2mq+XqMMZDovDjHIGNdin4u7wT6gc4xSH0zafINrqn1+9/ZCgYwAgL 1QL2zfkbEPv46CQgEPaeyXqlvg8YO4sfaS94EUf0tEaXMhrRlMGZZ213/tX6TxwEZ1e2XBJJ77s hvLl47IpOSm9E1Lfb3RlUht78Z8uwFlJkFKRCZ1Np/+Pa0Ax0olAoKv8TAv36uD5iojip9vD7v1 jXAqgcVdwbyIrvGn+wW4tlATPRPj1XmIa2r/7hS6C77eZTHbMAU9 X-Google-Smtp-Source: AGHT+IGmUl1GdZxfwSb42zKFXUWo6QU+Vhl5qRPmA2BrlGjiHY8SxNw5HgzfPvnfGkzAQOdEnTenqg== X-Received: by 2002:a05:6902:240c:b0:e75:608f:4da9 with SMTP id 3f1490d57ef6-e756562a337mr2991253276.44.1746177676023; Fri, 02 May 2025 02:21:16 -0700 (PDT) Received: from donna.immunant.com ([12.9.190.3]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e755e7d92d0sm556427276.55.2025.05.02.02.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 02:21:15 -0700 (PDT) From: Per Larsen To: linux-kernel@vger.kernel.org Cc: sebastianene@google.com, catalin.marinas@arm.com, james.morse@arm.com, jean-philippe@linaro.org, kernel-team@android.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, lpieralisi@kernel.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, armellel@google.com, arve@android.com, ahomescu@google.com, Per Larsen , Ayrton Munoz , Per Larsen Subject: [PATCH 2/3] KVM: arm64: Bump the supported version of FF-A to 1.2 Date: Fri, 2 May 2025 02:21:07 -0700 Message-ID: <20250502092108.3224341-3-perl@immunant.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502092108.3224341-1-perl@immunant.com> References: <20250502092108.3224341-1-perl@immunant.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Per Larsen FF-A version 1.2 introduces the DIRECT_REQ2 ABI. Bump the FF-A version preferred by the hypervisor as a precursor to implementing the 1.2-only FFA_MSG_SEND_DIRECT_REQ2 and FFA_MSG_SEND_RESP2 messaging interfaces. We must also use SMCCC 1.2 for 64-bit SMCs if hypervisor negotiated FF-A 1.2, so ffa_set_retval is updated and a new function to call 64-bit smcs using SMCCC 1.2 with fallback to SMCCC 1.1 is introduced. Update deny-list in ffa_call_supported to mark FFA_NOTIFICATION_* and interfaces added in FF-A 1.2 as unsupported lest they get forwarded. Co-Developed-by: Ayrton Munoz Signed-off-by: Per Larsen Signed-off-by: Per Larsen --- arch/arm64/kvm/hyp/nvhe/Makefile | 1 + arch/arm64/kvm/hyp/nvhe/ffa.c | 109 ++++++++++++++++++++++++++----- 2 files changed, 94 insertions(+), 16 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Mak= efile index b43426a493df..95404ff16dac 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -27,6 +27,7 @@ hyp-obj-y :=3D timer-sr.o sysreg-sr.o debug-sr.o switch.o= tlb.o hyp-init.o host.o cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o ffa.o hyp-obj-y +=3D ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../en= try.o \ ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o +hyp-obj-y +=3D ../../../kernel/smccc-call.o hyp-obj-$(CONFIG_LIST_HARDENED) +=3D list_debug.o hyp-obj-y +=3D $(lib-objs) =20 diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 10e88207b78e..8102dd6a19f7 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -94,13 +94,57 @@ static void ffa_to_smccc_res(struct arm_smccc_res *res,= int ret) ffa_to_smccc_res_prop(res, ret, 0); } =20 -static void ffa_set_retval(struct kvm_cpu_context *ctxt, +static void ffa_set_retval(u64 func_id, + struct kvm_cpu_context *ctxt, struct arm_smccc_res *res) { cpu_reg(ctxt, 0) =3D res->a0; cpu_reg(ctxt, 1) =3D res->a1; cpu_reg(ctxt, 2) =3D res->a2; cpu_reg(ctxt, 3) =3D res->a3; + + /* + * Other result registers must be zero per DEN0077A but SMC32/HVC32 must + * preserve x8-x30 per DEN0028. + */ + cpu_reg(ctxt, 4) =3D 0; + cpu_reg(ctxt, 5) =3D 0; + cpu_reg(ctxt, 6) =3D 0; + cpu_reg(ctxt, 7) =3D 0; + + /* Per DEN0077A v1.2, x8-x17 must be zero for SMC64/HVC64 results*/ + if (ARM_SMCCC_IS_64(func_id) && hyp_ffa_version >=3D FFA_VERSION_1_2) { + cpu_reg(ctxt, 8) =3D 0; + cpu_reg(ctxt, 9) =3D 0; + cpu_reg(ctxt, 10) =3D 0; + cpu_reg(ctxt, 11) =3D 0; + cpu_reg(ctxt, 12) =3D 0; + cpu_reg(ctxt, 13) =3D 0; + cpu_reg(ctxt, 14) =3D 0; + cpu_reg(ctxt, 15) =3D 0; + cpu_reg(ctxt, 16) =3D 0; + cpu_reg(ctxt, 17) =3D 0; + } +} + +/* Call SMC64 using SMCCC 1.2 if hyp negotiated FF-A 1.2 falling back to 1= .1 */ +static void arm_smccc_1_2_smc_fallback(u64 func_id, u64 a1, u64 a2, u64 a3, + u64 a4, u64 a5, u64 a6, u64 a7, + struct arm_smccc_res *res) +{ + struct arm_smccc_1_2_regs args, regs; + + /* SMC64 only as SMC32 must preserve x8-x30 per DEN0028 1.6G Sec 2.6 */ + if (ARM_SMCCC_IS_64(func_id) && hyp_ffa_version >=3D FFA_VERSION_1_2) { + args =3D (struct arm_smccc_1_2_regs) { func_id, a1, a2, a3, a4, + a5, a6, a7 }; + arm_smccc_1_2_smc(&args, ®s); + *res =3D (struct arm_smccc_res) { .a0 =3D regs.a0, .a1 =3D regs.a1, + .a2 =3D regs.a2, .a3 =3D regs.a3 }; + return; + } + + arm_smccc_1_1_smc(func_id, a1, a2, a3, a4, a5, a6, a7, res); } =20 static bool is_ffa_call(u64 func_id) @@ -115,12 +159,12 @@ static int ffa_map_hyp_buffers(u64 ffa_page_count) { 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, - 0, 0, 0, 0, - &res); + arm_smccc_1_2_smc_fallback(FFA_FN64_RXTX_MAP, + hyp_virt_to_phys(hyp_buffers.tx), + hyp_virt_to_phys(hyp_buffers.rx), + ffa_page_count, + 0, 0, 0, 0, + &res); =20 return res.a0 =3D=3D FFA_SUCCESS ? FFA_RET_SUCCESS : res.a2; } @@ -174,10 +218,10 @@ static void ffa_mem_reclaim(struct arm_smccc_res *res= , u32 handle_lo, =20 static void ffa_retrieve_req(struct arm_smccc_res *res, u32 len) { - arm_smccc_1_1_smc(FFA_FN64_MEM_RETRIEVE_REQ, - len, len, - 0, 0, 0, 0, 0, - res); + arm_smccc_1_2_smc_fallback(FFA_FN64_MEM_RETRIEVE_REQ, + len, len, + 0, 0, 0, 0, 0, + res); } =20 static void ffa_rx_release(struct arm_smccc_res *res) @@ -628,6 +672,37 @@ static bool ffa_call_supported(u64 func_id) case FFA_RXTX_MAP: case FFA_MEM_DONATE: case FFA_MEM_RETRIEVE_REQ: + /* Optional notification interfaces added in FF-A 1.1 */ + case FFA_NOTIFICATION_BITMAP_CREATE: + case FFA_NOTIFICATION_BITMAP_DESTROY: + case FFA_NOTIFICATION_BIND: + case FFA_NOTIFICATION_UNBIND: + case FFA_NOTIFICATION_SET: + case FFA_NOTIFICATION_GET: + case FFA_NOTIFICATION_INFO_GET: + /* Unimplemented interfaces added in FF-A 1.2 */ + case FFA_MSG_SEND_DIRECT_REQ2: + + /* + * FFA_MSG_SEND_DIRECT_RESP2 is not meant to be invoked by the host or + * a guest VM because pkvm does not support communication between VMs + * via FF-A. Direct messages can only be sent from a non-secure sender + * endpoint to a secure receiver endpoint. Only receiver endpoints are + * expected to invoke FFA_MSG_SEND_DIRECT_RESP2. + */ + case FFA_MSG_SEND_DIRECT_RESP2: + + /* Reserved for secure endpoints per DEN0077A 1.2 REL0 Table 13.53. */ + case FFA_CONSOLE_LOG: + + /* + * Mandatory for secure endpoints per DEN0077A 1.2 REL0 Table 13.1 and + * optional for non-secure endpoints according to Table 13.38. + */ + case FFA_PARTITION_INFO_GET_REGS: + + /* Reserved for secure endpoints per DEN0077A 1.2 REL0 Table 17.2. */ + case FFA_EL3_INTR_HANDLE: return false; } =20 @@ -680,7 +755,8 @@ static int hyp_ffa_post_init(void) if (res.a0 !=3D FFA_SUCCESS) return -EOPNOTSUPP; =20 - switch (res.a2) { + /* Bit[0:1] holds minimum buffer size and alignment boundary */ + switch (res.a2 & 0x3) { case FFA_FEAT_RXTX_MIN_SZ_4K: min_rxtx_sz =3D SZ_4K; break; @@ -871,7 +947,7 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_= ctxt, u32 func_id) =20 ffa_to_smccc_error(&res, FFA_RET_NOT_SUPPORTED); out_handled: - ffa_set_retval(host_ctxt, &res); + ffa_set_retval(func_id, host_ctxt, &res); return true; } =20 @@ -883,7 +959,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_1, 0, 0, 0, 0, 0, 0, &res); + arm_smccc_1_1_smc(FFA_VERSION, FFA_VERSION_1_2, 0, 0, 0, 0, 0, 0, &res); if (res.a0 =3D=3D FFA_RET_NOT_SUPPORTED) return 0; =20 @@ -903,10 +979,11 @@ int hyp_ffa_init(void *pages) if (FFA_MAJOR_VERSION(res.a0) !=3D 1) return -EOPNOTSUPP; =20 - if (FFA_MINOR_VERSION(res.a0) < FFA_MINOR_VERSION(FFA_VERSION_1_1)) + /* See do_ffa_guest_version before bumping maximum supported version. */ + if (FFA_MINOR_VERSION(res.a0) < FFA_MINOR_VERSION(FFA_VERSION_1_2)) hyp_ffa_version =3D res.a0; else - hyp_ffa_version =3D FFA_VERSION_1_1; + hyp_ffa_version =3D FFA_VERSION_1_2; =20 tx =3D pages; pages +=3D KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE; --=20 2.49.0 From nobody Mon Feb 9 13:35:43 2026 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 DBEF01E883A for ; Fri, 2 May 2025 09:21:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746177682; cv=none; b=dYK6WY3Qm+SeakaYJ/7Bp8R3Z32/GKGoFBh7HXoQKIzsD2b+d2aShfrOoEoZqS5QBbansVGUDf4ANvn08E+chkB8n8NN8pb8jjvReqHCulLLdNpB0oYVxzuxwGQknyEDSOZXoQ8pL7fW1MYEZKkz09vO4G1XwfLY//ivbMUah0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746177682; c=relaxed/simple; bh=z41DDBbJl4TIvbOFCLPOvC2bUtA8XyTHiBwdchWGrpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FOFUpb1VaPKdXJ72Sced+pOA+TPYb8FuBeWeQGkfZ2/WRcc9N8ZIhhErhT3EZd7zrS72zroBk+ZSRLXADf7lfOs5wes7ZFQt/rRe0xIKvs+cn2k+7E0fop0f/5RY5ZdbZxi/gJN4xKX1vsNjHyeJakETCy70IsDZOV1DBqhkUa0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=immunant.com; spf=none smtp.mailfrom=immunant.com; dkim=pass (2048-bit key) header.d=immunant-com.20230601.gappssmtp.com header.i=@immunant-com.20230601.gappssmtp.com header.b=w84ioxnZ; arc=none smtp.client-ip=209.85.219.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=immunant.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=immunant.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=immunant-com.20230601.gappssmtp.com header.i=@immunant-com.20230601.gappssmtp.com header.b="w84ioxnZ" Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e732386e4b7so1719855276.1 for ; Fri, 02 May 2025 02:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=immunant-com.20230601.gappssmtp.com; s=20230601; t=1746177678; x=1746782478; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jyHCon4vU91wPH4dyinNdOyq5hW82Gz0ZN1lgTbU0wg=; b=w84ioxnZ5Z3LX1m0K6csiO9s/Ljcc7kswR/yXpwhua1hikMzvhha3JjGf9XUGtEPq4 iJojjnnAOvY9fERDJGmmTHcy+gN5CpI8Y5vsEs5Xgh9y9gf44ZX6cVPbXL64sgLD+DYc p61xr4F0S89b/NWineMq81M8hxC7VVRc7CEbmJXxhbio0bfqDxX7c/L6+XL84p93gqvp uAOKQaFKqXwDJeQvtxo/hkE5CEiqfs5b9U7E4Apmmoncqj5NfTHLOgGcs3ljXD9zAlmC rSg2vvGO4k1t7ks0H0E7ZkOYPU8HVNPczghbhX2mmy6CxUBn1kxkg+JljAjcuHc1u8TA jAbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746177678; x=1746782478; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jyHCon4vU91wPH4dyinNdOyq5hW82Gz0ZN1lgTbU0wg=; b=c/WJncqEjuRAyJfiz2A0DaTRexdzTZ4PDhYLpxeHEtTZasVbMvx21ORQrrZg5cta3h C8vLSTTZFlp5acah2a2OspGYbA6HaW92H6CNExLL3p4ySpKcI/xs69tJ26diyu+/89qz v7iaarwtI2lz6T3Hp90TRv3WYEqu3sqArpPJ23EY6UjExOtVOxFwSzjb3JZF3gi778yD YT67tM2QBdEDP2G41KeV4pUtzxnXRlKxpJOEDvk580MBk+vmB30UlyDT9CMNBLv+dxlZ GUlcPDU8CxUCUS83rh7gIOXgqNN9zfCHeZEu057IAJbO3fRnKqle6Ar06rJkDVfmW9rR k5ng== X-Gm-Message-State: AOJu0YydYUpvspRN73UfdFjDMojQ/hbjFtCc2g+AHEezrD0Yqdhxwx6d UAjd5z42i8FaqjuXoE1sf19aR6Dw0lwex6RN660m+GUzoTmYjp4gP4MJ/S6LsM4Ak8QKU2QQGZN 6vu0= X-Gm-Gg: ASbGnctc5wt64e+tMjglM7VmnH6aIdOpsmfAuO4EATGRBTc6u35XUMyntnaMOJGXvpy e3e2RUFp0MajcuqwNpqKIdPnarCQ/SeifW7LpeZPfHxe/WTkU5pwjpja0eaPRgeMV/jfnArSUhI GpcK6qrZsknJXo0RSJmMeLvSLiRY8R6JXsGhKsZYob/rCSAnnbRIwcTu9uTCOkqoHXwMUSmxWPr rJ4WtDM51b261Ca6DFnfMxtM6eLNKk9kjfrn7UVn8lejwt5xrggva0zYF26xqT3Mmbm50Dp/mGn nKBZjapu9gy0ALIHun/EGEf/iM7mq6YaW0adaArEBA== X-Google-Smtp-Source: AGHT+IGp+ETgvJSd9lvf2Hm0u8cGNqnSHJMy0WS2lG3WhWOOaG2gaDXYIeZ4OWRo041mgp+lOQesMg== X-Received: by 2002:a05:6902:1885:b0:e72:a584:bea0 with SMTP id 3f1490d57ef6-e756556fef7mr2617975276.21.1746177678568; Fri, 02 May 2025 02:21:18 -0700 (PDT) Received: from donna.immunant.com ([12.9.190.3]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e755e7d92d0sm556427276.55.2025.05.02.02.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 02:21:18 -0700 (PDT) From: Per Larsen To: linux-kernel@vger.kernel.org Cc: sebastianene@google.com, catalin.marinas@arm.com, james.morse@arm.com, jean-philippe@linaro.org, kernel-team@android.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, lpieralisi@kernel.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, armellel@google.com, arve@android.com, ahomescu@google.com, Per Larsen , Per Larsen Subject: [PATCH 3/3] KVM: arm64: Support FFA_MSG_SEND_DIRECT_REQ2 in host handler Date: Fri, 2 May 2025 02:21:08 -0700 Message-ID: <20250502092108.3224341-4-perl@immunant.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502092108.3224341-1-perl@immunant.com> References: <20250502092108.3224341-1-perl@immunant.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Per Larsen FF-A 1.2 adds the DIRECT_REQ2 messaging interface which is similar to the existing FFA_MSG_SEND_DIRECT_{REQ,RESP} functions except that it uses the SMC calling convention v1.2 which allows calls to use x4-x17 as argument and return registers. Add support for FFA_MSG_SEND_DIRECT_REQ2 in the host ffa handler. Signed-off-by: Per Larsen Signed-off-by: Per Larsen --- arch/arm64/kvm/hyp/nvhe/ffa.c | 111 +++++++++++++++++++++++++++++++++- include/linux/arm_ffa.h | 2 + 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 8102dd6a19f7..d8c066f3c5c9 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -79,6 +79,14 @@ static void ffa_to_smccc_error(struct arm_smccc_res *res= , u64 ffa_errno) }; } =20 +static void ffa_to_smccc_1_2_error(struct arm_smccc_1_2_regs *regs, u64 ff= a_errno) +{ + *regs =3D (struct arm_smccc_1_2_regs) { + .a0 =3D FFA_ERROR, + .a2 =3D ffa_errno, + }; +} + static void ffa_to_smccc_res_prop(struct arm_smccc_res *res, int ret, u64 = prop) { if (ret =3D=3D FFA_RET_SUCCESS) { @@ -89,11 +97,26 @@ static void ffa_to_smccc_res_prop(struct arm_smccc_res = *res, int ret, u64 prop) } } =20 +static void ffa_to_smccc_1_2_regs_prop(struct arm_smccc_1_2_regs *regs, in= t ret, u64 prop) +{ + if (ret =3D=3D FFA_RET_SUCCESS) { + *regs =3D (struct arm_smccc_1_2_regs) { .a0 =3D FFA_SUCCESS, + .a2 =3D prop }; + } else { + ffa_to_smccc_1_2_error(regs, ret); + } +} + static void ffa_to_smccc_res(struct arm_smccc_res *res, int ret) { ffa_to_smccc_res_prop(res, ret, 0); } =20 +static void ffa_to_smccc_1_2_regs(struct arm_smccc_1_2_regs *regs, int ret) +{ + ffa_to_smccc_1_2_regs_prop(regs, ret, 0); +} + static void ffa_set_retval(u64 func_id, struct kvm_cpu_context *ctxt, struct arm_smccc_res *res) @@ -127,6 +150,29 @@ static void ffa_set_retval(u64 func_id, } } =20 +static void ffa_set_retval_smccc_1_2(struct kvm_cpu_context *ctxt, + struct arm_smccc_1_2_regs *regs) +{ + cpu_reg(ctxt, 0) =3D regs->a0; + cpu_reg(ctxt, 1) =3D regs->a1; + cpu_reg(ctxt, 2) =3D regs->a2; + cpu_reg(ctxt, 3) =3D regs->a3; + cpu_reg(ctxt, 4) =3D regs->a4; + cpu_reg(ctxt, 5) =3D regs->a5; + cpu_reg(ctxt, 6) =3D regs->a6; + cpu_reg(ctxt, 7) =3D regs->a7; + cpu_reg(ctxt, 8) =3D regs->a8; + cpu_reg(ctxt, 9) =3D regs->a9; + cpu_reg(ctxt, 10) =3D regs->a10; + cpu_reg(ctxt, 11) =3D regs->a11; + cpu_reg(ctxt, 12) =3D regs->a12; + cpu_reg(ctxt, 13) =3D regs->a13; + cpu_reg(ctxt, 14) =3D regs->a14; + cpu_reg(ctxt, 15) =3D regs->a15; + cpu_reg(ctxt, 16) =3D regs->a16; + cpu_reg(ctxt, 17) =3D regs->a17; +} + /* Call SMC64 using SMCCC 1.2 if hyp negotiated FF-A 1.2 falling back to 1= .1 */ static void arm_smccc_1_2_smc_fallback(u64 func_id, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 a6, u64 a7, @@ -681,7 +727,6 @@ static bool ffa_call_supported(u64 func_id) case FFA_NOTIFICATION_GET: case FFA_NOTIFICATION_INFO_GET: /* Unimplemented interfaces added in FF-A 1.2 */ - case FFA_MSG_SEND_DIRECT_REQ2: =20 /* * FFA_MSG_SEND_DIRECT_RESP2 is not meant to be invoked by the host or @@ -709,6 +754,20 @@ static bool ffa_call_supported(u64 func_id) return true; } =20 +/* + * Must a given FFA function use the SMC calling convention v1.2? + */ +static bool ffa_call_needs_smccc_1_2(u64 func_id) +{ + switch (func_id) { + case FFA_MSG_SEND_DIRECT_REQ2: + case FFA_MSG_SEND_DIRECT_RESP2: + return true; + } + + return false; +} + static bool do_ffa_features(struct arm_smccc_res *res, struct kvm_cpu_context *ctxt) { @@ -882,9 +941,47 @@ static void do_ffa_part_get(struct arm_smccc_res *res, hyp_spin_unlock(&host_buffers.lock); } =20 +static void do_ffa_direct_msg2(struct arm_smccc_1_2_regs *regs, + struct kvm_cpu_context *ctxt, + u64 vm_handle) +{ + DECLARE_REG(u32, func_id, ctxt, 0); + DECLARE_REG(u32, endp, ctxt, 1); + DECLARE_REG(u64, uuid_lo, ctxt, 2); + DECLARE_REG(u64, uuid_hi, ctxt, 3); + DECLARE_REG(u64, x4, ctxt, 4); + DECLARE_REG(u64, x5, ctxt, 5); + DECLARE_REG(u64, x6, ctxt, 6); + DECLARE_REG(u64, x7, ctxt, 7); + DECLARE_REG(u64, x8, ctxt, 8); + DECLARE_REG(u64, x9, ctxt, 9); + DECLARE_REG(u64, x10, ctxt, 10); + DECLARE_REG(u64, x11, ctxt, 11); + DECLARE_REG(u64, x12, ctxt, 12); + DECLARE_REG(u64, x13, ctxt, 13); + DECLARE_REG(u64, x14, ctxt, 14); + DECLARE_REG(u64, x15, ctxt, 15); + DECLARE_REG(u64, x16, ctxt, 16); + DECLARE_REG(u64, x17, ctxt, 17); + + if (FIELD_GET(FFA_SRC_ENDPOINT_MASK, endp) !=3D vm_handle) { + ffa_to_smccc_1_2_regs(regs, FFA_RET_INVALID_PARAMETERS); + return; + } + + struct arm_smccc_1_2_regs args =3D { + func_id, endp, uuid_lo, uuid_hi, + x4, x5, x6, x7, x8, x9, x10, + x11, x12, x13, x14, x15, x16, x17 + }; + + arm_smccc_1_2_smc(&args, regs); +} + bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id) { struct arm_smccc_res res; + struct arm_smccc_1_2_regs regs; =20 /* * There's no way we can tell what a non-standard SMC call might @@ -940,14 +1037,24 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *ho= st_ctxt, u32 func_id) case FFA_PARTITION_INFO_GET: do_ffa_part_get(&res, host_ctxt); goto out_handled; + case FFA_MSG_SEND_DIRECT_REQ2: + if (hyp_ffa_version >=3D FFA_VERSION_1_2) { + do_ffa_direct_msg2(®s, host_ctxt, HOST_FFA_ID); + goto out_handled; + } + goto out_not_supported; } =20 if (ffa_call_supported(func_id)) return false; /* Pass through */ =20 +out_not_supported: ffa_to_smccc_error(&res, FFA_RET_NOT_SUPPORTED); out_handled: - ffa_set_retval(func_id, host_ctxt, &res); + if (ffa_call_needs_smccc_1_2(func_id)) + ffa_set_retval_smccc_1_2(host_ctxt, ®s); + else + ffa_set_retval(func_id, host_ctxt, &res); return true; } =20 diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 5bded24dc24f..4d541cf12ceb 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -268,6 +268,8 @@ bool ffa_partition_check_property(struct ffa_device *de= v, u32 property) (ffa_partition_check_property(dev, FFA_PARTITION_DIRECT_REQ2_RECV) && \ !dev->mode_32bit) =20 +#define FFA_SRC_ENDPOINT_MASK GENMASK(31, 16) + /* For use with FFA_MSG_SEND_DIRECT_{REQ,RESP} which pass data via registe= rs */ struct ffa_send_direct_data { unsigned long data0; /* w3/x3 */ --=20 2.49.0