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: 13413937 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 51B03E95A96 for ; Mon, 9 Oct 2023 15:35:36 +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=PJ9KqHft4ctVMalS3RubfezRetOse+JzdhkwoOpoCZI=; b=HswhS4vcYjZ4w1 Bct0cUxYA6SZ2DolexXBWQGpQbzV5QFBMUocqIpLqC5i9kZZJ/Fg2m3zEaEj4mAl4pygAJ9eop2KK 1787rzBgidGTMtS0HpgrD8ozMAnjBonWj7jsvGt+ILVauOgszw/Va5NtkE6+o1bDrQCcG7scrwuet YU8QwNSyRbVxN2Ur6xCsy7HpRva1Y4OkjiDd65Hh2/Ui8iP+Sk2xwjSS/5lTA60tIzwuIGeXcsuaz GurrWXRJHxGLr5HIw0/GuqWLQ/UbsdrnsRIfn4gcbzOywdKCtQyyAIBUJbSpAyK4q9S/PAuV831Sf k2/G7zmjqtVDzD0y/cCA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qpsHf-00B48Q-2q; Mon, 09 Oct 2023 15:35:03 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpsHV-00B3zX-2X for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2023 15:34:55 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-406619b53caso42956915e9.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=1696865690; x=1697470490; 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=WT7V6AZ26cidOG3ruLe3K86NfrAEQ3oBaGfcZy0uWnU=; b=yWIJGRYYG0ZaQxR+oDGVsXjInpR5iZQZiktU1ja2em/Aw0mHMkY8D8hNTQQscqpdsF +OcY6YN8mP0SRym7+rLoRYMNfJgqpo3gQEj+ILdnAHjOUW9q+MwYgL2FAbgnb9hWJhyb htQaqz8jnY8bndwyRu64Tw7Y0emeWVRvFK2Z/rtd4GtC6EPlkyqr4xSOKjhi6wxNwgAF ZfIbrLl4mpqKIle1KFqWGwK5qIVza8ESJxYG10BB2j+gbzTx46IPhkukLQtDamypCWeD RWoq73oe1S63cbakMjt+L9vDFgYP1HKQNo3zX8j0/IXOQZozQGGYi1us+ZgIhZmmND3k GS4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696865690; x=1697470490; 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=fFqO29T5CG/gr3+PpSjsd7adDV9mBIWp/Q+to3VfFPRvtAWO12LhSHtQOkNs6LUF5i 9rDgl3dTAmL3xgWHQ5SZvTWXBzQMNcfF3R7gkwJdN9Ccq1kwqMcs8nTVrqbURZGPYz7S E2SBb8b1P32R84yChj05TPy1WVcpGMy6qNy1/3OH+ppI/39reQl3OQiJDs/7HC8ucylD ADmGht5VxAeaK0Q5cJ7JeXZIVIuszpmTWOeKlovISGqii834TEY4alFwGHKtmoZCo3CM qj9KBi8wEUvVP4x7a95Z8GwBZIJYYL2vlTiTFsCqVb7RyZRwORmRkOQcVcfjnI3ynLp5 5jcQ== X-Gm-Message-State: AOJu0YziuIc0V8Kj2ztMQT2tJ6k36NtiOuKEOJYsqo2mhxieoP5NfhOF zrA1weKKCQlM08YF/QXiDr703Q== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231009_083453_824982_1DF136D0 X-CRM114-Status: GOOD ( 12.34 ) 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 --- 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);