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 2A896C02181 for ; Fri, 24 Jan 2025 14:16:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5EAE28006D; Fri, 24 Jan 2025 09:16:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0E2F280069; Fri, 24 Jan 2025 09:16:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 987F228006D; Fri, 24 Jan 2025 09:16:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7C5C6280069 for ; Fri, 24 Jan 2025 09:16:11 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 318B21C6CEC for ; Fri, 24 Jan 2025 14:16:11 +0000 (UTC) X-FDA: 83042544942.18.58A7890 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf01.hostedemail.com (Postfix) with ESMTP id A31914000A for ; Fri, 24 Jan 2025 14:16:08 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Sq+OxWD2; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=bxSvP9kH; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=wOtoRoiX; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aNF8nRMI; spf=pass (imf01.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737728169; 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=/xj6Ijb7bSBcyF4sWaq+LJ/LpMvYnSGhKkKhCNpx0Uw=; b=FSVooNGr06K/uaFga1GBxOcSwauAquZZNZ6xp9YbN1nRKi27b/tLv7Bs0BXIGS7dQQODwr g+vA4gqQ6mAIwNAdMUMLTpMoK8M45miQLzqgUC3z80cqLmLVF0d4yGXC1kP4jIUobAVq4K Ae2h9vp3mXOmg/Zj99KLu7wF1F/PC+A= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Sq+OxWD2; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=bxSvP9kH; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=wOtoRoiX; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aNF8nRMI; spf=pass (imf01.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737728169; a=rsa-sha256; cv=none; b=3QCw89vMSvUpkdkMQx7te+hePBte6wUwMJeV1lYoP8bBQj1z/6dx6LcBa4jRjwFUI53xzI Laf+2+xG8INb7ZHAjBOxYLWI7y3ycRwKYaAk0Cl80ePoBay4xP8PuwZ/2YMOq6jmRETTT0 FH6Es4XP6vyKeBrSuTqdgsgvXlSWu9E= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B9FF321180; Fri, 24 Jan 2025 14:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1737728167; h=from:from:reply-to: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:autocrypt:autocrypt; bh=/xj6Ijb7bSBcyF4sWaq+LJ/LpMvYnSGhKkKhCNpx0Uw=; b=Sq+OxWD2BU4acbQK8yiDLSQqldV9QcDA90nC8x1FGeFcuBGT9fPdxVXIwDkAFmHsVd95r6 F18fzVqOo/QhbFPNK+YQABJHpmrPgBFZSmHTI9Wr29+QfzXaR1l/BscejuLSe+Mvs5BAwD 2H8c9g1xG+X+vg3ahKHIb+G/lb+sYhk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1737728167; h=from:from:reply-to: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:autocrypt:autocrypt; bh=/xj6Ijb7bSBcyF4sWaq+LJ/LpMvYnSGhKkKhCNpx0Uw=; b=bxSvP9kHTROQv1+t2QrfIH445WQFrbimfKeVdhWMP4PP48sAi55ETpBLGwtoCqAl6A0m7m yI72xqlTfWv3DeBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1737728165; h=from:from:reply-to: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:autocrypt:autocrypt; bh=/xj6Ijb7bSBcyF4sWaq+LJ/LpMvYnSGhKkKhCNpx0Uw=; b=wOtoRoiXG62tr8m+vMbHnboU4Ryg4nDM7eEAm9a2kMbJkkHg6I8fLXTKdR4gX2g772T8AG j5vsJQV9uB5tOIllnSpCXZTtjDG2yWtsI+sYAWucXqEK4BQbi9ah77JHgy0uzg3iW4iwav +jl/K7ZbESz8Dfw3iTf0RiUE/k0CW50= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1737728165; h=from:from:reply-to: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:autocrypt:autocrypt; bh=/xj6Ijb7bSBcyF4sWaq+LJ/LpMvYnSGhKkKhCNpx0Uw=; b=aNF8nRMIjS3fZPD11aZe6HK36qLTDEOhAfp/THO6M3IIVqh6/l8tVl0BrqCpnxidbntBDx loLj7hINZxapTABw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8416B13999; Fri, 24 Jan 2025 14:16:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id C7nhH6Wgk2e7YwAAD6G6ig (envelope-from ); Fri, 24 Jan 2025 14:16:05 +0000 Message-ID: Date: Fri, 24 Jan 2025 15:16:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 3/4] rcu, slab: use a regular callback function for kvfree_rcu Content-Language: en-US To: Uladzislau Rezki Cc: Christoph Lameter , David Rientjes , "Paul E. McKenney" , Joel Fernandes , Josh Triplett , Boqun Feng , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , rcu@vger.kernel.org References: <20250123-slub-tiny-kfree_rcu-v1-0-0e386ef1541a@suse.cz> <20250123-slub-tiny-kfree_rcu-v1-3-0e386ef1541a@suse.cz> From: Vlastimil Babka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QeobXBDDE31t5SBg++veI6tXfpco/UiKEsDswL1WAr tEAZaruo7254TyH+gydURl2wJuzo/aZ7Y7PpqaODbYv727Dvm5eX64HCyyAH0s6sOCyGF5/p eIhrOn24oBf67KtdAN3H9JoFNUVTYJc1VJU3R1JtVdgwEdr+NEciEfYl0O19VpLE/PZxP4wX PWnhf5WjdoNI1Xec+RcJ5p/pSel0jnvBX8L2cmniYnmI883NhtGZsEWj++wyKiS4NranDFlA HdDM3b4lUth1pTtABKQ1YuTvehj7EfoWD3bv9kuGZGPrAeFNiHPdOT7DaXKeHpW9homgtBxj 8aX/UkSvEGJKUEbFL9cVa5tzyialGkSiZJNkWgeHe+jEcfRT6pJZOJidSCdzvJpbdJmm+eED w9XOLH1IIWh7RURU7G1iOfEfmImFeC3cbbS73LQEFGe1urxvIH5K/7vX+FkNcr9ujwWuPE9b 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A31914000A X-Stat-Signature: 4bs6zgdnxtpka4iahd9wmpx85op5tp4f X-Rspam-User: X-HE-Tag: 1737728168-902751 X-HE-Meta: U2FsdGVkX1/kGiYNzGrc/huuzLWhGA5L44SYsDkB4SWvRJnORJRbQAcq5/3FxPQp2mZ/12hunu/3YstlwuwsNSnI+ki4CZMplzy2cqKO428UERi+D6y6bmZ1NOjN68kR8/qIEzp8RzsHwpMGtQokHTYoYZRW3Xow2d98l0BlktJaNBDRSaBiFyTuPg/ufhXKmjrhLdckyVsg0KTaee78WlXG2Q1piZwPBmUYk8rzQ31MvDNfQyYUx8F50zaUq8hqmepB5Az46jb4iYaoMqVA+4g8ESVmmlr2W+MbsMQq/7kSFN55/VSy1iS1WuFxZ5v0Xml7CXRIT894TqNCJkTnIVJVttup0F+4UyXUPMuKT6dPc25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-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 1/24/25 13:47, Uladzislau Rezki wrote: > On Thu, Jan 23, 2025 at 11:37:20AM +0100, Vlastimil Babka wrote: >> RCU has been special-casing callback function pointers that are integers >> lower than 4096 as offsets of rcu_head for kvfree() instead. The tree >> RCU implementation no longer does that as the batched kvfree_rcu() is >> not a simple call_rcu(). The tiny RCU still does, and the plan is also >> to make tree RCU use call_rcu() for SLUB_TINY configurations. >> >> Instead of teaching tree RCU again to special case the offsets, let's >> remove the special casing completely. Since there's no SLOB anymore, it >> is possible to create a callback function that can take a pointer to a >> middle of slab object with unknown offset and determine the object's >> pointer before freeing it, so implement that as kvfree_rcu_cb(). >> >> Large kmalloc and vmalloc allocations are handled simply by aligning >> down to page size. For that we retain the requirement that the offset is >> smaller than 4096. But we can remove __is_kvfree_rcu_offset() completely >> and instead just opencode the condition in the BUILD_BUG_ON() check. >> >> Signed-off-by: Vlastimil Babka >> --- >> include/linux/rcupdate.h | 24 +++++++++--------------- >> kernel/rcu/tiny.c | 13 ------------- >> mm/slab.h | 2 ++ >> mm/slab_common.c | 5 +---- >> mm/slub.c | 42 ++++++++++++++++++++++++++++++++++++++++++ >> 5 files changed, 54 insertions(+), 32 deletions(-) >> >> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h >> index 3f70d1c8144426f40553c8c589f07097ece8a706..7ff16a70ca1c0fb1012c4118388f60687c5e5b3f 100644 >> --- a/include/linux/rcupdate.h >> +++ b/include/linux/rcupdate.h >> @@ -1025,12 +1025,6 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) >> #define RCU_POINTER_INITIALIZER(p, v) \ >> .p = RCU_INITIALIZER(v) >> >> -/* >> - * Does the specified offset indicate that the corresponding rcu_head >> - * structure can be handled by kvfree_rcu()? >> - */ >> -#define __is_kvfree_rcu_offset(offset) ((offset) < 4096) >> - >> /** >> * kfree_rcu() - kfree an object after a grace period. >> * @ptr: pointer to kfree for double-argument invocations. >> @@ -1041,11 +1035,11 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) >> * when they are used in a kernel module, that module must invoke the >> * high-latency rcu_barrier() function at module-unload time. >> * >> - * The kfree_rcu() function handles this issue. Rather than encoding a >> - * function address in the embedded rcu_head structure, kfree_rcu() instead >> - * encodes the offset of the rcu_head structure within the base structure. >> - * Because the functions are not allowed in the low-order 4096 bytes of >> - * kernel virtual memory, offsets up to 4095 bytes can be accommodated. >> + * The kfree_rcu() function handles this issue. In order to have a universal >> + * callback function handling different offsets of rcu_head, the callback needs >> + * to determine the starting address of the freed object, which can be a large >> + * kmalloc of vmalloc allocation. To allow simply aligning the pointer down to >> + * page boundary for those, only offsets up to 4095 bytes can be accommodated. >> * If the offset is larger than 4095 bytes, a compile-time error will >> * be generated in kvfree_rcu_arg_2(). If this error is triggered, you can >> * either fall back to use of call_rcu() or rearrange the structure to >> @@ -1091,10 +1085,10 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr); >> do { \ >> typeof (ptr) ___p = (ptr); \ >> \ >> - if (___p) { \ >> - BUILD_BUG_ON(!__is_kvfree_rcu_offset(offsetof(typeof(*(ptr)), rhf))); \ >> - kvfree_call_rcu(&((___p)->rhf), (void *) (___p)); \ >> - } \ >> + if (___p) { \ >> + BUILD_BUG_ON(offsetof(typeof(*(ptr)), rhf) >= 4096); \ >> + kvfree_call_rcu(&((___p)->rhf), (void *) (___p)); \ >> + } \ >> > Why removing the macro? At least __is_kvfree_rcu_offset() makes it > clear what and why + it has a nice comment what it is used for. 4096 > looks like hard-coded value. Hmm but it's ultimately shorter. We could add a short comment to kvfree_rcu_arg_2() referring to the longer explanation in the kfree_rcu() comment? > Or you do not want that someone else started to use that macro in > another places? And also that, since this has to be exposed in a "public" header. >> diff --git a/mm/slab.h b/mm/slab.h >> index e9fd9bf0bfa65b343a4ae0ecd5b4c2a325b04883..2f01c7317988ce036f0b22807403226a59f0f708 100644 >> --- a/mm/slab.h >> +++ b/mm/slab.h >> @@ -604,6 +604,8 @@ void __memcg_slab_free_hook(struct kmem_cache *s, struct slab *slab, >> void **p, int objects, struct slabobj_ext *obj_exts); >> #endif >> >> +void kvfree_rcu_cb(struct rcu_head *head); >> + >> size_t __ksize(const void *objp); >> >> static inline size_t slab_ksize(const struct kmem_cache *s) >> diff --git a/mm/slab_common.c b/mm/slab_common.c >> index 330cdd8ebc5380090ee784c58e8ca1d1a52b3758..f13d2c901daf1419993620459fbd5845eecb85f1 100644 >> --- a/mm/slab_common.c >> +++ b/mm/slab_common.c >> @@ -1532,9 +1532,6 @@ kvfree_rcu_list(struct rcu_head *head) >> rcu_lock_acquire(&rcu_callback_map); >> trace_rcu_invoke_kvfree_callback("slab", head, offset); >> >> - if (!WARN_ON_ONCE(!__is_kvfree_rcu_offset(offset))) >> - kvfree(ptr); >> - > This is not correct unless i miss something. Why do you remove this? Oops, meant to remove just the warn check, and unconditionally call kvfree(), thanks for noticing :) The warning could really only trigger due to a use-after-free corruption of the ptr pointer, because the BUILD_BUG_ON() would catch misuse with a too large offset, so we don't need to keep it. >> +void kvfree_rcu_cb(struct rcu_head *head) >> +{ >> + void *obj = head; >> + struct folio *folio; >> + struct slab *slab; >> + struct kmem_cache *s; >> + void *slab_addr; >> + >> + if (unlikely(is_vmalloc_addr(obj))) { >> + obj = (void *) PAGE_ALIGN_DOWN((unsigned long)obj); >> + vfree(obj); >> + return; >> + } >> + >> + folio = virt_to_folio(obj); >> + if (unlikely(!folio_test_slab(folio))) { >> + /* >> + * rcu_head offset can be only less than page size so no need to >> + * consider folio order >> + */ >> + obj = (void *) PAGE_ALIGN_DOWN((unsigned long)obj); >> + free_large_kmalloc(folio, obj); >> + return; >> + } >> + >> + slab = folio_slab(folio); >> + s = slab->slab_cache; >> + slab_addr = folio_address(folio); >> + >> + if (is_kfence_address(obj)) { >> + obj = kfence_object_start(obj); >> + } else { >> + unsigned int idx = __obj_to_index(s, slab_addr, obj); >> + >> + obj = slab_addr + s->size * idx; >> + obj = fixup_red_left(s, obj); >> + } >> + >> + slab_free(s, slab, obj, _RET_IP_); >> +} >> + > Tiny computer case. Just small nit, maybe remove unlikely() but you decide :) Force of habbit :) > -- > Uladzislau Rezki