From patchwork Fri Oct 13 11:48:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13420788 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 34426CDB484 for ; Fri, 13 Oct 2023 11:49:54 +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=UWUv4Hg7JrnsYRXFWLhcaTsR7GS2MEaHN5tcMI23SLo=; b=0SlFeMEc6X/ifH yd4RSZuotSsM4AQ/xtZDuvy7AcEtkVdY+EFtfW1Oiq7KUPVKcudATha3oZaVRtkPRDhOwC59OkF9q U+ObV32qFe7X66HBQw7XdtrAwUaaL3jwDLOWnvZIaySiBxjCMDbcq38a0n3zKCbN8wlRt6D93avcc q1HDOcjvE+iA5DQvdzp6abAD4VIgJ0a2PqGVESY3x6feRRq4+mK8Vvod6vFhxi4OqBWplpSKc6ySu tSz5Oobk6BcYYvt68KRHbWqHQe3SYSJY9/9SHlz2P3vwz5YYjb3ZFWaTLKeHcJN0YQRaroUeVjkNf cTGDfLYbTu43OrpupeIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qrGfZ-003Lkz-1X; Fri, 13 Oct 2023 11:49:29 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qrGfC-003LST-1y for linux-arm-kernel@lists.infradead.org; Fri, 13 Oct 2023 11:49:10 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4060b623e64so13096505e9.0 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=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=o08KoJEp1jyjQ9dNvbb3XNbjVFJz+FU0ksbtua1h9kU=; b=OzUn3ICVn9dTAVbdandVRiCvdAhlyMi5oe6N4cWUc2lAerpFjrTXy0/kR54fmUN5tr tRgxcTZG0EL1W47OxvwcivN1ldwS7wGfcD+tMHIFKrv8V31/xgHutQHZglbt3maHaA69 jxCCrOROAJDK121zSYjN0eheQ8dbC6vAjgd5gX+6AkQi4Z+Kc2ii4qBQYZSUg+5+54VF gySP7QcZTcgybFyumghrnvKYvYlgk4+IllIKFgXva7tGdF+1iFFCUvTZN/QvNLJeJYfH 1Hy2JYsogajLv0gUtozaY/KNJ7nvhA6588DoNP7ZPptI2Lq5ghGWns2JH1UW845Q62B1 xXGA== 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=l870/cn7wQLAjrbqKCfbwXaMYPreOvMvhFfo48PwAJts/74qcenn07oir7sy0tm+B/ pAyWPKl6IVfhDUCvxLOelJtOrUA5YwockK9L3L35MNhFFOe4DuzPV1eGL09ldq7cJRH4 9gudb+oI6C7ZEcPilSZucG5Ic6EdpwjAuVGwMjcmSXofawfXbMqLegEvV0e3No7IBIix QD0nf6Jo+nTTANThgYBNSyaRq7CTQpPhIcwM+0zct1eK9U+0wzZV8sJG8GhQfd7RzXJx f2RUrSVZ32GCJoSGGpw6W2j1elv290ijf8fLxixpt7V2+VHY3T2MbHOuvO23BggXM0q5 04tA== X-Gm-Message-State: AOJu0YzvfEY3UntXQwYdyHZRvTtKzN4Kx/nHo0HeSvyvJsVzN3IqWDLY o6EAxpGUkTWiF43MFGSqrVnD4w== X-Google-Smtp-Source: AGHT+IESLcsz5LctZsBuJll13spdgRKIkc+P4hRt3xAF1eR7x09EBzVgQ3xnO+6UB5cR8FVzALdv8A== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231013_044906_667997_F2D15D87 X-CRM114-Status: GOOD ( 11.82 ) 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);