Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp783957imm; Fri, 21 Sep 2018 08:14:29 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb9TOzmWdC9c2Dj8fGLwKQCiHXsAUjAvZGmRqKQEjl45CAXW7Fq5RLnWHrYSW/ieNRJo5y1 X-Received: by 2002:a62:dbc5:: with SMTP id f188-v6mr47707409pfg.182.1537542868969; Fri, 21 Sep 2018 08:14:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537542868; cv=none; d=google.com; s=arc-20160816; b=JzdnOBtQOtylTlUFgxiupPbMIQTAux82/7RVlpU2Qwt2WlV1wMePKRCiA3RtJnfy3s XrBFM07d5cwn/rawVfd3crfgpNOpGhw+T/j4A3WPXajdh/9lL4BZqXd6oi4Bbt+HUgST DidTF3KE6+TUNOE+g3icZ7js832wSIp4q4hMwj/DAiLJvh57JgOi7gz38Nu/9FDqeTan gZPqugYuQjSR77dSidAj/TPbX5apAJo00MG+GYvP1rTbT8msoc+EaWoEAYs6tHzOGns8 D6In/NtU6pVe+BETkmc37sXL+Bepjy9HgalIC+K9wDFht3Y194YWOc8dsf+Raczab066 IRDw== 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=hO7cmdJIadnfEdKyPe4txnXVBC1YpbB0zh8lfgmkasM=; b=ee9QUn2q/EDESqOblJI41lO/QAihdjEmDmWTNyW2uVJACLk/3Kw/rghwdVPykg4X0+ UHNWe7htkJQ0QvY+zcJc40mcAUYVBb0PRS/0hlnFqqRq3WnVL00b994LIE7C3nUxm9Ck LfT66wjAvFO7BlRrpRf7qUjXFoGMvJR4k0S8uBXTMDrJk3+LuwObiFIlzt9/nUqOmfyU QZTfsng7xIb7YVXwMONi1X3HZScPs5K8gQKfe7cWRATIobPOSx2aN5ZYvMZXgglQWM+t f4YJne8idSVV1qKvfy1W8wqrsxHEig3ZEhWCJzimWv+c7dGjgg5UVEf63oTWJLd0TxL4 zFXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WZr1l6Jo; 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 n1-v6si28418914pfe.66.2018.09.21.08.14.11; Fri, 21 Sep 2018 08:14:28 -0700 (PDT) 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=WZr1l6Jo; 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 S2391018AbeIUVD0 (ORCPT + 99 others); Fri, 21 Sep 2018 17:03:26 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44935 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390865AbeIUVDZ (ORCPT ); Fri, 21 Sep 2018 17:03:25 -0400 Received: by mail-wr1-f67.google.com with SMTP id v16-v6so13213761wro.11 for ; Fri, 21 Sep 2018 08:14:04 -0700 (PDT) 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=hO7cmdJIadnfEdKyPe4txnXVBC1YpbB0zh8lfgmkasM=; b=WZr1l6JoY+I0VxauNdDkNf5GbEjoBY448dSPfl6A/EwVGXDZXLzizhBatYrXgDgJ+p KTgu+UF7i1DJRCIsAG7F8dscP6Rl8uiTZxk6+Xx7W2BA5DUX9mAf1icqxX/KTD/Ta/Rl wJ5/g+GfWMk5uZl0iLUk3Wj7Osat6QvSbQB4yOUvmCGaaK6QNVebHsIzc2rpCyZwY4oL Z4QM5Y/hq5Y7An9eBAxqHA9RdBAlGTBhdrUNFnPARYlsc6cJUGb3l8VPf813j7Y6FwTt Io+7WeFgT9a4CiU88YOPH8tg0GiEQtlAS3cySWe2bCgSmPXmahDbcqBsBG59zf7I3VDe wLQA== 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=hO7cmdJIadnfEdKyPe4txnXVBC1YpbB0zh8lfgmkasM=; b=VYUlFTq8xUifot76/l95hn0TJtj1Fuh3i+5T2i37mKX992w9MBfEOuWf75Q7QCCsmo S3kCgV/ZVJBhY+raeE5ryeyVJ5l4lgNP63eGX6JBG6wRtRwGFv2jR54ZvGSTblJmwHwW JSCKLTjsPn6k516p0VXEf91TwZgdT3o6PNyGCditC1/bIA+tguHEqKdvnHHLyViC15QB NNHVJ/jlD5nhLzBbHntdVdZknM3fE1jtUH2e0f4NjCHRLtePX+3KsTBNR+2ePrtAe9Hb CChnSpBC/J3GNlqBX7dkTOaOoyqOGa/FjN2JHmOcU5L/hJ7RFpGY+rhnw0klmMKle9nv rMjw== X-Gm-Message-State: ABuFfoh9bX/fkyACWgUt0xrv2CuqRPOuwmVpFx+VvqYJZa+1oT550nQf UicFBUSozcscKc4GMmwCqoqnSw== X-Received: by 2002:adf:ad29:: with SMTP id p38-v6mr1807954wrc.25.1537542844026; Fri, 21 Sep 2018 08:14:04 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id e7-v6sm27990271wru.46.2018.09.21.08.14.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 08:14:02 -0700 (PDT) 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 v9 10/20] mm: move obj_to_index to include/linux/slab_def.h Date: Fri, 21 Sep 2018 17:13:32 +0200 Message-Id: <9d62f917393456653c1d38c7173dc876cef03c93.1537542735.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.444.g18242da7ef-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. 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 fe0ddf08aa2c..6d8de7630944 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.19.0.444.g18242da7ef-goog