Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp357586ybh; Fri, 6 Mar 2020 23:51:31 -0800 (PST) X-Google-Smtp-Source: ADFU+vv/wfuxZoaj2VUlxil7Y7mHCOjTjig9uV+4VFuzm7Ot6dXoLVDAKz/ihfuQtFgoAmzulI1k X-Received: by 2002:a54:4114:: with SMTP id l20mr5218762oic.127.1583567491896; Fri, 06 Mar 2020 23:51:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583567491; cv=none; d=google.com; s=arc-20160816; b=WkjWylJYV8aoXFq7Q9hHZHzQusbuUQac/xEwSVHqUZI9bGxxoLq/2Ee8Xano8/QGCf ZsRXhKhlUpC22GbEEyeQGo3jSbFr6a96sp50v0Be4VB2AYdyzOUMBga4FFAOrC0KjAMF lfj9jxH+2xmhvIp9ek18N2JJmkd8siPvNQMZyevxn/vEwEhMrp3kL6Q/F1hxETWmmCEY WEIz9f3aL2L/as1ODn4IG/oH8zljCwaFL+OZ8ufllkNwgOJEu51RtTvi0Pr2Loo6yPq0 N1oUbZ811KY2L7DmAaf9H33OjY+bEicK0W5s2aB1y3Z5ls5xKYc1y7AlnnDIKYzo2/0m MDUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lzhcSxhRoYq25n80YF1EtESa7xdST5h+El3OqWYt5Hg=; b=yhHRW6mf93rGuYm/QHC44DJlCVqQeA1VG5klAyncvJsSsC81BU5FtiVTCQtxGB5jcA 09RX8/27M7DTsOyqSE6HVDhwIBcxTS/Va6p47esDhxMbKpsx3srUZAXqLy4NgOcXtvwf A2mrBicAyVnbyLDXaxNLgoeuUXVBsuezKloWM07KltDoZSmigygq1W8nkUc4MGbascCN A4uHyFoe9MZ31viy/CXXR7mk2CIdZBn5+JS23FBhXrU9273ASY2pYkcZ1g7rXG6knXSN U7yd/bJXFys5VRJYoayvexhksY398dk/rB6htgHitCaEyx/2KJWJOc6UP3YB8SeJEbX4 DzGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cdSzanK2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16si1037461oic.232.2020.03.06.23.51.20; Fri, 06 Mar 2020 23:51:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cdSzanK2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726086AbgCGHuu (ORCPT + 99 others); Sat, 7 Mar 2020 02:50:50 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46690 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725907AbgCGHuu (ORCPT ); Sat, 7 Mar 2020 02:50:50 -0500 Received: by mail-pf1-f196.google.com with SMTP id o24so2261697pfp.13 for ; Fri, 06 Mar 2020 23:50:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lzhcSxhRoYq25n80YF1EtESa7xdST5h+El3OqWYt5Hg=; b=cdSzanK2cycSUIeu/UXqBeI2m6EEqm+kGhZ0/OwVDliTAxokaHvteVBDOLxoP8XeLc tqBNEY+Gep7ynltQwNMZ9o4vy3yNhUJWt2bgcg6eYmWto9x1e5xnTN/jcrHqXc5ioNai 7XYqz+mvxPOH5aLFK0d7xkVsk9stdNVWRIN+k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=lzhcSxhRoYq25n80YF1EtESa7xdST5h+El3OqWYt5Hg=; b=s9qlW0xb7hzkrqKWnED5ZeQtw1egQOhzW78G95gDivpClcb0sIgoBeUnPsZZ/W2f+A E3XDFGtdD8yjAtX8p8qcDS147eNqkvbHKHcSC3X2Cvp06rWdx7cNb6ZuKKJxy/qGKsva sD3BR4GUucf81Zaqouc1lTb6HAHbE7QNlzAFWR2a2MPZFiUQsbNLCl2+5fub+y5Jou3W xF/BtA4GOV8wUQcbmmKNUx01EeFFiLkV+w/5O3oK9SmAxXmNsAJl9DBN5LLs+nr4A81G SEjoIkngC2dCQXNzO75Eql92uDziPhxXMdzzfM8xlixaUPux8Hu6IvGSsKEyk3hj0XFF vSGA== X-Gm-Message-State: ANhLgQ1JVHfYpKQrOGPIH+bbuveJJB+hxXAwVa8LpI+ZJ+z2F48vFdny Ogf+w9ROI/FfNsxNUo2f9su/Yg== X-Received: by 2002:a63:745c:: with SMTP id e28mr6715988pgn.231.1583567449271; Fri, 06 Mar 2020 23:50:49 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id b4sm39496450pfd.18.2020.03.06.23.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2020 23:50:48 -0800 (PST) Date: Sat, 7 Mar 2020 16:50:46 +0900 From: Sergey Senozhatsky To: Hans Verkuil Cc: Sergey Senozhatsky , Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv4 04/11] videobuf2: add queue memory consistency parameter Message-ID: <20200307075046.GC176460@google.com> References: <20200302041213.27662-1-senozhatsky@chromium.org> <20200302041213.27662-5-senozhatsky@chromium.org> <7ab74b32-441d-1a1a-0112-6c4d0c0b900c@xs4all.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7ab74b32-441d-1a1a-0112-6c4d0c0b900c@xs4all.nl> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (20/03/06 15:04), Hans Verkuil wrote: [..] > > +static bool verify_consistency_attr(struct vb2_queue *q, bool consistent_mem) > > +{ > > + bool queue_attr = q->dma_attrs & DMA_ATTR_NON_CONSISTENT; > > + > > + if (consistent_mem != queue_attr) { > > This is the wrong way around! > > It's much better to write it like this: > > bool queue_is_consistent = !(q->dma_attrs & DMA_ATTR_NON_CONSISTENT); > > if (consistent_mem != queue_is_consistent) { Hmm... That's a great catch. Thanks for spotting this. Puzzled, how come I've never seen problems. > What concerns me more is that this means that this series has not been > tested properly. I found this when testing with v4l2-compliance and vivid. I fully understand your concerns. Give me a moment to figure out what's going on... OK. Apparently, the user-space I'm using for tests, utilizes different call path. vb2_core_create_bufs() is never even invoked. Hence queue consistency vs. request consistency checks are not performed. What happens, instead, is v4l_reqbufs()->vb2_core_reqbufs() path. It orphans existing buffers (if any), sets queue memory model, sets queue consistency model (DMA attr), then allocates buffers. On my test environment, I see that vb2_core_reqbufs() orphans the buffers, but it's always due to "*count == 0 || q->num_buffers != 0" conditions. The user-space I'm using does not twist queue ->memory or consistency attr, so the tests I'm running are limited in scenarios. verify_consistency_attr() is not on the list of reasons to orphan allocated buffer. It probably should be, tho. === diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index afb3c21a5902..d6b1d32bef3f 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -730,7 +730,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, } if (*count == 0 || q->num_buffers != 0 || - (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory)) { + (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory) || + !verify_consistency_attr(q, consistent_mem)) { /* * We already have buffers allocated, so first check if they * are not in use and can be freed. === > > + dprintk(1, "memory consistency model mismatch\n"); > > + return false; > > + } > > + return true; > > +} > > + > > int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, > > - unsigned int *count, unsigned requested_planes, > > - const unsigned requested_sizes[]) > > + bool consistent_mem, unsigned int *count, > > + unsigned requested_planes, > > + const unsigned requested_sizes[]) > > Use 'unsigned int' in the two lines above, as per checkpatch suggestion. OK, will do. This comes from the original code. There are 'unsigned'-s in the existing code, I saw it and didn't want to modify, in order to keep diffstats shorter. -ss