From patchwork Mon May 27 12:54:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13675200 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 D4E4FC25B74 for ; Mon, 27 May 2024 12:58:23 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5E98RlEeRNqsrCVZBYHRDVhN59mVytu79iRRporPE8A=; b=ndzFg9i9BebjGc 5mLDe1lgyHs9eI/abJvNztFOYDCGRnHazrQ3qWxmG+4W2ID+TViU/p6gNsFcZ6zAx4HSGjDZDcaFe G6uj3uZL2ZB/1xH3gRDiQIc2ctvG77tVTJ9OwVQfavPW2TcHgsX0KpfeW3l6T01h5q/XoSWcNEeNu pRTMeSTc2jEUVrLIcMKJLJs2/yF2HX9HbdWyAN+QJwPYaxHxsGEbH3LrDsSvPdVBSstuQjFWRQy8s B+ldpRxWpxLA4wi+eygS6khd5NkN6BEBrY8tVU+x/BIMUOmjqwjTNNEjtgYaVLTaRmuqOdjSStGz4 ciqTSbZ7ypwJq0GISvJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBZvY-0000000EyNK-0x9y; Mon, 27 May 2024 12:58:12 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBZuI-0000000ExbE-3dof for linux-arm-kernel@lists.infradead.org; Mon, 27 May 2024 12:56:57 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4210aa0154eso14690975e9.0 for ; Mon, 27 May 2024 05:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1716814610; x=1717419410; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hwqjl/ua5BMkegCLuGyA1/eY3rbR4AbTFjr6wje8pn4=; b=FJMEjyAI3YtFarN6a3BRu6jb2mRYBvOL0Bf8hwCpO7j6g4l00UPLHHBxNCPv5+q17u BJBJF9FwbZaYlu3XSHBSpCoPQrPR+2toXCocjrISK99IEAsNuiQpbZbbnW5ysH2RWO46 z8tnVmvqG9eKCRSEn6HNQCz7Ts1K+ZeDr5bjqGIlnqTEvLLDaGIyXD+Fp3ywKdyUuxN1 5Zs/kwN+EKiOdoq82rnmmMhHAAFtXZBGjSLNwnBhc6XXNscS6IQyYQHHkO6nTm01vUxf dvxPSjCoeZD0/61Pmq2CjzPzr99EzmXqXVZTH2Hd7EEtxV4S4/0YXBfsv4inC7IsgBo2 /xxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716814610; x=1717419410; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hwqjl/ua5BMkegCLuGyA1/eY3rbR4AbTFjr6wje8pn4=; b=A/Nv1/BeuS5K6YcTjPbGrn8ieiEcWwrcbfSNyAnUAP/TkyfDSY/8b6tT0UpC76H6de YHpEXcX98xNOxfP7y7l3N94jARbcYdA3aAwu9+rpMTYynBfBt8UeWClO4X2mbEqApLW0 R+Telunhl14cHu3Eeu3XVMmT89B7lEY1PgkRZMWAgUisiD8nMNv8qGw7T4pX43j/Hix0 XsWwOKul1VTnT5FSAeSbQqrd2ZU2pqnNJytIu+bJhEh95vY1eHU0zOxJUSSDi3t7OjRx mgGHQVvGrtw8hOEKOUOkncnh0sCFu8y+tHwuDL1gydi440gQCn/80FVZPVihxdlhhtDd E3kQ== X-Forwarded-Encrypted: i=1; AJvYcCXwFUXw92in0RLWof5E2wtd0QR0KX2s7ACcS9TCTOcgQkohsBl7AW+l6zOVye5tq5nMq6DbJYVWXfqkHKqrT7c6tJV+HoNKHuMXvSH/5JRq04KWBxw= X-Gm-Message-State: AOJu0YyZc3UiQeZO91u06OlfMMU/WOZh2Klihw839x4xDhXg8LhjlICR XBQ/LosF/62KrMfWv7qAzPuY1WPzlUSpe2PykFw6JJdCINdQRTDRn+eL628iegc= X-Google-Smtp-Source: AGHT+IEkkOnfkm2D13BrEQ3/361Fm2xiC1eRGcXiFJMGscUWHvqf4qBhm46RUioe2i98CYXq1xagcQ== X-Received: by 2002:a05:600c:4fc2:b0:421:1611:cd8a with SMTP id 5b1f17b1804b1-4211611ced2mr17280225e9.4.1716814610493; Mon, 27 May 2024 05:56:50 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:75a:e000:c322:131e:ff9d:ef41]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100f64f98sm138753635e9.24.2024.05.27.05.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 05:56:50 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 27 May 2024 14:54:56 +0200 Subject: [PATCH v10 06/15] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator MIME-Version: 1.0 Message-Id: <20240527-shm-bridge-v10-6-ce7afaa58d3a@linaro.org> References: <20240527-shm-bridge-v10-0-ce7afaa58d3a@linaro.org> In-Reply-To: <20240527-shm-bridge-v10-0-ce7afaa58d3a@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robert Marko , Das Srinagesh , Bartosz Golaszewski , Maximilian Luz , Catalin Marinas , Will Deacon , Srini Kandagatla , Arnd Bergmann , Elliot Berman , Alex Elder Cc: linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Andrew Halaney , Deepti Jaggi X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2079; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=MwBEmBbakFP8mlp72MFfpWCULQKICitWzxgwxI2nn+U=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBmVIMJUy60Czjqag7xEYc7ahX2YHMBSOfNGP/+O 3e+knl2ozuJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZlSDCQAKCRARpy6gFHHX cpb7D/4k0RoNmUPSLf9pVkBFfOLzL5VCbdT/rLt9zoANLGewCzYTlfvevPcAPxYcnPdVNxNOOsS 3VXMio/WlodYtrHhKM1jf3/YJxMis4vXMvQheuHxFiBah7735lA0IDUmZV0Y9SBMLd8XMYbzLIp 05gFaSIZkhvLVzzRNquuPq41VZpPpHFZnK2124ftvaesthOzdGPenn3F4MMMHunTtIaURjWEmJe 5exqKcCw8mtxtQhVw9VngQROJKUIE9xTf/8I89j0ITxquPXgPawilUvC3imwaIYv5o92UN75oyZ het5o9/XtuuGCnPl0dw8gA4hcOe8SJiZDoQUVAXp8/DBlW0JpsbnWmcioV8DfYHq5pHy+Xp/Ogb FTbgrA604bdVrYMxp3NBb/+ciCfiJEzUsTOQBbQ77KJblwh6ga81EPQlvAXriK8lKFKhOAVcpab q2kHrKK2NqesBOqKjrJaT1IjGe7jDA921eHyEAXZr0qw27EWYtt43O+7e3s5dyB0fBwU8TFr4ra SIlURWmItONYJRVfOhu4IzwRq74cpznca1b5sIksYOPsU0e4M4VNUTazf1rt1WBfvGGGrb/CnlG nEgnrJBy5fujQNRDlszNtrIhBemtxfigF2MQZGxyYpe6pzZ301OCp2a2KX0+ZVlntNF+QuKMQm0 +uP6Ntt5HyVprvg== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240527_055655_180036_51CB00A5 X-CRM114-Status: GOOD ( 11.89 ) 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 ea4d71bb0ad3..2c350de1df07 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1218,32 +1218,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);