Skip to content
  1. Dec 14, 2023
    • Greg Kroah-Hartman's avatar
      Linux 5.4.264 · 16e6e107
      Greg Kroah-Hartman authored
      
      
      Link: https://lore.kernel.org/r/20231211182015.049134368@linuxfoundation.org
      Tested-by: default avatarFlorian Fainelli <florian.fainelli@broadcom.com>
      Tested-by: default avatarHarshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
      Tested-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Tested-by: default avatarLinux Kernel Functional Testing <lkft@linaro.org>
      Tested-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      v5.4.264
      16e6e107
    • Mukesh Ojha's avatar
      devcoredump: Send uevent once devcd is ready · 06bcac5c
      Mukesh Ojha authored
      [ Upstream commit af54d778 ]
      
      dev_coredumpm() creates a devcoredump device and adds it
      to the core kernel framework which eventually end up
      sending uevent to the user space and later creates a
      symbolic link to the failed device. An application
      running in userspace may be interested in this symbolic
      link to get the name of the failed device.
      
      In a issue scenario, once uevent sent to the user space
      it start reading '/sys/class/devcoredump/devcdX/failing_device'
      to get the actual name of the device which might not been
      created and it is in its path of creation.
      
      To fix this, suppress sending uevent till the failing device
      symbolic link gets created and send uevent once symbolic
      link is created successfully.
      
      Fixes: 833c9545
      
       ("device coredump: add new device coredump class")
      Signed-off-by: default avatarMukesh Ojha <quic_mojha@quicinc.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/1700232572-25823-1-git-send-email-quic_mojha@quicinc.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      06bcac5c
    • Mukesh Ojha's avatar
      devcoredump : Serialize devcd_del work · c6a1282e
      Mukesh Ojha authored
      [ Upstream commit 01daccf7
      
       ]
      
      In following scenario(diagram), when one thread X running dev_coredumpm()
      adds devcd device to the framework which sends uevent notification to
      userspace and another thread Y reads this uevent and call to
      devcd_data_write() which eventually try to delete the queued timer that
      is not initialized/queued yet.
      
      So, debug object reports some warning and in the meantime, timer is
      initialized and queued from X path. and from Y path, it gets reinitialized
      again and timer->entry.pprev=NULL and try_to_grab_pending() stucks.
      
      To fix this, introduce mutex and a boolean flag to serialize the behaviour.
      
       	cpu0(X)			                cpu1(Y)
      
          dev_coredump() uevent sent to user space
          device_add()  ======================> user space process Y reads the
                                                uevents writes to devcd fd
                                                which results into writes to
      
                                               devcd_data_write()
                                                 mod_delayed_work()
                                                   try_to_grab_pending()
                                                     del_timer()
                                                       debug_assert_init()
         INIT_DELAYED_WORK()
         schedule_delayed_work()
                                                         debug_object_fixup()
                                                           timer_fixup_assert_init()
                                                             timer_setup()
                                                               do_init_timer()
                                                             /*
                                                              Above call reinitializes
                                                              the timer to
                                                              timer->entry.pprev=NULL
                                                              and this will be checked
                                                              later in timer_pending() call.
                                                             */
                                                       timer_pending()
                                                        !hlist_unhashed_lockless(&timer->entry)
                                                          !h->pprev
                                                      /*
                                                        del_timer() checks h->pprev and finds
                                                        it to be NULL due to which
                                                        try_to_grab_pending() stucks.
                                                      */
      
      Link: https://lore.kernel.org/lkml/2e1f81e2-428c-f11f-ce92-eb11048cb271@quicinc.com/
      Signed-off-by: default avatarMukesh Ojha <quic_mojha@quicinc.com>
      Link: https://lore.kernel.org/r/1663073424-13663-1-git-send-email-quic_mojha@quicinc.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Stable-dep-of: af54d778
      
       ("devcoredump: Send uevent once devcd is ready")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c6a1282e
    • Paulo Alcantara's avatar
      smb: client: fix potential NULL deref in parse_dfs_referrals() · d99376b7
      Paulo Alcantara authored
      [ Upstream commit 92414333 ]
      
      If server returned no data for FSCTL_DFS_GET_REFERRALS, @dfs_rsp will
      remain NULL and then parse_dfs_referrals() will dereference it.
      
      Fix this by returning -EIO when no output data is returned.
      
      Besides, we can't fix it in SMB2_ioctl() as some FSCTLs are allowed to
      return no data as per MS-SMB2 2.2.32.
      
      Fixes: 9d49640a
      
       ("CIFS: implement get_dfs_refer for SMB2+")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarRobert Morris <rtm@csail.mit.edu>
      Signed-off-by: default avatarPaulo Alcantara (SUSE) <pc@manguebit.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d99376b7
    • David Howells's avatar
      cifs: Fix non-availability of dedup breaking generic/304 · ab5813bb
      David Howells authored
      [ Upstream commit 691a41d8 ]
      
      Deduplication isn't supported on cifs, but cifs doesn't reject it, instead
      treating it as extent duplication/cloning.  This can cause generic/304 to go
      silly and run for hours on end.
      
      Fix cifs to indicate EOPNOTSUPP if REMAP_FILE_DEDUP is set in
      ->remap_file_range().
      
      Note that it's unclear whether or not commit b073a080 is meant to cause
      cifs to return an error if REMAP_FILE_DEDUP.
      
      Fixes: b073a080
      
       ("cifs: fix that return -EINVAL when do dedupe operation")
      Cc: stable@vger.kernel.org
      Suggested-by: default avatarDave Chinner <david@fromorbit.com>
      cc: Xiaoli Feng <fengxiaoli0714@gmail.com>
      cc: Shyam Prasad N <nspmangalore@gmail.com>
      cc: Rohith Surabattula <rohiths.msft@gmail.com>
      cc: Jeff Layton <jlayton@kernel.org>
      cc: Darrick Wong <darrick.wong@oracle.com>
      cc: fstests@vger.kernel.org
      cc: linux-cifs@vger.kernel.org
      cc: linux-fsdevel@vger.kernel.org
      Link: https://lore.kernel.org/r/3876191.1701555260@warthog.procyon.org.uk/
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ab5813bb
    • Greg Kroah-Hartman's avatar
      Revert "btrfs: add dmesg output for first mount and last unmount of a filesystem" · bdee8b28
      Greg Kroah-Hartman authored
      This reverts commit dd94ffab which is
      commit 2db31320
      
       upstream.
      
      As pointed out by many, the disk_super structure is NOT initialized
      before it is dereferenced in the function
      fs/btrfs/disk-io.c:open_ctree() that this commit adds, so something went
      wrong here.
      
      Revert it for now until it gets straightened out.
      
      Link: https://lore.kernel.org/r/5b0eb360-3765-40e1-854a-9da6d97eb405@roeck-us.net
      Link: https://lore.kernel.org/r/20231209172836.GA2154579@dev-arch.thelio-3990X
      Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
      Cc: Anand Jain <anand.jain@oracle.com>
      Cc: Qu Wenruo <wqu@suse.com>
      Cc: David Sterba <dsterba@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bdee8b28
    • Namhyung Kim's avatar
      tools headers UAPI: Sync linux/perf_event.h with the kernel sources · dd9e8519
      Namhyung Kim authored
      commit 65ba872a upstream.
      
      To pick the trivial change in:
      
        119a784c
      
       ("perf/core: Add a new read format to get a number of lost samples")
      
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20220819003644.508916-2-namhyung@kernel.org
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dd9e8519
    • Ido Schimmel's avatar
      drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group · 4a341627
      Ido Schimmel authored
      commit e0378187 upstream.
      
      The "NET_DM" generic netlink family notifies drop locations over the
      "events" multicast group. This is problematic since by default generic
      netlink allows non-root users to listen to these notifications.
      
      Fix by adding a new field to the generic netlink multicast group
      structure that when set prevents non-root users or root without the
      'CAP_SYS_ADMIN' capability (in the user namespace owning the network
      namespace) from joining the group. Set this field for the "events"
      group. Use 'CAP_SYS_ADMIN' rather than 'CAP_NET_ADMIN' because of the
      nature of the information that is shared over this group.
      
      Note that the capability check in this case will always be performed
      against the initial user namespace since the family is not netns aware
      and only operates in the initial network namespace.
      
      A new field is added to the structure rather than using the "flags"
      field because the existing field uses uAPI flags and it is inappropriate
      to add a new uAPI flag for an internal kernel check. In net-next we can
      rework the "flags" field to use internal flags and fold the new field
      into it. But for now, in order to reduce the amount of changes, add a
      new field.
      
      Since the information can only be consumed by root, mark the control
      plane operations that start and stop the tracing as root-only using the
      'GENL_ADMIN_PERM' flag.
      
      Tested using [1].
      
      Before:
      
       # capsh -- -c ./dm_repo
       # capsh --drop=cap_sys_admin -- -c ./dm_repo
      
      After:
      
       # capsh -- -c ./dm_repo
       # capsh --drop=cap_sys_admin -- -c ./dm_repo
       Failed to join "events" multicast group
      
      [1]
       $ cat dm.c
       #include <stdio.h>
       #include <netlink/genl/ctrl.h>
       #include <netlink/genl/genl.h>
       #include <netlink/socket.h>
      
       int main(int argc, char **argv)
       {
       	struct nl_sock *sk;
       	int grp, err;
      
       	sk = nl_socket_alloc();
       	if (!sk) {
       		fprintf(stderr, "Failed to allocate socket\n");
       		return -1;
       	}
      
       	err = genl_connect(sk);
       	if (err) {
       		fprintf(stderr, "Failed to connect socket\n");
       		return err;
       	}
      
       	grp = genl_ctrl_resolve_grp(sk, "NET_DM", "events");
       	if (grp < 0) {
       		fprintf(stderr,
       			"Failed to resolve \"events\" multicast group\n");
       		return grp;
       	}
      
       	err = nl_socket_add_memberships(sk, grp, NFNLGRP_NONE);
       	if (err) {
       		fprintf(stderr, "Failed to join \"events\" multicast group\n");
       		return err;
       	}
      
       	return 0;
       }
       $ gcc -I/usr/include/libnl3 -lnl-3 -lnl-genl-3 -o dm_repo dm.c
      
      Fixes: 9a8afc8d
      
       ("Network Drop Monitor: Adding drop monitor implementation & Netlink protocol")
      Reported-by: default avatar"The UK's National Cyber Security Centre (NCSC)" <security@ncsc.gov.uk>
      Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
      Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
      Link: https://lore.kernel.org/r/20231206213102.1824398-3-idosch@nvidia.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4a341627
    • Ido Schimmel's avatar
      psample: Require 'CAP_NET_ADMIN' when joining "packets" group · fe840251
      Ido Schimmel authored
      commit 44ec98ea upstream.
      
      The "psample" generic netlink family notifies sampled packets over the
      "packets" multicast group. This is problematic since by default generic
      netlink allows non-root users to listen to these notifications.
      
      Fix by marking the group with the 'GENL_UNS_ADMIN_PERM' flag. This will
      prevent non-root users or root without the 'CAP_NET_ADMIN' capability
      (in the user namespace owning the network namespace) from joining the
      group.
      
      Tested using [1].
      
      Before:
      
       # capsh -- -c ./psample_repo
       # capsh --drop=cap_net_admin -- -c ./psample_repo
      
      After:
      
       # capsh -- -c ./psample_repo
       # capsh --drop=cap_net_admin -- -c ./psample_repo
       Failed to join "packets" multicast group
      
      [1]
       $ cat psample.c
       #include <stdio.h>
       #include <netlink/genl/ctrl.h>
       #include <netlink/genl/genl.h>
       #include <netlink/socket.h>
      
       int join_grp(struct nl_sock *sk, const char *grp_name)
       {
       	int grp, err;
      
       	grp = genl_ctrl_resolve_grp(sk, "psample", grp_name);
       	if (grp < 0) {
       		fprintf(stderr, "Failed to resolve \"%s\" multicast group\n",
       			grp_name);
       		return grp;
       	}
      
       	err = nl_socket_add_memberships(sk, grp, NFNLGRP_NONE);
       	if (err) {
       		fprintf(stderr, "Failed to join \"%s\" multicast group\n",
       			grp_name);
       		return err;
       	}
      
       	return 0;
       }
      
       int main(int argc, char **argv)
       {
       	struct nl_sock *sk;
       	int err;
      
       	sk = nl_socket_alloc();
       	if (!sk) {
       		fprintf(stderr, "Failed to allocate socket\n");
       		return -1;
       	}
      
       	err = genl_connect(sk);
       	if (err) {
       		fprintf(stderr, "Failed to connect socket\n");
       		return err;
       	}
      
       	err = join_grp(sk, "config");
       	if (err)
       		return err;
      
       	err = join_grp(sk, "packets");
       	if (err)
       		return err;
      
       	return 0;
       }
       $ gcc -I/usr/include/libnl3 -lnl-3 -lnl-genl-3 -o psample_repo psample.c
      
      Fixes: 6ae0a628
      
       ("net: Introduce psample, a new genetlink channel for packet sampling")
      Reported-by: default avatar"The UK's National Cyber Security Centre (NCSC)" <security@ncsc.gov.uk>
      Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
      Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
      Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
      Link: https://lore.kernel.org/r/20231206213102.1824398-2-idosch@nvidia.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fe840251
    • Ido Schimmel's avatar
      genetlink: add CAP_NET_ADMIN test for multicast bind · 263bffd2
      Ido Schimmel authored
      This is a partial backport of upstream commit 4d54cc32 ("mptcp:
      avoid lock_fast usage in accept path"). It is only a partial backport
      because the patch in the link below was erroneously squash-merged into
      upstream commit 4d54cc32
      
       ("mptcp: avoid lock_fast usage in accept
      path"). Below is the original patch description from Florian Westphal:
      
      "
      genetlink sets NL_CFG_F_NONROOT_RECV for its netlink socket so anyone can
      subscribe to multicast messages.
      
      rtnetlink doesn't allow this unconditionally,  rtnetlink_bind() restricts
      bind requests to CAP_NET_ADMIN for a few groups.
      
      This allows to set GENL_UNS_ADMIN_PERM flag on genl mcast groups to
      mandate CAP_NET_ADMIN.
      
      This will be used by the upcoming mptcp netlink event facility which
      exposes the token (mptcp connection identifier) to userspace.
      "
      
      Link: https://lore.kernel.org/mptcp/20210213000001.379332-8-mathew.j.martineau@linux.intel.com/
      Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      263bffd2
    • Ido Schimmel's avatar
      netlink: don't call ->netlink_bind with table lock held · a149fbad
      Ido Schimmel authored
      From: Florian Westphal <fw@strlen.de>
      
      commit f2764bd4 upstream.
      
      When I added support to allow generic netlink multicast groups to be
      restricted to subscribers with CAP_NET_ADMIN I was unaware that a
      genl_bind implementation already existed in the past.
      
      It was reverted due to ABBA deadlock:
      
      1. ->netlink_bind gets called with the table lock held.
      2. genetlink bind callback is invoked, it grabs the genl lock.
      
      But when a new genl subsystem is (un)registered, these two locks are
      taken in reverse order.
      
      One solution would be to revert again and add a comment in genl
      referring 1e82a62f, "genetlink: remove genl_bind").
      
      This would need a second change in mptcp to not expose the raw token
      value anymore, e.g.  by hashing the token with a secret key so userspace
      can still associate subflow events with the correct mptcp connection.
      
      However, Paolo Abeni reminded me to double-check why the netlink table is
      locked in the first place.
      
      I can't find one.  netlink_bind() is already called without this lock
      when userspace joins a group via NETLINK_ADD_MEMBERSHIP setsockopt.
      Same holds for the netlink_unbind operation.
      
      Digging through the history, commit f7736080
      ("netlink: access nlk groups safely in netlink bind and getname")
      expanded the lock scope.
      
      commit 3a20773b ("net: netlink: cap max groups which will be considered in netlink_bind()")
      ... removed the nlk->ngroups access that the lock scope
      extension was all about.
      
      Reduce the lock scope again and always call ->netlink_bind without
      the table lock.
      
      The Fixes tag should be vs. the patch mentioned in the link below,
      but that one got squash-merged into the patch that came earlier in the
      series.
      
      Fixes: 4d54cc32
      
       ("mptcp: avoid lock_fast usage in accept path")
      Link: https://lore.kernel.org/mptcp/20210213000001.379332-8-mathew.j.martineau@linux.intel.com/T/#u
      Cc: Cong Wang <xiyou.wangcong@gmail.com>
      Cc: Xin Long <lucien.xin@gmail.com>
      Cc: Johannes Berg <johannes.berg@intel.com>
      Cc: Sean Tranchetti <stranche@codeaurora.org>
      Cc: Paolo Abeni <pabeni@redhat.com>
      Cc: Pablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a149fbad
    • Pavel Begunkov's avatar
      io_uring/af_unix: disable sending io_uring over sockets · 18824f59
      Pavel Begunkov authored
      commit 705318a9 upstream.
      
      File reference cycles have caused lots of problems for io_uring
      in the past, and it still doesn't work exactly right and races with
      unix_stream_read_generic(). The safest fix would be to completely
      disallow sending io_uring files via sockets via SCM_RIGHT, so there
      are no possible cycles invloving registered files and thus rendering
      SCM accounting on the io_uring side unnecessary.
      
      Cc:  <stable@vger.kernel.org>
      Fixes: 0091bfc8
      
       ("io_uring/af_unix: defer registered files gc to io_uring release")
      Reported-and-suggested-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/c716c88321939156909cfa1bd8b0faaf1c804103.1701868795.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      18824f59
    • Ryusuke Konishi's avatar
      nilfs2: fix missing error check for sb_set_blocksize call · 32f4536c
      Ryusuke Konishi authored
      commit d61d0ab5
      
       upstream.
      
      When mounting a filesystem image with a block size larger than the page
      size, nilfs2 repeatedly outputs long error messages with stack traces to
      the kernel log, such as the following:
      
       getblk(): invalid block size 8192 requested
       logical block size: 512
       ...
       Call Trace:
        dump_stack_lvl+0x92/0xd4
        dump_stack+0xd/0x10
        bdev_getblk+0x33a/0x354
        __breadahead+0x11/0x80
        nilfs_search_super_root+0xe2/0x704 [nilfs2]
        load_nilfs+0x72/0x504 [nilfs2]
        nilfs_mount+0x30f/0x518 [nilfs2]
        legacy_get_tree+0x1b/0x40
        vfs_get_tree+0x18/0xc4
        path_mount+0x786/0xa88
        __ia32_sys_mount+0x147/0x1a8
        __do_fast_syscall_32+0x56/0xc8
        do_fast_syscall_32+0x29/0x58
        do_SYSENTER_32+0x15/0x18
        entry_SYSENTER_32+0x98/0xf1
       ...
      
      This overloads the system logger.  And to make matters worse, it sometimes
      crashes the kernel with a memory access violation.
      
      This is because the return value of the sb_set_blocksize() call, which
      should be checked for errors, is not checked.
      
      The latter issue is due to out-of-buffer memory being accessed based on a
      large block size that caused sb_set_blocksize() to fail for buffers read
      with the initial minimum block size that remained unupdated in the
      super_block structure.
      
      Since nilfs2 mkfs tool does not accept block sizes larger than the system
      page size, this has been overlooked.  However, it is possible to create
      this situation by intentionally modifying the tool or by passing a
      filesystem image created on a system with a large page size to a system
      with a smaller page size and mounting it.
      
      Fix this issue by inserting the expected error handling for the call to
      sb_set_blocksize().
      
      Link: https://lkml.kernel.org/r/20231129141547.4726-1-konishi.ryusuke@gmail.com
      Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      Tested-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      32f4536c
    • Claudio Imbrenda's avatar
      KVM: s390/mm: Properly reset no-dat · 77a35392
      Claudio Imbrenda authored
      commit 27072b8e
      
       upstream.
      
      When the CMMA state needs to be reset, the no-dat bit also needs to be
      reset. Failure to do so could cause issues in the guest, since the
      guest expects the bit to be cleared after a reset.
      
      Cc: <stable@vger.kernel.org>
      Reviewed-by: default avatarNico Boehr <nrb@linux.ibm.com>
      Message-ID: <20231109123624.37314-1-imbrenda@linux.ibm.com>
      Signed-off-by: default avatarClaudio Imbrenda <imbrenda@linux.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      77a35392
    • Borislav Petkov (AMD)'s avatar
      x86/CPU/AMD: Check vendor in the AMD microcode callback · 1aee33d4
      Borislav Petkov (AMD) authored
      commit 9b8493dc upstream.
      
      Commit in Fixes added an AMD-specific microcode callback. However, it
      didn't check the CPU vendor the kernel runs on explicitly.
      
      The only reason the Zenbleed check in it didn't run on other x86 vendors
      hardware was pure coincidental luck:
      
        if (!cpu_has_amd_erratum(c, amd_zenbleed))
      	  return;
      
      gives true on other vendors because they don't have those families and
      models.
      
      However, with the removal of the cpu_has_amd_erratum() in
      
        05f5f739 ("x86/CPU/AMD: Drop now unused CPU erratum checking function")
      
      that coincidental condition is gone, leading to the zenbleed check
      getting executed on other vendors too.
      
      Add the explicit vendor check for the whole callback as it should've
      been done in the first place.
      
      Fixes: 522b1d69
      
       ("x86/cpu/amd: Add a Zenbleed fix")
      Cc: <stable@kernel.org>
      Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
      Link: https://lore.kernel.org/r/20231201184226.16749-1-bp@alien8.de
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1aee33d4
    • Ronald Wahl's avatar
      serial: 8250_omap: Add earlycon support for the AM654 UART controller · 3371eac2
      Ronald Wahl authored
      commit 8e42c301
      
       upstream.
      
      Currently there is no support for earlycon on the AM654 UART
      controller. This commit adds it.
      
      Signed-off-by: default avatarRonald Wahl <ronald.wahl@raritan.com>
      Reviewed-by: default avatarVignesh Raghavendra <vigneshr@ti.com>
      Link: https://lore.kernel.org/r/20231031131242.15516-1-rwahl@gmx.de
      Cc: stable <stable@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3371eac2
    • Daniel Mack's avatar
      serial: sc16is7xx: address RX timeout interrupt errata · ce79cf40
      Daniel Mack authored
      commit 08ce9a1b
      
       upstream.
      
      This device has a silicon bug that makes it report a timeout interrupt
      but no data in the FIFO.
      
      The datasheet states the following in the errata section 18.1.4:
      
        "If the host reads the receive FIFO at the same time as a
        time-out interrupt condition happens, the host might read 0xCC
        (time-out) in the Interrupt Indication Register (IIR), but bit 0
        of the Line Status Register (LSR) is not set (means there is no
        data in the receive FIFO)."
      
      The errata description seems to indicate it concerns only polled mode of
      operation when reading bit 0 of the LSR register. However, tests have
      shown and NXP has confirmed that the RXLVL register also yields 0 when
      the bug is triggered, and hence the IRQ driven implementation in this
      driver is equally affected.
      
      This bug has hit us on production units and when it does, sc16is7xx_irq()
      would spin forever because sc16is7xx_port_irq() keeps seeing an
      interrupt in the IIR register that is not cleared because the driver
      does not call into sc16is7xx_handle_rx() unless the RXLVL register
      reports at least one byte in the FIFO.
      
      Fix this by always reading one byte from the FIFO when this condition
      is detected in order to clear the interrupt. This approach was
      confirmed to be correct by NXP through their support channels.
      
      Tested by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
      
      Signed-off-by: default avatarDaniel Mack <daniel@zonque.org>
      Co-Developed-by: default avatarMaxim Popov <maxim.snafu@gmail.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20231123072818.1394539-1-daniel@zonque.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ce79cf40
    • Arnd Bergmann's avatar
      ARM: PL011: Fix DMA support · d896c47f
      Arnd Bergmann authored
      commit 58ac1b37 upstream.
      
      Since there is no guarantee that the memory returned by
      dma_alloc_coherent() is associated with a 'struct page', using the
      architecture specific phys_to_page() is wrong, but using
      virt_to_page() would be as well.
      
      Stop using sg lists altogether and just use the *_single() functions
      instead. This also simplifies the code a bit since the scatterlists in
      this driver always have only one entry anyway.
      
      https://lore.kernel.org/lkml/86db0fe5-930d-4cbb-bd7d-03367da38951@app.fastmail.com/
          Use consistent names for dma buffers
      
      gc: Add a commit log from the initial thread:
      https://lore.kernel.org/lkml/86db0fe5-930d-4cbb-bd7d-03367da38951@app.fastmail.com/
          Use consistent names for dma buffers
      
      Fixes: cb06ff10
      
       ("ARM: PL011: Add support for Rx DMA buffer polling.")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Tested-by: default avatarGregory CLEMENT <gregory.clement@bootlin.com>
      Signed-off-by: default avatarGregory CLEMENT <gregory.clement@bootlin.com>
      Cc: stable <stable@kernel.org>
      Link: https://lore.kernel.org/r/20231122171503.235649-1-gregory.clement@bootlin.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d896c47f
    • RD Babiera's avatar
      usb: typec: class: fix typec_altmode_put_partner to put plugs · 880b035b
      RD Babiera authored
      commit b17b7fe6 upstream.
      
      When typec_altmode_put_partner is called by a plug altmode upon release,
      the port altmode the plug belongs to will not remove its reference to the
      plug. The check to see if the altmode being released evaluates against the
      released altmode's partner instead of the calling altmode itself, so change
      adev in typec_altmode_put_partner to properly refer to the altmode being
      released.
      
      typec_altmode_set_partner is not run for port altmodes, so also add a check
      in typec_altmode_release to prevent typec_altmode_put_partner() calls on
      port altmode release.
      
      Fixes: 8a37d87d
      
       ("usb: typec: Bus type for alternate modes")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarRD Babiera <rdbabiera@google.com>
      Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Link: https://lore.kernel.org/r/20231129192349.1773623-2-rdbabiera@google.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      880b035b
    • Cameron Williams's avatar
      parport: Add support for Brainboxes IX/UC/PX parallel cards · a9022cbd
      Cameron Williams authored
      commit 1a031f6e
      
       upstream.
      
      Adds support for Intashield IX-500/IX-550, UC-146/UC-157, PX-146/PX-157,
      PX-203 and PX-475 (LPT port)
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarCameron Williams <cang1@live.co.uk>
      Acked-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Link: https://lore.kernel.org/r/AS4PR02MB790389C130410BD864C8DCC9C4A6A@AS4PR02MB7903.eurprd02.prod.outlook.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a9022cbd
    • Konstantin Aladyshev's avatar
      usb: gadget: f_hid: fix report descriptor allocation · fefc0559
      Konstantin Aladyshev authored
      commit 61890dc2 upstream.
      
      The commit 89ff3dfa ("usb: gadget: f_hid: fix f_hidg lifetime vs
      cdev") has introduced a bug that leads to hid device corruption after
      the replug operation.
      Reverse device managed memory allocation for the report descriptor
      to fix the issue.
      
      Tested:
      This change was tested on the AMD EthanolX CRB server with the BMC
      based on the OpenBMC distribution. The BMC provides KVM functionality
      via the USB gadget device:
      - before: KVM page refresh results in a broken USB device,
      - after: KVM page refresh works without any issues.
      
      Fixes: 89ff3dfa
      
       ("usb: gadget: f_hid: fix f_hidg lifetime vs cdev")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarKonstantin Aladyshev <aladyshev22@gmail.com>
      Link: https://lore.kernel.org/r/20231206080744.253-2-aladyshev22@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fefc0559
    • Wenchao Chen's avatar
      mmc: sdhci-sprd: Fix vqmmc not shutting down after the card was pulled · 1796ae6a
      Wenchao Chen authored
      [ Upstream commit 477865af ]
      
      With cat regulator_summary, we found that vqmmc was not shutting
      down after the card was pulled.
      
      cat /sys/kernel/debug/regulator/regulator_summary
      1.before fix
      1)Insert SD card
       vddsdio		1    1  0 unknown  3500mV 0mA  1200mV  3750mV
          71100000.mmc-vqmmc  1                         0mA  3500mV  3600mV
      
      2)Pull out the SD card
       vddsdio                1    1  0 unknown  3500mV 0mA  1200mV  3750mV
          71100000.mmc-vqmmc  1                         0mA  3500mV  3600mV
      
      2.after fix
      1)Insert SD cardt
       vddsdio                1    1  0 unknown  3500mV 0mA  1200mV  3750mV
          71100000.mmc-vqmmc  1                         0mA  3500mV  3600mV
      
      2)Pull out the SD card
       vddsdio		0    1  0 unknown  3500mV 0mA  1200mV  3750mV
          71100000.mmc-vqmmc  0                         0mA  3500mV  3600mV
      
      Fixes: fb8bd90f
      
       ("mmc: sdhci-sprd: Add Spreadtrum's initial host controller")
      Signed-off-by: default avatarWenchao Chen <wenchao.chen@unisoc.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20231115083406.7368-1-wenchao.chen@unisoc.com
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1796ae6a
    • Heiner Kallweit's avatar
      mmc: core: add helpers mmc_regulator_enable/disable_vqmmc · a1f29e99
      Heiner Kallweit authored
      [ Upstream commit 8d91f3f8
      
       ]
      
      There's a number of drivers (e.g. dw_mmc, meson-gx, mmci, sunxi) using
      the same mechanism and a private flag vqmmc_enabled to deal with
      enabling/disabling the vqmmc regulator.
      
      Move this to the core and create new helpers mmc_regulator_enable_vqmmc
      and mmc_regulator_disable_vqmmc.
      
      Signed-off-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
      Acked-by: default avatarMartin Blumenstingl <martin.blumenstingl@googlemail.com>
      Link: https://lore.kernel.org/r/71586432-360f-9b92-17f6-b05a8a971bc2@gmail.com
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Stable-dep-of: 477865af
      
       ("mmc: sdhci-sprd: Fix vqmmc not shutting down after the card was pulled")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a1f29e99
    • Boerge Struempfel's avatar
      gpiolib: sysfs: Fix error handling on failed export · 05918dec
      Boerge Struempfel authored
      [ Upstream commit 95dd1e34 ]
      
      If gpio_set_transitory() fails, we should free the GPIO again. Most
      notably, the flag FLAG_REQUESTED has previously been set in
      gpiod_request_commit(), and should be reset on failure.
      
      To my knowledge, this does not affect any current users, since the
      gpio_set_transitory() mainly returns 0 and -ENOTSUPP, which is converted
      to 0. However the gpio_set_transitory() function calles the .set_config()
      function of the corresponding GPIO chip and there are some GPIO drivers in
      which some (unlikely) branches return other values like -EPROBE_DEFER,
      and -EINVAL. In these cases, the above mentioned FLAG_REQUESTED would not
      be reset, which results in the pin being blocked until the next reboot.
      
      Fixes: e10f72bf
      
       ("gpio: gpiolib: Generalise state persistence beyond sleep")
      Signed-off-by: default avatarBoerge Struempfel <boerge.struempfel@gmail.com>
      Reviewed-by: default avatarAndy Shevchenko <andy@kernel.org>
      Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      05918dec
    • Peter Zijlstra's avatar
      perf: Fix perf_event_validate_size() · 152f51d1
      Peter Zijlstra authored
      [ Upstream commit 382c27f4 ]
      
      Budimir noted that perf_event_validate_size() only checks the size of
      the newly added event, even though the sizes of all existing events
      can also change due to not all events having the same read_format.
      
      When we attach the new event, perf_group_attach(), we do re-compute
      the size for all events.
      
      Fixes: a723968c
      
       ("perf: Fix u16 overflows")
      Reported-by: default avatarBudimir Markovic <markovicbudimir@gmail.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      152f51d1
    • Namhyung Kim's avatar
      perf/core: Add a new read format to get a number of lost samples · 84ca356e
      Namhyung Kim authored
      [ Upstream commit 119a784c
      
       ]
      
      Sometimes we want to know an accurate number of samples even if it's
      lost.  Currenlty PERF_RECORD_LOST is generated for a ring-buffer which
      might be shared with other events.  So it's hard to know per-event
      lost count.
      
      Add event->lost_samples field and PERF_FORMAT_LOST to retrieve it from
      userspace.
      
      Original-patch-by: default avatarJiri Olsa <jolsa@redhat.com>
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/20220616180623.1358843-1-namhyung@kernel.org
      Stable-dep-of: 382c27f4
      
       ("perf: Fix perf_event_validate_size()")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      84ca356e
    • AngeloGioacchino Del Regno's avatar
      arm64: dts: mediatek: mt8173-evb: Fix regulator-fixed node names · 07bdb1bd
      AngeloGioacchino Del Regno authored
      commit 24165c5d upstream.
      
      Fix a unit_address_vs_reg warning for the USB VBUS fixed regulators
      by renaming the regulator nodes from regulator@{0,1} to regulator-usb-p0
      and regulator-usb-p1.
      
      Cc: stable@vger.kernel.org
      Fixes: c0891284
      
       ("arm64: dts: mediatek: add USB3 DRD driver")
      Link: https://lore.kernel.org/r/20231025093816.44327-8-angelogioacchino.delregno@collabora.com
      Signed-off-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      07bdb1bd
    • Eugen Hristev's avatar
      arm64: dts: mediatek: mt7622: fix memory node warning check · 6109859f
      Eugen Hristev authored
      commit 8e6ecbfd upstream.
      
      dtbs_check throws a warning at the memory node:
      Warning (unit_address_vs_reg): /memory: node has a reg or ranges property, but no unit name
      
      fix by adding the address into the node name.
      
      Cc: stable@vger.kernel.org
      Fixes: 0b6286dd
      
       ("arm64: dts: mt7622: add bananapi BPI-R64 board")
      Signed-off-by: default avatarEugen Hristev <eugen.hristev@collabora.com>
      Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Link: https://lore.kernel.org/r/20230814065042.4973-1-eugen.hristev@collabora.com
      Signed-off-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6109859f
    • Daniel Borkmann's avatar
      packet: Move reference count in packet_sock to atomic_long_t · 148d8f07
      Daniel Borkmann authored
      commit db3fadac
      
       upstream.
      
      In some potential instances the reference count on struct packet_sock
      could be saturated and cause overflows which gets the kernel a bit
      confused. To prevent this, move to a 64-bit atomic reference count on
      64-bit architectures to prevent the possibility of this type to overflow.
      
      Because we can not handle saturation, using refcount_t is not possible
      in this place. Maybe someday in the future if it changes it could be
      used. Also, instead of using plain atomic64_t, use atomic_long_t instead.
      32-bit machines tend to be memory-limited (i.e. anything that increases
      a reference uses so much memory that you can't actually get to 2**32
      references). 32-bit architectures also tend to have serious problems
      with 64-bit atomics. Hence, atomic_long_t is the more natural solution.
      
      Reported-by: default avatar"The UK's National Cyber Security Centre (NCSC)" <security@ncsc.gov.uk>
      Co-developed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: stable@kernel.org
      Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20231201131021.19999-1-daniel@iogearbox.net
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      148d8f07
    • Petr Pavlu's avatar
      tracing: Fix a possible race when disabling buffered events · 965cbc6b
      Petr Pavlu authored
      commit c0591b1c upstream.
      
      Function trace_buffered_event_disable() is responsible for freeing pages
      backing buffered events and this process can run concurrently with
      trace_event_buffer_lock_reserve().
      
      The following race is currently possible:
      
      * Function trace_buffered_event_disable() is called on CPU 0. It
        increments trace_buffered_event_cnt on each CPU and waits via
        synchronize_rcu() for each user of trace_buffered_event to complete.
      
      * After synchronize_rcu() is finished, function
        trace_buffered_event_disable() has the exclusive access to
        trace_buffered_event. All counters trace_buffered_event_cnt are at 1
        and all pointers trace_buffered_event are still valid.
      
      * At this point, on a different CPU 1, the execution reaches
        trace_event_buffer_lock_reserve(). The function calls
        preempt_disable_notrace() and only now enters an RCU read-side
        critical section. The function proceeds and reads a still valid
        pointer from trace_buffered_event[CPU1] into the local variable
        "entry". However, it doesn't yet read trace_buffered_event_cnt[CPU1]
        which happens later.
      
      * Function trace_buffered_event_disable() continues. It frees
        trace_buffered_event[CPU1] and decrements
        trace_buffered_event_cnt[CPU1] back to 0.
      
      * Function trace_event_buffer_lock_reserve() continues. It reads and
        increments trace_buffered_event_cnt[CPU1] from 0 to 1. This makes it
        believe that it can use the "entry" that it already obtained but the
        pointer is now invalid and any access results in a use-after-free.
      
      Fix the problem by making a second synchronize_rcu() call after all
      trace_buffered_event values are set to NULL. This waits on all potential
      users in trace_event_buffer_lock_reserve() that still read a previous
      pointer from trace_buffered_event.
      
      Link: https://lore.kernel.org/all/20231127151248.7232-2-petr.pavlu@suse.com/
      Link: https://lkml.kernel.org/r/20231205161736.19663-4-petr.pavlu@suse.com
      
      Cc: stable@vger.kernel.org
      Fixes: 0fc1b09f
      
       ("tracing: Use temp buffer when filtering events")
      Signed-off-by: default avatarPetr Pavlu <petr.pavlu@suse.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      965cbc6b
    • Petr Pavlu's avatar
      tracing: Fix incomplete locking when disabling buffered events · 6f2e5096
      Petr Pavlu authored
      commit 7fed14f7 upstream.
      
      The following warning appears when using buffered events:
      
      [  203.556451] WARNING: CPU: 53 PID: 10220 at kernel/trace/ring_buffer.c:3912 ring_buffer_discard_commit+0x2eb/0x420
      [...]
      [  203.670690] CPU: 53 PID: 10220 Comm: stress-ng-sysin Tainted: G            E      6.7.0-rc2-default #4 56e6d0fcf5581e6e51eaaecbdaec2a2338c80f3a
      [  203.670704] Hardware name: Intel Corp. GROVEPORT/GROVEPORT, BIOS GVPRCRB1.86B.0016.D04.1705030402 05/03/2017
      [  203.670709] RIP: 0010:ring_buffer_discard_commit+0x2eb/0x420
      [  203.735721] Code: 4c 8b 4a 50 48 8b 42 48 49 39 c1 0f 84 b3 00 00 00 49 83 e8 01 75 b1 48 8b 42 10 f0 ff 40 08 0f 0b e9 fc fe ff ff f0 ff 47 08 <0f> 0b e9 77 fd ff ff 48 8b 42 10 f0 ff 40 08 0f 0b e9 f5 fe ff ff
      [  203.735734] RSP: 0018:ffffb4ae4f7b7d80 EFLAGS: 00010202
      [  203.735745] RAX: 0000000000000000 RBX: ffffb4ae4f7b7de0 RCX: ffff8ac10662c000
      [  203.735754] RDX: ffff8ac0c750be00 RSI: ffff8ac10662c000 RDI: ffff8ac0c004d400
      [  203.781832] RBP: ffff8ac0c039cea0 R08: 0000000000000000 R09: 0000000000000000
      [  203.781839] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
      [  203.781842] R13: ffff8ac10662c000 R14: ffff8ac0c004d400 R15: ffff8ac10662c008
      [  203.781846] FS:  00007f4cd8a67740(0000) GS:ffff8ad798880000(0000) knlGS:0000000000000000
      [  203.781851] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [  203.781855] CR2: 0000559766a74028 CR3: 00000001804c4000 CR4: 00000000001506f0
      [  203.781862] Call Trace:
      [  203.781870]  <TASK>
      [  203.851949]  trace_event_buffer_commit+0x1ea/0x250
      [  203.851967]  trace_event_raw_event_sys_enter+0x83/0xe0
      [  203.851983]  syscall_trace_enter.isra.0+0x182/0x1a0
      [  203.851990]  do_syscall_64+0x3a/0xe0
      [  203.852075]  entry_SYSCALL_64_after_hwframe+0x6e/0x76
      [  203.852090] RIP: 0033:0x7f4cd870fa77
      [  203.982920] Code: 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 66 90 b8 89 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d e9 43 0e 00 f7 d8 64 89 01 48
      [  203.982932] RSP: 002b:00007fff99717dd8 EFLAGS: 00000246 ORIG_RAX: 0000000000000089
      [  203.982942] RAX: ffffffffffffffda RBX: 0000558ea1d7b6f0 RCX: 00007f4cd870fa77
      [  203.982948] RDX: 0000000000000000 RSI: 00007fff99717de0 RDI: 0000558ea1d7b6f0
      [  203.982957] RBP: 00007fff99717de0 R08: 00007fff997180e0 R09: 00007fff997180e0
      [  203.982962] R10: 00007fff997180e0 R11: 0000000000000246 R12: 00007fff99717f40
      [  204.049239] R13: 00007fff99718590 R14: 0000558e9f2127a8 R15: 00007fff997180b0
      [  204.049256]  </TASK>
      
      For instance, it can be triggered by running these two commands in
      parallel:
      
       $ while true; do
          echo hist:key=id.syscall:val=hitcount > \
            /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/trigger;
        done
       $ stress-ng --sysinfo $(nproc)
      
      The warning indicates that the current ring_buffer_per_cpu is not in the
      committing state. It happens because the active ring_buffer_event
      doesn't actually come from the ring_buffer_per_cpu but is allocated from
      trace_buffered_event.
      
      The bug is in function trace_buffered_event_disable() where the
      following normally happens:
      
      * The code invokes disable_trace_buffered_event() via
        smp_call_function_many() and follows it by synchronize_rcu(). This
        increments the per-CPU variable trace_buffered_event_cnt on each
        target CPU and grants trace_buffered_event_disable() the exclusive
        access to the per-CPU variable trace_buffered_event.
      
      * Maintenance is performed on trace_buffered_event, all per-CPU event
        buffers get freed.
      
      * The code invokes enable_trace_buffered_event() via
        smp_call_function_many(). This decrements trace_buffered_event_cnt and
        releases the access to trace_buffered_event.
      
      A problem is that smp_call_function_many() runs a given function on all
      target CPUs except on the current one. The following can then occur:
      
      * Task X executing trace_buffered_event_disable() runs on CPU 0.
      
      * The control reaches synchronize_rcu() and the task gets rescheduled on
        another CPU 1.
      
      * The RCU synchronization finishes. At this point,
        trace_buffered_event_disable() has the exclusive access to all
        trace_buffered_event variables except trace_buffered_event[CPU0]
        because trace_buffered_event_cnt[CPU0] is never incremented and if the
        buffer is currently unused, remains set to 0.
      
      * A different task Y is scheduled on CPU 0 and hits a trace event. The
        code in trace_event_buffer_lock_reserve() sees that
        trace_buffered_event_cnt[CPU0] is set to 0 and decides the use the
        buffer provided by trace_buffered_event[CPU0].
      
      * Task X continues its execution in trace_buffered_event_disable(). The
        code incorrectly frees the event buffer pointed by
        trace_buffered_event[CPU0] and resets the variable to NULL.
      
      * Task Y writes event data to the now freed buffer and later detects the
        created inconsistency.
      
      The issue is observable since commit dea49978 ("tracing: Fix warning
      in trace_buffered_event_disable()") which moved the call of
      trace_buffered_event_disable() in __ftrace_event_enable_disable()
      earlier, prior to invoking call->class->reg(.. TRACE_REG_UNREGISTER ..).
      The underlying problem in trace_buffered_event_disable() is however
      present since the original implementation in commit 0fc1b09f
      ("tracing: Use temp buffer when filtering events").
      
      Fix the problem by replacing the two smp_call_function_many() calls with
      on_each_cpu_mask() which invokes a given callback on all CPUs.
      
      Link: https://lore.kernel.org/all/20231127151248.7232-2-petr.pavlu@suse.com/
      Link: https://lkml.kernel.org/r/20231205161736.19663-2-petr.pavlu@suse.com
      
      Cc: stable@vger.kernel.org
      Fixes: 0fc1b09f ("tracing: Use temp buffer when filtering events")
      Fixes: dea49978
      
       ("tracing: Fix warning in trace_buffered_event_disable()")
      Signed-off-by: default avatarPetr Pavlu <petr.pavlu@suse.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6f2e5096
    • Steven Rostedt (Google)'s avatar
      tracing: Always update snapshot buffer size · 84302391
      Steven Rostedt (Google) authored
      commit 7be76461 upstream.
      
      It use to be that only the top level instance had a snapshot buffer (for
      latency tracers like wakeup and irqsoff). The update of the ring buffer
      size would check if the instance was the top level and if so, it would
      also update the snapshot buffer as it needs to be the same as the main
      buffer.
      
      Now that lower level instances also has a snapshot buffer, they too need
      to update their snapshot buffer sizes when the main buffer is changed,
      otherwise the following can be triggered:
      
       # cd /sys/kernel/tracing
       # echo 1500 > buffer_size_kb
       # mkdir instances/foo
       # echo irqsoff > instances/foo/current_tracer
       # echo 1000 > instances/foo/buffer_size_kb
      
      Produces:
      
       WARNING: CPU: 2 PID: 856 at kernel/trace/trace.c:1938 update_max_tr_single.part.0+0x27d/0x320
      
      Which is:
      
      	ret = ring_buffer_swap_cpu(tr->max_buffer.buffer, tr->array_buffer.buffer, cpu);
      
      	if (ret == -EBUSY) {
      		[..]
      	}
      
      	WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY);  <== here
      
      That's because ring_buffer_swap_cpu() has:
      
      	int ret = -EINVAL;
      
      	[..]
      
      	/* At least make sure the two buffers are somewhat the same */
      	if (cpu_buffer_a->nr_pages != cpu_buffer_b->nr_pages)
      		goto out;
      
      	[..]
       out:
      	return ret;
       }
      
      Instead, update all instances' snapshot buffer sizes when their main
      buffer size is updated.
      
      Link: https://lkml.kernel.org/r/20231205220010.454662151@goodmis.org
      
      Cc: stable@vger.kernel.org
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Fixes: 6d9b3fa5
      
       ("tracing: Move tracing_max_latency into trace_array")
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      84302391
    • Ryusuke Konishi's avatar
      nilfs2: prevent WARNING in nilfs_sufile_set_segment_usage() · cb74e8fd
      Ryusuke Konishi authored
      commit 675abf8d
      
       upstream.
      
      If nilfs2 reads a disk image with corrupted segment usage metadata, and
      its segment usage information is marked as an error for the segment at the
      write location, nilfs_sufile_set_segment_usage() can trigger WARN_ONs
      during log writing.
      
      Segments newly allocated for writing with nilfs_sufile_alloc() will not
      have this error flag set, but this unexpected situation will occur if the
      segment indexed by either nilfs->ns_segnum or nilfs->ns_nextnum (active
      segment) was marked in error.
      
      Fix this issue by inserting a sanity check to treat it as a file system
      corruption.
      
      Since error returns are not allowed during the execution phase where
      nilfs_sufile_set_segment_usage() is used, this inserts the sanity check
      into nilfs_sufile_mark_dirty() which pre-reads the buffer containing the
      segment usage record to be updated and sets it up in a dirty state for
      writing.
      
      In addition, nilfs_sufile_set_segment_usage() is also called when
      canceling log writing and undoing segment usage update, so in order to
      avoid issuing the same kernel warning in that case, in case of
      cancellation, avoid checking the error flag in
      nilfs_sufile_set_segment_usage().
      
      Link: https://lkml.kernel.org/r/20231205085947.4431-1-konishi.ryusuke@gmail.com
      Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      Reported-by: default avatar <syzbot+14e9f834f6ddecece094@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=14e9f834f6ddecece094
      Tested-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cb74e8fd
    • Jason Zhang's avatar
      ALSA: pcm: fix out-of-bounds in snd_pcm_state_names · 610ebc28
      Jason Zhang authored
      commit 2b3a7a30
      
       upstream.
      
      The pcm state can be SNDRV_PCM_STATE_DISCONNECTED at disconnect
      callback, and there is not an entry of SNDRV_PCM_STATE_DISCONNECTED
      in snd_pcm_state_names.
      
      This patch adds the missing entry to resolve this issue.
      
      cat /proc/asound/card2/pcm0p/sub0/status
      That results in stack traces like the following:
      
      [   99.702732][ T5171] Unexpected kernel BRK exception at EL1
      [   99.702774][ T5171] Internal error: BRK handler: f2005512 [#1] PREEMPT SMP
      [   99.703858][ T5171] Modules linked in: bcmdhd(E) (...)
      [   99.747425][ T5171] CPU: 3 PID: 5171 Comm: cat Tainted: G         C OE     5.10.189-android13-4-00003-g4a17384380d8-ab11086999 #1
      [   99.748447][ T5171] Hardware name: Rockchip RK3588 CVTE V10 Board (DT)
      [   99.749024][ T5171] pstate: 60400005 (nZCv daif +PAN -UAO -TCO BTYPE=--)
      [   99.749616][ T5171] pc : snd_pcm_substream_proc_status_read+0x264/0x2bc
      [   99.750204][ T5171] lr : snd_pcm_substream_proc_status_read+0xa4/0x2bc
      [   99.750778][ T5171] sp : ffffffc0175abae0
      [   99.751132][ T5171] x29: ffffffc0175abb80 x28: ffffffc009a2c498
      [   99.751665][ T5171] x27: 0000000000000001 x26: ffffff810cbae6e8
      [   99.752199][ T5171] x25: 0000000000400cc0 x24: ffffffc0175abc60
      [   99.752729][ T5171] x23: 0000000000000000 x22: ffffff802f558400
      [   99.753263][ T5171] x21: ffffff81d8d8ff00 x20: ffffff81020cdc00
      [   99.753795][ T5171] x19: ffffff802d110000 x18: ffffffc014fbd058
      [   99.754326][ T5171] x17: 0000000000000000 x16: 0000000000000000
      [   99.754861][ T5171] x15: 000000000000c276 x14: ffffffff9a976fda
      [   99.755392][ T5171] x13: 0000000065689089 x12: 000000000000d72e
      [   99.755923][ T5171] x11: ffffff802d110000 x10: 00000000000000e0
      [   99.756457][ T5171] x9 : 9c431600c8385d00 x8 : 0000000000000008
      [   99.756990][ T5171] x7 : 0000000000000000 x6 : 000000000000003f
      [   99.757522][ T5171] x5 : 0000000000000040 x4 : ffffffc0175abb70
      [   99.758056][ T5171] x3 : 0000000000000001 x2 : 0000000000000001
      [   99.758588][ T5171] x1 : 0000000000000000 x0 : 0000000000000000
      [   99.759123][ T5171] Call trace:
      [   99.759404][ T5171]  snd_pcm_substream_proc_status_read+0x264/0x2bc
      [   99.759958][ T5171]  snd_info_seq_show+0x54/0xa4
      [   99.760370][ T5171]  seq_read_iter+0x19c/0x7d4
      [   99.760770][ T5171]  seq_read+0xf0/0x128
      [   99.761117][ T5171]  proc_reg_read+0x100/0x1f8
      [   99.761515][ T5171]  vfs_read+0xf4/0x354
      [   99.761869][ T5171]  ksys_read+0x7c/0x148
      [   99.762226][ T5171]  __arm64_sys_read+0x20/0x30
      [   99.762625][ T5171]  el0_svc_common+0xd0/0x1e4
      [   99.763023][ T5171]  el0_svc+0x28/0x98
      [   99.763358][ T5171]  el0_sync_handler+0x8c/0xf0
      [   99.763759][ T5171]  el0_sync+0x1b8/0x1c0
      [   99.764118][ T5171] Code: d65f03c0 b9406102 17ffffae 94191565 (d42aa240)
      [   99.764715][ T5171] ---[ end trace 1eeffa3e17c58e10 ]---
      [   99.780720][ T5171] Kernel panic - not syncing: BRK handler: Fatal exception
      
      Signed-off-by: default avatarJason Zhang <jason.zhang@rock-chips.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20231206013139.20506-1-jason.zhang@rock-chips.com
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      610ebc28
    • Philipp Zabel's avatar
      ARM: dts: imx7: Declare timers compatible with fsl,imx6dl-gpt · 439166b1
      Philipp Zabel authored
      [ Upstream commit 397caf68 ]
      
      The timer nodes declare compatibility with "fsl,imx6sx-gpt", which
      itself is compatible with "fsl,imx6dl-gpt". Switch the fallback
      compatible from "fsl,imx6sx-gpt" to "fsl,imx6dl-gpt".
      
      Fixes: 94967345
      
       ("ARM: dts: add imx7d soc dtsi file")
      Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
      Signed-off-by: default avatarRoland Hieber <rhi@pengutronix.de>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      439166b1
    • Anson Huang's avatar
      ARM: dts: imx: make gpt node name generic · 4fe36f83
      Anson Huang authored
      [ Upstream commit 7c48b086
      
       ]
      
      Node name should be generic, use "timer" instead of "gpt" for gpt node.
      
      Signed-off-by: default avatarAnson Huang <Anson.Huang@nxp.com>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Stable-dep-of: 397caf68
      
       ("ARM: dts: imx7: Declare timers compatible with fsl,imx6dl-gpt")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4fe36f83
    • Kunwu Chan's avatar
      ARM: imx: Check return value of devm_kasprintf in imx_mmdc_perf_init · 69b669cc
      Kunwu Chan authored
      [ Upstream commit 1c2b1049
      
       ]
      
      devm_kasprintf() returns a pointer to dynamically allocated memory
      which can be NULL upon failure. Ensure the allocation was successful
      by checking the pointer validity.
      
      Release the id allocated in 'mmdc_pmu_init' when 'devm_kasprintf'
      return NULL
      
      Suggested-by: default avatarAhmad Fatoum <a.fatoum@pengutronix.de>
      Fixes: e76bdfd7
      
       ("ARM: imx: Added perf functionality to mmdc driver")
      Signed-off-by: default avatarKunwu Chan <chentao@kylinos.cn>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      69b669cc
    • Dinghao Liu's avatar
      scsi: be2iscsi: Fix a memleak in beiscsi_init_wrb_handle() · 59348f14
      Dinghao Liu authored
      [ Upstream commit 235f2b54 ]
      
      When an error occurs in the for loop of beiscsi_init_wrb_handle(), we
      should free phwi_ctxt->be_wrbq before returning an error code to prevent
      potential memleak.
      
      Fixes: a7909b39
      
       ("[SCSI] be2iscsi: Fix dynamic CID allocation Mechanism in driver")
      Signed-off-by: default avatarDinghao Liu <dinghao.liu@zju.edu.cn>
      Link: https://lore.kernel.org/r/20231123081941.24854-1-dinghao.liu@zju.edu.cn
      Reviewed-by: default avatarMike Christie <michael.christie@oracle.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      59348f14
    • Petr Pavlu's avatar
      tracing: Fix a warning when allocating buffered events fails · 8244ea91
      Petr Pavlu authored
      [ Upstream commit 34209fe8 ]
      
      Function trace_buffered_event_disable() produces an unexpected warning
      when the previous call to trace_buffered_event_enable() fails to
      allocate pages for buffered events.
      
      The situation can occur as follows:
      
      * The counter trace_buffered_event_ref is at 0.
      
      * The soft mode gets enabled for some event and
        trace_buffered_event_enable() is called. The function increments
        trace_buffered_event_ref to 1 and starts allocating event pages.
      
      * The allocation fails for some page and trace_buffered_event_disable()
        is called for cleanup.
      
      * Function trace_buffered_event_disable() decrements
        trace_buffered_event_ref back to 0, recognizes that it was the last
        use of buffered events and frees all allocated pages.
      
      * The control goes back to trace_buffered_event_enable() which returns.
        The caller of trace_buffered_event_enable() has no information that
        the function actually failed.
      
      * Some time later, the soft mode is disabled for the same event.
        Function trace_buffered_event_disable() is called. It warns on
        "WARN_ON_ONCE(!trace_buffered_event_ref)" and returns.
      
      Buffered events are just an optimization and can handle failures. Make
      trace_buffered_event_enable() exit on the first failure and left any
      cleanup later to when trace_buffered_event_disable() is called.
      
      Link: https://lore.kernel.org/all/20231127151248.7232-2-petr.pavlu@suse.com/
      Link: https://lkml.kernel.org/r/20231205161736.19663-3-petr.pavlu@suse.com
      
      Fixes: 0fc1b09f
      
       ("tracing: Use temp buffer when filtering events")
      Signed-off-by: default avatarPetr Pavlu <petr.pavlu@suse.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8244ea91
    • Dinghao Liu's avatar
      ASoC: wm_adsp: fix memleak in wm_adsp_buffer_populate · 4713be84
      Dinghao Liu authored
      [ Upstream commit 29046a78 ]
      
      When wm_adsp_buffer_read() fails, we should free buf->regions.
      Otherwise, the callers of wm_adsp_buffer_populate() will
      directly free buf on failure, which makes buf->regions a leaked
      memory.
      
      Fixes: a792af69
      
       ("ASoC: wm_adsp: Refactor compress stream initialisation")
      Signed-off-by: default avatarDinghao Liu <dinghao.liu@zju.edu.cn>
      Reviewed-by: default avatarRichard Fitzgerald <rf@opensource.cirrus.com>
      Link: https://lore.kernel.org/r/20231204074158.12026-1-dinghao.liu@zju.edu.cn
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4713be84