]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 27 May 2024 12:54:56 +0000 (14:54 +0200)
committerBjorn Andersson <andersson@kernel.org>
Sun, 23 Jun 2024 21:08:05 +0000 (16:08 -0500)
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 <bartosz.golaszewski@linaro.org>
Reviewed-by: Andrew Halaney <ahalaney@redhat.com>
Tested-by: Andrew Halaney <ahalaney@redhat.com> # sc8280xp-lenovo-thinkpad-x13s
Tested-by: Deepti Jaggi <quic_djaggi@quicinc.com> #sa8775p-ride
Reviewed-by: Elliot Berman <quic_eberman@quicinc.com>
Link: https://lore.kernel.org/r/20240527-shm-bridge-v10-6-ce7afaa58d3a@linaro.org
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
drivers/firmware/qcom/qcom_scm.c

index 827985997a9c3ea18db07c3a8442c88db35ad88f..69557f551ecf52bd77be5b8d326fc66c11424ffb 100644 (file)
@@ -1217,32 +1217,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.
-        */
+       int ret;
 
-       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);