From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 385E21AA1E4 for ; Thu, 12 Jun 2025 08:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749718200; cv=none; b=OO07k3zDnrYHJSUke/oNTvrY8ANACDOOfznBmWMeIE1+o5kcHmG0POdZBT/qdKDz4GQ2cD/w33+FsmX7WzfaIINLn9DR/C79vM0yq3m0DGUTyrG3wJmAWDVPVyryujQq38+wdXhW9jjgXtYFwuu6sP3H9KFVUjO6rUtTYJxqjGk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749718200; c=relaxed/simple; bh=Tz31FWc8ZSU6ldYx49dpHsfPC5cmR3+X/nnw+nZkGvk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=m1d41/ZH0mHCEGjNsqHZl4zU+OvgwRSVLNKo3YevbTyLGcscYvj7gpW0AlD3o2r7+4Xpi+v2cOgpPCslnjdY0y4RkpNZjS5iDKBzfRj9mzxTVJbFRlk5OLim4TYuq5drn5WjXtlygAhkYXH43H0Fz1fOA4X4OrVL2XWmy1Cc/lU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JGDmFSSC; arc=none smtp.client-ip=209.85.128.44 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JGDmFSSC" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-451d54214adso5332455e9.3 for ; Thu, 12 Jun 2025 01:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749718197; x=1750322997; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IuVAAh36fkRqoU5+WrRN9V7KcWrda8Rt/Pe6BIRVzcs=; b=JGDmFSSCSzqgimlwTAhwIlay4LeQ/ypez+MZ8tzllXwICqZT8KKb5jfVv0XwI5K+t5 POFQ24In6PA05H0BCeMTUAtwZP7d/kzTI+5SC5vwFFUyRC+M4chQ92hIOUb/M8H0qFwR dUT2a8vo2Z5fQ0LjlKyfMOIndQbhxXHC3ZC7Z5ljBzgWaDCVYN2l2LYYgHyvdSmNsoEO kq2nLjhVD4LmgwRxGqa363MQOoE/8gp5wDcn01TijMxKJ5b9PNyCUuUrYp1D4V5pOYI+ Mg/7Fx7kQZm+fHL6ZN6fKS5BcoKV7xTbjsgwOnrCcmhWt0jsTYjw+Nty66grcZxuMRBw n8gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749718197; x=1750322997; h=content-transfer-encoding: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=IuVAAh36fkRqoU5+WrRN9V7KcWrda8Rt/Pe6BIRVzcs=; b=sXgs+G5tMXxaBoq+H/AhxP1mQtwfBdTK3JENflj25qrFGCnx9WbW2+cfjf6IgM4FaH SnsqLDr91F0hLNWvVwtGCFKWuDf6MWWTDTntilzO6/WmWFAnGS2ikCLLs4/0iELfXYbx 6hKfce7il7JKKZkwUsRr3GglPbrv4vFB94V3wl99oJvEEvoVqi5tuAzqSY0SNJZ+rJgs bTxWZaUHw4ckItgWjn++tsqHOBz859qDvpMlsQUfb5GI1W6FMpWgiCWXS6dSvAIOy3wP TGKpnYA/SrMb2T41NWg+UVSBP7TrlrlrOrE+NlvufDAk4LeYEHB+gbUkn8nPG6/730qO oM/A== X-Forwarded-Encrypted: i=1; AJvYcCXNgqFTemF3BbvZFWb8gtaIu+Smt64vbuvNc3CIX5vIRvAUACNDqjnISOdpioW5+yE9ReiwEK1oWHkZ6weMlA==@vger.kernel.org X-Gm-Message-State: AOJu0Yx+nfB9zZTl947n8KlvmkPdfUBUzc96NVqhDtjxUHBKrBuz4sNj U3EPlNS7HNKkcnC5HleqPogL8LOIAMvYjF37mOsY+a1/DgIhi22QRWWSkKQvNDBI49spWjAQkGb oGn60Sy7ALd+DNeed2fwORtzvYBAHQ3NHNayRj/EW X-Gm-Gg: ASbGncvXy/VA/K0OGHZhN18aC1QxwqNnt54CQTjA8C/hpSgGoYbCkKH6dmLgGtx09dQ 9Af9PH1pRNYPFx8Xk2qMOI1emwK/uxKVcRoB1soBfLobPpxmwa11YkTxrROJiW2rE2n5zMNvJpH KjvleNLu1WIxAvVdOVZlDwez9ZAO+mDbNujSpqlVFTatEONSLY/rMngyemIjHw0eoxOwcG5l/y1 RJGJJf4Vz6L X-Google-Smtp-Source: AGHT+IHm7NginZE5oMnjujYEo6jg+R4PPqVdxx630Yf+odjyFRxGpbvJieAtccV/DmBp6q1if19zXlSexyIS2kSKvgI= X-Received: by 2002:a5d:64c9:0:b0:3a3:652d:1638 with SMTP id ffacd0b85a97d-3a5586e9619mr5350282f8f.48.1749718197373; Thu, 12 Jun 2025 01:49:57 -0700 (PDT) Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20250611194840.877308-1-bqe@google.com> <20250611194840.877308-4-bqe@google.com> In-Reply-To: From: Alice Ryhl Date: Thu, 12 Jun 2025 10:49:45 +0200 X-Gm-Features: AX0GCFvPCLH4mUb2i-_l7Sq7OF8j6-HxDtqlJsvNUK2C-bZxtlXbyZ5Jsfy0DRU Message-ID: Subject: Re: [PATCH v12 3/5] rust: add bitmap API. To: Burak Emir Cc: Yury Norov , Kees Cook , Rasmus Villemoes , Viresh Kumar , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , "Gustavo A . R . Silva" , Carlos LLama , Pekka Ristola , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 12, 2025 at 10:47=E2=80=AFAM Burak Emir wrote: > > On Wed, Jun 11, 2025 at 11:58=E2=80=AFPM Alice Ryhl wrote: > > > > On Wed, Jun 11, 2025 at 9:48=E2=80=AFPM Burak Emir wro= te: > [...] > > > diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs > > > new file mode 100644 > > > index 000000000000..1fe72ca980ac > > > --- /dev/null > > > +++ b/rust/kernel/bitmap.rs > > > @@ -0,0 +1,582 @@ > > > +// SPDX-License-Identifier: GPL-2.0 > > > + > > > +// Copyright (C) 2025 Google LLC. > > > + > > > +//! Rust API for bitmap. > > > +//! > > > +//! C headers: [`include/linux/bitmap.h`](srctree/include/linux/bitm= ap.h). > > > + > > > +use crate::alloc::{AllocError, Flags}; > > > +use crate::bindings; > > > +#[cfg(not(CONFIG_RUST_BITMAP_HARDENED))] > > > +use crate::pr_err; > > > +use core::ptr::NonNull; > > > + > > > +/// Represents a C bitmap. Wraps underlying C bitmap API. > > > +/// > > > +/// # Invariants > > > +/// > > > +/// Must reference a `[c_ulong]` long enough to fit `data.len()` bit= s. > > > +#[cfg_attr(CONFIG_64BIT, repr(align(8)))] > > > +#[cfg_attr(not(CONFIG_64BIT), repr(align(4)))] > > > +pub struct CBitmap { > > > + data: [()], > > > +} > > > > I wonder if we should just call this type Bitmap? > > > > OK. I am renaming the other type to OwnedBitmap then. Just thinking a bit more about naming ... how about calling it BitmapVec? Rust generally uses the terminology "Vec" to refer to arrays whose size is not known at compile-time, and "Array" when the size is known. Then, if we eventually add another type for declaring fixed-size bitmaps in Rust, that type can be BitmapArray (that's the type you'll want in a global). Alice