From patchwork Fri Aug 30 07:03:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 824291 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 1DA8515217F for ; Fri, 30 Aug 2024 07:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001480; cv=none; b=b8gfGLJwHx7MQoaUF4C3ucG9cTPrkFtOkvXMm8dEsx7DrBsKsUX8Ai9KONrsKfr2chXmkagmrZHXVslmptoP2jLfKvAK2OWuWRTlTrLjFPq7812IuO7A4r7XY9TEEqzIrOprk8poBhEXB827xg/GZayJSDBESSdanvT18yJ4t0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001480; c=relaxed/simple; bh=mrYsgAuZfGUR8a8DXSlScOmgUWNB5y3kFvuvISaLR1g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nto5CiM/j0p5lXxb9vhdSWG4+gggD+s7b+kmR5ebmU1Hgg6SNUKQTJ5HOhR3WXxEq8apikLYwT0ucloIPjIN2dOywM4ebldwN9wDwpoLr8CdMbHsr9hJkTMqqb5whE+NSgAh5L2V8CnbEZKxouhxI1cEx35licf9hzYkT71SdFA= 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=IS1i2oeh; arc=none smtp.client-ip=209.85.218.43 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="IS1i2oeh" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a86abbd68ffso257860566b.0 for ; Fri, 30 Aug 2024 00:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725001477; x=1725606277; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MJjNgUGJenoBaIKVAgwwwsHux2S25WdElfpi6ReEk9U=; b=IS1i2oeh7nx1IhLLzty3pFy84g1mP50uDp/ay0GlWXdfZRoJ/ei2hRnvOxFBW1vmy6 fj+iD8nzzU2td1dtxsL/qpF0CKsifrshVUVYgWUobJTCwCD0GBOfci/CANsbFiEj1e2l /HOnriDbpGJaAx9RQ7WaEiIVzJD+jAHn8JqWaSmw3g9Q6OJppIvGcljwyGKPY04BFHDW OLM96OqXuxEU0miBhWkeMna8I0WDGnM5LDESHrmkRophogQ9CCdSUk90OhZ2hAxMcHyw LRiF6GhRO1LD6W76kcnj02rAhQsPNnPWZHRgmXho9AhJ4vBDialYrJWTDl4UMD++2dKI Q28g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725001477; x=1725606277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MJjNgUGJenoBaIKVAgwwwsHux2S25WdElfpi6ReEk9U=; b=iuhJemGgODMWLwIRzVK9vwEiQyKM5cLMWE+M9RurCPGGWMlGNBQ9ZAHd05tCXr9KXh taX0RGPLcFtkbT8g0O20h1kLKaTxfMoCvkshI2NyF5WKqw1srYNf38i3ZefmC5lnzdtT CourIDXLbtyzPRMvqCTYmU2Qn4HetIKW/xSWKMeGEC9i1BauKN9P3pvKIwDSNCai8Ec1 4wT/m+LExmopT7/C9M9BVa2xS2UNWk3QNYK/s3vX+BIAtFQS18Btx+KxLKQ4ZlEF/KTz AwGGMgcq2VU3MEF4a5ez8n7V3zVye8p2vqwtFCr8yRCzoNScLz+ou+7yHfFdrVIX7sL0 4TtA== X-Forwarded-Encrypted: i=1; AJvYcCUOVzPhrhZQKpuR4ElyI5M0J4evah/LYuUwaXjIDzFo2Z20Npey7Kf0FZr+XNKmosXcQGeJPxvf4sQ9Lg==@vger.kernel.org X-Gm-Message-State: AOJu0YyhbP4me8FUwGz6M7wpTffuxtyorGzLdt8KS09Hm6MIWHA54tfk XT9ZDVMy4Y5pMw4UGEf01LR28VCl9ySyRffFulB7gWyD0phlLPytX5WcP4zsXNM= X-Google-Smtp-Source: AGHT+IH87EkQZslfXd1cN/MuD1B1+tjpJHcDRiz/ebksiuYOXdKRtj8j5p8EyAgrD5jVzjEwQczjhA== X-Received: by 2002:a17:906:4788:b0:a7d:89ac:9539 with SMTP id a640c23a62f3a-a898231fe8emr528271266b.7.1725001477275; Fri, 30 Aug 2024 00:04:37 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 00:04:36 -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 1/4] dma-buf: heaps: restricted_heap: add no_map attribute Date: Fri, 30 Aug 2024 09:03:48 +0200 Message-Id: <20240830070351.2855919-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830070351.2855919-1-jens.wiklander@linaro.org> References: <20240830070351.2855919-1-jens.wiklander@linaro.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a no_map attribute to struct restricted_heap_attachment and struct restricted_heap to skip the call to dma_map_sgtable() if set. This avoids trying to map a dma-buf that doens't refer to memory accessible by the kernel. Signed-off-by: Jens Wiklander --- drivers/dma-buf/heaps/restricted_heap.c | 17 +++++++++++++---- drivers/dma-buf/heaps/restricted_heap.h | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/dma-buf/heaps/restricted_heap.c b/drivers/dma-buf/heaps/restricted_heap.c index 8bc8a5e3f969..4bf28e3727ca 100644 --- a/drivers/dma-buf/heaps/restricted_heap.c +++ b/drivers/dma-buf/heaps/restricted_heap.c @@ -16,6 +16,7 @@ struct restricted_heap_attachment { struct sg_table *table; struct device *dev; + bool no_map; }; static int @@ -54,6 +55,8 @@ restricted_heap_memory_free(struct restricted_heap *rheap, struct restricted_buf static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachment *attachment) { struct restricted_buffer *restricted_buf = dmabuf->priv; + struct dma_heap *heap = restricted_buf->heap; + struct restricted_heap *rheap = dma_heap_get_drvdata(heap); struct restricted_heap_attachment *a; struct sg_table *table; @@ -70,6 +73,7 @@ static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachm sg_dma_mark_restricted(table->sgl); a->table = table; a->dev = attachment->dev; + a->no_map = rheap->no_map; attachment->priv = a; return 0; @@ -92,9 +96,12 @@ restricted_heap_map_dma_buf(struct dma_buf_attachment *attachment, struct sg_table *table = a->table; int ret; - ret = dma_map_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); - if (ret) - return ERR_PTR(ret); + if (!a->no_map) { + ret = dma_map_sgtable(attachment->dev, table, direction, + DMA_ATTR_SKIP_CPU_SYNC); + if (ret) + return ERR_PTR(ret); + } return table; } @@ -106,7 +113,9 @@ restricted_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, struct sg_t WARN_ON(a->table != table); - dma_unmap_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); + if (!a->no_map) + dma_unmap_sgtable(attachment->dev, table, direction, + DMA_ATTR_SKIP_CPU_SYNC); } static int diff --git a/drivers/dma-buf/heaps/restricted_heap.h b/drivers/dma-buf/heaps/restricted_heap.h index 7dec4b8a471b..94cc0842f70d 100644 --- a/drivers/dma-buf/heaps/restricted_heap.h +++ b/drivers/dma-buf/heaps/restricted_heap.h @@ -27,6 +27,8 @@ struct restricted_heap { unsigned long cma_paddr; unsigned long cma_size; + bool no_map; + void *priv_data; }; From patchwork Fri Aug 30 07:03:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 824290 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 0FF9815AD99 for ; Fri, 30 Aug 2024 07:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001484; cv=none; b=nSoUeWw9eMtTJAWaa78+MqpbICzDb98l1zgza185uQh5Ez7Temw6qZrbEsJClIhW5flhkS+2YZEjTPeGz114K3InkayG24cjTjnL4LQAEc5HI6BXo0RwewLpHCJc/zhiOqX+bwPfCn/XONSjsLPeK5jEwvpJLWk5zqO6Slw8UeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001484; c=relaxed/simple; bh=Ds/p/QFF05sAfiQkLU7WUEFq731HQlapY7eFUuPiT1g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ml9tm/pChaJKpCkjK/z3+J6ipZt+sTO4c0gDe2OoMeClAS5+slkGMEY8Z8FTWr2PXtfKAYNeXh7hwvp/eVaZ9FTfI0Gnf8gdMFnLBxwv/2tMl8yhcq/uEQZO3cikVrXJkEjz4MZ1/Sq+fobB0PX+bDdnnUHEOXrIVe68bZY7q7g= 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=g5JV0Z2B; arc=none smtp.client-ip=209.85.218.51 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="g5JV0Z2B" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a867a564911so179271066b.2 for ; Fri, 30 Aug 2024 00:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725001481; x=1725606281; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xfKg3et82GR8Ut+Mah5KVc5YDnZncDhvNa0IoupXc1A=; b=g5JV0Z2Bp7xrqloOddFPC4aQyt66eAcYjODTp5zrihHQisSIFxkBms28HER0F0t8ee B3QcDwOL5vhnMxvvZcy8kVtynfmaSZZsk1RFlyK+UJnYdf6SnQVbp38+KetnrvG6W7o2 c5K8tSmMC5yhggUh6hPHd743TkDQ5zlsUiIVOw1HkcX5KUPWB2QFusekVfTZRPpI7wuJ cjm8ugHg0mm3dj2Kw60yVtHJbUpOKkgiDNc1XL2eu4W6WjrzzK3OwLGQQbu3m5gKfhzu hBnxea9+brn4N/DjBGCDrsg9xY7IMy8ju2/FZ+HivLhQDhQnr/BY0iUk2PGgc0ZKn7Yg zlSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725001481; x=1725606281; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xfKg3et82GR8Ut+Mah5KVc5YDnZncDhvNa0IoupXc1A=; b=DP63rNu+NjGx/JTO/6KE1BuL6YjgPRBJ9qhxiGsz7NIcNsX62/M+zcOSktmcBxBLdc YFjSIgPPKB5lGVX2bMjgxcria+PH3frwnfyZWB0uIvSx1WRVwwufD82D4CNcroJJaK16 mFq4ZMUYN5C1hQw4uq6n9lgoOPHO2Hxudyc1icDzU8yFXkVfYwUKNm9Yu8vnNP7CN/Rw 0L+IsmZrOFx79+07OxM5a2jvZfk5iv+fCPzNQSevBwyeErvgKZrensWQIdSTRWYYpzHo WUbkGgDLxmnPFGjXfn4K0yAqtfwSNqGTP72ByEBVnPz/BJiwkUNYqE2BO2kv9kCCHfBZ 1z7g== X-Forwarded-Encrypted: i=1; AJvYcCWVSyMxR+z8RtLJ25IKzzoY/YcFpe1bq6Qn3hQ3EWjpOIZzaUsszyLITExEdA0PWjGdoM40g8S01vWfwA==@vger.kernel.org X-Gm-Message-State: AOJu0YxgCdFla3zd50kd2vf9SxU7GQo+37sSsOQYtY/11f3tFJAE67ug yj6/XSJe4aXfhOs08pfEzELV5zA86QNnFY/4EXc6JpBNMI2TiqSvxkdyXixYvIA= X-Google-Smtp-Source: AGHT+IECnqDtOxbvfOy9sPbk0lCyiNAqNWYzneroZfijzEEU+LtepnDur/LFnUatGwBb6xPr3tERGg== X-Received: by 2002:a17:907:6d0a:b0:a86:7f6a:8779 with SMTP id a640c23a62f3a-a897fad4d42mr418259566b.57.1725001481050; Fri, 30 Aug 2024 00:04:41 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 00:04:40 -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 3/4] dt-bindings: reserved-memory: add linaro,restricted-heap Date: Fri, 30 Aug 2024 09:03:50 +0200 Message-Id: <20240830070351.2855919-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830070351.2855919-1-jens.wiklander@linaro.org> References: <20240830070351.2855919-1-jens.wiklander@linaro.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Olivier Masse DMABUF reserved memory definition for OP-TEE secure data path feature. Signed-off-by: Olivier Masse Signed-off-by: Jens Wiklander --- .../linaro,restricted-heap.yaml | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/reserved-memory/linaro,restricted-heap.yaml diff --git a/Documentation/devicetree/bindings/reserved-memory/linaro,restricted-heap.yaml b/Documentation/devicetree/bindings/reserved-memory/linaro,restricted-heap.yaml new file mode 100644 index 000000000000..0ab87cf02775 --- /dev/null +++ b/Documentation/devicetree/bindings/reserved-memory/linaro,restricted-heap.yaml @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/reserved-memory/linaro,restricted-heap.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linaro Secure DMABUF Heap + +maintainers: + - Olivier Masse + +description: + Linaro OP-TEE firmware needs a reserved memory for the + Secure Data Path feature (aka SDP). + The purpose is to provide a restricted memory heap which allow + the normal world OS (REE) to allocate/free restricted buffers. + The TEE is reponsible for protecting the SDP memory buffers. + TEE Trusted Application can access restricted memory references + provided as parameters (DMABUF file descriptor). + +allOf: + - $ref: "reserved-memory.yaml" + +properties: + compatible: + const: linaro,restricted-heap + + reg: + description: + Region of memory reserved for OP-TEE SDP feature + + no-map: + $ref: /schemas/types.yaml#/definitions/flag + description: + Avoid creating a virtual mapping of the region as part of the OS' + standard mapping of system memory. + +unevaluatedProperties: false + +required: + - compatible + - reg + - no-map + +examples: + - | + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + + sdp@3e800000 { + compatible = "linaro,restricted-heap"; + no-map; + reg = <0 0x3E800000 0 0x00400000>; + }; + };