From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932339AbbJIEdE (ORCPT ); Fri, 9 Oct 2015 00:33:04 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:10600 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753033AbbJIEdC (ORCPT ); Fri, 9 Oct 2015 00:33:02 -0400 Subject: Re: [PATCH] btrfs: fix waitqueue_active without memory barrier in btrfs To: Kosuke Tatsukawa , Chris Mason , David Sterba References: <17EC94B0A072C34B8DCF0D30AD16044A02874794@BPXM09GP.gisp.nec.co.jp> CC: "linux-btrfs@vger.kernel.org" , "linux-kernel@vger.kernel.org" From: Josef Bacik Message-ID: <56174371.8080107@fb.com> Date: Thu, 8 Oct 2015 21:32:49 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <17EC94B0A072C34B8DCF0D30AD16044A02874794@BPXM09GP.gisp.nec.co.jp> Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.14.151,1.0.33,0.0.0000 definitions=2015-10-09_05:2015-10-08,2015-10-09,1970-01-01 signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/08/2015 05:35 PM, Kosuke Tatsukawa wrote: > btrfs_bio_counter_sub() seems to be missing a memory barrier which might > cause the waker to not notice the waiter and miss sending a wake_up as > in the following figure. > > btrfs_bio_counter_sub btrfs_rm_dev_replace_blocked > ------------------------------------------------------------------------ > if (waitqueue_active(&fs_info->replace_wait)) > /* The CPU might reorder the test for > the waitqueue up here, before > prior writes complete */ > /* wait_event */ > /* __wait_event */ > /* ___wait_event */ > long __int = prepare_to_wait_event(&wq, > &__wait, state); > if (!percpu_counter_sum(&fs_info->bio_counter)) > percpu_counter_sub(&fs_info->bio_counter, > amount); > schedule() percpu_counter_sub can't be reordered, in its most basic form it does preempt_disable/enable which in its most basic form does barrier(). Thanks, Josef