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=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,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 92A9DC47423 for ; Fri, 2 Oct 2020 14:19:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A64D206A5 for ; Fri, 2 Oct 2020 14:19:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WbL9t9/X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388046AbgJBOTC (ORCPT ); Fri, 2 Oct 2020 10:19:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726017AbgJBOTB (ORCPT ); Fri, 2 Oct 2020 10:19:01 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 563C8C0613E2 for ; Fri, 2 Oct 2020 07:19:00 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id x14so1345636oic.9 for ; Fri, 02 Oct 2020 07:19:00 -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=tYH/6hO5lgQzTOW7dEpfFVSSkr8P55YhoTlw55xP13w=; b=WbL9t9/X+2+U5VeNgqJ2mzYEVs8LZ8q8hjggo7N19g1Jfbf7P1wkvnp8roJdVEw2lS c3i+9tyC5AUycxhnZX3RIt4oznfraSi/7+MhXAFF62q39I2RYcbTn5QT7+m9u2tkqg6l t8CPQiS4CwE3/je84zeBM5/j7j3lEb16Ugt2aIYvU40jH0TI0PR5J1CBlhaYuqhraQ9S VNH44ZU9nil0inzWBzSBsDd31QGBA5Yoy3hYBsIdwpYvq+FTYKKD014ZVWSBoeXqJDuA xB8WY3nYSYtoHgpNv87LMV6Wm9qhKizfdSBX5z2jHJgzn6f3UzGseSKEQmzLzzorHWIt HJog== 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=tYH/6hO5lgQzTOW7dEpfFVSSkr8P55YhoTlw55xP13w=; b=Xkny51sytj+qv8bIQsilTBdHPaNxqShq7CHeAb86DbnuUUbARyyVSu+l11de+5Sga4 MoWlglWtD6+ca2MFkzrMGzAAnt4sOm7/RicN6hWH5MIdGhBfx0A0w2YUUajkQvqdOQtm dt64fvIX8YKnZpkdWDplVfrwkPFjh2WRic64BT8dy9Ad3uZgM54DWdFP05XnEEiswZV6 UXS3f+0nIsf4AtEjzpuRN05XItBTCr+RZAytnzaqtvoL3d04iizfN7zl6cXlAZjVnhV7 A94rVSX9QzZcTVME7f4LjbafwDurQYEFzxbR1hxsJ0mrrBrJG80Y2epDUsLvM9oebFAB 91Gg== X-Gm-Message-State: AOAM531BEvCmQ/84bjncpQx/prSpOLa1GeqLYNk20j2itjDdWCPJmCJL NAC4WsNfjvdre0pXr1DslQjZXpqDPUZH/EPdqXqcWw== X-Google-Smtp-Source: ABdhPJw5Vk1wThTWQ6piVA0iJPsTuINRFUfh4+KEWMJ5Uik/MuAwN5wnmzE+TbLezcePV0M0IStZFxXkagfJnjRDzgc= X-Received: by 2002:aca:3d07:: with SMTP id k7mr1392880oia.172.1601648339445; Fri, 02 Oct 2020 07:18:59 -0700 (PDT) MIME-Version: 1.0 References: <20200929133814.2834621-1-elver@google.com> <20200929133814.2834621-4-elver@google.com> In-Reply-To: From: Marco Elver Date: Fri, 2 Oct 2020 16:18:48 +0200 Message-ID: Subject: Re: [PATCH v4 03/11] arm64, kfence: enable KFENCE for ARM64 To: Jann Horn 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2 Oct 2020 at 08:48, Jann Horn wrote: > > On Tue, Sep 29, 2020 at 3:38 PM Marco Elver wrote: > > Add architecture specific implementation details for KFENCE and enable > > KFENCE for the arm64 architecture. In particular, this implements the > > required interface in . Currently, the arm64 version does > > not yet use a statically allocated memory pool, at the cost of a pointer > > load for each is_kfence_address(). > [...] > > diff --git a/arch/arm64/include/asm/kfence.h b/arch/arm64/include/asm/kfence.h > [...] > > +static inline bool arch_kfence_initialize_pool(void) > > +{ > > + const unsigned int num_pages = ilog2(roundup_pow_of_two(KFENCE_POOL_SIZE / PAGE_SIZE)); > > + struct page *pages = alloc_pages(GFP_KERNEL, num_pages); > > + > > + if (!pages) > > + return false; > > + > > + __kfence_pool = page_address(pages); > > + return true; > > +} > > If you're going to do "virt_to_page(meta->addr)->slab_cache = cache;" > on these pages in kfence_guarded_alloc(), and pass them into kfree(), > you'd better mark these pages as non-compound - something like > alloc_pages_exact() or split_page() may help. Otherwise, I think when > SLUB's kfree() does virt_to_head_page() right at the start, that will > return a pointer to the first page of the entire __kfence_pool, and > then when it loads page->slab_cache, it gets some random cache and > stuff blows up. Kinda surprising that you haven't run into that during > your testing, maybe I'm missing something... I added a WARN_ON() check in kfence_initialize_pool() to check if our pages are compound or not; they are not. In slub.c, __GFP_COMP is passed to alloc_pages(), which causes them to have a compound head I believe. > Also, this kinda feels like it should be the "generic" version of > arch_kfence_initialize_pool() and live in mm/kfence/core.c ? Done for v5. Thanks, -- Marco 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=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,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 25209C4727D for ; Fri, 2 Oct 2020 14:19:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B54F020719 for ; Fri, 2 Oct 2020 14:19:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WbL9t9/X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B54F020719 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 05F4C6B0071; Fri, 2 Oct 2020 10:19:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2C76900002; Fri, 2 Oct 2020 10:19:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF3CB6B0073; Fri, 2 Oct 2020 10:19:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id B2B6D6B0071 for ; Fri, 2 Oct 2020 10:19:01 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3A60A8249980 for ; Fri, 2 Oct 2020 14:19:01 +0000 (UTC) X-FDA: 77327192082.20.suit64_0304b71271a4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 09931180C07AB for ; Fri, 2 Oct 2020 14:19:01 +0000 (UTC) X-HE-Tag: suit64_0304b71271a4 X-Filterd-Recvd-Size: 5999 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Fri, 2 Oct 2020 14:19:00 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id z26so1344034oih.12 for ; Fri, 02 Oct 2020 07:19:00 -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=tYH/6hO5lgQzTOW7dEpfFVSSkr8P55YhoTlw55xP13w=; b=WbL9t9/X+2+U5VeNgqJ2mzYEVs8LZ8q8hjggo7N19g1Jfbf7P1wkvnp8roJdVEw2lS c3i+9tyC5AUycxhnZX3RIt4oznfraSi/7+MhXAFF62q39I2RYcbTn5QT7+m9u2tkqg6l t8CPQiS4CwE3/je84zeBM5/j7j3lEb16Ugt2aIYvU40jH0TI0PR5J1CBlhaYuqhraQ9S VNH44ZU9nil0inzWBzSBsDd31QGBA5Yoy3hYBsIdwpYvq+FTYKKD014ZVWSBoeXqJDuA xB8WY3nYSYtoHgpNv87LMV6Wm9qhKizfdSBX5z2jHJgzn6f3UzGseSKEQmzLzzorHWIt HJog== 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=tYH/6hO5lgQzTOW7dEpfFVSSkr8P55YhoTlw55xP13w=; b=lm74U7Ysnnv93CXWHQbwerAhvbY5l8uN9VyIUTPpT7zUYch2RDIvtZe0oueH872RPC qev1qHMbjNjnEuUZuoO/UPKHh7Ko8UkKwAlfROEhTvmIAVRgfIf3YzXT+1PgLB5viKIa vYM6+xobE6GyVYlfU1T5zQ6Oo71PDkPcuznH6tRmFyuTa/0DNEH9Z07Fo5N/JGuBkI6a GU8nloEvmT7/FjpScWLfiopfADlcvJo/4HlCDQGSVcmpkYACuNdfkuWZlV4BjDPk/vHA /lUWN6BARUh6dqbzbGAk5h2EWZN8N+sARhqMljnPkMFvKT3bmLA0awLdq8IQaqTLZ7j+ XnUQ== X-Gm-Message-State: AOAM531jwqOabkj2DmTzi1J10tNhNsZmGz62uL9S+7PJUVf0vRQu3G2n jEjJtfkAWS492idFGgJ2v12AfuJ0TvGBU+0mJULf5Q== X-Google-Smtp-Source: ABdhPJw5Vk1wThTWQ6piVA0iJPsTuINRFUfh4+KEWMJ5Uik/MuAwN5wnmzE+TbLezcePV0M0IStZFxXkagfJnjRDzgc= X-Received: by 2002:aca:3d07:: with SMTP id k7mr1392880oia.172.1601648339445; Fri, 02 Oct 2020 07:18:59 -0700 (PDT) MIME-Version: 1.0 References: <20200929133814.2834621-1-elver@google.com> <20200929133814.2834621-4-elver@google.com> In-Reply-To: From: Marco Elver Date: Fri, 2 Oct 2020 16:18:48 +0200 Message-ID: Subject: Re: [PATCH v4 03/11] arm64, kfence: enable KFENCE for ARM64 To: Jann Horn 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 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, 2 Oct 2020 at 08:48, Jann Horn wrote: > > On Tue, Sep 29, 2020 at 3:38 PM Marco Elver wrote: > > Add architecture specific implementation details for KFENCE and enable > > KFENCE for the arm64 architecture. In particular, this implements the > > required interface in . Currently, the arm64 version does > > not yet use a statically allocated memory pool, at the cost of a pointer > > load for each is_kfence_address(). > [...] > > diff --git a/arch/arm64/include/asm/kfence.h b/arch/arm64/include/asm/kfence.h > [...] > > +static inline bool arch_kfence_initialize_pool(void) > > +{ > > + const unsigned int num_pages = ilog2(roundup_pow_of_two(KFENCE_POOL_SIZE / PAGE_SIZE)); > > + struct page *pages = alloc_pages(GFP_KERNEL, num_pages); > > + > > + if (!pages) > > + return false; > > + > > + __kfence_pool = page_address(pages); > > + return true; > > +} > > If you're going to do "virt_to_page(meta->addr)->slab_cache = cache;" > on these pages in kfence_guarded_alloc(), and pass them into kfree(), > you'd better mark these pages as non-compound - something like > alloc_pages_exact() or split_page() may help. Otherwise, I think when > SLUB's kfree() does virt_to_head_page() right at the start, that will > return a pointer to the first page of the entire __kfence_pool, and > then when it loads page->slab_cache, it gets some random cache and > stuff blows up. Kinda surprising that you haven't run into that during > your testing, maybe I'm missing something... I added a WARN_ON() check in kfence_initialize_pool() to check if our pages are compound or not; they are not. In slub.c, __GFP_COMP is passed to alloc_pages(), which causes them to have a compound head I believe. > Also, this kinda feels like it should be the "generic" version of > arch_kfence_initialize_pool() and live in mm/kfence/core.c ? Done for v5. Thanks, -- Marco 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=-6.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,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 CED02C4363D for ; Fri, 2 Oct 2020 14:20:24 +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 7B04B206A5 for ; Fri, 2 Oct 2020 14:20:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="v/tXrVsW"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="WbL9t9/X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B04B206A5 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=1zlFTRhq59qXi/Wt4hnbCP59qXpcNR2Mf7w+x7pRLSc=; b=v/tXrVsWfMujOlx2kdIZvz7vO YH/ZijP3O931JlPix/AtbZBVNJztncYlBGEgYP0slE+U81cWgpUPOsZNpDEIkDY0EFXfJPSAnCxCJ Pd9laBl/mjndFDbY3E4zePYFnQ0dxBAREvsp7ZFt2zIRg3OIE0+qz3Tri6Avm6MbM0eDe/kEvnyhN j3lNPGt1wXY/zy6jbFj2YiUPg/dpPGkoSIQWTTOwa/IRbVx4wd5/uzNzL21aUuo94wEVy/XPzMukg RA3mYHQWDya2UYBbELb+QjrLlmKkFXnZK/z8OZTA9JLBVe1ERYI7qvhaz0UJw+M8GlKun7H+PVAm0 2urlrcAJg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kOLtq-0007wP-8u; Fri, 02 Oct 2020 14:19:06 +0000 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kOLtn-0007uQ-5e for linux-arm-kernel@lists.infradead.org; Fri, 02 Oct 2020 14:19:04 +0000 Received: by mail-oi1-x241.google.com with SMTP id v20so1370556oiv.3 for ; Fri, 02 Oct 2020 07:19:01 -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=tYH/6hO5lgQzTOW7dEpfFVSSkr8P55YhoTlw55xP13w=; b=WbL9t9/X+2+U5VeNgqJ2mzYEVs8LZ8q8hjggo7N19g1Jfbf7P1wkvnp8roJdVEw2lS c3i+9tyC5AUycxhnZX3RIt4oznfraSi/7+MhXAFF62q39I2RYcbTn5QT7+m9u2tkqg6l t8CPQiS4CwE3/je84zeBM5/j7j3lEb16Ugt2aIYvU40jH0TI0PR5J1CBlhaYuqhraQ9S VNH44ZU9nil0inzWBzSBsDd31QGBA5Yoy3hYBsIdwpYvq+FTYKKD014ZVWSBoeXqJDuA xB8WY3nYSYtoHgpNv87LMV6Wm9qhKizfdSBX5z2jHJgzn6f3UzGseSKEQmzLzzorHWIt HJog== 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=tYH/6hO5lgQzTOW7dEpfFVSSkr8P55YhoTlw55xP13w=; b=casxtEQkH3PeWd/kCltcrP1VaN/ckFXv67rMg5ZlTGP1XdvVcdaBo3QYVIyFLbs9cM cNCcehey6sf21tT6BogORYTL0J8niIkgK3ZprvIXbTZNep+oPqU34HDdLkR/xgY8ffJQ LcjWWYLpZgjuvWwIkjlaoONhtk7ruFJd0SafvrR+QO+oBR413JyibjxJ4KYCi712u1hQ 7E3X7/Jb5CDSpfi4tBZkxzdQCBc4NumFfRbgdLe0Dzg2tRHt6aVhWsQAAKhzsb1QzUZv 4AZ6kURDMGAuO9IdMU/iMHgrGE9U10uKY3n3ZPNNRUU2s8ZxzpZZMIZB46Xh55sxiX/g SQJA== X-Gm-Message-State: AOAM530xPJEevz2U2glXPs/Hj7uBui4ipBtBEWaFeOTVVlKxOOUnO6G2 gxrBtF8DDSKVGw3nOYlMdoawa+Ziyx1qp3fIbPqecQ== X-Google-Smtp-Source: ABdhPJw5Vk1wThTWQ6piVA0iJPsTuINRFUfh4+KEWMJ5Uik/MuAwN5wnmzE+TbLezcePV0M0IStZFxXkagfJnjRDzgc= X-Received: by 2002:aca:3d07:: with SMTP id k7mr1392880oia.172.1601648339445; Fri, 02 Oct 2020 07:18:59 -0700 (PDT) MIME-Version: 1.0 References: <20200929133814.2834621-1-elver@google.com> <20200929133814.2834621-4-elver@google.com> In-Reply-To: From: Marco Elver Date: Fri, 2 Oct 2020 16:18:48 +0200 Message-ID: Subject: Re: [PATCH v4 03/11] arm64, kfence: enable KFENCE for ARM64 To: Jann Horn X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201002_101903_247386_A5C18BAC X-CRM114-Status: GOOD ( 23.03 ) 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 , 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, 2 Oct 2020 at 08:48, Jann Horn wrote: > > On Tue, Sep 29, 2020 at 3:38 PM Marco Elver wrote: > > Add architecture specific implementation details for KFENCE and enable > > KFENCE for the arm64 architecture. In particular, this implements the > > required interface in . Currently, the arm64 version does > > not yet use a statically allocated memory pool, at the cost of a pointer > > load for each is_kfence_address(). > [...] > > diff --git a/arch/arm64/include/asm/kfence.h b/arch/arm64/include/asm/kfence.h > [...] > > +static inline bool arch_kfence_initialize_pool(void) > > +{ > > + const unsigned int num_pages = ilog2(roundup_pow_of_two(KFENCE_POOL_SIZE / PAGE_SIZE)); > > + struct page *pages = alloc_pages(GFP_KERNEL, num_pages); > > + > > + if (!pages) > > + return false; > > + > > + __kfence_pool = page_address(pages); > > + return true; > > +} > > If you're going to do "virt_to_page(meta->addr)->slab_cache = cache;" > on these pages in kfence_guarded_alloc(), and pass them into kfree(), > you'd better mark these pages as non-compound - something like > alloc_pages_exact() or split_page() may help. Otherwise, I think when > SLUB's kfree() does virt_to_head_page() right at the start, that will > return a pointer to the first page of the entire __kfence_pool, and > then when it loads page->slab_cache, it gets some random cache and > stuff blows up. Kinda surprising that you haven't run into that during > your testing, maybe I'm missing something... I added a WARN_ON() check in kfence_initialize_pool() to check if our pages are compound or not; they are not. In slub.c, __GFP_COMP is passed to alloc_pages(), which causes them to have a compound head I believe. > Also, this kinda feels like it should be the "generic" version of > arch_kfence_initialize_pool() and live in mm/kfence/core.c ? Done for v5. Thanks, -- Marco _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel