Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5524667pxb; Mon, 14 Feb 2022 00:46:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVG8PDLww3lxuBJPyOlSnDinaf8/KyBrBoD0VQ1NSSow60JuNdF+WrjewmJex1L7Z6pnZW X-Received: by 2002:a05:6402:448e:: with SMTP id er14mr14487361edb.440.1644828384473; Mon, 14 Feb 2022 00:46:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644828384; cv=none; d=google.com; s=arc-20160816; b=v/VuChKY8/S/8x5HzK+PkGCaqP87VBKTxOAqRLL0KgsT7C93am5M0HvU+YH3Hy1vHx MA6hFY1tBAVvxXxrUkdeDyt2okHbdZV5GA4Ct1hpC1iC3L/kRt1zvqvkDr+oUuc1bTqW pqzUrs9NC28BzgtFunTYLQOTrh/2SZ4LgEcW7bXKKawwjp7XwoUPpxFsdJz3PN/nReyx daZdkCLAu6+d8Kv/9Jw4xuEA+JvgyYzk7NaZe/nBQ9YcjXeNg5e7M4eZkcb7a2DwuzuQ OPrQuM0chRSvK66Titbo5iLGiB2yOVmRNex1Wh7Lh1jmzK7Y3taP0Yfl28CakiAXzReg lWtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dXSM5xdDFyWUNKhUzhGptRGBx5rWOK73GFZx/zWBRc8=; b=F+hJbdnoTJ1DShWhUr2sXnE4XLnPJOce7RyZbW2HThszIK1SkeRAZ7M3yWq0J8vacX V8Vpx2VT5UYBQ79rsPm/SHX2hbW4j0u9eWpY6MBfYyjQFMoJ2sztN4aJ9j4yP3w/Zkad Vb2LGmWJ2tkdaGmUxSqZ/W1uLNzMRNQPAwmKOXVBVaVHUpii+9t9zTSQ7JOROUgNJAUG 071uYsQd763T/2XIHpRizKHmq6KWaAEjMdfLK6JEZN524fLrgNXcxNjWtQUzbFJNsvlY Ot/7bwWrmAOjHsGUNTNJm7s2Q0NhL1VERMoSSSzxCjo5TNtHedQ49RduqLe3bs9EA8aZ Rr8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=W+cv+jWG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t16si17203461edi.545.2022.02.14.00.46.01; Mon, 14 Feb 2022 00:46:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=W+cv+jWG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234801AbiBNF1V (ORCPT + 99 others); Mon, 14 Feb 2022 00:27:21 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:34218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233254AbiBNF1U (ORCPT ); Mon, 14 Feb 2022 00:27:20 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE4A74E3A8 for ; Sun, 13 Feb 2022 21:27:12 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id i10so2044346plr.2 for ; Sun, 13 Feb 2022 21:27:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dXSM5xdDFyWUNKhUzhGptRGBx5rWOK73GFZx/zWBRc8=; b=W+cv+jWGDhLxepKIENZltiKGyObGtaLgzPhCm6O+2RO43+buTJzScUzaDJH3nVBSnm CM1lBO75X+dlCU+rhpoWFNg/+/8j8QSwZz5QGKfp6Xp0nmwpwdYVjtfDgkTZyOVS+a26 AyXMyNUvhOyYYoRMXlAZ7u1U8YMmA31mCS0Y0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dXSM5xdDFyWUNKhUzhGptRGBx5rWOK73GFZx/zWBRc8=; b=V2S3dC51NKlyTB9bKZGqNo+e1++nqHf+mzj47Odjss/3NVcSEq9TGsG8T0OPaX3pOG M9xI0shRNyfptnONRWuMZ93+NA019MiEinezvG8g1VbRHI0QrDTfr8oXv7v4BfIeMx9I lK00kid+vlldykNm599Si0NobDBPNeMqwp3XV3Oc/uldCQ1dcRdy+/j8Sc6xNEV9Wa/M aXmx5u46dYRI/DYBeaAza6P0i/0VFGOgtNg6updz4imAF89xXu6SS1Sm0uzswNpXP8Fy 3d84l+0RvchQacF58KaxPBnpaMqyI778BptkShvxTwiM4mt0I9AXv6jxmOaM0WSXJHtD ZPzg== X-Gm-Message-State: AOAM533vrFQ1tLly2vEOh0t/yIuopZFG/Y/O4G/F26dzZgZxq9AEGS2R bmMEzDjFANWR6a3n1UZLT5ZSVg== X-Received: by 2002:a17:902:e74b:: with SMTP id p11mr12810354plf.115.1644816432102; Sun, 13 Feb 2022 21:27:12 -0800 (PST) Received: from google.com ([2401:fa00:8f:203:b736:df7d:23c5:206e]) by smtp.gmail.com with ESMTPSA id w12sm18704725pgl.64.2022.02.13.21.27.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 21:27:11 -0800 (PST) Date: Mon, 14 Feb 2022 14:27:03 +0900 From: Sergey Senozhatsky To: Miguel Ojeda Cc: Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Wedson Almeida Filho , Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Michael Ellerman , Sumera Priyadarsini , Sven Van Asbroeck , Gary Guo , Boris-Chengbiao Zhou , Boqun Feng , Fox Chen , Dan Robertson , Viktor Garske , Dariusz Sosnowski , =?iso-8859-1?B?TOlv?= Lanteri Thauvin , Niklas Mohrin , Gioh Kim , Daniel Xu , Milan Landaverde , Morgan Bartlett , Maciej Falkowski , Jiapeng Chong , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness Subject: Re: [PATCH v4 10/20] rust: add `kernel` crate Message-ID: References: <20220212130410.6901-1-ojeda@kernel.org> <20220212130410.6901-11-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220212130410.6901-11-ojeda@kernel.org> X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (22/02/12 14:03), Miguel Ojeda wrote: [..] > +unsafe impl GlobalAlloc for KernelAllocator { > + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { > + // `krealloc()` is used instead of `kmalloc()` because the latter is > + // an inline function and cannot be bound to as a result. > + unsafe { bindings::krealloc(ptr::null(), layout.size(), bindings::GFP_KERNEL) as *mut u8 } [..] > +impl Pages { > + /// Allocates a new set of contiguous pages. > + pub fn new() -> Result { > + // TODO: Consider whether we want to allow callers to specify flags. > + // SAFETY: This only allocates pages. We check that it succeeds in the next statement. > + let pages = unsafe { > + bindings::alloc_pages( > + bindings::GFP_KERNEL | bindings::__GFP_ZERO | bindings::__GFP_HIGHMEM, > + ORDER, > + ) > + }; [..] Is this flexible enough? Why not let user pass bindings::GFP_* bitmask, just like what the underlying kernel API does.