From patchwork Sun Mar 3 15:01:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13579820 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 789E1C54E55 for ; Sun, 3 Mar 2024 15:01:49 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9xmxMK+Ri145R0uo5OO/XjckLFGC4AkpPe18TYUE7L8=; b=fSa0DEHkQfWXqG 9bEuKpCsvanqo34TlUBDyw3HsdWpr7MwHA++J0z+vN+sLtv9YEBk/bctjibE5G9rB/iv/7aPaBCju xehNen6dpMbcOO/uUL1AERZVPcD3U+fiIfaAVbwDOY9hCmaqUlDyWILi6trZAOOmcoQtJtwk8X6Gh dgarE3PA9+CpwfpXOmWNvFgC0JnbsfjBeNl/9QeFpCZBdwiiUA8iKdi45BWVtAZvzlMWDsKrNzryA sAiE+ULZY/ES8uoQMH9xAE/HkKT9U27k+A628yJy+xQo4zq2H5BgOtXNjdlQdRPDLPT3i2gm3LNFN QzpUWtUYNC8fqJeesprQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgnLN-000000068Kb-2W2b; Sun, 03 Mar 2024 15:01:37 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgnLG-000000068EI-056h for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2024 15:01:31 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a26fa294e56so646720466b.0 for ; Sun, 03 Mar 2024 07:01:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1709478088; x=1710082888; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fcH8Gs0ePK1IRGlv4zM5EcshiNK/rdgYWkudHAB0izE=; b=j+kdNkG/aGfYEZQ2m0zeF1JJgFsbtbnCD6Ne6fgcHE46SAzjnHyqhkV7kULF/JecQg Z0Y9BLz/EXFnzx6Y7jZaJjiB1dXUDCbsz/SMXtLhczWlo4uTH6iFTSQm3f9P7dhvos1V KmlzsLAAz+oYvEvXI8YDA2YYT0UpN8BTVbJYkUXHwBEOiATbtHsPK4p9ytSVkkmKysGm n00M/HTD9sFLW5m7HDqRSXsWPkBlsmscL7A3ycGfmzJMbMOZpcAjNeCNHx8ffFJEQny+ TYsh9r1JD5ykHV4pjeoYWCbzlyGiOn6yKjX9AGgcTCReoRXJAljd5vJ/TUgtiftUxgiD Zc+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709478088; x=1710082888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fcH8Gs0ePK1IRGlv4zM5EcshiNK/rdgYWkudHAB0izE=; b=SJewrC5GLSVNSoq3Z8YPoQ5CJWJZhOBbCP1zOukVBUyCAnuneuO+bm3uY6cvOb7CzH 25YsHCCQ9NtqUAj2e+D5hIKHhikUDcQDOMPy79uRcB2FErO032UDovMbL4UVvY8WELyu 540dSWGmmgPmcYzQRl4a9GpLdIIhqflGh9Y7RliO0eNcaDYJDW/92LwAjzPGThfdIgWr tnrmEfuFR5Am7k0DgsaOxaH/bJAPCq9Ws6tQQS/W5tyPZLitweW6t31+UoIb7rfsfj+P EhRSfs4B7u5UJXbDMGCVBUMoiFF9OdsKISW7mkpNWxNoS9lq4OoMrQY3DvyiW53Ct6bW UgKA== X-Forwarded-Encrypted: i=1; AJvYcCUMvvHBd8Uq8SCg8rhYCsJKXdgjINXx2zpw+g9e6IYD6O+uIIUOQs+XIUyT7QR1KpNFt303g9pIkxI/x1xngqEoe4FXJiRVKeXrnkUII6aXYFVdlYw= X-Gm-Message-State: AOJu0YwmEDHdp6bFnkigYckJRVddxp0jQdpv6XNdUq9dM+6KqWIr+JCh NbJP69WxqaU/0OzwTEGLELU/jDErUi4gw1Sp0xuu0z5eki+x9lfdNbSPtJaIc+A= X-Google-Smtp-Source: AGHT+IHvinUrWnb2ODBDZj/G27wn+bgJ59fftISqEVUtBV74uxy7DphSvelwNQdD7qV6cUmJJn5hPQ== X-Received: by 2002:a17:906:3bd5:b0:a3f:ac54:5aa1 with SMTP id v21-20020a1709063bd500b00a3fac545aa1mr5265556ejf.21.1709478088194; Sun, 03 Mar 2024 07:01:28 -0800 (PST) Received: from brgl-uxlite.. ([77.241.232.10]) by smtp.gmail.com with ESMTPSA id ch14-20020a170906c2ce00b00a42ea946917sm3740293ejb.130.2024.03.03.07.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 07:01:27 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski , Deepti Jaggi Subject: [PATCH v8 05/12] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator Date: Sun, 3 Mar 2024 16:01:08 +0100 Message-Id: <20240303150115.133633-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240303150115.133633-1-brgl@bgdev.pl> References: <20240303150115.133633-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240303_070130_102953_9D4F64C8 X-CRM114-Status: GOOD ( 11.89 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Let's use the new TZ memory allocator to obtain a buffer for this call instead of using dma_alloc_coherent(). Signed-off-by: Bartosz Golaszewski Reviewed-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 054b538828d5..50c574fef3ac 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1197,32 +1197,21 @@ int qcom_scm_ice_set_key(u32 index, const u8 *key, u32 key_size, .args[4] = data_unit_size, .owner = ARM_SMCCC_OWNER_SIP, }; - void *keybuf; - dma_addr_t key_phys; + int ret; - /* - * 'key' may point to vmalloc()'ed memory, but we need to pass a - * physical address that's been properly flushed. The sanctioned way to - * do this is by using the DMA API. But as is best practice for crypto - * keys, we also must wipe the key after use. This makes kmemdup() + - * dma_map_single() not clearly correct, since the DMA API can use - * bounce buffers. Instead, just use dma_alloc_coherent(). Programming - * keys is normally rare and thus not performance-critical. - */ - - keybuf = dma_alloc_coherent(__scm->dev, key_size, &key_phys, - GFP_KERNEL); + void *keybuf __free(qcom_tzmem) = qcom_tzmem_alloc(__scm->mempool, + key_size, + GFP_KERNEL); if (!keybuf) return -ENOMEM; memcpy(keybuf, key, key_size); - desc.args[1] = key_phys; + desc.args[1] = qcom_tzmem_to_phys(keybuf); ret = qcom_scm_call(__scm->dev, &desc, NULL); memzero_explicit(keybuf, key_size); - dma_free_coherent(__scm->dev, key_size, keybuf, key_phys); return ret; } EXPORT_SYMBOL_GPL(qcom_scm_ice_set_key);