From patchwork Tue Jun 26 13:15:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10488995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8946760386 for ; Tue, 26 Jun 2018 13:19:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78B7828960 for ; Tue, 26 Jun 2018 13:19:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D05428963; Tue, 26 Jun 2018 13:19:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0285528960 for ; Tue, 26 Jun 2018 13:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=VDedw3jqejnke2398ZX8f9FG+iTMpTPlPlY06OGGRBY=; b=k2qTpEAU8RijQOL3N5z4h75oW7 8tseHnPGfmojalW1N7bLDE+7+CPHqI1wYNJrnDDb+RXNuGgsO2Nbjp5PPX7DAMAW1B4Anq4gz/kjJ VSConeonK3/xBk1Wr/IYbmqAFu1vWAAmEYTkyswuGoTgtHB9WRiOX2ZGCxIOCf9Ct31XkEzmAdPTz ALeQ2V7+hNJyBGxoGd2iQFq/Fl9+99gd5Qm2xBb4jfHbAsual8zqJ1+2heTwPCl8BhKb+9OgBOpfU P+EQB+hRQ2xRXxrjk8o3VDrdca9rudmxrpQjiQj7iAVopKgBunOi5y+sK5FJ3e2s6zg8FCk5tuBtU GUkIgZyg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXnsb-0000gI-4b; Tue, 26 Jun 2018 13:19:33 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXnp4-0007E1-1b for linux-arm-kernel@lists.infradead.org; Tue, 26 Jun 2018 13:16:23 +0000 Received: by mail-wm0-x244.google.com with SMTP id e16-v6so1892167wmd.0 for ; Tue, 26 Jun 2018 06:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VCj9H90+ovXjReBaVfSQH5CvcvzciBxLHdjd+ndYlao=; b=algw/UwANNBO1mP8NOPjPQ7LzR9BXgfrF6JZbe2j23CRiaeC4quc9v2Pm9S+28nZQW Uf1RnrtevSQnDWdy3oME8nUVpfliRZHbflCk1KaJOPBh+s59TQ2rXTVjSXQKYX4xc3rz YZzGV2bP1kDQhyhl4DJjYrVYQ1FAGxZDG+k4fMLnl24PHJYajW8B2l5xnkDzRQ4LmvXb SxsYH1O+NiL3nOvOh1DGsY63j5ex5TO/l1Kr8InZzfDWLgr+XcjnYAvWwyI3RsWLJnyQ E6VXTSe7AJsh27qa/Mziek9jIq97/MtUKUwmCtGqACW66dqg0VgJNVLs6UEfJ3/a0j6H tepg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VCj9H90+ovXjReBaVfSQH5CvcvzciBxLHdjd+ndYlao=; b=aJ1Z5IMz28NVttb8bNSfQ9fVMuyOYoGPTi6m1VuXPvdln3/jLwYOsA8QUvOPEGPHe/ QMAPEllayp9vV6Y0TNbiaxAqTGHB2J73mmPysuqORg+ikJ0Xf6I2IilONb7SwPxaVeer 8nUEVIctyzTOkEbRwAa/zo+ADZAojFW3csNU5BTo+/YZsaE5Duxhexw2QFwECioyEbbF c2AIjXoSWHvJkTGDQ8bQ165jTgi55hRi4HyvECGO1RCge/VDQUcra7QdtpiuIiDNt1Cw eqYTnPmXgVGgHVqEztnJ/wRxk0pSJRs4Eu0Gx6qsAtU8WCHa/GI6f299M2IvzR0aibrK SU2Q== X-Gm-Message-State: APt69E2GaZHl1JcXa9JBkxe3yEkNLvkqCdtd0wBveKO3FVRXo18WZzdn yZRvLMUTwpGZVsXxNcfHoaLRsQ== X-Google-Smtp-Source: AAOMgpf2aPNc18qI7NpSf6WnKXLP4rIHGIUXeOMxVhHuHs/y7iMs+6rYMoW3PHAwctKy6CsBoOJ11Q== X-Received: by 2002:a1c:5c93:: with SMTP id q141-v6mr1611058wmb.77.1530018950315; Tue, 26 Jun 2018 06:15:50 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id w15-v6sm2162639wrn.25.2018.06.26.06.15.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 06:15:48 -0700 (PDT) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , Christoph Lameter , Andrew Morton , Mark Rutland , Nick Desaulniers , Marc Zyngier , Dave Martin , Ard Biesheuvel , "Eric W . Biederman" , Ingo Molnar , Paul Lawrence , Geert Uytterhoeven , Arnd Bergmann , "Kirill A . Shutemov" , Greg Kroah-Hartman , Kate Stewart , Mike Rapoport , kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kbuild@vger.kernel.org Subject: [PATCH v4 09/17] khwasan, arm64: enable top byte ignore for the kernel Date: Tue, 26 Jun 2018 15:15:19 +0200 Message-Id: <82571a6721547446b789f759f93bf7f3930541be.1530018818.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180626_061554_110206_AB90BE0C X-CRM114-Status: GOOD ( 13.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Andrey Konovalov , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgeniy Stepanov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP KHWASAN uses the Top Byte Ignore feature of arm64 CPUs to store a pointer tag in the top byte of each pointer. This commit enables the TCR_TBI1 bit, which enables Top Byte Ignore for the kernel, when KHWASAN is used. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/mm/proc.S | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index fd208eac9f2a..483aceedad76 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -289,6 +289,7 @@ #define TCR_A1 (UL(1) << 22) #define TCR_ASID16 (UL(1) << 36) #define TCR_TBI0 (UL(1) << 37) +#define TCR_TBI1 (UL(1) << 38) #define TCR_HA (UL(1) << 39) #define TCR_HD (UL(1) << 40) #define TCR_NFD1 (UL(1) << 54) diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 03646e6a2ef4..c5175e098d02 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -47,6 +47,12 @@ /* PTWs cacheable, inner/outer WBWA */ #define TCR_CACHE_FLAGS TCR_IRGN_WBWA | TCR_ORGN_WBWA +#ifdef CONFIG_KASAN_HW +#define TCR_KASAN_FLAGS TCR_TBI1 +#else +#define TCR_KASAN_FLAGS 0 +#endif + #define MAIR(attr, mt) ((attr) << ((mt) * 8)) /* @@ -440,7 +446,7 @@ ENTRY(__cpu_setup) */ ldr x10, =TCR_TxSZ(VA_BITS) | TCR_CACHE_FLAGS | TCR_SMP_FLAGS | \ TCR_TG_FLAGS | TCR_KASLR_FLAGS | TCR_ASID16 | \ - TCR_TBI0 | TCR_A1 + TCR_TBI0 | TCR_A1 | TCR_KASAN_FLAGS tcr_set_idmap_t0sz x10, x9 /*