Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2980541rwb; Sat, 29 Jul 2023 20:05:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlFnfZq8K7IT6gx1OVccX5XFaPvOygaXAoAEKJCG+8ae7jWD6PhZxejlen2O0BgN71IBXvoM X-Received: by 2002:a17:902:f551:b0:1b7:f64b:378a with SMTP id h17-20020a170902f55100b001b7f64b378amr6210498plf.16.1690686345914; Sat, 29 Jul 2023 20:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690686345; cv=none; d=google.com; s=arc-20160816; b=KhyzFJXlkw+vVXlMgYPzVF1xmCIsGs8aXgFx417DyEvFLZFgd4vti5WOtFEozVzJ6Y WzTh/0/mqCXjOZs3uWo//agFc30Abo/zKd5XWj2zYIH5QdTsvBC19yQ1HswFwTnRro90 OaXSHPmE2XFMcRJLW5hb/lgu8xse25fn3zKbJremsfWSURCLfKa/oOTRVIzVC6yPSbD7 JCy4xSiTTDEDbRcRful+WCkoWp/PJR9COkQ8+TitkSOacI/GNkTopusbHApScOQvH0WO gr0tKFL4RYrembjLDfLzq0/Nn6gmPHAnjxycQsfr+jl+J8Ah3IouP/lDq6Vtn5bJqxxG 4IcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature; bh=PhtA3S/JDjazeAwjyLjhNAHRYNrsVmh0Eu0g8T30AIE=; fh=tFfV2Hc1NTWnO/fewVQCE2XevA8nc3/HN3wr0tC9QUE=; b=tMT3LAPTo4gA1fv0UQXfjpeyBcFNenhBMZPKjJvkNTkOXoh3TRL/MJzfeA7B49Un51 B0PZzI0OBFKneXfUQ8D+J1PM90YRAR7zCthWvYbJ7ggsY4GDm8AG8XoFNCz+MDWVFptF c7K+iNA1jHjSB1Y592crbhdi2yK8HcNgSPyMLQPTVawocND+hAoYVe3z6HmdNpWlPj9g 6VMP8mPEh0UcBm9caR53S6dVqKJ5+xOpOSxCyA6yoU53kgXGeEuxBXZjYgGuMry8YjHl +iiF5YrHVpwFb9XmvW4d1QMDJ45lMWMH8kj1mhHXR/FnMGWO1vO/Fgtzhdgn51Tr2nV8 8rhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=GxodfzLo; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a170902d2d100b001b8c824e826si3813685plc.533.2023.07.29.20.05.34; Sat, 29 Jul 2023 20:05:45 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b=GxodfzLo; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229643AbjG3B36 (ORCPT + 99 others); Sat, 29 Jul 2023 21:29:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjG3B34 (ORCPT ); Sat, 29 Jul 2023 21:29:56 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C3162D42; Sat, 29 Jul 2023 18:29:55 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-99c0cb7285fso23510466b.0; Sat, 29 Jul 2023 18:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690680593; x=1691285393; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=PhtA3S/JDjazeAwjyLjhNAHRYNrsVmh0Eu0g8T30AIE=; b=GxodfzLoeHEML6pPfMb2i5ubNXaelxwAO2W34igO8jTtDBLWAt2ufATykcytjJB8XK vRDO87nLa5BC6iBaAXZRhxA1WdUZnyXa6Oka3eCRskFpe0sphP2EKno+HJbCKkry8KOy /e7Kp1UbvgRvyH3FITUQ897aimqik+1v8IU1zDld5RkiJkubHET2EMfJ3SVYKX9+yDrW uci5ip+cKB0n4I4oupu75FnnBpkAAnFeRtrcpnzq8QYdWnzCksKBWKPhwd5vBad4Dkjw /XZJ4UfgI2saPGQ26eXmXctum+25eDOYCjhFIfpibT9wOEhjqBpY8pdiT0Lr+uNJjt+w p0jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690680593; x=1691285393; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PhtA3S/JDjazeAwjyLjhNAHRYNrsVmh0Eu0g8T30AIE=; b=H4xrd1bM20/zSK6tgcu29WAB6swX21hPDrD0Ec3esSOkeNkg9ZSCo6OgN9MKq01fg2 RznhtbxAORJCYkpMyAAcMRKt6cKcMp3e3Hp0xA01V3B92VRrtlYlbE0cO4mDuuZ9UEsN 9uNOFPQgMQ2fZFOXmZ7c8nFwhdCJ8hzYLm4EGohkmeOv1Ild2JGzV5wjNb4Efjr2mB6i rO5g1hgyNGUbvL/f5C3z4eXUR/BCoBo0vRB7dDj+W83nLj4NimtZJrLqwRLzN/d3eag7 VVf9FV0jZCRGlhMHMfcjksftS2fuZGWgxqpRshlkwroaCw8uOOi+UcGzMPkVkRQoe86Z N8Mg== X-Gm-Message-State: ABy/qLb4gPURkEpyTUTawhG20oEBkz572m0XwiAGjxi4stAWCUfQxv28 HKjRVdPkHdpf1ahcwArJyfY= X-Received: by 2002:a17:906:32c3:b0:970:71c:df58 with SMTP id k3-20020a17090632c300b00970071cdf58mr3269835ejk.42.1690680593477; Sat, 29 Jul 2023 18:29:53 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id s4-20020a170906c30400b009926928d486sm3948593ejz.35.2023.07.29.18.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jul 2023 18:29:53 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 45DFB27C0054; Sat, 29 Jul 2023 21:29:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 29 Jul 2023 21:29:50 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrieelgdegiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhepgeeljeeitdehvdehgefgjeevfeejjeekgfevffeiueejhfeuiefggeeuheeg gefgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsg hoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieeg qddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigi hmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 29 Jul 2023 21:29:49 -0400 (EDT) From: Boqun Feng To: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , 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: [PATCH 2/3] rust: allocator: Use krealloc_aligned() in KernelAllocator::alloc Date: Sat, 29 Jul 2023 18:29:03 -0700 Message-ID: <20230730012905.643822-3-boqun.feng@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230730012905.643822-1-boqun.feng@gmail.com> References: <20230730012905.643822-1-boqun.feng@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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) { -- 2.41.0