From patchwork Mon Jan 29 06:30:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfei Dong X-Patchwork-Id: 767763 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 B0E3D4CE02; Mon, 29 Jan 2024 06:30:49 +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=1706509851; cv=none; b=XF6omy+l7RbNq2vZ9g+LsiwzadBX82KJW0SbFOsBDa10LWKYd1wgujZt+CrlipkRKTGVfutEQA3X5xR3dSifJQV7r9p4WWX7ycGjFw5L/RSAz54m0MTcQpyFpg4dCeh5w8FyMrV2bTsaa3Aosw1IdieVQaG7GecGv/uXNO5q17c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509851; c=relaxed/simple; bh=9w2g6Gq7+Vgz14KR9HnQQihLeCCf4NtwnAbBqhhkmRM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HXawG8Ii/ZQ/qmHXI/oLkksNIrERm5q2A9x6YciBvtW02CY+R0R+KtmY9QyXXtY/gHJtz6feEv0pCXI/33diTa7hWa5jv5ybsw7roQguATpoCWfO5BF1bYof7SepaV+y9P/2daiW6MHCCK+exKcqEQd8+yckR1kQmWCY63JpuxY= 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=jhkTa5bB; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="jhkTa5bB" X-UUID: edf4142cbe6f11eea2298b7352fd921d-20240129 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=iRfjJ9YWROks75IUMtZC2wrUKi1suXGk03fbJUFbyt0=; b=jhkTa5bBLiYUT3wpEltBxfzcWPuTQQZYVqddzaf9asJdWmMcexNnkzGzCmHJqKWIzWSQxBOVUfhdMicHCknFw6ecI1RAoTomn2is7LHQtJgekjkE1ZtA2Lo6HW2V877F/BsOqusz6vAkJ+Cfu6vXriNcO0HJT9lNCgFAU1VnBUE=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36, REQID:fb4fdc5f-960c-4c64-89c6-9a1053dcc4b8, IP:0, U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:6e16cf4, CLOUDID:7ed4dc7f-4f93-4875-95e7-8c66ea833d57, 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: edf4142cbe6f11eea2298b7352fd921d-20240129 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 902818360; Mon, 29 Jan 2024 14:30:43 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 29 Jan 2024 14:30:40 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 29 Jan 2024 14:30:38 +0800 From: Yunfei Dong To: Jeffrey Kardatzke , =?utf-8?q?N=C3=ADcolas_F_=2E_?= =?utf-8?q?R_=2E_A_=2E_Prado?= , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert 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_K=C3=B6nig?= , Matthias Brugger , , , , , , , Subject: [PATCH v4,03/22] v4l2: verify restricted dmabufs are used in restricted queue Date: Mon, 29 Jan 2024 14:30:06 +0800 Message-ID: <20240129063025.29251-4-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129063025.29251-1-yunfei.dong@mediatek.com> References: <20240129063025.29251-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--8.360000-8.000000 X-TMASE-MatchedRID: vT/skvKLwFh/+iNkyaz33x+WEMjoO9WWTJDl9FKHbrn8dcjERAe6XpPD bikkMnICYUA4QKGgNJ2/QAgXHCg/RXdWNVeH9NKPSEQN/D/3cG4k9Lf/qe8xx9VU7IWeAUCLMCm LSFOvZt1yylwV7Bc73YAy6p60ZV62fJ5/bZ6npdiyO81X3yak88kZdO1mPd6HHujJdWgMIOuuBc q5ylGQImmWoby5Y3Os7MRn2aF6FKR+3BndfXUhXQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--8.360000-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: DF28679987472B888EA7E9A1D6228B4E0BCD01647BD0B2DD86B95E8C06EC4EB42000:8 X-MTK: N From: Jeffrey Kardatzke Verfies in the dmabuf implementations that if the restricted memory flag is set for a queue that the dmabuf submitted to the queue is unmappable. Signed-off-by: Jeffrey Kardatzke Signed-off-by: Yunfei Dong --- drivers/media/common/videobuf2/videobuf2-dma-contig.c | 8 ++++++++ drivers/media/common/videobuf2/videobuf2-dma-sg.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index 3d4fd4ef5310..f953570fef27 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c @@ -710,6 +710,14 @@ static int vb2_dc_map_dmabuf(void *mem_priv) return -EINVAL; } + /* Verify the dmabuf is restricted if we are in restricted mode, this is done + * by validating there is no page entry for the dmabuf. + */ + if (buf->vb->vb2_queue->restricted_mem && sg_page(sgt->sgl)) { + pr_err("restricted queue requires restricted dma_buf"); + return -EINVAL; + } + /* checking if dmabuf is big enough to store contiguous chunk */ contig_size = vb2_dc_get_contiguous_size(sgt); if (contig_size < buf->size) { diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index 6975a71d740f..f87bd3f40b9b 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -570,6 +570,14 @@ static int vb2_dma_sg_map_dmabuf(void *mem_priv) return -EINVAL; } + /* Verify the dmabuf is restricted if we are in restricted mode, this is done + * by validating there is no page entry for the dmabuf. + */ + if (buf->vb->vb2_queue->restricted_mem && !sg_page(sgt->sgl)) { + pr_err("restricted queue requires restricted dma_buf"); + return -EINVAL; + } + buf->dma_sgt = sgt; buf->vaddr = NULL;