From patchwork Tue Jan 28 20:35:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 860737 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.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 6FBBA1E98E1; Tue, 28 Jan 2025 20:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738096587; cv=none; b=L9+eqV8cdZGl4HT1eZ00rTc8lk1WeswKNSqVO5NasbQ3XRPpaa9jmYEuAd2TltA0zmTVV/8NGZsswRz8Z1ouP3PZP/1fpm2lmJmFClhUBCXTltuZmf8W0lpC+2uHGrmELv5ABZ8GmKUtVIfEpTBu2KsHMsV46GGBhe18+JnJWDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738096587; c=relaxed/simple; bh=qVTrrQkFDNqvXyLb4nP25mCPoBVYVZ41Pr+y0QNrMso=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gcHdLHDdAj32p95VI360bI8VWExvydtZEeDEDkEuItKgm9+5/Lq1F65txq71wXXVmlTMdzCwePlszzjKQr3S26aF8ptv77gx8avl3DvLG7F9o2qDHOwg20dx2M8WVW7L9xRjNr3moN8qvLO9nbSa5bvcspPfbwQIVsoz4b8/KDM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BvGpkedl; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BvGpkedl" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5401be44b58so6557292e87.0; Tue, 28 Jan 2025 12:36:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738096583; x=1738701383; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=z8MTyUlPh3gZbGYt+/m2sUV5tFwW7lwH2zL30YhNj3E=; b=BvGpkedlxhN3T8I1AJiP9M5U7VQtOv6K6BAbAdWwX2uyfJD/RtegxjQ7jA8wbffrKE hfgTzb05tiL3569gMJQQu2ZLLmUdcN/kgu0BnnNgpFGqyHw+L5NYCjFvrxdiQP9z9Nlu qV9Q6Pdj/rXWL8O6vg7vr2ot6b/xP1wl77JTb4eIJJKr+Gse9pjlWG4rLX0uF1I8eVXM sVa7YG2+sEIqnjJZwuexR97mDGqMhzYsE9bFUzJudVTU4lN0BjqNKswNxkdPVf4IYL5x CJtk0rvB6DjvdugTpuoU/sfWO+SrdBhmfQGtpjB33VekG4WlfBiGZHsAV5hIZ0uaapet vCrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738096583; x=1738701383; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z8MTyUlPh3gZbGYt+/m2sUV5tFwW7lwH2zL30YhNj3E=; b=FIPwd7uxMY3UR+1PVoko6CEBZ6gMu9MJGQch0IIeom9S1MvIFeJZ03tiVrDCzFLv63 FKZQ0KtDBTPvy9VB08O1LLybzQ1IC85Ni/oqPozkPVQsRg9t92+gO+2QjyepZbILEbOv Gavlo7OPHTYAEd/cJ8AYtA/u8KVZg1BsPSGWLvOZ7IHq2GhLcKtJbeVISO9XEzMHHdMb EKh3xKQTWLQqEkWcECc1teJOR7t1cVuN3ojR7OI5fz52PCCPcRCyqRqvoT8H6NiMu/fS 3dDRzZWoFeVb6CEXDWu7J8hltsCPwaFYzAPwKr9S6dykNHafg8cPnsQa9I18xCJ9xP2W 0LJQ== X-Forwarded-Encrypted: i=1; AJvYcCU7PneG0fqTR6unjt2+Q9C8pZw5LfVerldIFV/WfRCFUtd/+/jQ/NVMzSA09yZfZ2YIuX42dgm7+QoLa/o=@vger.kernel.org, AJvYcCVSbBZKh4Hj19ud/fs95fP9U7YuZZiqmBDOdn43sKtugewRuQTWT4tTwKFk1fu622mrSaHU0s+N@vger.kernel.org X-Gm-Message-State: AOJu0YwmuUEGL8mDtV5iW8X8xorA3ombYXqisdyhrh4enRZyg+BnhYZH 9IjTSXMv3kgf2Qa5aQe90JqJyIDIEMlaeKAm8yJQK1J4go0EPo5bqCz1yQPI X-Gm-Gg: ASbGncuI7423aXzwC+oOSJduqw8hnsU/db9zykyqtzRSEcZNz6D3UwZkv6NCJwGf6wz yUDcHlaJFwcvSjN7rY/w81Gj41bVdxl+jWFm8PREuETpTgQwuwH02jIGpsJLPoyRIrSvjkq2l7O V+SpeLk6vhuExHDdJGB4mSdVHOSRsu3/NJMIhjjF9iDwlNInj0pVgZQGe3KucIEIJxrXGS0LskM 2InK1+DuTvB12O1nOVXAasgbZpfhxeCA+NkWqmqPktn2qc7pLnxAQNj+Wp+FkECCPC5OxmOv6dt 3SPv6DB+YsKABOsejc61JNlZQ1oMLHBij3pNiPlbPSm5vrzbX/uBhJR7pMeLj/4VOPqg/HD2UOa 09fVVkMNWj/c= X-Google-Smtp-Source: AGHT+IGXx8ir1+EZxeY6N5v7kjSeoMSS2MCJ9pG/fcIMmWsjx/6j0N5nIJirlOL33zDZIryOayb8uQ== X-Received: by 2002:ac2:43bb:0:b0:540:1a0c:9bac with SMTP id 2adb3069b0e04-543e4c32548mr129480e87.34.1738096583093; Tue, 28 Jan 2025 12:36:23 -0800 (PST) Received: from razdolb.local (static.248.157.217.95.clients.your-server.de. [95.217.157.248]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c822fcb0sm1778361e87.55.2025.01.28.12.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 12:36:21 -0800 (PST) From: Mikhail Rudenko Date: Tue, 28 Jan 2025 23:35:51 +0300 Subject: [PATCH v3 1/2] media: videobuf2: Fix dmabuf cache sync/flush in dma-contig Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250128-b4-rkisp-noncoherent-v3-1-baf39c997d2a@gmail.com> References: <20250128-b4-rkisp-noncoherent-v3-0-baf39c997d2a@gmail.com> In-Reply-To: <20250128-b4-rkisp-noncoherent-v3-0-baf39c997d2a@gmail.com> To: Dafna Hirschfeld , Laurent Pinchart , Mauro Carvalho Chehab , Heiko Stuebner , Tomasz Figa , Marek Szyprowski , Hans Verkuil , Sergey Senozhatsky Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Mikhail Rudenko , stable@vger.kernel.org X-Mailer: b4 0.14.2 When support for V4L2_FLAG_MEMORY_NON_CONSISTENT was removed in commit 129134e5415d ("media: media/v4l2: remove V4L2_FLAG_MEMORY_NON_CONSISTENT flag"), vb2_dc_dmabuf_ops_{begin,end}_cpu_access() functions were made no-ops. Later, when support for V4L2_MEMORY_FLAG_NON_COHERENT was introduced in commit c0acf9cfeee0 ("media: videobuf2: handle V4L2_MEMORY_FLAG_NON_COHERENT flag"), the above functions remained no-ops, making cache maintenance for non-coherent dmabufs allocated by dma-contig impossible. Fix this by reintroducing dma_sync_sgtable_for_{cpu,device} and {flush,invalidate}_kernel_vmap_range calls to vb2_dc_dmabuf_ops_{begin,end}_cpu_access() functions for non-coherent buffers. Fixes: c0acf9cfeee0 ("media: videobuf2: handle V4L2_MEMORY_FLAG_NON_COHERENT flag") Cc: stable@vger.kernel.org Signed-off-by: Mikhail Rudenko --- .../media/common/videobuf2/videobuf2-dma-contig.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index bb0b7fa67b539aa73ad5ccf3c3bc318e26f8a4cb..146d7997a0da5989fb081a6f28ce0641fe726e63 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c @@ -427,6 +427,17 @@ static int vb2_dc_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf, enum dma_data_direction direction) { + struct vb2_dc_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + if (!buf->non_coherent_mem) + return 0; + + if (buf->vaddr) + invalidate_kernel_vmap_range(buf->vaddr, buf->size); + + dma_sync_sgtable_for_cpu(buf->dev, sgt, buf->dma_dir); + return 0; } @@ -434,6 +445,17 @@ static int vb2_dc_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf, enum dma_data_direction direction) { + struct vb2_dc_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + if (!buf->non_coherent_mem) + return 0; + + if (buf->vaddr) + flush_kernel_vmap_range(buf->vaddr, buf->size); + + dma_sync_sgtable_for_device(buf->dev, sgt, buf->dma_dir); + return 0; } From patchwork Tue Jan 28 20:35:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 860525 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 490891EF084; Tue, 28 Jan 2025 20:36:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738096590; cv=none; b=D9tQI8NLgS+DHPRsIzlHbDmsK+Q2jS5zoF5OZhHUT+PFoTuJ7097S/n+d1w9ggXw4tnUetIJDkF6rxDcI5Q9YYmh1oEL5Y/Odm3GzbMRpy9yriS9JbPPp17uhdZtJzxzqBIzmK8yaBoBYpM+1XafRbvhbOqLl7mDXb4B4PwC/9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738096590; c=relaxed/simple; bh=yqiH8zQa4ElqkkjmIJW5m3RfF/o4uD61OfV0gG8rgTM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=thINJfeSFQCd+lL9A8Wd27NWFHRjmDD1ATBw7E/o9zuCjUoSZgCBWe452If6DB5euQpCkgFpRdM2S4vrINnnyotqYROeRlyqgjSS1rNd2RaDQifN2yq7KpGwZPJorwQwJLOE8GXc0uVdzGTSTWTg8r22xBF8yv181kC6VMfLEsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GIu9wA8P; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GIu9wA8P" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-53e3a37ae07so6878199e87.3; Tue, 28 Jan 2025 12:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738096586; x=1738701386; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=UOk1tpd1Scx8u9ygptTnBU+QUAeBmZsMjmcHaDde8t4=; b=GIu9wA8PAf4MY5/mc1aZ48zOZGUAi9Jw03CQ4RpL9An7OmdaOlEvYGuAqeHaHJTkGx PhI1V33iVJgb8qgmFqvd4TdgsUbO4Wts/dht2JAxvg3eNaQ2+q36MOboeaBnMZ9hiyFM g453wJkSYFWoIup2Sin72EGthZHp4GCxxZzeTwIwuY+yxlfQDAK8pCQobfp5WxlyM9I7 5NtxS39FrKYeuMiJTUbofqUn9qn+vksMVblzWwExJym97zw5bUIRhSGSI4nfD0M9chxK rbK5uJNjUskOJvGAuKzac66tTiRNGTcgm71HUUFRkZrbN5zyyQdKzhWkZzfxswZGFLFz yqgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738096586; x=1738701386; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UOk1tpd1Scx8u9ygptTnBU+QUAeBmZsMjmcHaDde8t4=; b=lI8wDAuJW/9qsDb51OZ5/LYvut6N8mBy4TELW07rbK+j6a2UrXNXnjbXzJM64Spnfq RGZvKtGpKsCctJ6koDFoFC/5wlHNYFS6UrKR4ZQ9Smr73xpsk0dwwwdp/8FTZ9UxgrXx oCAnJASNnYeRDwTPTr3yOYbHIsXgf8zfR4801IlCJN4xafb5LPDNBcJGuSN4jOVExJjV Cbpwvf+tvpProoqOf0cvMVVxkJgikieaRA/GEv2VUx2mE+OoGzrdYfE/+dCiN9kFk7ZL H8eUuYBFCGaXxSnrXvBiCiZOmKU/ueUUym1jzGH9vsYGDquZVvzHPNsq/7DqRVliME5j u4qw== X-Forwarded-Encrypted: i=1; AJvYcCXFFalzq5VimnADkPB4UDovhIpMlKRGEfbvOuABy0NiMmAsov1xj+7FnX4sRqVxGqK73chueBHWG83Hxis=@vger.kernel.org X-Gm-Message-State: AOJu0YzpEM8PRj5sujsbORr2Oz0WiSOO1D+XH3dfknYgLf5RcsQcgEod Y7xAtc2BDRiTI8wbxMgjiIuX9P6kTB7ZZE//wTPbX0iKqzfWRDzGNcVff2cY X-Gm-Gg: ASbGncsU57AWS/u0RQFxUzp6AsoFubPCuFc6j2ctG7gY/iP7hfdfmIeotWguc/BF456 0cmgh/mYMPugDmn9OsHQ0J5Rb6Ryj7LAObNsT/o5D8sjWKmXLP4fLSqgj29/DEcQLdLZLhWPXGG PxXylQd+1M0Nmr9MjAXs7lIxrrDDw9YxU3QNBqoKmWkhvNEDksVs7ADLrf7wXM5uAHmDqYo3Lh5 FpIOFwcx3jdExzBlDP8zm33onqo8z2Hlfjfdm0WmlnQpS3WTN2mEHTYqCmTHlmhIiCqeypumnAj mmQJfv6j0f4wsIX0IJSHUyJdcvGgPECVN3TMTI3ousDo7xiwiGWHDZwdOnGT8PKKnGFedfNUH8t 3KRMnPHaXOqE= X-Google-Smtp-Source: AGHT+IGMzL/80XBmn1eSfudDP9ZNpYqbMrbvgK9R+lJGhmNTKy7DW7XmzgqBK5JBk5vxw5I6MfuFfQ== X-Received: by 2002:a05:6512:b81:b0:540:17ac:b379 with SMTP id 2adb3069b0e04-543e4bf6192mr102601e87.25.1738096585531; Tue, 28 Jan 2025 12:36:25 -0800 (PST) Received: from razdolb.local (static.248.157.217.95.clients.your-server.de. [95.217.157.248]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543c822fcb0sm1778361e87.55.2025.01.28.12.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 12:36:24 -0800 (PST) From: Mikhail Rudenko Date: Tue, 28 Jan 2025 23:35:52 +0300 Subject: [PATCH v3 2/2] media: rkisp1: Allow non-coherent video capture buffers Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250128-b4-rkisp-noncoherent-v3-2-baf39c997d2a@gmail.com> References: <20250128-b4-rkisp-noncoherent-v3-0-baf39c997d2a@gmail.com> In-Reply-To: <20250128-b4-rkisp-noncoherent-v3-0-baf39c997d2a@gmail.com> To: Dafna Hirschfeld , Laurent Pinchart , Mauro Carvalho Chehab , Heiko Stuebner , Tomasz Figa , Marek Szyprowski , Hans Verkuil , Sergey Senozhatsky Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Mikhail Rudenko X-Mailer: b4 0.14.2 Currently, the rkisp1 driver always uses coherent DMA allocations for video capture buffers. However, on some platforms, using non-coherent buffers can improve performance, especially when CPU processing of MMAP'ed video buffers is required. For example, on the Rockchip RK3399 running at maximum CPU frequency, the time to memcpy a frame from a 1280x720 XRGB32 MMAP'ed buffer to a malloc'ed userspace buffer decreases from 7.7 ms to 1.1 ms when using non-coherent DMA allocation. When doing cache management with DMA_BUF_IOCTL_SYNC, DMA_BUF_SYNC_START and DMA_BUF_SYNC_END operations take around 270 us each. This change allows userspace to request the allocation of non-coherent buffers. Note that the behavior for existing users will remain unchanged unless they explicitly set the V4L2_MEMORY_FLAG_NON_COHERENT flag when allocating buffers. Signed-off-by: Mikhail Rudenko --- drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c index 6dcefd144d5abe358323e37ac6133c6134ac636e..c94f7d1d73a92646457a27da20726ec6f92e7717 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c @@ -1563,6 +1563,7 @@ static int rkisp1_register_capture(struct rkisp1_capture *cap) q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->lock = &node->vlock; q->dev = cap->rkisp1->dev; + q->allow_cache_hints = 1; ret = vb2_queue_init(q); if (ret) { dev_err(cap->rkisp1->dev,