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: 10660721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB5AC1932 for ; Tue, 30 Oct 2018 11:36:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8B3128501 for ; Tue, 30 Oct 2018 11:36:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C0EA299EE; Tue, 30 Oct 2018 11:36:37 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30FFA28501 for ; Tue, 30 Oct 2018 11:36:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FCE66B0494; Tue, 30 Oct 2018 07:36:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5AD656B0498; Tue, 30 Oct 2018 07:36:36 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49E3F6B0499; Tue, 30 Oct 2018 07:36:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by kanga.kvack.org (Postfix) with ESMTP id D1B566B0494 for ; Tue, 30 Oct 2018 07:36:35 -0400 (EDT) Received: by mail-lj1-f197.google.com with SMTP id e11-v6so4201741lji.23 for ; Tue, 30 Oct 2018 04:36:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0c4qq4Ww0v5TJSITOLozxcLN7WvXMS6Pv+NS1rx0eYU=; b=jqcTT++PD2it/9tRqTmuCWTrAXlDiRNQkkHoFcxQK5pTGG+sy1no+AGbeBA44rvJsg semOz9RDdBW/l5Isdr4+wPuG+L1wE+n7i0kqUrk3Ib6xhfzAfCeP/puXYqfGsn37eXeI z2I1mZ+TKWt1PseZWcxUfj7i5x2LgHM+FQ+4Cz3m1GyyWkjVhBuk9ZjvsHelYhvW7k2v uO3iTBVm8yWPzyWoj3YzZkA4DMd244B5PD8l53pdYGah6sElmcKGhm76yknlUJV4KCu5 Q4QKZBsR3q39db9eoIdRdS9ZIWdugd30/gfMa2P1at0pkmnyCZv8oPZGmpPSGveGrXWA 4EGw== X-Gm-Message-State: AGRZ1gIFf33F9h75k2BmspcGBDCfzlbVW+o0/hvnyxfMIUQe7W9hBxel S63AUzOqDfAXaLT3G+/eObJblrresreddEMhMRimw0wSB/47gaz/98SKBo7JMUmxFx3sUDdTt3A EjRyRaQalBAeiFP7layzkY16I3ElCvxyK1CsxU42AgVbm4BtGbw74e8NPc8GJWZjGr8G9uGQAV6 dWDLW04ahE5HQvdA4DGdfz1CxMotrTbMoy856C3M6tSwjKvSgJuhZweRjTFowes5fuhG5v8i2Jp LvPOU6OO5EiYM3+0rbxQyMIn4bBM4AHcLTaw9zPF+k7EOy4dNtKgcdMII8Ak+XY7EJaGluX7Wn7 /QpN9tsg1Of5DsRvDX4DK9FIylbjtpgRLYjS7JmsZTPSCpGGvWbmJV1ixSiibQlqrbx3iaMp8vK 8 X-Received: by 2002:a2e:2019:: with SMTP id g25-v6mr4056521ljg.20.1540899395137; Tue, 30 Oct 2018 04:36:35 -0700 (PDT) X-Received: by 2002:a2e:2019:: with SMTP id g25-v6mr4056470ljg.20.1540899393890; Tue, 30 Oct 2018 04:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540899393; cv=none; d=google.com; s=arc-20160816; b=zJX3tCkQ7eQa4bPaDSWdT5RXo77q4QOKSHgqvSOsFXupxktcQJpCaw2WZPO4WKjjgN DByHTS1HhHnFAd2eQ4ZuwZgsPYa8TzY1OcaOwrvQhDzPV6R3z7bkfgNt0GBIjiUYo+Vu NGbc6aUOZKKspbq76M+OMN77yZxfarrkmavkPtUzT3cKQzwG2lUeflhyf2WfKes7LkKY spvgYq6e3FMLp+zg4A7jqB3Aoi9uXxBstXokLPlW4Jj0sLfPNcUEeyurQsouAPRkskyM 9K9EOlenok/RzjpGLFqCtWbfZoZgqPLm9pF3WuhYMaMKNRZX4Jjhd2NnTQqmbP2ycWg7 8nmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=0c4qq4Ww0v5TJSITOLozxcLN7WvXMS6Pv+NS1rx0eYU=; b=jSvEQzjKF7/2ZcycQnBsOlP2Z+ctwAdbHi6qh1RTMA+uaoNH9ir0jwWF9J5Wlm0Yui imwkMI6p+zGHy1S343kIIJM9wgS+DYCsLgqHSTnFVg0jZ9xidCfF9lsIjVLNrPc6kbeA jxcPW6UeqVWo+ViFbpdTL/3vac+Z3N4CHIdwIVNlITwOpdV+dePFyu5b/JZ9u3A+UYFJ znXFLanXjjnajcsk4AtNt5KB1BSdFM70K1BX7nwQBolurpg1E1Vz6z1y7D0IxxNkp7fJ +nOpQIl6+9g+LzjP8YAGj30P88aIzIWpkg1atmUHZIt5m/VELUMgl40tmy3WaNIZq6Rg 7TVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gOwgddOR; spf=pass (google.com: domain of anders.roxell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=anders.roxell@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y206sor3327092lfa.42.2018.10.30.04.36.33 for (Google Transport Security); Tue, 30 Oct 2018 04:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of anders.roxell@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gOwgddOR; spf=pass (google.com: domain of anders.roxell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=anders.roxell@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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-Smtp-Source: AJdET5cBHlupzI8DFEfRW+LDvxxFFzuGpyilXSNopOL7zP/54j9IfzjkvZ65UOZv4HAurPUmo0LM8A== 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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); }