Skip to content
  1. Jul 28, 2023
  2. Jul 27, 2023
    • Dom Cobley's avatar
    • Greg Kroah-Hartman's avatar
    • Hersen Wu's avatar
      Revert "drm/amd/display: edp do not add non-edid timings" · 1d4607f2
      Hersen Wu authored
      commit d6149086 upstream.
      
      This change causes regression when eDP and external display in mirror
      mode. When external display supports low resolution than eDP, use eDP
      timing to driver external display may cause corruption on external
      display.
      
      This reverts commit e749dd10.
      
      Cc: stable@vger.kernel.org
      Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2655
      
      
      Signed-off-by: default avatarHersen Wu <hersenxs.wu@amd.com>
      Reviewed-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1d4607f2
    • Wayne Lin's avatar
      drm/amd/display: Add polling method to handle MST reply packet · 2f2ba3c1
      Wayne Lin authored
      
      
      commit 4f6d9e38 upstream.
      
      [Why]
      Specific TBT4 dock doesn't send out short HPD to notify source
      that IRQ event DOWN_REP_MSG_RDY is set. Which violates the spec
      and cause source can't send out streams to mst sinks.
      
      [How]
      To cover this misbehavior, add an additional polling method to detect
      DOWN_REP_MSG_RDY is set. HPD driven handling method is still kept.
      Just hook up our handler to drm mgr->cbs->poll_hpd_irq().
      
      Cc: Mario Limonciello <mario.limonciello@amd.com>
      Cc: Alex Deucher <alexander.deucher@amd.com>
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarJerry Zuo <jerry.zuo@amd.com>
      Acked-by: default avatarAlan Liu <haoping.liu@amd.com>
      Signed-off-by: default avatarWayne Lin <wayne.lin@amd.com>
      Tested-by: default avatarDaniel Wheeler <daniel.wheeler@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2f2ba3c1
    • Hersen Wu's avatar
      drm/amd/display: fix linux dp link lost handled only one time · 78ea2ed7
      Hersen Wu authored
      
      
      commit e322843e upstream.
      
      [Why]
      linux amdgpu defer handle link lost irq. dm add handle
      request to irq work queue for the first irq of link lost.
      if link training fails for link lost handle, link will not
      be enabled anymore.
      
      [How]
      allow adding handle request of link lost to work queue
      before running dp link training for link lost.
      
      Signed-off-by: default avatarHersen Wu <hersenxs.wu@amd.com>
      Acked-by: default avatarAlex Hung <alex.hung@amd.com>
      Tested-by: default avatarDaniel Wheeler <daniel.wheeler@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      [ Modified due to not having
        c5a31f17 ("drm/amd/display: move dp irq handler functions from dc_link_dp to link_dp_irq_handler")
        until kernel 6.3-rc1.]
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      78ea2ed7
    • Srinivasan Shanmugam's avatar
      drm/amd/display: Clean up errors & warnings in amdgpu_dm.c · b31143b0
      Srinivasan Shanmugam authored
      
      
      commit 87279fdf upstream.
      
      Fix the following errors & warnings reported by checkpatch:
      
      ERROR: space required before the open brace '{'
      ERROR: space required before the open parenthesis '('
      ERROR: that open brace { should be on the previous line
      ERROR: space prohibited before that ',' (ctx:WxW)
      ERROR: else should follow close brace '}'
      ERROR: open brace '{' following function definitions go on the next line
      ERROR: code indent should use tabs where possible
      
      WARNING: braces {} are not necessary for single statement blocks
      WARNING: void function return statements are not generally useful
      WARNING: Block comments use * on subsequent lines
      WARNING: Block comments use a trailing */ on a separate line
      
      Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
      Cc: Aurabindo Pillai <aurabindo.pillai@amd.com>
      Cc: Alex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarSrinivasan Shanmugam <srinivasan.shanmugam@amd.com>
      Reviewed-by: default avatarRodrigo Siqueira <Rodrigo.Siqueira@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      [ Modified for missing
        c5a31f17 ("drm/amd/display: move dp irq handler functions from dc_link_dp to link_dp_irq_handler")
        which landed in 6.3]
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b31143b0
    • Qingqing Zhuo's avatar
      drm/amd/display: force connector state when bpc changes during compliance · c14702da
      Qingqing Zhuo authored
      
      
      commit 028c4ccf upstream.
      
      [Why]
      During DP DSC compliance tests, bpc requested would
      change between sub-tests, which requires stream
      to be recommited.
      
      [How]
      Force connector to disconnect and reconnect whenever
      there is a bpc change in automated test.
      
      Reviewed-by: default avatarJerry Zuo <Jerry.Zuo@amd.com>
      Acked-by: default avatarAlan Liu <HaoPing.Liu@amd.com>
      Signed-off-by: default avatarQingqing Zhuo <qingqing.zhuo@amd.com>
      Signed-off-by: default avatarhersen wu <hersenxs.wu@amd.com>
      Tested-by: default avatarDaniel Wheeler <daniel.wheeler@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      [ Adjustments for headers that were moved around in later commits. ]
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c14702da
    • Wayne Lin's avatar
      drm/dp_mst: Clear MSG_RDY flag before sending new message · 00f68f5c
      Wayne Lin authored
      
      
      commit 72f1de49 upstream.
      
      [Why]
      The sequence for collecting down_reply from source perspective should
      be:
      
      Request_n->repeat (get partial reply of Request_n->clear message ready
      flag to ack DPRX that the message is received) till all partial
      replies for Request_n are received->new Request_n+1.
      
      Now there is chance that drm_dp_mst_hpd_irq() will fire new down
      request in the tx queue when the down reply is incomplete. Source is
      restricted to generate interveleaved message transactions so we should
      avoid it.
      
      Also, while assembling partial reply packets, reading out DPCD DOWN_REP
      Sideband MSG buffer + clearing DOWN_REP_MSG_RDY flag should be
      wrapped up as a complete operation for reading out a reply packet.
      Kicking off a new request before clearing DOWN_REP_MSG_RDY flag might
      be risky. e.g. If the reply of the new request has overwritten the
      DPRX DOWN_REP Sideband MSG buffer before source writing one to clear
      DOWN_REP_MSG_RDY flag, source then unintentionally flushes the reply
      for the new request. Should handle the up request in the same way.
      
      [How]
      Separete drm_dp_mst_hpd_irq() into 2 steps. After acking the MST IRQ
      event, driver calls drm_dp_mst_hpd_irq_send_new_request() and might
      trigger drm_dp_mst_kick_tx() only when there is no on going message
      transaction.
      
      Changes since v1:
      * Reworked on review comments received
      -> Adjust the fix to let driver explicitly kick off new down request
      when mst irq event is handled and acked
      -> Adjust the commit message
      
      Changes since v2:
      * Adjust the commit message
      * Adjust the naming of the divided 2 functions and add a new input
        parameter "ack".
      * Adjust code flow as per review comments.
      
      Changes since v3:
      * Update the function description of drm_dp_mst_hpd_irq_handle_event
      
      Changes since v4:
      * Change ack of drm_dp_mst_hpd_irq_handle_event() to be an array align
        the size of esi[]
      
      Signed-off-by: default avatarWayne Lin <Wayne.Lin@amd.com>
      Reviewed-by: default avatarLyude Paul <lyude@redhat.com>
      Acked-by: default avatarJani Nikula <jani.nikula@intel.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      00f68f5c
    • Srinivasan Shanmugam's avatar
      drm/amd/display: fix some coding style issues · c085ffaf
      Srinivasan Shanmugam authored
      
      
      commit ae67558b upstream.
      
      Fix the following checkpatch checks in amdgpu_dm.c
      
      CHECK: Prefer kernel type 'u8' over 'uint8_t'
      CHECK: Prefer kernel type 'u32' over 'uint32_t'
      CHECK: Prefer kernel type 'u64' over 'uint64_t'
      CHECK: Prefer kernel type 's32' over 'int32_t'
      
      Signed-off-by: default avatarSrinivasan Shanmugam <srinivasan.shanmugam@amd.com>
      Reviewed-by: default avatarHarry Wentland <harry.wentland@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      [ PSR-SU support was introduced in kernel 6.2 with commits like
        30ebe415 ("drm/amd/display: add FB_DAMAGE_CLIPS support")
        but PSR-SU isn't enabled in 6.1.y, so this block needs to be skipped
        when backporting. ]
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c085ffaf
    • Hamza Mahfooz's avatar
      drm/amd/display: use max_dsc_bpp in amdgpu_dm · 374735cb
      Hamza Mahfooz authored
      
      
      commit 6e5abe94 upstream.
      
      Since, the quirk is handled in the DRM core now, we can use that value
      instead of the internal value.
      
      Reviewed-by: default avatarHarry Wentland <harry.wentland@amd.com>
      Signed-off-by: default avatarHamza Mahfooz <hamza.mahfooz@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      374735cb
    • Ilya Leoshkevich's avatar
      selftests/bpf: Fix sk_assign on s390x · 268bfb37
      Ilya Leoshkevich authored
      
      
      [ Upstream commit 7ce878ca ]
      
      sk_assign is failing on an s390x machine running Debian "bookworm" for
      2 reasons: legacy server_map definition and uninitialized addrlen in
      recvfrom() call.
      
      Fix by adding a new-style server_map definition and dropping addrlen
      (recvfrom() allows NULL values for src_addr and addrlen).
      
      Since the test should support tc built without libbpf, build the prog
      twice: with the old-style definition and with the new-style definition,
      then select the right one at runtime. This could be done at compile
      time too, but this would not be cross-compilation friendly.
      
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Link: https://lore.kernel.org/r/20230129190501.1624747-2-iii@linux.ibm.com
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      268bfb37
    • Yonghong Song's avatar
      selftests/bpf: Workaround verification failure for fexit_bpf2bpf/func_replace_return_code · fd1e31d1
      Yonghong Song authored
      
      
      [ Upstream commit 63d78b7e ]
      
      With latest llvm17, selftest fexit_bpf2bpf/func_replace_return_code
      has the following verification failure:
      
        0: R1=ctx(off=0,imm=0) R10=fp0
        ; int connect_v4_prog(struct bpf_sock_addr *ctx)
        0: (bf) r7 = r1                       ; R1=ctx(off=0,imm=0) R7_w=ctx(off=0,imm=0)
        1: (b4) w6 = 0                        ; R6_w=0
        ; memset(&tuple.ipv4.saddr, 0, sizeof(tuple.ipv4.saddr));
        ...
        ; return do_bind(ctx) ? 1 : 0;
        179: (bf) r1 = r7                     ; R1=ctx(off=0,imm=0) R7=ctx(off=0,imm=0)
        180: (85) call pc+147
        Func#3 is global and valid. Skipping.
        181: R0_w=scalar()
        181: (bc) w6 = w0                     ; R0_w=scalar() R6_w=scalar(umax=4294967295,var_off=(0x0; 0xffffffff))
        182: (05) goto pc-129
        ; }
        54: (bc) w0 = w6                      ; R0_w=scalar(umax=4294967295,var_off=(0x0; 0xffffffff)) R6_w=scalar(umax=4294967295,var_off=(0x0; 0xffffffff))
        55: (95) exit
        At program exit the register R0 has value (0x0; 0xffffffff) should have been in (0x0; 0x1)
        processed 281 insns (limit 1000000) max_states_per_insn 1 total_states 26 peak_states 26 mark_read 13
        -- END PROG LOAD LOG --
        libbpf: prog 'connect_v4_prog': failed to load: -22
      
      The corresponding source code:
      
        __attribute__ ((noinline))
        int do_bind(struct bpf_sock_addr *ctx)
        {
              struct sockaddr_in sa = {};
      
              sa.sin_family = AF_INET;
              sa.sin_port = bpf_htons(0);
              sa.sin_addr.s_addr = bpf_htonl(SRC_REWRITE_IP4);
      
              if (bpf_bind(ctx, (struct sockaddr *)&sa, sizeof(sa)) != 0)
                      return 0;
      
              return 1;
        }
        ...
        SEC("cgroup/connect4")
        int connect_v4_prog(struct bpf_sock_addr *ctx)
        {
        ...
              return do_bind(ctx) ? 1 : 0;
        }
      
      Insn 180 is a call to 'do_bind'. The call's return value is also the return value
      for the program. Since do_bind() returns 0/1, so it is legitimate for compiler to
      optimize 'return do_bind(ctx) ? 1 : 0' to 'return do_bind(ctx)'. However, such
      optimization breaks verifier as the return value of 'do_bind()' is marked as any
      scalar which violates the requirement of prog return value 0/1.
      
      There are two ways to fix this problem, (1) changing 'return 1' in do_bind() to
      e.g. 'return 10' so the compiler has to do 'do_bind(ctx) ? 1 :0', or (2)
      suggested by Andrii, marking do_bind() with __weak attribute so the compiler
      cannot make any assumption on do_bind() return value.
      
      This patch adopted adding __weak approach which is simpler and more resistant
      to potential compiler optimizations.
      
      Suggested-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20230310012410.2920570-1-yhs@fb.com
      
      
      Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fd1e31d1
    • Andrii Nakryiko's avatar
      selftests/bpf: make test_align selftest more robust · a7c1eb9c
      Andrii Nakryiko authored
      
      
      [ Upstream commit 4f999b76 ]
      
      test_align selftest relies on BPF verifier log emitting register states
      for specific instructions in expected format. Unfortunately, BPF
      verifier precision backtracking log interferes with such expectations.
      And instruction on which precision propagation happens sometimes don't
      output full expected register states. This does indeed look like
      something to be improved in BPF verifier, but is beyond the scope of
      this patch set.
      
      So to make test_align a bit more robust, inject few dummy R4 = R5
      instructions which capture desired state of R5 and won't have precision
      tracking logs on them. This fixes tests until we can improve BPF
      verifier output in the presence of precision tracking.
      
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20221104163649.121784-7-andrii@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a7c1eb9c
    • Andrii Nakryiko's avatar
      bpf: aggressively forget precise markings during state checkpointing · 4c8f30a2
      Andrii Nakryiko authored
      
      
      [ Upstream commit 7a830b53 ]
      
      Exploit the property of about-to-be-checkpointed state to be able to
      forget all precise markings up to that point even more aggressively. We
      now clear all potentially inherited precise markings right before
      checkpointing and branching off into child state. If any of children
      states require precise knowledge of any SCALAR register, those will be
      propagated backwards later on before this state is finalized, preserving
      correctness.
      
      There is a single selftests BPF program change, but tremendous one: 25x
      reduction in number of verified instructions and states in
      trace_virtqueue_add_sgs.
      
      Cilium results are more modest, but happen across wider range of programs.
      
      SELFTESTS RESULTS
      =================
      
      $ ./veristat -C -e file,prog,insns,states ~/imprecise-early-results.csv ~/imprecise-aggressive-results.csv | grep -v '+0'
      File                 Program                  Total insns (A)  Total insns (B)  Total insns (DIFF)  Total states (A)  Total states (B)  Total states (DIFF)
      -------------------  -----------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      loop6.bpf.linked1.o  trace_virtqueue_add_sgs           398057            15114   -382943 (-96.20%)              8717               336      -8381 (-96.15%)
      -------------------  -----------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      
      CILIUM RESULTS
      ==============
      
      $ ./veristat -C -e file,prog,insns,states ~/imprecise-early-results-cilium.csv ~/imprecise-aggressive-results-cilium.csv | grep -v '+0'
      File           Program                           Total insns (A)  Total insns (B)  Total insns (DIFF)  Total states (A)  Total states (B)  Total states (DIFF)
      -------------  --------------------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      bpf_host.o     tail_handle_nat_fwd_ipv4                    23426            23221       -205 (-0.88%)              1537              1515         -22 (-1.43%)
      bpf_host.o     tail_handle_nat_fwd_ipv6                    13009            12904       -105 (-0.81%)               719               708         -11 (-1.53%)
      bpf_host.o     tail_nodeport_nat_ingress_ipv6               5261             5196        -65 (-1.24%)               247               243          -4 (-1.62%)
      bpf_host.o     tail_nodeport_nat_ipv6_egress                3446             3406        -40 (-1.16%)               203               198          -5 (-2.46%)
      bpf_lxc.o      tail_handle_nat_fwd_ipv4                    23426            23221       -205 (-0.88%)              1537              1515         -22 (-1.43%)
      bpf_lxc.o      tail_handle_nat_fwd_ipv6                    13009            12904       -105 (-0.81%)               719               708         -11 (-1.53%)
      bpf_lxc.o      tail_ipv4_ct_egress                          5074             4897       -177 (-3.49%)               255               248          -7 (-2.75%)
      bpf_lxc.o      tail_ipv4_ct_ingress                         5100             4923       -177 (-3.47%)               255               248          -7 (-2.75%)
      bpf_lxc.o      tail_ipv4_ct_ingress_policy_only             5100             4923       -177 (-3.47%)               255               248          -7 (-2.75%)
      bpf_lxc.o      tail_ipv6_ct_egress                          4558             4536        -22 (-0.48%)               188               187          -1 (-0.53%)
      bpf_lxc.o      tail_ipv6_ct_ingress                         4578             4556        -22 (-0.48%)               188               187          -1 (-0.53%)
      bpf_lxc.o      tail_ipv6_ct_ingress_policy_only             4578             4556        -22 (-0.48%)               188               187          -1 (-0.53%)
      bpf_lxc.o      tail_nodeport_nat_ingress_ipv6               5261             5196        -65 (-1.24%)               247               243          -4 (-1.62%)
      bpf_overlay.o  tail_nodeport_nat_ingress_ipv6               5261             5196        -65 (-1.24%)               247               243          -4 (-1.62%)
      bpf_overlay.o  tail_nodeport_nat_ipv6_egress                3482             3442        -40 (-1.15%)               204               201          -3 (-1.47%)
      bpf_xdp.o      tail_nodeport_nat_egress_ipv4               17200            15619      -1581 (-9.19%)              1111              1010        -101 (-9.09%)
      -------------  --------------------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20221104163649.121784-6-andrii@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4c8f30a2
    • Andrii Nakryiko's avatar
      bpf: stop setting precise in current state · 8b57a37d
      Andrii Nakryiko authored
      
      
      [ Upstream commit f63181b6 ]
      
      Setting reg->precise to true in current state is not necessary from
      correctness standpoint, but it does pessimise the whole precision (or
      rather "imprecision", because that's what we want to keep as much as
      possible) tracking. Why is somewhat subtle and my best attempt to
      explain this is recorded in an extensive comment for __mark_chain_precise()
      function. Some more careful thinking and code reading is probably required
      still to grok this completely, unfortunately. Whiteboarding and a bunch
      of extra handwaiving in person would be even more helpful, but is deemed
      impractical in Git commit.
      
      Next patch pushes this imprecision property even further, building on top of
      the insights described in this patch.
      
      End results are pretty nice, we get reduction in number of total instructions
      and states verified due to a better states reuse, as some of the states are now
      more generic and permissive due to less unnecessary precise=true requirements.
      
      SELFTESTS RESULTS
      =================
      
      $ ./veristat -C -e file,prog,insns,states ~/subprog-precise-results.csv ~/imprecise-early-results.csv | grep -v '+0'
      File                                     Program                 Total insns (A)  Total insns (B)  Total insns (DIFF)  Total states (A)  Total states (B)  Total states (DIFF)
      ---------------------------------------  ----------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      bpf_iter_ksym.bpf.linked1.o              dump_ksym                           347              285       -62 (-17.87%)                20                19          -1 (-5.00%)
      pyperf600_bpf_loop.bpf.linked1.o         on_event                           3678             3736        +58 (+1.58%)               276               285          +9 (+3.26%)
      setget_sockopt.bpf.linked1.o             skops_sockopt                      4038             3947        -91 (-2.25%)               347               343          -4 (-1.15%)
      test_l4lb.bpf.linked1.o                  balancer_ingress                   4559             2611     -1948 (-42.73%)               118               105        -13 (-11.02%)
      test_l4lb_noinline.bpf.linked1.o         balancer_ingress                   6279             6268        -11 (-0.18%)               237               236          -1 (-0.42%)
      test_misc_tcp_hdr_options.bpf.linked1.o  misc_estab                         1307             1303         -4 (-0.31%)               100                99          -1 (-1.00%)
      test_sk_lookup.bpf.linked1.o             ctx_narrow_access                   456              447         -9 (-1.97%)                39                38          -1 (-2.56%)
      test_sysctl_loop1.bpf.linked1.o          sysctl_tcp_mem                     1389             1384         -5 (-0.36%)                26                25          -1 (-3.85%)
      test_tc_dtime.bpf.linked1.o              egress_fwdns_prio101                518              485        -33 (-6.37%)                51                46          -5 (-9.80%)
      test_tc_dtime.bpf.linked1.o              egress_host                         519              468        -51 (-9.83%)                50                44         -6 (-12.00%)
      test_tc_dtime.bpf.linked1.o              ingress_fwdns_prio101               842             1000      +158 (+18.76%)                73                88        +15 (+20.55%)
      xdp_synproxy_kern.bpf.linked1.o          syncookie_tc                     405757           373173     -32584 (-8.03%)             25735             22882      -2853 (-11.09%)
      xdp_synproxy_kern.bpf.linked1.o          syncookie_xdp                    479055           371590   -107465 (-22.43%)             29145             22207      -6938 (-23.81%)
      ---------------------------------------  ----------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      
      Slight regression in test_tc_dtime.bpf.linked1.o/ingress_fwdns_prio101
      is left for a follow up, there might be some more precision-related bugs
      in existing BPF verifier logic.
      
      CILIUM RESULTS
      ==============
      
      $ ./veristat -C -e file,prog,insns,states ~/subprog-precise-results-cilium.csv ~/imprecise-early-results-cilium.csv | grep -v '+0'
      File           Program                         Total insns (A)  Total insns (B)  Total insns (DIFF)  Total states (A)  Total states (B)  Total states (DIFF)
      -------------  ------------------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      bpf_host.o     cil_from_host                               762              556      -206 (-27.03%)                43                37         -6 (-13.95%)
      bpf_host.o     tail_handle_nat_fwd_ipv4                  23541            23426       -115 (-0.49%)              1538              1537          -1 (-0.07%)
      bpf_host.o     tail_nodeport_nat_egress_ipv4             33592            33566        -26 (-0.08%)              2163              2161          -2 (-0.09%)
      bpf_lxc.o      tail_handle_nat_fwd_ipv4                  23541            23426       -115 (-0.49%)              1538              1537          -1 (-0.07%)
      bpf_overlay.o  tail_nodeport_nat_egress_ipv4             33581            33543        -38 (-0.11%)              2160              2157          -3 (-0.14%)
      bpf_xdp.o      tail_handle_nat_fwd_ipv4                  21659            20920       -739 (-3.41%)              1440              1376         -64 (-4.44%)
      bpf_xdp.o      tail_handle_nat_fwd_ipv6                  17084            17039        -45 (-0.26%)               907               905          -2 (-0.22%)
      bpf_xdp.o      tail_lb_ipv4                              73442            73430        -12 (-0.02%)              4370              4369          -1 (-0.02%)
      bpf_xdp.o      tail_lb_ipv6                             152114           151895       -219 (-0.14%)              6493              6479         -14 (-0.22%)
      bpf_xdp.o      tail_nodeport_nat_egress_ipv4             17377            17200       -177 (-1.02%)              1125              1111         -14 (-1.24%)
      bpf_xdp.o      tail_nodeport_nat_ingress_ipv6             6405             6397         -8 (-0.12%)               309               308          -1 (-0.32%)
      bpf_xdp.o      tail_rev_nodeport_lb4                      7126             6934       -192 (-2.69%)               414               402         -12 (-2.90%)
      bpf_xdp.o      tail_rev_nodeport_lb6                     18059            17905       -154 (-0.85%)              1105              1096          -9 (-0.81%)
      -------------  ------------------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20221104163649.121784-5-andrii@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8b57a37d
    • Andrii Nakryiko's avatar
      bpf: allow precision tracking for programs with subprogs · 56675ddc
      Andrii Nakryiko authored
      
      
      [ Upstream commit be2ef816 ]
      
      Stop forcing precise=true for SCALAR registers when BPF program has any
      subprograms. Current restriction means that any BPF program, as soon as
      it uses subprograms, will end up not getting any of the precision
      tracking benefits in reduction of number of verified states.
      
      This patch keeps the fallback mark_all_scalars_precise() behavior if
      precise marking has to cross function frames. E.g., if subprogram
      requires R1 (first input arg) to be marked precise, ideally we'd need to
      backtrack to the parent function and keep marking R1 and its
      dependencies as precise. But right now we give up and force all the
      SCALARs in any of the current and parent states to be forced to
      precise=true. We can lift that restriction in the future.
      
      But this patch fixes two issues identified when trying to enable
      precision tracking for subprogs.
      
      First, prevent "escaping" from top-most state in a global subprog. While
      with entry-level BPF program we never end up requesting precision for
      R1-R5 registers, because R2-R5 are not initialized (and so not readable
      in correct BPF program), and R1 is PTR_TO_CTX, not SCALAR, and so is
      implicitly precise. With global subprogs, though, it's different, as
      global subprog a) can have up to 5 SCALAR input arguments, which might
      get marked as precise=true and b) it is validated in isolation from its
      main entry BPF program. b) means that we can end up exhausting parent
      state chain and still not mark all registers in reg_mask as precise,
      which would lead to verifier bug warning.
      
      To handle that, we need to consider two cases. First, if the very first
      state is not immediately "checkpointed" (i.e., stored in state lookup
      hashtable), it will get correct first_insn_idx and last_insn_idx
      instruction set during state checkpointing. As such, this case is
      already handled and __mark_chain_precision() already handles that by
      just doing nothing when we reach to the very first parent state.
      st->parent will be NULL and we'll just stop. Perhaps some extra check
      for reg_mask and stack_mask is due here, but this patch doesn't address
      that issue.
      
      More problematic second case is when global function's initial state is
      immediately checkpointed before we manage to process the very first
      instruction. This is happening because when there is a call to global
      subprog from the main program the very first subprog's instruction is
      marked as pruning point, so before we manage to process first
      instruction we have to check and checkpoint state. This patch adds
      a special handling for such "empty" state, which is identified by having
      st->last_insn_idx set to -1. In such case, we check that we are indeed
      validating global subprog, and with some sanity checking we mark input
      args as precise if requested.
      
      Note that we also initialize state->first_insn_idx with correct start
      insn_idx offset. For main program zero is correct value, but for any
      subprog it's quite confusing to not have first_insn_idx set. This
      doesn't have any functional impact, but helps with debugging and state
      printing. We also explicitly initialize state->last_insns_idx instead of
      relying on is_state_visited() to do this with env->prev_insns_idx, which
      will be -1 on the very first instruction. This concludes necessary
      changes to handle specifically global subprog's precision tracking.
      
      Second identified problem was missed handling of BPF helper functions
      that call into subprogs (e.g., bpf_loop and few others). From precision
      tracking and backtracking logic's standpoint those are effectively calls
      into subprogs and should be called as BPF_PSEUDO_CALL calls.
      
      This patch takes the least intrusive way and just checks against a short
      list of current BPF helpers that do call subprogs, encapsulated in
      is_callback_calling_function() function. But to prevent accidentally
      forgetting to add new BPF helpers to this "list", we also do a sanity
      check in __check_func_call, which has to be called for each such special
      BPF helper, to validate that BPF helper is indeed recognized as
      callback-calling one. This should catch any missed checks in the future.
      Adding some special flags to be added in function proto definitions
      seemed like an overkill in this case.
      
      With the above changes, it's possible to remove forceful setting of
      reg->precise to true in __mark_reg_unknown, which turns on precision
      tracking both inside subprogs and entry progs that have subprogs. No
      warnings or errors were detected across all the selftests, but also when
      validating with veristat against internal Meta BPF objects and Cilium
      objects. Further, in some BPF programs there are noticeable reduction in
      number of states and instructions validated due to more effective
      precision tracking, especially benefiting syncookie test.
      
      $ ./veristat -C -e file,prog,insns,states ~/baseline-results.csv ~/subprog-precise-results.csv  | grep -v '+0'
      File                                      Program                     Total insns (A)  Total insns (B)  Total insns (DIFF)  Total states (A)  Total states (B)  Total states (DIFF)
      ----------------------------------------  --------------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      pyperf600_bpf_loop.bpf.linked1.o          on_event                               3966             3678       -288 (-7.26%)               306               276         -30 (-9.80%)
      pyperf_global.bpf.linked1.o               on_event                               7563             7530        -33 (-0.44%)               520               517          -3 (-0.58%)
      pyperf_subprogs.bpf.linked1.o             on_event                              36358            36934       +576 (+1.58%)              2499              2531         +32 (+1.28%)
      setget_sockopt.bpf.linked1.o              skops_sockopt                          3965             4038        +73 (+1.84%)               343               347          +4 (+1.17%)
      test_cls_redirect_subprogs.bpf.linked1.o  cls_redirect                          64965            64901        -64 (-0.10%)              4619              4612          -7 (-0.15%)
      test_misc_tcp_hdr_options.bpf.linked1.o   misc_estab                             1491             1307      -184 (-12.34%)               110               100         -10 (-9.09%)
      test_pkt_access.bpf.linked1.o             test_pkt_access                         354              349         -5 (-1.41%)                25                24          -1 (-4.00%)
      test_sock_fields.bpf.linked1.o            egress_read_sock_fields                 435              375       -60 (-13.79%)                22                20          -2 (-9.09%)
      test_sysctl_loop2.bpf.linked1.o           sysctl_tcp_mem                         1508             1501         -7 (-0.46%)                29                28          -1 (-3.45%)
      test_tc_dtime.bpf.linked1.o               egress_fwdns_prio100                    468              435        -33 (-7.05%)                45                41          -4 (-8.89%)
      test_tc_dtime.bpf.linked1.o               ingress_fwdns_prio100                   398              408        +10 (+2.51%)                42                39          -3 (-7.14%)
      test_tc_dtime.bpf.linked1.o               ingress_fwdns_prio101                  1096              842      -254 (-23.18%)                97                73        -24 (-24.74%)
      test_tcp_hdr_options.bpf.linked1.o        estab                                  2758             2408      -350 (-12.69%)               208               181        -27 (-12.98%)
      test_urandom_usdt.bpf.linked1.o           urand_read_with_sema                    466              448        -18 (-3.86%)                31                28          -3 (-9.68%)
      test_urandom_usdt.bpf.linked1.o           urand_read_without_sema                 466              448        -18 (-3.86%)                31                28          -3 (-9.68%)
      test_urandom_usdt.bpf.linked1.o           urandlib_read_with_sema                 466              448        -18 (-3.86%)                31                28          -3 (-9.68%)
      test_urandom_usdt.bpf.linked1.o           urandlib_read_without_sema              466              448        -18 (-3.86%)                31                28          -3 (-9.68%)
      test_xdp_noinline.bpf.linked1.o           balancer_ingress_v6                    4302             4294         -8 (-0.19%)               257               256          -1 (-0.39%)
      xdp_synproxy_kern.bpf.linked1.o           syncookie_tc                         583722           405757   -177965 (-30.49%)             35846             25735     -10111 (-28.21%)
      xdp_synproxy_kern.bpf.linked1.o           syncookie_xdp                        609123           479055   -130068 (-21.35%)             35452             29145      -6307 (-17.79%)
      ----------------------------------------  --------------------------  ---------------  ---------------  ------------------  ----------------  ----------------  -------------------
      
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20221104163649.121784-4-andrii@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      56675ddc
    • Masahiro Yamada's avatar
      scripts/kallsyms: update the usage in the comment block · dd33fbe4
      Masahiro Yamada authored
      
      
      commit 79549da6 upstream.
      
      Commit 010a0aad ("kallsyms: Correctly sequence symbols when
      CONFIG_LTO_CLANG=y") added --lto-clang, and updated the usage()
      function, but not the comment. Update it in the same way.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dd33fbe4
    • Yuma Ueda's avatar
      scripts/kallsyms.c Make the comment up-to-date with current implementation · 5fab8c91
      Yuma Ueda authored
      
      
      commit adc40221 upstream.
      
      The comment in scripts/kallsyms.c describing the usage of
      scripts/kallsyms does not reflect the latest implementation.
      Fix the comment to be equivalent to what the usage() function prints.
      
      Signed-off-by: default avatarYuma Ueda <cyan@0x00a1e9.dev>
      Reviewed-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      Link: https://lore.kernel.org/r/20221118133631.4554-1-cyan@0x00a1e9.dev
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5fab8c91
    • Arnd Bergmann's avatar
      kallsyms: add kallsyms_seqs_of_names to list of special symbols · 320f980b
      Arnd Bergmann authored
      
      
      commit ced0f245 upstream.
      
      My randconfig build setup ran into another kallsyms warning:
      
      Inconsistent kallsyms data
      Try make KALLSYMS_EXTRA_PASS=1 as a workaround
      
      After adding some debugging code to kallsyms.c, I saw that the recently
      added kallsyms_seqs_of_names symbol can sometimes cause the second stage
      table to be slightly longer than the first stage, which makes the
      build inconsistent.
      
      Add it to the exception table that contains all other kallsyms-generated
      symbols.
      
      Fixes: 60443c88 ("kallsyms: Improve the performance of kallsyms_lookup_name()")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      320f980b
    • Abe Kohandel's avatar
      spi: dw: Remove misleading comment for Mount Evans SoC · 7531eb07
      Abe Kohandel authored
      
      
      commit 5b6d0b91 upstream.
      
      Remove a misleading comment about the DMA operations of the Intel Mount
      Evans SoC's SPI Controller as requested by Serge.
      
      Signed-off-by: default avatarAbe Kohandel <abe.kohandel@intel.com>
      Link: https://lore.kernel.org/linux-spi/20230606191333.247ucbf7h3tlooxf@mobilestation/
      
      
      Fixes: 0760d5d0 ("spi: dw: Add compatible for Intel Mount Evans SoC")
      Reviewed-by: default avatarSerge Semin <fancer.lancer@gmail.com>
      Link: https://lore.kernel.org/r/20230606231844.726272-1-abe.kohandel@intel.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7531eb07
    • Yunxiang Li's avatar
      drm/ttm: fix bulk_move corruption when adding a entry · 70a30156
      Yunxiang Li authored
      
      
      commit 44819136 upstream.
      
      When the resource is the first in the bulk_move range, adding it again
      (thus moving it to the tail) will corrupt the list since the first
      pointer is not moved. This eventually lead to null pointer deref in
      ttm_lru_bulk_move_del()
      
      Fixes: fee2ede1 ("drm/ttm: rework bulk move handling v5")
      Signed-off-by: default avatarYunxiang Li <Yunxiang.Li@amd.com>
      Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
      CC: stable@vger.kernel.org
      Link: https://patchwork.freedesktop.org/patch/msgid/20230622141902.28718-3-Yunxiang.Li@amd.com
      
      
      Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      70a30156
    • Mohamed Khalfella's avatar
      tracing/histograms: Return an error if we fail to add histogram to hist_vars list · 61622fa3
      Mohamed Khalfella authored
      commit 4b8b3905 upstream.
      
      Commit 6018b585 ("tracing/histograms: Add histograms to hist_vars if
      they have referenced variables") added a check to fail histogram creation
      if save_hist_vars() failed to add histogram to hist_vars list. But the
      commit failed to set ret to failed return code before jumping to
      unregister histogram, fix it.
      
      Link: https://lore.kernel.org/linux-trace-kernel/20230714203341.51396-1-mkhalfella@purestorage.com
      
      
      
      Cc: stable@vger.kernel.org
      Fixes: 6018b585 ("tracing/histograms: Add histograms to hist_vars if they have referenced variables")
      Signed-off-by: default avatarMohamed Khalfella <mkhalfella@purestorage.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      61622fa3
    • Zhang Yi's avatar
      jbd2: recheck chechpointing non-dirty buffer · bae17da3
      Zhang Yi authored
      
      
      commit c2d6fd9d upstream.
      
      There is a long-standing metadata corruption issue that happens from
      time to time, but it's very difficult to reproduce and analyse, benefit
      from the JBD2_CYCLE_RECORD option, we found out that the problem is the
      checkpointing process miss to write out some buffers which are raced by
      another do_get_write_access(). Looks below for detail.
      
      jbd2_log_do_checkpoint() //transaction X
       //buffer A is dirty and not belones to any transaction
       __buffer_relink_io() //move it to the IO list
       __flush_batch()
        write_dirty_buffer()
                                   do_get_write_access()
                                   clear_buffer_dirty
                                   __jbd2_journal_file_buffer()
                                   //add buffer A to a new transaction Y
         lock_buffer(bh)
         //doesn't write out
       __jbd2_journal_remove_checkpoint()
       //finish checkpoint except buffer A
       //filesystem corrupt if the new transaction Y isn't fully write out.
      
      Due to the t_checkpoint_list walking loop in jbd2_log_do_checkpoint()
      have already handles waiting for buffers under IO and re-added new
      transaction to complete commit, and it also removing cleaned buffers,
      this makes sure the list will eventually get empty. So it's fine to
      leave buffers on the t_checkpoint_list while flushing out and completely
      stop using the t_checkpoint_io_list.
      
      Cc: stable@vger.kernel.org
      Suggested-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarZhang Yi <yi.zhang@huawei.com>
      Tested-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20230606135928.434610-2-yi.zhang@huaweicloud.com
      
      
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bae17da3
    • Vladimir Oltean's avatar
      net: phy: prevent stale pointer dereference in phy_init() · b9f0f20a
      Vladimir Oltean authored
      [ Upstream commit 1c613bea ]
      
      mdio_bus_init() and phy_driver_register() both have error paths, and if
      those are ever hit, ethtool will have a stale pointer to the
      phy_ethtool_phy_ops stub structure, which references memory from a
      module that failed to load (phylib).
      
      It is probably hard to force an error in this code path even manually,
      but the error teardown path of phy_init() should be the same as
      phy_exit(), which is now simply not the case.
      
      Fixes: 55d8f053 ("net: phy: Register ethtool PHY operations")
      Link: https://lore.kernel.org/netdev/ZLaiJ4G6TaJYGJyU@shell.armlinux.org.uk/
      
      
      Suggested-by: default avatarRussell King (Oracle) <linux@armlinux.org.uk>
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Link: https://lore.kernel.org/r/20230720000231.1939689-1-vladimir.oltean@nxp.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b9f0f20a
    • Eric Dumazet's avatar
      tcp: annotate data-races around fastopenq.max_qlen · f311c768
      Eric Dumazet authored
      
      
      [ Upstream commit 70f360dd ]
      
      This field can be read locklessly.
      
      Fixes: 1536e285 ("tcp: Add a TCP_FASTOPEN socket option to get a max backlog on its listner")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-12-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f311c768
    • Eric Dumazet's avatar
      tcp: annotate data-races around icsk->icsk_user_timeout · 01a1563a
      Eric Dumazet authored
      
      
      [ Upstream commit 26023e91 ]
      
      This field can be read locklessly from do_tcp_getsockopt()
      
      Fixes: dca43c75 ("tcp: Add TCP_USER_TIMEOUT socket option.")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-11-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      01a1563a
    • Eric Dumazet's avatar
      tcp: annotate data-races around tp->notsent_lowat · 918a1beb
      Eric Dumazet authored
      
      
      [ Upstream commit 1aeb87bc ]
      
      tp->notsent_lowat can be read locklessly from do_tcp_getsockopt()
      and tcp_poll().
      
      Fixes: c9bee3b7 ("tcp: TCP_NOTSENT_LOWAT socket option")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-10-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      918a1beb
    • Eric Dumazet's avatar
      tcp: annotate data-races around rskq_defer_accept · b02f8fce
      Eric Dumazet authored
      
      
      [ Upstream commit ae488c74 ]
      
      do_tcp_getsockopt() reads rskq_defer_accept while another cpu
      might change its value.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-9-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b02f8fce
    • Eric Dumazet's avatar
      tcp: annotate data-races around tp->linger2 · 17c3d758
      Eric Dumazet authored
      
      
      [ Upstream commit 9df5335c ]
      
      do_tcp_getsockopt() reads tp->linger2 while another cpu
      might change its value.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-8-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      17c3d758
    • Eric Dumazet's avatar
      tcp: annotate data-races around icsk->icsk_syn_retries · e6393972
      Eric Dumazet authored
      
      
      [ Upstream commit 3a037f0f ]
      
      do_tcp_getsockopt() and reqsk_timer_handler() read
      icsk->icsk_syn_retries while another cpu might change its value.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-7-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e6393972
    • Eric Dumazet's avatar
      tcp: annotate data-races around tp->keepalive_probes · d27a1aa3
      Eric Dumazet authored
      
      
      [ Upstream commit 6e5e1de6 ]
      
      do_tcp_getsockopt() reads tp->keepalive_probes while another cpu
      might change its value.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-6-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d27a1aa3
    • Eric Dumazet's avatar
      tcp: annotate data-races around tp->keepalive_intvl · 161b0693
      Eric Dumazet authored
      
      
      [ Upstream commit 5ecf9d4f ]
      
      do_tcp_getsockopt() reads tp->keepalive_intvl while another cpu
      might change its value.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-5-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      161b0693
    • Eric Dumazet's avatar
      tcp: annotate data-races around tp->keepalive_time · 87b8466e
      Eric Dumazet authored
      
      
      [ Upstream commit 4164245c ]
      
      do_tcp_getsockopt() reads tp->keepalive_time while another cpu
      might change its value.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-4-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      87b8466e
    • Eric Dumazet's avatar
      tcp: annotate data-races around tp->tsoffset · 2c84a3d7
      Eric Dumazet authored
      
      
      [ Upstream commit dd23c9f1 ]
      
      do_tcp_getsockopt() reads tp->tsoffset while another cpu
      might change its value.
      
      Fixes: 93be6ce0 ("tcp: set and get per-socket timestamp")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-3-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2c84a3d7
    • Eric Dumazet's avatar
      tcp: annotate data-races around tp->tcp_tx_delay · 949eb838
      Eric Dumazet authored
      
      
      [ Upstream commit 348b81b6 ]
      
      do_tcp_getsockopt() reads tp->tcp_tx_delay while another cpu
      might change its value.
      
      Fixes: a842fe14 ("tcp: add optional per socket transmit delay")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230719212857.3943972-2-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      949eb838
    • Douglas Anderson's avatar
      Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_remove_adv_monitor() · 0d4d6b08
      Douglas Anderson authored
      
      
      [ Upstream commit de6dfcef ]
      
      KASAN reports that there's a use-after-free in
      hci_remove_adv_monitor(). Trawling through the disassembly, you can
      see that the complaint is from the access in bt_dev_dbg() under the
      HCI_ADV_MONITOR_EXT_MSFT case. The problem case happens because
      msft_remove_monitor() can end up freeing the monitor
      structure. Specifically:
        hci_remove_adv_monitor() ->
        msft_remove_monitor() ->
        msft_remove_monitor_sync() ->
        msft_le_cancel_monitor_advertisement_cb() ->
        hci_free_adv_monitor()
      
      Let's fix the problem by just stashing the relevant data when it's
      still valid.
      
      Fixes: 7cf5c297 ("Bluetooth: hci_sync: Refactor remove Adv Monitor")
      Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0d4d6b08
    • Pauli Virtanen's avatar
      Bluetooth: ISO: fix iso_conn related locking and validity issues · e969bfed
      Pauli Virtanen authored
      
      
      [ Upstream commit d40ae85e ]
      
      sk->sk_state indicates whether iso_pi(sk)->conn is valid. Operations
      that check/update sk_state and access conn should hold lock_sock,
      otherwise they can race.
      
      The order of taking locks is hci_dev_lock > lock_sock > iso_conn_lock,
      which is how it is in connect/disconnect_cfm -> iso_conn_del ->
      iso_chan_del.
      
      Fix locking in iso_connect_cis/bis and sendmsg/recvmsg to take lock_sock
      around updating sk_state and conn.
      
      iso_conn_del must not occur during iso_connect_cis/bis, as it frees the
      iso_conn. Hold hdev->lock longer to prevent that.
      
      This should not reintroduce the issue fixed in commit 241f5193
      ("Bluetooth: ISO: Avoid circular locking dependency"), since the we
      acquire locks in order. We retain the fix in iso_sock_connect to release
      lock_sock before iso_connect_* acquires hdev->lock.
      
      Similarly for commit 6a5ad251 ("Bluetooth: ISO: Fix possible
      circular locking dependency"). We retain the fix in iso_conn_ready to
      not acquire iso_conn_lock before lock_sock.
      
      iso_conn_add shall return iso_conn with valid hcon. Make it so also when
      reusing an old CIS connection waiting for disconnect timeout (see
      __iso_sock_close where conn->hcon is set to NULL).
      
      Trace with iso_conn_del after iso_chan_add in iso_connect_cis:
      ===============================================================
      iso_sock_create:771: sock 00000000be9b69b7
      iso_sock_init:693: sk 000000004dff667e
      iso_sock_bind:827: sk 000000004dff667e 70:1a:b8:98:ff:a2 type 1
      iso_sock_setsockopt:1289: sk 000000004dff667e
      iso_sock_setsockopt:1289: sk 000000004dff667e
      iso_sock_setsockopt:1289: sk 000000004dff667e
      iso_sock_connect:875: sk 000000004dff667e
      iso_connect_cis:353: 70:1a:b8:98:ff:a2 -> 28:3d:c2:4a:7e:da
      hci_get_route:1199: 70:1a:b8:98:ff:a2 -> 28:3d:c2:4a:7e:da
      hci_conn_add:1005: hci0 dst 28:3d:c2:4a:7e:da
      iso_conn_add:140: hcon 000000007b65d182 conn 00000000daf8625e
      __iso_chan_add:214: conn 00000000daf8625e
      iso_connect_cfm:1700: hcon 000000007b65d182 bdaddr 28:3d:c2:4a:7e:da status 12
      iso_conn_del:187: hcon 000000007b65d182 conn 00000000daf8625e, err 16
      iso_sock_clear_timer:117: sock 000000004dff667e state 3
          <Note: sk_state is BT_BOUND (3), so iso_connect_cis is still
          running at this point>
      iso_chan_del:153: sk 000000004dff667e, conn 00000000daf8625e, err 16
      hci_conn_del:1151: hci0 hcon 000000007b65d182 handle 65535
      hci_conn_unlink:1102: hci0: hcon 000000007b65d182
      hci_chan_list_flush:2780: hcon 000000007b65d182
      iso_sock_getsockopt:1376: sk 000000004dff667e
      iso_sock_getname:1070: sock 00000000be9b69b7, sk 000000004dff667e
      iso_sock_getname:1070: sock 00000000be9b69b7, sk 000000004dff667e
      iso_sock_getsockopt:1376: sk 000000004dff667e
      iso_sock_getname:1070: sock 00000000be9b69b7, sk 000000004dff667e
      iso_sock_getname:1070: sock 00000000be9b69b7, sk 000000004dff667e
      iso_sock_shutdown:1434: sock 00000000be9b69b7, sk 000000004dff667e, how 1
      __iso_sock_close:632: sk 000000004dff667e state 5 socket 00000000be9b69b7
           <Note: sk_state is BT_CONNECT (5), even though iso_chan_del sets
           BT_CLOSED (6). Only iso_connect_cis sets it to BT_CONNECT, so it
           must be that iso_chan_del occurred between iso_chan_add and end of
           iso_connect_cis.>
      BUG: kernel NULL pointer dereference, address: 0000000000000000
      PGD 8000000006467067 P4D 8000000006467067 PUD 3f5f067 PMD 0
      Oops: 0000 [#1] PREEMPT SMP PTI
      Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
      RIP: 0010:__iso_sock_close (net/bluetooth/iso.c:664) bluetooth
      ===============================================================
      
      Trace with iso_conn_del before iso_chan_add in iso_connect_cis:
      ===============================================================
      iso_connect_cis:356: 70:1a:b8:98:ff:a2 -> 28:3d:c2:4a:7e:da
      ...
      iso_conn_add:140: hcon 0000000093bc551f conn 00000000768ae504
      hci_dev_put:1487: hci0 orig refcnt 21
      hci_event_packet:7607: hci0: event 0x0e
      hci_cmd_complete_evt:4231: hci0: opcode 0x2062
      hci_cc_le_set_cig_params:3846: hci0: status 0x07
      hci_sent_cmd_data:3107: hci0 opcode 0x2062
      iso_connect_cfm:1703: hcon 0000000093bc551f bdaddr 28:3d:c2:4a:7e:da status 7
      iso_conn_del:187: hcon 0000000093bc551f conn 00000000768ae504, err 12
      hci_conn_del:1151: hci0 hcon 0000000093bc551f handle 65535
      hci_conn_unlink:1102: hci0: hcon 0000000093bc551f
      hci_chan_list_flush:2780: hcon 0000000093bc551f
      __iso_chan_add:214: conn 00000000768ae504
          <Note: this conn was already freed in iso_conn_del above>
      iso_sock_clear_timer:117: sock 0000000098323f95 state 3
      general protection fault, probably for non-canonical address 0x30b29c630930aec8: 0000 [#1] PREEMPT SMP PTI
      CPU: 1 PID: 1920 Comm: bluetoothd Tainted: G            E      6.3.0-rc7+ #4
      Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
      RIP: 0010:detach_if_pending+0x28/0xd0
      Code: 90 90 0f 1f 44 00 00 48 8b 47 08 48 85 c0 0f 84 ad 00 00 00 55 89 d5 53 48 83 3f 00 48 89 fb 74 7d 66 90 48 8b 03 48 8b 53 08 <>
      RSP: 0018:ffffb90841a67d08 EFLAGS: 00010007
      RAX: 0000000000000000 RBX: ffff9141bd5061b8 RCX: 0000000000000000
      RDX: 30b29c630930aec8 RSI: ffff9141fdd21e80 RDI: ffff9141bd5061b8
      RBP: 0000000000000001 R08: 0000000000000000 R09: ffffb90841a67b88
      R10: 0000000000000003 R11: ffffffff8613f558 R12: ffff9141fdd21e80
      R13: 0000000000000000 R14: ffff9141b5976010 R15: ffff914185755338
      FS:  00007f45768bd840(0000) GS:ffff9141fdd00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000619000424074 CR3: 0000000009f5e005 CR4: 0000000000170ee0
      Call Trace:
       <TASK>
       timer_delete+0x48/0x80
       try_to_grab_pending+0xdf/0x170
       __cancel_work+0x37/0xb0
       iso_connect_cis+0x141/0x400 [bluetooth]
      ===============================================================
      
      Trace with NULL conn->hcon in state BT_CONNECT:
      ===============================================================
      __iso_sock_close:619: sk 00000000f7c71fc5 state 1 socket 00000000d90c5fe5
      ...
      __iso_sock_close:619: sk 00000000f7c71fc5 state 8 socket 00000000d90c5fe5
      iso_chan_del:153: sk 00000000f7c71fc5, conn 0000000022c03a7e, err 104
      ...
      iso_sock_connect:862: sk 00000000129b56c3
      iso_connect_cis:348: 70:1a:b8:98:ff:a2 -> 28:3d:c2:4a:7d:2a
      hci_get_route:1199: 70:1a:b8:98:ff:a2 -> 28:3d:c2:4a:7d:2a
      hci_dev_hold:1495: hci0 orig refcnt 19
      __iso_chan_add:214: conn 0000000022c03a7e
          <Note: reusing old conn>
      iso_sock_clear_timer:117: sock 00000000129b56c3 state 3
      ...
      iso_sock_ready:1485: sk 00000000129b56c3
      ...
      iso_sock_sendmsg:1077: sock 00000000e5013966, sk 00000000129b56c3
      BUG: kernel NULL pointer dereference, address: 00000000000006a8
      PGD 0 P4D 0
      Oops: 0000 [#1] PREEMPT SMP PTI
      CPU: 1 PID: 1403 Comm: wireplumber Tainted: G            E      6.3.0-rc7+ #4
      Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
      RIP: 0010:iso_sock_sendmsg+0x63/0x2a0 [bluetooth]
      ===============================================================
      
      Fixes: 241f5193 ("Bluetooth: ISO: Avoid circular locking dependency")
      Fixes: 6a5ad251 ("Bluetooth: ISO: Fix possible circular locking dependency")
      Signed-off-by: default avatarPauli Virtanen <pav@iki.fi>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e969bfed
    • Pauli Virtanen's avatar
      Bluetooth: hci_event: call disconnect callback before deleting conn · 59bd1e47
      Pauli Virtanen authored
      
      
      [ Upstream commit 7f7cfcb6 ]
      
      In hci_cs_disconnect, we do hci_conn_del even if disconnection failed.
      
      ISO, L2CAP and SCO connections refer to the hci_conn without
      hci_conn_get, so disconn_cfm must be called so they can clean up their
      conn, otherwise use-after-free occurs.
      
      ISO:
      ==========================================================
      iso_sock_connect:880: sk 00000000eabd6557
      iso_connect_cis:356: 70:1a:b8:98:ff:a2 -> 28:3d:c2:4a:7e:da
      ...
      iso_conn_add:140: hcon 000000001696f1fd conn 00000000b6251073
      hci_dev_put:1487: hci0 orig refcnt 17
      __iso_chan_add:214: conn 00000000b6251073
      iso_sock_clear_timer:117: sock 00000000eabd6557 state 3
      ...
      hci_rx_work:4085: hci0 Event packet
      hci_event_packet:7601: hci0: event 0x0f
      hci_cmd_status_evt:4346: hci0: opcode 0x0406
      hci_cs_disconnect:2760: hci0: status 0x0c
      hci_sent_cmd_data:3107: hci0 opcode 0x0406
      hci_conn_del:1151: hci0 hcon 000000001696f1fd handle 2560
      hci_conn_unlink:1102: hci0: hcon 000000001696f1fd
      hci_conn_drop:1451: hcon 00000000d8521aaf orig refcnt 2
      hci_chan_list_flush:2780: hcon 000000001696f1fd
      hci_dev_put:1487: hci0 orig refcnt 21
      hci_dev_put:1487: hci0 orig refcnt 20
      hci_req_cmd_complete:3978: opcode 0x0406 status 0x0c
      ... <no iso_* activity on sk/conn> ...
      iso_sock_sendmsg:1098: sock 00000000dea5e2e0, sk 00000000eabd6557
      BUG: kernel NULL pointer dereference, address: 0000000000000668
      PGD 0 P4D 0
      Oops: 0000 [#1] PREEMPT SMP PTI
      Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
      RIP: 0010:iso_sock_sendmsg (net/bluetooth/iso.c:1112) bluetooth
      ==========================================================
      
      L2CAP:
      ==================================================================
      hci_cmd_status_evt:4359: hci0: opcode 0x0406
      hci_cs_disconnect:2760: hci0: status 0x0c
      hci_sent_cmd_data:3085: hci0 opcode 0x0406
      hci_conn_del:1151: hci0 hcon ffff88800c999000 handle 3585
      hci_conn_unlink:1102: hci0: hcon ffff88800c999000
      hci_chan_list_flush:2780: hcon ffff88800c999000
      hci_chan_del:2761: hci0 hcon ffff88800c999000 chan ffff888018ddd280
      ...
      BUG: KASAN: slab-use-after-free in hci_send_acl+0x2d/0x540 [bluetooth]
      Read of size 8 at addr ffff888018ddd298 by task bluetoothd/1175
      
      CPU: 0 PID: 1175 Comm: bluetoothd Tainted: G            E      6.4.0-rc4+ #2
      Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
      Call Trace:
       <TASK>
       dump_stack_lvl+0x5b/0x90
       print_report+0xcf/0x670
       ? __virt_addr_valid+0xf8/0x180
       ? hci_send_acl+0x2d/0x540 [bluetooth]
       kasan_report+0xa8/0xe0
       ? hci_send_acl+0x2d/0x540 [bluetooth]
       hci_send_acl+0x2d/0x540 [bluetooth]
       ? __pfx___lock_acquire+0x10/0x10
       l2cap_chan_send+0x1fd/0x1300 [bluetooth]
       ? l2cap_sock_sendmsg+0xf2/0x170 [bluetooth]
       ? __pfx_l2cap_chan_send+0x10/0x10 [bluetooth]
       ? lock_release+0x1d5/0x3c0
       ? mark_held_locks+0x1a/0x90
       l2cap_sock_sendmsg+0x100/0x170 [bluetooth]
       sock_write_iter+0x275/0x280
       ? __pfx_sock_write_iter+0x10/0x10
       ? __pfx___lock_acquire+0x10/0x10
       do_iter_readv_writev+0x176/0x220
       ? __pfx_do_iter_readv_writev+0x10/0x10
       ? find_held_lock+0x83/0xa0
       ? selinux_file_permission+0x13e/0x210
       do_iter_write+0xda/0x340
       vfs_writev+0x1b4/0x400
       ? __pfx_vfs_writev+0x10/0x10
       ? __seccomp_filter+0x112/0x750
       ? populate_seccomp_data+0x182/0x220
       ? __fget_light+0xdf/0x100
       ? do_writev+0x19d/0x210
       do_writev+0x19d/0x210
       ? __pfx_do_writev+0x10/0x10
       ? mark_held_locks+0x1a/0x90
       do_syscall_64+0x60/0x90
       ? lockdep_hardirqs_on_prepare+0x149/0x210
       ? do_syscall_64+0x6c/0x90
       ? lockdep_hardirqs_on_prepare+0x149/0x210
       entry_SYSCALL_64_after_hwframe+0x72/0xdc
      RIP: 0033:0x7ff45cb23e64
      Code: 15 d1 1f 0d 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b8 0f 1f 00 f3 0f 1e fa 80 3d 9d a7 0d 00 00 74 13 b8 14 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 48 83 ec 28 89 54 24 1c 48 89
      RSP: 002b:00007fff21ae09b8 EFLAGS: 00000202 ORIG_RAX: 0000000000000014
      RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007ff45cb23e64
      RDX: 0000000000000001 RSI: 00007fff21ae0aa0 RDI: 0000000000000017
      RBP: 00007fff21ae0aa0 R08: 000000000095a8a0 R09: 0000607000053f40
      R10: 0000000000000001 R11: 0000000000000202 R12: 00007fff21ae0ac0
      R13: 00000fffe435c150 R14: 00007fff21ae0a80 R15: 000060f000000040
       </TASK>
      
      Allocated by task 771:
       kasan_save_stack+0x33/0x60
       kasan_set_track+0x25/0x30
       __kasan_kmalloc+0xaa/0xb0
       hci_chan_create+0x67/0x1b0 [bluetooth]
       l2cap_conn_add.part.0+0x17/0x590 [bluetooth]
       l2cap_connect_cfm+0x266/0x6b0 [bluetooth]
       hci_le_remote_feat_complete_evt+0x167/0x310 [bluetooth]
       hci_event_packet+0x38d/0x800 [bluetooth]
       hci_rx_work+0x287/0xb20 [bluetooth]
       process_one_work+0x4f7/0x970
       worker_thread+0x8f/0x620
       kthread+0x17f/0x1c0
       ret_from_fork+0x2c/0x50
      
      Freed by task 771:
       kasan_save_stack+0x33/0x60
       kasan_set_track+0x25/0x30
       kasan_save_free_info+0x2e/0x50
       ____kasan_slab_free+0x169/0x1c0
       slab_free_freelist_hook+0x9e/0x1c0
       __kmem_cache_free+0xc0/0x310
       hci_chan_list_flush+0x46/0x90 [bluetooth]
       hci_conn_cleanup+0x7d/0x330 [bluetooth]
       hci_cs_disconnect+0x35d/0x530 [bluetooth]
       hci_cmd_status_evt+0xef/0x2b0 [bluetooth]
       hci_event_packet+0x38d/0x800 [bluetooth]
       hci_rx_work+0x287/0xb20 [bluetooth]
       process_one_work+0x4f7/0x970
       worker_thread+0x8f/0x620
       kthread+0x17f/0x1c0
       ret_from_fork+0x2c/0x50
      ==================================================================
      
      Fixes: b8d29052 ("Bluetooth: clean up connection in hci_cs_disconnect")
      Signed-off-by: default avatarPauli Virtanen <pav@iki.fi>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      59bd1e47
    • Pauli Virtanen's avatar
      Bluetooth: use RCU for hci_conn_params and iterate safely in hci_sync · 13ad45ad
      Pauli Virtanen authored
      
      
      [ Upstream commit 195ef75e ]
      
      hci_update_accept_list_sync iterates over hdev->pend_le_conns and
      hdev->pend_le_reports, and waits for controller events in the loop body,
      without holding hdev lock.
      
      Meanwhile, these lists and the items may be modified e.g. by
      le_scan_cleanup. This can invalidate the list cursor or any other item
      in the list, resulting to invalid behavior (eg use-after-free).
      
      Use RCU for the hci_conn_params action lists. Since the loop bodies in
      hci_sync block and we cannot use RCU or hdev->lock for the whole loop,
      copy list items first and then iterate on the copy. Only the flags field
      is written from elsewhere, so READ_ONCE/WRITE_ONCE should guarantee we
      read valid values.
      
      Free params everywhere with hci_conn_params_free so the cleanup is
      guaranteed to be done properly.
      
      This fixes the following, which can be triggered e.g. by BlueZ new
      mgmt-tester case "Add + Remove Device Nowait - Success", or by changing
      hci_le_set_cig_params to always return false, and running iso-tester:
      
      ==================================================================
      BUG: KASAN: slab-use-after-free in hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
      Read of size 8 at addr ffff888001265018 by task kworker/u3:0/32
      
      Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
      Workqueue: hci0 hci_cmd_sync_work
      Call Trace:
      <TASK>
      dump_stack_lvl (./arch/x86/include/asm/irqflags.h:134 lib/dump_stack.c:107)
      print_report (mm/kasan/report.c:320 mm/kasan/report.c:430)
      ? __virt_addr_valid (./include/linux/mmzone.h:1915 ./include/linux/mmzone.h:2011 arch/x86/mm/physaddr.c:65)
      ? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
      kasan_report (mm/kasan/report.c:538)
      ? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
      hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
      ? __pfx_hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2780)
      ? mutex_lock (kernel/locking/mutex.c:282)
      ? __pfx_mutex_lock (kernel/locking/mutex.c:282)
      ? __pfx_mutex_unlock (kernel/locking/mutex.c:538)
      ? __pfx_update_passive_scan_sync (net/bluetooth/hci_sync.c:2861)
      hci_cmd_sync_work (net/bluetooth/hci_sync.c:306)
      process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
      worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
      ? __pfx_worker_thread (kernel/workqueue.c:2480)
      kthread (kernel/kthread.c:376)
      ? __pfx_kthread (kernel/kthread.c:331)
      ret_from_fork (arch/x86/entry/entry_64.S:314)
      </TASK>
      
      Allocated by task 31:
      kasan_save_stack (mm/kasan/common.c:46)
      kasan_set_track (mm/kasan/common.c:52)
      __kasan_kmalloc (mm/kasan/common.c:374 mm/kasan/common.c:383)
      hci_conn_params_add (./include/linux/slab.h:580 ./include/linux/slab.h:720 net/bluetooth/hci_core.c:2277)
      hci_connect_le_scan (net/bluetooth/hci_conn.c:1419 net/bluetooth/hci_conn.c:1589)
      hci_connect_cis (net/bluetooth/hci_conn.c:2266)
      iso_connect_cis (net/bluetooth/iso.c:390)
      iso_sock_connect (net/bluetooth/iso.c:899)
      __sys_connect (net/socket.c:2003 net/socket.c:2020)
      __x64_sys_connect (net/socket.c:2027)
      do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80)
      entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120)
      
      Freed by task 15:
      kasan_save_stack (mm/kasan/common.c:46)
      kasan_set_track (mm/kasan/common.c:52)
      kasan_save_free_info (mm/kasan/generic.c:523)
      __kasan_slab_free (mm/kasan/common.c:238 mm/kasan/common.c:200 mm/kasan/common.c:244)
      __kmem_cache_free (mm/slub.c:1807 mm/slub.c:3787 mm/slub.c:3800)
      hci_conn_params_del (net/bluetooth/hci_core.c:2323)
      le_scan_cleanup (net/bluetooth/hci_conn.c:202)
      process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
      worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
      kthread (kernel/kthread.c:376)
      ret_from_fork (arch/x86/entry/entry_64.S:314)
      ==================================================================
      
      Fixes: e8907f76 ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3")
      Signed-off-by: default avatarPauli Virtanen <pav@iki.fi>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      13ad45ad