From patchwork Tue Oct 30 11:35:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Roxell X-Patchwork-Id: 149739 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5333643ljp; Tue, 30 Oct 2018 04:36:36 -0700 (PDT) X-Google-Smtp-Source: AJdET5e3pKUt+Lp5WVZdYIS8B3EuGIZWJg8oOg4ygwZjAHmyCURnE99LEM9dcLomocbER4sbUyhq X-Received: by 2002:a63:c00b:: with SMTP id h11-v6mr17840162pgg.159.1540899396240; Tue, 30 Oct 2018 04:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540899396; cv=none; d=google.com; s=arc-20160816; b=vnDhbmhHfUVZh2WqjOYW1XDBrdchb0Q8WKrT58r1FYOYgtslmq1Xm4YbyvAbSraRUT ekY0axaWy5/d3KKw1EGlFB4Xz2eqhiBMTFzyAfg3XwZidXlNXpPzHdonb407IwoEF/sp PP0b13Zi2ZX/8mUNaKwcMumpvY+5z0ZZIq7Knc1RqAMCfIQbP8w6LfzDwssqX7CYnBIX 6IM2u9lPboHsKsp5lCWblIGglBGM7gsIpQRCiHxP2akS8UXBfR6I6lEBRhjMNndnaTnI WQrMWBqHietstTARfyvzrczzpRzt8fbrFL9bKY6UaRd2t8RbMEzOfqdp6jbSj+yCJqRq 4ACA== 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=b8xfyOKQ0Sxyaa1upVjftrn91c2HxZHnFTj4WCXWSrcJmw5FjsPu65TuwtbOUyrNGb NBcjKYdt8goCAhLyqpfCu/gGEsmbYp5RLpWXHQ2TUN/fttgB9PyfL8rM/PB8S6ujZozB 6GUGBnyfcJJGLPaVjLKku4FhJ2jiq3YORMgVjydNcVf91YQ6aLD9NANHfTD8u2kbNJzs sEhY6EXGkF0IbHj6zYPeLQMC9uv2ixF+El8FE9UwgiChbGq6iKIjL+i/13L3C6+V25ij cCJSyuatcylnJxal1bsMPzQKxM7JqaMa36NhZwxH9Vx/QdyJpUlYrBdHrZhOsOFjmckT C8MQ== 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-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-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 q9-v6si17091699plr.197.2018.10.30.04.36.36; Tue, 30 Oct 2018 04:36:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-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-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-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 S1727436AbeJ3U3m (ORCPT + 2 others); Tue, 30 Oct 2018 16:29:42 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:41624 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726731AbeJ3U3m (ORCPT ); Tue, 30 Oct 2018 16:29:42 -0400 Received: by mail-lf1-f66.google.com with SMTP id c16so8568061lfj.8 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=jRd7KLrzNRuSLUZZt5NDQ0fh+SZjEbeL28ovqA1BwkiCCBN9qeh/8kRjGq0OpMccJY BeJ6cJxm511OXMd1DvwvhxLtorD1by4qGg6C1jMaPW+LdWazUDc+b02mrWbM/v96tCaR 6zHisFVHJzkRsGxMoHx23Z1yQ8hUACWERY30S687zznEPCQYKZIpsmc9vny1M5G/xsam iYITs5ZFhraf1KBnga4XBHxsCTwjyBRIaOILUmBiHMwVYfW2LE2JrIE218J6fX8l79e2 A0HoZCW6TLW5AfGvgDLw1wa8QKZaPQ17jRTcKte+kiandaAdx+PM5qWAma3/TNfWAniR wztg== X-Gm-Message-State: AGRZ1gJyZ/tBvfnDg1X8tBmMf3YZIXAN/s/XKo+OwJ6EoOMrwDxq2p/l OVJaoCSnnn94ih1OvcKtdfaaBQ== 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 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@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(+) -- 2.19.1 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); }