From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6434D334685 for ; Tue, 3 Feb 2026 11:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770118465; cv=none; b=bGYbLGOjKCDnyrlY6ECt3b5B4pK7jDN5bL7e22fNcXMWaGI1PGt5Vb/8y8UNW8Ma0wSFtFh2GOl4eD7gRwzkdVEjKmJgypo4cARF4PRm1hR5cdj0fDC/BtbWRAPYcTOgT7PRcxfjMK9uUyeTf8y9pSYBxFdoW47WGd3djlL4N7g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770118465; c=relaxed/simple; bh=r/0+9qJswzrRb/+EdDwKidCVLUWK29vWT4K+wcArP6I=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=USTQrSmlcCm+BnWjY1lJPLTQjPsbgYd1ig3UjepVRYpFAg6Uht3KOFjC5bahP3DWK9Pv8gY+gNEzhMG9qsiM31iGOCH/7eiXmpQ7eVrYzjovm7BpheTfd8VG1gFtTFEQi3P9TTCyi+cXcnY/fI9BIj3E7CfcuA/dQWspLGvFDq8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CzfmK0MA; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CzfmK0MA" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4806fa4a180so47139355e9.2 for ; Tue, 03 Feb 2026 03:34:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770118463; x=1770723263; darn=lists.linux.dev; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Wt6rr7j8WqJzmDBy6ebcZd6xKb6YF9nq3jIKBZXTuLo=; b=CzfmK0MAzGPuAZ1tjhj4SN1DjWQ6q9rdjBpuwqIj+zSO/ioQ7w7LC8BqM4mjdBWDUC DsXazaKfMMnxrumiShBZio9BjFK5aAcDkGOqc/2nMlvm4tlwWun07JWYmrrt25a2GmbD J/aaql+v1L9dX4GufLmHygs9LwcLux5TlAKZ7bTwqbxY2h84Lm2/yQ4Yq4Mwf8dGPmt7 dkvFXCRDraHlC0pIs060IqFx4a7U65sd12oOJylFqwyTr3maG4LF22ZSSGGwb7e40dq1 3sF5ktRl2I+KrEcYNbdOIGBMvBpmBDK0dKeXvJUB+TzKnGsA6BQnAaAhk1pan/vPmo6b AsMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770118463; x=1770723263; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Wt6rr7j8WqJzmDBy6ebcZd6xKb6YF9nq3jIKBZXTuLo=; b=ToOEOtDBET1K/E9oswQs99ZUSlmXGpIYmDRVg7FFXkrTDYpXXWhFD/bM5DlsX8aSmu lDcSpfrTrCNTn6TMpFMFw6IsBTncs/GIAhq0m1mCaalPSyc4XRU6f1lZLdO2OClN1dlH wkTfNguGuS3Qn5X+QHRQC47A/8zVUzhhZIu7kWwa6hH6ZSXTG0jk8Cofx0zkNjz6i1ki XJA5Qd3QMd2+1j+sHUY6ZjiVPuxTLUXcCnqcBFyH6fgXW2wf4kgRbgo7tBGpM1YXwglc osFlrMJLKPRI8WjVm5HrXJUeKhEpDEnC5T45s9Z0sYrXZJ5r2W1AnID4dqT6yt43Bdjg 3ldg== X-Forwarded-Encrypted: i=1; AJvYcCVe9qI8mxuzxfBLyljAl8dgPKJ+ozLBxfo1XwA+Tz70X3FAqh0XCX7160BdGbOkLKVSgejJ@lists.linux.dev X-Gm-Message-State: AOJu0YyVEnu+IbqUOQXdT/pSPTO2Wpjumt0XOL9nbYHCirJ/necstA9K hYbIAzVf1hIjlT4oaqzMCbicAuRzEMfaN5SB3yUT/45HqUM/r6Dr9V1KwN8Uxo375C+fqeUiEpq HdUmADp2UCG8U0kGhiQ== X-Received: from wmjq2.prod.google.com ([2002:a7b:ce82:0:b0:480:3842:3532]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1c20:b0:475:de14:db1e with SMTP id 5b1f17b1804b1-482db4d84d1mr202173045e9.24.1770118462768; Tue, 03 Feb 2026 03:34:22 -0800 (PST) Date: Tue, 03 Feb 2026 11:34:07 +0000 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAC/dgWkC/3WMwQ7CIBAFf6XZs5hCLbY9+R+mByxb2AShAUM0D f8u9u7lJfOSmR0SRsIEU7NDxEyJgq8gTg0sVnmDjHRlEK3oeR1G3pFHZtFtGBMbR7le9EP2yAe o0hZxpfcRvM+VLaVXiJ+jn/nv/ZvKnLVsuI5aYdcpKdXNhGAcnpfwhLmU8gWYaqQZrQAAAA== X-Change-Id: 20251202-inline-helpers-996f4db65e18 X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=2301; i=aliceryhl@google.com; h=from:subject:message-id; bh=r/0+9qJswzrRb/+EdDwKidCVLUWK29vWT4K+wcArP6I=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBpgd04KSDTy59pIFCvPyqmf0oiuMXWez7Ej7S0v Efk/14aHv6JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaYHdOAAKCRAEWL7uWMY5 RoepD/4hC0AzibWqTqtig41zWC+uqMM3eR2aWMM0i25I9KhiHYzJwp+gXTjm/sdMUtX+fmLdomD JOOtqTqJRgJb2M6ppRVbT6Zr16NDh2thgm6DmrBDyUDidDREkq6Ka3U57sAP8dr1LUsA4a4wOl1 IGU4hI3u6+dqf4OaEBSnjjfLEErseNEYr090nMDDZ/uALAI68FtDhxcFDbUTcuzM5qUvAgQkEhb s1CRiaOYLsF5YUi+oVfF56c4X/ek8JBXcVe+oBqQQyBTdeE/twj8UzBksin0Kq5fvtOdgBXaJzi 8mI9ffxQo2D4BrnbbBVi28EOVU0WJ31j8MKrthJHjeJKtuf7nLSMMOMcUD8wOqeB/kNXsMEHbR3 jrhfVfvFXEqmLCU86/tLNr8sU9I4BYtjIwrjCEBwGQ9rdGzWcSE+BfVvQ8ECDNXhYSBNBramDs5 GABnreeSJ/GWaIZajEcbzUy8pVe/IONoUyl5bwYcOTd+0Q7o13gGfv//GGGx5GzFqvu7E7WTwkd rJvBNgGJd8jgAI6H9e+h4K9C7POeRap4wWVkfVmisaVarpIVsNkkcvIb46ihFwBsHYSKbvEuPA3 l6Br7+K+wySDSLflrojd8uUlpgesx82SSP1oAJb6ZVTP8iJuKc9sWSRchCqBGagigA03+NGfmuq VDWmoDGJBU6oFcg== X-Mailer: b4 0.14.2 Message-ID: <20260203-inline-helpers-v2-0-beb8547a03c9@google.com> Subject: [PATCH v2 0/3] Inline helpers into Rust without full LTO From: Alice Ryhl To: Miguel Ojeda Cc: Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Alexandre Courbot , Will Deacon , Peter Zijlstra , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Nicolas Schier , Andrew Morton , Uladzislau Rezki , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, Alice Ryhl , Matthew Maurer Content-Type: text/plain; charset="utf-8" Currently the only way for Rust code to call a static inline function is to go through a helper in rust/helpers/. This introduces performance costs due to additional function calls and also clutters backtraces and flame graphs with helper symbols. To get rid of these helper symbols, provide functionality to inline helpers into Rust using llvm-link. This option complements full LTO, by being much cheaper and avoiding incompatibility with BTF. I ran a microbenchmark showing the benefit of this. All the benchmark does is call refcount_inc() in a loop. This was chosen since refcounting is quite hot in Binder. The results are that Rust spends 6.35 ns per call vs 5.73 ns per call in C. When enabling this option, the two languages become equally fast, and disassembly confirms the exact same machine code is used (in particular there is no call to rust_helper_refcount_inc). Benchmarking Binder also results in an improvement from this change. This patch is complementary to: https://lore.kernel.org/all/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com/ Signed-off-by: Alice Ryhl --- Changes in v2: - Dropped merged patches. - Generate two copies of helpers.bc, one for built-in and one for modules. - Remove unused llvm-as tool. - Add $(cmd_ld_single) to avoid breaking CONFIG_LTO builds (note that LTO does not happen over the language boundary, except for helpers). - Improve Kconfig help message. - Link to v1: https://lore.kernel.org/r/20251202-inline-helpers-v1-0-879dae33a66a@google.com --- Gary Guo (3): kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE` rust: helpers: #define __rust_helper build: rust: provide an option to inline C helpers into Rust Makefile | 3 ++- init/Kconfig | 15 +++++++++++++++ lib/Kconfig.debug | 15 +++++++++++++++ rust/Makefile | 29 +++++++++++++++++++++++++---- rust/exports.c | 5 ++++- rust/helpers/helpers.c | 29 +++++++++++++++++++++++++++++ scripts/Makefile.build | 7 ++++++- 7 files changed, 96 insertions(+), 7 deletions(-) --- base-commit: 33a647c659ffa5bdb94abc345c8c86768ff96215 change-id: 20251202-inline-helpers-996f4db65e18 Best regards, -- Alice Ryhl