From patchwork Tue Nov 22 15:11:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9441347 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C4379600BA for ; Tue, 22 Nov 2016 15:11:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3B65284C2 for ; Tue, 22 Nov 2016 15:11:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6F2328597; Tue, 22 Nov 2016 15:11:39 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCBDC284C2 for ; Tue, 22 Nov 2016 15:11:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755456AbcKVPLh (ORCPT ); Tue, 22 Nov 2016 10:11:37 -0500 Received: from mail-pf0-f181.google.com ([209.85.192.181]:35509 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753170AbcKVPLg (ORCPT ); Tue, 22 Nov 2016 10:11:36 -0500 Received: by mail-pf0-f181.google.com with SMTP id i88so4704623pfk.2 for ; Tue, 22 Nov 2016 07:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=5/4cSoUQ3xGceZqjhUNG0PSgUVH/8vRL2puX+bBOjNM=; b=g0CqPp/QZDGy+w1CcwJ7B4RlDtjv6W++ghRPDdOGel5TX33i7HfRaOr3aAMbDASSlA TZVqecU4toZTVafnuL0AsKMpPEczaWzRVoWxT6TErSzCICLIpFYcDZ6fzGOWQdOowuJD TVIJj/SS3hlbg3arBTMwEb6CT+M4cGS6YTA+VPI4Qvm+0ZQGNz7wy0um3z4SXu66nUU4 Vk+BiincFunl6waCV2qLqO0//elfXbt+Yjn+L0cw6wOIvVzIFTIVIP2JNJu3Bc3q+but MJHetdG5NWK1GPykXZOrhrg10TNEZJKkrGq9ScbSNB38YhTAlWJCyYBnhq6vbqEGZCBP drWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=5/4cSoUQ3xGceZqjhUNG0PSgUVH/8vRL2puX+bBOjNM=; b=S2iJPmrkU410PXA80S+o9B+mVcNfbU+PR7p/8IMxF6WBwJpUZqIe97cP/ErtCIVxSX xgilPhAql51ze0ZCzMmFL5qmVm8mDd490K0lRCvlZc1aEReAhULuj9Pleb7xU9YDPyCa Zxqc2fX0YUiJJQauLPgWLeRXD9Y2rqur0i0qcltecFpY+bBpsqxSNMr/qT20m14QJX5d Cbw6aOKJ3xFwZwyO6xRfLfilOkj0Y5yKrlRe5GmUQvjMDqCGX73RVJNhZUqpPCqffSxc +WmkQjRLoqHzcuiNPb+E4NckaFNOAWYNHv4vin68YPuLrZanJ4dljUGc+/l97AzCzWM0 wTzA== X-Gm-Message-State: AKaTC00QaFS59PIZCMoDj7PSIJYslyYtapKRVKumQT7uBMktVcKLqblU1ezlv3ElqXnZ9A== X-Received: by 10.99.127.16 with SMTP id a16mr44907549pgd.27.1479827495202; Tue, 22 Nov 2016 07:11:35 -0800 (PST) Received: from ?IPv6:2620:10d:c081:1103:93ec:cd5a:c00e:84a3? ([2620:10d:c090:180::7531]) by smtp.gmail.com with ESMTPSA id r74sm46003076pfl.79.2016.11.22.07.11.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Nov 2016 07:11:34 -0800 (PST) Subject: Re: [PATCH 1/1] block_dev: Fixed direct I/O bio sector calculation To: Damien Le Moal References: <1479796729-25517-1-git-send-email-damien.lemoal@wdc.com> Cc: linux-block@vger.kernel.org, Christoph Hellwig From: Jens Axboe Message-ID: Date: Tue, 22 Nov 2016 08:11:33 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1479796729-25517-1-git-send-email-damien.lemoal@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 11/21/2016 11:38 PM, Damien Le Moal wrote: > A direct I/O alignment must be always checked against the device blocks size, > but the I/O offset (bio->bi_iter.bi_sector must always use 512B sector unit, and > not the actual logical block size. Oops indeed, that's not great... Added for 4.10. While there, we can then also get rid of the blkbits variable, and (more importantly), the call to blksize_bits(): bool should_dirty = false; @@ -211,7 +210,8 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, blk_qc_t qc; int i; - if ((pos | iov_iter_alignment(iter)) & ((1 << blkbits) - 1)) + if ((pos | iov_iter_alignment(iter)) & + (bdev_logical_block_size(bdev) - 1)) return -EINVAL; if (nr_pages <= DIO_INLINE_BIO_VECS) @@ -331,7 +331,6 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) struct file *file = iocb->ki_filp; struct inode *inode = bdev_file_inode(file); struct block_device *bdev = I_BDEV(inode); - unsigned blkbits = blksize_bits(bdev_logical_block_size(bdev)); struct blkdev_dio *dio; struct bio *bio; bool is_read = (iov_iter_rw(iter) == READ); @@ -339,7 +338,8 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) blk_qc_t qc = BLK_QC_T_NONE; int ret; - if ((pos | iov_iter_alignment(iter)) & ((1 << blkbits) - 1)) + if ((pos | iov_iter_alignment(iter)) & + (bdev_logical_block_size(bdev) - 1)) return -EINVAL; bio = bio_alloc_bioset(GFP_KERNEL, nr_pages, blkdev_dio_pool); diff --git a/fs/block_dev.c b/fs/block_dev.c index e49fb797e447..b0c790a19db9 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -202,7 +202,6 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, { struct file *file = iocb->ki_filp; struct block_device *bdev = I_BDEV(bdev_file_inode(file)); - unsigned blkbits = blksize_bits(bdev_logical_block_size(bdev)); struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *vecs, *bvec; loff_t pos = iocb->ki_pos;