From patchwork Wed Sep 11 22:52:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13801194 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62214EE57DC for ; Wed, 11 Sep 2024 22:56:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E06216B00AD; Wed, 11 Sep 2024 18:56:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB4F86B00AF; Wed, 11 Sep 2024 18:56:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C56F96B00B0; Wed, 11 Sep 2024 18:56:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A30CA6B00AD for ; Wed, 11 Sep 2024 18:56:55 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 597CC160AB3 for ; Wed, 11 Sep 2024 22:56:55 +0000 (UTC) X-FDA: 82553969190.28.D0820F4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id B399420012 for ; Wed, 11 Sep 2024 22:56:53 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pnKBHrnc; spf=pass (imf03.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726095309; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V3AfaQ6IrC++OfKloqSZu9fg84uCu6HgILZZet6SJcA=; b=WR/sdQfovnZSPyN1ey5vYT1vqw7mROiSUuK6fuVzW8ifA+tBYO9kikK9V2yiriMBnULB76 TQxsuMn1EACt4yYBU7+zH9TVyQzOQd1frwaGp3QiS07J+udeqdEYY9wzRoSTfbi3xoi4u0 sALFlUXX1NIYuNL2xkvSzHEOD94eYkU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726095309; a=rsa-sha256; cv=none; b=oiSGotuXN5PS8zvWpgtvH7jsBvTyj224z335wR6hwBKsN9tGmV6n8vNEU9tfe0z1x72ZvY bo7SwjZcRIyteFt20pqm6FCZnYOYfWLPLxWEPWz/bc2H3TlDlQ17zFFbab/uHYtKDrBAnJ k7rsIJN+l6ioz6CWEAInwIN+pJObUPo= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pnKBHrnc; spf=pass (imf03.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 67BF05C06D5; Wed, 11 Sep 2024 22:56:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4980C4CEC5; Wed, 11 Sep 2024 22:56:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726095412; bh=BuRbAjKmy40vmT3N1pF21OHcKiAzSp8OEnKFLe420pQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pnKBHrncLFslJd6q/nHuhtzqz1+1TBPq4XFiNkHyvx2teZQ09/rGvMq0rkZmjaUBQ Lbl4cpf4vZTYynneRL3vdFi1Bfzk//roOP+ergED0hIoIvTi45n+mq3kqjXJBmtOIE 2TUOfgMT/w6x7qTIrzC8BUSB0AsHIbayljpcYeLVt29Kz+Z5MdCntUZpOmeys+BJf/ +U0AYlUBKLQjbjODoG/ESll0BCXm0zsGtMDWqGWYJ0vhDiGDgL7bZP03DwWiqctj4+ qO7e62LiIaAdh3IGXN1jfezc0FpgcGxB/ZoBVQ43AZLRbGXi/3TLRnAl1HraDUiSRM p61kKYP/nDxBg== From: Danilo Krummrich To: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@samsung.com, aliceryhl@google.com, akpm@linux-foundation.org Cc: daniel.almeida@collabora.com, faith.ekstrand@collabora.com, boris.brezillon@collabora.com, lina@asahilina.net, mcanal@igalia.com, zhiw@nvidia.com, cjia@nvidia.com, jhubbard@nvidia.com, airlied@redhat.com, ajanulgu@redhat.com, lyude@redhat.com, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Danilo Krummrich Subject: [PATCH v7 21/26] rust: alloc: implement `contains` for `Flags` Date: Thu, 12 Sep 2024 00:52:57 +0200 Message-ID: <20240911225449.152928-22-dakr@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911225449.152928-1-dakr@kernel.org> References: <20240911225449.152928-1-dakr@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B399420012 X-Stat-Signature: y8eiucpnwjcr7c7ja15brsdmtad8f8rp X-HE-Tag: 1726095413-413301 X-HE-Meta: U2FsdGVkX19ies8ZbudbcF7rxisp8vkKt0bu2IrySy2lT32laEZqV6+9D+/c+IT5Bhywlj74FrWw8XcJpc34EWi8tLRgg0stvWPEjfag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77atSqIuJ6oNXKBTs6lJI8Xixe4g8MxcWoGkyPNiSdP6p4cCd8ES0HsaIxaalXO7WbZMjNehaOhUXLdbNdXQU8T3fvPSE0FY1vfS0HlA2tuEsZxUiY6LUU58Hc3xKf9VIAX0gI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Provide a simple helper function to check whether given flags do contain one or multiple other flags. This is used by a subsequent patch implementing the Cmalloc `Allocator` to check for __GFP_ZERO. Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin Signed-off-by: Danilo Krummrich Reviewed-by: Gary Guo --- rust/kernel/alloc.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs index aabdf80e4f7b..caa0b9dfac87 100644 --- a/rust/kernel/alloc.rs +++ b/rust/kernel/alloc.rs @@ -34,7 +34,7 @@ /// They can be combined with the operators `|`, `&`, and `!`. /// /// Values can be used from the [`flags`] module. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] pub struct Flags(u32); impl Flags { @@ -42,6 +42,11 @@ impl Flags { pub(crate) fn as_raw(self) -> u32 { self.0 } + + /// Check whether `flags` is contained in `self`. + pub fn contains(self, flags: Flags) -> bool { + (self & flags) == flags + } } impl core::ops::BitOr for Flags {