From patchwork Fri Dec 6 22:52:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13897901 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 8C8F5E7717B for ; Fri, 6 Dec 2024 22:52:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5A706B030F; Fri, 6 Dec 2024 17:52:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E1F56B0311; Fri, 6 Dec 2024 17:52:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 837116B0312; Fri, 6 Dec 2024 17:52:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 55CB56B030F for ; Fri, 6 Dec 2024 17:52:20 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1C94C1A08B6 for ; Fri, 6 Dec 2024 22:52:20 +0000 (UTC) X-FDA: 82866033642.01.83458BD Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf20.hostedemail.com (Postfix) with ESMTP id A72C01C0009 for ; Fri, 6 Dec 2024 22:51:59 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=nZLqgrAj; spf=pass (imf20.hostedemail.com: domain of 3IYBTZwYKCLAikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3IYBTZwYKCLAikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733525530; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VpkME8tKt7xRuIeyUR2rAOpo4R/J9PT1fVyVW9ktqRE=; b=QO9aHzuljn6eoH+MZJ5b8EAHDnETSD+QLtdmeIW1GW1ny5mT+VbAjMBC0g15An4d3gzFjP W9TM15fcZFyBrBrRoOhKoS7NmFqzlCxBWzuibAROmML/08on9F76iWwJL4evQXgmfcoh4M In49ALr9vm6FwTlGzPYTz6N9XZXYcpk= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=nZLqgrAj; spf=pass (imf20.hostedemail.com: domain of 3IYBTZwYKCLAikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3IYBTZwYKCLAikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733525530; a=rsa-sha256; cv=none; b=kDiZJ1woCFMl6VUKnc4PFz5JR+MrB2sI4gBQsb0s6reevwWdEufy9/SW5Y6lN2IJJphVDY qN3EJlvsWd4qaNPpNesvZ9k1mVoVQFktqcDrasHs2GUcWT5eFh3r0+Y1ftzG7GU3iE4zxI nVMtRCEXOdY1VQpV6k5U66pBdepJl9I= Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ee86953aeaso2515938a91.2 for ; Fri, 06 Dec 2024 14:52:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733525537; x=1734130337; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VpkME8tKt7xRuIeyUR2rAOpo4R/J9PT1fVyVW9ktqRE=; b=nZLqgrAj8Sak3PGy9pxQdmKdQJ1cWPCLYgiveXI3KprtcgC/WFf/4IE4KuSyr4ziiQ Iep8xqFUjPHWojyIq9kmxTgMccPhy/iSDYfYOEMMJX43BcrrIcq7NQAaItNEwfIoyv+1 1Hdk4IGO1ojpSQPBfmXIm+LMYfQoE5oavisfCL04wr8atoS7h3P2E239STdyXo7IFgwp 5zRbV/e9oUY4w1uA/lz4OA8N+AuRzOeMBM8yDIZuPDRlIRAdo7e/omj8yIF1uyj5kA/y fsWmeNCUm174/RRf8D5cxp5dj0n+RbQ1Brtmgy0uhQskvB0mQQXXKp0+6/ZQk6TLJz30 ucHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525537; x=1734130337; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VpkME8tKt7xRuIeyUR2rAOpo4R/J9PT1fVyVW9ktqRE=; b=nuB0VK5ITGvd11JadX5Sd4yEmLx8zl701D14Se4GFDfVNVTIDNeX4KaILSNcvZU1kQ jkf8paypXrqy/u5U+uHdk758HoevRg6VlIRQ8WrfiprP8rvbsa2VQEr8R8an0i3BG1Z+ VWGXD6kzqMfL3GIv0+PqiJjtR/Le3KNoqQm8dRw639ZSD74s5CjkgldKmRMwHjmaM39o E/H/nmFGbpckH2iPuFMNGSNcbWMj9bTpsHPRS9ZfWNBmoxdWcnVRhY1yhUdApRK0wCi/ hV54WYSfkHiLQkMtPRNJQ+8X1sSeA5OXUwImyWuYx61lNHtlJ5hkPCzl38uKPSUMaEMh kRwA== X-Forwarded-Encrypted: i=1; AJvYcCVpg3+YRltAup7PbM0XnRMEirblQcPRyDGNeTGsjRle2IFrHAwvIa5IZGJUbUufkTiailN6aYvgSw==@kvack.org X-Gm-Message-State: AOJu0Yw3sHFSSqNUYCUN4ZJc9VExezcqoxv9b+Gi3be/KHRL+7Z4Schf L18brI8rDsKfhThzmL+kny/C/w6ti5GMdAFKxXd8tYZlMExheQkrHGgVZoMI8MqMkin0XcuUFIU RiQ== X-Google-Smtp-Source: AGHT+IHFlvnZGP/uT3lo2rN1Kek/VGxFz7KPL1PDra1Y7TXq5etwmH5ZVO3EXQpkF7vZG3RxgNCe7HXm2rM= X-Received: from pjboi8.prod.google.com ([2002:a17:90b:3a08:b0:2ea:4a74:ac2]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1e43:b0:2ee:8008:b583 with SMTP id 98e67ed59e1d1-2ef69fffa82mr7837910a91.16.1733525537081; Fri, 06 Dec 2024 14:52:17 -0800 (PST) Date: Fri, 6 Dec 2024 14:52:02 -0800 In-Reply-To: <20241206225204.4008261-1-surenb@google.com> Mime-Version: 1.0 References: <20241206225204.4008261-1-surenb@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241206225204.4008261-6-surenb@google.com> Subject: [PATCH v5 5/6] mm/slab: allow freeptr_offset to be used with ctor From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mjguzik@gmail.com, oliver.sang@intel.com, mgorman@techsingularity.net, david@redhat.com, peterx@redhat.com, oleg@redhat.com, dave@stgolabs.net, paulmck@kernel.org, brauner@kernel.org, dhowells@redhat.com, hdanton@sina.com, hughd@google.com, minchan@google.com, jannh@google.com, shakeel.butt@linux.dev, souravpanda@google.com, pasha.tatashin@soleen.com, corbet@lwn.net, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspamd-Queue-Id: A72C01C0009 X-Stat-Signature: r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tBoZ4Y2nak9TLSRYiV1W8TxERO5ejT6DCbRanpQZA2IlxMoo3xnEq3IzLq3nzr+sXXjcOFjic3DpACrdvKj9cY0K/KIdAIBP9r7IQTfkUWTzRSw0RFg0a7OO+bM8PVqgG7xmxcORTofLRMtTU6NyqMFy6yCuJyOkJlGQUqg8G19Cdv10n1saSW1TfU6NPrDur75Hct0q4O7g56G6LreY+EhvXoWPRXDgUUpgd7zG586ObBiqLR1NXN9OLa7KjxzPYo5tUKsSURJKpvJ+wbyTPfsubLadKwJHlnHuNRzfWK2lK3M+npN3HAegvtG/kZ8Tcb2KEqunBmYN7Lmn1mzf+jr1WPnrtP0Y4xcm+LXVugQgXUlw8DVGuLNXCoqJT+/OE5ioTaUe2gkhcXIA4CvXdr3QioBzUSYxx7GkDEQMsIz7xwecX8NFD0QVW/gX9pLzQNs6t2fwjogrQnKQRsumqTFnFfIqSdhf+3L4ifEuviWJdrUthOY1/MEJ7s8gJVxFksK0yJF3/UdaHPjUm6gpQ5ZQ6oMfisQnvIraqKlA3+skjop+UVcTdHSM8LNkC9ab5NyOii7VKEjOGyr6aXSBw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: There is no real reason to prevent freeptr_offset usage when a slab cache has a ctor. The only real limitation is that any field unioned with the free pointer and initialized by ctor will be overwritten since free pointer is set after @ctor invocation. Document this limitation and enable usage of freeptr_offset with ctor. Suggested-by: Vlastimil Babka Signed-off-by: Suren Baghdasaryan Reviewed-by: Vlastimil Babka --- include/linux/slab.h | 5 +++-- mm/slub.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 681b685b6c4e..6bad744bef5e 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -305,8 +305,9 @@ struct kmem_cache_args { * Using %0 as a value for @freeptr_offset is valid. If @freeptr_offset * is specified, %use_freeptr_offset must be set %true. * - * Note that @ctor currently isn't supported with custom free pointers - * as a @ctor requires an external free pointer. + * Note that fields unioned with free pointer cannot be initialized by + * @ctor since free pointer is set after @ctor invocation, so those + * values will be overwritten. */ unsigned int freeptr_offset; /** diff --git a/mm/slub.c b/mm/slub.c index 870a1d95521d..f62c829b7b6b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5462,7 +5462,7 @@ static int calculate_sizes(struct kmem_cache_args *args, struct kmem_cache *s) s->inuse = size; if (((flags & SLAB_TYPESAFE_BY_RCU) && !args->use_freeptr_offset) || - (flags & SLAB_POISON) || s->ctor || + (flags & SLAB_POISON) || (s->ctor && !args->use_freeptr_offset) || ((flags & SLAB_RED_ZONE) && (s->object_size < sizeof(void *) || slub_debug_orig_size(s)))) { /*