From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CEB85C25B75 for ; Wed, 15 May 2024 17:31:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UharPUDSPyK6n+Th1YhveX9C8Y2hp2tV3FQ7Zq4H45c=; b=uVHPU/Ygqokl+iomYKcMKMHO8c du+O1Lx6wIsFYAcM1KuDV0FmkxJOXk//p6zuMOdaST8nQVkpj7gTrlpQFCJCTrKeGd9rM59rHbffQ js2NKYtfoOrYo+01D52JmziptIuUPje+xB7YYiflKUwoFgQM4X1omQUNp0T41vChFHu3yWyY6LJ8y Koz8xcbYvNVVNvy1Db5OCLmRAUV+tzOQv+qO0ruQf6yiCCaGg51qt9wmUOShw5M8WWW15GxtNjxRV VCE/6ufjtjU4qx6pJsAuaX4qOFSdeiFgG8FAW5gJphbWnp4kXzkSRXlC0Gl0Z/sHD1dcd0ObF5qKe vk2+tYWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7ITP-00000002Pzt-0SCz; Wed, 15 May 2024 17:31:27 +0000 Received: from mail-lj1-x249.google.com ([2a00:1450:4864:20::249]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7ITK-00000002Pv7-2uf5 for linux-arm-kernel@lists.infradead.org; Wed, 15 May 2024 17:31:25 +0000 Received: by mail-lj1-x249.google.com with SMTP id 38308e7fff4ca-2e21d6edfe9so62627941fa.2 for ; Wed, 15 May 2024 10:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715794277; x=1716399077; darn=lists.infradead.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=oIxYZVobvIdd7vKzFbjZBSV/+kl+kajpQ7Ua3d9tnLGxhGD2gpwbS4zaeMsKCTWOUp AAojdBaSniTLHTrHG2Fs4viDjePW6vq4tvO8KmUQUNw7ixVGvkv7tAOupyEemdk6SCn2 nQY4xM6vQ5++Fup6YiZQ1KZHg6JqvLzdSovq2KEOuFfD8+Dv8Qq30/wz3zvKx7JRr8nJ fmWFYAGGbCT8fJfzM0xAvbYSTQBBr6Zfa86Og7Fm9nZLsFYedTVRLwGJuDCMpc2XHeMY 35XVJcAQWp8Khg2vUXQ+QWSIR3UL9b49VWLcSnW9Il9EplC7uswDQd1sXa/8F5tLF2yi SalA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715794277; x=1716399077; 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=jPBM8JsliWIcwCL/2EP9ISNMuNCX7pFATNl/L6GUIlQPgZb4MvkOs6HBHHz+ccJ8Gk ycGJBMkSYuGLN+l5OTzZPP0ZX79VfGL+fa59RjqZzDUkysauPredfLonB3U+Jd95iqx+ gn+ipcGWb4/cYML1amnuDXzfz1ybiZ8W5Z8n//qRZ3tzTbOXlSolQxpScXKJJ2cQujwm E60sRoe3UgXh6IeMJH2TkXcDB2KSpyBajEPRuwD+a3E1c+kPiIkE+Oq7aUytRqxYOT/+ 6xzgTWSQGMbmiD9+cRPXZQvnVecUbj4yrxrhRVdMlJc6Y00uCWO7Dkaox0P397t7Ek4m WvDA== X-Forwarded-Encrypted: i=1; AJvYcCWSiSACNxv7yJ0t52Ldge9UNgsnbE4chMIK9j7osNOqvnl27WBkKWCWuH+yUGqvDI3mkWLLN10pkfQuol5YSEBKR2T6JfEmbIaF6xyBrrNTw6Y1ckc= X-Gm-Message-State: AOJu0Ywhiu9SlcH2JAE5Gnvmd4shJsgTA/FJZNCBXWpUZRfIjJTy1V+l pGyvJwGOcMb90KliplM6b0fRdHYJPS6B0EbxVc+awJbzgpDWUErU/S3Dh4oSH6NlBZxIda+N2d+ upV4P+lsJBuSrBfPgSznAF7HuHQ== 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> 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240515_103122_756696_453E3ADC X-CRM114-Status: GOOD ( 15.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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); } +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 != FFA_SUCCESS) + goto out_unlock; + + count = 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 = res->a3; + } else { + /* FFA_VERSION_1_0 lacks the size in the response */ + partition_sz = FFA_1_0_PARTITON_INFO_SZ; + } + + copy_sz = 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; } 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; } extern const struct bus_type ffa_bus_type; +/* 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; -- 2.45.0.rc1.225.g2a3ae87e7f-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel