All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure()
@ 2023-07-04 12:19 Miaohe Lin
  2023-07-04 16:13 ` kernel test robot
  2023-07-04 16:23 ` kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Miaohe Lin @ 2023-07-04 12:19 UTC (permalink / raw)
  To: akpm, naoya.horiguchi; +Cc: linux-mm, linux-kernel, linmiaohe

If memory_failure() succeeds to hwpoison a page, the set_mce_nospec() is
expected to be called to prevent speculative access to the page by marking
it not-present. Add such missing call to set_mce_nospec() in async memory
failure handling scene.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/memory-failure.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index e245191e6b04..c7f88c4042d4 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -63,6 +63,7 @@
 #include <linux/pagewalk.h>
 #include <linux/shmem_fs.h>
 #include <linux/sysctl.h>
+#include <linux/set_memory.h>
 #include "swap.h"
 #include "internal.h"
 #include "ras/ras_event.h"
@@ -2407,7 +2408,9 @@ static void memory_failure_work_func(struct work_struct *work)
 		if (entry.flags & MF_SOFT_OFFLINE)
 			soft_offline_page(entry.pfn, entry.flags);
 		else
-			memory_failure(entry.pfn, entry.flags);
+			if (!memory_failure(entry.pfn, entry.flags))
+				if (!entry.flags & MF_SW_SIMULATED)
+					set_mce_nospec(entry.pfn);
 	}
 }
 
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure()
  2023-07-04 12:19 [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure() Miaohe Lin
@ 2023-07-04 16:13 ` kernel test robot
  2023-07-04 16:23 ` kernel test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2023-07-04 16:13 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: llvm, oe-kbuild-all

Hi Miaohe,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Miaohe-Lin/mm-memory-failure-add-missing-set_mce_nospec-for-memory_failure/20230704-202035
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20230704121948.1331846-1-linmiaohe%40huawei.com
patch subject: [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure()
config: arm64-randconfig-r003-20230704 (https://download.01.org/0day-ci/archive/20230705/202307050036.KEckskkD-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce: (https://download.01.org/0day-ci/archive/20230705/202307050036.KEckskkD-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307050036.KEckskkD-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> mm/memory-failure.c:2406:9: warning: logical not is only applied to the left hand side of this bitwise operator [-Wlogical-not-parentheses]
    2406 |                                 if (!entry.flags & MF_SW_SIMULATED)
         |                                     ^            ~
   mm/memory-failure.c:2406:9: note: add parentheses after the '!' to evaluate the bitwise operator first
    2406 |                                 if (!entry.flags & MF_SW_SIMULATED)
         |                                     ^                             
         |                                      (                            )
   mm/memory-failure.c:2406:9: note: add parentheses around left hand side expression to silence this warning
    2406 |                                 if (!entry.flags & MF_SW_SIMULATED)
         |                                     ^           
         |                                     (           )
   1 warning generated.


vim +2406 mm/memory-failure.c

  2387	
  2388	static void memory_failure_work_func(struct work_struct *work)
  2389	{
  2390		struct memory_failure_cpu *mf_cpu;
  2391		struct memory_failure_entry entry = { 0, };
  2392		unsigned long proc_flags;
  2393		int gotten;
  2394	
  2395		mf_cpu = container_of(work, struct memory_failure_cpu, work);
  2396		for (;;) {
  2397			spin_lock_irqsave(&mf_cpu->lock, proc_flags);
  2398			gotten = kfifo_get(&mf_cpu->fifo, &entry);
  2399			spin_unlock_irqrestore(&mf_cpu->lock, proc_flags);
  2400			if (!gotten)
  2401				break;
  2402			if (entry.flags & MF_SOFT_OFFLINE)
  2403				soft_offline_page(entry.pfn, entry.flags);
  2404			else
  2405				if (!memory_failure(entry.pfn, entry.flags))
> 2406					if (!entry.flags & MF_SW_SIMULATED)
  2407						set_mce_nospec(entry.pfn);
  2408		}
  2409	}
  2410	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure()
  2023-07-04 12:19 [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure() Miaohe Lin
  2023-07-04 16:13 ` kernel test robot
@ 2023-07-04 16:23 ` kernel test robot
  2023-07-05  1:53   ` Miaohe Lin
  1 sibling, 1 reply; 4+ messages in thread
From: kernel test robot @ 2023-07-04 16:23 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: oe-kbuild-all

Hi Miaohe,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Miaohe-Lin/mm-memory-failure-add-missing-set_mce_nospec-for-memory_failure/20230704-202035
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20230704121948.1331846-1-linmiaohe%40huawei.com
patch subject: [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure()
config: arm64-randconfig-r021-20230704 (https://download.01.org/0day-ci/archive/20230705/202307050025.piXqvNt6-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230705/202307050025.piXqvNt6-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307050025.piXqvNt6-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/export.h:5,
                    from include/linux/linkage.h:7,
                    from include/linux/kernel.h:17,
                    from mm/memory-failure.c:39:
   mm/memory-failure.c: In function 'memory_failure_work_func':
>> mm/memory-failure.c:2406:37: warning: suggest parentheses around operand of '!' or change '&' to '&&' or '!' to '~' [-Wparentheses]
    2406 |                                 if (!entry.flags & MF_SW_SIMULATED)
         |                                     ^~~~~~~~~~~~
   include/linux/compiler.h:57:52: note: in definition of macro '__trace_if_var'
      57 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
         |                                                    ^~~~
   mm/memory-failure.c:2406:33: note: in expansion of macro 'if'
    2406 |                                 if (!entry.flags & MF_SW_SIMULATED)
         |                                 ^~
>> mm/memory-failure.c:2406:37: warning: suggest parentheses around operand of '!' or change '&' to '&&' or '!' to '~' [-Wparentheses]
    2406 |                                 if (!entry.flags & MF_SW_SIMULATED)
         |                                     ^~~~~~~~~~~~
   include/linux/compiler.h:57:61: note: in definition of macro '__trace_if_var'
      57 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
         |                                                             ^~~~
   mm/memory-failure.c:2406:33: note: in expansion of macro 'if'
    2406 |                                 if (!entry.flags & MF_SW_SIMULATED)
         |                                 ^~
>> mm/memory-failure.c:2406:37: warning: suggest parentheses around operand of '!' or change '&' to '&&' or '!' to '~' [-Wparentheses]
    2406 |                                 if (!entry.flags & MF_SW_SIMULATED)
         |                                     ^~~~~~~~~~~~
   include/linux/compiler.h:68:10: note: in definition of macro '__trace_if_value'
      68 |         (cond) ?                                        \
         |          ^~~~
   include/linux/compiler.h:55:28: note: in expansion of macro '__trace_if_var'
      55 | #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
         |                            ^~~~~~~~~~~~~~
   mm/memory-failure.c:2406:33: note: in expansion of macro 'if'
    2406 |                                 if (!entry.flags & MF_SW_SIMULATED)
         |                                 ^~


vim +2406 mm/memory-failure.c

  2387	
  2388	static void memory_failure_work_func(struct work_struct *work)
  2389	{
  2390		struct memory_failure_cpu *mf_cpu;
  2391		struct memory_failure_entry entry = { 0, };
  2392		unsigned long proc_flags;
  2393		int gotten;
  2394	
  2395		mf_cpu = container_of(work, struct memory_failure_cpu, work);
  2396		for (;;) {
  2397			spin_lock_irqsave(&mf_cpu->lock, proc_flags);
  2398			gotten = kfifo_get(&mf_cpu->fifo, &entry);
  2399			spin_unlock_irqrestore(&mf_cpu->lock, proc_flags);
  2400			if (!gotten)
  2401				break;
  2402			if (entry.flags & MF_SOFT_OFFLINE)
  2403				soft_offline_page(entry.pfn, entry.flags);
  2404			else
  2405				if (!memory_failure(entry.pfn, entry.flags))
> 2406					if (!entry.flags & MF_SW_SIMULATED)
  2407						set_mce_nospec(entry.pfn);
  2408		}
  2409	}
  2410	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure()
  2023-07-04 16:23 ` kernel test robot
@ 2023-07-05  1:53   ` Miaohe Lin
  0 siblings, 0 replies; 4+ messages in thread
From: Miaohe Lin @ 2023-07-05  1:53 UTC (permalink / raw)
  To: kernel test robot; +Cc: oe-kbuild-all

On 2023/7/5 0:23, kernel test robot wrote:
> Hi Miaohe,
> 
> [This is a private test report for your RFC patch.]
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on akpm-mm/mm-everything]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Miaohe-Lin/mm-memory-failure-add-missing-set_mce_nospec-for-memory_failure/20230704-202035
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
> patch link:    https://lore.kernel.org/r/20230704121948.1331846-1-linmiaohe%40huawei.com
> patch subject: [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure()
> config: arm64-randconfig-r021-20230704 (https://download.01.org/0day-ci/archive/20230705/202307050025.piXqvNt6-lkp@intel.com/config)
> compiler: aarch64-linux-gcc (GCC) 12.3.0
> reproduce: (https://download.01.org/0day-ci/archive/20230705/202307050025.piXqvNt6-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202307050025.piXqvNt6-lkp@intel.com/

Thanks for reporting. This leads to problem too when I compiled the kernel and it's fixed in my workload but I forgot to post that change to the patch. Sorry for my careless.

	mm/memory-failure.c: In function ‘memory_failure_work_func’:
	mm/memory-failure.c:2412:9: error: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
	 2412 |     if (!entry.flags & MF_SW_SIMULATED)
	      |         ^~~~~~~~~~~~


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-05  2:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-04 12:19 [RFC PATCH] mm: memory-failure: add missing set_mce_nospec() for memory_failure() Miaohe Lin
2023-07-04 16:13 ` kernel test robot
2023-07-04 16:23 ` kernel test robot
2023-07-05  1:53   ` Miaohe Lin

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.