Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2708303lqp; Mon, 25 Mar 2024 07:13:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWdKXuNhVR/7H+lmR2f+7dzG28RZale+rWrE2/P51/ZVMy0CQLWOwW+/OdNYjh4PsA/AYAH5+hathr0/GNfpHomV4F3RInrhPaNKWeELw== X-Google-Smtp-Source: AGHT+IFWTTAMVt1462tyU9oXm10TKrjJarOp8LT46fhtQJZ/uSfMJCxHGvFDJzXAVwb+GHaPWDGu X-Received: by 2002:a17:906:f592:b0:a4b:7394:e46e with SMTP id cm18-20020a170906f59200b00a4b7394e46emr1214656ejd.50.1711376007424; Mon, 25 Mar 2024 07:13:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711376007; cv=pass; d=google.com; s=arc-20160816; b=nsFYFZbP3GCmHKOTQwISA8VI/KISgyjeayoi3mm9SdjbHaMqGweFtCrITYXARdyHmz eOiVN2It6rRCyjp3ppsU8IYAQ/DFp90HtFCQlQ0tgjGGwmy2/r1xjRmSTuEy19caKfQf Dys9wsHOE5hDNaxIg4zMO/tc8C1Byu5tTv9EbTMdw3oBOoFGqnrEaXb7kvxNUNT34vmZ QEJJmpRbVXb3mMQEzMRkUFygyVdP2KYfUnsiIBb243XVXzUHMy6vuS5TjSKGWhGWOnP1 oRfepPnULwUwmrTT/jqm5Md57Eyy/zbaxt1LPiSWxcd9QbqTEZb+3Q1mrCvCqRkmqDaw XKhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=sodtg05G0+kvZkJVm8IsH+PblHBiK83uT7JTQwgljWI=; fh=lixUD6npXTGxbHzeBISnuNRNDlJ4gfSBhRFRqZDBcpc=; b=pFaQ8r8snV4p6gGo+ydWrjttVqcSKiIsYl1wrg8Q35qecdP2PKd6oO8GUsG4NLZwpC 2Z5YsUJiuUbDSJfeindCkwOFoKy+BL029Cw6ycjvngevtlY1bERwGKbJgj40AL7BEUky LXDL9kNUzIC7/CroXmBH/k9uE1O1562/4b8d82g3k+YTfMEN4ePwARTxWlUzluLC7RXd 4SS7sWiEcABwqAjNzS+dff0ieQ+LIHP+9XG+D3fbmDhdgl9XabIsdzD6t++2w60GgN0a ZgWclgze+S7PrkXhRHs6zp9p28oZkiAGbNF3em+aLPD2xc0Bx+1XtV1KtJ7X9ZPa/JZY 2a8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=JpVBnGXX; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-116782-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116782-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kl24-20020a170907995800b00a46abf52061si2636501ejc.30.2024.03.25.07.13.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 07:13:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116782-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=JpVBnGXX; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-116782-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116782-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EE7621F21809 for ; Mon, 25 Mar 2024 14:13:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A90181802A7; Mon, 25 Mar 2024 10:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="JpVBnGXX" Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D881181814 for ; Mon, 25 Mar 2024 10:04:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711361048; cv=none; b=Ua+l7bD4KE4J+o1Wdcll389UpLH8xlOSIQAXB54UF7RD5HBSQyDdDgzfuhCieoWULtvylG/MXqyUjfeUaBNivDvdKWQaItNfIioYbXzXN9g7xNk8nLbAfhscRtatCCL6b2S6yABv+ibJ55T8uECTS4KeHmFzjlu8b+CXIm/wxvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711361048; c=relaxed/simple; bh=MfTLVwBpHmT3NhU5IyU2HA2DGd9BDnhPRzctKeGkWdU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=tgskOR0ayV+S1xhT8o6rL/NkWmZRawPYSiLToYR2B3EQr1pAj9a/vc0na7NqCF4nLFiIvfWPJYHItOxhk9dYZRvbVlwQ5hwmOrYCUNRbFbr4CXVPVa3jAc0vJSHSq6t2B2p1CDVvGKfIdCNTpIGdO7pDRSWRBYnyJXyzoz6w9iA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=JpVBnGXX; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-341cf77b86bso355213f8f.2 for ; Mon, 25 Mar 2024 03:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1711361044; x=1711965844; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sodtg05G0+kvZkJVm8IsH+PblHBiK83uT7JTQwgljWI=; b=JpVBnGXX8Kns4ZaR5LwA5sLy4ES4iGLJHt+AhnGL2s4tJt/VGOkAW/5JGiKqfO/65g +8IT0ujtMFbS3TWEY0fiTi6qFh0fA70eAppEn/g1znNUFYq5aIfGSHC5elFV3j2u0t3s N8E8dcFMXp9yuWBhrI1paXCGOD2R5Y1wykSsSBaj8Q0lp5g/hR5DZ2sPuT4hLTa/t793 NkmEv1LGbSBueawBRzNyqNdrcmUEI4eFz6P6eIezMb1iHsRNB3n1eE2q6DrEKVIdZtz8 d4JNoZh57rlNSp6uWbnz/JLIIdA/vArRc9bEYCGP7vB7p/EpeQaF8ALQ6MqtrjTy7ijX 8m2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711361044; x=1711965844; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sodtg05G0+kvZkJVm8IsH+PblHBiK83uT7JTQwgljWI=; b=PKm9/1PtbXX+1YBGZWrLkDL2lDh37jVlf0j77QvwXtyITFxf5ugnZoyxFs/kuf4uvg higF+RlFgYrpsn4nm5UuGYoqPKsfmxMYRFnR1vsxdfVrs9ptk27mEJ5kzyw4r/s3W2dM UYoIhCHjD388rlkGu/cHOZRyvEiciq70J5h+o/Bb3757INI8LOe9vx5n0+h7F2+4I/Vu MIWxNkAP4ByW5MUtWYs/jv2CW13NPgoZcC0dxKp2cKCADcFhAbsmV5h6fCM/CXGL4hWW oBqpLvsu5q9lCTO319m7Deoqzteoqswunt2rw7NoZ7aJW6ZgFC9dTZ+ajwVppeH5QJX4 758Q== X-Forwarded-Encrypted: i=1; AJvYcCXv7moSnXmZASNb427bvU4LCelgRruVJWf2oHy0LYfVFcTPlwKk795SYQdO5Iv1IkLvQPQKD1vcqeYtkOsUDs3Nnwcq3zTiEjtg6G9k X-Gm-Message-State: AOJu0YyvWICKEVst9SvI7TTmcFjprgxjpOkkUFZxrylnkqHSeHL3/lIQ yyi8YQ1S6F77OxC9ycyUQISyGNlNFLvva0cEJvaAA5P4JZqwI0oV3hAvv+ytsgY= X-Received: by 2002:a5d:4612:0:b0:33e:7f51:c2f7 with SMTP id t18-20020a5d4612000000b0033e7f51c2f7mr3962132wrq.52.1711361044516; Mon, 25 Mar 2024 03:04:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:04:04 -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 Subject: [PATCH v9 00/13] firmware: qcom: qseecom: convert to using the TZ allocator Date: Mon, 25 Mar 2024 11:03:46 +0100 Message-Id: <20240325100359.17001-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Bartosz Golaszewski SCM calls that take memory buffers as arguments require that they be page-aligned, physically continuous and non-cachable. The same requirements apply to the buffer used to pass additional arguments to SCM calls that take more than 4. To that end drivers typically use dma_alloc_coherent() to allocate memory of suitable format which is slow and inefficient space-wise. SHM Bridge is a safety mechanism that - once enabled - will only allow passing buffers to the TrustZone that have been explicitly marked as shared. It improves the overall system safety with SCM calls and is required by the upcoming scminvoke functionality. The end goal of this series is to enable SHM bridge support for those architectures that support it but to that end we first need to unify the way memory for SCM calls is allocated. This in itself is beneficial as the current approach of using dma_alloc_coherent() in most places is quite slow. First let's add a new TZ Memory allocator that allows users to create dynamic memory pools of format suitable for sharing with the TrustZone. Make it ready for implementing multiple build-time modes. Convert all relevant drivers to using it. Add separate pools for SCM core and for qseecom. Finally add support for SHM bridge and make it the default mode of operation with the generic allocator as fallback for the platforms that don't support SHM bridge. Tested on db410c, RB5, sm8550-qrd. Previous iteration tested also on sa8775p-ride and lenovo X13s (please do retest on those platforms if you can). v8 -> v9: - split the qseecom driver rework into two parts: first convert it to using the __free() helper and then make it switch to tzmem - use QCOM_SCM_PERM_RW instead of (QCOM_SCM_PERM_WRITE | QCOM_SCM_PERM_READ) - add the TZMEM MAINTAINERS entry in correct alphabetical order - add a missing break; in a switch case in the tzmem module v7 -> v8: - make the pool size dynamic and add different policies for pool growth - improve commit messages and the cover letter: describe what the SHM bridge is and why do we need it and the new allocator, explain why it's useful to merge these changes already, independently from scminvoke - improve kerneldoc format - improve the comment on the PIL SCM calls - fix license tags, drop "or-later" for GPL v2 - add lockdep and sleeping asserts - minor tweaks and improvements v6 -> v7: - fix a Kconfig issue: TZMEM must select GENERIC_ALLOCATOR v5 -> v6: Fixed two issues reported by autobuilders: - add a fix for memory leaks in the qseecom driver as the first patch for easier backporting to the v6.6.y branch - explicitly cast the bus address stored in a variable of type dma_addr_t to phys_addr_t expected by the genpool API v4 -> v5: - fix the return value from qcom_tzmem_init() if SHM Bridge is not supported - remove a comment that's no longer useful - collect tags v3 -> v4: - include linux/sizes.h for SZ_X macros - use dedicated RCU APIs to dereference radix tree slots - fix kerneldocs - fix the comment in patch 14/15: it's the hypervisor, not the TrustZone that creates the SHM bridge v2 -> v3: - restore pool management and use separate pools for different users - don't use the new allocator in qcom_scm_pas_init_image() as the TrustZone will create an SHM bridge for us here - rewrite the entire series again for most part v1 -> v2: - too many changes to list, it's a complete rewrite as explained above Bartosz Golaszewski (13): firmware: qcom: add a dedicated TrustZone buffer allocator firmware: qcom: scm: enable the TZ mem allocator firmware: qcom: scm: smc: switch to using the SCM allocator firmware: qcom: scm: make qcom_scm_assign_mem() use the TZ allocator firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator firmware: qcom: scm: make qcom_scm_lmh_dcvsh() use the TZ allocator firmware: qcom: scm: make qcom_scm_qseecom_app_get_id() use the TZ allocator firmware: qcom: qseecom: convert to using the cleanup helpers firmware: qcom: qseecom: convert to using the TZ allocator firmware: qcom: scm: add support for SHM bridge operations firmware: qcom: tzmem: enable SHM Bridge support firmware: qcom: scm: clarify the comment in qcom_scm_pas_init_image() arm64: defconfig: enable SHM Bridge support for the TZ memory allocator MAINTAINERS | 8 + arch/arm64/configs/defconfig | 1 + drivers/firmware/qcom/Kconfig | 31 ++ drivers/firmware/qcom/Makefile | 1 + .../firmware/qcom/qcom_qseecom_uefisecapp.c | 285 ++++------- drivers/firmware/qcom/qcom_scm-smc.c | 30 +- drivers/firmware/qcom/qcom_scm.c | 182 ++++--- drivers/firmware/qcom/qcom_scm.h | 6 + drivers/firmware/qcom/qcom_tzmem.c | 455 ++++++++++++++++++ drivers/firmware/qcom/qcom_tzmem.h | 13 + include/linux/firmware/qcom/qcom_qseecom.h | 4 +- include/linux/firmware/qcom/qcom_scm.h | 6 + include/linux/firmware/qcom/qcom_tzmem.h | 56 +++ 13 files changed, 813 insertions(+), 265 deletions(-) create mode 100644 drivers/firmware/qcom/qcom_tzmem.c create mode 100644 drivers/firmware/qcom/qcom_tzmem.h create mode 100644 include/linux/firmware/qcom/qcom_tzmem.h -- 2.40.1