Skip to content

Commit

Permalink
Add mm/ modifications
Browse files Browse the repository at this point in the history
Signed-off-by: ShivamKumarJha <[email protected]>
  • Loading branch information
ShivamKumarJha committed Jan 19, 2022
1 parent 6b6887d commit 381fbff
Show file tree
Hide file tree
Showing 11 changed files with 596 additions and 44 deletions.
3 changes: 2 additions & 1 deletion mm/compaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* lifting
*
* Copyright IBM Corp. 2007-2010 Mel Gorman <[email protected]>
* Copyright (C) 2021 XiaoMi, Inc.
*/
#include <linux/cpu.h>
#include <linux/swap.h>
Expand Down Expand Up @@ -1905,7 +1906,7 @@ static enum compact_result __compact_finished(struct compact_control *cc)
* other migratetype buddy lists.
*/
if (find_suitable_fallback(area, order, migratetype,
true, &can_steal) != -1) {
true, &can_steal, cc->order) != -1) {

/* movable pages are OK in any pageblock */
if (migratetype == MIGRATE_MOVABLE)
Expand Down
23 changes: 21 additions & 2 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* linux/mm/filemap.c
*
* Copyright (C) 1994-1999 Linus Torvalds
* Copyright (C) 2021 XiaoMi, Inc.
*/

/*
Expand Down Expand Up @@ -955,6 +956,13 @@ int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
int ret;

__SetPageLocked(page);
#ifdef CONFIG_PERF_HUMANTASK
//page->_kworker = current->tgid ;
if (current->human_task) {
//trace_filemap_debug_einfo(page,current,"page_cache_lru",0);
}
#endif

ret = __add_to_page_cache_locked(page, mapping, offset,
gfp_mask, &shadow);
if (unlikely(ret))
Expand Down Expand Up @@ -1330,6 +1338,11 @@ void unlock_page(struct page *page)
VM_BUG_ON_PAGE(!PageLocked(page), page);
if (clear_bit_unlock_is_negative_byte(PG_locked, &page->flags))
wake_up_page_bit(page, PG_locked);
#ifdef CONFIG_PERF_HUMANTASK
if (current->human_task) {
//trace_filemap_debug_einfo(page,current,"unlock_page",0);
}
#endif
}
EXPORT_SYMBOL(unlock_page);

Expand Down Expand Up @@ -1432,10 +1445,16 @@ int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
return 0;

up_read(&mm->mmap_sem);
if (flags & FAULT_FLAG_KILLABLE)
if (flags & FAULT_FLAG_KILLABLE) {
#ifdef CONFIG_PERF_HUMANTASK
if (current->human_task) {
//trace_filemap_debug_einfo(page,current,"locked_killable",0);
}
#endif
wait_on_page_locked_killable(page);
else
} else {
wait_on_page_locked(page);
}
return 0;
} else {
if (flags & FAULT_FLAG_KILLABLE) {
Expand Down
3 changes: 2 additions & 1 deletion mm/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* internal.h: mm/ internal definitions
*
* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
* Copyright (C) 2021 XiaoMi, Inc.
* Written by David Howells ([email protected])
*/
#ifndef __MM_INTERNAL_H
Expand Down Expand Up @@ -241,7 +242,7 @@ unsigned long
isolate_migratepages_range(struct compact_control *cc,
unsigned long low_pfn, unsigned long end_pfn);
int find_suitable_fallback(struct free_area *area, unsigned int order,
int migratetype, bool only_stealable, bool *can_steal);
int migratetype, bool only_stealable, bool *can_steal, unsigned int start_order);

#endif

Expand Down
4 changes: 3 additions & 1 deletion mm/kasan/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This file contains common generic and tag-based KASAN code.
*
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
* Copyright (C) 2021 XiaoMi, Inc.
* Author: Andrey Ryabinin <[email protected]>
*
* Some code borrowed from https://github.com/xairy/kasan-prototype by
Expand Down Expand Up @@ -470,7 +471,8 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object,

kasan_set_free_info(cache, object, tag);

quarantine_put(get_free_info(cache, object), cache);
if (!quarantine_put(get_free_info(cache, object), cache))
return false;

return IS_ENABLED(CONFIG_KASAN_GENERIC);
}
Expand Down
6 changes: 3 additions & 3 deletions mm/kasan/kasan.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ struct page *kasan_addr_to_page(const void *addr);

#if defined(CONFIG_KASAN_GENERIC) && \
(defined(CONFIG_SLAB) || defined(CONFIG_SLUB))
void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache);
bool quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache);
void quarantine_reduce(void);
void quarantine_remove_cache(struct kmem_cache *cache);
#else
static inline void quarantine_put(struct kasan_free_meta *info,
struct kmem_cache *cache) { }
static inline bool quarantine_put(struct kasan_free_meta *info,
struct kmem_cache *cache) { return false; }
static inline void quarantine_reduce(void) { }
static inline void quarantine_remove_cache(struct kmem_cache *cache) { }
#endif
Expand Down
44 changes: 43 additions & 1 deletion mm/kasan/quarantine.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* Author: Alexander Potapenko <[email protected]>
* Copyright (C) 2016 Google, Inc.
* Copyright (C) 2021 XiaoMi, Inc.
*
* Based on code by Dmitry Chernenkov.
*
Expand All @@ -29,6 +30,7 @@
#include <linux/srcu.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/cpuhotplug.h>

#include "../slab.h"
#include "kasan.h"
Expand All @@ -43,6 +45,7 @@ struct qlist_head {
struct qlist_node *head;
struct qlist_node *tail;
size_t bytes;
bool offline;
};

#define QLIST_INIT { NULL, NULL, 0 }
Expand Down Expand Up @@ -170,7 +173,7 @@ static void qlist_free_all(struct qlist_head *q, struct kmem_cache *cache)
qlist_init(q);
}

void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache)
bool quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache)
{
unsigned long flags;
struct qlist_head *q;
Expand All @@ -187,6 +190,10 @@ void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache)
local_irq_save(flags);

q = this_cpu_ptr(&cpu_quarantine);
if (q->offline) {
local_irq_restore(flags);
return false;
}
qlist_put(q, &info->quarantine_link, cache->size);
if (unlikely(q->bytes > QUARANTINE_PERCPU_SIZE)) {
qlist_move_all(q, &temp);
Expand All @@ -208,6 +215,8 @@ void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache)
}

local_irq_restore(flags);

return true;
}

void quarantine_reduce(void)
Expand Down Expand Up @@ -327,3 +336,36 @@ void quarantine_remove_cache(struct kmem_cache *cache)

synchronize_srcu(&remove_cache_srcu);
}

static int kasan_cpu_online(unsigned int cpu)
{
this_cpu_ptr(&cpu_quarantine)->offline = false;
return 0;
}

static int kasan_cpu_offline(unsigned int cpu)
{
struct qlist_head *q;

q = this_cpu_ptr(&cpu_quarantine);
/* Ensure the ordering between the writing to q->offline and
* qlist_free_all. Otherwise, cpu_quarantine may be corrupted
* by interrupt.
*/
WRITE_ONCE(q->offline, true);
barrier();
qlist_free_all(q, NULL);
return 0;
}

static int __init kasan_cpu_quarantine_init(void)
{
int ret = 0;

ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mm/kasan:online",
kasan_cpu_online, kasan_cpu_offline);
if (ret < 0)
pr_err("kasan cpu quarantine register failed [%d]\n", ret);
return ret;
}
late_initcall(kasan_cpu_quarantine_init);
Loading

0 comments on commit 381fbff

Please sign in to comment.