6.1.193-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 1617/2857 mm/ksm: fix use of a freed anon_vma at swap-in
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 4c2dec1dce368ad9e9b1814307cb5ef3832fa07e ]
A folio read from a swap slot previously shared by KSM can remain in the swap cache after the process that first mapped it exits. Its anon_vma can then be freed, so ksm_might_need_to_copy() must not dereference it to compare roots.
Doing so can result in some false-positives, resulting in the reverse mapping missing the new folio mapping, preventing migration and reclaim.
SLAB_TYPESAFE_BY_RCU allows individual anon_vma objects to be reused immediately after freeing. A stale pointer can then refer to another anon_vma whose root matches, even though the target VMA is not linked to that anon_vma.
Move the anonymous rmap compatibility checks into folio_anon_rmap_compatible(). Keep the page-index check and compare the folio's anon_vma pointer against the VMA's own anon_vma and root first.
If neither matches, bite the bullet and walk the VMA's anon_vma_chain. The VMA keeps these anon_vmas alive, and finding a match guarantees that reverse mapping can find the new mapping.
Lorenzo Stoakes says in a private discussion:
"This isn't quite equivalent to the existing check.
Every anon_vma in an anon_vma_chain shares the same root, but if you split a VMA then fork both of them like this:
VMA A
/ \ <split>
VMA B VMA C
\ /
root <- anon_vma 1
----^ ^---- <fork>
/ parent \
anon_vma 2 anon_vma 3
| |
VMA D VMA E
VMA's D and E both get their own new
anon_vma's such that:
VMA D: anon_vma 2 -> anon_vma 1 -> root
VMA E: anon_vma 3 -> anon_vma 1 -> root
And if you found a folio referencing anon_vma 2, the existing check:
anon_vma->root == vma->anon-vma->root
Would be true for VMA's B, C, D & E.
However after your change it'd be true for VMA D only, as it's the only one with anon_vma 2 in its anon_vma_chain.
Whether or not that could actually happen in practice... 🙂 I don't know.
[...] after your change it'd be true for VMA D only, as it's the only one with anon_vma 2 in its anon_vma_chain. [...] I would [...] say that you are making the test stricter but more correct.
"
If this affects performance when KSM was never even involved, we could just track whether KSM ever merged anything and just skip these checks.
There isn't really a lot we can do otherwise: for mapped folios we might be able to use folio_get_anon_vma(), but for unmapped folios there really is no easy way to see if the anon_vma is still valid.
Document the (confusing) lifetime requirements of folio_anon_vma().
--- mm/ksm.c | 16 +++++++++++++--- mm/util.c | 13 +++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-)
mm/ksm.c +13 -3
@@ -2692,6 +2692,7 @@ struct page *ksm_might_need_to_copy(struct page *page, {struct folio *folio =page_folio (page);struct anon_vma *anon_vma =folio_anon_vma (folio); +struct anon_vma_chain *avc;struct page *new_page;if (PageKsm (page)) {
@@ -2700,9 +2701,18 @@ struct page *ksm_might_need_to_copy(struct page *page,return page;/* no need to copy it */ }else if (!anon_vma) {return page;/* no need to copy it */ - }else if (page->index ==linear_page_index (vma, address) && - anon_vma->root == vma->anon_vma->root) { -return page;/* still no need to copy it */ + }else if (page->index ==linear_page_index (vma, address)) { +/* +* Careful: anon_vma might have been freed, so we cannot safely +* dereference it. Add a fast path before we walk the anon_vma chain. +*/ +if (anon_vma == vma->anon_vma || anon_vma == vma->anon_vma->root) +return page;/* still no need to copy it */ + +list_for_each_entry (avc, &vma->anon_vma_chain, same_vma) { +if (avc->anon_vma == anon_vma) +return page; + } }if (!PageUptodate (page))return page;/* let do_swap_page report the error */
mm/util.c +13 -0
@@ -743,6 +743,19 @@ bool folio_mapped(struct folio *folio) }EXPORT_SYMBOL (folio_mapped); +/** +* folio_anon_vma - Get a folio's raw anon_vma pointer. +* @folio: The folio. +* +* The returned pointer may be stale for an unmapped folio. The caller +* must ensure the anon_vma stays alive before dereferencing it. A folio +* reference or lock alone is insufficient; use folio_get_anon_vma() when +* the anon_vma's lifetime is not otherwise protected. Note that +* folio_get_anon_vma() is only useful for folios that are still mapped. +* +* Return: The raw anon_vma pointer for an anonymous, non-KSM folio, or +* %NULL otherwise. +*/ struct anon_vma *folio_anon_vma (struct folio *folio) {unsigned long mapping = (unsigned long )folio->mapping;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1618/2857 ksmbd: enforce the read-only share flag when creating a stream
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit 09139429fab3a5114c18d7c15fb161511d4d66c9 ]
When a share is read-only, smb2_open() rejects opens that would create or truncate a file. Creating a named stream on an existing file with streams_xattr sets neither O_CREAT nor O_TRUNC, so it passes this check, and smb2_set_stream_name_xattr() then creates the stream. On a Time Machine share, opening a missing AFP_AfpInfo stream also writes one. A user who can write a file at the filesystem level can therefore add streams to it through a read-only share.
Do not create a stream or synthesize AFP_AfpInfo when the share is not writable. Existing streams still open normally, and a missing stream opened with FILE_OPEN still returns STATUS_OBJECT_NAME_NOT_FOUND.
--- fs/smb/server/smb2pdu.c | 3 +++ 1 file changed, 3 insertions(+)
fs/smb/server/smb2pdu.c +3 -0
@@ -2559,6 +2559,9 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path,return -EBADF ; } +if (!test_tree_conn_flag (fp->tcon,KSMBD_TREE_CONN_FLAG_WRITABLE )) +return -EACCES ; + rc =ksmbd_vfs_setxattr (user_ns, path, xattr_stream_name,NULL ,0 ,0 , false);if (rc <0 )pr_err ("Failed to store XATTR stream name :%d\n" , rc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1619/2857 fbcon: Rebuild rotated font buffer on font change
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yao Yiqi <[email protected]>
[ Upstream commit e4b6b865d45d8dafb6c6f28c8a993a5b4431d25a ]
fbcon_rotate_font() caches a rotated copy of the console font in par->rotated.buf. The buffer is sized from the font's width, height and charcount, and is rebuilt in fbcon_init(), fbcon_switch() and fbcon_modechanged(), but not in fbcon_do_set_font().
When the font is changed through KDFONTOP, the new geometry is installed and vc_resize() redraws before the buffer is rebuilt. The rotated putcs/cursor ops then index the old buffer with the new cell size; KASAN reports a slab-out-of-bounds read in soft_cursor().
Rebuild the buffer for the visible console before the redraw, as the other callers do: select the console's blitting state with set_blitting_type() (which also uploads the new font's map on tile-blitting hardware), then rebuild. Background consoles keep their rebuild at fbcon_switch() time, as the buffer is shared per framebuffer and must not be updated for a console that is not being displayed.
To ensure a correct rollback when the rebuild or the following vc_resize() fails, save the rotated font state, clear it before rebuilding, and restore it in the error path of fbcon_do_set_font().
--- drivers/video/fbdev/core/fbcon.c | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
drivers/video/fbdev/core/fbcon.c +57 -0
@@ -2415,6 +2415,12 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,int resize, ret, old_userfont, old_width, old_height, old_charcount;u8 *old_data = vc->vc_font.data;unsigned short old_hi_font_mask = vc->vc_hi_font_mask; +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +u8 *saved_fontdata =NULL , *saved_fontbuffer =NULL ; +u32 saved_fd_size =0 ; +int saved_cur_rotate =0 ; +bool rotated_saved = false; +#endif resize = (w != vc->vc_font.width) || (h != vc->vc_font.height); vc->vc_font.data = (void *)(p->fontdata = data);
@@ -2434,6 +2440,33 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,else if (!vc->vc_hi_font_mask && charcount ==512 )set_vc_hi_font (vc, true); +/* +* Select the console's blitting state and update the rotated font buffer +* to match the new font, so that the rendering below does not use a +* cache that was built for the old font. Clear the cached state so +* the rebuild allocates a fresh buffer; the old state is kept until +* the font change can no longer fail. +*/ +if (con_is_visible (vc)) { +set_blitting_type (vc, info); +if (par->rotate_font) { +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION + saved_fontdata = par->fontdata; + saved_fontbuffer = par->fontbuffer; + saved_fd_size = par->fd_size; + saved_cur_rotate = par->cur_rotate; + par->fontdata =NULL ; + par->fontbuffer =NULL ; + par->fd_size =0 ; + par->cur_rotate =0 ; + rotated_saved = true; +#endif + ret = par->rotate_font (info, vc); +if (ret) + goto err_out; + } + } +if (resize) {int cols, rows;
@@ -2450,11 +2483,28 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,update_screen (vc); } +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +if (rotated_saved) +kfree (saved_fontbuffer); +#endif if (old_userfont && (--REFCOUNT (old_data) ==0 ))kfree (old_data -FONT_EXTRA_WORDS *sizeof (int ));return 0 ; err_out: +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +/* +* Drop the buffer built for the new font and restore the saved +* state. +*/ +if (rotated_saved) { +kfree (par->fontbuffer); + par->fontdata = saved_fontdata; + par->fontbuffer = saved_fontbuffer; + par->fd_size = saved_fd_size; + par->cur_rotate = saved_cur_rotate; + } +#endif p->fontdata = old_data; vc->vc_font.data = old_data;
@@ -2474,6 +2524,13 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,else if (!old_hi_font_mask && vc->vc_hi_font_mask)set_vc_hi_font (vc, false); +/* +* Re-select the blitting type, which re-uploads the font map on +* tile-blitting hardware. +*/ +if (con_is_visible (vc)) +set_blitting_type (vc, info); +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1620/2857 btrfs: prevent deleting the wrong subvolume by ID
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: guolingxing <[email protected]>
[ Upstream commit 1960146913b31b288ed2cd607d103ee3b41681d4 ]
When deleting a subvolume by ID, btrfs_ioctl_snap_destroy() first resolves the requested ID to a name, then looks up that name again under the parent directory lock.
A concurrent rename can change which subvolume is associated with the name between these operations. Since the deletion path does not verify the ID of the resolved subvolume, it can delete a different subvolume while leaving the requested one intact.
This was reproduced by repeatedly exchanging the names of two subvolumes using renameat2(RENAME_EXCHANGE) while deleting one of them by ID. The wrong subvolume was deleted in 9 out of 14 independent tests.
Fix this by checking that the resolved subvolume ID matches the requested ID while holding the parent directory lock. Return -EAGAIN on a mismatch so that userspace can retry the operation instead of being told that the requested subvolume does not exist.
--- fs/btrfs/ioctl.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/btrfs/ioctl.c +11 -0
@@ -3446,6 +3446,17 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, inode =d_inode (dentry); dest =BTRFS_I (inode)->root; + +/* +* A concurrent rename may have changed which subvolume the name +* refers to. Verify that the resolved ID still matches the requested ID. +*/ +if (destroy_v2 && (vol_args2->flags &BTRFS_SUBVOL_SPEC_BY_ID ) && +btrfs_root_id (dest) != vol_args2->subvolid) { + err = -EAGAIN ; + goto out_dput; + } +if (!capable (CAP_SYS_ADMIN )) {/* * Regular user. Only allow this with a special mount
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1621/2857 ocfs2/heartbeat: serialize concurrent writes to a regions dev attribute
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eklavya Singh <[email protected]>
[ Upstream commit 0a8f258c0f012314c36b9e4818cdc0178c68f891 ]
o2hb_region_dev_store() checks reg->hr_bdev_file to see if the region is already started, but nothing stops two writers from doing that at the same time. configfs only serializes writes through the same open file, so two processes that each open the dev attribute can both get past the check:
A: hr_bdev_file is NULL, opens file A, sets hr_bdev_file = A
B: hr_bdev_file is NULL, opens file B, sets hr_bdev_file = B
A: start fails, fput(hr_bdev_file) drops B, sets it to NULL
B: start fails, fput(NULL)
Both calls also use the same hr_slots, hr_slot_data and hr_tmp_block, so the error paths can free the slot data twice.
syzbot hit the fput(NULL) with an unbound loop device, where every start fails with -EIO. With four threads doing the same thing on a KASAN kernel I get both crashes within a second:
BUG: KASAN: double-free in o2hb_unmap_slot_data+0x14d/0x2f0 BUG: kernel NULL pointer dereference, address: 0000000000000158
Add a mutex to the region and hold it in dev_store(), in the block_bytes, start_block and blocks stores, and in dev_show(), since they all look at hr_bdev_file. dev_store() cleans up with goto, so it takes the mutex in a small wrapper rather than with guard(). The mutex is dropped while dev_store() waits for the heartbeat to become steady, which takes seconds, so a read of dev doesn't stall behind a start. hr_bdev_file is already set at that point, so other writers still get -EINVAL, and the cleanup after the wait retakes the mutex.
With the patch the same test ran for 10 minutes with lockdep on and nothing was reported. So did a second one, with a working loop device, that interrupts starts during the wait while other threads read and write the attributes.
--- fs/ocfs2/cluster/heartbeat.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/heartbeat.c +19 -2
@@ -268,6 +268,8 @@ struct o2hb_region {struct list_head hr_handler_list;/* Serializes timeout arming against failed-start and teardown. */ struct mutex hr_arming_mutex; +/* Serializes the dev, block_bytes, start_block and blocks attributes. */ +struct mutex hr_dev_mutex;bool hr_stopping;/* last hb status, 0 for success, other value for error. */
@@ -1657,6 +1659,7 @@ static ssize_t o2hb_region_block_bytes_store(struct config_item *item,unsigned long block_bytes;unsigned int block_bits; +guard (mutex)(®->hr_dev_mutex);if (reg->hr_bdev)return -EINVAL ;
@@ -1686,6 +1689,7 @@ static ssize_t o2hb_region_start_block_store(struct config_item *item,char *p = (char *)page;ssize_t ret; +guard (mutex)(®->hr_dev_mutex);if (reg->hr_bdev)return -EINVAL ;
@@ -1711,6 +1715,7 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,unsigned long tmp;char *p = (char *)page; +guard (mutex)(®->hr_dev_mutex);if (reg->hr_bdev)return -EINVAL ;
@@ -1728,10 +1733,12 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,static ssize_t o2hb_region_dev_show (struct config_item *item,char *page) { +struct o2hb_region *reg =to_o2hb_region (item);unsigned int ret =0 ; -if (to_o2hb_region (item)->hr_bdev) - ret =sprintf (page,"%pg\n" ,to_o2hb_region (item)->hr_bdev); +guard (mutex)(®->hr_dev_mutex); +if (reg->hr_bdev) + ret =sprintf (page,"%pg\n" , reg->hr_bdev);return ret; }
@@ -1859,6 +1866,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,ssize_t ret = -EINVAL ;int live_threshold; +mutex_lock (®->hr_dev_mutex); +if (reg->hr_bdev) goto out;
@@ -1958,9 +1967,15 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, reg->hr_task = hb_task;spin_unlock (&o2hb_live_lock); +/* +* Don't hold hr_dev_mutex across the wait, which can take seconds. +* hr_bdev is already set, so other writers still get -EINVAL. +*/ +mutex_unlock (®->hr_dev_mutex); ret =wait_event_interruptible (o2hb_steady_queue,atomic_read (®->hr_steady_iterations) ==0 || reg->hr_node_deleted); +mutex_lock (®->hr_dev_mutex);if (ret) {atomic_set (®->hr_steady_iterations,0 ); reg->hr_aborted_start =1 ;
@@ -2012,6 +2027,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, out2:fdput (f); out: +mutex_unlock (®->hr_dev_mutex);return ret; }
@@ -2117,6 +2133,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *gINIT_LIST_HEAD (®->hr_all_item);mutex_init (®->hr_arming_mutex); +mutex_init (®->hr_dev_mutex); reg->hr_stopping = true;INIT_DELAYED_WORK (®->hr_write_timeout_work, o2hb_write_timeout);INIT_DELAYED_WORK (®->hr_nego_timeout_work, o2hb_nego_timeout);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1622/2857 ALSA: compress: fix buffer leak on failed SET_PARAMS
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit fbc74ca9fbf7e0b8f6872ccac62f9f4a1f3b5e53 ]
When the driver has neither ops->copy nor a preallocated dma_buffer_p, snd_compr_allocate_buffer() kmallocs runtime->buffer. If ops->set_params() then rejects the parameters, SET_PARAMS fails, the stream stays in the OPEN state and keeps the buffer. The next SET_PARAMS allocates a new buffer and overwrites the pointer, so repeated SET_PARAMS calls with parameters that the driver rejects leak one buffer per call.
Release the framework-owned buffer when ops->set_params() fails on an OPEN stream, so that a failed SET_PARAMS leaves no buffer behind and the buffer is allocated only once per successful setup. Use the same ownership check as snd_compr_free().
--- sound/core/compress_offload.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/core/compress_offload.c +8 -1
@@ -602,8 +602,15 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) } retval = stream->ops->set_params (stream, params); -if (retval) +if (retval) { +/* the stream stays OPEN: drop the buffer of the rejected setup */ +if (stream->runtime->state ==SNDRV_PCM_STATE_OPEN && + !stream->runtime->dma_buffer_p) { +kfree (stream->runtime->buffer); + stream->runtime->buffer =NULL ; + } goto out; + } stream->metadata_set = false; stream->next_track = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1623/2857 proc: dont let an entry below /proc/<pid>/net be a mountpoint
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit eeecea75ece2ba894bee4d3c53ed2e40abda8f0e ]
proc_net_d_revalidate() always returns 0 so that a dentry below /proc/<pid>/net is never reused after setns(). So lookup_fast() will end up calling d_invalidate(), which unhashes the dentry and detaches every mount on it, in every mount namespace; including locked mounts.
Then lookup_slow() creates a new dentry for the same entry. So a mount on /proc/<pid>/net/dev succeeds and goes away with the first lookup of the name by anybody with search permission on the directory. Given it's 0555 that's everyone's grandma. A mask on such a name hides nothing as the repro below shows.
Treat those entries like I did fd/, fdinfo/ and map_files/ and refuse to mount on them in the first place. It's nonsensical theater otherwise:
procnet net/dev stat
// SPDX-License-Identifier: GPL-2.0
/*
* procnet: cover an entry of /proc/<pid>/ with a bind mount, lock the mount,
* then look the name up.
*
* The first task stays alive, <pid> is its pid. The "container" task has its
* own mount namespace. There it binds a mask on /proc/<pid>/<name>. It drops to
* uid 1000 and enters a new user namespace with a new mount namespace, so that
* the mask is locked. Then one task looks the name up:
*
* stat the container calls stat() on the name * umount the container calls umount2(MNT_DETACH) on the name * nobody a task with uid 65534 in the first namespaces calls stat()
*
* The container lists its mounts before and after (that does not look the
* name up) and then reads the name. MASK is fine. Anything else means that
* the lookup uncovered the entry.
*
* usage: procnet <name> stat|umount|nobody
* name "status" is the control, "net/dev" is a file below net, "net/stat" is
* a directory below net
*/
#define _GNU_SOURCE
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#define WORK "/run/pn"
static char target[128];
static void die(const char *what)
{
fprintf(stderr, "FATAL %s: %s\n", what, strerror(errno));
exit(2);
}
static void write_str(const char *path, const char *s, int flags)
{
int fd = open(path, O_WRONLY | flags, 0644);
if (fd < 0 || write(fd, s, strlen(s)) < 0)
die(path);
close(fd);
}
/* list the mounts below /proc without a lookup of the target */
static void mounts(const char *when)
{
char line[512];
FILE *f = fopen("/proc/self/mountinfo", "r");
int n = 0;
if (!f)
die("mountinfo");
while (fgets(line, sizeof(line), f)) {
if (!strstr(line, " /proc/"))
continue;
printf("container: %s: mount: %s", when, line);
n++;
}
fclose(f);
if (!n)
printf("container: %s: nothing is mounted below /proc\n", when);
}
static void show(const char *when, int isdir)
{
char buf[48] = "";
int fd;
if (isdir) {
struct dirent *de;
DIR *d = opendir(target);
int hit = 0;
if (!d) {
printf("container: %s: opendir(%s) = %s\n", when, target, strerror(errno));
return;
}
printf("container: %s: readdir(%s) =", when, target);
while ((de = readdir(d))) {
if (de->d_name[0] == '.')
continue;
printf(" %s", de->d_name);
hit |= strcmp(de->d_name, "MASK");
}
closedir(d);
printf("%s\n", hit ? " <-- HIT" : "");
return;
}
fd = open(target, O_RDONLY);
if (fd < 0) {
printf("container: %s: open(%s) = %s\n", when, target, strerror(errno));
return;
}
if (read(fd, buf, sizeof(buf) - 1) < 0)
die("read");
close(fd);
if (strchr(buf, '\n'))
*strchr(buf, '\n') = 0;
printf("container: %s: read(%s) = \"%s\"%s\n", when, target, buf,
strncmp(buf, "MASK", 4) ? " <-- HIT" : "");
}
int main(int argc, char **argv)
{
const char *name = argc > 1 ? argv[1] : "net/dev";
const char *op = argc > 2 ? argv[2] : "stat";
int isdir = !strcmp(name, "net/stat");
int to_host[2], to_cont[2];
struct stat st;
pid_t pid;
char c;
setvbuf(stdout, NULL, _IOLBF, 0);
snprintf(target, sizeof(target), "/proc/%d/%s", getpid(), name);
if (unshare(CLONE_NEWNS) || mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL))
die("unshare");
mkdir(WORK, 0755);
if (mount("W", WORK, "tmpfs", 0, NULL))
die("mount W");
write_str(WORK "/mask", "MASK", O_CREAT);
mkdir(WORK "/maskdir", 0755);
write_str(WORK "/maskdir/MASK", "MASK", O_CREAT);
if (pipe(to_host) || pipe(to_cont))
die("pipe");
pid = fork();
if (pid < 0)
die("fork");
if (!pid) {
if (unshare(CLONE_NEWNS))
die("container unshare");
if (mount(isdir ? WORK "/maskdir" : WORK "/mask", target, NULL, MS_BIND, NULL)) {
printf("container: bind the mask on %s: %s\n", target, strerror(errno));
exit(0);
}
printf("container: bind the mask on %s: ok\n", target);
if (setgid(1000) || setuid(1000) || prctl(PR_SET_DUMPABLE, 1))
die("setuid");
/* lock the mount: a new user namespace with a copy of the tree */
if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
die("container userns");
write_str("/proc/self/setgroups", "deny", 0);
write_str("/proc/self/uid_map", "0 1000 1", 0);
write_str("/proc/self/gid_map", "0 1000 1", 0);
mounts("before");
errno = 0;
if (!strcmp(op, "stat")) {
stat(target, &st);
printf("container: stat(%s): %s\n", target, strerror(errno));
} else if (!strcmp(op, "umount")) {
umount2(target, MNT_DETACH);
printf("container: umount2(%s, MNT_DETACH): %s\n", target, strerror(errno));
} else if (write(to_host[1], "g", 1) != 1 || read(to_cont[0], &c, 1) != 1) {
die("sync");
}
mounts("after");
show("after", isdir);
exit(0);
}
close(to_host[1]);
if (read(to_host[0], &c, 1) == 1) {
pid_t p2 = fork();
if (!p2) {
if (setgid(65534) || setuid(65534))
die("setuid");
errno = 0;
stat(target, &st);
printf("nobody: uid %u: stat(%s): %s\n", getuid(), target, strerror(errno));
exit(0);
}
waitpid(p2, NULL, 0);
if (write(to_cont[1], "g", 1) != 1)
die("sync");
}
waitpid(pid, NULL, 0);
return 0;
}--- fs/proc/generic.c | 3 +++ 1 file changed, 3 insertions(+)
fs/proc/generic.c +3 -0
@@ -256,6 +256,9 @@ struct dentry *proc_lookup_de(struct inode *dir, struct dentry *dentry, inode =proc_get_inode (dir->i_sb, de);if (!inode)return ERR_PTR (-ENOMEM ); +/* never reused and so never a mountpoint for long */ +if (de->proc_dops == &proc_net_dentry_ops) +dont_mount (dentry);d_set_d_op (dentry, de->proc_dops);return d_splice_alias (inode, dentry); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1624/2857 nilfs2: validate directory position after llseek in readdir
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jake Labelle <[email protected]>
[ Upstream commit de7f49c12566cc5c7437a2f26c6c754b9d4d5648 ]
nilfs_readdir() uses ctx->pos, which userspace can set to an arbitrary value via llseek, as an offset into the directory folio and parses whatever bytes sit there as a directory entry. A position pointing into the middle of an entry -- or at unused bytes of a corrupted image that the page validator never inspected -- makes dir_emit() copy up to 255 (name_len) bytes from a bogus entry, possibly reading past the end of the folio and returning unrelated memory contents to userspace.
Snap unaligned positions onto a valid entry boundary by walking the rec_len chain from the chunk start before parsing, as ext2 does in ext2_validate_entry().
[ryusuke: fixed offset wrap-around in nilfs_validate_entry() and
conformed AI tag to guidelines]
--- fs/nilfs2/dir.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
fs/nilfs2/dir.c +34 -0
@@ -265,11 +265,27 @@ static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode *inode) de->file_type = nilfs_type_by_mode[(mode &S_IFMT )>>S_SHIFT ]; } +static inline unsigned int +nilfs_validate_entry (char *base,unsigned int offset,unsigned int mask) +{ +struct nilfs_dir_entry *de = (struct nilfs_dir_entry *)(base + offset); +struct nilfs_dir_entry *p = + (struct nilfs_dir_entry *)(base + (offset & mask)); + +while ((char *)p < (char *)de) { +if (p->rec_len ==0 ) +break ; + p =nilfs_next_entry (p); + } +return (char *)p - base; +} +static int nilfs_readdir (struct file *file,struct dir_context *ctx) {loff_t pos = ctx->pos;struct inode *inode =file_inode (file);struct super_block *sb = inode->i_sb; +unsigned int chunk_size =nilfs_chunk_size (inode);unsigned int offset = pos & ~PAGE_MASK ;unsigned long n = pos >>PAGE_SHIFT ;unsigned long npages =dir_pages (inode);
@@ -288,6 +304,24 @@ static int nilfs_readdir(struct file *file, struct dir_context *ctx) ctx->pos +=PAGE_SIZE - offset;return -EIO ; } +/* +* ctx->pos comes from userspace via llseek and may point +* into the middle of an entry -- or at unvalidated bytes +* of a crafted image. offset is only nonzero here on the +* very first iteration (subsequent pages always start at +* offset 0, which -- like any chunk boundary -- is always +* a legitimate entry start, since no rec_len chain crosses +* a chunk boundary). Snap a non-chunk-aligned offset onto +* a real entry boundary by walking the chain from the +* enclosing chunk's start, as ext2 does; otherwise +* dir_emit() copies name_len bytes from a fake entry, +* reading past the end of the folio. +*/ +if (offset & (chunk_size -1 )) { + offset =nilfs_validate_entry (kaddr, offset, + ~(chunk_size -1 )); + ctx->pos = ((loff_t )n <<PAGE_SHIFT ) + offset; + } de = (struct nilfs_dir_entry *)(kaddr + offset); limit = kaddr +nilfs_last_byte (inode, n) -NILFS_DIR_REC_LEN (1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1625/2857 mm/userfaultfd: wake waiters when registration modes are removed
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 4eee9c389b072e161549d46dcb1ae10b0222717e ]
UFFDIO_REGISTER can replace MISSING or MINOR tracking without waking faults that are already queued. For example, switching an anonymous range from MISSING to WP leaves a missing-fault waiter asleep until userspace explicitly wakes it.
When a registration change removes a UFFD mode, wake waiters in the affected interval after updating the VMA. The VMA is write-locked at this point, so no new faults can queue under the old modes and woken threads cannot retry until mmap_write_unlock(). Waiters for retained modes in the same interval may also wake and refault.
The hang reproduces for MISSING-to-WP and MINOR-to-MISSING transitions, with both read and unread fault events.
--- fs/userfaultfd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/userfaultfd.c +12 -0
@@ -1450,6 +1450,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, ret =0 ; do { + const bool any_mode_removed = vma->vm_flags & __VM_UFFD_FLAGS & ~vm_flags; + cond_resched(); BUG_ON(!vma_can_userfault(vma, vm_flags));
@@ -1504,6 +1506,16 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,userfaultfd_set_vm_flags (vma, new_flags); vma->vm_userfaultfd_ctx.ctx = ctx; +/* Retry faults for removed modes while the VMA is write-locked. */ +if (any_mode_removed) { +struct userfaultfd_wake_range range = { + .start = start, + .len = vma_end - start, + }; + +wake_userfault (ctx, &range); + } +if (is_vm_hugetlb_page (vma) &&uffd_disable_huge_pmd_share (vma))hugetlb_unshare_all_pmds (vma);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1626/2857 mm/madvise: add cond_resched() in THP branch of madvise_cold_or_pageout_pte_range()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Yang <[email protected]>
[ Upstream commit f5cfc8e3b20ad71949a1e5623ff45882c063a71b ]
During stress testing with stress-ng on a 256-CPU system, a softlockup was observed when madvise(MADV_COLD) was called on a 31GB memory region backed by transparent hugepages. The region contains 15935 THP PMD entries, and the softlockup was triggered after 14485 of them had been processed.
The THP branch of madvise_cold_or_pageout_pte_range() has no scheduling point. walk_pmd_range() invokes it once per 2MB PMD entry with no cond_resched() anywhere in the loop. Each iteration calls pmdp_invalidate() which issues a synchronous TLB shootdown (dsb ish) waiting for all CPUs to acknowledge. This operation can be time-consuming under heavy system load, causing the accumulated time across all PMD entries to exceed the softlockup threshold (20s) and panic when softlockup_panic=1. On a CONFIG_PREEMPT_NONE=y kernel, there is no other opportunity to reschedule during this entire traversal.
The regular PTE path already has an unconditional cond_resched() at the function tail (introduced by commit 9c276cc65a58 ("mm: introduce MADV_COLD") and commit 1a4e58cce84e ("mm: introduce MADV_PAGEOUT") when MADV_COLD and MADV_PAGEOUT were first introduced) and a conditional one inside the loop (commit b2f557a21bc8 ("mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range()")). The THP branch never received equivalent treatment.
Fix by adding cond_resched() at the huge_unlock exit path after spin_unlock(ptl) and reclaim_pages(), which is the single exit point for all goto paths in the THP branch.
Crash log:
watchdog: BUG: soft lockup - CPU#63 stuck for 23s! [stress-ng-vm:1665914] ... Call trace: pmdp_invalidate+0x48/0x68 madvise_cold_or_pageout_pte_range+0x84c/0xb00 walk_pmd_range.isra.0+0x1ac/0x3b0 walk_pud_range+0x120/0x190 walk_pgd_range+0x170/0x1b8 __walk_page_range+0x184/0x198 walk_page_range_vma+0x94/0x128 madvise_cold+0xd8/0x198 madvise_vma_behavior+0x234/0x638 madvise_walk_vmas.constprop.0+0xdc/0x210 madvise_do_behavior+0xa8/0x328 do_madvise+0xd8/0x140 __arm64_sys_madvise+0x2c/0xe0
--- mm/madvise.c | 1 + 1 file changed, 1 insertion(+)
mm/madvise.c +1 -0
@@ -399,6 +399,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,spin_unlock (ptl);if (pageout)reclaim_pages (&page_list); +cond_resched ();return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1627/2857 f2fs: fix to update superblock crc in sanity_check_area_boundary()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit f8f956c7ec8c0285d7a80bed497d2f7adcbded15 ]
This patch fixes the bug reported by Sashiko:
We should update superblock crc along w/ raw_super->segment_count in sanity_check_area_boundary() if sb_checksum feature is enabled.
--- fs/f2fs/super.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/f2fs/super.c +6 -0
@@ -3350,6 +3350,12 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,/* fix in-memory information all the time */ raw_super->segment_count =cpu_to_le32 ((main_end_blkaddr - segment0_blkaddr) >> log_blocks_per_seg); +if (__F2FS_HAS_FEATURE (raw_super,F2FS_FEATURE_SB_CHKSUM )) { +__u32 crc =f2fs_crc32 (sbi, raw_super, + offsetof(struct f2fs_super_block , crc)); + + raw_super->crc =cpu_to_le32 (crc); + }if (f2fs_readonly (sb) ||bdev_read_only (sb->s_bdev)) {set_sbi_flag (sbi,SBI_NEED_SB_WRITE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1628/2857 libceph: initialize CRUSH choose argument weights
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darong Lu <[email protected]>
[ Upstream commit c3a995ff0782587789333c621e1f6bd5e574371e ]
Initialize the CRUSH choose argument weight-set array before decoding so entries start in a defined state while the decoder fills them.
--- net/ceph/osdmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/osdmap.c +1 -1
@@ -320,7 +320,7 @@ static int decode_choose_arg(void **p, void *end, struct crush_choose_arg *arg)if (arg->weight_set_size) {u32 i; - arg->weight_set =kmalloc_array (arg->weight_set_size, + arg->weight_set =kcalloc (arg->weight_set_size,sizeof (*arg->weight_set),GFP_NOIO );if (!arg->weight_set)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1629/2857 ovl: inherit FMODE_NONOTIFY when opening directory realfiles
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 323899b4ed233d5b6e2fc160c16fbf39cf0317da ]
When fanotify hands a listener an fd for a permission event on an overlay directory, ovl_dir_open_realfile() opens the real directory via dentry_open(), not backing_file_open(), so the lower open could still raise FS_OPEN_PERM and deadlock a listener that also marks the backing filesystem.
Export dentry_open_nonotify() and call it from ovl_path_open_realfile() when the overlay user file must not generate events. Ordinary ovl_path_open() callers are unchanged.
--- fs/overlayfs/readdir.c | 10 +++++++++- fs/overlayfs/util.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-)
fs/overlayfs/readdir.c +9 -1
@@ -850,9 +850,17 @@ static struct file *ovl_dir_open_realfile(const struct file *file, {struct file *res;const struct cred *old_cred; +int flags =O_RDONLY | (file->f_flags &O_LARGEFILE ); + +/* +* Inherit FMODE_NONOTIFY from a fanotify permission fd so a listener +* that also watches the real filesystem does not deadlock. +*/ +if (file->f_mode &FMODE_NONOTIFY ) + flags |= __FMODE_NONOTIFY; old_cred =ovl_override_creds (file_inode (file)->i_sb); - res =ovl_path_open (realpath,O_RDONLY | (file->f_flags &O_LARGEFILE )); + res =ovl_path_open (realpath, flags);revert_creds (old_cred);return res;
fs/overlayfs/util.c +1 -1
@@ -519,7 +519,7 @@ struct file *ovl_path_open(const struct path *path, int flags)struct user_namespace *real_mnt_userns =mnt_user_ns (path->mnt);int err, acc_mode; -if (flags & ~(O_ACCMODE |O_LARGEFILE )) +if (flags & ~(O_ACCMODE |O_LARGEFILE | __FMODE_NONOTIFY))BUG ();switch (flags &O_ACCMODE ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1630/2857 mm/memory-tiers: unregister empty tiers outside memory_tier_lock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 500624f28eca441e35f978979ccfb373202fefd3 ]
When offlining a node's last memory empties its tier, clear_node_memory_tier() calls device_unregister() while holding memory_tier_lock. A concurrent sysfs read can hold a kernfs active reference and block in nodelist_show() on that mutex. device_unregister() then waits in kernfs_drain() for the read to finish and release its active reference, while the reader waits for the offlining task to release the mutex.
Return the node's former tier from clear_node_memory_tier(), making the helper more similar to set_node_memory_tier(), which also returns a memory_tier pointer. Let the caller unlink an empty tier under memory_tier_lock before rebuilding demotion targets, then unregister its device after dropping the lock.
--- mm/memory-tiers.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
mm/memory-tiers.c +13 -16
@@ -495,21 +495,14 @@ static struct memory_tier *set_node_memory_tier(int node)return memtier; } -static void destroy_memory_tier (struct memory_tier *memtier) +static struct memory_tier *clear_node_memory_tier (int node) { -list_del (&memtier->list); -device_unregister (&memtier->dev); -} - -static bool clear_node_memory_tier (int node) -{ -bool cleared = false;pg_data_t *pgdat;struct memory_tier *memtier; pgdat =NODE_DATA (node);if (!pgdat) -return false; +return NULL ;/* * Make sure that anybody looking at NODE_DATA who finds
@@ -527,14 +520,10 @@ static bool clear_node_memory_tier(int node)synchronize_rcu (); memtype = node_memory_types[node].memtype;node_clear (node, memtype->nodes); -if (nodes_empty (memtype->nodes)) { +if (nodes_empty (memtype->nodes))list_del_init (&memtype->tier_sibiling); -if (list_empty (&memtier->memory_types)) -destroy_memory_tier (memtier); - } - cleared = true; } -return cleared; +return memtier; }static void release_memtype (struct kref *kref)
@@ -598,6 +587,7 @@ static int __meminit memtier_hotplug_callback(struct notifier_block *self, {struct memory_tier *memtier;struct memory_notify *arg = _arg; +bool empty = false;/* * Only update the node migration order when a node is
@@ -609,9 +599,16 @@ static int __meminit memtier_hotplug_callback(struct notifier_block *self,switch (action) {case MEM_OFFLINE :mutex_lock (&memory_tier_lock); -if (clear_node_memory_tier (arg->status_change_nid)) + memtier =clear_node_memory_tier (arg->status_change_nid); +if (memtier) { + empty =list_empty (&memtier->memory_types); +if (empty) +list_del (&memtier->list);establish_demotion_targets (); + }mutex_unlock (&memory_tier_lock); +if (empty) +device_unregister (&memtier->dev);break ;case MEM_ONLINE :mutex_lock (&memory_tier_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1631/2857 f2fs: fix to fetch ino via ino_of_node() under cache lock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit cd6d8b1891395b681f2060916a4b83880b765698 ]
In f2fs_writeback_node_caches(), it's better to fetch ino via ino_of_node() under cache lock, otherwise, node cache content may become stale after cache is unlocked due to racing w/ truncation.
Commit 493b9dc8b52c ("f2fs: cache: use node cache") fixes similar issue in f2fs_flush_inline_data() introduced in commit 34c061ad85a2 ("f2fs: Avoid double lock for cp_rwsem during checkpoint").
--- fs/f2fs/node.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/node.c +3 -1
@@ -2073,9 +2073,11 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,/* flush inline_data */ if (page_private_inline (page)) { +nid_t ino =ino_of_node (page); +clear_page_private_inline (page);unlock_page (page); -flush_inline_data (sbi,ino_of_node (page)); +flush_inline_data (sbi, ino); goto lock_node; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1632/2857 xfs: dont skip free extents of the longest length in a whole-AG FITRIM
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit 5745f4f10a1a16aa5bb020acc38afa33f2d5ff99 ]
Since commit a66d636385d6 ("xfs: fix fstrim offset calculations"), the by-length walk of an AG in FITRIM starts with xfs_alloc_lookup_ge(cur, 0, pagf_longest) and walks down. The lookup lands on the longest free extent with the lowest block number. The other free extents of that length sort after it and are never discarded.
Start every by-length batch with xfs_alloc_lookup_le() at restart_bno.
--- fs/xfs/xfs_discard.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/xfs/xfs_discard.c +3 -2
@@ -53,9 +53,10 @@ xfs_trim_extents( cur =xfs_allocbt_init_cursor (mp,NULL , agbp, pag,XFS_BTNUM_CNT );/* -* Look up the longest btree in the AGF and start with it. +* Start at the last record of the longest length. */ - error =xfs_alloc_lookup_ge (cur,0 ,be32_to_cpu (agf->agf_longest), &i); + error =xfs_alloc_lookup_le (cur,NULLAGBLOCK , +be32_to_cpu (agf->agf_longest), &i);if (error) goto out_del_cursor;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1633/2857 mm/vma: fix expansion of VMA_MIXEDMAP_BIT VMAs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit 8146c6478224d8f6395c6b08a19c344a56d79867 ]
Commit ca3d76b0aa80 ("mm: add merging after mremap resize") combined merging with expansion of mremap()'d VMAs, however it also unintentionally disallowed the expansion of unmergeable VMAs.
Previously it was possible to expand a mixed mapping which mremap() had already ensured was a legal expansion.
This is clearly seen in the mremap() logic, as it checks vma_is_fixed_mapping() to determine legality of an expansion rather than vma_can_merge().
Additionally, copy_vma() allows for a failed merge to result in a new VMA being instantiated if MREMAP_MAYMOVE is specified.
However, this is not attempted, as a failure in vma_merge_extend() is assumed to be an -ENOMEM failure.
Since vma_merge_extend() is used exclusively by mremap() to perform a merge and/or expansion, resolve the issue by invoking vma_expand() for unmergeable VMAs there.
Explicitly assert that the VMA is both non-fixed and a mixed mapping. This provides double insurance against broken changes in future.
Note that khugepaged_enter_vma() (which vma_merge_new_range() runs) is redundant in this case, as a mixed mapping is not subject to khugepaged.
Also update the VMA userland tests to add a required predicate.
--- mm/mremap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/mremap.c +5 -1
@@ -1111,8 +1111,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,* expanding, so perform a simple expand for such vma. * Ideally the check for close op should be only done * when a vma would be actually removed due to a merge. +* +* Mixed mappings cannot be merged either, so they also +* need to be expanded directly. */ -if (!vma->vm_ops || !vma->vm_ops->close) { +if (!(vma->vm_flags &VM_MIXEDMAP ) && + (!vma->vm_ops || !vma->vm_ops->close)) { vma = vma_merge(mm, vma, extension_start, extension_end, vma->vm_flags, vma->anon_vma, vma->vm_file, extension_pgoff, vma_policy(vma),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1634/2857 drm/amdgpu: finish GPU recovery callbacks before restarting schedulers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prike Liang <[email protected]>
[ Upstream commit 733389cb31e2c55e355410759fdc68afe74a4582 ]
Run GPU post-reset callbacks, including KFD and display-audio resume, before restarting DRM scheduler workqueues. IP hardware initialization already happens inside ASIC recovery; this change orders the remaining callbacks before new scheduler submissions. Preserve the emergency-stop and guity job completition path's callbacks without starting schedulers,
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 43 ++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +24 -19
@@ -5621,7 +5621,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, }if (need_emergency_restart) - goto skip_sched_resume; + goto post_resume;/* * Must check guilty signal here since after this point all old
@@ -5693,7 +5693,30 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, !(tmp_vram_lost_counter < atomic_read(&adev->vram_lost_counter)))amdgpu_device_recheck_guilty_jobs ( tmp_adev, device_list_handle, reset_context); + } + +post_resume: +list_for_each_entry (tmp_adev, device_list_handle, reset_list) { +/* unlock kfd: SRIOV would do it separately */ +if (!need_emergency_restart && !amdgpu_sriov_vf (tmp_adev)) +amdgpu_amdkfd_post_reset (tmp_adev); + +/* kfd_post_reset will do nothing if kfd device is not initialized, +* need to bring up kfd here if it's not be initialized before +*/ +if (!adev->kfd.init_complete) +amdgpu_amdkfd_device_init (adev); + +if (audio_suspended) +amdgpu_device_resume_display_audio (tmp_adev); + +amdgpu_device_unset_mp1_state (tmp_adev); + } + +if (need_emergency_restart) + goto recover_end; +list_for_each_entry (tmp_adev, device_list_handle, reset_list) {for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i];
@@ -5730,24 +5753,6 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, } } -skip_sched_resume: -list_for_each_entry (tmp_adev, device_list_handle, reset_list) { -/* unlock kfd: SRIOV would do it separately */ -if (!need_emergency_restart && !amdgpu_sriov_vf (tmp_adev)) -amdgpu_amdkfd_post_reset (tmp_adev); - -/* kfd_post_reset will do nothing if kfd device is not initialized, -* need to bring up kfd here if it's not be initialized before -*/ -if (!adev->kfd.init_complete) -amdgpu_amdkfd_device_init (adev); - -if (audio_suspended) -amdgpu_device_resume_display_audio (tmp_adev); - -amdgpu_device_unset_mp1_state (tmp_adev); - } - recover_end: tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device, reset_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1635/2857 hwmon: (pmbus) Check return value from pmbus_thermal_add_sensor()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 11dfbd835b17b75f7cc7a4a969f33ff702b1b081 ]
During PMBus device probe, if registering a temperature sensor with the thermal subsystem fails, pmbus_add_sensor() silently ignores the error and returns success.
When a valid temperature sensor is detected (class PSC_TEMPERATURE and type "input"), pmbus_add_sensor() invokes pmbus_thermal_add_sensor() to hook it into the kernel's thermal framework. However, the return value of this call is completely discarded. If thermal registration fails, such as from an -ENOMEM allocation failure or an invalid device tree configuration like a malformed #thermal-sensor-cells property, no error is propagated.
Because the hardware monitor probe falsely succeeds despite the failure to register the thermal zone, the system is left without thermal mitigation for the affected PMBus device. This silently blinds the system to actual PMIC temperatures, preventing the execution of necessary cooling mechanisms or emergency shutdowns and risking localized overheating.
Pass the return value from pmbus_thermal_add_sensor() to the calling code to fix the problem. To enable passing the actual error, change the error return from pmbus_add_sensor() from NULL to ERR_PTR() and extract the error from in the calling code.
--- drivers/hwmon/pmbus/pmbus_core.c | 42 ++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 18 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +24 -18
@@ -1347,10 +1347,11 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data, {struct pmbus_sensor *sensor;struct device_attribute *a; +int err; sensor =devm_kzalloc (data->dev,sizeof (*sensor),GFP_KERNEL );if (!sensor) -return NULL ; +return ERR_PTR (-ENOMEM ); a = &sensor->attribute;if (type)
@@ -1375,14 +1376,17 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data, pmbus_show_sensor, pmbus_set_sensor);if (pmbus_add_attribute (data, &a->attr)) -return NULL ; +return ERR_PTR (-ENOMEM ); sensor->next = data->sensors; data->sensors = sensor;/* temperature sensors with _input values are registered with thermal */ -if (class ==PSC_TEMPERATURE &&strcmp (type,"input" ) ==0 ) -pmbus_thermal_add_sensor (data, sensor, seq); +if (class ==PSC_TEMPERATURE &&strcmp (type,"input" ) ==0 ) { + err =pmbus_thermal_add_sensor (data, sensor, seq); +if (err) +return ERR_PTR (err); + }return sensor; }
@@ -1483,8 +1487,8 @@ static int pmbus_add_limit_attrs(struct i2c_client *client, page,0xff , l->reg, attr->class, attr->update || l->update, false, true); -if (!curr) -return -ENOMEM ; +if (IS_ERR (curr)) +return PTR_ERR (curr);if (l->sbit && (info->func[page] & attr->sfunc)) { ret = pmbus_add_boolean(data, name, l->alarm, index,
@@ -1523,8 +1527,8 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, } base =pmbus_add_sensor (data, name,"input" , index, page, phase, attr->reg, attr->class, true, true, true); -if (!base) -return -ENOMEM ; +if (IS_ERR (base)) +return PTR_ERR (base);/* No limit and alarm attributes for phase specific sensors */ if (attr->sfunc && phase ==0xff ) { ret = pmbus_add_limit_attrs(client, data, info, name,
@@ -2154,8 +2158,8 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client,0xff ,PMBUS_VIRT_FAN_TARGET_1 + id,PSC_FAN , false, false, true); -if (!sensor) -return -ENOMEM ; +if (IS_ERR (sensor)) +return PTR_ERR (sensor);if (!((data->info->func[page] &PMBUS_HAVE_PWM12 ) || (data->info->func[page] &PMBUS_HAVE_PWM34 )))
@@ -2165,15 +2169,15 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client,0xff ,PMBUS_VIRT_PWM_1 + id,PSC_PWM , false, false, true); -if (!sensor) -return -ENOMEM ; +if (IS_ERR (sensor)) +return PTR_ERR (sensor); sensor =pmbus_add_sensor (data,"pwm" ,"enable" , index, page,0xff ,PMBUS_VIRT_PWM_ENABLE_1 + id,PSC_PWM , true, false, false); -if (!sensor) -return -ENOMEM ; +if (IS_ERR (sensor)) +return PTR_ERR (sensor);return 0 ; }
@@ -2190,6 +2194,7 @@ static int pmbus_add_fan_attributes(struct i2c_client *client,int f;for (f =0 ; f <ARRAY_SIZE (pmbus_fan_registers); f++) { +struct pmbus_sensor *sensor;int regval;if (!(info->func[page] & pmbus_fan_flags[f]))
@@ -2210,10 +2215,11 @@ static int pmbus_add_fan_attributes(struct i2c_client *client, (!(regval & (PB_FAN_1_INSTALLED >> ((f & 1) * 4))))) continue; -if (pmbus_add_sensor (data,"fan" ,"input" , index, - page,0xff , pmbus_fan_registers[f], -PSC_FAN , true, true, true) ==NULL ) -return -ENOMEM ; + sensor =pmbus_add_sensor (data,"fan" ,"input" , index, + page,0xff , pmbus_fan_registers[f], +PSC_FAN , true, true, true); +if (IS_ERR (sensor)) +return PTR_ERR (sensor);/* Fan control */ if (pmbus_check_word_register(client, page,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1636/2857 drm/amdgpu: drop the gang leader reference when freeing gang jobs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit c1584e10a7deb655438f21867b2b7a356a9aaf9f ]
Every job of a gang except the leader holds a reference to the scheduled fence of the leader in job->gang_submit. Only amdgpu_job_free(), used for jobs which never ran, drops it, so for every gang submission which completes the scheduler fence of the leader, and with it its hardware fence, is leaked. amdgpu_job_free() in turn checks for the leader only after drm_sched_job_cleanup() cleared the scheduler fence, so a leader freed there drops a reference it never took.
On navi31, 100 submissions of a GFX + COMPUTE gang grow the slab cache drm_sched_fence is merged into by 60 to 180 objects each time, while 100 GFX only submissions don't.
Use amdgpu_job_free() for the jobs the scheduler frees too, and check for the gang leader there before drm_sched_job_cleanup() clears the scheduler fence. As the scheduler clears the entity of the jobs it picked up, check for the scheduler fence instead to tell whether the job needs cleaning up.
Keep freeing the remaining IBs with amdgpu_job_free_resources() after drm_sched_job_cleanup(), so that it frees them with the hardware fence or right away and not with the scheduler fence, which nobody signals for jobs aborted after drm_sched_job_arm(), like a CS returning -EAGAIN.
v2: unify amdgpu_job_free() and amdgpu_job_free_cb() (Christian), don't
free the remaining IBs with the scheduler fence
v3: drop the comments (Christian)
v4: free the IBs with amdgpu_job_free_resources() again (Christian)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5 -15
@@ -179,18 +179,7 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)static void amdgpu_job_free_cb (struct drm_sched_job *s_job) { -struct amdgpu_job *job =to_amdgpu_job (s_job); - -drm_sched_job_cleanup (s_job); - -amdgpu_sync_free (&job->sync); -amdgpu_sync_free (&job->sched_sync); - -/* only put the hw fence if has embedded fence */ -if (!job->hw_fence.ops) -kfree (job); -else -dma_fence_put (&job->hw_fence); +amdgpu_job_free (to_amdgpu_job (s_job)); } void amdgpu_job_set_gang_leader(struct amdgpu_job *job,
@@ -211,14 +200,15 @@ void amdgpu_job_set_gang_leader(struct amdgpu_job *job,void amdgpu_job_free (struct amdgpu_job *job) { -if (job->base.entity) +if (job->gang_submit != &job->base.s_fence->scheduled) +dma_fence_put (job->gang_submit); + +if (job->base.s_fence)drm_sched_job_cleanup (&job->base);amdgpu_job_free_resources (job);amdgpu_sync_free (&job->sync);amdgpu_sync_free (&job->sched_sync); -if (job->gang_submit != &job->base.s_fence->scheduled) -dma_fence_put (job->gang_submit);if (!job->hw_fence.ops)kfree (job);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1637/2857 mm/ksm: mark migration stores with WRITE_ONCE()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit d3863210464f69c18615cbe400d48a6e53e770d4 ]
ksm_get_folio() deliberately samples stable_node->kpfn and folio->mapping without taking the folio lock because the KSM folio may be migrated concurrently. folio_migrate_ksm() updates the same state using plain assignments.
The reader can load the old kpfn, then the migrator can store the new kpfn, execute smp_wmb(), and clear the old folio's mapping before the reader checks that mapping. Thus the initial kpfn load can overlap its update and the subsequent mapping load can overlap the clear, with no common lock. This leaves marked READ_ONCE() accesses racing with plain stores.
The kernel reported:
BUG: KCSAN: data-race in folio_migrate_ksm / ksm_get_folio
read (marked) to 0xffff8ce401421330 of 8 bytes by task 48 on cpu 3:
ksm_get_folio+0x7f/0x2a0 ksm_scan_thread+0x1635/0x3330 kthread+0x1af/0x1f0
write to 0xffff8ce401421330 of 8 bytes by task 102 on cpu 1:
folio_migrate_ksm+0x6a/0xd0 folio_migrate_flags+0x193/0x420 __migrate_folio.isra.0+0x162/0x1a0 migrate_folio+0x4c/0x70 move_to_new_folio+0xd6/0x170
Use WRITE_ONCE() for both stores to pair them with the existing lockless reads. This preserves the existing smp_wmb()/smp_rmb() migration protocol and control flow while preventing compiler transformations of the shared accesses.
--- mm/ksm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/ksm.c +3 -2
@@ -846,7 +846,8 @@ static inline void set_page_stable_node(struct page *page, struct ksm_stable_node *stable_node) {VM_BUG_ON_PAGE (PageAnon (page) &&PageAnonExclusive (page), page); - page->mapping = (void *)((unsigned long )stable_node |PAGE_MAPPING_KSM ); +WRITE_ONCE (page->mapping, + (void *)((unsigned long )stable_node |PAGE_MAPPING_KSM )); }#ifdef CONFIG_SYSFS
@@ -2819,7 +2820,7 @@ void folio_migrate_ksm(struct folio *newfolio, struct folio *folio) stable_node =folio_stable_node (folio);if (stable_node) {VM_BUG_ON_FOLIO (stable_node->kpfn !=folio_pfn (folio), folio); - stable_node->kpfn =folio_pfn (newfolio); +WRITE_ONCE (stable_node->kpfn,folio_pfn (newfolio));/* * newfolio->mapping was set in advance; now we need smp_wmb() * to make sure that the new stable_node->kpfn is visible
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1638/2857 selftests:core: test coverage for dup_fd() failure handling in unshare_fd()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 611fbeb44a777e5ab54ab3127ec85f72147911d8 ]
At some point there'd been a dumb braino during the dup_fd() calling conventions change; caught by smatch and immediately fixed. The trouble is, there had been no test coverage for the dup_fd() failure handling - neither in kselftests nor in LTP. Fortunately, it can be triggered on stock kernel - ENOMEM would require fault injection, but EMFILE can be had with sysctl alone (fs.nr_open).
Add a test for dup_fd() failure.
Fixed up commit log and short log - Shuah Khan
Stable-dep-of: df0b7e0ea59c ("selftests/core: fix unshare_test with large fs.nr_open")
--- tools/testing/selftests/core/Makefile | 2 +- tools/testing/selftests/core/unshare_test.c | 94 +++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/core/unshare_test.c
tools/testing/selftests/core/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only CFLAGS += -g $(KHDR_INCLUDES) -TEST_GEN_PROGS := close_range_test +TEST_GEN_PROGS := close_range_test unshare_test include ../lib.mk
tools/testing/selftests/core/unshare_test.c new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1639/2857 selftests/core: fix unshare_test with large fs.nr_open
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Khorenko <[email protected]>
[ Upstream commit df0b7e0ea59c43708cff8c7e34da5e2f8d430e5e ]
The test assumes fs.nr_open is close to the default 1048576, but some systems set it much higher (e.g. 1073741816). This is systemd's doing:
since systemd v240 (2018), PID 1 bumps fs.nr_open and fs.file-max to their largest possible values on boot, as file descriptors are already accounted for by memcg [1].
In that case, dup2() to nr_open + 64 requires the kernel to allocate a file descriptor table with ~1 billion entries, which fails with ENOMEM.
On a kernel that already carries 04a2c4b4511d1, dup2() no longer fails with ENOMEM. The allocation is now rejected up front and the caller gets EMFILE instead, without the WARNING, but the test still fails.
Cap the nr_open value used for the test's own arithmetic to a known reasonable base value (1048576) and restore the true original value once the test has completed.
--- tools/testing/selftests/core/unshare_test.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
tools/testing/selftests/core/unshare_test.c +17 -2
@@ -40,6 +40,14 @@ TEST(unshare_EMFILE)ASSERT_EQ (sscanf (buf,"%d" , &nr_open),1 ); +/* +* Cap nr_open for the duration of the test to avoid ENOMEM from a +* huge fd table allocation; buf/n keep the real original value so +* fs.nr_open can be restored to it once the test is done. +*/ +if (nr_open >1024 *1024 ) + nr_open =1024 *1024 ; +ASSERT_EQ (0 ,getrlimit (RLIMIT_NOFILE , &rlimit));/* bump fs.nr_open */
@@ -73,10 +81,13 @@ TEST(unshare_EMFILE)if (pid ==0 ) {int err; +char buf3[32 ]; +ssize_t n3; -/* restore fs.nr_open */ +/* restore fs.nr_open to the (possibly capped) test baseline */ + n3 =sprintf (buf3,"%d\n" , nr_open);lseek (fd,0 ,SEEK_SET ); -write (fd, buf, n); +write (fd, buf3, n3);/* ... and now unshare(CLONE_FILES) must fail with EMFILE */ err =unshare (CLONE_FILES );EXPECT_EQ (err,-1 )
@@ -89,6 +100,10 @@ TEST(unshare_EMFILE)EXPECT_EQ (waitpid (pid, &status,0 ), pid);EXPECT_EQ (true,WIFEXITED (status));EXPECT_EQ (0 ,WEXITSTATUS (status)); + +/* restore the real fs.nr_open value */ +lseek (fd,0 ,SEEK_SET ); +write (fd, buf, n); }TEST_HARNESS_MAIN
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1640/2857 can: dev: can_dropped_invalid_skb: drop CAN XL frames on non-CAN XL devices
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Mailhol <[email protected]>
[ Upstream commit 0fce44e29fce4b07642491b098afb41bd571e4f2 ]
Sending a PF_PACKET bypasses the CAN framework logic and can directly reach a CAN driver's xmit() function. The PF_PACKET framework only checks that skb->len does not exceed the net_device MTU.
For a CAN device that is not CAN XL capable, anything above CANFD_MTU (72 bytes) is therefore dropped before it reaches the driver. However, CAN XL frames are variable length. can_is_canxl_skb() accepts lengths in the range CANXL_HDR_SIZE + CANXL_MIN_DLEN up to CANXL_MTU, i.e. 13 to 2060 bytes.
As a result, an ETH_P_CANXL skb with a length between 13 and 72 bytes can pass both the MTU and the can_dropped_invalid_skb() checks.
A driver that does not support CAN XL will interpret canxl_frame->flags as a length because of the overlap with can_frame->len. And because CANXL_XLF is set, the resulting length is between 128 and 255. For drivers that do not check can_frame->len before copying can_frame->data, as most drivers do, this results in a buffer overflow of up to 247 bytes.
Drop ETH_P_CANXL skbs if the device does not have the CAN_CAP_XL capability. Keep can_is_canxl_skb() for the validation of CAN XL skbs.
--- drivers/net/can/dev/skb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/can/dev/skb.c +2 -1
@@ -354,7 +354,8 @@ bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb)break ;case ETH_P_CANXL : -if (!can_is_canxl_skb (skb)) +if (!can_is_canxl_dev_mtu (dev->mtu) || + !can_is_canxl_skb (skb)) goto inval_skb;break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1641/2857 mptcp: pm: kernel: use RCU to free endpoint listeners
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 49b09ae0bf57b4230187d4cdd0a370558e44a6e8 ]
mptcp_pm_nl_create_listen_socket() starts the TCP listener directly instead of going through mptcp_listen(). It consequently misses setting SOCK_RCU_FREE on the parent MPTCP socket.
tcp_child_process() can invoke the listener's subflow_data_ready() callback without holding the MPTCP parent lock or a reference to the parent. An authenticated MP_JOIN racing with endpoint teardown can therefore access the parent after its last reference has been dropped. The ADD_ADDR error path can also close an already published listener.
Set SOCK_RCU_FREE before __inet_listen_sk() publishes the TCP listener, matching mptcp_listen(). This protects the parent on every subsequent close path, including a failed endpoint addition.
--- net/mptcp/pm_netlink.c | 1 + 1 file changed, 1 insertion(+)
net/mptcp/pm_netlink.c +1 -0
@@ -1261,6 +1261,7 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, }inet_sk_state_store (newsk,TCP_LISTEN ); +sock_set_flag (newsk,SOCK_RCU_FREE );WRITE_ONCE (mptcp_subflow_ctx (ssock->sk)->pm_listener, true); err =kernel_listen (ssock, backlog);if (err) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1642/2857 ocfs2: constify struct ocfs2_lock_res_ops
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christophe JAILLET <[email protected]>
[ Upstream commit 3ebe69c0c3ae3ef5ecd1ad86aa98a3b7cbe3c7e9 ]
"struct ocfs2_lock_res_ops" are not modified in this driver.
Constifying this structure moves some data to a read-only section, so increase overall security.
In order to do it, "struct ocfs2_lock_res" also needs to be adjusted to this new const qualifier.
On a x86_64, with allmodconfig:
Before:
======
text data bss dec hex filename 83038 2632 400 86070 15036 fs/ocfs2/dlmglue.o
After:
=====
text data bss dec hex filename 83806 1992 272 86070 15036 fs/ocfs2/dlmglue.o
Stable-dep-of: 5b4696e0bfc3 ("ocfs2: cache the mount context for dentry lock callbacks")
--- fs/ocfs2/dlmglue.c | 28 ++++++++++++++-------------- fs/ocfs2/ocfs2.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-)
fs/ocfs2/dlmglue.c +14 -14
@@ -222,12 +222,12 @@ struct ocfs2_lock_res_ops {*/ #define LOCK_TYPE_USES_LVB 0x2 -static struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = { +static const struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = { .get_osb = ocfs2_get_inode_osb, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { +static const struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { .get_osb = ocfs2_get_inode_osb, .check_downconvert = ocfs2_check_meta_downconvert, .set_lvb = ocfs2_set_meta_lvb,
@@ -235,50 +235,50 @@ static struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { .flags = LOCK_TYPE_REQUIRES_REFRESH|LOCK_TYPE_USES_LVB, }; -static struct ocfs2_lock_res_ops ocfs2_super_lops = { +static const struct ocfs2_lock_res_ops ocfs2_super_lops = { .flags =LOCK_TYPE_REQUIRES_REFRESH , }; -static struct ocfs2_lock_res_ops ocfs2_rename_lops = { +static const struct ocfs2_lock_res_ops ocfs2_rename_lops = { .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_nfs_sync_lops = { +static const struct ocfs2_lock_res_ops ocfs2_nfs_sync_lops = { .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_trim_fs_lops = { +static const struct ocfs2_lock_res_ops ocfs2_trim_fs_lops = { .flags =LOCK_TYPE_REQUIRES_REFRESH |LOCK_TYPE_USES_LVB , }; -static struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { +static const struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { .flags =LOCK_TYPE_REQUIRES_REFRESH |LOCK_TYPE_USES_LVB , }; -static struct ocfs2_lock_res_ops ocfs2_dentry_lops = { +static const struct ocfs2_lock_res_ops ocfs2_dentry_lops = { .get_osb = ocfs2_get_dentry_osb, .post_unlock = ocfs2_dentry_post_unlock, .downconvert_worker = ocfs2_dentry_convert_worker, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_inode_open_lops = { +static const struct ocfs2_lock_res_ops ocfs2_inode_open_lops = { .get_osb = ocfs2_get_inode_osb, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_flock_lops = { +static const struct ocfs2_lock_res_ops ocfs2_flock_lops = { .get_osb = ocfs2_get_file_osb, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_qinfo_lops = { +static const struct ocfs2_lock_res_ops ocfs2_qinfo_lops = { .set_lvb = ocfs2_set_qinfo_lvb, .get_osb = ocfs2_get_qinfo_osb, .flags =LOCK_TYPE_REQUIRES_REFRESH |LOCK_TYPE_USES_LVB , }; -static struct ocfs2_lock_res_ops ocfs2_refcount_block_lops = { +static const struct ocfs2_lock_res_ops ocfs2_refcount_block_lops = { .check_downconvert = ocfs2_check_refcount_downconvert, .downconvert_worker = ocfs2_refcount_convert_worker, .flags =0 ,
@@ -511,7 +511,7 @@ static inline void ocfs2_init_start_time(struct ocfs2_mask_waiter *mw)static void ocfs2_lock_res_init_common (struct ocfs2_super *osb,struct ocfs2_lock_res *res,enum ocfs2_lock_type type, -struct ocfs2_lock_res_ops *ops, +const struct ocfs2_lock_res_ops *ops,void *priv) { res->l_type = type;
@@ -554,7 +554,7 @@ void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,unsigned int generation, struct inode *inode) { - struct ocfs2_lock_res_ops *ops; + const struct ocfs2_lock_res_ops *ops;switch (type) {case OCFS2_LOCK_TYPE_RW :
fs/ocfs2/ocfs2.h +1 -1
@@ -154,7 +154,7 @@ struct ocfs2_lock_stats {struct ocfs2_lock_res {void *l_priv; -struct ocfs2_lock_res_ops *l_ops; +const struct ocfs2_lock_res_ops *l_ops;struct list_head l_blocked_list;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1643/2857 ocfs2: cache the mount context for dentry lock callbacks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 5b4696e0bfc358619adaeab25ad35b4979af8331 ]
ocfs2_drop_dentry_lock() drops the inode reference before releasing the DENTRY lock. This lets inode eviction release the local inode and open locks before a remote unlink can proceed past the DENTRY lock.
A DLM callback can still arrive before the DENTRY lock has been dropped. ocfs2_get_dentry_osb() obtains the mount context through dl_inode->i_sb, which can access a freed inode when the downconvert thread drops the last inode reference in its post-unlock callback:
Downconvert thread DLM callback thread
------------------ -------------------
ocfs2_process_blocked_lock()
ocfs2_dentry_post_unlock()
ocfs2_dentry_lock_put()
ocfs2_drop_dentry_lock()
iput(dl->dl_inode)
[inode reclaimed after RCU]
ocfs2_blocking_ast()
ocfs2_get_dentry_osb()
dl->dl_inode->i_sb
ocfs2_simple_drop_lockres()Store the mount context in the DENTRY lock resource's l_priv field and use the default mount-context lookup. Recover the containing dentry lock with container_of(), as already done for refcount locks, and remove ocfs2_get_dentry_osb(). ocfs2_dismount_volume() shuts down the DLM before freeing the mount context, so callbacks can use it without accessing the inode. Preserve the existing iput-before-unlock order to avoid delaying local inode and open lock release until after the DENTRY lock is released.
--- fs/ocfs2/dcache.h | 5 ++--- fs/ocfs2/dlmglue.c | 16 ++++------------ 2 files changed, 6 insertions(+), 15 deletions(-)
fs/ocfs2/dcache.h +2 -3
@@ -17,9 +17,8 @@ struct ocfs2_dentry_lock {u64 dl_parent_blkno;/* -* The ocfs2_dentry_lock keeps an inode reference until -* dl_lockres has been destroyed. This is usually done in -* ->d_iput() anyway, so there should be minimal impact. +* The inode reference is dropped before dl_lockres is unlocked. +* Callbacks must not use it to find the mount context during teardown. */ struct inode *dl_inode;struct ocfs2_lock_res dl_lockres;
fs/ocfs2/dlmglue.c +4 -12
@@ -56,7 +56,6 @@ struct ocfs2_mask_waiter {#endif }; -static struct ocfs2_super *ocfs2_get_dentry_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_inode_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_file_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_qinfo_osb (struct ocfs2_lock_res *lockres);
@@ -256,7 +255,6 @@ static const struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { };static const struct ocfs2_lock_res_ops ocfs2_dentry_lops = { - .get_osb = ocfs2_get_dentry_osb, .post_unlock = ocfs2_dentry_post_unlock, .downconvert_worker = ocfs2_dentry_convert_worker, .flags =0 ,
@@ -307,7 +305,7 @@ static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res {BUG_ON (lockres->l_type !=OCFS2_LOCK_TYPE_DENTRY ); -return (struct ocfs2_dentry_lock *)lockres->l_priv; + return container_of(lockres, struct ocfs2_dentry_lock, dl_lockres); }static inline struct ocfs2_mem_dqinfo *ocfs2_lock_res_qinfo (struct ocfs2_lock_res *lockres)
@@ -608,13 +606,6 @@ static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres)return be64_to_cpu (inode_blkno_be); } -static struct ocfs2_super *ocfs2_get_dentry_osb (struct ocfs2_lock_res *lockres) -{ -struct ocfs2_dentry_lock *dl = lockres->l_priv; - -return OCFS2_SB (dl->dl_inode->i_sb); -} -void ocfs2_dentry_lock_res_init (struct ocfs2_dentry_lock *dl,u64 parent,struct inode *inode) {
@@ -622,6 +613,7 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,u64 inode_blkno =OCFS2_I (inode)->ip_blkno;__be64 inode_blkno_be =cpu_to_be64 (inode_blkno);struct ocfs2_lock_res *lockres = &dl->dl_lockres; +struct ocfs2_super *osb =OCFS2_SB (inode->i_sb);ocfs2_lock_res_init_once (lockres);
@@ -650,9 +642,9 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,memcpy (&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START ], &inode_blkno_be,sizeof (__be64)); -ocfs2_lock_res_init_common (OCFS2_SB (inode->i_sb), lockres, +ocfs2_lock_res_init_common (osb, lockres,OCFS2_LOCK_TYPE_DENTRY , &ocfs2_dentry_lops, - dl); + osb); } static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1644/2857 ALSA: pcm: Optimize cpu_latency_qos_*() calls
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 9f6f4e97fd53908aecb0979507d9ff10a22288eb ]
We have a few cpu_latency_qos_*() calls in PCM callbacks, but they seem suboptimal in a few aspects:
- We call them at each time when the hw_params changed, but explicitly do remove and (re-)add; this could be cpu_latency_qos_update_request(), instead
- The setup of cpu_latency_qos_*() doesn't have to be in hw_params at all; it's not the place where the actual parameters are set up, but rather better at the prepare callback.
- The hw_free calls cpu_latency_qos_remove_request() unconditionally, which may be poking a WARNING when it wasn't queued.
For addressing the issues above, this patch cleans up and reorganize the cpu_latency_qos_*() calls in the PCM core by a couple helper functions. Now, they are set up at prepare callback, and cleared at hw_free and release callbacks via the new helpers.
Stable-dep-of: 9017bc3d13da ("ALSA: pcm: Prevent O_APPEND open on OSS streams")
--- sound/core/pcm_native.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-)
sound/core/pcm_native.c +25 -10
@@ -726,11 +726,32 @@ EXPORT_SYMBOL_GPL(snd_pcm_runtime_buffer_set_silence);#define is_oss_stream (substream) false#endif +static void pcm_qos_req_clear (struct snd_pcm_substream *substream) +{ +if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) +cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); +} + +static void pcm_qos_req_update (struct snd_pcm_substream *substream,int usecs) +{ +if (usecs <0 ) { +pcm_qos_req_clear (substream); +return ; + } + +if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) +cpu_latency_qos_update_request (&substream->latency_pm_qos_req, + usecs); +else +cpu_latency_qos_add_request (&substream->latency_pm_qos_req, + usecs); +} +static int snd_pcm_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) {struct snd_pcm_runtime *runtime; -int err, usecs; +int err;unsigned int bits;snd_pcm_uframes_t frames;
@@ -837,12 +858,6 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,snd_pcm_timer_resolution_change (substream);snd_pcm_set_state (substream,SNDRV_PCM_STATE_SETUP ); -if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) -cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); - usecs =period_to_usecs (runtime); -if (usecs >=0 ) -cpu_latency_qos_add_request (&substream->latency_pm_qos_req, - usecs); err =0 ; _error:if (err) {
@@ -921,7 +936,7 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream) goto unlock; result =do_hw_free (substream);snd_pcm_set_state (substream,SNDRV_PCM_STATE_OPEN ); -cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); +pcm_qos_req_clear (substream); unlock:snd_pcm_buffer_access_unlock (runtime);return result;
@@ -1974,6 +1989,7 @@ static int snd_pcm_do_prepare(struct snd_pcm_substream *substream, err = substream->ops->prepare (substream);if (err <0 )return err; +pcm_qos_req_update (substream,period_to_usecs (substream->runtime));return snd_pcm_do_reset (substream, state); }
@@ -2748,8 +2764,7 @@ void snd_pcm_release_substream(struct snd_pcm_substream *substream) substream->ops->close (substream); substream->hw_opened =0 ; } -if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) -cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); +pcm_qos_req_clear (substream);if (substream->pcm_release) { substream->pcm_release (substream); substream->pcm_release =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1645/2857 ALSA: pcm: Prevent O_APPEND open on OSS streams
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 9017bc3d13da0ea4e63be618c87143a7b69185e6 ]
ALSA PCM core accepts to re-use the existing stream when O_APPEND is passed, and it's been used for dmix, etc. However, this mode isn't supposed to be used for OSS: the OSS stream allows re-configuration via its hw_params/hw_refine procedure even while it's being mmapped, so it implies the usage of only a single stream. Because of this assumption, the sanity check is skipped for OSS streams, and if user may attach to an existing OSS stream with O_APPEND, it may result in a UAF of the mapped pages which could be used as a privilege escalation exploit.
For addressing it, this patch simply prohibits the O_APPEND behavior on the OSS stream. O_APPEND is never used for OSS layer itself, so this can't break for the right applications.
--- sound/core/pcm.c | 2 ++ sound/core/pcm_local.h | 6 ++++++ sound/core/pcm_native.c | 6 ------ 3 files changed, 8 insertions(+), 6 deletions(-)
sound/core/pcm.c +2 -0
@@ -932,6 +932,8 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,return -ENODEV ;if (!SUBSTREAM_BUSY (substream))return -EBADFD ; +if (is_oss_stream (substream)) +return -EINVAL ; substream->ref_count++; *rsubstream = substream;return 0 ;
sound/core/pcm_local.h +6 -0
@@ -80,4 +80,10 @@ static inline void snd_pcm_dma_buffer_sync(struct snd_pcm_substream *substream, snd_dma_buffer_sync(snd_pcm_get_dma_buf(substream), mode); } +#if IS_ENABLED (CONFIG_SND_PCM_OSS ) +#define is_oss_stream (substream) ((substream)->oss.oss) +#else +#define is_oss_stream (substream) false +#endif +#endif /* __SOUND_CORE_PCM_LOCAL_H */
sound/core/pcm_native.c +0 -6
@@ -720,12 +720,6 @@ int snd_pcm_runtime_buffer_set_silence(struct snd_pcm_runtime *runtime) }EXPORT_SYMBOL_GPL (snd_pcm_runtime_buffer_set_silence); -#if IS_ENABLED (CONFIG_SND_PCM_OSS ) -#define is_oss_stream (substream) ((substream)->oss.oss) -#else -#define is_oss_stream (substream) false -#endif -static void pcm_qos_req_clear (struct snd_pcm_substream *substream) {if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1646/2857 tools: linux/types.h: Add 128-bit integer types for arm64 UAPI structures
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
[ Upstream commit 10a47fb67340bca274276faf855d7d460afd9a7a ]
The arm64 UAPI exposes some 128-bit integer types to represent things such as fpsimd registers in the sigcontext. In preparation for defining these using the '__u128' typedef implemented by uapi/linux/types.h, copy that typedef over to the private linux/types.h header used by the tools directory.
--- tools/include/linux/types.h | 5 +++++ 1 file changed, 5 insertions(+)
tools/include/linux/types.h +5 -0
@@ -23,6 +23,11 @@ typedef enum {__GFP_HIGH } gfp_t; +#ifdef __SIZEOF_INT128__ +typedef __signed__ __int128 __s128 __attribute__((aligned(16))); +typedef unsigned __int128 __u128 __attribute__((aligned (16 ))); +#endif +/* * We define u64 as uint64_t for every architecture * so that we can print it with "%"PRIx64 without getting warnings.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1647/2857 hwmon: (sht15) Stop deferred work before releasing its resources
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 5eab1e7f7ed12893f3864fe46ffcd5a41a752d6a ]
The IRQ handler and regulator notifier can leave work pending after a measurement or notification completes. Neither work item is drained before its resources are released on removal or probe failure.
Disable read_work before freeing the IRQ, since the worker can re-enable it. Use request_irq()/free_irq() for explicit teardown. Unregister the regulator notifier before cancelling update_supply_work and disabling the regulator. Apply the same ordering to probe failures.
--- drivers/hwmon/sht15.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
drivers/hwmon/sht15.c +19 -9
@@ -31,6 +31,7 @@#include <linux/bitrev.h> #include <linux/gpio/consumer.h> #include <linux/of.h> +#include <linux/workqueue.h> /* Commands */ #define SHT15_MEASURE_TEMP 0x03
@@ -804,7 +805,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)disable_irq_nosync (irq);atomic_inc (&data->interrupt_handled);/* Then schedule a reading work struct */ -if (data->state !=SHT15_READING_NOTHING ) +if (READ_ONCE (data->state) !=SHT15_READING_NOTHING )schedule_work (&data->read_work);return IRQ_HANDLED ; }
@@ -976,11 +977,8 @@ static int sht15_probe(struct platform_device *pdev) goto err_release_reg; } - ret =devm_request_irq (&pdev->dev,gpiod_to_irq (data->data), - sht15_interrupt_fired, -IRQF_TRIGGER_FALLING , -"sht15 data" , - data); + ret =request_irq (gpiod_to_irq (data->data), sht15_interrupt_fired, +IRQF_TRIGGER_FALLING ,"sht15 data" , data);if (ret) {dev_err (&pdev->dev,"failed to get irq for data line\n" ); goto err_release_reg;
@@ -988,15 +986,15 @@ static int sht15_probe(struct platform_device *pdev)disable_irq_nosync (gpiod_to_irq (data->data)); ret =sht15_connection_reset (data);if (ret) - goto err_release_reg; + goto err_free_irq; ret =sht15_soft_reset (data);if (ret) - goto err_release_reg; + goto err_free_irq; ret =sysfs_create_group (&pdev->dev.kobj, &sht15_attr_group);if (ret) {dev_err (&pdev->dev,"sysfs create failed\n" ); - goto err_release_reg; + goto err_free_irq; } data->hwmon_dev =hwmon_device_register (data->dev);
@@ -1009,9 +1007,15 @@ static int sht15_probe(struct platform_device *pdev) err_release_sysfs_group:sysfs_remove_group (&pdev->dev.kobj, &sht15_attr_group); +err_free_irq: +WRITE_ONCE (data->state,SHT15_READING_NOTHING ); +disable_irq (gpiod_to_irq (data->data)); +cancel_work_sync (&data->read_work); +free_irq (gpiod_to_irq (data->data), data); err_release_reg:if (!IS_ERR (data->reg)) {regulator_unregister_notifier (data->reg, &data->nb); +cancel_work_sync (&data->update_supply_work);regulator_disable (data->reg); }return ret;
@@ -1025,12 +1029,18 @@ static int sht15_remove(struct platform_device *pdev)hwmon_device_unregister (data->hwmon_dev);sysfs_remove_group (&pdev->dev.kobj, &sht15_attr_group); +WRITE_ONCE (data->state,SHT15_READING_NOTHING ); +disable_irq (gpiod_to_irq (data->data)); +cancel_work_sync (&data->read_work); +free_irq (gpiod_to_irq (data->data), data); + ret =sht15_soft_reset (data);if (ret)dev_err (&pdev->dev,"Failed to reset device (%pe)\n" ,ERR_PTR (ret));if (!IS_ERR (data->reg)) {regulator_unregister_notifier (data->reg, &data->nb); +cancel_work_sync (&data->update_supply_work);regulator_disable (data->reg); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1648/2857 mm/mremap: fix moving PUD leaves
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 440c8779757f09f290770b1d361dc1516a9d0b3e ]
pud_none_or_clear_bad() only really works on page tables. PUD leaves confuse the check and make us clear the page table entry and print a warning.
Since commit aed877c2b4257 ("device/dax: properly refcount device dax pages when mapping"), this also leaks device-DAX folio references, mapcounts and RSS accounting, resulting in "Bad rss-counter state" warnings on exit.
Allow PUD leaves in get_old_pud(). If a PUD leaf cannot be moved as a whole or the move fails, split it. This unmaps it with proper accounting instead of treating the leaf entry as a PMD table.
Keep using pud_trans_huge() for now, in the future this code should be cleaned up to just check for PUD leaves.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/mremap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
mm/mremap.c +6 -6
@@ -47,7 +47,8 @@ static pud_t *get_old_pud(struct mm_struct *mm, unsigned long addr)return NULL ; pud =pud_offset (p4d, addr); -if (pud_none_or_clear_bad (pud)) +if (!pud_trans_huge (*pud) && !pud_devmap (*pud) && +pud_none_or_clear_bad (pud))return NULL ;return pud;
@@ -547,12 +548,11 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (!new_pud)break ;if (pud_trans_huge (*old_pud) ||pud_devmap (*old_pud)) { -if (extent ==HPAGE_PUD_SIZE ) { -move_pgt_entry (HPAGE_PUD , vma, old_addr, new_addr, - old_pud, new_pud, need_rmap_locks); -/* We ignore and continue on error? */ +if (extent ==HPAGE_PUD_SIZE && +move_pgt_entry (HPAGE_PUD , vma, old_addr, new_addr, + old_pud, new_pud, need_rmap_locks))continue ; - } +split_huge_pud (vma, old_pud, old_addr); }else if (IS_ENABLED (CONFIG_HAVE_MOVE_PUD ) && extent ==PUD_SIZE ) { if (move_pgt_entry(NORMAL_PUD, vma, old_addr, new_addr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1649/2857 mm/mremap: recheck PUDs under the page table lock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 402882943dfa8bab5c2bcc66189f9fb2828f248e ]
Once get_old_pud() is fixed to accept PUD leaves, unmap_mapping_range() can clear a leaf between the lookup and the move. Holding mmap_lock in write mode does not prevent this.
If the zap happens before move_page_tables() tests the entry, an empty PUD can reach move_normal_pud(), where pud_populate() turns it into a present page table entry. If it happens after the test, move_huge_pud() can instead try to move an empty entry, triggering CONFIG_DEBUG_VM warnings on powerpc.
Recheck the source under the page table lock in both helpers. Treat an empty source in move_normal_pud() as a completed move, and use __pud_trans_huge_lock() in move_huge_pud().
In the future we should likely have the code lookup a PUD/PMD lockless once, instead of multiple times, because one of the problematic bits here is the:
pud_trans_huge(*old_pud)
--- mm/mremap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
mm/mremap.c +8 -2
@@ -346,14 +346,18 @@ static bool move_normal_pud(struct vm_area_struct *vma, unsigned long old_addr,if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING ); -/* Clear the pud */ pud = *old_pud; +if (unlikely (pud_none (pud))) + goto out_unlock; + +/* Clear the pud */ pud_clear (old_pud);VM_BUG_ON (!pud_none (*new_pud));pud_populate (mm, new_pud,pud_pgtable (pud));flush_tlb_range (vma, old_addr, old_addr +PUD_SIZE ); +out_unlock:if (new_ptl != old_ptl)spin_unlock (new_ptl);spin_unlock (old_ptl);
@@ -388,7 +392,9 @@ static bool move_huge_pud(struct vm_area_struct *vma, unsigned long old_addr,* We don't have to worry about the ordering of src and dst * ptlocks because exclusive mmap_lock prevents deadlock. */ - old_ptl =pud_lock (vma->vm_mm, old_pud); + old_ptl =__pud_trans_huge_lock (old_pud, vma); +if (unlikely (!old_ptl)) +return false; new_ptl =pud_lockptr (mm, new_pud);if (new_ptl != old_ptl)spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING );
Signature · 1 line
2.53.0
Re: [PATCH 6.1 1649/2857] mm/mremap: recheck PUDs under the page table lock
Hi Greg,
Quoted 28 lines · Greg Kroah-Hartman
6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit
402882943dfa8bab5c2bcc66189f9fb2828f248e]Once
get_old_pud()is fixed to accept PUD leaves,unmap_mapping_range()can clear a leaf between the lookup and the move. Holdingmmap_lockin write mode does not prevent this.If the zap happens before
move_page_tables()tests the entry, an empty PUD can reachmove_normal_pud(), wherepud_populate()turns it into a present page table entry. If it happens after the test,move_huge_pud()can instead try to move an empty entry, triggeringCONFIG_DEBUG_VMwarnings on powerpc.Recheck the source under the page table lock in both helpers. Treat an empty source in
move_normal_pud()as a completed move, and use__pud_trans_huge_lock()inmove_huge_pud().In the future we should likely have the code lookup a PUD/PMD lockless once, instead of multiple times, because one of the problematic bits here is the:
pud_trans_huge(*old_pud)
Quoted 9 lines
Fixes 0881ace292b6 ("mm/mremap: use pmd/pud_poplulate to update page table entries")Reviewed-by Lorenzo Stoakes (ARM) <[email protected]>Reviewed-by Pedro Falcato <[email protected]>Tested-by Muhammad Usama Anjum <[email protected]>Reviewed-by Lance Yang <[email protected]>Signed-off-by David Hildenbrand (Arm) <[email protected]>[ sashal: adjusted context for move helpers using direct vma and old_addr arguments instead of pagetable_move_control ]
Similar to what I reported on v5.15, our CI also has an issue with this one on v6.1:
mm/mremap.c: In function 'move_huge_pud':
mm/mremap.c:395:19: error: implicit declaration of function '__pud_trans_huge_lock'; did you mean 'pud_trans_huge_lock'? [-Wimplicit-function-declaration]
395 | old_ptl = __pud_trans_huge_lock(old_pud, vma);
| ^~~~~~~~~~~~~~~~~~~~~
| pud_trans_huge_lock
mm/mremap.c:395:17: error: assignment to 'spinlock_t *' {aka 'struct spinlock *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
395 | old_ptl = __pud_trans_huge_lock(old_pud, vma);
| ^https://github.com/multipath-tcp/mptcp_net-next/actions/runs/44566582776/job/135709990661#step:9:407
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Greg Kroah-Hartman
maintainerRe: [PATCH 6.1 1649/2857] mm/mremap: recheck PUDs under the page table lock
Quoted 45 lines · Matthieu Baerts
Hi Greg,
Quoted 28 lines · Greg Kroah-Hartman
6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit
402882943dfa8bab5c2bcc66189f9fb2828f248e]Once
get_old_pud()is fixed to accept PUD leaves,unmap_mapping_range()can clear a leaf between the lookup and the move. Holdingmmap_lockin write mode does not prevent this.If the zap happens before
move_page_tables()tests the entry, an empty PUD can reachmove_normal_pud(), wherepud_populate()turns it into a present page table entry. If it happens after the test,move_huge_pud()can instead try to move an empty entry, triggeringCONFIG_DEBUG_VMwarnings on powerpc.Recheck the source under the page table lock in both helpers. Treat an empty source in
move_normal_pud()as a completed move, and use__pud_trans_huge_lock()inmove_huge_pud().In the future we should likely have the code lookup a PUD/PMD lockless once, instead of multiple times, because one of the problematic bits here is the:
pud_trans_huge(*old_pud)Quoted 9 lines
Fixes 0881ace292b6 ("mm/mremap: use pmd/pud_poplulate to update page table entries")Reviewed-by Lorenzo Stoakes (ARM) <[email protected]>Reviewed-by Pedro Falcato <[email protected]>Tested-by Muhammad Usama Anjum <[email protected]>Reviewed-by Lance Yang <[email protected]>Signed-off-by David Hildenbrand (Arm) <[email protected]>[ sashal: adjusted context for move helpers using direct vma and old_addr arguments instead of pagetable_move_control ]Similar to what I reported on v5.15, our CI also has an issue with this one on v6.1:
mm/mremap.c: In function 'move_huge_pud':
mm/mremap.c:395:19: error: implicit declaration of function '__pud_trans_huge_lock'; did you mean 'pud_trans_huge_lock'? [-Wimplicit-function-declaration]
Quoted 9 lines
395 | old_ptl = __pud_trans_huge_lock(old_pud, vma); | ^~~~~~~~~~~~~~~~~~~~~ | pud_trans_huge_lock mm/mremap.c:395:17: error: assignment to 'spinlock_t *' {aka 'struct spinlock *'} from 'int' makes pointer from integer without a cast [-Wint-conversion] 395 | old_ptl = __pud_trans_huge_lock(old_pud, vma); | ^https://github.com/multipath-tcp/mptcp_net-next/actions/runs/44566582776/job/135709990661#step:9:407
thanks, now dropped from here and 5.15.y
greg k-h
Sasha Levin
maintainerRe: [PATCH 6.1 1649/2857] mm/mremap: recheck PUDs under the page table lock
Quoted 1 line
thanks, now dropped from here and 5.15.y
The build break is fixed by 54a948a1e97a ("mm/huge pud: use transparent huge pud helpers only with CONFIG_TRANSPARENT_HUGEPAGE"), which is now queued ahead of it, so I've requeued the recheck patch for 6.1 and 5.15.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 1650/2857 mm: page_alloc: do not give all non-blocking requests reserve access
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Weiner <[email protected]>
[ Upstream commit 6ee3d87b940848aaed5d4e8d005c5f674bf2637a ]
Patch series "mm: page_alloc: fix reserve access for non-blocking requests", v2.
Two fixes for how non-blocking allocations interact with the highatomic reserve. There are prerequisites for Salvatore's "mm/page_alloc: avoid direct reclaim and compaction for costly __GFP_NORETRY allocations" [0].
Patch 1 narrows which requests may physically take highatomic pages, patch 2 narrows which requests may count them in their watermark check.
Both are prerequisites for Salvatore's patch: it clears __GFP_DIRECT_RECLAIM for costly __GFP_NORETRY requests, which turns every large page cache folio allocation that reaches the slowpath into a non-blocking one. Without patch 1, those requests may fall back to the highatomic freelists reserved for atomic requests. Without patch 2, they count the free highatomic pages in their watermark check while being served from regular memory, so they can consume regular high-order blocks below the min watermark by the size of the reserve. GFP_NOWAIT requests hit both paths today, so these are existing problems worthy of their own stable backports; but Salvatore's patch would widen them significantly.
Patch 2 reproduction: a GFP_NOWAIT burst under memory pressure can drain regular free memory to zero while the highatomic reserve sits idle. Measured on a 32G box with an anonymous working set, swap, and a full 290M reserve, three synthetic bursts drove the 28G Normal zone's regular free memory to 28M, 0.8M and 0.6M against a 60M min watermark. Swapout failed its swap table allocation inside reclaim, reclaim scanned 13M pages to free 200k, and page faults stalled for tens to hundreds of milliseconds. With the fix the burst stops at the min watermark and nothing else happens. This was found in review and reproduced synthetically; it has not been observed in production.
GFP_ATOMIC order-0 requests have a milder version of the same problem:
They are entitled to the reserve but are served regular memory first, so the fix there has to change the watermark check and the freelist order together. Salvatore's change doesn't interact with this, though; fixing that is left for a separate patch.
This patch (of 2):
281dd25c1a01 ("mm/page_alloc: let GFP_ATOMIC order-0 allocs access highatomic reserves") accidentally gave all non-blocking allocation requests access to highatomic reserves, which includes GFP_NOWAIT and other sites clearing __GFP_DIRECT_RECLAIM.
While this improved atomic request success rate, it's unintentionally broad and can actually worsen highatomic requests by squandering the reserves on requests that don't need it.
There are concurrent efforts to clear __GFP_DIRECT_RECLAIM altogether for costly order __GFP_NORETRY requests, which would then also fall into this exemption and deplete reserves even faster.
What GFP_ATOMIC has over the others is __GFP_HIGH, which alloc_flags_slowpath() translates to ALLOC_MIN_RESERVE.
Narrow the exemption to contexts that have both ALLOC_NON_BLOCK | ALLOC_MIN_RESERVE.
--- mm/internal.h | 3 +++ mm/page_alloc.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-)
mm/internal.h +3 -0
@@ -797,6 +797,9 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,/* Flags that allow allocations below the min watermark. */ #define ALLOC_RESERVES (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM) +/* Flags that mean GFP_ATOMIC */ +#define ALLOC_MASK_ATOMIC (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE) +enum ttu_flags ;struct tlbflush_unmap_batch ;
mm/page_alloc.c +3 -1
@@ -3777,7 +3777,9 @@ struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone,* reserves as failing now is worse than failing a * high-order atomic allocation in the future. */ -if (!page && (alloc_flags & (ALLOC_OOM |ALLOC_NON_BLOCK ))) +if (!page && + ((alloc_flags &ALLOC_OOM ) || + (alloc_flags &ALLOC_MASK_ATOMIC ) ==ALLOC_MASK_ATOMIC )) page =__rmqueue_smallest (zone, order,MIGRATE_HIGHATOMIC );if (!page) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1651/2857 drm/amdgpu: cancel idle work in hw_init failure paths for vcn/uvd/vce/jpeg
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Liu <[email protected]>
[ Upstream commit a56c2536c399d57a9bb1c02fd411e0c25859af3b ]
When hw_init() fails, amdgpu_device_ip_fini_early() skips hw_fini() because status.hw was never set. For VCN, UVD (including UVD ENC), VCE, and JPEG, hw_fini() is where cancel_delayed_work_sync() is called. Any idle work queued during the partial hw_init() is therefore left pending after sw_fini() frees the adev state the handler touches.
Cancel the idle work in each hw_init() error path, immediately before returning the error, so that hw_fini() remains the sole cancel site on the normal teardown path with no duplication.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 8 ++++---- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c | 4 +++- drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c | 4 +++- drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/vce_v4_0.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 17 ++++++++++------- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 +++- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 4 +++- 17 files changed, 69 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +3 -1
@@ -135,7 +135,9 @@ static int jpeg_v2_0_hw_init(void *handle) (adev->doorbell_index.vcn.vcn_ring0_1 << 1), 0); r =amdgpu_ring_test_helper (ring); -if (!r) +if (r) +cancel_delayed_work_sync (&adev->jpeg.idle_work); +else DRM_INFO ("JPEG decode initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +5 -1
@@ -184,12 +184,16 @@ static int jpeg_v2_5_hw_init(void *handle) r =amdgpu_ring_test_helper (ring);if (r) -return r; + goto error; }DRM_INFO ("JPEG decode initialized successfully.\n" );return 0 ; + +error: +cancel_delayed_work_sync (&adev->jpeg.idle_work); +return r; }/**
drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +4 -4
@@ -151,11 +151,11 @@ static int jpeg_v3_0_hw_init(void *handle) r =amdgpu_ring_test_helper (ring);if (r) -return r; - -DRM_INFO ("JPEG decode initialized successfully.\n" ); +cancel_delayed_work_sync (&adev->jpeg.idle_work); +else +DRM_INFO ("JPEG decode initialized successfully.\n" ); -return 0 ; +return r; }/**
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +5 -1
@@ -143,11 +143,15 @@ static int jpeg_v4_0_hw_init(void *handle) r =amdgpu_ring_test_helper (ring);if (r) -return r; + goto error;DRM_DEV_INFO (adev->dev,"JPEG decode initialized successfully.\n" );return 0 ; + +error: +cancel_delayed_work_sync (&adev->jpeg.idle_work); +return r; }/**
drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c +3 -1
@@ -712,7 +712,9 @@ static int uvd_v3_1_hw_init(void *handle)amdgpu_ring_commit (ring); done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->uvd.idle_work); +else DRM_INFO ("UVD initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c +3 -1
@@ -195,7 +195,9 @@ static int uvd_v4_2_hw_init(void *handle)amdgpu_ring_commit (ring); done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->uvd.idle_work); +else DRM_INFO ("UVD initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c +3 -1
@@ -192,7 +192,9 @@ static int uvd_v5_0_hw_init(void *handle)amdgpu_ring_commit (ring); done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->uvd.idle_work); +else DRM_INFO ("UVD initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +3 -1
@@ -513,7 +513,9 @@ static int uvd_v6_0_hw_init(void *handle) } done: -if (!r) { +if (r) { +cancel_delayed_work_sync (&adev->uvd.idle_work); + }else {if (uvd_v6_0_enc_support (adev))DRM_INFO ("UVD and UVD ENC initialized successfully.\n" );else
drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c +3 -1
@@ -581,7 +581,9 @@ static int uvd_v7_0_hw_init(void *handle) } } done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->uvd.idle_work); +else DRM_INFO ("UVD and UVD ENC initialized successfully.\n" );return r;
drivers/gpu/drm/amd/amdgpu/vce_v2_0.c +5 -1
@@ -469,12 +469,16 @@ static int vce_v2_0_hw_init(void *handle)for (i =0 ; i < adev->vce.num_rings; i++) { r =amdgpu_ring_test_helper (&adev->vce.ring[i]);if (r) -return r; + goto error; }DRM_INFO ("VCE initialized successfully.\n" );return 0 ; + +error: +cancel_delayed_work_sync (&adev->vce.idle_work); +return r; }static int vce_v2_0_hw_fini (void *handle)
drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +5 -1
@@ -479,12 +479,16 @@ static int vce_v3_0_hw_init(void *handle)for (i =0 ; i < adev->vce.num_rings; i++) { r =amdgpu_ring_test_helper (&adev->vce.ring[i]);if (r) -return r; + goto error; }DRM_INFO ("VCE initialized successfully.\n" );return 0 ; + +error: +cancel_delayed_work_sync (&adev->vce.idle_work); +return r; }static int vce_v3_0_hw_fini (void *handle)
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +5 -1
@@ -532,12 +532,16 @@ static int vce_v4_0_hw_init(void *handle)for (i =0 ; i < adev->vce.num_rings; i++) { r =amdgpu_ring_test_helper (&adev->vce.ring[i]);if (r) -return r; + goto error; }DRM_INFO ("VCE initialized successfully.\n" );return 0 ; + +error: +cancel_delayed_work_sync (&adev->vce.idle_work); +return r; }static int vce_v4_0_hw_fini (void *handle)
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +10 -7
@@ -199,25 +199,28 @@ static int vcn_v1_0_hw_init(void *handle) r =amdgpu_ring_test_helper (ring);if (r) - goto done; + goto error_vcn;for (i =0 ; i < adev->vcn.num_enc_rings; ++i) { ring = &adev->vcn.inst->ring_enc[i]; r =amdgpu_ring_test_helper (ring);if (r) - goto done; + goto error_vcn; } ring = &adev->jpeg.inst->ring_dec; r =amdgpu_ring_test_helper (ring);if (r) - goto done; + goto error_both; -done: -if (!r) -DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , - (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" ); +DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , + (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" ); +return 0 ; +error_both: +cancel_delayed_work_sync (&adev->jpeg.idle_work); +error_vcn: +cancel_delayed_work_sync (&adev->vcn.idle_work);return r; }
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +3 -1
@@ -248,7 +248,9 @@ static int vcn_v2_0_hw_init(void *handle) } done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->vcn.idle_work); +else DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" );
drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +3 -1
@@ -309,7 +309,9 @@ static int vcn_v2_5_hw_init(void *handle) } done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->vcn.idle_work); +else DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" );
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +3 -1
@@ -355,7 +355,9 @@ static int vcn_v3_0_hw_init(void *handle) } done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->vcn.idle_work); +else DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" );
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +3 -1
@@ -261,7 +261,9 @@ static int vcn_v4_0_hw_init(void *handle) } done: -if (!r) +if (r) +cancel_delayed_work_sync (&adev->vcn.idle_work); +else DRM_INFO ("VCN decode and encode initialized successfully(under %s).\n" , (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG )?"DPG Mode" :"SPG Mode" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1652/2857 ovl: look up the index by the decoded origin
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 520ef67f47f69255695859b0008281a384d0bc20 ]
A file opened by file handle on an overlay with nfs_export=on can show the stale lower data of a file that was copied up to the upper layer. While the file opened this way stays in the inode cache, a lookup of the copied up file by path fails with ESTALE for all users. The open can also succeed for a file that was removed, where it has to fail with ESTALE. This happens with a handle that has one byte changed. The handle comes from an NFS client, or from a process that calls open_by_handle_at() with CAP_DAC_READ_SEARCH in the initial user namespace.
When a file in a lower layer is about to be modified, overlayfs first copies it to the upper layer (copy up). With nfs_export=on, each copy up also creates an entry in the index directory, a directory that overlayfs keeps for itself on the upper filesystem.
The handle of an overlay file that comes from a lower layer wraps the handle of its lower inode. Overlayfs calls this lower inode the origin. The overlay handle stays valid after a copy up.
To decode such a handle, ovl_lower_fh_to_d() first decodes the wrapped handle to the origin. If no overlay inode is cached for the origin, it looks in the index directory:
- An index entry there leads to the upper file.
- A whiteout, the marker that overlayfs uses for a removed file, means that the overlay file was removed.
The name of an index entry is the handle that copy up encoded for the origin, as a hex string.
ovl_lower_fh_to_d() builds the name for this lookup from the bytes that the caller passed in. But handles with different bytes can decode to the same inode:
- Overlayfs ignores some flag bits of the handle.
- A lower filesystem can accept a different fid type, extra bytes, or generation 0 for any generation.
Such a handle decodes to the origin but misses the index entry or the whiteout. So the decode returns an overlay inode that has only the lower file.
While that inode is cached, a path lookup of a copied up file fails with ESTALE, since the upper file that the lookup finds does not match the cached inode, which has none.
Reproduced on tmpfs and on ext4 with open_by_handle_at(), after a copy up and a mount cycle. A handle in which one flag bit, the fid type, the length or the generation was changed read the old lower data, and path lookups returned ESTALE.
Fix this by re-encoding the decoded origin and building the index name from that handle.
--- Documentation/filesystems/overlayfs.rst | 3 ++- fs/overlayfs/export.c | 4 ++-- fs/overlayfs/namei.c | 13 ++++++++++--- fs/overlayfs/overlayfs.h | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-)
Documentation/filesystems/overlayfs.rst +2 -1
@@ -534,7 +534,8 @@ When decoding an overlay file handle, the following steps are followed: 1. Find underlying layer by UUID and path type information. 2. Decode the underlying filesystem file handle to underlying dentry. -3. For a lower file handle, lookup the handle in index directory by name. +3. For a lower file handle, encode the decoded underlying inode again and + lookup that handle in index directory by name. 4. If a whiteout is found in index, return ESTALE. This represents an overlay object that was deleted after its file handle was encoded. 5. For a non-directory, instantiate a disconnected overlay dentry from the
fs/overlayfs/export.c +2 -2
@@ -726,9 +726,9 @@ static struct dentry *ovl_lower_fh_to_d(struct super_block *sb, } } -/* Then lookup indexed upper/whiteout by origin fh */ +/* Then lookup indexed upper/whiteout by origin */ if (ofs->indexdir) { - index =ovl_get_index_fh (ofs, fh); + index =ovl_get_index_origin (ofs, origin.dentry); err =PTR_ERR (index);if (IS_ERR (index)) { index =NULL ;
fs/overlayfs/namei.c +10 -3
@@ -667,14 +667,21 @@ int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin,return err; } -/* Lookup index by file handle for NFS export */ -struct dentry *ovl_get_index_fh (struct ovl_fs *ofs,struct ovl_fh *fh) +/* +* Lookup index by decoded origin for NFS export. +* +* The name of an index is the hex of the file handle that copy up encoded. +* The bytes of the handle to decode cannot be used as the name, because a +* lower fs may decode many handles to the same inode. For example, it may +* ignore the fid type, extra fid bytes or a zero generation. +*/ +struct dentry *ovl_get_index_origin (struct ovl_fs *ofs,struct dentry *origin) {struct dentry *index;struct qstr name;int err; - err =ovl_get_index_name_fh (fh, &name); + err =ovl_get_index_name (ofs, origin, &name);if (err)return ERR_PTR (err);
fs/overlayfs/overlayfs.h +1 -1
@@ -537,7 +537,7 @@ struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index);int ovl_verify_index (struct ovl_fs *ofs,struct dentry *index);int ovl_get_index_name (struct ovl_fs *ofs,struct dentry *origin,struct qstr *name); -struct dentry *ovl_get_index_fh (struct ovl_fs *ofs,struct ovl_fh *fh); +struct dentry *ovl_get_index_origin (struct ovl_fs *ofs,struct dentry *origin);struct dentry *ovl_lookup_index (struct ovl_fs *ofs,struct dentry *upper,struct dentry *origin,bool verify);int ovl_path_next (int idx,struct dentry *dentry,struct path *path);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1653/2857 drm/msm/hdmi: Handle msm_hdmi_power_on() errors during .atomic_pre_enable()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Kozlowski <[email protected]>
[ Upstream commit dd6ecace57851878e62367a6f1a26dd5b9aa217f ]
Properly handle power up failures during .atomic_pre_enable() by aborting the .atomic_pre_enable() to avoid accessing registers why blocks did not bring up. Otherwise this could lead to imprecise aborts when accessing MMIO while entire power domain is off.
Patchwork: https://patchwork.freedesktop.org/patch/752652/
--- drivers/gpu/drm/msm/hdmi/hdmi_bridge.c | 30 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/msm/hdmi/hdmi_bridge.c +25 -5
@@ -19,7 +19,7 @@ void msm_hdmi_bridge_destroy(struct drm_bridge *bridge)drm_bridge_remove (bridge); } -static void msm_hdmi_power_on (struct drm_bridge *bridge) +static int msm_hdmi_power_on (struct drm_bridge *bridge) {struct drm_device *dev = bridge->dev;struct hdmi_bridge *hdmi_bridge =to_hdmi_bridge (bridge);
@@ -27,11 +27,15 @@ static void msm_hdmi_power_on(struct drm_bridge *bridge)const struct hdmi_platform_config *config = hdmi->config;int i, ret; -pm_runtime_get_sync (&hdmi->pdev->dev); + ret =pm_runtime_resume_and_get (&hdmi->pdev->dev); +if (ret) +return ret; ret =regulator_bulk_enable (config->pwr_reg_cnt, hdmi->pwr_regs); -if (ret) +if (ret) {DRM_DEV_ERROR (dev->dev,"failed to enable pwr regulator: %d\n" , ret); + goto err_pm_put; + }if (config->pwr_clk_cnt >0 ) {DBG ("pixclock: %lu" , hdmi->pixclock);
@@ -47,8 +51,19 @@ static void msm_hdmi_power_on(struct drm_bridge *bridge)if (ret) {DRM_DEV_ERROR (dev->dev,"failed to enable pwr clk: %s (%d)\n" , config->pwr_clk_names[i], ret); + goto err_clk_disable; } } + +return 0 ; + +err_clk_disable: +while (i--) +clk_disable_unprepare (hdmi->pwr_clks[i]); +regulator_bulk_disable (config->pwr_reg_cnt, hdmi->pwr_regs); +err_pm_put: +pm_runtime_put (&hdmi->pdev->dev); +return ret; }static void power_off (struct drm_bridge *bridge)
@@ -143,8 +158,13 @@ static void msm_hdmi_bridge_pre_enable(struct drm_bridge *bridge)DBG ("power up" );if (!hdmi->power_on) { -msm_hdmi_phy_resource_enable (phy); -msm_hdmi_power_on (bridge); +if (msm_hdmi_phy_resource_enable (phy)) +return ; + +if (msm_hdmi_power_on (bridge)) { +msm_hdmi_phy_resource_disable (phy); +return ; + } hdmi->power_on = true;if (hdmi->hdmi_mode) {msm_hdmi_config_avi_infoframe (hdmi);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1654/2857 drm/amd/pm: populate unique ID for smu 13.0.7
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kevin Wang <[email protected]>
[ Upstream commit 079f9103d9cde68fb2ccc414e94520f43ee102de ]
The smu 13.0.7 backend does not register get_unique_id, leaving adev->unique_id at zero and KFD topology without the stable GPU identifier consumed by HIP.
The failure is observed at:
auto ierr = hipDeviceGetUuid(&uuid, 0);
--- .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +20 -0
@@ -1695,6 +1695,25 @@ static int smu_v13_0_7_set_df_cstate(struct smu_context *smu, NULL); } +static void smu_v13_0_7_get_unique_id (struct smu_context *smu) +{ +SmuMetricsExternal_t metrics_external; +SmuMetrics_t *metrics = &metrics_external.SmuMetrics; +struct amdgpu_device *adev = smu->adev; +u32 upper32 =0 , lower32 =0 ; +int ret; + + ret =smu_cmn_get_metrics_table (smu, &metrics_external, false); +if (ret) + goto out; + + upper32 = metrics->PublicSerialNumberUpper; + lower32 = metrics->PublicSerialNumberLower; + +out: + adev->unique_id = ((u64 )upper32 <<32 ) | lower32; +} +static const struct pptable_funcs smu_v13_0_7_ppt_funcs = { .get_allowed_feature_mask = smu_v13_0_7_get_allowed_feature_mask, .set_default_dpm_table = smu_v13_0_7_set_default_dpm_table,
@@ -1760,6 +1779,7 @@ static const struct pptable_funcs smu_v13_0_7_ppt_funcs = { .set_mp1_state = smu_v13_0_7_set_mp1_state, .set_df_cstate = smu_v13_0_7_set_df_cstate, .gpo_control = smu_v13_0_gpo_control, + .get_unique_id = smu_v13_0_7_get_unique_id, };void smu_v13_0_7_set_ppt_funcs (struct smu_context *smu)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1655/2857 drm/amdgpu: keep the CS user fence BO in GTT
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit 7a56d929dc2304edaa6231e1eb5eb82b7e8b74a9 ]
The CS ioctl hands the GPU the GART address of the user fence BO, but since the BO keeps its own preferred and allowed domains, it no longer makes sure the BO is in GTT. A user fence in a VRAM BO, which only needs to be a page in size, gets its address from amdgpu_bo_gpu_offset(), which warns about non-contiguous VRAM. On navi31, a CS with a user fence in a 4K VRAM BO, or in one created with AMDGPU_GEM_CREATE_VM_ALWAYS_VALID:
WARNING: amdgpu_object.c:1531 at amdgpu_bo_gpu_offset+0x86/0xb0 [amdgpu], CPU#11: cs_gem_checks/18393 RIP: 0010:amdgpu_bo_gpu_offset+0x86/0xb0 [amdgpu] Call Trace: <TASK> amdgpu_cs_parser_bos.isra.0+0x4eb/0x850 [amdgpu] amdgpu_cs_ioctl+0x97e/0x2510 [amdgpu] drm_ioctl_kernel+0xac/0x110 [drm] drm_ioctl+0x2c6/0x5b0 [drm] __x64_sys_ioctl+0xa0/0xf0 do_syscall_64+0xa3/0x4d0 entry_SYSCALL_64_after_hwframe+0x76/0x7e
and BOs which can't be in GTT at all, like GWS or OA ones of a page in size, pass the checks as well.
Only take BOs which can't be anywhere else than in GTT as user fence, which the CS then validates there along with its other BOs. While at it, detect userptrs with amdgpu_ttm_tt_is_userptr(); amdgpu_ttm_tt_get_usermm() returns NULL once the task which created the userptr is gone.
v2: only take BOs which can only be in GTT instead of special casing the
user fence BO in the validation, use amdgpu_ttm_tt_is_userptr() (Christian)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6 -1
@@ -153,7 +153,12 @@ static int amdgpu_cs_p1_user_fence(struct amdgpu_cs_parser *p,if (size !=PAGE_SIZE || data->offset > (size -8 ))return -EINVAL ; -if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm)) +if (amdgpu_ttm_tt_is_userptr (bo->tbo.ttm)) +return -EINVAL ; + +/* The GPU writes the user fence through the GART */ +if (bo->preferred_domains !=AMDGPU_GEM_DOMAIN_GTT && + bo->allowed_domains !=AMDGPU_GEM_DOMAIN_GTT )return -EINVAL ; *offset = data->offset;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1656/2857 ksmbd: do not read past the DACL in the access denied debug message
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit 8296a64df5448548f410fb246c1d88a93609602b ]
When smb_check_perm_dacl() falls back to the POSIX ACL and then denies the request, its debug message prints the access mask of the ACE that the second DACL walk stopped at. On that path the walk ran to the end of the DACL, so the pointer is one past the last ACE. If the DACL is the last part of the stored security descriptor, the message reads 4 bytes past the buffer, and KASAN reports a slab-out-of-bounds read in smb_check_perm_dacl().
Print the requested and allowed masks instead. They are what the check compares.
--- fs/smb/server/smbacl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/server/smbacl.c +2 -2
@@ -1626,8 +1626,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, check_access_bits:if (granted & ~(access_bits |FILE_READ_ATTRIBUTES |READ_CONTROL |WRITE_DAC |DELETE )) { -ksmbd_debug (SMB ,"Access denied with winACL, granted : %x, access_req : %x\n" , - granted,le32_to_cpu (ace->access_req)); +ksmbd_debug (SMB ,"Access denied with winACL, requested : %x, allowed : %x\n" , + granted, access_bits); rc = -EACCES ; goto err_out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1657/2857 scsi: target: Move I/O path stats to per CPU
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Christie <[email protected]>
[ Upstream commit 9cf2317b795d6cde0fccb8744b5a080a9586020e ]
The atomic use in the main I/O path is causing perf issues when using higher performance backend devices and multiple queues. This moves the stats to per CPU. Combined with the next patch that moves the non_ordered/delayed_cmd_count to per CPU, IOPS by up to 33% for 8K IOS when using 4 or more queues.
Stable-dep-of: 6a6e7d7230cd ("scsi: target: Fix demo-mode dynamic ACL dev-entry UAF vs LUN teardown")
--- drivers/target/target_core_device.c | 69 +++++++++++++++++++++-------- drivers/target/target_core_stat.c | 69 ++++++++++++++++++++++++----- include/target/target_core_base.h | 20 ++++++--- 3 files changed, 121 insertions(+), 37 deletions(-)
drivers/target/target_core_device.c +50 -19
@@ -56,14 +56,14 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd)rcu_read_lock (); deve =target_nacl_find_deve (nacl, se_cmd->orig_fe_lun);if (deve) { -atomic_long_inc (&deve->total_cmds); +this_cpu_inc (deve->stats->total_cmds);if (se_cmd->data_direction ==DMA_TO_DEVICE ) -atomic_long_add (se_cmd->data_length, - &deve->write_bytes); +this_cpu_add (deve->stats->write_bytes, + se_cmd->data_length);else if (se_cmd->data_direction ==DMA_FROM_DEVICE ) -atomic_long_add (se_cmd->data_length, - &deve->read_bytes); +this_cpu_add (deve->stats->read_bytes, + se_cmd->data_length);if ((se_cmd->data_direction ==DMA_TO_DEVICE ) && deve->lun_access_ro) {
@@ -127,14 +127,14 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd)* target_core_fabric_configfs.c:target_fabric_port_release */ se_cmd->se_dev =rcu_dereference_raw (se_lun->lun_se_dev); -atomic_long_inc (&se_cmd->se_dev->num_cmds); +this_cpu_inc (se_cmd->se_dev->stats->total_cmds);if (se_cmd->data_direction ==DMA_TO_DEVICE ) -atomic_long_add (se_cmd->data_length, - &se_cmd->se_dev->write_bytes); +this_cpu_add (se_cmd->se_dev->stats->write_bytes, + se_cmd->data_length);else if (se_cmd->data_direction ==DMA_FROM_DEVICE ) -atomic_long_add (se_cmd->data_length, - &se_cmd->se_dev->read_bytes); +this_cpu_add (se_cmd->se_dev->stats->read_bytes, + se_cmd->data_length);return ret; }
@@ -323,6 +323,7 @@ int core_enable_device_list_for_node( struct se_portal_group *tpg) {struct se_dev_entry *orig, *new; +int ret =0 ; new =kzalloc (sizeof (*new),GFP_KERNEL );if (!new) {
@@ -330,6 +331,12 @@ int core_enable_device_list_for_node(return -ENOMEM ; } + new->stats = alloc_percpu(struct se_dev_entry_io_stats); +if (!new->stats) { + ret = -ENOMEM ; + goto free_deve; + } +spin_lock_init (&new->ua_lock);INIT_LIST_HEAD (&new->ua_list);INIT_LIST_HEAD (&new->lun_link);
@@ -352,8 +359,8 @@ int core_enable_device_list_for_node(" for dynamic -> explicit NodeACL conversion:" " %s\n", nacl->initiatorname);mutex_unlock (&nacl->lun_entry_mutex); -kfree (new); -return -EINVAL ; + ret = -EINVAL ; + goto free_stats; }if (orig->se_lun_acl !=NULL ) { pr_warn_ratelimited("Detected existing explicit"
@@ -361,8 +368,8 @@ int core_enable_device_list_for_node(" mapped_lun: %llu, failing\n" , nacl->initiatorname, mapped_lun);mutex_unlock (&nacl->lun_entry_mutex); -kfree (new); -return -EINVAL ; + ret = -EINVAL ; + goto free_stats; } new->se_lun = lun;
@@ -395,6 +402,20 @@ int core_enable_device_list_for_node(target_luns_data_has_changed (nacl, new, true);return 0 ; + +free_stats: +free_percpu (new->stats); +free_deve: +kfree (new); +return ret; +} + +static void target_free_dev_entry (struct rcu_head *head) +{ + struct se_dev_entry *deve = container_of(head, struct se_dev_entry, + rcu_head); +free_percpu (deve->stats); +kfree (deve); } void core_disable_device_list_for_node(
@@ -444,7 +465,7 @@ void core_disable_device_list_for_node(kref_put (&orig->pr_kref, target_pr_kref_release);wait_for_completion (&orig->pr_comp); -kfree_rcu (orig, rcu_head); +call_rcu (&orig->rcu_head, target_free_dev_entry);core_scsi3_free_pr_reg_from_nacl (dev, nacl);target_luns_data_has_changed (nacl,NULL , false);
@@ -731,11 +752,13 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)if (!dev)return NULL ; + dev->stats = alloc_percpu(struct se_dev_io_stats); +if (!dev->stats) + goto free_device; + dev->queues =kcalloc (nr_cpu_ids,sizeof (*dev->queues),GFP_KERNEL ); -if (!dev->queues) { - hba->backend->ops->free_device (dev); -return NULL ; - } +if (!dev->queues) + goto free_stats; dev->queue_cnt = nr_cpu_ids;for (i =0 ; i < dev->queue_cnt; i++) {
@@ -749,6 +772,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)INIT_WORK (&q->sq.work, target_queued_submit_work); } + dev->se_hba = hba; dev->transport = hba->backend->ops; dev->transport_flags = dev->transport->transport_flags_default;
@@ -831,6 +855,12 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name) sizeof(dev->t10_wwn.revision));return dev; + +free_stats: +free_percpu (dev->stats); +free_device: + hba->backend->ops->free_device (dev); +return NULL ; }/*
@@ -1041,6 +1071,7 @@ void target_free_device(struct se_device *dev) dev->transport->free_prot (dev);kfree (dev->queues); +free_percpu (dev->stats); dev->transport->free_device (dev); }
drivers/target/target_core_stat.c +57 -12
138 lines not on this page · raw message
include/target/target_core_base.h +14 -6
@@ -658,15 +658,19 @@ struct se_lun_acl {struct se_ml_stat_grps ml_stat_grps; }; +struct se_dev_entry_io_stats { +u32 total_cmds; +u32 read_bytes; +u32 write_bytes; +}; +struct se_dev_entry {u64 mapped_lun;u64 pr_res_key;u64 creation_time;bool lun_access_ro;u32 attach_count; -atomic_long_t total_cmds; -atomic_long_t read_bytes; -atomic_long_t write_bytes; +struct se_dev_entry_io_stats __percpu *stats;/* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */ struct kref pr_kref;struct completion pr_comp;
@@ -790,6 +794,12 @@ struct se_device_queue {struct se_cmd_queue sq; }; +struct se_dev_io_stats { +u32 total_cmds; +u32 read_bytes; +u32 write_bytes; +}; +struct se_device {/* RELATIVE TARGET PORT IDENTIFER Counter */ u16 dev_rpti_counter;
@@ -813,9 +823,7 @@ struct se_device {atomic_long_t num_resets;atomic_long_t aborts_complete;atomic_long_t aborts_no_task; -atomic_long_t num_cmds; -atomic_long_t read_bytes; -atomic_long_t write_bytes; +struct se_dev_io_stats __percpu *stats;/* Active commands on this virtual SE device */ atomic_t non_ordered;bool ordered_sync_in_progress;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1658/2857 scsi: target: Fix demo-mode dynamic ACL dev-entry UAF vs LUN teardown
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yu Zhang <[email protected]>
[ Upstream commit 6a6e7d7230cd4e0a6c003bae5b85bf37a1e77b94 ]
A demo-mode (generate_node_acls=1) login that allocates a dynamic NodeACL populates that ACL's per-LUN dev entries in core_tpg_add_node_to_devs() *before* the ACL is linked onto tpg->acl_node_list by target_add_node_acl():
core_tpg_check_initiator_node_acl():
...
core_tpg_add_node_to_devs(acl, tpg, NULL); /* builds deves */
target_add_node_acl(acl); /* only now listed */
The LUN teardown sweep, core_clear_lun_from_tpg(), enumerates only tpg->acl_node_list, so a dev entry whose ACL is still in the window above is invisible to the sweep and is never disabled. It is left on the se_lun->lun_deve_list after core_tpg_remove_lun() frees the se_lun; when the same unpacked_lun is later re-added and the se_lun is reallocated at the same address, the stale dev entry is rediscovered by target_nacl_find_deve() and core_enable_device_list_for_node() corrupts lun_deve_list:
BUG: KASAN: slab-use-after-free ... core_enable_device_list_for_node+0x5ce/0x880 core_tpg_add_node_to_devs+0x169/0x190 core_dev_add_lun+0x146/0x190 target_fabric_port_link+0xe9/0x1b0 configfs_symlink+0x381/0xae0 __x64_sys_symlink+0x55/0x80
The demo-mode login path that drives the ACL/dev-entry creation is reachable by an unauthenticated initiator; the colliding LUN add/remove is a local configfs operation.
Commit 49cb77e297dc ("target: Avoid mappedlun symlink creation during lun shutdown") introduced se_lun->lun_shutdown and guarded the *explicit* ACL MappedLUN path (target_fabric_mappedlun_link()), but the demo-mode automatic path, core_tpg_add_node_to_devs() -> core_enable_device_list_for_node(), was never given the equivalent guard, and the publish-after-populate ordering in core_tpg_check_initiator_node_acl() was left unchanged.
Fix it in three cooperating parts:
1) Publish the dynamic NodeACL onto acl_node_list *before* creating its dev entries, so the teardown sweep can observe them.
2) Refuse to attach a dev entry to an se_lun that is shutting down, checked under nacl->lun_entry_mutex -- the same lock the sweep takes -- so once the sweep has passed an ACL any later enable for that LUN observes lun_shutdown and skips it.
3) In core_enable_device_list_for_node(), insert the new dev entry onto lun->lun_deve_list while still holding nacl->lun_entry_mutex, in both the replace and the new-entry branch. Previously the entry was added to nacl->lun_entry_hlist under the mutex but to lun->lun_deve_list only after dropping it; with the ACL now published early, the sweep could take the mutex in that gap, find the entry on the hlist, core_disable_device_list_for_node() it (list_del() on the not-yet- linked lun_link succeeds and the entry is freed), and then the enable would list_add_tail() the freed entry back onto lun_deve_list. Linking both lists under the mutex makes enable and the sweep mutually exclusive, closing that window.
core_tpg_add_node_to_devs() already ignores the return value of core_enable_device_list_for_node(), so a shutting-down LUN is simply skipped.
--- drivers/target/target_core_device.c | 18 +++++++++++++++--- drivers/target/target_core_tpg.c | 10 +++++++++- 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/target/target_core_device.c +15 -3
@@ -350,6 +350,19 @@ int core_enable_device_list_for_node( new->attach_count++;mutex_lock (&nacl->lun_entry_mutex); +/* +* Do not attach a new dev entry to an se_lun that is being torn down. +* lun_shutdown is set by core_tpg_remove_lun() before its +* core_clear_lun_from_tpg() sweep; checking it here under the same +* nacl->lun_entry_mutex the sweep takes guarantees that once the sweep +* has passed this ACL no dev entry can be left dangling on the +* se_lun->lun_deve_list that is about to be freed. +*/ +if (lun->lun_shutdown) { +mutex_unlock (&nacl->lun_entry_mutex); + ret = -ENODEV ; + goto free_stats; + } orig =target_nacl_find_deve (nacl, mapped_lun);if (orig && orig->se_lun) {struct se_lun *orig_lun = orig->se_lun;
@@ -376,12 +389,12 @@ int core_enable_device_list_for_node( new->se_lun_acl = lun_acl;hlist_del_rcu (&orig->link);hlist_add_head_rcu (&new->link, &nacl->lun_entry_hlist); -mutex_unlock (&nacl->lun_entry_mutex);spin_lock (&lun->lun_deve_lock);list_del (&orig->lun_link);list_add_tail (&new->lun_link, &lun->lun_deve_list);spin_unlock (&lun->lun_deve_lock); +mutex_unlock (&nacl->lun_entry_mutex);kref_put (&orig->pr_kref, target_pr_kref_release);wait_for_completion (&orig->pr_comp);
@@ -394,11 +407,10 @@ int core_enable_device_list_for_node( new->se_lun = lun; new->se_lun_acl = lun_acl;hlist_add_head_rcu (&new->link, &nacl->lun_entry_hlist); -mutex_unlock (&nacl->lun_entry_mutex); -spin_lock (&lun->lun_deve_lock);list_add_tail (&new->lun_link, &lun->lun_deve_list);spin_unlock (&lun->lun_deve_lock); +mutex_unlock (&nacl->lun_entry_mutex);target_luns_data_has_changed (nacl, new, true);return 0 ;
drivers/target/target_core_tpg.c +9 -1
@@ -265,6 +265,15 @@ struct se_node_acl *core_tpg_check_initiator_node_acl(kref_get (&acl->acl_kref); acl->dynamic_node_acl =1 ; +/* +* Publish the dynamic NodeACL on tpg->acl_node_list before creating +* its demo-mode MappedLUN dev entries below, so that a concurrent LUN +* teardown sweep (core_clear_lun_from_tpg(), which walks acl_node_list) +* can observe and disable those dev entries. Otherwise a dev entry can +* be left on an se_lun->lun_deve_list that is about to be freed. +*/ +target_add_node_acl (acl); +/* * Here we only create demo-mode MappedLUNs from the active * TPG LUNs if the fabric is not explicitly asking for
@@ -274,7 +283,6 @@ struct se_node_acl *core_tpg_check_initiator_node_acl( (tpg->se_tpg_tfo->tpg_check_demo_mode_login_only(tpg) != 1))core_tpg_add_node_to_devs (acl, tpg,NULL ); -target_add_node_acl (acl);return acl; }EXPORT_SYMBOL (core_tpg_check_initiator_node_acl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1659/2857 scsi: target: Fix LUN/device R/W and total command stats
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Christie <[email protected]>
[ Upstream commit 95aa2041c654161d1b5c1eca5379d67d91ef1cf2 ]
In commit 9cf2317b795d ("scsi: target: Move I/O path stats to per CPU") I saw we sometimes use %u and also misread the spec. As a result I thought all the stats were supposed to be 32-bit only. However, for the majority of cases we support currently, the spec specifies u64 bit stats. This patch converts the stats changed in the commit above to u64.
--- drivers/target/target_core_stat.c | 24 ++++++++++++------------ include/target/target_core_base.h | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-)
drivers/target/target_core_stat.c +12 -12
@@ -282,7 +282,7 @@ static ssize_t target_stat_lu_num_cmds_show(struct config_item *item,struct se_device *dev =to_stat_lu_dev (item);struct se_dev_io_stats *stats;unsigned int cpu; -u32 cmds =0 ; +u64 cmds =0 ;for_each_possible_cpu (cpu) { stats =per_cpu_ptr (dev->stats, cpu);
@@ -290,7 +290,7 @@ static ssize_t target_stat_lu_num_cmds_show(struct config_item *item, }/* scsiLuNumCommands */ -return snprintf (page,PAGE_SIZE ,"%u\n" , cmds); +return snprintf (page,PAGE_SIZE ,"%llu\n" , cmds); } static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,
@@ -299,7 +299,7 @@ static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,struct se_device *dev =to_stat_lu_dev (item);struct se_dev_io_stats *stats;unsigned int cpu; -u32 bytes =0 ; +u64 bytes =0 ;for_each_possible_cpu (cpu) { stats =per_cpu_ptr (dev->stats, cpu);
@@ -307,7 +307,7 @@ static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item, }/* scsiLuReadMegaBytes */ -return snprintf (page,PAGE_SIZE ,"%u\n" , bytes >>20 ); +return snprintf (page,PAGE_SIZE ,"%llu\n" , bytes >>20 ); } static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,
@@ -316,7 +316,7 @@ static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,struct se_device *dev =to_stat_lu_dev (item);struct se_dev_io_stats *stats;unsigned int cpu; -u32 bytes =0 ; +u64 bytes =0 ;for_each_possible_cpu (cpu) { stats =per_cpu_ptr (dev->stats, cpu);
@@ -324,7 +324,7 @@ static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item, }/* scsiLuWrittenMegaBytes */ -return snprintf (page,PAGE_SIZE ,"%u\n" , bytes >>20 ); +return snprintf (page,PAGE_SIZE ,"%llu\n" , bytes >>20 ); }static ssize_t target_stat_lu_resets_show (struct config_item *item,char *page)
@@ -1044,7 +1044,7 @@ static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,struct se_dev_entry *deve;unsigned int cpu;ssize_t ret; -u32 cmds =0 ; +u64 cmds =0 ;rcu_read_lock (); deve =target_nacl_find_deve (nacl, lacl->mapped_lun);
@@ -1059,7 +1059,7 @@ static ssize_t target_stat_auth_num_cmds_show(struct config_item *item, }/* scsiAuthIntrOutCommands */ - ret =snprintf (page,PAGE_SIZE ,"%u\n" , cmds); + ret =snprintf (page,PAGE_SIZE ,"%llu\n" , cmds);rcu_read_unlock ();return ret; }
@@ -1073,7 +1073,7 @@ static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,struct se_dev_entry *deve;unsigned int cpu;ssize_t ret; -u32 bytes =0 ; +u64 bytes =0 ;rcu_read_lock (); deve =target_nacl_find_deve (nacl, lacl->mapped_lun);
@@ -1088,7 +1088,7 @@ static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item, }/* scsiAuthIntrReadMegaBytes */ - ret =snprintf (page,PAGE_SIZE ,"%u\n" , bytes >>20 ); + ret =snprintf (page,PAGE_SIZE ,"%llu\n" , bytes >>20 );rcu_read_unlock ();return ret; }
@@ -1102,7 +1102,7 @@ static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,struct se_dev_entry *deve;unsigned int cpu;ssize_t ret; -u32 bytes =0 ; +u64 bytes =0 ;rcu_read_lock (); deve =target_nacl_find_deve (nacl, lacl->mapped_lun);
@@ -1117,7 +1117,7 @@ static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item, }/* scsiAuthIntrWrittenMegaBytes */ - ret =snprintf (page,PAGE_SIZE ,"%u\n" , bytes >>20 ); + ret =snprintf (page,PAGE_SIZE ,"%llu\n" , bytes >>20 );rcu_read_unlock ();return ret; }
include/target/target_core_base.h +6 -6
@@ -659,9 +659,9 @@ struct se_lun_acl { };struct se_dev_entry_io_stats { -u32 total_cmds; -u32 read_bytes; -u32 write_bytes; +u64 total_cmds; +u64 read_bytes; +u64 write_bytes; };struct se_dev_entry {
@@ -795,9 +795,9 @@ struct se_device_queue { };struct se_dev_io_stats { -u32 total_cmds; -u32 read_bytes; -u32 write_bytes; +u64 total_cmds; +u64 read_bytes; +u64 write_bytes; };struct se_device {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1660/2857 KVM: arm64: vgic-its: Dont map an LPI from more than one event
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit de81b28f0b83b22163d7d9a9b708d7aa912e0ef7 ]
KVM keeps one vgic_irq per LPI. A MAPTI of an LPI whose vgic_irq already exists reuses it for the new ITE and leaves its target vCPU as it was. Mapping one LPI from two events is UNPREDICTABLE (IHI 0069H.b, 5.2.10), but nothing stops a guest from doing it. If the first MAPTI names a collection the guest never maps and the second a mapped one, the LPI translates through the second event with a NULL target vCPU.
When the VMM routes an assigned device's MSI to that event on a host with GICv4 enabled, kvm_vgic_v4_set_forwarding() takes the vPE from the NULL target vCPU and the host oopses:
Unable to handle kernel paging request at virtual address 0000000000001980 [...] Call trace: its_build_vmapti_cmd (drivers/irqchip/irq-gic-v3-its.c:943) (P) its_irq_set_vcpu_affinity (drivers/irqchip/irq-gic-v3-its.c:1380) irq_set_vcpu_affinity (kernel/irq/manage.c:670) its_map_vlpi (drivers/irqchip/irq-gic-v4.c:326) kvm_vgic_v4_set_forwarding (arch/arm64/kvm/vgic/vgic-v4.c:485) kvm_arch_irq_bypass_add_producer (arch/arm64/kvm/arm.c:2977) irq_bypass_register_consumer (virt/lib/irqbypass.c:44) kvm_irqfd (arch/arm64/kvm/../../../virt/kvm/eventfd.c:496) kvm_vm_ioctl (arch/arm64/kvm/../../../virt/kvm/kvm_main.c:5270)
Track in each vgic_irq whether an ITE maps it. Drop a MAPTI of an LPI that is already mapped, as a failed MAPTI already is. Restoring the ITS tables keeps the first ITE it reads for each LPI and drops any later one, so a guest saved with a double mapping still restores. Key the check on the mapping, not on the vgic_irq. A vgic_irq outlives its ITE while anything holds a reference to it, such as the vCPU it was last queued on. A later MAPTI of such an LPI succeeds as before, and now retargets it to its collection.
--- arch/arm64/kvm/vgic/vgic-its.c | 37 +++++++++++++++++++++++++++++----- include/kvm/arm_vgic.h | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +32 -5
@@ -816,12 +816,18 @@ int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)/* Requires the its_lock to be held. */ static void its_free_ite (struct kvm *kvm,struct its_ite *ite) { +struct vgic_irq *irq = ite->irq;list_del (&ite->ite_list);/* This put matches the get in vgic_add_lpi. */ -if (ite->irq) { -if (ite->irq->hw) -WARN_ON (its_unmap_vlpi (ite->irq->host_irq)); +if (irq) { + scoped_guard(raw_spinlock_irqsave, &irq->irq_lock) { +if (irq->hw) +WARN_ON (its_unmap_vlpi (ite->irq->host_irq)); + + irq->hw = false; + irq->mapped = false; + }vgic_put_irq (kvm, ite->irq); }
@@ -829,6 +835,23 @@ static void its_free_ite(struct kvm *kvm, struct its_ite *ite)kfree (ite); } +/* Mapping one LPI from two events is UNPREDICTABLE: the first ITE keeps it. */ +static bool vgic_its_map_lpi (struct kvm *kvm,struct its_ite *ite, +struct vgic_irq *irq,struct kvm_vcpu *vcpu) +{ + scoped_guard(raw_spinlock_irqsave, &irq->irq_lock) { +if (!irq->mapped) { + irq->mapped = true; + irq->target_vcpu = vcpu; + ite->irq = irq; +return true; + } + } + +vgic_put_irq (kvm, irq); +return false; +} +static u64 its_cmd_mask_field (u64 *its_cmd,int word,int shift,int size) {return (le64_to_cpu (its_cmd[word]) >> shift) & (BIT_ULL (size) -1 );
@@ -1138,13 +1161,14 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, vcpu =kvm_get_vcpu (kvm, collection->target_addr); irq =vgic_add_lpi (kvm, lpi_nr, vcpu); +if (!IS_ERR (irq) && !vgic_its_map_lpi (kvm, ite, irq, vcpu)) + irq =ERR_PTR (-EEXIST );if (IS_ERR (irq)) {if (new_coll)vgic_its_free_collection (its, coll_id);its_free_ite (kvm, ite);return PTR_ERR (irq); } - ite->irq = irq;return 0 ; }
@@ -2291,7 +2315,10 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,its_free_ite (kvm, ite);return PTR_ERR (irq); } - ite->irq = irq; + +/* Drop an ITE whose LPI another ITE maps, as MAPTI does. */ +if (!vgic_its_map_lpi (kvm, ite, irq, vcpu)) +its_free_ite (kvm, ite);return offset; }
include/kvm/arm_vgic.h +1 -0
@@ -138,6 +138,7 @@ struct vgic_irq {bool active;/* not used for LPIs */ bool enabled;bool hw;/* Tied to HW IRQ */ +bool mapped;/* LPIs: mapped by an ITE */ struct kref refcount;/* Used for LPIs */ u32 hwintid;/* HW INTID number */ unsigned int host_irq;/* linux irq corresponding to hwintid */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1661/2857 l2tp: snapshot sequencing state when building transmit headers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit d06ae66516e1aaf023808912af6292aef09d46c3 ]
Updates to send_seq from netlink, PPP setsockopt and receive-side negotiation race with packet transmission. The header length is updated separately, while transmit reads both fields repeatedly without synchronization.
For example, transmit can push a ten-byte L2TPv2 header, then a concurrent writer clears send_seq before the header builder reads it. The builder writes only six bytes, leaving four bytes of uninitialized skb headroom in the outgoing packet. The reverse mismatch overwrites the beginning of the payload. A later hdr_len read can also make the UDP length disagree with the skb length.
KCSAN reported:
BUG: KCSAN: data-race in l2tp_session_set_header_len / l2tp_xmit_skb
write to 0xffff888100d0944a of 2 bytes by task 116 on cpu 1:
l2tp_session_set_header_len+0x81/0xc0 l2tp_nl_cmd_session_modify+0x122/0x2c0 genl_family_rcv_msg_doit+0x170/0x1d0
read to 0xffff888100d0944a of 2 bytes by task 115 on cpu 0:
l2tp_xmit_skb+0x9c/0xc80 pppol2tp_sendmsg+0x21c/0x2a0 __sys_sendto+0x28c/0x2a0
The bug can lead to leak kernel base address for KASLR bypass, the corresponding reproducer can be provided per request.
Initialize hdr_len to the maximum header size and leave it unchanged when sequencing is toggled. Snapshot send_seq once per packet and use that snapshot for the actual header length and header construction, including the sequence flag. Use the same length for headroom, the header push and the UDP length. PPP callers can safely reserve the maximum size; L2TPv3 header sizes do not depend on sequencing.
Make send_seq a separate bool so READ_ONCE() and WRITE_ONCE() can be used without sharing a bitfield storage unit with other configuration flags. Preserve the netlink attribute's existing low-bit truncation.
--- net/l2tp/l2tp_core.c | 51 +++++++++++++++++++---------------------- net/l2tp/l2tp_core.h | 6 ++--- net/l2tp/l2tp_debugfs.c | 4 ++-- net/l2tp/l2tp_netlink.c | 11 ++++----- net/l2tp/l2tp_ppp.c | 8 +++---- 5 files changed, 35 insertions(+), 45 deletions(-)
net/l2tp/l2tp_core.c +24 -27
@@ -697,11 +697,9 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,* check if we sre sending sequence numbers and if not, * configure it so. */ -if (!session->lns_mode && !session->send_seq) { +if (!session->lns_mode && !READ_ONCE (session->send_seq)) {trace_session_seqnum_lns_enable (session); - session->send_seq =1 ; -l2tp_session_set_header_len (session, tunnel->version, - tunnel->encap); +WRITE_ONCE (session->send_seq, true); } }else {/* No sequence numbers.
@@ -719,12 +717,10 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,* If we're the LNS and we're sending sequence numbers, the * LAC is broken. Discard the frame. */ -if (!session->lns_mode && session->send_seq) { +if (!session->lns_mode &&READ_ONCE (session->send_seq)) {trace_session_seqnum_lns_disable (session); - session->send_seq =0 ; -l2tp_session_set_header_len (session, tunnel->version, - tunnel->encap); - }else if (session->send_seq) { +WRITE_ONCE (session->send_seq, false); + }else if (READ_ONCE (session->send_seq)) {pr_debug_ratelimited ("%s: recv data has no seq numbers when required. Discarding.\n" , session->name);atomic_long_inc (&session->stats.rx_seq_discards);
@@ -934,7 +930,8 @@ EXPORT_SYMBOL_GPL(l2tp_udp_encap_recv);/* Build an L2TP header for the session into the buffer provided. */ -static int l2tp_build_l2tpv2_header (struct l2tp_session *session,void *buf) +static int l2tp_build_l2tpv2_header (struct l2tp_session *session,void *buf, +bool send_seq) {struct l2tp_tunnel *tunnel = session->tunnel;__be16 *bufp = buf;
@@ -943,14 +940,14 @@ static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf)u32 tunnel_id = tunnel->peer_tunnel_id;u32 session_id = session->peer_session_id; -if (session->send_seq) +if (send_seq) flags |=L2TP_HDRFLAG_S ;/* Setup L2TP header. */ *bufp++ =htons (flags); *bufp++ =htons (tunnel_id); *bufp++ =htons (session_id); -if (session->send_seq) { +if (send_seq) { *bufp++ =htons (session->ns); *bufp++ =0 ; session->ns++;
@@ -961,7 +958,8 @@ static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf)return bufp - optr; } -static int l2tp_build_l2tpv3_header (struct l2tp_session *session,void *buf) +static int l2tp_build_l2tpv3_header (struct l2tp_session *session,void *buf, +bool send_seq) {struct l2tp_tunnel *tunnel = session->tunnel;char *bufp = buf;
@@ -987,7 +985,7 @@ static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf)if (session->l2specific_type ==L2TP_L2SPECTYPE_DEFAULT ) {u32 l2h =0 ; -if (session->send_seq) { +if (send_seq) { l2h =0x40000000 | session->ns; session->ns++; session->ns &=0xffffff ;
@@ -1021,19 +1019,24 @@ static int l2tp_xmit_queue(struct l2tp_tunnel *tunnel, struct sk_buff *skb, strustatic int l2tp_xmit_core (struct l2tp_session *session,struct sk_buff *skb,unsigned int *len) {struct l2tp_tunnel *tunnel = session->tunnel; +bool send_seq =READ_ONCE (session->send_seq);unsigned int data_len = skb->len;struct sock *sk = tunnel->sock; +u16 hdr_len = session->hdr_len;int headroom, uhlen, udp_len;int ret =NET_XMIT_SUCCESS ;struct inet_sock *inet;struct udphdr *uh; +if (tunnel->version ==L2TP_HDR_VER_2 && !send_seq) + hdr_len -=4 ; +/* Check that there's enough headroom in the skb to insert IP, * UDP and L2TP headers. If not enough, expand it to * make room. Adjust truesize. */ uhlen = (tunnel->encap ==L2TP_ENCAPTYPE_UDP ) ?sizeof (*uh) :0 ; - headroom =NET_SKB_PAD +sizeof (struct iphdr ) + uhlen + session->hdr_len; + headroom =NET_SKB_PAD +sizeof (struct iphdr ) + uhlen + hdr_len;if (skb_cow_head (skb, headroom)) {kfree_skb (skb);return NET_XMIT_DROP ;
@@ -1041,9 +1044,9 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns/* Setup L2TP header */ if (tunnel->version ==L2TP_HDR_VER_2 ) -l2tp_build_l2tpv2_header (session,__skb_push (skb, session->hdr_len)); +l2tp_build_l2tpv2_header (session,__skb_push (skb, hdr_len), send_seq);else -l2tp_build_l2tpv3_header (session,__skb_push (skb, session->hdr_len)); +l2tp_build_l2tpv3_header (session,__skb_push (skb, hdr_len), send_seq);/* Reset skb netfilter state */ memset (&(IPCB (skb)->opt),0 ,sizeof (IPCB (skb)->opt));
@@ -1086,7 +1089,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns uh =udp_hdr (skb); uh->source = inet->inet_sport; uh->dest = inet->inet_dport; - udp_len = uhlen + session->hdr_len + data_len; + udp_len = uhlen + hdr_len + data_len;if (udp_len >U16_MAX ) {kfree_skb (skb); ret =NET_XMIT_DROP ;
@@ -1580,16 +1583,11 @@ void l2tp_session_delete(struct l2tp_session *session) }EXPORT_SYMBOL_GPL (l2tp_session_delete); -/* We come here whenever a session's send_seq, cookie_len or -* l2specific_type parameters are set. -*/ -void l2tp_session_set_header_len (struct l2tp_session *session,int version, -enum l2tp_encap_type encap) +static void l2tp_session_set_header_len (struct l2tp_session *session,int version, +enum l2tp_encap_type encap) {if (version ==L2TP_HDR_VER_2 ) { - session->hdr_len =6 ; -if (session->send_seq) - session->hdr_len +=4 ; + session->hdr_len =10 ; }else { session->hdr_len =4 + session->cookie_len; session->hdr_len +=l2tp_get_l2specific_len (session);
@@ -1597,7 +1595,6 @@ void l2tp_session_set_header_len(struct l2tp_session *session, int version, session->hdr_len +=4 ; } } -EXPORT_SYMBOL_GPL (l2tp_session_set_header_len);struct l2tp_session *l2tp_session_create (int priv_size,struct l2tp_tunnel *tunnel,u32 session_id,u32 peer_session_id,struct l2tp_session_cfg *cfg)
net/l2tp/l2tp_core.h +2 -4
@@ -79,7 +79,7 @@ struct l2tp_session {u8 peer_cookie[8 ];int peer_cookie_len;u16 l2specific_type; -u16 hdr_len; +u16 hdr_len;/* maximum L2TP header length */ u32 nr;/* session NR state (receive) */ u32 ns;/* session NR state (send) */ struct sk_buff_head reorder_q;/* receive reorder queue */
@@ -93,8 +93,8 @@ struct l2tp_session {char name[L2TP_SESSION_NAME_MAX ];/* for logging */ char ifname[IFNAMSIZ ]; +bool send_seq;/* send packets with sequence numbers? */ unsigned int recv_seq:1; /* expect receive packets with sequence numbers? */ - unsigned int send_seq:1; /* send packets with sequence numbers? */ unsigned int lns_mode:1; /* behave as LNS?* LAC enables sequence numbers under LNS control. */
@@ -261,8 +261,6 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,int l2tp_udp_encap_recv (struct sock *sk,struct sk_buff *skb);/* Transmit path helpers for sending packets over the tunnel socket. */ -void l2tp_session_set_header_len (struct l2tp_session *session,int version, -enum l2tp_encap_type encap);int l2tp_xmit_skb (struct l2tp_session *session,struct sk_buff *skb);/* Pseudowire management.
net/l2tp/l2tp_debugfs.c +2 -2
@@ -183,12 +183,12 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v) session->pwtype ==L2TP_PWTYPE_ETH ?"ETH" : session->pwtype ==L2TP_PWTYPE_PPP ?"PPP" : ""); -if (session->send_seq || session->recv_seq) +if (READ_ONCE (session->send_seq) || session->recv_seq)seq_printf (m," nr %u, ns %u\n" , session->nr, session->ns);seq_printf (m," refcnt %d\n" ,refcount_read (&session->ref_count));seq_printf (m," config 0/0/%c/%c/-/%s %08x %u\n" , session->recv_seq ?'R' :'-' , - session->send_seq ?'S' :'-' , +READ_ONCE (session->send_seq) ?'S' :'-' , session->lns_mode ?"LNS" :"LAC" ,0 ,jiffies_to_msecs (session->reorder_timeout));
net/l2tp/l2tp_netlink.c +4 -7
@@ -689,12 +689,9 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *infif (info->attrs[L2TP_ATTR_RECV_SEQ ]) session->recv_seq =nla_get_u8 (info->attrs[L2TP_ATTR_RECV_SEQ ]); -if (info->attrs[L2TP_ATTR_SEND_SEQ ]) { -struct l2tp_tunnel *tunnel = session->tunnel; - - session->send_seq =nla_get_u8 (info->attrs[L2TP_ATTR_SEND_SEQ ]); -l2tp_session_set_header_len (session, tunnel->version, tunnel->encap); - } +if (info->attrs[L2TP_ATTR_SEND_SEQ ]) +WRITE_ONCE (session->send_seq, +nla_get_u8 (info->attrs[L2TP_ATTR_SEND_SEQ ]) &1 );if (info->attrs[L2TP_ATTR_LNS_MODE ]) session->lns_mode =nla_get_u8 (info->attrs[L2TP_ATTR_LNS_MODE ]);
@@ -737,7 +734,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl (session->peer_cookie_len &&nla_put (skb,L2TP_ATTR_PEER_COOKIE , session->peer_cookie_len, session->peer_cookie)) ||nla_put_u8 (skb,L2TP_ATTR_RECV_SEQ , session->recv_seq) || -nla_put_u8 (skb,L2TP_ATTR_SEND_SEQ , session->send_seq) || +nla_put_u8 (skb,L2TP_ATTR_SEND_SEQ ,READ_ONCE (session->send_seq)) ||nla_put_u8 (skb,L2TP_ATTR_LNS_MODE , session->lns_mode) || (l2tp_tunnel_uses_xfrm (tunnel) && nla_put_u8(skb, L2TP_ATTR_USING_IPSEC, 1)) ||
net/l2tp/l2tp_ppp.c +3 -5
@@ -1205,15 +1205,13 @@ static int pppol2tp_session_setsockopt(struct sock *sk, err = -EINVAL ;break ; } - session->send_seq = !!val; +WRITE_ONCE (session->send_seq, !!val); {struct pppox_sock *po =pppox_sk (sk); po->chan.hdrlen = val ?PPPOL2TP_L2TP_HDR_SIZE_SEQ :PPPOL2TP_L2TP_HDR_SIZE_NOSEQ ; } -l2tp_session_set_header_len (session, session->tunnel->version, - session->tunnel->encap);break ;case PPPOL2TP_SO_LNSMODE :
@@ -1323,7 +1321,7 @@ static int pppol2tp_session_getsockopt(struct sock *sk,break ;case PPPOL2TP_SO_SENDSEQ : - *val = session->send_seq; + *val =READ_ONCE (session->send_seq);break ;case PPPOL2TP_SO_LNSMODE :
@@ -1569,7 +1567,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v) state, user_data_ok);seq_printf (m," 0/0/%c/%c/%s %08x %u\n" , session->recv_seq ?'R' :'-' , - session->send_seq ?'S' :'-' , +READ_ONCE (session->send_seq) ?'S' :'-' , session->lns_mode ?"LNS" :"LAC" ,0 ,jiffies_to_msecs (session->reorder_timeout));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1662/2857 mm/khugepaged: flush deferred unmaps before dropping a failed folio
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 854e5ff8b3ce2a776586cabebaeae645c992345b ]
collapse_file() can fail its reference-count or dirty-folio check after unmapping with TTU_BATCH_FLUSH. Both paths put back the isolated folio, then unlock it and drop the lookup reference before reaching the common try_to_unmap_flush().
The page-cache reference does not keep the folio stable once the lock is released. Another collapse can replace and free it. With its PTEs already gone, that collapse cannot flush the first task's per-task TLB batch, and retract_page_tables() skips short or unaligned VMAs. A CPU can therefore retain a user translation to the freed folio. This has been reproduced with unprivileged MADV_COLLAPSE on a memfd.
Flush at out_unlock while the lookup reference and folio lock are still held. The common flush continues to cover the accumulated pagelist on both success and rollback, preserving batching on successful collapses.
--- mm/khugepaged.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
mm/khugepaged.c +7 -3
@@ -2011,6 +2011,11 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,WARN_ON_ONCE (xas_error (&xas));continue ; out_unlock: +/* +* The page may have been unmapped with TTU_BATCH_FLUSH. +* Flush before releasing the lock and our last reference. +*/ +try_to_unmap_flush ();unlock_page (page);put_page (page); goto xa_unlocked;
@@ -2056,9 +2061,8 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, xa_unlocked:/* -* If collapse is successful, flush must be done now before copying. -* If collapse is unsuccessful, does flush actually need to be done? -* Do it anyway, to clear the state. +* Flush before copying the pages, or releasing them in rollback. +* This is a no-op if out_unlock already flushed the batch. */ try_to_unmap_flush ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1663/2857 mm/hugetlb: fix mremap deadlock when PMD sharing is possible
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Zhe <[email protected]>
[ Upstream commit 92daa8652f88c8cfc05f4899a8408a04b02f211e ]
move_hugetlb_page_tables() holds the mapping's i_mmap_rwsem for write while moving hugetlb PTEs. This prevents races with truncation and protects huge_pmd_unshare(), but the move loop must not call helpers that can acquire the same rwsem for read.
huge_pte_alloc() can do that when the destination can use PMD
sharing: it may call huge_pmd_share(), which takes i_mmap_rwsem for read while searching for a shareable PMD table. Calling it while the move path already holds i_mmap_rwsem for write can deadlock.
Avoid that path for PMD-sized hugetlb mappings that can use PMD sharing. Instead of allocating or sharing the destination page table while moving, zap the source range and let the destination fault path populate or share the PMD lazily.
Reuse the hugetlb unmap logic for the source-side zap by splitting the core loop out of __unmap_hugepage_range(). The wrapper keeps the existing tlb_start_vma(), tlb_end_vma() and huge_pmd_unshare_flush() behavior, while move_hugetlb_page_tables() can reuse the unmap loop with its existing mmu_gather.
--- mm/hugetlb.c | 66 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 18 deletions(-)
mm/hugetlb.c +48 -18
@@ -99,6 +99,10 @@ static int __huge_pmd_unshare(struct mmu_gather *tlb, bool check_locks);static void hugetlb_unshare_pmds (struct vm_area_struct *vma,unsigned long start,unsigned long end,bool take_locks); +static void hugetlb_unmap_range (struct mmu_gather *tlb, +struct vm_area_struct *vma,unsigned long start, +unsigned long end,struct page *ref_page, +zap_flags_t zap_flags);static struct resv_map *vma_resv_map (struct vm_area_struct *vma);static inline bool subpool_is_free (struct hugepage_subpool *spool)
@@ -5292,6 +5296,8 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += sz, new_addr += sz) {const unsigned long offset_to_last_entry = (old_addr | last_addr_mask) - old_addr; +const unsigned long offset_to_last_dst_entry = + (new_addr | last_addr_mask) - new_addr; src_pte =huge_pte_offset (mm, old_addr, sz);if (!src_pte) {
@@ -5308,6 +5314,24 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,continue ; } +/* +* Avoid entering the destination PMD sharing path while holding +* i_mmap_rwsem for write. Leave destination page table +* population to the fault path, which can share the PMD lazily. +*/ +if (sz ==PMD_SIZE &&want_pmd_share (new_vma, new_addr)) { +const unsigned long unmap_size = +min (old_end - old_addr, + offset_to_last_dst_entry + sz); + +hugetlb_unmap_range (&tlb, vma, old_addr, + old_addr + unmap_size,NULL , +ZAP_FLAG_DROP_MARKER ); + old_addr += unmap_size - sz; + new_addr += unmap_size - sz; +continue ; + } + dst_pte =huge_pte_alloc (mm, new_vma, new_addr, sz);if (!dst_pte)break ;
@@ -5327,9 +5351,10 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,return len + old_addr - old_end; } -static void __unmap_hugepage_range (struct mmu_gather *tlb,struct vm_area_struct *vma, -unsigned long start,unsigned long end, -struct page *ref_page,zap_flags_t zap_flags) +static void hugetlb_unmap_range (struct mmu_gather *tlb, +struct vm_area_struct *vma,unsigned long start, +unsigned long end,struct page *ref_page, +zap_flags_t zap_flags) {struct mm_struct *mm = vma->vm_mm;unsigned long address;
@@ -5339,27 +5364,12 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_structstruct page *page;struct hstate *h =hstate_vma (vma);unsigned long sz =huge_page_size (h); -struct mmu_notifier_range range;unsigned long last_addr_mask;WARN_ON (!is_vm_hugetlb_page (vma));BUG_ON (start & ~huge_page_mask (h));BUG_ON (end & ~huge_page_mask (h)); -/* -* This is a hugetlb vma, all the pte entries should point -* to huge page. -*/ -tlb_change_page_size (tlb, sz); -tlb_start_vma (tlb, vma); - -/* -* If sharing possible, alert mmu notifiers of worst case. -*/ -mmu_notifier_range_init (&range,MMU_NOTIFY_UNMAP ,0 , vma, mm, start, - end); -adjust_range_if_pmd_sharing_possible (vma, &range.start, &range.end); -mmu_notifier_invalidate_range_start (&range); last_addr_mask =hugetlb_mask_last_page (h); address = start;for (; address < end; address += sz) {
@@ -5446,6 +5456,26 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_structif (ref_page)break ; } +} + +static void __unmap_hugepage_range (struct mmu_gather *tlb,struct vm_area_struct *vma, +unsigned long start,unsigned long end, +struct page *ref_page,zap_flags_t zap_flags) +{ +struct mm_struct *mm = vma->vm_mm; +struct mmu_notifier_range range; + +tlb_change_page_size (tlb,huge_page_size (hstate_vma (vma))); +tlb_start_vma (tlb, vma); + +/* +* If sharing possible, alert mmu notifiers of worst case. +*/ +mmu_notifier_range_init (&range,MMU_NOTIFY_UNMAP ,0 , vma, mm, start, + end); +adjust_range_if_pmd_sharing_possible (vma, &range.start, &range.end); +mmu_notifier_invalidate_range_start (&range); +hugetlb_unmap_range (tlb, vma, start, end, ref_page, zap_flags);mmu_notifier_invalidate_range_end (&range);tlb_end_vma (tlb, vma);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1664/2857 mm/huge_memory: fix truncate racing with PMD zapping
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit e6a07d29b0a60f3a4cfe77fe34eeb4b3fb38d6c4 ]
zap_huge_pmd_folio() removes the rmap before calling folio_mark_dirty(). If this was the last mapping, truncation can skip unmapping the folio and proceed without waiting for the PMD lock, racing with dirtying.
ifs_set_range_dirty() can oops if MADV_DONTNEED races with ftruncate() on XFS, when we get the folio set dirty after it was found to not be mapped anymore.
Move folio_mark_dirty() and folio_mark_accessed() before rmap removal, matching the PTE zap path. This keeps the folio mapped while updating its state, so truncation must wait for the page table lock.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/huge_memory.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/huge_memory.c +6 -2
@@ -1681,8 +1681,6 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,if (pmd_present (orig_pmd)) { page =pmd_page (orig_pmd); -page_remove_rmap (page, vma, true); -VM_BUG_ON_PAGE (page_mapcount (page) <0 , page);VM_BUG_ON_PAGE (!PageHead (page), page); }else if (thp_migration_supported ()) {swp_entry_t entry;
@@ -1706,6 +1704,12 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,folio_mark_dirty (page_folio (page)); } +/* Remove the rmap after transferring the dirty bit to the folio. */ +if (pmd_present (orig_pmd)) { +page_remove_rmap (page, vma, true); +VM_BUG_ON_PAGE (page_mapcount (page) <0 , page); + } +spin_unlock (ptl);if (flush_needed)tlb_remove_page_size (tlb, page,HPAGE_PMD_SIZE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1665/2857 udf: fix preallocation discarding before an empty allocation extent
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit 0c52750caaaccee8b0e929450fe6538ec4985722 ]
udf_discard_prealloc() finds the last extent of a file by peeking at the next one with udf_next_aext() and stopping when that returns 0. The peek reads into eloc and elen, and the code then uses them as the last extent. But when udf_next_aext() returns 0 they hold no defined
value: if the extent list ends in a continuation descriptor that leads to an empty allocation extent, they describe that continuation, i.e. the block of the empty allocation extent, one block long.
The kernel creates such lists itself: when udf_delete_aext() removes the only descriptor of the last allocation extent in a list, it leaves that allocation extent empty and the continuation to it in place.
If the last extent is a preallocation, udf_discard_prealloc() deletes it with udf_delete_aext(), which finds the following allocation extent empty, so it also removes the continuation and frees that allocation extent's block. udf_discard_prealloc() then frees eloc and elen: that block a second time, instead of the preallocated blocks. On a space bitmap the preallocated blocks leak and the free block count drifts. On an unallocated space table the second free adds a second free extent for the same block, which is later handed out twice: fsx as run by generic/091 and generic/263 ends up with two parts of its test file in one block and reads back bad data.
Peek into separate variables, so that eloc and elen keep the last extent that udf_next_aext() returned with 1.
--- fs/udf/truncate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/udf/truncate.c +4 -3
@@ -122,8 +122,8 @@ void udf_discard_prealloc(struct inode *inode) {struct extent_position epos = {};struct extent_position prev_epos = {}; -struct kernel_lb_addr eloc; -uint32_t elen; +struct kernel_lb_addr eloc, tmpeloc; +uint32_t elen, tmpelen;uint64_t lbcount =0 ;int8_t etype =-1 , netype;struct udf_inode_info *iinfo =UDF_I (inode);
@@ -136,7 +136,8 @@ void udf_discard_prealloc(struct inode *inode) epos.block = iinfo->i_location;/* Find the last extent in the file */ -while ((netype =udf_next_aext (inode, &epos, &eloc, &elen,0 )) !=-1 ) { +while ((netype =udf_next_aext (inode, &epos, &tmpeloc, &tmpelen, +0 )) !=-1 ) {brelse (prev_epos.bh); prev_epos = epos;if (prev_epos.bh)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1666/2857 fbdev: kyro: Use devm_ioremap() for mmio registers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giovanni Di Santi <[email protected]>
[ Upstream commit e0bf12a43243e6afc5a03fc55c58ec48aba48088 ]
Replace the manual ioremap() call for the MMIO registers with the device-managed devm_ioremap() variant.
This simplifies the driver's resource management by ensuring the memory is automatically unmapped when the driver detaches from the device.
Stable-dep-of: d3bc005a6294 ("fbdev: kyro: Release WC setup on registration failure")
--- drivers/video/fbdev/kyro/fbdev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/video/fbdev/kyro/fbdev.c +3 -5
@@ -720,13 +720,14 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) kyro_fix.mmio_len =pci_resource_len (pdev,1 ); currentpar->regbase = deviceInfo.pSTGReg = -ioremap (kyro_fix.mmio_start, kyro_fix.mmio_len); +devm_ioremap (&pdev->dev, kyro_fix.mmio_start, + kyro_fix.mmio_len);if (!currentpar->regbase) goto out_free_fb; info->screen_base =pci_ioremap_wc_bar (pdev,0 );if (!info->screen_base) - goto out_unmap_regs; + goto out_free_fb;if (!nomtrr) currentpar->wc_cookie = arch_phys_wc_add(kyro_fix.smem_start,
@@ -775,8 +776,6 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) out_unmap:iounmap (info->screen_base); -out_unmap_regs: -iounmap (currentpar->regbase); out_free_fb:framebuffer_release (info);
@@ -799,7 +798,6 @@ static void kyrofb_remove(struct pci_dev *pdev) deviceInfo.ulOverlayOffset =0 ;iounmap (info->screen_base); -iounmap (par->regbase);arch_phys_wc_del (par->wc_cookie);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1667/2857 fbdev: kyro: Use devm_ioremap_wc() for screen mem
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giovanni Di Santi <[email protected]>
[ Upstream commit 32dfb6112ea3ca143636832cd34234f2be4830bb ]
Replace the manual pci_ioremap_wc() call for mapping screen memory with the device-managed devm_ioremap_wc() variant.
This simplifies the driver's resource management by ensuring the memory is automatically unmapped when the driver detaches from the device.
Stable-dep-of: d3bc005a6294 ("fbdev: kyro: Release WC setup on registration failure")
--- drivers/video/fbdev/kyro/fbdev.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/video/fbdev/kyro/fbdev.c +3 -6
@@ -725,7 +725,8 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (!currentpar->regbase) goto out_free_fb; - info->screen_base =pci_ioremap_wc_bar (pdev,0 ); + info->screen_base =devm_ioremap_wc (&pdev->dev, kyro_fix.smem_start, + kyro_fix.smem_len);if (!info->screen_base) goto out_free_fb;
@@ -763,7 +764,7 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)fb_memset (info->screen_base,0 , size);if (register_framebuffer (info) <0 ) - goto out_unmap; + goto out_free_fb; fb_info(info, "%s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n", info->fix.id,
@@ -774,8 +775,6 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; -out_unmap: -iounmap (info->screen_base); out_free_fb:framebuffer_release (info);
@@ -797,8 +796,6 @@ static void kyrofb_remove(struct pci_dev *pdev) deviceInfo.ulNextFreeVidMem =0 ; deviceInfo.ulOverlayOffset =0 ; -iounmap (info->screen_base); -arch_phys_wc_del (par->wc_cookie);unregister_framebuffer (info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1668/2857 fbdev: kyro: Release WC setup on registration failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit d3bc005a62945aec57059201092b12b7c955e5a7 ]
If register_framebuffer() fails, kyrofb_probe() frees the framebuffer without releasing its write-combining range. Release the range before freeing the framebuffer. Earlier failures still skip this cleanup.
The missing cleanup already exists in the initial Git import, before the conversion from mtrr_add() to arch_phys_wc_add().
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/video/fbdev/kyro/fbdev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/video/fbdev/kyro/fbdev.c +3 -1
@@ -764,7 +764,7 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)fb_memset (info->screen_base,0 , size);if (register_framebuffer (info) <0 ) - goto out_free_fb; + goto out_free_wc; fb_info(info, "%s frame buffer device, at %dx%d@%d using %ldk/%ldk of VRAM\n", info->fix.id,
@@ -775,6 +775,8 @@ static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; +out_free_wc: +arch_phys_wc_del (currentpar->wc_cookie); out_free_fb:framebuffer_release (info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1669/2857 hwmon: (coretemp) Fix 32-bit jiffies wraparound in show_temp()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 9a6aa085c94c7f2817c4d50a7264e6fb51286f40 ]
show_temp() rate-limits MSR reads by storing tdata->last_updated as an unsigned long and comparing it against jiffies using time_after(jiffies, tdata->last_updated + HZ).
time_after() relies on signed long subtraction, which only produces the expected result while the two timestamps are within LONG_MAX jiffies of each other. On 32-bit kernels, if tempX_input is not read for more than LONG_MAX jiffies (~24.85 days at HZ=1000), the signed difference flips sign and time_after() evaluates to false. Because tdata->last_updated is only refreshed when time_after() succeeds, subsequent reads remain blocked from refreshing for another ~24.85 days until jiffies wraps past tdata->last_updated + HZ again, returning either a stale cached temperature or -ENODATA if the sensor had never been read since initialization.
Store tdata->last_updated as a u64 and use get_jiffies_64() with time_after64(), which does not wrap in any practical uptime.
--- drivers/hwmon/coretemp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/hwmon/coretemp.c +4 -3
@@ -70,7 +70,7 @@ struct temp_data {int temp;int ttarget;int tjmax; -unsigned long last_updated; +u64 last_updated;unsigned int cpu;u32 cpu_core_id;u32 status_reg;
@@ -157,7 +157,8 @@ static ssize_t show_temp(struct device *dev,mutex_lock (&tdata->update_lock);/* Check whether the time interval has elapsed */ -if (!tdata->valid ||time_after (jiffies, tdata->last_updated +HZ )) { +if (!tdata->valid || +time_after64 (get_jiffies_64 (), tdata->last_updated +HZ )) {rdmsr_on_cpu (tdata->cpu, tdata->status_reg, &eax, &edx);/* * Ignore the valid bit. In all observed cases the register
@@ -167,7 +168,7 @@ static ssize_t show_temp(struct device *dev,*/ tdata->temp = tdata->tjmax - ((eax >>16 ) &0x7f ) *1000 ; tdata->valid = true; - tdata->last_updated = jiffies; + tdata->last_updated =get_jiffies_64 (); }mutex_unlock (&tdata->update_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1670/2857 hwmon: (tmp108) Fix initial conversion delay and wait until ready
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 7cd60538073e465310c94b2a2f0ea8d2f03768ef ]
In tmp108_common_probe(), the driver only adds the 30 ms conversion delay (TMP108_CONVERSION_TIME_MS) to ready_time if the sensor was previously in TMP108_MODE_SHUTDOWN. However, the TMP108 hardware defaults to continuous conversion mode (TMP108_MODE_CONTINUOUS) upon power-on reset, including immediately after enabling the vcc supply regulator during probe, while the temperature register retains its power-on reset value of 0x0000 (0°C) until the first conversion completes. Because the initial mode is not shutdown, the delay is bypassed and early reads via thermal zone registration or sysfs before the first conversion finishes return an uninitialized 0°C reading.
In addition, returning -EAGAIN from tmp108_read() while waiting for a conversion to complete after probe or resume can trigger an unnecessary tight retry loop in callers or fail initial reads.
Unconditionally set ready_time to TMP108_CONVERSION_TIME_MS ahead in tmp108_common_probe(), track ready_time as ktime_t, and wait for the remaining conversion time in tmp108_read() using usleep_range() instead of returning -EAGAIN.
--- drivers/hwmon/tmp108.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
drivers/hwmon/tmp108.c +11 -15
@@ -14,7 +14,7 @@#include <linux/of.h> #include <linux/i2c.h> #include <linux/init.h> -#include <linux/jiffies.h> +#include <linux/ktime.h> #include <linux/regmap.h> #include <linux/slab.h>
@@ -73,7 +73,7 @@struct tmp108 {struct regmap *regmap;u16 orig_config; -u64 ready_time; +ktime_t ready_time; };/* convert 12-bit TMP108 register value to milliCelsius */
@@ -94,6 +94,7 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,struct tmp108 *tmp108 =dev_get_drvdata (dev);unsigned int regval;int err, hyst; +s64 delay;if (type == hwmon_chip) {if (attr == hwmon_chip_update_interval) {
@@ -123,12 +124,10 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input: -/* Is it too early to return a conversion ? */ -if (time_before64 (get_jiffies_64 (), tmp108->ready_time)) { -dev_dbg (dev,"%s: Conversion not ready yet..\n" , - __func__); -return -EAGAIN ; - } +/* Wait if it is too early to return a conversion */ + delay =ktime_us_delta (tmp108->ready_time,ktime_get ()); +if (delay >0 ) +usleep_range (delay, delay +1000 ); err =regmap_read (tmp108->regmap,TMP108_REG_TEMP , ®val);if (err <0 )return err;
@@ -371,11 +370,8 @@ static int tmp108_probe(struct i2c_client *client)return err; } - tmp108->ready_time =get_jiffies_64 (); -if ((tmp108->orig_config &TMP108_CONF_MODE_MASK ) == -TMP108_MODE_SHUTDOWN ) - tmp108->ready_time += -msecs_to_jiffies (TMP108_CONVERSION_TIME_MS ); + tmp108->ready_time =ktime_add_ms (ktime_get (), +TMP108_CONVERSION_TIME_MS ); err =devm_add_action_or_reset (dev, tmp108_restore_config, tmp108);if (err) {
@@ -405,8 +401,8 @@ static int tmp108_resume(struct device *dev) err =regmap_update_bits (tmp108->regmap,TMP108_REG_CONF ,TMP108_CONF_MODE_MASK ,TMP108_MODE_CONTINUOUS ); - tmp108->ready_time =get_jiffies_64 () + -msecs_to_jiffies (TMP108_CONVERSION_TIME_MS ); + tmp108->ready_time =ktime_add_ms (ktime_get (), +TMP108_CONVERSION_TIME_MS );return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1671/2857 drm/amdgpu: dont walk the CS chunks when allocating them failed
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit ade92d50aad6799a5a9d7e73cd1604fd0576e656 ]
amdgpu_cs_pass1() sets p->nchunks before allocating p->chunks, and the allocation failure path skips resetting it. amdgpu_cs_parser_fini() then frees the kdata of nchunks chunks from a NULL array. On navi48 with the chunk array allocation failed through failslab:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:amdgpu_cs_parser_fini+0x35d/0x710 [amdgpu] amdgpu_cs_ioctl+0xcae/0x7a20 [amdgpu] drm_ioctl_kernel+0x180/0x320 [drm]
Set nchunks once the array exists.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -2
@@ -208,13 +208,14 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,if (IS_ERR (chunk_array))return PTR_ERR (chunk_array); - p->nchunks = cs->in.num_chunks; - p->chunks =kvmalloc_array (p->nchunks,sizeof (struct amdgpu_cs_chunk ), +/* parser_fini() walks nchunks chunks, set it once they exist */ + p->chunks =kvmalloc_array (cs->in.num_chunks,sizeof (struct amdgpu_cs_chunk ),GFP_KERNEL );if (!p->chunks) { ret = -ENOMEM ; goto free_chunk; } + p->nchunks = cs->in.num_chunks;for (i =0 ; i < p->nchunks; i++) {struct drm_amdgpu_cs_chunk __user *chunk_ptr =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1672/2857 nvme: unregister when pr_register() is given a zero new key
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit a9d431124fb2e58215daf0299d6fcf47bbc2d6b1 ]
The block layer PR API defines a zero new_key in pr_register() as unregistering old_key. nvme_pr_register() sends Replace Reservation Key with a zero NRKEY instead. The host stays registered with key 0, and its next registration with another key fails with Reservation Conflict.
The pNFS SCSI layout client unregisters this way at umount. A later mount cannot register and sends all I/O through the metadata server.
Send Unregister Reservation Key when new_key is zero.
--- drivers/nvme/host/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +6 -1
@@ -2236,7 +2236,12 @@ static int nvme_pr_register(struct block_device *bdev, u64 old,if (flags & ~PR_FL_IGNORE_KEY )return -EOPNOTSUPP ; - cdw10 = old ?2 :0 ; +if (!new) + cdw10 =1 ; +else if (old) + cdw10 =2 ; +else + cdw10 =0 ; cdw10 |= (flags &PR_FL_IGNORE_KEY ) ?1 <<3 :0 ; cdw10 |= (1 <<30 ) | (1 <<31 );/* PTPL=1 */ return nvme_pr_command (bdev, cdw10, old, new, nvme_cmd_resv_register);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1673/2857 mm/vma: dont leak the charge for stack growth
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit b1ee87802111156e27557e82acc31fa7dfc76e2a ]
acct_stack_growth() charges stack expansion even without VM_ACCOUNT. This can happen for read-only or MAP_NORESERVE mappings created with MAP_GROWSDOWN. Unmapping these VMAs does not release the charge, leaking Committed_AS.
Only check and charge growth for VM_ACCOUNT VMAs, matching mremap(). Unaccounted growth skips the overcommit check while remaining subject to the other stack-growth limits.
--- mm/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/mmap.c +2 -1
@@ -1974,7 +1974,8 @@ static int acct_stack_growth(struct vm_area_struct *vma,* Overcommit.. This must be the final test, as it will * update security statistics. */ -if (security_vm_enough_memory_mm (mm, grow)) +if ((vma->vm_flags &VM_ACCOUNT ) && +security_vm_enough_memory_mm (mm, grow))return -ENOMEM ;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1674/2857 drm/i915/psr: Clear selective fetch area when duplicating plane state
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jouni Högander <[email protected]>
[ Upstream commit cbe565475988d3b22dc36f13c14d9f0eec1685cd ]
We are currently not clearing selective fetch area when duplicating plane state. This is causing problem when plane is re-used for another purpose. Fix this by clearing selective fetch area when duplicating plane state.
Now as the state is cleared we need to ensure we have consistent selective fetch area in plane state on full update. Earlier this was relying on selective fetch area being copied from old state on state duplicate. Now this isn't true anymore as we are clearing it. Tackle this by setting full plane area as selective fetch area for each plane on full update. Rename the label as skip_su_area_calc as the loop setting the plane selective fetch area is not skipped anymore.
Move also psr2_sel_fetch_pipe_state_supported check after psr2_su_area initialization. The loop is run on full update as well now and it needs initialized psr2_su_area. Clip_area_update is only touching rect height and x1/x2 are left untouched.
Don't set the area at all for planes not intersecting with the selective update area. It is already zero sized after plane state duplicate.
--- drivers/gpu/drm/i915/display/intel_atomic_plane.c | 1 + drivers/gpu/drm/i915/display/intel_psr.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/display/intel_atomic_plane.c +1 -0
@@ -109,6 +109,7 @@ intel_plane_duplicate_state(struct drm_plane *plane) intel_state->ggtt_vma =NULL ; intel_state->dpt_vma =NULL ; intel_state->flags =0 ; + intel_state->psr2_sel_fetch_area =DRM_RECT_INIT (0 ,0 ,0 ,0 );/* add reference to fb */ if (intel_state->hw.fb)
drivers/gpu/drm/i915/display/intel_psr.c +6 -3
@@ -1807,7 +1807,7 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,if (!psr2_sel_fetch_pipe_state_supported (crtc_state)) { full_update = true; - goto skip_sel_fetch_set_loop; + goto skip_su_area_calc; }/*
@@ -1893,7 +1893,7 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state, }if (full_update) - goto skip_sel_fetch_set_loop; + goto skip_su_area_calc; ret =drm_atomic_add_affected_planes (&state->base, &crtc->base);if (ret)
@@ -1901,6 +1901,10 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,intel_psr2_sel_fetch_pipe_alignment (crtc_state, &pipe_clip); +skip_su_area_calc: +if (full_update) +clip_area_update (&pipe_clip, &display_area, &display_area); +/* * Now that we have the pipe damaged area check if it intersect with * every plane, if it does set the plane selective fetch area.
@@ -1947,7 +1951,6 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state, } } -skip_sel_fetch_set_loop:psr2_man_trk_ctl_calc (crtc_state, &pipe_clip, full_update);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1675/2857 mm/madvise: preserve VMA_SOFTDIRTY_BIT when changing anonymous names
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 652f15be3c11415725694ccea317c51e35c0b582 ]
When changing the anonymous VMA name, madvise_update_vma() calls vma_modify_name() to possibly merge with adjacent VMAs. We don't call vma_modify_flags() and consequently don't obtain the new VMA flags.
Later in the function we update the VMA flags to the stale new_vma_flags we obtained before. This can result in us losing the VMA_SOFTDIRTY_BIT flag set on a VMA we just merged with.
There is no need to update the VMA flags at all, so just exit early. This skips calling khugepaged_enter_vma(), but since the flags didn't change this is fine.
--- mm/madvise.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/madvise.c +4 -0
@@ -143,6 +143,7 @@ static int madvise_update_vma(struct vm_area_struct *vma, struct anon_vma_name *anon_name) {struct mm_struct *mm = vma->vm_mm; +bool set_new_anon_name = new_flags == vma->vm_flags;int error;pgoff_t pgoff;
@@ -179,6 +180,9 @@ static int madvise_update_vma(struct vm_area_struct *vma, } success: +if (set_new_anon_name) +return replace_anon_vma_name (vma, anon_name); +/* * vm_flags is protected by the mmap_lock held in write mode. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1676/2857 mm/mempolicy: apply bind policies against the scoped allocation zone
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price (Meta) <[email protected]>
[ Upstream commit d4ea410ce4b8aa46a316476ea2624a357bf31fa9 ]
QEMU fails to start a guest with a VFIO device when guest RAM comes from a memory backend bound to a movable-only node:
vfio_container_dma_map(0x55b1b1317800, 0x0, 0x10000000,
0x7f39a2200000)
= -12 (Cannot allocate memory)
VFIO pins guest RAM when the device is realized, and the pin faults the pages in. io_uring fixed buffers fail the same way. Faulting the range in before pinning lets the same pin succeed, since resident pages are migrated off the node instead.
A long-term pin faults under memalloc_pin_save(). PF_MEMALLOC_PIN makes current_gfp_context() clear __GFP_MOVABLE, but policy_nodemask() tests apply_policy_zone() against the caller's gfp.
The bind keeps its movable-only nodemask, and the allocation finds no usable zone:
page allocation failure:
order:0,
mode:0x140dc2(GFP_HIGHUSER|__GFP_ZERO|__GFP_COMP),
nodemask=1,cpuset=/,mems_allowed=0-1Call Trace: warn_alloc+0x136/0x150 __alloc_frozen_pages_noprof+0xed8/0x1720 alloc_pages_mpol+0xaa/0x170 vma_alloc_folio_noprof+0x65/0xd0 __handle_mm_fault+0x137b/0x1ac0 handle_mm_fault+0xa0/0x270 __get_user_pages+0x250/0xfd0 __gup_longterm_locked+0x116/0x870 gup_fast_fallback+0xcfc/0xdf0 pin_user_pages_fast+0x47/0x60 io_pin_pages+0x9a/0x110
Base page faults fail with -ENOMEM.
hugetlb faults fail with -EFAULT.
Check the policy zone against current_gfp_context(gfp), so a pin-scoped fault falls back off the movable-only nodemask, like any other non-movable allocation under the same bind.
Tested in qemu with a dax/kmem movable-only node 1. io_uring and VFIO pins of unfaulted base pages and 2MB hugetlb pages now succeed and land on node 0 (correct). QEMU now starts with the same backend binding.
--- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mempolicy.c +1 -1
@@ -1838,7 +1838,7 @@ nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy)/* Lower zones don't get a nodemask applied for MPOL_BIND */ if (unlikely (mode ==MPOL_BIND ) && -apply_policy_zone (policy,gfp_zone (gfp)) && +apply_policy_zone (policy,gfp_zone (current_gfp_context (gfp))) &&cpuset_nodemask_valid_mems_allowed (&policy->nodes))return &policy->nodes;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1677/2857 mm/memory: reject remote COW faults on PFN mappings
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 8db6921cc07b74197a3866d62ed262b68aeadcf3 ]
When handling a COW fault without a normal source page (PFN mappings), __wp_page_copy_user() copies from the faulting user address. For remote faults, this accesses the wrong address space, resulting in wrong data getting copied.
For example, user_events updates an enable bit in the registering process's memory. If that memory needs to be faulted in, user_event_enabler_fault_fixup() calls fixup_user_fault() from a work item. Placing the enable bit in a private PFN mapping can trigger this remote COW path.
Reject these faults with VM_FAULT_SIGBUS when the target mm differs from current->mm: remote faults. Ordinary (non-PFN) mappings are not affected.
The user-address copy dates back to commit 6aab341e0a28 ("mm: re-architect the VM_UNPAGED logic"); likely, actual ways to get remote faults in there on COW PFN mappings appeared afterwards. But the fix is simple and straight forward.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/memory.c | 9 +++++++++ 1 file changed, 9 insertions(+)
mm/memory.c +9 -0
@@ -2895,6 +2895,13 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src,return 0 ; } +/* +* __copy_from_user_inatomic() only works as expected for local faults. +* Reject remote faults. +*/ +if (unlikely (mm != current->mm)) +return -EFAULT ; +/* * If the source page was a PFN mapping, we don't have * a "struct page" for it. We do a best-effort copy by
@@ -3167,6 +3174,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)put_page (old_page);delayacct_wpcopy_end (); +if (ret == -EFAULT ) +return VM_FAULT_SIGBUS ;return ret == -EHWPOISON ?VM_FAULT_HWPOISON :0 ; }kmsan_copy_page_meta (new_page, old_page);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1678/2857 mm/mremap: use pudp_huge_get_and_clear() when moving huge PUDs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit b4417d08034a7b4a3083e0e2d95429d4542524f2 ]
move_huge_pud() reads the old PUD and clears it in separate operations. Hardware accessed or dirty updates between those operations can be lost when the saved entry is installed at the new address.
The raw pud_clear() also bypasses page_table_check_pud_clear(), while set_pud_at() accounts for the destination mapping. This leaves the checker counts unbalanced for mappings tracked by page table checking.
To fix it, simply use pudp_huge_get_and_clear().
--- mm/mremap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/mremap.c +1 -2
@@ -400,8 +400,7 @@ static bool move_huge_pud(struct vm_area_struct *vma, unsigned long old_addr,spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING );/* Clear the pud */ - pud = *old_pud; -pud_clear (old_pud); + pud =pudp_huge_get_and_clear (mm, old_addr, old_pud);VM_BUG_ON (!pud_none (*new_pud));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1679/2857 mm/userfaultfd: compare exact registration modes before skipping
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price <[email protected]>
[ Upstream commit 05f64f211a25f7d9771d4fde109aad97174a1cf3 ]
Changing registration from MISSING|WP to WP returns success but leaves MISSING enabled. The no-op check sees that WP is already set and skips the update, so later accesses to missing pages still wait for userspace.
Skip the update only when the current and requested UFFD modes match exactly.
--- fs/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/userfaultfd.c +1 -1
@@ -1464,7 +1464,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,* userfaultfd and with the right tracking mode too. */ if (vma->vm_userfaultfd_ctx.ctx == ctx && - (vma->vm_flags & vm_flags) == vm_flags) + (vma->vm_flags & __VM_UFFD_FLAGS) == vm_flags) goto skip;if (vma->vm_start > start)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1680/2857 apparmor: fix query_data() output overlapping the lookup key
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft) <[email protected]>
[ Upstream commit d30844001360a403a511cf24fc75ecaa6a7a7544 ]
In query_data(), buf and query point into the same multi_transaction
buffer: buf at the start, query a few bytes in, and the lookup key right after the label string that query points to. Reusing the buffer is by design and is safe as long as the query is fully parsed before buf is written to, but the key is not: it is dereferenced on every iteration of label_for_each_confined(), after output has already been written. So when the label has more than one profile with a data table, the data of the first matching profile is written to buf while the key is still needed, and overwrites it if the data is large enough. The later lookups then run on a corrupted key. Besides, if the data has no NUL byte from the key's position to the end of the allocation, strhash() -> strlen() -> jhash() reads past the 4096-byte slab object, triggering an out-of-bound read:
BUG: KASAN: slab-out-of-bounds in jhash+0x595/0x5e0 Read of size 1 at addr ff1100001159d000 by task exploit/155 CPU: 0 UID: 1000 PID: 155 Comm: exploit Not tainted 7.3.0-rc7 #1 Call Trace: jhash+0x595/0x5e0 aa_write_access+0x880/0x1400 vfs_write+0x26f/0xd20 ksys_write+0x115/0x210
Writing to the .access file is unprivileged (0666), but triggering this requires loaded profiles that carry a data table, which needs CAP_MAC_ADMIN and is not the case on default distribution policies.
Fix by copying the key with kstrdup() before writing any output to buf, so the key stays valid across all loop iterations regardless of what gets written to the overlapping buffer.
--- security/apparmor/apparmorfs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
security/apparmor/apparmorfs.c +12 -3
@@ -743,7 +743,7 @@ static void profile_query_cb(struct aa_profile *profile, struct aa_perms *perms,static ssize_t query_data (char *buf,size_t buf_len,char *query,size_t query_len) { -char *out; +char *out, *keydup;const char *key;struct label_it i;struct aa_label *label, *curr;
@@ -764,11 +764,18 @@ static ssize_t query_data(char *buf, size_t buf_len,if (buf_len <sizeof (bytes) +sizeof (blocks))return -EINVAL ;/* not enough space */ +/* buf overlaps query, keep a copy of the key for the later lookups */ + keydup =kstrdup (key,GFP_KERNEL ); +if (!keydup) +return -ENOMEM ; + curr =begin_current_label_crit_section (); label =aa_label_parse (curr, query,GFP_KERNEL , false, false);end_current_label_crit_section (curr); -if (IS_ERR (label)) +if (IS_ERR (label)) { +kfree (keydup);return PTR_ERR (label); + }/* We are going to leave space for two numbers. The first is the total * number of bytes we are writing after the first number. This is so
@@ -786,13 +793,14 @@ static ssize_t query_data(char *buf, size_t buf_len,if (!profile->data)continue ; - data =rhashtable_lookup_fast (profile->data, &key, + data =rhashtable_lookup_fast (profile->data, &keydup, profile->data->p);if (data) {if (out +sizeof (outle32) + data->size > buf + buf_len) {aa_put_label (label); +kfree (keydup);return -EINVAL ;/* not enough space */ } outle32 =__cpu_to_le32 (data->size);
@@ -804,6 +812,7 @@ static ssize_t query_data(char *buf, size_t buf_len, } }aa_put_label (label); +kfree (keydup); outle32 =__cpu_to_le32 (out - buf -sizeof (bytes));memcpy (buf, &outle32,sizeof (outle32));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1681/2857 hwmon: (aquacomputer_d5next) reject short status reports
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit cf8f81babd2e96087dedbb74985bc1781c98f73d ]
The HID raw_event callback runs before HID core validates the received report length. aqc_raw_event() reads device-specific status fields at fixed offsets, including multi-byte values, without first ensuring that the received buffer contains every field. A truncated report can therefore cause out-of-bounds reads and update hwmon state with unrelated data.
The required length differs between supported devices and cannot be derived from the HID report descriptor. Define the minimum length needed by each asynchronous status format, select it while configuring the device, and reject reports that do not contain the last field accessed by that format. Keep the published length zero until probe configuration is complete, which also excludes legacy devices whose status is retrieved through feature reports.
--- drivers/hwmon/aquacomputer_d5next.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/hwmon/aquacomputer_d5next.c +21 -0
@@ -84,6 +84,8 @@ static u8 secondary_ctrl_report[] = {#define D5NEXT_5V_VOLTAGE 0x39#define D5NEXT_12V_VOLTAGE 0x37#define D5NEXT_CTRL_REPORT_SIZE 0x329 +#define D5NEXT_MIN_STATUS_REPORT_SIZE (D5NEXT_PUMP_OFFSET + AQC_FAN_SPEED_OFFSET + \ + sizeof(u16))static u8 d5next_sensor_fan_offsets[] = {D5NEXT_PUMP_OFFSET ,D5NEXT_FAN_OFFSET };/* Pump and fan speed registers in D5 Next control report (from 0-100%) */
@@ -92,12 +94,16 @@ static u16 d5next_ctrl_fan_offsets[] = { 0x97, 0x42 };/* Register offsets for the Farbwerk RGB controller */ #define FARBWERK_NUM_SENSORS 4#define FARBWERK_SENSOR_START 0x2f +#define FARBWERK_MIN_STATUS_REPORT_SIZE (FARBWERK_SENSOR_START + \ + FARBWERK_NUM_SENSORS * AQC_TEMP_SENSOR_SIZE)/* Register offsets for the Farbwerk 360 RGB controller */ #define FARBWERK360_NUM_SENSORS 4#define FARBWERK360_SENSOR_START 0x32#define FARBWERK360_NUM_VIRTUAL_SENSORS 16#define FARBWERK360_VIRTUAL_SENSORS_START 0x3a +#define FARBWERK360_MIN_STATUS_REPORT_SIZE (FARBWERK360_VIRTUAL_SENSORS_START + \ + FARBWERK360_NUM_VIRTUAL_SENSORS * AQC_TEMP_SENSOR_SIZE)/* Register offsets for the Octo fan controller */ #define OCTO_POWER_CYCLES 0x18
@@ -107,6 +113,7 @@ static u16 d5next_ctrl_fan_offsets[] = { 0x97, 0x42 };#define OCTO_NUM_VIRTUAL_SENSORS 16#define OCTO_VIRTUAL_SENSORS_START 0x45#define OCTO_CTRL_REPORT_SIZE 0x65F +#define OCTO_MIN_STATUS_REPORT_SIZE (0xD8 + AQC_FAN_SPEED_OFFSET + sizeof(u16))static u8 octo_sensor_fan_offsets[] = {0x7D ,0x8A ,0x97 ,0xA4 ,0xB1 ,0xBE ,0xCB ,0xD8 };/* Fan speed registers in Octo control report (from 0-100%) */
@@ -121,6 +128,7 @@ static u16 octo_ctrl_fan_offsets[] = { 0x5B, 0xB0, 0x105, 0x15A, 0x1AF, 0x204, 0#define QUADRO_VIRTUAL_SENSORS_START 0x3c#define QUADRO_CTRL_REPORT_SIZE 0x3c1#define QUADRO_FLOW_SENSOR_OFFSET 0x6e +#define QUADRO_MIN_STATUS_REPORT_SIZE (0x97 + AQC_FAN_SPEED_OFFSET + sizeof(u16))static u8 quadro_sensor_fan_offsets[] = {0x70 ,0x7D ,0x8A ,0x97 };/* Fan speed registers in Quadro control report (from 0-100%) */
@@ -135,6 +143,7 @@ static u16 quadro_ctrl_fan_offsets[] = { 0x37, 0x8c, 0xe1, 0x136 };#define HIGHFLOWNEXT_CONDUCTIVITY 95#define HIGHFLOWNEXT_5V_VOLTAGE 97#define HIGHFLOWNEXT_5V_VOLTAGE_USB 99 +#define HIGHFLOWNEXT_MIN_STATUS_REPORT_SIZE (HIGHFLOWNEXT_5V_VOLTAGE_USB + sizeof(u16))/* Labels for D5 Next */ static const char *const label_d5next_temp[] = {
@@ -273,6 +282,7 @@ struct aqc_data {enum kinds kind;const char *name; +u16 min_report_size;ktime_t last_ctrl_report_op;int ctrl_report_delay;/* Delay between two ctrl report operations, in ms */
@@ -710,6 +720,8 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8return 0 ; priv =hid_get_drvdata (hdev); +if (!priv->min_report_size || size < priv->min_report_size) +return 0 ;/* Info provided with every report */ priv->serial_number[0 ] =get_unaligned_be16 (data +SERIAL_FIRST_PART );
@@ -848,6 +860,7 @@ static void aqc_debugfs_init(struct aqc_data *priv)static int aqc_probe (struct hid_device *hdev,const struct hid_device_id *id) {struct aqc_data *priv; +u16 min_report_size =0 ;int ret; priv =devm_kzalloc (&hdev->dev,sizeof (*priv),GFP_KERNEL );
@@ -892,6 +905,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->power_label = label_d5next_power; priv->voltage_label = label_d5next_voltages; priv->current_label = label_d5next_current; + min_report_size =D5NEXT_MIN_STATUS_REPORT_SIZE ;break ;case USB_PRODUCT_ID_FARBWERK : priv->kind = farbwerk;
@@ -900,6 +914,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->num_temp_sensors =FARBWERK_NUM_SENSORS ; priv->temp_sensor_start_offset =FARBWERK_SENSOR_START ; priv->temp_label = label_temp_sensors; + min_report_size =FARBWERK_MIN_STATUS_REPORT_SIZE ;break ;case USB_PRODUCT_ID_FARBWERK360 : priv->kind = farbwerk360;
@@ -912,6 +927,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->temp_label = label_temp_sensors; priv->virtual_temp_label = label_virtual_temp_sensors; + min_report_size =FARBWERK360_MIN_STATUS_REPORT_SIZE ;break ;case USB_PRODUCT_ID_OCTO : priv->kind = octo;
@@ -933,6 +949,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->power_label = label_fan_power; priv->voltage_label = label_fan_voltage; priv->current_label = label_fan_current; + min_report_size =OCTO_MIN_STATUS_REPORT_SIZE ;break ;case USB_PRODUCT_ID_QUADRO : priv->kind = quadro;
@@ -955,6 +972,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->power_label = label_fan_power; priv->voltage_label = label_fan_voltage; priv->current_label = label_fan_current; + min_report_size =QUADRO_MIN_STATUS_REPORT_SIZE ;break ;case USB_PRODUCT_ID_HIGHFLOWNEXT : priv->kind = highflownext;
@@ -968,11 +986,14 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->speed_label = label_highflownext_fan_speed; priv->power_label = label_highflownext_power; priv->voltage_label = label_highflownext_voltage; + min_report_size =HIGHFLOWNEXT_MIN_STATUS_REPORT_SIZE ;break ;default :break ; } + priv->min_report_size = min_report_size; +if (priv->buffer_size !=0 ) { priv->checksum_start =0x01 ; priv->checksum_length = priv->buffer_size -3 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1682/2857 virtio_blk: use synchronous quiesce in virtblk_freeze_priv()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Zhang <[email protected]>
[ Upstream commit 6c6dec7883f8eb10b326bc9d109a4990c885d949 ]
blk_mq_run_work_fn() can call blk_mq_sched_dispatch_requests() through blk_mq_run_dispatch_ops(). The dispatcher checks QUEUE_FLAG_QUIESCED while the flag is clear. It can then be preempted before it gets a request. At that time, it has no queue usage reference, so blk_mq_freeze_queue() does not wait for it.
virtblk_freeze_priv() then calls blk_mq_quiesce_queue_nowait() and blk_mq_unfreeze_queue(). A new request can enter the queue. The old dispatcher can run again, use its old flag check, get the new request, and call virtio_queue_rq(). At the same time, virtblk_freeze_priv() can reset the device, delete the virtqueues, and free vblk->vqs. The old dispatcher can then use a deleted virtqueue or a NULL vblk->vqs, and the kernel can crash.
Fix this by using blk_mq_quiesce_queue(), which waits for dispatch code that was already running. Keep the existing freeze and unfreeze order. The queue remains quiesced until virtblk_restore_priv() calls blk_mq_unquiesce_queue().
--- drivers/block/virtio_blk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/virtio_blk.c +1 -1
@@ -1205,7 +1205,7 @@ static int virtblk_freeze(struct virtio_device *vdev)/* Ensure no requests in virtqueues before deleting vqs. */ blk_mq_freeze_queue (q); -blk_mq_quiesce_queue_nowait (q); +blk_mq_quiesce_queue (q);blk_mq_unfreeze_queue (q);/* Ensure we don't receive any more interrupts */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1683/2857 hwmon: (aquacomputer_d5next) Avoid truncating scaled sensor readings
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vas Zayarskiy <[email protected]>
[ Upstream commit c221091f7e30c64280e4cbfa27dc4c05edc96d0c ]
High Flow Next power is reported in watts. Multiplying the 16-bit value by one million can overflow both the signed intermediate and the u32 cache. Store power in long, perform the conversion in u64, and clamp to LONG_MAX. The other existing power conversions fit in a signed 32-bit value. Return -ENODATA for unavailable power instead of exposing the stored error as a reading.
The power cache is updated by HID reports without the hwmon read mutex. Read it once with READ_ONCE() and use that snapshot for both the availability check and the returned value. Mark the corresponding updates with WRITE_ONCE() so that the shared accesses are explicit.
Widen the shared current cache to u32. The Aquastream XT conversion to milliamperes can exceed 65535 mA; clamp its negative conversion results to zero before assigning to the unsigned cache. This also permits devices with scaled aggregate currents to store milliamperes directly.
--- drivers/hwmon/aquacomputer_d5next.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/hwmon/aquacomputer_d5next.c +15 -9
@@ -17,6 +17,7 @@#include <linux/hwmon.h> #include <linux/jiffies.h> #include <linux/ktime.h> +#include <linux/limits.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/seq_file.h>
@@ -312,9 +313,9 @@ struct aqc_data {/* Sensor values */ s32 temp_input[20 ];/* Max 4 physical and 16 virtual */ u16 speed_input[8 ]; -u32 power_input[8 ]; +long power_input[8 ];u16 voltage_input[8 ]; -u16 current_input[8 ]; +u32 current_input[8 ];/* Label values */ const char *const *temp_label;
@@ -525,6 +526,7 @@ static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u3static int aqc_read (struct device *dev,enum hwmon_sensor_types type,u32 attr,int channel,long *val) { +long power;int ret;struct aqc_data *priv =dev_get_drvdata (dev);
@@ -542,7 +544,10 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, *val = priv->speed_input[channel];break ;case hwmon_power: - *val = priv->power_input[channel]; + power =READ_ONCE (priv->power_input[channel]); +if (power == -ENODATA ) +return -ENODATA ; + *val = power;break ;case hwmon_pwm:if (priv->fan_ctrl_offsets) {
@@ -755,9 +760,9 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8for (i =0 ; i < priv->num_fans; i++) { priv->speed_input[i] =get_unaligned_be16 (data + priv->fan_sensor_offsets[i] +AQC_FAN_SPEED_OFFSET ); - priv->power_input[i] = -get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + -AQC_FAN_POWER_OFFSET ) *10000 ; +WRITE_ONCE (priv->power_input[i], +get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + +AQC_FAN_POWER_OFFSET ) *10000 ); priv->voltage_input[i] =get_unaligned_be16 (data + priv->fan_sensor_offsets[i] +AQC_FAN_VOLTAGE_OFFSET ) *10 ;
@@ -780,10 +785,11 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8case highflownext:/* If external temp sensor is not connected, its power reading is also N/A */ if (priv->temp_input[1 ] == -ENODATA ) - priv->power_input[0 ] = -ENODATA ; +WRITE_ONCE (priv->power_input[0 ], -ENODATA );else - priv->power_input[0 ] = -get_unaligned_be16 (data +HIGHFLOWNEXT_POWER ) *1000000 ; +WRITE_ONCE (priv->power_input[0 ], +min_t (u64,get_unaligned_be16 (data +HIGHFLOWNEXT_POWER ) * +1000000ULL ,LONG_MAX )); priv->voltage_input[0 ] =get_unaligned_be16 (data +HIGHFLOWNEXT_5V_VOLTAGE ) *10 ; priv->voltage_input[1] =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1684/2857 drm/amd/display: Drop clock requirements on DCN32 when no displays are active
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Misha Nasledov <[email protected]>
[ Upstream commit bba4dc3306483335ddbe065c05b2d8359ec387a4 ]
amdgpu_dm builds the new dc_state as a copy of the old one. When the last stream is removed, dml1_validate() returns early on pipe_cnt == 0 and never reaches dcn32_calculate_dlg_params(), so bw.dcn.clk keeps the dramclk/dcfclk/fclk requirements of the display that was just turned off. dcn32_update_clocks() then keeps those hard minimums applied.
On an RX 7900 XTX this leaves UCLK at 456 MHz and DCFCLK at 637 MHz with the monitor off, and the board idles at 28.4 W. With this change they drop to 96 MHz and 145 MHz and board power falls to 15.3 W.
Reset the clock requirements in that case, as calculate_dlg_params() already does when no HUBP is active and as the DML2 path does for stream_count == 0.
--- .../gpu/drm/amd/display/dc/dcn32/dcn32_resource.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c +14 -1
@@ -1870,8 +1870,21 @@ bool dcn32_validate_bandwidth(struct dc *dc,if (fast_validate)dcn32_restore_mall_state (dc, context, &mall_temp_config); -if (pipe_cnt ==0 ) +if (pipe_cnt ==0 ) { +/* The context is a copy of the previous state, so without this the +* clocks the last display needed stay applied with all displays off. +*/ + context->bw_ctx.bw.dcn.clk.socclk_khz =0 ; + context->bw_ctx.bw.dcn.clk.dppclk_khz =0 ; + context->bw_ctx.bw.dcn.clk.dcfclk_khz =0 ; + context->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz =0 ; + context->bw_ctx.bw.dcn.clk.dramclk_khz =0 ; + context->bw_ctx.bw.dcn.clk.fclk_khz =0 ; + context->bw_ctx.bw.dcn.clk.p_state_change_support = true; + context->bw_ctx.bw.dcn.clk.fclk_p_state_change_support = true; + context->bw_ctx.bw.dcn.clk.num_ways =0 ; goto validate_out; + }if (!out) goto validate_fail;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1685/2857 mm/filemap: read mapping->a_ops->free_folio under i_lock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit dc24e273244e9d712257d5a6c20a32c7f5ca84e6 ]
memory_failure() -> ... -> filemap_remove_folio() can read mapping->a_ops after the inode has been freed. Once the folio is deleted from the pagecache it no longer pins the mapping, so after i_lock is dropped e.g., a concurrent final iput() can evict and free the inode before filemap_free_folio() looks up mapping->a_ops->free_folio.
Most callers hold a reference on the inode, but not all.
Documentation/filesystems/vfs.rst explicitly states that ->free_folio() must not assume the original address_space mapping still exists.
Fix it by loading ->free_folio while i_lock is still held, similar to what folio_unmap_invalidate() does.
Inline filemap_free_folio() into its remaining caller such that delete_from_page_cache_batch() also just loads the callback before dropping the i_lock.
The bug was found by code inspection and has not been reproduced.
Fix generated by an LLM and sent by Josef Bacik in private.
--- mm/filemap.c | 37 ++++++++++++++++++++----------------- mm/internal.h | 1 - mm/truncate.c | 10 +++++++++- 3 files changed, 29 insertions(+), 19 deletions(-)
mm/filemap.c +20 -17
@@ -223,20 +223,6 @@ void __filemap_remove_folio(struct folio *folio, void *shadow)page_cache_delete (mapping, folio, shadow); } -void filemap_free_folio (struct address_space *mapping,struct folio *folio) -{ -void (*free_folio)(struct folio *); -int refs =1 ; - - free_folio = mapping->a_ops->free_folio; -if (free_folio) -free_folio (folio); - -if (folio_test_large (folio) && !folio_test_hugetlb (folio)) - refs =folio_nr_pages (folio); -folio_put_refs (folio, refs); -} -/** * filemap_remove_folio - Remove folio from page cache. * @folio: The folio.
@@ -248,6 +234,8 @@ void filemap_free_folio(struct address_space *mapping, struct folio *folio)void filemap_remove_folio (struct folio *folio) {struct address_space *mapping = folio->mapping; +void (*free_folio)(struct folio *folio); +int refs =1 ;BUG_ON (!folio_test_locked (folio));spin_lock (&mapping->host->i_lock);
@@ -256,9 +244,14 @@ void filemap_remove_folio(struct folio *folio)xa_unlock_irq (&mapping->i_pages);if (mapping_shrinkable (mapping))inode_add_lru (mapping->host); + free_folio = mapping->a_ops->free_folio;spin_unlock (&mapping->host->i_lock); -filemap_free_folio (mapping, folio); +if (free_folio) +free_folio (folio); +if (folio_test_large (folio) && !folio_test_hugetlb (folio)) + refs =folio_nr_pages (folio); +folio_put_refs (folio, refs); }/*
@@ -318,6 +311,7 @@ static void page_cache_delete_batch(struct address_space *mapping,void delete_from_page_cache_batch (struct address_space *mapping,struct folio_batch *fbatch) { +void (*free_folio)(struct folio *folio);int i;if (!folio_batch_count (fbatch))
@@ -335,10 +329,19 @@ void delete_from_page_cache_batch(struct address_space *mapping,xa_unlock_irq (&mapping->i_pages);if (mapping_shrinkable (mapping))inode_add_lru (mapping->host); + free_folio = mapping->a_ops->free_folio;spin_unlock (&mapping->host->i_lock); -for (i =0 ; i <folio_batch_count (fbatch); i++) -filemap_free_folio (mapping, fbatch->folios[i]); +for (i =0 ; i <folio_batch_count (fbatch); i++) { +struct folio *folio = fbatch->folios[i]; +int refs =1 ; + +if (free_folio) +free_folio (folio); +if (folio_test_large (folio) && !folio_test_hugetlb (folio)) + refs =folio_nr_pages (folio); +folio_put_refs (folio, refs); + } }int filemap_check_errors (struct address_space *mapping)
mm/internal.h +0 -1
@@ -129,7 +129,6 @@ unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices);unsigned find_get_entries (struct address_space *mapping,pgoff_t start,pgoff_t end,struct folio_batch *fbatch,pgoff_t *indices); -void filemap_free_folio (struct address_space *mapping,struct folio *folio);int truncate_inode_folio (struct address_space *mapping,struct folio *folio);bool truncate_inode_partial_folio (struct folio *folio,loff_t start,loff_t end);
mm/truncate.c +9 -1
@@ -597,6 +597,9 @@ EXPORT_SYMBOL(invalidate_mapping_pages);static int invalidate_complete_folio2 (struct address_space *mapping,struct folio *folio) { +void (*free_folio)(struct folio *folio); +int refs =1 ; +if (folio->mapping != mapping)return 0 ;
@@ -613,9 +616,14 @@ static int invalidate_complete_folio2(struct address_space *mapping,xa_unlock_irq (&mapping->i_pages);if (mapping_shrinkable (mapping))inode_add_lru (mapping->host); + free_folio = mapping->a_ops->free_folio;spin_unlock (&mapping->host->i_lock); -filemap_free_folio (mapping, folio); +if (free_folio) +free_folio (folio); +if (folio_test_large (folio) && !folio_test_hugetlb (folio)) + refs =folio_nr_pages (folio); +folio_put_refs (folio, refs);return 1 ; failed:xa_unlock_irq (&mapping->i_pages);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1686/2857 hwrng: virtio - Remove usage of the deprecated ida_simple_xx() API
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christophe JAILLET <[email protected]>
[ Upstream commit e4db80d80cff590eb5fe0444b665cec839c34133 ]
ida_alloc() and ida_free() should be preferred to the deprecated ida_simple_get() and ida_simple_remove().
This is less verbose.
Stable-dep-of: 0f7bf47f5a0c ("hwrng: virtio - prevent use-after-free after a failed restore")
--- drivers/char/hw_random/virtio-rng.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/hw_random/virtio-rng.c +3 -3
@@ -154,7 +154,7 @@ static int probe_common(struct virtio_device *vdev)if (!vi)return -ENOMEM ; - vi->index = index =ida_simple_get (&rng_index_ida,0 ,0 ,GFP_KERNEL ); + vi->index = index =ida_alloc (&rng_index_ida,GFP_KERNEL );if (index <0 ) { err = index; goto err_ida;
@@ -186,7 +186,7 @@ static int probe_common(struct virtio_device *vdev)return 0 ; err_find: -ida_simple_remove (&rng_index_ida, index); +ida_free (&rng_index_ida, index); err_ida:kfree (vi);return err;
@@ -204,7 +204,7 @@ static void remove_common(struct virtio_device *vdev)hwrng_unregister (&vi->hwrng);virtio_reset_device (vdev); vdev->config->del_vqs (vdev); -ida_simple_remove (&rng_index_ida, vi->index); +ida_free (&rng_index_ida, vi->index);kfree (vi); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1687/2857 hwrng: virtio - prevent use-after-free after a failed restore
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 0f7bf47f5a0cc26320aa4b14f4504d03a07f4b74 ]
remove_common() frees the driver data during freeze, but does not clear vdev->priv, which points to freed memory. If probe_common() then fails during restore, a later remove or freeze can dereference the dangling pointer.
Clear vdev->priv on the probe_common() error cleanup path and before freeing the driver data in remove_common(). Also reset the device and return early from remove_common() if vdev->priv is already NULL for a safe teardown after a failed restore.
Message-ID: <[email protected]>
--- drivers/char/hw_random/virtio-rng.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/char/hw_random/virtio-rng.c +7 -0
@@ -188,6 +188,7 @@ static int probe_common(struct virtio_device *vdev) err_find:ida_free (&rng_index_ida, index); err_ida: + vdev->priv =NULL ;kfree (vi);return err; }
@@ -196,6 +197,11 @@ static void remove_common(struct virtio_device *vdev) {struct virtrng_info *vi = vdev->priv; +if (!vi) { +virtio_reset_device (vdev); +return ; + } + vi->hwrng_removed = true; vi->data_avail =0 ; vi->data_idx =0 ;
@@ -205,6 +211,7 @@ static void remove_common(struct virtio_device *vdev)virtio_reset_device (vdev); vdev->config->del_vqs (vdev);ida_free (&rng_index_ida, vi->index); + vdev->priv =NULL ;kfree (vi); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1688/2857 mm/rmap: handle device-exclusive entries in folio_referenced_one()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit f3c493d2f42b5f44a5c134d8d7ea7f960caf5e2c ]
page_vma_mapped_walk() can return non-present device-exclusive entries, but folio_referenced_one() passes them to PTE young-bit accessors that require present PTEs.
We must neither call clear_flush_young_ptes_notify() nor folio_pte_batch() with non-present entries. For example, clearing the young bit on non-present PTEs can corrupt the entry: on arm64 PTE_AF overlaps the swap type, so clearing it turns a device-exclusive entry into an ordinary swap entry.
folio_pte_batch() will VM_WARN_ON_FOLIO.
Apply the same approach as the previous fixes to e.g., damon_ptep_mkold():
treat these entries as old from the CPU's perspective and obtain their young state through the MMU notifier.
Skip PTE batching and MGLRU look-around for non-present entries, and don't modify non-present PTEs.
--- mm/rmap.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
mm/rmap.c +15 -3
@@ -827,14 +827,26 @@ static bool folio_referenced_one(struct folio *folio, }if (pvmw.pte) { -if (lru_gen_enabled () &&pte_young (*pvmw.pte) && +pte_t pteval =ptep_get (pvmw.pte); +bool young = false; + +if (lru_gen_enabled () &&pte_present (pteval) && +pte_young (pteval) && !(vma->vm_flags & (VM_SEQ_READ |VM_RAND_READ ))) {lru_gen_look_around (&pvmw); referenced++; } -if (ptep_clear_flush_young_notify (vma, address, - pvmw.pte)) { +/* +* PFN swap PTEs, such as device-exclusive ones, that +* actually map pages are "old" from a CPU perspective. +* The MMU notifier takes care of any device aspects. +*/ +if (pte_present (pteval)) + young =ptep_clear_flush_young (vma, address, pvmw.pte); + young |=mmu_notifier_clear_flush_young (vma->vm_mm, address, + address +PAGE_SIZE ); +if (young) {/* * Don't treat a reference through * a sequentially read mapping as such.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1689/2857 fork: take mmap_lock before copying mm_struct
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit ef694e2d210111cc08c52fd25da9ab130170bfa3 ]
dup_mm() copies the parent's mm_struct before dup_mmap() takes the mmap_lock. A concurrent brk() can leave the child with a stale mm->brk and newer heap mappings, causing later brk() requests to fail.
Other operations (e.g., PR_SET_MM) on the parent's mm_struct can similarly cause inconsistencies.
As a simple and robust fix, grab the parent's mmap_lock earlier. This way we don't need to update individual mm fields in dup_mmap() and keep missing ones. Stop updating the 4 existing members (total_vm, data_vm, exec_vm, stack_vm), as that is now no longer required.
Keep releasing the parent's mmap_lock in dup_mmap(), before userfaultfd completion, to avoid moving the userfaultfd handling into the caller. This should get cleaned up later.
Move uprobe_start_dup_mmap() to preserve the lock ordering.
--- kernel/fork.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
kernel/fork.c +15 -14
@@ -591,11 +591,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,MA_STATE (old_mas, &oldmm->mm_mt,0 ,0 );MA_STATE (mas, &mm->mm_mt,0 ,0 ); -uprobe_start_dup_mmap (); -if (mmap_write_lock_killable (oldmm)) { - retval = -EINTR ; - goto fail_uprobe_end; - } +mmap_assert_write_locked (oldmm);flush_cache_dup_mm (oldmm);uprobe_dup_mmap (oldmm, mm);/*
@@ -606,11 +602,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,/* No ordering required: file already has been exposed. */ dup_mm_exe_file (mm, oldmm); - mm->total_vm = oldmm->total_vm; - mm->data_vm = oldmm->data_vm; - mm->exec_vm = oldmm->exec_vm; - mm->stack_vm = oldmm->stack_vm; - retval =ksm_fork (mm, oldmm);if (retval) goto out;
@@ -720,7 +711,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,flush_tlb_mm (oldmm);mmap_write_unlock (oldmm);dup_userfaultfd_complete (&uf); -fail_uprobe_end:uprobe_end_dup_mmap ();return retval;
@@ -751,7 +741,7 @@ static inline void mm_free_pgd(struct mm_struct *mm)#else static int dup_mmap (struct mm_struct *mm,struct mm_struct *oldmm) { -mmap_write_lock (oldmm); +mmap_assert_write_locked (oldmm);dup_mm_exe_file (mm, oldmm);mmap_write_unlock (oldmm);return 0 ;
@@ -1548,10 +1538,18 @@ static struct mm_struct *dup_mm(struct task_struct *tsk,if (!mm) goto fail_nomem; +uprobe_start_dup_mmap (); +if (mmap_write_lock_killable (oldmm)) { +free_mm (mm); + goto fail_uprobe; + } +memcpy (mm, oldmm,sizeof (*mm)); -if (!mm_init (mm, tsk, mm->user_ns)) - goto fail_nomem; +if (!mm_init (mm, tsk, mm->user_ns)) { +mmap_write_unlock (oldmm); + goto fail_uprobe; + } err =dup_mmap (mm, oldmm);if (err)
@@ -1570,7 +1568,10 @@ static struct mm_struct *dup_mm(struct task_struct *tsk, mm->binfmt =NULL ;mm_init_owner (mm,NULL );mmput (mm); +return NULL ; +fail_uprobe: +uprobe_end_dup_mmap (); fail_nomem:return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1690/2857 hwmon: (coretemp) Check for NULL platform device in hotplug callbacks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit 0f9c7ed3b5009a037e5533eac03a0d4d45ecf1f0 ]
coretemp_get_pdev() returns NULL when topology_logical_die_id(cpu) is negative (such as -ENODEV or -ERANGE from topology_get_logical_id() on a firmware/hardware APIC ID mismatch) or exceeds max_zones (for example, under asymmetric or anomalous ACPI die topologies where topology_max_packages() * topology_max_dies_per_package() is smaller than the logical die count).
Commit 6d03bbff456b ("hwmon: (coretemp) Simplify platform device handling") pre-allocated zone_devices[0 .. max_zones - 1] during module init and dropped the NULL checks on pdev in coretemp_cpu_online() and coretemp_cpu_offline(), passing pdev unconditionally to platform_get_drvdata(). When coretemp_get_pdev() returns NULL, platform_get_drvdata(pdev) dereferences &pdev->dev and triggers a kernel NULL pointer dereference.
Check for a NULL pdev and return 0 in both coretemp_cpu_online() and coretemp_cpu_offline() before calling platform_get_drvdata(). Returning 0 in coretemp_cpu_online() ignores the unmapped CPU without blocking CPU bringup or tearing down valid thermal zones on other dies.
--- drivers/hwmon/coretemp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/hwmon/coretemp.c +6 -0
@@ -619,6 +619,9 @@ static int coretemp_cpu_online(unsigned int cpu)if (!cpu_has (c,X86_FEATURE_DTHERM ))return -ENODEV ; +if (!pdev) +return 0 ; + pdata =platform_get_drvdata (pdev);if (!pdata->hwmon_dev) {struct device *hwmon;
@@ -670,6 +673,9 @@ static int coretemp_cpu_offline(unsigned int cpu)return 0 ;/* If the physical CPU device does not exist, just return */ +if (!pdev) +return 0 ; + pd =platform_get_drvdata (pdev);if (!pd->hwmon_dev)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1691/2857 drm/edid: parse VICs from CTA VDB early
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jani Nikula <[email protected]>
[ Upstream commit c3292ab5fbd7045f019418b2ce1977891419ad28 ]
A number of places need access to the VICs. Just parse them early for easy access. Gracefully handle multiple CTA VDBs. It's unlikely to have more than one, but the CTA-861 references "Video Data Block(s)", so err on the safe side.
Start parsing them now, convert users in follow-up to have fewer moving parts in one go.
Stable-dep-of: 0de95c96655c ("drm/amdgpu: Only enable HDMI audio if display supports it")
--- drivers/gpu/drm/drm_connector.c | 1 + drivers/gpu/drm/drm_edid.c | 36 +++++++++++++++++++++++++++++++++ include/drm/drm_connector.h | 10 +++++++++ 3 files changed, 47 insertions(+)
drivers/gpu/drm/drm_connector.c +1 -0
@@ -564,6 +564,7 @@ void drm_connector_cleanup(struct drm_connector *connector)ida_free (&dev->mode_config.connector_ida, connector->index);kfree (connector->display_info.bus_formats); +kfree (connector->display_info.vics);drm_mode_object_unregister (dev, &connector->base);kfree (connector->name); connector->name =NULL ;
drivers/gpu/drm/drm_edid.c +36 -0
@@ -5704,6 +5704,36 @@ drm_default_rgb_quant_range(const struct drm_display_mode *mode) }EXPORT_SYMBOL (drm_default_rgb_quant_range); +/* CTA-861 Video Data Block (CTA VDB) */ +static void parse_cta_vdb (struct drm_connector *connector,const struct cea_db *db) +{ +struct drm_display_info *info = &connector->display_info; +int i, vic_index, len =cea_db_payload_len (db); +const u8 *svds =cea_db_data (db); +u8 *vics; + +if (!len) +return ; + +/* Gracefully handle multiple VDBs, however unlikely that is */ + vics =krealloc (info->vics, info->vics_len + len,GFP_KERNEL ); +if (!vics) +return ; + + vic_index = info->vics_len; + info->vics_len += len; + info->vics = vics; + +for (i =0 ; i < len; i++) { +u8 vic =svd_to_vic (svds[i]); + +if (!drm_valid_cea_vic (vic)) + vic =0 ; + + info->vics[vic_index++] = vic; + } +} +static void drm_parse_vcdb (struct drm_connector *connector,const u8 *db) {struct drm_display_info *info = &connector->display_info;
@@ -6023,6 +6053,8 @@ static void drm_parse_cea_ext(struct drm_connector *connector,drm_parse_vcdb (connector, data); else if (cea_db_is_hdmi_hdr_metadata_block(db)) drm_parse_hdr_metadata_block(connector, data); + else if (cea_db_tag(db) == CTA_DB_VIDEO) + parse_cta_vdb(connector, db); }cea_db_iter_end (&iter); }
@@ -6176,6 +6208,10 @@ static void drm_reset_display_info(struct drm_connector *connector) info->mso_stream_count =0 ; info->mso_pixel_overlap =0 ; info->max_dsc_bpp =0 ; + +kfree (info->vics); + info->vics =NULL ; + info->vics_len =0 ; } static u32 update_display_info(struct drm_connector *connector,
include/drm/drm_connector.h +10 -0
@@ -662,6 +662,16 @@ struct drm_display_info {* monitor's default value is used instead. */ u32 max_dsc_bpp; + +/** +* @vics: Array of vics_len VICs. Internal to EDID parsing. +*/ +u8 *vics; + +/** +* @vics_len: Number of elements in vics. Internal to EDID parsing. +*/ +int vics_len; }; int drm_display_info_set_bus_formats(struct drm_display_info *info,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1692/2857 drm/edid: parse display info has_audio similar to is_hdmi
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jani Nikula <[email protected]>
[ Upstream commit 0374ffa507d8106202a956f5951226f1d9eac22e ]
Since we already iterate everything that's needed for determining audio, reduce the need to call drm_detect_monitor_audio() by storing has_audio to connector info.
Stable-dep-of: 0de95c96655c ("drm/amdgpu: Only enable HDMI audio if display supports it")
--- drivers/gpu/drm/drm_edid.c | 6 ++++++ include/drm/drm_connector.h | 8 ++++++++ 2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_edid.c +6 -0
@@ -6032,6 +6032,9 @@ static void drm_parse_cea_ext(struct drm_connector *connector, info->color_formats |=DRM_COLOR_FORMAT_YCBCR444 ;if (edid_ext[3 ] &EDID_CEA_YCRCB422 ) info->color_formats |=DRM_COLOR_FORMAT_YCBCR422 ; +if (edid_ext[3 ] &EDID_BASIC_AUDIO ) + info->has_audio = true; + }drm_edid_iter_end (&edid_iter);
@@ -6055,6 +6058,8 @@ static void drm_parse_cea_ext(struct drm_connector *connector,drm_parse_hdr_metadata_block (connector, data); else if (cea_db_tag(db) == CTA_DB_VIDEO) parse_cta_vdb(connector, db); + else if (cea_db_tag(db) == CTA_DB_AUDIO) + info->has_audio = true; }cea_db_iter_end (&iter); }
@@ -6193,6 +6198,7 @@ static void drm_reset_display_info(struct drm_connector *connector) info->max_tmds_clock =0 ; info->dvi_dual = false; info->is_hdmi = false; + info->has_audio = false; info->has_hdmi_infoframe = false; info->rgb_quant_range_selectable = false;memset (&info->hdmi,0 ,sizeof (info->hdmi));
include/drm/drm_connector.h +8 -0
@@ -597,6 +597,14 @@ struct drm_display_info {*/ bool is_hdmi; +/** +* @has_audio: True if the sink supports audio. +* +* This field shall be used instead of calling +* drm_detect_monitor_audio() when possible. +*/ +bool has_audio; +/** * @has_hdmi_infoframe: Does the sink support the HDMI infoframe? */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1693/2857 drm/amdgpu: Only enable HDMI audio if display supports it
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: renpanpan <[email protected]>
[ Upstream commit 0de95c96655c8a12df62e47871016f49e5cd8618 ]
The amdgpu legacy DCE audio path (dce_v6/v8/v10) unconditionally calls audio_enable(pin, true) at the end of afmt_setmode(), regardless of whether the connected display advertises audio support in its EDID.
This causes a phantom HDMI audio output to appear for displays that have no audio capability (no basic audio bit, no Audio Data Block in EDID), because the GPU sets the AUDIO_ENABLED register bit, which drives the HDA codec's ELDV pin sense, making the codec report the jack as audio-available.
The radeon, nouveau, and dw-hdmi drivers all gate audio enablement on display_info.has_audio. Apply the same check to amdgpu's DCE afmt_setmode functions.
--- drivers/gpu/drm/amd/amdgpu/dce_v10_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/dce_v6_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c +3 -2
@@ -1738,8 +1738,9 @@ static void dce_v10_0_afmt_setmode(struct drm_encoder *encoder,WREG32 (mmAFMT_RAMP_CONTROL2 + dig->afmt->offset,0x00000001 );WREG32 (mmAFMT_RAMP_CONTROL3 + dig->afmt->offset,0x00000001 ); -/* enable audio after to setting up hw */ -dce_v10_0_audio_enable (adev, dig->afmt->pin, true); +/* Only enable audio if the display supports it */ +if (connector->display_info.has_audio) +dce_v10_0_audio_enable (adev, dig->afmt->pin, true); }static void dce_v10_0_afmt_enable (struct drm_encoder *encoder,bool enable)
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c +3 -2
@@ -1702,8 +1702,9 @@ static void dce_v6_0_afmt_setmode(struct drm_encoder *encoder,dce_v6_0_audio_dp_enable (encoder,1 ); } -/* enable audio after setting up hw */ -dce_v6_0_audio_enable (adev, dig->afmt->pin, true); +/* Only enable audio if the display supports it */ +if (connector->display_info.has_audio) +dce_v6_0_audio_enable (adev, dig->afmt->pin, true); }static void dce_v6_0_afmt_enable (struct drm_encoder *encoder,bool enable)
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c +3 -2
@@ -1667,8 +1667,9 @@ static void dce_v8_0_afmt_setmode(struct drm_encoder *encoder,WREG32 (mmAFMT_RAMP_CONTROL2 + offset,0x00000001 );WREG32 (mmAFMT_RAMP_CONTROL3 + offset,0x00000001 ); -/* enable audio after setting up hw */ -dce_v8_0_audio_enable (adev, dig->afmt->pin, true); +/* Only enable audio if the display supports it */ +if (connector->display_info.has_audio) +dce_v8_0_audio_enable (adev, dig->afmt->pin, true); }static void dce_v8_0_afmt_enable (struct drm_encoder *encoder,bool enable)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1694/2857 ASoC: qdsp6: audioreach: Add ADSP ready check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivasa Rao Mandadapu <[email protected]>
[ Upstream commit 47bc8cf60e926d1fb0c5d990bf6f5e01e9b3352e ]
Check for SPF readiness in prm driver probe to avoid race conditions during ADSP pil loading.
This patch is to avoid, sending requests to ADSP before it's power domains are up and ready.
Stable-dep-of: ef7062864c05 ("ASoC: qcom: q6apm: Guard callbacks until probe data is ready")
--- sound/soc/qcom/qdsp6/q6apm.c | 13 +++++++++++++ sound/soc/qcom/qdsp6/q6apm.h | 2 ++ sound/soc/qcom/qdsp6/q6prm.c | 4 ++++ 3 files changed, 19 insertions(+)
sound/soc/qcom/qdsp6/q6apm.c +13 -0
@@ -27,6 +27,8 @@ struct apm_graph_mgmt_cmd {#define APM_GRAPH_MGMT_PSIZE (p, n) ALIGN(struct_size(p, sub_graph_id_list, n), 8) +struct q6apm *g_apm; +int q6apm_send_cmd_sync (struct q6apm *apm,struct gpr_pkt *pkt,uint32_t rsp_opcode) {gpr_device_t *gdev = apm->gdev;
@@ -143,6 +145,15 @@ static void q6apm_put_audioreach_graph(struct kref *ref)kfree (graph); } +bool q6apm_is_adsp_ready (void ) +{ +if (g_apm && g_apm->state) +return true; + +return false; +} +EXPORT_SYMBOL_GPL (q6apm_is_adsp_ready); +static int q6apm_get_apm_state (struct q6apm *apm) {struct gpr_pkt *pkt;
@@ -760,6 +771,8 @@ static int apm_probe(gpr_device_t *gdev)idr_init (&apm->modules_idr); + g_apm = apm; +q6apm_get_apm_state (apm); ret =snd_soc_register_component (dev, &q6apm_audio_component,NULL ,0 );
sound/soc/qcom/qdsp6/q6apm.h +2 -0
@@ -149,4 +149,6 @@ bool q6apm_is_sub_graphs_connected(struct q6apm *apm, u32 src_sgid, u32 dst_sgid);int q6apm_graph_get_rx_shmem_module_iid (struct q6apm_graph *graph); +bool q6apm_is_adsp_ready (void ); +#endif /* __APM_GRAPH_ */
sound/soc/qcom/qdsp6/q6prm.c +4 -0
@@ -12,6 +12,7 @@#include <linux/soc/qcom/apr.h> #include <dt-bindings/soc/qcom,gpr.h> #include <dt-bindings/sound/qcom,q6dsp-lpass-ports.h> +#include "q6apm.h" #include "q6prm.h" #include "audioreach.h"
@@ -226,6 +227,9 @@ static int prm_probe(gpr_device_t *gdev)init_waitqueue_head (&cc->wait);dev_set_drvdata (dev, cc); +if (!q6apm_is_adsp_ready ()) +return -EPROBE_DEFER ; +return devm_of_platform_populate (dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1695/2857 ASoC: qcom: q6apm: Guard callbacks until probe data is ready
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mohit Sharma <[email protected]>
[ Upstream commit ef7062864c0511bba52775d0eb3aa72d886b5f3a ]
The GPR bus needs to make response callbacks available before invoking a client probe because clients can issue synchronous commands from probe. This creates a short interval where a callback can run before the client has published its private data.
Make q6apm publish its driver data only after all callback-visible state has been initialized. Have the q6apm and q6prm callbacks ignore packets received before driver data is available.
--- sound/soc/qcom/qdsp6/q6apm.c | 6 ++++-- sound/soc/qcom/qdsp6/q6prm.c | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)
sound/soc/qcom/qdsp6/q6apm.c +4 -2
@@ -757,8 +757,6 @@ static int apm_probe(gpr_device_t *gdev)if (!apm)return -ENOMEM ; -dev_set_drvdata (dev, apm); -mutex_init (&apm->lock); apm->dev = dev; apm->gdev = gdev;
@@ -771,6 +769,7 @@ static int apm_probe(gpr_device_t *gdev)idr_init (&apm->modules_idr); +dev_set_drvdata (dev, apm); g_apm = apm;q6apm_get_apm_state (apm);
@@ -811,6 +810,9 @@ static int apm_callback(struct gpr_resp_pkt *data, void *priv, int op)struct gpr_ibasic_rsp_result_t *result;struct gpr_hdr *hdr = &data->hdr; +if (!apm) +return 0 ; + result = data->payload;switch (hdr->opcode) {
sound/soc/qcom/qdsp6/q6prm.c +3 -0
@@ -197,6 +197,9 @@ static int prm_callback(struct gpr_resp_pkt *data, void *priv, int op)struct gpr_ibasic_rsp_result_t *result;struct gpr_hdr *hdr = &data->hdr; +if (!prm) +return 0 ; +switch (hdr->opcode) {case PRM_CMD_RSP_REQUEST_HW_RSC :case PRM_CMD_RSP_RELEASE_HW_RSC :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1696/2857 ASoC: qcom: audioreach: fix ADSP ready check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
[ Upstream commit dd33c2e7b21d72b151a87b5dafffee2c019043e5 ]
currently q6apm_is_adsp_ready() will only return the cached value of previous result. If we are unlucky and previous result is not-ready then the caller will always get not-ready flag.
This is not correct, we should query the dsp of its current state in irrespective of previous reported state.
--- sound/soc/qcom/qdsp6/q6apm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
sound/soc/qcom/qdsp6/q6apm.c +9 -8
@@ -145,14 +145,6 @@ static void q6apm_put_audioreach_graph(struct kref *ref)kfree (graph); } -bool q6apm_is_adsp_ready (void ) -{ -if (g_apm && g_apm->state) -return true; - -return false; -} -EXPORT_SYMBOL_GPL (q6apm_is_adsp_ready);static int q6apm_get_apm_state (struct q6apm *apm) {
@@ -169,6 +161,15 @@ static int q6apm_get_apm_state(struct q6apm *apm)return apm->state; } +bool q6apm_is_adsp_ready (void ) +{ +if (g_apm) +return q6apm_get_apm_state (g_apm); + +return false; +} +EXPORT_SYMBOL_GPL (q6apm_is_adsp_ready); +static struct audioreach_module *__q6apm_find_module_by_mid (struct q6apm *apm,struct audioreach_graph_info *info,uint32_t mid)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1697/2857 ASoC: qcom: q6apm: clear g_apm on driver removal
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ajay Kumar Nandam <[email protected]>
[ Upstream commit be2172758f2b7c801ae80b9c8d1510b31eeffdaa ]
The global g_apm pointer is set during apm_probe() but never cleared in apm_remove(). After the driver is removed the devm-managed struct q6apm is freed, leaving g_apm dangling. A subsequent call to q6apm_is_adsp_ready() dereferences the freed pointer.
Clear g_apm in apm_remove() before the component is unregistered so that q6apm_is_adsp_ready() returns false instead of triggering a use-after-free.
--- sound/soc/qcom/qdsp6/q6apm.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/qcom/qdsp6/q6apm.c +1 -0
@@ -790,6 +790,7 @@ static int apm_probe(gpr_device_t *gdev)static void apm_remove (gpr_device_t *gdev) { + g_apm =NULL ;of_platform_depopulate (&gdev->dev);snd_soc_unregister_component (&gdev->dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1698/2857 ocfs2: use the stored hash when checking xattr bucket collision
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit e39baff18b85cf8956aee138d7944b6581e8ba36 ]
ocfs2_check_xattr_bucket_collision() decides whether splitting a full bucket can make room for the entry being set by recomputing the hash of the name:
u32 name_hash = ocfs2_xattr_name_hash(inode, name, strlen(name)); if (name_hash != le32_to_cpu(xh->xh_entries[0].xe_name_hash)) return 0;
For a new entry that is the hash it will be stored under, so comparing it is correct. An existing entry keeps the hash it already has: an update never rewrites xe_name_hash, since ocfs2_xa_add_entry() is the only writer of that field for a real entry and ocfs2_xa_prepare_entry() calls it only when loc->xl_entry is NULL.
An entry stored by a kernel that sign-extended the name bytes when hashing can still be updated, because ocfs2_xattr_find_entry() searches a non-indexed xattr block by memcmp on the name and never looks at xe_name_hash. Growing it past the space left in the block converts the block into a tree, ocfs2_cp_xattr_block_to_bucket() fills the bucket in stored hash order, and the update runs out of room in the bucket too. The collision check then compares the unsigned hash against the legacy hashes in the bucket and reports no collision.
ocfs2_xattr_set_entry_index_block() goes on to allocate a bucket that ocfs2_divide_xattr_bucket() cannot fill: a bucket whose entries all share one hash has no divide position, so all it does is append an empty bucket with a sentinel hash one above the last entry's.
The re-search that follows depends on where the unsigned hash sorts. Below the legacy ones, it comes back to the full bucket and the set fails with -ENOSPC, having grown the tree for nothing. Above them, it lands on the new empty bucket, which ocfs2_xattr_bucket_find() handles explicitly and ocfs2_find_xe_in_bucket() scans zero times, so the set stores a second copy of the entry under the unsigned hash and returns success. The original stays in the full bucket, listxattr reports the name twice and getxattr returns the new copy.
Pass the hash the entry is stored under instead: the stored one for an existing entry, the unsigned one for a new entry. A tree whose entries are all stored under the unsigned hash sees no change, since there the two are the same value.
Stable-dep-of: e8de099f2958 ("ocfs2: do not read the entry array of an empty xattr bucket")
--- fs/ocfs2/xattr.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
fs/ocfs2/xattr.c +17 -10
@@ -5601,16 +5601,14 @@ static int ocfs2_rm_xattr_cluster(struct inode *inode,/* * check whether the xattr bucket is filled up with the same hash value. -* If we want to insert the xattr with the same hash, return -ENOSPC. -* If we want to insert a xattr with different hash value, go ahead -* and ocfs2_divide_xattr_bucket will handle this. +* If the entry being set carries that same hash, return -ENOSPC, since +* ocfs2_divide_xattr_bucket() has no divide position to work with. +* Otherwise go ahead and ocfs2_divide_xattr_bucket() will handle this. */ -static int ocfs2_check_xattr_bucket_collision (struct inode *inode, -struct ocfs2_xattr_bucket *bucket, -const char *name) +static int ocfs2_check_xattr_bucket_collision (struct ocfs2_xattr_bucket *bucket, +u32 name_hash) {struct ocfs2_xattr_header *xh =bucket_xh (bucket); -u32 name_hash =ocfs2_xattr_name_hash (inode, name,strlen (name));if (name_hash !=le32_to_cpu (xh->xh_entries[0 ].xe_name_hash))return 0 ;
@@ -5707,6 +5705,7 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,struct ocfs2_xattr_search *xs, struct ocfs2_xattr_set_ctxt *ctxt) { + u32 name_hash;int ret;trace_ocfs2_xattr_set_entry_index_block (xi->xi_name);
@@ -5726,10 +5725,18 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,* the maximum number of collisions we will allow for then is * one bucket's worth, so check it here whether we need to * add a new bucket for the insert. +* +* An existing entry keeps the hash it was stored under, and that is +* the hash a split has to work with. A new entry is stored under the +* unsigned one, which is what ocfs2_xa_add_entry() will write. */ - ret =ocfs2_check_xattr_bucket_collision (inode, - xs->bucket, - xi->xi_name); +if (xs->not_found) + name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, + xi->xi_name_len); +else + name_hash =le32_to_cpu (xs->here->xe_name_hash); + + ret =ocfs2_check_xattr_bucket_collision (xs->bucket, name_hash);if (ret) {mlog_errno (ret); goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1699/2857 ocfs2: do not read the entry array of an empty xattr bucket
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit e8de099f2958c84aa23186c5481e69f7ffd39355 ]
ocfs2_check_xattr_bucket_collision() decides whether splitting a bucket can make room by comparing the hash being inserted against the first and the last entry. xh_count comes off disk and is never checked, and a bucket is allowed to hold no entries: ocfs2_xa_remove_entry() keeps the last slot when it removes the only one, so that an empty bucket still carries the hash it is keyed by. xh_count then reads back as 0 while xh_entries[0] is still meaningful, and the second comparison indexes xh_entries[-1].
That is outside the __counted_by_le(xh_count) bounds of xh_entries[] and lands on the header. An entry is 16 bytes and xe_name_hash is its first field, so the value read is xh_count | xh_free_start << 16. It stays inside the block, but the answer is arbitrary, and for an empty bucket it says there is no collision, so a new bucket gets added on the strength of it.
An empty bucket holds no entries to collide with. Return before reading the array.
One way to reach the test with an empty bucket is a set that removes the bucket's only entry during cleanup and then fails for space again, since it is that second -ENOSPC which calls this. Growing a value past OCFS2_XATTR_INLINE_SIZE is the easy route: the cluster allocation fails, the "!orig_clusters" arm of ocfs2_xa_cleanup_value_truncate() removes the entry, and although the "growing" caller does set ctxt->set_abort, only ocfs2_xattr_block_set() and __ocfs2_xattr_set_handle() look at it, so ocfs2_xattr_set_entry_index_block() goes straight on to the collision check.
This sits on commit a9ea8b397864 ("ocfs2: use the stored hash when checking xattr bucket collision"), which gave the collision check its two argument form and is marked for 6.2 and later. The read fixed here is present in the three argument version too, but a tree without that commit needs the hunk adapted by hand.
--- fs/ocfs2/xattr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/ocfs2/xattr.c +10 -1
@@ -5609,11 +5609,20 @@ static int ocfs2_check_xattr_bucket_collision(struct ocfs2_xattr_bucket *bucket, u32 name_hash) {struct ocfs2_xattr_header *xh =bucket_xh (bucket); +u16 count =le16_to_cpu (xh->xh_count); + +/* +* An empty bucket keeps the hash of the entry that was removed in +* xh_entries[0] so that it can still be found, but it holds no +* entries to collide with. +*/ +if (!count) +return 0 ;if (name_hash !=le32_to_cpu (xh->xh_entries[0 ].xe_name_hash))return 0 ; -if (xh->xh_entries[le16_to_cpu (xh->xh_count) -1 ].xe_name_hash == +if (xh->xh_entries[count -1 ].xe_name_hash == xh->xh_entries[0 ].xe_name_hash) { mlog(ML_ERROR, "Too much hash collision in xattr bucket %llu, " "hash = %u\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1700/2857 ocfs2: read the xattr entry hash before defragmenting the bucket
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit f48151da595e74efdc23d83d8d6d142207b8c731 ]
Patch series "ocfs2: fix stale xattr entry pointers and empty header reads", v1.
Five defects in the ocfs2 extended attribute code, plus one robustness measure that belongs with them, all on the paths that move entries between a block, a bucket and an index tree. They fall into two groups.
Stale entry pointers (patches 1 to 3)
ocfs2_xa_set() writes through a pointer into xh_entries[] that two of its callers invalidate first. Defragmenting a bucket ends in a sort() on xe_name_hash, and lib/sort.c is an unstable heapsort, so entries that share a hash can trade slots. Copying a block into a bucket changes the order outright, since a block holds its entries in insertion order while a bucket holds them by hash, yet ocfs2_xattr_update_xattr_search() relocates the search by the index the entry had in the block. Neither path compares the entry's name with the one being set, so setxattr() can replace a neighbouring attribute's value and still report success, or trip ocfs2_xa_reuse_entry()'s BUG_ON. Patch 1 takes the hash before the sort; patches 2 and 3 look the entry up again afterwards.
Reads of an empty entry array (patches 4 to 6)
A block and a bucket may both hold no entries: ocfs2_xa_remove_entry() keeps the last slot when it removes the only one, so an empty bucket still carries the hash it is keyed by. Three sites index xh_entries[] without checking xh_count and so read xh_entries[-1], which lands on the header and comes back as xh_count | xh_free_start << 16. Nothing faults, but the value is acted on: the collision check reports no collision for an empty bucket, the divide commits a sentinel hash that hides part of the key space from ocfs2_xattr_bucket_find(), and the block to bucket copy claims storage the bucket does not hold. Patches 4 to 6 guard each site and keep the one read of xh_entries[0] that ocfs2_xa_remove_entry() documents as intentional.
This patch (of 6):
ocfs2_xattr_set_entry_index_block() takes the hash a bucket split has to work with out of xs->here, but only after ocfs2_xattr_set_entry_bucket() has tried and failed to fit the entry. That call defragments the bucket when it runs out of room, and ocfs2_defrag_xattr_bucket() finishes by sorting the entry array by name hash. lib/sort.c is not stable, so two entries sharing a hash may trade slots and xs->here is left naming an entry other than the one the search found.
The hash value itself survives the permutation -- the array is already sorted, so a slot can only exchange with an equal-hash neighbour -- but there is no reason to depend on that. Pick the hash up before the set, where xs->here is unambiguously the entry the search landed on.
No functional change intended.
--- fs/ocfs2/xattr.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
fs/ocfs2/xattr.c +16 -10
@@ -5719,6 +5719,22 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,trace_ocfs2_xattr_set_entry_index_block (xi->xi_name); +/* +* An existing entry keeps the hash it was stored under, and that is +* the hash a split has to work with. A new entry is stored under the +* unsigned one, which is what ocfs2_xa_add_entry() will write. +* +* Read it before the set below. Filling the bucket may defragment it, +* and ocfs2_defrag_xattr_bucket() re-sorts the entry array, so +* afterwards xs->here only denotes whichever entry the sort left in +* that slot. +*/ +if (xs->not_found) + name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, + xi->xi_name_len); +else + name_hash =le32_to_cpu (xs->here->xe_name_hash); + ret =ocfs2_xattr_set_entry_bucket (inode, xi, xs, ctxt);if (!ret) goto out;
@@ -5734,17 +5750,7 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,* the maximum number of collisions we will allow for then is * one bucket's worth, so check it here whether we need to * add a new bucket for the insert. -* -* An existing entry keeps the hash it was stored under, and that is -* the hash a split has to work with. A new entry is stored under the -* unsigned one, which is what ocfs2_xa_add_entry() will write. */ -if (xs->not_found) - name_hash =ocfs2_xattr_name_hash (inode, xi->xi_name, - xi->xi_name_len); -else - name_hash =le32_to_cpu (xs->here->xe_name_hash); - ret =ocfs2_check_xattr_bucket_collision (xs->bucket, name_hash);if (ret) {mlog_errno (ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1701/2857 drm/amd/display: Avoid closing unowned DDC pins
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Hung <[email protected]>
[ Upstream commit e7ba638b8116cb5f1a5690f543052371215f1626 ]
[WHY]dal_ddc_open() cleans up pins it acquires on later failures. If the data-pin open fails, this attempt acquired nothing. If opening the clock pin or configuring fails, dal_ddc_open() closes the pins it opened. An extra dal_ddc_close() is unnecessary and unsafe:GPIO_RESULT_ALREADY_OPENED can mean AUX owns the existing handles, and closing them here would disrupt AUX.
[HOW]
Remove the extra dal_ddc_close() from the failed-open path.
--- drivers/gpu/drm/amd/display/dc/core/dc_link.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -5
@@ -399,12 +399,8 @@ bool dc_link_is_dp_sink_present(struct dc_link *link)* which indicates we need additional delay */ -if (dal_ddc_open (ddc,GPIO_MODE_INPUT , -GPIO_DDC_CONFIG_TYPE_MODE_I2C ) !=GPIO_RESULT_OK ) { -dal_ddc_close (ddc); - +if (dal_ddc_open (ddc,GPIO_MODE_INPUT ,GPIO_DDC_CONFIG_TYPE_MODE_I2C ) !=GPIO_RESULT_OK )return present; - }/* * Read GPIO: DP sink is present if both clock and data pins are zero
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1702/2857 ALSA: hda/realtek: Fix internal speakers on Acer Aspire AL16-31P
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luis Gerardo Lopez Hernandez <[email protected]>
[ Upstream commit d933955c456e0573b40eae4f72a3af37ab1c15c3 ]
The Acer Aspire AL16-31P (Intel Alder Lake-N, Realtek ALC269VC, PCI/codec SSID 2782:1718) has its internal speakers wired to pin 0x1b, but the BIOS marks that pin as not connected (0x411111f0) and only exposes pin 0x14 as the speaker. As a result the internal speakers are silent while headphones, HDMI and Bluetooth work.
This is the same layout as the Infinix Y4 Max and MEDION E15433, which share the 0x2782 subsystem vendor. Reuse their fixup, which configures pin 0x1b as an internal speaker and limits the internal mic boost.
Tested by booting with snd-hda-intel model=2782:1705: the fixup is picked, pin 0x1b is used as a speaker output, the internal speakers work, and they are muted when headphones are plugged in.
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -10528,6 +10528,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x2782 ,0x1701 ,"Infinix Y4 Max" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x2782 ,0x1705 ,"MEDION E15433" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x2782 ,0x1707 ,"Vaio VJFE-ADL" ,ALC298_FIXUP_SPK_VOLUME ), +SND_PCI_QUIRK (0x2782 ,0x1718 ,"Acer Aspire AL16-31P" ,ALC269VC_FIXUP_INFINIX_Y4_MAX ),SND_PCI_QUIRK (0x8086 ,0x2074 ,"Intel NUC 8" ,ALC233_FIXUP_INTEL_NUC8_DMIC ),SND_PCI_QUIRK (0x8086 ,0x2080 ,"Intel NUC 8 Rugged" ,ALC256_FIXUP_INTEL_NUC8_RUGGED ), SND_PCI_QUIRK(0x8086, 0x2081, "Intel NUC 10", ALC256_FIXUP_INTEL_NUC10),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1703/2857 vduse: fix VA/PA confusion in the coherent page fault path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: chenglong.ma <[email protected]>
[ Upstream commit bb2e6f166547838fd7c320b01c90918b736f76e2 ]
vduse_domain_get_coherent_page() assumes that iotlb entries above bounce_size were installed by vduse_domain_alloc_coherent(), so it treats map->addr as a physical address. But vduse registers with use_va = true, and when the device is bound to vhost_vdpa, vhost_vdpa_va_map() stores a userspace virtual address in map->addr, which vduse_domain_set_map() then copies into the same iotlb. A process holding the domain file descriptor across a rebind can therefore fault in an arbitrary physical page with read/write access, ignoring the entry permissions.
Additionally, since the domain file mmap lacks VM_IO, the domain file itself can be mapped and passed to vhost_vdpa_va_map(), producing self-referential entries that bypass the coherent path check.
To fix, only translate entries whose backing file is the domain file itself in vduse_domain_get_coherent_page(), reject such entries in vduse_domain_set_map() since only external mappings should be imported, and set VM_IO on the domain file mmap so vhost_vdpa_va_map() refuses to map it in the first place.
--- drivers/vdpa/vdpa_user/iova_domain.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_user/iova_domain.c +10 -1
@@ -76,6 +76,10 @@ int vduse_domain_set_map(struct vduse_iova_domain *domain,for (map =vhost_iotlb_itree_first (iotlb, start, last); map; map =vhost_iotlb_itree_next (map, start, last)) { map_file = (struct vdpa_map_file *)map->opaque; +if (!map_file || map_file->file == domain->file) { + ret = -EINVAL ; + goto err; + } ret = vduse_iotlb_add_range(domain, map->start, map->last, map->addr, map->perm, map_file->file,
@@ -222,6 +226,7 @@ vduse_domain_get_coherent_page(struct vduse_iova_domain *domain, u64 iova) {u64 start = iova &PAGE_MASK ;u64 last = start +PAGE_SIZE -1 ; +struct vdpa_map_file *map_file;struct vhost_iotlb_map *map;struct page *page =NULL ;
@@ -230,6 +235,10 @@ vduse_domain_get_coherent_page(struct vduse_iova_domain *domain, u64 iova)if (!map) goto out; + map_file = (struct vdpa_map_file *)map->opaque; +if (!map_file || map_file->file != domain->file) + goto out; + page =pfn_to_page ((map->addr + iova - map->start) >>PAGE_SHIFT );get_page (page); out:
@@ -565,7 +574,7 @@ static int vduse_domain_mmap(struct file *file, struct vm_area_struct *vma) {struct vduse_iova_domain *domain = file->private_data; - vma->vm_flags |=VM_DONTDUMP |VM_DONTEXPAND ; + vma->vm_flags |=VM_IO |VM_DONTDUMP |VM_DONTEXPAND ; vma->vm_private_data = domain; vma->vm_ops = &vduse_domain_mmap_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1704/2857 drm/amdkfd: use the queues process info for the WPTR BO eviction fence
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit da2897ee8b811945fd40ecc4aaf03291c14ce61c ]
amdgpu_amdkfd_map_gtt_bo_to_gart() removes the eviction fence of bo->vm_bo->vm->process_info from the WPTR BO of a new queue. bo->vm_bo is the VM which opened the BO last, not necessarily the KFD process' VM, and a render node VM has no process info.
On navi31, an unprivileged process which exports its WPTR BO with AMDKFD_IOC_EXPORT_DMABUF and imports it on a second render node fd oopses in AMDKFD_IOC_CREATE_QUEUE:
BUG: kernel NULL pointer dereference, address: 0000000000000060 RIP: 0010:amdgpu_amdkfd_map_gtt_bo_to_gart+0x86/0x1a0 [amdgpu] init_user_queue.part.0+0x180/0x250 [amdgpu] pqm_create_queue+0x32d/0x730 [amdgpu] kfd_ioctl_create_queue+0x583/0x9f0 [amdgpu]
Pass the process info of the queue instead. With the fix, the queue is created and destroyed normally.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 8 +++++--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -1
@@ -294,7 +294,8 @@ int amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel(struct kgd_mem *mem, void **kptr, uint64_t *size);void amdgpu_amdkfd_gpuvm_unmap_gtt_bo_from_kernel (struct kgd_mem *mem); -int amdgpu_amdkfd_map_gtt_bo_to_gart (struct amdgpu_device *adev,struct amdgpu_bo *bo); +int amdgpu_amdkfd_map_gtt_bo_to_gart (struct amdgpu_device *adev,struct amdgpu_bo *bo, +struct amdkfd_process_info *process_info);int amdgpu_amdkfd_gpuvm_restore_process_bos (void *process_info,struct dma_fence **ef);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5 -3
@@ -2163,11 +2163,13 @@ int amdgpu_amdkfd_gpuvm_sync_memory(* amdgpu_amdkfd_map_gtt_bo_to_gart - Map BO to GART and increment reference count * @adev: Device to which allocated BO belongs * @bo: Buffer object to be mapped +* @process_info: KFD process info of the queue the BO is for * * Before return, bo reference count is incremented. To release the reference and unpin/ * unmap the BO, call amdgpu_amdkfd_free_gtt_mem. */ -int amdgpu_amdkfd_map_gtt_bo_to_gart (struct amdgpu_device *adev,struct amdgpu_bo *bo) +int amdgpu_amdkfd_map_gtt_bo_to_gart (struct amdgpu_device *adev,struct amdgpu_bo *bo, +struct amdkfd_process_info *process_info) {int ret;
@@ -2189,8 +2191,8 @@ int amdgpu_amdkfd_map_gtt_bo_to_gart(struct amdgpu_device *adev, struct amdgpu_b goto err_map_bo_gart_failed; } -amdgpu_amdkfd_remove_eviction_fence ( - bo, bo->vm_bo->vm->process_info->eviction_fence); +/* bo->vm_bo can be the VM of any file which opened the BO */ +amdgpu_amdkfd_remove_eviction_fence (bo, process_info->eviction_fence);amdgpu_bo_unreserve (bo);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -1
@@ -368,7 +368,8 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, goto err_wptr_map_gart; } - err =amdgpu_amdkfd_map_gtt_bo_to_gart (dev->adev, wptr_bo); + err =amdgpu_amdkfd_map_gtt_bo_to_gart (dev->adev, wptr_bo, + p->kgd_process_info);if (err) {pr_err ("Failed to map wptr bo to GART\n" ); goto err_wptr_map_gart;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1705/2857 mm/filemap: finish fault cleanup before dropping the fault lock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 97156a6c355c21f7122421915f05461bd11699a4 ]
On a retried fault, a fatal signal interrupting the folio lock wait makes lock_folio_maybe_drop_mmap() drop the fault lock without pinning the file. However, filemap_fault() may still need to release mapping->invalidate_lock. A concurrent munmap() can release the last file reference and free the mapping before that unlock.
Defer dropping the fault lock to filemap_fault()'s retry cleanup, after releasing invalidate_lock. If the fault lock was already dropped for I/O, release the existing file reference instead. Keep the fault lock held for FAULT_FLAG_RETRY_NOWAIT as before.
--- mm/filemap.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-)
mm/filemap.c +13 -23
@@ -3078,11 +3078,11 @@ loff_t mapping_seek_hole_data(struct address_space *mapping, loff_t start,* @folio - the folio to lock. * @fpin - the pointer to the file we may pin (or is already pinned). * -* This works similar to lock_folio_or_retry in that it can drop the -* mmap_lock. It differs in that it actually returns the folio locked -* if it returns 1 and 0 if it couldn't lock the folio. If we did have -* to drop the mmap_lock then fpin will point to the pinned file and -* needs to be fput()'ed at a later point. +* Returns 1 with the folio locked, or 0 if locking failed. +* +* On both entry and return, a non-NULL *fpin means the fault lock has +* already been dropped and the caller must eventually fput() the file. +* Otherwise the fault lock is still held, including on failure. */ static int lock_folio_maybe_drop_mmap (struct vm_fault *vmf,struct folio *folio,struct file **fpin)
@@ -3099,20 +3099,9 @@ static int lock_folio_maybe_drop_mmap(struct vm_fault *vmf, struct folio *folio,return 0 ; *fpin =maybe_unlock_mmap_for_io (vmf, *fpin); -if (vmf->flags &FAULT_FLAG_KILLABLE ) { -if (__folio_lock_killable (folio)) { -/* -* We didn't have the right flags to drop the mmap_lock, -* but all fault_handlers only check for fatal signals -* if we return VM_FAULT_RETRY, so we need to drop the -* mmap_lock here and return 0 if we don't have a fpin. -*/ -if (*fpin ==NULL ) -mmap_read_unlock (vmf->vma->vm_mm); -return 0 ; - } - }else -__folio_lock (folio); +if (vmf->flags &FAULT_FLAG_KILLABLE ) +return !__folio_lock_killable (folio); +__folio_lock (folio);return 1 ; }
@@ -3231,7 +3220,7 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf,* vma->vm_mm->mmap_lock must be held on entry. * * If our return value has VM_FAULT_RETRY set, it's because the mmap_lock -* may be dropped before doing I/O or by lock_folio_maybe_drop_mmap(). +* may be dropped before doing I/O or when aborting an interrupted wait. * * If our return value does not have VM_FAULT_RETRY set, the mmap_lock * has not been released.
@@ -3374,9 +3363,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) out_retry:/* -* We dropped the mmap_lock, we need to return to the fault handler to -* re-find the vma and come back and find our hopefully still populated -* page. +* With fpin set, the fault lock was already dropped. Otherwise it is +* still held. Release invalidate_lock before dropping either protection. */ if (folio)folio_put (folio);
@@ -3384,6 +3372,8 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)filemap_invalidate_unlock_shared (mapping);if (fpin)fput (fpin); +else if (!(vmf->flags &FAULT_FLAG_RETRY_NOWAIT )) +mmap_read_unlock (vmf->vma->vm_mm);return ret |VM_FAULT_RETRY ; }EXPORT_SYMBOL (filemap_fault);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1706/2857 mm/shmem: make shmem_file() check the files inode
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit d3710111839d11339e414b1bb3fea3d05ab83f6e ]
shmem_file() only checks if file->f_mapping is a shmem mapping. This mapping can belong to another file, however, as with a Coda file backed by a tmpfs container after mmap().
So it does not guarantee that the file inode is an actual shmem inode.
Seal handling and memfd preservation use this check before accessing shmem inode state, so they can access an inode of the wrong type.
Let's make shmem_file() check the inode's file operations instead, to identify shmem inodes reliably. This will identify regular shmem inodes, including memfds and ordinary tmpfs files, independently of wrapper file operations.
Use shmem_mapping() in collapse_file() instead to not change the behavior of collapse_file(): it operates on the page cache and uses mapping->host for shmem inode operations. Focusing on the file does not seem relevant.
--- include/linux/shmem_fs.h | 15 ++++++--------- mm/khugepaged.c | 2 +- mm/shmem.c | 5 +++++ 3 files changed, 12 insertions(+), 10 deletions(-)
include/linux/shmem_fs.h +6 -9
@@ -75,12 +75,18 @@ extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags);extern int shmem_lock (struct file *file,int lock,struct ucounts *ucounts);#ifdef CONFIG_SHMEM +bool shmem_file (struct file *file);extern const struct address_space_operations shmem_aops;static inline bool shmem_mapping (struct address_space *mapping) {return mapping->a_ops == &shmem_aops; }#else +static inline bool shmem_file (struct file *file) +{ +return false; +} +static inline bool shmem_mapping (struct address_space *mapping) {return false;
@@ -123,15 +129,6 @@ static inline struct page *shmem_read_mapping_page( mapping_gfp_mask(mapping)); } -static inline bool shmem_file (struct file *file) -{ -if (!IS_ENABLED (CONFIG_SHMEM )) -return false; -if (!file || !file->f_mapping) -return false; -return shmem_mapping (file->f_mapping); -} -/* * If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages * beyond i_size's notion of EOF, which fallocate has committed to reserving:
mm/khugepaged.c +1 -1
@@ -1774,12 +1774,12 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, struct collapse_control *cc) {struct address_space *mapping = file->f_mapping; +const bool is_shmem =shmem_mapping (mapping);struct page *hpage;pgoff_t index, end = start +HPAGE_PMD_NR ;LIST_HEAD (pagelist);XA_STATE_ORDER (xas, &mapping->i_pages, start,HPAGE_PMD_ORDER );int nr_none =0 , result =SCAN_SUCCEED ; -bool is_shmem =shmem_file (file);int nr;VM_BUG_ON (!IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !is_shmem);
mm/shmem.c +5 -0
@@ -239,6 +239,11 @@ static const struct inode_operations shmem_special_inode_operations;static const struct vm_operations_struct shmem_vm_ops;static struct file_system_type shmem_fs_type; +bool shmem_file (struct file *file) +{ +return file &&file_inode (file)->i_fop == &shmem_file_operations; +} +bool vma_is_shmem (struct vm_area_struct *vma) {return vma->vm_ops == &shmem_vm_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1707/2857 nvmet: reject keep-alive timeouts that would overflow
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingjie Wang <[email protected]>
[ Upstream commit 96ae13f40ce5930cd58c43128e385131476f2a66 ]
nvmet_set_feat_kato() and nvmet_alloc_ctrl() convert the 32-bit millisecond KATO from the host to seconds with DIV_ROUND_UP(kato, 1000). The addition in DIV_ROUND_UP() is done in 32 bits, so any KATO above 4294966296 ms wraps around and rounds to 0 seconds. A Set Features command with KATO 0xffffffff then succeeds but disables the keep-alive
timer: Get Features returns 0 and Keep Alive fails with Keep Alive Timeout Invalid. A Connect command with such a KATO creates a controller without a keep-alive timer.
The converted value has more consumers that can overflow. Get Features multiplies it by 1000, and the timer paths multiply it by HZ in 32 bits and arm a delay that must not exceed MAX_JIFFY_OFFSET.
Reject a KATO whose rounded value does not fit all of these. Return Keep Alive Timeout Invalid from both Set Features and Connect. Validate Set Features before stopping the current timer so a failed update leaves its timeout unchanged. Round in 64 bits. A KATO of 0 keeps its current meaning.
--- drivers/nvme/target/admin-cmd.c | 7 ++++++- drivers/nvme/target/core.c | 7 ++++++- drivers/nvme/target/nvmet.h | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +6 -1
@@ -814,8 +814,13 @@ u16 nvmet_set_feat_kato(struct nvmet_req *req) {u32 val32 =le32_to_cpu (req->cmd->common.cdw11); +if (val32 >NVMET_MAX_KATO *MSEC_PER_SEC ) { + req->error_loc = offsetof(struct nvme_common_command , cdw11); +return NVME_SC_KA_TIMEOUT_INVALID |NVME_STATUS_DNR ; + } +nvmet_stop_keep_alive_timer (req->sq->ctrl); - req->sq->ctrl->kato =DIV_ROUND_UP (val32,1000 ); + req->sq->ctrl->kato =DIV_ROUND_UP_ULL (val32,MSEC_PER_SEC );nvmet_start_keep_alive_timer (req->sq->ctrl);nvmet_set_result (req, req->sq->ctrl->kato);
drivers/nvme/target/core.c +6 -1
@@ -1414,6 +1414,11 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,int ret;u16 status; +if (kato >NVMET_MAX_KATO *MSEC_PER_SEC ) { + req->error_loc = offsetof(struct nvmf_connect_command , kato); +return NVME_SC_KA_TIMEOUT_INVALID |NVME_STATUS_DNR ; + } + status =NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; subsys =nvmet_find_get_subsys (req->port, subsysnqn);if (!subsys) {
@@ -1478,7 +1483,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, kato =NVMET_DISC_KATO_MS ;/* keep-alive timeout in seconds */ - ctrl->kato =DIV_ROUND_UP (kato,1000 ); + ctrl->kato =DIV_ROUND_UP_ULL (kato,MSEC_PER_SEC ); ctrl->err_counter =0 ;spin_lock_init (&ctrl->error_lock);
drivers/nvme/target/nvmet.h +8 -0
@@ -7,6 +7,7 @@#define _NVMET_H#include <linux/dma-mapping.h> +#include <linux/jiffies.h> #include <linux/types.h> #include <linux/device.h> #include <linux/kref.h>
@@ -561,6 +562,13 @@ bool nvmet_subsys_nsid_exists(struct nvmet_subsys *subsys, u32 nsid);#define NVMET_KAS 10#define NVMET_DISC_KATO_MS 120000 +/* +* Largest keep-alive timeout in seconds that can be reported back in +* milliseconds and converted to jiffies without overflowing. +*/ +#define NVMET_MAX_KATO \ + min3(U32_MAX / MSEC_PER_SEC, U32_MAX / HZ, MAX_JIFFY_OFFSET / HZ) +int __init nvmet_init_configfs (void ); void __exit nvmet_exit_configfs(void);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1708/2857 arm64: suspend: Save and restore TPIDR2_EL0 across CPU suspend
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Wang <[email protected]>
[ Upstream commit beeec04046227eba42b7cc5ab32498aa43da9632 ]
TPIDR2_EL0 is a live EL0 register on systems with SME, but cpu_do_suspend()/cpu_do_resume() don't preserve it. Its value is UNKNOWN after a warm reset, so the task that initiates suspend can return to userspace with a corrupted TPIDR2_EL0.
Save and restore it alongside TPIDR_EL0 and TPIDRRO_EL0. The new slot fits in existing padding, so sizeof(struct cpu_suspend_ctx) is unchanged.
--- arch/arm64/include/asm/suspend.h | 2 +- arch/arm64/mm/proc.S | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
arch/arm64/include/asm/suspend.h +1 -1
@@ -2,7 +2,7 @@#ifndef __ASM_SUSPEND_H#define __ASM_SUSPEND_H -#define NR_CTX_REGS 13 +#define NR_CTX_REGS 14#define NR_CALLEE_SAVED_REGS 12/*
arch/arm64/mm/proc.S +8 -0
@@ -102,6 +102,10 @@ SYM_FUNC_START(cpu_do_suspend) * call stack. */ str x18, [x0, #96] +alternative_if ARM64_SME + mrs_s x2, SYS_TPIDR2_EL0 + str x2, [x0, #104] +alternative_else_nop_endif ret SYM_FUNC_END(cpu_do_suspend)
@@ -145,6 +149,10 @@ SYM_FUNC_START(cpu_do_resume) */ disable_daif msr mdscr_el1, x10 +alternative_if ARM64_SME + ldr x2, [x0, #104] + msr_s SYS_TPIDR2_EL0, x2 +alternative_else_nop_endif msr sctlr_el1, x12 set_this_cpu_offset x13
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1709/2857 mm: document mmu_notifier_invalidate_range_start_nonblock()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
[ Upstream commit 7ced098fcfe596feab3cea4f40128b0119c7bf1a ]
Document what mmu_notifier_invalidate_range_start_nonblock() is for. Also add a __must_check annotation to signal that callers must bail out if a notifier vetoes the operation.
Stable-dep-of: 6d65925777ec ("mm/mmu_notifier: finish non-blocking interval invalidation on error")
--- include/linux/mmu_notifier.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
include/linux/mmu_notifier.h +8 -1
@@ -461,7 +461,14 @@ mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)lock_map_release (&__mmu_notifier_invalidate_range_start_map); } -static inline int +/* +* This version of mmu_notifier_invalidate_range_start() avoids blocking, but it +* can return an error if a notifier can't proceed without blocking, in which +* case you're not allowed to modify PTEs in the specified range. +* +* This is mainly intended for OOM handling. +*/ +static inline int __must_check mmu_notifier_invalidate_range_start_nonblock (struct mmu_notifier_range *range) {int ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1710/2857 mm/mmu_notifier: finish non-blocking interval invalidation on error
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 6d65925777ecae9d7a571a327e41c63f3940a0c7 ]
When an ordinary MMU notifier rejects a non-blocking invalidation, the interval invalidation started beforehand is left unfinished: the caller skips mmu_notifier_invalidate_range_end(). Subsequent interval notifier operations can then wait forever.
The only in-tree trigger is nouveau SVM, which uses both notifier types and rejects non-blocking invalidations. Reaping via the OOM reaper or process_mrelease() can therefore leave the GPU fault worker stuck, holding a reference that prevents the dying process's address space and memory from being freed.
End the interval invalidation when an ordinary notifier fails a non-blocking invalidation, like mn_itree_invalidate() already does when an interval notifier fails. Make that handling clearer in the documentation of mmu_notifier_invalidate_range_start_nonblock().
Fix generated by an LLM and sent by Josef Bacik in private.
--- include/linux/mmu_notifier.h | 3 ++- mm/mmu_notifier.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-)
include/linux/mmu_notifier.h +2 -1
@@ -464,7 +464,8 @@ mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)/* * This version of mmu_notifier_invalidate_range_start() avoids blocking, but it * can return an error if a notifier can't proceed without blocking, in which -* case you're not allowed to modify PTEs in the specified range. +* case you're not allowed to modify PTEs in the specified range or call +* mmu_notifier_invalidate_range_end(). * * This is mainly intended for OOM handling. */
mm/mmu_notifier.c +13 -4
@@ -537,16 +537,25 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) {struct mmu_notifier_subscriptions *subscriptions = range->mm->notifier_subscriptions; -int ret; +const bool has_itree = subscriptions->has_itree; +int ret =0 ; -if (subscriptions->has_itree) { +if (has_itree) { ret =mn_itree_invalidate (subscriptions, range);if (ret)return ret; }if (!hlist_empty (&subscriptions->list)) -return mn_hlist_invalidate_range_start (subscriptions, range); -return 0 ; + ret =mn_hlist_invalidate_range_start (subscriptions, range); + +/* +* On error, the non-blocking caller is not allowed to call +* invalidate_range_end(), as in mn_itree_invalidate(). +*/ +if (ret && has_itree && !mmu_notifier_range_blockable (range)) +mn_itree_inv_end (subscriptions); + +return ret; } static void
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1711/2857 mm/shmem: fix accounting of swapin-error markers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 66ce68a249f4ac56cd6968aa6d8ded20fb4b7d09 ]
A failed swap read replaces the swap entry with a swapin-error marker in the page-cache and subtracts its pages from "alloced" and "swapped"; however, it leaves their block charge in place.
Removing the marker during truncate then subtracts from "swapped" again. This can underflow the counters or make swapped reach zero while other pages remain swapped out, causing swapoff to loop without finding them.
When installing the marker, subtract only from "swapped" and let shmem_recalc_inode() reduce "alloced" and release the block charge.
Make shmem_free_swap() report successful removal separately from the number of swap pages freed, so removing a swapin-error marker does not subtract from "swapped" again.
It's a bit confusing, but replacing a swapped out page by a swapin-error marker in shmem_set_folio_swapin_error() behaves as follows:
Initially:
alloced=1, swapped=1, nrpages=0 Calling shmem_recalc_inode(inode, 0, -1) -> swapped = 0 -> freed = 1 - 0 - 0 = 1 -> alloced -= freed -> alloced=0, swapped=0, block charge released
--- mm/shmem.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
mm/shmem.c +18 -14
@@ -787,18 +787,24 @@ static void shmem_delete_from_page_cache(struct folio *folio, void *radswap) }/* -* Remove swap entry from page cache, free the swap and its page cache. +* Remove a swap entry or swapin-error marker at index. +* Return whether it was removed, counting freed swap pages in nr_swaps_freed. */ -static int shmem_free_swap (struct address_space *mapping, -pgoff_t index,void *radswap) +static bool shmem_free_swap (struct address_space *mapping, +pgoff_t index,void *radswap,long *nr_swaps_freed) { +const swp_entry_t swp =radix_to_swp_entry (radswap);void *old; old =xa_cmpxchg_irq (&mapping->i_pages, index, radswap,NULL ,0 );if (old != radswap) -return -ENOENT ; -free_swap_and_cache (radix_to_swp_entry (radswap)); -return 0 ; +return false; +/* A swapin-error marker holds no swap slot, so just drop it. */ +if (!non_swap_entry (swp)) { +free_swap_and_cache (swp); + (*nr_swaps_freed)++; + } +return true; }/*
@@ -944,8 +950,8 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,if (xa_is_value (folio)) {if (unfalloc)continue ; - nr_swaps_freed += !shmem_free_swap (mapping, - indices[i], folio); +shmem_free_swap (mapping, indices[i], folio, + &nr_swaps_freed);continue ; }
@@ -1014,12 +1020,12 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,if (xa_is_value (folio)) {if (unfalloc)continue ; -if (shmem_free_swap (mapping, index, folio)) { +if (!shmem_free_swap (mapping, index, folio, + &nr_swaps_freed)) {/* Swap was replaced by page: retry */ index--;break ; } - nr_swaps_freed++;continue ; }
@@ -1761,11 +1767,9 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,delete_from_swap_cache (folio);spin_lock_irq (&info->lock);/* -* Don't treat swapin error folio as alloced. Otherwise inode->i_blocks won't -* be 0 when inode is released and thus trigger WARN_ON(inode->i_blocks) in -* shmem_evict_inode. +* Let shmem_recalc_inode() reduce alloced and release the block charge +* for the freed swap pages. */ - info->alloced--; info->swapped--;shmem_recalc_inode (inode);spin_unlock_irq (&info->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1712/2857 mm: hugetlb: move hugeltb sysctls to its own file
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kefeng Wang <[email protected]>
[ Upstream commit 962de54828c5bb100eb8de881b79ed9c8b7468c0 ]
This moves all hugetlb sysctls to its own file, also kill an useless hugetlb_treat_movable_handler() defination.
Stable-dep-of: dfb190302d2b ("mm/hugetlb: fix mremap move length truncation")
--- include/linux/hugetlb.h | 8 ------- kernel/sysctl.c | 32 -------------------------- mm/hugetlb.c | 51 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 43 deletions(-)
include/linux/hugetlb.h +0 -8
@@ -137,14 +137,6 @@ void hugepage_put_subpool(struct hugepage_subpool *spool);void hugetlb_dup_vma_private (struct vm_area_struct *vma);void clear_vma_resv_huge_pages (struct vm_area_struct *vma); -int hugetlb_sysctl_handler (struct ctl_table *,int ,void *,size_t *,loff_t *); -int hugetlb_overcommit_handler (struct ctl_table *,int ,void *,size_t *, -loff_t *); -int hugetlb_treat_movable_handler (struct ctl_table *,int ,void *,size_t *, -loff_t *); -int hugetlb_mempolicy_sysctl_handler (struct ctl_table *,int ,void *,size_t *, -loff_t *); - int move_hugetlb_page_tables(struct vm_area_struct *vma, struct vm_area_struct *new_vma, unsigned long old_addr, unsigned long new_addr,
kernel/sysctl.c +0 -32
@@ -2162,38 +2162,6 @@ static struct ctl_table vm_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, }, -#endif -#ifdef CONFIG_HUGETLB_PAGE - { - .procname = "nr_hugepages", - .data = NULL, - .maxlen = sizeof(unsigned long), - .mode = 0644, - .proc_handler = hugetlb_sysctl_handler, - }, -#ifdef CONFIG_NUMA - { - .procname = "nr_hugepages_mempolicy", - .data = NULL, - .maxlen = sizeof(unsigned long), - .mode = 0644, - .proc_handler = &hugetlb_mempolicy_sysctl_handler, - }, -#endif - { - .procname = "hugetlb_shm_group", - .data = &sysctl_hugetlb_shm_group, - .maxlen = sizeof(gid_t), - .mode = 0644, - .proc_handler = proc_dointvec, - }, - { - .procname = "nr_overcommit_hugepages", - .data = NULL, - .maxlen = sizeof(unsigned long), - .mode = 0644, - .proc_handler = hugetlb_overcommit_handler, - },#endif { .procname = "lowmem_reserve_ratio",
mm/hugetlb.c +48 -3
87 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1713/2857 mm/hugetlb: fix mremap move length truncation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Zhe <[email protected]>
[ Upstream commit dfb190302d2b4af86c6ae48af0d3b09f28b35460 ]
Patch series "mm/hugetlb: fix mremap bugs", v3.
This series fixes a few hugetlb mremap bugs.
Patch 1 fixes the return type of move_hugetlb_page_tables(), so large hugetlb moves cannot be truncated when reported back to the generic mremap code.
Patch 2 disables hugetlb PMD sharing for UFFD missing mode, so UFFDIO_POISON markers cannot become visible through shared PMD page tables.
Patch 3 fixes the recursive i_mmap_rwsem deadlock in the hugetlb mremap path by avoiding the destination PMD sharing allocation path while the mapping lock is already held for write.
This patch (of 3):
move_hugetlb_page_tables() returns the number of bytes moved, but its return type is int while the generic move_page_tables() path uses unsigned long lengths.
A hugetlb mremap() move length above INT_MAX can therefore be misreported to copy_vma_and_data(). The out-of-range conversion to int is implementation-defined; on common 64-bit builds, for example, a 4 GiB move can be reported as zero, making the caller treat the move as a failure and use the wrong length for rollback.
Return unsigned long from move_hugetlb_page_tables(), matching move_page_tables() and preserving the full byte count.
--- include/linux/hugetlb.h | 15 ++++++--------- mm/hugetlb.c | 7 +++---- 2 files changed, 9 insertions(+), 13 deletions(-)
include/linux/hugetlb.h +6 -9
@@ -137,10 +137,9 @@ void hugepage_put_subpool(struct hugepage_subpool *spool);void hugetlb_dup_vma_private (struct vm_area_struct *vma);void clear_vma_resv_huge_pages (struct vm_area_struct *vma); -int move_hugetlb_page_tables (struct vm_area_struct *vma, -struct vm_area_struct *new_vma, -unsigned long old_addr,unsigned long new_addr, -unsigned long len); +unsigned long move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma,unsigned long old_addr, +unsigned long new_addr,unsigned long len);int copy_hugetlb_page_range (struct mm_struct *,struct mm_struct *,struct vm_area_struct *,struct vm_area_struct *); long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *,
@@ -296,11 +295,9 @@ static inline int copy_hugetlb_page_range(struct mm_struct *dst,return 0 ; } -static inline int move_hugetlb_page_tables (struct vm_area_struct *vma, -struct vm_area_struct *new_vma, -unsigned long old_addr, -unsigned long new_addr, -unsigned long len) +static inline unsigned long move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma,unsigned long old_addr, +unsigned long new_addr,unsigned long len) {BUG ();return 0 ;
mm/hugetlb.c +3 -4
@@ -5308,10 +5308,9 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,spin_unlock (dst_ptl); } -int move_hugetlb_page_tables (struct vm_area_struct *vma, -struct vm_area_struct *new_vma, -unsigned long old_addr,unsigned long new_addr, -unsigned long len) +unsigned long move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma,unsigned long old_addr, +unsigned long new_addr,unsigned long len) {struct hstate *h =hstate_vma (vma);struct address_space *mapping = vma->vm_file->f_mapping;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1714/2857 vsock/virtio: Move length check to callers of virtio_vsock_skb_rx_put()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
[ Upstream commit 87dbae5e36613a6020f3d64a2eaeac0a1e0e6dc6 ]
virtio_vsock_skb_rx_put() only calls skb_put() if the length in the packet header is not zero even though skb_put() handles this case gracefully.
Remove the functionally redundant check from virtio_vsock_skb_rx_put() and, on the assumption that this is a worthwhile optimisation for handling credit messages, augment the existing length checks in virtio_transport_rx_work() to elide the call for zero-length payloads. Since the callers all have the length, extend virtio_vsock_skb_rx_put() to take it as an additional parameter rather than fish it back out of the packet header.
Note that the vhost code already has similar logic in vhost_vsock_alloc_skb().
Message-Id: <[email protected]>
Stable-dep-of: d5e912448cd9 ("vhost/vsock: size receive SKBs from declared payload")
--- drivers/vhost/vsock.c | 2 +- include/linux/virtio_vsock.h | 9 ++------- net/vmw_vsock/virtio_transport.c | 4 +++- 3 files changed, 6 insertions(+), 9 deletions(-)
drivers/vhost/vsock.c +1 -1
@@ -372,7 +372,7 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq,return NULL ; } -virtio_vsock_skb_rx_put (skb); +virtio_vsock_skb_rx_put (skb, payload_len); nbytes =copy_from_iter (skb->data, payload_len, &iov_iter);if (nbytes != payload_len) {
include/linux/virtio_vsock.h +2 -7
@@ -46,14 +46,9 @@ static inline void virtio_vsock_skb_clear_tap_delivered(struct sk_buff *skb)VIRTIO_VSOCK_SKB_CB (skb)->tap_delivered = false; } -static inline void virtio_vsock_skb_rx_put (struct sk_buff *skb) +static inline void virtio_vsock_skb_rx_put (struct sk_buff *skb,u32 len) { -u32 len; - - len =le32_to_cpu (virtio_vsock_hdr (skb)->len); - -if (len >0 ) -skb_put (skb, len); +skb_put (skb, len); }static inline struct sk_buff *virtio_vsock_alloc_skb (unsigned int size,gfp_t mask)
net/vmw_vsock/virtio_transport.c +3 -1
@@ -527,7 +527,9 @@ static void virtio_transport_rx_work(struct work_struct *work)continue ; } -virtio_vsock_skb_rx_put (skb); +if (payload_len) +virtio_vsock_skb_rx_put (skb, payload_len); +virtio_transport_deliver_tap_pkt (skb);virtio_transport_recv_pkt (&virtio_transport, skb); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1715/2857 vsock/virtio: Rename virtio_vsock_skb_rx_put()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
[ Upstream commit 8ca76151d2c8219edea82f1925a2a25907ff6a9d ]
In preparation for using virtio_vsock_skb_rx_put() when populating SKBs on the vsock TX path, rename virtio_vsock_skb_rx_put() to virtio_vsock_skb_put().
No functional change.
Message-Id: <[email protected]>
Stable-dep-of: d5e912448cd9 ("vhost/vsock: size receive SKBs from declared payload")
--- drivers/vhost/vsock.c | 2 +- include/linux/virtio_vsock.h | 2 +- net/vmw_vsock/virtio_transport.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/vhost/vsock.c +1 -1
@@ -372,7 +372,7 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq,return NULL ; } -virtio_vsock_skb_rx_put (skb, payload_len); +virtio_vsock_skb_put (skb, payload_len); nbytes =copy_from_iter (skb->data, payload_len, &iov_iter);if (nbytes != payload_len) {
include/linux/virtio_vsock.h +1 -1
@@ -46,7 +46,7 @@ static inline void virtio_vsock_skb_clear_tap_delivered(struct sk_buff *skb)VIRTIO_VSOCK_SKB_CB (skb)->tap_delivered = false; } -static inline void virtio_vsock_skb_rx_put (struct sk_buff *skb,u32 len) +static inline void virtio_vsock_skb_put (struct sk_buff *skb,u32 len) {skb_put (skb, len); }
net/vmw_vsock/virtio_transport.c +1 -1
@@ -528,7 +528,7 @@ static void virtio_transport_rx_work(struct work_struct *work) }if (payload_len) -virtio_vsock_skb_rx_put (skb, payload_len); +virtio_vsock_skb_put (skb, payload_len);virtio_transport_deliver_tap_pkt (skb);virtio_transport_recv_pkt (&virtio_transport, skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1716/2857 vhost/vsock: size receive SKBs from declared payload
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit d5e912448cd98b261eba8e35ab838f2dc69a79f5 ]
vhost_vsock_alloc_skb() sizes the skb from iov_length(), the total guest descriptor length. virtio_transport_inc_rx_pkt() instead adds hdr->len to rx_bytes and buf_used, and budgets each queued skb as SKB_TRUESIZE(0). The guest controls the descriptor length and hdr->len independently.
A guest can therefore provide a 64 KiB descriptor while declaring a zero payload. The descriptor-sized skb remains queued, rx_bytes and buf_used remain unchanged, and only the fixed queue-entry budget limits retention. This is not a lifetime leak: the skb is freed when dequeued or at socket teardown. Repeating this across connections can nevertheless exhaust host memory. On Linux v7.2, 455 such descriptors retained 30,255,680 bytes for a 262,144-byte receive buffer; a full-payload control retained 265,984 bytes.
Vhost previously read hdr->len and allocated pkt->buf from that value. The conversion from virtio_vsock_pkt to sk_buff instead allocated receive skbs from the descriptor length, introducing the allocation-accounting mismatch.
Copy the header into a stack object and validate hdr->len before allocating the skb. Size the allocation as sizeof(hdr) + payload_len so descriptor capacity no longer determines queued memory. Check payload_len against len - sizeof(hdr) to avoid addition overflow on 32-bit hosts.
--- drivers/vhost/vsock.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
drivers/vhost/vsock.c +16 -18
@@ -327,7 +327,7 @@ static struct sk_buff * vhost_vsock_alloc_skb(struct vhost_virtqueue *vq, unsigned int out, unsigned int in) { - struct virtio_vsock_hdr *hdr; + struct virtio_vsock_hdr hdr;struct iov_iter iov_iter;struct sk_buff *skb;size_t payload_len;
@@ -344,34 +344,32 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq,if (len >VIRTIO_VSOCK_MAX_PKT_BUF_SIZE +VIRTIO_VSOCK_SKB_HEADROOM )return NULL ; -/* len contains both payload and hdr */ - skb =virtio_vsock_alloc_skb (len,GFP_KERNEL ); -if (!skb) -return NULL ; -iov_iter_init (&iov_iter,ITER_SOURCE , vq->iov, out, len); - hdr =virtio_vsock_hdr (skb); - nbytes =copy_from_iter (hdr,sizeof (*hdr), &iov_iter); -if (nbytes !=sizeof (*hdr)) { + nbytes =copy_from_iter (&hdr,sizeof (hdr), &iov_iter); +if (nbytes !=sizeof (hdr)) {vq_err (vq,"Expected %zu bytes for pkt->hdr, got %zu bytes\n" , -sizeof (*hdr), nbytes); -kfree_skb (skb); +sizeof (hdr), nbytes);return NULL ; } - payload_len =le32_to_cpu (hdr->len); + payload_len =le32_to_cpu (hdr.len); + +/* The pkt is too big or the length in the header is invalid */ +if (payload_len > len -sizeof (hdr)) +return NULL ; + +/* Allocate only for the payload declared in the header. */ + skb =virtio_vsock_alloc_skb (payload_len +sizeof (hdr),GFP_KERNEL ); +if (!skb) +return NULL ; + +memcpy (virtio_vsock_hdr (skb), &hdr,sizeof (hdr));/* No payload */ if (!payload_len)return skb; -/* The pkt is too big or the length in the header is invalid */ -if (payload_len +sizeof (*hdr) > len) { -kfree_skb (skb); -return NULL ; - } -virtio_vsock_skb_put (skb, payload_len); nbytes =copy_from_iter (skb->data, payload_len, &iov_iter);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1717/2857 selinux: prevent KMSAN warning in selinux_inet_conn_request()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Kanner <[email protected]>
commit 1df83cbf23a27174aee6ea5e52462f03f7e48a10 upstream.
KMSAN reports the following issue:
[ 81.822503] ===================================================== [ 81.823222] BUG: KMSAN: uninit-value in selinux_inet_conn_request+0x2c8/0x4b0 [ 81.823891] selinux_inet_conn_request+0x2c8/0x4b0 [ 81.824385] security_inet_conn_request+0xc0/0x160 [ 81.824886] tcp_v4_route_req+0x30e/0x490 [ 81.825343] tcp_conn_request+0xdc8/0x3400 [ 81.825813] tcp_v4_conn_request+0x134/0x190 [ 81.826292] tcp_rcv_state_process+0x1f4/0x3b40 [ 81.826797] tcp_v4_do_rcv+0x9ca/0xc30 [ 81.827236] tcp_v4_rcv+0x3bf5/0x4180 [ 81.827670] ip_protocol_deliver_rcu+0x822/0x1230 [ 81.828174] ip_local_deliver_finish+0x259/0x370 [ 81.828667] ip_local_deliver+0x1c0/0x450 [ 81.829105] ip_sublist_rcv+0xdc1/0xf50 [ 81.829534] ip_list_rcv+0x72e/0x790 [ 81.829941] __netif_receive_skb_list_core+0x10d5/0x1180 [ 81.830499] netif_receive_skb_list_internal+0xc41/0x1190 [ 81.831064] napi_complete_done+0x2c4/0x8b0 [ 81.831532] e1000_clean+0x12bf/0x4d90 [ 81.831983] __napi_poll+0xa6/0x760 [ 81.832391] net_rx_action+0x84c/0x1550 [ 81.832831] __do_softirq+0x272/0xa6c [ 81.833239] __irq_exit_rcu+0xb7/0x1a0 [ 81.833654] irq_exit_rcu+0x17/0x40 [ 81.834044] common_interrupt+0x8d/0xa0 [ 81.834494] asm_common_interrupt+0x2b/0x40 [ 81.834949] default_idle+0x17/0x20 [ 81.835356] arch_cpu_idle+0xd/0x20 [ 81.835766] default_idle_call+0x43/0x70 [ 81.836210] do_idle+0x258/0x800 [ 81.836581] cpu_startup_entry+0x26/0x30 [ 81.837002] __pfx_ap_starting+0x0/0x10 [ 81.837444] secondary_startup_64_no_verify+0x17a/0x17b [ 81.837979] [ 81.838166] Local variable nlbl_type.i created at: [ 81.838596] selinux_inet_conn_request+0xe3/0x4b0 [ 81.839078] security_inet_conn_request+0xc0/0x160
KMSAN warning is reproducible with:
* netlabel_mgmt_protocount is 0 (e.g. netlbl_enabled() returns 0)
* CONFIG_SECURITY_NETWORK_XFRM may be set or not
* CONFIG_KMSAN=y
* ssh USER@HOSTNAME /bin/date
selinux_skb_peerlbl_sid() will call selinux_xfrm_skb_sid(), then fall to selinux_netlbl_skbuff_getsid() which will not initialize nlbl_type, but it will be passed to:
err = security_net_peersid_resolve(nlbl_sid,
nlbl_type, xfrm_sid, sid);
and checked by KMSAN, although it will not be used inside security_net_peersid_resolve() (at least now), since this function will check either (xfrm_sid == SECSID_NULL) or (nlbl_sid == SECSID_NULL) first and return before using uninitialized nlbl_type.
--- security/selinux/netlabel.c | 1 + 1 file changed, 1 insertion(+)
security/selinux/netlabel.c +1 -0
@@ -196,6 +196,7 @@ int selinux_netlbl_skbuff_getsid(struct sk_buff *skb,struct netlbl_lsm_secattr secattr;if (!netlbl_enabled ()) { + *type =NETLBL_NLTYPE_NONE ; *sid =SECSID_NULL ;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1718/2857 ovl: inherit FMODE_NONOTIFY when reading directory layers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 9ff338af0e002fe217cfa16b1289b76f6b21fc72 ]
Listing a merged or impure overlay directory opens the real layer directories from ovl_dir_read(), when the readdir cache is filled. Those opens use plain ovl_path_open(), so when the directory fd is one that fanotify created for a permission event, they can still raise FS_OPEN_PERM. A listener that also marks the backing filesystem and calls getdents() on the event fd before answering then deadlocks the same way as with the directory open fixed by the previous commit.
Store the overlay user file in struct ovl_readdir_data and pass it to ovl_path_open_realfile() from ovl_dir_read(), for both the merged and the impure cache. Internal readers such as ovl_check_empty_dir() and the mount-time workdir cleanup still pass no user file.
A note about severity and real world impact: The FAN_OPEN_PERM event is traditionally used by anti-malware protection agents and security/audit agents. The scope that is often used in those use cases is FAN_MARK_MOUNT and agents typically monitor multiple mounts in a mount namespace. FAN_OPEN_PERM from directory open requires user opt-in with FAN_ONDIR. It is often not the case that anti-malware agents monitor open of directories. Security/audit engines are more likely to opt-into FAN_OPEN_PERM on directories, but are less likely to list the content of a directory within the scope of FAN_OPEN_PERM event, so the real world impact of this bug is likely not significant.
--- fs/overlayfs/readdir.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
fs/overlayfs/readdir.c +20 -11
@@ -37,6 +37,7 @@ struct ovl_dir_cache {struct ovl_readdir_data {struct dir_context ctx; +const struct file *user_file;struct dentry *dentry;bool is_lowest;struct rb_root *root;
@@ -295,9 +296,13 @@ static inline int ovl_dir_read(const struct path *realpath, struct ovl_readdir_data *rdd) {struct file *realfile; +int flags =O_RDONLY |O_LARGEFILE ;int err; - realfile =ovl_path_open (realpath,O_RDONLY |O_LARGEFILE ); +if (rdd->user_file && (rdd->user_file->f_mode &FMODE_NONOTIFY )) + flags |= __FMODE_NONOTIFY; + + realfile =ovl_path_open (realpath, flags);if (IS_ERR (realfile))return PTR_ERR (realfile);
@@ -341,12 +346,13 @@ static void ovl_dir_reset(struct file *file) }static int ovl_dir_read_merged (struct dentry *dentry,struct list_head *list, -struct rb_root *root) +struct rb_root *root,const struct file *user_file) {int err;struct path realpath;struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_merge, + .user_file = user_file, .dentry = dentry, .list = list, .root = root,
@@ -390,9 +396,10 @@ static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos) od->cursor = p; } -static struct ovl_dir_cache *ovl_cache_get (struct dentry *dentry) +static struct ovl_dir_cache *ovl_dir_cache_get (struct file *file) {int res; +struct dentry *dentry = file->f_path.dentry;struct ovl_dir_cache *cache; cache =ovl_dir_cache (d_inode (dentry));
@@ -411,7 +418,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)INIT_LIST_HEAD (&cache->entries); cache->root =RB_ROOT ; - res =ovl_dir_read_merged (dentry, &cache->entries, &cache->root); + res =ovl_dir_read_merged (dentry, &cache->entries, &cache->root, file);if (res) {ovl_cache_free (&cache->entries);kfree (cache);
@@ -547,14 +554,15 @@ static bool ovl_fill_plain(struct dir_context *ctx, const char *name,return true; } -static int ovl_dir_read_impure (const struct path *path,struct list_head *list, -struct rb_root *root) +static int ovl_dir_read_impure (const struct path *path,struct list_head *list, +struct rb_root *root,const struct file *user_file) {int err;struct path realpath;struct ovl_cache_entry *p, *n;struct ovl_readdir_data rdd = { .ctx.actor = ovl_fill_plain, + .user_file = user_file, .list = list, .root = root, };
@@ -592,9 +600,10 @@ static int ovl_dir_read_impure(const struct path *path, struct list_head *list,return 0 ; } -static struct ovl_dir_cache *ovl_cache_get_impure (const struct path *path) +static struct ovl_dir_cache *ovl_cache_get_impure (struct file *file) {int res; +const struct path *path = &file->f_path;struct dentry *dentry = path->dentry;struct ovl_fs *ofs =OVL_FS (dentry->d_sb);struct ovl_dir_cache *cache;
@@ -611,7 +620,7 @@ static struct ovl_dir_cache *ovl_cache_get_impure(const struct path *path)if (!cache)return ERR_PTR (-ENOMEM ); - res =ovl_dir_read_impure (path, &cache->entries, &cache->root); + res =ovl_dir_read_impure (path, &cache->entries, &cache->root, file);if (res) {ovl_cache_free (&cache->entries);kfree (cache);
@@ -726,7 +735,7 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)dput (parent);if (ovl_is_impure_dir (file)) { - rdt.cache =ovl_cache_get_impure (&file->f_path); + rdt.cache =ovl_cache_get_impure (file);if (IS_ERR (rdt.cache))return PTR_ERR (rdt.cache); }
@@ -773,7 +782,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)if (!od->cache) {struct ovl_dir_cache *cache; - cache =ovl_cache_get (dentry); + cache =ovl_dir_cache_get (file); err =PTR_ERR (cache);if (IS_ERR (cache)) goto out;
@@ -987,7 +996,7 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)const struct cred *old_cred; old_cred =ovl_override_creds (dentry->d_sb); - err =ovl_dir_read_merged (dentry, list, &root); + err =ovl_dir_read_merged (dentry, list, &root,NULL );revert_creds (old_cred);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1719/2857 mm/migrate: snapshot the source nid before the misplaced migration
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yafang Shao <[email protected]>
[ Upstream commit fe623a81ad9eddf10059b4e44bca0440d9120613 ]
A successful migration frees the source folio before the promotion counter update, so the folio_nid() read there operates on a freed folio — which may already have been reallocated. It happens to work today, as Zi explained:
: Strictly speaking, it can be seen as a benign UAF. It works, because : 1. folio->flags happens to be the same as page->flags,
: 2. folio/page nid is stored in the ->flags and never changed. :
: In memdesc world, after a folio is freed, I assume folio->flags would be : zeroed since struct folio is freed and calling folio_nid() on a freed : folio would give a bogus result (yeah, it can be mitigated by not : zeroing node field and each node has its own struct folio pool, but that : makes folio_nid() implementation dependent).
and Matthew explained further:
: once struct folio is separately allocated, it's a UAF. It could be : recycled to a different NID or maybe the slab containing the folio could : be freed (assuming we're not holding the RCU read lock at this point in : migration, and I don't see why we would be).
A separate concern is memory hot-removal. With memory-tiering mode enabled, successful migration can release the source before the promotion-accounting folio_nid() read. If the task is preempted there, an otherwise-free source block can be offlined and removed first. On the x86 path, removal can unmap the source's vmemmap, so the later read can fault. The snapshot avoids that read.
--- mm/migrate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/migrate.c +2 -1
@@ -2458,6 +2458,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma,int isolated;int nr_remaining;unsigned int nr_succeeded; +int src_node =page_to_nid (page);LIST_HEAD (migratepages);int nr_pages =thp_nr_pages (page);
@@ -2495,7 +2496,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, }if (nr_succeeded) {count_vm_numa_events (NUMA_PAGE_MIGRATE , nr_succeeded); -if (!node_is_toptier (page_to_nid (page)) &&node_is_toptier (node)) +if (!node_is_toptier (src_node) &&node_is_toptier (node))mod_node_page_state (pgdat,PGPROMOTE_SUCCESS , nr_succeeded); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1720/2857 comedi: addi_apci_3xxx: fix subdevice count underallocation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Zi <[email protected]>
[ Upstream commit 3de5aa458dede472a253266d02902bd95af8e849 ]
In apci3xxx_auto_attach(), the number of subdevices is computed with
n_subdevices = (board->ai_n_chan ? 0 : 1) + board->has_ao + ...
The ternary is inverted: when the board has analog input channels (ai_n_chan != 0), it counts 0 instead of 1, so the AI subdevice that is actually created is not accounted for. As a result comedi_alloc_subdevices() allocates one entry too few, and the later subdevice initialization (notably the TTL Digital I/O subdevice, which is populated last) writes past the end of the allocated array, causing a slab out-of-bounds write.
Flip the ternary to count 1 when ai_n_chan is non-zero and 0 otherwise, matching the subdevice creation order in the function.
--- drivers/comedi/drivers/addi_apci_3xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/addi_apci_3xxx.c +1 -1
@@ -787,7 +787,7 @@ static int apci3xxx_auto_attach(struct comedi_device *dev, dev->irq = pcidev->irq; } - n_subdevices = (board->ai_n_chan ?0 :1 ) + board->has_ao + + n_subdevices = (board->ai_n_chan ?1 :0 ) + board->has_ao + board->has_dig_in + board->has_dig_out + board->has_ttl_io; ret =comedi_alloc_subdevices (dev, n_subdevices);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1721/2857 SUNRPC: Copy the deferred RPC Call from the head buffer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit 2192a56b0686599358909c3e12e9a366f5b5d452 upstream.
svc_defer() snapshots the RPC Call for replay once a pending cache upcall resolves. It copies the Call starting (rq_arg.len - head[0].iov_len) bytes before head[0].iov_base, a back-up that once covered a transport header. No transport has had one since commit 983084b2672c ("SUNRPC: Remove svc_rqst::rq_xprt_hlen"), so the two lengths are meant to be equal.
An RPCSEC_GSS Call breaks that assumption. Unwrapping the integrity service truncates rq_arg.len by the length of the trailing checksum, and unwrapping the privacy service leaves rq_arg.len short by an amount the client sets with trailing bytes after the wrap token. Neither adjusts head[0].iov_len. Both lengths are size_t, so the subtraction underflows and the copy starts past head[0].iov_base. Every deferred integrity Call replays a shifted snapshot.
A deferred replay skips GSS verification, so a shifted snapshot runs as an authenticated Call. With the privacy service the offset is client-chosen. A forged Call placed in that window, naming another user's GSS context handle, runs under that identity.
Copy the Call from head[0].iov_base. Refuse to defer a Call whose length runs past the head buffer, so the copy cannot read out of bounds.
[doebel: 6.1 backport. In this tree the RPC Call header is parsed
with svc_getnl(), which advances rq_arg.head[0].iov_base while rq_arg.len keeps measuring from the start of the receive buffer, so len > head[0].iov_len for every Call at svc_defer() time and the upstream guard and copy-from-iov_base cannot apply; keep the skip-based snapshot that svc_deferred_recv() expects. A GSS privacy unwrap breaks the len - iov_len invariant by resetting rq_arg.len (gss_unwrap_kerberos_v2()); refuse to defer after a GSS integrity/privacy unwrap (rq_auth_slack != 0) or when len < head[0].iov_len.]
--- net/sunrpc/svc_xprt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/sunrpc/svc_xprt.c +14 -0
@@ -1221,6 +1221,20 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req) }else {size_t skip;size_t size; + +/* +* A GSS integrity/privacy unwrap can reset rq_arg.len so +* it no longer measures from the start of the receive +* buffer (see gss_unwrap_kerberos_v2()). In that state +* len - iov_len does not locate the buffer start, and a +* snapshot taken here would be replayed without GSS +* verification. Refuse to defer; the caller fails the +* request and the client retries. +*/ +if (rqstp->rq_auth_slack || + rqstp->rq_arg.len < rqstp->rq_arg.head[0 ].iov_len) +return NULL ; +/* FIXME maybe discard if size too large */ size =sizeof (struct svc_deferred_req ) + rqstp->rq_arg.len; dr =kmalloc (size,GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1722/2857 comedi: dt2811: fix shift-out-of-bounds in IRQ check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit 471ce96a9c415b8a67bd5081ac2089a458cacc2f ]
The IRQ number passed via comedi_devconfig->options[1] is a signed int that comes from userspace. The check it->options[1] <= 7 does not reject negative values, so a negative IRQ number reaches BIT(it->options[1]), which is undefined behavior and triggers a UBSAN shift-out-of-bounds warning:
UBSAN: shift-out-of-bounds in drivers/comedi/drivers/dt2811.c:570:31 shift exponent -251 is negative
Add an explicit lower bound check (it->options[1] >= 0) so that only valid IRQ numbers 0..7 are accepted before the shift.
--- drivers/comedi/drivers/dt2811.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/dt2811.c +1 -1
@@ -566,7 +566,7 @@ static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it)dt2811_reset (dev);/* IRQ's 2,3,5,7 are valid for async command support */ -if (it->options[1 ] <=7 && (BIT (it->options[1 ]) &0xac )) { +if (it->options[1 ] >=0 && it->options[1 ] <=7 && (BIT (it->options[1 ]) &0xac )) { ret =request_irq (it->options[1 ], dt2811_interrupt,0 , dev->board_name, dev);if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1723/2857 ocfs2: validate move extents against a stable EOF
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 84db6619cb702c37cf848b450c21b9c9706b0775 ]
The move-extents range must be bounded by the inode size used for extent movement. ocfs2_ioctl_move_extents() checks and clamps the request before taking the local inode and cluster locks in ocfs2_move_extents(). It also uses separate i_size_read() calls for the range check and subtraction.
A concurrent truncate can invalidate the first check and make the later unsigned subtraction underflow:
Move-extents ioctl Truncate
------------------ --------
check me_start <= i_size
take inode and cluster locks shrink EOF below me_start release locks
compare me_start + me_len with EOF
set me_len = EOF - me_start
[unsigned underflow]
acquire inode and cluster locks
select extents using the bad range
A truncate after clamping can also leave the range extending beyond EOF. Conversely, the cached size may be smaller than the size refreshed when the cluster inode lock is acquired. Early validation can then reject a valid start or permanently shorten the requested length and threshold. The me_start + me_len comparison can also wrap for a large input length.
Validate and adjust the original request once, after inode_lock(), the exclusive rw lock and ocfs2_inode_lock() have stabilized and refreshed the size. Read EOF once, reject a start beyond it, and bound the length by EOF minus start. Normalize the threshold using the same EOF snapshot. This keeps zero as the default-threshold sentinel until validation uses the size that will govern extent movement.
Move goal validation after range adjustment as well. Its allocation-group capacity check uses me_len and must see the EOF-clamped length. Both validation failures use the existing inode-lock unwind path before any extent movement or transaction starts.
Range errors now reach the ioctl's normal copyout path, as goal errors already did. Unlike the old early rejection, a failed copyout can therefore override -EINVAL with -EFAULT.
--- fs/ocfs2/move_extents.c | 62 ++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
fs/ocfs2/move_extents.c +31 -31
@@ -906,8 +906,10 @@ static int __ocfs2_move_extents_range(struct buffer_head *di_bh,static int ocfs2_move_extents (struct ocfs2_move_extents_context *context) {int status; +u64 i_size;handle_t *handle;struct inode *inode = context->inode; +struct ocfs2_move_extents *range = context->range;struct ocfs2_dinode *di;struct buffer_head *di_bh =NULL ;struct ocfs2_super *osb =OCFS2_SB (inode->i_sb);
@@ -932,6 +934,35 @@ static int ocfs2_move_extents(struct ocfs2_move_extents_context *context) goto out_rw_unlock; } + i_size =i_size_read (inode); +if (range->me_start > i_size) { + status = -EINVAL ; +mlog_errno (status); + goto out_inode_unlock; + } + +if (range->me_len > i_size - range->me_start) + range->me_len = i_size - range->me_start; + +/* +* The default threshold for defragmentation is 1 MiB, which +* matches the maximum OCFS2 cluster size. +*/ +if (!range->me_threshold) + range->me_threshold =1024 *1024 ; + +if (range->me_threshold > i_size) + range->me_threshold = i_size; + +/* The goal check depends on the adjusted range length. */ +if (!context->auto_defrag) { + status =ocfs2_validate_and_adjust_move_goal (inode, context->range); +if (status) { +mlog_errno (status); + goto out_inode_unlock; + } + } +/* * rememer ip_xattr_sem also needs to be held if necessary */
@@ -1024,49 +1055,18 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp) goto out_free; } -if (range.me_start >i_size_read (inode)) { - status = -EINVAL ; - goto out_free; - } - -if (range.me_start + range.me_len >i_size_read (inode)) - range.me_len =i_size_read (inode) - range.me_start; - context->range = ⦥ -/* -* ok, the default theshold for the defragmentation -* is 1M, since our maximum clustersize was 1M also. -* any thought? -*/ -if (!range.me_threshold) - range.me_threshold =1024 *1024 ; - -if (range.me_threshold >i_size_read (inode)) - range.me_threshold =i_size_read (inode); -if (range.me_flags &OCFS2_MOVE_EXT_FL_AUTO_DEFRAG ) { context->auto_defrag =1 ;if (range.me_flags &OCFS2_MOVE_EXT_FL_PART_DEFRAG ) context->partial =1 ; - }else { -/* -* first best-effort attempt to validate and adjust the goal -* (physical address in block), while it can't guarantee later -* operation can succeed all the time since global_bitmap may -* change a bit over time. -*/ - - status =ocfs2_validate_and_adjust_move_goal (inode, &range); -if (status) - goto out_copy; } status =ocfs2_move_extents (context);if (status)mlog_errno (status); -out_copy:/* * movement/defragmentation may end up being partially completed, * that's the reason why we need to return userspace the finished
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1724/2857 xfs: add a flag to convert unwritten extents without allocating blocks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit f3ca3498dfe624f9b604c934263538a3acd55af5 ]
xfs_bmapi_write() with XFS_BMAPI_CONVERT also allocates blocks for holes and delalloc extents in the range. Add XFS_BMAPI_CONVERT_ONLY for callers that may only convert already allocated blocks. It stops at a hole or delalloc extent, and returns -ENOSR if it stops before mapping anything.
Marked for stable because "xfs: refuse a pNFS LAYOUTCOMMIT of a range without blocks" needs it.
--- fs/xfs/libxfs/xfs_bmap.c | 14 ++++++++++++-- fs/xfs/libxfs/xfs_bmap.h | 10 +++++++++- 2 files changed, 21 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +12 -2
@@ -4333,6 +4333,8 @@ xfs_bmapi_finish(* Returns a negative error code on failure, including -ENOSPC when it could not * allocate any blocks and -ENOSR when it did allocate blocks to convert a * delalloc range, but those blocks were before the passed in range. +* With XFS_BMAPI_CONVERT_ONLY, it stops at a hole or a delalloc extent instead +* of allocating blocks, and returns -ENOSR if it stops before mapping anything. */ int xfs_bmapi_write(
@@ -4392,6 +4394,8 @@ xfs_bmapi_write(*/ ASSERT ((flags & (XFS_BMAPI_PREALLOC |XFS_BMAPI_ZERO )) != (XFS_BMAPI_PREALLOC |XFS_BMAPI_ZERO )); +ASSERT (!(flags &XFS_BMAPI_CONVERT_ONLY ) || + (flags &XFS_BMAPI_CONVERT ));if (XFS_IS_CORRUPT (mp, !xfs_ifork_has_extents (ifp)) ||XFS_TEST_ERROR (false, mp,XFS_ERRTAG_BMAPIFORMAT )) {
@@ -4439,6 +4443,9 @@ xfs_bmapi_write(* that we found, if any. */ if (need_alloc || wasdelay) { +if (flags &XFS_BMAPI_CONVERT_ONLY ) +break ; + bma.eof = eof; bma.conv = !!(flags &XFS_BMAPI_CONVERT ); bma.wasdel = wasdelay;
@@ -4526,10 +4533,13 @@ xfs_bmapi_write(* * To avoid a successful return with *nmap set to 0, return the magic * -ENOSR error code for this particular case so that the caller can -* handle it. +* handle it. The same goes for XFS_BMAPI_CONVERT_ONLY stopping at a +* hole or a delalloc extent at the start of the range, in which case +* nothing has been changed. */ if (!n) { -ASSERT (bma.nallocs >= *nmap); +ASSERT ((flags &XFS_BMAPI_CONVERT_ONLY ) ? bma.nallocs ==0 : + bma.nallocs >= *nmap);return -ENOSR ; } *nmap = n;
fs/xfs/libxfs/xfs_bmap.h +9 -1
@@ -86,6 +86,13 @@ struct xfs_bmalloca {/* Do not update the rmap btree. Used for reconstructing bmbt from rmapbt. */ #define XFS_BMAPI_NORMAP (1u << 10) +/* +* Use with XFS_BMAPI_CONVERT to convert unwritten extents without allocating +* blocks. Stop at a hole or a delalloc extent: return the mappings found so +* far, or -ENOSR if there are none. +*/ +#define XFS_BMAPI_CONVERT_ONLY (1u << 12) +#define XFS_BMAPI_FLAGS \ { XFS_BMAPI_ENTIRE, "ENTIRE" }, \ { XFS_BMAPI_METADATA, "METADATA" }, \
@@ -97,7 +104,8 @@ struct xfs_bmalloca { { XFS_BMAPI_REMAP, "REMAP" }, \ { XFS_BMAPI_COWFORK, "COWFORK" }, \ { XFS_BMAPI_NODISCARD, "NODISCARD" }, \ - { XFS_BMAPI_NORMAP, "NORMAP" } + { XFS_BMAPI_NORMAP, "NORMAP" }, \ + { XFS_BMAPI_CONVERT_ONLY, "CONVERT_ONLY" } static inline int xfs_bmapi_aflag(int w)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1725/2857 udf: dont use eloc after the end of the unallocated space table
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit 94401199df90e1c2a50c6e4b73618ac5a4ba83ba ]
When udf_next_aext() returns 0, its eloc, elen and etype outputs hold no defined value. Two walks of the unallocated space table still use eloc after the walk has reached the end of the table.
udf_table_prealloc_blocks() looks for a free extent starting at first_block and decides whether it found one by comparing eloc with first_block after the walk. If the table's list ends in a continuation descriptor that leads to an empty allocation extent, eloc is then the block of that allocation extent, which is in use, and if that is first_block, the block is handed out as preallocation. Once udf_discard_prealloc() no longer frees the wrong block, this is what still makes fsx in generic/091 and generic/263 read back bad data on a table, in about one run in four. Only take the extent if the walk stopped at it.
When udf_table_free_blocks() cannot merge the freed blocks into an existing extent, it appends a new one and sets only its block number, so the partition reference comes from whatever eloc held after the walk, and with long allocation descriptors it is written to disk. For a table without extents, eloc was never set. Take the partition reference from the freed blocks instead. Short allocation descriptors do not store the partition reference, which is why this half remains a latent long-descriptor fix rather than a reproduced failure.
--- fs/udf/balloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/udf/balloc.c +2 -1
@@ -473,6 +473,7 @@ static void udf_table_free_blocks(struct super_block *sb,int adsize; + eloc.partitionReferenceNum = bloc->partitionReferenceNum; eloc.logicalBlockNum = start; elen =EXT_RECORDED_ALLOCATED | (count << sb->s_blocksize_bits);
@@ -545,7 +546,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb, ;/* empty loop body */ } -if (first_block == eloc.logicalBlockNum) { +if (etype !=-1 && first_block == eloc.logicalBlockNum) { epos.offset -= adsize; alloc_count = (elen >> sb->s_blocksize_bits);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1726/2857 drm/komeda: Fix bits parsing of GLB_CORE_ID
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raveendra Talabattula <[email protected]>
[ Upstream commit ec902de0221747094f9ccbb61454e9633fbf282f ]
GLB_CORE_ID contains the product and version information returned by the hardware. The current macros parses VERSION_MINOR as a 4-bit field and VERSION_STATUS as an 8-bit field, which does not match the register layout. As a result, the driver reports an incorrect version number.
Fix the parsing macros to match the hardware specification:
- VERSION_MINOR is 8 bits at [11:4]
- VERSION_STATUS is 4 bits at [3:0]
--- drivers/gpu/drm/arm/display/include/malidp_product.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/arm/display/include/malidp_product.h +7 -3
@@ -8,14 +8,18 @@#define _MALIDP_PRODUCT_H_/* Product identification */ +/* GLB_CORE_ID fields as per HW specification: +* MINOR is 8 bits ([11:4]) and STATUS is 4 bits ([3:0]). +* Update masks/shifts accordingly. +*/ #define MALIDP_CORE_ID (__product, __major, __minor, __status) \ ((((__product) & 0xFFFF) << 16) | (((__major) & 0xF) << 12) | \ - (((__minor) & 0xF) << 8) | ((__status) & 0xFF)) + (((__minor) & 0xFF) << 4) | ((__status) & 0xF))#define MALIDP_CORE_ID_PRODUCT_ID (__core_id) ((__u32)(__core_id) >> 16)#define MALIDP_CORE_ID_MAJOR (__core_id) (((__u32)(__core_id) >> 12) & 0xF) -#define MALIDP_CORE_ID_MINOR (__core_id) (((__u32)(__core_id) >> 8) & 0xF) -#define MALIDP_CORE_ID_STATUS (__core_id) (((__u32)(__core_id)) & 0xFF) +#define MALIDP_CORE_ID_MINOR (__core_id) (((__u32)(__core_id) >> 4) & 0xFF) +#define MALIDP_CORE_ID_STATUS (__core_id) ((__u32)(__core_id) & 0xF)/* Mali-display product IDs */ #define MALIDP_D71_PRODUCT_ID 0x0071
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1727/2857 drm/panfrost: Prevent division by 0
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit fd4227f03546c323b5b21568f727233e9792d298 ]
When updating and debug-printing devfreq stats, in the very unlikely off-chance that total device time is less than 100 ns, division by 0 would happen. Fix the divisor when relevant and rearrange operands.
--- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_devfreq.c +1 -1
@@ -69,7 +69,7 @@ static int panfrost_devfreq_get_dev_status(struct device *dev,dev_dbg (pfdev->dev,"busy %lu total %lu %lu %% freq %lu MHz\n" , status->busy_time, status->total_time, - status->busy_time / (status->total_time /100 ), + status->busy_time *100 /MAX (status->total_time,1 ), status->current_frequency /1000 /1000 );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1728/2857 drm/omap: dsi: avoid sending bta sync all the time in writes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andreas Kemnade <[email protected]>
[ Upstream commit 20207f78382ff339f3a7f7c5db2c0219b157d32a ]
Some chips need configuration commands to be sent first, before they can send data. TC358762 for example needs PPI_LPTXTIMECNT configured and PPI_STARTPPI set to 1 to be able to transmit anything. To be able to configure such chips, do not send bta sync during writes if no acks are requested. Instead just wait for the packet to be sent to avoid FIFO overflows. There might be more to do about acks, but there seem to be virtually no users of that flag.
This came to light when fiddling with the Epson Moverio BT-200 display which consists of 2 TC358762 bridges with SPI funneled through to the unknown display chip. With that patch the bridge can be accessed, Reading back registers works, when the above-mentioned registers are set.
In Command-Mode update, there was a nop sent, apparently the most relevant part was the bta sync to actually force low power mode.
Video mode panel at OMAP4 (BT-200) and video mode at OMAP5 was tested.
--- drivers/gpu/drm/omapdrm/dss/dsi.c | 63 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 32 deletions(-)
drivers/gpu/drm/omapdrm/dss/dsi.c +31 -32
@@ -58,9 +58,6 @@ static void dsi_uninit_dispc(struct dsi_data *dsi);static int dsi_vc_send_null (struct dsi_data *dsi,int vc,int channel); -static ssize_t _omap_dsi_host_transfer (struct dsi_data *dsi,int vc, -const struct mipi_dsi_msg *msg); -#ifdef DSI_PERF_MEASURE static bool dsi_perf;module_param (dsi_perf, bool,0644 );
@@ -2189,28 +2186,45 @@ static int dsi_vc_send_null(struct dsi_data *dsi, int vc, int channel)static int dsi_vc_write_common (struct omap_dss_device *dssdev,int vc,const struct mipi_dsi_msg *msg) { +DECLARE_COMPLETION_ONSTACK (completion);struct dsi_data *dsi =to_dsi_data (dssdev); +u32 err;int r; +/* wait for IRQ for packet transmission confirmation */ + r =dsi_register_isr_vc (dsi, vc, dsi_completion_handler, + &completion,DSI_VC_IRQ_PACKET_SENT ); +if (r) +return r; +if (mipi_dsi_packet_format_is_short (msg->type)) r =dsi_vc_send_short (dsi, vc, msg);else r =dsi_vc_send_long (dsi, vc, msg); -if (r <0 ) +if ((!r) &&wait_for_completion_timeout (&completion, +msecs_to_jiffies (500 )) ==0 ) + r = -EIO ; + +dsi_unregister_isr_vc (dsi, vc, dsi_completion_handler, + &completion,DSI_VC_IRQ_PACKET_SENT ); +if (r)return r; -/* -* TODO: we do not always have to do the BTA sync, for example -* we can improve performance by setting the update window -* information without sending BTA sync between the commands. -* In that case we can return early. -*/ +/* TODO: find out if more needs to be done for MIPI_DSI_MSG_REQ_ACK */ - r =dsi_vc_send_bta_sync (dssdev, vc); -if (r) { -DSSERR ("bta sync failed\n" ); -return r; +if (msg->flags &MIPI_DSI_MSG_REQ_ACK ) { + r =dsi_vc_send_bta_sync (dssdev, vc); +if (r) { +DSSERR ("bta sync failed\n" ); +return r; + } + }else { + err =dsi_get_errors (dsi); +if (err) { +DSSERR ("Error while sending: %x\n" , err); +return -EIO ; + } }/* RX_FIFO_NOT_EMPTY */
@@ -3228,21 +3242,6 @@ static int _dsi_update(struct dsi_data *dsi)return 0 ; } -static int _dsi_send_nop (struct dsi_data *dsi,int vc,int channel) -{ -const u8 payload[] = {MIPI_DCS_NOP }; -const struct mipi_dsi_msg msg = { - .channel = channel, - .type =MIPI_DSI_DCS_SHORT_WRITE , - .tx_len =1 , - .tx_buf = payload, - }; - -WARN_ON (!dsi_bus_is_locked (dsi)); - -return _omap_dsi_host_transfer (dsi, vc, &msg); -} -static int dsi_update_channel (struct omap_dss_device *dssdev,int vc) {struct dsi_data *dsi =to_dsi_data (dssdev);
@@ -3263,13 +3262,13 @@ static int dsi_update_channel(struct omap_dss_device *dssdev, int vc)DSSDBG ("dsi_update_channel: %d" , vc);/* -* Send NOP between the frames. If we don't send something here, the +* Transition to LP here. If we don't send something here, the * updates stop working. This is probably related to DSI spec stating * that the DSI host should transition to LP at least once per frame. */ - r =_dsi_send_nop (dsi,VC_CMD , dsi->dsidev->channel); + r =dsi_vc_send_bta_sync (dssdev,VC_CMD );if (r <0 ) { -DSSWARN ("failed to send nop between frames: %d\n" , r); +DSSWARN ("failed to send bta sync between frames: %d\n" , r); goto err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1729/2857 drm: of: Fix drm_of_get_data_lanes_count_ep() return value documentation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Vasut <[email protected]>
[ Upstream commit e3eca845ef7d6cd8c407f9b42beb45af94ff096b ]
Update drm_of_get_data_lanes_count_ep() return value documentation to match the drm_of_get_data_lanes_count() return value documentation. The drm_of_get_data_lanes_count_ep() is only a wrapper around the drm_of_get_data_lanes_count() and therefore returns the same error codes.
Simplify the return code description of drm_of_get_data_lanes_count() and drm_of_get_data_lanes_count_ep() to -ENODATA and -EINVAL.
--- drivers/gpu/drm/drm_of.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_of.c +4 -4
@@ -443,8 +443,8 @@ EXPORT_SYMBOL_GPL(drm_of_lvds_get_data_mapping);* * Return: * * min..max - positive integer count of "data-lanes" elements -* * -ve - the "data-lanes" property is missing or invalid -* * -EINVAL - the "data-lanes" property is unsupported +* * -ENODATA - the property does not have a value. +* * -EINVAL - the "data-lanes" property is missing or invalid */ int drm_of_get_data_lanes_count (const struct device_node *endpoint,const unsigned int min,const unsigned int max)
@@ -475,8 +475,8 @@ EXPORT_SYMBOL_GPL(drm_of_get_data_lanes_count);* * Return: * * min..max - positive integer count of "data-lanes" elements -* * -EINVAL - the "data-mapping" property is unsupported -* * -ENODEV - the "data-mapping" property is missing +* * -ENODATA - the property does not have a value. +* * -EINVAL - the "data-lanes" property is missing or invalid */ int drm_of_get_data_lanes_count_ep(const struct device_node *port, int port_reg, int reg,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1730/2857 bpftool: Fix spurious batch file read error
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 713c02b59e21840f623a3e31c43d967026c75181 ]
do_batch() checks errno after the read loop to detect read failures, but fgets() does not clear errno on success, so a stale errno left by a previously executed command (e.g. map dump's EBADF from a double close) makes bpftool report a batch file read failure and exit with an error even though every command succeeded.
Clear errno before each fgets() call, so the post-loop check only sees the outcome of the last read: zero on success or EOF, E2BIG for an overlong line, and a genuine errno when fgets() fails.
Since errno is now reset before every read in batch mode, drop the USE_LIBCAP errno reset in main() that existed only to keep errno clean for the batch mode.
--- tools/bpf/bpftool/main.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
tools/bpf/bpftool/main.c +5 -11
@@ -333,7 +333,11 @@ static int do_batch(int argc, char **argv)if (json_output)jsonw_start_array (json_wtr); -while (fgets (buf,sizeof (buf), fp)) { +for (;;) { + errno =0 ; +if (!fgets (buf,sizeof (buf), fp)) +break ; + cp =strchr (buf,'#' );if (cp) *cp ='\0' ;
@@ -435,16 +439,6 @@ int main(int argc, char **argv)setlinebuf (stdout); -#ifdef USE_LIBCAP -/* Libcap < 2.63 hooks before main() to compute the number of -* capabilities of the running kernel, and doing so it calls prctl() -* which may fail and set errno to non-zero. -* Let's reset errno to make sure this does not interfere with the -* batch mode. -*/ - errno =0 ; -#endif - last_do_help = do_help; pretty_output = false; json_output = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1731/2857 regulator: fixed: reject incompatible platform devices
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chandradhar Kumar <[email protected]>
[ Upstream commit f7396c2dbbc1bed6c2c554d1ddf80d16e4780a7d ]
The fixed regulator driver expects non-DT platform devices to provide their configuration through platform_data as a struct fixed_voltage_config.
An explicitly bound driver can bypass the normal platform device/driver matching and attach the fixed regulator driver to an unrelated platform device. This causes the driver's platform_data to be interpreted as a struct fixed_voltage_config even though it contains data for a different device.
Reject non-DT platform devices whose name does not match the fixed regulator driver before accessing their platform data.
--- drivers/regulator/fixed.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/regulator/fixed.c +4 -0
@@ -29,6 +29,7 @@#include <linux/regulator/of_regulator.h> #include <linux/regulator/machine.h> #include <linux/clk.h> +#include <linux/string.h> struct fixed_voltage_data {
@@ -182,6 +183,9 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)enum gpiod_flags gflags;int ret; +if (!pdev->dev.of_node &&strcmp (pdev->name,"reg-fixed-voltage" )) +return -ENODEV ; + drvdata =devm_kzalloc (&pdev->dev,sizeof (struct fixed_voltage_data ),GFP_KERNEL );if (!drvdata)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1732/2857 spi: sh-msiof: SITMDR1/SIRMDR1 bitfield conversion
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
[ Upstream commit 6bae252a9452ca8496670230a7821c34450763a2 ]
Convert MSIOF Transmit and Receive Mode Register 1 field accesses to use the FIELD_PREP() bitfield access macro.
This gets rid of explicit shifts.
Stable-dep-of: 152867998da9 ("spi: sh-msiof: propagate setup runtime-PM errors")
--- drivers/spi/spi-sh-msiof.c | 45 ++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-)
drivers/spi/spi-sh-msiof.c +24 -21
@@ -7,6 +7,7 @@* Copyright (C) 2014-2017 Glider bvba */ +#include <linux/bitfield.h> #include <linux/bitmap.h> #include <linux/clk.h> #include <linux/completion.h>
@@ -84,20 +85,19 @@ struct sh_msiof_spi_priv {/* SITMDR1 and SIRMDR1 */ #define SIMDR1_TRMD BIT(31)/* Transfer Mode (1 = Master mode) */ -#define SIMDR1_SYNCMD_MASK GENMASK(29, 28)/* SYNC Mode */ -#define SIMDR1_SYNCMD_SPI (2 << 28)/* Level mode/SPI */ -#define SIMDR1_SYNCMD_LR (3 << 28)/* L/R mode */ -#define SIMDR1_SYNCAC_SHIFT 25/* Sync Polarity (1 = Active-low) */ -#define SIMDR1_BITLSB_SHIFT 24/* MSB/LSB First (1 = LSB first) */ -#define SIMDR1_DTDL_SHIFT 20/* Data Pin Bit Delay for MSIOF_SYNC */ -#define SIMDR1_SYNCDL_SHIFT 16/* Frame Sync Signal Timing Delay */ -#define SIMDR1_FLD_MASK GENMASK(3, 2)/* Frame Sync Signal Interval (0-3) */ -#define SIMDR1_FLD_SHIFT 2 +#define SIMDR1_SYNCMD GENMASK(29, 28)/* SYNC Mode */ +#define SIMDR1_SYNCMD_SPI 2U/* Level mode/SPI */ +#define SIMDR1_SYNCMD_LR 3U/* L/R mode */ +#define SIMDR1_SYNCAC BIT(25)/* Sync Polarity (1 = Active-low) */ +#define SIMDR1_BITLSB BIT(24)/* MSB/LSB First (1 = LSB first) */ +#define SIMDR1_DTDL GENMASK(22, 20)/* Data Pin Bit Delay for MSIOF_SYNC */ +#define SIMDR1_SYNCDL GENMASK(18, 16)/* Frame Sync Signal Timing Delay */ +#define SIMDR1_FLD GENMASK(3, 2)/* Frame Sync Signal Interval (0-3) */ #define SIMDR1_XXSTP BIT(0)/* Transmission/Reception Stop on FIFO */ /* SITMDR1 */ #define SITMDR1_PCON BIT(30)/* Transfer Signal Connection */ -#define SITMDR1_SYNCCH_MASK GENMASK(27, 26)/* Sync Signal Channel Select */ -#define SITMDR1_SYNCCH_SHIFT 26/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */ +#define SITMDR1_SYNCCH GENMASK(27, 26)/* Sync Signal Channel Select */ +/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */ /* SITMDR2 and SIRMDR2 */ #define SIMDR2_BITLEN1 (i) (((i) - 1) << 24)/* Data Size (8-32 bits) */
@@ -341,8 +341,9 @@ static u32 sh_msiof_spi_get_dtdl_and_syncdl(struct sh_msiof_spi_priv *p)return 0 ; } - val =sh_msiof_get_delay_bit (p->info->dtdl) <<SIMDR1_DTDL_SHIFT ; - val |=sh_msiof_get_delay_bit (p->info->syncdl) <<SIMDR1_SYNCDL_SHIFT ; + val =FIELD_PREP (SIMDR1_DTDL ,sh_msiof_get_delay_bit (p->info->dtdl)) | +FIELD_PREP (SIMDR1_SYNCDL , +sh_msiof_get_delay_bit (p->info->syncdl));return val; }
@@ -361,16 +362,18 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss,* 1 0 11 11 0 0 * 1 1 11 11 1 1 */ - tmp =SIMDR1_SYNCMD_SPI |1 <<SIMDR1_FLD_SHIFT |SIMDR1_XXSTP ; - tmp |= !cs_high <<SIMDR1_SYNCAC_SHIFT ; - tmp |= lsb_first <<SIMDR1_BITLSB_SHIFT ; + tmp =FIELD_PREP (SIMDR1_SYNCMD ,SIMDR1_SYNCMD_SPI ) | +FIELD_PREP (SIMDR1_FLD ,1 ) |SIMDR1_XXSTP | +FIELD_PREP (SIMDR1_SYNCAC , !cs_high) | +FIELD_PREP (SIMDR1_BITLSB , lsb_first); tmp |=sh_msiof_spi_get_dtdl_and_syncdl (p);if (spi_controller_is_slave (p->ctlr)) {sh_msiof_write (p,SITMDR1 , tmp |SITMDR1_PCON ); }else {sh_msiof_write (p,SITMDR1 , tmp |SIMDR1_TRMD |SITMDR1_PCON | - (ss <MAX_SS ? ss :0 ) <<SITMDR1_SYNCCH_SHIFT ); +FIELD_PREP (SITMDR1_SYNCCH , + ss <MAX_SS ? ss :0 )); }if (p->ctlr->flags &SPI_CONTROLLER_MUST_TX ) {/* These bits are reserved if RX needs TX */
@@ -565,12 +568,12 @@ static int sh_msiof_spi_setup(struct spi_device *spi)return 0 ;/* Configure native chip select mode/polarity early */ - clr =SIMDR1_SYNCMD_MASK ; - set =SIMDR1_SYNCMD_SPI ; + clr =SIMDR1_SYNCMD ; + set =FIELD_PREP (SIMDR1_SYNCMD ,SIMDR1_SYNCMD_SPI );if (spi->mode &SPI_CS_HIGH ) - clr |=BIT (SIMDR1_SYNCAC_SHIFT ); + clr |=SIMDR1_SYNCAC ;else - set |=BIT (SIMDR1_SYNCAC_SHIFT ); + set |=SIMDR1_SYNCAC ;pm_runtime_get_sync (&p->pdev->dev); tmp =sh_msiof_read (p,SITMDR1 ) & ~clr;sh_msiof_write (p,SITMDR1 , tmp | set |SIMDR1_TRMD |SITMDR1_PCON );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1733/2857 spi: sh-msiof: propagate setup runtime-PM errors
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 152867998da9f331d6235d76aae1c7e1650708a9 ]
sh_msiof_spi_setup() ignores pm_runtime_get_sync() before programming native chip-select registers and marking the configuration initialized.
Use the checked runtime-PM helper and return failure before register access.
--- drivers/spi/spi-sh-msiof.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/spi/spi-sh-msiof.c +4 -1
@@ -559,6 +559,7 @@ static int sh_msiof_spi_setup(struct spi_device *spi)struct sh_msiof_spi_priv *p =spi_controller_get_devdata (spi->controller);u32 clr, set, tmp; +int ret;if (spi->cs_gpiod ||spi_controller_is_slave (p->ctlr))return 0 ;
@@ -574,7 +575,9 @@ static int sh_msiof_spi_setup(struct spi_device *spi) clr |=SIMDR1_SYNCAC ; else set |= SIMDR1_SYNCAC; -pm_runtime_get_sync (&p->pdev->dev); + ret =pm_runtime_resume_and_get (&p->pdev->dev); +if (ret <0 ) +return ret; tmp =sh_msiof_read (p,SITMDR1 ) & ~clr;sh_msiof_write (p,SITMDR1 , tmp | set |SIMDR1_TRMD |SITMDR1_PCON ); tmp =sh_msiof_read (p,SIRMDR1 ) & ~clr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1734/2857 iio: humidity: hts221: report available values via read_avail()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adi Nata <[email protected]>
[ Upstream commit 003e99cf33e344a380ba10b3e04ccb862f3d9dc3 ]
Replace the custom oversampling_ratio_available sysfs attributes with the standard IIO read_avail() callback. This lets the IIO core create and format *_available attributes and exposes the lists to in-kernel consumers.
As a consequence, the incorrectly named in_humidity_oversampling_ratio_available attribute is replaced by the standard in_humidityrelative_oversampling_ratio_available name for the IIO_HUMIDITYRELATIVE channel. The temperature oversampling and sampling frequency available attribute names are unchanged.
--- drivers/iio/humidity/hts221_core.c | 106 +++++++++++------------------ 1 file changed, 40 insertions(+), 66 deletions(-)
drivers/iio/humidity/hts221_core.c +40 -66
@@ -10,7 +10,6 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/device.h> -#include <linux/iio/sysfs.h> #include <linux/delay.h> #include <linux/pm.h> #include <linux/regmap.h>
@@ -48,7 +47,7 @@ struct hts221_odr {struct hts221_avg {u8 addr;u8 mask; -u16 avg_avl[HTS221_AVG_DEPTH ]; +int avg_avl[HTS221_AVG_DEPTH ]; };static const struct hts221_odr hts221_odr_table[] = {
@@ -57,6 +56,8 @@ static const struct hts221_odr hts221_odr_table[] = { { 13, 0x03 }, /* 12.5Hz */ }; +static const int hts221_odr_avail[] = { 1, 7, 13 }; + static const struct hts221_avg hts221_avg_list[] = { { .addr = 0x10,
@@ -96,7 +97,11 @@ static const struct iio_chan_spec hts221_channels[] = {BIT (IIO_CHAN_INFO_OFFSET ) |BIT (IIO_CHAN_INFO_SCALE ) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .info_mask_separate_available = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_index = 0, .scan_type = { .sign = 's',
@@ -112,7 +117,11 @@ static const struct iio_chan_spec hts221_channels[] = {BIT (IIO_CHAN_INFO_OFFSET ) |BIT (IIO_CHAN_INFO_SCALE ) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .info_mask_separate_available = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_SAMP_FREQ), .scan_index = 1, .scan_type = { .sign = 's',
@@ -191,53 +200,35 @@ static int hts221_update_avg(struct hts221_hw *hw,return 0 ; } -static ssize_t hts221_sysfs_sampling_freq (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -int i; -ssize_t len =0 ; - -for (i =0 ; i <ARRAY_SIZE (hts221_odr_table); i++) - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , - hts221_odr_table[i].hz); - buf[len -1 ] ='\n' ; - -return len; -} - -static ssize_t -hts221_sysfs_rh_oversampling_avail (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -const struct hts221_avg *avg = &hts221_avg_list[HTS221_SENSOR_H ]; -ssize_t len =0 ; -int i; - -for (i =0 ; i <ARRAY_SIZE (avg->avg_avl); i++) - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , - avg->avg_avl[i]); - buf[len -1 ] ='\n' ; - -return len; -} - -static ssize_t -hts221_sysfs_temp_oversampling_avail (struct device *dev, -struct device_attribute *attr, -char *buf) +static int hts221_read_avail (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +const int **vals,int *type,int *length, +long mask) { -const struct hts221_avg *avg = &hts221_avg_list[HTS221_SENSOR_T ]; -ssize_t len =0 ; -int i; - -for (i =0 ; i <ARRAY_SIZE (avg->avg_avl); i++) - len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , - avg->avg_avl[i]); - buf[len -1 ] ='\n' ; - -return len; +switch (mask) { +case IIO_CHAN_INFO_OVERSAMPLING_RATIO : +switch (chan->type) { +case IIO_HUMIDITYRELATIVE : + *vals = hts221_avg_list[HTS221_SENSOR_H ].avg_avl; + *length =ARRAY_SIZE (hts221_avg_list[HTS221_SENSOR_H ].avg_avl); +break ; +case IIO_TEMP : + *vals = hts221_avg_list[HTS221_SENSOR_T ].avg_avl; + *length =ARRAY_SIZE (hts221_avg_list[HTS221_SENSOR_T ].avg_avl); +break ; +default : +return -EINVAL ; + } + *type =IIO_VAL_INT ; +return IIO_AVAIL_LIST ; +case IIO_CHAN_INFO_SAMP_FREQ : + *vals = hts221_odr_avail; + *type =IIO_VAL_INT ; + *length =ARRAY_SIZE (hts221_odr_avail); +return IIO_AVAIL_LIST ; +default : +return -EINVAL ; + } }int hts221_set_enable (struct hts221_hw *hw,bool enable)
@@ -521,27 +512,10 @@ static int hts221_validate_trigger(struct iio_dev *iio_dev,return hw->trig == trig ?0 : -EINVAL ; } -static IIO_DEVICE_ATTR(in_humidity_oversampling_ratio_available, S_IRUGO, - hts221_sysfs_rh_oversampling_avail, NULL, 0); -static IIO_DEVICE_ATTR(in_temp_oversampling_ratio_available, S_IRUGO, - hts221_sysfs_temp_oversampling_avail, NULL, 0); -static IIO_DEV_ATTR_SAMP_FREQ_AVAIL (hts221_sysfs_sampling_freq); - -static struct attribute *hts221_attributes[] = { - &iio_dev_attr_sampling_frequency_available.dev_attr.attr, - &iio_dev_attr_in_humidity_oversampling_ratio_available.dev_attr.attr, - &iio_dev_attr_in_temp_oversampling_ratio_available.dev_attr.attr, -NULL , -}; - -static const struct attribute_group hts221_attribute_group = { - .attrs = hts221_attributes, -}; -static const struct iio_info hts221_info = { - .attrs = &hts221_attribute_group, .read_raw = hts221_read_raw, .write_raw = hts221_write_raw, + .read_avail = hts221_read_avail, .validate_trigger = hts221_validate_trigger, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1735/2857 dt-bindings: iio: light: ltr501: Sort compatible enum array
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esben Haabendal <[email protected]>
[ Upstream commit 6c430006fbcb63dc8baee3c3bf356b264ba7f61e ]
Restore alphabetical sorting of the properties.compatible.enum array.
Stable-dep-of: 198ed7962e42 ("dt-bindings: iio: light: ltr501: Add missing ltr303 compatible")
--- Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml +1 -1
@@ -15,9 +15,9 @@ allOf: properties: compatible: enum: + - liteon,ltr301 - liteon,ltr501 - liteon,ltr559 - - liteon,ltr301 reg: maxItems: 1
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1736/2857 dt-bindings: iio: light: ltr501: Add missing ltr303 compatible
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esben Haabendal <[email protected]>
[ Upstream commit 198ed7962e42f1e45b7f48b9abc70aad9e3185f8 ]
When support for ltr303 was back in 2021, the bindings documentation was not updated accordingly.
--- Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml +1 -0
@@ -16,6 +16,7 @@ properties: compatible: enum: - liteon,ltr301 + - liteon,ltr303 - liteon,ltr501 - liteon,ltr559
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1737/2857 iio: temperature: tmp117: fix calibbias cache update on I2C write failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Salah Triki <[email protected]>
[ Upstream commit 61fff9cebbfdf39bbd04d366882476d1def14047 ]
The calibbias cache (data->calibbias) was updated before the I2C write to TMP117_REG_TEMP_OFFSET was known to succeed. If the write failed, the function correctly returned an error, but the driver's internal cache had already been updated to the new value.
This causes the cache and the actual hardware register to go out of
sync: a subsequent write of the same value would be silently skipped by the early "if (off == data->calibbias) return 0;" check, since the cache matches even though the register was never successfully updated.
Update data->calibbias only after confirming the I2C write succeeded, so the cache always reflects the actual state of the device.
Found by code inspection.
--- drivers/iio/temperature/tmp117.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/iio/temperature/tmp117.c +7 -2
@@ -85,15 +85,20 @@ static int tmp117_write_raw(struct iio_dev *indio_dev, {struct tmp117_data *data =iio_priv (indio_dev);s16 off; +int ret;switch (mask) {case IIO_CHAN_INFO_CALIBBIAS : off =clamp_t (int, val,S16_MIN ,S16_MAX );if (off == data->calibbias)return 0 ; + + ret =i2c_smbus_write_word_swapped (data->client,TMP117_REG_TEMP_OFFSET , off); +if (ret) +return ret; + data->calibbias = off; -return i2c_smbus_write_word_swapped (data->client, -TMP117_REG_TEMP_OFFSET , off); +return 0 ;default :return -EINVAL ;
Signature · 1 line
2.53.0