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 B7742C4363D for ; Fri, 2 Oct 2020 16:10:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 733D620758 for ; Fri, 2 Oct 2020 16:10:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IwPpPrdN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388148AbgJBQKs (ORCPT ); Fri, 2 Oct 2020 12:10:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbgJBQKs (ORCPT ); Fri, 2 Oct 2020 12:10:48 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B657C0613E2 for ; Fri, 2 Oct 2020 09:10:46 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id t16so2201810edw.7 for ; Fri, 02 Oct 2020 09:10:46 -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=TKrnU8OMrTP2HnfeDQ36W4jlkOILiDTjG4Jt9zQv/MU=; b=IwPpPrdNsnu5FlD1OobJFZzCKqafUWQ2s30+vLINDfRq3i2kHN3JPuk792i6I+hxFV ppJtNzpaq2Cyq6riihUjk4eQqNIMm2lNSgD8CghVcRL52lvCfcA//XhoaZmtkPagobKq HCOdykTKtGQhET9fzgpMmoZTDgMd4WrfE/JxVJQpF/4lFDcN7XepWB5YL/3Pf0auVNXk KZrJc6PPwixBYO+cxDLI3DeOJ3ahyyEk4BWSc2EKTkjlRoB+Hw0tLXJtech+Dexow3/q eghOfkOJigf4cnjYXMzGakOnokbBwexTzgZXEAEVFTpz1djWvjOhfbTp7zQs67XINkSU 9qnw== 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=TKrnU8OMrTP2HnfeDQ36W4jlkOILiDTjG4Jt9zQv/MU=; b=aPjt1fSzBStHs5jAZsvfTHGJASXVgXUrnJTyBjcGyX64TlqV8sHs+UbMKO4XCMwe0B tkGGQptcYutEh5xdcygN+gZCS+q9AdxOviUOCgBTQ/x7FaEQycs/hQxti5QFegW0AeT3 fY02z2Cgu6DV8nlh4pKA21WQBz1vQzSV+0SUMGc9C1Cj9JS0o3DBNb0Z2aZg2RBq7a2A 06ZMHpv4ML/XDrVViNF9ojmMaZkSnzq9+16oDw/E8GUwlhEnGU97dyCa3RSJGGULAAE8 ClPou12HWLSB313EOmfmNiVtZzQM+hVXQs2fl2eujnbhTLH0klDGKY+G740FzkS2lfZW bCKw== X-Gm-Message-State: AOAM533m08xp01uED7t1FG43OcE4e+8ydxfAsmp2gLdWwJiPuHDVBkei zIt2vrdkghylx9MvCl1gi0WMtUVebu+BVWw8YBGJrA== X-Google-Smtp-Source: ABdhPJxLy7vg7Hji+HMyUSROdJEDLd+lE2ee6OVvCPRAEz3XaYpLc31KjN/VPPgbMoqSSYcuD6bOTMFH3k2TEj8w4JM= X-Received: by 2002:a05:6402:b0e:: with SMTP id bm14mr3217947edb.259.1601655044643; Fri, 02 Oct 2020 09:10:44 -0700 (PDT) MIME-Version: 1.0 References: <20200929133814.2834621-1-elver@google.com> <20200929133814.2834621-4-elver@google.com> In-Reply-To: From: Jann Horn Date: Fri, 2 Oct 2020 18:10:18 +0200 Message-ID: Subject: Re: [PATCH v4 03/11] arm64, kfence: enable KFENCE for ARM64 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 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 4:19 PM Marco Elver wrote: > > 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. Aah, I mixed up high-order pages and compound pages. Sorry for the noise. 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 0CFAFC35257 for ; Fri, 2 Oct 2020 16:10:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6E17C206FA for ; Fri, 2 Oct 2020 16:10:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IwPpPrdN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E17C206FA 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 D1A7D6B005C; Fri, 2 Oct 2020 12:10:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCD886B005D; Fri, 2 Oct 2020 12:10:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE2426B0062; Fri, 2 Oct 2020 12:10:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0232.hostedemail.com [216.40.44.232]) by kanga.kvack.org (Postfix) with ESMTP id 8E80D6B005C for ; Fri, 2 Oct 2020 12:10:47 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 20330181AE878 for ; Fri, 2 Oct 2020 16:10:47 +0000 (UTC) X-FDA: 77327473734.23.sort03_4e14bba271a5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 8C92137613 for ; Fri, 2 Oct 2020 16:10:46 +0000 (UTC) X-HE-Tag: sort03_4e14bba271a5 X-Filterd-Recvd-Size: 6122 Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 2 Oct 2020 16:10:46 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id l17so2196137edq.12 for ; Fri, 02 Oct 2020 09:10:46 -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=TKrnU8OMrTP2HnfeDQ36W4jlkOILiDTjG4Jt9zQv/MU=; b=IwPpPrdNsnu5FlD1OobJFZzCKqafUWQ2s30+vLINDfRq3i2kHN3JPuk792i6I+hxFV ppJtNzpaq2Cyq6riihUjk4eQqNIMm2lNSgD8CghVcRL52lvCfcA//XhoaZmtkPagobKq HCOdykTKtGQhET9fzgpMmoZTDgMd4WrfE/JxVJQpF/4lFDcN7XepWB5YL/3Pf0auVNXk KZrJc6PPwixBYO+cxDLI3DeOJ3ahyyEk4BWSc2EKTkjlRoB+Hw0tLXJtech+Dexow3/q eghOfkOJigf4cnjYXMzGakOnokbBwexTzgZXEAEVFTpz1djWvjOhfbTp7zQs67XINkSU 9qnw== 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=TKrnU8OMrTP2HnfeDQ36W4jlkOILiDTjG4Jt9zQv/MU=; b=swGHXTTEySqWORvXW3jvwqKdr4IKRGvSe3qaOBuVKiAscudPHGyMkYc4mR0tYJgE5b /I3QWml4lOIOFZKdCQUohdpf0WGTkPqsCAZSDKwYDaczxS/GqtQJLK4WCwhAiqOKfulG VwzKF1c2ZzfG9twx9Z8mu7ha+e2ZEuNxy1K9z6E0+4YTSCbxB88xNC2E1q8P19Zh6Rqr 6DuffQ1bj5KHKpdVF4S+t7gNXOG4kzYdARU9EyYxSieLnn7xzZCUagLUxjjkSzehHxAO KmG7/YCxH1AHiJmJoQOW3u0dZj9VetQc+dYibAB1/cfjsghw/dooFr3oyGmEk1NGZiRF aA9Q== X-Gm-Message-State: AOAM530szKb2MwnGDJVZ6wCDL2Myb0Nfj2bregIqHGu7wm0GzWpdc+lk sWSNbBWAPpPuy/c5ebqwzwPYprtVV5yBE7/9egX5Rw== X-Google-Smtp-Source: ABdhPJxLy7vg7Hji+HMyUSROdJEDLd+lE2ee6OVvCPRAEz3XaYpLc31KjN/VPPgbMoqSSYcuD6bOTMFH3k2TEj8w4JM= X-Received: by 2002:a05:6402:b0e:: with SMTP id bm14mr3217947edb.259.1601655044643; Fri, 02 Oct 2020 09:10:44 -0700 (PDT) MIME-Version: 1.0 References: <20200929133814.2834621-1-elver@google.com> <20200929133814.2834621-4-elver@google.com> In-Reply-To: From: Jann Horn Date: Fri, 2 Oct 2020 18:10:18 +0200 Message-ID: Subject: Re: [PATCH v4 03/11] arm64, kfence: enable KFENCE for ARM64 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 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 4:19 PM Marco Elver wrote: > > 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. Aah, I mixed up high-order pages and compound pages. Sorry for the noise. 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 75EF9C4363C for ; Fri, 2 Oct 2020 16:12:07 +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 17E3E206FA for ; Fri, 2 Oct 2020 16:12:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PebrKGQF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="IwPpPrdN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 17E3E206FA 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=R+6M22SWfoye+CyyMhtD6kK2KIigulGUGBIb2xXb+3I=; b=PebrKGQFaDxJcC2eVYrPT/dSy dbTtQ2hgnG5xSl6XfOc0HIv7CHwxgGgviCd6I5onnNj+XoeOBNpTCDsXdklOVHu1fgPNgl/q01XzH jf5RQMYDtlhPULgsHSzlffYhvTJ/B251a6ZtS7b2V0Umw1kn+leCtKjQhhEMJt8gnzkC7KZxixTim ShC5PEb7UA35VyKbTxXZnTum1h5EdIjUNYyhNjylerpjbQ+W9ZAfbwLuCCleqieV4uXSrtxRgGFkd jIRw0+Bc99H7WATfjfjsOlLN9994hqGIhfHlhc76ld7m9IBI76MshECOSyBEs2/LLkbW4OKeE5VzF +GMXwEZOw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kONdz-0000y8-2k; Fri, 02 Oct 2020 16:10:51 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kONdu-0000vj-Aw for linux-arm-kernel@lists.infradead.org; Fri, 02 Oct 2020 16:10:48 +0000 Received: by mail-ed1-x544.google.com with SMTP id g3so2202284edu.6 for ; Fri, 02 Oct 2020 09:10:45 -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=TKrnU8OMrTP2HnfeDQ36W4jlkOILiDTjG4Jt9zQv/MU=; b=IwPpPrdNsnu5FlD1OobJFZzCKqafUWQ2s30+vLINDfRq3i2kHN3JPuk792i6I+hxFV ppJtNzpaq2Cyq6riihUjk4eQqNIMm2lNSgD8CghVcRL52lvCfcA//XhoaZmtkPagobKq HCOdykTKtGQhET9fzgpMmoZTDgMd4WrfE/JxVJQpF/4lFDcN7XepWB5YL/3Pf0auVNXk KZrJc6PPwixBYO+cxDLI3DeOJ3ahyyEk4BWSc2EKTkjlRoB+Hw0tLXJtech+Dexow3/q eghOfkOJigf4cnjYXMzGakOnokbBwexTzgZXEAEVFTpz1djWvjOhfbTp7zQs67XINkSU 9qnw== 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=TKrnU8OMrTP2HnfeDQ36W4jlkOILiDTjG4Jt9zQv/MU=; b=qsAul+jYzmZRFrqyJ4njry5lWR6aj33C19GUeZ5PrYVMlWGLeKmFC9DIdLIIDqf14P iHPh9bZHh3Z9Q4UyQaPG1np1ZAMzIAXPYAWTuQz7MMFyXG5QZFApSKJVnkSS1kS1fjc0 UNVM0+J8pVA/YPcE1fZhqbLbDhq7mFiDty/S8rULyc4USpPC1OjMWqKkiFBhAEohFlo7 BVbLjckE0Nz25sBp/h+1yYgYv0Y51qL2/4WpJT/7kJgjI7WEHx/y3quxaYCcJDCNtA33 06U3Bbwb2kIh5uQ3H/cbW5soeWouT58hzHfMS27St11xg4po4KoOYQv5f/Imp+XA97Ob 9ghQ== X-Gm-Message-State: AOAM532Wc4Sgz/zNzNdR6h4YV7shOvjP7wz4eYrx1Gg0rS5rNCZYDhbM dkpIgzVbC5kjQMemCof953D4e/aoZah25o49FYE5uA== X-Google-Smtp-Source: ABdhPJxLy7vg7Hji+HMyUSROdJEDLd+lE2ee6OVvCPRAEz3XaYpLc31KjN/VPPgbMoqSSYcuD6bOTMFH3k2TEj8w4JM= X-Received: by 2002:a05:6402:b0e:: with SMTP id bm14mr3217947edb.259.1601655044643; Fri, 02 Oct 2020 09:10:44 -0700 (PDT) MIME-Version: 1.0 References: <20200929133814.2834621-1-elver@google.com> <20200929133814.2834621-4-elver@google.com> In-Reply-To: From: Jann Horn Date: Fri, 2 Oct 2020 18:10:18 +0200 Message-ID: Subject: Re: [PATCH v4 03/11] arm64, kfence: enable KFENCE for ARM64 To: Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201002_121046_420973_8191D84F X-CRM114-Status: GOOD ( 25.97 ) 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, Oct 2, 2020 at 4:19 PM Marco Elver wrote: > > 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. Aah, I mixed up high-order pages and compound pages. Sorry for the noise. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel