linux_dsm_epyc7002/drivers/usb/gadget/function
Benjamin Herrenschmidt 4a56a478a5 usb: gadget: mass_storage: Fix races between fsg_disable and fsg_set_alt
If fsg_disable() and fsg_set_alt() are called too closely to each
other (for example due to a quick reset/reconnect), what can happen
is that fsg_set_alt sets common->new_fsg from an interrupt while
handle_exception is trying to process the config change caused by
fsg_disable():

	fsg_disable()
	...
	handle_exception()
		sets state back to FSG_STATE_NORMAL
		hasn't yet called do_set_interface()
		or is inside it.

 ---> interrupt
	fsg_set_alt
		sets common->new_fsg
		queues a new FSG_STATE_CONFIG_CHANGE
 <---

Now, the first handle_exception can "see" the updated
new_fsg, treats it as if it was a fsg_set_alt() response,
call usb_composite_setup_continue() etc...

But then, the thread sees the second FSG_STATE_CONFIG_CHANGE,
and goes back down the same path, wipes and reattaches a now
active fsg, and .. calls usb_composite_setup_continue() which
at this point is wrong.

Not only we get a backtrace, but I suspect the second set_interface
wrecks some state causing the host to get upset in my case.

This fixes it by replacing "new_fsg" by a "state argument" (same
principle) which is set in the same lock section as the state
update, and retrieved similarly.

That way, there is never any discrepancy between the dequeued
state and the observed value of it. We keep the ability to have
the latest reconfig operation take precedence, but we guarantee
that once "dequeued" the argument (new_fsg) will not be clobbered
by any new event.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2019-08-12 08:55:24 +03:00
..
f_acm.c
f_ecm.c
f_eem.c USB: gadget: function: fix issue Unneeded variable: "value" 2019-07-03 10:58:44 +03:00
f_fs.c usb: gadget: Zero ffs_io_data 2019-06-18 11:58:29 +03:00
f_hid.c USB: gadget: f_hid: fix deadlock in f_hidg_write() 2019-03-20 10:58:48 +02:00
f_loopback.c
f_mass_storage.c usb: gadget: mass_storage: Fix races between fsg_disable and fsg_set_alt 2019-08-12 08:55:24 +03:00
f_mass_storage.h
f_midi.c
f_ncm.c usb: gadget: f_ncm: Add OS descriptor support 2019-05-03 09:13:47 +03:00
f_obex.c
f_phonet.c
f_printer.c
f_rndis.c
f_serial.c
f_sourcesink.c
f_subset.c
f_tcm.c
f_uac1_legacy.c usb: gadget: do not use __constant_cpu_to_le16 2019-05-03 09:13:48 +03:00
f_uac1.c
f_uac2.c
f_uvc.c media: usb/gadget/f_uvc: set device_caps in struct video_device 2019-06-05 08:47:44 -04:00
f_uvc.h
g_zero.h
Makefile
ndis.h
rndis.c
rndis.h
storage_common.c
storage_common.h Revert "usb: gadget: storage: Remove warning message" 2019-07-04 13:05:59 +02:00
tcm.h
u_audio.c usb: gadget: u_audio: Fixed variable declaration coding style issue 2019-06-18 11:58:28 +03:00
u_audio.h
u_ecm.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_eem.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_ether_configfs.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_ether.c usb: Replace snprintf with scnprintf in gether_get_ifname 2019-06-20 08:53:11 +03:00
u_ether.h
u_fs.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_gether.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_hid.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_midi.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_ncm.h usb: gadget: f_ncm: Add OS descriptor support 2019-05-03 09:13:47 +03:00
u_phonet.h
u_printer.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_rndis.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_serial.c
u_serial.h
u_tcm.h
u_uac1_legacy.c
u_uac1_legacy.h
u_uac1.h
u_uac2.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
u_uvc.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
uvc_configfs.c usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
uvc_configfs.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
uvc_queue.c
uvc_queue.h
uvc_v4l2.c media: usb/gadget/f_uvc: set device_caps in struct video_device 2019-06-05 08:47:44 -04:00
uvc_v4l2.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
uvc_video.c
uvc_video.h usb: gadget: Change Andrzej Pietrasiewicz's e-mail address 2019-02-11 11:12:29 +02:00
uvc.h