From patchwork Mon Mar 3 11:40:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 870025 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 80CC3200BBC; Mon, 3 Mar 2025 11:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741002017; cv=none; b=NK2DnzDkaOZeOf/mT5QmIJoLoKEj6HnGqV6+2Gbk+vktV9JHiQDZHowleyLwoKPkynJEM/7D4qjox5265EomH4IzCPv2b9YuCvM6gJbgwbAe3jDEGYMHySM59lbfYSUX5EV2MsDDLYyJ8ft6HfDlxC0VrUQWKokrGw8FZNP3Exk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741002017; c=relaxed/simple; bh=vexmjRShWRkr7S+O8wIzsYn1ODE9j/1sozVgI1TDUjs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bp3aqvUx8Fb9JqUvHtvCbKIBubOo+WQSm/owfF7NrC6+PbJqsrkPi3/X/xiCHL1fi6fO2P52FIO+zNIFKspKjQmOqXcmU/hyrOUGpyIKof95L+wVEXtzIlU0+bdQkS/TFvcsslSuiw3JiM8yB+1sIKQPhCIBSbkNsavIMiiQWEI= 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=PWcfLBpg; arc=none smtp.client-ip=209.85.167.53 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="PWcfLBpg" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5494bc8a526so3717827e87.0; Mon, 03 Mar 2025 03:40:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741002013; x=1741606813; 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=a3KshhKLPc3asFmOXQnuU+ysx6yVcCHiVd9RsF7krHs=; b=PWcfLBpgbyy01yn5+C0iJvUKDGS3hDiO+8ezodFzKDM1PrDwyXd9c3YpAfyRvgkVKH NfJSQQmxBGLNAlvSTtpvDJgaP4lgAuSu19p66EoCpllYBqeU8uyEOLhHF5fmrajxvWdx rsZTAuy/YSa46607ao7hsEPAzMlfohqa5KmicpPOViW9yhMxRCDEE6W/eQYRp7Juk/P8 MxXElLKztOFprUWanUNzCQ9JImc+KGSnqdDu1V5/ujSMxJpk0tzLttGcPERFqt25RT7E MK74uQlOpp2Xa4BJ/yQBG99bJ3wfpLUZBIomiPfzmo6Kj+7l3UHfWhAnl1+OHnaKjKTO xi1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741002013; x=1741606813; 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=a3KshhKLPc3asFmOXQnuU+ysx6yVcCHiVd9RsF7krHs=; b=U6j6SeiWo/CnWoQm188JMboR12+9RsAqwFLOM/C0mqlvvxckmNz0W8hhjcrk23Zj30 CijLWU+s/WuagumHVkGAS1IMny4EWCXI6hq2S8YJTbaIM1lvPI9LlRz/hc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o58FGCyA== X-Received: by 2002:ac2:4a74:0:b0:549:4e80:6dc0 with SMTP id 2adb3069b0e04-5494e806dc6mr4270805e87.0.1741002012981; Mon, 03 Mar 2025 03:40:12 -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-54949de706fsm1125399e87.23.2025.03.03.03.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 03:40:12 -0800 (PST) From: Mikhail Rudenko Date: Mon, 03 Mar 2025 14:40:09 +0300 Subject: [PATCH v4 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: <20250303-b4-rkisp-noncoherent-v4-1-e32e843fb6ef@gmail.com> References: <20250303-b4-rkisp-noncoherent-v4-0-e32e843fb6ef@gmail.com> In-Reply-To: <20250303-b4-rkisp-noncoherent-v4-0-e32e843fb6ef@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 a13ec569c82f6da2d977222b94af32e74c6c6c82..d41095fe5bd21faf815d6b035d7bc888a84a95d5 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, direction); + 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, direction); + return 0; } From patchwork Mon Mar 3 11:40:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 870024 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 3C52E201006; Mon, 3 Mar 2025 11:40:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741002018; cv=none; b=Zy+9pykK0Jvrr2WqeN8/MRd4g2usFoTjyT75SLyHC2nslejplJhTXb0D/Fr4DNTEiL5iJSjN+qJS+EjIhuFFZxD4Emh9ix4rgcixBAq3SMz18278ltqQHA+QlgyzDjvgC1H5mPnGvsC3R7P0Y7N3yNaGFCUhUQY4PwS5M3IM5Sg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741002018; c=relaxed/simple; bh=YYbw0twHWKoAfJ9niGlDXpv/GCZV3S5e278sKRuhd1o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Oyqr4OTnfMnPzNk5IVnE0SAa6dYslLrJfpSGoftk0Uy2KmCJ1IgXHJ79k5HsxUqRgp8Qi1UDYfHn77B3lFhflB2S0OL98BsB2JQRQofcpzKMetMGitdsMGsFbjjBR522zy1a+0eYMr9nUghLyqdHjpJjeX5HkCsm2dYRsKX2eI0= 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=LVydP8Gh; arc=none smtp.client-ip=209.85.167.53 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="LVydP8Gh" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-549490e290dso3158583e87.2; Mon, 03 Mar 2025 03:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741002015; x=1741606815; 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=RqOngwUEjSuVUtl2EN2OtrWhKsT4v+sY6g+D1KtVO20=; b=LVydP8Gh4kYxLkMR5DNbcCr1sPYhsfIFVrG57frC53GxtXT+FUoorKTM26v8ghKAyr kMZHaxbhZHRJ/4R0Bc6cG5vxXsAekNhLcrXpLc0uCvmpGOYhGHMnOgyayYwi9QZoyWcM wUEL6o+pAob98XLNlsIRhWfxf2MuF317D20ANxlPmMxihTaL/EawtaiVoUa+AYCXGUOP AUOIxYUIAhH16ovgg8e+2efBeeCovBMwPTKowXhtYvwYP4fcpQf9dmnbJIfDe04TF0Dy wFQOB9NJJtA1LagsbausG1oKIKBA3IoBB051A/J+dvB9/LKwhHCCaUB+0GEtEQZmRQy5 QH4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741002015; x=1741606815; 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=RqOngwUEjSuVUtl2EN2OtrWhKsT4v+sY6g+D1KtVO20=; b=gyZRSzVqfsjjNedGF7h7xomYWcSZX//HF7IcZGQv54pJCQhL6kdmyB77p4MNkQDtJY rXx6DUq9ZkjPuIrIgA+DfyFUsAc9NNYF+Q09Tn/osQJ4J3zuxK9jpsSaOBROnV2Cx6MS 1blhBsOe+i2dwjQxMVej4qBDF92gll+AVePuzDaxZbstykZHkvS2V9PpSyr5Yyy7Slfx rfhPXjxFVRxd8TB1VuuG+cDtmx2+gGrhzfn8CLavCXmPCRZjblj/TVqeNDs6XBprpTsK Svu75IT+l/ymqXPbPhalha4ZiheyGvWAglcHC0ujRwxOUSVtiXYUzcPCfe2CjXml5Qti V+qw== X-Forwarded-Encrypted: i=1; AJvYcCW/Uo+0tfrcgc3kMihjtKz0t/0jo22WuuqWECIZpErg3iJtLLBiMMd0L80v9XuPBrMUmPEPk9ZrziMqWOA=@vger.kernel.org X-Gm-Message-State: AOJu0Yyw/JZtoC0NYCk30qezix59lsDhDKhXG1E99FtVq7Rbgti0HoQX g7caA/nG7DHgPyywyzw9C7w++V6C/xtcAwriA+t7cEGWM7uEU6NbTzOL5OT7 X-Gm-Gg: ASbGnctR5G4n51KU0zi41lKfrT9mUl8FbjbbU8WuWBGd5FlXmyzAZHosTgpPJeF19jl mgwotfKrlv85I0w5H66+a8gJF+Fi8oBgXDo8uTBA41DoMI/ML3oobm15ILiglhgTqwGpG0cjuhS XrsIpFz9nwJu99+H5NlUV735E7uch7oDrO4caAj1CbpeKMUIhfW+IXwe7KZvG1sIN2Sk5CLh4Vw RthVz0HR9+gnNERWM9jmE0icNYgiLizZHEAGVMnhURpzeiBTLMQ+Ehe25NzCCN/B2kiJklC0Q6t ygJn6QfQ2RGSSI+f/ibSzXEpp7zZJwVbm98lHgPaePah4VHSuSqYQtHafOPgzV4R0ELw32FRgBd 0mDyf7ImBvC1kgU8lAjM+kQgImpz0bM6DQYH8E2rC X-Google-Smtp-Source: AGHT+IH6/3bm43v60en4yvBpA0E6eJcZTxM/vDnluS8y2VWAPrUuChj3nEiAbcrbv7L0cQ0TzEE54A== X-Received: by 2002:a05:6512:3f18:b0:545:1d96:d6f7 with SMTP id 2adb3069b0e04-5494c333056mr5105031e87.32.1741002014366; Mon, 03 Mar 2025 03:40:14 -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-54949de706fsm1125399e87.23.2025.03.03.03.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 03:40:13 -0800 (PST) From: Mikhail Rudenko Date: Mon, 03 Mar 2025 14:40:10 +0300 Subject: [PATCH v4 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: <20250303-b4-rkisp-noncoherent-v4-2-e32e843fb6ef@gmail.com> References: <20250303-b4-rkisp-noncoherent-v4-0-e32e843fb6ef@gmail.com> In-Reply-To: <20250303-b4-rkisp-noncoherent-v4-0-e32e843fb6ef@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,