Re: [PATCH] ARC: [plat-eznps] add missing atomic_fetch_xxx operations

2016-09-19 Thread Vineet Gupta
On 09/18/2016 10:34 PM, Noam Camus wrote:
> From: Noam Camus 
>
> Build brekeage since last changes to generic atomic operations.
> Added couple of missing macros which are now mandatory
>
> Signed-off-by: Noam Camus 

Added to for-next !

Thx,
-Vineet



> ---
>  arch/arc/include/asm/atomic.h |2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/arch/arc/include/asm/atomic.h b/arch/arc/include/asm/atomic.h
> index 4e3c1b6..4f732bf 100644
> --- a/arch/arc/include/asm/atomic.h
> +++ b/arch/arc/include/asm/atomic.h
> @@ -284,6 +284,7 @@ static inline int atomic_fetch_##op(int i, atomic_t *v)   
> \
>  ATOMIC_OPS(add, +=, CTOP_INST_AADD_DI_R2_R2_R3)
>  #define atomic_sub(i, v) atomic_add(-(i), (v))
>  #define atomic_sub_return(i, v) atomic_add_return(-(i), (v))
> +#define atomic_fetch_sub(i, v) atomic_fetch_add(-(i), (v))
>  
>  #undef ATOMIC_OPS
>  #define ATOMIC_OPS(op, c_op, asm_op) \
> @@ -292,6 +293,7 @@ ATOMIC_OPS(add, +=, CTOP_INST_AADD_DI_R2_R2_R3)
>  
>  ATOMIC_OPS(and, &=, CTOP_INST_AAND_DI_R2_R2_R3)
>  #define atomic_andnot(mask, v) atomic_and(~(mask), (v))
> +#define atomic_fetch_andnot(mask, v) atomic_fetch_and(~(mask), (v))
>  ATOMIC_OPS(or, |=, CTOP_INST_AOR_DI_R2_R2_R3)
>  ATOMIC_OPS(xor, ^=, CTOP_INST_AXOR_DI_R2_R2_R3)
>  


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 0/3] ARC unwinder switch to .eh_frame

2016-09-19 Thread Vineet Gupta
Hi Daniel,

Give these a shot and let me know if they work fine for you.
I'm working on some more improvements to unwinder which will follow
a bit later.

Thx,
-Vineet

Vineet Gupta (3):
  ARC: module: support R_ARC_32_PCREL relocation
  ARC: dw2 unwind: factor CIE specifics for .eh_frame/.debug_frame
  ARC: dw2 unwind: switch to .eh_frame based unwinding

 arch/arc/Makefile |  2 ++
 arch/arc/include/asm/elf.h|  3 +--
 arch/arc/kernel/entry.S   | 12 
 arch/arc/kernel/module.c  | 19 ---
 arch/arc/kernel/unwind.c  | 24 +---
 arch/arc/kernel/vmlinux.lds.S | 15 +--
 6 files changed, 33 insertions(+), 42 deletions(-)

-- 
2.7.4


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 3/3] ARC: dw2 unwind: switch to .eh_frame based unwinding

2016-09-19 Thread Vineet Gupta
So finally after almost 8 years of dealing with .debug_frame, we are
finally switching to .eh_frame. The reason being stripped kernel
binaries had non-functional unwinder as .debug_frame was gone.
Also, in general .eh_frame seems more common way of doing unwinding.

This also folds a revert of f52e126cc747 ("ARC: unwind: ensure that
.debug_frame is generated (vs. .eh_frame)") to ensure that we start
getting .eh_frame

Reported-by: Daniel Mentz 
Signed-off-by: Vineet Gupta 
---
 arch/arc/Makefile |  2 ++
 arch/arc/kernel/entry.S   | 12 
 arch/arc/kernel/module.c  | 13 -
 arch/arc/kernel/unwind.c  |  5 ++---
 arch/arc/kernel/vmlinux.lds.S | 15 +--
 5 files changed, 13 insertions(+), 34 deletions(-)

diff --git a/arch/arc/Makefile b/arch/arc/Makefile
index 601ed173080b..fc6ff8f09f23 100644
--- a/arch/arc/Makefile
+++ b/arch/arc/Makefile
@@ -66,6 +66,8 @@ endif
 
 endif
 
+cflags-$(CONFIG_ARC_DW2_UNWIND)+= -fasynchronous-unwind-tables
+
 # By default gcc 4.8 generates dwarf4 which kernel unwinder can't grok
 ifeq ($(atleast_gcc48),y)
 cflags-$(CONFIG_ARC_DW2_UNWIND)+= -gdwarf-2
diff --git a/arch/arc/kernel/entry.S b/arch/arc/kernel/entry.S
index 2efb0625331d..741712d4d6ff 100644
--- a/arch/arc/kernel/entry.S
+++ b/arch/arc/kernel/entry.S
@@ -61,18 +61,6 @@ ENTRY(ret_from_fork)
bret_from_exception
 END(ret_from_fork)
 
-#ifdef CONFIG_ARC_DW2_UNWIND
-; Workaround for bug 94179 (STAR ):
-; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
-; section (.debug_frame) as loadable. So we force it here.
-; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
-; would not work after a clean build due to kernel build system dependencies.
-.section .debug_frame, "wa",@progbits
-
-; Reset to .text as this file is included in entry-.S
-.section .text, "ax",@progbits
-#endif
-
 ;### Non TLB Exception Handling #
 
 ; -
diff --git a/arch/arc/kernel/module.c b/arch/arc/kernel/module.c
index 576a238434a1..9a2849756022 100644
--- a/arch/arc/kernel/module.c
+++ b/arch/arc/kernel/module.c
@@ -22,13 +22,9 @@ static inline void arc_write_me(unsigned short *addr, 
unsigned long value)
*(addr + 1) = (value & 0x);
 }
 
-/* ARC specific section quirks - before relocation loop in generic loader
- *
- * For dwarf unwinding out of modules, this needs to
- * 1. Ensure the .debug_frame is allocatable (ARC Linker bug: despite
- *-fasynchronous-unwind-tables it doesn't).
- * 2. Since we are iterating thru sec hdr tbl anyways, make a note of
- *the exact section index, for later use.
+/*
+ * This gets called before relocation loop in generic loader
+ * Make a note of the section index of unwinding section
  */
 int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
  char *secstr, struct module *mod)
@@ -40,8 +36,7 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr 
*sechdrs,
mod->arch.unw_info = NULL;
 
for (i = 1; i < hdr->e_shnum; i++) {
-   if (strcmp(secstr+sechdrs[i].sh_name, ".debug_frame") == 0) {
-   sechdrs[i].sh_flags |= SHF_ALLOC;
+   if (strcmp(secstr+sechdrs[i].sh_name, ".eh_frame") == 0) {
mod->arch.unw_sec_idx = i;
break;
}
diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
index 4e5dbe7617a1..61fd1ce63c56 100644
--- a/arch/arc/kernel/unwind.c
+++ b/arch/arc/kernel/unwind.c
@@ -111,7 +111,7 @@ UNW_REGISTER_INFO};
 #define DW_EH_PE_indirect 0x80
 #define DW_EH_PE_omit 0xff
 
-#define CIE_ID 0xUL
+#define CIE_ID 0
 
 typedef unsigned long uleb128_t;
 typedef signed long sleb128_t;
@@ -510,8 +510,7 @@ static const u32 *__cie_for_fde(const u32 *fde)
 {
const u32 *cie;
 
-   /* cie = fde + 1 - fde[1] / sizeof(*fde); */
-   cie = (u32 *) fde[1];
+   cie = fde + 1 - fde[1] / sizeof(*fde);
 
return cie;
 }
diff --git a/arch/arc/kernel/vmlinux.lds.S b/arch/arc/kernel/vmlinux.lds.S
index 894e696bddaa..bb6d8c5ff2e9 100644
--- a/arch/arc/kernel/vmlinux.lds.S
+++ b/arch/arc/kernel/vmlinux.lds.S
@@ -84,7 +84,7 @@ SECTIONS
 
/*
 * .exit.text is discard at runtime, not link time, to deal with
-* references from .debug_frame
+* references from unwinding sections
 * It will be init freed, being inside [__init_start : __init_end]
 */
.exit.text : { EXIT_TEXT }
@@ -120,18 +120,13 @@ SECTIONS
 
 #ifdef CONFIG_ARC_DW2_UNWIND
. = ALIGN(PAGE_SIZE);
-   .debug_frame  : {
+   .eh_frame  : {
__start_unwind = .;
-   *(.debug_frame)
+   *(.eh_frame)
__end_unwind = .;
}
-   /*
-* gcc 4.8 generates this for -fasynchonous-unwind-tables,
-

[PATCH 2/3] ARC: dw2 unwind: factor CIE specifics for .eh_frame/.debug_frame

2016-09-19 Thread Vineet Gupta
This paves way for switching to .eh_frame based unwindiing

Signed-off-by: Vineet Gupta 
---
 arch/arc/kernel/unwind.c | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
index 0587bf121d11..4e5dbe7617a1 100644
--- a/arch/arc/kernel/unwind.c
+++ b/arch/arc/kernel/unwind.c
@@ -111,6 +111,8 @@ UNW_REGISTER_INFO};
 #define DW_EH_PE_indirect 0x80
 #define DW_EH_PE_omit 0xff
 
+#define CIE_ID 0xUL
+
 typedef unsigned long uleb128_t;
 typedef signed long sleb128_t;
 
@@ -232,6 +234,7 @@ void __init arc_unwind_init(void)
 
 static const u32 bad_cie, not_fde;
 static const u32 *cie_for_fde(const u32 *fde, const struct unwind_table *);
+static const u32 *__cie_for_fde(const u32 *fde);
 static signed fde_pointer_type(const u32 *cie);
 
 struct eh_frame_hdr_table_entry {
@@ -338,10 +341,9 @@ static void init_unwind_hdr(struct unwind_table *table,
for (fde = table->address, tableSize = table->size, n = 0;
 tableSize;
 tableSize -= sizeof(*fde) + *fde, fde += 1 + *fde / sizeof(*fde)) {
-   /* const u32 *cie = fde + 1 - fde[1] / sizeof(*fde); */
-   const u32 *cie = (const u32 *)(fde[1]);
+   const u32 *cie = __cie_for_fde(fde);
 
-   if (fde[1] == 0x)
+   if (fde[1] == CIE_ID)
continue;   /* this is a CIE */
ptr = (const u8 *)(fde + 2);
header->table[n].start = read_pointer(&ptr,
@@ -504,6 +506,16 @@ static sleb128_t get_sleb128(const u8 **pcur, const u8 
*end)
return value;
 }
 
+static const u32 *__cie_for_fde(const u32 *fde)
+{
+   const u32 *cie;
+
+   /* cie = fde + 1 - fde[1] / sizeof(*fde); */
+   cie = (u32 *) fde[1];
+
+   return cie;
+}
+
 static const u32 *cie_for_fde(const u32 *fde, const struct unwind_table *table)
 {
const u32 *cie;
@@ -511,19 +523,18 @@ static const u32 *cie_for_fde(const u32 *fde, const 
struct unwind_table *table)
if (!*fde || (*fde & (sizeof(*fde) - 1)))
return &bad_cie;
 
-   if (fde[1] == 0x)
+   if (fde[1] == CIE_ID)
return ¬_fde;/* this is a CIE */
 
if ((fde[1] & (sizeof(*fde) - 1)))
 /* || fde[1] > (unsigned long)(fde + 1) - (unsigned long)table->address) */
return NULL;/* this is not a valid FDE */
 
-   /* cie = fde + 1 - fde[1] / sizeof(*fde); */
-   cie = (u32 *) fde[1];
+   cie = __cie_for_fde(fde);
 
if (*cie <= sizeof(*cie) + 4 || *cie >= fde[1] - sizeof(*fde)
|| (*cie & (sizeof(*cie) - 1))
-   || (cie[1] != 0x))
+   || (cie[1] != CIE_ID))
return NULL;/* this is not a (valid) CIE */
return cie;
 }
-- 
2.7.4


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 1/3] ARC: module: support R_ARC_32_PCREL relocation

2016-09-19 Thread Vineet Gupta
Signed-off-by: Vineet Gupta 
---
 arch/arc/include/asm/elf.h | 3 +--
 arch/arc/kernel/module.c   | 6 --
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/arc/include/asm/elf.h b/arch/arc/include/asm/elf.h
index 51a99e25fe33..7096f97a1434 100644
--- a/arch/arc/include/asm/elf.h
+++ b/arch/arc/include/asm/elf.h
@@ -23,8 +23,7 @@
 /* ARC Relocations (kernel Modules only) */
 #define  R_ARC_32  0x4
 #define  R_ARC_32_ME   0x1B
-#define  R_ARC_S25H_PCREL  0x10
-#define  R_ARC_S25W_PCREL  0x11
+#define  R_ARC_32_PCREL0x31
 
 /*to set parameters in the core dumps */
 #define ELF_ARCH   EM_ARCOMPACT
diff --git a/arch/arc/kernel/module.c b/arch/arc/kernel/module.c
index 376e04622962..576a238434a1 100644
--- a/arch/arc/kernel/module.c
+++ b/arch/arc/kernel/module.c
@@ -106,10 +106,12 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
 */
relo_type = ELF32_R_TYPE(rel_entry[i].r_info);
 
-   if (likely(R_ARC_32_ME == relo_type))
+   if (likely(R_ARC_32_ME == relo_type))   /* ME ( S + A ) */
arc_write_me((unsigned short *)location, relocation);
-   else if (R_ARC_32 == relo_type)
+   else if (R_ARC_32 == relo_type) /* ( S + A ) */
*((Elf32_Addr *) location) = relocation;
+   else if (R_ARC_32_PCREL == relo_type)   /* ( S + A ) - PDATA ) 
*/
+   *((Elf32_Addr *) location) = relocation - location;
else
goto relo_err;
 
-- 
2.7.4


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 0/3] ARC unwinder switch to .eh_frame

2016-09-19 Thread Daniel Mentz
Hi Vineet,

Thank you for your patches. I applied them, and verified that
unwinding works with code that is compiled into the kernel image as
well as kernel modules.
I confirmed that the .eh_frame section is present and that the
.debug_frame section is absent. I also verified that the file size of
the .ko files are small enough for our embedded platform and that
unnecessary sections like .debug_info, .debug_line, .debug_str etc.
are also absent.
Is there anything else you want me to test?
Thanks
Daniel


On Mon, Sep 19, 2016 at 2:49 PM, Vineet Gupta
 wrote:
> Hi Daniel,
>
> Give these a shot and let me know if they work fine for you.
> I'm working on some more improvements to unwinder which will follow
> a bit later.
>
> Thx,
> -Vineet
>
> Vineet Gupta (3):
>   ARC: module: support R_ARC_32_PCREL relocation
>   ARC: dw2 unwind: factor CIE specifics for .eh_frame/.debug_frame
>   ARC: dw2 unwind: switch to .eh_frame based unwinding
>
>  arch/arc/Makefile |  2 ++
>  arch/arc/include/asm/elf.h|  3 +--
>  arch/arc/kernel/entry.S   | 12 
>  arch/arc/kernel/module.c  | 19 ---
>  arch/arc/kernel/unwind.c  | 24 +---
>  arch/arc/kernel/vmlinux.lds.S | 15 +--
>  6 files changed, 33 insertions(+), 42 deletions(-)
>
> --
> 2.7.4
>

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 0/3] ARC unwinder switch to .eh_frame

2016-09-19 Thread Vineet Gupta
On 09/19/2016 06:21 PM, Daniel Mentz wrote:
> Hi Vineet,
> 
> Thank you for your patches. I applied them, and verified that
> unwinding works with code that is compiled into the kernel image as
> well as kernel modules.
> I confirmed that the .eh_frame section is present and that the
> .debug_frame section is absent. I also verified that the file size of
> the .ko files are small enough for our embedded platform and that
> unnecessary sections like .debug_info, .debug_line, .debug_str etc.
> are also absent.
> Is there anything else you want me to test?
> Thanks
> Daniel

Nope - that is it. Just wanted to make sure it is "field" tested :-)

Thx,
-Vineet


> On Mon, Sep 19, 2016 at 2:49 PM, Vineet Gupta
>  wrote:
>> Hi Daniel,
>>
>> Give these a shot and let me know if they work fine for you.
>> I'm working on some more improvements to unwinder which will follow
>> a bit later.
>>
>> Thx,
>> -Vineet
>>
>> Vineet Gupta (3):
>>   ARC: module: support R_ARC_32_PCREL relocation
>>   ARC: dw2 unwind: factor CIE specifics for .eh_frame/.debug_frame
>>   ARC: dw2 unwind: switch to .eh_frame based unwinding
>>
>>  arch/arc/Makefile |  2 ++
>>  arch/arc/include/asm/elf.h|  3 +--
>>  arch/arc/kernel/entry.S   | 12 
>>  arch/arc/kernel/module.c  | 19 ---
>>  arch/arc/kernel/unwind.c  | 24 +---
>>  arch/arc/kernel/vmlinux.lds.S | 15 +--
>>  6 files changed, 33 insertions(+), 42 deletions(-)
>>
>> --
>> 2.7.4
>>
> 


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc