-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ShivamKumarJha <[email protected]>
- Loading branch information
1 parent
2ec729d
commit 83a3b45
Showing
12 changed files
with
587 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
* | ||
|
@@ -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" | ||
|
@@ -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 } | ||
|
@@ -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; | ||
} | ||
qlist_put(q, &info->quarantine_link, cache->size); | ||
if (unlikely(q->bytes > QUARANTINE_PERCPU_SIZE)) { | ||
qlist_move_all(q, &temp); | ||
|
@@ -327,3 +334,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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.