From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by kanga.kvack.org (Postfix) with ESMTP id DB0698E0001 for ; Mon, 24 Sep 2018 05:19:39 -0400 (EDT) Received: by mail-io1-f71.google.com with SMTP id s14-v6so38892106ioc.0 for ; Mon, 24 Sep 2018 02:19:39 -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 m188-v6sor8073817ite.7.2018.09.24.02.19.38 for (Google Transport Security); Mon, 24 Sep 2018 02:19:38 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Dmitry Vyukov Date: Mon, 24 Sep 2018 11:19:17 +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: Andrey Konovalov 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 2:24 PM, Andrey Konovalov wrote: > 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. Ah, OK, then false alarm.