Received: by 2002:a4f:b056:0:0:0:0:0 with SMTP id m22csp1402583ivi; Fri, 2 Oct 2020 09:15:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPt0sWuT/Kajb1DNnR+uooosn1EjX55Yz6SrFame4Sc2pLR7VjIb69R6O/iB2DypLSlpqt X-Received: by 2002:a17:906:c43:: with SMTP id t3mr2995425ejf.219.1601655319915; Fri, 02 Oct 2020 09:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601655319; cv=none; d=google.com; s=arc-20160816; b=TI5MAF9v0rf7x5kgnhfoV3C7ASeSQkOX8CKFm7gfAI+eIwJ72HpzJc0NMxx1Bn2trk Py8Pa52R0Wnv+HzefJfGVocoNng2G+1FPT8UQKzTJnccqqqUq1F4EqgKdz2mYgJIXCx+ EXiMD5kS+gBNYME3/IC8WWsszJmjCxcdji4nSR5wPog4djQ6ptXMdv0hmkYJK0FaUU78 NKEKNnvNSIFpCvJJO6c5cfvS/seVOlG/hLdGHNfUeGQ+6Ok+fA1bpGTWOy9A8ES5yCnw 9WKWrA0CvZABnaEts1mQtCIjqN9zo5RM+UD/DwpoBVODOBjt/NCcAHsI757WpQdJOk3E cLmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TKrnU8OMrTP2HnfeDQ36W4jlkOILiDTjG4Jt9zQv/MU=; b=c47E22Eamm1bem/EDxiODl004S4yoVTOQinjvySzf/nVvrTsufETpSuyohFLbG0w4A CDej82dCFI1iVe7JaXRii+5rt2aIowW+daKiy9V7/t6RiGx7g15yZsmZeqFWognFIpAk 5rwArCTMkq118xJBKLDeE0AV9gksH4iGn93mfsK8vAWIIBoRrMLTWFB1TsICQcpeXtnR WVBqiQDulzysUhyhRHHJZcS5sJQ93fRnbgHUq80MAfJLOBFBotawjMetuh2dWxzqmWPZ uNH8J4dZPKIOHQiH4FbrEi0HoML5EmMqRbslWHMT1CEy6a4JKfhnZYSIvBaq9uPIjm8Y XawA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IwPpPrdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h24si1531789ejk.63.2020.10.02.09.14.57; Fri, 02 Oct 2020 09:15:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IwPpPrdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388139AbgJBQKs (ORCPT + 99 others); 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-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.