Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp898405rdg; Fri, 13 Oct 2023 04:50:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsf3nTuO6y4JSLXhxv0oLcV8eE9E4MrkdUxPoK2tTNrKtCWG/vtT5se/5bDGbgo0S9W2lj X-Received: by 2002:a17:902:f381:b0:1c9:dece:4c4c with SMTP id f1-20020a170902f38100b001c9dece4c4cmr5521511ple.15.1697197837296; Fri, 13 Oct 2023 04:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697197837; cv=none; d=google.com; s=arc-20160816; b=CoVeVpf8J2RqAfhRwak8NzXh3iQeeUJtEKh/8Wfc1P63CvcoOIFzhAPIQ7JGTpwHrq 9MYDixPjUfjljc3r8hBEQf/UUcF91SFyhDK1ZooiSMJWw8KKUWxdl+1hIQa0YsX0YHKR UaWa6lp9SYYQ1w7NCtqxFpl3oukvKgfgEkezsyKELs/d90VGPtobN7AC9uD87hp5+kAH 3CytK6mTMcBPDvNUUm+piMOwPHlnsRvQnE9XH2IYihLxTl+JM/oBq+wD4wqI+LnxBBiX 0VkQmQ4Q/ELksEYmwq/40lR0iQhYGZi+VHzu8hfASkJVFoa3/zUq8+3e/901ueC2582r vvZg== 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=o08KoJEp1jyjQ9dNvbb3XNbjVFJz+FU0ksbtua1h9kU=; fh=lirm1ccAeXZZB1cIo+N1DqklpgcFmD/vJ7PCWNIL0HU=; b=1C/7bnRyQW/bJLLC6CggngkG6t8e5gzK96ab9BaekHqNAy1+TFv5Fl3R+WPFFVmoK6 DtNxoKb63l41cZ2oVVGIAU3iJ1TVIbuoA5i+ehv7BzHy2PFyR7423GiFhK27sJUv9RGs 7zpRv5OnrSdYofAw/U2zIQBpmezHCy34EycTKCC2OJL3hPGgZit1ToDASyXMXEHZv7fo 6PnT+Dklju+7QDTKYdQU6l19esxqKpxRHqMyF2Snc/1ktvWOOmkyQBZlu3Kmx1mf7Tvo mYTgA/olAdjoQ3/FQaPf/Z3euvBEeO1jHgIC3tXyfeXLyqkZAffIEwMzvxlnT6DNycYW oKpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=vDaPYF+a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u10-20020a170902bf4a00b001c6240dec42si4106007pls.647.2023.10.13.04.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:50:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=vDaPYF+a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 36738826EC8F; Fri, 13 Oct 2023 04:50:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231633AbjJMLtc (ORCPT + 99 others); Fri, 13 Oct 2023 07:49:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbjJMLtE (ORCPT ); Fri, 13 Oct 2023 07:49:04 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E28D7 for ; Fri, 13 Oct 2023 04:49:02 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40675f06f1fso20095195e9.1 for ; Fri, 13 Oct 2023 04:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1697197741; x=1697802541; 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=o08KoJEp1jyjQ9dNvbb3XNbjVFJz+FU0ksbtua1h9kU=; b=vDaPYF+adfV81tK+HR46pTeOCItb18NbJqiN3VoqZhj0J91mxQToL1F2kK+MLpg6nO HtFlN0EdrSTRKkW3Bn5IXWg0wn6PM+NYtZ+0Igjil1Fw+tI/lXP65/Y+eDzIooq/gfEK 999c8k4hN1Wu6hrzM3+OL/AFj0lEeXATn0+PK1pwmEHvs88iWN2dkzUixwfFSkEUrjXj srwN16SEislxfNtn9g0x/uSLE81tBnBg+h+k4aOF/bTajESIc1M+8DrXRFmNdkD8jOI5 6HtbPld/DXHMxq04ZAEC32uCrTjkdbIHo6nDO3kkgKYdHj/xj8dXhewAFktYyNYNwVBA hJkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697197741; x=1697802541; 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=o08KoJEp1jyjQ9dNvbb3XNbjVFJz+FU0ksbtua1h9kU=; b=D4K91r9V9P/kVi+kusuTlEtqvrYbCnm5oziks17kuRBHp8RztKtLwzveOqDcDGEgSL o3D5ShfhC3jEU+YgNIqU2wqsSGY3k2ILCvXgOdMwX69b8O0+Hn2B8HznOF73Eh+Bs8q0 tUcluzdFoxJQ7t0lALtuzKntFopwkhByN8iTFTj0TjOMIa3xYypjezOwwySa1fxGz00/ CleDVrq2Qt3CeAydmcYAcgySwBuppUjsjyOkqZrGekdY9KVt1yogatUZb5l6QGcvaJga 9XvWS2vVh2NvPVn5G0rzJlgFrawuDZNC8Llkz/QikLDU/eHdM1PrGtiRstd7KypAYHau W9qA== X-Gm-Message-State: AOJu0YznzP+8lXphdNl1QpsIYZxhfQbYE0hrPpXQPxDytjgK1Li5LuUy jZmSw91XqS1V2hZbh8t+bJaKEQ== X-Received: by 2002:a05:600c:4f51:b0:403:aced:f7f4 with SMTP id m17-20020a05600c4f5100b00403acedf7f4mr20749395wmq.12.1697197740780; Fri, 13 Oct 2023 04:49:00 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4209:13a:988d:80be]) by smtp.gmail.com with ESMTPSA id j23-20020a05600c1c1700b00407754b998dsm974509wms.27.2023.10.13.04.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:49:00 -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 v4 08/15] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator Date: Fri, 13 Oct 2023 13:48:36 +0200 Message-Id: <20231013114843.63205-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231013114843.63205-1-brgl@bgdev.pl> References: <20231013114843.63205-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Fri, 13 Oct 2023 04:50:01 -0700 (PDT) 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); -- 2.39.2