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