Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10635732imu; Thu, 6 Dec 2018 04:29:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/WhyZZ/0pMxdFkxRYJaeaWdrh1XkpoHtUoPVcLdssqg0iKe1aIloPackWslbVMyiCcItntC X-Received: by 2002:a62:6b85:: with SMTP id g127mr29538384pfc.42.1544099353930; Thu, 06 Dec 2018 04:29:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544099353; cv=none; d=google.com; s=arc-20160816; b=zBDANCPTxIDOBu/6BtQ1cnqOEdDOXxi+EavleozVAc27NhMBmSSIvD9H6HX5iidzar SuM8BjxOoxnSzObFWmDgs1RaAhB3huJlKeuamJQ8vm2XjKXmhiinfrdUqoSdW6NgQMHn Z5gnNJA/rrIuNn33bRKwM2aK9+3mZsv4FNjOCCqVrunH62F9PYX4pyfqqdLjcSBZWQ21 Hac/Gx3FDXh5FlTZ5wsVu4zbjl5xoo6URQ+Y+cHzMhVYoHLOq0pFKdauL381mQnVNckZ F/YWsPqtMRQJ3llKSXBTtnMdGbn6FYi5HPY6xNBawda/CkZ6NqKQwhmpvCxhDnW5WbHt 3snw== 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=FaduiTR0nXd7TQE8kfxwL/3d+/oPKBLmf6eac6TNL3k=; b=lfO5ESBwi8TfgA8GoT2R5xywr6yIDk5fnpPN92dNO0hFMZ5bGpGqmcjH4zwAJRph/l lg3zuWrGX5DieXUlDvee2708lVxv45XLeOVJfeVi+BNNLjGQhHuxV5V8Mod7AMFIjjj+ nrbdrre9gGfHy7SiaQSOu3EoMSA5av+l9ysKgRA3MJIiQfvEJqXWjZPifVk+bmPSumRk 89reLET3p8CjyyKbzXjpCeY+wLnTbN+1UzaPwM0kdNLCX3HuMVfEelf9IbrOj7v8m/Ho RbeOPnWnTh9g75KGtMAYqG9rN3SMCp9jdQW5N8OluG8bNEJZItee9KM8OTt3ilFi7Ov0 jxlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=amkNNJFo; 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 w9si194963pgg.72.2018.12.06.04.28.58; Thu, 06 Dec 2018 04:29:13 -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=amkNNJFo; 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 S1729796AbeLFMZX (ORCPT + 99 others); Thu, 6 Dec 2018 07:25:23 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37917 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729747AbeLFMZU (ORCPT ); Thu, 6 Dec 2018 07:25:20 -0500 Received: by mail-wm1-f67.google.com with SMTP id m22so841273wml.3 for ; Thu, 06 Dec 2018 04:25:18 -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=FaduiTR0nXd7TQE8kfxwL/3d+/oPKBLmf6eac6TNL3k=; b=amkNNJFo/2s75YdZiL5n/4pvWc/wOQ5QEZTyzJHRBocvyLknCN88PMDvlrNNK9gwNE AmP8SUBWlWQUDUWncQqFRmp6dXktNfMvWYNee0okybhgmzKzdmWhGpx7eT8OTM0tuxCr yHRpBgiG9Q9Lb121RHPzhivLL7zymiGKbF+87vY6gQTCGuObr8dCNOYldKpjaZ/F7tbj QSJJJsuNLdT8o+8BNy/DeiQD99TXxSCjPa/b+qc+Wd537R3TivAl4UuDa7B/uHzpPWyb YIUHha77STDq8QIfw/CO/h7jdBKIpVlPuH3SfA1z5ySRzid61e9FSti/Uf8Fzr9GGYTk FIMg== 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=FaduiTR0nXd7TQE8kfxwL/3d+/oPKBLmf6eac6TNL3k=; b=FU2KWQPppFF0rmiKvMD3sLpt57dgijm3Gaoa1ps7YNAWm3hdyx7pslYecGLU9MkDhy 6bOpdprmC8L6rhEh/KtIQ02F5lxmsru/8TSpTXGj5pMgB1G0iVy0z9hjOYMh0AS9E87I nVGytDqw1MPx7m412VRbpCX5gjy6eJKct3O0BUpMUgPve3dWFHD0f8dXk3rFnLPgIMUk X/Ti+Qwnyh0PbrzNES5fM+1cqjQCClIR/OJSsAw/j7z2WE+7cUhv6flfwlA7okstTzsM hEle0y7ajlrFuSLBEL2NeziFZAA/gqjQ+EnduwmZPgnuRLs/cHdhZGc9R3jtSRdLmQAX p18g== X-Gm-Message-State: AA+aEWbdRym9hzznp87v7Sy/V4JByXayet3PK862qKTFRcNRjAJK1TQ+ NgK31JHfqavlpmbhj7RYnwqk1Q== X-Received: by 2002:a1c:2457:: with SMTP id k84mr19289771wmk.139.1544099117816; Thu, 06 Dec 2018 04:25:17 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id j8sm339988wrt.40.2018.12.06.04.25.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 04:25:17 -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 v13 18/25] mm: move obj_to_index to include/linux/slab_def.h Date: Thu, 6 Dec 2018 13:24:36 +0100 Message-Id: X-Mailer: git-send-email 2.20.0.rc1.387.gf8505762e3-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.rc1.387.gf8505762e3-goog