1. 09 11月, 2022 15 次提交
    • G
      mm/sharepool: fix deadlock in sp_check_mmap_addr · 78c82ea5
      Guo Mengqi 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5OE1J
      CVE: NA
      
      --------------------------------
      
      Fix a deadlock indicated below:
      
      [  171.669844] Chain exists of:
      [  171.669844]   &mm->mmap_lock --> sp_group_sem --> &spg->rw_lock
      [  171.669844]
      [  171.671469]  Possible unsafe locking scenario:
      [  171.671469]
      [  171.672121]        CPU0                    CPU1
      [  171.672415]        ----                    ----
      [  171.672706]   lock(&spg->rw_lock);
      [  171.673114]                                lock(sp_group_sem);
      [  171.673706]                                lock(&spg->rw_lock);
      [  171.674208]   lock(&mm->mmap_lock);
      [  171.674863]
      [  171.674863]  *** DEADLOCK ***
      
      sharepool use lock in order:
      sp_group_sem --> &spg->rw_lock --> mm->mmap_lock
      However, in sp_check_mmap_addr(), when mm->mmap_lock is held, it
      requested sp_group_sem, which is: mm->mmap_lock --> sp_group_sem.
      This causes ABBA problem.
      
      This happens in:
      
      [  171.642687] the existing dependency chain (in reverse order) is:
      [  171.643745]
      [  171.643745] -> #2 (&spg->rw_lock){++++}-{3:3}:
      [  171.644639]        __lock_acquire+0x6f4/0xc40
      [  171.645189]        lock_acquire+0x2f0/0x3c8
      [  171.645631]        down_read+0x64/0x2d8
      [  171.646075]        proc_usage_by_group+0x50/0x258 (spg->rw_lock)
      [  171.646542]        idr_for_each+0x6c/0xf0
      [  171.647011]        proc_group_usage_show+0x140/0x178
      [  171.647629]        seq_read_iter+0xe4/0x498
      [  171.648217]        proc_reg_read_iter+0xa8/0xe0
      [  171.648776]        new_sync_read+0xfc/0x1a0
      [  171.649002]        vfs_read+0x1ac/0x1c8
      [  171.649217]        ksys_read+0x74/0xf8
      [  171.649596]        __arm64_sys_read+0x24/0x30
      [  171.649934]        el0_svc_common.constprop.0+0x8c/0x270
      [  171.650528]        do_el0_svc+0x34/0xb8
      [  171.651069]        el0_svc+0x1c/0x28
      [  171.651278]        el0_sync_handler+0x8c/0xb0
      [  171.651636]        el0_sync+0x168/0x180
      [  171.652118]
      [  171.652118] -> #1 (sp_group_sem){++++}-{3:3}:
      [  171.652692]        __lock_acquire+0x6f4/0xc40
      [  171.653059]        lock_acquire+0x2f0/0x3c8
      [  171.653303]        down_read+0x64/0x2d8
      [  171.653704]        mg_is_sharepool_addr+0x184/0x340 (&sp_group_sem)
      [  171.654085]        sp_check_mmap_addr+0x64/0x108
      [  171.654668]        arch_get_unmapped_area_topdown+0x9c/0x528
      [  171.655370]        thp_get_unmapped_area+0x54/0x68
      [  171.656170]        get_unmapped_area+0x94/0x160
      [  171.656415]        __do_mmap_mm+0xd4/0x540
      [  171.656629]        do_mmap+0x98/0x648
      [  171.656838]        vm_mmap_pgoff+0xc0/0x188
      [  171.657129]        vm_mmap+0x6c/0x98
      [  171.657619]        elf_map+0xe0/0x118
      [  171.657835]        load_elf_binary+0x4ec/0xfd8
      [  171.658103]        bprm_execve.part.9+0x3ec/0x840
      [  171.658448]        bprm_execve+0x7c/0xb0
      [  171.658919]        kernel_execve+0x18c/0x198
      [  171.659500]        run_init_process+0xf0/0x108
      [  171.660073]        try_to_run_init_process+0x20/0x58
      [  171.660558]        kernel_init+0xcc/0x120
      [  171.660862]        ret_from_fork+0x10/0x18
      [  171.661273]
      [  171.661273] -> #0 (&mm->mmap_lock){++++}-{3:3}:
      [  171.661885]        check_prev_add+0xa4/0xbd8
      [  171.662229]        validate_chain+0xf54/0x14b8
      [  171.662705]        __lock_acquire+0x6f4/0xc40
      [  171.663310]        lock_acquire+0x2f0/0x3c8
      [  171.663658]        down_write+0x60/0x208
      [  171.664179]        mg_sp_alloc+0x24c/0x1150 (mm->mmap_lock)
      [  171.665245]        dev_ioctl+0x1128/0x1fb8 [sharepool_dev]
      [  171.665688]        __arm64_sys_ioctl+0xb0/0xe8
      [  171.666250]        el0_svc_common.constprop.0+0x8c/0x270
      [  171.667255]        do_el0_svc+0x34/0xb8
      [  171.667806]        el0_svc+0x1c/0x28
      [  171.668249]        el0_sync_handler+0x8c/0xb0
      [  171.668661]        el0_sync+0x168/0x180
      Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
      78c82ea5
    • G
      mm/sharepool: fix deadlock in spa_stat_of_mapping_show · 608669b7
      Guo Mengqi 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5OE1J
      CVE: NA
      
      --------------------------------
      
      The mutex protecting spm_dvpp_list has an ABBA deadlock with
      spg->rw_lock. Try add a process to a sharepool group and cat
      /proc/sharepool/spa_stat at the same time will reproduce the
      problem.
      
      Remove spg->rw_lock to avoid this.
      
      [ 1101.013480]INFO: task test:3567 blocked for more than 30 seconds.
      [ 1101.014378]      Tainted: G           OE     5.10.0+ #45
      [ 1101.015707]task:test state:D stack:    0 pid: 3567
      [ 1101.016464]Call trace:
      [ 1101.016736] __switch_to+0xc0/0x128
      [ 1101.017082] __schedule+0x3fc/0x898
      [ 1101.017626] schedule+0x48/0xd8
      [ 1101.017981] schedule_preempt_disabled+0x14/0x20
      [ 1101.018519] __mutex_lock.isra.1+0x160/0x638
      [ 1101.018899] __mutex_lock_slowpath+0x24/0x30
      [ 1101.019291] mutex_lock+0x5c/0x68
      [ 1101.019607] sp_mapping_create+0x118/0x1b0
      [ 1101.019963] sp_init_group_master_locked.part.9+0x10c/0x288
      [ 1101.020356] mg_sp_group_add_task.part.16+0x7dc/0xcd0
      [ 1101.020750] mg_sp_group_add_task+0x54/0xd0
      [ 1101.021120] dev_ioctl+0x360/0x1e20 [sharepool_dev]
      [ 1101.022171] __arm64_sys_ioctl+0xb0/0xe8
      [ 1101.022695] el0_svc_common.constprop.0+0x88/0x268
      [ 1101.023143] do_el0_svc+0x34/0xb8
      [ 1101.023487] el0_svc+0x1c/0x28
      [ 1101.023775] el0_sync_handler+0x8c/0xb0
      [ 1101.024120] el0_sync+0x168/0x180
      Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
      608669b7
    • G
      mm/sharepool: fix softlockup in high pressure use case. · 8b19f5e0
      Guo Mengqi 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5ODCT
      CVE: NA
      
      --------------------------------
      
      When there are a large number of groups in the system, or with a large
      number of processes in each group, "cat /proc/sharepool/proc_stat"
      will encounter softlockup before all prints finished.
      This is because there are too many loops in the callback function.
      Remove one of the loops to reduce time cost and add a cond_resched() to
      avoid this.
      
      root@buildroot:~/install# cat /proc/sharepool/proc_stat
      [ 1250.647469] watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [cat:309]
      [ 1250.648610] Modules linked in: sharepool_dev(OE)
      [ 1250.650795] CPU: 0 PID: 309 Comm: cat Tainted: G     OE     5.10.0+ #43
      [ 1250.651216] Hardware name: linux,dummy-virt (DT)
      [ 1250.651721] pstate: 80000005 (Nzcv daif -PAN -UAO -TCO BTYPE=--)
      [ 1250.652426] pc : get_process_sp_res+0x40/0x90
      [ 1250.652747] lr : proc_usage_by_group+0x158/0x218
          ...
      [ 1250.657903] Call trace:
      [ 1250.658376]  get_process_sp_res+0x40/0x90
      [ 1250.658602]  proc_usage_by_group+0x158/0x218
      [ 1250.658838]  idr_for_each+0x6c/0xf0
      [ 1250.659027]  proc_group_usage_show+0x104/0x120
      [ 1250.659263]  seq_read_iter+0xe0/0x498
      [ 1250.659462]  proc_reg_read_iter+0xa8/0xe0
      [ 1250.659660]  generic_file_splice_read+0xf0/0x1b0
      [ 1250.659865]  do_splice_to+0x7c/0xd0
      [ 1250.660029]  splice_direct_to_actor+0xe0/0x2a8
      [ 1250.660353]  do_splice_direct+0xa4/0xf8
      [ 1250.660902]  do_sendfile+0x1bc/0x420
      [ 1250.661079]  __arm64_sys_sendfile64+0x170/0x178
      [ 1250.661298]  el0_svc_common.constprop.0+0x88/0x268
      [ 1250.661505]  do_el0_svc+0x34/0xb8
      [ 1250.661686]  el0_svc+0x1c/0x28
      [ 1250.661836]  el0_sync_handler+0x8c/0xb0
      [ 1250.662033]  el0_sync+0x168/0x180
      Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
      8b19f5e0
    • G
      mm/sharepool: delete redundant codes · cd65775f
      Guo Mengqi 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5O5RQ
      CVE: NA
      
      --------------------------------
      
      Notice that in sp_unshare_uva(), for authentication check, comparison
      between current->tgid and spa->applier is well enough. There is no need
      to check current->mm against spa->mm.
      
      Other redundant cases:
      - find_spg_node_by_spg() will never return NULL in current use context;
      - spg_info_show() will not come across a group with id 0.
      
      Therefore, delete these redundant paths.
      Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
      cd65775f
    • Z
      mm/sharepool: Add a read lock in proc_usage_show() · d5fb0387
      Zhang Zekun 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5XQS4
      CVE: NA
      
      -----------------------------------------------
      
      In function get_process_sp_res(), spg_node can be freed by other
      process, the access to spg_node->spg can cause kernel panic. Add
      a pair of read lock to fix this problem.
      Fix the same problem in proc_sp_group_state().
      
      Fixes: 3d37f8717287 ("[Huawei] mm: sharepool: use built-in-statistics")
      Signed-off-by: NZhang Zekun <zhangzekun11@huawei.com>
      d5fb0387
    • G
      mm/sharepool: fix static code-check errors · de73eb95
      Guo Mengqi 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5MS48
      CVE: NA
      
      --------------------------------
      
      Fix two bugs revealed by static check:
      
      - Release the mm->mmap_lock when mm->sp_group_master had not been
      initialized.
      - Do not add mm to master list if there process add group failed.
      Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
      de73eb95
    • G
      mm/sharepool: fix statistics error · 738027fc
      Guo Mengqi 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5M3PS
      CVE: NA
      
      --------------------------------
      
      - fix SP_RES value incorrect bug
      - fix SP_RES_T value incorrect bug
      - fix pid field uninitialized error in pass-through scenario
      Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
      738027fc
    • Z
      mm/sharepool: Remove the comment and fix a bug in mg_sp_group_id_by_pid() · c2e830a7
      Zhang Zekun 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5LY2R
      CVE: NA
      
      -------------------------------------------
      
      Remove the meaningless comment in mg_sp_free() and the fix the
      bug in mg_sp_group_id_by_pid() parameter check path.
      Signed-off-by: NZhang Zekun <zhangzekun11@huawei.com>
      c2e830a7
    • Z
      mm/sharepool: Remove enable_mdc_default_group and change the definition of is_process_in_group() · 36ddb7ca
      Zhang Zekun 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5LY51
      CVE: NA
      
      ----------------------------------------------
      
      The variable enable_mdc_default_group has been deprecated, thus remove
      it and the corresponding code.
      The definition of is_process_in_group() can be ambiguous, thus change
      the return value type.
      Signed-off-by: NZhang Zekun <zhangzekun11@huawei.com>
      36ddb7ca
    • Z
      mm/sharepool: Remove sp_device_number_detect function · 5b9c2984
      Zhang Zekun 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5LY4H
      CVE: NA
      
      -----------------------------------------
      
      Remove the sp_device_number, and we don't need 'sp_device_number'
      to detect the sp_device_number. Instead, we use maco 'MAX_DEVID' to
      take the place of sp_device_number.
      Signed-off-by: NZhang Zekun <zhangzekun11@huawei.com>
      5b9c2984
    • Z
      mm/sharepool: Remove unused sp_dev_va_start and sp_dev_va_size · 009c8a05
      Zhang Zekun 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5LY5K
      CVE: NA
      
      -----------------------------------
      
      Remove the unused sp_dev_va_start and sp_dev_va_size, the related
      code can be removed.
      
      Add the dvpp_addr checker in mg_is_sharepool_addr() for current proc.
      Signed-off-by: NZhang Zekun <zhangzekun11@huawei.com>
      009c8a05
    • W
      mm/sharepool: Delete unused sysctl interface · 00f8b7c2
      Wang Wensheng 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5LHGZ
      CVE: NA
      
      --------------------------------
      
      Delete unused sysctl interfaces in sharepool feature.
      Signed-off-by: NWang Wensheng <wangwensheng4@huawei.com>
      00f8b7c2
    • G
      mm/sharepool: fix dvpp spm redundant print error · efa70a93
      Guo Mengqi 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5KSDH
      CVE: NA
      
      --------------------------------
      
      Fix sharepool redundant /proc/sharepool/spa_stat prints when there are
      multiple groups which are all attached to same sp_mapping.
      
      Traverse all dvpp-mappings rather than all groups.
      Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
      efa70a93
    • G
      mm/sharepool: proc_sp_group_state bugfix · a38909f1
      Guo Mengqi 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5K3MH
      CVE: NA
      
      --------------------------------
      
      After refactoring, cat /proc/pid_xx/sp_group will cause kernel panic.
      Fix this error.
      Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
      a38909f1
    • G
      mm/sharepool: remove deprecated interfaces · aa7f4227
      Guo Mengqi 提交于
      hulk inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5KC7C
      CVE: NA
      
      --------------------------------
      
      Most interfaces starting with "sp_" are deprecated, remove them.
      Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
      aa7f4227
  2. 08 11月, 2022 8 次提交
  3. 07 11月, 2022 17 次提交