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: 13685126 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 BC023C25B78 for ; Tue, 4 Jun 2024 12:26:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CC156B00B4; Tue, 4 Jun 2024 08:26:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27C1A6B00B5; Tue, 4 Jun 2024 08:26:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 143D16B00B6; Tue, 4 Jun 2024 08:26:09 -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 E7D386B00B4 for ; Tue, 4 Jun 2024 08:26:08 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 977AE1603D1 for ; Tue, 4 Jun 2024 12:26:08 +0000 (UTC) X-FDA: 82193128416.27.80CD01B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 8506940016 for ; Tue, 4 Jun 2024 12:26:05 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=D+BGbWSd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717503965; 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:references:dkim-signature; bh=g9xu8CO6FcwPIS6aRjJr9urN6rt6ZyZUoWGzoofY+lc=; b=Fx5Q3hGUk034pDrbvrbcBXBA5eoqeKbYsGLhRc/6d4QP8qG1vyco5/Vx3iYsmN0VODyc5m YmmASuJu71+gcvgL5Op6tQxT7dy05D/sXpRKwnMoZtWzX2jVV9ALdRAhpAxlHKQG/Inmo5 ofgufgS14qOScozr3wuskotJDAb82FU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=D+BGbWSd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717503965; a=rsa-sha256; cv=none; b=c0bhRFM/V0UFVhTjN9FPdrHtqhRW4umRvTeQ5TAt2HSmEcW34zO3wdaJjzpVRxCVGDI3vf sYqIrkgKBj4i20XJLmi3LDccwlnhwd2hxLcskhzIr8H8JC+QObz3kyHaYPjJYwhc5G61km 6Dgl49j4n1qYjgHRD9XstP2P4e4yY8g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717503964; 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=D+BGbWSdnUu575pFWlf6WUaigVRJFG3ZmoZBMJHUFcmJms4pGVe+wgKy0FpSXcrXmWMzul sHd+377IqHAJdr+TcyZh8eGDTmre8s6ha+al8g0nto8GhNw6CDF3osaFfMM6wD0+1drjRO oQAXWT/FkrSNruaqmBfnqWau6v36ZIM= 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-Rspamd-Queue-Id: 8506940016 X-Stat-Signature: x3e3ie8rauxg954ddqdnowycpunrt8ix X-Rspam-User: X-R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j+hKLrKyWI8l+n0MP9b3KfcnA0Bd6VBj2+YETN7y20cfcC8+V4odjbW7sYra11/Z0ASzUyN7zA35tdIJ6PFvb4nADX/NrJZ/dxiW9Lz6OkfABb5ZKAFa+uT1jvrOjziypKR9tZMcPn1xr0k/wqT0WTZ+DdCa466rSyqGgZUuTP0GaKjSmYhEdrs/dmIidAcoLMu1aeyoiZ4fyehKyu+pvugh3VymajhzgSrWi+g4SM8a+2pwP3D5ZbCe+7F5MNAm8Qq1mUNp1jTrw5M+e2TBHSYjVqxK5osvTI4k0FAWPdQW4fWNS+rXLQjMGQ+G8e1+RmzOc6nDVTfzcAKPBYXZEOLQZIZtBHV96JRY2ae+ZMIbeBWniq8vk2ytdxcZ+qgpcRylxjM8J9NnMexm7bRk8nOFmVHdvg4NNKx6tL8g741Vk+KyUwz56FkHn3aMk9jGmNA1XcnaMm2Y3n5b9CPa+nmT+H/k14jUsU+Oj8ZSwVzuMhbhsJpw6V87qnom8lf9batAPX9Gphs4++aanhVVhPkd+OTEf0NB24G/ZMZcuJBa8oJA5kL/QedzJGJfeeNeyZEn61A== 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: 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