Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp535916lqt; Thu, 6 Jun 2024 10:26:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGMRumFOSDs96QdELgZoB4yG4zPxTfuSBcOspx9frOi6JEGI69qbNaDbmruoTFM/39LsCX1nxnis+TY41xxDCmWdG6MPm6NFVr/2Y50A== X-Google-Smtp-Source: AGHT+IELJy8GAbMkbtustD/C1I5p1yDQmQe5kkGpM0H4kRbvmQWjvtznXsm2otvlVXPgCV6vKrRn X-Received: by 2002:a50:d65d:0:b0:579:be37:fa5a with SMTP id 4fb4d7f45d1cf-57c508842d5mr32457a12.8.1717694799069; Thu, 06 Jun 2024 10:26:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717694799; cv=pass; d=google.com; s=arc-20160816; b=YwWsg+LrrOnqvZF3fDUjk6apjaAwnmGbX67DKIYYEB1k/qYgpGJpJTs8+AObDxECuQ ICMBtQMYo+R/qSk7VBKLAR18QQ+4VJOSd2oEcpmgb4u1Jt3k42V8mI/Tj9YMAxpytRKh x0rRBy2oWwu8N5iYQODCtT3jmoUvh/wHyW0HjBsn9lMmH5/1OCkw6OlODZCiClfnpr+2 S0GxSWAVwP6tI7YMeclJMS+kbUHn5eGD+i9xfRkTmJGPsH1Rl8qQwOeRd2/KEP1Ru2Rp 85y8Ok/wTQSJnEs/p6wxhAXfxcqLFt54dV9lPIli2pTrTA418N+UN+TUrDElbk90tCo7 boOg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Jniy+NLgVrBfK0p3PyzP0Z6EZrAShqg1T5f6U9wpTZM=; fh=cMm56bHFaWlTv2KvkWLzQhQiLSWy+xR8heTq+Jq5qYA=; b=AxPF3jr3G8INY5pINLS/xSlCNkczYAxxOE+4jirUmIVs0sM+OlRi1tqejaETpVnn2Y cIjq70xzd/OwHYuslOaYYbZPCDIOrudx9yTk8L80KV/lS4eFiY+5xGF6CqCgyJEbQblq LO9O9aHKiz3GSxfb7GG5MYmuc7osF/wDLSV2RmCtmkbT0/29wu0skcp1i6f4r7sGrjJ8 EMf31Wr4/cg8U8e0OxDDmE1zyUsjIz2aWOnFVPU0i3bQC8MffT+YnkiqymHmVhAiC+oo WSccU0KkTw605lqvtSSSX1z1hWG8NbdUvsk2JO2MEP0irRos9dcBWeHxmQRt0bNjHIyl oKfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=U6cVw9w4; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-204796-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204796-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae22b4e5si889297a12.409.2024.06.06.10.26.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 10:26:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204796-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=U6cVw9w4; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-204796-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204796-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9AA301F27917 for ; Thu, 6 Jun 2024 17:26:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B77AD1991CC; Thu, 6 Jun 2024 17:26:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="U6cVw9w4" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 85BC41990D8; Thu, 6 Jun 2024 17:26:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694781; cv=none; b=BtfcZs4lj1W4Ex8Qj5p/7g9Id7YqtKe4z8jITBHSqvVYQUe7Jcw2anXZVT2Wq7a6cD1GMXH93SEbhZFe1ZptUImlVW2UOr6vDbFMAEsm8FFtK+bt3Bn+a08/Eh9veRkGROTTn6bH/znoVksK5i2v1rhpNdZJpJJ3tRX0FOswU1s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694781; c=relaxed/simple; bh=l8EdykTqJ3aoDDrALAsVEr30BhVYMuefAflhbdzU+3A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pwt7N64kzigV8RAQqIZcb/mJOJ82Tj0b2/E46fWY9QEcouUeD7FhRtZ1X/aRGHTTmS8I+Zg7g3oNUigggxGrAqlEb3fVHIwh7TsW5FdLSYL/ebFzNVrKV1peOQOOCBzSopf2f9q7mRYgv+mo7hbRQpPlp3WHzqAKYQBrPc0lXog= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=U6cVw9w4; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Jniy+NLgVrBfK0p3PyzP0Z6EZrAShqg1T5f6U9wpTZM=; b=U6cVw9w4l6T0HIwuVstgOdFrTf /eJRHcWb1hvtr8USQwnMbi9gwBnZoAmC5llmrCK8WoJavNxSZyU1vBRsTXpX1mIxRV2HbXbKvemvr TcXvzrpg5zh8w7sQ/DUmTHhVSvF/gW4d7nzHmzLdSKn8+nXlNSLKkBVrg5ifTV1HQcWCAL4a1TzO7 qOWitxMaFgEvdbg1vnic8/zdxscPveTofIJJgbgTNMTGr1zZ0yrw7ce5WHIqVbg4oxX0vZIbXtgXw aC3yBbxrIM1qZQ9dcKNVCUGJtqPoggVx2LR7agbJzNJM8kOrpNoU60HebjaE6iXoVS3ZhuNGq8+B4 tvA9fqYA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sFGsN-00000001fmR-14ZR; Thu, 06 Jun 2024 17:26:11 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id E941230047C; Thu, 6 Jun 2024 19:26:07 +0200 (CEST) Date: Thu, 6 Jun 2024 19:26:07 +0200 From: Peter Zijlstra To: Alice Ryhl Cc: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Josh Poimboeuf , Jason Baron , Ard Biesheuvel , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , linux-trace-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] rust: add tracepoint support Message-ID: <20240606172607.GG8774@noisy.programming.kicks-ass.net> References: <20240606-tracepoint-v1-0-6551627bf51b@google.com> <20240606-tracepoint-v1-3-6551627bf51b@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240606-tracepoint-v1-3-6551627bf51b@google.com> On Thu, Jun 06, 2024 at 03:05:26PM +0000, Alice Ryhl wrote: > Make it possible to have Rust code call into tracepoints defined by C > code. It is still required that the tracepoint is declared in a C > header, and that this header is included in the input to bindgen. > > Signed-off-by: Alice Ryhl > --- > rust/bindings/bindings_helper.h | 1 + > rust/bindings/lib.rs | 15 +++++++ > rust/helpers.c | 24 +++++++++++ > rust/kernel/lib.rs | 1 + > rust/kernel/tracepoint.rs | 92 +++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 133 insertions(+) > > diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h > index ddb5644d4fd9..d442f9ccfc2c 100644 > --- a/rust/bindings/bindings_helper.h > +++ b/rust/bindings/bindings_helper.h > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > > diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs > index 40ddaee50d8b..48856761d682 100644 > --- a/rust/bindings/lib.rs > +++ b/rust/bindings/lib.rs > @@ -48,3 +48,18 @@ mod bindings_helper { > } > > pub use bindings_raw::*; > + > +/// Rust version of the C macro `rcu_dereference_raw`. > +/// > +/// The rust helper only works with void pointers, but this wrapper method makes it work with any > +/// pointer type using pointer casts. > +/// > +/// # Safety > +/// > +/// This method has the same safety requirements as the C macro of the same name. > +#[inline(always)] > +pub unsafe fn rcu_dereference_raw(p: *const *mut T) -> *mut T { > + // SAFETY: This helper calls into the C macro, so the caller promises to uphold the safety > + // requirements. > + unsafe { __rcu_dereference_raw(p as *mut *mut _) as *mut T } > +} > diff --git a/rust/helpers.c b/rust/helpers.c > index 2c37a0f5d7a8..0560cc2a512a 100644 > --- a/rust/helpers.c > +++ b/rust/helpers.c > @@ -165,6 +165,30 @@ rust_helper_krealloc(const void *objp, size_t new_size, gfp_t flags) > } > EXPORT_SYMBOL_GPL(rust_helper_krealloc); > > +void rust_helper_preempt_enable_notrace(void) > +{ > + preempt_enable_notrace(); > +} > +EXPORT_SYMBOL_GPL(rust_helper_preempt_enable_notrace); > + > +void rust_helper_preempt_disable_notrace(void) > +{ > + preempt_disable_notrace(); > +} > +EXPORT_SYMBOL_GPL(rust_helper_preempt_disable_notrace); A notrace wrapper that is tracable, lol. > +bool rust_helper_current_cpu_online(void) > +{ > + return cpu_online(raw_smp_processor_id()); > +} > +EXPORT_SYMBOL_GPL(rust_helper_current_cpu_online); > + > +void *rust_helper___rcu_dereference_raw(void **p) > +{ > + return rcu_dereference_raw(p); > +} > +EXPORT_SYMBOL_GPL(rust_helper___rcu_dereference_raw); I'm going to keep yelling and objecting to these wrappers. Fix bindgen already. Or whatever is needed to get it to interoperate with C inline / asm. NAK NAK NAK