Hi Heming, url: https://github.com/0day-ci/linux/commits/Heming-Zhao/md-bitmap-don-t-set-sb-values-if-can-t-pass-sanity-check/20220325-105426 base: git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git md-next config: powerpc-randconfig-m031-20220324 (https://download.01.org/0day-ci/archive/20220326/202203260647.ZIDU6VYv-lkp@xxxxxxxxx/config ) compiler: powerpc-linux-gcc (GCC) 11.2.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@xxxxxxxxx> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx> New smatch warnings: drivers/md/md-bitmap.c:644 md_bitmap_read_sb() error: uninitialized symbol 'chunksize'. drivers/md/md-bitmap.c:648 md_bitmap_read_sb() error: uninitialized symbol 'daemon_sleep'. drivers/md/md-bitmap.c:650 md_bitmap_read_sb() error: uninitialized symbol 'write_behind'. Old smatch warnings: drivers/md/md-bitmap.c:371 read_page() warn: should 'index << (12 - inode->i_blkbits)' be a 64 bit type? drivers/md/md-bitmap.c:2182 md_bitmap_resize() warn: should 'old_counts.chunks << old_counts.chunkshift' be a 64 bit type? drivers/md/md-bitmap.c:2206 md_bitmap_resize() warn: should '1 << chunkshift' be a 64 bit type? vim +/chunksize +644 drivers/md/md-bitmap.c e64e4018d57271 drivers/md/md-bitmap.c Andy Shevchenko 2018-08-01 578 static int md_bitmap_read_sb(struct bitmap *bitmap) 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 579 { 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 580 char *reason = NULL; 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 581 bitmap_super_t *sb; 4b6d287f627b5f drivers/md/bitmap.c NeilBrown 2005-09-09 582 unsigned long chunksize, daemon_sleep, write_behind; 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 583 unsigned long long events; c4ce867fdad200 drivers/md/bitmap.c Goldwyn Rodrigues 2014-03-29 584 int nodes = 0; 1dff2b87a34a1a drivers/md/bitmap.c NeilBrown 2012-05-22 585 unsigned long sectors_reserved = 0; 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 586 int err = -EINVAL; 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 587 struct page *sb_page; 33e38ac6887d97 drivers/md/bitmap.c Goldwyn Rodrigues 2015-07-01 588 loff_t offset = bitmap->mddev->bitmap_info.offset; 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 589 1ec885cdd01a9a drivers/md/bitmap.c NeilBrown 2012-05-22 590 if (!bitmap->storage.file && !bitmap->mddev->bitmap_info.offset) { ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 591 chunksize = 128 * 1024 * 1024; ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 592 daemon_sleep = 5 * HZ; ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 593 write_behind = 0; b405fe91e50c60 drivers/md/bitmap.c NeilBrown 2012-05-22 594 set_bit(BITMAP_STALE, &bitmap->flags); ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 595 err = 0; ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 596 goto out_no_sb; ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 597 } 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 598 /* page 0 is the superblock, read it... */ 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 599 sb_page = alloc_page(GFP_KERNEL); 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 600 if (!sb_page) 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 601 return -ENOMEM; 1ec885cdd01a9a drivers/md/bitmap.c NeilBrown 2012-05-22 602 bitmap->storage.sb_page = sb_page; 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 603 b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 604 re_read: f9209a323547f0 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 605 /* If cluster_slot is set, the cluster is setup */ f9209a323547f0 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 606 if (bitmap->cluster_slot >= 0) { 3b0e6aacbfe04f drivers/md/bitmap.c Stephen Rothwell 2015-03-03 607 sector_t bm_blocks = bitmap->mddev->resync_max_sectors; f9209a323547f0 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 608 a913096decbf41 drivers/md/md-bitmap.c Zhao Heming 2020-10-06 609 bm_blocks = DIV_ROUND_UP_SECTOR_T(bm_blocks, a913096decbf41 drivers/md/md-bitmap.c Zhao Heming 2020-10-06 610 (bitmap->mddev->bitmap_info.chunksize >> 9)); 124eb761edfdee drivers/md/bitmap.c Goldwyn Rodrigues 2015-03-24 611 /* bits to bytes */ 124eb761edfdee drivers/md/bitmap.c Goldwyn Rodrigues 2015-03-24 612 bm_blocks = ((bm_blocks+7) >> 3) + sizeof(bitmap_super_t); 124eb761edfdee drivers/md/bitmap.c Goldwyn Rodrigues 2015-03-24 613 /* to 4k blocks */ 935f3d4fc62c1f drivers/md/bitmap.c NeilBrown 2015-03-02 614 bm_blocks = DIV_ROUND_UP_SECTOR_T(bm_blocks, 4096); 33e38ac6887d97 drivers/md/bitmap.c Goldwyn Rodrigues 2015-07-01 615 offset = bitmap->mddev->bitmap_info.offset + (bitmap->cluster_slot * (bm_blocks << 3)); ec0cc226854a79 drivers/md/bitmap.c NeilBrown 2016-11-02 616 pr_debug("%s:%d bm slot: %d offset: %llu\n", __func__, __LINE__, 33e38ac6887d97 drivers/md/bitmap.c Goldwyn Rodrigues 2015-07-01 617 bitmap->cluster_slot, offset); f9209a323547f0 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 618 } f9209a323547f0 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 619 1ec885cdd01a9a drivers/md/bitmap.c NeilBrown 2012-05-22 620 if (bitmap->storage.file) { 1ec885cdd01a9a drivers/md/bitmap.c NeilBrown 2012-05-22 621 loff_t isize = i_size_read(bitmap->storage.file->f_mapping->host); f49d5e62d9352d drivers/md/bitmap.c NeilBrown 2007-01-26 622 int bytes = isize > PAGE_SIZE ? PAGE_SIZE : isize; f49d5e62d9352d drivers/md/bitmap.c NeilBrown 2007-01-26 623 1ec885cdd01a9a drivers/md/bitmap.c NeilBrown 2012-05-22 624 err = read_page(bitmap->storage.file, 0, 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 625 bitmap, bytes, sb_page); f49d5e62d9352d drivers/md/bitmap.c NeilBrown 2007-01-26 626 } else { 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 627 err = read_sb_page(bitmap->mddev, 33e38ac6887d97 drivers/md/bitmap.c Goldwyn Rodrigues 2015-07-01 628 offset, 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 629 sb_page, 938b533d479e74 drivers/md/bitmap.c Shaohua Li 2017-10-16 630 0, sizeof(bitmap_super_t)); a654b9d8f851f4 drivers/md/bitmap.c NeilBrown 2005-06-21 631 } 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 632 if (err) 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 633 return err; 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 634 b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 635 err = -EINVAL; 27581e5ae01f77 drivers/md/bitmap.c NeilBrown 2012-05-22 636 sb = kmap_atomic(sb_page); 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 637 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 638 /* verify that the bitmap-specific fields are valid */ 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 639 if (sb->magic != cpu_to_le32(BITMAP_MAGIC)) 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 640 reason = "bad magic"; bd926c63b7a684 drivers/md/bitmap.c NeilBrown 2005-11-08 641 else if (le32_to_cpu(sb->version) < BITMAP_MAJOR_LO || 3c462c880b52aa drivers/md/bitmap.c Goldwyn Rodrigues 2015-08-19 642 le32_to_cpu(sb->version) > BITMAP_MAJOR_CLUSTERED) 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 643 reason = "unrecognized superblock version"; 1187cf0a3c8b64 drivers/md/bitmap.c NeilBrown 2009-03-31 @644 else if (chunksize < 512) Checked before initialized 7dd5d34c6c2da0 drivers/md/bitmap.c NeilBrown 2006-01-06 645 reason = "bitmap chunksize too small"; d744540cd39e93 drivers/md/bitmap.c Jonathan Brassow 2011-06-08 646 else if (!is_power_of_2(chunksize)) 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 647 reason = "bitmap chunksize not a power of 2"; 1b04be96f6910e drivers/md/bitmap.c NeilBrown 2009-12-14 @648 else if (daemon_sleep < 1 || daemon_sleep > MAX_SCHEDULE_TIMEOUT) 7dd5d34c6c2da0 drivers/md/bitmap.c NeilBrown 2006-01-06 649 reason = "daemon sleep period out of range"; 4b6d287f627b5f drivers/md/bitmap.c NeilBrown 2005-09-09 @650 else if (write_behind > COUNTER_MAX) 4b6d287f627b5f drivers/md/bitmap.c NeilBrown 2005-09-09 651 reason = "write-behind limit out of range (0 - 16383)"; 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 652 if (reason) { ec0cc226854a79 drivers/md/bitmap.c NeilBrown 2016-11-02 653 pr_warn("%s: invalid bitmap file superblock: %s\n", 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 654 bmname(bitmap), reason); 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 655 goto out; 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 656 } 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 657 f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 658 chunksize = le32_to_cpu(sb->chunksize); Initialize here f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 659 daemon_sleep = le32_to_cpu(sb->daemon_sleep) * HZ; f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 660 write_behind = le32_to_cpu(sb->write_behind); f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 661 sectors_reserved = le32_to_cpu(sb->sectors_reserved); f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 662 /* Setup nodes/clustername only if bitmap version is f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 663 * cluster-compatible f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 664 */ f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 665 if (sb->version == cpu_to_le32(BITMAP_MAJOR_CLUSTERED)) { f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 666 nodes = le32_to_cpu(sb->nodes); f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 667 strlcpy(bitmap->mddev->bitmap_info.cluster_name, f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 668 sb->cluster_name, 64); f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 669 } f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 670 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 671 /* keep the array size field of the bitmap superblock up to date */ 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 672 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 673 278c1ca2f254d0 drivers/md/bitmap.c NeilBrown 2012-03-19 674 if (bitmap->mddev->persistent) { 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 675 /* 278c1ca2f254d0 drivers/md/bitmap.c NeilBrown 2012-03-19 676 * We have a persistent array superblock, so compare the 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 677 * bitmap's UUID and event counter to the mddev's 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 678 */ 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 679 if (memcmp(sb->uuid, bitmap->mddev->uuid, 16)) { ec0cc226854a79 drivers/md/bitmap.c NeilBrown 2016-11-02 680 pr_warn("%s: bitmap superblock UUID mismatch\n", 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 681 bmname(bitmap)); 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 682 goto out; 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 683 } 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 684 events = le64_to_cpu(sb->events); b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 685 if (!nodes && (events < bitmap->mddev->events)) { ec0cc226854a79 drivers/md/bitmap.c NeilBrown 2016-11-02 686 pr_warn("%s: bitmap file is out of date (%llu < %llu) -- forcing full recovery\n", 278c1ca2f254d0 drivers/md/bitmap.c NeilBrown 2012-03-19 687 bmname(bitmap), events, 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 688 (unsigned long long) bitmap->mddev->events); b405fe91e50c60 drivers/md/bitmap.c NeilBrown 2012-05-22 689 set_bit(BITMAP_STALE, &bitmap->flags); 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 690 } 278c1ca2f254d0 drivers/md/bitmap.c NeilBrown 2012-03-19 691 } 278c1ca2f254d0 drivers/md/bitmap.c NeilBrown 2012-03-19 692 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 693 /* assign fields using values from superblock */ 4f2e639af4bd5e drivers/md/bitmap.c NeilBrown 2006-10-21 694 bitmap->flags |= le32_to_cpu(sb->state); bd926c63b7a684 drivers/md/bitmap.c NeilBrown 2005-11-08 695 if (le32_to_cpu(sb->version) == BITMAP_MAJOR_HOSTENDIAN) b405fe91e50c60 drivers/md/bitmap.c NeilBrown 2012-05-22 696 set_bit(BITMAP_HOSTENDIAN, &bitmap->flags); 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 697 bitmap->events_cleared = le64_to_cpu(sb->events_cleared); cf921cc19cf7c1 drivers/md/bitmap.c Goldwyn Rodrigues 2014-03-30 698 strlcpy(bitmap->mddev->bitmap_info.cluster_name, sb->cluster_name, 64); 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 699 err = 0; b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 700 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 701 out: b2f46e68825648 drivers/md/bitmap.c Cong Wang 2011-11-28 702 kunmap_atomic(sb); f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 703 if (err == 0 && nodes && (bitmap->cluster_slot < 0)) { 3560741e316b3e drivers/md/bitmap.c Zhilong Liu 2017-03-15 704 /* Assigning chunksize is required for "re_read" */ f9209a323547f0 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 705 bitmap->mddev->bitmap_info.chunksize = chunksize; b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 706 err = md_setup_cluster(bitmap->mddev, nodes); b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 707 if (err) { ec0cc226854a79 drivers/md/bitmap.c NeilBrown 2016-11-02 708 pr_warn("%s: Could not setup cluster service (%d)\n", b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 709 bmname(bitmap), err); b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 710 goto out_no_sb; b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 711 } b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 712 bitmap->cluster_slot = md_cluster_ops->slot_number(bitmap->mddev); b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 713 goto re_read; b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 714 } b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 715 b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 716 ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 717 out_no_sb: b405fe91e50c60 drivers/md/bitmap.c NeilBrown 2012-05-22 718 if (test_bit(BITMAP_STALE, &bitmap->flags)) ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 719 bitmap->events_cleared = bitmap->mddev->events; f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 720 if (err == 0) { ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 721 bitmap->mddev->bitmap_info.chunksize = chunksize; ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 722 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; ef99bf480de9bd drivers/md/bitmap.c NeilBrown 2012-05-22 723 bitmap->mddev->bitmap_info.max_write_behind = write_behind; c4ce867fdad200 drivers/md/bitmap.c Goldwyn Rodrigues 2014-03-29 724 bitmap->mddev->bitmap_info.nodes = nodes; f9fd5e55a60521 drivers/md/md-bitmap.c Heming Zhao 2022-03-25 725 } 1dff2b87a34a1a drivers/md/bitmap.c NeilBrown 2012-05-22 726 if (bitmap->mddev->bitmap_info.space == 0 || 1dff2b87a34a1a drivers/md/bitmap.c NeilBrown 2012-05-22 727 bitmap->mddev->bitmap_info.space > sectors_reserved) 1dff2b87a34a1a drivers/md/bitmap.c NeilBrown 2012-05-22 728 bitmap->mddev->bitmap_info.space = sectors_reserved; b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 729 if (err) { e64e4018d57271 drivers/md/md-bitmap.c Andy Shevchenko 2018-08-01 730 md_bitmap_print_sb(bitmap); f9209a323547f0 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 731 if (bitmap->cluster_slot < 0) b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 732 md_cluster_stop(bitmap->mddev); b97e92574c0bf3 drivers/md/bitmap.c Goldwyn Rodrigues 2014-06-06 733 } 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 734 return err; 32a7627cf3a353 drivers/md/bitmap.c NeilBrown 2005-06-21 735 } -- 0-DAY CI Kernel Test Service https://01.org/lkp _______________________________________________ kbuild mailing list -- kbuild@xxxxxxxxxxxx To unsubscribe send an email to kbuild-leave@xxxxxxxxxxxx