From patchwork Fri Dec 8 23:02:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Liu Bo X-Patchwork-Id: 10103441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7F7A5602A0 for ; Sat, 9 Dec 2017 00:05:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 718B428E9D for ; Sat, 9 Dec 2017 00:05:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63ED228FE3; Sat, 9 Dec 2017 00:05:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A275928E9D for ; Sat, 9 Dec 2017 00:05:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751155AbdLIAFA (ORCPT ); Fri, 8 Dec 2017 19:05:00 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:38614 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750788AbdLIAE7 (ORCPT ); Fri, 8 Dec 2017 19:04:59 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vB902EIi060759 for ; Sat, 9 Dec 2017 00:04:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=Bcx5DjmXZ42Gnv6C0UKD65O1XsAGQXE97iu8BWHPvOg=; b=naLbebji7CNqzn0HACvYNPQBOL/qC0gdMtMqLvIdQ7RuU/9RwOpofyNUkyxxKGdbUzhD qk59j+ssZg4/Ah6WOxInWNRTM0Q4fo1QTpnM90Fa1g/kfJFIoHTomhWvbw6ExLRCPehj ZxRbSTJEHwZRLsqH7kXJzIyMt7Ubgatzx3ldAEW8BeMOejDWm5Iq4GDdowl84aldG5M/ jrpK+LRMNCnrnLSOmzOHKQOUL3kNpc/G4KUUCbpTa6axbnEwBv/pRguKeKJKUQV69vJb 423+6/welBUth6JB42AHrVv8kipa2bDZ3zhZl1Sxy7NKjS1yiVZcJaJnOaALxSnQWebh 8A== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2er4pag20d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 09 Dec 2017 00:04:58 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vB904vBO003146 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 9 Dec 2017 00:04:57 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vB904vvB030390 for ; Sat, 9 Dec 2017 00:04:57 GMT Received: from dhcp-10-211-47-181.usdhcp.oraclecorp.com.com (/10.211.47.181) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 08 Dec 2017 16:04:57 -0800 From: Liu Bo To: linux-btrfs@vger.kernel.org Subject: [PATCH] Btrfs: raid56: fix race between merge_bio and rbio_orig_end_io Date: Fri, 8 Dec 2017 16:02:35 -0700 Message-Id: <20171208230235.30636-1-bo.li.liu@oracle.com> X-Mailer: git-send-email 2.9.4 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8739 signatures=668644 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=18 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=657 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712080323 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We're not allowed to take any new bios to rbio->bio_list in rbio_orig_end_io(), otherwise we may get merged with more bios and rbio->bio_list is not empty. This should only happens in error-out cases, the normal path of recover and full stripe write have already set RBIO_RMW_LOCKED_BIT to disable merge before doing IO. Reported-by: Jérôme Carretero Signed-off-by: Liu Bo --- fs/btrfs/raid56.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index 5aa9d22..127c782 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -859,12 +859,23 @@ static void free_raid_bio(struct btrfs_raid_bio *rbio) */ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t err) { - struct bio *cur = bio_list_get(&rbio->bio_list); + struct bio *cur; struct bio *next; + /* + * We're not allowed to take any new bios to rbio->bio_list + * from now on, otherwise we may get merged with more bios and + * rbio->bio_list is not empty. + */ + spin_lock(&rbio->bio_list_lock); + set_bit(RBIO_RMW_LOCKED_BIT, &rbio->flags); + spin_unlock(&rbio->bio_list_lock); + if (rbio->generic_bio_cnt) btrfs_bio_counter_sub(rbio->fs_info, rbio->generic_bio_cnt); + cur = bio_list_get(&rbio->bio_list); + free_raid_bio(rbio); while (cur) {