From patchwork Mon Feb 21 10:53:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 12753433 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 39D93C433EF for ; Mon, 21 Feb 2022 10:54:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AECAA8D0003; Mon, 21 Feb 2022 05:54:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A76108D0001; Mon, 21 Feb 2022 05:54:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C9AF8D0003; Mon, 21 Feb 2022 05:54:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 7871C8D0001 for ; Mon, 21 Feb 2022 05:54:00 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 45206608DC for ; Mon, 21 Feb 2022 10:54:00 +0000 (UTC) X-FDA: 79166477040.03.E51C3FC Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf20.hostedemail.com (Postfix) with ESMTP id BBAB61C0004 for ; Mon, 21 Feb 2022 10:53:59 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id m1-20020a17090a668100b001bc023c6f34so4675406pjj.3 for ; Mon, 21 Feb 2022 02:53:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aA5sKZP46Br2IXGSlOJ6tqSDR6UxBlE/5/p8sTxFW2A=; b=TWXXfAQAoJokZM5wJBrVvEyYs+WaUxvPz/zifG36IeQ28CHce0CzCreiT2Lh78cklx tSBjiq3VySZhLEMOmAiUqrEKlLPMUhTQX9D01txRno+rzAJ0/PBum81r1/qFAR9BcYhf c7Y0wlGCn6ZCvmuSZbEre5JidSb/Lfd+0fr+oGqCQyahOo57+LHcEQbLb8SwYvsRUK+k mHcYuRl/BAu6IeHexEL4G32rL5+GNPosCx3ZHoyit0PBwyt50XLsZ8idVJt9bFbB2UTx M3RS4IIG1m3c3yIwATCQV4lDOaRg+enMG+GvFJRnfe9k6PjfS0dslpHqmztoZhSv4IRs 0m6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aA5sKZP46Br2IXGSlOJ6tqSDR6UxBlE/5/p8sTxFW2A=; b=RLu6aYp4R77VmoTef8bhf5ytrBTqcacAkHh69+Uj9wOc6Gm0K0hCC3gmL6vnHcHeMq s4Sxa5x0XBdRBO+11E19muPo/vOGXqQLP1rrwMW5ixhQP9rUKLZz1cnjK0feJyzyZljP Ja/zHdmO+rMhvwhAsXSvKO//1L7e63VCugS6mHHos04Fp20yhV9IjuoaE/otYEvPwign 9if6B+uK9ywWn4LrX9QSqWswrhuC6bOVfMjjv4hHvA/GuO3Kx/Mw1V9vSVylJJqB9LhW zNtdzfthGvl1q9QK0cRisgty05l48+wDwYzsizt65qGru+Hl0Dm69rIn7dtJ77Ov/koL iSnA== X-Gm-Message-State: AOAM531al5S9OOf5cvO6iT1lqkjtc5MioCY4fnKQLXMXuDiTtGJZ0c9i 5DhKb0KwG1/3cZ2c+GIwzKKeQNucFxMhPw== X-Google-Smtp-Source: ABdhPJzkBcA6oUH/qAaVd478izfxy2f+MQeMcLSeJRQBVr6AW6QXp3xyg6hHzj0PclNb0Z1q3auSqQ== X-Received: by 2002:a17:90b:240f:b0:1b8:e0b1:9667 with SMTP id nr15-20020a17090b240f00b001b8e0b19667mr25349719pjb.244.1645440838606; Mon, 21 Feb 2022 02:53:58 -0800 (PST) Received: from ip-172-31-19-208.ap-northeast-1.compute.internal (ec2-18-181-137-102.ap-northeast-1.compute.amazonaws.com. [18.181.137.102]) by smtp.gmail.com with ESMTPSA id u6sm2214725pfk.203.2022.02.21.02.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 02:53:58 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: linux-mm@kvack.org Cc: Roman Gushchin , Andrew Morton , Vlastimil Babka , linux-kernel@vger.kernel.org, Joonsoo Kim , David Rientjes , Christoph Lameter , Pekka Enberg , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH 1/5] mm/sl[au]b: Unify __ksize() Date: Mon, 21 Feb 2022 10:53:32 +0000 Message-Id: <20220221105336.522086-2-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220221105336.522086-1-42.hyeyoo@gmail.com> References: <20220221105336.522086-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BBAB61C0004 X-Stat-Signature: qmtfrwk6u94n576hnefqwzxk5mjhf1ch Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TWXXfAQA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1645440839-538110 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: Only SLOB need to implement __ksize() separately because SLOB records size in object header for kmalloc objects. Unify SLAB/SLUB's __ksize(). Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slab.c | 23 ----------------------- mm/slab_common.c | 29 +++++++++++++++++++++++++++++ mm/slub.c | 16 ---------------- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index ddf5737c63d9..eb73d2499480 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -4199,27 +4199,4 @@ void __check_heap_object(const void *ptr, unsigned long n, } #endif /* CONFIG_HARDENED_USERCOPY */ -/** - * __ksize -- Uninstrumented ksize. - * @objp: pointer to the object - * - * Unlike ksize(), __ksize() is uninstrumented, and does not provide the same - * safety checks as ksize() with KASAN instrumentation enabled. - * - * Return: size of the actual memory used by @objp in bytes - */ -size_t __ksize(const void *objp) -{ - struct kmem_cache *c; - size_t size; - BUG_ON(!objp); - if (unlikely(objp == ZERO_SIZE_PTR)) - return 0; - - c = virt_to_cache(objp); - size = c ? c->object_size : 0; - - return size; -} -EXPORT_SYMBOL(__ksize); diff --git a/mm/slab_common.c b/mm/slab_common.c index 23f2ab0713b7..488997db0d97 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1245,6 +1245,35 @@ void kfree_sensitive(const void *p) } EXPORT_SYMBOL(kfree_sensitive); +#ifndef CONFIG_SLOB +/** + * __ksize -- Uninstrumented ksize. + * @objp: pointer to the object + * + * Unlike ksize(), __ksize() is uninstrumented, and does not provide the same + * safety checks as ksize() with KASAN instrumentation enabled. + * + * Return: size of the actual memory used by @objp in bytes + */ +size_t __ksize(const void *object) +{ + struct folio *folio; + + if (unlikely(object == ZERO_SIZE_PTR)) + return 0; + + folio = virt_to_folio(object); + +#ifdef CONFIG_SLUB + if (unlikely(!folio_test_slab(folio))) + return folio_size(folio); +#endif + + return slab_ksize(folio_slab(folio)->slab_cache); +} +EXPORT_SYMBOL(__ksize); +#endif + /** * ksize - get the actual amount of memory allocated for a given object * @objp: Pointer to the object diff --git a/mm/slub.c b/mm/slub.c index 261474092e43..3a4458976ab7 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4526,22 +4526,6 @@ void __check_heap_object(const void *ptr, unsigned long n, } #endif /* CONFIG_HARDENED_USERCOPY */ -size_t __ksize(const void *object) -{ - struct folio *folio; - - if (unlikely(object == ZERO_SIZE_PTR)) - return 0; - - folio = virt_to_folio(object); - - if (unlikely(!folio_test_slab(folio))) - return folio_size(folio); - - return slab_ksize(folio_slab(folio)->slab_cache); -} -EXPORT_SYMBOL(__ksize); - void kfree(const void *x) { struct folio *folio;