From patchwork Fri Aug 30 07:03:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13784393 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.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 577FB1531D0 for ; Fri, 30 Aug 2024 07:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001480; cv=none; b=IaYOtTgzkoL9nm6BdhT5/K15XQbXrAACGFibfLC3mmul4NKvI35bhDoTCj6+aGQQqmxxyzxxkqM6x/oFUFGnXkPn6wydx0gASEPiVAYu7vbkavZW4A5mKBcLvwbdgjoHbMgTveqjk7NkvDim20zBINyZbjlSWMxT2w5oyU3KmOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001480; c=relaxed/simple; bh=l4FyY0fAOQkXCQ8r7DUhe/hxcGrqq9PbkHCsIcW8yFg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=g+BukUkWMOGLCy7wDc2RtqrTMI1BAYsoeCEg3YrbPYJjJq+OIC+QRV8y0ckHWuHLGaCQSZ5TcQOrwCvnnTtxFwN6SBpvzQSAOcoAXx83VQa2LkKam6TF54s53O9pxzYHr/KAo6E1CCfdqWeSzGRmileYpbiZEv94hUJ1AUwapts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=A9BfnUds; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="A9BfnUds" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a86abbd68ffso257856766b.0 for ; Fri, 30 Aug 2024 00:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725001476; x=1725606276; 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=NAqkPKV8FIclg2RIfEME8aNTCMBfxloXKZQVTM0jEG4=; b=A9BfnUds/mrpq0ax3wgc0E99PV/62ThwtsEbOZGjsOfmblsZVbu3NFmL19oo5kMh7S AQ54tQPUR6GI/gwVj62wc9DmTOscpqFO+phznsh3YNtwNkLndVkLHO0gnKwmc2gxk6U7 xrf+KgTgSuZn3kL/lDIdI8vTRK+joWY42BnB+2aKJx8zlTAE+4WkorgSAfqrhbIZOZcn TiNyXDxWuLZnoDSNOBkzakpZGdI+Xulg82kxMKpU7cZDOh/6Z4Dx60N81ejSiaF8qfML CXPnQgBSC49mJzQCHO72NxcKhmPhSItAmg3aZoTxAKpz2qLxQn8A9hEBtqLhjPBGAPip 3vxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725001476; x=1725606276; 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=NAqkPKV8FIclg2RIfEME8aNTCMBfxloXKZQVTM0jEG4=; b=ZIZ4PIYg+uewKG5FLGBlIU8sD+JNJK9cLWDq1aASXIK+uXPZya4BNzMyEAeQ/wjUov z4wV5F/YwNUVhQMjupzwHoPz2kW5EucoQCfRWOxq9qjUUx77R78/a5avgIesXJ6Ucvg5 wVPXzp6zOgswVlEQZJ5dbjUFD2B+v3lOn1cRiTANnHtS2h8+Ts6XPpIZo0/Y/neEQDQn yIoWif716rCuFf/q6NpeyuDE5BlnJRZWNk5aTOMVDXTTNsSDeCB8EW70xhQenSXCLXUq v9cbfqQJKg8LgBwWf7vsJtM8HApZVGLaWhppT/20KCzv0UvAYBs19VIUYmkoxBqqxdo0 MssA== X-Forwarded-Encrypted: i=1; AJvYcCWTLJbLXGm6uwpzJrjxEVTZBF987T2unlVPx3HuVCRm7kBvw/LfBZzifa9iM0nlyQI1d2LaQcPHsPmf0g==@vger.kernel.org X-Gm-Message-State: AOJu0YyymTFRtcKCdQWrwrGn7rN5deKaTXe4dNcd8jPzWc3ktXrXrMsC YSpa4BWvilCC/w/phmadKkxyjaG9CLRY31daE7iEvuOdM8nhwlVHFc0rdFYjG1o= X-Google-Smtp-Source: AGHT+IFDgPRujvPs0pY58RBt0z0M4T/+m/fwfgJO35cZdR0pWvXLPvq+fQ5KKo/0SLFh8TiIvn9dYw== X-Received: by 2002:a17:907:6d25:b0:a86:94cd:97f0 with SMTP id a640c23a62f3a-a89a26bfcb7mr138897066b.19.1725001475410; Fri, 30 Aug 2024 00:04:35 -0700 (PDT) Received: from rayden.urgonet (h-217-31-164-171.A175.priv.bahnhof.se. [217.31.164.171]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89892232c7sm178026866b.222.2024.08.30.00.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 00:04:34 -0700 (PDT) From: Jens Wiklander To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, op-tee@lists.trustedfirmware.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Cc: Olivier Masse , Thierry Reding , Yong Wu , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T . J . Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Sumit Garg , Matthias Brugger , AngeloGioacchino Del Regno , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jens Wiklander Subject: [RFC PATCH 0/4] Linaro restricted heap Date: Fri, 30 Aug 2024 09:03:47 +0200 Message-Id: <20240830070351.2855919-1-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Hi, This patch set is based on top of Yong Wu's restricted heap patch set [1]. It's also a continuation on Olivier's Add dma-buf secure-heap patch set [2]. The Linaro restricted heap uses genalloc in the kernel to manage the heap carvout. This is a difference from the Mediatek restricted heap which relies on the secure world to manage the carveout. I've tried to adress the comments on [2], but [1] introduces changes so I'm afraid I've had to skip some comments. This can be tested on QEMU with the following steps: repo init -u https://github.com/jenswi-linaro/manifest.git -m qemu_v8.xml \ -b prototype/sdp-v1 repo sync -j8 cd build make toolchains -j4 make all -j$(nproc) make run-only # login and at the prompt: xtest --sdp-basic https://optee.readthedocs.io/en/latest/building/prerequisites.html list dependencies needed to build the above. The tests are pretty basic, mostly checking that a Trusted Application in the secure world can access and manipulate the memory. Cheers, Jens [1] https://lore.kernel.org/dri-devel/20240515112308.10171-1-yong.wu@mediatek.com/ [2] https://lore.kernel.org/lkml/20220805135330.970-1-olivier.masse@nxp.com/ Changes since Olivier's post [2]: * Based on Yong Wu's post [1] where much of dma-buf handling is done in the generic restricted heap * Simplifications and cleanup * New commit message for "dma-buf: heaps: add Linaro restricted dmabuf heap support" * Replaced the word "secure" with "restricted" where applicable Etienne Carriere (1): tee: new ioctl to a register tee_shm from a dmabuf file descriptor Jens Wiklander (2): dma-buf: heaps: restricted_heap: add no_map attribute dma-buf: heaps: add Linaro restricted dmabuf heap support Olivier Masse (1): dt-bindings: reserved-memory: add linaro,restricted-heap .../linaro,restricted-heap.yaml | 56 ++++++ drivers/dma-buf/heaps/Kconfig | 10 ++ drivers/dma-buf/heaps/Makefile | 1 + drivers/dma-buf/heaps/restricted_heap.c | 17 +- drivers/dma-buf/heaps/restricted_heap.h | 2 + .../dma-buf/heaps/restricted_heap_linaro.c | 165 ++++++++++++++++++ drivers/tee/tee_core.c | 38 ++++ drivers/tee/tee_shm.c | 104 ++++++++++- include/linux/tee_drv.h | 11 ++ include/uapi/linux/tee.h | 29 +++ 10 files changed, 426 insertions(+), 7 deletions(-) create mode 100644 Documentation/devicetree/bindings/reserved-memory/linaro,restricted-heap.yaml create mode 100644 drivers/dma-buf/heaps/restricted_heap_linaro.c