From patchwork Mon Jan 22 10:21:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13525123 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 3B725C4725D for ; Mon, 22 Jan 2024 10:22:57 +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=AhkFoHTLj2EE74eIijXhMz2kPukwc7xpEnG6QeddNTE=; b=4bNoBSPrSS4o5X mkMeSc00/kQ9GkelfLMQklJpDQ/XM7deTsWpqga2QMHrIMb+3LO7bl+qgA0whi0+Ct8GOcIX+TLYA ZSDIr2jS5Lwd3ox8JIlTxRrZOv9QmBbBk8kibu3dtBQF4EhrSbOV2mE2FDg0IniFopgQb1eC3MnxJ MaK+bgTfHJs+G8ZDl2xKmXId6r5/NlTOW3WT/XNycDOD/PaOFex15C6nEYOQoHutHmErTcIezpbec JFsNCdfuzyy2ojqpvQ4T4yORrw+a9oTUlcB4pUnoQbnvkxj1azvot+J3HOo25eyniysFkOyvmmjOP ZhH8P3Rnz6/4bVVAH0Jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rRrRi-00BUev-11; Mon, 22 Jan 2024 10:22:26 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rRrRb-00BUVD-0b for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2024 10:22:22 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-33931b38b65so1014635f8f.3 for ; Mon, 22 Jan 2024 02:22:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1705918931; x=1706523731; 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=/tupJ2FnxBizYD8gOKKXQjNXDQsDvYn5mQ/R4h0dASo=; b=zZwA/FgTzZyPkunrYvbU++8K6jlRA/ps3CeRlPqsUJlDvPfBqo847iNxKcHW4Oc+fT qOHqQmx/TBB4d/kqaA3gk1a/rJwa1AUYfcwK5s8arOwFxrGzWbXHAMrrNLHjFcwi7L9H OulKJfqCvPsIOsopDAxdhS0La4H+YBPqgGzFZmaxdArvNZpe5jyXfqn9On4hu6I0BFT1 61Aa1SVC39Y25z8KlBQ5a9ELX1+plYxupfvf6yihDpI/dGtMnueB8NYRtacZDm6i6D9H 5klC6C2YZg6woFxxWfDDjoTkn8yP0jl/R6s2ZppaeIYDUXejJWfVQshOjAJbJsVw4b1M nkGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705918931; x=1706523731; 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=/tupJ2FnxBizYD8gOKKXQjNXDQsDvYn5mQ/R4h0dASo=; b=t2p4qCxzedlMvkqgSO5KNWn610whvDg/DIU5PYW1gz1cE+bFsaVCCfZQqk/57gkc7r eyG302OcZR7TXthy+63rBP0njj0YLbsWmVcPXJ14RWQrYoFmbWMOGCYXuikQh/Un9Z+F ul2vxkfYOIZ9iGkr+TceEog7zAO0glGhddt9uW0M5bOSdEzeRmUOu6RJ5WV7wN1sJbQP G2tUBItP9+xjVygfe2r0h75+LRh1GudqGXhuFLvLAFTGmLy9A3DLPC4KPpDqFhS/OtEj pLrcdhvNYFPC+RojkQyDcLER6Zt9eTAJb1RFF9iGXO8vMGR6vB7jnaO8ZcF8G11UY6jQ 6YKg== X-Gm-Message-State: AOJu0YyjwNd4nUGjrr+kSw1zaCif86x7s9foUPj2Dc+YJ4hiOWiLfCSX LR5U6NxxHJtrs1SG3OQf4nsmZzRWx6YRHlGrh9uoXjFoKS81ymK4tzlKbCUflPM= X-Google-Smtp-Source: AGHT+IHo7nxQqV7rDJpw1IjEjwkuHZwdD5i1xwHKtbpOagmrOPEHHHS36P+daOmrbwgOkTmUqq/oig== X-Received: by 2002:a05:6000:104:b0:337:ac2c:cfd9 with SMTP id o4-20020a056000010400b00337ac2ccfd9mr1168674wrx.196.1705918930810; Mon, 22 Jan 2024 02:22:10 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:92a0:6172:d229:1898]) by smtp.gmail.com with ESMTPSA id q7-20020adffec7000000b0033926505eafsm6377904wrs.32.2024.01.22.02.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 02:22:10 -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 , Catalin Marinas , Will Deacon , 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: [RESEND PATCH v6 05/12] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator Date: Mon, 22 Jan 2024 11:21:50 +0100 Message-Id: <20240122102157.22761-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240122102157.22761-1-brgl@bgdev.pl> References: <20240122102157.22761-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240122_022219_258093_6CDBA062 X-CRM114-Status: GOOD ( 12.52 ) 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 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);