From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754148AbcICMbn (ORCPT ); Sat, 3 Sep 2016 08:31:43 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:49082 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752434AbcICMbj (ORCPT ); Sat, 3 Sep 2016 08:31:39 -0400 Date: Sat, 3 Sep 2016 14:31:33 +0200 From: Peter Zijlstra To: Alan Stern Cc: "Paul E. McKenney" , Ingo Molnar , Felipe Balbi , USB list , Kernel development list Subject: Re: Memory barrier needed with wake_up_process()? Message-ID: <20160903123133.GD2794@worktop> References: <20160902184759.GB3663@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 02, 2016 at 04:29:19PM -0400, Alan Stern wrote: > I'm afraid so. The code doesn't use wait_event(), in part because > there's no wait_queue (since only one task is involved). You can use wait_queue fine with just one task, and it would clean up the code tremendously. You can replace things like the earlier mentioned: while (bh->state != BUF_STATE_EMPTY) { rc = sleep_thread(common, false); if (rc) return rc; } with: rc = wait_event_interruptible(&common->wq, bh->state == BUF_STATE_EMPTY); if (rc) return rc; > But maybe there's another barrier which needs to be fixed. Felipe, can > you check to see if received_cbw() is getting called in > get_next_command(), and if so, what value it returns? Or is the > preceding sleep_thread() the one that never wakes up? > > It could be that the smp_wmb() in wakeup_thread() needs to be smp_mb(). > The reason being that get_next_command() runs outside the protection of > the spinlock. Being somewhat confused by the code, I fail to follow that argument. wakeup_thread() is always called under that spinlock(), but since the critical section is 2 stores, I fail to see how a smp_mb() can make any difference over the smp_wmb() already there.