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: 13784398 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 49DD9CA0EE6 for ; Fri, 30 Aug 2024 07:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=NAqkPKV8FIclg2RIfEME8aNTCMBfxloXKZQVTM0jEG4=; b=2k0//aLWBjLPOA9HheXBIREWad QpFSh+GGCKZ0eAt5Pr5zt2MJQxaW1O9k7Q+7E02e95iiXuMpHscyrmGGJjNohveXLhFEpOpDwKlpM TDVZFvCoUCO9jJDZIkJO0AcBkClGW/Kliask2M3pTVAqFS9uCt3or5XvLFZzFwKiTCvthLVUoISre vfmkq1ig6e3fmid5KwmxCnv9IJcn2uQVzcgL2KqafdZTd6dmOmLWlTqG/BoC1K1ZOmiw2b5TorcHv jTizooyHfSImAE1VSDpMWlzJno5JHn0fvKcTo2OeTmIgr7wFtjK0UxrjW6bGzOoVYXgySj+unEfv7 Y/S0aubg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjvhO-000000052Wl-066S; Fri, 30 Aug 2024 07:05:34 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjvgT-000000052Ez-3PGG for linux-arm-kernel@lists.infradead.org; Fri, 30 Aug 2024 07:04:39 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a86abbd68ffso257856466b.0 for ; Fri, 30 Aug 2024 00:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725001476; x=1725606276; 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=NAqkPKV8FIclg2RIfEME8aNTCMBfxloXKZQVTM0jEG4=; b=RGEdPpKYUDN0rECUSMsbYvRPEbrrSvZWBQqtAcDTRELmBbCOVr3tpUfoMXJ2YsgOtN JiCZy19XR8oQmpQNSkbvz6eYcBBcYxzURbaegq6zysCfsTxcYoEmmTkb8ofBK8d8qIfV NL2jPmGTYELcuEkJ9X0Rc1haStInokpwybwr4B95diK9ZpIYPoFV4UV1vIGGgUnjQY1r McKX1YILymyYwZgkMVQYyzxKEKQzpIxbYnbsYH2K5iAGUnofO4iF3pMt2m/amDYEXpkc l0vbTGH/zgR9Jsa6eBsS7/HEN4SKqpCawHBAPaTsbEwHoEyRr8KCd132S9mf5oLG0zJq Q5Eg== 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=JL1gD7v1ftUI6PV2fmuE4CPO56/CLacGuUEA9UjA8kj70Z5faQIVmzknuDExBHFxQ7 NOJn3ULx6P39tRy2g1CUzTAOpG20j3GHgkj58Mwdn1TeIWFYG7/LAsSHWgWL8NuOLsyz 1AyR/skswRPk7TYQot0I84/KxeNCYJ9judEkc3HlFY44CTB4gU4tGR2VXVmMC9osjuhS g4swjBlOBkul5uoOEoA7FXfAvB1/QsD41PM+2Z6kspAacIHXdk8crn1ymWG8BkX47bTX Bxp9XNXVCO906X1EWUVN/Qm+g5wzE8j4tP8T+uLfXs3WW5YCTccI15dw8OEkJaUkkhLk 4Z6Q== X-Forwarded-Encrypted: i=1; AJvYcCVNa67IwkxfJkJfPvWVgTI2TqsMmxgv85ka9PGPITq2m4tgzjIo4YEAFNYPXPDbRpQxqF4xc2dJEPGEI/jNlRk2@lists.infradead.org X-Gm-Message-State: AOJu0YyR0BhUESTA5CQgZNmhU5obsMuEo5XYnv8HQkK2zbGyEpLz84Ye tNH/BmcO7rgI3ZsDUwvGd4495KOHK1S+dSOIVfTP8tR8ae2OpiFu4+kOUqjvjyY= 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 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240830_000437_888066_AC444DF5 X-CRM114-Status: GOOD ( 16.35 ) 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 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