Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8415573ybl; Thu, 16 Jan 2020 16:26:21 -0800 (PST) X-Google-Smtp-Source: APXvYqziLC4rBQudDrtEFFc+JyAF1cFajzB+sZFI48XrfJqIfAG+EzwNsa07bHG2z05/QJXmDnj0 X-Received: by 2002:a9d:198b:: with SMTP id k11mr4343557otk.295.1579220781018; Thu, 16 Jan 2020 16:26:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579220781; cv=none; d=google.com; s=arc-20160816; b=k/ZL5pFraLzJ49FBfuZFOUwnbNhTYfg7otsTot7YS0ayfkZ2tGmHIm2mVvnBPYWN+j 0hzrRszfeRi8OoVeydKGsK4bb+VfcAOvdQBxtG+7cGJop0movg+RVVWbHFZel97HC1+R 1oIST4CQLbwbxBsyl4rZvEY+eGUBKZfkMdyNoXmUZWqnP4UueEkdJ71gYj7v+gHzmA0Z 30YbSyIwzBm596RswmVQ/GkF/KmgrQ+IIETMEnpCJMRiDRkDJyV//X+5Phl66ArNXim7 /GupmqCzIrhLsB0AB0y86AM27lYMsYWh4/wzbq/xX5apx5YWIWIZwTd9nXeC+50w+Ai3 Wplg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ZeEx6vriQEqUZqvv01zk5S/tyK4ds56A87BGFV2fdo0=; b=rEit+f17tO/f2SSm+yW9SEI3KZWUlTMHVjd+KfDCZ1nPYCgao0PBGviYTre/SQ3eD4 4RVLhWymScyZ2R6T/h/0DpzbenDAByz8nw0Yf0WTpMdZt4ucegnlP0CnbdVUUn3WJQ0Q BHB4rs52xpzqSSKRJBesyS/k84XnEZbpx0OedRmatwvDKJKFEke6J4C+ZV8hNH2lpbn+ ny8GNrZ+sFkZ6g1I5BHRHus9EODJw02GZmt1DQZaDOWr4y/cwgvvM86e8ov7tB64Ut7/ Kcm/mNIe1+MTdnJPsL2cYxULN5hPwyW5/x1klXl+iazt9NatDtp5mt14+/2/dhwyisGb iNgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="JO/zYu9/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si13908918otk.251.2020.01.16.16.26.08; Thu, 16 Jan 2020 16:26:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="JO/zYu9/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390108AbgAPWpY (ORCPT + 99 others); Thu, 16 Jan 2020 17:45:24 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41807 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732417AbgAPWpX (ORCPT ); Thu, 16 Jan 2020 17:45:23 -0500 Received: by mail-wr1-f66.google.com with SMTP id c9so20829459wrw.8 for ; Thu, 16 Jan 2020 14:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ZeEx6vriQEqUZqvv01zk5S/tyK4ds56A87BGFV2fdo0=; b=JO/zYu9/0B1QqfWk+Q90BO8T36nWjCEP/YqBt2+1t6iCF3P6VwHPIiIMeynH+Bhv55 kPWdlzTgaAgFMQRfpCr6D5dzTeesa8rygYDAeaMvPfIrEXwCEn+8vxI25g54ecrlZJBN PiJc01/a42az6zmQV2n/NAOGJ/yiScTNSIdiBHjBjXzVAHki5SrJNlUya2Z72x9fRpzw fBxmCvMLlyfrZK7D31ZrdKo7kiUM69JenaK1BgzhgHSzeoUEDWKh1dc5kaVavpMpLcAx fdRwfBbLV2jHZSvjFyInwFPUh4tzghTMEgRwY1MvfN+Jn0ksENiXujDRc2JwgQImVzEh ghuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ZeEx6vriQEqUZqvv01zk5S/tyK4ds56A87BGFV2fdo0=; b=EIjUtZFCm/7P3xtHJaQ/Kf0aSRcRI5VOHkr56AFZpR7l9BtSThX63pGp3iOlKxNuxh FANgAcd7mbaJAiIavGOYPzFJi6VdHu7oLx6VXzgFlhW3BSJyHFrnTQp6fQlEg8V47BoQ 0g6i/1hlyjXnNo+GD42UPVjy3ktVaZYyBCsQHy9hZ+icYQjLCyelZj924bkAbkk1H34d kz6ZSdZ14/SZptyjMrMNuZNW+Zei2/GM+OWM/2Bsu8qiSYZhmjB029jxcLhQmfvglTX+ lTEDNAFkTTu6WVQgYTaaGlvNoHKJ/nV7vHbtQz9Fu/gUHkwpcCfo9kIHeuqhrlOIOIK1 txRA== X-Gm-Message-State: APjAAAU+SVyGEKsvqDGUYsoxeGY9QkD4xoYsxBxQdrw+mfCkVkysnkYa F3s0wXucqMsq8DbqunUucebre+Ix9cD5C95nZ7c= X-Received: by 2002:adf:e5ce:: with SMTP id a14mr5528976wrn.214.1579214721659; Thu, 16 Jan 2020 14:45:21 -0800 (PST) MIME-Version: 1.0 References: <1578736236-141308-1-git-send-email-chengzhihao1@huawei.com> In-Reply-To: <1578736236-141308-1-git-send-email-chengzhihao1@huawei.com> From: Richard Weinberger Date: Thu, 16 Jan 2020 23:45:10 +0100 Message-ID: Subject: Re: [PATCH v2] ubifs: Fix deadlock in concurrent bulk-read and writepage To: Zhihao Cheng Cc: Richard Weinberger , Sascha Hauer , "zhangyi (F)" , linux-mtd@lists.infradead.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 11, 2020 at 10:43 AM Zhihao Cheng wro= te: > > In ubifs, concurrent execution of writepage and bulk read on the same fil= e > may cause ABBA deadlock, for example (Reproduce method see Link): > > Process A(Bulk-read starts from page4) Process B(write page4 back= ) > vfs_read wb_workfn or fsync > ... ... > generic_file_buffered_read write_cache_pages > ubifs_readpage LOCK(page4) > > ubifs_bulk_read ubifs_writepage > LOCK(ui->ui_mutex) ubifs_write_inode > > ubifs_do_bulk_read LOCK(ui->ui_mutex) > find_or_create_page(alloc page4) =E2=86=91 > LOCK(page4) <-- ABBA deadlock occurs! > > In order to ensure the serialization execution of bulk read, we can't > remove the big lock 'ui->ui_mutex' in ubifs_bulk_read(). Instead, we > allow ubifs_do_bulk_read() to lock page failed by replacing > find_or_create_page(FGP_LOCK) with > pagecache_get_page(FGP_LOCK | FGP_NOWAIT). > > Signed-off-by: Zhihao Cheng > Suggested-by: zhangyi (F) > Cc: > Fixes: 4793e7c5e1c ("UBIFS: add bulk-read facility") > Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D206153 > --- > fs/ubifs/file.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) Applied. Thanks a lot for hunting this down! --=20 Thanks, //richard