Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3058794imu; Mon, 19 Nov 2018 10:01:24 -0800 (PST) X-Google-Smtp-Source: AJdET5fIOll+nvQ0LS+feNjmJ/WaU5iC8QgE2IL+idpPP5nml3VBdF95QXbBsd6VQbYfrJ79iiF1 X-Received: by 2002:a62:7687:: with SMTP id r129mr23746241pfc.17.1542650484641; Mon, 19 Nov 2018 10:01:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542650484; cv=none; d=google.com; s=arc-20160816; b=tVtjeUzgnAMBbrM8JnsYMgyOQrDShARRzaNGfz6tT/f4xn2x9Wq3MkCgQWcajs3wVm bcxrbtTf3tKLgynBp+6dI4ud9/OGx/heej4QGcjSscdOFpnO8DhAwXZFNhDnS2yQ1YiN 17cRnlkW9x1i/5dowa/UGJAZmericTxALgApxLvrbCh1EH5r8jwJyJU2h+SE5Bog7GHI i6yrTUeMrUnoLE1EyCDr3Ga9M3laquXF2RVwdG2d7oXY2bvMSp4+eZQ3h5bIToH7z20e 6As1oquEDYMva0bcfGst1GXnf1eVoSqVzNGcpv5jdpNQaEZ7BfMki6oxHenCZZGAUGaM NM9g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cBY+8MCYl7Pt2u4fgIp4uUDblUGYip587r7PaUkTkfw=; b=fHhP1bGqOiWb2scmIb38u+eb8uCB3vrhmLcZBZr1TG4pIJb4H1uDOEkvmJbarU6Cgx FSDbvhVqcRsKGTkE6N2Xfj+HHP4FC2m4UhTZ9PzDH25b6NDXOReppE16QeU10AVyjvi6 XdFZc/keL5lC8UeSOm/svVf2yba0HoupeIv9TucVnXx9UQUIAnDSBBPTfjMtGm2UvnaD RHpgLDcLc3Tk8/GNhCaJJmfnTVTyEDWiNimGh6KZMxUOFA04vU15DEBBHHEv03emydiM n1/cVH7pouUI/ZzckoHzUzrpZcN4cB2XJ9/sPqtdpZiN5KYIKVzIeiBgsdTOKdZG/nYJ ODhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vdQLWKLr; 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 j66-v6si30376095pfb.284.2018.11.19.10.01.05; Mon, 19 Nov 2018 10:01:24 -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; dkim=pass header.i=@kernel.org header.s=default header.b=vdQLWKLr; 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 S1732013AbeKTDA5 (ORCPT + 99 others); Mon, 19 Nov 2018 22:00:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:60880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730931AbeKTDAz (ORCPT ); Mon, 19 Nov 2018 22:00:55 -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 684D621479; Mon, 19 Nov 2018 16:36:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645406; bh=xaoyrTsrv3/VD4kZLWqR8sYKi93iI/jLaNUfG8K1wbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vdQLWKLrUZu+P90x14q8Zfr3ZV02RmXp2016hP7xRlI+fhLYSp4QhFgR+HKLgZPEP lXnJLfyjHv2b5GB9vlx/Ulm/kAqLTW4/DO8lFgw/gOZaVnfRzHCJ3vLgHe5Wor7GUX 24x4X5UrNCL9yTUXkU/q4m84EN+FZTKXQ6bgABOU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wengang Wang , Junxiao Bi , Changwei Ge , Joseph Qi , Mark Fasheh , Joel Becker , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 102/205] ocfs2: free up write context when direct IO failed Date: Mon, 19 Nov 2018 17:26:49 +0100 Message-Id: <20181119162633.496649826@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wengang Wang commit 5040f8df56fb90c7919f1c9b0b6e54c843437456 upstream. The write context should also be freed even when direct IO failed. Otherwise a memory leak is introduced and entries remain in oi->ip_unwritten_list causing the following BUG later in unlink path: ERROR: bug expression: !list_empty(&oi->ip_unwritten_list) ERROR: Clear inode of 215043, inode has unwritten extents ... Call Trace: ? __set_current_blocked+0x42/0x68 ocfs2_evict_inode+0x91/0x6a0 [ocfs2] ? bit_waitqueue+0x40/0x33 evict+0xdb/0x1af iput+0x1a2/0x1f7 do_unlinkat+0x194/0x28f SyS_unlinkat+0x1b/0x2f do_syscall_64+0x79/0x1ae entry_SYSCALL_64_after_hwframe+0x151/0x0 This patch also logs, with frequency limit, direct IO failures. Link: http://lkml.kernel.org/r/20181102170632.25921-1-wen.gang.wang@oracle.com Signed-off-by: Wengang Wang Reviewed-by: Junxiao Bi Reviewed-by: Changwei Ge Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/aops.c | 12 ++++++++++-- fs/ocfs2/cluster/masklog.h | 9 +++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -2412,8 +2412,16 @@ static int ocfs2_dio_end_io(struct kiocb /* this io's submitter should not have unlocked this before we could */ BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); - if (bytes > 0 && private) - ret = ocfs2_dio_end_io_write(inode, private, offset, bytes); + if (bytes <= 0) + mlog_ratelimited(ML_ERROR, "Direct IO failed, bytes = %lld", + (long long)bytes); + if (private) { + if (bytes > 0) + ret = ocfs2_dio_end_io_write(inode, private, offset, + bytes); + else + ocfs2_dio_free_write_ctx(inode, private); + } ocfs2_iocb_clear_rw_locked(iocb); --- a/fs/ocfs2/cluster/masklog.h +++ b/fs/ocfs2/cluster/masklog.h @@ -178,6 +178,15 @@ do { \ ##__VA_ARGS__); \ } while (0) +#define mlog_ratelimited(mask, fmt, ...) \ +do { \ + static DEFINE_RATELIMIT_STATE(_rs, \ + DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + if (__ratelimit(&_rs)) \ + mlog(mask, fmt, ##__VA_ARGS__); \ +} while (0) + #define mlog_errno(st) ({ \ int _st = (st); \ if (_st != -ERESTARTSYS && _st != -EINTR && \