From: Peter Zijlstra <peterz@infradead.org>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: x86@kernel.org, Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
linux-kernel@vger.kernel.org,
Indu Bhagat <indu.bhagat@oracle.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
linux-perf-users@vger.kernel.org, Mark Brown <broonie@kernel.org>,
linux-toolchains@vger.kernel.org, Jordan Rome <jordalgo@meta.com>,
Sam James <sam@gentoo.org>,
linux-trace-kernel@vger.kerne.org,
Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Jens Remus <jremus@linux.ibm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Florian Weimer <fweimer@redhat.com>,
Andy Lutomirski <luto@kernel.org>
Subject: Re: [PATCH v3 09/19] unwind: Introduce sframe user space unwinding
Date: Tue, 29 Oct 2024 14:27:09 +0100 [thread overview]
Message-ID: <20241029132709.GY14555@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <42c0a99236af65c09c8182e260af7bcf5aa1e158.1730150953.git.jpoimboe@kernel.org>
On Mon, Oct 28, 2024 at 02:47:36PM -0700, Josh Poimboeuf wrote:
> +static int __sframe_add_section(unsigned long sframe_addr,
> + unsigned long text_start,
> + unsigned long text_end)
> +{
> + struct maple_tree *sframe_mt = ¤t->mm->sframe_mt;
> + struct sframe_section *sec;
> + struct sframe_header shdr;
> + unsigned long header_end;
> + int ret;
> +
> + if (copy_from_user(&shdr, (void __user *)sframe_addr, sizeof(shdr)))
> + return -EFAULT;
> +
> + if (shdr.preamble.magic != SFRAME_MAGIC ||
> + shdr.preamble.version != SFRAME_VERSION_2 ||
> + !(shdr.preamble.flags & SFRAME_F_FDE_SORTED) ||
> + shdr.auxhdr_len || !shdr.num_fdes || !shdr.num_fres ||
> + shdr.fdes_off > shdr.fres_off) {
> + return -EINVAL;
> + }
> +
> + sec = kmalloc(sizeof(*sec), GFP_KERNEL);
> + if (!sec)
> + return -ENOMEM;
> +
> + header_end = sframe_addr + SFRAME_HDR_SIZE(shdr);
> +
> + sec->sframe_addr = sframe_addr;
> + sec->text_addr = text_start;
> + sec->fdes_addr = header_end + shdr.fdes_off;
> + sec->fres_addr = header_end + shdr.fres_off;
> + sec->fdes_nr = shdr.num_fdes;
> + sec->ra_off = shdr.cfa_fixed_ra_offset;
> + sec->fp_off = shdr.cfa_fixed_fp_offset;
> +
> + ret = mtree_insert_range(sframe_mt, text_start, text_end, sec, GFP_KERNEL);
> + if (ret) {
> + kfree(sec);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +int sframe_add_section(unsigned long sframe_addr, unsigned long text_start,
> + unsigned long text_end)
> +{
> + struct mm_struct *mm = current->mm;
> + struct vm_area_struct *sframe_vma;
> +
> + mmap_read_lock(mm);
DEFINE_GUARD(mmap_read_lock, struct mm_struct *,
mmap_read_lock(_T), mmap_read_unlock(_T))
in include/linux/mmap_lock.h ?
> +
> + sframe_vma = vma_lookup(mm, sframe_addr);
> + if (!sframe_vma)
> + goto err_unlock;
> +
> + if (text_start && text_end) {
> + struct vm_area_struct *text_vma;
> +
> + text_vma = vma_lookup(mm, text_start);
> + if (!(text_vma->vm_flags & VM_EXEC))
> + goto err_unlock;
> +
> + if (PAGE_ALIGN(text_end) != text_vma->vm_end)
> + goto err_unlock;
> + } else {
> + struct vm_area_struct *vma, *text_vma = NULL;
> + VMA_ITERATOR(vmi, mm, 0);
> +
> + for_each_vma(vmi, vma) {
> + if (vma->vm_file != sframe_vma->vm_file ||
> + !(vma->vm_flags & VM_EXEC))
> + continue;
> +
> + if (text_vma) {
> + pr_warn_once("%s[%d]: multiple EXEC segments unsupported\n",
> + current->comm, current->pid);
> + goto err_unlock;
> + }
> +
> + text_vma = vma;
> + }
> +
> + if (!text_vma)
> + goto err_unlock;
> +
> + text_start = text_vma->vm_start;
> + text_end = text_vma->vm_end;
> + }
> +
> + mmap_read_unlock(mm);
> +
> + return __sframe_add_section(sframe_addr, text_start, text_end);
> +
> +err_unlock:
> + mmap_read_unlock(mm);
> + return -EINVAL;
> +}
> +int sframe_remove_section(unsigned long sframe_addr)
> +{
> + struct mm_struct *mm = current->mm;
> + struct sframe_section *sec;
> + unsigned long index = 0;
> +
> + mt_for_each(&mm->sframe_mt, sec, index, ULONG_MAX) {
> + if (sec->sframe_addr == sframe_addr)
> + return __sframe_remove_section(mm, sec);
> + }
> +
> + return -EINVAL;
> +}
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -64,6 +64,7 @@
> #include <linux/rcupdate.h>
> #include <linux/uidgid.h>
> #include <linux/cred.h>
> +#include <linux/sframe.h>
>
> #include <linux/nospec.h>
>
> @@ -2784,6 +2785,16 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
> case PR_RISCV_SET_ICACHE_FLUSH_CTX:
> error = RISCV_SET_ICACHE_FLUSH_CTX(arg2, arg3);
> break;
> + case PR_ADD_SFRAME:
> + if (arg5)
> + return -EINVAL;
> + error = sframe_add_section(arg2, arg3, arg4);
> + break;
> + case PR_REMOVE_SFRAME:
> + if (arg3 || arg4 || arg5)
> + return -EINVAL;
> + error = sframe_remove_section(arg2);
> + break;
> default:
> error = -EINVAL;
> break;
So I realize that mtree has an internal lock, but are we sure we don't
want a lock around those prctl()s?
next prev parent reply other threads:[~2024-10-29 13:27 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-28 21:47 [PATCH v3 00/19] unwind, perf: " Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 01/19] x86/vdso: Fix DWARF generation for getrandom() Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 02/19] x86/asm: Avoid emitting DWARF CFI for non-VDSO Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-30 17:19 ` Jens Remus
2024-10-30 17:51 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 03/19] x86/asm: Fix VDSO DWARF generation with kernel IBT enabled Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 04/19] x86/vdso: Use SYM_FUNC_{START,END} in __kernel_vsyscall() Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 05/19] x86/vdso: Use CFI macros in __vdso_sgx_enter_enclave() Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 06/19] x86/vdso: Enable sframe generation in VDSO Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-30 18:20 ` Jens Remus
2024-10-30 19:17 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 07/19] unwind: Add user space unwinding API Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-12-06 10:29 ` Jens Remus
2024-12-09 20:54 ` Josh Poimboeuf
2024-12-11 14:53 ` Jens Remus
2024-12-11 17:48 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 08/19] unwind/x86: Enable CONFIG_HAVE_UNWIND_USER_FP Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-29 13:13 ` Peter Zijlstra
2024-10-29 16:31 ` Josh Poimboeuf
2024-10-29 18:08 ` Peter Zijlstra
2024-10-28 21:47 ` [PATCH v3 09/19] unwind: Introduce sframe user space unwinding Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-29 13:27 ` Peter Zijlstra [this message]
2024-10-29 16:50 ` Josh Poimboeuf
2024-10-29 18:10 ` Peter Zijlstra
2024-10-29 23:32 ` Andrii Nakryiko
2024-10-30 5:53 ` Josh Poimboeuf
2024-10-31 20:57 ` Andrii Nakryiko
2024-10-31 21:00 ` Nick Desaulniers
2024-10-31 21:38 ` Indu Bhagat
2024-11-01 18:38 ` Andrii Nakryiko
2024-11-01 18:47 ` Steven Rostedt
2024-11-01 18:54 ` Andrii Nakryiko
2024-11-03 0:07 ` Indu Bhagat
2024-10-31 23:03 ` Josh Poimboeuf
2024-11-01 18:34 ` Andrii Nakryiko
2024-11-01 19:29 ` Josh Poimboeuf
2024-11-01 19:44 ` Andrii Nakryiko
2024-11-01 19:46 ` Andrii Nakryiko
2024-11-01 19:51 ` Josh Poimboeuf
2024-11-01 19:09 ` Segher Boessenkool
2024-11-01 19:33 ` Josh Poimboeuf
2024-11-01 19:35 ` Josh Poimboeuf
2024-11-01 19:48 ` Josh Poimboeuf
2024-11-01 21:35 ` Segher Boessenkool
2024-11-05 17:40 ` Steven Rostedt
2024-11-05 17:45 ` Steven Rostedt
2024-11-06 17:04 ` Jens Remus
2024-11-07 8:25 ` Weinan Liu
2024-11-07 16:59 ` Jens Remus
2024-11-13 20:50 ` Steven Rostedt
2024-11-13 21:15 ` Josh Poimboeuf
2024-11-13 22:13 ` Steven Rostedt
2024-11-13 22:21 ` Steven Rostedt
2024-11-13 22:25 ` Steven Rostedt
2024-11-14 9:57 ` Jens Remus
2024-11-13 15:56 ` Jens Remus
2024-11-13 20:50 ` Steven Rostedt
2024-11-13 21:13 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 10/19] unwind/x86: Enable CONFIG_HAVE_UNWIND_USER_SFRAME Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-29 13:14 ` Peter Zijlstra
2024-10-28 21:47 ` [PATCH v3 11/19] unwind: Add deferred user space unwinding API Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-29 13:48 ` Peter Zijlstra
2024-10-29 16:51 ` Josh Poimboeuf
2024-10-29 13:49 ` Peter Zijlstra
2024-10-29 17:05 ` Josh Poimboeuf
2024-10-29 18:11 ` Peter Zijlstra
2024-10-29 13:56 ` Peter Zijlstra
2024-10-29 17:17 ` Josh Poimboeuf
2024-10-29 17:47 ` Mathieu Desnoyers
2024-10-29 18:20 ` Peter Zijlstra
2024-10-30 6:17 ` Steven Rostedt
2024-10-30 14:03 ` Peter Zijlstra
2024-10-30 19:58 ` Steven Rostedt
2024-10-30 20:48 ` Josh Poimboeuf
2024-10-29 18:34 ` Josh Poimboeuf
2024-10-30 13:44 ` Mathieu Desnoyers
2024-10-30 17:47 ` Josh Poimboeuf
2024-10-30 17:55 ` Josh Poimboeuf
2024-10-30 18:25 ` Josh Poimboeuf
2024-10-29 23:32 ` Andrii Nakryiko
2024-10-30 6:10 ` Josh Poimboeuf
2024-10-31 21:22 ` Andrii Nakryiko
2024-10-31 23:13 ` Josh Poimboeuf
2024-10-31 23:28 ` Andrii Nakryiko
2024-11-01 17:41 ` Josh Poimboeuf
2024-11-01 18:05 ` Andrii Nakryiko
2024-10-28 21:47 ` [PATCH v3 12/19] perf: Remove get_perf_callchain() 'init_nr' argument Josh Poimboeuf
2024-10-28 21:47 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 13/19] perf: Remove get_perf_callchain() 'crosstask' argument Josh Poimboeuf
2024-10-28 21:48 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 14/19] perf: Simplify get_perf_callchain() user logic Josh Poimboeuf
2024-10-28 21:48 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 15/19] perf: Add deferred user callchains Josh Poimboeuf
2024-10-28 21:48 ` Josh Poimboeuf
2024-10-29 14:06 ` Peter Zijlstra
2024-11-06 9:45 ` Jens Remus
2024-10-28 21:47 ` [PATCH v3 16/19] perf tools: Minimal CALLCHAIN_DEFERRED support Josh Poimboeuf
2024-10-28 21:48 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 17/19] perf record: Enable defer_callchain for user callchains Josh Poimboeuf
2024-10-28 21:48 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 18/19] perf script: Display PERF_RECORD_CALLCHAIN_DEFERRED Josh Poimboeuf
2024-10-28 21:48 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 19/19] perf tools: Merge deferred user callchains Josh Poimboeuf
2024-10-28 21:48 ` Josh Poimboeuf
2024-10-28 21:47 ` [PATCH v3 00/19] unwind, perf: sframe user space unwinding Josh Poimboeuf
2024-10-28 21:54 ` Josh Poimboeuf
2024-10-28 23:55 ` Josh Poimboeuf
2024-10-29 14:08 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241029132709.GY14555@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii.nakryiko@gmail.com \
--cc=broonie@kernel.org \
--cc=fweimer@redhat.com \
--cc=indu.bhagat@oracle.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=jordalgo@meta.com \
--cc=jpoimboe@kernel.org \
--cc=jremus@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-toolchains@vger.kernel.org \
--cc=linux-trace-kernel@vger.kerne.org \
--cc=luto@kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sam@gentoo.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome