From nobody Wed Dec 17 10:43:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF641207DE2 for ; Tue, 18 Mar 2025 22:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742336109; cv=none; b=jtU8hgMjvSX/HFzjBSIedpgZd/w3Q39wH7FPaK6ZOMauemjBzikc8rAwr9y2nw4wrEcX3Kul+emBeG2ftg1E2NFVVwSKB75X042+saFtWXcHDh20rwUmTtlmsTJCbA38NAwGB1zv99yDEnP6tZCR/YwYOlIbdjjJMIwKsPO0Nxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742336109; c=relaxed/simple; bh=9o1sGRawhMhE83lK347pgMnxLiJgYGjZ2/N4XtWqcOU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PUppysGU1VjsvMdPPN19FGppf/bw++WWlO4SwWmcidDcL1JFcQewBZy+t8UsihLPQiy93782rmcZFS/gcIdkioZvhJcn+kzXdQ0lfcYubwn4nqpIOhoWRsBoW1d6nn+qlBL458epWjduOe/uUSemh6oy2VjEjW1IEZl/82MJJvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hb9nAnIz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hb9nAnIz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742336106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nBMqWWSmA8jTU5EpZWWLoWgjipzuL5yIrBN/CPUgt3Q=; b=hb9nAnIz2dx7GHzfrh9bINeANaWtOFXqEIlc9CGUmg1baDt6lmyxeAFUTZeQbF3EPe5BA5 HfnQFLo5mnWc0bA5+DxPvNx/zWa80qRWmSgWxTxa4/Ik2skQZBtyqmXkJjsvUTJX8hIlOe 3fNnHRYQVCdYjoVeUhvTP/igzVOPXho= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-bVm7ohtuPQSGfVyANmeaYQ-1; Tue, 18 Mar 2025 18:15:05 -0400 X-MC-Unique: bVm7ohtuPQSGfVyANmeaYQ-1 X-Mimecast-MFC-AGG-ID: bVm7ohtuPQSGfVyANmeaYQ_1742336104 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43cec217977so25918405e9.0 for ; Tue, 18 Mar 2025 15:15:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742336104; x=1742940904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nBMqWWSmA8jTU5EpZWWLoWgjipzuL5yIrBN/CPUgt3Q=; b=TU3ZHlmc4byGTd3dt3rEcBo9y4DnBDpuFCfoPS3zsuop7bFNHNBDmpiV8C8VhhaPeI pgvWJA/iT//ZcwHr0N5sEcYaCJrbWPgPKm6yuibiPukcoBJDEg8zeGdF3aXTiwYgyAI2 ee/9gpJL18oWt0hWucoC0nx7d2mvGmnVj6fhnUAZNJ8cF43cQGMAQnwJj7cUhRD5wMWI QvEW3D5By1hYbUQ9eO7BlPY1lR2dJRzfYfzN/t4g7B07X4/lrWqaKHRJufo9sv+MB4rj Yx3jyCKM/Pwy+bZbAbHdSZ3TUvbLGxpQB7oqd+zzLqxIL4SyPwZBjP0k8LFjkSCPjvtG XgVQ== X-Gm-Message-State: AOJu0YxPANAIYBWtftQ2Mrham+1S+P9McmRd+ion4nBEeeYyUIP1XLi4 woSp1/EcVBOD77OXIcfxgOxGlgt9pupYTWDTmMqn1uWVEVbqIF0JPuGI/YXd7Ad/64Ahs5NC5g1 kAA4ntJBKpmvkeGd8HXhORce74VkP4Q5Xodof1VBEJJ7oYQcpvaJhmOjDJsz3XEot4LrOLDecOv 8TsKiiRhSGyghe92X1DC9jnOnB5rS+12pxZKq7X/21tHy6 X-Gm-Gg: ASbGncvYOBcS1nuNzFtxcgtjAkBBwCKfDwfZLAB3mU7PHY3TdExIq1lf9B0DFqv3Yox jvx/KcPMynOLXwnYnpnujXRa4E47lg8sQQaP/wsvow4cVItabQHTHHVX+GJkasK1YtjTS1LwzjA MNqAj8BNt3jfdj1Ka+8yiz+BthgbPfQdCBMuZjVwxxCEEZlDAkwmTaCIGqDFJ4Ls0mluC8NuUJa VA+OLOLzgi7W30DFTPIesdgtpW/tVCSUu8ZoxKJhkQNa5yyiQRl29bomiT3Zfrc5+gw2lAeq9SH UhUNQ4Etaonx++Jvo8A1ZA4hwuXFMQYB7QnNAtC7kEWZ1kVgusemF7yOoLPkn228tPnR0WJIpiL n X-Received: by 2002:a5d:47ca:0:b0:391:47d8:de3d with SMTP id ffacd0b85a97d-399739bc959mr401452f8f.16.1742336103912; Tue, 18 Mar 2025 15:15:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVLQM9GTMoKWmV/uO8RTwFHvBEBsZ0wjM+Jkn+TplyWph+3HhlRdj3hBn4fJ8DOgl1P3A6xg== X-Received: by 2002:a5d:47ca:0:b0:391:47d8:de3d with SMTP id ffacd0b85a97d-399739bc959mr401407f8f.16.1742336103412; Tue, 18 Mar 2025 15:15:03 -0700 (PDT) Received: from localhost (p200300cbc72d250094b54b7dad4afd0b.dip0.t-ipconnect.de. [2003:cb:c72d:2500:94b5:4b7d:ad4a:fd0b]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-395cbbc88f2sm19281199f8f.101.2025.03.18.15.15.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Mar 2025 15:15:02 -0700 (PDT) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, David Hildenbrand , Andrew Morton , Andrii Nakryiko , Matthew Wilcox , Russell King , Masami Hiramatsu , Oleg Nesterov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Tong Tiangen Subject: [PATCH v2 2/3] kernel/events/uprobes: pass VMA to set_swbp(), set_orig_insn() and uprobe_write_opcode() Date: Tue, 18 Mar 2025 23:14:56 +0100 Message-ID: <20250318221457.3055598-3-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318221457.3055598-1-david@redhat.com> References: <20250318221457.3055598-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We already have the VMA, no need to look it up using get_user_page_vma_remote(). We can now switch to get_user_pages_remote(). Signed-off-by: David Hildenbrand --- arch/arm/probes/uprobes/core.c | 4 ++-- include/linux/uprobes.h | 6 +++--- kernel/events/uprobes.c | 33 +++++++++++++++++---------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/arch/arm/probes/uprobes/core.c b/arch/arm/probes/uprobes/core.c index f5f790c6e5f89..885e0c5e8c20d 100644 --- a/arch/arm/probes/uprobes/core.c +++ b/arch/arm/probes/uprobes/core.c @@ -26,10 +26,10 @@ bool is_swbp_insn(uprobe_opcode_t *insn) (UPROBE_SWBP_ARM_INSN & 0x0fffffff); } =20 -int set_swbp(struct arch_uprobe *auprobe, struct mm_struct *mm, +int set_swbp(struct arch_uprobe *auprobe, struct vm_area_struct *vma, unsigned long vaddr) { - return uprobe_write_opcode(auprobe, mm, vaddr, + return uprobe_write_opcode(auprobe, vma, vaddr, __opcode_to_mem_arm(auprobe->bpinsn)); } =20 diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index b1df7d792fa16..288a42cc40baa 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -185,13 +185,13 @@ struct uprobes_state { }; =20 extern void __init uprobes_init(void); -extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigne= d long vaddr); -extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, un= signed long vaddr); +extern int set_swbp(struct arch_uprobe *aup, struct vm_area_struct *vma, u= nsigned long vaddr); +extern int set_orig_insn(struct arch_uprobe *aup, struct vm_area_struct *v= ma, unsigned long vaddr); extern bool is_swbp_insn(uprobe_opcode_t *insn); extern bool is_trap_insn(uprobe_opcode_t *insn); extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs); extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs); -extern int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_stru= ct *mm, unsigned long vaddr, uprobe_opcode_t); +extern int uprobe_write_opcode(struct arch_uprobe *auprobe, struct vm_area= _struct *vma, unsigned long vaddr, uprobe_opcode_t); extern struct uprobe *uprobe_register(struct inode *inode, loff_t offset, = loff_t ref_ctr_offset, struct uprobe_consumer *uc); extern int uprobe_apply(struct uprobe *uprobe, struct uprobe_consumer *uc,= bool); extern void uprobe_unregister_nosync(struct uprobe *uprobe, struct uprobe_= consumer *uc); diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 259038d099819..ac17c16f65d63 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -474,19 +474,19 @@ static int update_ref_ctr(struct uprobe *uprobe, stru= ct mm_struct *mm, * * uprobe_write_opcode - write the opcode at a given virtual address. * @auprobe: arch specific probepoint information. - * @mm: the probed process address space. + * @vma: the probed virtual memory area. * @vaddr: the virtual address to store the opcode. * @opcode: opcode to be written at @vaddr. * * Called with mm->mmap_lock held for read or write. * Return 0 (success) or a negative errno. */ -int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, - unsigned long vaddr, uprobe_opcode_t opcode) +int uprobe_write_opcode(struct arch_uprobe *auprobe, struct vm_area_struct= *vma, + unsigned long vaddr, uprobe_opcode_t opcode) { + struct mm_struct *mm =3D vma->vm_mm; struct uprobe *uprobe; struct page *old_page, *new_page; - struct vm_area_struct *vma; int ret, is_register, ref_ctr_updated =3D 0; bool orig_page_huge =3D false; unsigned int gup_flags =3D FOLL_FORCE; @@ -498,9 +498,9 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, st= ruct mm_struct *mm, if (is_register) gup_flags |=3D FOLL_SPLIT_PMD; /* Read the page with vaddr into memory */ - old_page =3D get_user_page_vma_remote(mm, vaddr, gup_flags, &vma); - if (IS_ERR(old_page)) - return PTR_ERR(old_page); + ret =3D get_user_pages_remote(mm, vaddr, 1, gup_flags, &old_page, NULL); + if (ret !=3D 1) + return ret; =20 ret =3D verify_opcode(old_page, vaddr, &opcode); if (ret <=3D 0) @@ -590,30 +590,31 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, = struct mm_struct *mm, /** * set_swbp - store breakpoint at a given address. * @auprobe: arch specific probepoint information. - * @mm: the probed process address space. + * @vma: the probed virtual memory area. * @vaddr: the virtual address to insert the opcode. * * For mm @mm, store the breakpoint instruction at @vaddr. * Return 0 (success) or a negative errno. */ -int __weak set_swbp(struct arch_uprobe *auprobe, struct mm_struct *mm, uns= igned long vaddr) +int __weak set_swbp(struct arch_uprobe *auprobe, struct vm_area_struct *vm= a, + unsigned long vaddr) { - return uprobe_write_opcode(auprobe, mm, vaddr, UPROBE_SWBP_INSN); + return uprobe_write_opcode(auprobe, vma, vaddr, UPROBE_SWBP_INSN); } =20 /** * set_orig_insn - Restore the original instruction. - * @mm: the probed process address space. + * @vma: the probed virtual memory area. * @auprobe: arch specific probepoint information. * @vaddr: the virtual address to insert the opcode. * * For mm @mm, restore the original opcode (opcode) at @vaddr. * Return 0 (success) or a negative errno. */ -int __weak -set_orig_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned = long vaddr) +int __weak set_orig_insn(struct arch_uprobe *auprobe, + struct vm_area_struct *vma, unsigned long vaddr) { - return uprobe_write_opcode(auprobe, mm, vaddr, + return uprobe_write_opcode(auprobe, vma, vaddr, *(uprobe_opcode_t *)&auprobe->insn); } =20 @@ -1153,7 +1154,7 @@ static int install_breakpoint(struct uprobe *uprobe, = struct vm_area_struct *vma, if (first_uprobe) set_bit(MMF_HAS_UPROBES, &mm->flags); =20 - ret =3D set_swbp(&uprobe->arch, mm, vaddr); + ret =3D set_swbp(&uprobe->arch, vma, vaddr); if (!ret) clear_bit(MMF_RECALC_UPROBES, &mm->flags); else if (first_uprobe) @@ -1168,7 +1169,7 @@ static int remove_breakpoint(struct uprobe *uprobe, s= truct vm_area_struct *vma, struct mm_struct *mm =3D vma->vm_mm; =20 set_bit(MMF_RECALC_UPROBES, &mm->flags); - return set_orig_insn(&uprobe->arch, mm, vaddr); + return set_orig_insn(&uprobe->arch, vma, vaddr); } =20 struct map_info { --=20 2.48.1