From patchwork Tue Jun 4 12:25:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13685130 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C79EC41513 for ; Tue, 4 Jun 2024 12:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=8EqY/bv0D4G+P2+mA+N8LYFvKCnrvS1a5WGLnlysNQA=; b=WvjHlzlhsgF/ld HHHDdlH0Xq4eFEcz/QzRsLhAHoXMwYzt+zHeG94zPDMaVZMrFKlt6Z8KBtzoD5HBspi+pTFa6/viY zhIbOawpmofsBu+z6akuqmK4UIVOUxeIjr7URKtucoIKvHT34wNg7YZcBsQ4P24St7HbDEu5Pw1yE OwyXp9pQxtlXf3kB3xtrzJ3M6az/K3pFbiED5VQuJKzTn5tzm+d5H2FBa3bylTYIDo92Lm6MK1xuQ ptjOZn9Lkhv69reZcHxVfufLp++s4kRpDxrFh8DkltaIXj6Id5U6NHIQHYLnne4pCMR3YzgL8PH1m JW4+o56AkSkN+9f2D4Uw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sETEw-00000002Gca-3v2l; Tue, 04 Jun 2024 12:26:10 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sETEt-00000002Gaw-3b30 for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 12:26:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717503966; 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; bh=g9xu8CO6FcwPIS6aRjJr9urN6rt6ZyZUoWGzoofY+lc=; b=ByAfaejEAMEEBAxvT5E+xmraPUXOM6GOC2wiCO8dhOXRcRjBhhwkkVMmLEZab/mwxTx9Fp AHHXfgN0d6HHieZu/OJ+ls89klVAYPFJvCgc3UOYvkuyQtj5mkr9NCa8flikD/Rqg+ZzQ2 bch9q36x6stM3c/6D0lzj97vC1pJcjQ= Received: from mx-prod-mc-05.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-404-6cKNhcoxPuygImNn1gcRmw-1; Tue, 04 Jun 2024 08:26:01 -0400 X-MC-Unique: 6cKNhcoxPuygImNn1gcRmw-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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B184B18FF939; Tue, 4 Jun 2024 12:25:57 +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 0BEB91955D92; Tue, 4 Jun 2024 12:25:49 +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 0/3] kernel/events/uprobes: uprobe_write_opcode() rewrite Date: Tue, 4 Jun 2024 14:25:45 +0200 Message-ID: <20240604122548.359952-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240604_052607_981706_2D80962C X-CRM114-Status: GOOD ( 14.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Against mm/mm-unstable. There is interest in supporting uprobes on hugetlb pages [1]. Having uprobe_write_opcode() implement COW-breaking itself is really far from optimal, and having to add hugetlb COW-breaking to implement hugetlb support really does sound wrong. Further, I think the current code doesn't really handle some things properly (see patch #3) when replacing/zapping pages. Let's rewrite it, to leave COW-breaking to the fault handler, and handle registration/unregistration by temporarily unmapping the anonymous page, modifying it, and mapping it again. We still have to implement zapping of anonymous pages ourselves, unfortunately. Note that we now won't have to allocate another anonymous folio when unregistering (which will be beneficial for hugetlb as well), we can simply modify the already-mapped one from the registration (if any). When registering a uprobe, we'll first trigger a write fault to break COW to then modify the already-mapped page. Briefly sanity tested with perf: [root@localhost ~]# perf probe -x /usr/bin/bash -a main ... [root@localhost ~]# perf record -e probe_bash:main -aR sleep 10 & [1] 2196 [root@localhost ~]# bash [root@localhost ~]# exit exit [root@localhost ~]# bash [root@localhost ~]# exit exit [root@localhost ~]# [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.287 MB perf.data (8 samples) ] ... [root@localhost ~]# perf report --stdio # To display the perf.data header info, please use --header/--header-only optio> # # # Total Lost Samples: 0 # # Samples: 8 of event 'probe_bash:main' # Event count (approx.): 8 # # Overhead Command Shared Object Symbol # ........ ........... ............. ........ # 75.00% grepconf.sh bash [.] main 25.00% bash bash [.] main ... Are there any uprobe tests / benchmarks that are worth running? [1] https://lkml.kernel.org/r/ZiK50qob9yl5e0Xz@bender.morinfr.org Cc: Andrew Morton Cc: Guillaume Morin Cc: Russell King Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Namhyung Kim Cc: Mark Rutland Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Ian Rogers Cc: Adrian Hunter Cc: "Liang, Kan" David Hildenbrand (3): kernel/events/uprobes: pass VMA instead of MM to install_breakpoint() kernel/events/uprobes: pass VMA to set_swbp(), set_orig_insn() and uprobe_write_opcode() kernel/events/uprobes: uprobe_write_opcode() rewrite arch/arm/probes/uprobes/core.c | 4 +- include/linux/uprobes.h | 6 +- kernel/events/uprobes.c | 387 +++++++++++++++++++-------------- 3 files changed, 223 insertions(+), 174 deletions(-) base-commit: 065d3634d60843b8e338d405b844cc7f2e5e1c66