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 48FBBCD1297 for ; Wed, 10 Apr 2024 09:16:00 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sDVto4fCDzl47NLwn1lpL8WNLv7lLvrYIlqp7owxNGI=; b=AIW6chkKrujDQ6 BBVYAS9+rNBfoKOEnUghxnfUwJOLGepHyIYW+RZxZutlYeQUniKHIgv7MpFZDO2FLaPkvSH5Q7ypI kXDX7P2lQkczjJn7qkS63vd2I7UY3hWT+oOEZx+TenFVuHBfK+qh1eV7DjAyvDsogYjnyBNPJFuRR lX/JrwmBPBKCF5053Hg3+Ijj/focaLtD/zrGfEvK66aFZWgMTcScFqLIFBKJe+9+cDo9iibP2p8Xi nVh6kBY+OScbFLrq+yNn2SnktHXjumZUqHdVsdun0h2Ruo2NvkRYzzxVf9x8fox3tSevBafQIX8PR hRZ/tdAggtHYYrzu6iMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruU3P-000000065ah-2j6W; Wed, 10 Apr 2024 09:15:39 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruU3M-000000065XC-1qaY for linux-arm-kernel@lists.infradead.org; Wed, 10 Apr 2024 09:15:37 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-41699bbfb91so52135e9.0 for ; Wed, 10 Apr 2024 02:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712740533; x=1713345333; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mo5yUXNBd3ZqPlawfQyQwNue5di0stprqcnUautikic=; b=F+5CjQHDmA7za1lt2OBwqxQtY6erPRNnMHVt8zoG+l60RzlxsxSY0itGS+RNmCRcTP MAcvbXwPoG+2kqr7fm3FD+6WsU7cN4ReHezlxuiHnD8fDBgiji9vOJIwpYqxgbsOdDGN /aQ61gQNZJpYCgFpGDwvWvTopTaZ3zd3NbEj0rvSPk6ZAj0btba8DUCzR8lOHvrmz2pP ZGWOiN+ikv1px9SAwfo9MYW7b/gyo1JirIJtfVZ/wGYOF8WLoY5+jXoYd8FqwSsCLmvw ZDgJIGrL1C74yWTUNfjiQ3rwDjMdFhB9HWrlK0rEFXGfFA+A3bixGYA7kDaFcoDgT8yL NIHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712740533; x=1713345333; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mo5yUXNBd3ZqPlawfQyQwNue5di0stprqcnUautikic=; b=AfKtlfdQzGWkDCVdih/ZzieAiX8qayzbmKEhm4gGRdZwGr73LQPQla1rndqkBjoHl2 ufkXDAeBKJ0ePITiWz6jKt6QkA5zKChXJl6NuJoclCxQkB0P3Ma2cc60tgqzts2yIVxm 9TLDnyiElQB7vwq9+l9P5WdbZOPIgZNVSixFEFNn4IRNrYRz6+0U6X551ynomZbyAvn+ NrGexacaAYsJXK3JcYvABJ2aAHdLJcj8Ew77bjg+qc7FJ8McEvCVv1m5oyKsSFmjTnmN Xm7zKLRLpcmvI43PFbBb+694fJGXQBw31dlXrWuXoBnWXRYykw6RU+cnYq+LAprLIdpF a9bA== X-Forwarded-Encrypted: i=1; AJvYcCW7B8XVgiGV2M/fbeM8c0XomgYumOkFcpUhUBDEGDOhGRENTgZfZ3YZVEG82cRBMDiUUqx9K5Lro3j/+WftGZG21v7Iw/s7ecEyLMO/PvyP3XtAy50= X-Gm-Message-State: AOJu0YxQgxtM9b6lff1FEWtbQEVwM7931xZa7AEF0lzC7OHMZcN+LtZ0 BQHLmO0cGIFd2fbPLg3lsV7vr16qo9bt9BWPOhwpxlwtAL1RwvgS72VBs8OAvQ== X-Google-Smtp-Source: AGHT+IEBtQIBTBIKC8UbwL32JAPKT7O7PWWE97mAxwT/AQp+UyPWzOdg2/EhifcyhKX5pP1qVudzgw== X-Received: by 2002:a05:600c:5113:b0:414:daa3:c192 with SMTP id o19-20020a05600c511300b00414daa3c192mr161451wms.0.1712740532752; Wed, 10 Apr 2024 02:15:32 -0700 (PDT) Received: from google.com (248.199.140.34.bc.googleusercontent.com. [34.140.199.248]) by smtp.gmail.com with ESMTPSA id di3-20020a0560000ac300b00341c7129e28sm13315653wrb.91.2024.04.10.02.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 02:15:32 -0700 (PDT) Date: Wed, 10 Apr 2024 09:15:30 +0000 From: Sebastian Ene To: Vincent Donnefort Cc: 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, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH] KVM: arm64: Add support for FFA_PARTITION_INFO_GET Message-ID: References: <20240409151908.541589-1-sebastianene@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240410_021536_617681_362DCDA5 X-CRM114-Status: GOOD ( 33.13 ) 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 On Tue, Apr 09, 2024 at 05:15:20PM +0100, Vincent Donnefort wrote: > Hi Seb, > > On Tue, Apr 09, 2024 at 03:19:08PM +0000, Sebastian Ene wrote: > > 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 | 49 +++++++++++++++++++++++++++++++++++ > > 1 file changed, 49 insertions(+) > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c > > index 320f2eaa14a9..72fc365bc7a8 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/ffa.c > > +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c > > @@ -67,6 +67,7 @@ struct kvm_ffa_buffers { > > */ > > static struct kvm_ffa_buffers hyp_buffers; > > static struct kvm_ffa_buffers host_buffers; > > +static u32 ffa_version; > > > > static void ffa_to_smccc_error(struct arm_smccc_res *res, u64 ffa_errno) > > { > > @@ -640,6 +641,49 @@ static bool do_ffa_features(struct arm_smccc_res *res, > > return true; > > } > > > > +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 off, count, sz, buf_sz; > > + > > + hyp_spin_lock(&host_buffers.lock); > > + if (!host_buffers.rx) { > > + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); > > + 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; > > Looking at the table 13.34, it seems what's in "count" depends on the flag. > Shouldn't we check its value, and only memcpy into the host buffers if the flag > is 0? > When the flag is `1` the count referes to the number of partitions deployed. In both cases we have to copy something unless count == 0. > > + > > + if (ffa_version > FFA_VERSION_1_0) { > > + buf_sz = sz = res->a3; > > + if (sz > sizeof(struct ffa_partition_info)) > > + buf_sz = sizeof(struct ffa_partition_info); > > What are you trying to protect against here? We have to trust EL3 anyway, (as > other functions do). > > The WARN() could be kept though to make sure we won't overflow our buffer. But > it could be transformed into an error? FFA_RET_ABORTED? > > I think we can keep it as a WARN_ON because it is not expected to have a return code of FFA_SUCCESS but the buffer to be overflown. The TEE is expected to return NO_MEMORY in w2 if the results cannot fit in the RX buffer. Thanks, Seb > > + } else { > > + /* FFA_VERSION_1_0 lacks the size in the response */ > > + buf_sz = sz = 8; > > + } > > + > > + WARN_ON((count - 1) * sz + buf_sz > PAGE_SIZE); > > + for (off = 0; off < count * sz; off += sz) > > + memcpy(host_buffers.rx + off, hyp_buffers.rx + off, buf_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; > > @@ -686,6 +730,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_PARTITION_INFO_GET: > > + do_ffa_part_get(&res, host_ctxt); > > + break; > > } > > > > if (ffa_call_supported(func_id)) > > @@ -726,6 +773,8 @@ int hyp_ffa_init(void *pages) > > if (FFA_MAJOR_VERSION(res.a0) != 1) > > return -EOPNOTSUPP; > > > > + ffa_version = res.a0; > > + > > arm_smccc_1_1_smc(FFA_ID_GET, 0, 0, 0, 0, 0, 0, 0, &res); > > if (res.a0 != FFA_SUCCESS) > > return -EOPNOTSUPP; > > -- > > 2.44.0.478.gd926399ef9-goog > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel