From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E28CDC41513 for ; Mon, 31 Jul 2023 08:53:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229615AbjGaIx3 (ORCPT ); Mon, 31 Jul 2023 04:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjGaIwa (ORCPT ); Mon, 31 Jul 2023 04:52:30 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CCEE1FC4 for ; Mon, 31 Jul 2023 01:49:32 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b962535808so64017991fa.0 for ; Mon, 31 Jul 2023 01:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1690793371; x=1691398171; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=AEpQPsL8CKvgd9jCnKauvgppTMsvJVGBjZ9X1QDN9oE=; b=4CsLTWSrXtKZeou89ehTdDcI35pXhzam4Gf+T2BNZK/F9IAwoXnSZdoCJhiuzuWEob v+FHWghCDcj3bHalbjjF+ZQpieuLc22Up7FE1aLSBkKUodTfIVMGIuVzXjati/lwr9gN XAU30D5Zh4A4gcTRNx85Pq1gBYV9VweZylbeWjn8M8U2ijFQBPYl1taHlJn3CxMF0CVh GA8hHanjU1vc9LC8TTV0LsX0+xlRcpJ6WxpwyzrK8ioLE8hEH0VzN2K8ePI9xuHXUvtL e1Inx4wkGuVdOmVskj2bNxagSFMJU2veOk4Xv/8H35PxkMBvvSD7cWsft78kMFPaGKOK WNIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690793371; x=1691398171; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AEpQPsL8CKvgd9jCnKauvgppTMsvJVGBjZ9X1QDN9oE=; b=cDc+uK4mwp1V5On3nI7/PfguhBOYVhu4m+CT+FbBqG+2N59TKnojHSZwuvHEZ2xo7t 6DxyVuGdIg7gVVcNMIklt83czKrs/uDFZg6EMvWb1obsP59KptdJsqICq7d2wejvnPSj vZXcXNCwcKS/vMv4duz4ASQhlC4Zxe76YypjoszqLfUNLgkp/npXKLbkzE0CvBFYPjMw GRP9+gJvFSvuwi0OHg6tw6asuMfuRbss3Y4/2IckxIHKmE9aV15tjjhCLc9ULXWfyPlr CQpQvKVFB1rve8AlBQyB4bGbUIF2v90jM9686LqgkoziHNvwLRZ3j8DGa3G3RXFoY3CC HOZg== X-Gm-Message-State: ABy/qLboFH8zUyUBSVwBSgFXvHB4/nWjcFhIVI/DFfrNaZ6zfpENXyK3 VAiYo6nlbmGBXwvh5DVEWdIlxQ== X-Google-Smtp-Source: APBJJlGFJ70YghXLG/YDeubPbpWWwMiyEaj0546fMRnCHGzwMbMfwcMsEuKBc1tsdJm+7ssl+pZkYQ== X-Received: by 2002:a2e:2c19:0:b0:2b7:3b73:2589 with SMTP id s25-20020a2e2c19000000b002b73b732589mr5498532ljs.32.1690793370676; Mon, 31 Jul 2023 01:49:30 -0700 (PDT) Received: from localhost ([165.225.194.221]) by smtp.gmail.com with ESMTPSA id w3-20020a1cf603000000b003fa973e6612sm13350468wmc.44.2023.07.31.01.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 01:49:29 -0700 (PDT) References: <20230730012905.643822-1-boqun.feng@gmail.com> <20230730012905.643822-3-boqun.feng@gmail.com> User-agent: mu4e 1.10.5; emacs 28.2.50 From: "Andreas Hindborg (Samsung)" To: Boqun Feng Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , Benno Lossin , Martin Rodriguez Reboredo , Alice Ryhl , Dariusz Sosnowski , Geoffrey Thomas , Fox Chen , John Baublitz , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Kees Cook , stable@vger.kernel.org Subject: Re: [PATCH 2/3] rust: allocator: Use krealloc_aligned() in KernelAllocator::alloc Date: Mon, 31 Jul 2023 10:48:57 +0200 In-reply-to: <20230730012905.643822-3-boqun.feng@gmail.com> Message-ID: <873514qxd2.fsf@metaspace.dk> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Boqun Feng writes: > This fixes the potential issue that when KernelAllocator is used, the > allocation may be mis-aligned due to SLAB's alignment guarantee. > > Signed-off-by: Boqun Feng > --- > rust/kernel/allocator.rs | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/rust/kernel/allocator.rs b/rust/kernel/allocator.rs > index fae11d1fdba7..1aec688cf0e0 100644 > --- a/rust/kernel/allocator.rs > +++ b/rust/kernel/allocator.rs > @@ -41,9 +41,9 @@ unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: Layout, flags: bindings::gf > > 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 } > + // SAFETY: `ptr::null_mut()` is null and `layout` has a non-zero size by the function safety > + // requirement. > + unsafe { krealloc_aligned(ptr::null_mut(), layout, bindings::GFP_KERNEL) } > } > > unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { Reviewed-by: Andreas Hindborg