Skip to content

Commit

Permalink
Merge tag 'mm-hotfixes-stable-2024-12-07-22-39' of git://git.kernel.o…
Browse files Browse the repository at this point in the history
…rg/pub/scm/linux/kernel/git/akpm/mm

Pull misc fixes from Andrew Morton:
 "24 hotfixes.  17 are cc:stable.  15 are MM and 9 are non-MM.

  The usual bunch of singletons - please see the relevant changelogs for
  details"

* tag 'mm-hotfixes-stable-2024-12-07-22-39' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (24 commits)
  iio: magnetometer: yas530: use signed integer type for clamp limits
  sched/numa: fix memory leak due to the overwritten vma->numab_state
  mm/damon: fix order of arguments in damos_before_apply tracepoint
  lib: stackinit: hide never-taken branch from compiler
  mm/filemap: don't call folio_test_locked() without a reference in next_uptodate_folio()
  scatterlist: fix incorrect func name in kernel-doc
  mm: correct typo in MMAP_STATE() macro
  mm: respect mmap hint address when aligning for THP
  mm: memcg: declare do_memsw_account inline
  mm/codetag: swap tags when migrate pages
  ocfs2: update seq_file index in ocfs2_dlm_seq_next
  stackdepot: fix stack_depot_save_flags() in NMI context
  mm: open-code page_folio() in dump_page()
  mm: open-code PageTail in folio_flags() and const_folio_flags()
  mm: fix vrealloc()'s KASAN poisoning logic
  Revert "readahead: properly shorten readahead when falling back to do_page_cache_ra()"
  selftests/damon: add _damon_sysfs.py to TEST_FILES
  selftest: hugetlb_dio: fix test naming
  ocfs2: free inode when ocfs2_get_init_inode() fails
  nilfs2: fix potential out-of-bounds memory access in nilfs_find_entry()
  ...
  • Loading branch information
torvalds committed Dec 8, 2024
2 parents 62b5a46 + f1ee548 commit 553c89e
Show file tree
Hide file tree
Showing 27 changed files with 128 additions and 88 deletions.
13 changes: 7 additions & 6 deletions drivers/iio/magnetometer/yamaha-yas530.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ static int yas537_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y
u8 data[8];
u16 xy1y2[3];
s32 h[3], s[3];
int half_range = BIT(13);
int i, ret;

mutex_lock(&yas5xx->lock);
Expand Down Expand Up @@ -406,13 +407,13 @@ static int yas537_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y
/* The second version of YAS537 needs to include calibration coefficients */
if (yas5xx->version == YAS537_VERSION_1) {
for (i = 0; i < 3; i++)
s[i] = xy1y2[i] - BIT(13);
h[0] = (c->k * (128 * s[0] + c->a2 * s[1] + c->a3 * s[2])) / BIT(13);
h[1] = (c->k * (c->a4 * s[0] + c->a5 * s[1] + c->a6 * s[2])) / BIT(13);
h[2] = (c->k * (c->a7 * s[0] + c->a8 * s[1] + c->a9 * s[2])) / BIT(13);
s[i] = xy1y2[i] - half_range;
h[0] = (c->k * (128 * s[0] + c->a2 * s[1] + c->a3 * s[2])) / half_range;
h[1] = (c->k * (c->a4 * s[0] + c->a5 * s[1] + c->a6 * s[2])) / half_range;
h[2] = (c->k * (c->a7 * s[0] + c->a8 * s[1] + c->a9 * s[2])) / half_range;
for (i = 0; i < 3; i++) {
clamp_val(h[i], -BIT(13), BIT(13) - 1);
xy1y2[i] = h[i] + BIT(13);
h[i] = clamp(h[i], -half_range, half_range - 1);
xy1y2[i] = h[i] + half_range;
}
}

Expand Down
2 changes: 1 addition & 1 deletion fs/nilfs2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static inline unsigned int nilfs_chunk_size(struct inode *inode)
*/
static unsigned int nilfs_last_byte(struct inode *inode, unsigned long page_nr)
{
unsigned int last_byte = inode->i_size;
u64 last_byte = inode->i_size;

last_byte -= page_nr << PAGE_SHIFT;
if (last_byte > PAGE_SIZE)
Expand Down
1 change: 1 addition & 0 deletions fs/ocfs2/dlmglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -3110,6 +3110,7 @@ static void *ocfs2_dlm_seq_next(struct seq_file *m, void *v, loff_t *pos)
struct ocfs2_lock_res *iter = v;
struct ocfs2_lock_res *dummy = &priv->p_iter_res;

(*pos)++;
spin_lock(&ocfs2_dlm_tracking_lock);
iter = ocfs2_dlm_next_res(iter, priv);
list_del_init(&dummy->l_debug_list);
Expand Down
4 changes: 3 additions & 1 deletion fs/ocfs2/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ static struct inode *ocfs2_get_init_inode(struct inode *dir, umode_t mode)
mode = mode_strip_sgid(&nop_mnt_idmap, dir, mode);
inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
status = dquot_initialize(inode);
if (status)
if (status) {
iput(inode);
return ERR_PTR(status);
}

return inode;
}
Expand Down
56 changes: 28 additions & 28 deletions fs/proc/vmcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,34 @@ static ssize_t read_vmcore(struct kiocb *iocb, struct iov_iter *iter)
return __read_vmcore(iter, &iocb->ki_pos);
}

/**
* vmcore_alloc_buf - allocate buffer in vmalloc memory
* @size: size of buffer
*
* If CONFIG_MMU is defined, use vmalloc_user() to allow users to mmap
* the buffer to user-space by means of remap_vmalloc_range().
*
* If CONFIG_MMU is not defined, use vzalloc() since mmap_vmcore() is
* disabled and there's no need to allow users to mmap the buffer.
*/
static inline char *vmcore_alloc_buf(size_t size)
{
#ifdef CONFIG_MMU
return vmalloc_user(size);
#else
return vzalloc(size);
#endif
}

/*
* Disable mmap_vmcore() if CONFIG_MMU is not defined. MMU is
* essential for mmap_vmcore() in order to map physically
* non-contiguous objects (ELF header, ELF note segment and memory
* regions in the 1st kernel pointed to by PT_LOAD entries) into
* virtually contiguous user-space in ELF layout.
*/
#ifdef CONFIG_MMU

/*
* The vmcore fault handler uses the page cache and fills data using the
* standard __read_vmcore() function.
Expand Down Expand Up @@ -457,34 +485,6 @@ static vm_fault_t mmap_vmcore_fault(struct vm_fault *vmf)
#endif
}

/**
* vmcore_alloc_buf - allocate buffer in vmalloc memory
* @size: size of buffer
*
* If CONFIG_MMU is defined, use vmalloc_user() to allow users to mmap
* the buffer to user-space by means of remap_vmalloc_range().
*
* If CONFIG_MMU is not defined, use vzalloc() since mmap_vmcore() is
* disabled and there's no need to allow users to mmap the buffer.
*/
static inline char *vmcore_alloc_buf(size_t size)
{
#ifdef CONFIG_MMU
return vmalloc_user(size);
#else
return vzalloc(size);
#endif
}

/*
* Disable mmap_vmcore() if CONFIG_MMU is not defined. MMU is
* essential for mmap_vmcore() in order to map physically
* non-contiguous objects (ELF header, ELF note segment and memory
* regions in the 1st kernel pointed to by PT_LOAD entries) into
* virtually contiguous user-space in ELF layout.
*/
#ifdef CONFIG_MMU

static const struct vm_operations_struct vmcore_mmap_ops = {
.fault = mmap_vmcore_fault,
};
Expand Down
4 changes: 2 additions & 2 deletions include/linux/page-flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static const unsigned long *const_folio_flags(const struct folio *folio,
{
const struct page *page = &folio->page;

VM_BUG_ON_PGFLAGS(PageTail(page), page);
VM_BUG_ON_PGFLAGS(page->compound_head & 1, page);
VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
return &page[n].flags;
}
Expand All @@ -315,7 +315,7 @@ static unsigned long *folio_flags(struct folio *folio, unsigned n)
{
struct page *page = &folio->page;

VM_BUG_ON_PGFLAGS(PageTail(page), page);
VM_BUG_ON_PGFLAGS(page->compound_head & 1, page);
VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
return &page[n].flags;
}
Expand Down
4 changes: 2 additions & 2 deletions include/linux/pgalloc_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr)
}

void pgalloc_tag_split(struct folio *folio, int old_order, int new_order);
void pgalloc_tag_copy(struct folio *new, struct folio *old);
void pgalloc_tag_swap(struct folio *new, struct folio *old);

void __init alloc_tag_sec_init(void);

Expand All @@ -245,7 +245,7 @@ static inline struct alloc_tag *pgalloc_tag_get(struct page *page) { return NULL
static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) {}
static inline void alloc_tag_sec_init(void) {}
static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order) {}
static inline void pgalloc_tag_copy(struct folio *new, struct folio *old) {}
static inline void pgalloc_tag_swap(struct folio *new, struct folio *old) {}

#endif /* CONFIG_MEM_ALLOC_PROFILING */

Expand Down
2 changes: 1 addition & 1 deletion include/linux/scatterlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static inline void sg_dma_mark_bus_address(struct scatterlist *sg)
}

/**
* sg_unmark_bus_address - Unmark the scatterlist entry as a bus address
* sg_dma_unmark_bus_address - Unmark the scatterlist entry as a bus address
* @sg: SG entry
*
* Description:
Expand Down
6 changes: 3 additions & 3 deletions include/linux/stackdepot.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static inline int stack_depot_early_init(void) { return 0; }
* If the provided stack trace comes from the interrupt context, only the part
* up to the interrupt entry is saved.
*
* Context: Any context, but setting STACK_DEPOT_FLAG_CAN_ALLOC is required if
* Context: Any context, but unsetting STACK_DEPOT_FLAG_CAN_ALLOC is required if
* alloc_pages() cannot be used from the current context. Currently
* this is the case for contexts where neither %GFP_ATOMIC nor
* %GFP_NOWAIT can be used (NMI, raw_spin_lock).
Expand All @@ -156,7 +156,7 @@ static inline int stack_depot_early_init(void) { return 0; }
*/
depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,
unsigned int nr_entries,
gfp_t gfp_flags,
gfp_t alloc_flags,
depot_flags_t depot_flags);

/**
Expand All @@ -175,7 +175,7 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,
* Return: Handle of the stack trace stored in depot, 0 on failure
*/
depot_stack_handle_t stack_depot_save(unsigned long *entries,
unsigned int nr_entries, gfp_t gfp_flags);
unsigned int nr_entries, gfp_t alloc_flags);

/**
* __stack_depot_get_stack_record - Get a pointer to a stack_record struct
Expand Down
2 changes: 1 addition & 1 deletion include/trace/events/damon.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TRACE_EVENT_CONDITION(damos_before_apply,
unsigned int target_idx, struct damon_region *r,
unsigned int nr_regions, bool do_trace),

TP_ARGS(context_idx, target_idx, scheme_idx, r, nr_regions, do_trace),
TP_ARGS(context_idx, scheme_idx, target_idx, r, nr_regions, do_trace),

TP_CONDITION(do_trace),

Expand Down
12 changes: 9 additions & 3 deletions kernel/sched/fair.c
Original file line number Diff line number Diff line change
Expand Up @@ -3399,10 +3399,16 @@ static void task_numa_work(struct callback_head *work)

/* Initialise new per-VMA NUMAB state. */
if (!vma->numab_state) {
vma->numab_state = kzalloc(sizeof(struct vma_numab_state),
GFP_KERNEL);
if (!vma->numab_state)
struct vma_numab_state *ptr;

ptr = kzalloc(sizeof(*ptr), GFP_KERNEL);
if (!ptr)
continue;

if (cmpxchg(&vma->numab_state, NULL, ptr)) {
kfree(ptr);
continue;
}

vma->numab_state->start_scan_seq = mm->numa_scan_seq;

Expand Down
36 changes: 22 additions & 14 deletions lib/alloc_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,34 @@ void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
}
}

void pgalloc_tag_copy(struct folio *new, struct folio *old)
void pgalloc_tag_swap(struct folio *new, struct folio *old)
{
union pgtag_ref_handle handle;
union codetag_ref ref;
struct alloc_tag *tag;
union pgtag_ref_handle handle_old, handle_new;
union codetag_ref ref_old, ref_new;
struct alloc_tag *tag_old, *tag_new;

tag = pgalloc_tag_get(&old->page);
if (!tag)
tag_old = pgalloc_tag_get(&old->page);
if (!tag_old)
return;
tag_new = pgalloc_tag_get(&new->page);
if (!tag_new)
return;

if (!get_page_tag_ref(&new->page, &ref, &handle))
if (!get_page_tag_ref(&old->page, &ref_old, &handle_old))
return;
if (!get_page_tag_ref(&new->page, &ref_new, &handle_new)) {
put_page_tag_ref(handle_old);
return;
}

/* swap tags */
__alloc_tag_ref_set(&ref_old, tag_new);
update_page_tag_ref(handle_old, &ref_old);
__alloc_tag_ref_set(&ref_new, tag_old);
update_page_tag_ref(handle_new, &ref_new);

/* Clear the old ref to the original allocation tag. */
clear_page_tag_ref(&old->page);
/* Decrement the counters of the tag on get_new_folio. */
alloc_tag_sub(&ref, folio_size(new));
__alloc_tag_ref_set(&ref, tag);
update_page_tag_ref(handle, &ref);
put_page_tag_ref(handle);
put_page_tag_ref(handle_old);
put_page_tag_ref(handle_new);
}

static void shutdown_mem_profiling(bool remove_file)
Expand Down
10 changes: 9 additions & 1 deletion lib/stackdepot.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,15 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,
prealloc = page_address(page);
}

raw_spin_lock_irqsave(&pool_lock, flags);
if (in_nmi()) {
/* We can never allocate in NMI context. */
WARN_ON_ONCE(can_alloc);
/* Best effort; bail if we fail to take the lock. */
if (!raw_spin_trylock_irqsave(&pool_lock, flags))
goto exit;
} else {
raw_spin_lock_irqsave(&pool_lock, flags);
}
printk_deferred_enter();

/* Try to find again, to avoid concurrently inserting duplicates. */
Expand Down
1 change: 1 addition & 0 deletions lib/stackinit_kunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ static noinline void test_ ## name (struct kunit *test) \
static noinline DO_NOTHING_TYPE_ ## which(var_type) \
do_nothing_ ## name(var_type *ptr) \
{ \
OPTIMIZER_HIDE_VAR(ptr); \
/* Will always be true, but compiler doesn't know. */ \
if ((unsigned long)ptr > 0x2) \
return DO_NOTHING_RETURN_ ## which(ptr); \
Expand Down
7 changes: 5 additions & 2 deletions mm/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,22 @@ static void __dump_page(const struct page *page)
{
struct folio *foliop, folio;
struct page precise;
unsigned long head;
unsigned long pfn = page_to_pfn(page);
unsigned long idx, nr_pages = 1;
int loops = 5;

again:
memcpy(&precise, page, sizeof(*page));
foliop = page_folio(&precise);
if (foliop == (struct folio *)&precise) {
head = precise.compound_head;
if ((head & 1) == 0) {
foliop = (struct folio *)&precise;
idx = 0;
if (!folio_test_large(foliop))
goto dump;
foliop = (struct folio *)page;
} else {
foliop = (struct folio *)(head - 1);
idx = folio_page_idx(foliop, page);
}

Expand Down
4 changes: 2 additions & 2 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3501,10 +3501,10 @@ static struct folio *next_uptodate_folio(struct xa_state *xas,
continue;
if (xa_is_value(folio))
continue;
if (folio_test_locked(folio))
continue;
if (!folio_try_get(folio))
continue;
if (folio_test_locked(folio))
goto skip;
/* Has the page moved or been split? */
if (unlikely(folio != xas_reload(xas)))
goto skip;
Expand Down
11 changes: 10 additions & 1 deletion mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ static inline void sanity_check_pinned_pages(struct page **pages,
*/
for (; npages; npages--, pages++) {
struct page *page = *pages;
struct folio *folio = page_folio(page);
struct folio *folio;

if (!page)
continue;

folio = page_folio(page);

if (is_zero_page(page) ||
!folio_test_anon(folio))
Expand Down Expand Up @@ -409,6 +414,10 @@ void unpin_user_pages(struct page **pages, unsigned long npages)

sanity_check_pinned_pages(pages, npages);
for (i = 0; i < npages; i += nr) {
if (!pages[i]) {
nr = 1;
continue;
}
folio = gup_folio_next(pages, npages, i, &nr);
gup_put_folio(folio, nr, FOLL_PIN);
}
Expand Down
6 changes: 3 additions & 3 deletions mm/kasan/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static inline void fail_non_kasan_kunit_test(void) { }

#endif /* CONFIG_KUNIT */

static DEFINE_SPINLOCK(report_lock);
static DEFINE_RAW_SPINLOCK(report_lock);

static void start_report(unsigned long *flags, bool sync)
{
Expand All @@ -212,7 +212,7 @@ static void start_report(unsigned long *flags, bool sync)
lockdep_off();
/* Make sure we don't end up in loop. */
report_suppress_start();
spin_lock_irqsave(&report_lock, *flags);
raw_spin_lock_irqsave(&report_lock, *flags);
pr_err("==================================================================\n");
}

Expand All @@ -222,7 +222,7 @@ static void end_report(unsigned long *flags, const void *addr, bool is_write)
trace_error_report_end(ERROR_DETECTOR_KASAN,
(unsigned long)addr);
pr_err("==================================================================\n");
spin_unlock_irqrestore(&report_lock, *flags);
raw_spin_unlock_irqrestore(&report_lock, *flags);
if (!test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags))
check_panic_on_warn("KASAN");
switch (kasan_arg_fault) {
Expand Down
Loading

0 comments on commit 553c89e

Please sign in to comment.