[PATCH v2] csky: fix csky_cmpxchg_fixup not working

Yang Li posted 1 patch 1 month, 1 week ago
arch/csky/mm/fault.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH v2] csky: fix csky_cmpxchg_fixup not working
Posted by Yang Li 1 month, 1 week ago
In the csky_cmpxchg_fixup function, it is incorrect to use the global
 variable csky_cmpxchg_stw to determine the address where the exception
 occurred.The global variable csky_cmpxchg_stw stores the opcode at the
 time of the exception, while &csky_cmpxchg_stw shows the address where
 the exception occurred.

Signed-off-by: Yang Li <yang.li85200@gmail.com>
---
V1 -> V2:Eliminate compilation warnings

 arch/csky/mm/fault.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
index a885518ce1dd..5226bc08c336 100644
--- a/arch/csky/mm/fault.c
+++ b/arch/csky/mm/fault.c
@@ -45,8 +45,8 @@ static inline void csky_cmpxchg_fixup(struct pt_regs *regs)
 	if (trap_no(regs) != VEC_TLBMODIFIED)
 		return;
 
-	if (instruction_pointer(regs) == csky_cmpxchg_stw)
-		instruction_pointer_set(regs, csky_cmpxchg_ldw);
+	if (instruction_pointer(regs) == (unsigned long)&csky_cmpxchg_stw)
+		instruction_pointer_set(regs, (unsigned long)&csky_cmpxchg_ldw);
 	return;
 }
 #endif
-- 
2.34.1
Re: [PATCH v2] csky: fix csky_cmpxchg_fixup not working
Posted by Guo Ren 1 month, 1 week ago
On Wed, Oct 16, 2024 at 5:56 PM Yang Li <yang.li85200@gmail.com> wrote:
>
> In the csky_cmpxchg_fixup function, it is incorrect to use the global
>  variable csky_cmpxchg_stw to determine the address where the exception
>  occurred.The global variable csky_cmpxchg_stw stores the opcode at the
>  time of the exception, while &csky_cmpxchg_stw shows the address where
>  the exception occurred.
>
> Signed-off-by: Yang Li <yang.li85200@gmail.com>
> ---
> V1 -> V2:Eliminate compilation warnings
>
>  arch/csky/mm/fault.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
> index a885518ce1dd..5226bc08c336 100644
> --- a/arch/csky/mm/fault.c
> +++ b/arch/csky/mm/fault.c
> @@ -45,8 +45,8 @@ static inline void csky_cmpxchg_fixup(struct pt_regs *regs)
>         if (trap_no(regs) != VEC_TLBMODIFIED)
>                 return;
>
> -       if (instruction_pointer(regs) == csky_cmpxchg_stw)
> -               instruction_pointer_set(regs, csky_cmpxchg_ldw);
> +       if (instruction_pointer(regs) == (unsigned long)&csky_cmpxchg_stw)
> +               instruction_pointer_set(regs, (unsigned long)&csky_cmpxchg_ldw);
csky_cmpxchg_ldw(stw) is a label symbol, not a variable.

arch/csky/kernel/atomic.S:
GLOBAL(csky_cmpxchg_ldw)
GLOBAL(csky_cmpxchg_stw)

Your modification does not affect the ASM output.

(gdb) p main
$1 = {void (void)} 0x5fa <main>
(gdb) p &main
$2 = (void (*)(void)) 0x5fa <main>

>         return;
>  }
>  #endif
> --
> 2.34.1
>


-- 
Best Regards
 Guo Ren
Re: [PATCH v2] csky: fix csky_cmpxchg_fixup not working
Posted by yang li 1 month ago
Hi Guo Ren:
In C language, your conclusion is correct, but in assembly language,
 global_symbol != &global_symbol
I did the following experiment:

liyang@liyang-virtual-machine:~/Desktop/test$ ls
main.c  test.s
liyang@liyang-virtual-machine:~/Desktop/test$ cat test.s

.globl test_symbol
test_symbol:
        nop
liyang@liyang-virtual-machine:~/Desktop/test$ cat main.c
#include <stdio.h>

extern unsigned long test_symbol;
int main(void)
{
        printf("test_symbol = 0x%lx\n",(unsigned long)test_symbol);
        printf("&test_symbol = 0x%lx\n",(unsigned long)&test_symbol);

        printf("main = 0x%lx\n",(unsigned long)main);
        printf("&main = 0x%lx\n",(unsigned long)&main);
}
liyang@liyang-virtual-machine:~/Desktop/test$ gcc main.c test.s --static -o test
liyang@liyang-virtual-machine:~/Desktop/test$ ls
main.c  test  test.s
liyang@liyang-virtual-machine:~/Desktop/test$ readelf test -s | grep test_symbol
   884: 000000000040170c     0 NOTYPE  GLOBAL DEFAULT    7 test_symbol
liyang@liyang-virtual-machine:~/Desktop/test$ readelf test -s | grep main -w
  1605: 0000000000401685   135 FUNC    GLOBAL DEFAULT    7 main
liyang@liyang-virtual-machine:~/Desktop/test$ ./test
test_symbol = 0x4b853001f0f90
&test_symbol = 0x40170c
main = 0x401685
&main = 0x401685

The above test can lead to the conclusion that:
Both c_symbol and &c_symbol represent the address of a symbol, but
&ASM_symbol represents the address of a symbol while ASM_symbol
 represents the opcode stored at that address.

On Thu, Oct 17, 2024 at 2:05 PM Guo Ren <guoren@kernel.org> wrote:
>
> On Wed, Oct 16, 2024 at 5:56 PM Yang Li <yang.li85200@gmail.com> wrote:
> >
> > In the csky_cmpxchg_fixup function, it is incorrect to use the global
> >  variable csky_cmpxchg_stw to determine the address where the exception
> >  occurred.The global variable csky_cmpxchg_stw stores the opcode at the
> >  time of the exception, while &csky_cmpxchg_stw shows the address where
> >  the exception occurred.
> >
> > Signed-off-by: Yang Li <yang.li85200@gmail.com>
> > ---
> > V1 -> V2:Eliminate compilation warnings
> >
> >  arch/csky/mm/fault.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
> > index a885518ce1dd..5226bc08c336 100644
> > --- a/arch/csky/mm/fault.c
> > +++ b/arch/csky/mm/fault.c
> > @@ -45,8 +45,8 @@ static inline void csky_cmpxchg_fixup(struct pt_regs *regs)
> >         if (trap_no(regs) != VEC_TLBMODIFIED)
> >                 return;
> >
> > -       if (instruction_pointer(regs) == csky_cmpxchg_stw)
> > -               instruction_pointer_set(regs, csky_cmpxchg_ldw);
> > +       if (instruction_pointer(regs) == (unsigned long)&csky_cmpxchg_stw)
> > +               instruction_pointer_set(regs, (unsigned long)&csky_cmpxchg_ldw);
> csky_cmpxchg_ldw(stw) is a label symbol, not a variable.
>
> arch/csky/kernel/atomic.S:
> GLOBAL(csky_cmpxchg_ldw)
> GLOBAL(csky_cmpxchg_stw)
>
> Your modification does not affect the ASM output.
>
> (gdb) p main
> $1 = {void (void)} 0x5fa <main>
> (gdb) p &main
> $2 = (void (*)(void)) 0x5fa <main>
>
> >         return;
> >  }
> >  #endif
> > --
> > 2.34.1
> >
>
>
> --
> Best Regards
>  Guo Ren
Re: [PATCH v2] csky: fix csky_cmpxchg_fixup not working
Posted by Guo Ren 4 weeks, 1 day ago
Hi yang,


On Mon, Oct 21, 2024 at 3:51 PM yang li <yang.li85200@gmail.com> wrote:
>
> Hi Guo Ren:
> In C language, your conclusion is correct, but in assembly language,
>  global_symbol != &global_symbol
> I did the following experiment:
>
> liyang@liyang-virtual-machine:~/Desktop/test$ ls
> main.c  test.s
> liyang@liyang-virtual-machine:~/Desktop/test$ cat test.s
>
> .globl test_symbol
> test_symbol:
>         nop
> liyang@liyang-virtual-machine:~/Desktop/test$ cat main.c
> #include <stdio.h>
>
> extern unsigned long test_symbol;
> int main(void)
> {
>         printf("test_symbol = 0x%lx\n",(unsigned long)test_symbol);
>         printf("&test_symbol = 0x%lx\n",(unsigned long)&test_symbol);
>
>         printf("main = 0x%lx\n",(unsigned long)main);
>         printf("&main = 0x%lx\n",(unsigned long)&main);
> }
> liyang@liyang-virtual-machine:~/Desktop/test$ gcc main.c test.s --static -o test
> liyang@liyang-virtual-machine:~/Desktop/test$ ls
> main.c  test  test.s
> liyang@liyang-virtual-machine:~/Desktop/test$ readelf test -s | grep test_symbol
>    884: 000000000040170c     0 NOTYPE  GLOBAL DEFAULT    7 test_symbol
> liyang@liyang-virtual-machine:~/Desktop/test$ readelf test -s | grep main -w
>   1605: 0000000000401685   135 FUNC    GLOBAL DEFAULT    7 main
> liyang@liyang-virtual-machine:~/Desktop/test$ ./test
> test_symbol = 0x4b853001f0f90
> &test_symbol = 0x40170c
> main = 0x401685
> &main = 0x401685
>
> The above test can lead to the conclusion that:
> Both c_symbol and &c_symbol represent the address of a symbol, but
> &ASM_symbol represents the address of a symbol while ASM_symbol
>  represents the opcode stored at that address.
>
> On Thu, Oct 17, 2024 at 2:05 PM Guo Ren <guoren@kernel.org> wrote:
> >
> > On Wed, Oct 16, 2024 at 5:56 PM Yang Li <yang.li85200@gmail.com> wrote:
> > >
> > > In the csky_cmpxchg_fixup function, it is incorrect to use the global
> > >  variable csky_cmpxchg_stw to determine the address where the exception
> > >  occurred.The global variable csky_cmpxchg_stw stores the opcode at the
> > >  time of the exception, while &csky_cmpxchg_stw shows the address where
> > >  the exception occurred.
> > >
> > > Signed-off-by: Yang Li <yang.li85200@gmail.com>

You convinced me. Applied to csky/linux-next, thanks!


> > > ---
> > > V1 -> V2:Eliminate compilation warnings
> > >
> > >  arch/csky/mm/fault.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
> > > index a885518ce1dd..5226bc08c336 100644
> > > --- a/arch/csky/mm/fault.c
> > > +++ b/arch/csky/mm/fault.c
> > > @@ -45,8 +45,8 @@ static inline void csky_cmpxchg_fixup(struct pt_regs *regs)
> > >         if (trap_no(regs) != VEC_TLBMODIFIED)
> > >                 return;
> > >
> > > -       if (instruction_pointer(regs) == csky_cmpxchg_stw)
> > > -               instruction_pointer_set(regs, csky_cmpxchg_ldw);
> > > +       if (instruction_pointer(regs) == (unsigned long)&csky_cmpxchg_stw)
> > > +               instruction_pointer_set(regs, (unsigned long)&csky_cmpxchg_ldw);
> > csky_cmpxchg_ldw(stw) is a label symbol, not a variable.
> >
> > arch/csky/kernel/atomic.S:
> > GLOBAL(csky_cmpxchg_ldw)
> > GLOBAL(csky_cmpxchg_stw)
> >
> > Your modification does not affect the ASM output.
> >
> > (gdb) p main
> > $1 = {void (void)} 0x5fa <main>
> > (gdb) p &main
> > $2 = (void (*)(void)) 0x5fa <main>
> >
> > >         return;
> > >  }
> > >  #endif
> > > --
> > > 2.34.1
> > >
> >
> >
> > --
> > Best Regards
> >  Guo Ren



--
Best Regards
 Guo Ren