Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp4591426imd; Tue, 30 Oct 2018 04:37:43 -0700 (PDT) X-Google-Smtp-Source: AJdET5fdt0uCKU+mgKF9GCbMkXFujoxmdNhST8HARVTC6PW8KHsQec1+M0+FwQSMcHkplCCtjPOn X-Received: by 2002:a62:104b:: with SMTP id y72-v6mr2572856pfi.113.1540899463858; Tue, 30 Oct 2018 04:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540899463; cv=none; d=google.com; s=arc-20160816; b=kZaOW85bg/Y+aN6NpuuYtspITlkBw9w5TDqsC+8kmyhsxL1qQ/oVJK0pdWTkhr7nW0 0LQGoxf79qKnNIx7KbimAyAT4Nvpc6zjDqOyc1U7G5S2NRbW1NBgjWvZ2avrzlMMq99K T57hs7VA8E73hU+Mmcc5hwJRTMNtv7uQ9lQki00Y/lBUvmpXPVH88xuRRqzC/KqlgMk/ WbBCUfjIhSconkLw6BYAwZrTWQjFmrLUdig6PscqTPJ4sDhZxSYabHdwAnCulgUP1vzz GIC3+XXBOCgg9L1/m3tljdP06nVrYUkNbDQ6dfhlaLG2kYsZgzNA2o0QiuTxljAk8b2/ 3vBw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0c4qq4Ww0v5TJSITOLozxcLN7WvXMS6Pv+NS1rx0eYU=; b=KkV585yF4IKk5WEB72q1sAoahndbPT4aJxG15g7+8GdERQnqlpIcuaKizyM3wvcjQh yHjhC5K+nil9b5o4S3Bpml7+9hDonPi9xmkUjZ/JigPoNk/GrUqtBsG0d3jqCzjun6qj kxz1wIbnjbNMtIJm+8jQOlRc+e50H0UJjbmZXTHfe8McrYgFiHkPBgkCyJnxhFT0eiUD br0j0L7vg172FLubA7N/UUVB5Mhg1hVVL8FxCeazNukgQEO1ejHSSGJgraclAJYVevDt YTxbHdX/7D838skLjwgvAXJV3iTPh1OqnU59opqIwsaKJK96qOOvTUMVSOz0KvPWhkzi GENA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gOwgddOR; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x2-v6si23171968pln.232.2018.10.30.04.37.28; Tue, 30 Oct 2018 04:37:43 -0700 (PDT) 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=@linaro.org header.s=google header.b=gOwgddOR; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727650AbeJ3U3n (ORCPT + 99 others); Tue, 30 Oct 2018 16:29:43 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:45764 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727387AbeJ3U3m (ORCPT ); Tue, 30 Oct 2018 16:29:42 -0400 Received: by mail-lf1-f65.google.com with SMTP id c24-v6so8553819lfi.12 for ; Tue, 30 Oct 2018 04:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0c4qq4Ww0v5TJSITOLozxcLN7WvXMS6Pv+NS1rx0eYU=; b=gOwgddOR+rM/NtNShdA4L1NNw1ah30l4AEuLYCWkGLxRpGkzqsuwELBEJyXstMxvks r3xIVi8YMesJ+WLA6wEeQtB+6AHhfluoImBdENXlMGxg9GKiRGYsCdFDGvJOiJ6Tlyvn 8coK+mZ5pGtFlOWi8EUhQ4xAw8yLu8MTg5tik= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0c4qq4Ww0v5TJSITOLozxcLN7WvXMS6Pv+NS1rx0eYU=; b=FvF2KvcZOumuE9MvdYyXujZOJc4xo6OW/KvPV3V7apiy+rfEnWY4Cg5Ko3YJsZQENq 4XQfZ9QF0xB76Xh0rlOg+ZbnwYYQNW0mTOYs+3nteKrK7USMbk9LKExpqYGVultk/GE0 m/AL8HFWeToenDGP/EsmJvLETyQosTlCzGjvaiWc9vQ9ClVd9jaXLGccV2CNYte0Onrt /x+4zahRjAct8YrWb5zMb9veE/6JDUC+WNY/an7vjZuoUSF8jNc2YQgBZD8gvy1hgaqp Mml8Ur0CPCiQTtdQUcrPTViNfbqHsT/FSI5sBxzT015aEiLiafEjpIv2I0Z2wP0TUzL2 JZIg== X-Gm-Message-State: AGRZ1gKNWl0Sr2oQJ30jrkFRBTUqeQvjqc5qkYHILytutQ4L9kRVRC2F lrXkZYApARjBh6eXh2CDKbRLmA== X-Received: by 2002:a19:41c4:: with SMTP id o187mr1719486lfa.32.1540899393326; Tue, 30 Oct 2018 04:36:33 -0700 (PDT) Received: from localhost (c-732171d5.07-21-73746f28.bbcust.telenor.se. [213.113.33.115]) by smtp.gmail.com with ESMTPSA id l67-v6sm3776781lfg.45.2018.10.30.04.36.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 04:36:32 -0700 (PDT) From: Anders Roxell To: linux@armlinux.org.uk, gregkh@linuxfoundation.org, akpm@linux-foundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, tj@kernel.org, Anders Roxell , Arnd Bergmann Subject: [PATCH v2 2/2] writeback: don't decrement wb->refcnt if !wb->bdi Date: Tue, 30 Oct 2018 12:35:45 +0100 Message-Id: <20181030113545.30999-2-anders.roxell@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181030113545.30999-1-anders.roxell@linaro.org> References: <20181030113545.30999-1-anders.roxell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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