From patchwork Mon Jan 22 10:21:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13525121 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 05E86C47DD3 for ; Mon, 22 Jan 2024 10:22:55 +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: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:In-Reply-To:References: List-Owner; bh=fdYCwQo4C2IRGQ1tPtwiDUT8fNhW60Ot1qnPG/ynfEI=; b=cm1L7Gok17tdem hKhpblKSlGskNAfqkkAz8QUYadB6H5/rVya/kcjwwZ1kEF4q9sGWscPjAj8haqTBekEVxeBrwso2H Zl1WJSTbRfUjVj/gr5niItkyXIJHKx2EXYOrvGIQ2upKZ0KdTjxkNn8NG/A51BstApKrmkQ37ThnR icHIkEfcOkQ2e+CzhebJBMeLpdOgUt5uIEGvwc7LsqvOQVH0UE3RF+s8SXjrxYp93BTnmvTyMJCWh flKJJgz6ljPaitRqMKoEmyf/Z1CK02PwhoQEJHB+VieRcD5vuV3C/79QlZg9qNaAUNJmp7qV4QMf7 nh8pbpA5TlHJGwAbED4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rRrRh-00BUdy-0C; Mon, 22 Jan 2024 10:22:25 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rRrRa-00BUTg-20 for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2024 10:22:20 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40eaf973eb4so4296015e9.0 for ; Mon, 22 Jan 2024 02:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1705918926; x=1706523726; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Rf1BoFdqtUASlu+bDRkAxrtXf+RijsyUfpG8EnvAHFE=; b=cmsqs9FbSTEwDTch9PEc+Y5Lobs8mWuQfC9vlSk5HXQCNjUDWYqld6UK2TgXKjm+YU v/0PkOBbrN1qY+KGUVsYrP6wpWzQcXG6/V1esjJLr4Pf5Mg4zPQcinxWCHiAQC9+GqOh F4Q9HxL5W097oV39y5fWBodef/KsPTZKGlgcN00mNCYoMxXZKMivhY3kx7INsqtd6kVU FtDVaFtoIbkedQbRgLpwCcdKZoQE9waIXoLtx/oYHJGFIkWbKtx3y9QMZ5B55yS1Qnhy dzfqvWSHGJ34X6wzOEwB/nyuioHEINl5sjwHwq6HNXx9oWfPG1VL3w0wHr1BTK0JHXnW jRHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705918926; x=1706523726; 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=Rf1BoFdqtUASlu+bDRkAxrtXf+RijsyUfpG8EnvAHFE=; b=dt2zoDkAbCA6MkvwCYwAC/415AwgSqE9OryTOjiPDkIl29/8T9kB7AvTPTA0a+UnYu bhz0crv2q7JY/+nfhfZtOYBCoNibvRfpq1BQSYcTjeNu7XkHGyAbAZuLHwYbDzRspCA3 6J4dqMMhjqHsGzIYp2CNdGhwqe/pIuO93cAd4a6LPr2N3HuL3lXhCGaTkDNA/IJwrIfo ovVhYgGcl5jTEE/XLSFlIzVAHDFqP6PuzQHxcWVWdAchyO9/+TiDqUyiOhO5TE4L/Tlz ZRqAenBkKbc0ZdBrfFqebtoLSdElOPCPMXz4XMBbhnJVAi7Q6hBEVHdgYPOnqSIK7S3n MqkQ== X-Gm-Message-State: AOJu0Ywrq6qfTKKy/4JwV645zjOgBE2T6Uda5kkyLrBszTW46wU6cvAg lzwtE0iZ/Fd2RuLGVRVMeVS2KBR/F72TbO2vgUBP1BZsKcpWuqtHrTWFytiOjvY= X-Google-Smtp-Source: AGHT+IEdNK6nO0KwNdSrht0sUYc/g9kz76RCgf//L7woN5+hF39GrB6vClpm0hmQ1N0RwLSfUG6vZQ== X-Received: by 2002:a05:600c:5492:b0:40e:710d:7c1c with SMTP id iv18-20020a05600c549200b0040e710d7c1cmr2079899wmb.32.1705918925540; Mon, 22 Jan 2024 02:22:05 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:92a0:6172:d229:1898]) by smtp.gmail.com with ESMTPSA id q7-20020adffec7000000b0033926505eafsm6377904wrs.32.2024.01.22.02.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 02:22:04 -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 , Catalin Marinas , Will Deacon , 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: [RESEND PATCH v6 00/12] arm64: qcom: add and enable SHM Bridge support Date: Mon, 22 Jan 2024 11:21:45 +0100 Message-Id: <20240122102157.22761-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240122_022218_659178_5906B769 X-CRM114-Status: GOOD ( 20.23 ) 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 Resending after the merge window. I dropped the first patch which was a fix and was picked up last release cycle. We've established the need for using separate secured memory pools for SCM and QSEECOM as well as the upcoming scminvoke driver. It's also become clear that in order to be future-proof, the new allocator must be an abstraction layer of a higher level as the SHM Bridge will not be the only memory protection mechanism that we'll see upstream. Hence the rename to TrustZone Memory rather than SCM Memory allocator. Also to that end: the new allocator is its own module now and provides a Kconfig choice menu for selecting the mode of operation (currently default and SHM Bridge). Tested on sm8550 and sa8775p with the Inline Crypto Engine and remoteproc. 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 (12): 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 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 | 30 ++ drivers/firmware/qcom/Makefile | 1 + .../firmware/qcom/qcom_qseecom_uefisecapp.c | 281 +++++--------- drivers/firmware/qcom/qcom_scm-smc.c | 30 +- drivers/firmware/qcom/qcom_scm.c | 179 +++++---- drivers/firmware/qcom/qcom_scm.h | 6 + drivers/firmware/qcom/qcom_tzmem.c | 365 ++++++++++++++++++ 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 | 28 ++ 13 files changed, 684 insertions(+), 268 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