Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp735495pxu; Wed, 14 Oct 2020 12:17:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxK0GAm/zZgN7ihFfpdlyPolW9Y2+Q33t5GJQK/lN26dY45wM3H08Og689rt7K1/HWTjR4Q X-Received: by 2002:a05:6402:13da:: with SMTP id a26mr438777edx.291.1602703060157; Wed, 14 Oct 2020 12:17:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602703060; cv=none; d=google.com; s=arc-20160816; b=Ty/VcpeIhIhR4qqOltDp71/+/Y6uAXZ4SXQzF3QOMrxIE1PRJHH6rMMzJCo3rBV35S bDASrclbgO1jtj2Au02ilbXnxNsdkfQTaooUSOHfbUPu2c8mhC8VinQqQ4BV6yH3gH8f /MJ7a6CjlLkHkLjXyMjO8EfMfjGoPJq4EotbBm++8E4ct0v38gWf0spl6Exz91sSlhC6 T3zVmPeoWXabYN9v69cWdAswb2ojEywJbTsM/lj2htFLHwxfkXSoGNtML9UoLHmDZw12 t+fB+AiWov/QDpMeblSi3F4n40PBxSAjXzqA5zkty/hg6TbvDOmRi7rq8wQEz3lQZYjx yWrw== 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=ZeIyBZH1DlMazqL3WPQEWDzdrz72p5JAZek4MEGZox0=; b=V4nCb8UgGsqTgDO7I7sOH/3wHkXevkmRVJ1B5rf243FpTtP7TDF0sgCEgy3W+6+IJ3 GnAKzq+WxEkIpcYQT4XEhxFMxeTaThLnY3Iaq8IVP+EG3MxWf9y7ILe8hGzJaoLk0Qjr M9+Z3kv04xpFr6SIyQBVLkZcEtNb0oNZ4ewYdEYA94tpPY5WVNAfin41QsPE7/vCiXsV u+Hh77ddCavEV3DvAEQYjENREns/acnM7BsyAGh+oXM2BspHuJoUR+XojU5L+NRSW6lE GM7iqaoB9AUU58DMf2XDBldVr6VonRixWIkb09T64WXd7/S8hvJDT+YIQrirJmyiNKX0 KvSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="QoXiKIK/"; 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 bu15si284625edb.481.2020.10.14.12.17.17; Wed, 14 Oct 2020 12:17:40 -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="QoXiKIK/"; 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 S2390475AbgJNTM4 (ORCPT + 99 others); Wed, 14 Oct 2020 15:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390412AbgJNTMv (ORCPT ); Wed, 14 Oct 2020 15:12:51 -0400 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1610C0613D2 for ; Wed, 14 Oct 2020 12:12:50 -0700 (PDT) Received: by mail-oi1-x241.google.com with SMTP id h10so346085oie.5 for ; Wed, 14 Oct 2020 12:12:50 -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=ZeIyBZH1DlMazqL3WPQEWDzdrz72p5JAZek4MEGZox0=; b=QoXiKIK/b6kRcW6PeofIscaKrIR52aRKjK4qvKq8aq8FfwkJyBRTC0ZEcPvRccLrhQ u+FpbklPzt4CeRTorbjIFdSCfLOkMOflGkHc8h4q1COYv3UEi+R3nUAjbveX5cXR2V+p wCE7CgcPvaOdVfjawROqxRJ7rqWpmE5mbP3mPrTxWm8PrpDc5KuzQKTsrTsz1O27Csog KFs0ESSPZ2TcgNQ0ZsN3PYi4798fLNTOv9c63rkDZFfqUNSPRyVsOvlzYgs40HlLtSFs kgRH3yS4GXzfnqQaLDPtJF1yLg233FCVeq6yhxM4LWENkAIt6KpBXFiQVKjApYHQqAIV s10A== 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=ZeIyBZH1DlMazqL3WPQEWDzdrz72p5JAZek4MEGZox0=; b=YrYqLSV1iJ9vvYbAzfKtD3jzu5Uf5tcTgYm+vO+d8LaBmEFUoA/wCw3obk2GMSWd6n kPYw/XFJ2dLck1lMiCCQK3Hehv1Nmzm2228Dww7nXJirzu2cuBdcSyazFT92PZBJN0Mf 4pOvTN1BGJAd0CSWBM+YHMf5fHmFP5Cafr1l3zKQgvHVhQ4kiyPmA9bliL4C6y+WTeB/ Bx8dfAfISp4cgGdJoABZ707BGuxlLziZhbeGqRIziq+3h31wC3XazrAe79q6VxGHZJYX tZpHiC1Xij/jPqXOUKD0IciwwsZxtpVrCjql5o82HpnhcJj3EV94/exehlpbjODJvRYA 4sXw== X-Gm-Message-State: AOAM530bMW13ivmLk184vN3d9Hwp9qADLD7RcItTIfeYje2iDS8UGWEA NT3iYJxMM2NK9jLV5yVhOv8zUh3qMOo9OxBdkm5N7g== X-Received: by 2002:aca:3d07:: with SMTP id k7mr537643oia.172.1602702769984; Wed, 14 Oct 2020 12:12:49 -0700 (PDT) MIME-Version: 1.0 References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-4-elver@google.com> <20200921143059.GO2139@willie-the-truck> <20200929140226.GB53442@C02TD0UTHF1T.local> <20201001175716.GA89689@C02TD0UTHF1T.local> <20201008104501.GB72325@C02TD0UTHF1T.local> In-Reply-To: <20201008104501.GB72325@C02TD0UTHF1T.local> From: Marco Elver Date: Wed, 14 Oct 2020 21:12:37 +0200 Message-ID: Subject: Re: [PATCH v3 03/10] arm64, kfence: enable KFENCE for ARM64 To: Mark Rutland Cc: Alexander Potapenko , Will Deacon , Andrew Morton , "H. Peter Anvin" , "Paul E. McKenney" , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Catalin Marinas , Christoph Lameter , Dave Hansen , David Rientjes , Dmitriy Vyukov , Eric Dumazet , Greg Kroah-Hartman , Hillf Danton , Ingo Molnar , Jann Horn , Jonathan Cameron , Jonathan Corbet , Joonsoo Kim , Kees Cook , Pekka Enberg , Peter Zijlstra , SeongJae Park , Thomas Gleixner , Vlastimil Babka , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , LKML , kasan-dev , Linux ARM , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 8 Oct 2020 at 12:45, Mark Rutland wrote: > On Thu, Oct 08, 2020 at 11:40:52AM +0200, Marco Elver wrote: > > On Thu, 1 Oct 2020 at 19:58, Mark Rutland wrote: > > [...] > > > > > If you need virt_to_page() to work, the address has to be part of the > > > > > linear/direct map. > > [...] > > > > > > What's the underlying requirement here? Is this a performance concern, > > > codegen/codesize, or something else? > > > > It used to be performance, since is_kfence_address() is used in the > > fast path. However, with some further tweaks we just did to > > is_kfence_address(), our benchmarks show a pointer load can be > > tolerated. > > Great! > > I reckon that this is something we can optimize in futue if necessary > (e.g. with some form of code-patching for immediate values), but it's > good to have a starting point that works everywhere! > > [...] > > > > I'm not too worried about allocating this dynamically, but: > > > > > > * The arch code needs to set up the translation tables for this, as we > > > cannot safely change the mapping granularity live. > > > > > > * As above I'm fairly certain x86 needs to use a carevout from the > > > linear map to function correctly anyhow, so we should follow the same > > > approach for both arm64 and x86. That might be a static carevout that > > > we figure out the aliasing for, or something entirely dynamic. > > > > We're going with dynamically allocating the pool (for both x86 and > > arm64), since any benefits we used to measure from the static pool are > > no longer measurable (after removing a branch from > > is_kfence_address()). It should hopefully simplify a lot of things, > > given all the caveats that you pointed out. > > > > For arm64, the only thing left then is to fix up the case if the > > linear map is not forced to page granularity. > > The simplest way to do this is to modify arm64's arch_add_memory() to > force the entire linear map to be mapped at page granularity when KFENCE > is enabled, something like: > [...] > > ... and I given that RODATA_FULL_DEFAULT_ENABLED is the default, I > suspect it's not worth trying to only for that for the KFENCE region > unless someone complains. We've got most of this sorted now for v5 -- thank you! The only thing we're wondering now, is if there are any corner cases with using memblock_alloc'd memory for the KFENCE pool? (We'd like to avoid page alloc's MAX_ORDER limit.) We have a version that passes tests on x86 and arm64, but checking just in case. :-) Thanks, -- Marco