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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,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 03309C282C3 for ; Thu, 24 Jan 2019 19:57:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF53021726 for ; Thu, 24 Jan 2019 19:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548359877; bh=jQMbwjLjo3XtOB2OSs8mOO5xaZ+VQhfyRSWlBvvbJsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CJCvLyyxpVgDLcsEOCYstx28LlOQqv9s2XsioqG8qkYQ5vxVeodQ02A7lqnlbA4wT tZG1K7QlHJGeykfERSRVYiC2tbKBI8/mNyxpISxxPmFXPxwMME8Tkd/vyCHomu5HL9 IoZCYhqctJ7nmoWxQDN1ILxaaO3/3OfH6IDCKqc8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731462AbfAXTey (ORCPT ); Thu, 24 Jan 2019 14:34:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:34720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729789AbfAXTex (ORCPT ); Thu, 24 Jan 2019 14:34:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D776B218FC; Thu, 24 Jan 2019 19:34:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548358492; bh=jQMbwjLjo3XtOB2OSs8mOO5xaZ+VQhfyRSWlBvvbJsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ppij2Gv0agmcJi+3+7XluiZrgDUQlCKfjAH3tnwwdikGqxLem5rsVLf0qqRKkmHr1 bq/T4cm4hGvHLcPpcSyTJNdyLcj6yj15PqA5N7Qda8Yof0PwoZeCRk9uV2bMCV6hvo 4RwOdlswCJzxCqYD4PPHdYkO5GMte8N5Hfl4uPbM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Anders Roxell , Sasha Levin Subject: [PATCH 4.19 020/106] writeback: dont decrement wb->refcnt if !wb->bdi Date: Thu, 24 Jan 2019 20:19:37 +0100 Message-Id: <20190124190207.657867946@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124190206.342411005@linuxfoundation.org> References: <20190124190206.342411005@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 9a6bc0951cfa..c31157135598 100644 --- a/include/linux/backing-dev-defs.h +++ b/include/linux/backing-dev-defs.h @@ -258,6 +258,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