From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99F0FC46466 for ; Fri, 2 Oct 2020 22:27:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 076B7206B6 for ; Fri, 2 Oct 2020 22:27:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qpOS6AVU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 076B7206B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3BCB9900002; Fri, 2 Oct 2020 18:27:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34FB86B0093; Fri, 2 Oct 2020 18:27:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23EBF900002; Fri, 2 Oct 2020 18:27:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id E756F6B0092 for ; Fri, 2 Oct 2020 18:27:44 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 81BF5181AE868 for ; Fri, 2 Oct 2020 22:27:44 +0000 (UTC) X-FDA: 77328423648.29.stove08_240ff0c271a7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 650EA180868CE for ; Fri, 2 Oct 2020 22:27:44 +0000 (UTC) X-HE-Tag: stove08_240ff0c271a7 X-Filterd-Recvd-Size: 5960 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 2 Oct 2020 22:27:43 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id b12so3314209edz.11 for ; Fri, 02 Oct 2020 15:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WenNmI5oUkGle0L0WRFJAM5U4b70dfVnKCotDQT26ic=; b=qpOS6AVUOpuYRfzrRmEmY8nFGGqKUYhiSPRrmYu88Du2AlPVrjadxaORzyWIUB+fjv xpaD/n3wkuOKLrC9HL/gQdNsnY351O+V0ZdYMLnIVW2BKM9QtUmYIvTjPSk/Zfcq3pBN xsaKuY05LuXKpImIi1CiXpmFMSJ+WoX6JllYGomKn8gKTHCaHKeMWepJgmt5iX4SYnkM hXpZng8JV1+NGujOYQZt5ix2ASa/uwXlpzl2sc7HOPP3UKX1TxAPv2X9zN37wP9VfVbR RyR9KEP4ICSJJTRkowmJI7H/md2Pjy0JEq2U1hjvc1iMjpe41ESKQ/mHcBumKoqhLD0c Uk9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WenNmI5oUkGle0L0WRFJAM5U4b70dfVnKCotDQT26ic=; b=hqHH1tv/uABLvqM6ORlgXL5y2jKFW7+xKg3T7jHIgMqId/oo9sh+eCpswSrTBihqGL DUT/DcxLdsouNVv3JeQWK27i2rllTZcZxV4Uhn62DycdPrRodrCvUuR6o2b4eu4s2hBz cnX98RNTy2d+HOK1hFowv9d3oxqkvPGGYhjfEb8G841O80TfLUDa+4LN4Gh76+EsRMzL 0n+nqURmzq3n3672S1qUzNuBVb3EHTzCgkq0DIPi3Zbxu2JUu/aBCkgdPQ7UiUkCdCNU 2oqfWfR98Q06sV3LShh/SzCBYKim1lLu8RscOTleXYLx0Kb/RuqdSfpVKgAXiGzhB4fz DW+Q== X-Gm-Message-State: AOAM5302r9vbprXdkZhG8ymnomCLD1sEYr2zXgn5bLH8/sInBCLZcK0l FhdOpHSQz5OQ9kZnfy54OkNx+F8h+v3dvRKLyNvj3g== X-Google-Smtp-Source: ABdhPJzj0f7XvxzsCDrfMmIeI3C8DfvP4DCgq9+cCHs7tz7tMvkK8DfUcfTEg3mEkcGuHbAuc2NOlXwWuav+aHlt06Q= X-Received: by 2002:a05:6402:b0e:: with SMTP id bm14mr5117814edb.259.1601677662551; Fri, 02 Oct 2020 15:27:42 -0700 (PDT) MIME-Version: 1.0 References: <20200929133814.2834621-1-elver@google.com> <20200929133814.2834621-2-elver@google.com> <20201002171959.GA986344@elver.google.com> In-Reply-To: From: Jann Horn Date: Sat, 3 Oct 2020 00:27:16 +0200 Message-ID: Subject: Re: [PATCH v4 01/11] mm: add Kernel Electric-Fence infrastructure To: Marco Elver Cc: Andrew Morton , Alexander Potapenko , "H . Peter Anvin" , "Paul E . McKenney" , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Catalin Marinas , Christoph Lameter , Dave Hansen , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Hillf Danton , Ingo Molnar , Jonathan Cameron , Jonathan Corbet , Joonsoo Kim , Kees Cook , Mark Rutland , Pekka Enberg , Peter Zijlstra , SeongJae Park , Thomas Gleixner , Vlastimil Babka , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , kernel list , kasan-dev , Linux ARM , Linux-MM , SeongJae Park Content-Type: text/plain; charset="UTF-8" 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: On Fri, Oct 2, 2020 at 11:28 PM Marco Elver wrote: > On Fri, 2 Oct 2020 at 21:32, Jann Horn wrote: > > > That's another check; we don't want to make this more expensive. > > > > Ah, right, I missed that this is the one piece of KFENCE that is > > actually really hot code until Dmitry pointed that out. > > > > But actually, can't you reduce how hot this is for SLUB by moving > > is_kfence_address() down into the freeing slowpath? At the moment you > > use it in slab_free_freelist_hook(), which is in the super-hot > > fastpath, but you should be able to at least move it down into > > __slab_free()... > > > > Actually, you already have hooked into __slab_free(), so can't you > > just get rid of the check in the slab_free_freelist_hook()? > > I missed this bit: the loop that follows wants the free pointer, so I > currently see how this might work. :-/ reverse call graph: __slab_free do_slab_free slab_free kmem_cache_free (frees a single non-kmalloc allocation) kmem_cache_free_bulk (frees multiple) kfree (frees a single kmalloc allocation) ___cache_free (frees a single allocation for KASAN) So the only path for which we can actually loop in __slab_free() is kmem_cache_free_bulk(); and you've already changed build_detached_freelist() (which is used by kmem_cache_free_bulk() to group objects from the same page) to consume KFENCE allocations before they can ever reach __slab_free(). So we know that if we've reached __slab_free(), then we are being called with either a single object (which may be a KFENCE object) or with a list of objects that all belong to the same page and don't contain any KFENCE allocations.