From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
Mike Isely <isely@pobox.com>,
Mauro Carvalho Chehab <mchehab@redhat.com>
Subject: [023/119] V4L/DVB (13169): bttv: Fix potential out-of-order field processing
Date: Sun, 06 Dec 2009 15:59:59 -0800 [thread overview]
Message-ID: <20091207000644.059666416@mini.kroah.org> (raw)
In-Reply-To: <20091207000938.GA24743@kroah.com>
[-- Attachment #1: v4l-dvb-13169-bttv-fix-potential-out-of-order-field-processing.patch --]
[-- Type: text/plain, Size: 6094 bytes --]
2.6.31-stable review patch. If anyone has any objections, please let us know.
------------------
From: Mike Isely <isely@pobox.com>
commit 66349b4e7ab3825dbfc167a5f0309792a587adb7 upstream.
There is a subtle interaction in the bttv driver which can result in
fields being repeatedly processed out of order. This is a problem
specifically when running in V4L2_FIELD_ALTERNATE mode (probably the
most common case).
1. The determination of which fields are associated with which buffers
happens in videobuf, before the bttv driver gets a chance to queue the
corresponding DMA. Thus by the point when the DMA is queued for a
given buffer, the algorithm has to do the queuing based on the
buffer's already assigned field type - not based on which field is
"next" in the video stream.
2. The driver normally tries to queue both the top and bottom fields
at the same time (see bttv_irq_next_video()). It tries to sort out
top vs bottom by looking at the field type for the next 2 available
buffers and assigning them appropriately.
3. However the bttv driver *always* actually processes the top field
first. There's even an interrupt set aside for specifically
recognizing when the top field has been processed so that it can be
marked done even while the bottom field is still being DMAed.
Given all of the above, if one gets into a situation where
bttv_irq_next_video() gets entered when the first available buffer has
been pre-associated as a bottom field, then the function is going to
process the buffers out of order. That first available buffer will be
put into the bottom field slot and the buffer after that will be put
into the top field slot. Problem is, since the top field is always
processed first by the driver, then that second buffer (the one after
the first available buffer) will be the first one to be finished.
Because of the strict fifo handling of all video buffers, then that
top field won't be seen by the app until after the bottom field is
also processed. Worse still, the app will get back the
chronologically later bottom field first, *before* the top field is
received. The buffer's timestamps will even be backwards.
While not fatal to most TV apps, this behavior can subtlely degrade
userspace deinterlacing (probably will cause jitter). That's probably
why it has gone unnoticed. But it will also cause serious problems if
the app in question discards all but the latest received buffer (a
latency minimizing tactic) - causing one field to only ever be
displayed since the other is now always late. Unfortunately once you
get into this state, you're stuck this way - because having consumed
two buffers, now the next time around the "first" available buffer
will again be a bottom field and the same thing happens.
How can we get into this state? In a perfect world, where there's
always a few free buffers queued to the driver, it should be
impossible. However if something disrupts streaming, e.g. if the
userspace app can't queue free buffers fast enough for a moment due
perhaps to a CPU scheduling glitch, then the driver can get
momentarily starved and some number of fields will be dropped. That's
OK. But if an odd number of fields get dropped, then that "first"
available buffer might be the bottom field and now we're stuck...
This patch fixes that problem by deliberately only setting up a single
field for one frame if we don't get a top field as the first available
buffer. By purposely skipping the other field, then we only handle a
single buffer thus bringing things back into proper sync (i.e. top
field first) for the next frame. To do this we just drop the few
lines in bttv_irq_next_video() that attempt to set up the second
buffer when that second buffer isn't for the bottom field.
This is definitely a problem in when in V4L2_FIELD_ALTERNATE mode. In
the other modes this change either has no effect or doesn't harm
things any further anyway.
Signed-off-by: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
drivers/media/video/bt8xx/bttv-driver.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -3798,11 +3798,34 @@ bttv_irq_next_video(struct bttv *btv, st
if (!V4L2_FIELD_HAS_BOTH(item->vb.field) &&
(item->vb.queue.next != &btv->capture)) {
item = list_entry(item->vb.queue.next, struct bttv_buffer, vb.queue);
+ /* Mike Isely <isely@pobox.com> - Only check
+ * and set up the bottom field in the logic
+ * below. Don't ever do the top field. This
+ * of course means that if we set up the
+ * bottom field in the above code that we'll
+ * actually skip a field. But that's OK.
+ * Having processed only a single buffer this
+ * time, then the next time around the first
+ * available buffer should be for a top field.
+ * That will then cause us here to set up a
+ * top then a bottom field in the normal way.
+ * The alternative to this understanding is
+ * that we set up the second available buffer
+ * as a top field, but that's out of order
+ * since this driver always processes the top
+ * field first - the effect will be the two
+ * buffers being returned in the wrong order,
+ * with the second buffer also being delayed
+ * by one field time (owing to the fifo nature
+ * of videobuf). Worse still, we'll be stuck
+ * doing fields out of order now every time
+ * until something else causes a field to be
+ * dropped. By effectively forcing a field to
+ * drop this way then we always get back into
+ * sync within a single frame time. (Out of
+ * order fields can screw up deinterlacing
+ * algorithms.) */
if (!V4L2_FIELD_HAS_BOTH(item->vb.field)) {
- if (NULL == set->top &&
- V4L2_FIELD_TOP == item->vb.field) {
- set->top = item;
- }
if (NULL == set->bottom &&
V4L2_FIELD_BOTTOM == item->vb.field) {
set->bottom = item;
next prev parent reply other threads:[~2009-12-07 0:33 UTC|newest]
Thread overview: 133+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20091206235936.208334321@mini.kroah.org>
2009-12-07 0:09 ` [000/119] 2.6.31.7-stable review Greg KH
2009-12-06 23:59 ` [001/119] nilfs2: fix kernel oops in error case of nilfs_ioctl_move_blocks Greg KH
2009-12-06 23:59 ` [002/119] cifs: dont use CIFSGetSrvInodeNumber in is_path_accessible Greg KH
2009-12-06 23:59 ` [003/119] cifs: clean up handling when server doesnt consistently support inode numbers Greg KH
2009-12-06 23:59 ` [004/119] cifs: clear server inode number flag while autodisabling Greg KH
2009-12-06 23:59 ` [005/119] CIFS: fix oops in cifs_lookup during net boot Greg KH
2009-12-06 23:59 ` [006/119] CIFS: Duplicate data on appending to some Samba servers Greg KH
2009-12-06 23:59 ` [007/119] [SCSI] gdth: Prevent negative offsets in ioctl CVE-2009-3080 Greg KH
2009-12-06 23:59 ` [008/119] rtl8187: Fix kernel oops when device is removed when LEDS enabled Greg KH
2009-12-06 23:59 ` [009/119] md: dont clear endpoint for resync when resync is interrupted Greg KH
2009-12-06 23:59 ` [010/119] md/raid5: make sure curr_sync_completes is uptodate when reshape starts Greg KH
2009-12-06 23:59 ` [011/119] md/raid1/raid10: add a cond_resched Greg KH
2009-12-06 23:59 ` [012/119] ALSA: usb-audio: fix combine_word problem Greg KH
2009-12-06 23:59 ` [013/119] ALSA: hda - Dell Studio 1557 hd-audio quirk Greg KH
2009-12-06 23:59 ` [014/119] ALSA: AACI: fix AC97 multiple-open bug Greg KH
2009-12-06 23:59 ` [015/119] ALSA: AACI: fix recording bug Greg KH
2009-12-06 23:59 ` [016/119] jffs2: Fix memory corruption in jffs2_read_inode_range() Greg KH
2009-12-06 23:59 ` [017/119] sound: rawmidi: disable active-sensing-on-close by default Greg KH
2009-12-06 23:59 ` [018/119] sound: rawmidi: fix checking of O_APPEND when opening MIDI device Greg KH
2009-12-06 23:59 ` [019/119] sound: rawmidi: fix double init when opening MIDI device with O_APPEND Greg KH
2009-12-06 23:59 ` [020/119] sound: rawmidi: fix MIDI device O_APPEND error handling Greg KH
2009-12-06 23:59 ` [021/119] highmem: Fix race in debug_kmap_atomic() which could cause warn_count to underflow Greg KH
2009-12-06 23:59 ` [022/119] highmem: Fix debug_kmap_atomic() to also handle KM_IRQ_PTE, KM_NMI, and KM_NMI_PTE Greg KH
2009-12-07 1:11 ` Hugh Dickins
2009-12-07 9:50 ` Florian Mickler
2009-12-06 23:59 ` Greg KH [this message]
2009-12-07 0:00 ` [024/119] V4L/DVB (13170): bttv: Fix reversed polarity error when switching video standard Greg KH
2009-12-07 0:00 ` [025/119] V4L/DVB (13109): tda18271: fix signedness issue in tda18271_rf_tracking_filters_init Greg KH
2009-12-07 0:00 ` [026/119] V4L/DVB (13107): tda18271: fix overflow in FM radio frequency calculation Greg KH
2009-12-07 0:00 ` [027/119] V4L/DVB (13190): em28xx: fix panic that can occur when starting audio streaming Greg KH
2009-12-07 0:00 ` [028/119] V4L/DVB (13079): dib0700: fixed xc2028 firmware loading kernel oops Greg KH
2009-12-07 0:00 ` [029/119] V4L/DVB (13230): s2255drv: Dont conditionalize video buffer completion on waiting processes Greg KH
2009-12-07 0:00 ` [030/119] uids: Prevent tear down race Greg KH
2009-12-07 0:00 ` [031/119] pps: events reporting fix up Greg KH
2009-12-07 0:00 ` [032/119] pps: locking scheme fix up for PPS_GETPARAMS Greg KH
2009-12-07 0:00 ` [033/119] rtc: v3020: fix v3020_mmio_read_bit() Greg KH
2009-12-07 0:00 ` [034/119] fs: add missing compat_ptr handling for FS_IOC_RESVSP ioctl Greg KH
2009-12-07 0:00 ` [035/119] memcg: fix wrong pointer initialization at page migration when memcg is disabled Greg KH
2009-12-07 0:00 ` [036/119] pidns: fix a leak in /proc dentries and inodes with pid namespaces Greg KH
2009-12-07 0:00 ` [037/119] page allocator: Do not allow interrupts to use ALLOC_HARDER Greg KH
2009-12-07 0:00 ` [038/119] page allocator: always wake kswapd when restarting an allocation attempt after direct reclaim failed Greg KH
2009-12-07 0:00 ` [039/119] tty_port: If we are opened non blocking we still need to raise the carrier Greg KH
2009-12-07 0:00 ` [040/119] tty: cp210x: Fix carrier handling Greg KH
2009-12-07 0:00 ` [041/119] USB: ohci: quirk AMD prefetch for USB 1.1 ISO transfer Greg KH
2009-12-07 16:04 ` [Stable-review] " Stefan Bader
2009-12-07 16:48 ` Greg KH
2009-12-07 20:19 ` Stefan Bader
2009-12-07 0:00 ` [042/119] USB: usbmon: fix bug in mon_buff_area_shrink Greg KH
2009-12-07 0:00 ` [043/119] USB: option.c: add support for D-Link DWM-162-U5 Greg KH
2009-12-07 0:00 ` [044/119] USB: cdc_acm: Fix race condition when opening tty Greg KH
2009-12-07 0:00 ` [045/119] USB: xhci: Fix bug memory free after failed initialization Greg KH
2009-12-07 0:00 ` [046/119] USB: xhci: Fix TRB physical to virtual address translation Greg KH
2009-12-07 0:00 ` [047/119] USB: xhci: Fix scratchpad deallocation Greg KH
2009-12-07 0:00 ` [048/119] iwlwifi: Use RTS/CTS as the preferred protection mechanism for 6000 series Greg KH
2009-12-07 0:00 ` [049/119] iwlwifi: Fix issue on file transfer stalled in HT mode Greg KH
2009-12-07 0:00 ` [050/119] ima: replace GFP_KERNEL with GFP_NOFS Greg KH
2009-12-07 0:00 ` [051/119] NFSv4: Fix a cache validation bug which causes getcwd() to return ENOENT Greg KH
2009-12-07 0:00 ` [052/119] fuse: reject O_DIRECT flag also in fuse_create Greg KH
2009-12-07 0:00 ` [053/119] ASoC: Fix suspend with active audio streams Greg KH
2009-12-07 0:00 ` [054/119] ASoC: AIC23: Fixing infinite loop in resume path Greg KH
2009-12-07 0:00 ` [055/119] mac80211: fix two remote exploits Greg KH
2009-12-07 0:00 ` [056/119] mac80211: fix spurious delBA handling Greg KH
2009-12-07 0:00 ` [057/119] b43: Work around mac80211 race condition Greg KH
2009-12-07 0:00 ` [058/119] rfkill: fix miscdev ops Greg KH
2009-12-07 0:00 ` [059/119] thinkpad-acpi: fix sign of ERESTARTSYS return Greg KH
2009-12-07 0:00 ` [060/119] [CPUFREQ] Enable ACPI PDC handshake for VIA/Centaur CPUs Greg KH
2009-12-07 0:00 ` [061/119] V4L/DVB (13436): cxusb: Fix hang on DViCO FusionHDTV DVB-T Dual Digital 4 (rev 1) Greg KH
2009-12-07 0:00 ` [062/119] V4L/DVB (13321): radio-gemtek-pci: fix double mutex_lock Greg KH
2009-12-07 0:00 ` [063/119] V4L/DVB (12948): v4l1-compat: fix VIDIOC_G_STD handling Greg KH
2009-12-07 0:00 ` [064/119] V4L/DVB (12280): gspca - sonixj: Remove auto gain/wb/expo for the ov7660 sensor Greg KH
2009-12-07 0:00 ` [065/119] V4L/DVB (12356): gspca - sonixj: Webcam 0c45:6148 added Greg KH
2009-12-07 15:59 ` [Stable-review] " Stefan Bader
2009-12-07 16:48 ` Greg KH
2009-12-07 20:19 ` Stefan Bader
2009-12-07 0:00 ` [066/119] V4L/DVB (12501): gspca - sonixj: Do the ov7660 sensor work again Greg KH
2009-12-07 0:00 ` [067/119] V4L/DVB (12691): gspca - sonixj: Dont use mdelay() Greg KH
2009-12-07 0:00 ` [068/119] V4L/DVB (12696): gspca - sonixj / sn9c102: Two drivers for 0c45:60fc and 0c45:613e Greg KH
2009-12-07 0:00 ` [069/119] drm/i915: Select CONFIG_SHMEM Greg KH
2009-12-07 0:00 ` [070/119] drm: work around EDIDs with bad htotal/vtotal values Greg KH
2009-12-07 0:00 ` [071/119] drm/i915: Fix IRQ stall issue on Ironlake Greg KH
2009-12-07 0:00 ` [072/119] udp: Fix udp_poll() and ioctl() Greg KH
2009-12-07 0:00 ` [073/119] acenic: Pass up error code from ace_load_firmware() Greg KH
2009-12-07 0:00 ` [074/119] pkt_sched: pedit use proper struct Greg KH
2009-12-07 0:00 ` [075/119] net: fix sk_forward_alloc corruption Greg KH
2009-12-07 0:00 ` [076/119] bonding: Modify hash transmit policies to use the packets source MAC address Greg KH
2009-12-07 0:00 ` [077/119] sfc: Set ip_summed correctly for page buffers passed to GRO Greg KH
2009-12-07 0:00 ` [078/119] sparc64: replace parentheses in pmul() Greg KH
2009-12-07 0:00 ` [079/119] sparc: Move of_set_property_mutex acquisition outside of devtree_lock grab Greg KH
2009-12-07 0:00 ` [080/119] sched: Fix boot crash by zalloc()ing most of the cpu masks Greg KH
2009-12-08 1:39 ` Rusty Russell
2009-12-08 17:54 ` Greg KH
2009-12-07 0:00 ` [081/119] V4L/DVB (13202): smsusb: add autodetection support for three additional Hauppauge USB IDs Greg KH
2009-12-07 0:00 ` [082/119] V4L/DVB (13313): saa7134: add support for FORCE_TS_VALID mode for mpeg ts input Greg KH
2009-12-07 0:00 ` [083/119] V4L/DVB (13314): saa7134: set ts_force_val for the Hauppauge WinTV HVR-1150 Greg KH
2009-12-07 0:01 ` [084/119] ipv4: additional update of dev_net(dev) to struct *net in ip_fragment.c, NULL ptr OOPS Greg KH
2009-12-07 0:01 ` [085/119] [CPUFREQ] speedstep-ich: fix error caused by 394122ab144dae4b276d74644a2f11c44a60ac5c Greg KH
2009-12-07 0:01 ` [086/119] USB: EHCI: dont send Clear-TT-Buffer following a STALL Greg KH
2009-12-07 0:01 ` [087/119] USB: musb_gadget: fix STALL handling Greg KH
2009-12-07 0:01 ` [088/119] usb: amd5536udc: fixed shared interrupt bug and warning oops Greg KH
2009-12-07 0:01 ` [089/119] USB: ftdi_sio: Keep going when write errors are encountered Greg KH
2009-12-07 0:01 ` [090/119] USB: work around for EHCI with quirky periodic schedules Greg KH
2009-12-07 0:01 ` [091/119] tty_port: handle the nonblocking open of a dead port corner case Greg KH
2009-12-07 0:01 ` [092/119] [ARM] pxamci: call mmc_remove_host() before freeing resources Greg KH
2009-12-07 0:01 ` [093/119] param: dont complain about unused module parameters Greg KH
2009-12-07 0:01 ` [094/119] modules: dont export section names of empty sections via sysfs Greg KH
2009-12-07 0:01 ` [095/119] md: revert incorrect fix for read error handling in raid1 Greg KH
2009-12-07 0:01 ` [096/119] perf_event: Adjust frequency and unthrottle for non-group-leader events Greg KH
2009-12-07 0:01 ` [097/119] hso: fix soft-lockup Greg KH
2009-12-07 0:01 ` [098/119] block: use after free bug in __blkdev_get Greg KH
2009-12-07 0:01 ` [099/119] hwmon: (adt7475) Fix temperature fault flags Greg KH
2009-12-07 0:01 ` [100/119] hwmon: (adt7475) Cache limits for 60 seconds Greg KH
2009-12-07 0:01 ` [101/119] agp/intel: new host bridge support Greg KH
2009-12-07 0:01 ` [102/119] netfilter: nf_nat: fix NAT issue in 2.6.30.4+ Greg KH
2009-12-07 0:01 ` [103/119] netfilter: xt_connlimit: fix regression caused by zero family value Greg KH
2009-12-07 0:01 ` [104/119] b43: Fix DMA TX bounce buffer copying Greg KH
2009-12-07 0:01 ` [105/119] crypto: padlock-aes - Use the correct mask when checking whether copying is required Greg KH
2009-12-07 0:01 ` [106/119] sky2: set carrier off in probe Greg KH
2009-12-07 0:01 ` [107/119] ath5k: Linear PCDAC code fixes Greg KH
2009-12-07 0:01 ` [108/119] i2c: Fix userspace_device list corruption Greg KH
2009-12-07 0:01 ` [109/119] acerhdf: fix fan control for AOA150 model Greg KH
2009-12-07 0:01 ` [110/119] drm/fb: fix FBIOGET/PUT_VSCREENINFO pixel clock handling Greg KH
2009-12-07 0:01 ` [111/119] tty/of_serial: add missing ns16550a id Greg KH
2009-12-07 0:01 ` [112/119] V4L/DVB (13255): gspca - m5602-s5k4aa: Add vflip quirk for the Bruneinit laptop Greg KH
2009-12-07 0:01 ` [113/119] V4L/DVB (13256): gspca - m5602-s5k4aa: Add another MSI GX700 vflip quirk Greg KH
2009-12-07 0:01 ` [114/119] V4L/DVB (13257): gspca - m5602-s5k4aa: Add vflip for Fujitsu Amilo Xi 2528 Greg KH
2009-12-07 0:01 ` [115/119] PCI: Prevent AER driver from being loaded on non-root port PCIE devices Greg KH
2009-12-07 0:01 ` [116/119] acerhdf: additional BIOS versions Greg KH
2009-12-07 0:01 ` [117/119] acerhdf: return temperature in milidegree instead of degree Greg KH
2009-12-07 0:01 ` [118/119] Input: keyboard - fix braille keyboard keysym generation Greg KH
2009-12-07 0:01 ` [119/119] isdn: hfc_usb: Fix read buffer overflow Greg KH
2009-12-07 0:10 ` [000/119] 2.6.31.7-stable review Greg KH
2009-12-07 0:33 ` Alexander Beregalov
2009-12-07 0:37 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091207000644.059666416@mini.kroah.org \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=isely@pobox.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@redhat.com \
--cc=stable-review@kernel.org \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome