From patchwork Mon Feb 5 18:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546015 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 C6E50C4828D for ; Mon, 5 Feb 2024 18:28:36 +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=NSZlqXU0iVk1GLLf58ftPS71BYBB/1mNvp9DbINH+6o=; b=y68z3PS7teMph5 eq+rBYbuobvKhUsk8J1pX9wEkhJsozKo2cCtX+SEHxngPAhInj55TvICBZm77LvT3l6wL2LfY8nAI B7OIR/E+WUjpZn/VkOrEMb2/D4tvTn7ynIBqlkvghBvOnTLzb8IG+R5mFhz5h+w1lFrZdMrvjer5R QHqdxs9Zi6yyom+aMDdyL8Ku+J90ICoaN1sCe6m+3tFvhxKBIkTSnaPvoaY1HTNJw7QL8Vy489nil RlogEJA3ABHJfS4tXp436fWzNge8IoSlLCJpk/6oOz4qLLzJedu94J6CWLS9dh30jiKs8G/Wz7qKu OMCx/odtCNIT78TNc+uQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hg-00000004Mpv-21E1; Mon, 05 Feb 2024 18:28:24 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hd-00000004Mnv-3dHp for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:23 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33b1d7f736bso2551554f8f.3 for ; Mon, 05 Feb 2024 10:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157700; x=1707762500; 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=L9SYY+qgpvvxUhsi9zVed0l424i9mHr1dF1RqnBUnS8=; b=oEd2Km4t71Sxv4cMo0nPRkKDxx9UPymQLPGHtglyaoNlYdasJyv3b7ZByP1ivrgtY9 EeVwgWGpt3wFNg1xK39WhSeTdgO+ca5J9qkrF2kHC30A0Qtbj3bBFj4IWqEzv5Vir1eE 1WK6g1lL8lu7QI7kd09lIJg1fBXRazSqZ2u+nTmKal8YPqHrlOZTuRJn4iZOdCyk20G3 caQEytPbze+E+wrecdkXin4UY/xTjelUObQ0P3xv+bEmuD9HVGsfDBNXxEQJtp2b879a 0oexj0ZZ+IGK3VObFxLOjQOi3Xw1PMqjMThTkSmuqXFjtyhfcThdwgQ0e2nSnL2iwegq wQhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157700; x=1707762500; 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=L9SYY+qgpvvxUhsi9zVed0l424i9mHr1dF1RqnBUnS8=; b=OIg9ch71XLrFBfmgRzQ9gD16mhZdP/M+aONxyhdws/MRASI9ldJpNDv7HGv3DB4SpI JrOkQz8ZRhFCXEPMLzCzDtQJfdKWl32yv/X6x9NQdXiS14V9pSIV/Eu5amuHno8lTDos LgkqAH77FeKFLQ4W1h4UTbhgbOBYymIsK85YjameE5xX5Aj/IYwK4UWMqAwa6sxAShO8 S3y6KDcyFr2TNWKL1V+tSCzkgfQqzN8mTOovht324VjlFI/Tt6IA7cj0GHN5Uz/SfLk+ 0z15/jwi5bKwCXpgQ4NejQG5wtZmQ7Xqv3LVex6ZsGU8gh7bcHjKLtNuZ8Ev9oLiwp35 zJ/w== X-Gm-Message-State: AOJu0Ywfw8Bvb+EpqKKOEUgfHuvXnj+gIwfCX650vkHXgNaY2CxCVNXc RIrFu/hal81tzlZ051G84/WO9G2eYIkEfYTtvgmywkH4NGXq/M0Of8t8xN0/5TE= X-Google-Smtp-Source: AGHT+IFXKTwFzId4HeD48V0GUEepHR/dav3QLileDXFCLu/lm6sGjYLlaU1mBljSkwZfYSQSpyIiXQ== X-Received: by 2002:a05:6000:248:b0:33b:3c79:9182 with SMTP id m8-20020a056000024800b0033b3c799182mr223826wrz.3.1707157699823; Mon, 05 Feb 2024 10:28:19 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUPFThfwYFaIB2slHnICTpsQvB4UcTrsX/f+BFLAnnJdy9c28RIqhda+FuZCwcIlmbcV5/tWKoMvcpm9wRvSqRLQ4v+4ejqRA6DXTQ3X8dPYWedTiM9W+0RToVSi1DLKlvfsPEzHoipmpuyPoXCmC56W0AQyfkbajwY/XkHT4yfXMtQZvQnk6I2IbyweXaN8ap0NEMtHw8sby435OR7ULlT3KE0sGJDpdbpXEXIKj6mcgPv6m6NKkUhfLFiudkduLlzR54wT1tPVG/uQ5QQ8RN4hhMcrpC6LwLQ/3tXFrjyfS9m0TUVU1+2dQa5nKGAviEXyReU5IIOa4aZzBtkJW2mc+n0O2m5mj89mJwe3nxV2Ys7QeCbEQIMcUqiMJIWHWBDCkoX5UhwFapXv1Oxnlfjo9UN2AEFAG4ohn/gNATAAmn54PWeag/r0zg5fWz//Eomq9deTJRzOOC6Hhc1i1/pppRohEYcASGi+vQJox/gu1QAxq2Ye8bC6uYf6UgmGfOspR+v/BdFK8alipI9Nk+186CC/ljtiA== Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:19 -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 , 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 v7 00/12] arm64: qcom: add and enable SHM Bridge support Date: Mon, 5 Feb 2024 19:27:58 +0100 Message-Id: <20240205182810.58382-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-20240205_102822_136409_4C4A6E7C X-CRM114-Status: GOOD ( 18.86 ) 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 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. 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 (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 | 31 ++ 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, 685 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