From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 560642248B9 for ; Fri, 5 Dec 2025 14:29:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764944983; cv=none; b=JsbDV5hewObfJ4kOGn8JOcEdNMEGppHEFF8gV87BKFyq7feL9h/1m/N2tCWhMyUbUZ4qs22rkMShgfnf8aNUZfAgHVGiPmzcoXrKBz89/98qLgyzGNEIso2TaRoLyuD68JmeMVOCUmpDj3EOD2QRZG05Nb5AFWOnR2X7T1Xnmrk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764944983; c=relaxed/simple; bh=abCVAtbqooyF0UIqD8BhSOUnhoH4MFmezPBKW027k0s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LU2DymQLCG7e4ANt8B/b7OCO+JRdm6h0Rnn0vUDHunYgkROTukpbVY2u3mn2iY1dXMSot8XC6c9qLfHYBDfE+ZsaNMj3WI9G1DAPlxkxNotV8TZOG2qIp1rfxATkKB70wwkFChYWsOKBSZeO8/4T7u4183wy7/EAz9DGzVCZyis= 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=JVnVFnlI; arc=none smtp.client-ip=209.85.128.73 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="JVnVFnlI" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-477771366cbso14526645e9.0 for ; Fri, 05 Dec 2025 06:29:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764944977; x=1765549777; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ihHXRiFptoSn1UPDej1d31iPMC/rnq4IC8M6YRoybz4=; b=JVnVFnlIhx+p7u3Cx1GSoIFKRvEiZrySuqVqZx9mMvle5CvrTsaOijPFmlpPdSv4TH t1xJNnFLG0xGLLKP6wFDyFpfOZLHvCCYxYzxiyEAoVa4uW4S3ppzf2rLxjBrTnuox+as 9WvXeTB1Hci2gF3Dz5siLmL7BJ8wDz1T5IyoMP4+ncr2WKHS1lVGk5b3yGGLnwIv9aUF DBqj59bW0WFEQ/uKXM5FdDMUbn9FcRadwFpuYnUwCm7TMoBvOdN2svq5j3f4DC5bipTJ cTx5Gr1JD4FkkAEvsOkRyO5a8SCeSDPKrkgmngAHdVr5VZV69VJRhlHK503ILF+yoaSI ueLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764944977; x=1765549777; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ihHXRiFptoSn1UPDej1d31iPMC/rnq4IC8M6YRoybz4=; b=vJ1A+mQhoPcKF8PbESts2FtchLQUtQ5fgxaceuxBAxVWcztkjupVgwdAO4RlyMIyDM AWGJikJ7j/Ug98GzNdkww2TMYV1l8OzUEJ8yY6TL2uYTbK4BTxlTlSTaccICCY4F84o1 pT0IcD4xWSRpm2dmnIIrvPG4onlKtip9KS+pUQyoMbQ/pRVEf6SgDpz0xYdLuZFIeVvO 6pzcStwxRJzs5J2oT4P6uF6CidFSj6eMDTqdkM3qi6aOM1PsBXLfm+sOkeYWyYmplA+U ImgR9KNh2DTSLhIbtuDZnnmu5Z02qsIFuk4XzdAOmZMao+XQaxxaEf6Qw/9m+4igR6XD kjfw== X-Forwarded-Encrypted: i=1; AJvYcCX+M8eYONBqwkF3XEB8PzvK8QO+zB4wVSvJBI7Jdh+meM/v+yJjth0cMhFAUrvlFdaN0B1dHrfHyaZdufM=@vger.kernel.org X-Gm-Message-State: AOJu0YzD276vzlR4scHFrOWZK2DUcV8e6e3UXf5S1CXUZ0tjknDDdOtX WSot7u415V6vSA34mQtns8AMrH20XWD71FTvPmKVGuDtcaf8P1O2o5JOOdEVNwq7rH/4iv0LvDw J4G4JCkhWLb1iUsOvGQ== X-Google-Smtp-Source: AGHT+IG/BdKdEolpce9IynSZK74/u+mPv+jtkZRvtfG4q4RMC/qkIoJnhSAcuXTaRoHTzDBZuG0/i+Hsy6zvrX0= X-Received: from wmxb5-n2.prod.google.com ([2002:a05:600d:8445:20b0:477:a148:c6bf]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:474b:b0:477:9392:8557 with SMTP id 5b1f17b1804b1-4792af30ebcmr105499115e9.18.1764944977722; Fri, 05 Dec 2025 06:29:37 -0800 (PST) Date: Fri, 5 Dec 2025 14:29:36 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: Message-ID: Subject: Re: rust: wrong SAFETY comments in group_leader() and pid() + questions From: Alice Ryhl To: Oleg Nesterov , Christian Brauner Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Panagiotis Foliadis , Shankari Anand , FUJITA Tomonori , Alexey Gladkov , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Fri, Dec 05, 2025 at 02:19:27PM +0000, Alice Ryhl wrote: > Thanks a lot for your email! > > +Christian Brauner > > On Fri, Dec 05, 2025 at 03:08:23PM +0100, Oleg Nesterov wrote: > > 2. I am working on the patch(es) which move ->group_leader from task_struct to > > signal_struct, so the 1st change adds the new trivial helper in preparation: > > > > struct task_struct *task_group_leader(struct task_struct *task) > > { > > return task->group_leader; // will be updated > > } > > > > Now, how can I change group_leader() to use it? I guess I need to add > > > > struct task_struct *rust_helper_task_group_leader(struct task_struct *task) > > { > > return task_group_leader(task); > > } > > > > into rust/helpers/task.c, but will something like > > > > pub fn group_leader(&self) -> &Task { > > unsafe { bindings::task_group_leader(self.as_ptr()) } > > } > > > > work? I'm afraid it won't ;) > > That looks like it should work. The rust_helper_ function is only > required if task_group_leader is marked `static inline`. Otherwise > bindings:: will pick up the function straight from the C header. (As > long as the relevant header is included in bindings_helper.h) Ah, actually you need to convert from *mut bindings::task_struct to &Task. And you need a safety comment. E.g.: pub fn group_leader(&self) -> &Task { // SAFETY: The lifetime of the returned task reference is tied to // the lifetime of `self`, and given that a task has a reference to // its group leader, we know it must be valid for the lifetime of // the returned task reference. unsafe { &*bindings::task_group_leader(self.as_ptr()).cast::() } } Alice