From patchwork Mon Mar 25 10:03:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13601737 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 EAF3DC54E64 for ; Mon, 25 Mar 2024 10:04:47 +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=/A3VUntLMItsxs4b1WYzoj/4Txy8ZqaogSue6ko493U=; b=nXYzaIuOGWSmkh PRjeED7M1buaCmrR6x4ChjxMDSafSPpVzdolPQq2IyaNeG6+uGgcAVNBBcrAGFA1ntDcdSMC8cmVy BAMic0HjVV9CqKVqcva6OpaD2KG884KbOca8y+RdfPD/JAqpXbNYC7lHxhpeSuXymuOVj38cdPm4R FSn877sZE4YPBAHV8/jvUIC7UWFBeSbDgaLXUiCNg3yaxeJrJOHJoejoziIbp2Nnt1G2K4DHsrsgL JE6Yx3mIBfYhwh1fCAGD/0k6k2vSGX8j8nYYxbrq+uTTJVZoBPRROLWYxsIX51yIvb/htjCDHS9+m U47pbP/cRg69htvWPUiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohBv-0000000GcdO-1MQp; Mon, 25 Mar 2024 10:04:31 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohBc-0000000GcQR-12kK for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2024 10:04:13 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-341c7c8adf3so969696f8f.0 for ; Mon, 25 Mar 2024 03:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1711361050; x=1711965850; 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=8fl37vGRYSy2kvf67OGkupfqZ+uqFGGpfw8NF9/514Q=; b=byDN+3A8/An+bjwEyA+ydFqaTNA6ZuyQz5Dmkc++8/kMbDH9+Wtmpqy9EMchDaFqZ5 oZftoXJ23Cg6hWjNIBj1QNunD8TLd4z9+LFV9GRdJzFgF3l9W+5C6LmxxW5Y/EDApcfO D5y1s8GSSwocYGV/pM9cbcdwHPQlbx2rM2SMYRlWGr2lMq6AJCQGm8Xx7IHY5O+Qzozi upzv0y8uAoJVHviMhnnt4xmVSxyihufFBdnqY/TVCqbDhQvRFqldMS7aR8oOIf06TYiB 9MD0N95ffL+LEELTJjhGgC+1rerHNGxZA4n8eNl1UgV0MJ5gt8Qejce6ZJO1E/jG37Vc QLrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711361050; x=1711965850; 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=8fl37vGRYSy2kvf67OGkupfqZ+uqFGGpfw8NF9/514Q=; b=jj2BpmvQP4zCOmvl1mIJfjQRArQ+C8uQOpTc4GXwSL7c1Nep8mlFYWfXrXf+RS9nVR OAUfqfaKHyz9xv/NBaiWfC1GR7bMi++r57nAZo6vNoBecwdNf2AQDo876UBT07STFP++ XzAg87ey609hvwDLLnWkHWnZwCD0qG5MXHGkBDCWvdfVZpxuoGhok95/hvJjKWvu+2RA +Z58bip4EuVa3KBZVZPrjBsg7WUE/aXVGh+e1UTxUDMQLwjxa1sRjFQM1K1U5iDpWVvR RAw0sH2XdM1S8nbIN9cffEXmzQgtXUOj1S6azuxNshGkhbpK2RxQm3zwH594SBV4ckeO OXpg== X-Forwarded-Encrypted: i=1; AJvYcCXhKrq6eAM165AwsQcjb8N5+my2SvPt2eRoCtWJkRUR/wbxNby9vplmDpfE70nVRbHQ9ZKK40oXiX593HP3osFqx4ZJr3ulv9vDa0bm+v2S0RT27KY= X-Gm-Message-State: AOJu0YziWlCdefgC1SYKEcQFzpLC+Msvm3jiPWwTnqZ/NDt7riXorYDx MBG0p0TVxQH9B0W10IJoOt/5cCk+vhHCPjqiqEGGdNmlCnXrfAuoYZfU9CZDh2k= X-Google-Smtp-Source: AGHT+IH+hhp3hOA7UiKIPybzE1EoKjoYoyhlQKM6glQr3E4kR6w3ftf3S8vD8LlexgRD9oDYqvKJUA== X-Received: by 2002:a5d:4084:0:b0:33e:c924:5486 with SMTP id o4-20020a5d4084000000b0033ec9245486mr4958754wrp.46.1711361050341; Mon, 25 Mar 2024 03:04:10 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:75a:e000:861d:8b72:a859:4ce9]) by smtp.gmail.com with ESMTPSA id dv13-20020a0560000d8d00b0033e25c39ac3sm9086874wrb.80.2024.03.25.03.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:04:09 -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 , Arnd Bergmann Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski , Deepti Jaggi Subject: [PATCH v9 05/13] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator Date: Mon, 25 Mar 2024 11:03:51 +0100 Message-Id: <20240325100359.17001-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240325100359.17001-1-brgl@bgdev.pl> References: <20240325100359.17001-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240325_030412_371908_B17E6D32 X-CRM114-Status: GOOD ( 12.37 ) 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 Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- 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 cd47389ac80c..de66319cbfb9 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1200,32 +1200,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);