From patchwork Mon Nov 27 14:15:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13469729 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 67A53C4167B for ; Mon, 27 Nov 2023 14:17:37 +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=K2LMOZhr86vMgoXFp9BNQuwHI6ijYRHUF+FtZRJKjBQ=; b=nNf8ZIQEsTLsj1 kMVzXozjpqS2sqV3jNLWm9ahBJ6G8hGqLH1QARANxqxqGpc7PrC0WY7Bg/1NU1QmXOfPBo1NmdJ+O 2f4geRhe8zxIsFpbtkhzeJ2NsTpozr9HyxwGOU0b7XvojuWoyYhYAhsqQZC39oghxQNSIqqvP+LGN VDTasux+9vYo+AB05DfMcXCkW5lUgGfeZkH+UX+9g1WVWihkfR2WXaY8j+NSNLnS5oSsNmseAIezO UjHaHvCIISQ86cNWnBUhSDoCOzShJX+GTBNYbN6wCs4KARSmNJLk06Vf9dyR92TAzIM2A6T9Q4Kas 6OFpzrmH6FIDBMsJzC/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7cQ6-002fba-23; Mon, 27 Nov 2023 14:17:07 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7cPK-002fHs-16 for linux-arm-kernel@lists.infradead.org; Mon, 27 Nov 2023 14:16:21 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40b34563987so24247455e9.1 for ; Mon, 27 Nov 2023 06:16:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701094577; x=1701699377; 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=Xqz1VK0mYS8f9CyDoxvSzBDgulCTNu27LF81cKbiT0w=; b=qTMl8RlLbE6cQ08WFIShT/T1KzrOBSIFJIyYGfZKcvyss41lbYlv89+2rnapLbZLl/ 2KGykEPSgBtmVUKCk5feEfND++efmQMIkpWDx23FlywrbqrZfOf9HSxa16IODkY7TbPw sfppPeYZHexwR2BWE0LZ34VH0Fk5OIJQzaUkTVddkCpGD9fwg8s1uj2B2yd/mNwGQNg6 owtrb9Uql/0trFJ5A1xK2VwNxd/6AUVoA8tQ8EppYmO1TZwvYftNnAfIVhY1sn0U6McE ZjHtA3u+0KhVn9lGRL0Y5xvWdMOE4emJtaqJQmExhrxCt2CegvuODZvqA1wilTyBgtr9 Iezw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701094577; x=1701699377; 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=Xqz1VK0mYS8f9CyDoxvSzBDgulCTNu27LF81cKbiT0w=; b=Jur1hCnchx7Jc3RsbcH+19uTK+M4PYukeAOZ41akPvOmwMSj2Ir+WDXyi+x+NeK9sd 8HWSy20GrHkfRrVm2dFA4xerU0IG4s/6lCjhysWXiyl5Se2jJlVW8npVuLgzFCQz5+cA Wzc2hY6VtphCsguoPp3J/TCxuCYXskybHNii5Uxf0E3hJa9Jj7p+7NYFVounJWAo2aBn gOuSNs3s12lhZ6Zup8fynAdslZqjRgO2xKET8zY0vZ0cKMI5Y6yNMIRNfgOQNr78ThJp We9+IUeNf7ldqcspG0hr45yH2HchYuTFvWPUERZ0a3IZuceD25uje6oTMcizbNjR2LAb zENQ== X-Gm-Message-State: AOJu0Yx/ckNxpREdsx/GDs3p4iwA77NFcP3Og236c3lpFYitconEwrsX WKtFS8YekIhy+SV1zEOBf4fXGQ== X-Google-Smtp-Source: AGHT+IHMn0wWKy0PNcRLMmHMGiQMxo3AwVXygRjIyzuZuJGMIUuaMDA6AO6HM2buOAcnfZO9zniPxg== X-Received: by 2002:a05:600c:4f12:b0:409:6e0e:e95a with SMTP id l18-20020a05600c4f1200b004096e0ee95amr9379119wmq.19.1701094576249; Mon, 27 Nov 2023 06:16:16 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:bf33:77c7:8131:5e64]) by smtp.gmail.com with ESMTPSA id be7-20020a05600c1e8700b00405442edc69sm14658830wmb.14.2023.11.27.06.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:16:15 -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 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 v6 06/13] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator Date: Mon, 27 Nov 2023 15:15:53 +0100 Message-Id: <20231127141600.20929-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231127141600.20929-1-brgl@bgdev.pl> References: <20231127141600.20929-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231127_061618_515138_4E53CE3F X-CRM114-Status: GOOD ( 11.92 ) 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);