mm/memory-failure: prioritize prctl(PR_MCE_KILL) over vm.memory_failure_early_kill
Subsystems (8)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Andrew Morton
maintainerPATCH 1/5 mm/memory-failure: prioritize prctl(PR_MCE_KILL) over vm.memory_failure_early_kill
From: Naoya Horiguchi <[email protected]>
Subject: mm/memory-failure: prioritize prctl(PR_MCE_KILL) over vm.memory_failure_early_kill
Patch series "hwpoison: fixes signaling on memory error"
This is a small patchset to solve issues in memory error handler to send SIGBUS to proper process/thread as expected in configuration. Please see descriptions in individual patches for more details.
This patch (of 2):
Early-kill policy is controlled from two types of settings, one is per-process setting prctl(PR_MCE_KILL) and the other is system-wide setting vm.memory_failure_early_kill. Users expect per-process setting to override system-wide setting as many other settings do, but early-kill setting doesn't work as such. For example, if a system configures vm.memory_failure_early_kill to 1 (enabled), a process receives SIGBUS even if it's configured to explicitly disable PF_MCE_KILL by prctl(). That's not desirable for applications with their own policies.
This patch is suggesting to change the priority of these two types of settings, by checking sysctl_memory_failure_early_kill only when a given process has the default kill policy.
Note that this patch is solving a thread choice issue too. Originally, collect_procs() always chooses the main thread when vm.memory_failure_early_kill is 1, even if the process has a dedicated thread for memory error handling. SIGBUS should be sent to the dedicated thread if early-kill is enabled via vm.memory_failure_early_kill as we are doing for PR_MCE_KILL_EARLY processes.
---
mm/memory-failure.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
mm/memory-failure.c renamed from mm/memory-failure.c~mm-memory-failure-prioritize-prctlpr_mce_kill-over-vmmemory_failure_early_kill +10 -10
@@ -402,9 +402,15 @@ static struct task_struct *find_early_ki {struct task_struct *t; -for_each_thread (tsk, t) -if ((t->flags &PF_MCE_PROCESS ) && (t->flags &PF_MCE_EARLY )) -return t; +for_each_thread (tsk, t) { +if (t->flags &PF_MCE_PROCESS ) { +if (t->flags &PF_MCE_EARLY ) +return t; + }else { +if (sysctl_memory_failure_early_kill) +return t; + } + }return NULL ; }
@@ -417,17 +423,11 @@ static struct task_struct *find_early_kistatic struct task_struct *task_early_kill (struct task_struct *tsk,int force_early) { -struct task_struct *t;if (!tsk->mm)return NULL ;if (force_early)return tsk; - t =find_early_kill_thread (tsk); -if (t) -return t; -if (sysctl_memory_failure_early_kill) -return tsk; -return NULL ; +return find_early_kill_thread (tsk); }/*
_
Andrew Morton
maintainerPATCH 2/5 mm/memory-failure: send SIGBUS(BUS_MCEERR_AR) only to current thread
In reply to a message not in the archiveFrom: Naoya Horiguchi <[email protected]>
Subject: mm/memory-failure: send SIGBUS(BUS_MCEERR_AR) only to current thread
Action Required memory error should happen only when a processor is about to access to a corrupted memory, so it's synchronous and only affects current process/thread. Recently commit 872e9a205c84 ("mm,memory_failure: don't send BUS_MCEERR_AO for action required error") fixed the issue that Action Required memory could unnecessarily send SIGBUS to the processes which share the error memory. But we still have another issue that we could send SIGBUS to a wrong thread.
This is because collect_procs() and task_early_kill() fails to add the current process to "to-kill" list. So this patch is suggesting to fix it. With this fix, SIGBUS(BUS_MCEERR_AR) is never sent to non-current process/thread.
---
mm/memory-failure.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
mm/memory-failure.c renamed from mm/memory-failure.c~mm-memory-failure-send-sigbusbus_mceerr_ar-only-to-current-thread +16 -7
@@ -212,15 +212,13 @@ static int kill_proc(struct to_kill *tk,short addr_lsb = tk->size_shift;int ret =0 ; -if ((t->mm == current->mm) || !(flags &MF_ACTION_REQUIRED )) -pr_err ("Memory failure: %#lx: Sending SIGBUS to %s:%d due to hardware memory corruption\n" , +pr_err ("Memory failure: %#lx: Sending SIGBUS to %s:%d due to hardware memory corruption\n" , pfn, t->comm, t->pid);if (flags &MF_ACTION_REQUIRED ) { -if (t->mm == current->mm) - ret =force_sig_mceerr (BUS_MCEERR_AR , +WARN_ON_ONCE (t != current); + ret =force_sig_mceerr (BUS_MCEERR_AR , (void __user *)tk->addr, addr_lsb); -/* send no signal to non-current processes */ }else {/* * Don't use force here, it's convenient if the signal
@@ -419,14 +417,25 @@ static struct task_struct *find_early_ki* to be signaled when some page under the process is hwpoisoned. * Return task_struct of the dedicated thread (main thread unless explicitly * specified) if the process is "early kill," and otherwise returns NULL. +* +* Note that the above is true for Action Optional case, but not for Action +* Required case where SIGBUS should sent only to the current thread. */ static struct task_struct *task_early_kill (struct task_struct *tsk,int force_early) {if (!tsk->mm)return NULL ; -if (force_early) -return tsk; +if (force_early) { +/* +* Comparing ->mm here because current task might represent +* a subthread, while tsk always points to the main thread. +*/ +if (tsk->mm == current->mm) +return current; +else +return NULL ; + }return find_early_kill_thread (tsk); }
_
Andrew Morton
maintainerPATCH 3/5 ocfs2: fix build failure when TCP/IP is disabled
In reply to a message not in the archiveFrom: Tom Seewald <[email protected]>
Subject: ocfs2: fix build failure when TCP/IP is disabled
After commit 12abc5ee7873 ("tcp: add tcp_sock_set_nodelay") and commit c488aeadcbd0 ("tcp: add tcp_sock_set_user_timeout"), building the kernel with OCFS2_FS=y but without INET=y causes it to fail with:
ld: fs/ocfs2/cluster/tcp.o: in function `o2net_accept_many':
tcp.c:(.text+0x21b1): undefined reference to `tcp_sock_set_nodelay'
ld: tcp.c:(.text+0x21c1): undefined reference to `tcp_sock_set_user_timeout '
ld: fs/ocfs2/cluster/tcp.o: in function `o2net_start_connect':
tcp.c:(.text+0x2633): undefined reference to `tcp_sock_set_nodelay'
ld: tcp.c:(.text+0x2643): undefined reference to `tcp_sock_set_user_timeout '
This is due to tcp_sock_set_nodelay() and tcp_sock_set_user_timeout() being declared in linux/tcp.h and defined in net/ipv4/tcp.c, which depend on TCP/IP being enabled.
To fix this, make OCFS2_FS depend on INET=y which already requires NET=y.
12abc5ee7873 ("tcp: add tcp_sock_set_nodelay") and commit
---
fs/ocfs2/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/Kconfig renamed from fs/ocfs2/Kconfig~fix-build-failure-of-ocfs2-when-tcp-ip-is-disabled +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config OCFS2_FS tristate "OCFS2 file system support" - depends on NET && SYSFS && CONFIGFS_FS + depends on INET && SYSFS && CONFIGFS_FS select JBD2 select CRC32 select QUOTA
_
Andrew Morton
maintainerPATCH 4/5 lib/lzo: fix ambiguous encoding bug in lzo-rle
In reply to a message not in the archiveFrom: Dave Rodgman <[email protected]>
Subject: lib/lzo: fix ambiguous encoding bug in lzo-rle
In some rare cases, for input data over 32 KB, lzo-rle could encode two different inputs to the same compressed representation, so that decompression is then ambiguous (i.e. data may be corrupted - although zram is not affected because it operates over 4 KB pages).
This modifies the compressor without changing the decompressor or the bitstream format, such that:
- there is no change to how data produced by the old compressor is decompressed
- an old decompressor will correctly decode data from the updated compressor
- performance and compression ratio are not affected
- we avoid introducing a new bitstream format
In testing over 12.8M real-world files totalling 903 GB, three files were affected by this bug. I also constructed 37M semi-random 64 KB files totalling 2.27 TB, and saw no affected files. Finally I tested over files constructed to contain each of the ~1024 possible bad input sequences; for all of these cases, updated lzo-rle worked correctly.
There is no significant impact to performance or compression ratio.
---
Documentation/lzo.txt | 8 ++++++-- lib/lzo/lzo1x_compress.c | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-)
Documentation/lzo.txt renamed from Documentation/lzo.txt~lib-lzo-fix-ambiguous-encoding-bug-in-lzo-rle +6 -2
@@ -159,11 +159,15 @@ Byte sequences distance = 16384 + (H << 14) + D state = S (copy S literals after this block) End of stream is reached if distance == 16384 + In version 1 only, to prevent ambiguity with the RLE case when + ((distance & 0x803f) == 0x803f) && (261 <= length <= 264), the + compressor must not emit block copies where distance and length + meet these conditions. In version 1 only, this instruction is also used to encode a run of - zeros if distance = 0xbfff, i.e. H = 1 and the D bits are all 1. + zeros if distance = 0xbfff, i.e. H = 1 and the D bits are all 1. In this case, it is followed by a fourth byte, X. - run length = ((X << 3) | (0 0 0 0 0 L L L)) + 4. + run length = ((X << 3) | (0 0 0 0 0 L L L)) + 4 0 0 1 L L L L L (32..63) Copy of small block within 16kB distance (preferably less than 34B)
lib/lzo/lzo1x_compress.c renamed from lib/lzo/lzo1x_compress.c~lib-lzo-fix-ambiguous-encoding-bug-in-lzo-rle +13 -0
@@ -268,6 +268,19 @@ m_len_done: *op++ = (M4_MARKER | ((m_off >>11 ) &8 ) | (m_len -2 )); else { +if (unlikely (((m_off &0x403f ) ==0x403f ) + && (m_len >=261 ) + && (m_len <=264 )) + &&likely (bitstream_version)) { +// Under lzo-rle, block copies +// for 261 <= length <= 264 and +// (distance & 0x80f3) == 0x80f3 +// can result in ambiguous +// output. Adjust length +// to 260 to prevent ambiguity. + ip -= m_len -260 ; + m_len =260 ; + } m_len -=M4_MAX_LEN ; *op++ = (M4_MARKER | ((m_off >>11 ) &8 ));while (unlikely (m_len >255 )) {
_
Andrew Morton
maintainerPATCH 5/5 amdgpu: a NULL ->mm does not mean a thread is a kthread
In reply to a message not in the archiveFrom: Christoph Hellwig <[email protected]>
Subject: amdgpu: a NULL ->mm does not mean a thread is a kthread
Use the proper API instead.
---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h~amdgpu-a-null-mm-does-not-mean-a-thread-is-a-kthread +1 -1
@@ -196,7 +196,7 @@ uint8_t amdgpu_amdkfd_get_xgmi_hops_counpagefault_disable (); \if ((mmptr) == current->mm) { \ valid = !get_user ((dst), (wptr)); \ - }else if (current->mm ==NULL ) { \ + }else if (current->flags &PF_KTHREAD ) { \kthread_use_mm (mmptr); \ valid = !get_user ((dst), (wptr)); \kthread_unuse_mm (mmptr); \
_