Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp246017lqo; Thu, 16 May 2024 05:23:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpngqavozjIoYsVwPqMjl0ezcgPRaonYVX2EkJv9A1zJCGGza2IagUgKzV2SDToYnq02KOKCvMNeonvagvhjy06c+8vScVCJxvqF8Sjg== X-Google-Smtp-Source: AGHT+IGosAy2bl+c0Upu8nVsUFo9bF2Cl7viSEEfjJOZ5OghHzH5fqHivMwwFkHSYZ4u24GbfBgi X-Received: by 2002:a05:6870:c90d:b0:22e:d572:271b with SMTP id 586e51a60fabf-24172f71a98mr19364882fac.58.1715862186608; Thu, 16 May 2024 05:23:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715862186; cv=pass; d=google.com; s=arc-20160816; b=bl8aHsjrRRuBfP7TiRGh7ZmFBYhPs75NYtlbixwL4XRY8zJTrBeGn1FWcaQTIMTmvy YPDu5+fVnsGxHhlMZ/f0nLcWdi4g4dgSjvJb5XNgN4eQQFd2jLbkXGL3wfoRPHXDFnt6 xrfH/hV8vZDyLhr56N3SzEqilwTyCeOUqjjFk7TtOA1QKMMTO9XgVnb2CO8FeLBEU/G3 AFtnpCPAbOGPea6yurhtQkChpRgspKBG4jBERGYaYCME6Kc1K7+nxlU5uEaEyID+tjdZ 34WxuKwJw6zktx98kEJrv2C7MRotPs4cBzRjSGufWR4uL2tEChtGWk+dL/CmdDRJPz0k pm1Q== 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=3WxlCtbU1qW9txXiClj0zSPD/0sJD2ixlShY7ai2IRo=; fh=biKe3ab6vu9B2YV/BY0rSGdgJ9M/b05dGcvzyA7ivrs=; b=yvxN4kAv9KclLlEXO5Q93+U0DdfhB9nUBZ+1944KhhQInWn+0cMAhl3hhVtiXYMU2g +UuVmCyEBF+VRO1n4RnWFMPRdq08an+eTduj0wva0G9KoARYKjvBBaZAS8P8MSXAvHHk 1BquZid6wGuzb+VRjmaJunvvqvYbD12WkM4cvWoSbpH50Pn7w0/93PulxEcg91sAVv44 kkXK56TOGQ1jdOk1fXq7WLPPiHvMOWDXioY5jmK8JWPGch1Un8WPt9VySgyStbFegKZK Xa5AEYdEVORUht4AECmN73oYB6ygw/MFX8etj+OsBiEpD/90YcOf6CcMG1Auf4DdMivI +yYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=PKmxRF2I; 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-181000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181000-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 6a1803df08f44-6a15f1d8319si162788696d6.69.2024.05.16.05.23.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 05:23:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181000-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=PKmxRF2I; 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-181000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181000-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 CD31B1C22904 for ; Thu, 16 May 2024 12:22:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AEA9C14D2B7; Thu, 16 May 2024 12:21:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="PKmxRF2I" 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 695A8146D6E; Thu, 16 May 2024 12:21:24 +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=1715862087; cv=none; b=sCY68uFj3mNxQDErpe1Blj27DJIREG+snizSX49QjUxnOeAGnbOC6vxC3KK+7vUKqHKoN9U2GTjqoeZRlLkwM/H+XNh2C2anPgdhPO5u35vGTQTodlQikBcr4VP8FtcZgi2TD2J2dMwbF1jsqQf/6jO6tqlfQNicL3lOvpkwfng= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715862087; c=relaxed/simple; bh=ahyi6ObHE9tXYr+Cu30R5U22EMnYIEacoQQEy+MRQwU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Omcdxm5pKL7tP+j0Z5koDDX4jbtBPqGukkuHqmBq3hWe2MM7jJKRDTDcCRNtjAX0yHcGos+j4rqTd/eOF0VyvKkHBQ2SbtVm/9700RIrURrw47PtpBRVZUKBxOhRcJ8t7xFuMSKj8Z8kDb7ty9Q2lU7PARtMDDP43CHtVOFKQ74= 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=PKmxRF2I; 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: c92545e4137e11ef8065b7b53f7091ad-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=3WxlCtbU1qW9txXiClj0zSPD/0sJD2ixlShY7ai2IRo=; b=PKmxRF2IZ4eX+IrfpOl2p7NLR1wRw+Rz5IPJpa52Glspx+/EHhr+DwC+W17EsniGLA9JqzLxbi3iG7/57KV7xs8fD8Da4+6i3xEWhkrqTc9VfpAFcUVY+fBByad2v97GEQVWmBFXMNUGk8Mck6oLTubm5N/mN70aO1h9LlCF4no=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.38,REQID:7f8f2d95-c617-4301-84ac-e028065a0d2e,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:82c5f88,CLOUDID:0209f083-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: c92545e4137e11ef8065b7b53f7091ad-20240516 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 99272032; Thu, 16 May 2024 20:21:13 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n1.mediatek.inc (172.21.101.185) 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:11 +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:10 +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,03/24] v4l2: verify restricted dmabufs are used in restricted queue Date: Thu, 16 May 2024 20:20:41 +0800 Message-ID: <20240516122102.16379-4-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 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..35a3c1c01eae 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_dma_is_restricted(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..2399a9c074ba 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_dma_is_restricted(sgt->sgl)) { + pr_err("restricted queue requires restricted dma_buf"); + return -EINVAL; + } + buf->dma_sgt = sgt; buf->vaddr = NULL; -- 2.25.1