Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3306400imu; Sun, 11 Nov 2018 12:02:45 -0800 (PST) X-Google-Smtp-Source: AJdET5fRtvZ/FceRNPLluHd+sX4vRmQIwld5WA0tnlduHL72vZ57SWoxQe8GuKOilgycZBmFqjNL X-Received: by 2002:a17:902:6848:: with SMTP id f8mr994897pln.300.1541966565719; Sun, 11 Nov 2018 12:02:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541966565; cv=none; d=google.com; s=arc-20160816; b=xaYz4NDKsU8MFAxMAFWVeZunU0cOsv8tohvt1chUQIDaUhvCMTYbTelijHl1zkgt5B wi3hUUsdf8HjtS9MmO0b1/R79ENFhc/bvsT2ohXqX4Ki0nSa2S5L3gjGq3ttMycoX1wW xVwxTy1heFUldEdm8+mVqwZjS+jTGGIOJeRBeX3bwtTnAxa0U+YG4wKe24bNxQLOwjIb c1jSa9oZeCeVm+xitH9l5LUM/MpKCWm05JTyIRE1SbEJy+m705znO90wWgSdbEzzoAsu iUEDSRy7xNkSxeo235LmdLd3FIc1gUUJpFJzv3l+oFpgSRwUf3xpsQ5B0OooGg1Tl5nh 3ZYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=aArW4ovP0WtQzArnt10UgtaRfD7KM8dyhbK9UQQJKuI=; b=dsy1uW9WTKE0rsbm/PFeQ6kpsr0Yqi2S5MkymQQzF7gxeGgU63jjEuvLAB8e5qQcKV wMpwTI/YAr3SAkvQxE0QGtzH0FBtHPgEui7R2T64rfOqHsE8cEYBmvi8uyoeX/33vVNv /dIFARS2K8NQYpykDiN8pEV2HN04t0Vy9uB+mdnPJGZhJbcOlZZbssbNXYd6AG6+fwTm 9lBWdhLPzPXydO0QOL2V2O/sdDt+YYgfJ37/KxppCceilWakTX8kXcJBBzXWICzIGn5b d7v9W47ehAAW5uboEJFzyCTzHezQJefxY4mcd4uYNxYFtvr8Huq7NwGUAg5RqpxEnLIH Nj7w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si15646541plw.81.2018.11.11.12.02.30; Sun, 11 Nov 2018 12:02:45 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730958AbeKLFte (ORCPT + 99 others); Mon, 12 Nov 2018 00:49:34 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:51288 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730811AbeKLFse (ORCPT ); Mon, 12 Nov 2018 00:48:34 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsv-0000oU-15; Sun, 11 Nov 2018 19:59:05 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsV-0001f0-4q; Sun, 11 Nov 2018 19:58:39 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Theodore Ts'o" , "Pranay Kr. Srivastava" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 216/366] ext4: Fix WARN_ON_ONCE in ext4_commit_super() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: "Pranay Kr. Srivastava" commit 4743f83990614af6adb09ea7aa3c37b78c4031ab upstream. If there are racing calls to ext4_commit_super() it's possible for another writeback of the superblock to result in the buffer being marked with an error after we check if the buffer is marked as having a write error and the buffer up-to-date flag is set again. If that happens mark_buffer_dirty() can end up throwing a WARN_ON_ONCE. Fix this by moving this check to write before we call write_buffer_dirty(), and keeping the buffer locked during this whole sequence. Signed-off-by: Pranay Kr. Srivastava Signed-off-by: Theodore Ts'o Signed-off-by: Ben Hutchings --- fs/ext4/super.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4653,20 +4653,6 @@ static int ext4_commit_super(struct supe if (!sbh || block_device_ejected(sb)) return error; - if (buffer_write_io_error(sbh)) { - /* - * Oh, dear. A previous attempt to write the - * superblock failed. This could happen because the - * USB device was yanked out. Or it could happen to - * be a transient write error and maybe the block will - * be remapped. Nothing we can do but to retry the - * write and hope for the best. - */ - ext4_msg(sb, KERN_ERR, "previous I/O error to " - "superblock detected"); - clear_buffer_write_io_error(sbh); - set_buffer_uptodate(sbh); - } /* * If the file system is mounted read-only, don't update the * superblock write time. This avoids updating the superblock @@ -4695,7 +4681,23 @@ static int ext4_commit_super(struct supe &EXT4_SB(sb)->s_freeinodes_counter)); BUFFER_TRACE(sbh, "marking dirty"); ext4_superblock_csum_set(sb); + lock_buffer(sbh); + if (buffer_write_io_error(sbh)) { + /* + * Oh, dear. A previous attempt to write the + * superblock failed. This could happen because the + * USB device was yanked out. Or it could happen to + * be a transient write error and maybe the block will + * be remapped. Nothing we can do but to retry the + * write and hope for the best. + */ + ext4_msg(sb, KERN_ERR, "previous I/O error to " + "superblock detected"); + clear_buffer_write_io_error(sbh); + set_buffer_uptodate(sbh); + } mark_buffer_dirty(sbh); + unlock_buffer(sbh); if (sync) { error = sync_dirty_buffer(sbh); if (error)