On 11/18/21 10:30 AM, Kumar Kartikeya Dwivedi wrote:
On Thu, Nov 18, 2021 at 10:57:15PM IST, Yonghong Song wrote:
On 11/15/21 9:42 PM, Kumar Kartikeya Dwivedi wrote:
In CRIU, we need to be able to determine whether the page pinned by
io_uring is still present in the same range in the process VMA.
/proc/<pid>/pagemap gives us the PFN, hence using this helper we can
establish this mapping easily from the iterator side.
It is a simple wrapper over the in-kernel page_to_pfn helper, and
ensures the passed in pointer is a struct page PTR_TO_BTF_ID. This is
obtained from the bvec of io_uring_ubuf for the CRIU usecase.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
---
fs/io_uring.c | 17 +++++++++++++++++
include/linux/bpf.h | 1 +
include/uapi/linux/bpf.h | 9 +++++++++
kernel/trace/bpf_trace.c | 2 ++
scripts/bpf_doc.py | 2 ++
tools/include/uapi/linux/bpf.h | 9 +++++++++
6 files changed, 40 insertions(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 46a110989155..9e9df6767e29 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -11295,6 +11295,23 @@ static struct bpf_iter_reg io_uring_buf_reg_info = {
.seq_info = &bpf_io_uring_buf_seq_info,
};
+BPF_CALL_1(bpf_page_to_pfn, struct page *, page)
+{
+ /* PTR_TO_BTF_ID can be NULL */
+ if (!page)
+ return U64_MAX;
+ return page_to_pfn(page);
+}
+
+BTF_ID_LIST_SINGLE(btf_page_to_pfn_ids, struct, page)
+
+const struct bpf_func_proto bpf_page_to_pfn_proto = {
+ .func = bpf_page_to_pfn,
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_PTR_TO_BTF_ID,
+ .arg1_btf_id = &btf_page_to_pfn_ids[0],
Does this helper need to be gpl_only?
The typically guideline whether the same info can be retrieved from
userspace. If yes, no gpl is needed. Otherwe, it needs to be gpl.
Also, the helper is implemented in io_uring.c and the helper
is used by tracing programs. Maybe we can put the helper
in bpf_trace.c? The helper itself is not tied to io_uring, right?
Not sure about it, it wraps over a macro.
+};
+
static int __init io_uring_iter_init(void)
{
io_uring_buf_reg_info.ctx_arg_info[0].btf_id = btf_io_uring_ids[0];
[...]
--
Kartikeya