All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Schmitz <schmitzmic@gmail.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Andreas Schwab <schwab@linux-m68k.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Greg Ungerer <gerg@linux-m68k.org>,
	linux-m68k@lists.linux-m68k.org,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: RFC: remove set_fs for m68k
Date: Fri, 6 Aug 2021 15:10:55 +1200	[thread overview]
Message-ID: <251aa093-047a-b37c-4e88-d543c6fa8bc6@gmail.com> (raw)
In-Reply-To: <8884e940-22e8-72a5-e9ec-f9b2628b6ef4@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]

Hi Christoph,

Am 01.08.2021 um 07:31 schrieb Michael Schmitz:
> Hi Christoph,
>> I'll back out the top commit of your series (the one removing set_fs())
>> and retest. Again, this may take a few days to show any results.
>
> No further format errors, kernel panics or lockups seen after almost a
> week of tests.
>
> That suggests something is wrong with your 'm68k: remove set_fs()' commit.
>
> I'll try adding a get_fc() and warn whenever FC does not match what your
> patch expects, maybe that can help to get a clearer picture.

See attached patches, to be applied on top of your RFC series - ran this 
for five days now, with no further errors. Will run this a while longer 
yet, but in the ordinary course of testing, I'd have seen errors by now.

Haven't seen the WARN_ON trigger once yet though, which is more than a 
little odd. Heisenbug?

I am aware that this patch defeats the purpose of the 'lets lose set_fs' 
patch series, and Linus was quite convincing in saying preemption 
couldn't be an issue so saving DFC ought not to be necessary. If there 
is anything else I can try to get to the bottom of these format errors, 
please say so.

Cheers,

	Michael



[-- Attachment #2: 0002-m68k-warn-in-get_fc-if-DFC-is-not-USER_DATA.patch --]
[-- Type: text/x-diff, Size: 905 bytes --]

From d5f7c3d4b4e4b437dfb54f9eb1ed6876dfb63744 Mon Sep 17 00:00:00 2001
From: Michael Schmitz <schmitzmic@gmail.com>
Date: Sun, 1 Aug 2021 13:06:21 +1200
Subject: [PATCH 2/2] m68k: warn in get_fc() if DFC is not USER_DATA

Trace uacess mode restore operations that mess up the SFC/DFC
registers - read out current DFC before changing modes and warn
when the current mode wasn't USER_DATA!

Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
---
 arch/m68k/include/asm/processor.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/m68k/include/asm/processor.h b/arch/m68k/include/asm/processor.h
index 29dfa54..a8c533d 100644
--- a/arch/m68k/include/asm/processor.h
+++ b/arch/m68k/include/asm/processor.h
@@ -98,6 +98,7 @@ static inline unsigned long get_fc(void)
 {
 	unsigned long val;
 	__asm__ ("movec %/dfc,%0":"=r" (val):);
+	WARN_ON_ONCE(val != USER_DATA);
 	return val;
 }
 /*
-- 
2.7.4


[-- Attachment #3: 0001-m68k-add-get_fc-to-read-uaccess-mode.patch --]
[-- Type: text/x-diff, Size: 5350 bytes --]

From fcb3f2543125ca3fe269b50646f8c4782d31ba80 Mon Sep 17 00:00:00 2001
From: Michael Schmitz <schmitzmic@gmail.com>
Date: Sun, 1 Aug 2021 12:11:59 +1200
Subject: [PATCH 1/2] m68k: add get_fc() to read uaccess mode

Add back get_fc(), force_user_fc_begin() and force_user_fc_end(),
and use these to restore original DFC after uaccess operations,
instead of unconditionally setting USER_DATA.

Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
---
 arch/m68k/include/asm/processor.h | 35 +++++++++++++++++++++++++++++++++++
 arch/m68k/include/asm/tlbflush.h  |  8 ++++++--
 arch/m68k/kernel/process.c        |  2 +-
 arch/m68k/kernel/traps.c          |  6 ++++--
 arch/m68k/mm/cache.c              |  4 +++-
 5 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/arch/m68k/include/asm/processor.h b/arch/m68k/include/asm/processor.h
index debb453..29dfa54 100644
--- a/arch/m68k/include/asm/processor.h
+++ b/arch/m68k/include/asm/processor.h
@@ -94,10 +94,45 @@ static inline void set_fc(unsigned long val)
 			      "movec %0,%/dfc\n\t"
 			      : /* no outputs */ : "r" (val) : "memory");
 }
+static inline unsigned long get_fc(void)
+{
+	unsigned long val;
+	__asm__ ("movec %/dfc,%0":"=r" (val):);
+	return val;
+}
+/*
+ * Force the uaccess routines to be wired up for actual userspace access,
+ * overriding any possible set_fs(KERNEL_DS) still lingering around.  Undone
+ * using force_uaccess_end below.
+ */
+static inline unsigned long force_user_fc_begin(void)
+{
+        unsigned long fc = get_fc();
+
+        set_fc(USER_DATA);
+        return fc;
+}
+
+static inline void force_user_fc_end(unsigned long oldfc)
+{
+        set_fc(oldfc);
+}
 #else
 static inline void set_fc(unsigned long val)
 {
 }
+static inline unsigned long get_fs(void)
+{
+	return USER_DATA;
+}
+static inline unsigned long force_user_fc_begin(void)
+{
+        return USER_DATA;
+}
+
+static inline void force_user_fc_end(unsigned long oldfc)
+{
+}
 #endif /* CONFIG_CPU_HAS_ADDRESS_SPACES */
 
 struct thread_struct {
diff --git a/arch/m68k/include/asm/tlbflush.h b/arch/m68k/include/asm/tlbflush.h
index 524b13d..7c34d14 100644
--- a/arch/m68k/include/asm/tlbflush.h
+++ b/arch/m68k/include/asm/tlbflush.h
@@ -13,12 +13,13 @@ 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) {
+		unsigned long old_fc = get_fc();
 		set_fc(SUPER_DATA);
 		__asm__ __volatile__(".chip 68040\n\t"
 				     "pflush (%0)\n\t"
 				     ".chip 68k"
 				     : : "a" (addr));
-		set_fc(USER_DATA);
+		set_fc(old_fc);
 	} else if (CPU_IS_020_OR_030)
 		__asm__ __volatile__("pflush #4,#4,(%0)" : : "a" (addr));
 }
@@ -83,8 +84,11 @@ static inline void flush_tlb_mm(struct mm_struct *mm)
 
 static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
 {
-	if (vma->vm_mm == current->active_mm)
+	if (vma->vm_mm == current->active_mm) {
+		unsigned long old_fc = force_user_fc_begin();
 		__flush_tlb_one(addr);
+		force_user_fc_end(old_fc);
+	}
 }
 
 static inline void flush_tlb_range(struct vm_area_struct *vma,
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index fb257b7..cab012d 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -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.fc = USER_DATA;
+	p->thread.fc = get_fc();
 
 	if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
 		/* kernel thread */
diff --git a/arch/m68k/kernel/traps.c b/arch/m68k/kernel/traps.c
index c5e0a4f..1b07329 100644
--- a/arch/m68k/kernel/traps.c
+++ b/arch/m68k/kernel/traps.c
@@ -181,6 +181,7 @@ static inline void access_error060 (struct frame *fp)
 static inline unsigned long probe040(int iswrite, unsigned long addr, int wbs)
 {
 	unsigned long mmusr;
+	unsigned long old_fc = get_fc();
 
 	set_fc(wbs);
 
@@ -191,7 +192,7 @@ static inline unsigned long probe040(int iswrite, unsigned long addr, int wbs)
 
 	asm volatile (".chip 68040; movec %%mmusr,%0; .chip 68k" : "=r" (mmusr));
 
-	set_fc(USER_DATA);
+	set_fc(old_fc);
 
 	return mmusr;
 }
@@ -200,6 +201,7 @@ static inline int do_040writeback1(unsigned short wbs, unsigned long wba,
 				   unsigned long wbd)
 {
 	int res = 0;
+	unsigned long old_fc = get_fc();
 
 	set_fc(wbs);
 
@@ -215,7 +217,7 @@ static inline int do_040writeback1(unsigned short wbs, unsigned long wba,
 		break;
 	}
 
-	set_fc(USER_DATA);
+	set_fc(old_fc);
 
 	pr_debug("do_040writeback1, res=%d\n", res);
 
diff --git a/arch/m68k/mm/cache.c b/arch/m68k/mm/cache.c
index d26eb1a..70fd62b 100644
--- a/arch/m68k/mm/cache.c
+++ b/arch/m68k/mm/cache.c
@@ -109,14 +109,16 @@ static void __flush_icache_range(unsigned long address, unsigned long endaddr,
 
 void flush_icache_user_range(unsigned long address, unsigned long endaddr)
 {
+	unsigned long old_fc = get_fc();
 	__flush_icache_range(address, endaddr, USER_DATA);
 }
 
 void flush_icache_range(unsigned long address, unsigned long endaddr)
 {
+	unsigned long old_fc = get_fc();
 	set_fc(SUPER_DATA);
 	__flush_icache_range(address, endaddr, SUPER_DATA);
-	set_fc(USER_DATA);
+	set_fc(old_fc);
 }
 EXPORT_SYMBOL(flush_icache_range);
 
-- 
2.7.4


  reply	other threads:[~2021-08-06  3:11 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09  7:01 RFC: remove set_fs for m68k Christoph Hellwig
2021-07-09  7:01 ` [PATCH 1/7] m68k: document that access_ok is broken for !CONFIG_CPU_HAS_ADDRESS_SPACES Christoph Hellwig
2021-07-09  7:01 ` [PATCH 2/7] m68k: use BUILD_BUG for passing invalid sizes to get_user/put_user Christoph Hellwig
2021-07-09  7:01 ` [PATCH 3/7] m68k: remove the inline copy_{from,to}_user variants Christoph Hellwig
2021-07-09  7:01 ` [PATCH 4/7] m68k: remove the err argument to the get_user/put_user assembly helpers Christoph Hellwig
2021-07-09  7:01 ` [PATCH 5/7] m68k: factor the 8-byte lowlevel {get,put}_user code into helpers Christoph Hellwig
2021-07-09  7:01 ` [PATCH 6/7] m68k: provide __{get,put}_kernel_nofault Christoph Hellwig
2021-07-09  7:01 ` [PATCH 7/7] m68k: remove set_fs() Christoph Hellwig
2021-07-11  7:20 ` RFC: remove set_fs for m68k Michael Schmitz
2021-07-12  9:50   ` Christoph Hellwig
2021-07-12 10:20   ` Andreas Schwab
2021-07-12 19:12     ` Michael Schmitz
2021-07-13  5:41       ` Christoph Hellwig
2021-07-13  8:16         ` Michael Schmitz
2021-07-13  8:54           ` Christoph Hellwig
2021-07-14 19:26             ` Michael Schmitz
2021-07-14 20:03               ` Andreas Schwab
2021-07-15  5:44                 ` Michael Schmitz
2021-07-16  2:03               ` Michael Schmitz
2021-07-17  5:41                 ` Michael Schmitz
2021-07-18  1:14                   ` Michael Schmitz
2021-07-21 17:05                     ` Christoph Hellwig
2021-07-21 19:20                       ` Michael Schmitz
2021-07-23  4:00                       ` Michael Schmitz
2021-07-23  5:11                         ` Christoph Hellwig
2021-07-25  7:36                           ` Michael Schmitz
2021-07-31 19:31                             ` Michael Schmitz
2021-08-06  3:10                               ` Michael Schmitz [this message]
2021-08-11  9:12                                 ` Christoph Hellwig
2021-08-12  3:37                                   ` Michael Schmitz
2021-08-15  7:42                                 ` Christoph Hellwig
2021-08-15 19:17                                   ` Michael Schmitz
2021-08-16  6:58                                     ` Christoph Hellwig
     [not found]                                       ` <23f745f2-9086-81fb-3d9e-40ea08a1923@linux-m68k.org>
     [not found]                                         ` <20210816075155.GA29187@lst.de>
     [not found]                                           ` <d407a2a1-738b-5cd5-c2ed-b7250c5da8ec@gmail.com>
     [not found]                                             ` <83571ae-10ae-2919-cde-b6b4a5769c9@linux-m68k.org>
     [not found]                                               ` <dc594142-e459-533e-cac2-c7a213cec464@gmail.com>
     [not found]                                                 ` <f4ab2dcb-6761-c60b-54ce-35d0d017d371@gmail.com>
     [not found]                                                   ` <d772d22e-a945-3e35-80a2-f4783893bea@linux-m68k.org>
     [not found]                                                     ` <b2c55280-657b-51c2-065c-3fc93db050b9@gmail.com>
     [not found]                                                       ` <d7b8f7eb-fc18-c8d-fe3e-dcdf19d3f4b@linux-m68k.org>
     [not found]                                                         ` <755e55ba-4ce2-b4e4-a628-5abc183a557a@linux-m68k.org>
     [not found]                                                           ` <b52a10fe-3e4b-5740-d3f8-52bce3bc988@linux-m68k.org>
     [not found]                                                             ` <31f27da7-be60-8eb-9834-748b653c2246@linux-m68k.org>
2021-09-07  3:28                                                               ` Mainline kernel crashes, was " Finn Thain
2021-09-07  5:53                                                                 ` Michael Schmitz
2021-09-07 23:50                                                                   ` Finn Thain
2021-09-08  8:54                                                                     ` Michael Schmitz
2021-09-09  9:40                                                                       ` Finn Thain
2021-09-09 23:29                                                                         ` Michael Schmitz
2021-09-09 22:51                                                                       ` Finn Thain
2021-09-10  0:03                                                                         ` Michael Schmitz
2021-09-12  0:51                                                                           ` Finn Thain
2021-09-12  3:55                                                                             ` Brad Boyer
2021-09-13  1:27                                                                             ` Finn Thain
2021-09-13  3:26                                                                               ` Michael Schmitz
2021-09-13  5:22                                                                                 ` Finn Thain
2021-09-13  7:20                                                                                   ` Michael Schmitz
2021-09-14  3:13                                                                                     ` Michael Schmitz
2021-09-15  1:38                                                                                     ` Finn Thain
2021-09-15  8:37                                                                                       ` Michael Schmitz
2021-09-16  9:04                                                                                         ` Finn Thain
2021-09-16 22:28                                                                                           ` Michael Schmitz
2021-09-21 21:14                                       ` Michael Schcmitz
2021-08-22 19:33                                         ` Michael Schmitz
2021-08-23  4:04                                           ` Michael Schmitz
2021-08-23 17:59                                           ` Linus Torvalds
2021-08-23 21:31                                             ` Michael Schmitz
2021-08-23 21:49                                               ` Linus Torvalds
2021-08-24  8:08                                                 ` Andreas Schwab
2021-08-24  8:44                                                 ` Michael Schmitz
2021-08-24  8:59                                                   ` Andreas Schwab
2021-08-25  7:51                                                     ` Michael Schmitz
2021-08-25  8:44                                                       ` Andreas Schwab
2021-08-25 22:59                                                         ` Michael Schmitz
2021-08-25 23:30                                                           ` Brad Boyer
2021-08-26  7:46                                                             ` Michael Schmitz
2021-08-26  7:45                                                           ` Andreas Schwab
2021-09-14  2:43                                             ` Michael Schmitz
2021-09-14 15:54                                               ` Linus Torvalds
2021-09-14 16:28                                                 ` Al Viro
2021-09-14 16:38                                                   ` Linus Torvalds
2021-09-15  1:06                                                     ` Al Viro
2021-07-12 19:04   ` Michael Schmitz

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=251aa093-047a-b37c-4e88-d543c6fa8bc6@gmail.com \
    --to=schmitzmic@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=gerg@linux-m68k.org \
    --cc=hch@lst.de \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=schwab@linux-m68k.org \
    --cc=torvalds@linux-foundation.org \
    /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: link
Be 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.