From patchwork Tue Oct 1 14:59:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13818243 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 720BBCEACD5 for ; Tue, 1 Oct 2024 15:02:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 04C5668001B; Tue, 1 Oct 2024 11:02:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F09CD280068; Tue, 1 Oct 2024 11:02:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAAB668001B; Tue, 1 Oct 2024 11:02:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B5096280068 for ; Tue, 1 Oct 2024 11:02:29 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 713B4815F5 for ; Tue, 1 Oct 2024 15:02:29 +0000 (UTC) X-FDA: 82625349618.12.9DB69DF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 8A4D740012 for ; Tue, 1 Oct 2024 15:02:27 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pGrDvkAu; spf=pass (imf27.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727794882; a=rsa-sha256; cv=none; b=lqZiagVaPXenBphrrwpx6k8UktDvfP7MANKygyhsIWbjVwxAvczXpO5jSJEpmnHWQqs+EH RJp+DZebBct1RdsoVQl4Ve/aWVl7Rt8kNbIgcF94tfRua3OXhMkL8nEp/TnLKiATMLrDWw rLFa2Urmj3K4UCVqTHOv19W2aBQUSG0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pGrDvkAu; spf=pass (imf27.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=1727794882; 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=IIt0dFxxtEQYosJ5ltIiL6nguC3ESRR0tY9hc3mlrpA=; b=QoCVkZOqd07h8YEumHSPySg2p/8JZi5UyG/osN08TMTvvU03CfUQhrH403MUVreyYVAPA+ /RESj6NQhxWdBdCoULbOROTl+tppJs7nUTvd+6NTB0r5MliQsEq8Byoson4lXod4qU/Gwx r+TqF9qh5ha3PLDZQSrzP6g4ZqJcdgY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 981BE5C3930; Tue, 1 Oct 2024 15:02:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6951AC4CED3; Tue, 1 Oct 2024 15:02:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727794946; bh=ZDmHNLUIwFFHS+R3VBXXGD9KVgIi1Tkfsy4gCUrqKAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pGrDvkAu7K7mNxFAaWK1ijXKGhH0O55fTL6tlWOoxx7u5L1OfHYlMSDQlcCwRNz+k ZfFhTd9KDHWXs91qO5mF+JtxWNKdZ8HfZ2OODmexqa8PiZa5Vge98pHPs8N+YusiGC j0W418/ImK15iFqWO/ljbxZ02FLdhJSWbxlF0ao15m7KngrJTcRpzeV30jPZKwBryb 3I649ueGfTvclLz2QjX5T0L0dIrCN8B2zh7DX6PQjSg6pHY1axCLT2MR/IUmpT/Xnx EnGt8oLGcYhK0PX6UXV6hq6Ojfe1feUFvjHPV6Rfu+sLIWqe9FE5ToIRC3qH3vz98D r9ucqKGDGPTfA== 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 v8 24/29] rust: alloc: implement `contains` for `Flags` Date: Tue, 1 Oct 2024 16:59:59 +0200 Message-ID: <20241001150008.183102-25-dakr@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241001150008.183102-1-dakr@kernel.org> References: <20241001150008.183102-1-dakr@kernel.org> MIME-Version: 1.0 X-Stat-Signature: dpccn499jedtjikyi3jiq556kx9u5tw5 X-Rspamd-Queue-Id: 8A4D740012 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727794947-562340 X-HE-Meta: U2FsdGVkX19sOTuvAk0S300D3OYYDc+F7cR0DzRNdcc1oCYv3uJPqXiC2jSCND1QiBssb7O0LDbu2P6+FDzuMf4qML4yltERIcruqU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VpBvqFL0NnV75FCN3Fp5uVL2iiF5+tB8l7e63MDgRj2G3XNaw7tR8U8vsQD1IzGv+UTCo3NtGwlCXug0oh1IUkzs80hKdoUh5Mmd6PPSq2RngQDnDNYDvXRiJ1HHmCY5V/RiE3NpHe5boqWobgaPCDOs/GgsjOwcrdGmDaiogji68nBDP0mr67y1qdk1lp+8P4Q5cy 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 Reviewed-by: Gary Guo Signed-off-by: Danilo Krummrich --- 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 e8955340fe62..8acaa24a8f1f 100644 --- a/rust/kernel/alloc.rs +++ b/rust/kernel/alloc.rs @@ -35,7 +35,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 { @@ -43,6 +43,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 {