From nobody Sat Feb 7 19:41:29 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 2F23C13B598; Thu, 28 Mar 2024 19:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655720; cv=none; b=eRgDoysZsOz8pRmsneZvtyKuCECKflDZ4Y9TQ/5gcq/sn8xBMiG0FxjF0oUx65rbIrC+ffsSpHm7iRXwCDFJh7b8EenvakBSmFAgTMZ3WiRAOsiSHdK4BuYn1OpT3J/qDO+oQxg5zZguf2MB6RlGUXkI1TDvhb7/8nV9yVFciGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655720; c=relaxed/simple; bh=8H5op9oxVlU0msUtq5I4WSqtnbdnJghczRSI2SqtUaM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=I3V5uP+xaYnPL0AfZdeCTFwrCYgZzL3Rc+xqyXZnOHn1Xof8nkSm+spYO/94aWVzrnUzpWL2xtqyYfDU2COVChrS5GEHZguRbOYmly9nfwIOa36Pc11sRKerc3gYJGgogWIl7ry6hTDithUIdvQHugqEuJtJmqGarwDarrTeR8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FUBDeGl9; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FUBDeGl9" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1e0d82c529fso12721145ad.2; Thu, 28 Mar 2024 12:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711655718; x=1712260518; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EzqUPsfXWj4binayeXTWXcfCoPWBBRiht8YRpbXdcMA=; b=FUBDeGl9A7jmubRkBgVcnyIBChMi26PnlOPx/hjHJ/Mwg/tfyOMh7bvFZjFpE0UYCT ZHhzlllWiC43WF87h1e6HXC+FNmq/N+I64RKBVrvGhCzTORfDXdxx5ULDAZ8B6x4NU0O BsCpp7uKTtZjvwe56Ja/5YH/7PFIl2TnruX+SdQDH5Z90cYemOiUMdah3jZhbdqII+Ik U2KJ14rdZTYjMYpuIE8PthCac3sV83w92HqV/yI4GV3pHfp6ooQE3USdRMY37YRyEn0L 1KENrWbJaoD5M7ktUKfderZlbGMyNYCjDAxlyvvKNkHVO94TluyG3Ti2DEKWf45ee3zg tAtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711655718; x=1712260518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EzqUPsfXWj4binayeXTWXcfCoPWBBRiht8YRpbXdcMA=; b=sXRKYaTuteajfrZxL5eW2BceANRBRYHVinBBO0jSAHlx0asCxh35dMWFB/o6qKd8I1 /ga1r1pdcpihQkI7G9XGpmCD1QXxE5NVoQGjXPwdCabyxV/myNTg9WEt5ED1uSmiaTgo wtVYc2blaZClgQWqrkcJStPIuPmBx6QUJQ2IifGsTnPr8nw99JsADSoC6k8mkG7RBHXT eNyyJvWZeJnXux06lI7ngbDaRrtV226uM+MLm4u7vPTEg9V2Jn9Nc8x0xCXOCllOPJpm +OeYIJU5SaR2DkNZBeCLiwl135P9/iNFO542d5+5PIqGuGJNwqdHW0R8KnK09/rCMrJu kiNA== X-Forwarded-Encrypted: i=1; AJvYcCWl82i6PKd0T0L31FhqG7RdyYAuG+OXFMzk6EGfjzx+wEc2Vp5iNh0dPYNU4Zeryo0fgW3TTxlnRGI3DXpKwEz+Dtk/Of++W2IBDZxNc2B8ijoSxLW7O5HUyWS6au2Gtx5cPpqJ X-Gm-Message-State: AOJu0YzpKAA92gEgXa3Bg92LF9u7zWC/DMgxJPY/NgKPlBNkSkcWipey U+AJXnVr9/qBKEzk04bN7t4qEq6GWMUUfYO6CtqgJrG9q7nxR0ZHoBerG+8e X-Google-Smtp-Source: AGHT+IFcH8y9aRYK8WAqYucQcxKLzTdOpTXagA/BsEXoq0kvwRHyM3jJoCzmityUgjvvuOTNcC1qnQ== X-Received: by 2002:a17:902:e888:b0:1e0:b5d4:9fa3 with SMTP id w8-20020a170902e88800b001e0b5d49fa3mr634632plg.2.1711655718390; Thu, 28 Mar 2024 12:55:18 -0700 (PDT) Received: from wedsonaf-dev.home.lan ([189.124.190.154]) by smtp.googlemail.com with ESMTPSA id p16-20020a170902e75000b001dd7a97a266sm2006520plf.282.2024.03.28.12.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 12:55:18 -0700 (PDT) From: Wedson Almeida Filho To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho , FUJITA Tomonori , Trevor Gross , netdev@vger.kernel.org Subject: [PATCH v2 1/5] rust: phy: implement `Send` for `Registration` Date: Thu, 28 Mar 2024 16:54:53 -0300 Message-Id: <20240328195457.225001-2-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328195457.225001-1-wedsonaf@gmail.com> References: <20240328195457.225001-1-wedsonaf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wedson Almeida Filho In preparation for requiring `Send` for `Module` implementations in the next patch. Cc: FUJITA Tomonori Cc: Trevor Gross Cc: netdev@vger.kernel.org Signed-off-by: Wedson Almeida Filho Reviewed-by: Alice Ryhl --- rust/kernel/net/phy.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 96e09c6e8530..265d0e1c1371 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -640,6 +640,10 @@ pub struct Registration { drivers: Pin<&'static mut [DriverVTable]>, } =20 +// SAFETY: The only action allowed in a `Registration` instance is droppin= g it, which is safe to do +// from any thread because `phy_drivers_unregister` can be called from any= thread context. +unsafe impl Send for Registration {} + impl Registration { /// Registers a PHY driver. pub fn register( --=20 2.34.1 From nobody Sat Feb 7 19:41:29 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 87D5013B791; Thu, 28 Mar 2024 19:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655724; cv=none; b=I/hWT3f2q4eETqKllJBk+/0y+12HNeLjsMHw4CG3TJZ/ak0AZTjj7mQZaETluykr52HUiAyouF8S26Yt0OW/jw5R5mVzyJ2UR5lGsPLAOhgbk1MO9FcG/5OdXcrnZKGgEcw9V4ikm7TxEk+dDu545XjORx1l+G4bqDSk4C9IAX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655724; c=relaxed/simple; bh=cjEsbiErL4GEiLgWPr00zMhV+ra7917lJ1keLF6jIuU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f3nlPS7Iay+xmHrqX3yqb+u0KovwtLLbBD3y6DKEfjRz+qKzII7DcQ37OR7V7dNBaA8LfPte7DbR0XR4FI4P+ucmq7h4qUN4d83xx7qZti/i0ii7yQXS2H9qZbWlJMUQnJxP8vFD4zPGW++rRp39z3NXsRQRCXaYymA8vOjlpGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gPWPu2UM; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gPWPu2UM" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6e6b22af648so1810277b3a.0; Thu, 28 Mar 2024 12:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711655723; x=1712260523; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3onkuNTqsbsPIhsygl1fro8dFk+/knTOJGgy1+clLaE=; b=gPWPu2UMrdNMHAZtDJp8iahagtqXaTKstTkTrUSr/k7+F9uI5F25MsM8vSdH6qfYUL Eh9r5I9feTiNtqtIGRU1fJqWBw5LzTucgGinku1zcC3CcT8wmhwFYB12t7DUQUFtNyUm DHtsxm7IShaBcJK+oryafg86T2pPdkHINxm/bB2QdLcP/X/XVFm2MWxXIRNtfskTp4Oz fJ4WzUXP9H/naottyJouNLOS7/C7BcmwTkWbXMUWr1c7bMTingRodQPVDNuoGqfGYY1C 66FfVLkKNloKXHF5kOI1YFtrUzlmllB91L6GGtCi/nJ7IVH5/60/068ommHKvBQeCxZy jEuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711655723; x=1712260523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3onkuNTqsbsPIhsygl1fro8dFk+/knTOJGgy1+clLaE=; b=c70/XWa16ITaHO5BAmzJrjm61bAsWjn8/ZTH4lAcdSBycyDlG6avflqmYOMLL5LcR7 csM/3esfC0wsHY3rqo/Gk68oXa1IqWwFM7BUlF23Q0T54Tj1MArdONovPnUdRkQfE7pi VZTgKahiD/T2MQYlCvT0HV1tzU5BoGuUAlX897qwlrbecK2qTWtOZm/828jP3K80oF5K ZzFEDfypqr0VZ6nd64ndBF70cmvOLMdVFpbmftqkn03Jt993yp9LRAr+gCw9/9qkw8kM rGXPvGLCB6mJ5ePdFWfeQdj+DLjZSbtxTM2b2csbaiclphUg+sc7sBdaqxV4yCdRCiA6 NwVA== X-Forwarded-Encrypted: i=1; AJvYcCUGvW1Gb0JZNIegFvAYTj+vhRU/UuainNVBj+7E1A4HgwgzGuT07HC0oSLF3vn2yJTRVpN6n4Yi2I8twe7iGQ7qteIm5KqYa4jnKkYw X-Gm-Message-State: AOJu0Yzu+2+sDTdPIi+wOyNxI2oWiHgB1PxGyII2VpwFrEj893XXeaLQ COGJM3Eq9NPL7MJjVeOBZ+RqkQ2NedcHU1I6DJnoPVI6LDlFoZnhTXVWZ0Ev X-Google-Smtp-Source: AGHT+IFHIFFoXRxFAQKTg7a2ng7z0GqOTb5sKGnRXt/T4T4naasjHmM5jKwJejoXUwY2joLDaGiA7w== X-Received: by 2002:a17:902:f54a:b0:1e0:aca5:fd24 with SMTP id h10-20020a170902f54a00b001e0aca5fd24mr498128plf.24.1711655722792; Thu, 28 Mar 2024 12:55:22 -0700 (PDT) Received: from wedsonaf-dev.home.lan ([189.124.190.154]) by smtp.googlemail.com with ESMTPSA id p16-20020a170902e75000b001dd7a97a266sm2006520plf.282.2024.03.28.12.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 12:55:22 -0700 (PDT) From: Wedson Almeida Filho To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: [PATCH v2 2/5] rust: kernel: require `Send` for `Module` implementations Date: Thu, 28 Mar 2024 16:54:54 -0300 Message-Id: <20240328195457.225001-3-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328195457.225001-1-wedsonaf@gmail.com> References: <20240328195457.225001-1-wedsonaf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wedson Almeida Filho The thread that calls the module initialisation code when a module is loaded is not guaranteed [in fact, it is unlikely] to be the same one that calls the module cleanup code on module unload, therefore, `Module` implementations must be `Send` to account for them moving from one thread to another implicitly. Signed-off-by: Wedson Almeida Filho Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 5c641233e26d..9141a95efb25 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -62,7 +62,7 @@ /// The top level entrypoint to implementing a kernel module. /// /// For any teardown or cleanup operations, your type may implement [`Drop= `]. -pub trait Module: Sized + Sync { +pub trait Module: Sized + Sync + Send { /// Called at module initialization time. /// /// Use this method to perform whatever setup or registration your mod= ule --=20 2.34.1 From nobody Sat Feb 7 19:41:29 2026 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 91E6A13B5B5; Thu, 28 Mar 2024 19:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655729; cv=none; b=m8ImBDwlRFr3i+S0Jko7QcHgHihdtWdxS5RwXALc+lD3diZDgjaXzb0Ubh/0YPKCHeuQyKTeibf7PlEkOKWm/Zf1xdk/7PiX/19+11keQ+VpMHtO+3cVLcr6rct/mIjIQ23LvGLxK8wbly3SyABGCMm/Kcgo/Xy5TnRTUr7InX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655729; c=relaxed/simple; bh=fwHF+9VfvjyLijiOuriTU4phk/vNv1/uaYRVz+QNv7A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=isvx6wr31I4dyPVQSUzuwotnTz5MYxZDQdt4ZY3P+90+//9inmpM9PVspibp6yFmkFB/7ztaNT0PdE4l380Jfa699t/4eMIpNzplBMzfD2jWUC+n/Vblqv8GxW1S1IQ/tCri6iMty3OnEYEH+bCdfZaaLJ2NFGxBrcJUMXHHjnQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OQe1+o/L; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OQe1+o/L" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1e04ac4209eso11812105ad.1; Thu, 28 Mar 2024 12:55:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711655727; x=1712260527; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FaV84KT2HRtfO0aaQj0mOFU/al8Iv6el5mE2P2C4AwY=; b=OQe1+o/L32zVC66/Yf0xaT18an0+S8chAJIN1F2YZ+5iphBaWjraL0WCFMi8MDDeke 9n8i3yHsP8C5Ghcq/irjQYrHs8juzuvqw3YU49DkD/QMPUHI6CoSOFqmYL1i37D2H2Ei y8y02yfZvQS5ePuvVrwo0yU3uHD74Z/UZgSQ2SRpferKXyNn0zdv29BiT6vhbgMsdXGw t2T7aITcJGPSfBlLGAIKY2VSExq6VdnwCxtRtCV5pXv+s4q64nx9WSKOM9bZdJE0B1tH hdOMpIoELl03EL2HKd26OIyZ4+cFnH1Sr0AnKQ+BeHUjGGB86r6OQ6LdVc9+ePnCQVRF EgEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711655727; x=1712260527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FaV84KT2HRtfO0aaQj0mOFU/al8Iv6el5mE2P2C4AwY=; b=arZhbnjLiJrcOYhIm9qwxcuJyiTg8/2V3smv2oUDBDTgxxlUcehz/jHGWux0jujD9+ yDZ443k9R+PDDoy/1kKE3aacvVjToGWOsyW7T/4mAQ17+HdtfkCv/6yWU7+poA5N7fK0 VdXWJrSLsAP+pF9usNGZTKBFW0bx5QL5EB03blDUzYNtNxcatGnLis//6TJWfNbspGs6 fpIhha7yDL5HvXBJ5/sO754deFjANii7Pgspr9Bzy89FJAqLEfp4QElnC9S06VDZeisr /fD8Kcd2jfulPE0HdOhaCA/X2nqHXEbzPB0Zffg1IY3ymRXGKm4mWbeay+qQwfxl1Uq4 P1CA== X-Forwarded-Encrypted: i=1; AJvYcCUVXNpv2wK1t9BpCXbfgcZsmQtBPD34/Cbas90LaJXCC7kTaI2yqnWG5dawHjezIgStlw5Moyq4YMuy64/GeuFYVL2a2zozeT+glzrw X-Gm-Message-State: AOJu0YzmjjJsk2/883NiMewotDhn0hsq+IHCc2pB/e1QWCIQ31f1Hh7M 1ik52yQeHuPVj/+maYKLnBtVe8KkdiDbZfjM8VvtUc7xJoM4lNvUDLBJo3Dy X-Google-Smtp-Source: AGHT+IHtnVuR83rlRhJFX22O35yxSF4w2PJlJYzX7KvTLxFR+XM7g0omTJVVf70kwzut9sZDcrSPXg== X-Received: by 2002:a17:903:555:b0:1e0:af99:819e with SMTP id jo21-20020a170903055500b001e0af99819emr478073plb.20.1711655726788; Thu, 28 Mar 2024 12:55:26 -0700 (PDT) Received: from wedsonaf-dev.home.lan ([189.124.190.154]) by smtp.googlemail.com with ESMTPSA id p16-20020a170902e75000b001dd7a97a266sm2006520plf.282.2024.03.28.12.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 12:55:26 -0700 (PDT) From: Wedson Almeida Filho To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: [PATCH v2 3/5] rust: module: prefix all module paths with `::` Date: Thu, 28 Mar 2024 16:54:55 -0300 Message-Id: <20240328195457.225001-4-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328195457.225001-1-wedsonaf@gmail.com> References: <20240328195457.225001-1-wedsonaf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wedson Almeida Filho This prevents the macro-generated code from accidentally referring to the wrong symbol if the caller's code happens to have submodules called `core` or `kernel`. Signed-off-by: Wedson Almeida Filho Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/macros/module.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 27979e582e4b..6da1246742a5 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -213,12 +213,12 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { // SAFETY: `__this_module` is constructed by the kernel at loa= d time and will not be // freed until the module is unloaded. #[cfg(MODULE)] - static THIS_MODULE: kernel::ThisModule =3D unsafe {{ - kernel::ThisModule::from_ptr(&kernel::bindings::__this_mod= ule as *const _ as *mut _) + static THIS_MODULE: ::kernel::ThisModule =3D unsafe {{ + ::kernel::ThisModule::from_ptr(&::kernel::bindings::__this= _module as *const _ as *mut _) }}; #[cfg(not(MODULE))] - static THIS_MODULE: kernel::ThisModule =3D unsafe {{ - kernel::ThisModule::from_ptr(core::ptr::null_mut()) + static THIS_MODULE: ::kernel::ThisModule =3D unsafe {{ + ::kernel::ThisModule::from_ptr(::core::ptr::null_mut()) }}; =20 // Loadable modules need to export the `{{init,cleanup}}_modul= e` identifiers. @@ -230,7 +230,7 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { #[doc(hidden)] #[no_mangle] #[link_section =3D \".init.text\"] - pub unsafe extern \"C\" fn init_module() -> core::ffi::c_int {{ + pub unsafe extern \"C\" fn init_module() -> ::core::ffi::c_int= {{ __init() }} =20 @@ -248,11 +248,11 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { #[doc(hidden)] #[link_section =3D \"{initcall_section}\"] #[used] - pub static __{name}_initcall: extern \"C\" fn() -> core::ffi::= c_int =3D __{name}_init; + pub static __{name}_initcall: extern \"C\" fn() -> ::core::ffi= ::c_int =3D __{name}_init; =20 #[cfg(not(MODULE))] #[cfg(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS)] - core::arch::global_asm!( + ::core::arch::global_asm!( r#\".section \"{initcall_section}\", \"a\" __{name}_initcall: .long __{name}_init - . @@ -263,7 +263,7 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { #[cfg(not(MODULE))] #[doc(hidden)] #[no_mangle] - pub extern \"C\" fn __{name}_init() -> core::ffi::c_int {{ + pub extern \"C\" fn __{name}_init() -> ::core::ffi::c_int {{ __init() }} =20 @@ -274,8 +274,8 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { __exit() }} =20 - fn __init() -> core::ffi::c_int {{ - match <{type_} as kernel::Module>::init(&THIS_MODULE) {{ + fn __init() -> ::core::ffi::c_int {{ + match <{type_} as ::kernel::Module>::init(&THIS_MODULE) {{ Ok(m) =3D> {{ unsafe {{ __MOD =3D Some(m); --=20 2.34.1 From nobody Sat Feb 7 19:41:29 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 1ACAD13BAF9; Thu, 28 Mar 2024 19:55:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655733; cv=none; b=HNWwr83j1Cj5xQxHNO2J8oXD9t9+ABelZWyOZJyCN9+UCNsIg6J+aNqlcil7G7ne5bxZk9ru2Bi3J9/I3Ox5A8ct9SnmOeisqGCbFxE2xHT+ctNC0Plnd3LChT/FZhJWpjgBQLYcG0kE/WS16PzzEGsFNOnMCzI1ElCW2Cn6PrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655733; c=relaxed/simple; bh=9njTVxVVwgfiSjgHOUmEIu0P17Go2yCn58n6W0SP5Es=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DW76CF1BTvWWiGbG483kpBKGFiSt68O9X9WqthLa6X4mZ49oFQHWzkJJlW3ee7l3GvghTNEFfhEAamxDmK90ET89o+iXS0gGz3ApaNp2lLgPWejjYqbsLEU00BfnTM9kjRACjqNShRZafSQ6eozfvvyILkNqbe1kOfMGNMJ3+Gw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X0sf9n78; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X0sf9n78" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1e0189323b4so9647925ad.1; Thu, 28 Mar 2024 12:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711655731; x=1712260531; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eFzgNfFcqYNPSbmQhYX6OGJpt5Y5nswpF3NJb6j2OdA=; b=X0sf9n78PRMly+zsDkFGk5+vfx/3k5TYkRJOUHAH+Ue4+PdlCN+Ves8y3Vp8yM8AhO TU5jKaCSOK6T2Avxlbt+BOVK0oXE+0p2DEH7L4g7GZxB/eirnloL2vE0cgKJdp+3NHky RU+7cBO+8+6QYj+H/UiOGzgdUAnPJ+B6kAUU0vZe86PlLRKcuqsJtzpnkXTgENv62IRy rQ7UGeZBsdy6OG92Ti9AAwBWlSLtZov4pDBCnEFmnpD7xRLDcgQR8XvXzhGP8osesg/n OEoTK4pRPQCEPFbdbd8mq8+HJeVkXEHipijm+PD4S7iVKXDo8GobJXcsorI8iHzIMc6f tqgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711655731; x=1712260531; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eFzgNfFcqYNPSbmQhYX6OGJpt5Y5nswpF3NJb6j2OdA=; b=DdvSGjE0EFHOq8gauYOlJKjrYK14LpFz+6/vHNjqu8aHtKDW0AhtocyAMYEDHLssUs 2Nt90Gx4OghVhdjy+4VUgcGv6+gVzmxh+FkaYN04NGBbv9dseUG6N8LTKr+BsZwctxTU oERfhmlsYszuhdZVdH3sBglnOmZdKuLUbS9ue0oot6A+qdrOgszDW3ycx7kFSdKxajs4 t0c8xCKK/ZOt9UXvJsyZhHCuDBGA8QbI+I4QthuJcn4c6HXHXSj3DKYwTbHUYYXEUOpa 4WPxzV+d0QU9I0gVIfDeD/U9puT8Bg3HOzWGnF8md7TzbuLpuLeSJERrZfkGiZ3CWexy xc8Q== X-Forwarded-Encrypted: i=1; AJvYcCWc4NUEKuKlbymLa49I5Kuk6uwlnm1iYdAhvPnZGMnrR/UhfASeB+6M/AbStx2pZ+nRUcY6oDQ6V7g6Imz1ImNONMl82Cvh/pJcSuZN X-Gm-Message-State: AOJu0Yy0LzsOf6dcyZIq1ikfSJ4BwhoA9nocd11I6Gmy8unsdq07Lf4T tbW3ajbEjvdqUNAUua8zPGHAmJ+m2qt1ze6JCZzdw+clPHznkfiR/oKJVkxQ X-Google-Smtp-Source: AGHT+IG+D0l6DfepneZctCx/VQQeOlx1YOgoyeQ+hN3YPoAaK0e9uIe53cdwNnhuxyCx3RQMpgPJXw== X-Received: by 2002:a17:902:6541:b0:1de:e954:c0e4 with SMTP id d1-20020a170902654100b001dee954c0e4mr346476pln.63.1711655731409; Thu, 28 Mar 2024 12:55:31 -0700 (PDT) Received: from wedsonaf-dev.home.lan ([189.124.190.154]) by smtp.googlemail.com with ESMTPSA id p16-20020a170902e75000b001dd7a97a266sm2006520plf.282.2024.03.28.12.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 12:55:31 -0700 (PDT) From: Wedson Almeida Filho To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho , Valentin Obst Subject: [PATCH v2 4/5] rust: introduce `InPlaceModule` Date: Thu, 28 Mar 2024 16:54:56 -0300 Message-Id: <20240328195457.225001-5-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328195457.225001-1-wedsonaf@gmail.com> References: <20240328195457.225001-1-wedsonaf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wedson Almeida Filho This allows modules to be initialised in-place in pinned memory, which enables the usage of pinned types (e.g., mutexes, spinlocks, driver registrations, etc.) in modules without any extra allocations. Drivers that don't need this may continue to implement `Module` without any changes. Reviewed-by: Benno Lossin Tested-by: Valentin Obst Signed-off-by: Wedson Almeida Filho Reviewed-by: Alice Ryhl --- rust/kernel/lib.rs | 23 +++++++++++++++++++++++ rust/macros/module.rs | 18 ++++++------------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 9141a95efb25..64aee4fbc53b 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -72,6 +72,29 @@ pub trait Module: Sized + Sync + Send { fn init(module: &'static ThisModule) -> error::Result; } =20 +/// A module that is pinned and initialised in-place. +pub trait InPlaceModule: Sync + Send { + /// Creates an initialiser for the module. + /// + /// It is called when the module is loaded. + fn init(module: &'static ThisModule) -> impl init::PinInit; +} + +impl InPlaceModule for T { + fn init(module: &'static ThisModule) -> impl init::PinInit { + let initer =3D move |slot: *mut Self| { + let m =3D ::init(module)?; + + // SAFETY: `slot` is valid for write per the contract with `pi= n_init_from_closure`. + unsafe { slot.write(m) }; + Ok(()) + }; + + // SAFETY: On success, `initer` always fully initialises an instan= ce of `Self`. + unsafe { init::pin_init_from_closure(initer) } + } +} + /// Equivalent to `THIS_MODULE` in the C API. /// /// C header: [`include/linux/export.h`](srctree/include/linux/export.h) diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 6da1246742a5..4e5b5a68c3af 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -208,7 +208,7 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { #[used] static __IS_RUST_MODULE: () =3D (); =20 - static mut __MOD: Option<{type_}> =3D None; + static mut __MOD: ::core::mem::MaybeUninit<{type_}> =3D ::core= ::mem::MaybeUninit::uninit(); =20 // SAFETY: `__this_module` is constructed by the kernel at loa= d time and will not be // freed until the module is unloaded. @@ -275,23 +275,17 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { }} =20 fn __init() -> ::core::ffi::c_int {{ - match <{type_} as ::kernel::Module>::init(&THIS_MODULE) {{ - Ok(m) =3D> {{ - unsafe {{ - __MOD =3D Some(m); - }} - return 0; - }} - Err(e) =3D> {{ - return e.to_errno(); - }} + let initer =3D <{type_} as ::kernel::InPlaceModule>::init(= &THIS_MODULE); + match unsafe {{ ::kernel::init::PinInit::__pinned_init(ini= ter, __MOD.as_mut_ptr()) }} {{ + Ok(m) =3D> 0, + Err(e) =3D> e.to_errno(), }} }} =20 fn __exit() {{ unsafe {{ // Invokes `drop()` on `__MOD`, which should be used f= or cleanup. - __MOD =3D None; + __MOD.assume_init_drop(); }} }} =20 --=20 2.34.1 From nobody Sat Feb 7 19:41:29 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 69DC113BC27; Thu, 28 Mar 2024 19:55:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655737; cv=none; b=fMSqC8J6cpltg8xUHnI7b2zNNtLWL6Zi4GzqqugNvkNg6IHnAhXGNwzDeXvr/CixSSgn4ZQl9T5TGnbuH2KSML+JLYNboPNc/LcZoDuxz7l6MpXcJCMU6ogKuRpu+vHvMW0y7TTJW5isxFcobIZzGpYFKcHU6Le/pTBoPdU4bok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711655737; c=relaxed/simple; bh=wWj//ZRkBbl8k60DprtNUbePyBaev0Or6IZeN9Y0ZaE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mZIvUr8Ft/KcqoEXfePbU/oC7L7pb5vXuAak7Moopg0u8DYRpf2OhKbqBQoZDHk5OSbaFcFKCk60ZcfZc0o8I5TWlVdbth4OPavhLW5DzI0hDW0AqSG1HWy44ILy3LRK2mpjP4agd7atnh2NzCNM2xMNl9ZoMxz3W6UGCfWhgB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D3QhY6pb; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D3QhY6pb" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1dddbe47ac1so16416315ad.1; Thu, 28 Mar 2024 12:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711655735; x=1712260535; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FSb8eKkSmpgApznHJ4AQVQvwhW2C0OCmaJRtnqePdn0=; b=D3QhY6pbNoh936GluYPFBXQN+gzC+/IFa3A75000ODAywdMBJiQT+U42SxvtTuMDFb Uyc/xjuyo22P6jsAtp0ie356IfQXK4oGD6R7zJSodh5D9VC5R67ElIZJU9H731ZoK4VG 91drqQ4dM73wssfGwr8oKI2K4HfjXb724LO+axkabUIDo7JjhjqSuj9K0HY5+CGnRWXN VnuzTzfKLSfizfF2Rq8Evq7YWiSRcUzaRHTP7j+ydrgmCOCn/pq585tJ+3UUuDfQxGmH t5mJfWVcvmX6EGreoQFxwL77RA43EVIunyZuURHt5vVWGOI3amCTVtf+ZzACv3ykypIC LN8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711655736; x=1712260536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FSb8eKkSmpgApznHJ4AQVQvwhW2C0OCmaJRtnqePdn0=; b=NMNsHNwAiSfWSPrQGzGriecta0S7n5TjTjJIgUZD6c4VBgRDrlzLPVVOdyKPwpgMWG 4AahqgOw+RNm5ht/5lekvoiAWazv9rTCiVq9qxo7N8hI4ch1oHLNLkQP7fzFWSuph1m3 P0ZB2m/mKLBvGl82yqCqg/H/PO0J7n/2uHXaQfMyZehtVWvxsbtdPnnC4pB+7fNxP/Gg DUpLiZmvN86Nn1xuh1qQ51S4FyELzDV0lM1eywYtoeO0ql12Q3X9e2Vh8/bTsHoyKIsy 5dU5SLoZmpBguGusQGdZVxJbXm6bDhMX/VcS4Z+uEAdGbG5gPLEIwUGgq4NriqkBCVqn LJ4g== X-Forwarded-Encrypted: i=1; AJvYcCUmYaXS3HbbHxuOnQ0hwWb1NaR0B20EYjD7hqV/rI0HWTRW3n0cVyviqgmrOAVMrEIWFhfYNsna5+Cf+p4CM/5SJAckxYVTyHadxTVr X-Gm-Message-State: AOJu0Ywlnoiy4SEiFcLyiUMZtUdZkZNhPKRXEwfdjzw5lIPEczX3sshI 6tBU2Gp8Ci7IoxJpXrtycu2xlBipnQ0Ns8Kh7e2weyBzu5Wq173VmRwbEdFI X-Google-Smtp-Source: AGHT+IEYlLJemolUcBMlceKN++uY05ZJZtrov0oZFQWPSostxpmZPLoRzERpdQ0s6Sky87FcZRHvVg== X-Received: by 2002:a17:903:1c7:b0:1e0:115c:e05a with SMTP id e7-20020a17090301c700b001e0115ce05amr5392991plh.12.1711655735653; Thu, 28 Mar 2024 12:55:35 -0700 (PDT) Received: from wedsonaf-dev.home.lan ([189.124.190.154]) by smtp.googlemail.com with ESMTPSA id p16-20020a170902e75000b001dd7a97a266sm2006520plf.282.2024.03.28.12.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 12:55:35 -0700 (PDT) From: Wedson Almeida Filho To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: [PATCH v2 5/5] samples: rust: add in-place initialisation sample Date: Thu, 28 Mar 2024 16:54:57 -0300 Message-Id: <20240328195457.225001-6-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328195457.225001-1-wedsonaf@gmail.com> References: <20240328195457.225001-1-wedsonaf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wedson Almeida Filho This is a modified version of rust_minimal that is initialised in-place and has a mutex. Signed-off-by: Wedson Almeida Filho Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- samples/rust/Kconfig | 11 +++++++++ samples/rust/Makefile | 1 + samples/rust/rust_inplace.rs | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 samples/rust/rust_inplace.rs diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index b0f74a81c8f9..59f44a8b6958 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -20,6 +20,17 @@ config SAMPLE_RUST_MINIMAL =20 If unsure, say N. =20 +config SAMPLE_RUST_INPLACE + tristate "Minimal in-place" + help + This option builds the Rust minimal module with in-place + initialisation. + + To compile this as a module, choose M here: + the module will be called rust_inplace. + + If unsure, say N. + config SAMPLE_RUST_PRINT tristate "Printing macros" help diff --git a/samples/rust/Makefile b/samples/rust/Makefile index 03086dabbea4..791fc18180e9 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 =20 obj-$(CONFIG_SAMPLE_RUST_MINIMAL) +=3D rust_minimal.o +obj-$(CONFIG_SAMPLE_RUST_INPLACE) +=3D rust_inplace.o obj-$(CONFIG_SAMPLE_RUST_PRINT) +=3D rust_print.o =20 subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) +=3D hostprogs diff --git a/samples/rust/rust_inplace.rs b/samples/rust/rust_inplace.rs new file mode 100644 index 000000000000..0410e97a689f --- /dev/null +++ b/samples/rust/rust_inplace.rs @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust minimal in-place sample. + +use kernel::prelude::*; +use kernel::{new_mutex, sync::Mutex}; + +module! { + type: RustInPlace, + name: "rust_inplace", + author: "Rust for Linux Contributors", + description: "Rust minimal in-place sample", + license: "GPL", +} + +#[pin_data(PinnedDrop)] +struct RustInPlace { + #[pin] + numbers: Mutex>, +} + +impl kernel::InPlaceModule for RustInPlace { + fn init(_module: &'static ThisModule) -> impl PinInit { + pr_info!("Rust in-place minimal sample (init)\n"); + pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); + try_pin_init!(Self { + numbers <- { + let mut numbers =3D Vec::new(); + numbers.push(72, GFP_KERNEL)?; + numbers.push(108, GFP_KERNEL)?; + numbers.push(200, GFP_KERNEL)?; + new_mutex!(numbers) + }, + }) + } +} + +#[pinned_drop] +impl PinnedDrop for RustInPlace { + fn drop(self: Pin<&mut Self>) { + pr_info!("My numbers are {:?}\n", *self.numbers.lock()); + pr_info!("Rust minimal inplace sample (exit)\n"); + } +} --=20 2.34.1