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 8C5AFCD11C2 for ; Wed, 10 Apr 2024 10:18:40 +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=PCu8ldFghJnA7aVf4r1oWQHziW22ffivwqbhOqj8ivw=; b=f2x4p1D1ODuV3h D+YQapQI0QGsDlSjXSoRz3MCQANEQTuEMX5juDK3wOjiAge6v1orAxjm9rS25fhZFOcfJHXTnKm19 a6HARZcsMl8F+XjR9ng7UjHTpiuQK7DotVQ99tjwrTicTObXzlVAMkVsmeDrxtODHJ7VlMmeqwFJU JzUnyGXtwACSij2dox2Vdl0FdL2mXCz45kQ8IaWHhRTcmBG+SIlV5MQByoEls/7bp6nWqFT0h37cS kW6vyp/MZtC1qCfdp4BR28p+GZrV8bmCkRHEkXYtXt5kHpQCqPRv5wQO86Zj2kTHtX8jz+smbG5fx AbvhLhzWn482Lk4TP8sg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruV2B-00000006LrP-1y8X; Wed, 10 Apr 2024 10:18:27 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruV28-00000006LqM-01Xr for linux-arm-kernel@lists.infradead.org; Wed, 10 Apr 2024 10:18:25 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-41641a889ccso48835e9.1 for ; Wed, 10 Apr 2024 03:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712744301; x=1713349101; 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=vT68oS4RVQULaWAEFFaBC6rqDsXdkDc5eppWUMWD6Io=; b=nmoBbaCO1zBXNscYIcrI4uqO555rpwgzZrXoBX5Hli2WTWUpwjF1CV7FF6+z8QzG8J yZniCHTdklZKD3coL5SqpbBTOd6SzsZOPrsLGZx7eK3dNo0fZV1LXJO5QvCrmdtj7xaM jiAIt9ZPouIILKfpCNb3HpruuRb4AOAGtff0sEjW9X/aw0KIyOLV9tzvf7GE/82EoBci n4Y5fa9C5NiaZCU41Dr2jw4cBqyi+t2tyFaR76dM8KMNhUX7Ak1xQLLrNQNaSno8FTkB eZxRShr761YxSUfxDSdH1uChXtYLFrgcdiBTmkSOOMCAC8lfPhjGiTn0LoZMD04lD52p ThWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712744301; x=1713349101; 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=vT68oS4RVQULaWAEFFaBC6rqDsXdkDc5eppWUMWD6Io=; b=XMtyY4IITk53JA28M1FBB4Dk7ofVtCqvUM1XGwTet70cxCpDw6TGwvn9uIi6IJVViF 5UXaPIhojJ0nRo1OvSRNzdeqkWFbZCOc1BC+zLZH9dDi9fJUBv6yM/3nWzbTp9YrkBcn MYcNo2G8XzfqCPH6yiSrp9okWk/NuaqaZJdCNqt6v+60QhP4CeQe018k/JOy+5/Rve+y jdNRnbZRgjiN2dbnVCIgTNsEzkdsp+jUsJw+5duI6ktbkFWxotr5BqurDemcpyuvOBNC /K12OmyrvoZl9RD4jGxqoXylt2derYCT4Eh9VQ5Ssrkr/fmdHmhpvj7VllpEkWfd/6Ds 1PKQ== X-Forwarded-Encrypted: i=1; AJvYcCXRJxmG3evb2ZfRupG9z6RFKfHvUrXbbfPt9AWriruKmhElBPyp8mbnuJ45jKxIzARu3ESG1gS49IxcjPzDQw/xbd1CnQKu5T8Bo5CZ58VwJ8B9OHc= X-Gm-Message-State: AOJu0YyCpcLX4GvCpOvrSZHOaZ0C8dcyBgfphZ06spMSyiGGmifp1K1q 6enfhBBTeMrFrMM7kMAFRVD9uvRIzW0b4pL721PDDTdgi+jZB8yGnp5RE47KfA== X-Google-Smtp-Source: AGHT+IF04oIgLfak4zpgaHX/QvWLj2Gry8uOBqaulhtF8YFr4xta0pvMXzu6sMK/eZd+mX/Vi1I/5w== X-Received: by 2002:a05:600c:5105:b0:414:1400:a776 with SMTP id o5-20020a05600c510500b004141400a776mr111247wms.5.1712744300762; Wed, 10 Apr 2024 03:18:20 -0700 (PDT) Received: from google.com (248.199.140.34.bc.googleusercontent.com. [34.140.199.248]) by smtp.gmail.com with ESMTPSA id r6-20020a05600c458600b004162a9f03a6sm1832887wmo.7.2024.04.10.03.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 03:18:19 -0700 (PDT) Date: Wed, 10 Apr 2024 10:18:18 +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_031824_160410_B4F58738 X-CRM114-Status: GOOD ( 27.91 ) 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 10:53:31AM +0100, Vincent Donnefort wrote: > [...] > > > > > +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. > > I see "Return the count of partitions deployed in the system corresponding to > the specified UUID in w2" > > Which I believe means nothing has been copied in the buffer? > When the flag in w5 is 1 the size argument stored in w3 will be zero and the loop will not be executed, so nothing will be copied to the host buffers. > > > > > > + > > > > + 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. > > WARN() is crashing the hypervisor. It'd be a shame here as we can easily recover > by just sending an error back to the caller. I agree with you but this is not expected to happen unless TZ messes up something/is not complaint with the spec, in which case I would like to catch this. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel