/* * UWB radio (channel) management. * * Copyright (C) 2008 Cambridge Silicon Radio Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include "uwb-internal.h" static int uwb_radio_select_channel(struct uwb_rc *rc) { /* * Default to channel 9 (BG1, TFC1) unless the user has * selected a specific channel or there are no active PALs. */ if (rc->active_pals == 0) return -1; if (rc->beaconing_forced) return rc->beaconing_forced; return 9; } /* * Notify all active PALs that the channel has changed. */ static void uwb_radio_channel_changed(struct uwb_rc *rc, int channel) { struct uwb_pal *pal; list_for_each_entry(pal, &rc->pals, node) { if (pal->channel && channel != pal->channel) { pal->channel = channel; if (pal->channel_changed) pal->channel_changed(pal, pal->channel); } } } /* * Change to a new channel and notify any active PALs of the new * channel. * * When stopping the radio, PALs need to be notified first so they can * terminate any active reservations. */ static int uwb_radio_change_channel(struct uwb_rc *rc, int channel) { int ret = 0; struct device *dev = &rc->uwb_dev.dev; dev_dbg(dev, "%s: channel = %d, rc->beaconing = %d\n", __func__, channel, rc->beaconing); if (channel == -1) uwb_radio_channel_changed(rc, channel); if (channel != rc->beaconing) { if (rc->beaconing != -1 && channel != -1) { /* * FIXME: should signal the channel change * with a Channel Change IE. */ ret = uwb_radio_change_channel(rc, -1); if (ret < 0) return ret; } ret = uwb_rc_beacon(rc, channel, 0); } if (channel != -1) uwb_radio_channel_changed(rc, rc->beaconing); return ret; } /** * uwb_radio_start - request that the radio be started * @pal: the PAL making the request. * * If the radio is not already active, a suitable channel is selected * and beacons are started. */ int uwb_radio_start(struct uwb_pal *pal) { struct uwb_rc *rc = pal->rc; int ret = 0; mutex_lock(&rc->uwb_dev.mutex); if (!pal->channel) { pal->channel = -1; rc->active_pals++; ret = uwb_radio_change_channel(rc, uwb_radio_select_channel(rc)); } mutex_unlock(&rc->uwb_dev.mutex); return ret; } EXPORT_SYMBOL_GPL(uwb_radio_start); /** * uwb_radio_stop - request that the radio be stopped. * @pal: the PAL making the request. * * Stops the radio if no other PAL is making use of it. */ void uwb_radio_stop(struct uwb_pal *pal) { struct uwb_rc *rc = pal->rc; mutex_lock(&rc->uwb_dev.mutex); if (pal->channel) { rc->active_pals--; uwb_radio_change_channel(rc, uwb_radio_select_channel(rc)); pal->channel = 0; } mutex_unlock(&rc->uwb_dev.mutex); } EXPORT_SYMBOL_GPL(uwb_radio_stop); /* * uwb_radio_force_channel - force a specific channel to be used * @rc: the radio controller. * @channel: the channel to use; -1 to force the radio to stop; 0 to * use the default channel selection algorithm. */ int uwb_radio_force_channel(struct uwb_rc *rc, int channel) { int ret = 0; mutex_lock(&rc->uwb_dev.mutex); rc->beaconing_forced = channel; ret = uwb_radio_change_channel(rc, uwb_radio_select_channel(rc)); mutex_unlock(&rc->uwb_dev.mutex); return ret; } /* * uwb_radio_setup - setup the radio manager * @rc: the radio controller. * * The radio controller is reset to ensure it's in a known state * before it's used. */ int uwb_radio_setup(struct uwb_rc *rc) { return uwb_rc_reset(rc); } /* * uwb_radio_reset_state - reset any radio manager state * @rc: the radio controller. * * All internal radio manager state is reset to values corresponding * to a reset radio controller. */ void uwb_radio_reset_state(struct uwb_rc *rc) { struct uwb_pal *pal; mutex_lock(&rc->uwb_dev.mutex); list_for_each_entry(pal, &rc->pals, node) { if (pal->channel) { pal->channel = -1; if (pal->channel_changed) pal->channel_changed(pal, -1); } } rc->beaconing = -1; rc->scanning = -1; mutex_unlock(&rc->uwb_dev.mutex); } /* * uwb_radio_shutdown - shutdown the radio manager * @rc: the radio controller. * * The radio controller is reset. */ void uwb_radio_shutdown(struct uwb_rc *rc) { uwb_radio_reset_state(rc); uwb_rc_reset(rc); } d'>966d2b04e070bc040319aaebfec09e0144dc3341 (patch) tree4b96156e3d1dd4dfd6039b7c219c9dc4616da52d /net/rds/Kconfig parent1b1bc42c1692e9b62756323c675a44cb1a1f9dbd (diff)
percpu-refcount: fix reference leak during percpu-atomic transition
percpu_ref_tryget() and percpu_ref_tryget_live() should return "true" IFF they acquire a reference. But the return value from atomic_long_inc_not_zero() is a long and may have high bits set, e.g. PERCPU_COUNT_BIAS, and the return value of the tryget routines is bool so the reference may actually be acquired but the routines return "false" which results in a reference leak since the caller assumes it does not need to do a corresponding percpu_ref_put(). This was seen when performing CPU hotplug during I/O, as hangs in blk_mq_freeze_queue_wait where percpu_ref_kill (blk_mq_freeze_queue_start) raced with percpu_ref_tryget (blk_mq_timeout_work). Sample stack trace: __switch_to+0x2c0/0x450 __schedule+0x2f8/0x970 schedule+0x48/0xc0 blk_mq_freeze_queue_wait+0x94/0x120 blk_mq_queue_reinit_work+0xb8/0x180 blk_mq_queue_reinit_prepare+0x84/0xa0 cpuhp_invoke_callback+0x17c/0x600 cpuhp_up_callbacks+0x58/0x150 _cpu_up+0xf0/0x1c0 do_cpu_up+0x120/0x150 cpu_subsys_online+0x64/0xe0 device_online+0xb4/0x120 online_store+0xb4/0xc0 dev_attr_store+0x68/0xa0 sysfs_kf_write+0x80/0xb0 kernfs_fop_write+0x17c/0x250 __vfs_write+0x6c/0x1e0 vfs_write+0xd0/0x270 SyS_write+0x6c/0x110 system_call+0x38/0xe0 Examination of the queue showed a single reference (no PERCPU_COUNT_BIAS, and __PERCPU_REF_DEAD, __PERCPU_REF_ATOMIC set) and no requests. However, conditions at the time of the race are count of PERCPU_COUNT_BIAS + 0 and __PERCPU_REF_DEAD and __PERCPU_REF_ATOMIC set. The fix is to make the tryget routines use an actual boolean internally instead of the atomic long result truncated to a int. Fixes: e625305b3907 percpu-refcount: make percpu_ref based on longs instead of ints Link: https://bugzilla.kernel.org/show_bug.cgi?id=190751 Signed-off-by: Douglas Miller <dougmill@linux.vnet.ibm.com> Reviewed-by: Jens Axboe <axboe@fb.com> Signed-off-by: Tejun Heo <tj@kernel.org> Fixes: e625305b3907 ("percpu-refcount: make percpu_ref based on longs instead of ints") Cc: stable@vger.kernel.org # v3.18+
Diffstat (limited to 'net/rds/Kconfig')