From patchwork Mon Nov 20 13:21:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13461301 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 42C5FC197A0 for ; Mon, 20 Nov 2023 13:23:11 +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=4UQge3R/gc6lA8 S3it9AtOn5ex0J8V1BGOux5TPwkLUQoImtvqydbrdhT0yrBLfYrJiMx8DU7rB88Ij6tJDih00JeBL zkApBiomd4AaAzgIRhHwQJ3GxO7gfETEF49ZYP/tZmVXwPBse/g6jNs8WvliIJWdWmbpgdjYnY6Ii ExqdXv/uaY5FJhELqw8ebXgKLQwaQts1mIVVkywSUjA2QNAEHQJf4RxzuImp7JmmtV/qtJxekDxRd mw/M3xzMxmcmNT67IT1zC5bBLmA/iJSy1IizpUMAB4jyOEzq0bDyJeOFeK06mwma3Mwv9Pa31Tfom 1yMj1g4ugaCXN4Y9uWXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r54Ed-00C8Lj-0W; Mon, 20 Nov 2023 13:22:43 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r54DX-00C860-0X for linux-arm-kernel@lists.infradead.org; Mon, 20 Nov 2023 13:21:42 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4083f61312eso17949245e9.3 for ; Mon, 20 Nov 2023 05:21:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1700486489; x=1701091289; 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=WPVvqubj21mCvzT9Xn0/ev9Ksql0C6FDUM0GZPGxiXDSqfVIIiiI4m5GNM7QdfLywP d11bZdYB9dAWt+f9WaikQG0go1A7rwZCjMkocoPljxyGFj1+jeEjyOP6Ey/EbsOegtB6 NUlGeGO4r1YbJkM5gmzkERtRzjs/ezvYK3N6a/9KwxG0u1MU3LYmDVAAF2X82TXrEsxZ EwfSA0BcElyYZWRoDdtuMh52JOAUap1NmM8VCLWv7n1T3cR4pa6di2YaRevvzlKkRUHK FQODsFsw5oj80ed6UXCzvyyz3X6vsEGnxCJKgUMm+gSZv6PkFq+ruJBGuVnAfDZ5xYHw bBgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700486489; x=1701091289; 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=mqNu/r/ZE63Cd+SH5VBOmpy1xEVhT1CVJBUTFbeeVy6IiDT/7yk1g/CqS/EfebPuxf 1w1xOC2xGfycqRYdZcUbNifTKgbYrbjz8P4550C4htollAqjh9/gcTNmUaFlPVjkCKM7 y5O931KiP/Hwg5895QmJLlI7+m6z6VqLSUuHBp1lRKucpjlQ9f59aN08kndP1ml2FRG8 hVhdQ2pQriXKvGe1zJoB9lXcRBaS7SFEr0layrI/0TFjVabdtKfhJMf1kU4SYS/7NtP0 y8lHeIVDEcp8sXI/EoJPw2p6gzLvwyf65+qoAUrhyP5yLtebdleQUJxwezCCD68TQ8Al 4vbQ== X-Gm-Message-State: AOJu0Yz13+WOWR+ge/3B+DSUMmg9HgIiprU3uE6KrLJ0+YjXdCnfl2u8 QAwWEp08RfN5biVHQQflFxRv1Q== X-Google-Smtp-Source: AGHT+IEHJG2PWRT7hWRMJXRn4DOeHbhS3nW6N5WgPprhwMyamnDq4Sm6+2fVU7uQp0iok0njT7QtbA== X-Received: by 2002:a05:600c:1994:b0:405:40ec:415d with SMTP id t20-20020a05600c199400b0040540ec415dmr6097795wmq.39.1700486489266; Mon, 20 Nov 2023 05:21:29 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:c590:a7ce:883:eba3]) by smtp.gmail.com with ESMTPSA id k18-20020a05600c0b5200b004065e235417sm17329192wmr.21.2023.11.20.05.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 05:21:28 -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: [RESEND PATCH v5 05/12] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator Date: Mon, 20 Nov 2023 14:21:11 +0100 Message-Id: <20231120132118.30473-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231120132118.30473-1-brgl@bgdev.pl> References: <20231120132118.30473-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231120_052135_342256_BA82C0A7 X-CRM114-Status: GOOD ( 11.98 ) 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);