Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1712446lqb; Sun, 26 May 2024 13:46:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUf12fnQd55Msda3EHD9IFLlv/SoZ2qanXdQppUdjkndIY/k97pin5HESrJ3xN2amIJjAyeRR5TuS+f5UNFpO9QqSfxeiokujSuOXTZig== X-Google-Smtp-Source: AGHT+IFWglXxoAdYcdoRQ3XdRFE9LQiLVkzI4EqJwnbYDmVVQQhulKF7c5IhXTc9PMiwfg/hJw1y X-Received: by 2002:a9d:730e:0:b0:6f0:2e49:b1ad with SMTP id 46e09a7af769-6f8d0a7389cmr8339397a34.9.1716756391078; Sun, 26 May 2024 13:46:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716756391; cv=pass; d=google.com; s=arc-20160816; b=RWyJfCOmoq9p60h2JIQDNasJURVsfhgSU2ddP7C3sIwi6kPx/0zffgRf3LjxdrMUs8 Rg/VEXYeA8XR/XPZYY8g+ZJFvi7hdAy+bwfokWJPgld2jpqLzZqEK4Oz9sD1s9YSy2v0 BPi8dBjnictL5i2bvnYMUFmOi4777ruyaB9niPEfr3hDSuJwOjb1ur0P39QvMB2luS71 w2zJdgKBPKOz71TgLv0HR2exejCEIkNTSv9KE5VBbkcYWQTzmnvs0ZPbA5Klt0l75WHe J5xVBb1vn3F59GIxL/1WqRnhAv8Swzu85lSmdu2SVyAUk5dor8WwTNBuRROcSgFSGvHY u48A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=olzLsgqFKH6QmJG3VKpKMY6MsX7VlqO82UfDalm5GjQ=; fh=DKtxEIyLlwGIMkRiKPBtWpk9t661FxZYkfvBHoMaO14=; b=yLzphRFP/uKpFv7FQ0iUlgmMtcPFSbTHFrWRHYbjqy31Xe8hUZN8PmcHZ3k0Av2gc2 4lV8TBxZvh9gUopggD8gNyo20y4EmaB2b5J3KbZbLU8oyRRdCIilXwLV7V9CuomI0hpN wWNLvv4/ERJOL/Tw+++sBfD59ezv/yVvSAmuH/3gxeaZPH2UquzHpDOlz6j/OISVfBVT Q0zRL7Tlv2zoKb2bTUOY4Kq6aLHpng4QZvB9v9t+fgnVN4SyMLhDcP6Vq+ZwWEwhOTKN 6UN5dNCEU5KtaHQtzDRk2iTeHKq/9td+rse6P12EdfiCw/G+Oo8iVJQM/LoPpakYzIQS 8LKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IsmZax6Y; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189867-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-682288e67desi5027771a12.443.2024.05.26.13.46.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 13:46:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IsmZax6Y; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189867-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7A89C281165 for ; Sun, 26 May 2024 20:46:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CD3A139D11; Sun, 26 May 2024 20:46:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IsmZax6Y" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 442B31A2C26; Sun, 26 May 2024 20:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716756382; cv=none; b=nSOYSSYVI2yesFCHRlgqzllG8GgNgyPqaEzKSBkbMluFgX3qcrcN2tpB8gcq6x+KssNquFyBMTvbWDgvghSXRDblYs41kBz1mssB8csFXXHel25jmtVD07QW8xDBLJlltuCP1zXFJbu3yjKr/TEcu+QtYjuu45kfrD23l/XWOhA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716756382; c=relaxed/simple; bh=rt+luzDKVTP2ZR/sRuF+JTDWUKx2Jda97Licl23pJpU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AWK8jRMpAJeVpIyKpsBSi2hJgMAqOs+XiIWjCT2Cq6tsB2soRPuxR66yTbsAE4ciEaWGicr9zAYGcvAwF0mJySK/BOf5EhmJsdJfFkuR5ZKhnrmXqE2SOM0fBQIIOlSKW7GTzT1ElIj9H59HAN9xXhWbhSGGNCCZMc0eeICSMek= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IsmZax6Y; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 675ACC2BD10; Sun, 26 May 2024 20:46:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716756381; bh=rt+luzDKVTP2ZR/sRuF+JTDWUKx2Jda97Licl23pJpU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IsmZax6Yx3f5lNdSyocfqc+vTxOaLnwtvDKqz5V3HtPnVgOrV89wB9ll0CYKii5zG ZG7VvqrRdVLGI1KbK4zbsCly7pQhAnM8zfJ7qf+hqI9Z3seImnu0fFwWDFwV/5+hrw EstKGuzt3ozMg6LmBn+rSdU3Lmlf/Gpg97NBHAvvyjF1AR/BjRUjjHSHxZuoJgU8kI C6jWEQzs1QJvB5VAv1HCpBor8lKehM5UGgJjRk15mRXr2Qv4i52ZyQgVQW3vfKZzc6 pnfl5WBQt/dHNs/K4AXmxwdR3mxTzkIABqvoJdfukqSpGuleXq45+Gx3DjtJLZUXeP RiRavu8oB1J/g== Date: Sun, 26 May 2024 15:46:19 -0500 From: Bjorn Andersson To: Mukesh Ojha Cc: konrad.dybcio@linaro.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] firmware: qcom_scm: Add a padded page to ensure DMA memory from lower 4GB Message-ID: References: <1716564705-9929-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1716564705-9929-1-git-send-email-quic_mojha@quicinc.com> On Fri, May 24, 2024 at 09:01:45PM GMT, Mukesh Ojha wrote: > For SCM protection, memory allocation should be physically contiguous, > 4K aligned, and non-cacheable to avoid XPU violations. This granularity > of protection applies from the secure world. Additionally, it's possible > that a 32-bit secure peripheral will access memory in SoCs like > sm8{4|5|6}50 for some remote processors. Therefore, memory allocation > needs to be done in the lower 4 GB range. To achieve this, Linux's CMA > pool can be used with dma_alloc APIs. > > However, dma_alloc APIs will fall back to the buddy pool if the requested > size is less than or equal to PAGE_SIZE. It's also possible that the remote > processor's metadata blob size is less than a PAGE_SIZE. Even though the > DMA APIs align the requested memory size to PAGE_SIZE, they can still fall > back to the buddy allocator, which may fail if `CONFIG_ZONE_{DMA|DMA32}` > is disabled. Does "fail" here mean that the buddy heap returns a failure - in some case where dma_alloc would have succeeded, or that it does give you a PAGE_SIZE allocation which doesn't meeting your requirements? From this I do find the behavior of dma_alloc unintuitive, do we know if there's a reason for the "equal to PAGE_SIZE" case you describe here? > > To address this issue, use an extra page as padding to ensure allocation > from the CMA region. Since this memory is temporary, it will be released > once the remote processor is up or in case of any failure. > Thanks for updating the commit message, this is good. Regards, Bjorn > Signed-off-by: Mukesh Ojha > --- > Changes in v2: > - Described the issue more clearly in commit text. > > drivers/firmware/qcom/qcom_scm.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c > index 520de9b5633a..0426972178a4 100644 > --- a/drivers/firmware/qcom/qcom_scm.c > +++ b/drivers/firmware/qcom/qcom_scm.c > @@ -538,6 +538,7 @@ static void qcom_scm_set_download_mode(bool enable) > int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, > struct qcom_scm_pas_metadata *ctx) > { > + size_t page_aligned_size; > dma_addr_t mdata_phys; > void *mdata_buf; > int ret; > @@ -555,7 +556,8 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, > * data blob, so make sure it's physically contiguous, 4K aligned and > * non-cachable to avoid XPU violations. > */ > - mdata_buf = dma_alloc_coherent(__scm->dev, size, &mdata_phys, > + page_aligned_size = PAGE_ALIGN(size + PAGE_SIZE); > + mdata_buf = dma_alloc_coherent(__scm->dev, page_aligned_size, &mdata_phys, > GFP_KERNEL); > if (!mdata_buf) { > dev_err(__scm->dev, "Allocation of metadata buffer failed.\n"); > @@ -580,11 +582,11 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, > > out: > if (ret < 0 || !ctx) { > - dma_free_coherent(__scm->dev, size, mdata_buf, mdata_phys); > + dma_free_coherent(__scm->dev, page_aligned_size, mdata_buf, mdata_phys); > } else if (ctx) { > ctx->ptr = mdata_buf; > ctx->phys = mdata_phys; > - ctx->size = size; > + ctx->size = page_aligned_size; > } > > return ret ? : res.result[0]; > -- > 2.7.4 >