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 A521FC25B75 for ; Wed, 15 May 2024 15:41:24 +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=4j0xCjFrwF0UR+16E+oz+vhFDRTPMLSmWhmfSHo8JNY=; b=IbvOcKnF0J8d0M kFI9piU+Hqi142WBynAZGBdDHayyMsaWJULvXVYssaMgONEZheS2cOt69w5PkTLTAN2Ccja/bhDlQ Ib15Ru1KfcWedEa37mWYmvkExMC95/qiPyws9owgHbVM71LukIPdKWt9LfxZ2Vb+Pg+IJJeU/vvo9 Vf46EoUD9CqQBm/6R7TgwrFjnatGPhD6v5ObHq+mnbd6FdpV8MeROiCRnqvFrrSs555Muf+NdwV6c 18HZXem0E2i0yQN2htfrpFZqyFhZqeRqhYlMV/BQTobztYmcsCCBoIwABF4cB7DZB3OlUUmqQaR1O nQO7j9lIqDrNQalWn9RQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7Gkf-00000001zN5-28th; Wed, 15 May 2024 15:41:09 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7Gka-00000001zMH-2cFY for linux-arm-kernel@lists.infradead.org; Wed, 15 May 2024 15:41:07 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42012c85e61so285245e9.0 for ; Wed, 15 May 2024 08:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715787658; x=1716392458; 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=vO+JXqkTWjh4IOLAvLgHOUrmin8Jhsgi5Im6h/wkV6k=; b=Sg6A8x733hQHeOUck/Gbq5Xy5NPUqLOtwtPJAkkFQyBzfs5e05X0u2t8IGYnuXMAg+ FxlCYlDjH4gsV7SeFF8dT71LP7A5QA2QsP1GWkmT3+xo8VQIdOpiuHnAkWgqaV05xMM7 0mvw7AXAFHeT/Ry8li+7yQQ+QIUEUDkhb//u6T0dIO8xt05x5o08DSPh7sH471OgcYx9 lADJAUT1gWabKgwIrUSyb8WrHuXaZmVgrD3sdjONkOxj6KKgxDosFGUGmvTCLOO1v8Dc yXlRENR/Xmm/iSB9OwzEtJB2i6OF5O13IUD0yZU0xFuXDTPtE0fYvb/X+cSbdtv9E7xg Hi2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715787658; x=1716392458; 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=vO+JXqkTWjh4IOLAvLgHOUrmin8Jhsgi5Im6h/wkV6k=; b=a74zl2oIxtv9ZY4IToXTIDsKTXlG4cyVIJJvVPZOvCH2w0smgBzmaFsfn6+51+E1Z0 fvg2ov6M92wKkWmJgq9UASYGFNpIQlldWZ/pq8lrHkyzDJdpZURdmaYHO1wexW4QvCms KDFNCD2paY499Z4MHhviViBkU7vIAstQVEa1gmdqN034ipmu2ekoZkiWWkClKtDmbFUb OUKJMoSSfew1ErC8EH/LA/NymR64LKs4SE5vLpHItb1It2tT6bJn/DcUsu3BYRfUgc8K TEJ81eqac1UPMenrckAjAPJqKBKjPssF9qkzSySNx4CTTza1las9cNmzO371EkzTlDoy +E1Q== X-Forwarded-Encrypted: i=1; AJvYcCXdNW0o2GYTsY0Wb/U0tnqDrMlTU3V/Cj8T0S2K9YkspTvXke3vYiJHJaUVtioM/gtvEYtRSHjy6ns1zK8TnI0QwJItp4fuCpRpJKZ5og7s/2j7LyM= X-Gm-Message-State: AOJu0YzNAfLk1uBPj4EnDbL5AWYXUt0+ZwxhA4krAwG5T/3lmLGi8otR q+zL0CKvFwyX+RLmJNu1+HT2HU0DXIyEn9iTCzRaxwpqufKYq94FfixdFVziMA== X-Google-Smtp-Source: AGHT+IHpV0wJBjkz/uiNnJbApuw4cK0JvcZtxkvSENnR0QDdzmWnFUZlqPQiOoJqXfr/mDKKEF4FGw== X-Received: by 2002:a05:600c:5010:b0:41b:4c6a:de6d with SMTP id 5b1f17b1804b1-4200f8b159fmr8618745e9.5.1715787657840; Wed, 15 May 2024 08:40:57 -0700 (PDT) Received: from google.com (216.131.76.34.bc.googleusercontent.com. [34.76.131.216]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42014c21260sm125210465e9.3.2024.05.15.08.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:40:57 -0700 (PDT) Date: Wed, 15 May 2024 15:40:55 +0000 From: Sebastian Ene To: Will Deacon 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, yuzenghui@huawei.com, lpieralisi@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 2/4] KVM: arm64: Add support for FFA_PARTITION_INFO_GET Message-ID: References: <20240418163025.1193763-2-sebastianene@google.com> <20240418163025.1193763-4-sebastianene@google.com> <20240503150114.GB18656@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240503150114.GB18656@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240515_084104_690778_D443CC02 X-CRM114-Status: GOOD ( 37.14 ) 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 Fri, May 03, 2024 at 04:01:16PM +0100, Will Deacon wrote: > On Thu, Apr 18, 2024 at 04:30:24PM +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 | 46 +++++++++++++++++++++++++++++++++++ > > 1 file changed, 46 insertions(+) > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c > > index 023712e8beeb..d53f50c73acb 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/ffa.c > > +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c > > @@ -674,6 +674,49 @@ static void do_ffa_version(struct arm_smccc_res *res, > > hyp_spin_unlock(&host_buffers.lock); > > } Hello Will, > > > > +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); > > This should be FFA_RET_BUSY per the spec. > Good catch, thank you ! I am fixing this. > > + 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 (host_buffers.ffa_version > FFA_VERSION_1_0) { > > The spec says that the size field is populated based on the flags > parameter. Why aren't you checking that instead of the version number? > Right but the flags were introduced in the latest version (they were not in 1.0). In 1.0 the content of w5 is reserved and this is why I need the version check. > > + buf_sz = sz = res->a3; > > + if (sz > sizeof(struct ffa_partition_info)) > > + buf_sz = sizeof(struct ffa_partition_info); > > I don't think this is right, as if the payload really is bigger than > 'struct ffa_partition_info' we'll truncate the data (and you don't > adjust res->a3 afaict). > > Can't we just copy the whole thing back to the host? We're not > interpreting the thing, so we can just treat it like a stream of bytes. > Let me rewrite this. You are right, we should treat it like a stream of bytes. > > + } else { > > + /* FFA_VERSION_1_0 lacks the size in the response */ > > + buf_sz = sz = 8; > > Can you define that as a constant in arm_ffa.h, please? It's the size of > a 1.0 partition info structure. > Yup, I am adding this. > > + } > > + > > + WARN_ON((count - 1) * sz + buf_sz > PAGE_SIZE); > > We should bounds-check against 'KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE' and > return an error (FFA_RET_ABORTED) if the size is over that. > Thanks, this should work I will do this. > > + for (off = 0; off < count * sz; off += sz) > > + > > + memcpy(host_buffers.rx + off, hyp_buffers.rx + off, buf_sz); > > I think this is wrong if bit 0 of 'flags' is set to 1. In that case, I > think you just get back the number of partitions and that's it, so we > shouldn't be going near the mailboxes. > I removed this, thanks for the review ! > Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel