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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21315C30658 for ; Tue, 2 Jul 2024 21:42:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 935BC6B008A; Tue, 2 Jul 2024 17:42:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BE3D6B0092; Tue, 2 Jul 2024 17:42:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 711556B0095; Tue, 2 Jul 2024 17:42:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 50DE56B008A for ; Tue, 2 Jul 2024 17:42:15 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D941D16059B for ; Tue, 2 Jul 2024 21:42:14 +0000 (UTC) X-FDA: 82296136188.21.C28FF40 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by imf20.hostedemail.com (Postfix) with ESMTP id 999EA1C0015 for ; Tue, 2 Jul 2024 21:42:12 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CNBdHD82; spf=pass (imf20.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.181 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719956510; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gJQj9aBGbbKul4hCpDKi82UeY7RwXMGhGVaVDyW0wOk=; b=l3Ieq5NFZQcMRGK52CR1GSfX0GJ+Fhnwnn5wbgukaW6EM88rgGAt176CFfLqnKTdKw7xl5 AJ6ep9mwyo4/x9JxaM2By/iVfINDqQ7VPefZ48d4GXNspTP5JzwNe8jFgRb9a5QUm5igTU 1BeFOr2FjlNKZ/ITEZ6f+8M4DM80U3c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719956510; a=rsa-sha256; cv=none; b=ngOmGqmj/d0X/Ma7tpRrB5N66VIdPHi+Se2T6ggWB4TUFnZ8eXt9t3VRIaB2rVpoiz5RFv sXtbyL5dKaNiTGqkMNE4VELOxZ+GvC7WJC0MjEVdnD4TX/ZydOyicABEKx72/pCb89NJ7c pmyMdhz09upQ2iqARMHpDuou7FqzoIg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CNBdHD82; spf=pass (imf20.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.181 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e03618fc78bso4294038276.2 for ; Tue, 02 Jul 2024 14:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719956531; x=1720561331; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=gJQj9aBGbbKul4hCpDKi82UeY7RwXMGhGVaVDyW0wOk=; b=CNBdHD82IthYYMiOYg+nqmAELcFC5vaZ2eheMpKOzpLAC3NOV7RVhgBx/nXpCq8M5A 9EmJ/TluKFznqy/nBTNx2yf+uJ3Z3OBYsgk3HIKtMIbaN0qku5QFg7Cn9k61/EZYFFW1 EK7uFkO+mJeE0xbrJaDo9JFq0a1DpVvQNaEY8KeTs58hlsj2A9uTSWB3rsohDFIEWM+A wNcolMQw8hmUgFlbjt+lkCyRllBuOhKvOKzsVGcywi1gDHwOKqSqkVFul1kFQ6+8zw/T +vf0bn1uwTa860Fyj0HAdz4PH+I+6HFdT6wejAqaWnZS49o/H1Qvl4/3zU2d9XSwlQik esdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719956531; x=1720561331; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gJQj9aBGbbKul4hCpDKi82UeY7RwXMGhGVaVDyW0wOk=; b=J68Rwt8jbbGVwbV07CD5hM4IChdoTZ3x91r6lyQjnupUjQwXGhf030oSVBNEauzTYT hrvYP99KJa/LsvXJfPs73CWAQxvI2NQHsiRd83P24N8c78g5SZUM8IPRv53Wp/Xra1MV qgdbJkXsQfHRVzEMo/nAE0fnzEUDwXdYb4ROIYrP0c4BqHUuNd/n7mwitNaVIm25fWAU s/UvE6WKUPFfCPvlLe1PVNWIF/zLcCGAAJek3CnPCIqxfDVlSgeeSd+rtC4jS5IKDCsE 1iSUgMvNg04wypVzE1iNLT2RfcH7b+226RDQg1V5BDByc83psN2GyI8Z9atQ4pyriNOw 7cRA== X-Forwarded-Encrypted: i=1; AJvYcCVp2T7H2uBLL9ZUdHHUR7v7DFKBpRKWofxXSmu3QYC6/Fr5plsTMNet9q3tMkIswen4FuXNaeThruSKxtZAbSGLp50= X-Gm-Message-State: AOJu0Yx2U5GQF6v3tQnmDH64xTn6ypoFMGFiVs0f54AfV3K1ie3nuhZw lQI6MVq/kPWe80FCaZwMUKUXSgOQ36XsOwiTUgLH9ThOt0keqjZY X-Google-Smtp-Source: AGHT+IH1O8QzAcBaZC3Iu5DWMawGK4UuV/285H1s7NP0rmqg1WqoLOmUjwLDaVwNlrwR4zcAGkYHmA== X-Received: by 2002:a5b:f09:0:b0:e02:c70d:d292 with SMTP id 3f1490d57ef6-e036eb6e1b9mr10684186276.33.1719956531633; Tue, 02 Jul 2024 14:42:11 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b59e6228b7sm47620306d6.126.2024.07.02.14.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 14:42:11 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfauth.nyi.internal (Postfix) with ESMTP id 984251200043; Tue, 2 Jul 2024 17:42:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 02 Jul 2024 17:42:10 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeiucetufdoteggodetrfdotffvucfrrh hofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epfffhvfevuffkfhggtggugfgjsehtkeertddttdejnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhepvefghfeuveekudetgfevudeuudejfeeltdfhgfehgeekkeeigfdukefhgfegleef necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqh hunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddu jeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvg drnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Jul 2024 17:42:10 -0400 (EDT) Date: Tue, 2 Jul 2024 14:41:11 -0700 From: Boqun Feng To: Vlastimil Babka Cc: Alice Ryhl , linux-mm@kvack.org, David Rientjes , Christoph Lameter , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin , Kees Cook , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH] mm, slab: extend kmalloc() alignment for non power-of-two sizes Message-ID: References: <20240702155800.166503-2-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 999EA1C0015 X-Stat-Signature: uduoanaz94bgj6hdkd7wth83m3rgfx6a X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1719956532-397548 X-HE-Meta: U2FsdGVkX19CIp/1To/paZco+e3pgAF2VibKNF7rBf6NUI/FMfSHg7MzUj6071CeT8xSajgUyYzcfX3IXXZWeLZOZ66sl1sB+s9gopR+vk/mbHxh5hyY4G5l/TGP+YqFNGjAEkd8hhGCefBDJxefXPfTO9GezmLDiT2vTEUPD9OyyzSXDgHFItzQpEdmXDUvnIhS/SVb4Jd0lkH25GTmpABOTNi/elRIFEMCGq/lUlN1E8+jwgdNq8tlmgbd2OAsE7ph383eaTAsPMdvABQpkTljqjB7/cZgJHdbAhqnurFnj+BfxY805CEd3Pb9gAJU6HZD6wuzEEcFcvfMWqglCHi3OW6JYH3rrOKjkh7w7JT8muukLMVDS5qGndHIo/GaaAD6ge5vRqDbCElm1mmLGsipVDGuXpwLN3JElVJcyApDZmVE67u+vpXixk+/5Co7Zad3nSGlpFCxckI1gbRdLyaHec2OhzipvbtxX1KtQG8QYcGArY3kO7Yf7The75LxxBAXkC8/earNJGMBwmXA1Cf1T7ZbD6pfkNwuOWeSFbSVHXKQBj2qTm5VfsPqQRWhSi1tpZol9IjAEJ6NXne73Ik7Jp8f2lYbd/AHl9L8iQdMV3rGctDBrvBTnAH0CXxsqVgXls9GaspEU49tp9NPdRaJ/6JkxVSFMnvDA6UqIwIdwkKlvd0ef3b7D0zs6i2n6d4oxT1mFVOoRvBV+pLBLgRlKlGMbfC7ewiHuVG4k085AB2FJQ4A4+Liq2w3rznYuC72rf6oOUCgZo2lGqm1VyIPUpr9MGn8NUFtrDv6QNpov+Fe98xlymEtezbLRVrUjf98QjWM9KqG3jqVtvUgIa6bxEiu3FYCq7Z/RYP88V7eGIOqtqt2WxX4evcpZB7sXhY5jtm0j/jC4SHL3GFTUVEeroF80WLEv6rQkkRZKWdLCYodEiQJiXB805YHvr6XHYSo6tXEK9xgakvhNZ5 vqW9QKCq 2z8AyhH4pIF3Aj+kgy9A9o+itGWG2yRuLU89REMWIrConAYKOjIPpyehD6L+tfQd6szm3rloPxvtgBIEG6o3eSVvmtp59cvm1Q/Dn9+u1rWC2p+Qu/zoSARVVz6flZs9FfWpNSfwhXw4xWByKeECXLo752p0BfPpBoiwk60ok+brVKEuVsXA23rTdXWmYH0f6K2+++k8/M4L2y4rc6UCpeM8AgTxB8Lxxu4SqWAc/pjB5MvcbgfwG1Lsr/gyGre5+CZK58ymEDdJSNPeq8D2kgXmTvdxwyuOk3y2t/8v+sKecTn3qTYu+ew0bBTSfIa9BJxugMiI+mQJuqOLTmVeNHAC1MZhTmZsfSNw9KPg5ngJQDxqzKSmTZCZAejMCQZFrAWY0EH1Wr6mfdb37FFxHXI08UsRVO31cBVhBOgaXxfUAZDJxqHlupKeP42t9/sjyB1V60VfpJV4h9WOI0KLSU41YLWDVy9/5JtKrWORiRP8B8txvqJnx0GAyuPuoSYmXr7ym X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jul 02, 2024 at 11:18:36PM +0200, Vlastimil Babka wrote: > On 7/2/24 6:40 PM, Alice Ryhl wrote: > > On Tue, Jul 2, 2024 at 5:58 PM Vlastimil Babka wrote: > > Thanks! > > > > Since this change is motivated by Rust, why not also include the Rust > > change in this patch? You would need to remove the if inside > > krealloc_aligned in rust/kernel/alloc/allocator.rs and update the > > comments. > > Right, thanks. Does this look ok? (not tested as I don't have the > environment working) > Thanks! This overall looks good to me. > diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs > index 229642960cd1..c619acb8b285 100644 > --- a/rust/kernel/alloc/allocator.rs > +++ b/rust/kernel/alloc/allocator.rs > @@ -18,23 +18,16 @@ pub(crate) unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: Layout, flags: F > // Customized layouts from `Layout::from_size_align()` can have size < align, so pad first. > let layout = new_layout.pad_to_align(); > > + // Note that `layout.size()` (after padding) is guaranteed to be a multiple of `layout.align()` > + // which together with the slab guarantee means the `krealloc` will return a properly aligned > + // object (see comments in `kmalloc()` for more information). > let mut size = layout.size(); The `mut` needs to be removed since no need to modify `size` afterwards. > > - if layout.align() > bindings::ARCH_SLAB_MINALIGN { > - // The alignment requirement exceeds the slab guarantee, thus try to enlarge the size > - // to use the "power-of-two" size/alignment guarantee (see comments in `kmalloc()` for > - // more information). > - // > - // Note that `layout.size()` (after padding) is guaranteed to be a multiple of > - // `layout.align()`, so `next_power_of_two` gives enough alignment guarantee. > - size = size.next_power_of_two(); > - } > - > // SAFETY: > // - `ptr` is either null or a pointer returned from a previous `k{re}alloc()` by the > // function safety requirement. > // - `size` is greater than 0 since it's either a `layout.size()` (which cannot be zero > - // according to the function safety requirement) or a result from `next_power_of_two()`. > + // according to the function safety requirement) The word "either" needs to be removed as well. With these changes, Reviewed-by: Boqun Feng Regards, Boqun > unsafe { bindings::krealloc(ptr as *const core::ffi::c_void, size, flags.0) as *mut u8 } > } > >