From patchwork Tue Oct 1 22:52:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13818823 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 478471C0DC5; Tue, 1 Oct 2024 22:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727823136; cv=none; b=RZwwxDv5QveuUMA3hm0VUvjF0gE2YbExq2he9H/v85be6/wahDmPU/oi+zcYv7Isph0Cr4QuBo1AvSOZj/GnCPGGDBEMXNlH2L4ukkkWwhXK+OLwDt62tQmT3ERecQt2zIbEGocThWYuCEPkLvZiGnSQLmntkg4b0U2xtQVfDgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727823136; c=relaxed/simple; bh=jVm5JoE6ytGpFpN+XW5rkiBwjgERB/1SvKPY0MEK07o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=AAG2zG/ZZGJvQRIOgv52xSQITRA7R5+lBP/d0jNjiZGRNOsgoA6clYhRSKXuKN1jEJ/z04BFJNFxLC3YonF2GjLGsK/CoYGx3QVpQYiKbV6ArxHc8Mt+TtV30jhzKVKENu8rHawtvLlN2/G02mTZfPJBw0fTLEeSboETasCMpow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MOoGW4fU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MOoGW4fU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E59CC4CEC6; Tue, 1 Oct 2024 22:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727823135; bh=jVm5JoE6ytGpFpN+XW5rkiBwjgERB/1SvKPY0MEK07o=; h=From:To:Cc:Subject:Date:From; b=MOoGW4fUK1mub8zHKlSLKYINOQ3VpxTjIMf4tzRRP3TT1K0s42P8RvQ0Fi0yhllvN kMNpF47RJK/HsMqGSjRfkYItmcku72FabjdxS5ANVw9pwcsUeA9qD6YW0vy+Tg/D9R +IygtOcPh4W5LcquRJBX0DmwbyqF4pqvE5M9rzTY2GryBcPRwHapOQcUh0AUs+ykfw MOJC6jQc5+9Hign1iq/qhrJWKt512KxSbf9k9y790+F3rM6jQJxtbczcPoZ73pV7Sz hIF/DEGFIpHMBfY73MUkSs7Jr5cQO6KLpaffkLwEtNy2gr5HPliSO2HYh7rFJkx8Rq ufdC3IZtKYzmg== From: Andrii Nakryiko To: linux-trace-kernel@vger.kernel.org, peterz@infradead.org, oleg@redhat.com Cc: rostedt@goodmis.org, mhiramat@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, jolsa@kernel.org, paulmck@kernel.org, willy@infradead.org, surenb@google.com, akpm@linux-foundation.org, linux-mm@kvack.org, mjguzik@gmail.com, brauner@kernel.org, jannh@google.com, mhocko@kernel.org, vbabka@suse.cz, mingo@kernel.org, Andrii Nakryiko Subject: [PATCH v2 tip/perf/core 0/5] uprobes,mm: speculative lockless VMA-to-uprobe lookup Date: Tue, 1 Oct 2024 15:52:02 -0700 Message-ID: <20241001225207.2215639-1-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Implement speculative (lockless) resolution of VMA to inode to uprobe, bypassing the need to take mmap_lock for reads, if possible. Patch #1 by Suren adds mm_struct helpers that help detect whether mm_struct were changed, which is used by uprobe logic to validate that speculative results can be trusted after all the lookup logic results in a valid uprobe instance. Patch #2 follows to make mm_lock_seq into 64-bit counter (on 64-bit architectures). Patch #3 adds back RCU-delayed freeing for FMODE_BACKING files, which is necessary to make speculation safe to access struct file's memory in any possible situation. Patch #4 is a simplification to uprobe VMA flag checking, suggested by Oleg. And, finally, patch #5 is the speculative VMA-to-uprobe resolution logic. See corresponding patch for details and benchmarking results. v1->v2: - adjusted vma_end_write_all() comment to point out it should never be called manually now, but I wasn't sure how ACQUIRE/RELEASE comments should be reworded (previously requested by Jann), so I'd appreciate some help there (Jann); - int -> long change for mm_lock_seq, as agreed at LPC2024 (Jann, Suren, Liam); - kfree_rcu_mightsleep() for FMODE_BACKING (Suren, Christian); - vm_flags simplification in find_active_uprobe_rcu() and find_active_uprobe_speculative() (Oleg); - guard(rcu)() simplified find_active_uprobe_speculative() implementation. Andrii Nakryiko (4): mm: switch to 64-bit mm_lock_seq/vm_lock_seq on 64-bit architectures fs: add back RCU-delayed freeing of FMODE_BACKING file uprobes: simplify find_active_uprobe_rcu() VMA checks uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution Suren Baghdasaryan (1): mm: introduce mmap_lock_speculation_{start|end} fs/file_table.c | 2 +- include/linux/mm.h | 6 ++-- include/linux/mm_types.h | 7 ++-- include/linux/mmap_lock.h | 72 ++++++++++++++++++++++++++++++++------- kernel/events/uprobes.c | 46 ++++++++++++++++++++++++- kernel/fork.c | 3 -- 6 files changed, 114 insertions(+), 22 deletions(-)