From patchwork Mon Oct 9 15:34:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13413909 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76C82E95A9F for ; Mon, 9 Oct 2023 15:35:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377617AbjJIPfS (ORCPT ); Mon, 9 Oct 2023 11:35:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377616AbjJIPfB (ORCPT ); Mon, 9 Oct 2023 11:35:01 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23C15F2 for ; Mon, 9 Oct 2023 08:34:51 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-405361bb9f7so42847025e9.2 for ; Mon, 09 Oct 2023 08:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1696865689; x=1697470489; darn=vger.kernel.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=WT7V6AZ26cidOG3ruLe3K86NfrAEQ3oBaGfcZy0uWnU=; b=woYXjaalu9aIkvPxURRfbCqsZZKg8A1DQuPnzTNWvTT23IIlWuSUniowhaoiBVtuhw FAKnL06YGzF2nJSxH21ZZpquVHTclrZ7AxbCUrTUPoj2BTvbURLJBOOGh9PUEt6U9VYG jjg437gA22tZZ7KbHL9Nc4M6MH6aZhVa/ySBpwt9VfGt+tEPUZwr0/N2G9DyesNAAbFM V6swssNeH/vViLAV5r1WIjkPcsvrZin77yRYlGDDSMJ19Q6xJ2NeR4+aJMstgpO9PCY7 OovQAYRZWL+gePhGff1OBSe9TBwMdmp+dAz5mwddP01DksM6EmBKV/NeZLGkVEvxYQaf 94YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696865689; x=1697470489; 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=WT7V6AZ26cidOG3ruLe3K86NfrAEQ3oBaGfcZy0uWnU=; b=gyAn+S0NqMwB43QtaqCWmcjnJlRC5G7Wbu2wldaq9mOz3jIl8omjYEb5GANWPM8meJ 54JrOPx32c8weIP3jk+vpsWQN9eTTCHnDX3r/a9/7yAOScGYxldpG+QJeyW67zDIiXUn koItGeDFq7GuQZWuEYAVxvhtqjQ8BcdWteN+btInwIQxeDA6pYOkMumYZ+NTEmLrvhG9 2dIHDON4HvX1h0RmyhWRfknc/mNVlcJhNQ67WITpg+RtbmGzY60SMmOXiR7M0qvdIPa7 LkNinAGXQwivnxBihfszPTe666azHswF9xHMiYzGyerPOAVlz+pqbaW7JuXRTAGYon3R r/+g== X-Gm-Message-State: AOJu0Yy7VriHpiB8tZQ0/UgNi7DE8JkUCau4MKcx6j/vMd2bDgAnKkgy fGHbimEv0wAUeUTBfYPwPsts2w== X-Google-Smtp-Source: AGHT+IG2Kyg2+eJFy8yr/9Sv3Py49/NM5wcjqgfeeWHCRX3tIetOY73CKPk4pgTaDtvl/4eX4+JlKQ== X-Received: by 2002:a5d:58f2:0:b0:31f:f326:766b with SMTP id f18-20020a5d58f2000000b0031ff326766bmr13334322wrd.6.1696865689675; Mon, 09 Oct 2023 08:34:49 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f20d:2959:7545:e99f]) by smtp.gmail.com with ESMTPSA id b3-20020adff243000000b0031431fb40fasm10016521wrp.89.2023.10.09.08.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:34:49 -0700 (PDT) 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 Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v3 08/15] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator Date: Mon, 9 Oct 2023 17:34:20 +0200 Message-Id: <20231009153427.20951-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231009153427.20951-1-brgl@bgdev.pl> References: <20231009153427.20951-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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 --- 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 754f6056b99f..31071a714cf1 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);