From patchwork Tue Jun 4 12:25:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13685128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EF5CC25B7E for ; Tue, 4 Jun 2024 12:26:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F96A6B0085; Tue, 4 Jun 2024 08:26:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A88C6B00B8; Tue, 4 Jun 2024 08:26:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84ABD6B009D; Tue, 4 Jun 2024 08:26:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 61E8A6B00B8 for ; Tue, 4 Jun 2024 08:26:22 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 29EC4A0564 for ; Tue, 4 Jun 2024 12:26:22 +0000 (UTC) X-FDA: 82193129004.19.9B2C13A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 73EDC1C0013 for ; Tue, 4 Jun 2024 12:26:20 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RYMtTkYy; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717503980; a=rsa-sha256; cv=none; b=q1nY6SJseAxMN1toZ10DTshTp2K9CVf/8HA1qRnQycPoaOPDVCDSvjRVuSmKwoMEVk9zKR pUdyjV9/ND6R4x3Q0//zGgoYK2BJZId4Y6Eu74mjj8JAbMhj59HWGG9/xwpPctP/U5CV3G hpuI4PIKxd6IoNhUwhgG1rftuBLplBs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RYMtTkYy; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717503980; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=aXfKzgnS1a7dNjnPxPlU/qmVEHFMnEf3bxdZwelxxd0=; b=sZvAEmtr6QfdOBCEhr5rq6epq9Mt+8Tq9aMX/eNTFu3dn8oszmOkGxSZqcGmTX2beHG/6F 9mK9wtkXXPBlvluQmpCc5fTwPpNiiBn5rqLPzQerAZRXEdWK9S4ZZlnjw+RepxR1VOAq+o eiXyq7OmqMYAT1Sb33FeF7xjbYe8bVk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717503979; 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=aXfKzgnS1a7dNjnPxPlU/qmVEHFMnEf3bxdZwelxxd0=; b=RYMtTkYy2mtuMBcGWwcNUnJhkUQ6mEbdpm2Og76mw+bfZyeFl5+EMxEYiO3ktUF0W2g8rg xWvrwxR/aa5JY5wIU632IjI5SyXsctoybOlyqB8BQ6bfmy38c4JSggn+jDWaGGNzqTKwwh cawqlvm6WvU0APY/KBXLPjyNQ73KIE0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-121-ODGmKQOXNA-4YSKHFzPAow-1; Tue, 04 Jun 2024 08:26:14 -0400 X-MC-Unique: ODGmKQOXNA-4YSKHFzPAow-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E85DF18BF6E4; Tue, 4 Jun 2024 12:26:10 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.193.118]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1B8851955D8B; Tue, 4 Jun 2024 12:26:04 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, David Hildenbrand , Andrew Morton , Guillaume Morin , Russell King , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" Subject: [PATCH RFC 2/3] kernel/events/uprobes: pass VMA to set_swbp(), set_orig_insn() and uprobe_write_opcode() Date: Tue, 4 Jun 2024 14:25:47 +0200 Message-ID: <20240604122548.359952-3-david@redhat.com> In-Reply-To: <20240604122548.359952-1-david@redhat.com> References: <20240604122548.359952-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Rspamd-Queue-Id: 73EDC1C0013 X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: bn8y7xyfjftup9xiu5y1ih1yxgboojbu X-HE-Tag: 1717503980-656458 X-HE-Meta: U2FsdGVkX1/zqYxbmpQCeGaBM5oVvm2jjBF7WKPntCxEerntwfI/92ZTM6rR+i9jLXrgpBY6fFZp4s07W7V4AVDHELPs44qYk6A/Z1gQy/cR20kkt6m0Y9/zkJVc1njx3e81/WlhOHbx268wcGOa1nJo+9H5B8UiE0TcW3FgA4OWqz9fOXet5aiWvk0+l7yPum386/TZPslA/pm5yvJHmU4+RGLI5TW1sg3fLei5Kti9j61QidkEs6rh2u0suIFkM9W/XClotLL2StIIL+STI+/g3EnxKC7MFub/1TRTd7Rk96Tkk9zZ535+kh2i5yOqxuWvMoagWLdeaZmyac9n2nI45uoiUWelqCSgkOblIOwYRhIc2RaOAqGXBKah0yDReuzcLDvJJCQQG3tfNSdVpfeNIWFDGsOnDBHtcN5SDH8qB83F/oLjv2FRfO2dj3cb+7lmJaPHoAu8YbxGAHAgRzm6FnQwfIHuCtE+bBGD4irUmNAczCP0LXExBKq4nXuwTVFV3grd0s43fREzgRdNiX4K8VZUqGQ8FsNvG9C3B8g8AB4K1nB9e+Cy8YyeSdhQSRxqCFVnK8b1bLKyzxrm2FoTSXGJDtle2DinQfl1Xhl1kpUvYHmi91WFQ4bngH/YKrKhpuU2GUp3PWGI3lGuJYwDGf04+89nBF24HnWizg/SZMhfQNOHEr6VHkCK1RMiSV9Ta/HLQCk2AQShziBLZY57JP86EehamqEVbMtpxyT/D1UJgYVd3rGijbFMyZSKADLccc4lxCXv8Wc7oxCV7SPctfYJ5Y2Osbc82qBpGATiBo+C3Uy4DFGgorOLGots7ppG0TZDiL6MjJfRc1m9W0qyPSOUiPRCvHHTHnzSEe4/WAgwUflYOletqpRvahGnPagtD48OScDg3g1G7NoGYM0RQ6rwNmblmkYHOViJj1/ZQdmELqGMJFx29+mxiEhSExjPALnD+sCHhneY2OM K6Se53Dg 5HyOPV65fybrRXBRjOXMzhyNuxDwxVsavvvk40ZBJhq0eX7qxTvwSF2XIm4xd34up1zgMTIV2wC6l17BxMG1wgcb/BqCtO4iVSgfxv2GFmEFKSkstii7rumJyn0FBwJRy1GGjYcGlxlMtb/h4T3oTb+cXimtg05ZlASIRG+JjtvQxpE2o2BUVT4eTVU95lPrHo5TyEkpGVq5rw55qvf56qNuX85YlDnuiqfFkTWxUq6Qs0+GJhBrFUt5S4tBYdKzntK8nCC++iwRIkgQu1KK1cYyUu/YuBvK6QBV+qlkzyWdbJpuwPV3cbxQyHA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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); } -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)); } diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index f46e0ca0169c7..77580dba6f8de 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -103,13 +103,13 @@ struct uprobes_state { }; extern void __init uprobes_init(void); -extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr); -extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr); +extern int set_swbp(struct arch_uprobe *aup, struct vm_area_struct *vma, unsigned long vaddr); +extern int set_orig_insn(struct arch_uprobe *aup, struct vm_area_struct *vma, 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_struct *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 int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc); extern int uprobe_register_refctr(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc); extern int uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool); diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index c6d6b7a8e4410..f2b1fef7f1d62 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -449,19 +449,19 @@ static int update_ref_ctr(struct uprobe *uprobe, struct 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 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 = vma->vm_mm; struct uprobe *uprobe; struct page *old_page, *new_page; - struct vm_area_struct *vma; int ret, is_register, ref_ctr_updated = 0; bool orig_page_huge = false; unsigned int gup_flags = FOLL_FORCE; @@ -473,9 +473,9 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, if (is_register) gup_flags |= FOLL_SPLIT_PMD; /* Read the page with vaddr into memory */ - old_page = get_user_page_vma_remote(mm, vaddr, gup_flags, &vma); - if (IS_ERR(old_page)) - return PTR_ERR(old_page); + ret = get_user_pages_remote(mm, vaddr, 1, gup_flags, &old_page, NULL); + if (ret != 1) + return ret; ret = verify_opcode(old_page, vaddr, &opcode); if (ret <= 0) @@ -560,30 +560,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, unsigned long vaddr) +int __weak set_swbp(struct arch_uprobe *auprobe, struct vm_area_struct *vma, + unsigned long vaddr) { - return uprobe_write_opcode(auprobe, mm, vaddr, UPROBE_SWBP_INSN); + return uprobe_write_opcode(auprobe, vma, vaddr, UPROBE_SWBP_INSN); } /** * 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); } @@ -905,7 +906,7 @@ static int install_breakpoint(struct uprobe *uprobe, struct vm_area_struct *vma, if (first_uprobe) set_bit(MMF_HAS_UPROBES, &mm->flags); - ret = set_swbp(&uprobe->arch, mm, vaddr); + ret = set_swbp(&uprobe->arch, vma, vaddr); if (!ret) clear_bit(MMF_RECALC_UPROBES, &mm->flags); else if (first_uprobe) @@ -920,7 +921,7 @@ static int remove_breakpoint(struct uprobe *uprobe, struct vm_area_struct *vma, struct mm_struct *mm = vma->vm_mm; set_bit(MMF_RECALC_UPROBES, &mm->flags); - return set_orig_insn(&uprobe->arch, mm, vaddr); + return set_orig_insn(&uprobe->arch, vma, vaddr); } static inline bool uprobe_is_active(struct uprobe *uprobe)