Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp55515imu; Tue, 27 Nov 2018 08:58:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/VrFpCxabyT4ZrT9cXRgFcmi2zJppPmeZ041V3E+Jh6hcxBUiuEKeppL26VFRSuUveroPzO X-Received: by 2002:a17:902:2887:: with SMTP id f7mr32314078plb.176.1543337930417; Tue, 27 Nov 2018 08:58:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543337930; cv=none; d=google.com; s=arc-20160816; b=iAYv9EB1lkrjcW4RGP69v0AvP1ZdDh74cVhlKDoVq00+ZI0PpyNmeXdaQ57um5R0nD Gc1PYlNjtYCzU7VGKZYyElLQNLWobQ5SKVekbfW1nBpydjoFEXX9PfQoCDqkdJiSbsxN 6LZRoHV8fgvQ8nrx0VaDIF35f2Zk/O5j+C1mQfDlgCkMVJajPqjNsEri9GIxPBvH4/8O hcqoCf6KVm7j3DDvqwM/emEjg23p/KQ8jIreoRwlOTGEz9N1CnfAuA+TPOfZTZiGXLsj bycPzROyzM5D0QBfLVHM0Hhoy/Hm2ZRUuyRmdxo/p6gSphCZQ8+lIu2U/3CU+mhaJlfe lgeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gUtzPQYfY+TlBxAchiIeeRXD6wCQXCysNds7bqypcX0=; b=yR9qpkSdevCKYp8mtcWwBzC/JWEfcpxqoLmIvwsmT4n7JDNuSXuDk9mcqT0PhgVbv5 Comxq87qUJjToH4YRVLqV/CoKYwWGE9zrJ5SetqYluEAiuRSBef3JUuzoWFOOL215kYM 9Fc9Q75v14VO0T+lB7R2njWDMlaZMoHUQXznSlKneXr1/NlZPBNrmM33houSLJKV2GET ITITnamCU58Os+hErw4gvCNtqeHV+4bqQ/Qck4htSjhZb5TXFNvSvwpJCBE6vxDU5jcq gvtAW6M70us+UPYep7OosdTYJEwYnmkmbuzgXxoVOOVfdFEQYMiROWk/jmPbtotQDhk9 b51Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IMJYfJiI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si4512228plo.102.2018.11.27.08.58.33; Tue, 27 Nov 2018 08:58:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IMJYfJiI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731794AbeK1Dy4 (ORCPT + 99 others); Tue, 27 Nov 2018 22:54:56 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:50687 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731784AbeK1Dyz (ORCPT ); Tue, 27 Nov 2018 22:54:55 -0500 Received: by mail-wm1-f65.google.com with SMTP id 125so22650972wmh.0 for ; Tue, 27 Nov 2018 08:56:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gUtzPQYfY+TlBxAchiIeeRXD6wCQXCysNds7bqypcX0=; b=IMJYfJiI/vB4T61XMcgVTV8zpG/cNUZ9nUDQYlZotMywFSqsb9p6E5fGevB3WlOUPN WYEvLbC1mSpKJzaGwPyy4OY2YppWyioLYLVvVb2CTW36kbdDIZZULSxTmqVX0yCtLGZr h7ait1GfvypAFS10mVxKoj2RlvQLCgzvXNgOOzQ/gI4BzcJfQWOT8XhNOy4hcBvljuF3 m6lSda+HiC/s2RX543RqEk/6NhgRyhKa+80UGh0EpNFOe+b4oZiJW+HH4RvKtKxC/GCq 4CxUQoyDF4r1KcfNAGQtcjiexUSciNdRwhomD+90qhKiRoDRT0rbnTmTSXi3u6aQ4z7T QA2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gUtzPQYfY+TlBxAchiIeeRXD6wCQXCysNds7bqypcX0=; b=kpU7GYeKKP08kfbL0vjPZK6Y8mQVIaLsnMNFePGSxUdmWXCNV2sNhtsHoaolI6AeJu +nFPwGH8mOM+P+ZUvOona8TXatiqudDVGXJaVN6M4hcxhQMqwwB/P/W/LvPdwOqVdw57 FUPX3HNXG19HiCaaPsbapDDlGr3UdwmZfLfOMYC4vWd+vjPiJfXFvweqoQ2w0kvf10OQ 0tFe67VKX6kLhUAnkLosS+r1bsNmZLf0JpGuTpEvDG9C3PEsm8XnpRb6UjGihJtAdNFP VLpXbW1oG7jKAnrbnw3Uas5gVwC1JjHrPxwQ9x5rFm/o6XeaZQwzoXuNP38S9xzED50U /teQ== X-Gm-Message-State: AGRZ1gL5WEDJ1Bps1Ufbdi+aDGRJw16/vazgW54NWeZV5XRBkooBDtxR xXo5+aAPmQtar1AH+PisZE+eHw== X-Received: by 2002:a1c:b607:: with SMTP id g7mr29334808wmf.97.1543337781882; Tue, 27 Nov 2018 08:56:21 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id k73sm6383099wmd.36.2018.11.27.08.56.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:56:21 -0800 (PST) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , Christoph Lameter , Andrew Morton , Mark Rutland , Nick Desaulniers , Marc Zyngier , Dave Martin , Ard Biesheuvel , "Eric W . Biederman" , Ingo Molnar , Paul Lawrence , Geert Uytterhoeven , Arnd Bergmann , "Kirill A . Shutemov" , Greg Kroah-Hartman , Kate Stewart , Mike Rapoport , kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kbuild@vger.kernel.org Cc: Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Vishwath Mohan , Andrey Konovalov Subject: [PATCH v12 18/25] mm: move obj_to_index to include/linux/slab_def.h Date: Tue, 27 Nov 2018 17:55:36 +0100 Message-Id: X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While with SLUB we can actually preassign tags for caches with contructors and store them in pointers in the freelist, SLAB doesn't allow that since the freelist is stored as an array of indexes, so there are no pointers to store the tags. Instead we compute the tag twice, once when a slab is created before calling the constructor and then again each time when an object is allocated with kmalloc. Tag is computed simply by taking the lowest byte of the index that corresponds to the object. However in kasan_kmalloc we only have access to the objects pointer, so we need a way to find out which index this object corresponds to. This patch moves obj_to_index from slab.c to include/linux/slab_def.h to be reused by KASAN. Acked-by: Christoph Lameter Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- include/linux/slab_def.h | 13 +++++++++++++ mm/slab.c | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h index 3485c58cfd1c..9a5eafb7145b 100644 --- a/include/linux/slab_def.h +++ b/include/linux/slab_def.h @@ -104,4 +104,17 @@ static inline void *nearest_obj(struct kmem_cache *cache, struct page *page, return object; } +/* + * We want to avoid an expensive divide : (offset / cache->size) + * Using the fact that size is a constant for a particular cache, + * we can replace (offset / cache->size) by + * reciprocal_divide(offset, cache->reciprocal_buffer_size) + */ +static inline unsigned int obj_to_index(const struct kmem_cache *cache, + const struct page *page, void *obj) +{ + u32 offset = (obj - page->s_mem); + return reciprocal_divide(offset, cache->reciprocal_buffer_size); +} + #endif /* _LINUX_SLAB_DEF_H */ diff --git a/mm/slab.c b/mm/slab.c index 27859fb39889..d2f827316dfc 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -406,19 +406,6 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page, return page->s_mem + cache->size * idx; } -/* - * We want to avoid an expensive divide : (offset / cache->size) - * Using the fact that size is a constant for a particular cache, - * we can replace (offset / cache->size) by - * reciprocal_divide(offset, cache->reciprocal_buffer_size) - */ -static inline unsigned int obj_to_index(const struct kmem_cache *cache, - const struct page *page, void *obj) -{ - u32 offset = (obj - page->s_mem); - return reciprocal_divide(offset, cache->reciprocal_buffer_size); -} - #define BOOT_CPUCACHE_ENTRIES 1 /* internal cache of cache description objs */ static struct kmem_cache kmem_cache_boot = { -- 2.20.0.rc0.387.gc7a69e6b6c-goog