freebsd-skq/sys/dev/drm2/i915
Konstantin Belousov 5975e53d40 Fix a race in vm_page_busy_sleep(9).
Suppose that we have an exclusively busy page, and a thread which can
accept shared-busy page.  In this case, typical code waiting for the
page xbusy state to pass is
again:
	VM_OBJECT_WLOCK(object);
	...
	if (vm_page_xbusied(m)) {
		vm_page_lock(m);
 		VM_OBJECT_WUNLOCK(object);    <---1
		vm_page_busy_sleep(p, "vmopax");
 		goto again;
	}

Suppose that the xbusy state owner locked the object, unbusied the
page and unlocked the object after we are at the line [1], but before we
executed the load of the busy_lock word in vm_page_busy_sleep().  If it
happens that there is still no waiters recorded for the busy state,
the xbusy owner did not acquired the page lock, so it proceeded.

More, suppose that some other thread happen to share-busy the page
after xbusy state was relinquished but before the m->busy_lock is read
in vm_page_busy_sleep().  Again, that thread only needs vm_object lock
to proceed.  Then, vm_page_busy_sleep() reads busy_lock value equal to
the VPB_SHARERS_WORD(1).

In this case, all tests in vm_page_busy_sleep(9) pass and we are going
to sleep, despite the page being share-busied.

Update check for m->busy_lock == VPB_UNBUSIED in vm_page_busy_sleep(9)
to also accept shared-busy state if we only wait for the xbusy state to
pass.

Merge sequential if()s with the same 'then' clause in
vm_page_busy_sleep().

Note that the current code does not share-busy pages from parallel
threads, the only way to have more that one sbusy owner is right now
is to recurse.

Reported and tested by:	pho (previous version)
Reviewed by:	alc, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D8196
2016-10-13 14:41:05 +00:00
..
dvo_ch7xxx.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
dvo_ch7017.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
dvo_ivch.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
dvo_ns2501.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
dvo_sil164.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
dvo_tfp410.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
dvo.h Revert bus_get_cpus() for now. 2016-05-03 01:17:40 +00:00
i915_debug.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
i915_dma.c drm/i915: Call i915_gem_gtt_fini() when the device is detached 2016-03-12 11:57:32 +00:00
i915_drm.h sys/dev: minor spelling fixes. 2016-05-03 03:41:25 +00:00
i915_drv.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
i915_drv.h Remove redundant declarations for intel_fbc_enabled(..) and 2016-07-11 15:50:06 +00:00
i915_gem_context.c drm/i915: Import Linux commit 168f83660211b9e059e3bc0638daaa01e9ea0b71 2016-03-12 20:05:23 +00:00
i915_gem_evict.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
i915_gem_execbuffer.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
i915_gem_gtt.c sys/dev: minor spelling fixes. 2016-05-03 03:41:25 +00:00
i915_gem_stolen.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
i915_gem_tiling.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
i915_gem.c Fix a race in vm_page_busy_sleep(9). 2016-10-13 14:41:05 +00:00
i915_ioc32.c
i915_irq.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
i915_reg.h drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
i915_suspend.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_acpi.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_bios.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_bios.h drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_crt.c Don't repeat the the word 'the' 2016-05-17 12:52:31 +00:00
intel_ddi.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_display.c Don't repeat the the word 'the' 2016-05-17 12:52:31 +00:00
intel_dp.c etc: minor spelling fixes. 2016-05-02 16:47:28 +00:00
intel_drv.h Ensure waiting loops terminate during cold boot. This fixes boot with 2016-05-10 18:18:29 +00:00
intel_dvo.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_fb.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_hdmi.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_iic.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_lvds.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_modes.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_opregion.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_overlay.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_panel.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_pm.c i915kms intel_pm: Read from actual tsc_freq instead of uninitialized local 2016-04-20 02:58:22 +00:00
intel_ringbuffer.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_ringbuffer.h drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_sdvo_regs.h Reduce diff with linux 3.8.13 on i915 headers 2015-09-05 23:22:59 +00:00
intel_sdvo.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_sprite.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00
intel_tv.c drm/i915: Update to match Linux 3.8.13 2016-03-08 20:33:02 +00:00