diff mbox

[01/12,media] vb2: add explicit fence user API

Message ID 20170616073915.5027-2-gustavo@padovan.org (mailing list archive)
State New, archived
Headers show

Commit Message

Gustavo Padovan June 16, 2017, 7:39 a.m. UTC
From: Gustavo Padovan <gustavo.padovan@collabora.com>

Turn the reserved2 field into fence_fd that we will use to send
an in-fence to the kernel and return an out-fence from the kernel to
userspace.

Two new flags were added, V4L2_BUF_FLAG_IN_FENCE, that should be used
when sending a fence to the kernel to be waited on, and
V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ++--
 drivers/media/v4l2-core/videobuf2-v4l2.c      | 2 +-
 include/uapi/linux/videodev2.h                | 4 +++-
 3 files changed, 6 insertions(+), 4 deletions(-)

Comments

kernel test robot June 18, 2017, 2:09 p.m. UTC | #1
Hi Gustavo,

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.12-rc5 next-20170616]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Gustavo-Padovan/vb2-add-explicit-fence-user-API/20170618-210740
base:   git://linuxtv.org/media_tree.git master
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gnu-gcc (Debian 6.3.0-18) 6.3.0 20170516
reproduce:
        wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=sh 

All errors (new ones prefixed by >>):

   drivers/media//usb/cpia2/cpia2_v4l.c: In function 'cpia2_dqbuf':
>> drivers/media//usb/cpia2/cpia2_v4l.c:951:5: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
     buf->reserved2 = 0;
        ^~

vim +951 drivers/media//usb/cpia2/cpia2_v4l.c

1b18e7a0 drivers/media/usb/cpia2/cpia2_v4l.c   Sakari Ailus 2012-10-22  945  		| V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
ab33d507 drivers/media/video/cpia2/cpia2_v4l.c Alan Cox     2006-02-27  946  	buf->field = V4L2_FIELD_NONE;
ab33d507 drivers/media/video/cpia2/cpia2_v4l.c Alan Cox     2006-02-27  947  	buf->timestamp = cam->buffers[buf->index].timestamp;
ab33d507 drivers/media/video/cpia2/cpia2_v4l.c Alan Cox     2006-02-27  948  	buf->sequence = cam->buffers[buf->index].seq;
ab33d507 drivers/media/video/cpia2/cpia2_v4l.c Alan Cox     2006-02-27  949  	buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
ab33d507 drivers/media/video/cpia2/cpia2_v4l.c Alan Cox     2006-02-27  950  	buf->length = cam->frame_size;
2b719d7b drivers/media/video/cpia2/cpia2_v4l.c Sakari Ailus 2012-05-02 @951  	buf->reserved2 = 0;
ab33d507 drivers/media/video/cpia2/cpia2_v4l.c Alan Cox     2006-02-27  952  	buf->reserved = 0;
ab33d507 drivers/media/video/cpia2/cpia2_v4l.c Alan Cox     2006-02-27  953  	memset(&buf->timecode, 0, sizeof(buf->timecode));
ab33d507 drivers/media/video/cpia2/cpia2_v4l.c Alan Cox     2006-02-27  954  

:::::: The code at line 951 was first introduced by commit
:::::: 2b719d7baf490e24ce7d817c6337b7c87fda84c1 [media] v4l: drop v4l2_buffer.input and V4L2_BUF_FLAG_INPUT

:::::: TO: Sakari Ailus <sakari.ailus@iki.fi>
:::::: CC: Mauro Carvalho Chehab <mchehab@redhat.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot June 18, 2017, 2:58 p.m. UTC | #2
Hi Gustavo,

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.12-rc5 next-20170616]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Gustavo-Padovan/vb2-add-explicit-fence-user-API/20170618-210740
base:   git://linuxtv.org/media_tree.git master
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_qbuf':
>> drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1297:10: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
         (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING)) {
             ^~
   drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1299:50: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
      pipe->frame_request_config_id[buf->index] = buf->reserved2 &
                                                     ^~
   drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_dqbuf':
   drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1483:5: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
     buf->reserved2 = pipe->frame_config_id[buf->index];
        ^~
   In file included from include/linux/printk.h:329:0,
                    from include/linux/kernel.h:13,
                    from include/linux/delay.h:21,
                    from drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:24:
   drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1488:6: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
      buf->reserved2);
         ^
   include/linux/dynamic_debug.h:135:9: note: in definition of macro 'dynamic_dev_dbg'
          ##__VA_ARGS__);  \
            ^~~~~~~~~~~
>> drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1486:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(isp->dev, "dqbuf buffer %d (%s) for asd%d with exp_id %d, isp_config_id %d\n",
     ^~~~~~~
   drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c: At top level:
>> cc1: warning: unrecognized command line option '-Wno-implicit-fallthrough'
--
   drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_qbuf':
   drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c:1297:10: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
         (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING)) {
             ^~
   drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c:1299:50: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
      pipe->frame_request_config_id[buf->index] = buf->reserved2 &
                                                     ^~
   drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_dqbuf':
   drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c:1483:5: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
     buf->reserved2 = pipe->frame_config_id[buf->index];
        ^~
   In file included from include/linux/printk.h:329:0,
                    from include/linux/kernel.h:13,
                    from include/linux/delay.h:21,
                    from drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c:24:
   drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c:1488:6: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
      buf->reserved2);
         ^
   include/linux/dynamic_debug.h:135:9: note: in definition of macro 'dynamic_dev_dbg'
          ##__VA_ARGS__);  \
            ^~~~~~~~~~~
   drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c:1486:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(isp->dev, "dqbuf buffer %d (%s) for asd%d with exp_id %d, isp_config_id %d\n",
     ^~~~~~~
   drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c: At top level:
>> cc1: warning: unrecognized command line option '-Wno-implicit-fallthrough'

vim +1297 drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c

a49d2536 Alan Cox 2017-02-17  1291  
a49d2536 Alan Cox 2017-02-17  1292  done:
a49d2536 Alan Cox 2017-02-17  1293  	if (!((buf->flags & NOFLUSH_FLAGS) == NOFLUSH_FLAGS))
a49d2536 Alan Cox 2017-02-17  1294  		wbinvd();
a49d2536 Alan Cox 2017-02-17  1295  
a49d2536 Alan Cox 2017-02-17  1296  	if (!atomisp_is_vf_pipe(pipe) &&
a49d2536 Alan Cox 2017-02-17 @1297  	    (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING)) {
a49d2536 Alan Cox 2017-02-17  1298  		/* this buffer will have a per-frame parameter */
a49d2536 Alan Cox 2017-02-17  1299  		pipe->frame_request_config_id[buf->index] = buf->reserved2 &
a49d2536 Alan Cox 2017-02-17  1300  					~ATOMISP_BUFFER_HAS_PER_FRAME_SETTING;
a49d2536 Alan Cox 2017-02-17  1301  		dev_dbg(isp->dev, "This buffer requires per_frame setting which has isp_config_id %d\n",
a49d2536 Alan Cox 2017-02-17  1302  			pipe->frame_request_config_id[buf->index]);
a49d2536 Alan Cox 2017-02-17  1303  	} else {
a49d2536 Alan Cox 2017-02-17  1304  		pipe->frame_request_config_id[buf->index] = 0;
a49d2536 Alan Cox 2017-02-17  1305  	}
a49d2536 Alan Cox 2017-02-17  1306  
a49d2536 Alan Cox 2017-02-17  1307  	pipe->frame_params[buf->index] = NULL;
a49d2536 Alan Cox 2017-02-17  1308  
a49d2536 Alan Cox 2017-02-17  1309  	rt_mutex_unlock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1310  
a49d2536 Alan Cox 2017-02-17  1311  	ret = videobuf_qbuf(&pipe->capq, buf);
a49d2536 Alan Cox 2017-02-17  1312  	rt_mutex_lock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1313  	if (ret)
a49d2536 Alan Cox 2017-02-17  1314  		goto error;
a49d2536 Alan Cox 2017-02-17  1315  
a49d2536 Alan Cox 2017-02-17  1316  	/* TODO: do this better, not best way to queue to css */
a49d2536 Alan Cox 2017-02-17  1317  	if (asd->streaming == ATOMISP_DEVICE_STREAMING_ENABLED) {
a49d2536 Alan Cox 2017-02-17  1318  		if (!list_empty(&pipe->buffers_waiting_for_param)) {
a49d2536 Alan Cox 2017-02-17  1319  			atomisp_handle_parameter_and_buffer(pipe);
a49d2536 Alan Cox 2017-02-17  1320  		} else {
a49d2536 Alan Cox 2017-02-17  1321  			atomisp_qbuffers_to_css(asd);
a49d2536 Alan Cox 2017-02-17  1322  
a49d2536 Alan Cox 2017-02-17  1323  #ifndef ISP2401
a49d2536 Alan Cox 2017-02-17  1324  			if (!atomisp_is_wdt_running(asd) && atomisp_buffers_queued(asd))
a49d2536 Alan Cox 2017-02-17  1325  				atomisp_wdt_start(asd);
a49d2536 Alan Cox 2017-02-17  1326  #else
a49d2536 Alan Cox 2017-02-17  1327  			if (!atomisp_is_wdt_running(pipe) &&
a49d2536 Alan Cox 2017-02-17  1328  				atomisp_buffers_queued_pipe(pipe))
a49d2536 Alan Cox 2017-02-17  1329  				atomisp_wdt_start(pipe);
a49d2536 Alan Cox 2017-02-17  1330  #endif
a49d2536 Alan Cox 2017-02-17  1331  		}
a49d2536 Alan Cox 2017-02-17  1332  	}
a49d2536 Alan Cox 2017-02-17  1333  
a49d2536 Alan Cox 2017-02-17  1334  	/* Workaround: Due to the design of HALv3,
a49d2536 Alan Cox 2017-02-17  1335  	 * sometimes in ZSL or SDV mode HAL needs to
a49d2536 Alan Cox 2017-02-17  1336  	 * capture multiple images within one streaming cycle.
a49d2536 Alan Cox 2017-02-17  1337  	 * But the capture number cannot be determined by HAL.
a49d2536 Alan Cox 2017-02-17  1338  	 * So HAL only sets the capture number to be 1 and queue multiple
a49d2536 Alan Cox 2017-02-17  1339  	 * buffers. Atomisp driver needs to check this case and re-trigger
a49d2536 Alan Cox 2017-02-17  1340  	 * CSS to do capture when new buffer is queued. */
a49d2536 Alan Cox 2017-02-17  1341  	if (asd->continuous_mode->val &&
a49d2536 Alan Cox 2017-02-17  1342  	    atomisp_subdev_source_pad(vdev)
a49d2536 Alan Cox 2017-02-17  1343  	    == ATOMISP_SUBDEV_PAD_SOURCE_CAPTURE &&
a49d2536 Alan Cox 2017-02-17  1344  	    pipe->capq.streaming &&
a49d2536 Alan Cox 2017-02-17  1345  	    !asd->enable_raw_buffer_lock->val &&
a49d2536 Alan Cox 2017-02-17  1346  	    asd->params.offline_parm.num_captures == 1) {
a49d2536 Alan Cox 2017-02-17  1347  #ifndef ISP2401
a49d2536 Alan Cox 2017-02-17  1348  		asd->pending_capture_request++;
a49d2536 Alan Cox 2017-02-17  1349  		dev_dbg(isp->dev, "Add one pending capture request.\n");
a49d2536 Alan Cox 2017-02-17  1350  #else
a49d2536 Alan Cox 2017-02-17  1351  	    if (asd->re_trigger_capture) {
a49d2536 Alan Cox 2017-02-17  1352  			ret = atomisp_css_offline_capture_configure(asd,
a49d2536 Alan Cox 2017-02-17  1353  				asd->params.offline_parm.num_captures,
a49d2536 Alan Cox 2017-02-17  1354  				asd->params.offline_parm.skip_frames,
a49d2536 Alan Cox 2017-02-17  1355  				asd->params.offline_parm.offset);
a49d2536 Alan Cox 2017-02-17  1356  			asd->re_trigger_capture = false;
a49d2536 Alan Cox 2017-02-17  1357  			dev_dbg(isp->dev, "%s Trigger capture again ret=%d\n",
a49d2536 Alan Cox 2017-02-17  1358  				__func__, ret);
a49d2536 Alan Cox 2017-02-17  1359  
a49d2536 Alan Cox 2017-02-17  1360  	    } else {
a49d2536 Alan Cox 2017-02-17  1361  			asd->pending_capture_request++;
a49d2536 Alan Cox 2017-02-17  1362  			asd->re_trigger_capture = false;
a49d2536 Alan Cox 2017-02-17  1363  			dev_dbg(isp->dev, "Add one pending capture request.\n");
a49d2536 Alan Cox 2017-02-17  1364  	    }
a49d2536 Alan Cox 2017-02-17  1365  #endif
a49d2536 Alan Cox 2017-02-17  1366  	}
a49d2536 Alan Cox 2017-02-17  1367  	rt_mutex_unlock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1368  
a49d2536 Alan Cox 2017-02-17  1369  	dev_dbg(isp->dev, "qbuf buffer %d (%s) for asd%d\n", buf->index,
a49d2536 Alan Cox 2017-02-17  1370  		vdev->name, asd->index);
a49d2536 Alan Cox 2017-02-17  1371  
a49d2536 Alan Cox 2017-02-17  1372  	return ret;
a49d2536 Alan Cox 2017-02-17  1373  
a49d2536 Alan Cox 2017-02-17  1374  error:
a49d2536 Alan Cox 2017-02-17  1375  	rt_mutex_unlock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1376  	return ret;
a49d2536 Alan Cox 2017-02-17  1377  }
a49d2536 Alan Cox 2017-02-17  1378  
a49d2536 Alan Cox 2017-02-17  1379  static int atomisp_qbuf_file(struct file *file, void *fh,
a49d2536 Alan Cox 2017-02-17  1380  					struct v4l2_buffer *buf)
a49d2536 Alan Cox 2017-02-17  1381  {
a49d2536 Alan Cox 2017-02-17  1382  	struct video_device *vdev = video_devdata(file);
a49d2536 Alan Cox 2017-02-17  1383  	struct atomisp_device *isp = video_get_drvdata(vdev);
a49d2536 Alan Cox 2017-02-17  1384  	struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
a49d2536 Alan Cox 2017-02-17  1385  	int ret;
a49d2536 Alan Cox 2017-02-17  1386  
a49d2536 Alan Cox 2017-02-17  1387  	rt_mutex_lock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1388  	if (isp->isp_fatal_error) {
a49d2536 Alan Cox 2017-02-17  1389  		ret = -EIO;
a49d2536 Alan Cox 2017-02-17  1390  		goto error;
a49d2536 Alan Cox 2017-02-17  1391  	}
a49d2536 Alan Cox 2017-02-17  1392  
a49d2536 Alan Cox 2017-02-17  1393  	if (!buf || buf->index >= VIDEO_MAX_FRAME ||
a49d2536 Alan Cox 2017-02-17  1394  		!pipe->outq.bufs[buf->index]) {
a49d2536 Alan Cox 2017-02-17  1395  		dev_err(isp->dev, "Invalid index for qbuf.\n");
a49d2536 Alan Cox 2017-02-17  1396  		ret = -EINVAL;
a49d2536 Alan Cox 2017-02-17  1397  		goto error;
a49d2536 Alan Cox 2017-02-17  1398  	}
a49d2536 Alan Cox 2017-02-17  1399  
a49d2536 Alan Cox 2017-02-17  1400  	if (buf->memory != V4L2_MEMORY_MMAP) {
a49d2536 Alan Cox 2017-02-17  1401  		dev_err(isp->dev, "Unsupported memory method\n");
a49d2536 Alan Cox 2017-02-17  1402  		ret = -EINVAL;
a49d2536 Alan Cox 2017-02-17  1403  		goto error;
a49d2536 Alan Cox 2017-02-17  1404  	}
a49d2536 Alan Cox 2017-02-17  1405  
a49d2536 Alan Cox 2017-02-17  1406  	if (buf->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
a49d2536 Alan Cox 2017-02-17  1407  		dev_err(isp->dev, "Unsupported buffer type\n");
a49d2536 Alan Cox 2017-02-17  1408  		ret = -EINVAL;
a49d2536 Alan Cox 2017-02-17  1409  		goto error;
a49d2536 Alan Cox 2017-02-17  1410  	}
a49d2536 Alan Cox 2017-02-17  1411  	rt_mutex_unlock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1412  
a49d2536 Alan Cox 2017-02-17  1413  	return videobuf_qbuf(&pipe->outq, buf);
a49d2536 Alan Cox 2017-02-17  1414  
a49d2536 Alan Cox 2017-02-17  1415  error:
a49d2536 Alan Cox 2017-02-17  1416  	rt_mutex_unlock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1417  
a49d2536 Alan Cox 2017-02-17  1418  	return ret;
a49d2536 Alan Cox 2017-02-17  1419  }
a49d2536 Alan Cox 2017-02-17  1420  
a49d2536 Alan Cox 2017-02-17  1421  static int __get_frame_exp_id(struct atomisp_video_pipe *pipe,
a49d2536 Alan Cox 2017-02-17  1422  		struct v4l2_buffer *buf)
a49d2536 Alan Cox 2017-02-17  1423  {
a49d2536 Alan Cox 2017-02-17  1424  	struct videobuf_vmalloc_memory *vm_mem;
a49d2536 Alan Cox 2017-02-17  1425  	struct atomisp_css_frame *handle;
a49d2536 Alan Cox 2017-02-17  1426  	int i;
a49d2536 Alan Cox 2017-02-17  1427  
a49d2536 Alan Cox 2017-02-17  1428  	for (i = 0; pipe->capq.bufs[i]; i++) {
a49d2536 Alan Cox 2017-02-17  1429  		vm_mem = pipe->capq.bufs[i]->priv;
a49d2536 Alan Cox 2017-02-17  1430  		handle = vm_mem->vaddr;
a49d2536 Alan Cox 2017-02-17  1431  		if (buf->index == pipe->capq.bufs[i]->i && handle)
a49d2536 Alan Cox 2017-02-17  1432  			return handle->exp_id;
a49d2536 Alan Cox 2017-02-17  1433  	}
a49d2536 Alan Cox 2017-02-17  1434  	return -EINVAL;
a49d2536 Alan Cox 2017-02-17  1435  }
a49d2536 Alan Cox 2017-02-17  1436  
a49d2536 Alan Cox 2017-02-17  1437  /*
a49d2536 Alan Cox 2017-02-17  1438   * Applications call the VIDIOC_DQBUF ioctl to dequeue a filled (capturing) or
a49d2536 Alan Cox 2017-02-17  1439   * displayed (output buffer)from the driver's outgoing queue
a49d2536 Alan Cox 2017-02-17  1440   */
a49d2536 Alan Cox 2017-02-17  1441  static int atomisp_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
a49d2536 Alan Cox 2017-02-17  1442  {
a49d2536 Alan Cox 2017-02-17  1443  	struct video_device *vdev = video_devdata(file);
a49d2536 Alan Cox 2017-02-17  1444  	struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
a49d2536 Alan Cox 2017-02-17  1445  	struct atomisp_sub_device *asd = pipe->asd;
a49d2536 Alan Cox 2017-02-17  1446  	struct atomisp_device *isp = video_get_drvdata(vdev);
a49d2536 Alan Cox 2017-02-17  1447  	int ret = 0;
a49d2536 Alan Cox 2017-02-17  1448  
a49d2536 Alan Cox 2017-02-17  1449  	rt_mutex_lock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1450  
a49d2536 Alan Cox 2017-02-17  1451  	if (isp->isp_fatal_error) {
a49d2536 Alan Cox 2017-02-17  1452  		rt_mutex_unlock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1453  		return -EIO;
a49d2536 Alan Cox 2017-02-17  1454  	}
a49d2536 Alan Cox 2017-02-17  1455  
a49d2536 Alan Cox 2017-02-17  1456  	if (asd->streaming == ATOMISP_DEVICE_STREAMING_STOPPING) {
a49d2536 Alan Cox 2017-02-17  1457  		rt_mutex_unlock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1458  		dev_err(isp->dev, "%s: reject, as ISP at stopping.\n",
a49d2536 Alan Cox 2017-02-17  1459  				__func__);
a49d2536 Alan Cox 2017-02-17  1460  		return -EIO;
a49d2536 Alan Cox 2017-02-17  1461  	}
a49d2536 Alan Cox 2017-02-17  1462  
a49d2536 Alan Cox 2017-02-17  1463  	rt_mutex_unlock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1464  
a49d2536 Alan Cox 2017-02-17  1465  	ret = videobuf_dqbuf(&pipe->capq, buf, file->f_flags & O_NONBLOCK);
a49d2536 Alan Cox 2017-02-17  1466  	if (ret) {
a49d2536 Alan Cox 2017-02-17  1467  		dev_dbg(isp->dev, "<%s: %d\n", __func__, ret);
a49d2536 Alan Cox 2017-02-17  1468  		return ret;
a49d2536 Alan Cox 2017-02-17  1469  	}
a49d2536 Alan Cox 2017-02-17  1470  	rt_mutex_lock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1471  	buf->bytesused = pipe->pix.sizeimage;
a49d2536 Alan Cox 2017-02-17  1472  	buf->reserved = asd->frame_status[buf->index];
a49d2536 Alan Cox 2017-02-17  1473  
a49d2536 Alan Cox 2017-02-17  1474  	/*
a49d2536 Alan Cox 2017-02-17  1475  	 * Hack:
a49d2536 Alan Cox 2017-02-17  1476  	 * Currently frame_status in the enum type which takes no more lower
a49d2536 Alan Cox 2017-02-17  1477  	 * 8 bit.
a49d2536 Alan Cox 2017-02-17  1478  	 * use bit[31:16] for exp_id as it is only in the range of 1~255
a49d2536 Alan Cox 2017-02-17  1479  	 */
a49d2536 Alan Cox 2017-02-17  1480  	buf->reserved &= 0x0000ffff;
a49d2536 Alan Cox 2017-02-17  1481  	if (!(buf->flags & V4L2_BUF_FLAG_ERROR))
a49d2536 Alan Cox 2017-02-17  1482  		buf->reserved |= __get_frame_exp_id(pipe, buf) << 16;
a49d2536 Alan Cox 2017-02-17  1483  	buf->reserved2 = pipe->frame_config_id[buf->index];
a49d2536 Alan Cox 2017-02-17  1484  	rt_mutex_unlock(&isp->mutex);
a49d2536 Alan Cox 2017-02-17  1485  
a49d2536 Alan Cox 2017-02-17 @1486  	dev_dbg(isp->dev, "dqbuf buffer %d (%s) for asd%d with exp_id %d, isp_config_id %d\n",
a49d2536 Alan Cox 2017-02-17  1487  		buf->index, vdev->name, asd->index, buf->reserved >> 16,
a49d2536 Alan Cox 2017-02-17  1488  		buf->reserved2);
a49d2536 Alan Cox 2017-02-17  1489  	return 0;

:::::: The code at line 1297 was first introduced by commit
:::::: a49d25364dfb9f8a64037488a39ab1f56c5fa419 staging/atomisp: Add support for the Intel IPU v2

:::::: TO: Alan Cox <alan@linux.intel.com>
:::::: CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Gustavo Padovan June 26, 2017, 3:39 p.m. UTC | #3
2017-06-18 kbuild test robot <lkp@intel.com>:

> Hi Gustavo,
> 
> [auto build test ERROR on linuxtv-media/master]
> [also build test ERROR on v4.12-rc5 next-20170616]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
> 
> url:    https://github.com/0day-ci/linux/commits/Gustavo-Padovan/vb2-add-explicit-fence-user-API/20170618-210740
> base:   git://linuxtv.org/media_tree.git master
> config: x86_64-allmodconfig (attached as .config)
> compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
> reproduce:
>         # save the attached .config to linux build tree
>         make ARCH=x86_64 
> 
> All error/warnings (new ones prefixed by >>):
> 
>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_qbuf':
> >> drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1297:10: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>          (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING)) {
>              ^~
>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1299:50: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>       pipe->frame_request_config_id[buf->index] = buf->reserved2 &
>                                                      ^~
>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_dqbuf':
>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1483:5: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>      buf->reserved2 = pipe->frame_config_id[buf->index];
>         ^~
>    In file included from include/linux/printk.h:329:0,
>                     from include/linux/kernel.h:13,
>                     from include/linux/delay.h:21,
>                     from drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:24:
>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1488:6: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>       buf->reserved2);
>          ^

Ouch! Seems the reserved2 was burned down by 2 drivers accessing it
without any care for the uAPI. I'll change my patches to use the
'reserved' field instead.

	Gustavo
Mauro Carvalho Chehab June 30, 2017, 11:12 a.m. UTC | #4
Em Fri, 16 Jun 2017 16:39:04 +0900
Gustavo Padovan <gustavo@padovan.org> escreveu:

> From: Gustavo Padovan <gustavo.padovan@collabora.com>
> 
> Turn the reserved2 field into fence_fd that we will use to send
> an in-fence to the kernel and return an out-fence from the kernel to
> userspace.
> 
> Two new flags were added, V4L2_BUF_FLAG_IN_FENCE, that should be used
> when sending a fence to the kernel to be waited on, and
> V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence.
> 
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com>
> ---
>  drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ++--
>  drivers/media/v4l2-core/videobuf2-v4l2.c      | 2 +-
>  include/uapi/linux/videodev2.h                | 4 +++-
>  3 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
> index 6f52970..8f6ab85 100644
> --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
> +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
> @@ -367,7 +367,7 @@ struct v4l2_buffer32 {
>  		__s32		fd;
>  	} m;
>  	__u32			length;
> -	__u32			reserved2;
> +	__s32			fence_fd;
>  	__u32			reserved;
>  };
>  
> @@ -530,7 +530,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
>  		put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) ||
>  		copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) ||
>  		put_user(kp->sequence, &up->sequence) ||
> -		put_user(kp->reserved2, &up->reserved2) ||
> +		put_user(kp->fence_fd, &up->fence_fd) ||
>  		put_user(kp->reserved, &up->reserved) ||
>  		put_user(kp->length, &up->length))
>  			return -EFAULT;
> diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
> index 0c06699..110fb45 100644
> --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
> +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
> @@ -203,7 +203,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb)
>  	b->timestamp = ns_to_timeval(vb->timestamp);
>  	b->timecode = vbuf->timecode;
>  	b->sequence = vbuf->sequence;
> -	b->reserved2 = 0;
> +	b->fence_fd = -1;
>  	b->reserved = 0;
>  
>  	if (q->is_multiplanar) {
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 2b8feb8..750d511 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -916,7 +916,7 @@ struct v4l2_buffer {
>  		__s32		fd;
>  	} m;
>  	__u32			length;
> -	__u32			reserved2;
> +	__s32			fence_fd;
>  	__u32			reserved;
>  };
>  
> @@ -953,6 +953,8 @@ struct v4l2_buffer {
>  #define V4L2_BUF_FLAG_TSTAMP_SRC_SOE		0x00010000
>  /* mem2mem encoder/decoder */
>  #define V4L2_BUF_FLAG_LAST			0x00100000

> +#define V4L2_BUF_FLAG_IN_FENCE			0x00200000
> +#define V4L2_BUF_FLAG_OUT_FENCE			0x00400000

Please document them at Documentation/media/uapi/v4l/buffer.rst.

We'll also need a new chapter at the documentation, describing the
explicit fences mechanism.

>  
>  /**
>   * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor
Tomasz Figa July 4, 2017, 5:57 a.m. UTC | #5
Hi Gustavo,

On Tue, Jun 27, 2017 at 12:39 AM, Gustavo Padovan <gustavo@padovan.org> wrote:
> 2017-06-18 kbuild test robot <lkp@intel.com>:
>
>> Hi Gustavo,
>>
>> [auto build test ERROR on linuxtv-media/master]
>> [also build test ERROR on v4.12-rc5 next-20170616]
>> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>>
>> url:    https://github.com/0day-ci/linux/commits/Gustavo-Padovan/vb2-add-explicit-fence-user-API/20170618-210740
>> base:   git://linuxtv.org/media_tree.git master
>> config: x86_64-allmodconfig (attached as .config)
>> compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
>> reproduce:
>>         # save the attached .config to linux build tree
>>         make ARCH=x86_64
>>
>> All error/warnings (new ones prefixed by >>):
>>
>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_qbuf':
>> >> drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1297:10: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>>          (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING)) {
>>              ^~
>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1299:50: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>>       pipe->frame_request_config_id[buf->index] = buf->reserved2 &
>>                                                      ^~
>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_dqbuf':
>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1483:5: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>>      buf->reserved2 = pipe->frame_config_id[buf->index];
>>         ^~
>>    In file included from include/linux/printk.h:329:0,
>>                     from include/linux/kernel.h:13,
>>                     from include/linux/delay.h:21,
>>                     from drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:24:
>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1488:6: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>>       buf->reserved2);
>>          ^
>
> Ouch! Seems the reserved2 was burned down by 2 drivers accessing it
> without any care for the uAPI. I'll change my patches to use the
> 'reserved' field instead.

Given that a reserved field has a clear meaning of being reserved and
the driver in question is in staging. I'd rather vote for fixing the
driver.

Best regards,
Tomasz
Alexandre Courbot July 4, 2017, 6:27 a.m. UTC | #6
On Tue, Jul 4, 2017 at 2:57 PM, Tomasz Figa <tfiga@google.com> wrote:
> Hi Gustavo,
>
> On Tue, Jun 27, 2017 at 12:39 AM, Gustavo Padovan <gustavo@padovan.org> wrote:
>> 2017-06-18 kbuild test robot <lkp@intel.com>:
>>
>>> Hi Gustavo,
>>>
>>> [auto build test ERROR on linuxtv-media/master]
>>> [also build test ERROR on v4.12-rc5 next-20170616]
>>> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>>>
>>> url:    https://github.com/0day-ci/linux/commits/Gustavo-Padovan/vb2-add-explicit-fence-user-API/20170618-210740
>>> base:   git://linuxtv.org/media_tree.git master
>>> config: x86_64-allmodconfig (attached as .config)
>>> compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
>>> reproduce:
>>>         # save the attached .config to linux build tree
>>>         make ARCH=x86_64
>>>
>>> All error/warnings (new ones prefixed by >>):
>>>
>>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_qbuf':
>>> >> drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1297:10: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>>>          (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING)) {
>>>              ^~
>>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1299:50: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>>>       pipe->frame_request_config_id[buf->index] = buf->reserved2 &
>>>                                                      ^~
>>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c: In function 'atomisp_dqbuf':
>>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1483:5: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>>>      buf->reserved2 = pipe->frame_config_id[buf->index];
>>>         ^~
>>>    In file included from include/linux/printk.h:329:0,
>>>                     from include/linux/kernel.h:13,
>>>                     from include/linux/delay.h:21,
>>>                     from drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:24:
>>>    drivers/staging/media//atomisp/pci/atomisp2/atomisp_ioctl.c:1488:6: error: 'struct v4l2_buffer' has no member named 'reserved2'; did you mean 'reserved'?
>>>       buf->reserved2);
>>>          ^
>>
>> Ouch! Seems the reserved2 was burned down by 2 drivers accessing it
>> without any care for the uAPI. I'll change my patches to use the
>> 'reserved' field instead.
>
> Given that a reserved field has a clear meaning of being reserved and
> the driver in question is in staging. I'd rather vote for fixing the
> driver.

Same here. It seems like this use of reserved2 should not have been
merged in the first place, thankfully it's only in staging.
diff mbox

Patch

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 6f52970..8f6ab85 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -367,7 +367,7 @@  struct v4l2_buffer32 {
 		__s32		fd;
 	} m;
 	__u32			length;
-	__u32			reserved2;
+	__s32			fence_fd;
 	__u32			reserved;
 };
 
@@ -530,7 +530,7 @@  static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
 		put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) ||
 		copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) ||
 		put_user(kp->sequence, &up->sequence) ||
-		put_user(kp->reserved2, &up->reserved2) ||
+		put_user(kp->fence_fd, &up->fence_fd) ||
 		put_user(kp->reserved, &up->reserved) ||
 		put_user(kp->length, &up->length))
 			return -EFAULT;
diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 0c06699..110fb45 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -203,7 +203,7 @@  static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb)
 	b->timestamp = ns_to_timeval(vb->timestamp);
 	b->timecode = vbuf->timecode;
 	b->sequence = vbuf->sequence;
-	b->reserved2 = 0;
+	b->fence_fd = -1;
 	b->reserved = 0;
 
 	if (q->is_multiplanar) {
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 2b8feb8..750d511 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -916,7 +916,7 @@  struct v4l2_buffer {
 		__s32		fd;
 	} m;
 	__u32			length;
-	__u32			reserved2;
+	__s32			fence_fd;
 	__u32			reserved;
 };
 
@@ -953,6 +953,8 @@  struct v4l2_buffer {
 #define V4L2_BUF_FLAG_TSTAMP_SRC_SOE		0x00010000
 /* mem2mem encoder/decoder */
 #define V4L2_BUF_FLAG_LAST			0x00100000
+#define V4L2_BUF_FLAG_IN_FENCE			0x00200000
+#define V4L2_BUF_FLAG_OUT_FENCE			0x00400000
 
 /**
  * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor