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 6FECAC41604 for ; Fri, 2 Oct 2020 22:27:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 346EA20754 for ; Fri, 2 Oct 2020 22:27:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qpOS6AVU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725775AbgJBW1p (ORCPT ); Fri, 2 Oct 2020 18:27:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725283AbgJBW1o (ORCPT ); Fri, 2 Oct 2020 18:27:44 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A97C0613E2 for ; Fri, 2 Oct 2020 15:27:44 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id dn5so3317426edb.10 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=pFdvcJ+Px2Ex367dr+FJamAE45La9zXCg7bvkpZZB31P5pNrHWNJ0FeCddnHHn6LpW VFNANZhsLVOPf/j4roBvIlXKFenHKZDJa++4FlID2g3QukbKcbI4x2z47fGQrtoifAYU uCB30GOtMIT1EujUV4ubVWXBUAtZWrsIx1assPx2iJzY0xKA6hdMKcerVVsMqMWJPRro 0PTxUlOW7xnlOf6vu4RG47ZYTavugYKlxcBTFl//xIBBIoOK/BlU3P0aWr6ieQANYwGP dxi7/9CxyKRT6jxf7lRRXOwsCnl8gL9B2HUZSXMLY/BA0awiI5V4XNU4J6XGO0uM3qbG dklQ== X-Gm-Message-State: AOAM530/7XFl+3RgP9g++GHo8rfF7+9GuCHQgAZz5ijJAuCLCuFOqjhi rGRGR0rj/3XKfqxpVvl1Sm/EzGAjkVoC6Fkp8ghoVA== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. 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=-3.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 636FEC35257 for ; Fri, 2 Oct 2020 22:29:18 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D4CD206B6 for ; Fri, 2 Oct 2020 22:29:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L44in5Jw"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="qpOS6AVU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D4CD206B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SVuMl7QYQ1GQzSIROutgr20kEBtZl2/oFCx1e46mF/M=; b=L44in5JwlQwRVQ3HDcFUroeXD jIi1E/ezvuZkPGsDzMy3jVpOQWEr/tzLGQaczGu+2Cwse1NsPJKYhpkv2VkZFtVmk1A2aGPbYWCSl ex/PP1MnRdrbJokMEMGxWxFilVMB58wZuNaoNKniPfFnJwZSu9lfaa6XeP0BxHmeYF4ZKi3neLisg PU1olxh3+o3vA4QaqJMDB9ClHHfmN9IG9c6b/L0qqedAF/qqt6jtGCwD/YumwS5oLnrIAOikbdI91 cASVqLc378FpZeEvFm2N5hqhte0hV9DT0hXEDXOXMdYSizJpvKxZ96iZ8XdRDNlg5B38v9zFuBkaE TAO4ddNfA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kOTWk-0007Ey-SF; Fri, 02 Oct 2020 22:27:46 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kOTWi-0007Df-7C for linux-arm-kernel@lists.infradead.org; Fri, 02 Oct 2020 22:27:45 +0000 Received: by mail-ed1-x542.google.com with SMTP id w1so3331974edr.3 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=sEhGUpvRQqIlgpMnZjAGSwgC8y/2nWa88UNk4BpHZijp+CzYYonfhyrfadjZ9ZPArx cQmGRqJ9yQ2eCb1k6VAUVBkruFDQV8ryWmM10T/PpTf9f1yTyBGHHYXWbT5B/y8npNsV HiISjuNSXeaTRQ9DscyyOf9lhm1XottAbbPq111LARbfKeofaxQWISMgjBcurBhgTqsq f72c1v3Cft7bE2EPFaAyASuYhXEXzZd13i+Psxlt6lLwJ7k6qLlAIZyYTbXuLqUJB7ZP uaHYdylXM37WHIeRbwaSfhFx5EV5RCNweiq4G/MsR89xfOqnPS7EO3/9YPJ+61IjN7v9 5fBw== X-Gm-Message-State: AOAM531VH1XwWjE3Ab5L50VWOevToQL1aFjtvrKlY2O/UnrvpJDWs4wz dWOxhEkmKT3zOUXM8ZXjHbCnu28HI8C+kb79iKBuPg== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201002_182744_323131_56AA5BC5 X-CRM114-Status: GOOD ( 22.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Hillf Danton , "open list:DOCUMENTATION" , Peter Zijlstra , Catalin Marinas , Dave Hansen , SeongJae Park , Linux-MM , Eric Dumazet , Alexander Potapenko , "H . Peter Anvin" , Christoph Lameter , Will Deacon , SeongJae Park , Jonathan Corbet , the arch/x86 maintainers , kasan-dev , Ingo Molnar , Vlastimil Babka , David Rientjes , Andrey Ryabinin , Kees Cook , "Paul E . McKenney" , Andrey Konovalov , Borislav Petkov , Andy Lutomirski , Jonathan Cameron , Thomas Gleixner , Andrew Morton , Dmitry Vyukov , Linux ARM , Greg Kroah-Hartman , kernel list , Pekka Enberg , Joonsoo Kim Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel