m68k: remove get_fs()/set_fs()
Subsystems (3)
RFC PATCH v2 1/1 m68k: remove get_fs()/set_fs()
Followup to my patch "Fixes to Linus' 'remove set_fs patch'", with kernel mode copy macros used in __get/put_kernel_nofault(). (As soon as I use the same __get/put_user_asm() macros with parameters, like in Christoph's patch, everything falls to pieces.)
The fact that I had to touch include/linux/uaccess.h at all means I got something horribly wrong in my use of MAKE_MM_SEG() to set the segments. This is just to show what does happen to boot and run OK, and perhaps help work out the differences to Christoph's version that sadly crashes for me.
--- arch/m68k/Kconfig | 1 - arch/m68k/include/asm/segment.h | 21 +----- arch/m68k/include/asm/thread_info.h | 2 +- arch/m68k/include/asm/tlbflush.h | 7 +- arch/m68k/include/asm/uaccess.h | 146 +++++++++++++++++++++++++++++++++++- arch/m68k/kernel/process.c | 2 +- arch/m68k/kernel/traps.c | 16 ++-- arch/m68k/mm/cache.c | 23 +++--- arch/m68k/mm/init.c | 2 +- arch/m68k/mm/motorola.c | 2 +- arch/m68k/sun3/config.c | 2 +- arch/m68k/sun3/mmu_emu.c | 7 +- include/linux/uaccess.h | 3 - 13 files changed, 181 insertions(+), 53 deletions(-)
arch/m68k/Kconfig +0 -1
@@ -33,7 +33,6 @@ config M68K select NO_DMA if !MMU && !COLDFIRE select OLD_SIGACTION select OLD_SIGSUSPEND3 - select SET_FS select UACCESS_MEMCPY if !MMU select VIRT_TO_BUS
arch/m68k/include/asm/segment.h +3 -18
@@ -26,19 +26,9 @@ typedef struct {#ifdef CONFIG_CPU_HAS_ADDRESS_SPACES /* -* Get/set the SFC/DFC registers for MOVES instructions +* Set the SFC/DFC registers for MOVES instructions */ -#define USER_DS MAKE_MM_SEG(__USER_DS) -#define KERNEL_DS MAKE_MM_SEG(__KERNEL_DS) - -static inline mm_segment_t get_fs (void ) -{ -mm_segment_t _v; - __asm__ ("movec %/dfc,%0" :"=r" (_v.seg):); -return _v; -} - -static inline void set_fs (mm_segment_t val) +static inline void set_segment (mm_segment_t val) { __asm__ __volatile__ ("movec %0,%/sfc\n\t" "movec %0,%/dfc\n\t"
@@ -46,14 +36,9 @@ static inline void set_fs(mm_segment_t val) }#else -#define USER_DS MAKE_MM_SEG(TASK_SIZE) -#define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF) -#define get_fs () (current_thread_info()->addr_limit) -#define set_fs (x) (current_thread_info()->addr_limit = (x)) +#define set_segment (x) ((void)(x))#endif -#define uaccess_kernel () (get_fs().seg == KERNEL_DS.seg) -#endif /* __ASSEMBLY__ */ #endif /* _M68K_SEGMENT_H */
arch/m68k/include/asm/thread_info.h +1 -1
@@ -37,7 +37,7 @@ struct thread_info {#define INIT_THREAD_INFO (tsk) \ { \ .task = &tsk, \ - .addr_limit = KERNEL_DS, \ + .addr_limit = MAKE_MM_SEG(SUPER_DATA), \ .preempt_count = INIT_PREEMPT_COUNT, \ }
arch/m68k/include/asm/tlbflush.h +4 -3
@@ -13,13 +13,14 @@ static inline void flush_tlb_kernel_page(void *addr)if (CPU_IS_COLDFIRE ) {mmu_write (MMUOR ,MMUOR_CNL ); }else if (CPU_IS_040_OR_060 ) { -mm_segment_t old_fs =get_fs (); -set_fs (KERNEL_DS ); +preempt_disable (); +set_segment (MAKE_MM_SEG (SUPER_DATA )); __asm__ __volatile__(".chip 68040\n\t" "pflush (%0)\n\t" ".chip 68k" : :"a" (addr)); -set_fs (old_fs); +set_segment (MAKE_MM_SEG (USER_DATA )); +preempt_enable (); }else if (CPU_IS_020_OR_030 ) __asm__ __volatile__("pflush #4,#4,(%0)" : :"a" (addr)); }
arch/m68k/include/asm/uaccess.h +143 -3
158 lines not on this page · raw message
arch/m68k/kernel/process.c +1 -1
@@ -155,7 +155,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,* Must save the current SFC/DFC value, NOT the value when * the parent was last descheduled - RGH 10-08-96 */ - p->thread.fs =get_fs ().seg; + p->thread.fs =USER_DATA ;if (unlikely (p->flags & (PF_KTHREAD |PF_IO_WORKER ))) {/* kernel thread */
arch/m68k/kernel/traps.c +8 -8
@@ -181,9 +181,9 @@ static inline void access_error060 (struct frame *fp)static inline unsigned long probe040 (int iswrite,unsigned long addr,int wbs) {unsigned long mmusr; -mm_segment_t old_fs =get_fs (); -set_fs (MAKE_MM_SEG (wbs)); +preempt_disable (); +set_segment (MAKE_MM_SEG (wbs));if (iswrite) asmvolatile (".chip 68040; ptestw (%0); .chip 68k" : :"a" (addr));
@@ -192,7 +192,8 @@ static inline unsigned long probe040(int iswrite, unsigned long addr, int wbs) asmvolatile (".chip 68040; movec %%mmusr,%0; .chip 68k" :"=r" (mmusr)); -set_fs (old_fs); +set_segment (MAKE_MM_SEG (USER_DATA )); +preempt_enable ();return mmusr; }
@@ -201,10 +202,9 @@ static inline int do_040writeback1(unsigned short wbs, unsigned long wba, unsigned long wbd) {int res =0 ; -mm_segment_t old_fs =get_fs (); -/* set_fs can not be moved, otherwise put_user() may oops */ -set_fs (MAKE_MM_SEG (wbs)); +preempt_disable (); +set_segment (MAKE_MM_SEG (wbs));switch (wbs &WBSIZ_040 ) {case BA_SIZE_BYTE :
@@ -218,8 +218,8 @@ static inline int do_040writeback1(unsigned short wbs, unsigned long wba,break ; } -/* set_fs can not be moved, otherwise put_user() may oops */ -set_fs (old_fs); +set_segment (MAKE_MM_SEG (USER_DATA )); +preempt_enable ();pr_debug ("do_040writeback1, res=%d\n" , res);
arch/m68k/mm/cache.c +14 -9
@@ -12,7 +12,7 @@#include <asm/traps.h> -static unsigned long virt_to_phys_slow (unsigned long vaddr) +static unsigned long virt_to_phys_slow (unsigned long vaddr,mm_segment_t seg) {if (CPU_IS_060 ) {unsigned long paddr;
@@ -55,7 +55,7 @@ static unsigned long virt_to_phys_slow(unsigned long vaddr) asmvolatile ("ptestr %3,%2@,#7,%0\n\t" "pmove %%psr,%1" :"=a&" (descaddr),"=m" (mmusr) - :"a" (vaddr),"d" (get_fs ().seg)); + :"a" (vaddr),"d" (seg.seg));if (mmusr & (MMU_I |MMU_B |MMU_L ))return 0 ; descaddr =phys_to_virt ((unsigned long )descaddr);
@@ -73,7 +73,7 @@ static unsigned long virt_to_phys_slow(unsigned long vaddr)/* Push n pages at kernel virtual address and clear the icache */ /* RZ: use cpush %bc instead of cpush %dc, cinv %ic */ -void flush_icache_user_range (unsigned long address,unsigned long endaddr) +static void do_flush_icache_range (unsigned long address,unsigned long endaddr,mm_segment_t seg) {if (CPU_IS_COLDFIRE ) {unsigned long start, end;
@@ -92,7 +92,7 @@ void flush_icache_user_range(unsigned long address, unsigned long endaddr) ".chip 68040\n\t" "cpushp %%bc,(%0)\n\t" ".chip 68k" - : : "a" (virt_to_phys_slow(address))); + : : "a" (virt_to_phys_slow(address, seg))); address +=PAGE_SIZE ; }while (address < endaddr); }else {
@@ -105,13 +105,18 @@ void flush_icache_user_range(unsigned long address, unsigned long endaddr) } } -void flush_icache_range (unsigned long address,unsigned long endaddr) +void flush_icache_user_range (unsigned long address,unsigned long endaddr) { -mm_segment_t old_fs =get_fs (); +do_flush_icache_range (address, endaddr,MAKE_MM_SEG (USER_DATA )); +} -set_fs (KERNEL_DS ); -flush_icache_user_range (address, endaddr); -set_fs (old_fs); +void flush_icache_range (unsigned long address,unsigned long endaddr) +{ +preempt_disable (); +set_segment (MAKE_MM_SEG (SUPER_DATA )); +do_flush_icache_range (address, endaddr,MAKE_MM_SEG (SUPER_DATA )); +set_segment (MAKE_MM_SEG (USER_DATA )); +preempt_enable (); }EXPORT_SYMBOL (flush_icache_range);
arch/m68k/mm/init.c +1 -1
@@ -96,7 +96,7 @@ void __init paging_init(void)/* * Set up SFC/DFC registers (user data space). */ -set_fs (USER_DS ); +set_segment (USER_DATA ); max_zone_pfn[ZONE_DMA ] = end_mem >>PAGE_SHIFT ;free_area_init (max_zone_pfn);
arch/m68k/mm/motorola.c +1 -1
@@ -467,7 +467,7 @@ void __init paging_init(void)/* * Set up SFC/DFC registers */ -set_fs (KERNEL_DS ); +set_segment (MAKE_MM_SEG (SUPER_DATA ));#ifdef DEBUG printk ("before free_area_init\n" );
arch/m68k/sun3/config.c +1 -1
@@ -89,7 +89,7 @@ void __init sun3_init(void) sun3_reserved_pmeg[249 ] =1 ; sun3_reserved_pmeg[252 ] =1 ; sun3_reserved_pmeg[253 ] =1 ; -set_fs (KERNEL_DS ); +set_segment (SUPER_DATA ); }/* Without this, Bad Things happen when something calls arch_reset. */
arch/m68k/sun3/mmu_emu.c +4 -3
@@ -191,14 +191,15 @@ void __init mmu_emu_init(unsigned long bootmem_end)for (seg =0 ; seg <PAGE_OFFSET ; seg +=SUN3_PMEG_SIZE )sun3_put_segmap (seg,SUN3_INVALID_PMEG ); -set_fs (MAKE_MM_SEG (3 )); +preempt_disable (); +set_segment (MAKE_MM_SEG (3 ));for (seg =0 ; seg <0x10000000 ; seg +=SUN3_PMEG_SIZE ) { i =sun3_get_segmap (seg);for (j =1 ; j <CONTEXTS_NUM ; j++) (*(romvec->pv_setctxt))(j, (void *)seg, i); } -set_fs (KERNEL_DS ); - +set_segment (SUPER_DATA ); +preempt_enable (); }/* erase the mappings for a dead context. Uses the pg_dir for hints
include/linux/uaccess.h +0 -3
@@ -29,9 +29,6 @@ static inline void force_uaccess_end(mm_segment_t oldfs) set_fs(oldfs); }#else /* CONFIG_SET_FS */ -typedef struct { -/* empty dummy */ -}mm_segment_t ;#ifndef TASK_SIZE_MAX #define TASK_SIZE_MAX TASK_SIZE
Signature · 1 line
2.7.4
Quoted 5 lines · Michael Schmitz
Followup to my patch "Fixes to Linus' 'remove
set_fspatch'", with kernel mode copy macros used in __get/put_kernel_nofault(). (As soon as I use the same __get/put_user_asm() macros with parameters, like in Christoph's patch, everything falls to pieces.)
Ok, strange. If this works for you, then the _concept_ is fine, and there's something odd going on with the "macros with 'moves' vs 'move' as a parameter" thing.
Quoted 3 lines
The fact that I had to touch
include/linux/uaccess.hat all means I got something horribly wrong in my use ofMAKE_MM_SEG()to set the segments.
Oh, that's straightforward enough: the m68k segment code uses the same 'mm_segment_t' type that the geberic kernel just wants to make empty for the non-CONFIG_SET_FS case.
So the m68k segment type should just use a different name.
In fact, the m68k manuals call them "alternate function code registers", so maybe it shouldn't be about "mm_segment_t" at all, but the type should really be named as such.
The "segment" naming is just legacy x86 nomenclature, so I suspect it would be a good thing to really walk away from that and make it very explicit about what this is on m68k.
So maybe it could be
typedef struct {
unsigned char val:3;
} function_code_reg_t;or something like that.
I suspect some real m68k person should make up the name, not me. The alternate function code registers are all from after my time ;)
Linus
Quoted 4 lines · Linus Torvalds
Ok, strange. If this works for you, then the _concept_ is fine, and there's something odd going on with the "macros with 'moves' vs 'move' as a parameter" thing.
Oh, I think I see the problem.
Or rather, I see it in Christoph's version of the patch, I don't think I've seen Michael's version, but that one was apparently very similar, so maybe it has the same bug.
Christoph does:
#define __put_user_asm(inst, res, x, ptr, bwl, reg) \
asm volatile ("\n" \
"1: #inst."#bwl" %2,%1\n"
...and then uses it with code like
__put_user_asm(MOVES, __pu_err, __pu_val, ptr, b, d);
and
__get_user_asm("move", __gk_err, __gk_dst, __gk_src, u8, b, d);and the issue is that there's a '#' too many.
The '#' turns the argument into a string, but it was already _supposed_ to be a string. But no, the problem is that it turns the macro name MOVES into the _string_ "MOVES".
Which happens to compile just fine, because "moves" is a real instruction. But it's actually _meant_ to be a macro that expands to either the string "moves" or "move".
So what happens is that at least in Christoph's version, I think the code _always_ uses "MOVES", even in configurations where the macro MOVES should have just become "move".
So it all builds fine, looks fine to the assembler, but it uses the wrong instruction.
Macro expansion with the '#' character and other macros used as arguments is something people need to be very careful with. It's why we have a whole header file for just the "stringify" operation, see <linux/stringify.h>
But in this case, it shouldn't have used '#' at all, since the argument was already a string, and never needed to be turned into a string by the pre-processor.
Linus
Hi Linus,
Am 08.07.2021 um 15:01 schrieb Linus Torvalds:
Quoted 30 lines
Quoted 4 lines · Linus Torvalds
Ok, strange. If this works for you, then the _concept_ is fine, and there's something odd going on with the "macros with 'moves' vs 'move' as a parameter" thing.
Oh, I think I see the problem.
Or rather, I see it in Christoph's version of the patch, I don't think I've seen Michael's version, but that one was apparently very similar, so maybe it has the same bug.
Christoph does:
#define __put_user_asm(inst, res, x, ptr, bwl, reg) \ asm volatile ("\n" \ "1: #inst."#bwl" %2,%1\n" ...and then uses it with code like
__put_user_asm(MOVES, __pu_err, __pu_val, ptr, b, d);and
__get_user_asm("move", __gk_err, __gk_dst, __gk_src, u8, b, d);and the issue is that there's a '#' too many.
Quoted 7 lines
The '#' turns the argument into a string, but it was already _supposed_ to be a string. But no, the problem is that it turns the macro name MOVES into the _string_ "MOVES".
Which happens to compile just fine, because "moves" is a real instruction. But it's actually _meant_ to be a macro that expands to either the string "moves" or "move".
Yes, that's where I got to (trying to implement what you suggested a few days ago, after the version I just sent) and hit a wall. What I meant by 'getting overly smart with the preprocessor'.
Quoted 7 lines
So what happens is that at least in Christoph's version, I think the code _always_ uses "MOVES", even in configurations where the macro MOVES should have just become "move".
So it all builds fine, looks fine to the assembler, but it uses the wrong instruction.
Yep - that was easy enough to test - never mind what you define MOVES as, that does not really matter. It always turns out 'moves'.
Quoted 8 lines
Macro expansion with the '#' character and other macros used as arguments is something people need to be very careful with. It's why we have a whole header file for just the "stringify" operation, see <
linux/stringify.h>But in this case, it shouldn't have used '#' at all, since the argument was already a string, and never needed to be turned into a string by the pre-processor.
Testing that option next... and works!. Though I still think Christoph's version is much cleaner...
Cheers,
Michael
Quoted 3 lines
Linus
Quoted 15 lines · Linus Torvalds
The '#' turns the argument into a string, but it was already _supposed_ to be a string. But no, the problem is that it turns the macro name MOVES into the _string_ "MOVES".
Which happens to compile just fine, because "moves" is a real instruction. But it's actually _meant_ to be a macro that expands to either the string "moves" or "move".
So what happens is that at least in Christoph's version, I think the code _always_ uses "MOVES", even in configurations where the macro MOVES should have just become "move".
So it all builds fine, looks fine to the assembler, but it uses the wrong instruction.
Quoted 8 lines
Macro expansion with the '#' character and other macros used as arguments is something people need to be very careful with. It's why we have a whole header file for just the "stringify" operation, see <
linux/stringify.h>But in this case, it shouldn't have used '#' at all, since the argument was already a string, and never needed to be turned into a string by the pre-processor.
Yes, that problem exists, but just removing the # causes "inst" to go into the cpp output. Let me brush up my cpp-foo.
Hi Christoph,
Am 08.07.2021 um 16:31 schrieb Christoph Hellwig:
Quoted 21 lines · Linus Torvalds
Quoted 20 lines
The '#' turns the argument into a string, but it was already _supposed_ to be a string. But no, the problem is that it turns the macro name MOVES into the _string_ "MOVES".
Which happens to compile just fine, because "moves" is a real instruction. But it's actually _meant_ to be a macro that expands to either the string "moves" or "move".
So what happens is that at least in Christoph's version, I think the code _always_ uses "MOVES", even in configurations where the macro MOVES should have just become "move".
So it all builds fine, looks fine to the assembler, but it uses the wrong instruction.
Macro expansion with the '#' character and other macros used as arguments is something people need to be very careful with. It's why we have a whole header file for just the "stringify" operation, see <
linux/stringify.h>
Quoted 6 lines
Quoted 3 lines
But in this case, it shouldn't have used '#' at all, since the argument was already a string, and never needed to be turned into a string by the pre-processor.
Yes, that problem exists, but just removing the # causes "inst" to go into the cpp output. Let me brush up my cpp-foo.
Putting quotes around 'inst' makes it compile for me.
Cheers,
Michael
Quoted 4 lines · Michael Schmitz
Quoted 2 lines
Yes, that problem exists, but just removing the # causes "inst" to go into the cpp output. Let me brush up my cpp-foo.
Putting quotes around 'inst' makes it compile for me.
Do you just want to take the series over from here? I think you are about 15 times more qualified than me anyway :)
Hi Christoph,
Am 08.07.2021 um 16:58 schrieb Christoph Hellwig:
Quoted 8 lines · Michael Schmitz
Quoted 4 lines
Quoted 2 lines
Yes, that problem exists, but just removing the # causes "inst" to go into the cpp output. Let me brush up my cpp-foo.
Putting quotes around 'inst' makes it compile for me.
Do you just want to take the series over from here? I think you are about 15 times more qualified than me anyway :)
Not in a million years :-) A brief look at my patch review history on linux-m68k will disabuse you of that notion. I routinely hit v6 and higher ... I'm a simple hobbyist, and a little out of my depth here.
Cheers,
Michael
Quoted 7 lines · Michael Schmitz
Hi Christoph,
Am 08.07.2021 um 16:58 schrieb Christoph Hellwig:
Quoted 4 lines · Michael Schmitz
Quoted 3 lines
Quoted 2 lines
Yes, that problem exists, but just removing the # causes "inst" to go into the cpp output. Let me brush up my cpp-foo.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Putting quotes around 'inst' makes it compile for me.
Do you just want to take the series over from here? I think you are about 15 times more qualified than me anyway :)
Not in a million years :-) A brief look at my patch review history on linux-m68k will disabuse you of that notion. I routinely hit v6 and higher ... I'm a simple hobbyist, and a little out of my depth here.
I've force pushed a new version to the branch, can you give it a spin?
Quoted 2 lines · Christoph Hellwig
I've force pushed a new version to the branch, can you give it a spin?
Please stop playing broken games with __constant_copy_to_user().
Now you didn't just break the return value, you broke the actual copy too. When it is supposed to do a 4-byte copy, the code now does *two* 4-byte copies, because that's the way __constant_copy_to_user_asm() works - it always does at least two accesses, and then the third one is conditional.
So that "6, l, l, )" in
case 4:
__constant_copy_to_user_asm(res, to, from, tmp, 6, l, l,);
break;literally means "try to do 2x 'l' sized moves (but not a third one), and return 6 if it fails". All of which is very wrong indeed.
So commit d36105c942e0 ("m68k: simplify the __constant_copy_to_user implementation") is very very broken.
But the rest looks good to me. Of course, I entirely missed the fact that Andreas pointed out - "instr" was inside a string - so who knows what I missed this time.
Linus
Hi Linus,
Quoted 10 lines · Linus Torvalds
Quoted 1 line · Christoph Hellwig
I've force pushed a new version to the branch, can you give it a spin?
Please stop playing broken games with
__constant_copy_to_user().Now you didn't just break the return value, you broke the actual copy too. When it is supposed to do a 4-byte copy, the code now does *two* 4-byte copies, because that's the way
__constant_copy_to_user_asm()works - it always does at least two accesses, and then the third one is conditional.
Quoted 8 lines
So that "6, l, l, )" in
case 4: __constant_copy_to_user_asm(res, to, from, tmp, 6, l, l,); break;literally means "try to do 2x 'l' sized moves (but not a third one), and return 6 if it fails". All of which is very wrong indeed.
In order to get the correct number of bytes copied, the patch would have to look like:
switch (n) {
case 1:
- __put_user_asm(res, *(u8 *)from, (u8 __user *)to, b, d, 1); + __constant_copy_to_user_asm(res, to, from, tmp, 1, b, ); break;
case 2:
- __put_user_asm(res, *(u16 *)from, (u16 __user *)to, w, r, 2); + __constant_copy_to_user_asm(res, to, from, tmp, 2, w, ); break;
case 3:
__constant_copy_to_user_asm(res, to, from, tmp, 3, w, b,); break;
case 4:
- __put_user_asm(res, *(u32 *)from, (u32 __user *)to, l, r, 4); + __constant_copy_to_user_asm(res, to, from, tmp, 4, l, ); break;
and __constant_copy_to_user_asm() changed to deal with an empty s2 parameter. Probably too much work.
Quoted 3 lines
So commit
d36105c942e0("m68k: simplify the__constant_copy_to_userimplementation") is very very broken.
Doesn't appear to matter - though I'll back out those changes to be safe.
Note that in this version, faults in __put_user_asm used from __constant_copy_to_user will return -EFAULT, not the remaining number of bytes to be copied, which might get confusing for the caller.
Cheers,
Michael
Quoted 6 lines
But the rest looks good to me. Of course, I entirely missed the fact that Andreas pointed out - "instr" was inside a string - so who knows what I missed this time.
Linus
Hi Christoph,
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Michael Schmitz
Hi Christoph,
Am 08.07.2021 um 16:58 schrieb Christoph Hellwig:
Quoted 3 lines · Michael Schmitz
Quoted 2 lines
Quoted 2 lines
Yes, that problem exists, but just removing the # causes "inst" to go into the cpp output. Let me brush up my cpp-foo.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Putting quotes around 'inst' makes it compile for me.
Do you just want to take the series over from here? I think you are about 15 times more qualified than me anyway :)
Not in a million years :-) A brief look at my patch review history on linux-m68k will disabuse you of that notion. I routinely hit v6 and higher ... I'm a simple hobbyist, and a little out of my depth here.
I've force pushed a new version to the branch, can you give it a spin?
Still the same fault (can't start init). But as Linus pointed out, your __constant_copy_to_user() is still broken.
I'll try to back out that part sometime later today.
Cheers,
Michael
Hi Christoph,
Quoted 5 lines · Michael Schmitz
Quoted 1 line · Christoph Hellwig
I've force pushed a new version to the branch, can you give it a spin?
Still the same fault (can't start init). But as Linus pointed out, your
__constant_copy_to_user()is still broken.
Forget that - got my git am munged up (applied yesterday's patch a second time, eek).
That patch works fine on a casual test. What you did to __constant_copy_to_user() does not appear to matter - but I haven't put the system under any kind of stress yet. I'm a little reluctant to do that (recovering from a trashed boot disk is a little dicey), I'll probably only try that with your changes to __constant_copy_to_user() from commit d36105c942e0 backed out.
That still leaves the issue of __constant_copy_to_user() possibly returning -EFAULT instead of the number of residual bytes to copy, but we can probably live with that for now (__constant_copy_to_user_asm() doesn't actually calculate the residual but just sets it to the number of bytes originally to be copied, which is the best we can do with the scheme used there).
Cheers,
Michael
Quoted 6 lines · Michael Schmitz
That patch works fine on a casual test. What you did to
__constant_copy_to_user()does not appear to matter - but I haven't put the system under any kind of stress yet. I'm a little reluctant to do that (recovering from a trashed boot disk is a little dicey), I'll probably only try that with your changes to__constant_copy_to_user()from commitd36105c942e0backed out.
As Linus pointed out, small copy_to_user basically doesn't happen as we have switched all the suspect call sites to just use put_user.
Geert: do you care about __constant_copy_to_user at all, or can we just kill it (as well as the copy_from_user side)?
Hi Christoph,
Am 09.07.2021 um 16:22 schrieb Christoph Hellwig:
Quoted 10 lines · Michael Schmitz
Quoted 6 lines
That patch works fine on a casual test. What you did to
__constant_copy_to_user()does not appear to matter - but I haven't put the system under any kind of stress yet. I'm a little reluctant to do that (recovering from a trashed boot disk is a little dicey), I'll probably only try that with your changes to__constant_copy_to_user()from commitd36105c942e0backed out.As Linus pointed out, small
copy_to_userbasically doesn't happen as we have switched all the suspect call sites to just useput_user.
Thanks, I missed that. That does explain it then.
I see you've put a warning message in set_fc() - let's see whether that triggers on a test run on real hardware.
Cheers,
Michael
Quoted 3 lines
Geert: do you care about
__constant_copy_to_userat all, or can we just kill it (as well as thecopy_from_userside)?
Geert Uytterhoeven
maintainerHi Christoph,
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Michael Schmitz
That patch works fine on a casual test. What you did to
__constant_copy_to_user()does not appear to matter - but I haven't put the system under any kind of stress yet. I'm a little reluctant to do that (recovering from a trashed boot disk is a little dicey), I'll probably only try that with your changes to__constant_copy_to_user()from commitd36105c942e0backed out.
Quoted 5 lines
As Linus pointed out, small
copy_to_userbasically doesn't happen as we have switched all the suspect call sites to just useput_user.Geert: do you care about
__constant_copy_to_userat all, or can we just kill it (as well as thecopy_from_userside)?
If it blocks you, feel free to remove it.
BTW, do you have an idea of how many calls use small sizes?
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hi Geert,
Am 09.07.2021 um 19:29 schrieb Geert Uytterhoeven:
Quoted 11 lines
Hi Christoph,
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Michael Schmitz
That patch works fine on a casual test. What you did to
__constant_copy_to_user()does not appear to matter - but I haven't put the system under any kind of stress yet. I'm a little reluctant to do that (recovering from a trashed boot disk is a little dicey), I'll probably only try that with your changes to__constant_copy_to_user()from commitd36105c942e0backed out.
Quoted 8 lines
Quoted 5 lines
As Linus pointed out, small
copy_to_userbasically doesn't happen as we have switched all the suspect call sites to just useput_user.Geert: do you care about
__constant_copy_to_userat all, or can we just kill it (as well as thecopy_from_userside)?If it blocks you, feel free to remove it.
BTW, do you have an idea of how many calls use small sizes?
Just booting to a login prompt: Quite a few with 8 bytes, some with 4 bytes (those from the keyboard driver), the rest is 16, 24, 36 and 92 bytes (a lot of those). Used ratelimiting so probably missed a few.
I'll repeat that again logging only the small sizes, but I think we can live with using the generic version for those few 4 and 8 byte cases.
Cheers,
Michael
Quoted 5 lines
Gr{oetje,eeting}s,
Geert
Quoted 2 lines · Michael Schmitz
Just booting to a login prompt: Quite a few with 8 bytes, some with 4 bytes (those from the keyboard driver), the rest is 16, 24, 36 and 92 bytes (a
The 4/8 byte ones can usually be switched to just use get/put_user easily.
Am 09.07.2021 um 20:53 schrieb Christoph Hellwig:
Quoted 3 lines · Michael Schmitz
Quoted 2 lines
Just booting to a login prompt: Quite a few with 8 bytes, some with 4 bytes (those from the keyboard driver), the rest is 16, 24, 36 and 92 bytes (a
Over 400x 8 bytes, 20x 4 bytes on a count with the larger one suppressed.
Quoted 2 lines
The 4/8 byte ones can usually be switched to just use get/put_user easily.
Need to log the call sites then ... that should be fun. Something to do tomorrow :-)
Cheers,
Michael
Geert Uytterhoeven
maintainerHi Michael,
Quoted 5 lines · Michael Schmitz
Am 09.07.2021 um 20:53 schrieb Christoph Hellwig:
Quoted 3 lines · Michael Schmitz
Quoted 2 lines
Just booting to a login prompt: Quite a few with 8 bytes, some with 4 bytes (those from the keyboard driver), the rest is 16, 24, 36 and 92 bytes (a
Quoted 7 lines
Over 400x 8 bytes, 20x 4 bytes on a count with the larger one suppressed.
Quoted 2 lines
The 4/8 byte ones can usually be switched to just use get/put_user easily.
Need to log the call sites then ... that should be fun. Something to do tomorrow :-)
WARN_ON_ONCE() is your friend.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hi Geert,
Am 09.07.2021 um 23:20 schrieb Geert Uytterhoeven:
Quoted 11 lines
Hi Michael,
Quoted 8 lines · Michael Schmitz
Am 09.07.2021 um 20:53 schrieb Christoph Hellwig:
Quoted 3 lines · Michael Schmitz
Quoted 2 lines
Just booting to a login prompt: Quite a few with 8 bytes, some with 4 bytes (those from the keyboard driver), the rest is 16, 24, 36 and 92 bytes (a
Over 400x 8 bytes, 20x 4 bytes on a count with the larger one suppressed.
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
The 4/8 byte ones can usually be switched to just use get/put_user easily.
Need to log the call sites then ... that should be fun. Something to do tomorrow :-)
WARN_ON_ONCE()is your friend.
Sure - here's the result:
WARNING: CPU: 0 PID: 1 at ./arch/m68k/include/asm/uaccess.h:395 raw_copy_to_user.constprop.27+0x26/0x42 WARNING: CPU: 0 PID: 819 at ./arch/m68k/include/asm/uaccess.h:395 do_pipe2+0x4a/0xbc WARNING: CPU: 0 PID: 838 at ./arch/m68k/include/asm/uaccess.h:395 __put_old_timespec32+0x36/0x58 WARNING: CPU: 0 PID: 854 at ./arch/m68k/include/asm/uaccess.h:303 vt_do_kdsk_ioctl+0x38/0x28a WARNING: CPU: 0 PID: 950 at ./arch/m68k/include/asm/uaccess.h:395 tty_ioctl+0x27a/0x6c4
uaccess.h:303 is __constant_copy_from_user.
Cheers,
Michael
Quoted 4 lines
Gr{oetje,eeting}s,
Geert
Am 10.07.2021 um 07:25 schrieb Michael Schmitz:
Quoted 24 lines
Hi Geert,
Am 09.07.2021 um 23:20 schrieb Geert Uytterhoeven:
Quoted 21 lines
Hi Michael,
Quoted 16 lines · Michael Schmitz
Am 09.07.2021 um 20:53 schrieb Christoph Hellwig:
Quoted 5 lines · Michael Schmitz
Quoted 4 lines
Just booting to a login prompt: Quite a few with 8 bytes, some with 4 bytes
(those from the keyboard driver), the rest is 16, 24, 36 and 92 bytes (aOver 400x 8 bytes, 20x 4 bytes on a count with the larger one suppressed.
Quoted 3 lines
The 4/8 byte ones can usually be switched to just use get/put_user easily.
Need to log the call sites then ... that should be fun. Something to do tomorrow :-)
Quoted 6 lines
Quoted 1 line
WARN_ON_ONCE()is your friend.Sure - here's the result:
WARNING: CPU: 0 PID: 1 at ./arch/m68k/include/asm/uaccess.h:395 raw_copy_to_user.constprop.27+0x26/0x42
That one got called from sys_llseek+0x5c/0x86
Cheers,
Michael
Quoted 20 lines
WARNING: CPU: 0 PID: 819 at ./arch/m68k/include/asm/uaccess.h:395 do_pipe2+0x4a/0xbc WARNING: CPU: 0 PID: 838 at ./arch/m68k/include/asm/uaccess.h:395 __put_old_timespec32+0x36/0x58 WARNING: CPU: 0 PID: 854 at ./arch/m68k/include/asm/uaccess.h:303 vt_do_kdsk_ioctl+0x38/0x28a WARNING: CPU: 0 PID: 950 at ./arch/m68k/include/asm/uaccess.h:395 tty_ioctl+0x27a/0x6c4uaccess.h:303 is
__constant_copy_from_user.Cheers,
Michael
Quoted 4 lines
Gr{oetje,eeting}s,
Geert
Quoted 2 lines · Michael Schmitz
That one got called from
sys_llseek+0x5c/0x86
That's the
if (offset >= 0) {
retval = -EFAULT;
if (!copy_to_user(result, &offset, sizeof(offset)))
retval = 0;
}and it might be worth doing a put_user() for. That would actually simplify the code to just
if (offset >= 0)
retval = put_user(offset, result);or something like that.
Except maybe there's some 32-bit architecture that doesn't support 8-byte get/put_user(), which may be why it's a copy_to_user().
I _think_ we made the rule be that everybody had to support 1/2/4/8 byte accesses, but maybe I remember incorrectly.
Linus
Quoted 6 lines · Linus Torvalds
Except maybe there's some 32-bit architecture that doesn't support 8-byte get/put_user(), which may be why it's a
copy_to_user().I _think_ we made the rule be that everybody had to support 1/2/4/8 byte accesses, but maybe I remember incorrectly.
We're _almost_ correct.
nios2 doesn't seem to support 8-byte user accesses.
Everybody else does seem to have a 'case 8:' at least according to my simplistic grep (but that grep might have been _too_ simplistic).
Added nios2 and the arch list.
I think we could easily just say "you have to support a 8-byte get/put_user()". At worst, an architecture can just implement it using copy_from_user() like some already do, ie something like
case 8: { \
u64 __x; \
if (unlikely(copy_from_user(&__x, ptr, 8))) { \
retval = -EFAULT; \
(x) = (__typeof__(*(ptr)))0; \
} else { \
(x) = *(__force __typeof__(*(ptr)) *)&__x; \
} \
break; \
} \so if somebody wants to make 'sys_llseek()' use put_user(), I'm ok with that.
Linus
Quoted 3 lines · Michael Schmitz
WARNING: CPU: 0 PID: 854 at ./arch/m68k/include/asm/uaccess.h:303 vt_do_kdsk_ioctl+0x38/0x28a
It's apparently the
if (copy_from_user(&kbe, user_kbe, sizeof(struct kbentry)))
which is 4 bytes in size.
Honestly, it could be done with a get_user(), but it could also just be ignored. We're not talking performance-sensitive code here.
x86 got rid of the constant-sized user copy games not because they don't exist, but because they just weren't worth the pain.
If somebody really wants to do it, then I suspect it would be better to special-case the 1/2/4/8 byte case in generic code, than have architectures special-case the odd sizes.
But it really shouldn't matter.
On x86, we found that
(a) inlining get_user() was bad, because it just caused lots of
duplicated code for the range checks.
(b) turning copy_to_user() into get_user() didn't really matter and
caused tons of duplicated code
(c) the (few) places that cared about performance should use neither,
and should use "uaccess_begin() + unsafe_get_user() + uaccess_end()" because the reason they mattered was that they ended up doing multiple accesses and the overhead was elsewhere.
Of course, on x86, the big reason for (c) is that the biggest cost often ends up being the "enable/disable user space accesses" overhead, which is about security and a feature that m68k doesn't have.
So the trace-offs are certainly a bit different on x86, but on the whole I suspect the lessons from x86 are not wrong.
Linus
Hi Linus,
Am 10.07.2021 um 07:53 schrieb Linus Torvalds:
Quoted 5 lines · Michael Schmitz
Quoted 3 lines
WARNING: CPU: 0 PID: 854 at ./arch/m68k/include/asm/uaccess.h:303 vt_do_kdsk_ioctl+0x38/0x28a
Quoted 8 lines
It's apparently the
if (
copy_from_user(&kbe, user_kbe, sizeof(struct kbentry)))which is 4 bytes in size.
Honestly, it could be done with a
get_user(), but it could also just be ignored. We're not talking performance-sensitive code here.
Yep - that one was quite rare. But I haven't actually done anything meaningful on the system yet :-)
The 8 byte copies are by far the majority. Got another one, just after logging in:
tty_ioctl+0x2ca
I'll run that instrumented version on my 030 for a IO stress test once the current test has finished. Just for the record - the WARN_ON_ONCE(in_interrupt) that Christoph added in set_fc() hasn't triggered yet.
Cheers,
Michael
Quoted 31 lines
x86 got rid of the constant-sized user copy games not because they don't exist, but because they just weren't worth the pain.
If somebody really wants to do it, then I suspect it would be better to special-case the 1/2/4/8 byte case in generic code, than have architectures special-case the odd sizes.
But it really shouldn't matter.
On x86, we found that
(a) inlining
get_user()was bad, because it just caused lots of
duplicated code for the range checks.(b) turning
copy_to_user()intoget_user()didn't really matter and
caused tons of duplicated code(c) the (few) places that cared about performance should use neither,
and should use "uaccess_begin()+unsafe_get_user()+uaccess_end()" because the reason they mattered was that they ended up doing multiple accesses and the overhead was elsewhere.Of course, on x86, the big reason for (c) is that the biggest cost often ends up being the "enable/disable user space accesses" overhead, which is about security and a feature that m68k doesn't have.
So the trace-offs are certainly a bit different on x86, but on the whole I suspect the lessons from x86 are not wrong.
Linus
Quoted 2 lines · Michael Schmitz
The 8 byte copies are by far the majority.
llseek might actually not be unusual. And the timeval structure is - I think - 8 bytes on 32-bit architectures and common for select timeouts etc. And select/poll can be one of the most common system calls out there depending on loads (usually graphical programs).
But again - I don't think it's even worth worrying about in architecture code. If you actually can measure it, I think we should fix it in generic code rather than have architectures work around some issue one by one.
I think the main issue for m68k should be "is it stable and works". At least first. And then worry about copy_to/from_user() with a constant size as a very very distant second concern.
Linus
Hi Linus,
Am 10.07.2021 um 09:18 schrieb Linus Torvalds:
Quoted 8 lines · Michael Schmitz
Quoted 2 lines
The 8 byte copies are by far the majority.
llseek might actually not be unusual. And the timeval structure is - I think - 8 bytes on 32-bit architectures and common for select timeouts etc. And select/poll can be one of the most common system calls out there depending on loads (usually graphical programs).
There's more const short reads in the old IDE code (1, 4 and 7 bytes, the latter two in the ioctl syscall), and one 8 byte one in the libata code (ata_get_identity()). None of this looks anywhere near performance critical as llseek or select/poll.
Quoted 4 lines
But again - I don't think it's even worth worrying about in architecture code. If you actually can measure it, I think we should fix it in generic code rather than have architectures work around some issue one by one.
I doubt it makes enough of a difference to measure, but maybe the llseek impact is large enough to show in IO benchmarks. I'll run tests on Christoph's latest patch series anyway so I'll have data to decide that.
Quoted 3 lines
I think the main issue for m68k should be "is it stable and works". At least first. And then worry about copy_to/from_user() with a constant size as a very very distant second concern.
So far, it looks like there's no regressions on either 030 or 040. Can't see much difference on 060 other than its use of sfc/dfc in the ifpsp060 support code, but that's all inside 'unimplemented instruction' trap handlers that can't be preempted AFAIK.
I'll ask Adrian to test these patches on 060 as well though.
Cheers,
Michael
Quoted 3 lines
Linus
Geert Uytterhoeven
maintainerHi Christoph,
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Michael Schmitz
Just booting to a login prompt: Quite a few with 8 bytes, some with 4 bytes (those from the keyboard driver), the rest is 16, 24, 36 and 92 bytes (a
The 4/8 byte ones can usually be switched to just use get/put_user easily.
Yeah, that seems like the best path forward.
I'm positively surprised that getting rid of the constant size handling shrinks the kernel by ca. 10 KiB. Probably it made sense a long time ago (perhaps before the fixup sections were added, if anyone still remembers?)...
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 11 lines · Linus Torvalds
Christoph does:
#define __put_user_asm(inst, res, x, ptr, bwl, reg) \ asm volatile ("\n" \ "1: #inst."#bwl" %2,%1\n" ...and then uses it with code like
__put_user_asm(MOVES, __pu_err, __pu_val, ptr, b, d);
Quoted 7 lines
and
__get_user_asm("move", __gk_err, __gk_dst, __gk_src, u8, b, d);and the issue is that there's a '#' too many.
The '#' turns the argument into a string,
No, it's inside a string, and the assembler just sees a comment starting with `#inst.'.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Quoted 10 lines · Linus Torvalds
So maybe it could be
typedef struct { unsigned char val:3; } function_code_reg_t;or something like that.
I suspect some real m68k person should make up the name, not me. The alternate function code registers are all from after my time ;)
I think the typedef is a little pointless that is why I dropped it entirely (mm_segment_t should go away entirely anyway). We could reduce the storage space for it, but that always requireѕ changing inline assembly, so I'd rather let a real m68k person do it if they care.