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=-12.8 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,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 15ED4C43461 for ; Mon, 7 Sep 2020 13:43:04 +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 B52F3215A4 for ; Mon, 7 Sep 2020 13:43:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XTtygZDq"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="JLnpFrQD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B52F3215A4 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:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yKK5ST9dxLEtdJtS9IbKpLTihJqsdhAxjWoz0ISXXzo=; b=XTtygZDqpSA8WKC9UQWsp7rVl xS0NDVLYO7pZ4uvDzD4X1b/xSbWB6IhSfTjXCCE0iYnWvi96dvvIyXPgjdF2fsHRcJHQq5DIhYYOg F+vr8Ev5Vdy5pWrObkFFJlzQbDw6I29TYa5YCeOcGPgqNAPf0b3av/Liv/gwE2I1Sl4yBv8kFUIlP sUgjKh8UQa3KAj1zGQY2tIp6SYpP70Ptgi2P3DGDTr3VebJdbxtUtsOz3OpXqk+yCLvyCDqRwN+Q8 +THpRC+CZCVOp6XWxx0pMeAohUus0rNS6sCWX1LIa6et8ULMHrcvKMCaIh+B4fVy7/Ggiv/r45+3N sal+QD3+Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFHOw-0003hZ-6N; Mon, 07 Sep 2020 13:41:42 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFHOa-0003Y1-Rc for linux-arm-kernel@lists.infradead.org; Mon, 07 Sep 2020 13:41:31 +0000 Received: by mail-qt1-x84a.google.com with SMTP id a14so8931563qtp.15 for ; Mon, 07 Sep 2020 06:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=jc0VYpbbwwHp06Vd4b4APbV9LFmrdZq9B0FcghhcNas=; b=JLnpFrQDFHHhtGxwd7cU7ERsS82nxZOuQ8YNkI2UfTvpbtnZ26+NTlgWOFFAb2LRAy aS1dc5kBprSvV8t8MGbx//5d7ru5muPH5hHlOPVmL2/Ajd24Wc0zxW//RtluwlFky1Kb 2UE9AbOazy+x+s728tQe2icQHfbNgYCeY6Ck15zQt0oW3OuWbgDF+ARKN9kHxs0cnr1c +bB51nd105vUY2uxWNS1Jp5hsFvwVNTO/MXr3S38P9Kr/T3hBQpqgmPMTpVcU36T7lrc tf2Cb754qEOSXnIUvscPliA2DNUhNvX/GDl9lt5tCVn0OIrB3HTBwewRFkOdEcuUpoev dzGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=jc0VYpbbwwHp06Vd4b4APbV9LFmrdZq9B0FcghhcNas=; b=X/Hl1VY83Zb4RouQ1U8J8zALOIsAhcidCMXDKYGXywgCDGavDjUJ68fd05zv9BxVy1 Rpip98NEoxCfV93c1ke6c784gFIo4bSdDjVyqTpKgfXG3+QvRWhfslS8bkzmMwxgBMZE nbw1Ph5mGySbvGW1Amr0L6jPue3QFsgejfBOWHxlHNDfKFcioTy/XcsXn6Hu1nnc/Jk/ eYQyhua9KLYoc2XcIW2C1wxw1eokhY0ljyYW0KExEUqvph+cNBkcV745guHmKf5vhz4s zPBBblxKVX7wmCb9CjjMmUlENL0tSJJNVGVNNlt3RMR5zPekcGLeDeoW/dpffMVLTFde LztQ== X-Gm-Message-State: AOAM533eHXip3+K8xtb52/wheB783AdKnmg33x9HYfRV2zI331QYsLTy EeLbsodg1MbeN+PQ8NxgYl/M8vkkGw== X-Google-Smtp-Source: ABdhPJxNUkuLAO9y2rbZdFgphW1Q+h54SGmHVNnG677jxAI1ltghY7irm/us6h8t84X9VnswP6n3DNuunA== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) (user=elver job=sendgmr) by 2002:a05:6214:17ca:: with SMTP id cu10mr18279241qvb.6.1599486076914; Mon, 07 Sep 2020 06:41:16 -0700 (PDT) Date: Mon, 7 Sep 2020 15:40:48 +0200 In-Reply-To: <20200907134055.2878499-1-elver@google.com> Message-Id: <20200907134055.2878499-4-elver@google.com> Mime-Version: 1.0 References: <20200907134055.2878499-1-elver@google.com> X-Mailer: git-send-email 2.28.0.526.ge36021eeef-goog Subject: [PATCH RFC 03/10] arm64, kfence: enable KFENCE for ARM64 From: Marco Elver To: elver@google.com, glider@google.com, akpm@linux-foundation.org, catalin.marinas@arm.com, cl@linux.com, rientjes@google.com, iamjoonsoo.kim@lge.com, mark.rutland@arm.com, penberg@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200907_094120_937713_1D13A366 X-CRM114-Status: GOOD ( 22.83 ) 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: linux-doc@vger.kernel.org, peterz@infradead.org, dave.hansen@linux.intel.com, linux-mm@kvack.org, edumazet@google.com, hpa@zytor.com, will@kernel.org, corbet@lwn.net, x86@kernel.org, kasan-dev@googlegroups.com, mingo@redhat.com, linux-arm-kernel@lists.infradead.org, aryabinin@virtuozzo.com, keescook@chromium.org, paulmck@kernel.org, jannh@google.com, andreyknvl@google.com, cai@lca.pw, luto@kernel.org, tglx@linutronix.de, dvyukov@google.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, bp@alien8.de 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 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(). Co-developed-by: Alexander Potapenko Signed-off-by: Alexander Potapenko Signed-off-by: Marco Elver --- For ARM64, we would like to solicit feedback on what the best option is to obtain a constant address for __kfence_pool. One option is to declare a memory range in the memory layout to be dedicated to KFENCE (like is done for KASAN), however, it is unclear if this is the best available option. We would like to avoid touching the memory layout. --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kfence.h | 39 +++++++++++++++++++++++++++++++++ arch/arm64/mm/fault.c | 4 ++++ 3 files changed, 44 insertions(+) create mode 100644 arch/arm64/include/asm/kfence.h diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 6d232837cbee..1acc6b2877c3 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -132,6 +132,7 @@ config ARM64 select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN if !(ARM64_16K_PAGES && ARM64_VA_BITS_48) select HAVE_ARCH_KASAN_SW_TAGS if HAVE_ARCH_KASAN + select HAVE_ARCH_KFENCE if (!ARM64_16K_PAGES && !ARM64_64K_PAGES) select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT diff --git a/arch/arm64/include/asm/kfence.h b/arch/arm64/include/asm/kfence.h new file mode 100644 index 000000000000..608dde80e5ca --- /dev/null +++ b/arch/arm64/include/asm/kfence.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_KFENCE_H +#define __ASM_KFENCE_H + +#include +#include +#include + +#include + +#define KFENCE_SKIP_ARCH_FAULT_HANDLER "el1_sync" + +/* + * FIXME: Support HAVE_ARCH_KFENCE_STATIC_POOL: Use the statically allocated + * __kfence_pool, to avoid the extra pointer load for is_kfence_address(). By + * default, however, we do not have struct pages for static allocations. + */ + +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; +} + +static inline bool kfence_protect_page(unsigned long addr, bool protect) +{ + set_memory_valid(addr, 1, !protect); + + return true; +} + +#endif /* __ASM_KFENCE_H */ diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index f07333e86c2f..d5b72ecbeeea 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -310,6 +311,9 @@ static void __do_kernel_fault(unsigned long addr, unsigned int esr, "Ignoring spurious kernel translation fault at virtual address %016lx\n", addr)) return; + if (kfence_handle_page_fault(addr)) + return; + if (is_el1_permission_fault(addr, esr, regs)) { if (esr & ESR_ELx_WNR) msg = "write to read-only memory"; -- 2.28.0.526.ge36021eeef-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel