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; };