From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> To: Palmer Dabbelt <palmer@sifive.com> Cc: atish.patra@wdc.com, linux-riscv@lists.infradead.org, albert@sifive.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] riscv: fix __user annotation for __copy_user() Date: Thu, 7 Jun 2018 18:51:33 +0200 [thread overview] Message-ID: <20180607165131.5qx43o6f2siwyivj@ltop.local> (raw) In-Reply-To: <mhng-497a442f-c0da-4f88-9b48-827c4f164ed1@palmer-si-x1c4> On Thu, Jun 07, 2018 at 09:30:19AM -0700, Palmer Dabbelt wrote: > > I haven't compiled this, but I think it should work. It's on the > fix-sparse branch of kernel.org/palmer/linux.git . It's essentially what I was thinking but I have some small remarks. > diff --git a/arch/riscv/include/asm/uaccess.h b/arch/riscv/include/asm/uaccess.h > index 14b0b22fb578..0dbbbab05dac 100644 > --- a/arch/riscv/include/asm/uaccess.h > +++ b/arch/riscv/include/asm/uaccess.h > @@ -392,19 +392,21 @@ do { \ > }) > > > -extern unsigned long __must_check __copy_user(void __user *to, > +extern unsigned long __must_check __asm_copy_from_user_user(void *to, > const void __user *from, unsigned long n); > +extern unsigned long __must_check __asm_copy_to_user_user(void __user *to, > + const void *from, unsigned long n); > > static inline unsigned long > raw_copy_from_user(void *to, const void __user *from, unsigned long n) > { > - return __copy_user(to, from, n); > + return __asm_copy_from_user(to, from, n); > } > > static inline unsigned long > raw_copy_to_user(void __user *to, const void *from, unsigned long n) > { > - return __copy_user(to, from, n); > + return __asm_copy_to_user(to, from, n); > } The asm function could have directly be named raw_copy_{to,from}_user() because the inline functions are just no-ops but it's very clear like so. > extern long strncpy_from_user(char *dest, const char __user *src, long count); > diff --git a/arch/riscv/lib/uaccess.S b/arch/riscv/lib/uaccess.S > index 58fb2877c865..bd51e47ebd44 100644 > --- a/arch/riscv/lib/uaccess.S > +++ b/arch/riscv/lib/uaccess.S > @@ -13,7 +13,15 @@ _epc: > .previous > .endm > > -ENTRY(__copy_user) > +/* __asm_copy_to_user and __asm_copy_from_user are actually the same function, > + * they're just provided as two different symbols to C code so sparse doesn't > + * yell about casting between two different address spaces. */ > +.global __asm_copy_to_user > +.set __asm_copy_to_user,__asm_copy_tofrom_user > +.global __asm_copy_from_user > +.set __asm_copy_from_user,__asm_copy_tofrom_user > + > +ENTRY(__asm_copy_tofrom_user) I don't think that the size (as reported by objdump, for example) will be correct or even present for __asm_copy_to_user & __asm_copy_to_user. What can be done is: ENTRY(__asm_copy_to_user) ENTRY(__asm_copy_from_user) <function definition> ENDPROC(__asm_copy_to_user) ENDPROC(__asm_copy_from_user) Finally, the symbol table need also something like: diff --git a/arch/riscv/kernel/riscv_ksyms.c b/arch/riscv/kernel/riscv_ksyms.c index 551734248..1e8f8fa54 100644 --- a/arch/riscv/kernel/riscv_ksyms.c +++ b/arch/riscv/kernel/riscv_ksyms.c @@ -13,6 +13,7 @@ * Assembly functions that may be used (directly or indirectly) by modules */ EXPORT_SYMBOL(__clear_user); -EXPORT_SYMBOL(__copy_user); +EXPORT_SYMBOL(__asm_copy_to_user); +EXPORT_SYMBOL(__asm_copy_from_user); EXPORT_SYMBOL(memset); EXPORT_SYMBOL(memcpy); Best regards, -- Luc
WARNING: multiple messages have this Message-ID (diff)
From: luc.vanoostenryck@gmail.com (Luc Van Oostenryck) To: linux-riscv@lists.infradead.org Subject: [PATCH 3/3] riscv: fix __user annotation for __copy_user() Date: Thu, 7 Jun 2018 18:51:33 +0200 [thread overview] Message-ID: <20180607165131.5qx43o6f2siwyivj@ltop.local> (raw) In-Reply-To: <mhng-497a442f-c0da-4f88-9b48-827c4f164ed1@palmer-si-x1c4> On Thu, Jun 07, 2018 at 09:30:19AM -0700, Palmer Dabbelt wrote: > > I haven't compiled this, but I think it should work. It's on the > fix-sparse branch of kernel.org/palmer/linux.git . It's essentially what I was thinking but I have some small remarks. > diff --git a/arch/riscv/include/asm/uaccess.h b/arch/riscv/include/asm/uaccess.h > index 14b0b22fb578..0dbbbab05dac 100644 > --- a/arch/riscv/include/asm/uaccess.h > +++ b/arch/riscv/include/asm/uaccess.h > @@ -392,19 +392,21 @@ do { \ > }) > > > -extern unsigned long __must_check __copy_user(void __user *to, > +extern unsigned long __must_check __asm_copy_from_user_user(void *to, > const void __user *from, unsigned long n); > +extern unsigned long __must_check __asm_copy_to_user_user(void __user *to, > + const void *from, unsigned long n); > > static inline unsigned long > raw_copy_from_user(void *to, const void __user *from, unsigned long n) > { > - return __copy_user(to, from, n); > + return __asm_copy_from_user(to, from, n); > } > > static inline unsigned long > raw_copy_to_user(void __user *to, const void *from, unsigned long n) > { > - return __copy_user(to, from, n); > + return __asm_copy_to_user(to, from, n); > } The asm function could have directly be named raw_copy_{to,from}_user() because the inline functions are just no-ops but it's very clear like so. > extern long strncpy_from_user(char *dest, const char __user *src, long count); > diff --git a/arch/riscv/lib/uaccess.S b/arch/riscv/lib/uaccess.S > index 58fb2877c865..bd51e47ebd44 100644 > --- a/arch/riscv/lib/uaccess.S > +++ b/arch/riscv/lib/uaccess.S > @@ -13,7 +13,15 @@ _epc: > .previous > .endm > > -ENTRY(__copy_user) > +/* __asm_copy_to_user and __asm_copy_from_user are actually the same function, > + * they're just provided as two different symbols to C code so sparse doesn't > + * yell about casting between two different address spaces. */ > +.global __asm_copy_to_user > +.set __asm_copy_to_user,__asm_copy_tofrom_user > +.global __asm_copy_from_user > +.set __asm_copy_from_user,__asm_copy_tofrom_user > + > +ENTRY(__asm_copy_tofrom_user) I don't think that the size (as reported by objdump, for example) will be correct or even present for __asm_copy_to_user & __asm_copy_to_user. What can be done is: ENTRY(__asm_copy_to_user) ENTRY(__asm_copy_from_user) <function definition> ENDPROC(__asm_copy_to_user) ENDPROC(__asm_copy_from_user) Finally, the symbol table need also something like: diff --git a/arch/riscv/kernel/riscv_ksyms.c b/arch/riscv/kernel/riscv_ksyms.c index 551734248..1e8f8fa54 100644 --- a/arch/riscv/kernel/riscv_ksyms.c +++ b/arch/riscv/kernel/riscv_ksyms.c @@ -13,6 +13,7 @@ * Assembly functions that may be used (directly or indirectly) by modules */ EXPORT_SYMBOL(__clear_user); -EXPORT_SYMBOL(__copy_user); +EXPORT_SYMBOL(__asm_copy_to_user); +EXPORT_SYMBOL(__asm_copy_from_user); EXPORT_SYMBOL(memset); EXPORT_SYMBOL(memcpy); Best regards, -- Luc
next prev parent reply other threads:[~2018-06-07 16:51 UTC|newest] Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-01 15:21 [PATCH 0/3] riscv: fix sparse annotations Luc Van Oostenryck 2018-06-01 15:21 ` Luc Van Oostenryck 2018-06-01 15:21 ` [PATCH 1/3] riscv: use NULL instead of a plain 0 Luc Van Oostenryck 2018-06-01 15:21 ` Luc Van Oostenryck 2018-06-01 15:21 ` [PATCH 2/3] riscv: no __user for probe_kernel_address() Luc Van Oostenryck 2018-06-01 15:21 ` Luc Van Oostenryck 2018-06-01 15:21 ` [PATCH 3/3] riscv: fix __user annotation for __copy_user() Luc Van Oostenryck 2018-06-01 15:21 ` Luc Van Oostenryck 2018-06-04 18:46 ` Atish Patra 2018-06-04 18:46 ` Atish Patra 2018-06-04 19:09 ` Luc Van Oostenryck 2018-06-04 19:09 ` Luc Van Oostenryck 2018-06-04 19:28 ` Atish Patra 2018-06-04 19:28 ` Atish Patra 2018-06-07 16:30 ` Palmer Dabbelt 2018-06-07 16:30 ` Palmer Dabbelt 2018-06-07 16:45 ` Atish Patra 2018-06-07 16:45 ` Atish Patra 2018-06-07 16:51 ` Luc Van Oostenryck [this message] 2018-06-07 16:51 ` Luc Van Oostenryck 2018-06-08 22:33 ` Palmer Dabbelt 2018-06-08 22:33 ` Palmer Dabbelt 2018-06-09 0:13 ` Luc Van Oostenryck 2018-06-09 0:13 ` Luc Van Oostenryck 2018-06-09 20:00 ` Palmer Dabbelt 2018-06-09 20:00 ` Palmer Dabbelt 2018-06-09 21:42 ` Luc Van Oostenryck 2018-06-09 21:42 ` Luc Van Oostenryck 2018-06-11 19:01 ` Palmer Dabbelt 2018-06-11 19:01 ` Palmer Dabbelt 2018-06-12 3:00 ` Luc Van Oostenryck 2018-06-12 3:00 ` Luc Van Oostenryck 2018-06-12 17:12 ` Palmer Dabbelt 2018-06-12 17:12 ` Palmer Dabbelt 2018-06-12 18:19 ` Luc Van Oostenryck 2018-06-12 18:19 ` Luc Van Oostenryck 2018-06-12 19:38 ` Palmer Dabbelt 2018-06-12 19:38 ` Palmer Dabbelt 2018-06-09 0:33 ` [PATCH] riscv: split the declaration of __copy_user Luc Van Oostenryck 2018-06-09 0:33 ` Luc Van Oostenryck
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180607165131.5qx43o6f2siwyivj@ltop.local \ --to=luc.vanoostenryck@gmail.com \ --cc=albert@sifive.com \ --cc=atish.patra@wdc.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-riscv@lists.infradead.org \ --cc=palmer@sifive.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.