From: Dan Carpenter <dan.carpenter@oracle.com> To: kbuild@lists.01.org Subject: Re: [PATCH 03/15] iomap: Allow filesystem to call iomap_dio_complete without i_rwsem Date: Tue, 22 Sep 2020 12:24:37 +0300 [thread overview] Message-ID: <20200922092437.GE4282@kadam> (raw) In-Reply-To: <20200921144353.31319-4-rgoldwyn@suse.de> [-- Attachment #1: Type: text/plain, Size: 14901 bytes --] Hi Goldwyn, url: https://github.com/0day-ci/linux/commits/Goldwyn-Rodrigues/BTRFS-DIO-inode-locking-D_SYNC-fix/20200921-224649 base: https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next config: x86_64-randconfig-m001-20200920 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> smatch warnings: fs/iomap/direct-io.c:582 __iomap_dio_rw() warn: passing zero to 'ERR_PTR' # https://github.com/0day-ci/linux/commit/072d65c9ae6669b5dd8ae4d8cccc49f2046afeb4 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Goldwyn-Rodrigues/BTRFS-DIO-inode-locking-D_SYNC-fix/20200921-224649 git checkout 072d65c9ae6669b5dd8ae4d8cccc49f2046afeb4 vim +/ERR_PTR +582 fs/iomap/direct-io.c 072d65c9ae6669 Christoph Hellwig 2020-09-21 410 struct iomap_dio * 072d65c9ae6669 Christoph Hellwig 2020-09-21 411 __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, 13ef954445df4f Jan Kara 2019-10-15 412 const struct iomap_ops *ops, const struct iomap_dio_ops *dops, 13ef954445df4f Jan Kara 2019-10-15 413 bool wait_for_completion) db074436f42196 Darrick J. Wong 2019-07-15 414 { db074436f42196 Darrick J. Wong 2019-07-15 415 struct address_space *mapping = iocb->ki_filp->f_mapping; db074436f42196 Darrick J. Wong 2019-07-15 416 struct inode *inode = file_inode(iocb->ki_filp); db074436f42196 Darrick J. Wong 2019-07-15 417 size_t count = iov_iter_count(iter); 88cfd30e188fcf Johannes Thumshirn 2019-11-26 418 loff_t pos = iocb->ki_pos; db074436f42196 Darrick J. Wong 2019-07-15 419 loff_t end = iocb->ki_pos + count - 1, ret = 0; db074436f42196 Darrick J. Wong 2019-07-15 420 unsigned int flags = IOMAP_DIRECT; db074436f42196 Darrick J. Wong 2019-07-15 421 struct blk_plug plug; db074436f42196 Darrick J. Wong 2019-07-15 422 struct iomap_dio *dio; db074436f42196 Darrick J. Wong 2019-07-15 423 db074436f42196 Darrick J. Wong 2019-07-15 424 if (!count) 072d65c9ae6669 Christoph Hellwig 2020-09-21 425 return NULL; db074436f42196 Darrick J. Wong 2019-07-15 426 13ef954445df4f Jan Kara 2019-10-15 427 if (WARN_ON(is_sync_kiocb(iocb) && !wait_for_completion)) 072d65c9ae6669 Christoph Hellwig 2020-09-21 428 return ERR_PTR(-EIO); 13ef954445df4f Jan Kara 2019-10-15 429 db074436f42196 Darrick J. Wong 2019-07-15 430 dio = kmalloc(sizeof(*dio), GFP_KERNEL); db074436f42196 Darrick J. Wong 2019-07-15 431 if (!dio) 072d65c9ae6669 Christoph Hellwig 2020-09-21 432 return ERR_PTR(-ENOMEM); db074436f42196 Darrick J. Wong 2019-07-15 433 db074436f42196 Darrick J. Wong 2019-07-15 434 dio->iocb = iocb; db074436f42196 Darrick J. Wong 2019-07-15 435 atomic_set(&dio->ref, 1); db074436f42196 Darrick J. Wong 2019-07-15 436 dio->size = 0; db074436f42196 Darrick J. Wong 2019-07-15 437 dio->i_size = i_size_read(inode); 838c4f3d7515ef Christoph Hellwig 2019-09-19 438 dio->dops = dops; db074436f42196 Darrick J. Wong 2019-07-15 439 dio->error = 0; db074436f42196 Darrick J. Wong 2019-07-15 440 dio->flags = 0; db074436f42196 Darrick J. Wong 2019-07-15 441 db074436f42196 Darrick J. Wong 2019-07-15 442 dio->submit.iter = iter; db074436f42196 Darrick J. Wong 2019-07-15 443 dio->submit.waiter = current; db074436f42196 Darrick J. Wong 2019-07-15 444 dio->submit.cookie = BLK_QC_T_NONE; db074436f42196 Darrick J. Wong 2019-07-15 445 dio->submit.last_queue = NULL; db074436f42196 Darrick J. Wong 2019-07-15 446 db074436f42196 Darrick J. Wong 2019-07-15 447 if (iov_iter_rw(iter) == READ) { db074436f42196 Darrick J. Wong 2019-07-15 448 if (pos >= dio->i_size) db074436f42196 Darrick J. Wong 2019-07-15 449 goto out_free_dio; ret needs to be set on this patch to prevent an Oops in the caller. db074436f42196 Darrick J. Wong 2019-07-15 450 a901004214994f Joseph Qi 2019-10-29 451 if (iter_is_iovec(iter)) db074436f42196 Darrick J. Wong 2019-07-15 452 dio->flags |= IOMAP_DIO_DIRTY; db074436f42196 Darrick J. Wong 2019-07-15 453 } else { db074436f42196 Darrick J. Wong 2019-07-15 454 flags |= IOMAP_WRITE; db074436f42196 Darrick J. Wong 2019-07-15 455 dio->flags |= IOMAP_DIO_WRITE; db074436f42196 Darrick J. Wong 2019-07-15 456 db074436f42196 Darrick J. Wong 2019-07-15 457 /* for data sync or sync, we need sync completion processing */ db074436f42196 Darrick J. Wong 2019-07-15 458 if (iocb->ki_flags & IOCB_DSYNC) db074436f42196 Darrick J. Wong 2019-07-15 459 dio->flags |= IOMAP_DIO_NEED_SYNC; db074436f42196 Darrick J. Wong 2019-07-15 460 db074436f42196 Darrick J. Wong 2019-07-15 461 /* db074436f42196 Darrick J. Wong 2019-07-15 462 * For datasync only writes, we optimistically try using FUA for db074436f42196 Darrick J. Wong 2019-07-15 463 * this IO. Any non-FUA write that occurs will clear this flag, db074436f42196 Darrick J. Wong 2019-07-15 464 * hence we know before completion whether a cache flush is db074436f42196 Darrick J. Wong 2019-07-15 465 * necessary. db074436f42196 Darrick J. Wong 2019-07-15 466 */ db074436f42196 Darrick J. Wong 2019-07-15 467 if ((iocb->ki_flags & (IOCB_DSYNC | IOCB_SYNC)) == IOCB_DSYNC) db074436f42196 Darrick J. Wong 2019-07-15 468 dio->flags |= IOMAP_DIO_WRITE_FUA; db074436f42196 Darrick J. Wong 2019-07-15 469 } db074436f42196 Darrick J. Wong 2019-07-15 470 db074436f42196 Darrick J. Wong 2019-07-15 471 if (iocb->ki_flags & IOCB_NOWAIT) { 88cfd30e188fcf Johannes Thumshirn 2019-11-26 472 if (filemap_range_has_page(mapping, pos, end)) { db074436f42196 Darrick J. Wong 2019-07-15 473 ret = -EAGAIN; db074436f42196 Darrick J. Wong 2019-07-15 474 goto out_free_dio; db074436f42196 Darrick J. Wong 2019-07-15 475 } db074436f42196 Darrick J. Wong 2019-07-15 476 flags |= IOMAP_NOWAIT; db074436f42196 Darrick J. Wong 2019-07-15 477 } db074436f42196 Darrick J. Wong 2019-07-15 478 88cfd30e188fcf Johannes Thumshirn 2019-11-26 479 ret = filemap_write_and_wait_range(mapping, pos, end); db074436f42196 Darrick J. Wong 2019-07-15 480 if (ret) db074436f42196 Darrick J. Wong 2019-07-15 481 goto out_free_dio; db074436f42196 Darrick J. Wong 2019-07-15 482 54752de928c400 Dave Chinner 2020-07-23 483 if (iov_iter_rw(iter) == WRITE) { db074436f42196 Darrick J. Wong 2019-07-15 484 /* 54752de928c400 Dave Chinner 2020-07-23 485 * Try to invalidate cache pages for the range we are writing. 60263d5889e6dc Christoph Hellwig 2020-07-23 486 * If this invalidation fails, let the caller fall back to 60263d5889e6dc Christoph Hellwig 2020-07-23 487 * buffered I/O. db074436f42196 Darrick J. Wong 2019-07-15 488 */ 54752de928c400 Dave Chinner 2020-07-23 489 if (invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, 60263d5889e6dc Christoph Hellwig 2020-07-23 490 end >> PAGE_SHIFT)) { 60263d5889e6dc Christoph Hellwig 2020-07-23 491 trace_iomap_dio_invalidate_fail(inode, pos, count); 60263d5889e6dc Christoph Hellwig 2020-07-23 492 ret = -ENOTBLK; 60263d5889e6dc Christoph Hellwig 2020-07-23 493 goto out_free_dio; 60263d5889e6dc Christoph Hellwig 2020-07-23 494 } db074436f42196 Darrick J. Wong 2019-07-15 495 54752de928c400 Dave Chinner 2020-07-23 496 if (!wait_for_completion && !inode->i_sb->s_dio_done_wq) { db074436f42196 Darrick J. Wong 2019-07-15 497 ret = sb_init_dio_done_wq(inode->i_sb); db074436f42196 Darrick J. Wong 2019-07-15 498 if (ret < 0) db074436f42196 Darrick J. Wong 2019-07-15 499 goto out_free_dio; db074436f42196 Darrick J. Wong 2019-07-15 500 } 54752de928c400 Dave Chinner 2020-07-23 501 } db074436f42196 Darrick J. Wong 2019-07-15 502 db074436f42196 Darrick J. Wong 2019-07-15 503 inode_dio_begin(inode); db074436f42196 Darrick J. Wong 2019-07-15 504 db074436f42196 Darrick J. Wong 2019-07-15 505 blk_start_plug(&plug); db074436f42196 Darrick J. Wong 2019-07-15 506 do { db074436f42196 Darrick J. Wong 2019-07-15 507 ret = iomap_apply(inode, pos, count, flags, ops, dio, db074436f42196 Darrick J. Wong 2019-07-15 508 iomap_dio_actor); db074436f42196 Darrick J. Wong 2019-07-15 509 if (ret <= 0) { db074436f42196 Darrick J. Wong 2019-07-15 510 /* magic error code to fall back to buffered I/O */ db074436f42196 Darrick J. Wong 2019-07-15 511 if (ret == -ENOTBLK) { db074436f42196 Darrick J. Wong 2019-07-15 512 wait_for_completion = true; db074436f42196 Darrick J. Wong 2019-07-15 513 ret = 0; db074436f42196 Darrick J. Wong 2019-07-15 514 } db074436f42196 Darrick J. Wong 2019-07-15 515 break; db074436f42196 Darrick J. Wong 2019-07-15 516 } db074436f42196 Darrick J. Wong 2019-07-15 517 pos += ret; db074436f42196 Darrick J. Wong 2019-07-15 518 419e9c38aa075e Jan Kara 2019-11-21 519 if (iov_iter_rw(iter) == READ && pos >= dio->i_size) { 419e9c38aa075e Jan Kara 2019-11-21 520 /* 419e9c38aa075e Jan Kara 2019-11-21 521 * We only report that we've read data up to i_size. 419e9c38aa075e Jan Kara 2019-11-21 522 * Revert iter to a state corresponding to that as 419e9c38aa075e Jan Kara 2019-11-21 523 * some callers (such as splice code) rely on it. 419e9c38aa075e Jan Kara 2019-11-21 524 */ 419e9c38aa075e Jan Kara 2019-11-21 525 iov_iter_revert(iter, pos - dio->i_size); db074436f42196 Darrick J. Wong 2019-07-15 526 break; 419e9c38aa075e Jan Kara 2019-11-21 527 } db074436f42196 Darrick J. Wong 2019-07-15 528 } while ((count = iov_iter_count(iter)) > 0); db074436f42196 Darrick J. Wong 2019-07-15 529 blk_finish_plug(&plug); db074436f42196 Darrick J. Wong 2019-07-15 530 db074436f42196 Darrick J. Wong 2019-07-15 531 if (ret < 0) db074436f42196 Darrick J. Wong 2019-07-15 532 iomap_dio_set_error(dio, ret); db074436f42196 Darrick J. Wong 2019-07-15 533 db074436f42196 Darrick J. Wong 2019-07-15 534 /* db074436f42196 Darrick J. Wong 2019-07-15 535 * If all the writes we issued were FUA, we don't need to flush the db074436f42196 Darrick J. Wong 2019-07-15 536 * cache on IO completion. Clear the sync flag for this case. db074436f42196 Darrick J. Wong 2019-07-15 537 */ db074436f42196 Darrick J. Wong 2019-07-15 538 if (dio->flags & IOMAP_DIO_WRITE_FUA) db074436f42196 Darrick J. Wong 2019-07-15 539 dio->flags &= ~IOMAP_DIO_NEED_SYNC; db074436f42196 Darrick J. Wong 2019-07-15 540 db074436f42196 Darrick J. Wong 2019-07-15 541 WRITE_ONCE(iocb->ki_cookie, dio->submit.cookie); db074436f42196 Darrick J. Wong 2019-07-15 542 WRITE_ONCE(iocb->private, dio->submit.last_queue); db074436f42196 Darrick J. Wong 2019-07-15 543 db074436f42196 Darrick J. Wong 2019-07-15 544 /* db074436f42196 Darrick J. Wong 2019-07-15 545 * We are about to drop our additional submission reference, which d9973ce2fe5bcd yangerkun 2020-03-18 546 * might be the last reference to the dio. There are three different d9973ce2fe5bcd yangerkun 2020-03-18 547 * ways we can progress here: db074436f42196 Darrick J. Wong 2019-07-15 548 * db074436f42196 Darrick J. Wong 2019-07-15 549 * (a) If this is the last reference we will always complete and free db074436f42196 Darrick J. Wong 2019-07-15 550 * the dio ourselves. db074436f42196 Darrick J. Wong 2019-07-15 551 * (b) If this is not the last reference, and we serve an asynchronous db074436f42196 Darrick J. Wong 2019-07-15 552 * iocb, we must never touch the dio after the decrement, the db074436f42196 Darrick J. Wong 2019-07-15 553 * I/O completion handler will complete and free it. db074436f42196 Darrick J. Wong 2019-07-15 554 * (c) If this is not the last reference, but we serve a synchronous db074436f42196 Darrick J. Wong 2019-07-15 555 * iocb, the I/O completion handler will wake us up on the drop db074436f42196 Darrick J. Wong 2019-07-15 556 * of the final reference, and we will complete and free it here db074436f42196 Darrick J. Wong 2019-07-15 557 * after we got woken by the I/O completion handler. db074436f42196 Darrick J. Wong 2019-07-15 558 */ db074436f42196 Darrick J. Wong 2019-07-15 559 dio->wait_for_completion = wait_for_completion; db074436f42196 Darrick J. Wong 2019-07-15 560 if (!atomic_dec_and_test(&dio->ref)) { db074436f42196 Darrick J. Wong 2019-07-15 561 if (!wait_for_completion) 072d65c9ae6669 Christoph Hellwig 2020-09-21 562 return ERR_PTR(-EIOCBQUEUED); db074436f42196 Darrick J. Wong 2019-07-15 563 db074436f42196 Darrick J. Wong 2019-07-15 564 for (;;) { db074436f42196 Darrick J. Wong 2019-07-15 565 set_current_state(TASK_UNINTERRUPTIBLE); db074436f42196 Darrick J. Wong 2019-07-15 566 if (!READ_ONCE(dio->submit.waiter)) db074436f42196 Darrick J. Wong 2019-07-15 567 break; db074436f42196 Darrick J. Wong 2019-07-15 568 db074436f42196 Darrick J. Wong 2019-07-15 569 if (!(iocb->ki_flags & IOCB_HIPRI) || db074436f42196 Darrick J. Wong 2019-07-15 570 !dio->submit.last_queue || db074436f42196 Darrick J. Wong 2019-07-15 571 !blk_poll(dio->submit.last_queue, db074436f42196 Darrick J. Wong 2019-07-15 572 dio->submit.cookie, true)) e6249cdd46e43a Ming Lei 2020-05-03 573 blk_io_schedule(); db074436f42196 Darrick J. Wong 2019-07-15 574 } db074436f42196 Darrick J. Wong 2019-07-15 575 __set_current_state(TASK_RUNNING); db074436f42196 Darrick J. Wong 2019-07-15 576 } db074436f42196 Darrick J. Wong 2019-07-15 577 072d65c9ae6669 Christoph Hellwig 2020-09-21 578 return dio; db074436f42196 Darrick J. Wong 2019-07-15 579 db074436f42196 Darrick J. Wong 2019-07-15 580 out_free_dio: db074436f42196 Darrick J. Wong 2019-07-15 581 kfree(dio); 072d65c9ae6669 Christoph Hellwig 2020-09-21 @582 return ERR_PTR(ret); 072d65c9ae6669 Christoph Hellwig 2020-09-21 583 } --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org [-- Attachment #2: config.gz --] [-- Type: application/gzip, Size: 39250 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com> To: kbuild-all@lists.01.org Subject: Re: [PATCH 03/15] iomap: Allow filesystem to call iomap_dio_complete without i_rwsem Date: Tue, 22 Sep 2020 12:24:37 +0300 [thread overview] Message-ID: <20200922092437.GE4282@kadam> (raw) In-Reply-To: <20200921144353.31319-4-rgoldwyn@suse.de> [-- Attachment #1: Type: text/plain, Size: 14901 bytes --] Hi Goldwyn, url: https://github.com/0day-ci/linux/commits/Goldwyn-Rodrigues/BTRFS-DIO-inode-locking-D_SYNC-fix/20200921-224649 base: https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next config: x86_64-randconfig-m001-20200920 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> smatch warnings: fs/iomap/direct-io.c:582 __iomap_dio_rw() warn: passing zero to 'ERR_PTR' # https://github.com/0day-ci/linux/commit/072d65c9ae6669b5dd8ae4d8cccc49f2046afeb4 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Goldwyn-Rodrigues/BTRFS-DIO-inode-locking-D_SYNC-fix/20200921-224649 git checkout 072d65c9ae6669b5dd8ae4d8cccc49f2046afeb4 vim +/ERR_PTR +582 fs/iomap/direct-io.c 072d65c9ae6669 Christoph Hellwig 2020-09-21 410 struct iomap_dio * 072d65c9ae6669 Christoph Hellwig 2020-09-21 411 __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, 13ef954445df4f Jan Kara 2019-10-15 412 const struct iomap_ops *ops, const struct iomap_dio_ops *dops, 13ef954445df4f Jan Kara 2019-10-15 413 bool wait_for_completion) db074436f42196 Darrick J. Wong 2019-07-15 414 { db074436f42196 Darrick J. Wong 2019-07-15 415 struct address_space *mapping = iocb->ki_filp->f_mapping; db074436f42196 Darrick J. Wong 2019-07-15 416 struct inode *inode = file_inode(iocb->ki_filp); db074436f42196 Darrick J. Wong 2019-07-15 417 size_t count = iov_iter_count(iter); 88cfd30e188fcf Johannes Thumshirn 2019-11-26 418 loff_t pos = iocb->ki_pos; db074436f42196 Darrick J. Wong 2019-07-15 419 loff_t end = iocb->ki_pos + count - 1, ret = 0; db074436f42196 Darrick J. Wong 2019-07-15 420 unsigned int flags = IOMAP_DIRECT; db074436f42196 Darrick J. Wong 2019-07-15 421 struct blk_plug plug; db074436f42196 Darrick J. Wong 2019-07-15 422 struct iomap_dio *dio; db074436f42196 Darrick J. Wong 2019-07-15 423 db074436f42196 Darrick J. Wong 2019-07-15 424 if (!count) 072d65c9ae6669 Christoph Hellwig 2020-09-21 425 return NULL; db074436f42196 Darrick J. Wong 2019-07-15 426 13ef954445df4f Jan Kara 2019-10-15 427 if (WARN_ON(is_sync_kiocb(iocb) && !wait_for_completion)) 072d65c9ae6669 Christoph Hellwig 2020-09-21 428 return ERR_PTR(-EIO); 13ef954445df4f Jan Kara 2019-10-15 429 db074436f42196 Darrick J. Wong 2019-07-15 430 dio = kmalloc(sizeof(*dio), GFP_KERNEL); db074436f42196 Darrick J. Wong 2019-07-15 431 if (!dio) 072d65c9ae6669 Christoph Hellwig 2020-09-21 432 return ERR_PTR(-ENOMEM); db074436f42196 Darrick J. Wong 2019-07-15 433 db074436f42196 Darrick J. Wong 2019-07-15 434 dio->iocb = iocb; db074436f42196 Darrick J. Wong 2019-07-15 435 atomic_set(&dio->ref, 1); db074436f42196 Darrick J. Wong 2019-07-15 436 dio->size = 0; db074436f42196 Darrick J. Wong 2019-07-15 437 dio->i_size = i_size_read(inode); 838c4f3d7515ef Christoph Hellwig 2019-09-19 438 dio->dops = dops; db074436f42196 Darrick J. Wong 2019-07-15 439 dio->error = 0; db074436f42196 Darrick J. Wong 2019-07-15 440 dio->flags = 0; db074436f42196 Darrick J. Wong 2019-07-15 441 db074436f42196 Darrick J. Wong 2019-07-15 442 dio->submit.iter = iter; db074436f42196 Darrick J. Wong 2019-07-15 443 dio->submit.waiter = current; db074436f42196 Darrick J. Wong 2019-07-15 444 dio->submit.cookie = BLK_QC_T_NONE; db074436f42196 Darrick J. Wong 2019-07-15 445 dio->submit.last_queue = NULL; db074436f42196 Darrick J. Wong 2019-07-15 446 db074436f42196 Darrick J. Wong 2019-07-15 447 if (iov_iter_rw(iter) == READ) { db074436f42196 Darrick J. Wong 2019-07-15 448 if (pos >= dio->i_size) db074436f42196 Darrick J. Wong 2019-07-15 449 goto out_free_dio; ret needs to be set on this patch to prevent an Oops in the caller. db074436f42196 Darrick J. Wong 2019-07-15 450 a901004214994f Joseph Qi 2019-10-29 451 if (iter_is_iovec(iter)) db074436f42196 Darrick J. Wong 2019-07-15 452 dio->flags |= IOMAP_DIO_DIRTY; db074436f42196 Darrick J. Wong 2019-07-15 453 } else { db074436f42196 Darrick J. Wong 2019-07-15 454 flags |= IOMAP_WRITE; db074436f42196 Darrick J. Wong 2019-07-15 455 dio->flags |= IOMAP_DIO_WRITE; db074436f42196 Darrick J. Wong 2019-07-15 456 db074436f42196 Darrick J. Wong 2019-07-15 457 /* for data sync or sync, we need sync completion processing */ db074436f42196 Darrick J. Wong 2019-07-15 458 if (iocb->ki_flags & IOCB_DSYNC) db074436f42196 Darrick J. Wong 2019-07-15 459 dio->flags |= IOMAP_DIO_NEED_SYNC; db074436f42196 Darrick J. Wong 2019-07-15 460 db074436f42196 Darrick J. Wong 2019-07-15 461 /* db074436f42196 Darrick J. Wong 2019-07-15 462 * For datasync only writes, we optimistically try using FUA for db074436f42196 Darrick J. Wong 2019-07-15 463 * this IO. Any non-FUA write that occurs will clear this flag, db074436f42196 Darrick J. Wong 2019-07-15 464 * hence we know before completion whether a cache flush is db074436f42196 Darrick J. Wong 2019-07-15 465 * necessary. db074436f42196 Darrick J. Wong 2019-07-15 466 */ db074436f42196 Darrick J. Wong 2019-07-15 467 if ((iocb->ki_flags & (IOCB_DSYNC | IOCB_SYNC)) == IOCB_DSYNC) db074436f42196 Darrick J. Wong 2019-07-15 468 dio->flags |= IOMAP_DIO_WRITE_FUA; db074436f42196 Darrick J. Wong 2019-07-15 469 } db074436f42196 Darrick J. Wong 2019-07-15 470 db074436f42196 Darrick J. Wong 2019-07-15 471 if (iocb->ki_flags & IOCB_NOWAIT) { 88cfd30e188fcf Johannes Thumshirn 2019-11-26 472 if (filemap_range_has_page(mapping, pos, end)) { db074436f42196 Darrick J. Wong 2019-07-15 473 ret = -EAGAIN; db074436f42196 Darrick J. Wong 2019-07-15 474 goto out_free_dio; db074436f42196 Darrick J. Wong 2019-07-15 475 } db074436f42196 Darrick J. Wong 2019-07-15 476 flags |= IOMAP_NOWAIT; db074436f42196 Darrick J. Wong 2019-07-15 477 } db074436f42196 Darrick J. Wong 2019-07-15 478 88cfd30e188fcf Johannes Thumshirn 2019-11-26 479 ret = filemap_write_and_wait_range(mapping, pos, end); db074436f42196 Darrick J. Wong 2019-07-15 480 if (ret) db074436f42196 Darrick J. Wong 2019-07-15 481 goto out_free_dio; db074436f42196 Darrick J. Wong 2019-07-15 482 54752de928c400 Dave Chinner 2020-07-23 483 if (iov_iter_rw(iter) == WRITE) { db074436f42196 Darrick J. Wong 2019-07-15 484 /* 54752de928c400 Dave Chinner 2020-07-23 485 * Try to invalidate cache pages for the range we are writing. 60263d5889e6dc Christoph Hellwig 2020-07-23 486 * If this invalidation fails, let the caller fall back to 60263d5889e6dc Christoph Hellwig 2020-07-23 487 * buffered I/O. db074436f42196 Darrick J. Wong 2019-07-15 488 */ 54752de928c400 Dave Chinner 2020-07-23 489 if (invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, 60263d5889e6dc Christoph Hellwig 2020-07-23 490 end >> PAGE_SHIFT)) { 60263d5889e6dc Christoph Hellwig 2020-07-23 491 trace_iomap_dio_invalidate_fail(inode, pos, count); 60263d5889e6dc Christoph Hellwig 2020-07-23 492 ret = -ENOTBLK; 60263d5889e6dc Christoph Hellwig 2020-07-23 493 goto out_free_dio; 60263d5889e6dc Christoph Hellwig 2020-07-23 494 } db074436f42196 Darrick J. Wong 2019-07-15 495 54752de928c400 Dave Chinner 2020-07-23 496 if (!wait_for_completion && !inode->i_sb->s_dio_done_wq) { db074436f42196 Darrick J. Wong 2019-07-15 497 ret = sb_init_dio_done_wq(inode->i_sb); db074436f42196 Darrick J. Wong 2019-07-15 498 if (ret < 0) db074436f42196 Darrick J. Wong 2019-07-15 499 goto out_free_dio; db074436f42196 Darrick J. Wong 2019-07-15 500 } 54752de928c400 Dave Chinner 2020-07-23 501 } db074436f42196 Darrick J. Wong 2019-07-15 502 db074436f42196 Darrick J. Wong 2019-07-15 503 inode_dio_begin(inode); db074436f42196 Darrick J. Wong 2019-07-15 504 db074436f42196 Darrick J. Wong 2019-07-15 505 blk_start_plug(&plug); db074436f42196 Darrick J. Wong 2019-07-15 506 do { db074436f42196 Darrick J. Wong 2019-07-15 507 ret = iomap_apply(inode, pos, count, flags, ops, dio, db074436f42196 Darrick J. Wong 2019-07-15 508 iomap_dio_actor); db074436f42196 Darrick J. Wong 2019-07-15 509 if (ret <= 0) { db074436f42196 Darrick J. Wong 2019-07-15 510 /* magic error code to fall back to buffered I/O */ db074436f42196 Darrick J. Wong 2019-07-15 511 if (ret == -ENOTBLK) { db074436f42196 Darrick J. Wong 2019-07-15 512 wait_for_completion = true; db074436f42196 Darrick J. Wong 2019-07-15 513 ret = 0; db074436f42196 Darrick J. Wong 2019-07-15 514 } db074436f42196 Darrick J. Wong 2019-07-15 515 break; db074436f42196 Darrick J. Wong 2019-07-15 516 } db074436f42196 Darrick J. Wong 2019-07-15 517 pos += ret; db074436f42196 Darrick J. Wong 2019-07-15 518 419e9c38aa075e Jan Kara 2019-11-21 519 if (iov_iter_rw(iter) == READ && pos >= dio->i_size) { 419e9c38aa075e Jan Kara 2019-11-21 520 /* 419e9c38aa075e Jan Kara 2019-11-21 521 * We only report that we've read data up to i_size. 419e9c38aa075e Jan Kara 2019-11-21 522 * Revert iter to a state corresponding to that as 419e9c38aa075e Jan Kara 2019-11-21 523 * some callers (such as splice code) rely on it. 419e9c38aa075e Jan Kara 2019-11-21 524 */ 419e9c38aa075e Jan Kara 2019-11-21 525 iov_iter_revert(iter, pos - dio->i_size); db074436f42196 Darrick J. Wong 2019-07-15 526 break; 419e9c38aa075e Jan Kara 2019-11-21 527 } db074436f42196 Darrick J. Wong 2019-07-15 528 } while ((count = iov_iter_count(iter)) > 0); db074436f42196 Darrick J. Wong 2019-07-15 529 blk_finish_plug(&plug); db074436f42196 Darrick J. Wong 2019-07-15 530 db074436f42196 Darrick J. Wong 2019-07-15 531 if (ret < 0) db074436f42196 Darrick J. Wong 2019-07-15 532 iomap_dio_set_error(dio, ret); db074436f42196 Darrick J. Wong 2019-07-15 533 db074436f42196 Darrick J. Wong 2019-07-15 534 /* db074436f42196 Darrick J. Wong 2019-07-15 535 * If all the writes we issued were FUA, we don't need to flush the db074436f42196 Darrick J. Wong 2019-07-15 536 * cache on IO completion. Clear the sync flag for this case. db074436f42196 Darrick J. Wong 2019-07-15 537 */ db074436f42196 Darrick J. Wong 2019-07-15 538 if (dio->flags & IOMAP_DIO_WRITE_FUA) db074436f42196 Darrick J. Wong 2019-07-15 539 dio->flags &= ~IOMAP_DIO_NEED_SYNC; db074436f42196 Darrick J. Wong 2019-07-15 540 db074436f42196 Darrick J. Wong 2019-07-15 541 WRITE_ONCE(iocb->ki_cookie, dio->submit.cookie); db074436f42196 Darrick J. Wong 2019-07-15 542 WRITE_ONCE(iocb->private, dio->submit.last_queue); db074436f42196 Darrick J. Wong 2019-07-15 543 db074436f42196 Darrick J. Wong 2019-07-15 544 /* db074436f42196 Darrick J. Wong 2019-07-15 545 * We are about to drop our additional submission reference, which d9973ce2fe5bcd yangerkun 2020-03-18 546 * might be the last reference to the dio. There are three different d9973ce2fe5bcd yangerkun 2020-03-18 547 * ways we can progress here: db074436f42196 Darrick J. Wong 2019-07-15 548 * db074436f42196 Darrick J. Wong 2019-07-15 549 * (a) If this is the last reference we will always complete and free db074436f42196 Darrick J. Wong 2019-07-15 550 * the dio ourselves. db074436f42196 Darrick J. Wong 2019-07-15 551 * (b) If this is not the last reference, and we serve an asynchronous db074436f42196 Darrick J. Wong 2019-07-15 552 * iocb, we must never touch the dio after the decrement, the db074436f42196 Darrick J. Wong 2019-07-15 553 * I/O completion handler will complete and free it. db074436f42196 Darrick J. Wong 2019-07-15 554 * (c) If this is not the last reference, but we serve a synchronous db074436f42196 Darrick J. Wong 2019-07-15 555 * iocb, the I/O completion handler will wake us up on the drop db074436f42196 Darrick J. Wong 2019-07-15 556 * of the final reference, and we will complete and free it here db074436f42196 Darrick J. Wong 2019-07-15 557 * after we got woken by the I/O completion handler. db074436f42196 Darrick J. Wong 2019-07-15 558 */ db074436f42196 Darrick J. Wong 2019-07-15 559 dio->wait_for_completion = wait_for_completion; db074436f42196 Darrick J. Wong 2019-07-15 560 if (!atomic_dec_and_test(&dio->ref)) { db074436f42196 Darrick J. Wong 2019-07-15 561 if (!wait_for_completion) 072d65c9ae6669 Christoph Hellwig 2020-09-21 562 return ERR_PTR(-EIOCBQUEUED); db074436f42196 Darrick J. Wong 2019-07-15 563 db074436f42196 Darrick J. Wong 2019-07-15 564 for (;;) { db074436f42196 Darrick J. Wong 2019-07-15 565 set_current_state(TASK_UNINTERRUPTIBLE); db074436f42196 Darrick J. Wong 2019-07-15 566 if (!READ_ONCE(dio->submit.waiter)) db074436f42196 Darrick J. Wong 2019-07-15 567 break; db074436f42196 Darrick J. Wong 2019-07-15 568 db074436f42196 Darrick J. Wong 2019-07-15 569 if (!(iocb->ki_flags & IOCB_HIPRI) || db074436f42196 Darrick J. Wong 2019-07-15 570 !dio->submit.last_queue || db074436f42196 Darrick J. Wong 2019-07-15 571 !blk_poll(dio->submit.last_queue, db074436f42196 Darrick J. Wong 2019-07-15 572 dio->submit.cookie, true)) e6249cdd46e43a Ming Lei 2020-05-03 573 blk_io_schedule(); db074436f42196 Darrick J. Wong 2019-07-15 574 } db074436f42196 Darrick J. Wong 2019-07-15 575 __set_current_state(TASK_RUNNING); db074436f42196 Darrick J. Wong 2019-07-15 576 } db074436f42196 Darrick J. Wong 2019-07-15 577 072d65c9ae6669 Christoph Hellwig 2020-09-21 578 return dio; db074436f42196 Darrick J. Wong 2019-07-15 579 db074436f42196 Darrick J. Wong 2019-07-15 580 out_free_dio: db074436f42196 Darrick J. Wong 2019-07-15 581 kfree(dio); 072d65c9ae6669 Christoph Hellwig 2020-09-21 @582 return ERR_PTR(ret); 072d65c9ae6669 Christoph Hellwig 2020-09-21 583 } --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org [-- Attachment #2: config.gz --] [-- Type: application/gzip, Size: 39250 bytes --]
next prev parent reply other threads:[~2020-09-22 9:24 UTC|newest] Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-21 14:43 [PATCH 0/15 v2] BTRFS DIO inode locking/D_SYNC fix Goldwyn Rodrigues 2020-09-21 14:43 ` [PATCH 01/15] fs: remove dio_end_io() Goldwyn Rodrigues 2020-09-22 14:17 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 02/15] btrfs: remove BTRFS_INODE_READDIO_NEED_LOCK Goldwyn Rodrigues 2020-09-22 13:18 ` Christoph Hellwig 2020-09-22 14:17 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 03/15] iomap: Allow filesystem to call iomap_dio_complete without i_rwsem Goldwyn Rodrigues 2020-09-21 15:09 ` Johannes Thumshirn 2020-09-22 13:19 ` hch 2020-09-22 9:24 ` Dan Carpenter [this message] 2020-09-22 9:24 ` Dan Carpenter 2020-09-22 14:16 ` Goldwyn Rodrigues 2020-09-22 14:58 ` Dan Carpenter 2020-09-22 14:58 ` Dan Carpenter 2020-09-22 16:06 ` Goldwyn Rodrigues 2020-09-22 14:17 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 04/15] iomap: Call inode_dio_end() before generic_write_sync() Goldwyn Rodrigues 2020-09-21 15:11 ` Johannes Thumshirn 2020-09-22 13:21 ` Christoph Hellwig 2020-09-22 14:20 ` Josef Bacik 2020-09-22 16:31 ` Darrick J. Wong 2020-09-22 17:25 ` Goldwyn Rodrigues 2020-09-22 21:49 ` Dave Chinner 2020-09-23 5:16 ` Christoph Hellwig 2020-09-23 5:31 ` Darrick J. Wong 2020-09-23 5:49 ` Christoph Hellwig 2020-09-23 5:59 ` Dave Chinner 2020-09-21 14:43 ` [PATCH 05/15] btrfs: split btrfs_direct_IO to read and write Goldwyn Rodrigues 2020-09-22 13:22 ` Christoph Hellwig 2020-09-22 14:27 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 06/15] btrfs: Move pos increment and pagecache extension to btrfs_buffered_write() Goldwyn Rodrigues 2020-09-22 13:22 ` Christoph Hellwig 2020-09-22 14:30 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 07/15] btrfs: Move FS error state bit early during write Goldwyn Rodrigues 2020-09-22 14:38 ` Josef Bacik 2020-09-23 9:10 ` Nikolay Borisov 2020-09-23 14:07 ` Goldwyn Rodrigues 2020-09-21 14:43 ` [PATCH 08/15] btrfs: Introduce btrfs_write_check() Goldwyn Rodrigues 2020-09-22 13:26 ` Christoph Hellwig 2020-09-22 14:42 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 09/15] btrfs: Introduce btrfs_inode_lock()/unlock() Goldwyn Rodrigues 2020-09-22 14:45 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 10/15] btrfs: Push inode locking and unlocking into buffered/direct write Goldwyn Rodrigues 2020-09-22 9:26 ` Dan Carpenter 2020-09-22 9:26 ` Dan Carpenter 2020-09-22 14:48 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 11/15] btrfs: Use inode_lock_shared() for direct writes within EOF Goldwyn Rodrigues 2020-09-22 14:52 ` Josef Bacik 2020-09-22 17:33 ` Goldwyn Rodrigues 2020-09-21 14:43 ` [PATCH 12/15] btrfs: Remove dio_sem Goldwyn Rodrigues 2020-09-22 14:52 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 13/15] btrfs: Call iomap_dio_complete() without inode_lock Goldwyn Rodrigues 2020-09-22 15:11 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 14/15] btrfs: Revert 09745ff88d93 ("btrfs: dio iomap DSYNC workaround") Goldwyn Rodrigues 2020-09-22 15:12 ` Josef Bacik 2020-09-21 14:43 ` [PATCH 15/15] iomap: Reinstate lockdep_assert_held in iomap_dio_rw() Goldwyn Rodrigues 2020-09-22 13:26 ` Christoph Hellwig 2020-09-22 0:52 [PATCH 03/15] iomap: Allow filesystem to call iomap_dio_complete without i_rwsem kernel test robot
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200922092437.GE4282@kadam \ --to=dan.carpenter@oracle.com \ --cc=kbuild@lists.01.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.