Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2283182imb; Mon, 4 Mar 2019 00:44:28 -0800 (PST) X-Google-Smtp-Source: APXvYqx0PIGImdkn1Wn9XsQdkVhisjcAhCVyaW+n+oCKG1vHbmXWrARLEqjHvsL6OFvlVM3r4Wbr X-Received: by 2002:a17:902:8643:: with SMTP id y3mr19011485plt.195.1551689068576; Mon, 04 Mar 2019 00:44:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551689068; cv=none; d=google.com; s=arc-20160816; b=kIzQgXFhLqnpz8FGUiqobQl+3L6MDEuB1ngdzWFZ00NRn1fTtVN1N36RRImzNFH4Al qb9HfOF3fxQERo4Maa7k4XrE7qZ2Ry0rjukq1bpMjZXcYA41LEBhy2e1Ie9XDISy2QRk cCVOJuF3fK5xS7fBZMKWxlqqy/mh2Jw9gmxtxA/bVCnMihhvZhWNLYx/XSLWUhNPLaw7 8ENWDhsKzCWxhqpOvOYl3ghXh1zaIYwhyz25o4QXAeMG1j69pX/ppruu+nGElEKc5GwV F+aeOJKeeQ6brH6o7HCuOftTEmuOTcngHzIh9iHvAttI+7AckdykKNwNIsdiDJoQEm9E IRHw== 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=vQWUAnz121RlWueuC4pcwiZqxEQo3mY/K1vCtPEEQJM=; b=Ll2LwMDYAHuAXZJeNr0+K9U5+pKFVAtuqT1t9u+UhGtB8wisA6DiROmtCjt7iHBYuj GaQGhkYniHfB7RClkYvehUeutANVcj00acM7VQwG3c3YS06CN+Uu7OYpkJZ0qIig7rY1 e12zaOzUK2nGQcqzXe94px8PVuRJYR1ydPs9bG7liZnFnFP1Nieyx68aMgBb9J3LG3tp 0Q4LDnsYppPd1KtTStYT7MD7bNi1F35ocMZA1ekYlgvYr0lwG8Mso9QOZMrmyKqXl5Fd vwY7+EaPzxxph7SCnHylPyYriLTMSrXDmx6S3R1NYu7w55O9/UV1NReq5OxTTlXzJmAN /jnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EBsmFjiS; 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 23si4672631pgc.220.2019.03.04.00.44.12; Mon, 04 Mar 2019 00:44:28 -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=EBsmFjiS; 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 S1727296AbfCDI3s (ORCPT + 99 others); Mon, 4 Mar 2019 03:29:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:56886 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726029AbfCDI3r (ORCPT ); Mon, 4 Mar 2019 03:29:47 -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 BF1EB20823; Mon, 4 Mar 2019 08:29:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551688186; bh=ETA4v65EPdId099ZeVbIDMPR3Dcpx5Xmm0o/j+HoEzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EBsmFjiSrGYuHgd++LEXZ17TngRg56u2jtthCMM64l8n7DUYFaTMVAPPvODnMobVH ncVvb/VMyGV8qrXGZ+m+w1dVz2add0LmlDlEAgE1Z82GhHenYqLceptJ4b0WL3dXdS bJXNZ2nS++TqOH1ptMSYlAmBQQyk9tfV2J9NtTII= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Moyer , Jan Kara , "=?UTF-8?q?Ernesto=20A . =20Fern=C3=A1ndez?=" , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 44/78] direct-io: allow direct writes to empty inodes Date: Mon, 4 Mar 2019 09:22:27 +0100 Message-Id: <20190304081627.455745386@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081625.508788074@linuxfoundation.org> References: <20190304081625.508788074@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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. ------------------ [ Upstream commit 8b9433eb4de3c26a9226c981c283f9f4896ae030 ] On a DIO_SKIP_HOLES filesystem, the ->get_block() method is currently not allowed to create blocks for an empty inode. This confusion comes from trying to bit shift a negative number, so check the size of the inode first. The problem is most visible for hfsplus, because the fallback to buffered I/O doesn't happen and the write fails with EIO. This is in part the fault of the module, because it gives a wrong return value on ->get_block(); that will be fixed in a separate patch. Reviewed-by: Jeff Moyer Reviewed-by: Jan Kara Signed-off-by: Ernesto A. Fernández Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/direct-io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index 1991460360930..1abb7634b2d58 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -679,6 +679,7 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, unsigned long fs_count; /* Number of filesystem-sized blocks */ int create; unsigned int i_blkbits = sdio->blkbits + sdio->blkfactor; + loff_t i_size; /* * If there was a memory error and we've overwritten all the @@ -708,8 +709,8 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, */ create = dio->op == REQ_OP_WRITE; if (dio->flags & DIO_SKIP_HOLES) { - if (fs_startblk <= ((i_size_read(dio->inode) - 1) >> - i_blkbits)) + i_size = i_size_read(dio->inode); + if (i_size && fs_startblk <= (i_size - 1) >> i_blkbits) create = 0; } -- 2.19.1