Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp407560lqh; Thu, 28 Mar 2024 06:00:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7HSJghU/nHCsNWHCei9hAS8s5Yv3vluthLfTBfFPJZCp5HfUy1fGxpLYqwNNXlOyANfi7CSOaoeCz0uiHtvdj/qLEQuiw8vDjAASumQ== X-Google-Smtp-Source: AGHT+IHfVVum3Wc/w8hWF21pjbVo75IU501qy1Ipw+xgaqXHWruZyxBcpJhtudMpgFKgIT23rIw5 X-Received: by 2002:ac2:4d84:0:b0:515:92fe:4356 with SMTP id g4-20020ac24d84000000b0051592fe4356mr1724307lfe.2.1711630840466; Thu, 28 Mar 2024 06:00:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711630840; cv=pass; d=google.com; s=arc-20160816; b=iwadAczL5qkAAhX9P5qsY0FitvP9m2WN67RPF1q67AHGtriKeiUM0ZhEaXH+YKFp8+ H/nkHX+OuT3LMGbeTcggKkc1CfY0SA6JQJciNNqww9z4Y4gV1KubjflaF7MHdBxXVq44 ztln3WmvFnmsmChhGgVU+W1LsYpovI88L/1YnXvWXQKvPfoEkEShEL9ECbb8UUr1Yjvy PMGDgjHhrzgfKUURxUFj+EDD1pMzCmrVd/gHDAuwx5MdLmWIwB/2BBByiLhbHju/BHlF VU5y7pwIcXYnp1jAnldIayhikad2k3KEUajcU+PyxWPmR2XlljvM/mPqkRybcx06PkoY ub/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=f/AjMOT3HT8tt2clqaveH3JYtGktFT3MJvxhAn7/WUU=; fh=jYvatizDX3B7OQcNywAK4Blz7LynWkAzwVhqzXUSgQo=; b=s2K9qh7aGMvlwVrrOQ6AdU+Oygu5b+BzHMHM39cZ5qsCIDJCwRyi8c5Lw328p+ENKP IVIBMjp/SefFjznq3Kvj9Ch8vXhQIRxyUx2BT3DpWdNrUYYOTTHkoPV1/2eNczMJSOPY 89U5FqLjZlkUfQ2M8a3aEdPW6b950GVmZop1R5KXdTOJl9geKzhCCeEqbQZBg047Udq8 Vv6rCg847kpmxW4xc2UZS4Q14GFNKcKJ307d1tuMIByGQDCPFV74JAXwG+oheqZ+kVie PUCiMm5VcKHgDTF6ot67V8smuQLjhdO5uLkUZuVQeKw9nRDRYWlHkhb5iBysy2Nn6nQU rI5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EgOmWPFW; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-122935-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122935-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l23-20020a1709060e1700b00a46e35a410fsi655864eji.917.2024.03.28.06.00.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 06:00:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122935-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=@gmail.com header.s=20230601 header.b=EgOmWPFW; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-122935-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122935-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 2F8A51F258BD for ; Thu, 28 Mar 2024 13:00:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 537057F7CE; Thu, 28 Mar 2024 13:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EgOmWPFW" Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.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 769112D792; Thu, 28 Mar 2024 13:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630830; cv=none; b=QeT2eL4Q9gwpkZ1InHZlazedrooRfK3xYO9y0EuNbZcrGQp/Z114/qqZ6JGbJ/uNFLB9L66uFKtkCIdP74U6z0Dr7/nQQZdKNZpDyvLOz+ML7haXuOtLzzo5EtOE/9mFwL5osLeK3PpnBQ5U18/LdV51By5aAeWC3WW7xg/CBWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630830; c=relaxed/simple; bh=ytlDWQ3r0yK5DRXkZh2+9C09CjyHTWVJS0gSnhKeG1g=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=SuogrpNjQbyE1X9PPQdUe2nmtAiARhGD9epsyCs++uJQoDL+1hszumH0JTV37Ej4bB4RYHNwm+qlIDPD7ZxzeNxbCTGfsKIAJUAQ13m/SvMinN/4ACNSBQ/lbLessbYvBm3+JgX5Z/BeilOeHFAVAGJH7ExqP5XazG4CCIQn2GY= 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=EgOmWPFW; arc=none smtp.client-ip=209.85.128.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 Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-61149e50602so7254057b3.0; Thu, 28 Mar 2024 06:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711630827; x=1712235627; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=f/AjMOT3HT8tt2clqaveH3JYtGktFT3MJvxhAn7/WUU=; b=EgOmWPFWrFER7QZhHz9BkULp2rvqocyUBeeNn6BomHeaaAZlogpYPjyIBTRMzPGJLN kV8vJlfCb/mk+vQjBFCVR9VRWUOdh0QczuLWZ8Yf9VQqbQjZiH2ERegMc+7LsT7AiKyc SOq9tPXjerqK2JRM2HMBAve9+XXLdFeNapdHIVyymGYEsGvfKxMEUSLJ4SKHSIY3B3rN B6yRbqS8OpYdsAl1K2fPPqGdfY0lqYJ7jQC/D74eYYXzmuCVxUXT2ULPFb1TJGHATWcC jhklbHryB5oD18cBXhttn/ZjyVrrR8BQaj6ypse10svKv1UQhMoca8QgFMLC+DYl4A7E ypqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711630827; x=1712235627; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f/AjMOT3HT8tt2clqaveH3JYtGktFT3MJvxhAn7/WUU=; b=Vu6zzpsplfE9Z+/Nwx3p80255uihqVKjSeWafN+tmjaYB+fxO9vYQxomwRwBcfR3ax u4FXujBUiWGAB0jbQ7P0fEYt5omKXGYj/pg6wOGsObsolNSiRqTNoUheUuXX2dvUjWMa 1jxS1+Ldg5ZN7pSMHziKDGnn9RHD0R0FjCNgQdFYV3ies2eJpowqTOb2PIVLTU2B1yid IKCQK4ovOA2Xz4g2x1Y/djDSzHSq/MP++lmRWkjyGmnhFJJ+1jXlng9saAbmSp8HNSfW mZSPfbOGU1dX/HhJREIKK5gEpaRTprq13f7GD1b71cg5UZfBjnRqMnyVBe6kPO1TjMI3 ek+A== X-Forwarded-Encrypted: i=1; AJvYcCWi5EpqC5ssCPfvYjz8r7vOciOVWX6GXomtwxh2GzjPPXbEqa7xuYZ8SDWTUh39pXv7hfRAKe2d1hXPdhpC+aTVvY/uqDIICYb3+li/ X-Gm-Message-State: AOJu0Yx6Un4ue9oH5F+nYFtbA/zthe/u9XuLYTbdkYqZpml7s6a3u5Bp gKdY22PtvoXcnv2DQ8lDT/IJB1QGumAjjJV99ZPGByYrU3c8vJxFsxTY292vYWc5Sa+J2/1dF0D CnaqRZbBMBpYlRrzZAJukPzqbLGE= X-Received: by 2002:a81:47c1:0:b0:613:fb28:b694 with SMTP id u184-20020a8147c1000000b00613fb28b694mr1127105ywa.3.1711630827494; Thu, 28 Mar 2024 06:00:27 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240327032337.188938-1-wedsonaf@gmail.com> <20240327032337.188938-3-wedsonaf@gmail.com> In-Reply-To: From: Wedson Almeida Filho Date: Thu, 28 Mar 2024 10:00:16 -0300 Message-ID: Subject: Re: [PATCH 2/2] samples: rust: add in-place initialisation sample To: Benno Lossin Cc: rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho Content-Type: text/plain; charset="UTF-8" On Wed, 27 Mar 2024 at 10:53, Benno Lossin wrote: > > On 27.03.24 04:23, Wedson Almeida Filho wrote: > > diff --git a/samples/rust/rust_inplace.rs b/samples/rust/rust_inplace.rs > > new file mode 100644 > > index 000000000000..ba8d051cac56 > > --- /dev/null > > +++ b/samples/rust/rust_inplace.rs > > @@ -0,0 +1,42 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > + > > +//! Rust minimal in-place sample. > > + > > +use kernel::prelude::*; > > + > > +module! { > > + type: RustInPlace, > > + name: "rust_inplace", > > + author: "Rust for Linux Contributors", > > + description: "Rust minimal in-place sample", > > + license: "GPL", > > +} > > + > > +#[pin_data(PinnedDrop)] > > +struct RustInPlace { > > + numbers: Vec, > > +} > > + > > +impl kernel::InPlaceModule for RustInPlace { > > + fn init(_module: &'static ThisModule) -> impl PinInit { > > + pr_info!("Rust minimal sample (init)\n"); > > This text needs updating. Fixed in v2. > > > + pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); > > + try_pin_init!(Self { > > + numbers: { > > + let mut numbers = Vec::new(); > > + numbers.push(72, GFP_KERNEL)?; > > + numbers.push(108, GFP_KERNEL)?; > > + numbers.push(200, GFP_KERNEL)?; > > + numbers > > + }, > > + }) > > I think it might be useful to also have a field that needs pin-init, eg > a `Mutex` or similar. What about placing the `Vec` inside of a mutex? I'm not sure this belongs in a "minimal" example. But I added it in v2 because we're already violating minimality with vectors anyway. Perhaps we should later have minimal samples and rename these to something else. > -- > Cheers, > Benno > > > + } > > +} > > + > > +#[pinned_drop] > > +impl PinnedDrop for RustInPlace { > > + fn drop(self: Pin<&mut Self>) { > > + pr_info!("My numbers are {:?}\n", self.numbers); > > + pr_info!("Rust minimal inplace sample (exit)\n"); > > + } > > +} > > -- > > 2.34.1 > > >