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 D4715CD128A for ; Thu, 11 Apr 2024 08:52:25 +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=i/reerGoHqlfrJrB9uh9reNZQN623/rrQPIvwhg8dnQ=; b=ncpALrhXabw+ma 78T//FgaLEWQQ7UPctb28YutNApSHfytgTgVcAOTyIoOkRq2dKDvB+jyhOVQ8ynS0Xf0ByPkFpscu +eeZ5BPLX/9L0A05RUY1Y0oY7TuUNovQfHSl3ti8Y6SoNFbPCYeZkidrbCd1cX9mF0AdA56yy3qq0 BkFeCTew7+pqRwXShnKOJ3DykVgyT7Gp//X6xB80Xf44dvwBrVuEuV5flTHws8r4vwwuULcZuImAa XOtaLlqmGCmn5eH77x8lZdzAPlseeJBJTvxx5T6UPQvUAetHrWd/RmdVgjJfEqzVroFHTyL7XFEJh P7UxmcSFF3qxkHmmUPiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruqAH-0000000BBiS-3XBx; Thu, 11 Apr 2024 08:52:13 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruqAF-0000000BBhN-1aZa for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2024 08:52:12 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-41699bbfb91so59905e9.0 for ; Thu, 11 Apr 2024 01:52:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712825528; x=1713430328; 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=BmVuDao6rc6hBIHx5Ev3aZcNpyMOiHsa4Eq9hXFl4JM=; b=Rh4w2z9XETJQFavwIyOV5O3+cNUDAhw/RJ0Jx3Yhu4KUtNBgbaVhfhLNruKd+RQrtj CHAkKkEe9rb3pXujRHB+aMzHc8Em4UCksPWqrVgvy6uGwQoVfTErwgCVXUV6EovmfgsB F0eRKP1tdF1GFlgB5claKKokJ+a3H4tOqwOMnO/NB2IH91/8FeuRktrOnd1C+UOqinyn WQW9G5mP3pHomHMN3IrXAMtkOATdc78Ezl6QDKvGREu9BrVrxa1ENf9zaRtuthxEDCeR N4CcGyuOPA2n+phMh20vILbhvz4ifLUo2pLvr26fbvYRNt/dcPhoCVoJym94i9z89hgE +vKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712825528; x=1713430328; 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=BmVuDao6rc6hBIHx5Ev3aZcNpyMOiHsa4Eq9hXFl4JM=; b=d4s+VtBRVauIH4wtaoJCfwaUwCPtkj+DsS1qfcQWbLxvdx+KcM1bUYrtEfg48rEKco uy0P9JZB1cMTt1rW9CH2WrLaB5mPzG+qSfi6u5+5+ZLUlOgtJ+y4T1BHUIj6HF4kDWVG nujpkPClhd7NHPvW46SOooBdKSlZkeYp5pgLslv1d+Iy7zqBXcnduiEtnUznxdMctVZo n+33QWUSJn0In49BJpKxC+7vrG7SjBNMekPXyE/R/r5Jo4ajmjMt/Pz+sQzn8qAL80KR 68GlI6iyMjGptq1sXs8IfyT0JlrWfjmJqSZK9wtoGTNWYOw/t0rInOHhQUDWsCNrOdGm tKHw== X-Forwarded-Encrypted: i=1; AJvYcCWzPVk0NLM8xdkETv/LiVAvelx8uHG0+Lu+2zwCra4VCkkSZZNUL3o/FRzM2tPamiHvYCMRFX1c7RMNLTTPazgA6voKFyqPz7plF5ajxk+i81hbpBQ= X-Gm-Message-State: AOJu0YwfB+boq6Dh8sQ9RebjWzVCYrsEn8YWjIPh5E/F5qNQQrPfux0A qUudBERjtL/oQg82xHjSZ9M+9pxkM/LW7qDE7jSzO5qOw/qQNKoqUK/HWel/cw== X-Google-Smtp-Source: AGHT+IEHyQAF1b0TC6DYctDGP2A1rpYsfzyhRAynoAl9y0PZ04YsPHHdl/c1/oosy8F6BWBGGSq7og== X-Received: by 2002:a05:600c:3d18:b0:417:d7a4:2a0e with SMTP id bh24-20020a05600c3d1800b00417d7a42a0emr88682wmb.5.1712825528471; Thu, 11 Apr 2024 01:52:08 -0700 (PDT) Received: from google.com (248.199.140.34.bc.googleusercontent.com. [34.140.199.248]) by smtp.gmail.com with ESMTPSA id he8-20020a05600c540800b00416a08788a5sm4855277wmb.27.2024.04.11.01.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 01:52:07 -0700 (PDT) Date: Thu, 11 Apr 2024 08:52:05 +0000 From: Sebastian Ene To: Lorenzo Pieralisi 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, vdonnefort@google.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-20240411_015211_467942_9D1525ED X-CRM114-Status: GOOD ( 32.62 ) 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 Wed, Apr 10, 2024 at 04:57:19PM +0200, Lorenzo Pieralisi wrote: > 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; > > + > > + 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); Hello Lorenzo, > > We are copying buf_sz but (correctly ?) returning res->a3 to the caller, > which is allowed to expect res->a3 bytes to be filled since that's what > firmware reported. > > Technically this is not a problem at present, because the caller > (ie the FF-A driver) and the hypervisor rely on the same descriptor > structures (and buf_sz can't be != sizeof(struct ffa_partition_info), > anything else is a bug as we stand); they must be kept in sync though as > the firmware version changes (*if* there are changes in the partition > descriptor - eg fields are added). > > An option would consist in just copying res->a3 bytes as firmware reports > (obviously keeping the RX buffer boundary checks for the memcpy). > Ack, let me fix this an spin up a new version. > It is just a heads-up because I noticed it, no more, I will let Sudeep > comment on this since he knows better. > > Lorenzo > Thanks for having a look, 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