|
|
@@ -8,7 +8,7 @@
|
|
|
|
#include <linux/srcu.h>
|
|
|
|
#include <linux/srcu.h>
|
|
|
|
#include <linux/interval_tree.h>
|
|
|
|
#include <linux/interval_tree.h>
|
|
|
|
|
|
|
|
|
|
|
|
struct mmu_notifier_mm;
|
|
|
|
struct mmu_notifier_subscriptions;
|
|
|
|
struct mmu_notifier;
|
|
|
|
struct mmu_notifier;
|
|
|
|
struct mmu_notifier_range;
|
|
|
|
struct mmu_notifier_range;
|
|
|
|
struct mmu_interval_notifier;
|
|
|
|
struct mmu_interval_notifier;
|
|
|
@@ -73,7 +73,7 @@ struct mmu_notifier_ops {
|
|
|
|
* through the gart alias address, so leading to memory
|
|
|
|
* through the gart alias address, so leading to memory
|
|
|
|
* corruption.
|
|
|
|
* corruption.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void (*release)(struct mmu_notifier *mn,
|
|
|
|
void (*release)(struct mmu_notifier *subscription,
|
|
|
|
struct mm_struct *mm);
|
|
|
|
struct mm_struct *mm);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@@ -85,7 +85,7 @@ struct mmu_notifier_ops {
|
|
|
|
* Start-end is necessary in case the secondary MMU is mapping the page
|
|
|
|
* Start-end is necessary in case the secondary MMU is mapping the page
|
|
|
|
* at a smaller granularity than the primary MMU.
|
|
|
|
* at a smaller granularity than the primary MMU.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int (*clear_flush_young)(struct mmu_notifier *mn,
|
|
|
|
int (*clear_flush_young)(struct mmu_notifier *subscription,
|
|
|
|
struct mm_struct *mm,
|
|
|
|
struct mm_struct *mm,
|
|
|
|
unsigned long start,
|
|
|
|
unsigned long start,
|
|
|
|
unsigned long end);
|
|
|
|
unsigned long end);
|
|
|
@@ -95,7 +95,7 @@ struct mmu_notifier_ops {
|
|
|
|
* latter, it is supposed to test-and-clear the young/accessed bitflag
|
|
|
|
* latter, it is supposed to test-and-clear the young/accessed bitflag
|
|
|
|
* in the secondary pte, but it may omit flushing the secondary tlb.
|
|
|
|
* in the secondary pte, but it may omit flushing the secondary tlb.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int (*clear_young)(struct mmu_notifier *mn,
|
|
|
|
int (*clear_young)(struct mmu_notifier *subscription,
|
|
|
|
struct mm_struct *mm,
|
|
|
|
struct mm_struct *mm,
|
|
|
|
unsigned long start,
|
|
|
|
unsigned long start,
|
|
|
|
unsigned long end);
|
|
|
|
unsigned long end);
|
|
|
@@ -106,7 +106,7 @@ struct mmu_notifier_ops {
|
|
|
|
* frequently used without actually clearing the flag or tearing
|
|
|
|
* frequently used without actually clearing the flag or tearing
|
|
|
|
* down the secondary mapping on the page.
|
|
|
|
* down the secondary mapping on the page.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int (*test_young)(struct mmu_notifier *mn,
|
|
|
|
int (*test_young)(struct mmu_notifier *subscription,
|
|
|
|
struct mm_struct *mm,
|
|
|
|
struct mm_struct *mm,
|
|
|
|
unsigned long address);
|
|
|
|
unsigned long address);
|
|
|
|
|
|
|
|
|
|
|
@@ -114,7 +114,7 @@ struct mmu_notifier_ops {
|
|
|
|
* change_pte is called in cases that pte mapping to page is changed:
|
|
|
|
* change_pte is called in cases that pte mapping to page is changed:
|
|
|
|
* for example, when ksm remaps pte to point to a new shared page.
|
|
|
|
* for example, when ksm remaps pte to point to a new shared page.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void (*change_pte)(struct mmu_notifier *mn,
|
|
|
|
void (*change_pte)(struct mmu_notifier *subscription,
|
|
|
|
struct mm_struct *mm,
|
|
|
|
struct mm_struct *mm,
|
|
|
|
unsigned long address,
|
|
|
|
unsigned long address,
|
|
|
|
pte_t pte);
|
|
|
|
pte_t pte);
|
|
|
@@ -169,9 +169,9 @@ struct mmu_notifier_ops {
|
|
|
|
* invalidate_range_end.
|
|
|
|
* invalidate_range_end.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int (*invalidate_range_start)(struct mmu_notifier *mn,
|
|
|
|
int (*invalidate_range_start)(struct mmu_notifier *subscription,
|
|
|
|
const struct mmu_notifier_range *range);
|
|
|
|
const struct mmu_notifier_range *range);
|
|
|
|
void (*invalidate_range_end)(struct mmu_notifier *mn,
|
|
|
|
void (*invalidate_range_end)(struct mmu_notifier *subscription,
|
|
|
|
const struct mmu_notifier_range *range);
|
|
|
|
const struct mmu_notifier_range *range);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@@ -192,8 +192,10 @@ struct mmu_notifier_ops {
|
|
|
|
* of what was passed to invalidate_range_start()/end(), if
|
|
|
|
* of what was passed to invalidate_range_start()/end(), if
|
|
|
|
* called between those functions.
|
|
|
|
* called between those functions.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void (*invalidate_range)(struct mmu_notifier *mn, struct mm_struct *mm,
|
|
|
|
void (*invalidate_range)(struct mmu_notifier *subscription,
|
|
|
|
unsigned long start, unsigned long end);
|
|
|
|
struct mm_struct *mm,
|
|
|
|
|
|
|
|
unsigned long start,
|
|
|
|
|
|
|
|
unsigned long end);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* These callbacks are used with the get/put interface to manage the
|
|
|
|
* These callbacks are used with the get/put interface to manage the
|
|
|
@@ -206,7 +208,7 @@ struct mmu_notifier_ops {
|
|
|
|
* and cannot sleep.
|
|
|
|
* and cannot sleep.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
struct mmu_notifier *(*alloc_notifier)(struct mm_struct *mm);
|
|
|
|
struct mmu_notifier *(*alloc_notifier)(struct mm_struct *mm);
|
|
|
|
void (*free_notifier)(struct mmu_notifier *mn);
|
|
|
|
void (*free_notifier)(struct mmu_notifier *subscription);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@@ -235,7 +237,7 @@ struct mmu_notifier {
|
|
|
|
* was required but mmu_notifier_range_blockable(range) is false.
|
|
|
|
* was required but mmu_notifier_range_blockable(range) is false.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
struct mmu_interval_notifier_ops {
|
|
|
|
struct mmu_interval_notifier_ops {
|
|
|
|
bool (*invalidate)(struct mmu_interval_notifier *mni,
|
|
|
|
bool (*invalidate)(struct mmu_interval_notifier *interval_sub,
|
|
|
|
const struct mmu_notifier_range *range,
|
|
|
|
const struct mmu_notifier_range *range,
|
|
|
|
unsigned long cur_seq);
|
|
|
|
unsigned long cur_seq);
|
|
|
|
};
|
|
|
|
};
|
|
|
@@ -265,7 +267,7 @@ struct mmu_notifier_range {
|
|
|
|
|
|
|
|
|
|
|
|
static inline int mm_has_notifiers(struct mm_struct *mm)
|
|
|
|
static inline int mm_has_notifiers(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return unlikely(mm->mmu_notifier_mm);
|
|
|
|
return unlikely(mm->notifier_subscriptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct mmu_notifier *mmu_notifier_get_locked(const struct mmu_notifier_ops *ops,
|
|
|
|
struct mmu_notifier *mmu_notifier_get_locked(const struct mmu_notifier_ops *ops,
|
|
|
@@ -280,30 +282,31 @@ mmu_notifier_get(const struct mmu_notifier_ops *ops, struct mm_struct *mm)
|
|
|
|
up_write(&mm->mmap_sem);
|
|
|
|
up_write(&mm->mmap_sem);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void mmu_notifier_put(struct mmu_notifier *mn);
|
|
|
|
void mmu_notifier_put(struct mmu_notifier *subscription);
|
|
|
|
void mmu_notifier_synchronize(void);
|
|
|
|
void mmu_notifier_synchronize(void);
|
|
|
|
|
|
|
|
|
|
|
|
extern int mmu_notifier_register(struct mmu_notifier *mn,
|
|
|
|
extern int mmu_notifier_register(struct mmu_notifier *subscription,
|
|
|
|
struct mm_struct *mm);
|
|
|
|
struct mm_struct *mm);
|
|
|
|
extern int __mmu_notifier_register(struct mmu_notifier *mn,
|
|
|
|
extern int __mmu_notifier_register(struct mmu_notifier *subscription,
|
|
|
|
struct mm_struct *mm);
|
|
|
|
struct mm_struct *mm);
|
|
|
|
extern void mmu_notifier_unregister(struct mmu_notifier *mn,
|
|
|
|
extern void mmu_notifier_unregister(struct mmu_notifier *subscription,
|
|
|
|
struct mm_struct *mm);
|
|
|
|
struct mm_struct *mm);
|
|
|
|
|
|
|
|
|
|
|
|
unsigned long mmu_interval_read_begin(struct mmu_interval_notifier *mni);
|
|
|
|
unsigned long
|
|
|
|
int mmu_interval_notifier_insert(struct mmu_interval_notifier *mni,
|
|
|
|
mmu_interval_read_begin(struct mmu_interval_notifier *interval_sub);
|
|
|
|
|
|
|
|
int mmu_interval_notifier_insert(struct mmu_interval_notifier *interval_sub,
|
|
|
|
struct mm_struct *mm, unsigned long start,
|
|
|
|
struct mm_struct *mm, unsigned long start,
|
|
|
|
unsigned long length,
|
|
|
|
unsigned long length,
|
|
|
|
const struct mmu_interval_notifier_ops *ops);
|
|
|
|
const struct mmu_interval_notifier_ops *ops);
|
|
|
|
int mmu_interval_notifier_insert_locked(
|
|
|
|
int mmu_interval_notifier_insert_locked(
|
|
|
|
struct mmu_interval_notifier *mni, struct mm_struct *mm,
|
|
|
|
struct mmu_interval_notifier *interval_sub, struct mm_struct *mm,
|
|
|
|
unsigned long start, unsigned long length,
|
|
|
|
unsigned long start, unsigned long length,
|
|
|
|
const struct mmu_interval_notifier_ops *ops);
|
|
|
|
const struct mmu_interval_notifier_ops *ops);
|
|
|
|
void mmu_interval_notifier_remove(struct mmu_interval_notifier *mni);
|
|
|
|
void mmu_interval_notifier_remove(struct mmu_interval_notifier *interval_sub);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* mmu_interval_set_seq - Save the invalidation sequence
|
|
|
|
* mmu_interval_set_seq - Save the invalidation sequence
|
|
|
|
* @mni - The mni passed to invalidate
|
|
|
|
* @interval_sub - The subscription passed to invalidate
|
|
|
|
* @cur_seq - The cur_seq passed to the invalidate() callback
|
|
|
|
* @cur_seq - The cur_seq passed to the invalidate() callback
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This must be called unconditionally from the invalidate callback of a
|
|
|
|
* This must be called unconditionally from the invalidate callback of a
|
|
|
@@ -314,15 +317,16 @@ void mmu_interval_notifier_remove(struct mmu_interval_notifier *mni);
|
|
|
|
* If the caller does not call mmu_interval_read_begin() or
|
|
|
|
* If the caller does not call mmu_interval_read_begin() or
|
|
|
|
* mmu_interval_read_retry() then this call is not required.
|
|
|
|
* mmu_interval_read_retry() then this call is not required.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static inline void mmu_interval_set_seq(struct mmu_interval_notifier *mni,
|
|
|
|
static inline void
|
|
|
|
|
|
|
|
mmu_interval_set_seq(struct mmu_interval_notifier *interval_sub,
|
|
|
|
unsigned long cur_seq)
|
|
|
|
unsigned long cur_seq)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
WRITE_ONCE(mni->invalidate_seq, cur_seq);
|
|
|
|
WRITE_ONCE(interval_sub->invalidate_seq, cur_seq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* mmu_interval_read_retry - End a read side critical section against a VA range
|
|
|
|
* mmu_interval_read_retry - End a read side critical section against a VA range
|
|
|
|
* mni: The range
|
|
|
|
* interval_sub: The subscription
|
|
|
|
* seq: The return of the paired mmu_interval_read_begin()
|
|
|
|
* seq: The return of the paired mmu_interval_read_begin()
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This MUST be called under a user provided lock that is also held
|
|
|
|
* This MUST be called under a user provided lock that is also held
|
|
|
@@ -334,15 +338,16 @@ static inline void mmu_interval_set_seq(struct mmu_interval_notifier *mni,
|
|
|
|
* Returns true if an invalidation collided with this critical section, and
|
|
|
|
* Returns true if an invalidation collided with this critical section, and
|
|
|
|
* the caller should retry.
|
|
|
|
* the caller should retry.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static inline bool mmu_interval_read_retry(struct mmu_interval_notifier *mni,
|
|
|
|
static inline bool
|
|
|
|
|
|
|
|
mmu_interval_read_retry(struct mmu_interval_notifier *interval_sub,
|
|
|
|
unsigned long seq)
|
|
|
|
unsigned long seq)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return mni->invalidate_seq != seq;
|
|
|
|
return interval_sub->invalidate_seq != seq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* mmu_interval_check_retry - Test if a collision has occurred
|
|
|
|
* mmu_interval_check_retry - Test if a collision has occurred
|
|
|
|
* mni: The range
|
|
|
|
* interval_sub: The subscription
|
|
|
|
* seq: The return of the matching mmu_interval_read_begin()
|
|
|
|
* seq: The return of the matching mmu_interval_read_begin()
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This can be used in the critical section between mmu_interval_read_begin()
|
|
|
|
* This can be used in the critical section between mmu_interval_read_begin()
|
|
|
@@ -357,14 +362,15 @@ static inline bool mmu_interval_read_retry(struct mmu_interval_notifier *mni,
|
|
|
|
* This call can be used as part of loops and other expensive operations to
|
|
|
|
* This call can be used as part of loops and other expensive operations to
|
|
|
|
* expedite a retry.
|
|
|
|
* expedite a retry.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static inline bool mmu_interval_check_retry(struct mmu_interval_notifier *mni,
|
|
|
|
static inline bool
|
|
|
|
|
|
|
|
mmu_interval_check_retry(struct mmu_interval_notifier *interval_sub,
|
|
|
|
unsigned long seq)
|
|
|
|
unsigned long seq)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Pairs with the WRITE_ONCE in mmu_interval_set_seq() */
|
|
|
|
/* Pairs with the WRITE_ONCE in mmu_interval_set_seq() */
|
|
|
|
return READ_ONCE(mni->invalidate_seq) != seq;
|
|
|
|
return READ_ONCE(interval_sub->invalidate_seq) != seq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern void __mmu_notifier_mm_destroy(struct mm_struct *mm);
|
|
|
|
extern void __mmu_notifier_subscriptions_destroy(struct mm_struct *mm);
|
|
|
|
extern void __mmu_notifier_release(struct mm_struct *mm);
|
|
|
|
extern void __mmu_notifier_release(struct mm_struct *mm);
|
|
|
|
extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
|
|
|
|
extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
|
|
|
|
unsigned long start,
|
|
|
|
unsigned long start,
|
|
|
@@ -480,15 +486,15 @@ static inline void mmu_notifier_invalidate_range(struct mm_struct *mm,
|
|
|
|
__mmu_notifier_invalidate_range(mm, start, end);
|
|
|
|
__mmu_notifier_invalidate_range(mm, start, end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void mmu_notifier_mm_init(struct mm_struct *mm)
|
|
|
|
static inline void mmu_notifier_subscriptions_init(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mm->mmu_notifier_mm = NULL;
|
|
|
|
mm->notifier_subscriptions = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
|
|
|
|
static inline void mmu_notifier_subscriptions_destroy(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mm_has_notifiers(mm))
|
|
|
|
if (mm_has_notifiers(mm))
|
|
|
|
__mmu_notifier_mm_destroy(mm);
|
|
|
|
__mmu_notifier_subscriptions_destroy(mm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -692,11 +698,11 @@ static inline void mmu_notifier_invalidate_range(struct mm_struct *mm,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void mmu_notifier_mm_init(struct mm_struct *mm)
|
|
|
|
static inline void mmu_notifier_subscriptions_init(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
|
|
|
|
static inline void mmu_notifier_subscriptions_destroy(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|