Re: [PATCH net-next v5 1/4] phylib: Add device reset delay support

2017-12-17 Thread Richard Leitner
Hi Rob,

On 12/15/2017 11:17 PM, Rob Herring wrote:
> On Mon, Dec 11, 2017 at 01:16:57PM +0100, Richard Leitner wrote:
>> From: Richard Leitner 
>>
>> Some PHYs need a minimum time after the reset gpio was asserted and/or
>> deasserted. To ensure we meet these timing requirements add two new
>> optional devicetree parameters for the phy: reset-delay-us and
>> reset-post-delay-us.
>>
>> Signed-off-by: Richard Leitner 
>> Reviewed-by: Geert Uytterhoeven 
>> ---
>>  Documentation/devicetree/bindings/net/phy.txt | 10 ++
>>  drivers/net/phy/mdio_device.c | 13 +++--
>>  drivers/of/of_mdio.c  |  4 
>>  include/linux/mdio.h  |  2 ++
>>  4 files changed, 27 insertions(+), 2 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/net/phy.txt 
>> b/Documentation/devicetree/bindings/net/phy.txt
>> index c05479f5ac7c..72860ce7f610 100644
>> --- a/Documentation/devicetree/bindings/net/phy.txt
>> +++ b/Documentation/devicetree/bindings/net/phy.txt
>> @@ -55,6 +55,12 @@ Optional Properties:
>>  
>>  - reset-gpios: The GPIO phandle and specifier for the PHY reset signal.
>>  
>> +- reset-delay-us: Delay after the reset was asserted in microseconds.
>> +  If this property is missing the delay will be skipped.
>> +
>> +- reset-post-delay-us: Delay after the reset was deasserted in microseconds.
>> +  If this property is missing the delay will be skipped.
> 
> I think these names could be clearer as to exactly what they mean. 
> Looking at existing properties with "reset-delay" there's a mixture of 
> definitions whether it is the assert time or the time after deassert.
> 
> So I'd call these "reset-assert-us" and "reset-deassert-us".

Ok, that would be fine with me, but are you sure that we should omit the
"-delay" term completely?

What would be the best approach to post this change (as the patchset was
already merged to net-next)? A separate patch or a v6 of the complete
patchset?

> 
> Rob
> 

regards;Richard.L


[PATCH v4 01/36] asm-generic/io.h: move ioremap_nocache/ioremap_uc/ioremap_wc/ioremap_wt out of ifndef CONFIG_MMU

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

It allows some architectures to use this generic macro instead of
defining theirs.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
Acked-by: Arnd Bergmann 
---
 include/asm-generic/io.h |   18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index b4531e3..7c6a39e 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -852,7 +852,16 @@ static inline void __iomem *__ioremap(phys_addr_t offset, 
size_t size,
 }
 #endif
 
+#ifndef iounmap
+#define iounmap iounmap
+
+static inline void iounmap(void __iomem *addr)
+{
+}
+#endif
+#endif /* CONFIG_MMU */
 #ifndef ioremap_nocache
+void __iomem *ioremap(phys_addr_t phys_addr, size_t size);
 #define ioremap_nocache ioremap_nocache
 static inline void __iomem *ioremap_nocache(phys_addr_t offset, size_t size)
 {
@@ -884,15 +893,6 @@ static inline void __iomem *ioremap_wt(phys_addr_t offset, 
size_t size)
 }
 #endif
 
-#ifndef iounmap
-#define iounmap iounmap
-
-static inline void iounmap(void __iomem *addr)
-{
-}
-#endif
-#endif /* CONFIG_MMU */
-
 #ifdef CONFIG_HAS_IOPORT_MAP
 #ifndef CONFIG_GENERIC_IOMAP
 #ifndef ioport_map
-- 
1.7.9.5



Re: [PATCH] trace: reenable preemption if we modify the ip

2017-12-17 Thread Masami Hiramatsu
On Fri, 15 Dec 2017 21:42:57 -0500
Josef Bacik  wrote:

> From: Josef Bacik 
> 
> Things got moved around between the original bpf_override_return patches
> and the final version, and now the ftrace kprobe dispatcher assumes if
> you modified the ip that you also enabled preemption.  Make a comment of
> this and enable preemption, this fixes the lockdep splat that happened
> when using this feature.
> 
> Signed-off-by: Josef Bacik 
> ---
>  kernel/trace/trace_kprobe.c | 9 -
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 5db849809a56..91f4b57dab82 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -1322,8 +1322,15 @@ static int kprobe_dispatcher(struct kprobe *kp, struct 
> pt_regs *regs)
>   if (tk->tp.flags & TP_FLAG_TRACE)
>   kprobe_trace_func(tk, regs);
>  #ifdef CONFIG_PERF_EVENTS
> - if (tk->tp.flags & TP_FLAG_PROFILE)
> + if (tk->tp.flags & TP_FLAG_PROFILE) {
>   ret = kprobe_perf_func(tk, regs);
> + /*
> +  * The ftrace kprobe handler leaves it up to us to re-enable
> +  * preemption here before returning if we've modified the ip.
> +  */
> + if (ret)
> + preempt_enable_no_resched();

Where is reset_current_kprobe()?
Since kprobes still expects this modification is used by jprobes,
we need to call it in caller-side.

Thank you,

> + }
>  #endif
>   return ret;
>  }
> -- 
> 2.7.5
> 


-- 
Masami Hiramatsu 


[PATCH v4 00/36] Andes(nds32) Linux Kernel

2017-12-17 Thread Greentime Hu
This is the 4th version patchset to add the Linux kernel port for Andes(nds32)
processors. Almost all of the feedbacks from v3 patchseries has been addressed.
Thanks to everyone who provided feedback on the previous version.


This patchset adds core architecture support to Linux for Andestech's
N13, N15, D15, N10, D10 processor cores.

Based on the 16/32-bit AndeStar RISC-like architecture, we designed the
configurable AndesCore series of embedded processor families. AndesCores
range from highly performance-efficient small-footprint cores for
microcontrollers and deeply-embedded applications to 1GHz+ cores running
Linux, covering general-purpose N-series cores for a wide range of computing
need, DSP-capable D-series cores for digital signal control,
instruction-extensible E-series cores for application-specific acceleration,
and secure S-series cores for best protection of the most valuable.

The patches are based on v4.14-rc8, and can also be found in the
following git tree:
  https://github.com/andestech/linux.git nds32-4.14-rc8-v4

The build script and toolchain repositories are able to be found here:
  https://github.com/andestech/build_script.git

Freely available instruction set and architecture overview documents can
be found on the following page:
  http://www.andestech.com/product.php?cls=9


Vincent Ren-Wei Chen and I will maintain this port. Thanks to everyone who
helped us and contributed to it. :) Any feedback is welcome.

Changes in v4:
 - Add atcpit100 timer driver due to it include vdso implementations and sent
   them together with nds32 may help reviewer to review.
 - Update ae3xx.dts for atcpit100 clock setting and remove vdso settings.
 - To get cycle counter register by timer driver instead of dts.
 - Use "depends on NDS32 || COMPILE_TEST" in atcpit100 driver because it is 
needed for nds32 vdso
 - Update defconfig becasue kconfig rename from CONFIG_CLKSRC_ATCPIT100 to 
CONFIG_TIMER_ATCPIT100
 - Remove ag101p.dts because we are not yet ready for ag101p platform.
 - Update copyright style to SPDX-License-Identifier
 - Include  instead of 
 - Add local_irq_save()/local_irq_restore() to protect SR_TLB_VPN in 
update_mmu_cache().
 - Update cpu_dcache_inval_all implementation to make sure all level cache are 
writeback.

Changes in v3:
 - Use arch's io.h instead of generic one
 - Add andestech-boards binding document
 - Update nds32/cpus.txt binding document
 - Remove atcpit100 timer drivers
 - Select NO_BOOTMEM and delete HAVE_MEMBLOCK_NODE_MAP
 - make CPU_BIG_ENDIAN and CPU_LITTLE_ENDIAN are dependent
 - Add cpu type to select HWZOL/CPU_CACHE_ALIASING
 - Change CPU_CACHE_NONALIASING to CPU_CACHE_ALIASING
 - Remove bootarg from device tree script
 - Update ag101p.dts and ae3xx.dts for correct board name.
 - Clear and simplify defconfig
 - Implement L2C_R_REG/ L2C_W_REG with readl/writel instead of 
__raw_readl/__raw_writel for endian save
 - Remove early_init_dt_add_memory_arch/early_init_dt_alloc_memory_arch to use 
the generic ones
 - Refine devicetree.c
 - Fix bug 
https://lkml.kernel.org/r/1499782590-31366-1-git-send-email-mark.rutl...@arm.com
 - Refine irqchip/irq-ativic32.c implementations
 - Add COMPILE_TEST in drivers/net/ethernet/faraday/Kconfig
 - Refine cache operations
 - Add CONFIG_HW_SUPPORT_UNALIGNMENT_ACCESS
 - Fix ZERO_PAGE define
 - Remove SA_RESTORER
 - Remove uapi/asm/signal.h
 - Redefine user_pt_regs
 - Remove spinlock.h
 - Remove __ARCH_WANT_RENAMEAT and __ARCH_WANT_SYSCALL_OFF_T from unistd.h
 - Remove set_fs(USER_DS) because flush_old_exec() will do this setting
 - Replace in_atomic() with faulthandler_disabled()
 - Add barrier.h
 - Select COMMON_CLK
 - Add clk_pll in dts
 - Add of_clk_init() in arch/nds32/kernel/time.c

Changes in v2:
 - Set GENERIC_CALIBRATE_DELAY default n
 - Add earlycon support
 - Remove earlyprintk
 - Add CPU_BIG_ENDIAN, CPU_LITTLE_ENDIAN support
 - Refine unalignment access exception handler
 - Add VMSPLIT support
 - Use only one defconfig
 - Change interrupt-cells from 2 to 1
 - Refine andestech cpu names in bindings/nds32/cpus.txt
 - Get clock frequency in dts because fpga bitmap doesn't include this feature
 - Update MAINTAINERS for bindings
 - Remove unused configs in Kconfig
 - Refine device tree scripts
 - Refine coding style
 - Use generic ioremap_nocache
 - Remove L2CC_PA_BASE define and its codes in head.S. It will be moved to 
bootloader.
 - Set PHYS_OFFSET to 0x0 instead of CONFIG_MEMORY_START
 - Remove unused macros
 - Simplify cpu_cache_* API
 - Change __asm__ __volatile__ to asm volatile
 - Refine uaccess.h
 - Remove unused/deprecated syscall
 - Use generic posix_types.h
 - Remove arch_trace_hardirqs_on/arch_trace_hardirqs_off
 - Fix bug of restart syscall
 - Refine syscall implementations
 - Use IS_ENABLED to replace ifdef as possible
 - Remove device_initcall(nds32_device_probe)
 - Refine vdso implementations
 - Refine 
copy_from_user()/copy_to_user()/clear_user()/get_user()/memmove()/memcpy()
 - Refine ioremap.c
 - Refine 

[PATCH v4 03/36] nds32: Assembly macros and definitions

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch includes assembly macros, bit field definitions used in .S
files across arch/nds32/.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/assembler.h |   39 ++
 arch/nds32/include/asm/bitfield.h  |  963 
 arch/nds32/include/asm/nds32.h |   83 
 arch/nds32/kernel/asm-offsets.c|   28 ++
 4 files changed, 1113 insertions(+)
 create mode 100644 arch/nds32/include/asm/assembler.h
 create mode 100644 arch/nds32/include/asm/bitfield.h
 create mode 100644 arch/nds32/include/asm/nds32.h
 create mode 100644 arch/nds32/kernel/asm-offsets.c

diff --git a/arch/nds32/include/asm/assembler.h 
b/arch/nds32/include/asm/assembler.h
new file mode 100644
index 000..c385578
--- /dev/null
+++ b/arch/nds32/include/asm/assembler.h
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __NDS32_ASSEMBLER_H__
+#define __NDS32_ASSEMBLER_H__
+
+.macro gie_disable
+   setgie.d
+   dsb
+.endm
+
+.macro gie_enable
+   setgie.e
+   dsb
+.endm
+
+.macro gie_save oldpsw
+   mfsr \oldpsw, $ir0
+   setgie.d
+dsb
+.endm
+
+.macro gie_restore oldpsw
+   andi \oldpsw, \oldpsw, #0x1
+   beqz \oldpsw, 7001f
+   setgie.e
+   dsb
+7001:
+.endm
+
+
+#define USER(insn,  reg, addr, opr)\
+:  insn  reg, addr, opr;   \
+   .section __ex_table,"a";\
+   .align 3;   \
+   .long   b, 9001f;   \
+   .previous
+
+#endif /* __NDS32_ASSEMBLER_H__ */
diff --git a/arch/nds32/include/asm/bitfield.h 
b/arch/nds32/include/asm/bitfield.h
new file mode 100644
index 000..c73f71d
--- /dev/null
+++ b/arch/nds32/include/asm/bitfield.h
@@ -0,0 +1,963 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __NDS32_BITFIELD_H__
+#define __NDS32_BITFIELD_H__
+/**
+ * cr0: CPU_VER (CPU Version Register)
+ */
+#define CPU_VER_offCFGID   0   /* Minor configuration */
+#define CPU_VER_offREV 16  /* Revision of the CPU version */
+#define CPU_VER_offCPUID   24  /* Major CPU versions */
+
+#define CPU_VER_mskCFGID   ( 0x  << CPU_VER_offCFGID )
+#define CPU_VER_mskREV ( 0xFF  << CPU_VER_offREV )
+#define CPU_VER_mskCPUID   ( 0xFF  << CPU_VER_offCPUID )
+
+/**
+ * cr1: ICM_CFG (Instruction Cache/Memory Configuration Register)
+ */
+#define ICM_CFG_offISET0   /* I-cache sets (# of cache 
lines) per way */
+#define ICM_CFG_offIWAY3   /* I-cache ways */
+#define ICM_CFG_offISZ 6   /* I-cache line size */
+#define ICM_CFG_offILCK9   /* I-cache locking support */
+#define ICM_CFG_offILMB10  /* On-chip ILM banks */
+#define ICM_CFG_offBSAV13  /* ILM base register alignment 
version */
+/* bit 15:31 reserved */
+
+#define ICM_CFG_mskISET( 0x7  << ICM_CFG_offISET )
+#define ICM_CFG_mskIWAY( 0x7  << ICM_CFG_offIWAY )
+#define ICM_CFG_mskISZ ( 0x7  << ICM_CFG_offISZ )
+#define ICM_CFG_mskILCK( 0x1  << ICM_CFG_offILCK )
+#define ICM_CFG_mskILMB( 0x7  << ICM_CFG_offILMB )
+#define ICM_CFG_mskBSAV( 0x3  << ICM_CFG_offBSAV )
+
+/**
+ * cr2: DCM_CFG (Data Cache/Memory Configuration Register)
+ */
+#define DCM_CFG_offDSET0   /* D-cache sets (# of cache 
lines) per way */
+#define DCM_CFG_offDWAY3   /* D-cache ways */
+#define DCM_CFG_offDSZ 6   /* D-cache line size */
+#define DCM_CFG_offDLCK9   /* D-cache locking support */
+#define DCM_CFG_offDLMB10  /* On-chip DLM banks */
+#define DCM_CFG_offBSAV13  /* DLM base register alignment 
version */
+/* bit 15:31 reserved */
+
+#define DCM_CFG_mskDSET( 0x7  << DCM_CFG_offDSET )
+#define DCM_CFG_mskDWAY( 0x7  << DCM_CFG_offDWAY )
+#define DCM_CFG_mskDSZ ( 0x7  << DCM_CFG_offDSZ )
+#define DCM_CFG_mskDLCK( 0x1  << DCM_CFG_offDLCK )
+#define DCM_CFG_mskDLMB( 0x7  << DCM_CFG_offDLMB )
+#define DCM_CFG_mskBSAV( 0x3  << DCM_CFG_offBSAV )
+
+/**
+ * cr3: MMU_CFG (MMU 

[PATCH v4 05/36] nds32: Exception handling

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch includes the exception/interrupt entries, pt_reg structure and
related accessors.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/ptrace.h |   66 +
 arch/nds32/kernel/ex-entry.S|  157 ++
 arch/nds32/kernel/ex-exit.S |  193 +
 arch/nds32/kernel/stacktrace.c  |   47 +++
 arch/nds32/kernel/traps.c   |  428 +++
 arch/nds32/mm/alignment.c   |  609 +++
 6 files changed, 1500 insertions(+)
 create mode 100644 arch/nds32/include/asm/ptrace.h
 create mode 100644 arch/nds32/kernel/ex-entry.S
 create mode 100644 arch/nds32/kernel/ex-exit.S
 create mode 100644 arch/nds32/kernel/stacktrace.c
 create mode 100644 arch/nds32/kernel/traps.c
 create mode 100644 arch/nds32/mm/alignment.c

diff --git a/arch/nds32/include/asm/ptrace.h b/arch/nds32/include/asm/ptrace.h
new file mode 100644
index 000..db7856c
--- /dev/null
+++ b/arch/nds32/include/asm/ptrace.h
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_PTRACE_H
+#define __ASM_NDS32_PTRACE_H
+
+#define PTRACE_GETREGS 12
+#define PTRACE_SETREGS 13
+#define PTRACE_GETFPREGS   14
+#define PTRACE_SETFPREGS   15
+
+#include 
+
+#ifndef __ASSEMBLY__
+
+struct pt_regs {
+   union {
+   struct user_pt_regs user_regs;
+   struct {
+   long uregs[26];
+   long fp;
+   long gp;
+   long lp;
+   long sp;
+   long ipc;
+#if defined(CONFIG_HWZOL)
+   long lb;
+   long le;
+   long lc;
+#else
+   long dummy[3];
+#endif
+   long syscallno;
+   };
+   };
+   long orig_r0;
+   long ir0;
+   long ipsw;
+   long pipsw;
+   long pipc;
+   long pp0;
+   long pp1;
+   long fucop_ctl;
+   long osp;
+};
+
+#include 
+extern void show_regs(struct pt_regs *);
+/* Avoid circular header include via sched.h */
+struct task_struct;
+extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
+int error_code, int si_code);
+
+#define arch_has_single_step() (1)
+#define user_mode(regs)(((regs)->ipsw & PSW_mskPOM) == 
0)
+#define interrupts_enabled(regs)   (!!((regs)->ipsw & PSW_mskGIE))
+#define valid_user_regs(regs)  (user_mode(regs) && 
interrupts_enabled(regs))
+#define regs_return_value(regs)((regs)->uregs[0])
+#define instruction_pointer(regs)  ((regs)->ipc)
+#define user_stack_pointer(regs)((regs)->sp)
+#define profile_pc(regs)   instruction_pointer(regs)
+
+#define ARCH_HAS_USER_SINGLE_STEP_INFO
+
+#endif /* __ASSEMBLY__ */
+#endif
diff --git a/arch/nds32/kernel/ex-entry.S b/arch/nds32/kernel/ex-entry.S
new file mode 100644
index 000..d2b3b8a
--- /dev/null
+++ b/arch/nds32/kernel/ex-entry.S
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef CONFIG_HWZOL
+   .macro push_zol
+   mfusr   $r14, $LB
+   mfusr   $r15, $LE
+   mfusr   $r16, $LC
+   .endm
+#endif
+
+   .macro  save_user_regs
+
+   smw.adm $sp, [$sp], $sp, #0x1
+   /* move $SP to the bottom of pt_regs */
+   addi$sp, $sp, -OSP_OFFSET
+
+   /* push $r0 ~ $r25 */
+   smw.bim $r0, [$sp], $r25
+   /* push $fp, $gp, $lp */
+   smw.bim $sp, [$sp], $sp, #0xe
+
+   mfsr$r12, $SP_USR
+   mfsr$r13, $IPC
+#ifdef CONFIG_HWZOL
+   push_zol
+#endif
+   movi$r17, -1
+   move$r18, $r0
+   mfsr$r19, $PSW
+   mfsr$r20, $IPSW
+   mfsr$r21, $P_IPSW
+   mfsr$r22, $P_IPC
+   mfsr$r23, $P_P0
+   mfsr$r24, $P_P1
+   smw.bim $r12, [$sp], $r24, #0
+   addi$sp, $sp, -FUCOP_CTL_OFFSET
+
+   /* Initialize kernel space $fp */
+   andi$p0, $r20, #PSW_mskPOM
+   movi$p1, #0x0
+   cmovz   $fp, $p1, $p0
+
+   andi$r16, $r19, #PSW_mskINTL
+   slti$r17, $r16, #4
+   bnez$r17, 1f
+   addi$r17, $r19, #-2
+   mtsr$r17, $PSW
+   isb
+1:
+   /* If it was superuser mode, we don't need to update $r25 */
+   bnez$p0, 2f
+   la  $p0, __entry_task
+   lw  $r25, [$p0]
+2:
+   .endm
+
+   .text
+
+/*
+ * Exception Vector
+ */
+exception_handlers:
+   .long   unhandled_exceptions!Reset/NMI
+   .long   unhandled_exceptions!TLB fill
+   .long   do_page_fault   !PTE not present
+   .long   

[PATCH v4 04/36] nds32: Kernel booting and initialization

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch includes the kernel startup code. It can get dtb pointer
passed from bootloader. It will create a temp mapping by tlb
instructions at beginning and goto start_kernel.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/kernel/head.S  |  189 ++
 arch/nds32/kernel/setup.c |  383 +
 2 files changed, 572 insertions(+)
 create mode 100644 arch/nds32/kernel/head.S
 create mode 100644 arch/nds32/kernel/setup.c

diff --git a/arch/nds32/kernel/head.S b/arch/nds32/kernel/head.S
new file mode 100644
index 000..4cbf6f4
--- /dev/null
+++ b/arch/nds32/kernel/head.S
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef CONFIG_CPU_BIG_ENDIAN
+#define OF_DT_MAGIC 0xd00dfeed
+#else
+#define OF_DT_MAGIC 0xedfe0dd0
+#endif
+
+   .globl  swapper_pg_dir
+   .equswapper_pg_dir, TEXTADDR - 0x4000
+
+/*
+ * Kernel startup entry point.
+ */
+   .section ".head.text", "ax"
+   .type   _stext, %function
+ENTRY(_stext)
+   setgie.d! Disable interrupt
+   isb
+/*
+ * Disable I/D-cache and enable it at a proper time
+ */
+   mfsr$r0, $mr8
+   li  $r1, #~(CACHE_CTL_mskIC_EN|CACHE_CTL_mskDC_EN)
+   and $r0, $r0, $r1
+   mtsr$r0, $mr8
+
+/*
+ * Process device tree blob
+ */
+   andi$r0,$r2,#0x3
+   li  $r10, 0
+   bne $r0, $r10, _nodtb
+   lwi $r0, [$r2]
+   li  $r1, OF_DT_MAGIC
+   bne $r0, $r1, _nodtb
+   move$r10, $r2
+_nodtb:
+
+/*
+ * Create a temporary mapping area for booting, before start_kernel
+ */
+   sethi   $r4, hi20(swapper_pg_dir)
+   li  $p0, (PAGE_OFFSET - PHYS_OFFSET)
+   sub $r4, $r4, $p0
+   tlbop   FlushAll! invalidate TLB\n"
+   isb
+   mtsr$r4, $L1_PPTB   ! load page table pointer\n"
+
+/* set NTC0 cacheable/writeback, mutliple page size in use */
+   mfsr$r3, $MMU_CTL
+   li  $r0, #~MMU_CTL_mskNTC0
+   and $r3, $r3, $r0
+#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
+   ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << 
MMU_CTL_offNTC0))
+#else
+   ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << 
MMU_CTL_offNTC0)|MMU_CTL_D8KB)
+#endif
+#ifdef CONFIG_HW_SUPPORT_UNALIGNMENT_ACCESS
+   li  $r0, #MMU_CTL_UNA
+   or  $r3, $r3, $r0
+#endif
+   mtsr$r3, $MMU_CTL
+   isb
+
+/* set page size and size of kernel image */
+mfsr$r0, $MMU_CFG
+srli$r3, $r0, MMU_CFG_offfEPSZ
+zeb $r3, $r3
+bnez$r3, _extra_page_size_support
+#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
+li  $r5, #SZ_4K ! Use 4KB page size
+#else
+li  $r5, #SZ_8K ! Use 8KB page size
+li  $r3, #1
+#endif
+mtsr$r3, $TLB_MISC
+b   _image_size_check
+
+_extra_page_size_support:! Use epzs pages size
+clz $r6, $r3
+subri   $r2, $r6, #31
+li  $r3, #1
+sll $r3, $r3, $r2
+/* MMU_CFG.EPSZ value -> meaning */
+mul $r5, $r3, $r3
+slli$r5, $r5, #14
+/* MMU_CFG.EPSZ  -> TLB_MISC.ACC_PSZ */
+addi$r3, $r2, #0x2
+mtsr$r3, $TLB_MISC
+
+_image_size_check:
+/* calculate the image maximum size accepted by TLB config */
+andi$r6, $r0, MMU_CFG_mskTBW
+andi$r0, $r0, MMU_CFG_mskTBS
+srli$r6, $r6, MMU_CFG_offTBW
+srli$r0, $r0, MMU_CFG_offTBS
+/*
+ * we just map the kernel to the maximum way - 1 of tlb
+ * reserver one way for UART VA mapping
+ * it will cause page fault if UART mapping cover the kernel mapping
+ *
+ * direct mapping is not supported now.
+ */
+li  $r2, 't'
+beqz$r6, __error ! MMU_CFG.TBW = 0 is direct mappin
+addi$r0, $r0, #0x2   ! MMU_CFG.TBS value -> meaning
+sll $r0, $r6, $r0! entries = k-way * n-set
+mul $r6, $r0, $r5! max size = entries * page size
+/* check kernel image size */
+la  $r3, (_end - PAGE_OFFSET)
+li  $r2, 's'
+bgt $r3, $r6, __error
+
+   li  $r2, #(PHYS_OFFSET + TLB_DATA_kernel_text_attr)
+li  $r3, PAGE_OFFSET
+add $r6, $r6, $r3
+
+_tlb:
+   mtsr$r3, $TLB_VPN
+   dsb
+   tlbop   $r2, RWR
+   isb
+   add $r3, $r3, $r5
+   add $r2, $r2, $r5
+   bgt $r6, $r3, _tlb
+   mfsr$r3, $TLB_MISC  ! setup access page size
+   li

[PATCH v4 06/36] nds32: MMU definitions

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch includes virtual memory layout, PHYS_OFFSET is defined as 0x0. It
also includes the 4KB/8KB page size configurations and pte operations.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/fixmap.h   |   29 +++
 arch/nds32/include/asm/highmem.h  |   65 ++
 arch/nds32/include/asm/memory.h   |  105 ++
 arch/nds32/include/asm/mmu.h  |   12 ++
 arch/nds32/include/asm/page.h |   67 ++
 arch/nds32/include/asm/pgalloc.h  |   96 +
 arch/nds32/include/asm/pgtable.h  |  413 +
 arch/nds32/include/asm/shmparam.h |   19 ++
 8 files changed, 806 insertions(+)
 create mode 100644 arch/nds32/include/asm/fixmap.h
 create mode 100644 arch/nds32/include/asm/highmem.h
 create mode 100644 arch/nds32/include/asm/memory.h
 create mode 100644 arch/nds32/include/asm/mmu.h
 create mode 100644 arch/nds32/include/asm/page.h
 create mode 100644 arch/nds32/include/asm/pgalloc.h
 create mode 100644 arch/nds32/include/asm/pgtable.h
 create mode 100644 arch/nds32/include/asm/shmparam.h

diff --git a/arch/nds32/include/asm/fixmap.h b/arch/nds32/include/asm/fixmap.h
new file mode 100644
index 000..0e60e15
--- /dev/null
+++ b/arch/nds32/include/asm/fixmap.h
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_FIXMAP_H
+#define __ASM_NDS32_FIXMAP_H
+
+#ifdef CONFIG_HIGHMEM
+#include 
+#include 
+#endif
+
+enum fixed_addresses {
+   FIX_HOLE,
+   FIX_KMAP_RESERVED,
+   FIX_KMAP_BEGIN,
+#ifdef CONFIG_HIGHMEM
+   FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_TYPE_NR * NR_CPUS),
+#endif
+   FIX_EARLYCON_MEM_BASE,
+   __end_of_fixed_addresses
+};
+#define FIXADDR_TOP ((unsigned long) (-(16 * PAGE_SIZE)))
+#define FIXADDR_SIZE   ((__end_of_fixed_addresses) << PAGE_SHIFT)
+#define FIXADDR_START  (FIXADDR_TOP - FIXADDR_SIZE)
+#define FIXMAP_PAGE_IO __pgprot(PAGE_DEVICE)
+void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot);
+
+#include 
+#endif /* __ASM_NDS32_FIXMAP_H */
diff --git a/arch/nds32/include/asm/highmem.h b/arch/nds32/include/asm/highmem.h
new file mode 100644
index 000..425d546
--- /dev/null
+++ b/arch/nds32/include/asm/highmem.h
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef _ASM_HIGHMEM_H
+#define _ASM_HIGHMEM_H
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Right now we initialize only a single pte table. It can be extended
+ * easily, subsequent pte tables have to be allocated in one physical
+ * chunk of RAM.
+ */
+/*
+ * Ordering is (from lower to higher memory addresses):
+ *
+ * high_memory
+ * Persistent kmap area
+ * PKMAP_BASE
+ * fixed_addresses
+ * FIXADDR_START
+ * FIXADDR_TOP
+ * Vmalloc area
+ * VMALLOC_START
+ * VMALLOC_END
+ */
+#define PKMAP_BASE ((FIXADDR_START - PGDIR_SIZE) & (PGDIR_MASK))
+#define LAST_PKMAP PTRS_PER_PTE
+#define LAST_PKMAP_MASK(LAST_PKMAP - 1)
+#define PKMAP_NR(virt) (((virt) - (PKMAP_BASE)) >> PAGE_SHIFT)
+#define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT))
+#define kmap_prot  PAGE_KERNEL
+
+static inline void flush_cache_kmaps(void)
+{
+   cpu_dcache_wbinval_all();
+}
+
+/* declarations for highmem.c */
+extern unsigned long highstart_pfn, highend_pfn;
+
+extern pte_t *pkmap_page_table;
+
+extern void *kmap_high(struct page *page);
+extern void kunmap_high(struct page *page);
+
+extern void kmap_init(void);
+
+/*
+ * The following functions are already defined by 
+ * when CONFIG_HIGHMEM is not set.
+ */
+#ifdef CONFIG_HIGHMEM
+extern void *kmap(struct page *page);
+extern void kunmap(struct page *page);
+extern void *kmap_atomic(struct page *page);
+extern void __kunmap_atomic(void *kvaddr);
+extern void *kmap_atomic_pfn(unsigned long pfn);
+extern struct page *kmap_atomic_to_page(void *ptr);
+#endif
+
+#endif
diff --git a/arch/nds32/include/asm/memory.h b/arch/nds32/include/asm/memory.h
new file mode 100644
index 000..60efc72
--- /dev/null
+++ b/arch/nds32/include/asm/memory.h
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_MEMORY_H
+#define __ASM_NDS32_MEMORY_H
+
+#include 
+#include 
+
+#ifndef __ASSEMBLY__
+#include 
+#endif
+
+#ifndef PHYS_OFFSET
+#define PHYS_OFFSET (0x0)
+#endif
+
+#ifndef __virt_to_bus
+#define __virt_to_bus  __virt_to_phys
+#endif
+
+#ifndef __bus_to_virt
+#define __bus_to_virt  __phys_to_virt
+#endif
+
+/*
+ * TASK_SIZE - the maximum size of a user space task.
+ * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
+ */
+#define TASK_SIZE  ((CONFIG_PAGE_OFFSET) - (SZ_32M))

[PATCH v4 07/36] nds32: MMU initialization

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch includes memory initializations and highmem supporting.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/mm/highmem.c  |   79 +
 arch/nds32/mm/init.c |  277 ++
 arch/nds32/mm/mm-nds32.c |   90 +++
 3 files changed, 446 insertions(+)
 create mode 100644 arch/nds32/mm/highmem.c
 create mode 100644 arch/nds32/mm/init.c
 create mode 100644 arch/nds32/mm/mm-nds32.c

diff --git a/arch/nds32/mm/highmem.c b/arch/nds32/mm/highmem.c
new file mode 100644
index 000..e17cb8a
--- /dev/null
+++ b/arch/nds32/mm/highmem.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+void *kmap(struct page *page)
+{
+   unsigned long vaddr;
+   might_sleep();
+   if (!PageHighMem(page))
+   return page_address(page);
+   vaddr = (unsigned long)kmap_high(page);
+   return (void *)vaddr;
+}
+
+EXPORT_SYMBOL(kmap);
+
+void kunmap(struct page *page)
+{
+   BUG_ON(in_interrupt());
+   if (!PageHighMem(page))
+   return;
+   kunmap_high(page);
+}
+
+EXPORT_SYMBOL(kunmap);
+
+void *kmap_atomic(struct page *page)
+{
+   unsigned int idx;
+   unsigned long vaddr, pte;
+   int type;
+   pte_t *ptep;
+
+   preempt_disable();
+   pagefault_disable();
+   if (!PageHighMem(page))
+   return page_address(page);
+
+   type = kmap_atomic_idx_push();
+
+   idx = type + KM_TYPE_NR * smp_processor_id();
+   vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
+   pte = (page_to_pfn(page) << PAGE_SHIFT) | (PAGE_KERNEL);
+   ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr);
+   set_pte(ptep, pte);
+
+   __nds32__tlbop_inv(vaddr);
+   __nds32__mtsr_dsb(vaddr, NDS32_SR_TLB_VPN);
+   __nds32__tlbop_rwr(pte);
+   __nds32__isb();
+   return (void *)vaddr;
+}
+
+EXPORT_SYMBOL(kmap_atomic);
+
+void __kunmap_atomic(void *kvaddr)
+{
+   if (kvaddr >= (void *)FIXADDR_START) {
+   unsigned long vaddr = (unsigned long)kvaddr;
+   pte_t *ptep;
+   kmap_atomic_idx_pop();
+   __nds32__tlbop_inv(vaddr);
+   __nds32__isb();
+   ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr);
+   set_pte(ptep, 0);
+   }
+   pagefault_enable();
+   preempt_enable();
+}
+
+EXPORT_SYMBOL(__kunmap_atomic);
diff --git a/arch/nds32/mm/init.c b/arch/nds32/mm/init.c
new file mode 100644
index 000..93ee016
--- /dev/null
+++ b/arch/nds32/mm/init.c
@@ -0,0 +1,277 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 1995-2005 Russell King
+// Copyright (C) 2012 ARM Ltd.
+// Copyright (C) 2013-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
+DEFINE_SPINLOCK(anon_alias_lock);
+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
+extern unsigned long phys_initrd_start;
+extern unsigned long phys_initrd_size;
+
+/*
+ * empty_zero_page is a special page that is used for
+ * zero-initialized data and COW.
+ */
+struct page *empty_zero_page;
+
+static void __init zone_sizes_init(void)
+{
+   unsigned long zones_size[MAX_NR_ZONES];
+
+   /* Clear the zone sizes */
+   memset(zones_size, 0, sizeof(zones_size));
+
+   zones_size[ZONE_NORMAL] = max_low_pfn;
+#ifdef CONFIG_HIGHMEM
+   zones_size[ZONE_HIGHMEM] = max_pfn;
+#endif
+   free_area_init(zones_size);
+
+}
+
+/*
+ * Map all physical memory under high_memory into kernel's address space.
+ *
+ * This is explicitly coded for two-level page tables, so if you need
+ * something else then this needs to change.
+ */
+static void __init map_ram(void)
+{
+   unsigned long v, p, e;
+   pgd_t *pge;
+   pud_t *pue;
+   pmd_t *pme;
+   pte_t *pte;
+   /* These mark extents of read-only kernel pages...
+* ...from vmlinux.lds.S
+*/
+
+   p = (u32) memblock_start_of_DRAM() & PAGE_MASK;
+   e = min((u32) memblock_end_of_DRAM(), (u32) __pa(high_memory));
+
+   v = (u32) __va(p);
+   pge = pgd_offset_k(v);
+
+   while (p < e) {
+   int j;
+   pue = pud_offset(pge, v);
+   pme = pmd_offset(pue, v);
+
+   if ((u32) pue != (u32) pge || (u32) pme != (u32) pge) {
+   panic("%s: Kernel hardcoded for "
+ "two-level page tables", __func__);
+   }
+
+   /* Alloc one page for holding PTE's... */
+   pte = (pte_t *) __va(memblock_alloc(PAGE_SIZE, PAGE_SIZE));
+   memset(pte, 0, 

[PATCH v4 08/36] nds32: MMU fault handling and page table management

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch includes page fault handler, mmap and fixup implementations.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/lib/copy_page.S |   37 
 arch/nds32/mm/extable.c|   16 ++
 arch/nds32/mm/fault.c  |  410 
 arch/nds32/mm/mmap.c   |   73 
 4 files changed, 536 insertions(+)
 create mode 100644 arch/nds32/lib/copy_page.S
 create mode 100644 arch/nds32/mm/extable.c
 create mode 100644 arch/nds32/mm/fault.c
 create mode 100644 arch/nds32/mm/mmap.c

diff --git a/arch/nds32/lib/copy_page.S b/arch/nds32/lib/copy_page.S
new file mode 100644
index 000..4a2ff85
--- /dev/null
+++ b/arch/nds32/lib/copy_page.S
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+
+   .text
+ENTRY(copy_page)
+   pushm   $r2, $r10
+   movi$r2, PAGE_SIZE >> 5
+.Lcopy_loop:
+   lmw.bim $r3, [$r1], $r10
+   smw.bim $r3, [$r0], $r10
+   subi45  $r2, #1
+   bnez38  $r2, .Lcopy_loop
+   popm$r2, $r10
+   ret
+ENDPROC(copy_page)
+
+ENTRY(clear_page)
+   pushm   $r1, $r9
+   movi$r1, PAGE_SIZE >> 5
+   movi55  $r2, #0
+   movi55  $r3, #0
+   movi55  $r4, #0
+   movi55  $r5, #0
+   movi55  $r6, #0
+   movi55  $r7, #0
+   movi55  $r8, #0
+   movi55  $r9, #0
+.Lclear_loop:
+   smw.bim $r2, [$r0], $r9
+   subi45  $r1, #1
+   bnez38  $r1, .Lclear_loop
+   popm$r1, $r9
+ret
+ENDPROC(clear_page)
diff --git a/arch/nds32/mm/extable.c b/arch/nds32/mm/extable.c
new file mode 100644
index 000..db7f0a7
--- /dev/null
+++ b/arch/nds32/mm/extable.c
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+
+int fixup_exception(struct pt_regs *regs)
+{
+   const struct exception_table_entry *fixup;
+
+   fixup = search_exception_tables(instruction_pointer(regs));
+   if (fixup)
+   regs->ipc = fixup->fixup;
+
+   return fixup != NULL;
+}
diff --git a/arch/nds32/mm/fault.c b/arch/nds32/mm/fault.c
new file mode 100644
index 000..3a246fb
--- /dev/null
+++ b/arch/nds32/mm/fault.c
@@ -0,0 +1,410 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+extern void die(const char *str, struct pt_regs *regs, long err);
+
+/*
+ * This is useful to dump out the page tables associated with
+ * 'addr' in mm 'mm'.
+ */
+void show_pte(struct mm_struct *mm, unsigned long addr)
+{
+   pgd_t *pgd;
+   if (!mm)
+   mm = _mm;
+
+   pr_alert("pgd = %p\n", mm->pgd);
+   pgd = pgd_offset(mm, addr);
+   pr_alert("[%08lx] *pgd=%08lx", addr, pgd_val(*pgd));
+
+   do {
+   pmd_t *pmd;
+
+   if (pgd_none(*pgd))
+   break;
+
+   if (pgd_bad(*pgd)) {
+   pr_alert("(bad)");
+   break;
+   }
+
+   pmd = pmd_offset(pgd, addr);
+#if PTRS_PER_PMD != 1
+   pr_alert(", *pmd=%08lx", pmd_val(*pmd));
+#endif
+
+   if (pmd_none(*pmd))
+   break;
+
+   if (pmd_bad(*pmd)) {
+   pr_alert("(bad)");
+   break;
+   }
+
+   if (IS_ENABLED(CONFIG_HIGHMEM))
+   {
+   pte_t *pte;
+   /* We must not map this if we have highmem enabled */
+   pte = pte_offset_map(pmd, addr);
+   pr_alert(", *pte=%08lx", pte_val(*pte));
+   pte_unmap(pte);
+   }
+   } while (0);
+
+   pr_alert("\n");
+}
+
+void do_page_fault(unsigned long entry, unsigned long addr,
+  unsigned int error_code, struct pt_regs *regs)
+{
+   struct task_struct *tsk;
+   struct mm_struct *mm;
+   struct vm_area_struct *vma;
+   siginfo_t info;
+   int fault;
+   unsigned int mask = VM_READ | VM_WRITE | VM_EXEC;
+   unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
+
+   error_code = error_code & (ITYPE_mskINST | ITYPE_mskETYPE);
+   tsk = current;
+   mm = tsk->mm;
+   info.si_code = SEGV_MAPERR;
+   /*
+* We fault-in kernel-space virtual memory on-demand. The
+* 'reference' page table is init_mm.pgd.
+*
+* NOTE! We MUST NOT take any locks for this case. We may
+* be in an interrupt or a critical region, and should
+* only copy the information from the master page table,
+* nothing more.
+*/
+   if (addr >= TASK_SIZE) {
+   if 

[PATCH v4 09/36] nds32: Cache and TLB routines

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch contains cache and TLB maintenance functions.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/cache.h |   12 +
 arch/nds32/include/asm/cache_info.h|   13 +
 arch/nds32/include/asm/cacheflush.h|   44 +++
 arch/nds32/include/asm/mmu_context.h   |   68 
 arch/nds32/include/asm/proc-fns.h  |   44 +++
 arch/nds32/include/asm/tlb.h   |   28 ++
 arch/nds32/include/asm/tlbflush.h  |   47 +++
 arch/nds32/include/uapi/asm/cachectl.h |   14 +
 arch/nds32/kernel/cacheinfo.c  |   49 +++
 arch/nds32/mm/cacheflush.c |  322 +++
 arch/nds32/mm/proc.c   |  540 
 arch/nds32/mm/tlb.c|   50 +++
 12 files changed, 1231 insertions(+)
 create mode 100644 arch/nds32/include/asm/cache.h
 create mode 100644 arch/nds32/include/asm/cache_info.h
 create mode 100644 arch/nds32/include/asm/cacheflush.h
 create mode 100644 arch/nds32/include/asm/mmu_context.h
 create mode 100644 arch/nds32/include/asm/proc-fns.h
 create mode 100644 arch/nds32/include/asm/tlb.h
 create mode 100644 arch/nds32/include/asm/tlbflush.h
 create mode 100644 arch/nds32/include/uapi/asm/cachectl.h
 create mode 100644 arch/nds32/kernel/cacheinfo.c
 create mode 100644 arch/nds32/mm/cacheflush.c
 create mode 100644 arch/nds32/mm/proc.c
 create mode 100644 arch/nds32/mm/tlb.c

diff --git a/arch/nds32/include/asm/cache.h b/arch/nds32/include/asm/cache.h
new file mode 100644
index 000..347db48
--- /dev/null
+++ b/arch/nds32/include/asm/cache.h
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __NDS32_CACHE_H__
+#define __NDS32_CACHE_H__
+
+#define L1_CACHE_BYTES 32
+#define L1_CACHE_SHIFT 5
+
+#define ARCH_DMA_MINALIGN   L1_CACHE_BYTES
+
+#endif /* __NDS32_CACHE_H__ */
diff --git a/arch/nds32/include/asm/cache_info.h 
b/arch/nds32/include/asm/cache_info.h
new file mode 100644
index 000..38ec458
--- /dev/null
+++ b/arch/nds32/include/asm/cache_info.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+struct cache_info {
+   unsigned char ways;
+   unsigned char line_size;
+   unsigned short sets;
+   unsigned short size;
+#if defined(CONFIG_CPU_CACHE_ALIASING)
+   unsigned short aliasing_num;
+   unsigned int aliasing_mask;
+#endif
+};
diff --git a/arch/nds32/include/asm/cacheflush.h 
b/arch/nds32/include/asm/cacheflush.h
new file mode 100644
index 000..7b9b20a
--- /dev/null
+++ b/arch/nds32/include/asm/cacheflush.h
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __NDS32_CACHEFLUSH_H__
+#define __NDS32_CACHEFLUSH_H__
+
+#include 
+
+#define PG_dcache_dirty PG_arch_1
+
+#ifdef CONFIG_CPU_CACHE_ALIASING
+void flush_cache_mm(struct mm_struct *mm);
+void flush_cache_dup_mm(struct mm_struct *mm);
+void flush_cache_range(struct vm_area_struct *vma,
+  unsigned long start, unsigned long end);
+void flush_cache_page(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long pfn);
+void flush_cache_kmaps(void);
+void flush_cache_vmap(unsigned long start, unsigned long end);
+void flush_cache_vunmap(unsigned long start, unsigned long end);
+
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
+void flush_dcache_page(struct page *page);
+void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
+  unsigned long vaddr, void *dst, void *src, int len);
+void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
+unsigned long vaddr, void *dst, void *src, int len);
+
+#define ARCH_HAS_FLUSH_ANON_PAGE
+void flush_anon_page(struct vm_area_struct *vma,
+struct page *page, unsigned long vaddr);
+
+#define ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
+void flush_kernel_dcache_page(struct page *page);
+void flush_icache_range(unsigned long start, unsigned long end);
+void flush_icache_page(struct vm_area_struct *vma, struct page *page);
+#define flush_dcache_mmap_lock(mapping)   spin_lock_irq(&(mapping)->tree_lock)
+#define flush_dcache_mmap_unlock(mapping) 
spin_unlock_irq(&(mapping)->tree_lock)
+
+#else
+#include 
+#endif
+
+#endif /* __NDS32_CACHEFLUSH_H__ */
diff --git a/arch/nds32/include/asm/mmu_context.h 
b/arch/nds32/include/asm/mmu_context.h
new file mode 100644
index 000..fd7d13c
--- /dev/null
+++ b/arch/nds32/include/asm/mmu_context.h
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_MMU_CONTEXT_H
+#define __ASM_NDS32_MMU_CONTEXT_H
+
+#include 
+#include 
+#include 
+#include 
+
+static inline int
+init_new_context(struct task_struct *tsk, struct mm_struct *mm)

[PATCH v4 11/36] nds32: IRQ handling

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch includes irq related functions and irqchip_init().

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/irqflags.h |   36 
 arch/nds32/kernel/irq.c   |9 +
 2 files changed, 45 insertions(+)
 create mode 100644 arch/nds32/include/asm/irqflags.h
 create mode 100644 arch/nds32/kernel/irq.c

diff --git a/arch/nds32/include/asm/irqflags.h 
b/arch/nds32/include/asm/irqflags.h
new file mode 100644
index 000..2bfd00f
--- /dev/null
+++ b/arch/nds32/include/asm/irqflags.h
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+
+#define arch_local_irq_disable()   \
+   GIE_DISABLE();
+
+#define arch_local_irq_enable()\
+   GIE_ENABLE();
+static inline unsigned long arch_local_irq_save(void)
+{
+   unsigned long flags;
+   flags = __nds32__mfsr(NDS32_SR_PSW) & PSW_mskGIE;
+   GIE_DISABLE();
+   return flags;
+}
+
+static inline unsigned long arch_local_save_flags(void)
+{
+   unsigned long flags;
+   flags = __nds32__mfsr(NDS32_SR_PSW) & PSW_mskGIE;
+   return flags;
+}
+
+static inline void arch_local_irq_restore(unsigned long flags)
+{
+   if(flags)
+   GIE_ENABLE();
+}
+
+static inline int arch_irqs_disabled_flags(unsigned long flags)
+{
+   return !flags;
+}
diff --git a/arch/nds32/kernel/irq.c b/arch/nds32/kernel/irq.c
new file mode 100644
index 000..6ff5a67
--- /dev/null
+++ b/arch/nds32/kernel/irq.c
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+
+void __init init_IRQ(void)
+{
+   irqchip_init();
+}
-- 
1.7.9.5



[PATCH v4 10/36] nds32: Process management

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch includes copy_thread(), start_thread() implementation and cpu_context
structure definition. nds32 uses $r25 to get current task_struct.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/current.h |   12 ++
 arch/nds32/include/asm/processor.h   |  102 +
 arch/nds32/include/asm/thread_info.h |   78 +
 arch/nds32/kernel/process.c  |  204 ++
 4 files changed, 396 insertions(+)
 create mode 100644 arch/nds32/include/asm/current.h
 create mode 100644 arch/nds32/include/asm/processor.h
 create mode 100644 arch/nds32/include/asm/thread_info.h
 create mode 100644 arch/nds32/kernel/process.c

diff --git a/arch/nds32/include/asm/current.h b/arch/nds32/include/asm/current.h
new file mode 100644
index 000..b4dcd22
--- /dev/null
+++ b/arch/nds32/include/asm/current.h
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef _ASM_NDS32_CURRENT_H
+#define _ASM_NDS32_CURRENT_H
+
+#ifndef __ASSEMBLY__
+register struct task_struct *current asm("$r25");
+#endif /* __ASSEMBLY__ */
+#define tsk $r25
+
+#endif /* _ASM_NDS32_CURRENT_H */
diff --git a/arch/nds32/include/asm/processor.h 
b/arch/nds32/include/asm/processor.h
new file mode 100644
index 000..cad9b8c
--- /dev/null
+++ b/arch/nds32/include/asm/processor.h
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_PROCESSOR_H
+#define __ASM_NDS32_PROCESSOR_H
+
+/*
+ * Default implementation of macro that returns current
+ * instruction pointer ("program counter").
+ */
+#define current_text_addr() ({ __label__ _l; _l: &&_l;})
+
+#ifdef __KERNEL__
+
+#include 
+#include 
+#include 
+
+#define KERNEL_STACK_SIZE  PAGE_SIZE
+#define STACK_TOP  TASK_SIZE
+#define STACK_TOP_MAX   TASK_SIZE
+
+struct cpu_context {
+   unsigned long r6;
+   unsigned long r7;
+   unsigned long r8;
+   unsigned long r9;
+   unsigned long r10;
+   unsigned long r11;
+   unsigned long r12;
+   unsigned long r13;
+   unsigned long r14;
+   unsigned long fp;
+   unsigned long pc;
+   unsigned long sp;
+};
+
+struct thread_struct {
+   struct cpu_context cpu_context; /* cpu context */
+   /* fault info */
+   unsigned long address;
+   unsigned long trap_no;
+   unsigned long error_code;
+};
+
+#define INIT_THREAD  { }
+
+#ifdef __NDS32_EB__
+#define PSW_DE PSW_mskBE
+#else
+#define PSW_DE 0x0
+#endif
+
+#ifdef CONFIG_WBNA
+#define PSW_valWBNAPSW_mskWBNA
+#else
+#define PSW_valWBNA0x0
+#endif
+
+#ifdef CONFIG_HWZOL
+#definePSW_valINIT (PSW_CPL_ANY | PSW_mskAEN | PSW_valWBNA | PSW_mskDT 
| PSW_mskIT | PSW_DE | PSW_mskGIE)
+#else
+#definePSW_valINIT (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT 
| PSW_DE | PSW_mskGIE)
+#endif
+
+#define start_thread(regs,pc,stack)\
+({ \
+   memzero(regs, sizeof(struct pt_regs));  \
+   regs->ipsw = PSW_valINIT;   \
+   regs->ir0 = (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE 
| PSW_SYSTEM | PSW_INTL_1); \
+   regs->ipc = pc; \
+   regs->sp = stack;   \
+})
+
+/* Forward declaration, a strange C thing */
+struct task_struct;
+
+/* Free all resources held by a thread. */
+#define release_thread(thread) do { } while(0)
+
+/* Prepare to copy thread state - unlazy all lazy status */
+#define prepare_to_copy(tsk)   do { } while (0)
+
+unsigned long get_wchan(struct task_struct *p);
+
+#define cpu_relax()barrier()
+
+#define task_pt_regs(task) \
+   ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \
+   - 8) - 1)
+
+/*
+ * Create a new kernel thread
+ */
+extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
+
+#define KSTK_EIP(tsk)  instruction_pointer(task_pt_regs(tsk))
+#define KSTK_ESP(tsk)  user_stack_pointer(task_pt_regs(tsk))
+
+#endif
+
+#endif /* __ASM_NDS32_PROCESSOR_H */
diff --git a/arch/nds32/include/asm/thread_info.h 
b/arch/nds32/include/asm/thread_info.h
new file mode 100644
index 000..818e769
--- /dev/null
+++ b/arch/nds32/include/asm/thread_info.h
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_THREAD_INFO_H
+#define __ASM_NDS32_THREAD_INFO_H
+
+#ifdef __KERNEL__
+
+#define THREAD_SIZE_ORDER  (1)
+#define THREAD_SIZE(PAGE_SIZE << THREAD_SIZE_ORDER)
+
+#ifndef __ASSEMBLY__
+
+struct task_struct;
+
+#include 
+#include 
+
+typedef unsigned long mm_segment_t;
+
+/*
+ * low level task data that entry.S needs immediate access to.
+ * 

[PATCH v4 14/36] nds32: DMA mapping API

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds support for the DMA mapping API. It uses dma_map_ops for
flexibility.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/dma-mapping.h |   14 ++
 arch/nds32/kernel/dma.c  |  459 ++
 2 files changed, 473 insertions(+)
 create mode 100644 arch/nds32/include/asm/dma-mapping.h
 create mode 100644 arch/nds32/kernel/dma.c

diff --git a/arch/nds32/include/asm/dma-mapping.h 
b/arch/nds32/include/asm/dma-mapping.h
new file mode 100644
index 000..2dd47d24
--- /dev/null
+++ b/arch/nds32/include/asm/dma-mapping.h
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef ASMNDS32_DMA_MAPPING_H
+#define ASMNDS32_DMA_MAPPING_H
+
+extern struct dma_map_ops nds32_dma_ops;
+
+static inline struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
+{
+   return _dma_ops;
+}
+
+#endif
diff --git a/arch/nds32/kernel/dma.c b/arch/nds32/kernel/dma.c
new file mode 100644
index 000..9bd1dc7
--- /dev/null
+++ b/arch/nds32/kernel/dma.c
@@ -0,0 +1,459 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * This is the page table (2MB) covering uncached, DMA consistent allocations
+ */
+static pte_t *consistent_pte;
+static DEFINE_RAW_SPINLOCK(consistent_lock);
+
+/*
+ * VM region handling support.
+ *
+ * This should become something generic, handling VM region allocations for
+ * vmalloc and similar (ioremap, module space, etc).
+ *
+ * I envisage vmalloc()'s supporting vm_struct becoming:
+ *
+ *  struct vm_struct {
+ *struct vm_region region;
+ *unsigned longflags;
+ *struct page  **pages;
+ *unsigned int nr_pages;
+ *unsigned longphys_addr;
+ *  };
+ *
+ * get_vm_area() would then call vm_region_alloc with an appropriate
+ * struct vm_region head (eg):
+ *
+ *  struct vm_region vmalloc_head = {
+ * .vm_list= LIST_HEAD_INIT(vmalloc_head.vm_list),
+ * .vm_start   = VMALLOC_START,
+ * .vm_end = VMALLOC_END,
+ *  };
+ *
+ * However, vmalloc_head.vm_start is variable (typically, it is dependent on
+ * the amount of RAM found at boot time.)  I would imagine that get_vm_area()
+ * would have to initialise this each time prior to calling vm_region_alloc().
+ */
+struct arch_vm_region {
+   struct list_head vm_list;
+   unsigned long vm_start;
+   unsigned long vm_end;
+   struct page *vm_pages;
+};
+
+static struct arch_vm_region consistent_head = {
+   .vm_list = LIST_HEAD_INIT(consistent_head.vm_list),
+   .vm_start = CONSISTENT_BASE,
+   .vm_end = CONSISTENT_END,
+};
+
+static struct arch_vm_region *vm_region_alloc(struct arch_vm_region *head,
+ size_t size, int gfp)
+{
+   unsigned long addr = head->vm_start, end = head->vm_end - size;
+   unsigned long flags;
+   struct arch_vm_region *c, *new;
+
+   new = kmalloc(sizeof(struct arch_vm_region), gfp);
+   if (!new)
+   goto out;
+
+   raw_spin_lock_irqsave(_lock, flags);
+
+   list_for_each_entry(c, >vm_list, vm_list) {
+   if ((addr + size) < addr)
+   goto nospc;
+   if ((addr + size) <= c->vm_start)
+   goto found;
+   addr = c->vm_end;
+   if (addr > end)
+   goto nospc;
+   }
+
+found:
+   /*
+* Insert this entry _before_ the one we found.
+*/
+   list_add_tail(>vm_list, >vm_list);
+   new->vm_start = addr;
+   new->vm_end = addr + size;
+
+   raw_spin_unlock_irqrestore(_lock, flags);
+   return new;
+
+nospc:
+   raw_spin_unlock_irqrestore(_lock, flags);
+   kfree(new);
+out:
+   return NULL;
+}
+
+static struct arch_vm_region *vm_region_find(struct arch_vm_region *head,
+unsigned long addr)
+{
+   struct arch_vm_region *c;
+
+   list_for_each_entry(c, >vm_list, vm_list) {
+   if (c->vm_start == addr)
+   goto out;
+   }
+   c = NULL;
+out:
+   return c;
+}
+
+/* FIXME: attrs is not used. */
+static void *nds32_dma_alloc_coherent(struct device *dev, size_t size,
+ dma_addr_t * handle, gfp_t gfp,
+ unsigned long attrs)
+{
+   struct page *page;
+   struct arch_vm_region *c;
+   unsigned long order;
+   u64 mask = ~0ULL, limit;
+   pgprot_t prot = pgprot_noncached(PAGE_KERNEL);
+
+   if (!consistent_pte) {
+   pr_err("%s: not initialized\n", __func__);
+   

[PATCH v4 13/36] nds32: Device specific operations

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch introduces ioremap implementations.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/io.h |   83 +++
 arch/nds32/mm/ioremap.c |   62 
 2 files changed, 145 insertions(+)
 create mode 100644 arch/nds32/include/asm/io.h
 create mode 100644 arch/nds32/mm/ioremap.c

diff --git a/arch/nds32/include/asm/io.h b/arch/nds32/include/asm/io.h
new file mode 100644
index 000..81b4616
--- /dev/null
+++ b/arch/nds32/include/asm/io.h
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_IO_H
+#define __ASM_NDS32_IO_H
+
+extern void iounmap(void __iomem *addr);
+#define __raw_writeb __raw_writeb
+static inline void __raw_writeb(u8 val, volatile void __iomem *addr)
+{
+   asm volatile("sbi %0, [%1]" : : "r" (val), "r" (addr));
+}
+
+#define __raw_writew __raw_writew
+static inline void __raw_writew(u16 val, volatile void __iomem *addr)
+{
+   asm volatile("shi %0, [%1]" : : "r" (val), "r" (addr));
+}
+
+#define __raw_writel __raw_writel
+static inline void __raw_writel(u32 val, volatile void __iomem *addr)
+{
+   asm volatile("swi %0, [%1]" : : "r" (val), "r" (addr));
+}
+
+#define __raw_readb __raw_readb
+static inline u8 __raw_readb(const volatile void __iomem *addr)
+{
+   u8 val;
+
+   asm volatile("lbi %0, [%1]" : "=r" (val) : "r" (addr));
+   return val;
+}
+
+#define __raw_readw __raw_readw
+static inline u16 __raw_readw(const volatile void __iomem *addr)
+{
+   u16 val;
+
+   asm volatile("lhi %0, [%1]" : "=r" (val) : "r" (addr));
+   return val;
+}
+
+#define __raw_readl __raw_readl
+static inline u32 __raw_readl(const volatile void __iomem *addr)
+{
+   u32 val;
+
+   asm volatile("lwi %0, [%1]" : "=r" (val) : "r" (addr));
+   return val;
+}
+
+#define __iormb()   rmb()
+#define __iowmb()   wmb()
+
+#define mmiowb()__asm__ __volatile__ ("msync all" : : : "memory");
+
+/*
+ * {read,write}{b,w,l,q}_relaxed() are like the regular version, but
+ * are not guaranteed to provide ordering against spinlocks or memory
+ * accesses.
+ */
+
+#define readb_relaxed(c)   ({ u8  __v = __raw_readb(c); __v; })
+#define readw_relaxed(c)   ({ u16 __v = le16_to_cpu((__force 
__le16)__raw_readw(c)); __v; })
+#define readl_relaxed(c)   ({ u32 __v = le32_to_cpu((__force 
__le32)__raw_readl(c)); __v; })
+#define writeb_relaxed(v,c)((void)__raw_writeb((v),(c)))
+#define writew_relaxed(v,c)((void)__raw_writew((__force 
u16)cpu_to_le16(v),(c)))
+#define writel_relaxed(v,c)((void)__raw_writel((__force 
u32)cpu_to_le32(v),(c)))
+
+/*
+ * {read,write}{b,w,l,q}() access little endian memory and return result in
+ * native endianness.
+ */
+#define readb(c)   ({ u8  __v = readb_relaxed(c); __iormb(); __v; })
+#define readw(c)   ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
+#define readl(c)   ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
+
+#define writeb(v,c)({ __iowmb(); writeb_relaxed((v),(c)); })
+#define writew(v,c)({ __iowmb(); writew_relaxed((v),(c)); })
+#define writel(v,c)({ __iowmb(); writel_relaxed((v),(c)); })
+#include 
+#endif /* __ASM_NDS32_IO_H */
diff --git a/arch/nds32/mm/ioremap.c b/arch/nds32/mm/ioremap.c
new file mode 100644
index 000..2f6741c
--- /dev/null
+++ b/arch/nds32/mm/ioremap.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+
+void __iomem *ioremap(phys_addr_t phys_addr, size_t size);
+
+static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size,
+ void *caller)
+{
+   struct vm_struct *area;
+   unsigned long addr, offset, last_addr;
+   pgprot_t prot;
+
+   /* Don't allow wraparound or zero size */
+   last_addr = phys_addr + size - 1;
+   if (!size || last_addr < phys_addr)
+   return NULL;
+
+   /*
+* Mappings have to be page-aligned
+*/
+   offset = phys_addr & ~PAGE_MASK;
+   phys_addr &= PAGE_MASK;
+   size = PAGE_ALIGN(last_addr + 1) - phys_addr;
+
+   /*
+* Ok, go for it..
+*/
+   area = get_vm_area_caller(size, VM_IOREMAP, caller);
+   if (!area)
+   return NULL;
+
+   area->phys_addr = phys_addr;
+   addr = (unsigned long)area->addr;
+   prot = __pgprot(_PAGE_V | _PAGE_M_KRW | _PAGE_D |
+   _PAGE_G | _PAGE_C_DEV);
+   if (ioremap_page_range(addr, addr + size, phys_addr, prot)) {
+   vunmap((void *)addr);
+   return NULL;
+   }
+   return (__force void __iomem *)(offset + (char *)addr);
+
+}
+
+void __iomem *ioremap(phys_addr_t phys_addr, 

[PATCH v4 15/36] nds32: ELF definitions

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds definitions for the ELF format, relocation types, vdso
locations and EXEC_PAGESIZE.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/elf.h |  179 ++
 arch/nds32/include/uapi/asm/auxvec.h |   12 +++
 arch/nds32/include/uapi/asm/param.h  |   11 +++
 3 files changed, 202 insertions(+)
 create mode 100644 arch/nds32/include/asm/elf.h
 create mode 100644 arch/nds32/include/uapi/asm/auxvec.h
 create mode 100644 arch/nds32/include/uapi/asm/param.h

diff --git a/arch/nds32/include/asm/elf.h b/arch/nds32/include/asm/elf.h
new file mode 100644
index 000..99203f1
--- /dev/null
+++ b/arch/nds32/include/asm/elf.h
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASMNDS32_ELF_H
+#define __ASMNDS32_ELF_H
+
+/*
+ * ELF register definitions..
+ */
+
+#include 
+
+typedef unsigned long elf_greg_t;
+typedef unsigned long elf_freg_t[3];
+
+extern unsigned int elf_hwcap;
+
+#define EM_NDS32   167
+
+#define R_NDS32_NONE   0
+#define R_NDS32_16_RELA19
+#define R_NDS32_32_RELA20
+#define R_NDS32_9_PCREL_RELA   22
+#define R_NDS32_15_PCREL_RELA  23
+#define R_NDS32_17_PCREL_RELA  24
+#define R_NDS32_25_PCREL_RELA  25
+#define R_NDS32_HI20_RELA  26
+#define R_NDS32_LO12S3_RELA27
+#define R_NDS32_LO12S2_RELA28
+#define R_NDS32_LO12S1_RELA29
+#define R_NDS32_LO12S0_RELA30
+#define R_NDS32_SDA15S3_RELA   31
+#define R_NDS32_SDA15S2_RELA   32
+#define R_NDS32_SDA15S1_RELA   33
+#define R_NDS32_SDA15S0_RELA   34
+#define R_NDS32_GOT20  37
+#define R_NDS32_25_PLTREL  38
+#define R_NDS32_COPY   39
+#define R_NDS32_GLOB_DAT   40
+#define R_NDS32_JMP_SLOT   41
+#define R_NDS32_RELATIVE   42
+#define R_NDS32_GOTOFF 43
+#define R_NDS32_GOTPC2044
+#define R_NDS32_GOT_HI20   45
+#define R_NDS32_GOT_LO12   46
+#define R_NDS32_GOTPC_HI20 47
+#define R_NDS32_GOTPC_LO12 48
+#define R_NDS32_GOTOFF_HI2049
+#define R_NDS32_GOTOFF_LO1250
+#define R_NDS32_INSN16 51
+#define R_NDS32_LABEL  52
+#define R_NDS32_LONGCALL1  53
+#define R_NDS32_LONGCALL2  54
+#define R_NDS32_LONGCALL3  55
+#define R_NDS32_LONGJUMP1  56
+#define R_NDS32_LONGJUMP2  57
+#define R_NDS32_LONGJUMP3  58
+#define R_NDS32_LOADSTORE  59
+#define R_NDS32_9_FIXED_RELA   60
+#define R_NDS32_15_FIXED_RELA  61
+#define R_NDS32_17_FIXED_RELA  62
+#define R_NDS32_25_FIXED_RELA  63
+#define R_NDS32_PLTREL_HI2064
+#define R_NDS32_PLTREL_LO1265
+#define R_NDS32_PLT_GOTREL_HI2066
+#define R_NDS32_PLT_GOTREL_LO1267
+#define R_NDS32_LO12S0_ORI_RELA72
+#define R_NDS32_DWARF2_OP1_RELA77
+#define R_NDS32_DWARF2_OP2_RELA78
+#define R_NDS32_DWARF2_LEB_RELA79
+#define R_NDS32_WORD_9_PCREL_RELA  94
+#define R_NDS32_LONGCALL4  107
+#define R_NDS32_RELA_NOP_MIX   192
+#define R_NDS32_RELA_NOP_MAX   255
+
+#define ELF_NGREG (sizeof (struct pt_regs) / sizeof(elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+/* Core file format: The core file is written in such a way that gdb
+   can understand it and provide useful information to the user (under
+   linux we use the 'trad-core' bfd).  There are quite a number of
+   obstacles to being able to view the contents of the floating point
+   registers, and until these are solved you will not be able to view the
+   contents of them.  Actually, you can read in the core file and look at
+   the contents of the user struct to find out what the floating point
+   registers contain.
+   The actual file contents are as follows:
+   UPAGE: 1 page consisting of a user struct that tells gdb what is present
+   in the file.  Directly after this is a copy of the task_struct, which
+   is currently not used by gdb, but it may come in useful at some point.
+   All of the registers are stored as part of the upage.  The upage should
+   always be only one page.
+   DATA: The data area is stored.  We use current->end_text to
+   current->brk to pick up all of the user variables, plus any memory
+   that may have been malloced.  No attempt is made to determine if a page
+   is demand-zero or if a page is totally unused, we just cover the entire
+   range.  All of the addresses are rounded in such a way that an integral
+   number of pages is 

[PATCH v4 19/36] nds32: Library functions

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch add support for various library functions.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/string.h  |   17 +++
 arch/nds32/include/asm/swab.h|   35 +
 arch/nds32/include/asm/uaccess.h |  283 ++
 arch/nds32/kernel/nds32_ksyms.c  |   31 +
 arch/nds32/lib/Makefile  |3 +
 arch/nds32/lib/clear_user.S  |   42 ++
 arch/nds32/lib/copy_from_user.S  |   45 ++
 arch/nds32/lib/copy_template.S   |   70 ++
 arch/nds32/lib/copy_to_user.S|   45 ++
 arch/nds32/lib/memcpy.S  |   30 
 arch/nds32/lib/memmove.S |   70 ++
 arch/nds32/lib/memset.S  |   33 +
 arch/nds32/lib/memzero.S |   18 +++
 13 files changed, 722 insertions(+)
 create mode 100644 arch/nds32/include/asm/string.h
 create mode 100644 arch/nds32/include/asm/swab.h
 create mode 100644 arch/nds32/include/asm/uaccess.h
 create mode 100644 arch/nds32/kernel/nds32_ksyms.c
 create mode 100644 arch/nds32/lib/Makefile
 create mode 100644 arch/nds32/lib/clear_user.S
 create mode 100644 arch/nds32/lib/copy_from_user.S
 create mode 100644 arch/nds32/lib/copy_template.S
 create mode 100644 arch/nds32/lib/copy_to_user.S
 create mode 100644 arch/nds32/lib/memcpy.S
 create mode 100644 arch/nds32/lib/memmove.S
 create mode 100644 arch/nds32/lib/memset.S
 create mode 100644 arch/nds32/lib/memzero.S

diff --git a/arch/nds32/include/asm/string.h b/arch/nds32/include/asm/string.h
new file mode 100644
index 000..179272c
--- /dev/null
+++ b/arch/nds32/include/asm/string.h
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_STRING_H
+#define __ASM_NDS32_STRING_H
+
+#define __HAVE_ARCH_MEMCPY
+extern void *memcpy(void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMMOVE
+extern void *memmove(void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMSET
+extern void *memset(void *, int, __kernel_size_t);
+
+extern void *memzero(void *ptr, __kernel_size_t n);
+#endif
diff --git a/arch/nds32/include/asm/swab.h b/arch/nds32/include/asm/swab.h
new file mode 100644
index 000..e01a755
--- /dev/null
+++ b/arch/nds32/include/asm/swab.h
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __NDS32_SWAB_H__
+#define __NDS32_SWAB_H__
+
+#include 
+#include 
+
+static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
+{
+   __asm__("wsbh   %0, %0\n\t" /* word swap byte within halfword */
+   "rotri  %0, %0, #16\n"
+   :"=r"(x)
+   :"0"(x));
+   return x;
+}
+
+static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
+{
+   __asm__("wsbh   %0, %0\n"   /* word swap byte within halfword */
+   :"=r"(x)
+   :"0"(x));
+   return x;
+}
+
+#define __arch_swab32(x) ___arch__swab32(x)
+#define __arch_swab16(x) ___arch__swab16(x)
+
+#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
+#define __BYTEORDER_HAS_U64__
+#define __SWAB_64_THRU_32__
+#endif
+
+#endif /* __NDS32_SWAB_H__ */
diff --git a/arch/nds32/include/asm/uaccess.h b/arch/nds32/include/asm/uaccess.h
new file mode 100644
index 000..18a009f
--- /dev/null
+++ b/arch/nds32/include/asm/uaccess.h
@@ -0,0 +1,283 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef _ASMANDES_UACCESS_H
+#define _ASMANDES_UACCESS_H
+
+/*
+ * User space memory access functions
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define VERIFY_READ0
+#define VERIFY_WRITE   1
+
+#define __asmeq(x, y)  ".ifnc " x "," y " ; .err ; .endif\n\t"
+
+/*
+ * The exception table consists of pairs of addresses: the first is the
+ * address of an instruction that is allowed to fault, and the second is
+ * the address at which the program should continue.  No registers are
+ * modified, so it is entirely up to the continuation code to figure out
+ * what to do.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path.  This means when everything is well,
+ * we don't even have to jump over them.  Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+
+struct exception_table_entry {
+   unsigned long insn, fixup;
+};
+
+extern int fixup_exception(struct pt_regs *regs);
+
+#define KERNEL_DS  ((mm_segment_t) { ~0UL })
+#define USER_DS((mm_segment_t) {TASK_SIZE - 1})
+
+#define get_ds()   (KERNEL_DS)
+#define get_fs()   (current_thread_info()->addr_limit)
+#define user_addr_max  get_fs
+
+static inline void set_fs(mm_segment_t fs)
+{
+   current_thread_info()->addr_limit = fs;
+}
+
+#define segment_eq(a, b)((a) == (b))
+
+#define __range_ok(addr, size) (size <= 

[PATCH v4 17/36] nds32: VDSO support

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds VDSO support. The VDSO code is currently used for
sys_rt_sigreturn() and optimised gettimeofday() (using the SoC timer counter).

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/vdso.h  |   24 +++
 arch/nds32/include/asm/vdso_datapage.h |   36 
 arch/nds32/include/asm/vdso_timer_info.h   |   14 ++
 arch/nds32/kernel/vdso.c   |  233 
 arch/nds32/kernel/vdso/Makefile|   82 +
 arch/nds32/kernel/vdso/datapage.S  |   21 +++
 arch/nds32/kernel/vdso/gen_vdso_offsets.sh |   15 ++
 arch/nds32/kernel/vdso/gettimeofday.c  |  271 
 arch/nds32/kernel/vdso/note.S  |   11 ++
 arch/nds32/kernel/vdso/sigreturn.S |   19 ++
 arch/nds32/kernel/vdso/vdso.S  |   18 ++
 arch/nds32/kernel/vdso/vdso.lds.S  |   76 
 12 files changed, 820 insertions(+)
 create mode 100644 arch/nds32/include/asm/vdso.h
 create mode 100644 arch/nds32/include/asm/vdso_datapage.h
 create mode 100644 arch/nds32/include/asm/vdso_timer_info.h
 create mode 100644 arch/nds32/kernel/vdso.c
 create mode 100644 arch/nds32/kernel/vdso/Makefile
 create mode 100644 arch/nds32/kernel/vdso/datapage.S
 create mode 100755 arch/nds32/kernel/vdso/gen_vdso_offsets.sh
 create mode 100644 arch/nds32/kernel/vdso/gettimeofday.c
 create mode 100644 arch/nds32/kernel/vdso/note.S
 create mode 100644 arch/nds32/kernel/vdso/sigreturn.S
 create mode 100644 arch/nds32/kernel/vdso/vdso.S
 create mode 100644 arch/nds32/kernel/vdso/vdso.lds.S

diff --git a/arch/nds32/include/asm/vdso.h b/arch/nds32/include/asm/vdso.h
new file mode 100644
index 000..af2c6af
--- /dev/null
+++ b/arch/nds32/include/asm/vdso.h
@@ -0,0 +1,24 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright (C) 2005-2017 Andes Technology Corporation
+ */
+
+#ifndef __ASM_VDSO_H
+#define __ASM_VDSO_H
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+
+#include 
+
+#define VDSO_SYMBOL(base, name)
   \
+({\
+   (unsigned long)(vdso_offset_##name + (unsigned long)(base)); \
+})
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* __ASM_VDSO_H */
diff --git a/arch/nds32/include/asm/vdso_datapage.h 
b/arch/nds32/include/asm/vdso_datapage.h
new file mode 100644
index 000..79db5a1
--- /dev/null
+++ b/arch/nds32/include/asm/vdso_datapage.h
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2012 ARM Limited
+// Copyright (C) 2005-2017 Andes Technology Corporation
+#ifndef __ASM_VDSO_DATAPAGE_H
+#define __ASM_VDSO_DATAPAGE_H
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+
+struct vdso_data {
+   bool cycle_count_down;  /* timer cyclye counter is decrease with time */
+   u32 cycle_count_offset; /* offset of timer cycle counter register */
+   u32 seq_count;  /* sequence count - odd during updates */
+   u32 xtime_coarse_sec;   /* coarse time */
+   u32 xtime_coarse_nsec;
+
+   u32 wtm_clock_sec;  /* wall to monotonic offset */
+   u32 wtm_clock_nsec;
+   u32 xtime_clock_sec;/* CLOCK_REALTIME - seconds */
+   u32 cs_mult;/* clocksource multiplier */
+   u32 cs_shift;   /* Cycle to nanosecond divisor (power of two) */
+
+   u64 cs_cycle_last;  /* last cycle value */
+   u64 cs_mask;/* clocksource mask */
+
+   u64 xtime_clock_nsec;   /* CLOCK_REALTIME sub-ns base */
+   u32 tz_minuteswest; /* timezone info for gettimeofday(2) */
+   u32 tz_dsttime;
+};
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* __ASM_VDSO_DATAPAGE_H */
diff --git a/arch/nds32/include/asm/vdso_timer_info.h 
b/arch/nds32/include/asm/vdso_timer_info.h
new file mode 100644
index 000..50ba117
--- /dev/null
+++ b/arch/nds32/include/asm/vdso_timer_info.h
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+extern struct timer_info_t timer_info;
+#define EMPTY_VALUE ~(0UL)
+#define EMPTY_TIMER_MAPPING EMPTY_VALUE
+#define EMPTY_REG_OFFSET EMPTY_VALUE
+
+struct timer_info_t
+{
+   bool cycle_count_down;
+   unsigned long mapping_base;
+   unsigned long cycle_count_reg_offset;
+};
diff --git a/arch/nds32/kernel/vdso.c b/arch/nds32/kernel/vdso.c
new file mode 100644
index 000..2eb01f4
--- /dev/null
+++ b/arch/nds32/kernel/vdso.c
@@ -0,0 +1,233 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2012 ARM Limited
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 

[PATCH v4 18/36] nds32: Signal handling support

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds support for signal handling.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/uapi/asm/sigcontext.h |   60 ++
 arch/nds32/kernel/signal.c   |  337 ++
 2 files changed, 397 insertions(+)
 create mode 100644 arch/nds32/include/uapi/asm/sigcontext.h
 create mode 100644 arch/nds32/kernel/signal.c

diff --git a/arch/nds32/include/uapi/asm/sigcontext.h 
b/arch/nds32/include/uapi/asm/sigcontext.h
new file mode 100644
index 000..00567b2
--- /dev/null
+++ b/arch/nds32/include/uapi/asm/sigcontext.h
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef _ASMNDS32_SIGCONTEXT_H
+#define _ASMNDS32_SIGCONTEXT_H
+
+/*
+ * Signal context structure - contains all info to do with the state
+ * before the signal handler was invoked.  Note: only add new entries
+ * to the end of the structure.
+ */
+
+struct zol_struct {
+   unsigned long nds32_lc; /* $LC */
+   unsigned long nds32_le; /* $LE */
+   unsigned long nds32_lb; /* $LB */
+};
+
+struct sigcontext {
+   unsigned long trap_no;
+   unsigned long error_code;
+   unsigned long oldmask;
+   unsigned long nds32_r0;
+   unsigned long nds32_r1;
+   unsigned long nds32_r2;
+   unsigned long nds32_r3;
+   unsigned long nds32_r4;
+   unsigned long nds32_r5;
+   unsigned long nds32_r6;
+   unsigned long nds32_r7;
+   unsigned long nds32_r8;
+   unsigned long nds32_r9;
+   unsigned long nds32_r10;
+   unsigned long nds32_r11;
+   unsigned long nds32_r12;
+   unsigned long nds32_r13;
+   unsigned long nds32_r14;
+   unsigned long nds32_r15;
+   unsigned long nds32_r16;
+   unsigned long nds32_r17;
+   unsigned long nds32_r18;
+   unsigned long nds32_r19;
+   unsigned long nds32_r20;
+   unsigned long nds32_r21;
+   unsigned long nds32_r22;
+   unsigned long nds32_r23;
+   unsigned long nds32_r24;
+   unsigned long nds32_r25;
+   unsigned long nds32_fp; /* $r28 */
+   unsigned long nds32_gp; /* $r29 */
+   unsigned long nds32_lp; /* $r30 */
+   unsigned long nds32_sp; /* $r31 */
+   unsigned long nds32_ipc;
+   unsigned long fault_address;
+   unsigned long used_math_flag;
+   /* FPU Registers */
+   struct zol_struct zol;
+};
+
+#endif
diff --git a/arch/nds32/kernel/signal.c b/arch/nds32/kernel/signal.c
new file mode 100644
index 000..b6313dd
--- /dev/null
+++ b/arch/nds32/kernel/signal.c
@@ -0,0 +1,337 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+struct rt_sigframe {
+   struct siginfo info;
+   struct ucontext uc;
+};
+
+static int restore_sigframe(struct pt_regs *regs,
+   struct rt_sigframe __user * sf)
+{
+   sigset_t set;
+   int err;
+
+   err = __copy_from_user(, >uc.uc_sigmask, sizeof(set));
+   if (err == 0) {
+   set_current_blocked();
+   }
+
+   __get_user_error(regs->uregs[0], >uc.uc_mcontext.nds32_r0, err);
+   __get_user_error(regs->uregs[1], >uc.uc_mcontext.nds32_r1, err);
+   __get_user_error(regs->uregs[2], >uc.uc_mcontext.nds32_r2, err);
+   __get_user_error(regs->uregs[3], >uc.uc_mcontext.nds32_r3, err);
+   __get_user_error(regs->uregs[4], >uc.uc_mcontext.nds32_r4, err);
+   __get_user_error(regs->uregs[5], >uc.uc_mcontext.nds32_r5, err);
+   __get_user_error(regs->uregs[6], >uc.uc_mcontext.nds32_r6, err);
+   __get_user_error(regs->uregs[7], >uc.uc_mcontext.nds32_r7, err);
+   __get_user_error(regs->uregs[8], >uc.uc_mcontext.nds32_r8, err);
+   __get_user_error(regs->uregs[9], >uc.uc_mcontext.nds32_r9, err);
+   __get_user_error(regs->uregs[10], >uc.uc_mcontext.nds32_r10, err);
+   __get_user_error(regs->uregs[11], >uc.uc_mcontext.nds32_r11, err);
+   __get_user_error(regs->uregs[12], >uc.uc_mcontext.nds32_r12, err);
+   __get_user_error(regs->uregs[13], >uc.uc_mcontext.nds32_r13, err);
+   __get_user_error(regs->uregs[14], >uc.uc_mcontext.nds32_r14, err);
+   __get_user_error(regs->uregs[15], >uc.uc_mcontext.nds32_r15, err);
+   __get_user_error(regs->uregs[16], >uc.uc_mcontext.nds32_r16, err);
+   __get_user_error(regs->uregs[17], >uc.uc_mcontext.nds32_r17, err);
+   __get_user_error(regs->uregs[18], >uc.uc_mcontext.nds32_r18, err);
+   __get_user_error(regs->uregs[19], >uc.uc_mcontext.nds32_r19, err);
+   __get_user_error(regs->uregs[20], >uc.uc_mcontext.nds32_r20, err);
+   __get_user_error(regs->uregs[21], >uc.uc_mcontext.nds32_r21, err);
+   __get_user_error(regs->uregs[22], 

[PATCH v4 21/36] nds32: L2 cache support

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds L2 cache support.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/l2_cache.h |  142 +
 arch/nds32/kernel/atl2c.c |   64 +
 2 files changed, 206 insertions(+)
 create mode 100644 arch/nds32/include/asm/l2_cache.h
 create mode 100644 arch/nds32/kernel/atl2c.c

diff --git a/arch/nds32/include/asm/l2_cache.h 
b/arch/nds32/include/asm/l2_cache.h
new file mode 100644
index 000..7706dd0
--- /dev/null
+++ b/arch/nds32/include/asm/l2_cache.h
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef L2_CACHE_H
+#define L2_CACHE_H
+
+/* CCTL_CMD_OP */
+#define L2_CA_CONF_OFF 0x0
+#define L2_IF_CONF_OFF 0x4
+#define L2CC_SETUP_OFF 0x8
+#define L2CC_PROT_OFF  0xC
+#define L2CC_CTRL_OFF  0x10
+#define L2_INT_EN_OFF   0x20
+#define L2_STA_OFF  0x24
+#define RDERR_ADDR_OFF 0x28
+#define WRERR_ADDR_OFF 0x2c
+#define EVDPTERR_ADDR_OFF  0x30
+#define IMPL3ERR_ADDR_OFF  0x34
+#define L2_CNT0_CTRL_OFF0x40
+#define L2_EVNT_CNT0_OFF0x44
+#define L2_CNT1_CTRL_OFF0x48
+#define L2_EVNT_CNT1_OFF0x4c
+#define L2_CCTL_CMD_OFF0x60
+#define L2_CCTL_STATUS_OFF 0x64
+#define L2_LINE_TAG_OFF0x68
+#define L2_LINE_DPT_OFF0x70
+
+#define CCTL_CMD_L2_IX_INVAL0x0
+#define CCTL_CMD_L2_PA_INVAL0x1
+#define CCTL_CMD_L2_IX_WB   0x2
+#define CCTL_CMD_L2_PA_WB   0x3
+#define CCTL_CMD_L2_PA_WBINVAL  0x5
+#define CCTL_CMD_L2_SYNC0xa
+
+/* CCTL_CMD_TYPE */
+#define CCTL_SINGLE_CMD 0
+#define CCTL_BLOCK_CMD  0x10
+#define CCTL_ALL_CMD   0x10
+
+/**
+ * L2_CA_CONF (Cache architecture configuration)
+ */
+#define L2_CA_CONF_offL2SET0
+#define L2_CA_CONF_offL2WAY4
+#define L2_CA_CONF_offL2CLSZ8
+#define L2_CA_CONF_offL2DW 11
+#define L2_CA_CONF_offL2PT 14
+#define L2_CA_CONF_offL2VER16
+
+#define L2_CA_CONF_mskL2SET(0xFUL << L2_CA_CONF_offL2SET)
+#define L2_CA_CONF_mskL2WAY(0xFUL << L2_CA_CONF_offL2WAY)
+#define L2_CA_CONF_mskL2CLSZ(0x7UL << L2_CA_CONF_offL2CLSZ)
+#define L2_CA_CONF_mskL2DW (0x7UL << L2_CA_CONF_offL2DW)
+#define L2_CA_CONF_mskL2PT (0x3UL << L2_CA_CONF_offL2PT)
+#define L2_CA_CONF_mskL2VER(0xUL << L2_CA_CONF_offL2VER)
+
+/**
+ * L2CC_SETUP (L2CC Setup register)
+ */
+#define L2CC_SETUP_offPART  0
+#define L2CC_SETUP_mskPART  (0x3UL << L2CC_SETUP_offPART)
+#define L2CC_SETUP_offDDLATC4
+#define L2CC_SETUP_mskDDLATC(0x3UL << L2CC_SETUP_offDDLATC)
+#define L2CC_SETUP_offTDLATC8
+#define L2CC_SETUP_mskTDLATC(0x3UL << L2CC_SETUP_offTDLATC)
+
+/**
+ * L2CC_PROT (L2CC Protect register)
+ */
+#define L2CC_PROT_offMRWEN  31
+#define L2CC_PROT_mskMRWEN  (0x1UL << L2CC_PROT_offMRWEN)
+
+/**
+ * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n)
+ */
+#define L2CC_CTRL_offEN 31
+#define L2CC_CTRL_mskEN (0x1UL << L2CC_CTRL_offEN)
+
+/**
+ * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n)
+ */
+#define L2_CCTL_STATUS_offCMD_COMP  31
+#define L2_CCTL_STATUS_mskCMD_COMP  (0x1 << L2_CCTL_STATUS_offCMD_COMP)
+
+#ifndef __ASSEMBLY__
+extern void __iomem *atl2c_base;
+
+#include 
+#include 
+#include 
+
+#define L2C_R_REG(offset)   readl(atl2c_base + offset)
+#define L2C_W_REG(offset, value)writel(value, atl2c_base + offset)
+
+#define L2_CMD_RDY()\
+do{;}while((L2C_R_REG(L2_CCTL_STATUS_OFF) & 
L2_CCTL_STATUS_mskCMD_COMP) == 0)
+
+static inline unsigned long L2_CACHE_SET(void)
+{
+   return 64 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2SET) >>
+ L2_CA_CONF_offL2SET);
+}
+
+static inline unsigned long L2_CACHE_WAY(void)
+{
+   return 1 +
+   ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2WAY) >>
+ 

[PATCH v4 16/36] nds32: System calls handling

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds support for system calls.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/syscall.h |  188 ++
 arch/nds32/include/asm/syscalls.h|   13 +++
 arch/nds32/include/asm/unistd.h  |6 ++
 arch/nds32/include/uapi/asm/unistd.h |   12 +++
 arch/nds32/kernel/ex-scall.S |  106 +++
 arch/nds32/kernel/sys_nds32.c|   61 +++
 arch/nds32/kernel/syscall_table.c|   17 +++
 7 files changed, 403 insertions(+)
 create mode 100644 arch/nds32/include/asm/syscall.h
 create mode 100644 arch/nds32/include/asm/syscalls.h
 create mode 100644 arch/nds32/include/asm/unistd.h
 create mode 100644 arch/nds32/include/uapi/asm/unistd.h
 create mode 100644 arch/nds32/kernel/ex-scall.S
 create mode 100644 arch/nds32/kernel/sys_nds32.c
 create mode 100644 arch/nds32/kernel/syscall_table.c

diff --git a/arch/nds32/include/asm/syscall.h b/arch/nds32/include/asm/syscall.h
new file mode 100644
index 000..f7e5e86
--- /dev/null
+++ b/arch/nds32/include/asm/syscall.h
@@ -0,0 +1,188 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef _ASM_NDS32_SYSCALL_H
+#define _ASM_NDS32_SYSCALL_H   1
+
+#include 
+struct task_struct;
+struct pt_regs;
+
+/**
+ * syscall_get_nr - find what system call a task is executing
+ * @task:  task of interest, must be blocked
+ * @regs:  task_pt_regs() of @task
+ *
+ * If @task is executing a system call or is at system call
+ * tracing about to attempt one, returns the system call number.
+ * If @task is not executing a system call, i.e. it's blocked
+ * inside the kernel for a fault or signal, returns -1.
+ *
+ * Note this returns int even on 64-bit machines.  Only 32 bits of
+ * system call number can be meaningful.  If the actual arch value
+ * is 64 bits, this truncates to 32 bits so 0x means -1.
+ *
+ * It's only valid to call this when @task is known to be blocked.
+ */
+int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+   return regs->syscallno;
+}
+
+/**
+ * syscall_rollback - roll back registers after an aborted system call
+ * @task:  task of interest, must be in system call exit tracing
+ * @regs:  task_pt_regs() of @task
+ *
+ * It's only valid to call this when @task is stopped for system
+ * call exit tracing (due to TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT),
+ * after tracehook_report_syscall_entry() returned nonzero to prevent
+ * the system call from taking place.
+ *
+ * This rolls back the register state in @regs so it's as if the
+ * system call instruction was a no-op.  The registers containing
+ * the system call number and arguments are as they were before the
+ * system call instruction.  This may not be the same as what the
+ * register state looked like at system call entry tracing.
+ */
+void syscall_rollback(struct task_struct *task, struct pt_regs *regs)
+{
+   regs->uregs[0] = regs->orig_r0;
+}
+
+/**
+ * syscall_get_error - check result of traced system call
+ * @task:  task of interest, must be blocked
+ * @regs:  task_pt_regs() of @task
+ *
+ * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
+ *
+ * It's only valid to call this when @task is stopped for tracing on exit
+ * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
+ */
+long syscall_get_error(struct task_struct *task, struct pt_regs *regs)
+{
+   unsigned long error = regs->uregs[0];
+   return IS_ERR_VALUE(error) ? error : 0;
+}
+
+/**
+ * syscall_get_return_value - get the return value of a traced system call
+ * @task:  task of interest, must be blocked
+ * @regs:  task_pt_regs() of @task
+ *
+ * Returns the return value of the successful system call.
+ * This value is meaningless if syscall_get_error() returned nonzero.
+ *
+ * It's only valid to call this when @task is stopped for tracing on exit
+ * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
+ */
+long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
+{
+   return regs->uregs[0];
+}
+
+/**
+ * syscall_set_return_value - change the return value of a traced system call
+ * @task:  task of interest, must be blocked
+ * @regs:  task_pt_regs() of @task
+ * @error: negative error code, or zero to indicate success
+ * @val:   user return value if @error is zero
+ *
+ * This changes the results of the system call that user mode will see.
+ * If @error is zero, the user sees a successful system call with a
+ * return value of @val.  If @error is nonzero, it's a negated errno
+ * code; the user sees a failed system call with this errno code.
+ *
+ * It's only valid to call this when @task is stopped for tracing on exit
+ * from a system call, due to 

[PATCH v4 22/36] nds32: Loadable modules

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds support for loadable modules.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/module.h |   11 ++
 arch/nds32/kernel/module.c  |  286 +++
 2 files changed, 297 insertions(+)
 create mode 100644 arch/nds32/include/asm/module.h
 create mode 100644 arch/nds32/kernel/module.c

diff --git a/arch/nds32/include/asm/module.h b/arch/nds32/include/asm/module.h
new file mode 100644
index 000..16cf9c7
--- /dev/null
+++ b/arch/nds32/include/asm/module.h
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef _ASM_NDS32_MODULE_H
+#define _ASM_NDS32_MODULE_H
+
+#include 
+
+#define MODULE_ARCH_VERMAGIC   "NDS32v3"
+
+#endif /* _ASM_NDS32_MODULE_H */
diff --git a/arch/nds32/kernel/module.c b/arch/nds32/kernel/module.c
new file mode 100644
index 000..714a6d6
--- /dev/null
+++ b/arch/nds32/kernel/module.c
@@ -0,0 +1,286 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+
+#include 
+
+void *module_alloc(unsigned long size)
+{
+   return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
+   GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE,
+   __builtin_return_address(0));
+}
+
+void module_free(struct module *module, void *region)
+{
+   vfree(region);
+}
+
+int module_frob_arch_sections(Elf_Ehdr * hdr,
+ Elf_Shdr * sechdrs,
+ char *secstrings, struct module *mod)
+{
+   return 0;
+}
+
+void do_reloc16(unsigned int val, unsigned int *loc, unsigned int val_mask,
+   unsigned int val_shift, unsigned int loc_mask,
+   unsigned int partial_in_place, unsigned int swap)
+{
+   unsigned int tmp = 0, tmp2 = 0;
+
+   __asm__ __volatile__("\tlhi.bi\t%0, [%2], 0\n"
+"\tbeqz\t%3, 1f\n"
+"\twsbh\t%0, %1\n"
+"1:\n":"=r"(tmp):"0"(tmp), "r"(loc), "r"(swap)
+   );
+
+   tmp2 = tmp & loc_mask;
+   if (partial_in_place) {
+   tmp &= (!loc_mask);
+   tmp =
+   tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask);
+   } else {
+   tmp = tmp2 | ((val & val_mask) >> val_shift);
+   }
+
+   __asm__ __volatile__("\tbeqz\t%3, 2f\n"
+"\twsbh\t%0, %1\n"
+"2:\n"
+"\tshi.bi\t%0, [%2], 0\n":"=r"(tmp):"0"(tmp),
+"r"(loc), "r"(swap)
+   );
+}
+
+void do_reloc32(unsigned int val, unsigned int *loc, unsigned int val_mask,
+   unsigned int val_shift, unsigned int loc_mask,
+   unsigned int partial_in_place, unsigned int swap)
+{
+   unsigned int tmp = 0, tmp2 = 0;
+
+   __asm__ __volatile__("\tlmw.bi\t%0, [%2], %0, 0\n"
+"\tbeqz\t%3, 1f\n"
+"\twsbh\t%0, %1\n"
+"\trotri\t%0, %1, 16\n"
+"1:\n":"=r"(tmp):"0"(tmp), "r"(loc), "r"(swap)
+   );
+
+   tmp2 = tmp & loc_mask;
+   if (partial_in_place) {
+   tmp &= (!loc_mask);
+   tmp =
+   tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask);
+   } else {
+   tmp = tmp2 | ((val & val_mask) >> val_shift);
+   }
+
+   __asm__ __volatile__("\tbeqz\t%3, 2f\n"
+"\twsbh\t%0, %1\n"
+"\trotri\t%0, %1, 16\n"
+"2:\n"
+"\tsmw.bi\t%0, [%2], %0, 0\n":"=r"(tmp):"0"(tmp),
+"r"(loc), "r"(swap)
+   );
+}
+
+static inline int exceed_limit(int offset, unsigned int val_mask,
+  struct module *module, Elf32_Rela * rel,
+  unsigned int relindex, unsigned int reloc_order)
+{
+   int abs_off = offset < 0 ? ~offset : offset;
+
+   if (abs_off & (~val_mask)) {
+   pr_err("\n%s: relocation type %d out of range.\n"
+  "please rebuild the kernel module with gcc option 
\"-Wa,-mno-small-text\".\n",
+  module->name, ELF32_R_TYPE(rel->r_info));
+   pr_err("section %d reloc %d offset 0x%x relative 0x%x.\n",
+  relindex, reloc_order, rel->r_offset, offset);
+   return true;
+   }
+   return false;
+}
+
+#ifdef __NDS32_EL__
+#define NEED_SWAP 1
+#else
+#define NEED_SWAP 0
+#endif
+
+int
+apply_relocate_add(Elf32_Shdr * sechdrs, const char *strtab,
+  unsigned int symindex, unsigned int relindex,
+  

[PATCH v4 23/36] nds32: Generic timers support

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds support for timer.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
Reviewed-by: Linus Walleij 
---
 arch/nds32/kernel/time.c |   11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 arch/nds32/kernel/time.c

diff --git a/arch/nds32/kernel/time.c b/arch/nds32/kernel/time.c
new file mode 100644
index 000..ac9d78c
--- /dev/null
+++ b/arch/nds32/kernel/time.c
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+
+void __init time_init(void)
+{
+   of_clk_init(NULL);
+   timer_probe();
+}
-- 
1.7.9.5



[PATCH v4 20/36] nds32: Debugging support

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds ptrace support.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/uapi/asm/ptrace.h |   25 +++
 arch/nds32/kernel/ptrace.c   |  311 ++
 2 files changed, 336 insertions(+)
 create mode 100644 arch/nds32/include/uapi/asm/ptrace.h
 create mode 100644 arch/nds32/kernel/ptrace.c

diff --git a/arch/nds32/include/uapi/asm/ptrace.h 
b/arch/nds32/include/uapi/asm/ptrace.h
new file mode 100644
index 000..358c99e
--- /dev/null
+++ b/arch/nds32/include/uapi/asm/ptrace.h
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __UAPI_ASM_NDS32_PTRACE_H
+#define __UAPI_ASM_NDS32_PTRACE_H
+
+#ifndef __ASSEMBLY__
+
+/*
+ * User structures for general purpose register.
+ */
+struct user_pt_regs {
+   long uregs[26];
+   long fp;
+   long gp;
+   long lp;
+   long sp;
+   long ipc;
+   long lb;
+   long le;
+   long lc;
+   long syscallno;
+};
+#endif
+#endif
diff --git a/arch/nds32/kernel/ptrace.c b/arch/nds32/kernel/ptrace.c
new file mode 100644
index 000..0e18564
--- /dev/null
+++ b/arch/nds32/kernel/ptrace.c
@@ -0,0 +1,311 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+enum nds32_regset {
+   REGSET_GPR,
+};
+
+static int gpr_get(struct task_struct *target,
+  const struct user_regset *regset,
+  unsigned int pos, unsigned int count,
+  void *kbuf, void __user * ubuf)
+{
+   struct user_pt_regs *uregs = _pt_regs(target)->user_regs;
+   return user_regset_copyout(, , , , uregs, 0, -1);
+}
+
+static int gpr_set(struct task_struct *target, const struct user_regset 
*regset,
+  unsigned int pos, unsigned int count,
+  const void *kbuf, const void __user * ubuf)
+{
+   int err;
+   struct user_pt_regs newregs = task_pt_regs(target)->user_regs;
+
+   err = user_regset_copyin(, , , , , 0, -1);
+   if (err)
+   return err;
+
+   task_pt_regs(target)->user_regs = newregs;
+   return 0;
+}
+
+static const struct user_regset nds32_regsets[] = {
+   [REGSET_GPR] = {
+   .core_note_type = NT_PRSTATUS,
+   .n = sizeof(struct user_pt_regs) / sizeof(u32),
+   .size = sizeof(u32),
+   .align = sizeof(u32),
+   .get = gpr_get,
+   .set = gpr_set}
+};
+
+static const struct user_regset_view nds32_user_view = {
+   .name = "nds32",.e_machine = EM_NDS32,
+   .regsets = nds32_regsets,.n = ARRAY_SIZE(nds32_regsets)
+};
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+   return _user_view;
+}
+
+/* get_user_reg()
+ *
+ * This routine will get a word off of the processes privileged stack.
+ * the offset is how far from the base addr as stored in the THREAD.
+ * this routine assumes that all the privileged stacks are in our
+ * data space.
+ */
+static inline unsigned int get_user_reg(struct task_struct *task, int offset)
+{
+   return task_pt_regs(task)->uregs[offset];
+}
+
+/* put_user_reg()
+ *
+ * this routine will put a word on the processes privileged stack.
+ * the offset is how far from the base addr as stored in the THREAD.
+ * this routine assumes that all the privileged stacks are in our
+ * data space.
+ */
+static inline int put_user_reg(struct task_struct *task, int offset, long data)
+{
+   struct pt_regs newregs, *regs = task_pt_regs(task);
+   int ret = -EINVAL;
+
+   newregs = *regs;
+   newregs.uregs[offset] = data;
+
+   if (valid_user_regs()) {
+   regs->uregs[offset] = data;
+   ret = 0;
+   }
+
+   return ret;
+}
+
+/*
+ * Called by kernel/ptrace.c when detaching..
+ *
+ * Make sure the single step bit is not set.
+ */
+void ptrace_disable(struct task_struct *child)
+{
+   user_disable_single_step(child);
+}
+
+static void fill_sigtrap_info(struct task_struct *tsk,
+ struct pt_regs *regs,
+ int error_code, int si_code, struct siginfo *info)
+{
+   tsk->thread.trap_no = ENTRY_DEBUG_RELATED;
+   tsk->thread.error_code = error_code;
+
+   memset(info, 0, sizeof(*info));
+   info->si_signo = SIGTRAP;
+   info->si_code = si_code;
+   info->si_addr = (void __user *)instruction_pointer(regs);
+}
+
+void user_single_step_siginfo(struct task_struct *tsk,
+ struct pt_regs *regs, struct siginfo *info)
+{
+   fill_sigtrap_info(tsk, regs, 0, TRAP_BRKPT, info);
+}
+
+/*
+ * 

[PATCH v4 24/36] nds32: Device tree support

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds support for device tree.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/boot/dts/Makefile  |8 +
 arch/nds32/boot/dts/ae3xx.dts |   65 +
 arch/nds32/kernel/devtree.c   |   19 
 3 files changed, 92 insertions(+)
 create mode 100644 arch/nds32/boot/dts/Makefile
 create mode 100644 arch/nds32/boot/dts/ae3xx.dts
 create mode 100644 arch/nds32/kernel/devtree.c

diff --git a/arch/nds32/boot/dts/Makefile b/arch/nds32/boot/dts/Makefile
new file mode 100644
index 000..d31faa8
--- /dev/null
+++ b/arch/nds32/boot/dts/Makefile
@@ -0,0 +1,8 @@
+ifneq '$(CONFIG_NDS32_BUILTIN_DTB)' '""'
+BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_NDS32_BUILTIN_DTB)).dtb.o
+else
+BUILTIN_DTB :=
+endif
+obj-$(CONFIG_OF) += $(BUILTIN_DTB)
+
+clean-files := *.dtb *.dtb.S
diff --git a/arch/nds32/boot/dts/ae3xx.dts b/arch/nds32/boot/dts/ae3xx.dts
new file mode 100644
index 000..0ef2c44
--- /dev/null
+++ b/arch/nds32/boot/dts/ae3xx.dts
@@ -0,0 +1,65 @@
+/dts-v1/;
+/ {
+   compatible = "andestech,ae3xx";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   interrupt-parent = <>;
+
+   chosen {
+   stdout-path = 
+   };
+
+   memory@0 {
+   device_type = "memory";
+   reg = <0x 0x4000>;
+   };
+
+   cpus {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   cpu@0 {
+   device_type = "cpu";
+   compatible = "andestech,n13", "andestech,nds32v3";
+   reg = <0>;
+   clock-frequency = <6000>;
+   };
+   };
+
+   apb: clk@0 {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <3000>;
+   };
+
+
+   intc: interrupt-controller {
+   compatible = "andestech,ativic32";
+   #interrupt-cells = <1>;
+   interrupt-controller;
+   };
+
+   serial0: serial@f030 {
+   compatible = "andestech,uart16550", "ns16550a";
+   reg = <0xf030 0x1000>;
+   interrupts = <8>;
+   clock-frequency = <14745600>;
+   reg-shift = <2>;
+   reg-offset = <32>;
+   no-loopback-test = <1>;
+   };
+
+   timer0: timer@f040 {
+   compatible = "andestech,atcpit100";
+   reg = <0xf040 0x1000>;
+   interrupts = <2>;
+   clocks = <>;
+   clock-names = "PCLK";
+   };
+
+   mac0: mac@e010 {
+   compatible = "andestech,atmac100";
+   reg = <0xe010 0x1000>;
+   interrupts = <18>;
+   };
+
+};
diff --git a/arch/nds32/kernel/devtree.c b/arch/nds32/kernel/devtree.c
new file mode 100644
index 000..bdce0fe
--- /dev/null
+++ b/arch/nds32/kernel/devtree.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+
+void __init early_init_devtree(void *params)
+{
+   if (!params || !early_init_dt_scan(params)) {
+   pr_crit("\n"
+   "Error: invalid device tree blob at (virtual address 
0x%p)\n"
+   "\nPlease check your bootloader.", params);
+
+   BUG_ON(1);
+   }
+
+   dump_stack_set_arch_desc("%s (DT)", of_flat_dt_get_machine_name());
+}
-- 
1.7.9.5



[PATCH v4 25/36] nds32: Miscellaneous header files

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch introduces some miscellaneous header files.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/delay.h  |   38 +++
 arch/nds32/include/asm/linkage.h|   11 +
 arch/nds32/include/uapi/asm/byteorder.h |   13 +++
 3 files changed, 62 insertions(+)
 create mode 100644 arch/nds32/include/asm/delay.h
 create mode 100644 arch/nds32/include/asm/linkage.h
 create mode 100644 arch/nds32/include/uapi/asm/byteorder.h

diff --git a/arch/nds32/include/asm/delay.h b/arch/nds32/include/asm/delay.h
new file mode 100644
index 000..1852a4e
--- /dev/null
+++ b/arch/nds32/include/asm/delay.h
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __NDS32_DELAY_H__
+#define __NDS32_DELAY_H__
+
+#include 
+
+static inline void __delay(unsigned long loops)
+{
+   __asm__ __volatile__(".align 2\n"
+"1:\n"
+"\taddi\t%0, %0, -1\n"
+"\tbgtz\t%0, 1b\n"
+:"=r"(loops)
+:"0"(loops));
+}
+
+static inline void __udelay(unsigned long usecs, unsigned long lpj)
+{
+   usecs *= (unsigned long)(((0x8000ULL / (50 / HZ)) +
+ 0x8000ULL) >> 32);
+   usecs = (unsigned long)(((unsigned long long)usecs * lpj) >> 32);
+   __delay(usecs);
+}
+
+#define udelay(usecs) __udelay((usecs), loops_per_jiffy)
+
+/* make sure "usecs *= ..." in udelay do not overflow. */
+#if HZ >= 1000
+#define MAX_UDELAY_MS  1
+#elif HZ <= 200
+#define MAX_UDELAY_MS  5
+#else
+#define MAX_UDELAY_MS  (1000 / HZ)
+#endif
+
+#endif
diff --git a/arch/nds32/include/asm/linkage.h b/arch/nds32/include/asm/linkage.h
new file mode 100644
index 000..e708c8b
--- /dev/null
+++ b/arch/nds32/include/asm/linkage.h
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_LINKAGE_H
+#define __ASM_LINKAGE_H
+
+/* This file is required by include/linux/linkage.h */
+#define __ALIGN .align 2
+#define __ALIGN_STR ".align 2"
+
+#endif
diff --git a/arch/nds32/include/uapi/asm/byteorder.h 
b/arch/nds32/include/uapi/asm/byteorder.h
new file mode 100644
index 000..a23f6f3a
--- /dev/null
+++ b/arch/nds32/include/uapi/asm/byteorder.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __NDS32_BYTEORDER_H__
+#define __NDS32_BYTEORDER_H__
+
+#ifdef __NDS32_EB__
+#include 
+#else
+#include 
+#endif
+
+#endif /* __NDS32_BYTEORDER_H__ */
-- 
1.7.9.5



[PATCH v4 26/36] nds32: defconfig

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds nds32 defconfig.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/configs/defconfig |  108 ++
 1 file changed, 108 insertions(+)
 create mode 100644 arch/nds32/configs/defconfig

diff --git a/arch/nds32/configs/defconfig b/arch/nds32/configs/defconfig
new file mode 100644
index 000..4d79d2db
--- /dev/null
+++ b/arch/nds32/configs/defconfig
@@ -0,0 +1,108 @@
+CONFIG_CROSS_COMPILE="nds32le-linux-"
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_USER_NS=y
+CONFIG_RELAY=y
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_KALLSYMS_ALL=y
+CONFIG_PROFILING=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_CACHE_L2 is not set
+CONFIG_VMSPLIT_3G_OPT=y
+CONFIG_PREEMPT=y
+# CONFIG_COMPACTION is not set
+CONFIG_HZ_100=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_BLK_DEV is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NET_CADENCE is not set
+# CONFIG_NET_VENDOR_BROADCOM is not set
+CONFIG_FTMAC100=y
+# CONFIG_NET_VENDOR_INTEL is not set
+# CONFIG_NET_VENDOR_MARVELL is not set
+# CONFIG_NET_VENDOR_MICREL is not set
+# CONFIG_NET_VENDOR_NATSEMI is not set
+# CONFIG_NET_VENDOR_SEEQ is not set
+# CONFIG_NET_VENDOR_STMICRO is not set
+# CONFIG_NET_VENDOR_WIZNET is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_SERIO is not set
+CONFIG_VT_HW_CONSOLE_BINDING=y
+CONFIG_SERIAL_8250=y
+# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=3
+CONFIG_SERIAL_8250_RUNTIME_UARTS=3
+CONFIG_SERIAL_OF_PLATFORM=y
+# CONFIG_HW_RANDOM is not set
+# CONFIG_HWMON is not set
+# CONFIG_RC_CORE is not set
+# CONFIG_VGA_CONSOLE is not set
+# CONFIG_HID_A4TECH is not set
+# CONFIG_HID_APPLE is not set
+# CONFIG_HID_BELKIN is not set
+# CONFIG_HID_CHERRY is not set
+# CONFIG_HID_CHICONY is not set
+# CONFIG_HID_CYPRESS is not set
+# CONFIG_HID_EZKEY is not set
+# CONFIG_HID_ITE is not set
+# CONFIG_HID_KENSINGTON is not set
+# CONFIG_HID_LOGITECH is not set
+# CONFIG_HID_MICROSOFT is not set
+# CONFIG_HID_MONTEREY is not set
+# CONFIG_USB_SUPPORT is not set
+CONFIG_TIMER_ATCPIT100=y
+CONFIG_GENERIC_PHY=y
+CONFIG_EXT4_FS=y
+CONFIG_EXT4_FS_POSIX_ACL=y
+CONFIG_EXT4_FS_SECURITY=y
+CONFIG_EXT4_ENCRYPTION=y
+CONFIG_FUSE_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_TMPFS=y
+CONFIG_TMPFS_POSIX_ACL=y
+CONFIG_CONFIGFS_FS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3_ACL=y
+CONFIG_NFS_V4=y
+CONFIG_NFS_V4_1=y
+CONFIG_NFS_USE_LEGACY_DNS=y
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_INFO_DWARF4=y
+CONFIG_GDB_SCRIPTS=y
+CONFIG_READABLE_ASM=y
+CONFIG_HEADERS_CHECK=y
+CONFIG_DEBUG_SECTION_MISMATCH=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_DEBUG_KERNEL=y
+CONFIG_PANIC_ON_OOPS=y
+# CONFIG_SCHED_DEBUG is not set
+# CONFIG_DEBUG_PREEMPT is not set
+CONFIG_STACKTRACE=y
+CONFIG_RCU_CPU_STALL_TIMEOUT=300
+# CONFIG_CRYPTO_HW is not set
-- 
1.7.9.5



[PATCH v4 27/36] nds32: Build infrastructure

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds Makefile, Kconfig and vmlinux.lds.S files required for building
an nds32 kernel.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/Kconfig |  108 
 arch/nds32/Kconfig.cpu |  161 
 arch/nds32/Makefile|   66 +++
 arch/nds32/boot/Makefile   |   15 
 arch/nds32/include/asm/Kbuild  |   53 
 arch/nds32/include/uapi/asm/Kbuild |   28 +++
 arch/nds32/kernel/Makefile |   23 ++
 arch/nds32/kernel/vmlinux.lds.S|   57 +
 arch/nds32/mm/Makefile |7 ++
 9 files changed, 518 insertions(+)
 create mode 100644 arch/nds32/Kconfig
 create mode 100644 arch/nds32/Kconfig.cpu
 create mode 100644 arch/nds32/Makefile
 create mode 100644 arch/nds32/boot/Makefile
 create mode 100644 arch/nds32/include/asm/Kbuild
 create mode 100644 arch/nds32/include/uapi/asm/Kbuild
 create mode 100644 arch/nds32/kernel/Makefile
 create mode 100644 arch/nds32/kernel/vmlinux.lds.S
 create mode 100644 arch/nds32/mm/Makefile

diff --git a/arch/nds32/Kconfig b/arch/nds32/Kconfig
new file mode 100644
index 000..c83506e
--- /dev/null
+++ b/arch/nds32/Kconfig
@@ -0,0 +1,108 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config NDS32
+def_bool y
+   select ARCH_HAS_RAW_COPY_USER
+   select ARCH_WANT_FRAME_POINTERS if FTRACE
+   select ARCH_WANT_IPC_PARSE_VERSION
+   select CLKSRC_MMIO
+   select CLONE_BACKWARDS
+   select COMMON_CLK
+   select TIMER_OF
+   select FRAME_POINTER
+   select GENERIC_ATOMIC64
+   select GENERIC_CPU_DEVICES
+   select GENERIC_CLOCKEVENTS
+   select GENERIC_IRQ_CHIP
+   select GENERIC_IRQ_PROBE
+   select GENERIC_IRQ_SHOW
+   select GENERIC_STRNCPY_FROM_USER
+   select GENERIC_STRNLEN_USER
+   select GENERIC_TIME_VSYSCALL
+   select HANDLE_DOMAIN_IRQ
+   select HAVE_ARCH_TRACEHOOK
+   select HAVE_DEBUG_KMEMLEAK
+   select HAVE_MEMBLOCK
+   select HAVE_REGS_AND_STACK_ACCESS_API
+   select IRQ_DOMAIN
+   select LOCKDEP_SUPPORT
+   select MODULES_USE_ELF_RELA
+   select OF
+   select OF_EARLY_FLATTREE
+   select NO_BOOTMEM
+   select NO_IOPORT_MAP
+   select RTC_LIB
+   select THREAD_INFO_IN_TASK
+   help
+ Andes(nds32) Linux support.
+
+config GENERIC_CALIBRATE_DELAY
+   def_bool n
+
+config GENERIC_CSUM
+def_bool y
+
+config GENERIC_HWEIGHT
+def_bool y
+
+config GENERIC_LOCKBREAK
+def_bool y
+   depends on PREEMPT
+
+config RWSEM_GENERIC_SPINLOCK
+   def_bool y
+
+config TRACE_IRQFLAGS_SUPPORT
+   def_bool y
+
+config STACKTRACE_SUPPORT
+def_bool y
+
+config FIX_EARLYCON_MEM
+   def_bool y
+
+config PGTABLE_LEVELS
+   default 2
+
+source "init/Kconfig"
+
+menu "System Type"
+source "arch/nds32/Kconfig.cpu"
+config NR_CPUS
+   int
+   default 1
+
+config MMU
+def_bool y
+
+config NDS32_BUILTIN_DTB
+string "Builtin DTB"
+default ""
+   help
+ User can use it to specify the dts of the SoC
+endmenu
+
+menu "Kernel Features"
+source "kernel/Kconfig.preempt"
+source "mm/Kconfig"
+source "kernel/Kconfig.hz"
+endmenu
+
+menu "Executable file formats"
+source "fs/Kconfig.binfmt"
+endmenu
+
+source "net/Kconfig"
+source "drivers/Kconfig"
+source "fs/Kconfig"
+
+menu "Kernel hacking"
+source "lib/Kconfig.debug"
+endmenu
+
+source "security/Kconfig"
+source "crypto/Kconfig"
+source "lib/Kconfig"
diff --git a/arch/nds32/Kconfig.cpu b/arch/nds32/Kconfig.cpu
new file mode 100644
index 000..6c9fbdc
--- /dev/null
+++ b/arch/nds32/Kconfig.cpu
@@ -0,0 +1,161 @@
+comment "Processor Features"
+
+config CPU_BIG_ENDIAN
+   bool "Big endian"
+
+config CPU_LITTLE_ENDIAN
+def_bool !CPU_BIG_ENDIAN
+
+config HWZOL
+   bool "hardware zero overhead loop support"
+   depends on CPU_D10 || CPU_D15
+   default n
+   help
+ A set of Zero-Overhead Loop mechanism is provided to reduce the
+ instruction fetch and execution overhead of loop-control instructions.
+ It will save 3 registers($LB, $LC, $LE) for context saving if say Y.
+ You don't need to save these registers if you can make sure your user
+ program doesn't use these registers.
+
+ If unsure, say N.
+
+config CPU_CACHE_ALIASING
+   bool "Aliasing cache"
+   depends on CPU_N10 || CPU_D10 || CPU_N13 || CPU_V3
+   default y
+   help
+ If this CPU is using VIPT data cache and its cache way size is larger
+ than page size, say Y. If it is using PIPT data cache, say N.
+
+ If unsure, say Y.
+
+choice
+   prompt "CPU type"
+   default CPU_V3

[PATCH v4 28/36] MAINTAINERS: Add nds32

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

Signed-off-by: Greentime Hu 
---
 MAINTAINERS |   11 +++
 1 file changed, 11 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2f4e462..20284c8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -857,6 +857,17 @@ X: drivers/iio/*/adjd*
 F: drivers/staging/iio/*/ad*
 F: drivers/staging/iio/trigger/iio-trig-bfin-timer.c
 
+ANDES ARCHITECTURE
+M: Greentime Hu 
+M: Vincent Chen 
+T: git https://github.com/andestech/linux.git
+S: Supported
+F: arch/nds32
+F: 
Documentation/devicetree/bindings/interrupt-controller/andestech,ativic32.txt
+F: Documentation/devicetree/bindings/nds32
+K: nds32
+N: nds32
+
 ANDROID CONFIG FRAGMENTS
 M: Rob Herring 
 S: Supported
-- 
1.7.9.5



[PATCH v4 30/36] dt-bindings: nds32 SoC Bindings

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds nds32 SoC(AE3XX and AG101P) binding documents.

Signed-off-by: Greentime Hu 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/nds32/andestech-boards |   40 
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nds32/andestech-boards

diff --git a/Documentation/devicetree/bindings/nds32/andestech-boards 
b/Documentation/devicetree/bindings/nds32/andestech-boards
new file mode 100644
index 000..f5d7569
--- /dev/null
+++ b/Documentation/devicetree/bindings/nds32/andestech-boards
@@ -0,0 +1,40 @@
+Andestech(nds32) AE3XX Platform
+-
+The AE3XX prototype demonstrates the AE3XX example platform on the FPGA. It
+is composed of one Andestech(nds32) processor and AE3XX.
+
+Required properties (in root node):
+- compatible = "andestech,ae3xx";
+
+Example:
+/dts-v1/;
+/ {
+   compatible = "andestech,ae3xx";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   interrupt-parent = <>;
+};
+
+Andestech(nds32) AG101P Platform
+-
+AG101P is a generic SoC Platform IP that works with any of Andestech(nds32)
+processors to provide a cost-effective and high performance solution for
+majority of embedded systems in variety of application domains. Users may
+simply attach their IP on one of the system buses together with certain glue
+logics to complete a SoC solution for a specific application. With
+comprehensive simulation and design environments, users may evaluate the
+system performance of their applications and track bugs of their designs
+efficiently. The optional hardware development platform further provides real
+system environment for early prototyping and software/hardware co-development.
+
+Required properties (in root node):
+   compatible = "andestech,ag101p";
+
+Example:
+/dts-v1/;
+/ {
+   compatible = "andestech,ag101p";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   interrupt-parent = <>;
+};
-- 
1.7.9.5



[PATCH v4 32/36] irqchip: Andestech Internal Vector Interrupt Controller driver

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds the Andestech Internal Vector Interrupt Controller
driver. You can find the spec here. Ch4.9 of AndeStar SPA V3 Manual.
http://www.andestech.com/product.php?cls=9

Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
Reviewed-by: Marc Zyngier 
---
 drivers/irqchip/Makefile   |1 +
 drivers/irqchip/irq-ativic32.c |  107 
 2 files changed, 108 insertions(+)
 create mode 100644 drivers/irqchip/irq-ativic32.c

diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index b842dfd..201ca9f 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -80,3 +80,4 @@ obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o 
irq-aspeed-i2c-ic.o
 obj-$(CONFIG_STM32_EXTI)   += irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)+= qcom-irq-combiner.o
 obj-$(CONFIG_IRQ_UNIPHIER_AIDET)   += irq-uniphier-aidet.o
+obj-$(CONFIG_NDS32)+= irq-ativic32.o
diff --git a/drivers/irqchip/irq-ativic32.c b/drivers/irqchip/irq-ativic32.c
new file mode 100644
index 000..f69a858
--- /dev/null
+++ b/drivers/irqchip/irq-ativic32.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static void ativic32_ack_irq(struct irq_data *data)
+{
+   __nds32__mtsr_dsb(BIT(data->hwirq), NDS32_SR_INT_PEND2);
+}
+
+static void ativic32_mask_irq(struct irq_data *data)
+{
+   unsigned long int_mask2 = __nds32__mfsr(NDS32_SR_INT_MASK2);
+   __nds32__mtsr_dsb(int_mask2 & (~(BIT(data->hwirq))), 
NDS32_SR_INT_MASK2);
+}
+
+static void ativic32_unmask_irq(struct irq_data *data)
+{
+   unsigned long int_mask2 = __nds32__mfsr(NDS32_SR_INT_MASK2);
+   __nds32__mtsr_dsb(int_mask2 | (BIT(data->hwirq)), NDS32_SR_INT_MASK2);
+}
+
+static struct irq_chip ativic32_chip = {
+   .name = "ativic32",
+   .irq_ack = ativic32_ack_irq,
+   .irq_mask = ativic32_mask_irq,
+   .irq_unmask = ativic32_unmask_irq,
+};
+
+static unsigned int __initdata nivic_map[6] = { 6, 2, 10, 16, 24, 32 };
+
+static struct irq_domain *root_domain;
+static int ativic32_irq_domain_map(struct irq_domain *id, unsigned int virq,
+ irq_hw_number_t hw)
+{
+
+   unsigned long int_trigger_type;
+   u32 type;
+   struct irq_data *irq_data;
+   int_trigger_type = __nds32__mfsr(NDS32_SR_INT_TRIGGER);
+   irq_data = irq_get_irq_data(virq);
+   if (!irq_data)
+   return -EINVAL;
+
+   if (int_trigger_type & (BIT(hw))) {
+   irq_set_chip_and_handler(virq, _chip, handle_edge_irq);
+   type = IRQ_TYPE_EDGE_RISING;
+   } else {
+   irq_set_chip_and_handler(virq, _chip, 
handle_level_irq);
+   type = IRQ_TYPE_LEVEL_HIGH;
+   }
+
+   irqd_set_trigger_type(irq_data, type);
+   return 0;
+}
+
+static struct irq_domain_ops ativic32_ops = {
+   .map = ativic32_irq_domain_map,
+   .xlate = irq_domain_xlate_onecell
+};
+
+static irq_hw_number_t get_intr_src(void)
+{
+   return ((__nds32__mfsr(NDS32_SR_ITYPE) & ITYPE_mskVECTOR) >> 
ITYPE_offVECTOR)
+   - NDS32_VECTOR_offINTERRUPT;
+}
+
+asmlinkage void asm_do_IRQ(struct pt_regs *regs)
+{
+   irq_hw_number_t hwirq = get_intr_src();
+   handle_domain_irq(root_domain, hwirq, regs);
+}
+
+int __init ativic32_init_irq(struct device_node *node, struct device_node 
*parent)
+{
+   unsigned long int_vec_base, nivic, nr_ints;
+
+   if (WARN(parent, "non-root ativic32 are not supported"))
+   return -EINVAL;
+
+   int_vec_base = __nds32__mfsr(NDS32_SR_IVB);
+
+   if (((int_vec_base & IVB_mskIVIC_VER) >> IVB_offIVIC_VER) == 0)
+   panic("Unable to use atcivic32 for this cpu.\n");
+
+   nivic = (int_vec_base & IVB_mskNIVIC) >> IVB_offNIVIC;
+   if (nivic >= ARRAY_SIZE(nivic_map))
+   panic("The number of input for ativic32 is not supported.\n");
+
+   nr_ints = nivic_map[nivic];
+
+   root_domain = irq_domain_add_linear(node, nr_ints,
+   _ops, NULL);
+
+   if (!root_domain)
+   panic("%s: unable to create IRQ domain\n", node->full_name);
+
+   return 0;
+}
+IRQCHIP_DECLARE(ativic32, "andestech,ativic32", ativic32_init_irq);
-- 
1.7.9.5



[PATCH v4 31/36] dt-bindings: interrupt-controller: Andestech Internal Vector Interrupt Controller

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds an irqchip driver document for the Andestech Internal Vector
Interrupt Controller.

Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
Reviewed-by: Rob Herring 
---
 .../interrupt-controller/andestech,ativic32.txt|   19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/interrupt-controller/andestech,ativic32.txt

diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/andestech,ativic32.txt 
b/Documentation/devicetree/bindings/interrupt-controller/andestech,ativic32.txt
new file mode 100644
index 000..f4b4193
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/interrupt-controller/andestech,ativic32.txt
@@ -0,0 +1,19 @@
+* Andestech Internal Vector Interrupt Controller
+
+The Internal Vector Interrupt Controller (IVIC) is a basic interrupt controller
+suitable for a simpler SoC platform not requiring a more sophisticated and
+bigger External Vector Interrupt Controller.
+
+
+Main node required properties:
+
+- compatible : should at least contain  "andestech,ativic32".
+- interrupt-controller : Identifies the node as an interrupt controller
+- #interrupt-cells: 1 cells and refer to interrupt-controller/interrupts
+
+Examples:
+   intc: interrupt-controller {
+   compatible = "andestech,ativic32";
+   #interrupt-cells = <1>;
+   interrupt-controller;
+   };
-- 
1.7.9.5



[PATCH v4 34/36] clocksource/drivers/atcpit100: Add andestech atcpit100 timer

2017-12-17 Thread Greentime Hu
From: Rick Chen 

ATCPIT100 is often used on the Andes architecture,
This timer provide 4 PIT channels. Each PIT channel is a
multi-function timer, can be configured as 32,16,8 bit timers
or PWM as well.

For system timer it will set channel 1 32-bit timer0 as clock
source and count downwards until underflow and restart again.

It also set channel 0 32-bit timer0 as clock event and count
downwards until condition match. It will generate an interrupt
for handling periodically.

Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
Reviewed-by: Linus Walleij 
---
 drivers/clocksource/Kconfig   |7 +
 drivers/clocksource/Makefile  |1 +
 drivers/clocksource/timer-atcpit100.c |  255 +
 3 files changed, 263 insertions(+)
 create mode 100644 drivers/clocksource/timer-atcpit100.c

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index cc60620..5bdf92c 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -615,4 +615,11 @@ config CLKSRC_ST_LPC
  Enable this option to use the Low Power controller timer
  as clocksource.
 
+config TIMER_ATCPIT100
+   bool "Clocksource for AE3XX platform"
+   depends on NDS32 || COMPILE_TEST
+   depends on HAS_IOMEM
+   help
+ This option enables support for the Andestech AE3XX platform timers.
+
 endmenu
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 72711f1..74efe5f 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -75,3 +75,4 @@ obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o
 obj-$(CONFIG_H8300_TPU)+= h8300_tpu.o
 obj-$(CONFIG_CLKSRC_ST_LPC)+= clksrc_st_lpc.o
 obj-$(CONFIG_X86_NUMACHIP) += numachip.o
+obj-$(CONFIG_TIMER_ATCPIT100)  += timer-atcpit100.o
diff --git a/drivers/clocksource/timer-atcpit100.c 
b/drivers/clocksource/timer-atcpit100.c
new file mode 100644
index 000..0077fdb
--- /dev/null
+++ b/drivers/clocksource/timer-atcpit100.c
@@ -0,0 +1,255 @@
+/*
+ *  Andestech ATCPIT100 Timer Device Driver Implementation
+ *
+ * Copyright (C) 2017 Andes Technology Corporation
+ * Rick Chen, Andes Technology Corporation 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "timer-of.h"
+
+/*
+ * Definition of register offsets
+ */
+
+/* ID and Revision Register */
+#define ID_REV 0x0
+
+/* Configuration Register */
+#define CFG0x10
+
+/* Interrupt Enable Register */
+#define INT_EN 0x14
+#define CH_INT_EN(c, i)((1<

[PATCH v4 33/36] net: faraday add nds32 support.

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch is used to support nds32 architecture to use these faraday
mac IP.

Signed-off-by: Greentime Hu 
---
 drivers/net/ethernet/faraday/Kconfig |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/faraday/Kconfig 
b/drivers/net/ethernet/faraday/Kconfig
index 040c7f1..1bdaffc 100644
--- a/drivers/net/ethernet/faraday/Kconfig
+++ b/drivers/net/ethernet/faraday/Kconfig
@@ -5,7 +5,7 @@
 config NET_VENDOR_FARADAY
bool "Faraday devices"
default y
-   depends on ARM
+   depends on ARM || NDS32 || COMPILE_TEST
---help---
  If you have a network (Ethernet) card belonging to this class, say Y.
 
@@ -18,7 +18,7 @@ if NET_VENDOR_FARADAY
 
 config FTMAC100
tristate "Faraday FTMAC100 10/100 Ethernet support"
-   depends on ARM
+   depends on ARM || NDS32 || COMPILE_TEST
select MII
---help---
  This driver supports the FTMAC100 10/100 Ethernet controller
@@ -27,7 +27,7 @@ config FTMAC100
 
 config FTGMAC100
tristate "Faraday FTGMAC100 Gigabit Ethernet support"
-   depends on ARM
+   depends on ARM || NDS32 || COMPILE_TEST
select PHYLIB
---help---
  This driver supports the FTGMAC100 Gigabit Ethernet controller
-- 
1.7.9.5



[PATCH v4 35/36] clocksource/drivers/atcpit100: VDSO support

2017-12-17 Thread Greentime Hu
From: Rick Chen 

VDSO needs real-time cycle count to ensure the time accuracy.
Unlike others, nds32 architecture does not define clock source,
hence VDSO needs atcpit100 offering real-time cycle count
to derive the correct time.

Signed-off-by: Vincent Chen 
Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
---
 drivers/clocksource/timer-atcpit100.c |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/clocksource/timer-atcpit100.c 
b/drivers/clocksource/timer-atcpit100.c
index 0077fdb..9b2b628 100644
--- a/drivers/clocksource/timer-atcpit100.c
+++ b/drivers/clocksource/timer-atcpit100.c
@@ -29,6 +29,9 @@
 #include 
 #include 
 #include "timer-of.h"
+#ifdef CONFIG_NDS32
+#include 
+#endif
 
 /*
  * Definition of register offsets
@@ -211,6 +214,17 @@ static u64 notrace atcpit100_timer_sched_read(void)
return ~readl(timer_of_base() + CH1_CNT);
 }
 
+#ifdef CONFIG_NDS32
+static void fill_vdso_need_info(struct device_node *node)
+{
+   struct resource timer_res;
+   of_address_to_resource(node, 0, _res);
+   timer_info.mapping_base = (unsigned long)timer_res.start;
+   timer_info.cycle_count_down = true;
+   timer_info.cycle_count_reg_offset = CH1_CNT;
+}
+#endif
+
 static int __init atcpit100_timer_init(struct device_node *node)
 {
int ret;
@@ -249,6 +263,10 @@ static int __init atcpit100_timer_init(struct device_node 
*node)
val = readl(base + INT_EN);
writel(val | CH0INT0EN, base + INT_EN);
 
+#ifdef CONFIG_NDS32
+   fill_vdso_need_info(node);
+#endif
+
return ret;
 }
 
-- 
1.7.9.5



[PATCH v4 36/36] dt-bindings: timer: Add andestech atcpit100 timer binding doc

2017-12-17 Thread Greentime Hu
From: Rick Chen 

Add a document to describe Andestech atcpit100 timer and
binding information.

Signed-off-by: Rick Chen 
Signed-off-by: Greentime Hu 
Acked-by: Rob Herring 
---
 .../bindings/timer/andestech,atcpit100-timer.txt   |   33 
 1 file changed, 33 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt

diff --git 
a/Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt 
b/Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt
new file mode 100644
index 000..4c9ea59
--- /dev/null
+++ b/Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt
@@ -0,0 +1,33 @@
+Andestech ATCPIT100 timer
+--
+ATCPIT100 is a generic IP block from Andes Technology, embedded in
+Andestech AE3XX platforms and other designs.
+
+This timer is a set of compact multi-function timers, which can be
+used as pulse width modulators (PWM) as well as simple timers.
+
+It supports up to 4 PIT channels. Each PIT channel is a
+multi-function timer and provide the following usage scenarios:
+One 32-bit timer
+Two 16-bit timers
+Four 8-bit timers
+One 16-bit PWM
+One 16-bit timer and one 8-bit PWM
+Two 8-bit timer and one 8-bit PWM
+
+Required properties:
+- compatible   : Should be "andestech,atcpit100"
+- reg  : Address and length of the register set
+- interrupts   : Reference to the timer interrupt
+- clocks   : a clock to provide the tick rate for "andestech,atcpit100"
+- clock-names  : should be "PCLK" for the peripheral clock source.
+
+Examples:
+
+timer0: timer@f040 {
+   compatible = "andestech,atcpit100";
+   reg = <0xf040 0x1000>;
+   interrupts = <2>;
+   clocks = <>;
+   clock-names = "PCLK";
+};
-- 
1.7.9.5



[PATCH v4 29/36] dt-bindings: nds32 CPU Bindings

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch adds nds32 CPU binding documents.

Signed-off-by: Vincent Chen 
Signed-off-by: Rick Chen 
Signed-off-by: Zong Li 
Signed-off-by: Greentime Hu 
Reviewed-by: Rob Herring 
---
 Documentation/devicetree/bindings/nds32/cpus.txt |   37 ++
 1 file changed, 37 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nds32/cpus.txt

diff --git a/Documentation/devicetree/bindings/nds32/cpus.txt 
b/Documentation/devicetree/bindings/nds32/cpus.txt
new file mode 100644
index 000..9a52937
--- /dev/null
+++ b/Documentation/devicetree/bindings/nds32/cpus.txt
@@ -0,0 +1,37 @@
+* Andestech Processor Binding
+
+This binding specifies what properties must be available in the device tree
+representation of a Andestech Processor Core, which is the root node in the
+tree.
+
+Required properties:
+
+   - compatible:
+   Usage: required
+   Value type: 
+   Definition: should be one of:
+   "andestech,n13"
+   "andestech,n15"
+   "andestech,d15"
+   "andestech,n10"
+   "andestech,d10"
+   "andestech,nds32v3"
+   - device_type
+   Usage: required
+   Value type: 
+   Definition: must be "cpu"
+   - reg: Contains CPU index.
+   - clock-frequency: Contains the clock frequency for CPU, in Hz.
+
+* Examples
+
+/ {
+   cpus {
+   cpu@0 {
+   device_type = "cpu";
+   compatible = "andestech,n13", "andestech,nds32v3";
+   reg = <0x0>;
+   clock-frequency = <6000>
+   };
+   };
+};
-- 
1.7.9.5



[PATCH v4 12/36] nds32: Atomic operations

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

This patch includes the atomic and futex operations. Many atomic operations use
the load-lock word(llw) and store-condition word(scw) operations.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/barrier.h |   15 ++
 arch/nds32/include/asm/futex.h   |  103 ++
 2 files changed, 118 insertions(+)
 create mode 100644 arch/nds32/include/asm/barrier.h
 create mode 100644 arch/nds32/include/asm/futex.h

diff --git a/arch/nds32/include/asm/barrier.h b/arch/nds32/include/asm/barrier.h
new file mode 100644
index 000..faafc37
--- /dev/null
+++ b/arch/nds32/include/asm/barrier.h
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __NDS32_ASM_BARRIER_H
+#define __NDS32_ASM_BARRIER_H
+
+#ifndef __ASSEMBLY__
+#define mb()   asm volatile("msync all":::"memory")
+#define rmb()  asm volatile("msync all":::"memory")
+#define wmb()  asm volatile("msync store":::"memory")
+#include 
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __NDS32_ASM_BARRIER_H */
diff --git a/arch/nds32/include/asm/futex.h b/arch/nds32/include/asm/futex.h
new file mode 100644
index 000..eab5e84
--- /dev/null
+++ b/arch/nds32/include/asm/futex.h
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __NDS32_FUTEX_H__
+#define __NDS32_FUTEX_H__
+
+#include 
+#include 
+#include 
+
+#define __futex_atomic_ex_table(err_reg)   \
+   "   .pushsection __ex_table,\"a\"\n"\
+   "   .align  3\n"\
+   "   .long   1b, 4f\n"   \
+   "   .long   2b, 4f\n"   \
+   "   .popsection\n"  \
+   "   .pushsection .fixup,\"ax\"\n"   \
+   "4: move%0, " err_reg "\n"  \
+   "   j   3b\n"   \
+   "   .popsection"
+
+#define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg)\
+   smp_mb();   \
+   asm volatile(   \
+   "   movi$ta, #0\n"  \
+   "1: llw %1, [%2+$ta]\n" \
+   "   " insn "\n" \
+   "2: scw %0, [%2+$ta]\n" \
+   "   beqz%0, 1b\n"   \
+   "   movi%0, #0\n"   \
+   "3:\n"  \
+   __futex_atomic_ex_table("%4")   \
+   : "=" (ret), "=" (oldval)   \
+   : "r" (uaddr), "r" (oparg), "i" (-EFAULT)   \
+   : "cc", "memory")
+static inline int
+futex_atomic_cmpxchg_inatomic(u32 * uval, u32 __user * uaddr,
+ u32 oldval, u32 newval)
+{
+   int ret = 0;
+   u32 val, tmp, flags;
+
+   if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
+   return -EFAULT;
+
+   smp_mb();
+   asm volatile ("   movi$ta, #0\n"
+ "1: llw %1, [%6 + $ta]\n"
+ "   sub %3, %1, %4\n"
+ "   cmovz   %2, %5, %3\n"
+ "   cmovn   %2, %1, %3\n"
+ "2: scw %2, [%6 + $ta]\n"
+ "   beqz%2, 1b\n"
+ "3:\n   " __futex_atomic_ex_table("%7")
+ :"+"(ret), "="(val), "="(tmp), "="(flags)
+ :"r"(oldval), "r"(newval), "r"(uaddr), "i"(-EFAULT)
+ :"$ta", "memory");
+   smp_mb();
+
+   *uval = val;
+   return ret;
+}
+
+static inline int
+arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
+{
+   int oldval = 0, ret;
+
+
+   pagefault_disable();
+   switch (op) {
+   case FUTEX_OP_SET:
+   __futex_atomic_op("move %0, %3", ret, oldval, tmp, uaddr,
+ oparg);
+   break;
+   case FUTEX_OP_ADD:
+   __futex_atomic_op("add  %0, %1, %3", ret, oldval, tmp, uaddr,
+ oparg);
+   break;
+   case FUTEX_OP_OR:
+   __futex_atomic_op("or   %0, %1, %3", ret, oldval, tmp, uaddr,
+ oparg);
+   break;
+   case FUTEX_OP_ANDN:
+   __futex_atomic_op("and  %0, %1, %3", ret, oldval, tmp, uaddr,
+ ~oparg);
+   break;
+   case FUTEX_OP_XOR:
+   

[PATCH v4 02/36] earlycon: add reg-offset to physical address before mapping

2017-12-17 Thread Greentime Hu
From: Greentime Hu 

It will get the wrong virtual address because port->mapbase is not added
the correct reg-offset yet. We have to update it before earlycon_map()
is called

Signed-off-by: Greentime Hu 
---
 drivers/tty/serial/earlycon.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index 98928f0..17dba0a 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -253,11 +253,12 @@ int __init of_setup_earlycon(const struct earlycon_id 
*match,
}
port->mapbase = addr;
port->uartclk = BASE_BAUD * 16;
-   port->membase = earlycon_map(port->mapbase, SZ_4K);
 
val = of_get_flat_dt_prop(node, "reg-offset", NULL);
if (val)
port->mapbase += be32_to_cpu(*val);
+   port->membase = earlycon_map(port->mapbase, SZ_4K);
+
val = of_get_flat_dt_prop(node, "reg-shift", NULL);
if (val)
port->regshift = be32_to_cpu(*val);
-- 
1.7.9.5



[PATCH net] ip6_tunnel: get the min mtu properly in ip6_tnl_xmit

2017-12-17 Thread Xin Long
Now it's using IPV6_MIN_MTU as the min mtu in ip6_tnl_xmit, but
IPV6_MIN_MTU actually only works when the inner packet is ipv6.

With IPV6_MIN_MTU for ipv4 packets, the new pmtu for inner dst
couldn't be set less than 1280. It would cause tx_err and the
packet to be dropped when the outer dst pmtu is close to 1280.

Jianlin found it by running ipv4 traffic with the topo:

  (client) gre6 <---> eth1 (route) eth2 <---> gre6 (server)

After changing eth2 mtu to 1300, the performance became very
low, or the connection was even broken. The issue also affects
ip4ip6 and ip6ip6 tunnels.

So if the inner packet is ipv4, 576 should be considered as the
min mtu.

Note that for ip4ip6 and ip6ip6 tunnels, the inner packet can
only be ipv4 or ipv6, but for gre6 tunnel, it may also be ARP.
This patch using 576 as the min mtu for non-ipv6 packet works
for all those cases.

Reported-by: Jianlin Shi 
Signed-off-by: Xin Long 
---
 net/ipv6/ip6_tunnel.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index db84f52..931c38f 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1123,8 +1123,13 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device 
*dev, __u8 dsfield,
max_headroom += 8;
mtu -= 8;
}
-   if (mtu < IPV6_MIN_MTU)
-   mtu = IPV6_MIN_MTU;
+   if (skb->protocol == htons(ETH_P_IPV6)) {
+   if (mtu < IPV6_MIN_MTU)
+   mtu = IPV6_MIN_MTU;
+   } else if (mtu < 576) {
+   mtu = 576;
+   }
+
if (skb_dst(skb) && !t->parms.collect_md)
skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
if (skb->len - t->tun_hlen - eth_hlen > mtu && !skb_is_gso(skb)) {
-- 
2.1.0



[PATCH net] ip6_gre: remove the incorrect mtu limit for ipgre tap

2017-12-17 Thread Xin Long
The same fix as the patch "ip_gre: remove the incorrect mtu limit for
ipgre tap" is also needed for ip6_gre.

Fixes: 61e84623ace3 ("net: centralize net_device min/max MTU checking")
Signed-off-by: Xin Long 
---
 net/ipv6/ip6_gre.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 4cfd8e0..416c891 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1308,6 +1308,7 @@ static void ip6gre_tap_setup(struct net_device *dev)
 
ether_setup(dev);
 
+   dev->max_mtu = 0;
dev->netdev_ops = _tap_netdev_ops;
dev->needs_free_netdev = true;
dev->priv_destructor = ip6gre_dev_free;
-- 
2.1.0



[PATCH net] ip_gre: remove the incorrect mtu limit for ipgre tap

2017-12-17 Thread Xin Long
ipgre tap driver calls ether_setup(), after commit 61e84623ace3
("net: centralize net_device min/max MTU checking"), the range
of mtu is [min_mtu, max_mtu], which is [68, 1500] by default.

It causes the dev mtu of the ipgre tap device to not be greater
than 1500, this limit value is not correct for ipgre tap device.

Besides, it's .change_mtu already does the right check. So this
patch is just to set max_mtu as 0, and leave the check to it's
.change_mtu.

Fixes: 61e84623ace3 ("net: centralize net_device min/max MTU checking")
Reported-by: Jianlin Shi 
Signed-off-by: Xin Long 
---
 net/ipv4/ip_gre.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 9c17356..45ffd3d 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -1310,6 +1310,7 @@ static const struct net_device_ops erspan_netdev_ops = {
 static void ipgre_tap_setup(struct net_device *dev)
 {
ether_setup(dev);
+   dev->max_mtu = 0;
dev->netdev_ops = _tap_netdev_ops;
dev->priv_flags &= ~IFF_TX_SKB_SHARING;
dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
-- 
2.1.0



[PATCH net] vxlan: update skb dst pmtu on tx path

2017-12-17 Thread Xin Long
Unlike ip tunnels, now vxlan doesn't do any pmtu update for
upper dst pmtu, even if it doesn't match the lower dst pmtu
any more.

The problem can be reproduced when reducing the vxlan lower
dev's pmtu when running netperf. In jianlin's testing, the
performance went to 1/7 of the previous.

This patch is to update the upper dst pmtu to match the lower
dst pmtu on tx path so that packets can be sent out even when
lower dev's pmtu has been changed.

It also works for metadata dst.

Note that this patch doesn't process any pmtu icmp packet.
But even in the future, the support for pmtu icmp packets
process of udp tunnels will also needs this.

The same thing will be done for geneve in another patch.

Signed-off-by: Xin Long 
---
 drivers/net/vxlan.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 19b9cc5..25b 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2155,6 +2155,13 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
}
 
ndst = >dst;
+   if (skb_dst(skb)) {
+   int mtu = dst_mtu(ndst) - VXLAN_HEADROOM;
+
+   skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL,
+  skb, mtu);
+   }
+
tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
ttl = ttl ? : ip4_dst_hoplimit(>dst);
err = vxlan_build_skb(skb, ndst, sizeof(struct iphdr),
@@ -2190,6 +2197,13 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
goto out_unlock;
}
 
+   if (skb_dst(skb)) {
+   int mtu = dst_mtu(ndst) - VXLAN6_HEADROOM;
+
+   skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL,
+  skb, mtu);
+   }
+
tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
ttl = ttl ? : ip6_dst_hoplimit(ndst);
skb_scrub_packet(skb, xnet);
-- 
2.1.0



[PATCH net] sctp: add SCTP_CID_RECONF conversion in sctp_cname

2017-12-17 Thread Xin Long
Whenever a new type of chunk is added, the corresp conversion in
sctp_cname should be added. Otherwise, in some places, pr_debug
will print it as "unknown chunk".

Fixes: cc16f00f6529 ("sctp: add support for generating stream reconf ssn reset 
request chunk")
Signed-off-by: Xin Long 
---
 net/sctp/debug.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/sctp/debug.c b/net/sctp/debug.c
index 3f619fd..291c97b 100644
--- a/net/sctp/debug.c
+++ b/net/sctp/debug.c
@@ -78,6 +78,9 @@ const char *sctp_cname(const union sctp_subtype cid)
case SCTP_CID_AUTH:
return "AUTH";
 
+   case SCTP_CID_RECONF:
+   return "RECONF";
+
default:
break;
}
-- 
2.1.0



[PATCH net] sctp: fix the issue that a __u16 variable may overflow in sctp_ulpq_renege

2017-12-17 Thread Xin Long
Now when reneging events in sctp_ulpq_renege(), the variable freed
could be increased by a __u16 value twice while freed is of __u16
type. It means freed may overflow at the second addition.

This patch is to fix it by using __u32 type for 'freed', while at
it, also to remove 'if (chunk)' check, as all renege commands are
generated in sctp_eat_data and it can't be NULL.

Reported-by: Marcelo Ricardo Leitner 
Signed-off-by: Xin Long 
---
 net/sctp/ulpqueue.c | 24 
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c
index a71be33..e36ec5d 100644
--- a/net/sctp/ulpqueue.c
+++ b/net/sctp/ulpqueue.c
@@ -1084,29 +1084,21 @@ void sctp_ulpq_partial_delivery(struct sctp_ulpq *ulpq,
 void sctp_ulpq_renege(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
  gfp_t gfp)
 {
-   struct sctp_association *asoc;
-   __u16 needed, freed;
-
-   asoc = ulpq->asoc;
+   struct sctp_association *asoc = ulpq->asoc;
+   __u32 freed = 0;
+   __u16 needed;
 
-   if (chunk) {
-   needed = ntohs(chunk->chunk_hdr->length);
-   needed -= sizeof(struct sctp_data_chunk);
-   } else
-   needed = SCTP_DEFAULT_MAXWINDOW;
-
-   freed = 0;
+   needed = ntohs(chunk->chunk_hdr->length) -
+sizeof(struct sctp_data_chunk);
 
if (skb_queue_empty(>base.sk->sk_receive_queue)) {
freed = sctp_ulpq_renege_order(ulpq, needed);
-   if (freed < needed) {
+   if (freed < needed)
freed += sctp_ulpq_renege_frags(ulpq, needed - freed);
-   }
}
/* If able to free enough room, accept this chunk. */
-   if (chunk && (freed >= needed)) {
-   int retval;
-   retval = sctp_ulpq_tail_data(ulpq, chunk, gfp);
+   if (freed >= needed) {
+   int retval = sctp_ulpq_tail_data(ulpq, chunk, gfp);
/*
 * Enter partial delivery if chunk has not been
 * delivered; otherwise, drain the reassembly queue.
-- 
2.1.0



Re: [kernel-hardening] [PATCH 0/3] kallsyms: don't leak address

2017-12-17 Thread Tobin C. Harding
On Mon, Dec 18, 2017 at 04:31:25PM +1100, Michael Ellerman wrote:
> "Tobin C. Harding"  writes:
> 
> > This set plugs a kernel address leak that occurs if kallsyms symbol
> > look up fails. This set was prompted by a leaking address found using
> > scripts/leaking_addresses.pl on a PowerPC machine in the wild.
> 
> Any details on that? I haven't heard about it.

I have an account on a server in USA. I'm not sure how much detail I
should give on the mailing list in case it is sensitive information. I
will email you off list. Responding here for the benefit of the list.

If this is not the correct way to handle this please say so.

thanks,
Tobin.


Re: [PATCH v2 0/5] Support for generalized use of make C={1,2} via a wrapper program

2017-12-17 Thread Joe Perches
On Sun, 2017-12-17 at 22:00 -0700, Jason Gunthorpe wrote:
> On Sun, Dec 17, 2017 at 03:14:10AM +0100, Knut Omang wrote:
> 
> > > I like the ability to add more checkers and keep then in the main
> > > upstream tree. But adding overrides for specific subsystems goes against
> > > the policy that all subsystems should be treated equally.
> > 
> > This is a tool to enable automated testing for as many checks as
> > possible, as soon as possible. Like any tool, it can be misused, but
> > that's IMHO an orthogonal problem that I think the maintainers will
> > be more than capable of preventing.
> > 
> > Think of this as a tightening screw: We eliminate errors class by
> > class or file by file, and in the same commit narrows in the list of
> > exceptions. That way we can fix issues piece by piece while avoiding
> > a lot of regressions in already clean parts.
> 
> Since you used drivers/infiniband as an example for this script..
> 
> I will say I agree with this idea.
> 
> It is not that we *want* infiniband to be different from the rest of
> the kernel, it is that we have this historical situation where we
> don't have a code base that already passes the various static checker
> things.
> 
> I would like it very much if I could run 'make static checker' and see
> no warnings. This helps me know that I when I accept patches I am not
> introducing new problems to code that has already been cleaned up.
> 
> Today when we run checkers we get so many warnings it is too hard to
> make any sense of it.

Here is a list of the checkpatch messages for drivers/infiniband
sorted by type.

Many of these might be corrected by using

$ ./scripts/checkpatch.pl -f --fix-inplace --types= \
  $(git ls-files drivers/infiniband/)

   5243 CHECK:CAMELCASE
   4487 WARNING:LONG_LINE
   1755 CHECK:PARENTHESIS_ALIGNMENT
   1664 CHECK:SPACING
910 WARNING:FUNCTION_ARGUMENTS
742 CHECK:OPEN_ENDED_LINE
685 CHECK:BRACES
643 CHECK:UNNECESSARY_PARENTHESES
478 WARNING:SIZEOF_PARENTHESIS
361 WARNING:UNSPECIFIED_INT
342 WARNING:LONG_LINE_COMMENT
338 ERROR:SPACING
338 CHECK:LINE_SPACING
306 WARNING:SPLIT_STRING
278 WARNING:SPACING
242 WARNING:SYMBOLIC_PERMS
194 WARNING:BLOCK_COMMENT_STYLE
175 CHECK:BIT_MACRO
158 WARNING:SPACE_BEFORE_TAB
154 WARNING:LINE_SPACING
139 CHECK:MACRO_ARG_REUSE
133 CHECK:UNCOMMENTED_DEFINITION
122 CHECK:AVOID_BUG
103 CHECK:COMPARISON_TO_NULL
101 WARNING:ENOSYS
 89 WARNING:BRACES
 78 WARNING:PREFER_PR_LEVEL
 74 WARNING:MULTILINE_DEREFERENCE
 59 CHECK:TYPO_SPELLING
 52 WARNING:EMBEDDED_FUNCTION_NAME
 52 CHECK:MULTIPLE_ASSIGNMENTS
 50 CHECK:PREFER_KERNEL_TYPES
 45 WARNING:RETURN_VOID
 39 WARNING:UNNECESSARY_ELSE
 38 ERROR:POINTER_LOCATION
 37 WARNING:ALLOC_WITH_MULTIPLY
 36 CHECK:ALLOC_SIZEOF_STRUCT
 35 CHECK:AVOID_EXTERNS
 34 WARNING:PRINTK_WITHOUT_KERN_LEVEL
 33 ERROR:CODE_INDENT
 32 WARNING:PREFER_PACKED
 32 CHECK:LOGICAL_CONTINUATIONS
 29 WARNING:MEMORY_BARRIER
 29 WARNING:LEADING_SPACE
 28 WARNING:DEEP_INDENTATION
 27 CHECK:USLEEP_RANGE
 23 WARNING:SUSPECT_CODE_INDENT
 23 ERROR:TRAILING_STATEMENTS
 21 WARNING:LONG_LINE_STRING
 20 WARNING:CONSIDER_KSTRTO
 18 WARNING:CONSTANT_COMPARISON
 18 ERROR:OPEN_BRACE
 15 WARNING:QUOTED_WHITESPACE_BEFORE_NEWLINE
 14 WARNING:VOLATILE
 14 ERROR:SWITCH_CASE_INDENT_LEVEL
 11 WARNING:OOM_MESSAGE
 11 WARNING:INCLUDE_LINUX
 10 WARNING:SSCANF_TO_KSTRTO
 10 WARNING:INDENTED_LABEL
  9 ERROR:GLOBAL_INITIALISERS
  9 ERROR:COMPLEX_MACRO
  9 ERROR:ASSIGN_IN_IF
  8 WARNING:UNNECESSARY_BREAK
  6 WARNING:PRINTF_L
  6 WARNING:MISORDERED_TYPE
  6 ERROR:INITIALISED_STATIC
  5 WARNING:TABSTOP
  5 WARNING:SINGLE_STATEMENT_DO_WHILE_MACRO
  5 WARNING:NAKED_SSCANF
  4 WARNING:NEEDLESS_IF
  4 ERROR:RETURN_PARENTHESES
  4 CHECK:BOOL_COMPARISON
  3 WARNING:TRAILING_SEMICOLON
  3 WARNING:STATIC_CONST_CHAR_ARRAY
  3 ERROR:TRAILING_WHITESPACE
  2 WARNING:UNNECESSARY_PARENTHESES
  2 WARNING:MISSING_SPACE
  2 WARNING:LOGGING_CONTINUATION
  2 CHECK:ARCH_DEFINES
  1 WARNING:TYPECAST_INT_CONSTANT
  1 WARNING:PREFER_DEV_LEVEL
  1 WARNING:NR_CPUS
  1 WARNING:NEW_TYPEDEFS
  1 WARNING:MINMAX
  1 WARNING:MACRO_WITH_FLOW_CONTROL
  1 WARNING:LINE_CONTINUATIONS
  1 WARNING:DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON
  1 WARNING:DEFAULT_NO_BREAK
  1 WARNING:CONST_STRUCT
  1 WARNING:CONSIDER_COMPLETION
  1 ERROR:WHILE_AFTER_BRACE
  1 ERROR:ELSE_AFTER_BRACE
  1 CHECK:REDUNDANT_CODE



[PATCH] net: qcom/emac: Change the order of mac up and sgmii open

2017-12-17 Thread Hemanth Puranik
This patch fixes the order of mac_up and sgmii_open for the
reasons noted below:

- If open takes more time(if the SGMII block is not responding or
  if we want to do some delay based task) in this situation we
  will hit NETDEV watchdog
- The main reason : We should signal to upper layers that we are
  ready to receive packets "only" when the entire path is initialized
  not the other way around, this is followed in the reset path where
  we do mac_down, sgmii_reset and mac_up. This also makes the driver
  uniform across the reset and open paths.
- In the future there may be need for delay based tasks to be done in
  sgmii open which will result in NETDEV watchdog
- As per the documentation the order of init should be sgmii, mac, rings
  and DMA

Signed-off-by: Hemanth Puranik 
---
 drivers/net/ethernet/qualcomm/emac/emac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/emac/emac.c 
b/drivers/net/ethernet/qualcomm/emac/emac.c
index 70c92b6..38c924bd 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac.c
@@ -253,18 +253,18 @@ static int emac_open(struct net_device *netdev)
return ret;
}
 
-   ret = emac_mac_up(adpt);
+   ret = adpt->phy.open(adpt);
if (ret) {
emac_mac_rx_tx_rings_free_all(adpt);
free_irq(irq->irq, irq);
return ret;
}
 
-   ret = adpt->phy.open(adpt);
+   ret = emac_mac_up(adpt);
if (ret) {
-   emac_mac_down(adpt);
emac_mac_rx_tx_rings_free_all(adpt);
free_irq(irq->irq, irq);
+   adpt->phy.close(adpt);
return ret;
}
 
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: r8169 regression: UDP packets dropped intermittantly

2017-12-17 Thread Jonathan Woithe
Resend to netdev.  LKML CCed in case anyone in the wider kernel community
can suggest a way forward.  Please CC responses if replying only to LKML.

It seems that this 4+ year old regression in the r8169 driver (documented in
this thread on netdev beginning on 9 March 2013) will never be fixed,
despite the identification of the commit which broke it.  Cards using this
driver will therefore remain unusable for certain workloads utilising UDP.

- Original message from 14 Nov 2017 -

Date: Tue, 14 Nov 2017 16:09:23 +1030
From: Jonathan Woithe 
To: netdev@vger.kernel.org
Subject: Re: r8169 regression: UDP packets dropped intermittantly

As far as I am aware there were no follow up comments to my last post on
this subject on 24 March 2017.  The text of that post is included below for
reference.  To summarise: a short test program which reliably triggered the
problem was written in the hope it would assist in the repair of this
regression.

Today I ran the tests on the 4.14 kernel.  The problem is still present.  If
the same machine is run under a 4.3 kernel with the hacked r8169 driver the
problem does not occur.  Using the 4.3 r8169 driver triggers the problem. 
It also works without trouble under 2.6.35.11 (the kernel we've stuck with
due to the problem affecting most newer kernels).

To recap the history of this thread, the misbehaviour of the r8169 driver in
the presence of small UDP packets affects kernels newer than 3.3.  The
initial post in this thread was on 9 March 2013.  The regression was
introduced with commit da78dbff2e05630921c551dbbc70a4b7981a8fff.

Since this regression has persisted for more than 4 years, is there any
chance that it will be fixed?  The inability to run newer kernels has
prevented us from providing them as upgrades in our products.  If this
problem in the r8169 driver will never be fixed, it seems we'll have to find
a supply of a PCI/PCIe NIC which doesn't utilise this driver.  Of course
this won't help those whose systems in the field are fitted with the
r8169-based card.

Regards
  jonathan

Post from Mar 24, 2017:

> On Thu, Jun 23, 2016 at 01:22:50AM +0200, Francois Romieu wrote:
> > Jonathan Woithe  :
> > [...]
> > > to mainline (in which case I'll keep watching out for it)?  Or is the
> > > out-of-tree workaround mentioned above considered to be the long term
> > > fix for those who encounter the problem?
> > 
> > It's a workaround. Nothing less, nothing more.
> 
> Recently I have had a chance to revisit this issue.  I have written a
> program (r8196-test, source is included below) which recreates the problem
> without requiring our external hardware devices.  That is, this program
> triggers the fault when run between two networked computers.  To use, two
> PCs are needed.  One (the "master") has an rtl8169 network card fitted (ours
> has a Netgear GA311, but the problem has been seen with others too from
> memory).  The network hardware of the other computer (the "slave") isn't
> important.  First run
> 
>   ./r8196-test
> 
> on the slave, followed by 
> 
>   ./r8196-test 
> 
> on the master.  When running stock kernel version 4.3 the master stops
> reliably within a minute or so with a timeout, indicating (in this case)
> that the response packet never arrived within the 0.5 second timeout period. 
> The ID whose response was never received by the master is reported as having
> been seen (and a response sent) by the slave.
> 
> If I substitute the forward ported r8169 driver mentioned earlier in this
> thread into kernel 4.3, the above program sequence runs seemingly
> indefinitely without any timeouts (runtime is beyond two hours as of this
> writing, compared to tens of seconds with the standard driver).
> 
> This demonstrates that the problem is independent of our custom network
> devices and allows the fault to be recreated using commodity hardware.
> 
> Does this make it any easier to develop a mainline fix for the regression?
> 
> Regards
>   jonathan
> 
> /*
>  * To test, the "master" mode is run on a PC with an RTL-8169 card.
>  * The "slave" mode is run on any other PC.  "Master" mode is activated
>  * by providing the IP of the slave PC on the command line.  The slave
>  * should be started before the master; without a running slave the master
>  * will time out.
>  *
>  * This code is in the public domain.
>  */
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> 
> #include 
> 
> unsigned char ping_payload[] = {
> 0x00, 0x00,
> 0x00, 0x00, 0x00, 0x00,
> };
> 
> #define PING_PAYLOAD_SIZE 6
> 
> unsigned char ack_payload[] = {
> 0x12, 0x34,
> 0x01, 0x01, 0x00, 0x00,
> 0x00, 0x00, 0x00, 0x00,
> 0x00, 0x00, 0x00, 0x00,
> };
> 
> #define ACK_PAYLOAD_SIZE 14
> 
> #define UDP_PORT 49491
> 
> signed int open_udp(const char *target_addr)
> {
> struct sockaddr_in local_addr;
> struct timeval tv;
> int sock;
> 
> sock = socket(PF_INET,SOCK_DGRAM, 0);
> if (sock 

Re: [kernel-hardening] [PATCH 0/3] kallsyms: don't leak address

2017-12-17 Thread Michael Ellerman
"Tobin C. Harding"  writes:

> This set plugs a kernel address leak that occurs if kallsyms symbol
> look up fails. This set was prompted by a leaking address found using
> scripts/leaking_addresses.pl on a PowerPC machine in the wild.

Any details on that? I haven't heard about it.

cheers


Re: [PATCH v2 0/5] Support for generalized use of make C={1,2} via a wrapper program

2017-12-17 Thread Jason Gunthorpe
On Sun, Dec 17, 2017 at 03:14:10AM +0100, Knut Omang wrote:

> > I like the ability to add more checkers and keep then in the main
> > upstream tree. But adding overrides for specific subsystems goes against
> > the policy that all subsystems should be treated equally.
> 
> This is a tool to enable automated testing for as many checks as
> possible, as soon as possible. Like any tool, it can be misused, but
> that's IMHO an orthogonal problem that I think the maintainers will
> be more than capable of preventing.
> 
> Think of this as a tightening screw: We eliminate errors class by
> class or file by file, and in the same commit narrows in the list of
> exceptions. That way we can fix issues piece by piece while avoiding
> a lot of regressions in already clean parts.

Since you used drivers/infiniband as an example for this script..

I will say I agree with this idea.

It is not that we *want* infiniband to be different from the rest of
the kernel, it is that we have this historical situation where we
don't have a code base that already passes the various static checker
things.

I would like it very much if I could run 'make static checker' and see
no warnings. This helps me know that I when I accept patches I am not
introducing new problems to code that has already been cleaned up.

Today when we run checkers we get so many warnings it is too hard to
make any sense of it.

Being able to say File X is now clean for check XYZ seems very useful
and may motivate people to clean up the files they actualy care
about...

> > There was discussion at Kernel Summit about how the different
> > subsystems already have different rules. This appears to be a way
> > to make that worse.
> 
> IMHO this is a tool that should help maintainers implement the
> policies they desire.  But the tool itself does not dictate any
> such.

Yes, again, in infiniband we like to see checkpatch be good for new
submission, even if that clashes with surrounding code. For instance
we have a mixture of sizeof foo and sizeof(foo) styles in the same
file/function now.

I certainly don't want to tell people they need to follow some
different style from 10 years ago when they send patches.

Jason


[PATCH net-next] udp: handle gro_receive only when necessary

2017-12-17 Thread zhangliping
From: zhangliping 

Under our udp pressure performance test, after gro is disabled, rx rate
will be improved from ~2500kpps to ~2800kpps. We can find some difference
from perf report:
1. gro is enabled:
  24.23%   [kernel]   [k] udp4_lib_lookup2
   5.42%   [kernel]   [k] __memcpy
   3.87%   [kernel]   [k] fib_table_lookup
   3.76%   [kernel]   [k] __netif_receive_skb_core
   3.68%   [kernel]   [k] ip_rcv

2. gro is disabled:
   9.66%   [kernel]   [k] udp4_lib_lookup2
   9.47%   [kernel]   [k] __memcpy
   4.75%   [kernel]   [k] fib_table_lookup
   4.71%   [kernel]   [k] __netif_receive_skb_core
   3.90%   [kernel]   [k] virtnet_poll

So if there's no udp tunnel(such as vxlan) configured, we can skip
the udp gro processing.

Signed-off-by: zhangliping 
---
 include/net/udp.h  |  2 ++
 net/ipv4/udp_offload.c |  7 +++
 net/ipv4/udp_tunnel.c  | 11 ++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/include/net/udp.h b/include/net/udp.h
index 6c759c8594e2..c503f8b06845 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -188,6 +188,8 @@ static inline struct udphdr *udp_gro_udphdr(struct sk_buff 
*skb)
return uh;
 }
 
+extern struct static_key_false udp_gro_needed;
+
 /* hash routines shared between UDPv4/6 and UDP-Litev4/6 */
 static inline int udp_lib_hash(struct sock *sk)
 {
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index 01801b77bd0d..9cb11a833964 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -10,10 +10,14 @@
  * UDPv4 GSO support
  */
 
+#include 
 #include 
 #include 
 #include 
 
+DEFINE_STATIC_KEY_FALSE(udp_gro_needed);
+EXPORT_SYMBOL_GPL(udp_gro_needed);
+
 static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
netdev_features_t features,
struct sk_buff *(*gso_inner_segment)(struct sk_buff *skb,
@@ -250,6 +254,9 @@ struct sk_buff **udp_gro_receive(struct sk_buff **head, 
struct sk_buff *skb,
int flush = 1;
struct sock *sk;
 
+   if (!static_branch_unlikely(_gro_needed))
+   goto out;
+
if (NAPI_GRO_CB(skb)->encap_mark ||
(skb->ip_summed != CHECKSUM_PARTIAL &&
 NAPI_GRO_CB(skb)->csum_cnt == 0 &&
diff --git a/net/ipv4/udp_tunnel.c b/net/ipv4/udp_tunnel.c
index 6539ff15e9a3..4a7b3c8223c0 100644
--- a/net/ipv4/udp_tunnel.c
+++ b/net/ipv4/udp_tunnel.c
@@ -1,4 +1,5 @@
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -73,6 +74,9 @@ void setup_udp_tunnel_sock(struct net *net, struct socket 
*sock,
udp_sk(sk)->gro_complete = cfg->gro_complete;
 
udp_tunnel_encap_enable(sock);
+
+   if (udp_sk(sk)->gro_receive)
+   static_branch_inc(_gro_needed);
 }
 EXPORT_SYMBOL_GPL(setup_udp_tunnel_sock);
 
@@ -185,7 +189,12 @@ EXPORT_SYMBOL_GPL(udp_tunnel_xmit_skb);
 
 void udp_tunnel_sock_release(struct socket *sock)
 {
-   rcu_assign_sk_user_data(sock->sk, NULL);
+   struct sock *sk = sock->sk;
+
+   if (udp_sk(sk)->gro_receive)
+   static_branch_dec(_gro_needed);
+
+   rcu_assign_sk_user_data(sk, NULL);
kernel_sock_shutdown(sock, SHUT_RDWR);
sock_release(sock);
 }
-- 
2.13.4




Re: [net-next] phylib: Add device reset GPIO support causes DSA MT7530 acquires reset-gpios fails

2017-12-17 Thread Sean Wang
On Fri, 2017-12-15 at 11:10 +0100, Andrew Lunn wrote:
> On Fri, Dec 15, 2017 at 02:55:03PM +0800, Sean Wang wrote:
> > Hi Sergei,
> > 
> > Recently I found the patch commit bafbdd527d56 (phylib: Add device reset
> > GPIO support) would have the impact on MT7530 driver. Which causes the
> > DSA MT7530 device (it's the child node under mdio bus) gets the
> > reset-gpios fails because the same GPIO seems already be held in the
> > earlier mdiobus_register_device call patched through the commit.
> > 
> > do you have any idea how the commits also considers DSA case ?
> > 
> > I guessed the DSA lan9303, mv88e8 switch should have the same issue
> > since they have the same GPIO name as mdiobus_register_device required.
> 
> Hi Sean
> 
> Ah, not good :-(
> 
> I _think_ for the mv88e6xxx, we can remove the gpio reset code from
> the driver, and let the mdio core do it. I need to test to be sure.
> 
> Would that work for you?
> 
>   Andrew
> 

It probably can't. Because before the GPIO line is manipulated to reset,
certain power control should be handled such as power sources from
external PMIC to let devices actually enter the proper state.

So, I thought the kind of reset should be better controlled by the
specific driver, not by generic core.

Sean



Re: [PATCH net-next v6 2/2] net: ethernet: socionext: add AVE ethernet driver

2017-12-17 Thread Kunihiko Hayashi
Hello David,

On Fri, 15 Dec 2017 12:57:49 -0500 David Miller  wrote:

> From: Kunihiko Hayashi 
> Date: Thu, 14 Dec 2017 19:05:10 +0900
> 
> > +static void ave_desc_write(struct net_device *ndev, enum desc_id id,
> > +  int entry, int offset, u32 val)
> > +{
> > +   struct ave_private *priv = netdev_priv(ndev);
> > +   u32 addr = (id == AVE_DESCID_TX) ? priv->tx.daddr : priv->rx.daddr;
> 
> Please always order local variables from longest to shortest line.
> 
> Audit your entire submission for this issue, thank you.

I see. I'll fix the order of local variables.

> > +   ret = register_netdev(ndev);
> > +   if (ret) {
> > +   dev_err(dev, "failed to register netdevice\n");
> > +   goto out_del_napi;
> > +   }
> > +
> > +   platform_set_drvdata(pdev, ndev);
> 
> You must make all software state settings before reigster_netdev() is
> invoked.
> 
> At the exact moment you call register_netdev(), your device can be
> brought up, interrupts processed, PHY state changes made, etc.
> 
> So you must put this platform_set_drvdata() before the
> register_netdev() call.
> 
> Generally speaking, register_netdev() must always be the last state
> modification done by your probe routine.

Indeed. It's not good to invoke register_netdev() with all software
initialization not completed. I'll move register_netdev() after
all initialization.

Thank you,

---
Best Regards,
Kunihiko Hayashi




Re: [PATCH] net: phy: xgene: disable clk on error paths

2017-12-17 Thread Quan Nguyen
On Sat, Dec 16, 2017 at 4:52 AM, Alexey Khoroshilov
 wrote:
>
> There are several error paths in xgene_mdio_probe(),
> where clk is left undisabled. The patch fixes them.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov 
> ---
>  drivers/net/phy/mdio-xgene.c | 21 +++--
>  1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/phy/mdio-xgene.c b/drivers/net/phy/mdio-xgene.c
> index bfd3090fb055..07c6048200c6 100644
> --- a/drivers/net/phy/mdio-xgene.c
> +++ b/drivers/net/phy/mdio-xgene.c
> @@ -194,8 +194,11 @@ static int xgene_mdio_reset(struct xgene_mdio_pdata 
> *pdata)
> }
>
> ret = xgene_enet_ecc_init(pdata);
> -   if (ret)
> +   if (ret) {
> +   if (pdata->dev->of_node)
> +   clk_disable_unprepare(pdata->clk);
> return ret;
> +   }
> xgene_gmac_reset(pdata);
>
> return 0;
> @@ -388,8 +391,10 @@ static int xgene_mdio_probe(struct platform_device *pdev)
> return ret;
>
> mdio_bus = mdiobus_alloc();
> -   if (!mdio_bus)
> -   return -ENOMEM;
> +   if (!mdio_bus) {
> +   ret = -ENOMEM;
> +   goto out_clk;
> +   }
>
> mdio_bus->name = "APM X-Gene MDIO bus";
>
> @@ -418,7 +423,7 @@ static int xgene_mdio_probe(struct platform_device *pdev)
> mdio_bus->phy_mask = ~0;
> ret = mdiobus_register(mdio_bus);
> if (ret)
> -   goto out;
> +   goto out_mdiobus;
>
> acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_HANDLE(dev), 1,
> acpi_register_phy, NULL, mdio_bus, NULL);
> @@ -426,16 +431,20 @@ static int xgene_mdio_probe(struct platform_device 
> *pdev)
> }
>
> if (ret)
> -   goto out;
> +   goto out_mdiobus;
>
> pdata->mdio_bus = mdio_bus;
> xgene_mdio_status = true;
>
> return 0;
>
> -out:
> +out_mdiobus:
> mdiobus_free(mdio_bus);
>
> +out_clk:
> +   if (dev->of_node)
> +   clk_disable_unprepare(pdata->clk);
> +
> return ret;
>  }
>

Acked.


[Patch v2] net: phy: marvell: Limit 88m1101 autoneg errata to 88E1145 as well.

2017-12-17 Thread Zhao Qiang
88E1145 also need this autoneg errata.

Fixes: f2899788353c ("net: phy: marvell: Limit errata to 88m1101")
Signed-off-by: Zhao Qiang 
---
Changes for v2
- modify the commit msg in a proper way.

 drivers/net/phy/marvell.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 4d02b27..a3f456b 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -2069,7 +2069,7 @@ static int m88e1510_probe(struct phy_device *phydev)
.flags = PHY_HAS_INTERRUPT,
.probe = marvell_probe,
.config_init = _config_init,
-   .config_aneg = _config_aneg,
+   .config_aneg = _config_aneg,
.read_status = _read_status,
.ack_interrupt = _ack_interrupt,
.config_intr = _config_intr,
-- 
1.7.1



Re: [PATCH net] net: bridge: fix early call to br_stp_change_bridge_id

2017-12-17 Thread Toshiaki Makita
On 2017/12/16 20:31, Nikolay Aleksandrov wrote:
> The early call to br_stp_change_bridge_id in bridge's newlink can cause
> a memory leak if an error occurs during the newlink because the fdb
> entries are not cleaned up if a different lladdr was specified, also
> another minor issue is that it generates fdb notifications with
> ifindex = 0. To remove this special case the call is done after netdev
> register and we cleanup any bridge fdb entries on changelink error.
> That also doesn't slow down normal bridge removal, alternative is to call
> it in its ndo_uninit.
...
> Fixes: a4b816d8ba1c ("bridge: Change local fdb entries whenever mac address 
> of bridge device changes")
> Signed-off-by: Nikolay Aleksandrov 
> ---
> Consequently this also would fix the null ptr deref due to the rhashtable
> not being initialized in net-next when br_stp_change_bridge_id is called.
> 
> Toshiaki, any reason you called br_stp_change_bridge_id before
> register_netdevice when you introduced it in 30313a3d5794 ?

Thank you for taking care of this.
It's my bad. I just missed the problem.

>  net/bridge/br_netlink.c | 14 +-
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
> index d0ef0a8e8831..b0362cadb7c8 100644
> --- a/net/bridge/br_netlink.c
> +++ b/net/bridge/br_netlink.c
> @@ -1262,19 +1262,23 @@ static int br_dev_newlink(struct net *src_net, struct 
> net_device *dev,
...
>   err = br_changelink(dev, tb, data, extack);
> - if (err)
> + if (err) {
> + /* clean possible fdbs from br_stp_change_bridge_id above */
> + br_fdb_delete_by_port(br, NULL, 0, 1);

Don't we need to call br_dev_delete (br_link_ops.dellink) after
successful register instead of br_fdb_delete?
Particularly I'm wondering if not calling br_sysfs_delbr() is ok or not.

-- 
Toshiaki Makita



RE: [patch iproute2] tc: fix command "tc actions del" hang issue

2017-12-17 Thread Chris Mi
> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Friday, December 15, 2017 1:17 PM
> To: Chris Mi 
> Cc: netdev@vger.kernel.org; j...@resnulli.us
> Subject: Re: [patch iproute2] tc: fix command "tc actions del" hang issue
> 
> On Thu, 14 Dec 2017 18:09:00 +0900
> Chris Mi  wrote:
> 
> > If command is RTM_DELACTION, a non-NULL pointer is passed to rtnl_talk().
> > Then flag NLM_F_ACK is not set on n->nlmsg_flags and netlink_ack()
> > will not be called. Command tc will wait for the reply for ever.
> >
> > Fixes: 86bf43c7c2fd ("lib/libnetlink: update rtnl_talk to support
> > malloc buff at run time")
> > Signed-off-by: Chris Mi 
> > Reviewed-by: Jiri Pirko 
> 
> Thanks for fixing this.
> Applied, but please don't linewrap the fixes tag.
Thank for fixing it. I'll pay attention to it next time.


Re: [PATCH 2/3] vsprintf: print if symbol not found

2017-12-17 Thread Tobin C. Harding
On Sun, Dec 17, 2017 at 04:04:14PM -0800, Joe Perches wrote:
> On Mon, 2017-12-18 at 10:53 +1100, Tobin C. Harding wrote:
> > Depends on: commit bd6b239cdbb2 ("kallsyms: don't leak address when
> > symbol not found")
> > 
> > Currently vsprintf for specifiers %p[SsB] relies on the behaviour of
> > kallsyms (sprint_symbol()) and prints the actual address if a symbol is
> > not found. Previous patch changes this behaviour so tha sprint_symbol()
> 
> tha->that
> 
> > returns an error if symbol not found. With this patch in place we can
> > print a sanitized message '' instead of leaking the address.
> > 
> > Print '' for printk specifier %s[sSB] if no symbol is found.
> 
> %s->%ps
> 
> > diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> []
> > @@ -460,6 +460,8 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list 
> > args);
> >  extern __printf(2, 0)
> >  const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args);
> >  
> > +extern int string_is_no_symbol(const char *s);
> > +
> []
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > 
> > +#define PRINTK_NO_SYMBOL_STR ""
> 
> "" ?  "not found"?

?

> []
> 
> > +int string_is_no_symbol(const char *s)
> > +{
> > +   return !!strstr(s, PRINTK_NO_SYMBOL_STR);
> > +}
> > +EXPORT_SYMBOL(string_is_no_symbol);
> 
> Why should string_is_no_symbol be exported?

I ummed and ahhed about this. By your comment I'm guessing I made the
wrong choice. The idea behind exporting the symbol was so users of
vsprintf could have a way to see if the symbol was found or not without
having to know what string was actually printed.

I'll remove it for v3 and implement your other suggestions.

thanks for the review,
Tobin.


pull-request: bpf-next 2017-12-18

2017-12-17 Thread Daniel Borkmann
Hi David,

The following pull-request contains BPF updates for your *net-next* tree.

The main changes are:

1) Allow arbitrary function calls from one BPF function to another BPF function.
   As of today when writing BPF programs, __always_inline had to be used in
   the BPF C programs for all functions, unnecessarily causing LLVM to inflate
   code size. Handle this more naturally with support for BPF to BPF calls
   such that this __always_inline restriction can be overcome. As a result,
   it allows for better optimized code and finally enables to introduce core
   BPF libraries in the future that can be reused out of different projects.
   x86 and arm64 JIT support was added as well, from Alexei.

2) Add infrastructure for tagging functions as error injectable and allow for
   BPF to return arbitrary error values when BPF is attached via kprobes on
   those. This way of injecting errors generically eases testing and debugging
   without having to recompile or restart the kernel. Tags for opting-in for
   this facility are added with BPF_ALLOW_ERROR_INJECTION(), from Josef.

3) For BPF offload via nfp JIT, add support for bpf_xdp_adjust_head() helper
   call for XDP programs. First part of this work adds handling of BPF
   capabilities included in the firmware, and the later patches add support
   to the nfp verifier part and JIT as well as some small optimizations,
   from Jakub.

4) The bpftool now also gets support for basic cgroup BPF operations such
   as attaching, detaching and listing current BPF programs. As a requirement
   for the attach part, bpftool can now also load object files through
   'bpftool prog load'. This reuses libbpf which we have in the kernel tree
   as well. bpftool-cgroup man page is added along with it, from Roman.

5) Back then commit e87c6bc3852b ("bpf: permit multiple bpf attachments for
   a single perf event") added support for attaching multiple BPF programs
   to a single perf event. Given they are configured through perf's ioctl()
   interface, the interface has been extended with a PERF_EVENT_IOC_QUERY_BPF
   command in this work in order to return an array of one or multiple BPF
   prog ids that are currently attached, from Yonghong.

6) Various minor fixes and cleanups to the bpftool's Makefile as well
   as a new 'uninstall' and 'doc-uninstall' target for removing bpftool
   itself or prior installed documentation related to it, from Quentin.

7) Add CONFIG_CGROUP_BPF=y to the BPF kernel selftest config file which is
   required for the test_dev_cgroup test case to run, from Naresh.

8) Fix reporting of XDP prog_flags for nfp driver, from Jakub.

9) Fix libbpf's exit code from the Makefile when libelf was not found in
   the system, also from Jakub.

Please consider pulling these changes from:

  git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git

Thanks a lot!



The following changes since commit 62cd277039a3413604f486f0ca87faec810d7bb7:

  Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next (2017-12-08 
10:48:25 -0500)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git 

for you to fetch changes up to 46df3d209db080395a98fc0875bd05e45e8f44e0:

  trace: reenable preemption if we modify the ip (2017-12-17 20:47:32 +0100)


Alexei Starovoitov (14):
  Merge branch 'bpf-tracing-multiprog-tp-query'
  Merge branch 'bpf-override-return'
  bpf: introduce function calls (function boundaries)
  bpf: introduce function calls (verification)
  selftests/bpf: add verifier tests for bpf_call
  bpf: teach verifier to recognize zero initialized stack
  selftests/bpf: add tests for stack_zero tracking
  libbpf: add support for bpf_call
  selftests/bpf: add bpf_call test
  selftests/bpf: add xdp noinline test
  bpf: add support for bpf_call to interpreter
  bpf: fix net.core.bpf_jit_enable race
  bpf: x64: add JIT support for multi-function programs
  bpf: arm64: add JIT support for multi-function programs

Daniel Borkmann (5):
  Merge branch 'bpf-bpftool-makefile-cleanups'
  Merge branch 'bpf-bpftool-cgroup-ops'
  Merge branch 'bpf-nfp-jit-adjust-head-support'
  selftests/bpf: additional bpf_call tests
  Merge branch 'bpf-to-bpf-function-calls'

Jakub Kicinski (8):
  nfp: add nfp_cpp_area_size() accessor
  nfp: bpf: prepare for parsing BPF FW capabilities
  nfp: bpf: prepare for call support
  nfp: bpf: add basic support for adjust head call
  nfp: bpf: optimize the adjust_head calls in trivial cases
  nfp: bpf: correct printk formats for size_t
  libbpf: fix Makefile exit code if libelf not found
  nfp: set flags in the correct member of netdev_bpf

Josef Bacik (6):
  add infrastructure for tagging functions as error injectable
  btrfs: make open_ctree 

[trivial PATCH] treewide: Align function definition open/close braces

2017-12-17 Thread Joe Perches
Some functions definitions have either the initial open brace and/or
the closing brace outside of column 1.

Move those braces to column 1.

This allows various function analyzers like gnu complexity to work
properly for these modified functions.

Miscellanea:

o Remove extra trailing ; and blank line from xfs_agf_verify

Signed-off-by: Joe Perches 
---
git diff -w shows no difference other than the above 'Miscellanea'

(this is against -next, but it applies against Linus' tree
 with a couple offsets)

 arch/x86/include/asm/atomic64_32.h   |  2 +-
 drivers/acpi/custom_method.c |  2 +-
 drivers/acpi/fan.c   |  2 +-
 drivers/gpu/drm/amd/display/dc/core/dc.c |  2 +-
 drivers/media/i2c/msp3400-kthreads.c |  2 +-
 drivers/message/fusion/mptsas.c  |  2 +-
 drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c |  2 +-
 drivers/net/wireless/ath/ath9k/xmit.c|  2 +-
 drivers/platform/x86/eeepc-laptop.c  |  2 +-
 drivers/rtc/rtc-ab-b5ze-s3.c |  2 +-
 drivers/scsi/dpt_i2o.c   |  2 +-
 drivers/scsi/sym53c8xx_2/sym_glue.c  |  2 +-
 fs/locks.c   |  2 +-
 fs/ocfs2/stack_user.c|  2 +-
 fs/xfs/libxfs/xfs_alloc.c|  5 ++---
 fs/xfs/xfs_export.c  |  2 +-
 kernel/audit.c   |  6 +++---
 kernel/trace/trace_printk.c  |  4 ++--
 lib/raid6/sse2.c | 14 +++---
 sound/soc/fsl/fsl_dma.c  |  2 +-
 20 files changed, 30 insertions(+), 31 deletions(-)

diff --git a/arch/x86/include/asm/atomic64_32.h 
b/arch/x86/include/asm/atomic64_32.h
index 97c46b8169b7..d4d4883080fa 100644
--- a/arch/x86/include/asm/atomic64_32.h
+++ b/arch/x86/include/asm/atomic64_32.h
@@ -122,7 +122,7 @@ static inline long long atomic64_read(const atomic64_t *v)
long long r;
alternative_atomic64(read, "=" (r), "c" (v) : "memory");
return r;
- }
+}
 
 /**
  * atomic64_add_return - add and return
diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
index c68e72414a67..e967c1173ba3 100644
--- a/drivers/acpi/custom_method.c
+++ b/drivers/acpi/custom_method.c
@@ -94,7 +94,7 @@ static void __exit acpi_custom_method_exit(void)
 {
if (cm_dentry)
debugfs_remove(cm_dentry);
- }
+}
 
 module_init(acpi_custom_method_init);
 module_exit(acpi_custom_method_exit);
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 6cf4988206f2..3563103590c6 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -219,7 +219,7 @@ fan_set_cur_state(struct thermal_cooling_device *cdev, 
unsigned long state)
return fan_set_state_acpi4(device, state);
else
return fan_set_state(device, state);
- }
+}
 
 static const struct thermal_cooling_device_ops fan_cooling_ops = {
.get_max_state = fan_get_max_state,
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c 
b/drivers/gpu/drm/amd/display/dc/core/dc.c
index d1488d5ee028..1e0d1e7c5324 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -461,7 +461,7 @@ static void disable_dangling_plane(struct dc *dc, struct 
dc_state *context)
  
**/
 
 struct dc *dc_create(const struct dc_init_data *init_params)
- {
+{
struct dc *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
unsigned int full_pipe_count;
 
diff --git a/drivers/media/i2c/msp3400-kthreads.c 
b/drivers/media/i2c/msp3400-kthreads.c
index 4dd01e9f553b..dc6cb8d475b3 100644
--- a/drivers/media/i2c/msp3400-kthreads.c
+++ b/drivers/media/i2c/msp3400-kthreads.c
@@ -885,7 +885,7 @@ static int msp34xxg_modus(struct i2c_client *client)
 }
 
 static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in)
- {
+{
struct msp_state *state = to_state(i2c_get_clientdata(client));
int source, matrix;
 
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 345f6035599e..69a62d23514b 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -2968,7 +2968,7 @@ mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
mutex_unlock(>sas_mgmt.mutex);
 out:
return ret;
- }
+}
 
 static void
 mptsas_parse_device_info(struct sas_identify *identify,
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c 
b/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c
index 3dd973475125..0ea141ece19e 100644
--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c
+++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c
@@ -603,7 +603,7 @@ static struct uni_table_desc 

Re: [PATCH 2/3] vsprintf: print if symbol not found

2017-12-17 Thread Joe Perches
On Mon, 2017-12-18 at 10:53 +1100, Tobin C. Harding wrote:
> Depends on: commit bd6b239cdbb2 ("kallsyms: don't leak address when
> symbol not found")
> 
> Currently vsprintf for specifiers %p[SsB] relies on the behaviour of
> kallsyms (sprint_symbol()) and prints the actual address if a symbol is
> not found. Previous patch changes this behaviour so tha sprint_symbol()

tha->that

> returns an error if symbol not found. With this patch in place we can
> print a sanitized message '' instead of leaking the address.
> 
> Print '' for printk specifier %s[sSB] if no symbol is found.

%s->%ps

> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
[]
> @@ -460,6 +460,8 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list 
> args);
>  extern __printf(2, 0)
>  const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args);
>  
> +extern int string_is_no_symbol(const char *s);
> +
[]
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> 
> +#define PRINTK_NO_SYMBOL_STR ""

"" ?  "not found"?

[]

> +int string_is_no_symbol(const char *s)
> +{
> + return !!strstr(s, PRINTK_NO_SYMBOL_STR);
> +}
> +EXPORT_SYMBOL(string_is_no_symbol);

Why should string_is_no_symbol be exported?



[PATCH 2/3] vsprintf: print if symbol not found

2017-12-17 Thread Tobin C. Harding
Depends on: commit bd6b239cdbb2 ("kallsyms: don't leak address when
symbol not found")

Currently vsprintf for specifiers %p[SsB] relies on the behaviour of
kallsyms (sprint_symbol()) and prints the actual address if a symbol is
not found. Previous patch changes this behaviour so tha sprint_symbol()
returns an error if symbol not found. With this patch in place we can
print a sanitized message '' instead of leaking the address.

Print '' for printk specifier %s[sSB] if no symbol is found.

Signed-off-by: Tobin C. Harding 
---
 include/linux/kernel.h |  2 ++
 lib/vsprintf.c | 18 +++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index ce51455e2adf..89e8ce79c2d1 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -460,6 +460,8 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
 extern __printf(2, 0)
 const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args);
 
+extern int string_is_no_symbol(const char *s);
+
 extern __scanf(2, 3)
 int sscanf(const char *, const char *, ...);
 extern __scanf(2, 0)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 01c3957b2de6..c112b0980ead 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -667,6 +667,8 @@ char *bdev_name(char *buf, char *end, struct block_device 
*bdev,
 }
 #endif
 
+#define PRINTK_NO_SYMBOL_STR ""
+
 static noinline_for_stack
 char *symbol_string(char *buf, char *end, void *ptr,
struct printf_spec spec, const char *fmt)
@@ -674,6 +676,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
unsigned long value;
 #ifdef CONFIG_KALLSYMS
char sym[KSYM_SYMBOL_LEN];
+   int ret;
 #endif
 
if (fmt[1] == 'R')
@@ -682,11 +685,14 @@ char *symbol_string(char *buf, char *end, void *ptr,
 
 #ifdef CONFIG_KALLSYMS
if (*fmt == 'B')
-   sprint_backtrace(sym, value);
+   ret = sprint_backtrace(sym, value);
else if (*fmt != 'f' && *fmt != 's')
-   sprint_symbol(sym, value);
+   ret = sprint_symbol(sym, value);
else
-   sprint_symbol_no_offset(sym, value);
+   ret = sprint_symbol_no_offset(sym, value);
+
+   if (ret == -1)
+   strcpy(sym, PRINTK_NO_SYMBOL_STR);
 
return string(buf, end, sym, spec);
 #else
@@ -694,6 +700,12 @@ char *symbol_string(char *buf, char *end, void *ptr,
 #endif
 }
 
+int string_is_no_symbol(const char *s)
+{
+   return !!strstr(s, PRINTK_NO_SYMBOL_STR);
+}
+EXPORT_SYMBOL(string_is_no_symbol);
+
 static noinline_for_stack
 char *resource_string(char *buf, char *end, struct resource *res,
  struct printf_spec spec, const char *fmt)
-- 
2.7.4



[PATCH 0/3] kallsyms: don't leak address

2017-12-17 Thread Tobin C. Harding
This set plugs a kernel address leak that occurs if kallsyms symbol
look up fails. This set was prompted by a leaking address found using
scripts/leaking_addresses.pl on a PowerPC machine in the wild.

Patch set does not change behaviour when KALLSYMS is not defined
(suggested by Linus).

RFC has been in flight for 3 weeks with no negative response.

Patch 1 - return error code if symbol look up fails.
Patch 2 - print  to buffer if symbol look up returns an error.
Patch 3 - maintain current behaviour in ftrace.

Patch 3 (the ftrace stuff) is untested.

thanks,
Tobin.

Tobin C. Harding (3):
  kallsyms: don't leak address when symbol not found
  vsprintf: print  if symbol not found
  trace: print address if symbol not found

 include/linux/kernel.h   |  2 ++
 kernel/kallsyms.c|  6 --
 kernel/trace/trace.h | 24 
 kernel/trace/trace_events_hist.c |  6 +++---
 lib/vsprintf.c   | 18 +++---
 5 files changed, 48 insertions(+), 8 deletions(-)

-- 
2.7.4



[PATCH 1/3] kallsyms: don't leak address when symbol not found

2017-12-17 Thread Tobin C. Harding
Currently if kallsyms_lookup() fails to find the symbol then the address
is printed. This potentially leaks sensitive information. Instead of
printing the address we can return an error, giving the calling code the
option to print the address or print some sanitized message.

Return error instead of printing address to argument buffer. Leave
buffer in a sane state.

Signed-off-by: Tobin C. Harding 
---
 kernel/kallsyms.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index d5fa4116688a..23b9336c1461 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -394,8 +394,10 @@ static int __sprint_symbol(char *buffer, unsigned long 
address,
 
address += symbol_offset;
name = kallsyms_lookup(address, , , , buffer);
-   if (!name)
-   return sprintf(buffer, "0x%lx", address - symbol_offset);
+   if (!name) {
+   buffer[0] = '\0';
+   return -1;
+   }
 
if (name != buffer)
strcpy(buffer, name);
-- 
2.7.4



[PATCH 3/3] trace: print address if symbol not found

2017-12-17 Thread Tobin C. Harding
Fixes behaviour modified by: commit bd6b239cdbb2 ("kallsyms: don't leak
address when symbol not found")

Previous patch changed behaviour of kallsyms function sprint_symbol() to
return an error code instead of printing the address if a symbol was not
found. Ftrace relies on the original behaviour. We should not break
tracing when applying the previous patch. We can maintain the original
behaviour by checking the return code on calls to sprint_symbol() and
friends.

Check return code and print actual address on error (i.e symbol not
found).

Signed-off-by: Tobin C. Harding 
---
 kernel/trace/trace.h | 24 
 kernel/trace/trace_events_hist.c |  6 +++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 2a6d0325a761..881b1a577d75 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1814,4 +1814,28 @@ static inline void trace_event_eval_update(struct 
trace_eval_map **map, int len)
 
 extern struct trace_iterator *tracepoint_print_iter;
 
+static inline int
+trace_sprint_symbol(char *buffer, unsigned long address)
+{
+   int ret;
+
+   ret = sprint_symbol(buffer, address);
+   if (ret == -1)
+   ret = sprintf(buffer, "0x%lx", address);
+
+   return ret;
+}
+
+static inline int
+trace_sprint_symbol_no_offset(char *buffer, unsigned long address)
+{
+   int ret;
+
+   ret = sprint_symbol_no_offset(buffer, address);
+   if (ret == -1)
+   ret = sprintf(buffer, "0x%lx", address);
+
+   return ret;
+}
+
 #endif /* _LINUX_KERNEL_TRACE_H */
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 1e1558c99d56..3e28522a76f4 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -982,7 +982,7 @@ static void hist_trigger_stacktrace_print(struct seq_file 
*m,
return;
 
seq_printf(m, "%*c", 1 + spaces, ' ');
-   sprint_symbol(str, stacktrace_entries[i]);
+   trace_sprint_symbol_addr(str, stacktrace_entries[i]);
seq_printf(m, "%s\n", str);
}
 }
@@ -1014,12 +1014,12 @@ hist_trigger_entry_print(struct seq_file *m,
seq_printf(m, "%s: %llx", field_name, uval);
} else if (key_field->flags & HIST_FIELD_FL_SYM) {
uval = *(u64 *)(key + key_field->offset);
-   sprint_symbol_no_offset(str, uval);
+   trace_sprint_symbol_no_offset(str, uval);
seq_printf(m, "%s: [%llx] %-45s", field_name,
   uval, str);
} else if (key_field->flags & HIST_FIELD_FL_SYM_OFFSET) {
uval = *(u64 *)(key + key_field->offset);
-   sprint_symbol(str, uval);
+   trace_sprint_symbol(str, uval);
seq_printf(m, "%s: [%llx] %-55s", field_name,
   uval, str);
} else if (key_field->flags & HIST_FIELD_FL_EXECNAME) {
-- 
2.7.4



Re: Linux 4.14 - regression: broken tun/tap / bridge network with virtio - bisected

2017-12-17 Thread Willem de Bruijn
On Fri, Dec 15, 2017 at 1:05 AM, Andreas Hartmann
 wrote:
> On 12/14/2017 at 11:17 PM Willem de Bruijn wrote:
 Well, the patch does not fix hanging VMs, which have been shutdown and
 can't be killed any more.
 Because of the stack trace

 [] vhost_net_ubuf_put_and_wait+0x35/0x60 [vhost_net]
 [] vhost_net_ioctl+0x304/0x870 [vhost_net]
 [] do_vfs_ioctl+0x8f/0x5c0
 [] SyS_ioctl+0x74/0x80
 [] do_syscall_64+0x5b/0x100
 [] entry_SYSCALL64_slow_path+0x25/0x25
 [] 0x

 I was hoping, that the problems could be related - but that seems not to
 be true.
>>>
>>> However, it turned out, that reverting the complete patchset "Remove UDP
>>> Fragmentation Offload support" prevent hanging qemu processes.
>>
>> That implies a combination of UFO and vhost zerocopy. Disabling
>> experimental_zcopytx in vhost_net will probably work around the bug
>> then.

I have been able to reproduce the hang by sending a UFO packet
between two guests running v4.13 on a host running v4.15-rc1.

The vhost_net_ubuf_ref refcount indeed hits overflow (-1) from
vhost_zerocopy_callback being called for each segment of a
segmented UFO skb. This refcount is decremented then on each
segment, but incremented only once for the entire UFO skb.

Before v4.14, these packets would be converted in skb_segment to
regular copy packets with skb_orphan_frags and the callback function
called once at this point. v4.14 added support for reference counted
zerocopy skb that can pass through skb_orphan_frags unmodified and
have their zerocopy state safely cloned with skb_zerocopy_clone.

The call to skb_zerocopy_clone must come after skb_orphan_frags
to limit cloning of this state to those skbs that can do so safely.

Please try a host with the following patch. This fixes it for me. I intend to
send it to net.

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index a592ca025fc4..d2d985418819 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3654,8 +3654,6 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,

skb_shinfo(nskb)->tx_flags |= skb_shinfo(head_skb)->tx_flags &
  SKBTX_SHARED_FRAG;
-   if (skb_zerocopy_clone(nskb, head_skb, GFP_ATOMIC))
-   goto err;

while (pos < offset + len) {
if (i >= nfrags) {
@@ -3681,6 +3679,8 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,

if (unlikely(skb_orphan_frags(frag_skb, GFP_ATOMIC)))
goto err;
+   if (skb_zerocopy_clone(nskb, frag_skb, GFP_ATOMIC))
+   goto err;

*nskb_frag = *frag;
__skb_frag_ref(nskb_frag);


This is relatively inefficient, as it calls skb_zerocopy_clone for each frag
in the frags[] array. I will follow-up with a patch to net-next that only
checks once per skb:

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 466581cf4cdc..a293a33604ec 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3662,7 +3662,8 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,

skb_shinfo(nskb)->tx_flags |= skb_shinfo(head_skb)->tx_flags &
  SKBTX_SHARED_FRAG;
-   if (skb_zerocopy_clone(nskb, head_skb, GFP_ATOMIC))
+   if (skb_orphan_frags(frag_skb, GFP_ATOMIC) ||
+   skb_zerocopy_clone(nskb, frag_skb, GFP_ATOMIC))
goto err;

while (pos < offset + len) {
@@ -3676,6 +3677,11 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,

BUG_ON(!nfrags);

+   if (skb_orphan_frags(frag_skb, GFP_ATOMIC) ||
+   skb_zerocopy_clone(nskb, frag_skb,
+  GFP_ATOMIC))
+   goto err;
+
list_skb = list_skb->next;
}

@@ -3687,9 +3693,6 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
goto err;
}

-   if (unlikely(skb_orphan_frags(frag_skb, GFP_ATOMIC)))
-   goto err;
-

I'll also send to net-next

(1) a patch to convert its vhost_net_ ubuf_ref refcnt to refcount_t

(2) a path to skb_zerocopy_clone to warn on clone if not
 sock_zerocopy_callback

> I already tested it w/ options vhost_net experimental_zcopytx=0 - but
> this didn't "resolve" anything. See
> https://www.mail-archive.com/netdev@vger.kernel.org/msg203197.html
>
> Therefore, I think your following thoughts are lapsed unfortunately,
> aren't they?

That experiment was perhaps run before commit 0c19f846d582 ("net:
accept UFO datagrams from tuntap and packet") and hit the other UFO
bug.

[PATCH] net: ibm: emac: support RGMII-[RX|TX]ID phymode

2017-12-17 Thread Christian Lamparter
The RGMII spec allows compliance for devices that implement an internal
delay on TXC and/or RXC inside the transmitter. This patch adds the
necessary RGMII_[RX|TX]ID mode code to handle such PHYs with the
emac driver.

Signed-off-by: Christian Lamparter 
---
 drivers/net/ethernet/ibm/emac/core.c  | 3 +++
 drivers/net/ethernet/ibm/emac/emac.h  | 3 +++
 drivers/net/ethernet/ibm/emac/rgmii.c | 9 +
 3 files changed, 15 insertions(+)

diff --git a/drivers/net/ethernet/ibm/emac/core.c 
b/drivers/net/ethernet/ibm/emac/core.c
index 7feff2450ed6..820173bee168 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -201,6 +201,9 @@ static inline int emac_phy_supports_gige(int phy_mode)
 {
return  phy_mode == PHY_MODE_GMII ||
phy_mode == PHY_MODE_RGMII ||
+   phy_mode == PHY_MODE_RGMII_ID ||
+   phy_mode == PHY_MODE_RGMII_RXID ||
+   phy_mode == PHY_MODE_RGMII_TXID ||
phy_mode == PHY_MODE_SGMII ||
phy_mode == PHY_MODE_TBI ||
phy_mode == PHY_MODE_RTBI;
diff --git a/drivers/net/ethernet/ibm/emac/emac.h 
b/drivers/net/ethernet/ibm/emac/emac.h
index 5afcc27ceebb..8c6d2af7281b 100644
--- a/drivers/net/ethernet/ibm/emac/emac.h
+++ b/drivers/net/ethernet/ibm/emac/emac.h
@@ -112,6 +112,9 @@ struct emac_regs {
 #define PHY_MODE_RMII  PHY_INTERFACE_MODE_RMII
 #define PHY_MODE_SMII  PHY_INTERFACE_MODE_SMII
 #define PHY_MODE_RGMII PHY_INTERFACE_MODE_RGMII
+#define PHY_MODE_RGMII_ID  PHY_INTERFACE_MODE_RGMII_ID
+#define PHY_MODE_RGMII_RXIDPHY_INTERFACE_MODE_RGMII_RXID
+#define PHY_MODE_RGMII_TXIDPHY_INTERFACE_MODE_RGMII_TXID
 #define PHY_MODE_TBI   PHY_INTERFACE_MODE_TBI
 #define PHY_MODE_GMII  PHY_INTERFACE_MODE_GMII
 #define PHY_MODE_RTBI  PHY_INTERFACE_MODE_RTBI
diff --git a/drivers/net/ethernet/ibm/emac/rgmii.c 
b/drivers/net/ethernet/ibm/emac/rgmii.c
index c4a1ac38bba8..7963adffbb1c 100644
--- a/drivers/net/ethernet/ibm/emac/rgmii.c
+++ b/drivers/net/ethernet/ibm/emac/rgmii.c
@@ -55,6 +55,9 @@ static inline int rgmii_valid_mode(int phy_mode)
return  phy_mode == PHY_MODE_GMII ||
phy_mode == PHY_MODE_MII ||
phy_mode == PHY_MODE_RGMII ||
+   phy_mode == PHY_MODE_RGMII_ID ||
+   phy_mode == PHY_MODE_RGMII_RXID ||
+   phy_mode == PHY_MODE_RGMII_TXID ||
phy_mode == PHY_MODE_TBI ||
phy_mode == PHY_MODE_RTBI;
 }
@@ -63,6 +66,9 @@ static inline const char *rgmii_mode_name(int mode)
 {
switch (mode) {
case PHY_MODE_RGMII:
+   case PHY_MODE_RGMII_ID:
+   case PHY_MODE_RGMII_RXID:
+   case PHY_MODE_RGMII_TXID:
return "RGMII";
case PHY_MODE_TBI:
return "TBI";
@@ -81,6 +87,9 @@ static inline u32 rgmii_mode_mask(int mode, int input)
 {
switch (mode) {
case PHY_MODE_RGMII:
+   case PHY_MODE_RGMII_ID:
+   case PHY_MODE_RGMII_RXID:
+   case PHY_MODE_RGMII_TXID:
return RGMII_FER_RGMII(input);
case PHY_MODE_TBI:
return RGMII_FER_TBI(input);
-- 
2.15.1



pull-request: bpf 2017-12-17

2017-12-17 Thread Daniel Borkmann
Hi David,

The following pull-request contains BPF updates for your *net* tree.

The main changes are:

1) Fix a corner case in generic XDP where we have non-linear skbs
   but enough tailroom in the skb to not miss to linearizing there,
   from Song.

2) Fix BPF JIT bugs in s390x and ppc64 to not recache skb data when
   BPF context is not skb, from Daniel.

3) Fix a BPF JIT bug in sparc64 where recaching skb data after helper
   call would use the wrong register for the skb, from Daniel.

Please consider pulling these changes from:

  git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git

Thanks a lot!



The following changes since commit 8c8f67a46f2bf33556ad12a1971734047b60831a:

  Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf (2017-12-13 
17:30:04 -0500)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git 

for you to fetch changes up to c1b08ebe5003ae291470cb6e26923628ab19606f:

  Merge branch 'bpf-jit-fixes' (2017-12-15 09:19:37 -0800)


Alexei Starovoitov (1):
  Merge branch 'bpf-jit-fixes'

Daniel Borkmann (5):
  bpf, s390x: do not reload skb pointers in non-skb context
  bpf, ppc64: do not reload skb pointers in non-skb context
  bpf: guarantee r1 to be ctx in case of bpf_helper_changes_pkt_data
  bpf, sparc: fix usage of wrong reg for load_skb_regs after call
  bpf: add test case for ld_abs and helper changing pkt data

Song Liu (1):
  xdp: linearize skb in netif_receive_generic_xdp()

 arch/powerpc/net/bpf_jit_comp64.c   |  6 ++--
 arch/s390/net/bpf_jit_comp.c| 11 
 arch/sparc/net/bpf_jit_comp_64.c|  6 ++--
 kernel/bpf/verifier.c   |  6 
 lib/test_bpf.c  | 43 +
 net/core/dev.c  |  2 +-
 tools/testing/selftests/bpf/test_verifier.c | 24 
 7 files changed, 87 insertions(+), 11 deletions(-)


Re: [PATCH] trace: reenable preemption if we modify the ip

2017-12-17 Thread Daniel Borkmann
On 12/16/2017 03:42 AM, Josef Bacik wrote:
> From: Josef Bacik 
> 
> Things got moved around between the original bpf_override_return patches
> and the final version, and now the ftrace kprobe dispatcher assumes if
> you modified the ip that you also enabled preemption.  Make a comment of
> this and enable preemption, this fixes the lockdep splat that happened
> when using this feature.
> 
> Signed-off-by: Josef Bacik 

Applied to bpf-next with Fixes tag, thanks Josef.


Re: [PATCH bpf-next] nfp: set flags in the correct member of netdev_bpf

2017-12-17 Thread Daniel Borkmann
On 12/16/2017 01:29 AM, Jakub Kicinski wrote:
> netdev_bpf.flags is the input member for installing the program.
> netdev_bpf.prog_flags is the output member for querying.  Set
> the correct one on query.
> 
> Fixes: 92f0292b35a0 ("net: xdp: report flags program was installed with on 
> query")
> Signed-off-by: Jakub Kicinski 
> Reviewed-by: Quentin Monnet 

Yep, netdevsim had this correct. :) Applied to bpf-next, thanks Jakub!


Re: [PATCH bpf-next] libbpf: fix Makefile exit code if libelf not found

2017-12-17 Thread Daniel Borkmann
On 12/16/2017 01:19 AM, Jakub Kicinski wrote:
> /bin/sh's exit does not recognize -1 as a number, leading to
> the following error message:
> 
> /bin/sh: 1: exit: Illegal number: -1
> 
> Use 1 as the exit code.
> 
> Signed-off-by: Jakub Kicinski 
> Reviewed-by: Quentin Monnet 

Applied to bpf-next, thanks Jakub!


Re: [PATCH bpf-next 00/13] bpf: introduce function calls

2017-12-17 Thread Daniel Borkmann
On 12/15/2017 02:55 AM, Alexei Starovoitov wrote:
> First of all huge thank you to Daniel, John, Jakub, Edward and others who
> reviewed multiple iterations of this patch set over the last many months
> and to Dave and others who gave critical feedback during netconf/netdev.
> 
> The patch is solid enough and we thought through numerous corner cases,
> but it's not the end. More followups with code reorg and features to follow.
> 
> TLDR: Allow arbitrary function calls from bpf function to another bpf 
> function.
> 
> Since the beginning of bpf all bpf programs were represented as a single 
> function
> and program authors were forced to use always_inline for all functions
> in their C code. That was causing llvm to unnecessary inflate the code size
> and forcing developers to move code to header files with little code reuse.
> 
> With a bit of additional complexity teach verifier to recognize
> arbitrary function calls from one bpf function to another as long as
> all of functions are presented to the verifier as a single bpf program.
> Extended program layout:
> ..
> r1 = ..// arg1
> r2 = ..// arg2
> call pc+1  // function call pc-relative
> exit
> .. = r1// access arg1
> .. = r2// access arg2
> ..
> call pc+20 // second level of function call
> ...
> 
> It allows for better optimized code and finally allows to introduce
> the core bpf libraries that can be reused in different projects,
> since programs are no longer limited by single elf file.
> With function calls bpf can be compiled into multiple .o files.
> 
> This patch is the first step. It detects programs that contain
> multiple functions and checks that calls between them are valid.
> It splits the sequence of bpf instructions (one program) into a set
> of bpf functions that call each other. Calls to only known
> functions are allowed. Since all functions are presented to
> the verifier at once conceptually it is 'static linking'.
> 
> Future plans:
> - introduce BPF_PROG_TYPE_LIBRARY and allow a set of bpf functions
>   to be loaded into the kernel that can be later linked to other
>   programs with concrete program types. Aka 'dynamic linking'.
> 
> - introduce function pointer type and indirect calls to allow
>   bpf functions call other dynamically loaded bpf functions while
>   the caller bpf function is already executing. Aka 'runtime linking'.
>   This will be more generic and more flexible alternative
>   to bpf_tail_calls.
> 
> FAQ:
> Q: Interpreter and JIT changes mean that new instruction is introduced ?
> A: No. The call instruction technically stays the same. Now it can call
>both kernel helpers and other bpf functions.
>Calling convention stays the same as well.
>From uapi point of view the call insn got new 'relocation' BPF_PSEUDO_CALL
>similar to BPF_PSEUDO_MAP_FD 'relocation' of bpf_ldimm64 insn.
> 
> Q: What had to change on LLVM side?
> A: Trivial LLVM patch to allow calls was applied to upcoming 6.0 release:
>https://reviews.llvm.org/rL318614
>with few bugfixes as well.
>Make sure to build the latest llvm to have bpf_call support.
> 
> More details in the patches.

Series applied to bpf-next, thanks Alexei!


Re: [RFC net-next] sfp/phylink: move module EEPROM ethtool access into netdev core ethtool

2017-12-17 Thread Russell King - ARM Linux
On Sun, Dec 17, 2017 at 07:29:22PM +0100, Andrew Lunn wrote:
> On Sun, Dec 17, 2017 at 02:48:27PM +, Russell King wrote:
> > Provide a pointer to the SFP bus in struct net_device, so that the
> > ethtool module EEPROM methods can access the SFP directly, rather
> > than needing every user to provide a hook for it.
> > 
> > Signed-off-by: Russell King 
> > ---
> > Questions:
> > 1. Is it worth adding a pointer to struct net_device for these two
> >methods, rather than having multiple duplicate veneers to vector
> >the ethtool module EEPROM ioctls through to the SFP bus layer?
> > 
> > 2. Should this allow network/phy drivers to override the default -
> >the code is currently structured to allow phy drivers to override
> >network drivers implementations, which seems the wrong way around.
> 
> Hi Russell
> 
> Looking at drivers which implement reading the EEPROM, very few of
> them expose the i2c bus, as a linux i2c bus. They seem to send
> commands off to the firmware, and have it return a block of data.  So
> converting to using the generic SFP code is not going to be too easy.
> 
> Probably a low hanging fruit is to expose a few library like functions
> for parsing the EEPROM data. As you said, there seems to be a few bugs
> in the drivers with respect to actually interpreting the data. So
> having one central implementation, without bugs, would be good.
> 
> Rather than adding the sfp bus to net_device, i think phylink will get
> more use. And the default implementation of these methods can look at
> the phylink to see if there is an sfp device.

You can't layer phylink on top of phylib on top of phylink for the
situation where we have a SFP cage connected to a PHY - that's the
problem.

SFP needs to know what is happening with the net device, and when
to enable or disable the laser, and although there's notifiers for
the netdev up/down, using that is far from ideal in this case - to
do so, SFP would need the reverse phandle in DT so it knows which
network device its associated with.  I've already been there with
a previous iteration of the SFP code.

> We are unlikely to be
> able to replace phydev with phylink, but maybe all new 10Gbps PHY and
> fibre modules not hidden behind firmware could use phylink? So having
> phylink in net_device could make sense. There has been a move to
> remove phydev from the drivers private structure and use the one in
> net_device. Maybe we should do the same for phylink?

I would suggest you read the patch that adds SFP support to the 88x3310
PHY driver - that case makes no use of phylink.  As I mention above,
it's not possible to layer phylink on top of phylib.  Not only would
that lead to nested locks, but phy drivers do not have the knowledge
necessary to know when to make various phylink calls, as phylib
drivers have no clue when the network device comes up/goes down for
example.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up
According to speedtest.net: 8.21Mbps down 510kbps up


Re: [PATCH] openvswitch: Trim off padding before L3 conntrack processing

2017-12-17 Thread Pravin Shelar
On Thu, Dec 14, 2017 at 12:05 PM, Ed Swierk  wrote:
> On Wed, Dec 13, 2017 at 4:58 PM, Pravin Shelar  wrote:
>> On Tue, Dec 12, 2017 at 8:17 AM, Ed Swierk  
>> wrote:
>>> A short IPv4 packet may have up to 6 bytes of padding following the IP
>>> payload when received on an Ethernet device.
>>>
>>> In the normal IPv4 receive path, ip_rcv() trims the packet to
>>> ip_hdr->tot_len before invoking NF_INET_PRE_ROUTING hooks (including
>>> conntrack). Then any subsequent L3+ processing steps, like
>>> nf_checksum(), use skb->len as the length of the packet, rather than
>>> referring back to ip_hdr->tot_len. In the IPv6 receive path, ip6_rcv()
>>> does the same using ipv6_hdr->payload_len.
>>>
>>> In the OVS conntrack receive path, this trimming does not occur, so
>>> the checksum verification in tcp_header() fails, printing "nf_ct_tcp:
>>> bad TCP checksum". Extra zero bytes don't affect the checksum, but the
>>> length in the IP pseudoheader does. That length is based on skb->len,
>>> and without trimming, it doesn't match the length the sender used when
>>> computing the checksum.
>>>
>>> With this change, OVS conntrack trims IPv4 and IPv6 packets prior to
>>> L3 processing.
>>>
>>> Signed-off-by: Ed Swierk 
>>> ---
>>>  net/openvswitch/conntrack.c | 17 +
>>>  1 file changed, 17 insertions(+)
>>>
>>> diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
>>> index d558e882ca0c..3a7c9215c431 100644
>>> --- a/net/openvswitch/conntrack.c
>>> +++ b/net/openvswitch/conntrack.c
>>> @@ -1105,12 +1105,29 @@ int ovs_ct_execute(struct net *net, struct sk_buff 
>>> *skb,
>>>const struct ovs_conntrack_info *info)
>>>  {
>>> int nh_ofs;
>>> +   unsigned int nh_len;
>>> int err;
>>>
>>> /* The conntrack module expects to be working at L3. */
>>> nh_ofs = skb_network_offset(skb);
>>> skb_pull_rcsum(skb, nh_ofs);
>>>
>>> +   /* Trim to L3 length since nf_checksum() doesn't expect padding. */
>> Can you explore if nf_checksum can be changed to avoid the padding?
>
> The nf_ip_checksum() and nf_ip6_checksum() helper functions can easily
> be changed to avoid the padding.
>
> My worry is that conntrack is just one of many netfilter hooks that
> perform L3+ processing, and may assume that once skb->data points to
> the L3 header, skb->len reflects the length of the L3 header and
> payload. For example, in nf_conntrack_ftp.c, help() uses skb->len to
> determine the length of the FTP payload and the TCP sequence number of
> the next packet; this would be thrown off by lower-layer padding.
>
> br_netfilter, a cousin of OVS, has always preserved this
> assumption--like ip_rcv() and ip6_rcv(), br_validate_ipv4() and
> br_validate_ipv6() trim the skb to the L3 length before they invoke
> NF_INET_PRE_ROUTING hooks. Modifying OVS to fit the mold seems more
> straightforward than changing this assumption.
>
we could avoid extra processing in fast path, thats why I wanted to
explore this, But if it is too complex, I am fine with this patch.

>>> +   switch (skb->protocol) {
>>> +   case htons(ETH_P_IP):
>>> +   nh_len = ntohs(ip_hdr(skb)->tot_len);
>>> +   break;
>>> +   case htons(ETH_P_IPV6):
>>> +   nh_len = ntohs(ipv6_hdr(skb)->payload_len)
>>> +   + sizeof(struct ipv6hdr);
>>> +   break;
>>> +   default:
>>> +   nh_len = skb->len;
>>> +   }
>>> +   err = pskb_trim_rcsum(skb, nh_len);
>>> +   if (err)
>>> +   return err;
>>> +
>> In case of error skb needs to be freed.
>
> Thanks, I will fix this.
>
> --Ed


Re: [RFC net-next] sfp/phylink: move module EEPROM ethtool access into netdev core ethtool

2017-12-17 Thread Andrew Lunn
On Sun, Dec 17, 2017 at 02:48:27PM +, Russell King wrote:
> Provide a pointer to the SFP bus in struct net_device, so that the
> ethtool module EEPROM methods can access the SFP directly, rather
> than needing every user to provide a hook for it.
> 
> Signed-off-by: Russell King 
> ---
> Questions:
> 1. Is it worth adding a pointer to struct net_device for these two
>methods, rather than having multiple duplicate veneers to vector
>the ethtool module EEPROM ioctls through to the SFP bus layer?
> 
> 2. Should this allow network/phy drivers to override the default -
>the code is currently structured to allow phy drivers to override
>network drivers implementations, which seems the wrong way around.

Hi Russell

Looking at drivers which implement reading the EEPROM, very few of
them expose the i2c bus, as a linux i2c bus. They seem to send
commands off to the firmware, and have it return a block of data.  So
converting to using the generic SFP code is not going to be too easy.

Probably a low hanging fruit is to expose a few library like functions
for parsing the EEPROM data. As you said, there seems to be a few bugs
in the drivers with respect to actually interpreting the data. So
having one central implementation, without bugs, would be good.

Rather than adding the sfp bus to net_device, i think phylink will get
more use. And the default implementation of these methods can look at
the phylink to see if there is an sfp device. We are unlikely to be
able to replace phydev with phylink, but maybe all new 10Gbps PHY and
fibre modules not hidden behind firmware could use phylink? So having
phylink in net_device could make sense. There has been a move to
remove phydev from the drivers private structure and use the one in
net_device. Maybe we should do the same for phylink?

Andrew


Re: [RFC net-next] sfp/phylink: move module EEPROM ethtool access into netdev core ethtool

2017-12-17 Thread Russell King - ARM Linux
> Questions:
> 1. Is it worth adding a pointer to struct net_device for these two
>methods, rather than having multiple duplicate veneers to vector
>the ethtool module EEPROM ioctls through to the SFP bus layer?
> 
> 2. Should this allow network/phy drivers to override the default -
>the code is currently structured to allow phy drivers to override
>network drivers implementations, which seems the wrong way around.

I should also mention that there's another place that having the
sfp bus pointer in the network device comes in handy - the case
where we have a SFP module connected to a PHY rather than the MAC.

In this case, phylink itself is not used to link the SFP to the
netdev, and phylib doesn't provide the necessary hooks into the PHY
driver for the PHY driver to know when the network device comes up
or goes down.  SFP needs to know that to assert/deassert the TX
DISABLE signal to disable the module laser.

Having the net_device structure contain a pointer to the SFP bus
allows phylink or network drivers to directly inform SFP of the
state of the network device, without needing intermediaries to
forward the state.

It's possible that this may not be the best approach - the only setup
I'm aware of at present that has the "mac <-> phy <-> sfp" setup is
the Macchiatobin, but if other phys are involved, it may be better
if instead of having PHY drivers having to add support for SFP, we
instead do it in phylib.  The counter argument to that is that SFP
likely needs more in-depth knowledge of the PHY than a the generic
phylib parts could know about.

The patches as they currently stand are in my "phy" branch, browsable
via:

 http://git.armlinux.org.uk/cgit/linux-arm.git/log/?h=phy

specifically:

 sfp: use netdev sfp_bus for start/stop
 net: phy: Add SFP support to Marvell 10G PHY driver

The last patch is does not (yet) take into account the RX_LOS signal
when determining the link state, which it ought to to avoid false
link assertions as can happen when there's noise pickup by the
detector.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up
According to speedtest.net: 8.21Mbps down 510kbps up


Re: [patch net-next] mlxsw: spectrum: Add "spectrum" prefix macro

2017-12-17 Thread Joe Perches
On Sun, 2017-12-17 at 17:15 +0100, Jiri Pirko wrote:
> From: Arkadi Sharshevsky 
> 
> Add "spectrum" string prefix macro for error strings.
[]
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c 
> b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
[]
> @@ -4168,13 +4168,11 @@ mlxsw_sp_master_lag_check(struct mlxsw_sp *mlxsw_sp,
>   u16 lag_id;
>  
>   if (mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, _id) != 0) {
> - NL_SET_ERR_MSG(extack,
> -"spectrum: Exceeded number of supported LAG 
> devices");
> + NL_SET_ERR_MSG(extack, MLXSW_SP_PREFIX "Exceeded number of 
> supported LAG devices");

Perhaps use NL_SET_ERR_MSG_MOD instead.

etc...



[patch net] mlxsw: spectrum_router: Remove batch neighbour deletion causing FW bug

2017-12-17 Thread Jiri Pirko
From: Petr Machata 

This reverts commit 63dd00fa3e524c27cc0509190084ab147ecc8ae2.

RAUHT DELETE_ALL seems to trigger a bug in FW. That manifests by later
calls to RAUHT ADD of an IPv6 neighbor to fail with "bad parameter"
error code.

Signed-off-by: Petr Machata 
Fixes: 63dd00fa3e52 ("mlxsw: spectrum_router: Add batch neighbour deletion")
Reviewed-by: Ido Schimmel 
Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 15 +++
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 72ef4f8..be657b8 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -2436,25 +2436,16 @@ static void mlxsw_sp_neigh_fini(struct mlxsw_sp 
*mlxsw_sp)
rhashtable_destroy(_sp->router->neigh_ht);
 }
 
-static int mlxsw_sp_neigh_rif_flush(struct mlxsw_sp *mlxsw_sp,
-   const struct mlxsw_sp_rif *rif)
-{
-   char rauht_pl[MLXSW_REG_RAUHT_LEN];
-
-   mlxsw_reg_rauht_pack(rauht_pl, MLXSW_REG_RAUHT_OP_WRITE_DELETE_ALL,
-rif->rif_index, rif->addr);
-   return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(rauht), rauht_pl);
-}
-
 static void mlxsw_sp_neigh_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
 struct mlxsw_sp_rif *rif)
 {
struct mlxsw_sp_neigh_entry *neigh_entry, *tmp;
 
-   mlxsw_sp_neigh_rif_flush(mlxsw_sp, rif);
list_for_each_entry_safe(neigh_entry, tmp, >neigh_list,
-rif_list_node)
+rif_list_node) {
+   mlxsw_sp_neigh_entry_update(mlxsw_sp, neigh_entry, false);
mlxsw_sp_neigh_entry_destroy(mlxsw_sp, neigh_entry);
+   }
 }
 
 enum mlxsw_sp_nexthop_type {
-- 
2.9.5



[patch net-next] mlxsw: spectrum: Add "spectrum" prefix macro

2017-12-17 Thread Jiri Pirko
From: Arkadi Sharshevsky 

Add "spectrum" string prefix macro for error strings.

Signed-off-by: Arkadi Sharshevsky 
Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 23 ++-
 drivers/net/ethernet/mellanox/mlxsw/spectrum.h |  2 ++
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index d373df7..57e5ab4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -4168,13 +4168,11 @@ mlxsw_sp_master_lag_check(struct mlxsw_sp *mlxsw_sp,
u16 lag_id;
 
if (mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, _id) != 0) {
-   NL_SET_ERR_MSG(extack,
-  "spectrum: Exceeded number of supported LAG 
devices");
+   NL_SET_ERR_MSG(extack, MLXSW_SP_PREFIX "Exceeded number of 
supported LAG devices");
return false;
}
if (lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
-   NL_SET_ERR_MSG(extack,
-  "spectrum: LAG device using unsupported Tx 
type");
+   NL_SET_ERR_MSG(extack, MLXSW_SP_PREFIX "LAG device using 
unsupported Tx type");
return false;
}
return true;
@@ -4416,15 +4414,14 @@ static int mlxsw_sp_netdevice_port_upper_event(struct 
net_device *lower_dev,
!netif_is_lag_master(upper_dev) &&
!netif_is_bridge_master(upper_dev) &&
!netif_is_ovs_master(upper_dev)) {
-   NL_SET_ERR_MSG(extack,
-  "spectrum: Unknown upper device type");
+   NL_SET_ERR_MSG(extack, MLXSW_SP_PREFIX "Unknown upper 
device type");
return -EINVAL;
}
if (!info->linking)
break;
if (netdev_has_any_upper_dev(upper_dev)) {
NL_SET_ERR_MSG(extack,
-  "spectrum: Enslaving a port to a device 
that already has an upper device is not supported");
+  MLXSW_SP_PREFIX "Enslaving a port to a 
device that already has an upper device is not supported");
return -EINVAL;
}
if (netif_is_lag_master(upper_dev) &&
@@ -4433,23 +4430,23 @@ static int mlxsw_sp_netdevice_port_upper_event(struct 
net_device *lower_dev,
return -EINVAL;
if (netif_is_lag_master(upper_dev) && vlan_uses_dev(dev)) {
NL_SET_ERR_MSG(extack,
-  "spectrum: Master device is a LAG master 
and this device has a VLAN");
+  MLXSW_SP_PREFIX "Master device is a LAG 
master and this device has a VLAN");
return -EINVAL;
}
if (netif_is_lag_port(dev) && is_vlan_dev(upper_dev) &&
!netif_is_lag_master(vlan_dev_real_dev(upper_dev))) {
NL_SET_ERR_MSG(extack,
-  "spectrum: Can not put a VLAN on a LAG 
port");
+  MLXSW_SP_PREFIX "Can not put a VLAN on a 
LAG port");
return -EINVAL;
}
if (netif_is_ovs_master(upper_dev) && vlan_uses_dev(dev)) {
NL_SET_ERR_MSG(extack,
-  "spectrum: Master device is an OVS 
master and this device has a VLAN");
+  MLXSW_SP_PREFIX "Master device is an OVS 
master and this device has a VLAN");
return -EINVAL;
}
if (netif_is_ovs_port(dev) && is_vlan_dev(upper_dev)) {
NL_SET_ERR_MSG(extack,
-  "spectrum: Can not put a VLAN on an OVS 
port");
+  MLXSW_SP_PREFIX "Can not put a VLAN on 
an OVS port");
return -EINVAL;
}
break;
@@ -4561,13 +4558,13 @@ static int mlxsw_sp_netdevice_port_vlan_event(struct 
net_device *vlan_dev,
case NETDEV_PRECHANGEUPPER:
upper_dev = info->upper_dev;
if (!netif_is_bridge_master(upper_dev)) {
-   NL_SET_ERR_MSG(extack, "spectrum: VLAN devices only 
support bridge and VRF uppers");
+   NL_SET_ERR_MSG(extack, MLXSW_SP_PREFIX "VLAN devices 
only support bridge and VRF uppers");
return -EINVAL;
}
if (!info->linking)
break;
if (netdev_has_any_upper_dev(upper_dev)) {
-   NL_SET_ERR_MSG(extack, 

Re: BUG: KASAN: use-after-free in fib_table_flush

2017-12-17 Thread Ido Schimmel
+Alexander

On Sun, Dec 17, 2017 at 08:55:57PM +0800, Fengguang Wu wrote:
> Hello,
> 
> FYI this happens in mainline kernel 4.15.0-rc3.
> It looks like a new regression.
> 
> It occurs in 4 out of 28 boots.
> 
> [  166.090516] 
> ==
> [  166.092419] BUG: KASAN: use-after-free in fib_table_flush+0x76c/0x870:
>   fib_table_flush at 
> net/ipv4/fib_trie.c:1868
> [  166.092907] Read of size 8 at addr 880012fc0b18 by task 
> kworker/u2:3/173
> [  166.093402]
> [  166.093528] CPU: 0 PID: 173 Comm: kworker/u2:3 Not tainted 4.15.0-rc3 #31
> [  166.094018] Workqueue: netns cleanup_net
> [  166.094298] Call Trace:
> [  166.094489]  print_address_description+0xa6/0x370:
>   print_address_description at 
> mm/kasan/report.c:253
> [  166.094867]  ? fib_table_flush+0x76c/0x870:
>   fib_table_flush at 
> net/ipv4/fib_trie.c:1868
> [  166.095159]  kasan_report+0x226/0x330:
>   kasan_report_error at 
> mm/kasan/report.c:352
>(inlined by) kasan_report at 
> mm/kasan/report.c:409
> [  166.095420]  fib_table_flush+0x76c/0x870:
>   fib_table_flush at 
> net/ipv4/fib_trie.c:1868
> [  166.095698]  ? fib_table_flush_external+0x5a0/0x5a0:
>   fib_table_flush at 
> net/ipv4/fib_trie.c:1836
> [  166.096067]  ? ip_fib_net_exit+0x94/0x360:
>   ip_fib_net_exit at 
> net/ipv4/fib_frontend.c:1313 (discriminator 16)
> [  166.096350]  ip_fib_net_exit+0x228/0x360:
>   ip_fib_net_exit at 
> net/ipv4/fib_frontend.c:1316
> [  166.096629]  ? ip_fib_net_exit+0x360/0x360:
>   fib_net_exit at 
> net/ipv4/fib_frontend.c:1355
> [  166.096930]  ops_exit_list+0xa8/0x160
> [  166.097233]  cleanup_net+0x414/0x860:
>   cleanup_net at 
> net/core/net_namespace.c:483 (discriminator 9)
> [  166.097487]  ? net_drop_ns+0x80/0x80:
>   cleanup_net at 
> net/core/net_namespace.c:439
> [  166.097748]  ? kvm_sched_clock_read+0x5/0x10:
>   kvm_sched_clock_read at 
> arch/x86/kernel/kvmclock.c:101
> [  166.098051]  ? native_sched_clock_from_tsc+0x40/0x70:
>   __preempt_count_dec_and_test at 
> arch/x86/include/asm/preempt.h:91
>(inlined by) cyc2ns_read_end 
> at arch/x86/kernel/tsc.c:81
>(inlined by) cycles_2_ns at 
> arch/x86/kernel/tsc.c:135
>(inlined by) 
> native_sched_clock_from_tsc at arch/x86/kernel/tsc.c:219
> [  166.098399]  ? sched_clock_cpu+0xf/0x70:
>   sched_clock_cpu at 
> kernel/sched/clock.c:363
> [  166.098672]  ? __lock_acquire+0x3b2/0x1fc0
> [  166.099054]  ? lock_downgrade+0x6a0/0x6a0:
>   lock_release at 
> kernel/locking/lockdep.c:4013
> [  166.099337]  ? lock_acquire+0x117/0x260:
>   get_current at 
> arch/x86/include/asm/current.h:15
>(inlined by) lock_acquire at 
> kernel/locking/lockdep.c:4006
> [  166.099609]  ? process_one_work+0x70f/0x11c0:
>   process_one_work at 
> kernel/workqueue.c:2087
> [  166.099938]  process_one_work+0x791/0x11c0:
>   process_one_work at 
> kernel/workqueue.c:2118
> [  166.100229]  ? kvm_sched_clock_read+0x5/0x10:
>   kvm_sched_clock_read at 
> arch/x86/kernel/kvmclock.c:101
> [  166.100532]  ? sched_clock+0x2d/0x40:
>   paravirt_sched_clock at 
> arch/x86/include/asm/paravirt.h:174
>(inlined by) sched_clock at 
> arch/x86/kernel/tsc.c:227
> [  166.100792]  ? cancel_delayed_work_sync+0x20/0x20:
>   process_one_work at 
> kernel/workqueue.c:2014
> [  166.101123]  worker_thread+0xe8/0x1070:
>   __read_once_size at 
> include/linux/compiler.h:183
>(inlined by) list_empty at 
> include/linux/list.h:203
>(inlined by) worker_thread at 
> kernel/workqueue.c:2247
> [  166.101392]  ? __kthread_parkme+0x164/0x230:
>   __kthread_parkme at 
> kernel/kthread.c:188
> [  166.101689]  ? 

Re: [patch iproute2] tc: implement filter block sharing to ingress and clsact qdiscs

2017-12-17 Thread Jiri Pirko
Sat, Dec 16, 2017 at 07:12:51PM CET, step...@networkplumber.org wrote:
>On Wed, 13 Dec 2017 16:13:57 +0100
>Jiri Pirko  wrote:
>
>> From: Jiri Pirko 
>> 
>> Signed-off-by: Jiri Pirko 
>
>This needs to wait until block sharing makes it into net-next upstream.

Sure. I like to send the userspace patch alongside with the kernel
patchset so the reviewers have full view. I hope you don't mind


[PATCH 0/4] bcm63xx_enet: remove mac_id usage

2017-12-17 Thread Jonas Gorski
This patchset aims at reducing the platform device id number usage with
the target of making it eventually possible to probe the driver through OF.

Runtested on BCM6358.

Since the patches touch mostly net/, they should go through net-next.

Jonas Gorski (4):
  bcm63xx_enet: just use "enet" as the clock name
  bcm63xx_enet: use platform data for dma channel numbers
  bcm63xx_enet: remove pointless mac_id check
  bcm63xx_enet: use platform device id directly for miibus name

 arch/mips/bcm63xx/dev-enet.c|  8 
 .../include/asm/mach-bcm63xx/bcm63xx_dev_enet.h |  4 
 drivers/net/ethernet/broadcom/bcm63xx_enet.c| 21 +
 drivers/net/ethernet/broadcom/bcm63xx_enet.h|  3 ---
 4 files changed, 17 insertions(+), 19 deletions(-)

-- 
1.9.1



[PATCH 1/4] bcm63xx_enet: just use "enet" as the clock name

2017-12-17 Thread Jonas Gorski
Now that we have the individual clocks available as "enet" we
don't need to rely on the device id for them anymore.

Signed-off-by: Jonas Gorski 
---
 drivers/net/ethernet/broadcom/bcm63xx_enet.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c 
b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index d9346e2ac720..5a5886345da2 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -1716,7 +1716,6 @@ static int bcm_enet_probe(struct platform_device *pdev)
struct bcm63xx_enet_platform_data *pd;
struct resource *res_mem, *res_irq, *res_irq_rx, *res_irq_tx;
struct mii_bus *bus;
-   const char *clk_name;
int i, ret;
 
if (!bcm_enet_shared_base[0])
@@ -1757,14 +1756,12 @@ static int bcm_enet_probe(struct platform_device *pdev)
if (priv->mac_id == 0) {
priv->rx_chan = 0;
priv->tx_chan = 1;
-   clk_name = "enet0";
} else {
priv->rx_chan = 2;
priv->tx_chan = 3;
-   clk_name = "enet1";
}
 
-   priv->mac_clk = devm_clk_get(>dev, clk_name);
+   priv->mac_clk = devm_clk_get(>dev, "enet");
if (IS_ERR(priv->mac_clk)) {
ret = PTR_ERR(priv->mac_clk);
goto out;
-- 
2.13.2



[PATCH 3/4] bcm63xx_enet: remove pointless mac_id check

2017-12-17 Thread Jonas Gorski
Enabling the ephy clock for mac 1 is harmless, and the actual usage of
the ephy is not restricted to mac 0, so we might as well remove the
check.

Signed-off-by: Jonas Gorski 
---
 drivers/net/ethernet/broadcom/bcm63xx_enet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c 
b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index e603a6fe6349..d4519c621d08 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -1787,7 +1787,7 @@ static int bcm_enet_probe(struct platform_device *pdev)
priv->tx_chan = pd->tx_chan;
}
 
-   if (priv->mac_id == 0 && priv->has_phy && !priv->use_external_mii) {
+   if (priv->has_phy && !priv->use_external_mii) {
/* using internal PHY, enable clock */
priv->phy_clk = devm_clk_get(>dev, "ephy");
if (IS_ERR(priv->phy_clk)) {
-- 
2.13.2



[PATCH 4/4] bcm63xx_enet: use platform device id directly for miibus name

2017-12-17 Thread Jonas Gorski
Directly use the platform device for generating the miibus name. This
removes the last user of bcm_enet_priv::mac_id and we can remove the
field.

Signed-off-by: Jonas Gorski 
---
 drivers/net/ethernet/broadcom/bcm63xx_enet.c | 3 +--
 drivers/net/ethernet/broadcom/bcm63xx_enet.h | 3 ---
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c 
b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index d4519c621d08..1fbbbabe7588 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -1750,7 +1750,6 @@ static int bcm_enet_probe(struct platform_device *pdev)
dev->irq = priv->irq = res_irq->start;
priv->irq_rx = res_irq_rx->start;
priv->irq_tx = res_irq_tx->start;
-   priv->mac_id = pdev->id;
 
priv->mac_clk = devm_clk_get(>dev, "enet");
if (IS_ERR(priv->mac_clk)) {
@@ -1818,7 +1817,7 @@ static int bcm_enet_probe(struct platform_device *pdev)
bus->priv = priv;
bus->read = bcm_enet_mdio_read_phylib;
bus->write = bcm_enet_mdio_write_phylib;
-   sprintf(bus->id, "%s-%d", pdev->name, priv->mac_id);
+   sprintf(bus->id, "%s-%d", pdev->name, pdev->id);
 
/* only probe bus where we think the PHY is, because
 * the mdio read operation return 0 instead of 0x
diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.h 
b/drivers/net/ethernet/broadcom/bcm63xx_enet.h
index 5a66728d4776..1d3c917eb830 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.h
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.h
@@ -193,9 +193,6 @@ struct bcm_enet_mib_counters {
 
 struct bcm_enet_priv {
 
-   /* mac id (from platform device id) */
-   int mac_id;
-
/* base remapped address of device */
void __iomem *base;
 
-- 
2.13.2



[PATCH 2/4] bcm63xx_enet: use platform data for dma channel numbers

2017-12-17 Thread Jonas Gorski
To reduce the reliance on device ids, pass the dma channel numbers to
the enet devices as platform data.

Signed-off-by: Jonas Gorski 
---
 arch/mips/bcm63xx/dev-enet.c  |  8 
 arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_enet.h |  4 
 drivers/net/ethernet/broadcom/bcm63xx_enet.c  | 11 ++-
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/arch/mips/bcm63xx/dev-enet.c b/arch/mips/bcm63xx/dev-enet.c
index e8284771d620..07b4c65a88a4 100644
--- a/arch/mips/bcm63xx/dev-enet.c
+++ b/arch/mips/bcm63xx/dev-enet.c
@@ -265,6 +265,14 @@ int __init bcm63xx_enet_register(int unit,
dpd->dma_chan_width = ENETDMA_CHAN_WIDTH;
}
 
+   if (unit == 0) {
+   dpd->rx_chan = 0;
+   dpd->tx_chan = 1;
+   } else {
+   dpd->rx_chan = 2;
+   dpd->tx_chan = 3;
+   }
+
ret = platform_device_register(pdev);
if (ret)
return ret;
diff --git a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_enet.h 
b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_enet.h
index c0bd47444cff..da39e4d326ba 100644
--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_enet.h
+++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_enet.h
@@ -55,6 +55,10 @@ struct bcm63xx_enet_platform_data {
 
/* DMA descriptor shift */
unsigned int dma_desc_shift;
+
+   /* dma channel ids */
+   int rx_chan;
+   int tx_chan;
 };
 
 /*
diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c 
b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index 5a5886345da2..e603a6fe6349 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -1752,15 +1752,6 @@ static int bcm_enet_probe(struct platform_device *pdev)
priv->irq_tx = res_irq_tx->start;
priv->mac_id = pdev->id;
 
-   /* get rx & tx dma channel id for this mac */
-   if (priv->mac_id == 0) {
-   priv->rx_chan = 0;
-   priv->tx_chan = 1;
-   } else {
-   priv->rx_chan = 2;
-   priv->tx_chan = 3;
-   }
-
priv->mac_clk = devm_clk_get(>dev, "enet");
if (IS_ERR(priv->mac_clk)) {
ret = PTR_ERR(priv->mac_clk);
@@ -1792,6 +1783,8 @@ static int bcm_enet_probe(struct platform_device *pdev)
priv->dma_chan_width = pd->dma_chan_width;
priv->dma_has_sram = pd->dma_has_sram;
priv->dma_desc_shift = pd->dma_desc_shift;
+   priv->rx_chan = pd->rx_chan;
+   priv->tx_chan = pd->tx_chan;
}
 
if (priv->mac_id == 0 && priv->has_phy && !priv->use_external_mii) {
-- 
2.13.2



Re: [PATCH net-next 2/2 v8] net: ethernet: Add a driver for Gemini gigabit ethernet

2017-12-17 Thread Linus Walleij
On Mon, Dec 11, 2017 at 8:16 PM, David Miller  wrote:
> From: Linus Walleij 

>> +if NET_VENDOR_CORTINA
>> +
>> +config GEMINI_ETHERNET
>> + tristate "Gemini Gigabit Ethernet support"
>> + depends on ARCH_GEMINI
>> + depends on OF
>> + select PHYLIB
>> + select CRC32
>> + ---help---
>> +   This driver supports StorLink SL351x (Gemini) dual Gigabit Ethernet.
>
> Make this driver buildable anywhere, you don't use any platform architecture
> specific features.

I pushed the recent v9 set where I remove the dep on ARCH_GEMINI
and the autobuilders complain a lot about the use of dma_to_pfn()
which turns out to be a ARM thing from 
included from .

I will try switching to functions from the generic dma-mapping API
and fix it up and send a v10.

Yours,
Linus Walleij


[RFC net-next] sfp/phylink: move module EEPROM ethtool access into netdev core ethtool

2017-12-17 Thread Russell King
Provide a pointer to the SFP bus in struct net_device, so that the
ethtool module EEPROM methods can access the SFP directly, rather
than needing every user to provide a hook for it.

Signed-off-by: Russell King 
---
Questions:
1. Is it worth adding a pointer to struct net_device for these two
   methods, rather than having multiple duplicate veneers to vector
   the ethtool module EEPROM ioctls through to the SFP bus layer?

2. Should this allow network/phy drivers to override the default -
   the code is currently structured to allow phy drivers to override
   network drivers implementations, which seems the wrong way around.

 drivers/net/phy/phylink.c | 28 
 drivers/net/phy/sfp-bus.c |  6 ++
 include/linux/netdevice.h |  3 +++
 include/linux/phylink.h   |  3 ---
 net/core/ethtool.c|  7 +++
 5 files changed, 12 insertions(+), 35 deletions(-)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index db5d5726ced9..0f59d7149a61 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -1247,34 +1247,6 @@ int phylink_ethtool_set_pauseparam(struct phylink *pl,
 }
 EXPORT_SYMBOL_GPL(phylink_ethtool_set_pauseparam);
 
-int phylink_ethtool_get_module_info(struct phylink *pl,
-   struct ethtool_modinfo *modinfo)
-{
-   int ret = -EOPNOTSUPP;
-
-   WARN_ON(!lockdep_rtnl_is_held());
-
-   if (pl->sfp_bus)
-   ret = sfp_get_module_info(pl->sfp_bus, modinfo);
-
-   return ret;
-}
-EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_info);
-
-int phylink_ethtool_get_module_eeprom(struct phylink *pl,
- struct ethtool_eeprom *ee, u8 *buf)
-{
-   int ret = -EOPNOTSUPP;
-
-   WARN_ON(!lockdep_rtnl_is_held());
-
-   if (pl->sfp_bus)
-   ret = sfp_get_module_eeprom(pl->sfp_bus, ee, buf);
-
-   return ret;
-}
-EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_eeprom);
-
 /**
  * phylink_ethtool_get_eee_err() - read the energy efficient ethernet error
  *   counter
diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c
index 1356dba0d9d3..4d61099b1357 100644
--- a/drivers/net/phy/sfp-bus.c
+++ b/drivers/net/phy/sfp-bus.c
@@ -321,6 +321,7 @@ static int sfp_register_bus(struct sfp_bus *bus)
}
if (bus->started)
bus->socket_ops->start(bus->sfp);
+   bus->netdev->sfp_bus = bus;
bus->registered = true;
return 0;
 }
@@ -335,6 +336,7 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
if (bus->phydev && ops && ops->disconnect_phy)
ops->disconnect_phy(bus->upstream);
}
+   bus->netdev->sfp_bus = NULL;
bus->registered = false;
 }
 
@@ -350,8 +352,6 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
  */
 int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
 {
-   if (!bus->registered)
-   return -ENOIOCTLCMD;
return bus->socket_ops->module_info(bus->sfp, modinfo);
 }
 EXPORT_SYMBOL_GPL(sfp_get_module_info);
@@ -370,8 +370,6 @@ EXPORT_SYMBOL_GPL(sfp_get_module_info);
 int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
  u8 *data)
 {
-   if (!bus->registered)
-   return -ENOIOCTLCMD;
return bus->socket_ops->module_eeprom(bus->sfp, ee, data);
 }
 EXPORT_SYMBOL_GPL(sfp_get_module_eeprom);
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index ef789e1d679e..99a0a155c319 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -57,6 +57,7 @@ struct device;
 struct phy_device;
 struct dsa_port;
 
+struct sfp_bus;
 /* 802.11 specific */
 struct wireless_dev;
 /* 802.15.4 specific */
@@ -1644,6 +1645,7 @@ enum netdev_priv_flags {
  * @priomap:   XXX: need comments on this one
  * @phydev:Physical device may attach itself
  * for hardware timestamping
+ * @sfp_bus:   attached  sfp_bus structure.
  *
  * @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock
  * @qdisc_running_key: lockdep class annotating Qdisc->running seqcount
@@ -1922,6 +1924,7 @@ struct net_device {
struct netprio_map __rcu *priomap;
 #endif
struct phy_device   *phydev;
+   struct sfp_bus  *sfp_bus;
struct lock_class_key   *qdisc_tx_busylock;
struct lock_class_key   *qdisc_running_key;
boolproto_down;
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index bd137c273d38..618fa5e83564 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -211,9 +211,6 @@ void phylink_ethtool_get_pauseparam(struct phylink *,
struct ethtool_pauseparam *);
 int phylink_ethtool_set_pauseparam(struct phylink *,
   

Re: [PATCH iproute2] ip route: broken logic when using default word and family not specified

2017-12-17 Thread Alexander Zubkov
OK. I have found the recommendations for kernel developers and
resubmited both of my patches according to their guidelines (I hope).
I have used my other e-mail because I think gmail is not good with
text email format.

On Sat, Dec 16, 2017 at 10:21 PM, Stephen Hemminger
 wrote:
> On Sat, 18 Nov 2017 14:12:48 +0100
> Alexander Zubkov  wrote:
>
>> Hello,
>>
>> I have found odd behaviour when using "ip route list" (and other bound
>> commands) with prefix "default".
>>
>> When family not specified, its value is completely ignored and "ip
>> route list default" shows all inet4 prefixes. Same do "ip route list
>> exact default" and "ip route list match default". Examples are at the
>> end of the message.
>>
>> When family is specified, the behaviour changes and default works as
>> expected (=0.0.0.0/0 for inet4 and =::/0 for inet6). The above
>> commands all shows only default prefix in the output and only "root
>> default" shows all prefixes.
>>
>> I tried to dig into the code and found that when default is using with
>> unspecified family - the resulting structures filter.[mr]dst will
>> actually become all-zeroes as in the case when nothing is specified.
>>
>> I propose to change this in such a way (see attached patch). When
>> default prefix is parsed, the flag PREFIXLEN_SPECIFIED is attached to
>> it too, like for prefixes with "/". It seems logical to me,
>> because "/0" is really implied by "default" and even directly set up
>> in the code:
>>
>> dst->bitlen = 0;
>>
>> Then during filtering there is additional logic for unspecified family
>> and specified prefix.
>>
>> With this patch ip route list commands shown above are working as
>> expected. And it also works with unspecified table when routes are
>> printed from different families.
>>
>> Examples after applying the patch:
>>
>> # ./ip route list
>> default via 192.168.0.2 dev eth0
>> 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.1
>> 192.168.1.0/24 via 192.168.0.3 dev eth0
>> # ./ip -6 route list
>> fe80::/64 dev eth0 proto kernel metric 256 pref medium
>> fe80:1::/64 via fe80::3 dev eth0 metric 1024 pref medium
>> default via fe80::2 dev eth0 metric 1024 pref medium
>> # ./ip route list default
>> default via 192.168.0.2 dev eth0
>> # ./ip route list exact default
>> default via 192.168.0.2 dev eth0
>> # ./ip route list match default
>> default via 192.168.0.2 dev eth0
>> # ./ip route list root default
>> default via 192.168.0.2 dev eth0
>> 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.1
>> 192.168.1.0/24 via 192.168.0.3 dev eth0
>> # ./ip route list default table all
>> default via 192.168.0.2 dev eth0
>> unreachable default dev lo proto kernel metric 4294967295 error -101 pref 
>> medium
>> default via fe80::2 dev eth0 metric 1024 pref medium
>> unreachable default dev lo proto kernel metric 4294967295 error -101 pref 
>> medium
>> unreachable default dev lo proto kernel metric 4294967295 error -101 pref 
>> medium
>> # ./ip route list root default table all
>> default via 192.168.0.2 dev eth0
>> 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.1
>> ...
>> ff00::/8 dev eth0 table local metric 256 pref medium
>> unreachable default dev lo proto kernel metric 4294967295 error -101 pref 
>> medium
>>
>> And before patch:
>>
>> # ip route list default
>> default via 192.168.0.2 dev eth0
>> 192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.1
>> 192.168.1.0/24 via 192.168.0.3 dev eth0
>> # ip route list match default
>> default via 192.168.0.2 dev eth0
>> 192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.1
>> 192.168.1.0/24 via 192.168.0.3 dev eth0
>> # ip route list exact default
>> default via 192.168.0.2 dev eth0
>> 192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.1
>> 192.168.1.0/24 via 192.168.0.3 dev eth0
>> # ip -4 route list exact default
>> default via 192.168.0.2 dev eth0
>> # ip -6 route list exact default
>> default via fe80::2 dev eth0  metric 1024
>> # ip route list exact default table all
>> default via 192.168.0.2 dev eth0
>> 192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.1
>> ...
>> local fe80::3c09:19ff:feee:9866 dev lo  table local  proto none  metric 0
>> ff00::/8 dev eth0  table local  metric 256
>> unreachable default dev lo  table unspec  proto kernel  metric
>> 4294967295  error -101
>
> I think this is fine, and see no problem.
> The patch is missing 'Signed-off-by' line which is required for iproute2;
> the overall rules for iproute2 are (mostly) the same as the kernel.
>
> Please resubmit with Signed-off-by


[PATCH v3] iproute: list/flush/save filter also by metric

2017-12-17 Thread Alexander Zubkov
Metric is one of the "unique key" fields of the route in Linux. But
still one can not use its value in filter while running ip list.
Because of this writing checks in scripts for example is incovenient.

Signed-off-by: Alexander Zubkov 
---
 ip/iproute.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index 16eadab..32c93ed 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -126,6 +126,7 @@ static struct
int oif, oifmask;
int mark, markmask;
int realm, realmmask;
+   __u32 metric, metricmask;
inet_prefix rprefsrc;
inet_prefix rvia;
inet_prefix rdst;
@@ -288,6 +289,14 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr 
**tb, int host_len)
if ((mark ^ filter.mark) & filter.markmask)
return 0;
}
+   if (filter.metricmask) {
+   __u32 metric = 0;
+
+   if (tb[RTA_PRIORITY])
+   metric = rta_getattr_u32(tb[RTA_PRIORITY]);
+   if ((metric ^ filter.metric) & filter.metricmask)
+   return 0;
+   }
if (filter.flushb &&
r->rtm_family == AF_INET6 &&
r->rtm_dst_len == 0 &&
@@ -441,7 +450,7 @@ int print_route(const struct sockaddr_nl *who, struct 
nlmsghdr *n, void *arg)
fprintf(fp, "src %s ",
rt_addr_n2a_rta(r->rtm_family, tb[RTA_PREFSRC]));
}
-   if (tb[RTA_PRIORITY])
+   if (tb[RTA_PRIORITY] && filter.metricmask != -1)
fprintf(fp, "metric %u ", rta_getattr_u32(tb[RTA_PRIORITY]));
if (r->rtm_flags & RTNH_F_DEAD)
fprintf(fp, "dead ");
@@ -1518,6 +1527,16 @@ static int iproute_list_flush_or_save(int argc, char 
**argv, int action)
if (get_unsigned(, *argv, 0))
invarg("invalid mark value", *argv);
filter.markmask = -1;
+   } else if (matches(*argv, "metric") == 0 ||
+  matches(*argv, "priority") == 0 ||
+  strcmp(*argv, "preference") == 0) {
+   __u32 metric;
+
+   NEXT_ARG();
+   if (get_u32(, *argv, 0))
+   invarg("\"metric\" value is invalid\n", *argv);
+   filter.metric = metric;
+   filter.metricmask = -1;
} else if (strcmp(*argv, "via") == 0) {
int family;
 



RE: [PATCH net-next v5 5/5] qede: Use NETIF_F_GRO_HW.

2017-12-17 Thread Chopra, Manish
> -Original Message-
> From: Michael Chan [mailto:michael.c...@broadcom.com]
> Sent: Saturday, December 16, 2017 1:40 PM
> To: da...@davemloft.net
> Cc: netdev@vger.kernel.org; andrew.gospoda...@broadcom.com; Elior, Ariel
> ; Dept-Eng Everest Linux L2  engeverestlinu...@cavium.com>
> Subject: [PATCH net-next v5 5/5] qede: Use NETIF_F_GRO_HW.
> 
> Advertise NETIF_F_GRO_HW and set edev->gro_disable according to the feature
> flag.  Add qede_fix_features() to drop NETIF_F_GRO_HW if XDP is running or
> MTU does not support GRO_HW or GRO is not set.
> qede_change_mtu() also checks and disables GRO_HW if MTU is not supported.
> 
> Cc: Ariel Elior 
> Cc: everest-linux...@cavium.com
> Acked-by: Manish Chopra 
> Signed-off-by: Michael Chan 
> ---
>  drivers/net/ethernet/qlogic/qede/qede.h |  2 ++
>  drivers/net/ethernet/qlogic/qede/qede_ethtool.c |  3 +++
> drivers/net/ethernet/qlogic/qede/qede_filter.c  | 21 ++---
>  drivers/net/ethernet/qlogic/qede/qede_main.c| 17 ++---
>  4 files changed, 25 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/net/ethernet/qlogic/qede/qede.h
> b/drivers/net/ethernet/qlogic/qede/qede.h
> index a3a70ad..8a33651 100644
> --- a/drivers/net/ethernet/qlogic/qede/qede.h
> +++ b/drivers/net/ethernet/qlogic/qede/qede.h
> @@ -494,6 +494,8 @@ int qede_free_tx_pkt(struct qede_dev *edev,  void
> qede_vlan_mark_nonconfigured(struct qede_dev *edev);  int
> qede_configure_vlan_filters(struct qede_dev *edev);
> 
> +netdev_features_t qede_fix_features(struct net_device *dev,
> + netdev_features_t features);
>  int qede_set_features(struct net_device *dev, netdev_features_t features);
> void qede_set_rx_mode(struct net_device *ndev);  void
> qede_config_rx_mode(struct net_device *ndev); diff --git
> a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
> b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
> index dae7412..4ca3847 100644
> --- a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
> +++ b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
> @@ -940,6 +940,9 @@ int qede_change_mtu(struct net_device *ndev, int
> new_mtu)
>   DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
>  "Configuring MTU size of %d\n", new_mtu);
> 
> + if (new_mtu > PAGE_SIZE)
> + ndev->features &= ~NETIF_F_GRO_HW;
> +
>   /* Set the mtu field and re-start the interface if needed */
>   args.u.mtu = new_mtu;
>   args.func = _update_mtu;
> diff --git a/drivers/net/ethernet/qlogic/qede/qede_filter.c
> b/drivers/net/ethernet/qlogic/qede/qede_filter.c
> index c1a0708..77aa826 100644
> --- a/drivers/net/ethernet/qlogic/qede/qede_filter.c
> +++ b/drivers/net/ethernet/qlogic/qede/qede_filter.c
> @@ -895,19 +895,26 @@ static void qede_set_features_reload(struct
> qede_dev *edev,
>   edev->ndev->features = args->u.features;  }
> 
> +netdev_features_t qede_fix_features(struct net_device *dev,
> + netdev_features_t features)
> +{
> + struct qede_dev *edev = netdev_priv(dev);
> +
> + if (edev->xdp_prog || edev->ndev->mtu > PAGE_SIZE ||
> + !(features & NETIF_F_GRO))
> + features &= ~NETIF_F_GRO_HW;
> +
> + return features;
> +}
> +
>  int qede_set_features(struct net_device *dev, netdev_features_t features)  {
>   struct qede_dev *edev = netdev_priv(dev);
>   netdev_features_t changes = features ^ dev->features;
>   bool need_reload = false;
> 
> - /* No action needed if hardware GRO is disabled during driver load */
> - if (changes & NETIF_F_GRO) {
> - if (dev->features & NETIF_F_GRO)
> - need_reload = !edev->gro_disable;
> - else
> - need_reload = edev->gro_disable;
> - }
> + if (changes & NETIF_F_GRO_HW)
> + need_reload = true;
> 
>   if (need_reload) {
>   struct qede_reload_args args;
> diff --git a/drivers/net/ethernet/qlogic/qede/qede_main.c
> b/drivers/net/ethernet/qlogic/qede/qede_main.c
> index 57332b3..90d79ae 100644
> --- a/drivers/net/ethernet/qlogic/qede/qede_main.c
> +++ b/drivers/net/ethernet/qlogic/qede/qede_main.c
> @@ -545,6 +545,7 @@ static int qede_ioctl(struct net_device *dev, struct ifreq
> *ifr, int cmd)  #endif
>   .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid,
>   .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid,
> + .ndo_fix_features = qede_fix_features,
>   .ndo_set_features = qede_set_features,
>   .ndo_get_stats64 = qede_get_stats64,
>  #ifdef CONFIG_QED_SRIOV
> @@ -572,6 +573,7 @@ static int qede_ioctl(struct net_device *dev, struct ifreq
> *ifr, int cmd)
>   .ndo_change_mtu = qede_change_mtu,
>   .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid,
>   .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid,
> + .ndo_fix_features = qede_fix_features,
>   

RE: [PATCH net-next v5 4/5] bnx2x: Use NETIF_F_GRO_HW.

2017-12-17 Thread Chopra, Manish
> -Original Message-
> From: Michael Chan [mailto:michael.c...@broadcom.com]
> Sent: Saturday, December 16, 2017 1:40 PM
> To: da...@davemloft.net
> Cc: netdev@vger.kernel.org; andrew.gospoda...@broadcom.com; Elior, Ariel
> ; Dept-Eng Everest Linux L2  engeverestlinu...@cavium.com>
> Subject: [PATCH net-next v5 4/5] bnx2x: Use NETIF_F_GRO_HW.
> 
> Advertise NETIF_F_GRO_HW and turn on TPA_MODE_GRO when
> NETIF_F_GRO_HW is set.  Disable NETIF_F_GRO_HW in bnx2x_fix_features() if
> the MTU does not support TPA_MODE_GRO or GRO is not set.
> bnx2x_change_mtu() also needs to disable NETIF_F_GRO_HW if the MTU does
> not support it.
> 
> Original parameter disable_tpa will continue to disable LRO and GRO_HW.
> 
> Preserve the original behavior of enabling LRO by default.  User has to run
> ethtool -K to explicitly enable GRO_HW.
> 
> Cc: Ariel Elior 
> Cc: everest-linux...@cavium.com
> Signed-off-by: Michael Chan 
> ---
>  drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c  | 24 
>   drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c |  8 +---
>  2 files changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> index 4c739d5..01b7f2f 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> @@ -2482,8 +2482,7 @@ static void bnx2x_bz_fp(struct bnx2x *bp, int index)
>*/
>   if (bp->dev->features & NETIF_F_LRO)
>   fp->mode = TPA_MODE_LRO;
> - else if (bp->dev->features & NETIF_F_GRO &&
> -  bnx2x_mtu_allows_gro(bp->dev->mtu))
> + else if (bp->dev->features & NETIF_F_GRO_HW)
>   fp->mode = TPA_MODE_GRO;
>   else
>   fp->mode = TPA_MODE_DISABLED;
> @@ -4874,6 +4873,9 @@ int bnx2x_change_mtu(struct net_device *dev, int
> new_mtu)
>*/
>   dev->mtu = new_mtu;
> 
> + if (!bnx2x_mtu_allows_gro(new_mtu))
> + dev->features &= ~NETIF_F_GRO_HW;
> +
>   if (IS_PF(bp) && SHMEM2_HAS(bp, curr_cfg))
>   SHMEM2_WR(bp, curr_cfg, CURR_CFG_MET_OS);
> 
> @@ -4903,10 +4905,13 @@ netdev_features_t bnx2x_fix_features(struct
> net_device *dev,
>   }
> 
>   /* TPA requires Rx CSUM offloading */
> - if (!(features & NETIF_F_RXCSUM)) {
> + if (!(features & NETIF_F_RXCSUM))
> + features &= ~NETIF_F_LRO;
> +
> + if (!(features & NETIF_F_GRO) || !bnx2x_mtu_allows_gro(dev->mtu))
> + features &= ~NETIF_F_GRO_HW;
> + if (features & NETIF_F_GRO_HW)
>   features &= ~NETIF_F_LRO;
> - features &= ~NETIF_F_GRO;
> - }
> 
>   return features;
>  }
> @@ -4933,13 +4938,8 @@ int bnx2x_set_features(struct net_device *dev,
> netdev_features_t features)
>   }
>   }
> 
> - /* if GRO is changed while LRO is enabled, don't force a reload */
> - if ((changes & NETIF_F_GRO) && (features & NETIF_F_LRO))
> - changes &= ~NETIF_F_GRO;
> -
> - /* if GRO is changed while HW TPA is off, don't force a reload */
> - if ((changes & NETIF_F_GRO) && bp->disable_tpa)
> - changes &= ~NETIF_F_GRO;
> + /* Don't care about GRO changes */
> + changes &= ~NETIF_F_GRO;
> 
>   if (changes)
>   bnx2x_reload = true;
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
> b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
> index 91e2a75..4d06548 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
> @@ -12400,8 +12400,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
> 
>   /* Set TPA flags */
>   if (bp->disable_tpa) {
> - bp->dev->hw_features &= ~NETIF_F_LRO;
> - bp->dev->features &= ~NETIF_F_LRO;
> + bp->dev->hw_features &= ~(NETIF_F_LRO |
> NETIF_F_GRO_HW);
> + bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
>   }
> 
>   if (CHIP_IS_E1(bp))
> @@ -13273,7 +13273,7 @@ static int bnx2x_init_dev(struct bnx2x *bp, struct
> pci_dev *pdev,
> 
>   dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
> NETIF_F_IPV6_CSUM |
>   NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
> - NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
> + NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
> NETIF_F_GRO_HW |
>   NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
>   if (!chip_is_e1x) {
>   dev->hw_features |= NETIF_F_GSO_GRE |
> NETIF_F_GSO_GRE_CSUM | @@ -13309,6 +13309,8 @@ static int
> bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
> 
>   dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
>   dev->features |= NETIF_F_HIGHDMA;
> + if (dev->features & NETIF_F_LRO)
> + dev->features &= ~NETIF_F_GRO_HW;
> 
>   /* Add Loopback 

[PATCH] iproute: "list/flush/save default" selected all of the routes

2017-12-17 Thread Alexander Zubkov
When running "ip route list default" and not specifying address family,
one will get all of the routes instead of just default only. The same
is for "exact default" and "match default".

It behaves in such a way because default route with unspecified family
has the same all-zeroes value like no prefix specified at all. Thus
following code blindly ignores the fact, that prefix was actually
specified.

This patch adds the flag PREFIXLEN_SPECIFIED to the default route too.
And then checks its value when filtering routes.

Signed-off-by: Alexander Zubkov 
---
 ip/iproute.c | 65 ++--
 lib/utils.c  |  1 +
 2 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index 16eadab..5e96783 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -190,20 +190,42 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr 
**tb, int host_len)
return 0;
if ((filter.tos^r->rtm_tos))
return 0;
-   if (filter.rdst.family &&
-   (r->rtm_family != filter.rdst.family || filter.rdst.bitlen > 
r->rtm_dst_len))
-   return 0;
-   if (filter.mdst.family &&
-   (r->rtm_family != filter.mdst.family ||
-(filter.mdst.bitlen >= 0 && filter.mdst.bitlen < r->rtm_dst_len)))
-   return 0;
-   if (filter.rsrc.family &&
-   (r->rtm_family != filter.rsrc.family || filter.rsrc.bitlen > 
r->rtm_src_len))
-   return 0;
-   if (filter.msrc.family &&
-   (r->rtm_family != filter.msrc.family ||
-(filter.msrc.bitlen >= 0 && filter.msrc.bitlen < r->rtm_src_len)))
-   return 0;
+   if (filter.rdst.family) {
+   if (r->rtm_family != filter.rdst.family ||
+   filter.rdst.bitlen > r->rtm_dst_len)
+   return 0;
+   } else if (filter.rdst.flags & PREFIXLEN_SPECIFIED) {
+   if (filter.rdst.bitlen > r->rtm_dst_len)
+   return 0;
+   }
+   if (filter.mdst.family) {
+   if (r->rtm_family != filter.mdst.family ||
+   (filter.mdst.bitlen >= 0 &&
+filter.mdst.bitlen < r->rtm_dst_len))
+   return 0;
+   } else if (filter.mdst.flags & PREFIXLEN_SPECIFIED) {
+   if (filter.mdst.bitlen >= 0 &&
+   filter.mdst.bitlen < r->rtm_dst_len)
+   return 0;
+   }
+   if (filter.rsrc.family) {
+   if (r->rtm_family != filter.rsrc.family ||
+   filter.rsrc.bitlen > r->rtm_src_len)
+   return 0;
+   } else if (filter.rsrc.flags & PREFIXLEN_SPECIFIED) {
+   if (filter.rsrc.bitlen > r->rtm_src_len)
+   return 0;
+   }
+   if (filter.msrc.family) {
+   if (r->rtm_family != filter.msrc.family ||
+   (filter.msrc.bitlen >= 0 &&
+filter.msrc.bitlen < r->rtm_src_len))
+   return 0;
+   } else if (filter.msrc.flags & PREFIXLEN_SPECIFIED) {
+   if (filter.msrc.bitlen >= 0 &&
+   filter.msrc.bitlen < r->rtm_src_len)
+   return 0;
+   }
if (filter.rvia.family) {
int family = r->rtm_family;
 
@@ -220,7 +242,9 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr 
**tb, int host_len)
 
if (tb[RTA_DST])
memcpy(, RTA_DATA(tb[RTA_DST]), (r->rtm_dst_len+7)/8);
-   if (filter.rsrc.family || filter.msrc.family) {
+   if (filter.rsrc.family || filter.msrc.family ||
+   filter.rsrc.flags & PREFIXLEN_SPECIFIED ||
+   filter.msrc.flags & PREFIXLEN_SPECIFIED) {
if (tb[RTA_SRC])
memcpy(, RTA_DATA(tb[RTA_SRC]), 
(r->rtm_src_len+7)/8);
}
@@ -240,15 +264,18 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr 
**tb, int host_len)
memcpy(, RTA_DATA(tb[RTA_PREFSRC]), 
host_len/8);
}
 
-   if (filter.rdst.family && inet_addr_match(, , 
filter.rdst.bitlen))
+   if ((filter.rdst.family || filter.rdst.flags & PREFIXLEN_SPECIFIED) &&
+   inet_addr_match(, , filter.rdst.bitlen))
return 0;
-   if (filter.mdst.family && filter.mdst.bitlen >= 0 &&
+   if ((filter.mdst.family || filter.mdst.flags & PREFIXLEN_SPECIFIED) &&
inet_addr_match(, , r->rtm_dst_len))
return 0;
 
-   if (filter.rsrc.family && inet_addr_match(, , 
filter.rsrc.bitlen))
+   if ((filter.rsrc.family || filter.rsrc.flags & PREFIXLEN_SPECIFIED) &&
+   inet_addr_match(, , filter.rsrc.bitlen))
return 0;
-   if (filter.msrc.family && filter.msrc.bitlen >= 0 &&
+   if ((filter.msrc.family || filter.msrc.flags & PREFIXLEN_SPECIFIED) &&
+   filter.msrc.bitlen >= 0 &&

Re: Support For Charity

2017-12-17 Thread M. M. Fridman
I Mikhail Fridman. has selected you specially as one of my beneficiaries
for my Charitable Donation, Just as I have declared on May 23, 2016 to give
my fortune as charity.

Check the link below for confirmation:

http://www.ibtimes.co.uk/russias-second-wealthiest-man-mikhail-fridman-plans-leaving-14-2bn-fortune-charity-1561604

Reply as soon as possible with further directives.

Best Regards,
Mikhail Fridman.