From patchwork Fri Feb 2 17:53:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 10197689 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 67FB96037D for ; Fri, 2 Feb 2018 17:54:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5752028EEA for ; Fri, 2 Feb 2018 17:54:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BCE728EFC; Fri, 2 Feb 2018 17:54:35 +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 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 9A92528EF5 for ; Fri, 2 Feb 2018 17:54:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753350AbeBBRyb (ORCPT ); Fri, 2 Feb 2018 12:54:31 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:37768 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753545AbeBBRxd (ORCPT ); Fri, 2 Feb 2018 12:53:33 -0500 Received: by mail-qt0-f196.google.com with SMTP id d54so31944118qtd.4; Fri, 02 Feb 2018 09:53:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=Q3i5j+IT7sUH6aLjWhTS8l0D19ecYoYyatxtwJM5MNw=; b=cEBUlyiutTBZsYCLv7S3Lxh3cJwt0OyUUhmWTP7UHV5+iYf/DXg+VqmBW/u3PyLXmu 7H+BdC1M4pO4l7KkDWrdjrs1FMD7GGUl/MmDICQPHHnPYbIveoV6jC/ijx1radwOFkRW ITwbkRcScwzF7nw3MfYjuMOo9xjAcCRE4cEJrxfMd7WQViFXjWYfXovBqUuxml1/G2xt rQvTMH6Ak8dDk/DhXuEoePar8ybUpnP15r5tPFo5oyS/MBZJD+4W4eV+lRXajMKlKv3g rmC3AC0eWiPvlY3L8kv5Ep2JWaT68O3QvJvlLO5TK8wkCnoDZXt8G+W4G292ZdQypn7j e8ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mime-version:content-disposition:user-agent; bh=Q3i5j+IT7sUH6aLjWhTS8l0D19ecYoYyatxtwJM5MNw=; b=npxfou+A3ew+GMH/JT+LRjPlpgZZQ98ww9Fj1Mp7BuFhrb4mO2Tn1jK5x2QzvUlaFv AOG/NFLGIQn8UTPLabLSoFUBXkBF6G+jRCVF0mTssMQmoCO3tHxyWer8cE5DQ6GIDpGx 3ZZerptVhp8/eT8/uAqE/FBhBrJEK6mP7SyanU0lGHbJ3M9aGPw65MtuvOnO1FZciXxq ejXwvfumJPLMMmAqCiWkEqeBQwi7Phb6ZNjIaT/v/c6LjyvRQV+9xAfkTYsLcBRs9HfJ Y5+M/xSxvUduZZFYbFUct424Na5tuemdtDadC766bLDNVO2Nanadm/0uMax0+g3e42ne CXYA== X-Gm-Message-State: AKwxytf8pHY/L1eoBu8P4ha8I2U+rhbVHktFDuztKsvlY1WQgcEGJJxF qAOebRWumf3xMpnXDSypC16SCWVj X-Google-Smtp-Source: AH8x224AwUod1arIQOWpB+Xulqr2mV7EG6pzMt4T8byjoeJuWoFIjkZjmZQmWxuuVblhvklMHSHq1A== X-Received: by 10.237.37.112 with SMTP id w45mr61587331qtc.242.1517594011955; Fri, 02 Feb 2018 09:53:31 -0800 (PST) Received: from localhost (dhcp-ec-8-6b-ed-7a-cf.cpe.echoes.net. [72.28.5.223]) by smtp.gmail.com with ESMTPSA id y30sm1697344qtm.50.2018.02.02.09.53.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Feb 2018 09:53:31 -0800 (PST) Date: Fri, 2 Feb 2018 09:53:28 -0800 From: Tejun Heo To: Jens Axboe , Miklos Szeredi Cc: Joshua Miller , kernel-team@fb.com, Johannes Weiner , Jan Kara , stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/2] bdi: make sure congestion states are clear on free Message-ID: <20180202175328.GL1121507@devbig577.frc2.facebook.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP FUSE has a bug where it fails to clear congestion states if a connection gets aborted while congested, which can leave nr_wb_congested[] stuck until reboot causing wait_iff_congested() to wait spuriously. While the bdi owner, FUSE, is primarily responsible for clearing congestion states before destroying bdi_writebacks, bdi layer can ensure that congestion states are not leaked beyond bdi_writeback lifecycle. Signed-off-by: Tejun Heo Reported-by: Joshua Miller Cc: Johannes Weiner Cc: Jan Kara Cc: stable@vger.kernel.org Acked-by: Johannes Weiner Reviewed-by: Jan Kara --- include/linux/backing-dev.h | 14 +++++++++++++- mm/backing-dev.c | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -220,6 +220,18 @@ static inline int bdi_sched_wait(void *w return 0; } +static inline void __wb_congested_free(struct bdi_writeback_congested *congested) +{ + /* + * Make sure congestion states are cleared before freeing to avoid + * nr_wb_congested() corruption which can lead to misbehaving + * wait_iff_congested(). + */ + clear_wb_congested(congested, BLK_RW_SYNC); + clear_wb_congested(congested, BLK_RW_ASYNC); + kfree(congested); +} + #ifdef CONFIG_CGROUP_WRITEBACK struct bdi_writeback_congested * @@ -409,7 +421,7 @@ wb_congested_get_create(struct backing_d static inline void wb_congested_put(struct bdi_writeback_congested *congested) { if (atomic_dec_and_test(&congested->refcnt)) - kfree(congested); + __wb_congested_free(congested); } static inline struct bdi_writeback *wb_find_current(struct backing_dev_info *bdi) --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -509,7 +509,7 @@ void wb_congested_put(struct bdi_writeba } spin_unlock_irqrestore(&cgwb_lock, flags); - kfree(congested); + __wb_congested_free(congested); } static void cgwb_release_workfn(struct work_struct *work)