Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp210862lqp; Tue, 11 Jun 2024 21:32:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQIBsGfafVFFHC4K8/9XyJqyn/z3FMIovOrcDqiQ+B/KEfMLIAK/0IORjO8hmPa1RCSJOqKCIeRyomgmb4L2+ocXeB2myfPowUGcOdZQ== X-Google-Smtp-Source: AGHT+IGwdNE0V+4BJaVt1NX1qBsz+MPtk71O10OCHaGz+4b59U3u6AYnjdDOIWSPq79dOLJ9UCRY X-Received: by 2002:a05:6e02:1fe7:b0:375:ae6b:9d92 with SMTP id e9e14a558f8ab-375cd16a2ffmr9175665ab.12.1718166776241; Tue, 11 Jun 2024 21:32:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718166776; cv=pass; d=google.com; s=arc-20160816; b=h6wbrWzsNMoUf7+thGGCZtzfBeKYYy3Ano6ClTQXX5leWPtQOlG0yi+wNJrpQBdfJU CzT2OQyuNBlY4LktONRlewgZShIX9RkYoX1e5RsOhnDk6kaNksurxKcRKxiiq9X4UG4f Y+G1+xem+uDVkJKV55MUexuv3MUGNKh1MR8EQNK+nAVlGrPGRz4Ijomogzw5yHiMSO+S TSsdjLLZXZuC+1hMrzhDiLGz42YsvCv5qMDTxUDE1SwqB/dwoCRLn0zkvQTLPyVk1o3m Ol0uQNAPd/SimvOL8gIaHZNt7ktKImNbXHKMryjoXasHpOm57izEb+9/S1QGnOFtxkLr 6qKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=26yCayUAzc76t5ERK7B6b8gwpGmJll8Ij+c08Bg2GMU=; fh=lJLVPUTKM5fFHwjRpoLm+AFRo/BYC4EmHksLeDikfkQ=; b=Ju2E3AtaLYhk+uLAz71CrQl5cNEYWnPuLnkdA9VfFM/IQLjk9h3bXRh0rZ3UBInK0a TuPtxzy6VAz3261phVcMPxjEEydNRgHvgfIT/QXAKbb1eWS6OGiJl5DD0U7qJq0k4x91 GlCk2LCcr42tm6/6/tmhQRTtjV+RXeNQ/eJqxx0wVAJsU8vrFAzI4nyLo+AibcUJ1EE/ PAOdjC/0DgyWdBS+OSP9KWdkX7kPHaTBbP8ceZdbu91WRVknOPiXhvFeuewhETVK29i/ Y6AQqn4ZmR/mrGt5FmBpDU0E/AvRxHfXcByGPWwRi86Ibvqmi4c5v4c8/wsF9+IHSKnk QTxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="JywGFy1/"; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-210909-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210909-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e5fd488dacsi7543844a12.51.2024.06.11.21.32.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 21:32:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210909-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="JywGFy1/"; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-210909-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210909-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 68CFBB2385E for ; Wed, 12 Jun 2024 04:31:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0B5326ACE; Wed, 12 Jun 2024 04:31:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="JywGFy1/" Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 66C5D63A for ; Wed, 12 Jun 2024 04:31:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718166690; cv=none; b=BLvdWf4qXm+DAqxC7gt3Q5HVgfy1J5p3iTyh+iynSaHPpTOypYGIR2vh3Tk2SUmmBEtj1Fbrd53iaatbZI339gewQXwD6DO90AyZg1H9OSZ0nJZT21yIOTrwGtnJeMG8WdGxn955hCAePc465XFIBGIxCdFiHu6I/RGwTNt7v/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718166690; c=relaxed/simple; bh=hSnJiEgR5nMe+pD1oPm3BPIx6ljI+CeVh/tUDiPt7w4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TGZb0Ar8aXrY04WO4hxNdRSbXOTXwiPygjMltMIpv/WBHyYCrFJWod3u6u6HWlBpKd5i7h/JN96K0l7pH3HUKn/MDCQCvFkANh+R1Z1EEfF91sn6McLpxE6akLjOfz/m9lR+H7W9AbQ51wYHTajTd+9OzH2J8tkeUCrBDcJ4mJQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=JywGFy1/; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7041a7d4beeso4005629b3a.2 for ; Tue, 11 Jun 2024 21:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718166689; x=1718771489; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=26yCayUAzc76t5ERK7B6b8gwpGmJll8Ij+c08Bg2GMU=; b=JywGFy1/ZJMdXblpUDu3vfbAHc41BGpW3SFtL5fAaPkpgADXKjklyV8/QSAf5MZrYl awRCMjXfwK8enCCLyMgvArnetTGIFCIvYP1w9RqvYYqSWPuYrFejFCfL2Ut+twi2egRp t5QAarNFZxXMKlNn/2heBWSKSqGE38tMpSOi8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718166689; x=1718771489; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=26yCayUAzc76t5ERK7B6b8gwpGmJll8Ij+c08Bg2GMU=; b=tmH9WabuvYM3NnbZOeiz6GvXHfntpNDX1oZ6Cmjyi8vbB8GFjp1h/7Ei0I1W65gZb7 9DURN8uXdf7y19tmObPjuj/u3FwF2TZYl06+4G4+743+GkJaDNJcrOShXYPvMotbYOwA GIVPRak0kVK/98c9kYuZLbIj42g+Q7P4V49GPot7010B2hwB4qVdR6DmBJ8vouE+IKuA +K8669999WQWCknAvcd87jUtTgxMXKkaO00FfUjPIIE7fQTzbEoucClbvGCRIW45R86U oG5TFMP8joitZN3vn5uSxXlhZYyvKb9HKWWogpkVZslCSsIntiGbj+saeZqjHUam0Js4 Gq1g== X-Forwarded-Encrypted: i=1; AJvYcCWqStngyn+dZQ02DLafJJOVQyjpwhqA2vSMO3EK0zGtd0DKbBr0KPKn0bTd3FVf+nd+e0ewyIaGjIrEPJOJH9JQLrEi7ryroljJ+qhJ X-Gm-Message-State: AOJu0YxsArvP4H7Dzg3fqWjyx/i0me1+VpONEJpxL8bWLuTj7mS9s2+u nQtwVyJO3PqBf4qZDhgjOrhquKAbyUVV687p/ZAucXeEAtcZcjKwZnYjVhKoKw== X-Received: by 2002:a05:6a21:81a2:b0:1b2:2e3e:42dd with SMTP id adf61e73a8af0-1b8a9be9bb0mr745623637.34.1718166688682; Tue, 11 Jun 2024 21:31:28 -0700 (PDT) Received: from chromium.org (174.71.80.34.bc.googleusercontent.com. [34.80.71.174]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f74179d0basm11631455ad.122.2024.06.11.21.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 21:31:28 -0700 (PDT) Date: Wed, 12 Jun 2024 13:31:22 +0900 From: Tomasz Figa To: Yunfei Dong Cc: Jeffrey Kardatzke , =?utf-8?B?TsOtY29sYXMgRiAuIFIgLiBBIC4=?= Prado , Nathan Hebert , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Sebastian Fricke , Mauro Carvalho Chehab , Marek Szyprowski , Chen-Yu Tsai , Yong Wu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Sumit Semwal , Brian Starkey , John Stultz , "T . J . Mercier" , Christian =?utf-8?B?S8O2bmln?= , Matthias Brugger , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Project_Global_Chrome_Upstream_Group@mediatek.com Subject: Re: [PATCH v6,03/24] v4l2: verify restricted dmabufs are used in restricted queue Message-ID: References: <20240516122102.16379-1-yunfei.dong@mediatek.com> <20240516122102.16379-4-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240516122102.16379-4-yunfei.dong@mediatek.com> On Thu, May 16, 2024 at 08:20:41PM +0800, Yunfei Dong wrote: > 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. > + */ Kernel coding style [1] defines multi-line comments to start with an empty line. [1] https://www.kernel.org/doc/html/latest/process/coding-style.html#commenting > + if (buf->vb->vb2_queue->restricted_mem && !sg_dma_is_restricted(sgt->sgl)) { > + pr_err("restricted queue requires restricted dma_buf"); > + return -EINVAL; This would leak the mapping. We need to unmap the attachment here. > + } > + > /* 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. > + */ Ditto. > + if (buf->vb->vb2_queue->restricted_mem && !sg_dma_is_restricted(sgt->sgl)) { > + pr_err("restricted queue requires restricted dma_buf"); > + return -EINVAL; Ditto. Best regards, Tomasz > + } > + > buf->dma_sgt = sgt; > buf->vaddr = NULL; > > -- > 2.25.1 >