Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'introduce bpf_find_vma'
Song Liu says: ==================== Changes v4 => v5: 1. Clean up and style change in 2/2. (Andrii) Changes v3 => v4: 1. Move mmap_unlock_work to task_iter.c to fix build for .config without !CONFIG_PERF_EVENTS. (kernel test robot <lkp@intel.com>) Changes v2 => v3: 1. Avoid using x86 only function in selftests. (Yonghong) 2. Add struct file and struct vm_area_struct to btf_task_struct_ids, and use it in bpf_find_vma and stackmap.c. (Yonghong) 3. Fix inaccurate comments. (Yonghong) Changes v1 => v2: 1. Share irq_work with stackmap.c. (Daniel) 2. Add tests for illegal writes to task/vma from the callback function. (Daniel) 3. Other small fixes. Add helper bpf_find_vma. This can be used in some profiling use cases. It might also be useful for LSM. ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Showing
13 changed files
with
466 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* Copyright (c) 2021 Facebook | ||
*/ | ||
|
||
#ifndef __MMAP_UNLOCK_WORK_H__ | ||
#define __MMAP_UNLOCK_WORK_H__ | ||
#include <linux/irq_work.h> | ||
|
||
/* irq_work to run mmap_read_unlock() in irq_work */ | ||
struct mmap_unlock_irq_work { | ||
struct irq_work irq_work; | ||
struct mm_struct *mm; | ||
}; | ||
|
||
DECLARE_PER_CPU(struct mmap_unlock_irq_work, mmap_unlock_work); | ||
|
||
/* | ||
* We cannot do mmap_read_unlock() when the irq is disabled, because of | ||
* risk to deadlock with rq_lock. To look up vma when the irqs are | ||
* disabled, we need to run mmap_read_unlock() in irq_work. We use a | ||
* percpu variable to do the irq_work. If the irq_work is already used | ||
* by another lookup, we fall over. | ||
*/ | ||
static inline bool bpf_mmap_unlock_get_irq_work(struct mmap_unlock_irq_work **work_ptr) | ||
{ | ||
struct mmap_unlock_irq_work *work = NULL; | ||
bool irq_work_busy = false; | ||
|
||
if (irqs_disabled()) { | ||
if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { | ||
work = this_cpu_ptr(&mmap_unlock_work); | ||
if (irq_work_is_busy(&work->irq_work)) { | ||
/* cannot queue more up_read, fallback */ | ||
irq_work_busy = true; | ||
} | ||
} else { | ||
/* | ||
* PREEMPT_RT does not allow to trylock mmap sem in | ||
* interrupt disabled context. Force the fallback code. | ||
*/ | ||
irq_work_busy = true; | ||
} | ||
} | ||
|
||
*work_ptr = work; | ||
return irq_work_busy; | ||
} | ||
|
||
static inline void bpf_mmap_unlock_mm(struct mmap_unlock_irq_work *work, struct mm_struct *mm) | ||
{ | ||
if (!work) { | ||
mmap_read_unlock(mm); | ||
} else { | ||
work->mm = mm; | ||
|
||
/* The lock will be released once we're out of interrupt | ||
* context. Tell lockdep that we've released it now so | ||
* it doesn't complain that we forgot to release it. | ||
*/ | ||
rwsem_release(&mm->mmap_lock.dep_map, _RET_IP_); | ||
irq_work_queue(&work->irq_work); | ||
} | ||
} | ||
|
||
#endif /* __MMAP_UNLOCK_WORK_H__ */ |
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.