From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by kanga.kvack.org (Postfix) with ESMTP id 042028E0001 for ; Fri, 21 Sep 2018 08:25:02 -0400 (EDT) Received: by mail-io1-f72.google.com with SMTP id z20-v6so14598281ioh.2 for ; Fri, 21 Sep 2018 05:25:01 -0700 (PDT) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y127-v6sor13998098iod.36.2018.09.21.05.25.00 for (Google Transport Security); Fri, 21 Sep 2018 05:25:00 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Andrey Konovalov Date: Fri, 21 Sep 2018 14:24:59 +0200 Message-ID: Subject: Re: [PATCH v8 09/20] kasan: preassign tags to objects with ctors or SLAB_TYPESAFE_BY_RCU Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: Dmitry Vyukov Cc: Andrey Ryabinin , Alexander Potapenko , 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 , "open list:DOCUMENTATION" , LKML , Linux ARM , linux-sparse@vger.kernel.org, Linux-MM , "open list:KERNEL BUILD + fi..." , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Vishwath Mohan On Fri, Sep 21, 2018 at 1:25 PM, Dmitry Vyukov wrote: > On Wed, Sep 19, 2018 at 8:54 PM, Andrey Konovalov wrote: >> if (!shuffle) { >> for_each_object_idx(p, idx, s, start, page->objects) { >> - setup_object(s, page, p); >> - if (likely(idx < page->objects)) >> - set_freepointer(s, p, p + s->size); >> - else >> + if (likely(idx < page->objects)) { >> + next = p + s->size; >> + next = setup_object(s, page, next); >> + set_freepointer(s, p, next); >> + } else >> set_freepointer(s, p, NULL); >> } >> - page->freelist = fixup_red_left(s, start); >> + start = fixup_red_left(s, start); >> + start = setup_object(s, page, start); >> + page->freelist = start; >> } > > Just want to double-check that this is correct. > We now do an additional setup_object call after the loop, but we do 1 > less in the loop. So total number of calls should be the same, right? > However, after the loop we call setup_object for the first object (?), > but inside of the loop we skip the call for the last object (?). Am I > missing something, or we call ctor twice for the last object and don't > call it for the first one? Inside the loop we call setup_object for the "next" object. So we start iterating on the first one, but call setup_object for the second. Then the loop moves on to the second one and calls setup_object for the third. And so on. So the loop calls setup_object for every object (including the last one) except for the first one. The idea is that we want the freelist pointer that is stored in the current object to have a tagged pointer to the next one, so we need to assign a tag to the next object before storing the pointer in the current one.