Skip to content
  1. Apr 08, 2022
    • Andreas Gruenbacher's avatar
      gfs2: gfs2_setattr_size error path fix · e9600f5c
      Andreas Gruenbacher authored
      commit 7336905a upstream.
      
      When gfs2_setattr_size() fails, it calls gfs2_rs_delete(ip, NULL) to get
      rid of any reservations the inode may have.  Instead, it should pass in
      the inode's write count as the second parameter to allow
      gfs2_rs_delete() to figure out if the inode has any writers left.
      
      In a next step, there are two instances of gfs2_rs_delete(ip, NULL) left
      where we know that there can be no other users of the inode.  Replace
      those with gfs2_rs_deltree(&ip->i_res) to avoid the unnecessary write
      count check.
      
      With that, gfs2_rs_delete() is only called with the inode's actual write
      count, so get rid of the second parameter.
      
      Fixes: a097dc7e
      
       ("GFS2: Make rgrp reservations part of the gfs2_inode structure")
      Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e9600f5c
    • Carlos Llamas's avatar
      loop: fix ioctl calls using compat_loop_info · fa86484d
      Carlos Llamas authored
      commit f941c51e upstream.
      
      Support for cryptoloop was deleted in commit 47e96246 ("block:
      remove support for cryptoloop and the xor transfer"), making the usage
      of loop_info->lo_encrypt_type obsolete. However, this member was also
      removed from the compat_loop_info definition and this breaks userspace
      ioctl calls for 32-bit binaries and CONFIG_COMPAT=y.
      
      This patch restores the compat_loop_info->lo_encrypt_type member and
      marks it obsolete as well as in the uapi header definitions.
      
      Fixes: 47e96246
      
       ("block: remove support for cryptoloop and the xor transfer")
      Signed-off-by: default avatarCarlos Llamas <cmllamas@google.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Link: https://lore.kernel.org/r/20220329201815.1347500-1-cmllamas@google.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fa86484d
    • Tom Rix's avatar
      rtc: check if __rtc_read_time was successful · 77dbaa66
      Tom Rix authored
      commit 915593a7 upstream.
      
      Clang static analysis reports this issue
      interface.c:810:8: warning: Passed-by-value struct
        argument contains uninitialized data
        now = rtc_tm_to_ktime(tm);
            ^~~~~~~~~~~~~~~~~~~
      
      tm is set by a successful call to __rtc_read_time()
      but its return status is not checked.  Check if
      it was successful before setting the enabled flag.
      Move the decl of err to function scope.
      
      Fixes: 2b2f5ff0
      
       ("rtc: interface: ignore expired timers when enqueuing new timers")
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Link: https://lore.kernel.org/r/20220326194236.2916310-1-trix@redhat.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      77dbaa66
    • Masahiro Yamada's avatar
      modpost: restore the warning message for missing symbol versions · 929b5daa
      Masahiro Yamada authored
      commit bf5c0c22 upstream.
      
      This log message was accidentally chopped off.
      
      I was wondering why this happened, but checking the ML log, Mark
      precisely followed my suggestion [1].
      
      I just used "..." because I was too lazy to type the sentence fully.
      Sorry for the confusion.
      
      [1]: https://lore.kernel.org/all/CAK7LNAR6bXXk9-ZzZYpTqzFqdYbQsZHmiWspu27rtsFxvfRuVA@mail.gmail.com/
      
      Fixes: 4a679593
      
       ("kbuild: modpost: Explicitly warn about unprototyped symbols")
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Acked-by: default avatarMark Brown <broonie@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      929b5daa
    • Matthew Wilcox (Oracle)'s avatar
      XArray: Update the LRU list in xas_split() · 9ba1807a
      Matthew Wilcox (Oracle) authored
      commit 3ed4bb77 upstream.
      
      When splitting a value entry, we may need to add the new nodes to the LRU
      list and remove the parent node from the LRU list.  The WARN_ON checks
      in shadow_lru_isolate() catch this oversight.  This bug was latent
      until we stopped splitting folios in shrink_page_list() with commit
      820c4e2e ("mm/vmscan: Free non-shmem folios without splitting them").
      That allows the creation of large shadow entries, and subsequently when
      trying to page in a small page, we will split the large shadow entry
      in __filemap_add_folio().
      
      Fixes: 8fc75643
      
       ("XArray: add xas_split")
      Reported-by: default avatarHugh Dickins <hughd@google.com>
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9ba1807a
    • Tom Rix's avatar
      can: mcp251xfd: mcp251xfd_register_get_dev_id(): fix return of error value · 1ba3f871
      Tom Rix authored
      commit fa7b514d upstream.
      
      Clang static analysis reports this issue:
      
      | mcp251xfd-core.c:1813:7: warning: The left operand
      |   of '&' is a garbage value
      |   FIELD_GET(MCP251XFD_REG_DEVID_ID_MASK, dev_id),
      |   ^                                      ~~~~~~
      
      dev_id is set in a successful call to mcp251xfd_register_get_dev_id().
      Though the status of calls made by mcp251xfd_register_get_dev_id() are
      checked and handled, their status' are not returned. So return err.
      
      Fixes: 55e5b97f
      
       ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN")
      Link: https://lore.kernel.org/all/20220319153128.2164120-1-trix@redhat.com
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1ba3f871
    • Pavel Skripkin's avatar
      can: mcba_usb: properly check endpoint type · 88272b4a
      Pavel Skripkin authored
      commit 136bed0b upstream.
      
      Syzbot reported warning in usb_submit_urb() which is caused by wrong
      endpoint type. We should check that in endpoint is actually present to
      prevent this warning.
      
      Found pipes are now saved to struct mcba_priv and code uses them
      directly instead of making pipes in place.
      
      Fail log:
      
      | usb 5-1: BOGUS urb xfer, pipe 3 != type 1
      | WARNING: CPU: 1 PID: 49 at drivers/usb/core/urb.c:502 usb_submit_urb+0xed2/0x18a0 drivers/usb/core/urb.c:502
      | Modules linked in:
      | CPU: 1 PID: 49 Comm: kworker/1:2 Not tainted 5.17.0-rc6-syzkaller-00184-g38f80f42147f #0
      | Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
      | Workqueue: usb_hub_wq hub_event
      | RIP: 0010:usb_submit_urb+0xed2/0x18a0 drivers/usb/core/urb.c:502
      | ...
      | Call Trace:
      |  <TASK>
      |  mcba_usb_start drivers/net/can/usb/mcba_usb.c:662 [inline]
      |  mcba_usb_probe+0x8a3/0xc50 drivers/net/can/usb/mcba_usb.c:858
      |  usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396
      |  call_driver_probe drivers/base/dd.c:517 [inline]
      
      Fixes: 51f3baad
      
       ("can: mcba_usb: Add support for Microchip CAN BUS Analyzer")
      Link: https://lore.kernel.org/all/20220313100903.10868-1-paskripkin@gmail.com
      Reported-and-tested-by: default avatar <syzbot+3bc1dce0cc0052d60fde@syzkaller.appspotmail.com>
      Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Reviewed-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      88272b4a
    • Hangyu Hua's avatar
      can: mcba_usb: mcba_usb_start_xmit(): fix double dev_kfree_skb in error path · f9134128
      Hangyu Hua authored
      commit 04c9b00b upstream.
      
      There is no need to call dev_kfree_skb() when usb_submit_urb() fails
      because can_put_echo_skb() deletes original skb and
      can_free_echo_skb() deletes the cloned skb.
      
      Fixes: 51f3baad
      
       ("can: mcba_usb: Add support for Microchip CAN BUS Analyzer")
      Link: https://lore.kernel.org/all/20220311080208.45047-1-hbh25y@gmail.com
      Signed-off-by: default avatarHangyu Hua <hbh25y@gmail.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f9134128
    • Matthew Wilcox (Oracle)'s avatar
      XArray: Fix xas_create_range() when multi-order entry present · 29968329
      Matthew Wilcox (Oracle) authored
      commit 3e3c6580 upstream.
      
      If there is already an entry present that is of order >= XA_CHUNK_SHIFT
      when we call xas_create_range(), xas_create_range() will misinterpret
      that entry as a node and dereference xa_node->parent, generally leading
      to a crash that looks something like this:
      
      general protection fault, probably for non-canonical address 0xdffffc0000000001:
      0000 [#1] PREEMPT SMP KASAN
      KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
      CPU: 0 PID: 32 Comm: khugepaged Not tainted 5.17.0-rc8-syzkaller-00003-g56e337f2cf13 #0
      RIP: 0010:xa_parent_locked include/linux/xarray.h:1207 [inline]
      RIP: 0010:xas_create_range+0x2d9/0x6e0 lib/xarray.c:725
      
      It's deterministically reproducable once you know what the problem is,
      but producing it in a live kernel requires khugepaged to hit a race.
      While the problem has been present since xas_create_range() was
      introduced, I'm not aware of a way to hit it before the page cache was
      converted to use multi-index entries.
      
      Fixes: 6b24ca4a
      
       ("mm: Use multi-index entries in the page cache")
      Reported-by: default avatar <syzbot+0d2b0bf32ca5cfd09f2e@syzkaller.appspotmail.com>
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      29968329
    • Jason A. Donenfeld's avatar
      wireguard: socket: ignore v6 endpoints when ipv6 is disabled · efde4c0c
      Jason A. Donenfeld authored
      commit 77fc73ac upstream.
      
      The previous commit fixed a memory leak on the send path in the event
      that IPv6 is disabled at compile time, but how did a packet even arrive
      there to begin with? It turns out we have previously allowed IPv6
      endpoints even when IPv6 support is disabled at compile time. This is
      awkward and inconsistent. Instead, let's just ignore all things IPv6,
      the same way we do other malformed endpoints, in the case where IPv6 is
      disabled.
      
      Fixes: e7096c13
      
       ("net: WireGuard secure network tunnel")
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      efde4c0c
    • Wang Hai's avatar
      wireguard: socket: free skb in send6 when ipv6 is disabled · ebcc492f
      Wang Hai authored
      commit bbbf962d
      
       upstream.
      
      I got a memory leak report:
      
      unreferenced object 0xffff8881191fc040 (size 232):
        comm "kworker/u17:0", pid 23193, jiffies 4295238848 (age 3464.870s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<ffffffff814c3ef4>] slab_post_alloc_hook+0x84/0x3b0
          [<ffffffff814c8977>] kmem_cache_alloc_node+0x167/0x340
          [<ffffffff832974fb>] __alloc_skb+0x1db/0x200
          [<ffffffff82612b5d>] wg_socket_send_buffer_to_peer+0x3d/0xc0
          [<ffffffff8260e94a>] wg_packet_send_handshake_initiation+0xfa/0x110
          [<ffffffff8260ec81>] wg_packet_handshake_send_worker+0x21/0x30
          [<ffffffff8119c558>] process_one_work+0x2e8/0x770
          [<ffffffff8119ca2a>] worker_thread+0x4a/0x4b0
          [<ffffffff811a88e0>] kthread+0x120/0x160
          [<ffffffff8100242f>] ret_from_fork+0x1f/0x30
      
      In function wg_socket_send_buffer_as_reply_to_skb() or wg_socket_send_
      buffer_to_peer(), the semantics of send6() is required to free skb. But
      when CONFIG_IPV6 is disable, kfree_skb() is missing. This patch adds it
      to fix this bug.
      
      Signed-off-by: default avatarWang Hai <wanghai38@huawei.com>
      Fixes: e7096c13
      
       ("net: WireGuard secure network tunnel")
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ebcc492f
    • Jason A. Donenfeld's avatar
      wireguard: queueing: use CFI-safe ptr_ring cleanup function · 76abd156
      Jason A. Donenfeld authored
      commit ec59f128
      
       upstream.
      
      We make too nuanced use of ptr_ring to entirely move to the skb_array
      wrappers, but we at least should avoid the naughty function pointer cast
      when cleaning up skbs. Otherwise RAP/CFI will honk at us. This patch
      uses the __skb_array_destroy_skb wrapper for the cleanup, rather than
      directly providing kfree_skb, which is what other drivers in the same
      situation do too.
      
      Reported-by: default avatarPaX Team <pageexec@freemail.hu>
      Fixes: 886fcee9
      
       ("wireguard: receive: use ring buffer for incoming handshakes")
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      76abd156
    • Pankaj Raghav's avatar
      nvme: fix the read-only state for zoned namespaces with unsupposed features · 5a2f97d2
      Pankaj Raghav authored
      commit 726be2c7 upstream.
      
      commit 2f4c9ba2 ("nvme: export zoned namespaces without Zone Append
      support read-only") marks zoned namespaces without append support
      read-only.  It does iso by setting NVME_NS_FORCE_RO in ns->flags in
      nvme_update_zone_info and checking for that flag later in
      nvme_update_disk_info to mark the disk as read-only.
      
      But commit 73d90386 ("nvme: cleanup zone information initialization")
      rearranged nvme_update_disk_info to be called before
      nvme_update_zone_info and thus not marking the disk as read-only.
      The call order cannot be just reverted because nvme_update_zone_info sets
      certain queue parameters such as zone_write_granularity that depend on the
      prior call to nvme_update_disk_info.
      
      Remove the call to set_disk_ro in nvme_update_disk_info. and call
      set_disk_ro after nvme_update_zone_info and nvme_update_disk_info to set
      the permission for ZNS drives correctly. The same applies to the
      multipath disk path.
      
      Fixes: 73d90386
      
       ("nvme: cleanup zone information initialization")
      Signed-off-by: default avatarPankaj Raghav <p.raghav@samsung.com>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5a2f97d2
    • Sungup Moon's avatar
      nvme: allow duplicate NSIDs for private namespaces · 1e2f5b03
      Sungup Moon authored
      commit 5974ea7c upstream.
      
      A NVMe subsystem with multiple controller can have private namespaces
      that use the same NSID under some conditions:
      
       "If Namespace Management, ANA Reporting, or NVM Sets are supported, the
        NSIDs shall be unique within the NVM subsystem. If the Namespace
        Management, ANA Reporting, and NVM Sets are not supported, then NSIDs:
         a) for shared namespace shall be unique; and
         b) for private namespace are not required to be unique."
      
      Reference: Section 6.1.6 NSID and Namespace Usage; NVM Express 1.4c spec.
      
      Make sure this specific setup is supported in Linux.
      
      Fixes: 9ad1927a
      
       ("nvme: always search for namespace head")
      Signed-off-by: default avatarSungup Moon <sungup.moon@samsung.com>
      [hch: refactored and fixed the controller vs subsystem based naming
            conflict]
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1e2f5b03
    • Baokun Li's avatar
      ubifs: rename_whiteout: correct old_dir size computing · 0fbc51fb
      Baokun Li authored
      commit 70575727 upstream.
      
      When renaming the whiteout file, the old whiteout file is not deleted.
      Therefore, we add the old dentry size to the old dir like XFS.
      Otherwise, an error may be reported due to `fscki->calc_sz != fscki->size`
      in check_indes.
      
      Fixes: 9e0a1fff
      
       ("ubifs: Implement RENAME_WHITEOUT")
      Reported-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarBaokun Li <libaokun1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0fbc51fb
    • Zhihao Cheng's avatar
      ubifs: Fix to add refcount once page is set private · 5aaa2c0f
      Zhihao Cheng authored
      commit 3b67db8a upstream.
      
      MM defined the rule [1] very clearly that once page was set with PG_private
      flag, we should increment the refcount in that page, also main flows like
      pageout(), migrate_page() will assume there is one additional page
      reference count if page_has_private() returns true. Otherwise, we may
      get a BUG in page migration:
      
        page:0000000080d05b9d refcount:-1 mapcount:0 mapping:000000005f4d82a8
        index:0xe2 pfn:0x14c12
        aops:ubifs_file_address_operations [ubifs] ino:8f1 dentry name:"f30e"
        flags: 0x1fffff80002405(locked|uptodate|owner_priv_1|private|node=0|
        zone=1|lastcpupid=0x1fffff)
        page dumped because: VM_BUG_ON_PAGE(page_count(page) != 0)
        ------------[ cut here ]------------
        kernel BUG at include/linux/page_ref.h:184!
        invalid opcode: 0000 [#1] SMP
        CPU: 3 PID: 38 Comm: kcompactd0 Not tainted 5.15.0-rc5
        RIP: 0010:migrate_page_move_mapping+0xac3/0xe70
        Call Trace:
          ubifs_migrate_page+0x22/0xc0 [ubifs]
          move_to_new_page+0xb4/0x600
          migrate_pages+0x1523/0x1cc0
          compact_zone+0x8c5/0x14b0
          kcompactd+0x2bc/0x560
          kthread+0x18c/0x1e0
          ret_from_fork+0x1f/0x30
      
      Before the time, we should make clean a concept, what does refcount means
      in page gotten from grab_cache_page_write_begin(). There are 2 situations:
      Situation 1: refcount is 3, page is created by __page_cache_alloc.
        TYPE_A - the write process is using this page
        TYPE_B - page is assigned to one certain mapping by calling
      	   __add_to_page_cache_locked()
        TYPE_C - page is added into pagevec list corresponding current cpu by
      	   calling lru_cache_add()
      Situation 2: refcount is 2, page is gotten from the mapping's tree
        TYPE_B - page has been assigned to one certain mapping
        TYPE_A - the write process is using this page (by calling
      	   page_cache_get_speculative())
      Filesystem releases one refcount by calling put_page() in xxx_write_end(),
      the released refcount corresponds to TYPE_A (write task is using it). If
      there are any processes using a page, page migration process will skip the
      page by judging whether expected_page_refs() equals to page refcount.
      
      The BUG is caused by following process:
          PA(cpu 0)                           kcompactd(cpu 1)
      				compact_zone
      ubifs_write_begin
        page_a = grab_cache_page_write_begin
          add_to_page_cache_lru
            lru_cache_add
              pagevec_add // put page into cpu 0's pagevec
        (refcnf = 3, for page creation process)
      ubifs_write_end
        SetPagePrivate(page_a) // doesn't increase page count !
        unlock_page(page_a)
        put_page(page_a)  // refcnt = 2
      				[...]
      
          PB(cpu 0)
      filemap_read
        filemap_get_pages
          add_to_page_cache_lru
            lru_cache_add
              __pagevec_lru_add // traverse all pages in cpu 0's pagevec
      	  __pagevec_lru_add_fn
      	    SetPageLRU(page_a)
      				isolate_migratepages
                                        isolate_migratepages_block
      				    get_page_unless_zero(page_a)
      				    // refcnt = 3
                                            list_add(page_a, from_list)
      				migrate_pages(from_list)
      				  __unmap_and_move
      				    move_to_new_page
      				      ubifs_migrate_page(page_a)
      				        migrate_page_move_mapping
      					  expected_page_refs get 3
                                        (migration[1] + mapping[1] + private[1])
      	 release_pages
      	   put_page_testzero(page_a) // refcnt = 3
                                                page_ref_freeze  // refcnt = 0
      	     page_ref_dec_and_test(0 - 1 = -1)
                                                page_ref_unfreeze
                                                  VM_BUG_ON_PAGE(-1 != 0, page)
      
      UBIFS doesn't increase the page refcount after setting private flag, which
      leads to page migration task believes the page is not used by any other
      processes, so the page is migrated. This causes concurrent accessing on
      page refcount between put_page() called by other process(eg. read process
      calls lru_cache_add) and page_ref_unfreeze() called by migration task.
      
      Actually zhangjun has tried to fix this problem [2] by recalculating page
      refcnt in ubifs_migrate_page(). It's better to follow MM rules [1], because
      just like Kirill suggested in [2], we need to check all users of
      page_has_private() helper. Like f2fs does in [3], fix it by adding/deleting
      refcount when setting/clearing private for a page. BTW, according to [4],
      we set 'page->private' as 1 because ubifs just simply SetPagePrivate().
      And, [5] provided a common helper to set/clear page private, ubifs can
      use this helper following the example of iomap, afs, btrfs, etc.
      
      Jump [6] to find a reproducer.
      
      [1] https://lore.kernel.org/lkml/2b19b3c4-2bc4-15fa-15cc-27a13e5c7af1@aol.com
      [2] https://www.spinics.net/lists/linux-mtd/msg04018.html
      [3] http://lkml.iu.edu/hypermail/linux/kernel/1903.0/03313.html
      [4] https://lore.kernel.org/linux-f2fs-devel/20210422154705.GO3596236@casper.infradead.org
      [5] https://lore.kernel.org/all/20200517214718.468-1-guoqing.jiang@cloud.ionos.com
      [6] https://bugzilla.kernel.org/show_bug.cgi?id=214961
      
      Fixes: 1e51764a
      
       ("UBIFS: add new flash file system")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5aaa2c0f
    • Zhihao Cheng's avatar
      ubifs: Fix read out-of-bounds in ubifs_wbuf_write_nolock() · e09fa531
      Zhihao Cheng authored
      commit 4f2262a3 upstream.
      
      Function ubifs_wbuf_write_nolock() may access buf out of bounds in
      following process:
      
      ubifs_wbuf_write_nolock():
        aligned_len = ALIGN(len, 8);   // Assume len = 4089, aligned_len = 4096
        if (aligned_len <= wbuf->avail) ... // Not satisfy
        if (wbuf->used) {
          ubifs_leb_write()  // Fill some data in avail wbuf
          len -= wbuf->avail;   // len is still not 8-bytes aligned
          aligned_len -= wbuf->avail;
        }
        n = aligned_len >> c->max_write_shift;
        if (n) {
          n <<= c->max_write_shift;
          err = ubifs_leb_write(c, wbuf->lnum, buf + written,
                                wbuf->offs, n);
          // n > len, read out of bounds less than 8(n-len) bytes
        }
      
      , which can be catched by KASAN:
        =========================================================
        BUG: KASAN: slab-out-of-bounds in ecc_sw_hamming_calculate+0x1dc/0x7d0
        Read of size 4 at addr ffff888105594ff8 by task kworker/u8:4/128
        Workqueue: writeback wb_workfn (flush-ubifs_0_0)
        Call Trace:
          kasan_report.cold+0x81/0x165
          nand_write_page_swecc+0xa9/0x160
          ubifs_leb_write+0xf2/0x1b0 [ubifs]
          ubifs_wbuf_write_nolock+0x421/0x12c0 [ubifs]
          write_head+0xdc/0x1c0 [ubifs]
          ubifs_jnl_write_inode+0x627/0x960 [ubifs]
          wb_workfn+0x8af/0xb80
      
      Function ubifs_wbuf_write_nolock() accepts that parameter 'len' is not 8
      bytes aligned, the 'len' represents the true length of buf (which is
      allocated in 'ubifs_jnl_xxx', eg. ubifs_jnl_write_inode), so
      ubifs_wbuf_write_nolock() must handle the length read from 'buf' carefully
      to write leb safely.
      
      Fetch a reproducer in [Link].
      
      Fixes: 1e51764a
      
       ("UBIFS: add new flash file system")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=214785
      Reported-by: default avatarChengsong Ke <kechengsong@huawei.com>
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e09fa531
    • Zhihao Cheng's avatar
      ubifs: setflags: Make dirtied_ino_d 8 bytes aligned · 560774cc
      Zhihao Cheng authored
      commit 1b83ec05 upstream.
      
      Make 'ui->data_len' aligned with 8 bytes before it is assigned to
      dirtied_ino_d. Since 8871d84c("ubifs: convert to fileattr")
      applied, 'setflags()' only affects regular files and directories, only
      xattr inode, symlink inode and special inode(pipe/char_dev/block_dev)
      have none- zero 'ui->data_len' field, so assertion
      '!(req->dirtied_ino_d & 7)' cannot fail in ubifs_budget_space().
      To avoid assertion fails in future evolution(eg. setflags can operate
      special inodes), it's better to make dirtied_ino_d 8 bytes aligned,
      after all aligned size is still zero for regular files.
      
      Fixes: 1e51764a
      
       ("UBIFS: add new flash file system")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      560774cc
    • Zhihao Cheng's avatar
      ubifs: Rectify space amount budget for mkdir/tmpfile operations · de407bf5
      Zhihao Cheng authored
      commit a6dab660 upstream.
      
      UBIFS should make sure the flash has enough space to store dirty (Data
      that is newer than disk) data (in memory), space budget is exactly
      designed to do that. If space budget calculates less data than we need,
      'make_reservation()' will do more work(return -ENOSPC if no free space
      lelf, sometimes we can see "cannot reserve xxx bytes in jhead xxx, error
      -28" in ubifs error messages) with ubifs inodes locked, which may effect
      other syscalls.
      
      A simple way to decide how much space do we need when make a budget:
      See how much space is needed by 'make_reservation()' in ubifs_jnl_xxx()
      function according to corresponding operation.
      
      It's better to report ENOSPC in ubifs_budget_space(), as early as we can.
      
      Fixes: 474b9370 ("ubifs: Implement O_TMPFILE")
      Fixes: 1e51764a
      
       ("UBIFS: add new flash file system")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      de407bf5
    • Zhihao Cheng's avatar
      ubifs: Fix 'ui->dirty' race between do_tmpfile() and writeback work · f3bdd3b7
      Zhihao Cheng authored
      commit 60eb3b9c upstream.
      
      'ui->dirty' is not protected by 'ui_mutex' in function do_tmpfile() which
      may race with ubifs_write_inode[wb_workfn] to access/update 'ui->dirty',
      finally dirty space is released twice.
      
      	open(O_TMPFILE)                wb_workfn
      do_tmpfile
        ubifs_budget_space(ino_req = { .dirtied_ino = 1})
        d_tmpfile // mark inode(tmpfile) dirty
        ubifs_jnl_update // without holding tmpfile's ui_mutex
          mark_inode_clean(ui)
            if (ui->dirty)
              ubifs_release_dirty_inode_budget(ui)  // release first time
                                         ubifs_write_inode
      				     mutex_lock(&ui->ui_mutex)
                                           ubifs_release_dirty_inode_budget(ui)
      				     // release second time
      				     mutex_unlock(&ui->ui_mutex)
            ui->dirty = 0
      
      Run generic/476 can reproduce following message easily
      (See reproducer in [Link]):
      
        UBIFS error (ubi0:0 pid 2578): ubifs_assert_failed [ubifs]: UBIFS assert
        failed: c->bi.dd_growth >= 0, in fs/ubifs/budget.c:554
        UBIFS warning (ubi0:0 pid 2578): ubifs_ro_mode [ubifs]: switched to
        read-only mode, error -22
        Workqueue: writeback wb_workfn (flush-ubifs_0_0)
        Call Trace:
          ubifs_ro_mode+0x54/0x60 [ubifs]
          ubifs_assert_failed+0x4b/0x80 [ubifs]
          ubifs_release_budget+0x468/0x5a0 [ubifs]
          ubifs_release_dirty_inode_budget+0x53/0x80 [ubifs]
          ubifs_write_inode+0x121/0x1f0 [ubifs]
          ...
          wb_workfn+0x283/0x7b0
      
      Fix it by holding tmpfile ubifs inode lock during ubifs_jnl_update().
      Similar problem exists in whiteout renaming, but previous fix("ubifs:
      Rename whiteout atomically") has solved the problem.
      
      Fixes: 474b9370
      
       ("ubifs: Implement O_TMPFILE")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=214765
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f3bdd3b7
    • Zhihao Cheng's avatar
      ubifs: Rename whiteout atomically · 17495eb2
      Zhihao Cheng authored
      commit 278d9a24 upstream.
      
      Currently, rename whiteout has 3 steps:
        1. create tmpfile(which associates old dentry to tmpfile inode) for
           whiteout, and store tmpfile to disk
        2. link whiteout, associate whiteout inode to old dentry agagin and
           store old dentry, old inode, new dentry on disk
        3. writeback dirty whiteout inode to disk
      
      Suddenly power-cut or error occurring(eg. ENOSPC returned by budget,
      memory allocation failure) during above steps may cause kinds of problems:
        Problem 1: ENOSPC returned by whiteout space budget (before step 2),
      	     old dentry will disappear after rename syscall, whiteout file
      	     cannot be found either.
      
      	     ls dir  // we get file, whiteout
      	     rename(dir/file, dir/whiteout, REANME_WHITEOUT)
      	     ENOSPC = ubifs_budget_space(&wht_req) // return
      	     ls dir  // empty (no file, no whiteout)
        Problem 2: Power-cut happens before step 3, whiteout inode with 'nlink=1'
      	     is not stored on disk, whiteout dentry(old dentry) is written
      	     on disk, whiteout file is lost on next mount (We get "dead
      	     directory entry" after executing 'ls -l' on whiteout file).
      
      Now, we use following 3 steps to finish rename whiteout:
        1. create an in-mem inode with 'nlink = 1' as whiteout
        2. ubifs_jnl_rename (Write on disk to finish associating old dentry to
           whiteout inode, associating new dentry with old inode)
        3. iput(whiteout)
      
      Rely writing in-mem inode on disk by ubifs_jnl_rename() to finish rename
      whiteout, which avoids middle disk state caused by suddenly power-cut
      and error occurring.
      
      Fixes: 9e0a1fff
      
       ("ubifs: Implement RENAME_WHITEOUT")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      17495eb2
    • Zhihao Cheng's avatar
      ubifs: Add missing iput if do_tmpfile() failed in rename whiteout · b0ef56ea
      Zhihao Cheng authored
      commit 716b4573 upstream.
      
      whiteout inode should be put when do_tmpfile() failed if inode has been
      initialized. Otherwise we will get following warning during umount:
        UBIFS error (ubi0:0 pid 1494): ubifs_assert_failed [ubifs]: UBIFS
        assert failed: c->bi.dd_growth == 0, in fs/ubifs/super.c:1930
        VFS: Busy inodes after unmount of ubifs. Self-destruct in 5 seconds.
      
      Fixes: 9e0a1fff
      
       ("ubifs: Implement RENAME_WHITEOUT")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Suggested-by: default avatarSascha Hauer <s.hauer@pengutronix.de>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b0ef56ea
    • Zhihao Cheng's avatar
      ubifs: Fix deadlock in concurrent rename whiteout and inode writeback · 70e9090a
      Zhihao Cheng authored
      commit afd42704 upstream.
      
      Following hung tasks:
      [   77.028764] task:kworker/u8:4    state:D stack:    0 pid:  132
      [   77.028820] Call Trace:
      [   77.029027]  schedule+0x8c/0x1b0
      [   77.029067]  mutex_lock+0x50/0x60
      [   77.029074]  ubifs_write_inode+0x68/0x1f0 [ubifs]
      [   77.029117]  __writeback_single_inode+0x43c/0x570
      [   77.029128]  writeback_sb_inodes+0x259/0x740
      [   77.029148]  wb_writeback+0x107/0x4d0
      [   77.029163]  wb_workfn+0x162/0x7b0
      
      [   92.390442] task:aa              state:D stack:    0 pid: 1506
      [   92.390448] Call Trace:
      [   92.390458]  schedule+0x8c/0x1b0
      [   92.390461]  wb_wait_for_completion+0x82/0xd0
      [   92.390469]  __writeback_inodes_sb_nr+0xb2/0x110
      [   92.390472]  writeback_inodes_sb_nr+0x14/0x20
      [   92.390476]  ubifs_budget_space+0x705/0xdd0 [ubifs]
      [   92.390503]  do_rename.cold+0x7f/0x187 [ubifs]
      [   92.390549]  ubifs_rename+0x8b/0x180 [ubifs]
      [   92.390571]  vfs_rename+0xdb2/0x1170
      [   92.390580]  do_renameat2+0x554/0x770
      
      , are caused by concurrent rename whiteout and inode writeback processes:
      	rename_whiteout(Thread 1)	        wb_workfn(Thread2)
      ubifs_rename
        do_rename
          lock_4_inodes (Hold ui_mutex)
          ubifs_budget_space
            make_free_space
              shrink_liability
      	  __writeback_inodes_sb_nr
      	    bdi_split_work_to_wbs (Queue new wb work)
      					      wb_do_writeback(wb work)
      						__writeback_single_inode
      					          ubifs_write_inode
      					            LOCK(ui_mutex)
      							   ↑
      	      wb_wait_for_completion (Wait wb work) <-- deadlock!
      
      Reproducer (Detail program in [Link]):
        1. SYS_renameat2("/mp/dir/file", "/mp/dir/whiteout", RENAME_WHITEOUT)
        2. Consume out of space before kernel(mdelay) doing budget for whiteout
      
      Fix it by doing whiteout space budget before locking ubifs inodes.
      BTW, it also fixes wrong goto tag 'out_release' in whiteout budget
      error handling path(It should at least recover dir i_size and unlock
      4 ubifs inodes).
      
      Fixes: 9e0a1fff
      
       ("ubifs: Implement RENAME_WHITEOUT")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=214733
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      70e9090a
    • Zhihao Cheng's avatar
      ubifs: rename_whiteout: Fix double free for whiteout_ui->data · b9a937f0
      Zhihao Cheng authored
      commit 40a8f0d5 upstream.
      
      'whiteout_ui->data' will be freed twice if space budget fail for
      rename whiteout operation as following process:
      
      rename_whiteout
        dev = kmalloc
        whiteout_ui->data = dev
        kfree(whiteout_ui->data)  // Free first time
        iput(whiteout)
          ubifs_free_inode
            kfree(ui->data)	    // Double free!
      
      KASAN reports:
      ==================================================================
      BUG: KASAN: double-free or invalid-free in ubifs_free_inode+0x4f/0x70
      Call Trace:
        kfree+0x117/0x490
        ubifs_free_inode+0x4f/0x70 [ubifs]
        i_callback+0x30/0x60
        rcu_do_batch+0x366/0xac0
        __do_softirq+0x133/0x57f
      
      Allocated by task 1506:
        kmem_cache_alloc_trace+0x3c2/0x7a0
        do_rename+0x9b7/0x1150 [ubifs]
        ubifs_rename+0x106/0x1f0 [ubifs]
        do_syscall_64+0x35/0x80
      
      Freed by task 1506:
        kfree+0x117/0x490
        do_rename.cold+0x53/0x8a [ubifs]
        ubifs_rename+0x106/0x1f0 [ubifs]
        do_syscall_64+0x35/0x80
      
      The buggy address belongs to the object at ffff88810238bed8 which
      belongs to the cache kmalloc-8 of size 8
      ==================================================================
      
      Let ubifs_free_inode() free 'whiteout_ui->data'. BTW, delete unused
      assignment 'whiteout_ui->data_len = 0', process 'ubifs_evict_inode()
      -> ubifs_jnl_delete_inode() -> ubifs_jnl_write_inode()' doesn't need it
      (because 'inc_nlink(whiteout)' won't be excuted by 'goto out_release',
       and the nlink of whiteout inode is 0).
      
      Fixes: 9e0a1fff
      
       ("ubifs: Implement RENAME_WHITEOUT")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b9a937f0
    • Yi Wang's avatar
      KVM: SVM: fix panic on out-of-bounds guest IRQ · e4d153d5
      Yi Wang authored
      commit a80ced6e upstream.
      
      As guest_irq is coming from KVM_IRQFD API call, it may trigger
      crash in svm_update_pi_irte() due to out-of-bounds:
      
      crash> bt
      PID: 22218  TASK: ffff951a6ad74980  CPU: 73  COMMAND: "vcpu8"
       #0 [ffffb1ba6707fa40] machine_kexec at ffffffff8565b397
       #1 [ffffb1ba6707fa90] __crash_kexec at ffffffff85788a6d
       #2 [ffffb1ba6707fb58] crash_kexec at ffffffff8578995d
       #3 [ffffb1ba6707fb70] oops_end at ffffffff85623c0d
       #4 [ffffb1ba6707fb90] no_context at ffffffff856692c9
       #5 [ffffb1ba6707fbf8] exc_page_fault at ffffffff85f95b51
       #6 [ffffb1ba6707fc50] asm_exc_page_fault at ffffffff86000ace
          [exception RIP: svm_update_pi_irte+227]
          RIP: ffffffffc0761b53  RSP: ffffb1ba6707fd08  RFLAGS: 00010086
          RAX: ffffb1ba6707fd78  RBX: ffffb1ba66d91000  RCX: 0000000000000001
          RDX: 00003c803f63f1c0  RSI: 000000000000019a  RDI: ffffb1ba66db2ab8
          RBP: 000000000000019a   R8: 0000000000000040   R9: ffff94ca41b82200
          R10: ffffffffffffffcf  R11: 0000000000000001  R12: 0000000000000001
          R13: 0000000000000001  R14: ffffffffffffffcf  R15: 000000000000005f
          ORIG_RAX: ffffffffffffffff  CS: 0010  SS: 0018
       #7 [ffffb1ba6707fdb8] kvm_irq_routing_update at ffffffffc09f19a1 [kvm]
       #8 [ffffb1ba6707fde0] kvm_set_irq_routing at ffffffffc09f2133 [kvm]
       #9 [ffffb1ba6707fe18] kvm_vm_ioctl at ffffffffc09ef544 [kvm]
          RIP: 00007f143c36488b  RSP: 00007f143a4e04b8  RFLAGS: 00000246
          RAX: ffffffffffffffda  RBX: 00007f05780041d0  RCX: 00007f143c36488b
          RDX: 00007f05780041d0  RSI: 000000004008ae6a  RDI: 0000000000000020
          RBP: 00000000000004e8   R8: 0000000000000008   R9: 00007f05780041e0
          R10: 00007f0578004560  R11: 0000000000000246  R12: 00000000000004e0
          R13: 000000000000001a  R14: 00007f1424001c60  R15: 00007f0578003bc0
          ORIG_RAX: 0000000000000010  CS: 0033  SS: 002b
      
      Vmx have been fix this in commit 3a8b0677
      
       (KVM: VMX: Do not BUG() on
      out-of-bounds guest IRQ), so we can just copy source from that to fix
      this.
      
      Co-developed-by: default avatarYi Liu <liu.yi24@zte.com.cn>
      Signed-off-by: default avatarYi Liu <liu.yi24@zte.com.cn>
      Signed-off-by: default avatarYi Wang <wang.yi59@zte.com.cn>
      Message-Id: <20220309113025.44469-1-wang.yi59@zte.com.cn>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e4d153d5
    • Li RongQing's avatar
      KVM: x86: fix sending PV IPI · de3af9b2
      Li RongQing authored
      commit c15e0ae4 upstream.
      
      If apic_id is less than min, and (max - apic_id) is greater than
      KVM_IPI_CLUSTER_SIZE, then the third check condition is satisfied but
      the new apic_id does not fit the bitmask.  In this case __send_ipi_mask
      should send the IPI.
      
      This is mostly theoretical, but it can happen if the apic_ids on three
      iterations of the loop are for example 1, KVM_IPI_CLUSTER_SIZE, 0.
      
      Fixes: aaffcfd1
      
       ("KVM: X86: Implement PV IPIs in linux guest")
      Signed-off-by: default avatarLi RongQing <lirongqing@baidu.com>
      Message-Id: <1646814944-51801-1-git-send-email-lirongqing@baidu.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      de3af9b2
    • David Matlack's avatar
      KVM: Prevent module exit until all VMs are freed · 2ec90e21
      David Matlack authored
      commit 5f6de5cb upstream.
      
      Tie the lifetime the KVM module to the lifetime of each VM via
      kvm.users_count. This way anything that grabs a reference to the VM via
      kvm_get_kvm() cannot accidentally outlive the KVM module.
      
      Prior to this commit, the lifetime of the KVM module was tied to the
      lifetime of /dev/kvm file descriptors, VM file descriptors, and vCPU
      file descriptors by their respective file_operations "owner" field.
      This approach is insufficient because references grabbed via
      kvm_get_kvm() do not prevent closing any of the aforementioned file
      descriptors.
      
      This fixes a long standing theoretical bug in KVM that at least affects
      async page faults. kvm_setup_async_pf() grabs a reference via
      kvm_get_kvm(), and drops it in an asynchronous work callback. Nothing
      prevents the VM file descriptor from being closed and the KVM module
      from being unloaded before this callback runs.
      
      Fixes: af585b92 ("KVM: Halt vcpu if page it tries to access is swapped out")
      Fixes: 3d3aab1b
      
       ("KVM: set owner of cpu and vm file operations")
      Cc: stable@vger.kernel.org
      Suggested-by: default avatarBen Gardon <bgardon@google.com>
      [ Based on a patch from Ben implemented for Google's kernel. ]
      Signed-off-by: default avatarDavid Matlack <dmatlack@google.com>
      Message-Id: <20220303183328.1499189-2-dmatlack@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2ec90e21
    • Vitaly Kuznetsov's avatar
      KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated · e094afbd
      Vitaly Kuznetsov authored
      commit b1e34d32
      
       upstream.
      
      Setting non-zero values to SYNIC/STIMER MSRs activates certain features,
      this should not happen when KVM_CAP_HYPERV_SYNIC{,2} was not activated.
      
      Note, it would've been better to forbid writing anything to SYNIC/STIMER
      MSRs, including zeroes, however, at least QEMU tries clearing
      HV_X64_MSR_STIMER0_CONFIG without SynIC. HV_X64_MSR_EOM MSR is somewhat
      'special' as writing zero there triggers an action, this also should not
      happen when SynIC wasn't activated.
      
      Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20220325132140.25650-4-vkuznets@redhat.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e094afbd
    • Vitaly Kuznetsov's avatar
      KVM: x86: Avoid theoretical NULL pointer dereference in kvm_irq_delivery_to_apic_fast() · 9e38128f
      Vitaly Kuznetsov authored
      commit 00b5f371
      
       upstream.
      
      When kvm_irq_delivery_to_apic_fast() is called with APIC_DEST_SELF
      shorthand, 'src' must not be NULL. Crash the VM with KVM_BUG_ON()
      instead of crashing the host.
      
      Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20220325132140.25650-3-vkuznets@redhat.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9e38128f
    • Vitaly Kuznetsov's avatar
      KVM: x86: Check lapic_in_kernel() before attempting to set a SynIC irq · 6e3cd49a
      Vitaly Kuznetsov authored
      commit 7ec37d1c
      
       upstream.
      
      When KVM_CAP_HYPERV_SYNIC{,2} is activated, KVM already checks for
      irqchip_in_kernel() so normally SynIC irqs should never be set. It is,
      however,  possible for a misbehaving VMM to write to SYNIC/STIMER MSRs
      causing erroneous behavior.
      
      The immediate issue being fixed is that kvm_irq_delivery_to_apic()
      (kvm_irq_delivery_to_apic_fast()) crashes when called with
      'irq.shorthand = APIC_DEST_SELF' and 'src == NULL'.
      
      Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20220325132140.25650-2-vkuznets@redhat.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6e3cd49a
    • Paul Cercueil's avatar
      MIPS: crypto: Fix CRC32 code · 33ccdb74
      Paul Cercueil authored
      commit 41022eff upstream.
      
      Commit 67512a8c ("MIPS: Avoid macro redefinitions") changed how the
      MIPS register macros were defined, in order to allow the code to compile
      under LLVM/Clang.
      
      The MIPS CRC32 code however wasn't updated accordingly, causing a build
      bug when using a MIPS32r6 toolchain without CRC support.
      
      Update the CRC32 code to use the macros correctly, to fix the build
      failures.
      
      Fixes: 67512a8c
      
       ("MIPS: Avoid macro redefinitions")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Signed-off-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      33ccdb74
    • Gwendal Grignou's avatar
      platform: chrome: Split trace include file · 0ea93956
      Gwendal Grignou authored
      commit eabd9a38 upstream.
      
      cros_ec_trace.h defined 5 tracing events, 2 for cros_ec_proto and
      3 for cros_ec_sensorhub_ring.
      These 2 files are in different kernel modules, the traces are defined
      twice in the kernel which leads to problem enabling only some traces.
      
      Move sensorhub traces from cros_ec_trace.h to cros_ec_sensorhub_trace.h
      and enable them only in cros_ec_sensorhub kernel module.
      
      Check we can now enable any single traces: without this patch,
      we can only enable all sensorhub traces or none.
      
      Fixes: d453ceb6
      
       ("platform/chrome: sensorhub: Add trace events for sample")
      
      Signed-off-by: default avatarGwendal Grignou <gwendal@chromium.org>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20220122001301.640337-1-gwendal@chromium.org
      Signed-off-by: default avatarBenson Leung <bleung@chromium.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0ea93956
    • Manish Rangankar's avatar
      scsi: qla2xxx: Use correct feature type field during RFF_ID processing · 5f731907
      Manish Rangankar authored
      commit a7e05f7a upstream.
      
      During SNS Register FC-4 Features (RFF_ID) the initiator driver was sending
      incorrect type field for NVMe supported device. Use correct feature type
      field.
      
      Link: https://lore.kernel.org/r/20220310092604.22950-12-njavali@marvell.com
      Fixes: e374f9f5
      
       ("scsi: qla2xxx: Migrate switch registration commands away from mailbox interface")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
      Signed-off-by: default avatarManish Rangankar <mrangankar@marvell.com>
      Signed-off-by: default avatarNilesh Javali <njavali@marvell.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5f731907
    • Quinn Tran's avatar
      scsi: qla2xxx: Reduce false trigger to login · 7e811bc2
      Quinn Tran authored
      commit d2646eed upstream.
      
      While a session is in the middle of a relogin, a late RSCN can be delivered
      from switch. RSCN trigger fabric scan where the scan logic can trigger
      another session login while a login is in progress.  Reduce the extra
      trigger to prevent multiple logins to the same session.
      
      Link: https://lore.kernel.org/r/20220310092604.22950-10-njavali@marvell.com
      Fixes: bee8b846
      
       ("scsi: qla2xxx: Reduce redundant ADISC command for RSCNs")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
      Signed-off-by: default avatarQuinn Tran <qutran@marvell.com>
      Signed-off-by: default avatarNilesh Javali <njavali@marvell.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7e811bc2
    • Quinn Tran's avatar
      scsi: qla2xxx: Fix stuck session of PRLI reject · 48e5bb73
      Quinn Tran authored
      commit f3502e2e upstream.
      
      Remove stale recovery code that prevents normal path recovery.
      
      Link: https://lore.kernel.org/r/20220310092604.22950-11-njavali@marvell.com
      Fixes: 1cbc0efc
      
       ("scsi: qla2xxx: Fix retry for PRLI RJT with reason of BUSY")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
      Signed-off-by: default avatarQuinn Tran <qutran@marvell.com>
      Signed-off-by: default avatarNilesh Javali <njavali@marvell.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      48e5bb73
    • Quinn Tran's avatar
      scsi: qla2xxx: Fix N2N inconsistent PLOGI · 60859466
      Quinn Tran authored
      commit c13ce47c upstream.
      
      For N2N topology, ELS Passthrough is used to send PLOGI. On failure of ELS
      pass through PLOGI, driver flipped over to using LLIOCB PLOGI for N2N. This
      is not consistent. Delete the session to restart the connection where ELS
      pass through PLOGI would be used consistently.
      
      Link: https://lore.kernel.org/r/20220310092604.22950-7-njavali@marvell.com
      Fixes: c76ae845
      
       ("scsi: qla2xxx: Add error handling for PLOGI ELS passthrough")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
      Signed-off-by: default avatarQuinn Tran <qutran@marvell.com>
      Signed-off-by: default avatarNilesh Javali <njavali@marvell.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      60859466
    • Arun Easi's avatar
      scsi: qla2xxx: Fix crash during module load unload test · 213e57b4
      Arun Easi authored
      commit 09722524 upstream.
      
      During purex packet handling the driver was incorrectly freeing a
      pre-allocated structure. Fix this by skipping that entry.
      
      System crashed with the following stack during a module unload test.
      
      Call Trace:
      	sbitmap_init_node+0x7f/0x1e0
      	sbitmap_queue_init_node+0x24/0x150
      	blk_mq_init_bitmaps+0x3d/0xa0
      	blk_mq_init_tags+0x68/0x90
      	blk_mq_alloc_map_and_rqs+0x44/0x120
      	blk_mq_alloc_set_map_and_rqs+0x63/0x150
      	blk_mq_alloc_tag_set+0x11b/0x230
      	scsi_add_host_with_dma.cold+0x3f/0x245
      	qla2x00_probe_one+0xd5a/0x1b80 [qla2xxx]
      
      Call Trace with slub_debug and debug kernel:
      	kasan_report_invalid_free+0x50/0x80
      	__kasan_slab_free+0x137/0x150
      	slab_free_freelist_hook+0xc6/0x190
      	kfree+0xe8/0x2e0
      	qla2x00_free_device+0x3bb/0x5d0 [qla2xxx]
      	qla2x00_remove_one+0x668/0xcf0 [qla2xxx]
      
      Link: https://lore.kernel.org/r/20220310092604.22950-6-njavali@marvell.com
      Fixes: 62e9dd17
      
       ("scsi: qla2xxx: Change in PUREX to handle FPIN ELS requests")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarMarco Patalano <mpatalan@redhat.com>
      Tested-by: default avatarMarco Patalano <mpatalan@redhat.com>
      Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
      Signed-off-by: default avatarArun Easi <aeasi@marvell.com>
      Signed-off-by: default avatarNilesh Javali <njavali@marvell.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      213e57b4
    • Arun Easi's avatar
      scsi: qla2xxx: Fix missed DMA unmap for NVMe ls requests · 97653190
      Arun Easi authored
      commit c85ab7d9 upstream.
      
      At NVMe ELS request time, request structure is DMA mapped and never
      unmapped. Fix this by calling the unmap on ELS completion.
      
      Link: https://lore.kernel.org/r/20220310092604.22950-5-njavali@marvell.com
      Fixes: e84067d7
      
       ("scsi: qla2xxx: Add FC-NVMe F/W initialization and transport registration")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
      Signed-off-by: default avatarArun Easi <aeasi@marvell.com>
      Signed-off-by: default avatarNilesh Javali <njavali@marvell.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      97653190
    • Quinn Tran's avatar
      scsi: qla2xxx: Fix laggy FC remote port session recovery · 42bc54f1
      Quinn Tran authored
      commit 713b4157 upstream.
      
      For session recovery, driver relies on the dpc thread to initiate certain
      operations. The dpc thread runs exclusively without the Mailbox interface
      being occupied. A recent code change for heartbeat check via mailbox cmd 0
      is preventing the dpc thread from carrying out its operation. This patch
      allows the higher priority error recovery to run first before running the
      lower priority heartbeat check.
      
      Link: https://lore.kernel.org/r/20220310092604.22950-9-njavali@marvell.com
      Fixes: d94d8158
      
       ("scsi: qla2xxx: Add heartbeat check")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
      Signed-off-by: default avatarQuinn Tran <qutran@marvell.com>
      Signed-off-by: default avatarNilesh Javali <njavali@marvell.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      42bc54f1
    • Quinn Tran's avatar
      scsi: qla2xxx: Fix hang due to session stuck · cce5e013
      Quinn Tran authored
      commit c02aada0 upstream.
      
      User experienced device lost. The log shows Get port data base command was
      queued up, failed, and requeued again. Every time it is requeued, it set
      the FCF_ASYNC_ACTIVE. This prevents any recovery code from occurring
      because driver thinks a recovery is in progress for this session. In
      essence, this session is hung.  The reason it gets into this place is the
      session deletion got in front of this call due to link perturbation.
      
      Break the requeue cycle and exit.  The session deletion code will trigger a
      session relogin.
      
      Link: https://lore.kernel.org/r/20220310092604.22950-8-njavali@marvell.com
      Fixes: 726b8548
      
       ("qla2xxx: Add framework for async fabric discovery")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
      Signed-off-by: default avatarQuinn Tran <qutran@marvell.com>
      Signed-off-by: default avatarNilesh Javali <njavali@marvell.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cce5e013