Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp245839lqo; Thu, 16 May 2024 05:22:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVb7niT1yFPJCRfkmXkhjxeLCZzJeWRuhluiSOLOMx4L6gZuXBUlIpSx5XBZBaEMSQe7eT9QB4lcSqAV6vCyIivxEgnXRVupK8nMKKxQ== X-Google-Smtp-Source: AGHT+IExfkvMTaqw+dOVpcBQmd3UE958zXcfAwYdkM8kRnTS4bosZ6ZU3E99VneDwwxKKvk56kv/ X-Received: by 2002:a05:620a:d81:b0:792:8d34:a9ba with SMTP id af79cd13be357-792c6ccb5b3mr3422895985a.24.1715862165438; Thu, 16 May 2024 05:22:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715862165; cv=pass; d=google.com; s=arc-20160816; b=kzJJLiSC+EX9IMIkFvwkMXVm1GxyPmewv6MU6nDM9P7zk7DBamVxvjfgXDshcyq0SU yHvtGt8pxsroHdjCNUpvrVu37qir6Dyg6Ri2S4fB0ozOh3Q04YYXKfykfftnljwmpn24 yhJgN55M187S1utAmPHZ8OzctynYAxBWWdzjVpH21H9JZzCWnirBcg5GGJfHoQBdB+RO F0FaPgEtYyMYu5Cc4TG9GePiu6mylzotXw/DWG9/CsDEYXIM3xvVmXX3sF1CleaqFZ6A jMODyaF9Saefh9/Pd/QNzsyBFCD3LFtax6M2QH3ix1KfpBFFvxrU0sUicANQwf43durL npOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VqP1QYcwPvehQiDGLMDFdLD0RzGBPSpThiQEXQE7PE0=; fh=biKe3ab6vu9B2YV/BY0rSGdgJ9M/b05dGcvzyA7ivrs=; b=V71T4ncaEFYIZEFK0U664t4TGUVNRgTosDdf5Ed+qrYK5SyLHbBeGaTvAwCNGLPuOP GjW2L7F6a35TPos+Bt9OcfqwuYT7Dsm93geTz3UltfuHCz2u3rVjeBLG380OqCCbBIa6 GynenrlTRxhtnhpcnt9YnBvQI5+wTfjwmjwA0xNQG8NPcDKBMZCocBWpfqy1LAXcpie+ TEUDzmo3wabpp2mirZS7ySl1l3EVxkyZqicFzLRXtHf63c5KB/97QCYXZLKvYFTt07qv 78veV85yhjSubqb+BYDTmvp7hCUJ4Rs9EkgjDtN2Kdr3C7X5dMw00OmX9l85vQfQeiZG Fijw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=o30T7B+X; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-180997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf30acddsi1585182885a.366.2024.05.16.05.22.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 05:22:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=o30T7B+X; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-180997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0802F1C22AA6 for ; Thu, 16 May 2024 12:22:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D555914A4E2; Thu, 16 May 2024 12:21:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="o30T7B+X" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D7E61465B4; Thu, 16 May 2024 12:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715862085; cv=none; b=eLFNSZabIsQ9dY2Dumxz39QYALpyrTvHc/e6EEk8eF8X0XcZzqsWmzTBetSSxoMEog+/2b3sfl86vKB4Zh3laRhvBPPqT/pipUXfWO2TM8AO5NyFKRyqfBjzwLRysyQXZp661LhlyTPIX5/3wwUQ2DW9BMi61jtpy4JbnL6jzVc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715862085; c=relaxed/simple; bh=MMlOdw9ZK61GMU4YfEFlPWyK1UKWaknfnx/1d8RHc9s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rPD3R/aCGBDNkOH6TvFhu1dp8qvzTO6ueoWD4QCUhU/PUukIJBoIs+fAoV+wpS1u4UrHut13BgVjMihG9AwTCvfPElqhjhuFiZytcKlj3zRkAt43aWzBk4jXOMSBLY5fcjafvLBwnbWCEoR/PbHEWMbMqpaXnYpWxBzyDW+NqHM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=o30T7B+X; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: c7f6e1b4137e11ef8065b7b53f7091ad-20240516 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=VqP1QYcwPvehQiDGLMDFdLD0RzGBPSpThiQEXQE7PE0=; b=o30T7B+XUKzLGCdbOD6BMZgGwwJSwdnCTwSUMcGS8H8CUtRToMLEwXcYreHSvQcwOgu7BtAAMsoDAm6/zk1MyKprAJofa70n2rcn6UkLEHeVP6w0rblObGoIaOYrlL6/O4xxizJ0gOEt8s5lgKVmH+kcJjcqgeYoCyOeTaJ68ME=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.38,REQID:dd4448df-b1ff-4853-9177-1fa69dc3881c,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:82c5f88,CLOUDID:50537087-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: c7f6e1b4137e11ef8065b7b53f7091ad-20240516 Received: from mtkmbs09n2.mediatek.inc [(172.21.101.94)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1956522864; Thu, 16 May 2024 20:21:11 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS09N1.mediatek.inc (172.21.101.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 16 May 2024 20:21:10 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 16 May 2024 20:21:09 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Nathan Hebert , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Sebastian Fricke , Tomasz Figa , Mauro Carvalho Chehab , Marek Szyprowski CC: Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , =?UTF-8?q?Christian=20K=C3=B6nig?= , Matthias Brugger , , , , , , Subject: [PATCH v6,02/24] v4l2: handle restricted memory flags in queue setup Date: Thu, 16 May 2024 20:20:40 +0800 Message-ID: <20240516122102.16379-3-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240516122102.16379-1-yunfei.dong@mediatek.com> References: <20240516122102.16379-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N From: Jeffrey Kardatzke Validates the restricted memory flags when setting up a queue and ensures the queue has the proper capability. Signed-off-by: Jeffrey Kardatzke Signed-off-by: Yunfei Dong --- .../media/common/videobuf2/videobuf2-core.c | 21 +++++++++++++++++++ .../media/common/videobuf2/videobuf2-v4l2.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 358f1fe42975..fe4c0594ab81 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -831,6 +831,15 @@ static bool verify_coherency_flags(struct vb2_queue *q, bool non_coherent_mem) return true; } +static bool verify_restricted_mem_flags(struct vb2_queue *q, bool restricted_mem) +{ + if (restricted_mem != q->restricted_mem) { + dprintk(q, 1, "restricted memory model mismatch\n"); + return false; + } + return true; +} + static int vb2_core_allocated_buffers_storage(struct vb2_queue *q) { if (!q->bufs) @@ -864,6 +873,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int q_num_bufs = vb2_get_num_buffers(q); unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; + bool restricted_mem = flags & V4L2_MEMORY_FLAG_RESTRICTED; unsigned int i, first_index; int ret = 0; @@ -907,6 +917,9 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, return 0; } + if (restricted_mem && (!q->allow_restricted_mem || memory != VB2_MEMORY_DMABUF)) + return -EINVAL; + /* * Make sure the requested values and current defaults are sane. */ @@ -924,6 +937,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, if (ret) return ret; set_queue_coherency(q, non_coherent_mem); + q->restricted_mem = restricted_mem; /* * Ask the driver how many buffers and planes per buffer it requires. @@ -1032,6 +1046,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; unsigned int q_num_bufs = vb2_get_num_buffers(q); + bool restricted_mem = flags & V4L2_MEMORY_FLAG_RESTRICTED; bool no_previous_buffers = !q_num_bufs; int ret = 0; @@ -1040,6 +1055,9 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, return -ENOBUFS; } + if (restricted_mem && (!q->allow_restricted_mem || memory != VB2_MEMORY_DMABUF)) + return -EINVAL; + if (no_previous_buffers) { if (q->waiting_in_dqbuf && *count) { dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n"); @@ -1058,6 +1076,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, return ret; q->waiting_for_buffers = !q->is_output; set_queue_coherency(q, non_coherent_mem); + q->restricted_mem = restricted_mem; } else { if (q->memory != memory) { dprintk(q, 1, "memory model mismatch\n"); @@ -1065,6 +1084,8 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, } if (!verify_coherency_flags(q, non_coherent_mem)) return -EINVAL; + if (!verify_restricted_mem_flags(q, restricted_mem)) + return -EINVAL; } num_buffers = min(*count, q->max_num_buffers - q_num_bufs); diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 293f3d5f1c4e..9ee24e537e0c 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -682,7 +682,7 @@ static void vb2_set_flags_and_caps(struct vb2_queue *q, u32 memory, *flags = 0; } else { /* Clear all unknown flags. */ - *flags &= V4L2_MEMORY_FLAG_NON_COHERENT; + *flags &= V4L2_MEMORY_FLAG_NON_COHERENT | V4L2_MEMORY_FLAG_RESTRICTED; } *caps |= V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS; @@ -698,6 +698,8 @@ static void vb2_set_flags_and_caps(struct vb2_queue *q, u32 memory, *caps |= V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS; if (q->supports_requests) *caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS; + if (q->allow_restricted_mem && q->io_modes & VB2_DMABUF) + *caps |= V4L2_BUF_CAP_SUPPORTS_RESTRICTED_MEM; if (max_num_bufs) { *max_num_bufs = q->max_num_buffers; *caps |= V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS; -- 2.25.1