Skip to content
  1. Jan 11, 2021
    • Guo Ren's avatar
      csky: Fixup _PAGE_ACCESSED for default pgprot · 719ae020
      Guo Ren authored
      
      
      When the system memory is exhausted, linux will trigger kswapd to
      shrink memory page cache. We found the csky's .text file mapping
      pages would be reclaimed earlier than arm's elf. Because csky
      doesn't give _PAGE_ACCESSED for default pgprot and in zap_pte_range
      
      if (pte_young(ptent) &&
          likely(!(vma->vm_flags & VM_SEQ_READ)))
              mark_page_accessed(page);
      
      mark_page_accessed will put the pages into active lru list.
      
      csky will throw the pages at first and keep them in active lru
      list later after real accessed, but arm would keep them in active
      lru list at the beginning.
      
      The following are statistics of different architecture styles:
      
      Default _PAGE_ACCESSED: alpha, arm, arm64, ia64, m68k, microblaze,
      			openrisc, powerpc, riscv, sh, um, x86,
      			xtensa
      Not def _PAGE_ACCESSED: arc, c6x, h8300, hexgon, mips, s390, nds32,
      			nios2, parisc, sparc
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      Co-developed-by: default avatarXu Kai <xukai@nationalchip.com>
      Signed-off-by: default avatarXu Kai <xukai@nationalchip.com>
      719ae020
  2. Dec 04, 2020
  3. Nov 04, 2020
  4. Jun 17, 2020
  5. May 27, 2020
  6. May 25, 2020
    • Guo Ren's avatar
      csky: Coding convention in entry.S · 9c8ea967
      Guo Ren authored
      
      
      There is no fixup or feature in the patch, we only cleanup with:
      
       - Remove unnecessary reg used (r11, r12), just use r9 & r10 &
         syscallid regs as temp useage.
       - Add _TIF_SYSCALL_WORK and _TIF_WORK_MASK to gather macros.
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      9c8ea967
    • Guo Ren's avatar
      csky: Fixup abiv2 syscall_trace break a4 & a5 · 356e27e1
      Guo Ren authored
      
      
      Current implementation could destory a4 & a5 when strace, so we need to get them
      from pt_regs by SAVE_ALL.
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      356e27e1
    • Guo Ren's avatar
      csky: Fixup CONFIG_PREEMPT panic · 63de78e7
      Guo Ren authored
      
      
      log:
      [    0.13373200] Calibrating delay loop...
      [    0.14077600] ------------[ cut here ]------------
      [    0.14116700] WARNING: CPU: 0 PID: 0 at kernel/sched/core.c:3790 preempt_count_add+0xc8/0x11c
      [    0.14348000] DEBUG_LOCKS_WARN_ON((preempt_count() < 0))Modules linked in:
      [    0.14395100] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.6.0 #7
      [    0.14410800]
      [    0.14427400] Call Trace:
      [    0.14450700] [<807cd226>] dump_stack+0x8a/0xe4
      [    0.14473500] [<80072792>] __warn+0x10e/0x15c
      [    0.14495900] [<80072852>] warn_slowpath_fmt+0x72/0xc0
      [    0.14518600] [<800a5240>] preempt_count_add+0xc8/0x11c
      [    0.14544900] [<807ef918>] _raw_spin_lock+0x28/0x68
      [    0.14572600] [<800e0eb8>] vprintk_emit+0x84/0x2d8
      [    0.14599000] [<800e113a>] vprintk_default+0x2e/0x44
      [    0.14625100] [<800e2042>] vprintk_func+0x12a/0x1d0
      [    0.14651300] [<800e1804>] printk+0x30/0x48
      [    0.14677600] [<80008052>] lockdep_init+0x12/0xb0
      [    0.14703800] [<80002080>] start_kernel+0x558/0x7f8
      [    0.14730000] [<800052bc>] csky_start+0x58/0x94
      [    0.14756600] irq event stamp: 34
      [    0.14775100] hardirqs last  enabled at (33): [<80067370>] ret_from_exception+0x2c/0x72
      [    0.14793700] hardirqs last disabled at (34): [<800e0eae>] vprintk_emit+0x7a/0x2d8
      [    0.14812300] softirqs last  enabled at (32): [<800655b0>] __do_softirq+0x578/0x6d8
      [    0.14830800] softirqs last disabled at (25): [<8007b3b8>] irq_exit+0xec/0x128
      
      The preempt_count of reg could be destroyed after csky_do_IRQ without reload
      from memory.
      
      After reference to other architectures (arm64, riscv), we move preempt entry
      into ret_from_exception and disable irq at the beginning of
      ret_from_exception instead of RESTORE_ALL.
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      Reported-by: default avatarLu Baoquan <lu.baoquan@intellif.com>
      63de78e7
  7. May 15, 2020
    • Al Viro's avatar
      csky: Fixup raw_copy_from_user() · a66c5ee6
      Al Viro authored
      
      
      If raw_copy_from_user(to, from, N) returns K, callers expect
      the first N - K bytes starting at to to have been replaced with
      the contents of corresponding area starting at from and the last
      K bytes of destination *left* *unmodified*.
      
      What arch/sky/lib/usercopy.c is doing is broken - it can lead to e.g.
      data corruption on write(2).
      
      raw_copy_to_user() is inaccurate about return value, which is a bug,
      but consequences are less drastic than for raw_copy_from_user().
      And just what are those access_ok() doing in there?  I mean, look into
      linux/uaccess.h; that's where we do that check (as well as zero tail
      on failure in the callers that need zeroing).
      
      AFAICS, all of that shouldn't be hard to fix; something like a patch
      below might make a useful starting point.
      
      I would suggest moving these macros into usercopy.c (they are never
      used anywhere else) and possibly expanding them there; if you leave
      them alive, please at least rename __copy_user_zeroing(). Again,
      it must not zero anything on failed read.
      
      Said that, I'm not sure we won't be better off simply turning
      usercopy.c into usercopy.S - all that is left there is a couple of
      functions, each consisting only of inline asm.
      
      Guo Ren reply:
      
      Yes, raw_copy_from_user is wrong, it's no need zeroing code.
      
      unsigned long _copy_from_user(void *to, const void __user *from,
      unsigned long n)
      {
              unsigned long res = n;
              might_fault();
              if (likely(access_ok(from, n))) {
                      kasan_check_write(to, n);
                      res = raw_copy_from_user(to, from, n);
              }
              if (unlikely(res))
                      memset(to + (n - res), 0, res);
              return res;
      }
      EXPORT_SYMBOL(_copy_from_user);
      
      You are right and access_ok() should be removed.
      
      but, how about:
      do {
      ...
              "2:     stw     %3, (%1, 0)     \n"             \
      +       "       subi    %0, 4          \n"               \
              "9:     stw     %4, (%1, 4)     \n"             \
      +       "       subi    %0, 4          \n"               \
              "10:    stw     %5, (%1, 8)     \n"             \
      +       "       subi    %0, 4          \n"               \
              "11:    stw     %6, (%1, 12)    \n"             \
      +       "       subi    %0, 4          \n"               \
              "       addi    %2, 16          \n"             \
              "       addi    %1, 16          \n"             \
      
      Don't expand __ex_table
      
      AI Viro reply:
      
      Hey, I've no idea about the instruction scheduling on csky -
      if that doesn't slow the things down, all the better.  It's just
      that copy_to_user() and friends are on fairly hot codepaths,
      and in quite a few situations they will dominate the speed of
      e.g. read(2).  So I tried to keep the fast path unchanged.
      Up to the architecture maintainers, obviously.  Which would be
      you...
      
      As for the fixups size increase (__ex_table size is unchanged)...
      You have each of those macros expanded exactly once.
      So the size is not a serious argument, IMO - useless complexity
      would be, if it is, in fact, useless; the size... not really,
      especially since those extra subi will at least offset it.
      
      Again, up to you - asm optimizations of (essentially)
      memcpy()-style loops are tricky and can depend upon the
      fairly subtle details of architecture.  So even on something
      I know reasonably well I would resort to direct experiments
      if I can't pass the buck to architecture maintainers.
      
      It *is* worth optimizing - this is where read() from a file
      that is already in page cache spends most of the time, etc.
      
      Guo Ren reply:
      
      Thx, after fixup some typo “sub %0, 4”, apply the patch.
      
      TODO:
       - user copy/from codes are still need optimizing.
      
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      a66c5ee6
    • Guo Ren's avatar
      csky: Fixup gdbmacros.txt with name sp in thread_struct · 1cd60acf
      Guo Ren authored
      
      
      The gdbmacros.txt use sp in thread_struct, but csky use ksp. This
      cause bttnobp fail to excute.
      
      TODO:
       - Still couldn't display the contents of stack.
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      1cd60acf
    • Guo Ren's avatar
      csky: Fixup remove unnecessary save/restore PSR code · cac70f83
      Guo Ren authored
      
      
      All processes' PSR could success from SETUP_MMU, so need set it
      in INIT_THREAD again.
      
      And use a3 instead of r7 in __switch_to for code convention.
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      cac70f83
    • Liu Yibin's avatar
      csky: Fixup remove duplicate irq_disable · 0749e14b
      Liu Yibin authored
      
      
      Interrupt has been disabled in __schedule() with local_irq_disable()
      and enabled in finish_task_switch->finish_lock_switch() with
      local_irq_enabled(), So needn't to disable irq here.
      
      Signed-off-by: default avatarLiu Yibin <jiulong@linux.alibaba.com>
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      0749e14b
    • Guo Ren's avatar
      csky: Fixup calltrace panic · 7dd98d55
      Guo Ren authored
      
      
      The implementation of show_stack will panic with wrong fp:
      
      addr    = *fp++;
      
      because the fp isn't checked properly.
      
      The current implementations of show_stack, wchan and stack_trace
      haven't been designed properly, so just deprecate them.
      
      This patch is a reference to riscv's way, all codes are modified from
      arm's. The patch is passed with:
      
       - cat /proc/<pid>/stack
       - cat /proc/<pid>/wchan
       - echo c > /proc/sysrq-trigger
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      7dd98d55
  8. May 06, 2020
    • Mao Han's avatar
      csky: Fixup perf callchain unwind · 16d1aaf3
      Mao Han authored
      
      
       [ 5221.974084] Unable to handle kernel paging request at virtual address 0xfffff000, pc: 0x8002c18e
       [ 5221.985929] Oops: 00000000
       [ 5221.989488]
       [ 5221.989488] CURRENT PROCESS:
       [ 5221.989488]
       [ 5221.992877] COMM=callchain_test PID=11962
       [ 5221.995213] TEXT=00008000-000087e0 DATA=00009f1c-0000a018 BSS=0000a018-0000b000
       [ 5221.999037] USER-STACK=7fc18e20  KERNEL-STACK=be204680
       [ 5221.999037]
       [ 5222.003292] PC: 0x8002c18e (perf_callchain_kernel+0x3e/0xd4)
       [ 5222.007957] LR: 0x8002c198 (perf_callchain_kernel+0x48/0xd4)
       [ 5222.074873] Call Trace:
       [ 5222.074873] [<800a248e>] get_perf_callchain+0x20a/0x29c
       [ 5222.074873] [<8009d964>] perf_callchain+0x64/0x80
       [ 5222.074873] [<8009dc1c>] perf_prepare_sample+0x29c/0x4b8
       [ 5222.074873] [<8009de6e>] perf_event_output_forward+0x36/0x98
       [ 5222.074873] [<800497e0>] search_exception_tables+0x20/0x44
       [ 5222.074873] [<8002cbb6>] do_page_fault+0x92/0x378
       [ 5222.074873] [<80098608>] __perf_event_overflow+0x54/0xdc
       [ 5222.074873] [<80098778>] perf_swevent_hrtimer+0xe8/0x164
       [ 5222.074873] [<8002ddd0>] update_mmu_cache+0x0/0xd8
       [ 5222.074873] [<8002c014>] user_backtrace+0x58/0xc4
       [ 5222.074873] [<8002c0b4>] perf_callchain_user+0x34/0xd0
       [ 5222.074873] [<800a2442>] get_perf_callchain+0x1be/0x29c
       [ 5222.074873] [<8009d964>] perf_callchain+0x64/0x80
       [ 5222.074873] [<8009d834>] perf_output_sample+0x78c/0x858
       [ 5222.074873] [<8009dc1c>] perf_prepare_sample+0x29c/0x4b8
       [ 5222.074873] [<8009de94>] perf_event_output_forward+0x5c/0x98
       [ 5222.097846]
       [ 5222.097846] [<800a0300>] perf_event_exit_task+0x58/0x43c
       [ 5222.097846] [<8006c874>] hrtimer_interrupt+0x104/0x2ec
       [ 5222.097846] [<800a0300>] perf_event_exit_task+0x58/0x43c
       [ 5222.097846] [<80437bb6>] dw_apb_clockevent_irq+0x2a/0x4c
       [ 5222.097846] [<8006c770>] hrtimer_interrupt+0x0/0x2ec
       [ 5222.097846] [<8005f2e4>] __handle_irq_event_percpu+0xac/0x19c
       [ 5222.097846] [<80437bb6>] dw_apb_clockevent_irq+0x2a/0x4c
       [ 5222.097846] [<8005f408>] handle_irq_event_percpu+0x34/0x88
       [ 5222.097846] [<8005f480>] handle_irq_event+0x24/0x64
       [ 5222.097846] [<8006218c>] handle_level_irq+0x68/0xdc
       [ 5222.097846] [<8005ec76>] __handle_domain_irq+0x56/0xa8
       [ 5222.097846] [<80450e90>] ck_irq_handler+0xac/0xe4
       [ 5222.097846] [<80029012>] csky_do_IRQ+0x12/0x24
       [ 5222.097846] [<8002a3a0>] csky_irq+0x70/0x80
       [ 5222.097846] [<800ca612>] alloc_set_pte+0xd2/0x238
       [ 5222.097846] [<8002ddd0>] update_mmu_cache+0x0/0xd8
       [ 5222.097846] [<800a0340>] perf_event_exit_task+0x98/0x43c
      
      The original fp check doesn't base on the real kernal stack region.
      Invalid fp address may cause kernel panic.
      
      Signed-off-by: default avatarMao Han <han_mao@linux.alibaba.com>
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      16d1aaf3
    • Liu Yibin's avatar
      csky: Fixup msa highest 3 bits mask · 5bcc0327
      Liu Yibin authored
      
      
      Just as comment mentioned, the msa format:
      
       cr<30/31, 15> MSA register format:
       31 - 29 | 28 - 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
         BA     Reserved  SH  WA  B   SO SEC  C   D   V
      
      So we should shift 29 bits not 28 bits for mask
      
      Signed-off-by: default avatarLiu Yibin <jiulong@linux.alibaba.com>
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      5bcc0327
  9. Apr 14, 2020
    • Guo Ren's avatar
      csky: Fixup perf probe -x hungup · a6769b95
      Guo Ren authored
      
      
      case:
       # perf probe -x /lib/libc-2.28.9000.so memcpy
       # perf record -e probe_libc:memcpy -aR sleep 1
      
      System hangup and cpu get in trap_c loop, because our hardware
      singlestep state could still get interrupt signal. When we get in
      uprobe_xol singlestep slot, we should disable irq in pt_regs->psr.
      
      And is_swbp_insn() need a csky arch implementation with a low 16bit
      mask.
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      a6769b95
  10. Apr 12, 2020
  11. Apr 10, 2020
  12. Apr 08, 2020
  13. Apr 03, 2020
  14. Mar 31, 2020
    • Guo Ren's avatar
      csky: Fixup cpu speculative execution to IO area · 996558f5
      Guo Ren authored
      
      
      For the memory size ( > 512MB, < 1GB), the MSA setting is:
      
       - SSEG0: PHY_START        , PHY_START + 512MB
       - SSEG1: PHY_START + 512MB, PHY_START + 1GB
      
      But the real memory is no more than 1GB, there is a gap between the
      end size of memory and border of 1GB. CPU could speculatively
      execute to that gap and if the gap of the bus couldn't respond to
      the CPU request, then the crash will happen.
      
      Now make the setting with:
      
       - SSEG0: PHY_START        , PHY_START + 512MB (no change)
       - SSEG1: Disabled (We use highmem to use the memory of 512MB~1GB)
      
      We also deprecated zhole_szie[] settings, it's only used by arm
      style CPUs. All memory gap should use Reserved setting of dts in
      csky system.
      
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      996558f5
  15. Mar 17, 2020
  16. Feb 25, 2020
  17. Feb 24, 2020
  18. Feb 03, 2020