From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13AA1C43387 for ; Tue, 8 Jan 2019 19:34:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA84B20827 for ; Tue, 8 Jan 2019 19:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546976096; bh=yL1Hp3LCsbPU8bkOJ1nZMnNehtYI+7MVpr9YdfarBCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=c62vGNpeJGzQyvVRtJ0UVCHf6pA4B/r8qB8s9N/O0km/WEp56RccoWgssRvfcp7Rg gQP0/xKYDsJ6w+Iq+LDHBzQRtP6na58ycau8MJGXqW3SwUmg+8bhsjhoi+P0GuxL7g zdj/XRa41GO2M2pk3l/21nQgjK0VGAiJFOEn2GSQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732114AbfAHTe4 (ORCPT ); Tue, 8 Jan 2019 14:34:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:43670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732092AbfAHTev (ORCPT ); Tue, 8 Jan 2019 14:34:51 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6A66F2063F; Tue, 8 Jan 2019 19:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546976091; bh=yL1Hp3LCsbPU8bkOJ1nZMnNehtYI+7MVpr9YdfarBCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=POs813D3Cno5GbGPhOwdqb/Z9IMcarZ98duMXF8JjEN9OLIhq2LxdSxj8yWPb/4I+ tIy2sTJVLWIylBFDUUepwN/BjGYxn2r4B+HJJ9UgA8GhRHRZ4g9eoUAkFiBxEK10Xe 0tT6k9ptyNbHbsEm+Um/rkdp5RCQSqInFCZXsvPg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anders Roxell , Arnd Bergmann , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.4 03/28] writeback: don't decrement wb->refcnt if !wb->bdi Date: Tue, 8 Jan 2019 14:34:20 -0500 Message-Id: <20190108193445.124251-3-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108193445.124251-1-sashal@kernel.org> References: <20190108193445.124251-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anders Roxell [ Upstream commit 347a28b586802d09604a149c1a1f6de5dccbe6fa ] This happened while running in qemu-system-aarch64, the AMBA PL011 UART driver when enabling CONFIG_DEBUG_TEST_DRIVER_REMOVE. arch_initcall(pl011_init) came before subsys_initcall(default_bdi_init), devtmpfs' handle_remove() crashes because the reference count is a NULL pointer only because wb->bdi hasn't been initialized yet. Rework so that wb_put have an extra check if wb->bdi before decrement wb->refcnt and also add a WARN_ON_ONCE to get a warning if it happens again in other drivers. Fixes: 52ebea749aae ("writeback: make backing_dev_info host cgroup-specific bdi_writebacks") Co-developed-by: Arnd Bergmann Signed-off-by: Arnd Bergmann Signed-off-by: Anders Roxell Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- include/linux/backing-dev-defs.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h index a307c37c2e6c..072501a0ac86 100644 --- a/include/linux/backing-dev-defs.h +++ b/include/linux/backing-dev-defs.h @@ -225,6 +225,14 @@ static inline void wb_get(struct bdi_writeback *wb) */ static inline void wb_put(struct bdi_writeback *wb) { + if (WARN_ON_ONCE(!wb->bdi)) { + /* + * A driver bug might cause a file to be removed before bdi was + * initialized. + */ + return; + } + if (wb != &wb->bdi->wb) percpu_ref_put(&wb->refcnt); } -- 2.19.1