From patchwork Tue Oct 17 09:27:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13424896 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 679A9CDB483 for ; Tue, 17 Oct 2023 09:28:40 +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=FWWkl9JL4tLvXA3qvbbMQDyMYVJsBcwyBiF5k3/BLx8=; b=E2sQC1W6SO9oSP xrlSN8Z15WIEE3yXieUF5QPWk73k8rjXEeWzVmddEzcMLKvMOPLYxKzSMQbBXAIEdFS7i9FWpZwzk ShpbnJOCs4HbSDN4BPxRFefD8YqUno/o/CseYoce9XRG/5452XTpeCx0zSfeDs7CMaNwEe6LqXds7 fXElXLX3D3rwRRSXx/Q012eEiAJZEbNzp2unvJZR3IbhlM1FdM8PXv3t+TSTjH6suLxzGFo0B5e6L 1li5cx9ZGwUQToxuIDE6eyT8ejQbebZ1ZltLWfRSx6tHSB5Zgm1sdpmNJO2Ue5to5ipeir1zNdjDh ZXS7H5F8spph9OQtvykQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qsgN1-00BoT6-0b; Tue, 17 Oct 2023 09:28:11 +0000 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qsgMh-00BoFq-1t for linux-arm-kernel@lists.infradead.org; Tue, 17 Oct 2023 09:27:52 +0000 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2c509f2c46cso49492661fa.1 for ; Tue, 17 Oct 2023 02:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1697534867; x=1698139667; 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=mmRpGDfzfzXXUGH1yNyuFJTa/GMKsCk+U3u4Li62P+I=; b=l6HtsLXap/4aOBxKlDnYLOPbdarkkzpeiadYvk2TEthtxEdY7AoUSBces9duDyw10r 9o6/xvXT5xuEZcfdZRdFPzVXGdDfcmvFzL7w1RTaZpmaktK9hBAQGRVm1jBqNgy3Ik9L b+mEfLRr1WYn+wy9KDv73lTzMTCPNW7AiCvq1pld3ZqhI0mtDYdTxAGox5WwCLvooI14 31YXv/RELhy9CIBw0InS7oNJZ09xQpLrioN8wthix3gM78m0SyYKwX7BoiWK9u1zGCeZ CfalvoaP5X0NlIAWi8rYZjhSJlYS+gCMJ6nljwHevgwCOJEkVwyZcee3BojXYH1Oin3u WIjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697534867; x=1698139667; 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=mmRpGDfzfzXXUGH1yNyuFJTa/GMKsCk+U3u4Li62P+I=; b=bDdG46UgiChTvH6yEXcU2gZ6mjtpq4lngY+DPG2GjDMCeQS1/URYp0ydeQnYkQHhm/ Q12eH45IO1N1L3YHqC/xPXLh98D4iil0thmWfH+/8wkIiAmbYefT4kYcTo1Oik7XG+or KNllXL3f3CR5i+DJf71njXFeNzANKDggVzzLAImkPgaRfVMKIpLGxEpDRTjehVo1LRXG V55wkhhit2Oq5AyGUv14TSw560APvCqB4ss0IPz/lxCARy9lknzsMcxgY+HrmnSEvRNL W/eJpdQzwmP8t6DfSoOVTZcl2BkmXdxJ3I0q1ySxZxXuh61Hs6tPSt2MvUQ6ZF2xpVOe Siaw== X-Gm-Message-State: AOJu0YyEg027ere5fUsjRA0BAFp83HdJdmT4ne0zKqf71EPR8phrVYwN +Ih/djPhEspHnV5a/EPCH9JYGA== X-Google-Smtp-Source: AGHT+IGBLq9c9rOXe1PcYXocYq4MKiwHQFSxbse8vbPHLvRroReBdaWXNZiCK0tx5duzH5CWmJSC2g== X-Received: by 2002:a2e:87d3:0:b0:2c4:fe14:a85 with SMTP id v19-20020a2e87d3000000b002c4fe140a85mr1398513ljj.18.1697534866969; Tue, 17 Oct 2023 02:27:46 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f1ee:b000:ce90:ed14]) by smtp.gmail.com with ESMTPSA id j5-20020a05600c1c0500b003fe1c332810sm9460787wms.33.2023.10.17.02.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 02:27:46 -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 v5 08/15] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator Date: Tue, 17 Oct 2023 11:27:25 +0200 Message-Id: <20231017092732.19983-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231017092732.19983-1-brgl@bgdev.pl> References: <20231017092732.19983-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231017_022751_639380_8B63C6FD X-CRM114-Status: GOOD ( 11.75 ) 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 --- 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);