From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968695AbdIZQQV (ORCPT ); Tue, 26 Sep 2017 12:16:21 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:56314 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934771AbdIZQQT (ORCPT ); Tue, 26 Sep 2017 12:16:19 -0400 X-Greylist: delayed 2618 seconds by postgrey-1.27 at vger.kernel.org; Tue, 26 Sep 2017 12:16:19 EDT Message-ID: <1506439955.1860.46.camel@codethink.co.uk> Subject: Re: [PATCH 4.4 35/53] Bluetooth: hidp: fix possible might sleep error in hidp_session_thread From: Ben Hutchings To: Jeffy Chen , Marcel Holtmann Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, AL Yu-Chen Cho , Rohit Vaswani , Jiri Slaby , Greg Kroah-Hartman Date: Tue, 26 Sep 2017 16:32:35 +0100 In-Reply-To: <20170828080519.231393037@linuxfoundation.org> References: <20170828080517.599193891@linuxfoundation.org> <20170828080519.231393037@linuxfoundation.org> Organization: Codethink Ltd. Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.9-1+b1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2017-08-28 at 10:05 +0200, Greg Kroah-Hartman wrote: > 4.4-stable review patch. If anyone has any objections, please let me know. > > ------------------ > > From: Jeffy Chen > > commit 5da8e47d849d3d37b14129f038782a095b9ad049 upstream. > > It looks like hidp_session_thread has same pattern as the issue reported in > old rfcomm: > > while (1) { > set_current_state(TASK_INTERRUPTIBLE); > if (condition) > break; > // may call might_sleep here > schedule(); > } > __set_current_state(TASK_RUNNING); > > Which fixed at: > dfb2fae Bluetooth: Fix nested sleeps > > So let's fix it at the same way, also follow the suggestion of: > https://lwn.net/Articles/628628/ > > Signed-off-by: Jeffy Chen > Tested-by: AL Yu-Chen Cho > Tested-by: Rohit Vaswani > Signed-off-by: Marcel Holtmann > Cc: Jiri Slaby > Signed-off-by: Greg Kroah-Hartman > > --- > net/bluetooth/hidp/core.c | 33 ++++++++++++++++++++++----------- > 1 file changed, 22 insertions(+), 11 deletions(-) > > --- a/net/bluetooth/hidp/core.c > +++ b/net/bluetooth/hidp/core.c [...] > + /* Ensure session->terminate is updated */ > + smp_mb__before_atomic(); > if (atomic_read(&session->terminate)) > break; [...] smp_mb__before_atomic() is only meant to avoid adding a redundant barrier next to an atomic RMW operation if it already includes one (which is arch-dependent). atomic_read() is not an RMW operation and never includes a barrier, so it needs an smp_mb() before it. Ben. -- Ben Hutchings Software Developer, Codethink Ltd.