From patchwork Tue Nov 6 17:30:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10670949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B93213BF for ; Tue, 6 Nov 2018 17:31:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44D452ABBF for ; Tue, 6 Nov 2018 17:31:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41D192ABCC; Tue, 6 Nov 2018 17:31:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3BC42AB5C for ; Tue, 6 Nov 2018 17:31:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5FC36B0364; Tue, 6 Nov 2018 12:31:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A385A6B0366; Tue, 6 Nov 2018 12:31:02 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B8B96B0367; Tue, 6 Nov 2018 12:31:02 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id 274956B0364 for ; Tue, 6 Nov 2018 12:31:02 -0500 (EST) Received: by mail-wm1-f72.google.com with SMTP id c64-v6so11381012wma.2 for ; Tue, 06 Nov 2018 09:31:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=rI9jB7TmpIHEDx4oMZya4ulbXmsHhxN+ATa3+HN3hoo=; b=Ww8mmtcGzEQ1waCxJ5GaFjP18jnevVAmhI1/vX2KjBKreVhA+pAuaOzGl5IBo9l+Gu dG1fOo9ukQLidd2E9rVHwF/dyLkaQhzXQLe8Qz4BsKkXSB/3dFU3jFyFn/G+H9ITMzeT wswwCFqz+r1D6XS96pAzJBn0i/2MnUch2YLyirNym8XVEFLh8f7JV67CzwbaO6AHltDo OkXapH3VedYJzaIXVeO95fnQMRcs+BZaRqRahuto24ZzXSFHKf8qvfZSYIilI8C/Rg79 5MRDz1iFQHwSumRwUqYRFoLWV9B7GRsfWkXEXw+5Aw+tV/w3Vhwll0SyGLeCgEQRChuS VoSQ== X-Gm-Message-State: AGRZ1gKA0GHVhCa31twV0gBqmvV+c5auA7xbzTgdawzMsb+ct7YTdBCq 45CpBylDScZolB753IALvdDxLPj2LVzNzyPlCOXtdHUDM6+hs6Sp82Jabf9rVNaWd7qxUj4Ar9z 4Ai8om1J5t8wkth2dlu2cIf4vaHEnPKBQwYCdEhWbGIL2qLsNiDml3sDg+PGCF8x9BYYQzxZO8K MpouKZMINDznGeE7g3wfjpfsY4ETkiyMJkrdTubiLfxQjO5ING9MBRtdzsJKFXgkHajGSgw7GJG vTHNaoGJjqelZy+U4yAYsBcFIG1siE44xzPsf5NsVgGQWCJfLqoO3Z5uKYCOvKvdqmBBHEz+m0A N8CtVk2K7JUlbubnZbftdnSpwI7tOa7r5xlzFVY96vkvq8LEuHqzNWXqpBypdRZS/plO9/OL/JU U X-Received: by 2002:a1c:9182:: with SMTP id t124-v6mr2683662wmd.8.1541525461447; Tue, 06 Nov 2018 09:31:01 -0800 (PST) X-Received: by 2002:a1c:9182:: with SMTP id t124-v6mr2683613wmd.8.1541525460472; Tue, 06 Nov 2018 09:31:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541525460; cv=none; d=google.com; s=arc-20160816; b=pqLLuW0DMXSeY56Q0K8ieJcGbvUliXgL/f+OVI+G83n8TN145K8hokaCy9twTXqUSW dkFp15ooMCsc9PHGOGtopRePCc6M1105HJiGBQT/vMB+s9LO4IGl1b/bicN63ySbbGRa zMvjdCi74FilHb3EzjeUL9tqFSP4m3wQLSy3oDL0dz8bKPlCzGKC9CxSp2QXqH9h+D9j +Al7be6giekzLZo16DuLQh4vdpRcysWn216+jrL761ec5Y7z8vI9oxlQNKZcnqD/RW1Z bX5/c6Mf63GBmJ1Y0ERTf8mmcOlvcQPBPPhPMEmQkbAj6dERTUctKEyJvsH9k7EJucv/ QdiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=rI9jB7TmpIHEDx4oMZya4ulbXmsHhxN+ATa3+HN3hoo=; b=cm2L2DdKEoGyd6HYbL+wCw74yd46MPTVE02c9IMhI662naHKlXk0h1RQjz2yS0t/kw 2RBNca6MDxwhwj6XbS1LN9qSX4cP/EtCvQnaVFw94G/o9t9HW9323Rhl2rpvtkmZcWJ0 59sPLyVuIbfVWQ5l6R3RkyXtYLd84aCG0pNwEp/G3m7iDOyPm7HKNWqlLB2VuphDVPuo newuhSo4ylUpa+Vq7Y9WybnQDdhltDRg/V5Fxq5Wxm0YI/h129zzSQmwKlYW1ZDCiGEE 9IgZc5t3eJ48DvmMDULrN24Mz9PRh6P6fA1wMY8Lvz8tpZ3usXY2hnTl3VizP8iZx8xQ C4UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=udLfAObm; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n2-v6sor1699874wma.14.2018.11.06.09.31.00 for (Google Transport Security); Tue, 06 Nov 2018 09:31:00 -0800 (PST) Received-SPF: pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=udLfAObm; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=rI9jB7TmpIHEDx4oMZya4ulbXmsHhxN+ATa3+HN3hoo=; b=udLfAObmnevegDvmjvehrjJ6fumrvuolhCuOXNHOAd13A3IJR05UKexovQypoDryBl xLOfxlCW403tvGmJitkdVnWP7/inh2psYBnbktlBrzAK8mjKmw6moztKW1XJ6QYWQM1F 3PRa4CiYmZw0K3YGr1xsblXGBg4vv7sPsZssjowCWXs25jv1SARq4KappkjxjvWnJsDF 1tuvR5qdMddlKt/5Yj0fwcYGGAnCShDN/OSzNjeL+0o2oVf1rTI++h3oVLiW2rGdCUd2 hw2TBR1eOAjs9cRRTBWTQw9tCVAM1ZZAc8GBO34Bg7TV9cfuAYpgnPpRsVM/RsfLCtNr i8kQ== X-Google-Smtp-Source: AJdET5cXF3fWWc+IszXIBT7xTDA/coT3Nkazw/U/NtSkMe85oUqeoQTw9O2ShjMSgQDgFzZmWWgchA== X-Received: by 2002:a1c:1c0c:: with SMTP id c12-v6mr2675547wmc.18.1541525459907; Tue, 06 Nov 2018 09:30:59 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id z17-v6sm16328416wrm.65.2018.11.06.09.30.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 09:30:58 -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 v10 11/22] mm: move obj_to_index to include/linux/slab_def.h Date: Tue, 6 Nov 2018 18:30:26 +0100 Message-Id: X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: References: MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP 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 = {