Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1974065rdb; Mon, 9 Oct 2023 08:36:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeeR+1i0NSTFUQByjssFlanZLKwc7VAZS7gIJUZ+fvgLluBGozMBdsfMVR9W3GBimIbtD6 X-Received: by 2002:a17:903:184:b0:1c8:8f61:967b with SMTP id z4-20020a170903018400b001c88f61967bmr7592802plg.3.1696865802003; Mon, 09 Oct 2023 08:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696865801; cv=none; d=google.com; s=arc-20160816; b=LuQJ7EsmFzhrfO5EAl3l9cCoeEhzXBXsaniwYw8Ao+DTF31e3Mf+FOwA1Czoz77S4K dH1As7ZAv02KYPbeVlMYMy+Upe2mHjmrGPDPyjD5LpoPpswY3SrSHPeujfN/BLcNo3m3 A2HopAg/rwzQJfeNVI0Oodmzcoo5nXEZ+BunOLSFDNLqofMeBlrZFinYxVETw1qAz1yz Sr24OwCiVAN86ZYJWXU3vDKNwCGrJr92yHMZpcdD7q5FcoCkF0By9RqeMNOAjPHs6GVJ wFcxOTQFWPhJdF+Fzak4Yr7rae5+5tYJ1WB1CPYvXlcEm6ciHulg71W6JH2veQuwGLvv Slog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WT7V6AZ26cidOG3ruLe3K86NfrAEQ3oBaGfcZy0uWnU=; fh=lirm1ccAeXZZB1cIo+N1DqklpgcFmD/vJ7PCWNIL0HU=; b=j56HBbxoPFBYl/pNRaPnp70XacD0oTSIVl91JLk12KV8lfT8GL/wn6hEPbxUwCyifn Z30oRWtdGj8tSxPYrzjqU4TryddsWiQJi8k7tgKqsnOX1lctq2aC0ALJKdyF2JNRkgM9 TD6zRCHiO1G8Qfq/p2pw6kiFgXNpHF84eNQQBPQRnV+3ChxCZn7QAC7CJ9l/rX6lmihb p1O6ZYw7LbG2VDM5YWgRHXEERyE3ZU2GJ2pYK5CrLqMGPfuFpl0HklDf0lTJjYd7/oKJ cKgZ+FIRSua3o7drIf5o5TyEV2ewRW0mT+1zpNOruNqwFU9EFoMuEmejmi5FM8ByLt5V nZtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=woYXjaal; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id b13-20020a170902650d00b001b9c3498526si13269plk.433.2023.10.09.08.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:36:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=woYXjaal; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id A2BEF801C4A9; Mon, 9 Oct 2023 08:36:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377736AbjJIPfZ (ORCPT + 99 others); Mon, 9 Oct 2023 11:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376940AbjJIPfB (ORCPT ); Mon, 9 Oct 2023 11:35:01 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33884F4 for ; Mon, 9 Oct 2023 08:34:51 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-406619b53caso42956825e9.1 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=g7MiYtcSxnXytUUx9n3CvTl6dWhSeXsZUANchBjiRNJHfCtCD0rPsPLIrexztjL6mM Tcom4LZCBSzZaKyNCg2pmrO22gvZYPNYK3zWp3X+jkKrM6pZ7pxp3zoUwSwy/V9IdrcW LYiB1zEBp9Lqbq7zLbsTpUYlECtZb7/6QfkOSYHPjyUO/WUK25DR76MJNdhFWBm0/IGr uR3BqsEhMYyG/jmMazvYt0NCr//LW0cNtvg2/IxpOlJgmS0tHVomU4CYNC9MFT0ApZPc IoR/HkAz2mbdyvGL37RxDsnLqTYvt7SOzEb4wCdO82heCJnL3Px55rddzw4GQWO+ssTr Ez1w== X-Gm-Message-State: AOJu0Yw6cDJNE7pb5BdyQH+Do4oh2SPDeLHtaonNInOpDJAYmbGDVo9N TeWZFlLgFK+uJm7WNgfROX+vdQ== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:36:37 -0700 (PDT) X-Spam-Level: ** 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 --- 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); -- 2.39.2