From patchwork Wed Jun 20 17:39:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10478371 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 0B2C0601D7 for ; Wed, 20 Jun 2018 17:46:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBB5D28DFB for ; Wed, 20 Jun 2018 17:46:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E049F28E15; Wed, 20 Jun 2018 17:46:25 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CA6328DFB for ; Wed, 20 Jun 2018 17:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932299AbeFTRqK (ORCPT ); Wed, 20 Jun 2018 13:46:10 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36113 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754490AbeFTRkX (ORCPT ); Wed, 20 Jun 2018 13:40:23 -0400 Received: by mail-wm0-f65.google.com with SMTP id v131-v6so1010111wma.1 for ; Wed, 20 Jun 2018 10:40:22 -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=NNTjp1zLzU5TrkbNCH/i6H4SroEd7wqmKsanmk6nVVo=; b=bFsStUkrQ0iQlrPVOiBmoBIbL39mZFNIc0wIbZll5jQQpzGkz4MbKilvlXwwlEuhSu 0Y0XIZKORt0shALA72NzNHucE9NOplJC+ZsJmZcH08JY+9K7M+6VZkK+TXZ4uOKFUuQ8 D66xYyXBH6zYcG7jlf9CGRPtkDOB8q9dkXOzBAySr4xbBEZigcnPierMx+uJwxP3GhAO UqG+8s7pCsI4W6JGf5xd27Hj9jrL97vRm9pKVfJT1YZZhUxC4z7T4bMcYRc2fTob6obF jlUnW87SdLRkh/dARxA/xlOwS1RNXdnvgH8wH1RP/BJxHEYT8UWxydE28B7/a0QcGcBp psAA== 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=NNTjp1zLzU5TrkbNCH/i6H4SroEd7wqmKsanmk6nVVo=; b=NnGvIIilYlhMM9bW5ev8YnFNM+KsaNDmazhocC4vZjnVSEMpiGVLPfG8Iwn4JeKPyZ CISNP8a9KTD4Hw0AXf3EHAqGWfisNqABSvGDVx/lJD1skxdgULLpcB/AXAvTt+Ud3kfP ug15oI7pV1hwNQgDSgfwJH35khVizSJM0+WN5xOPBAf75Ylq6ccYiz5FvOy4yXmfG7Gf 5SFjLVZVRWYOBefN0/9IBYa3pYAPjcT7vyvcF4I4BtCvjRwB2NmzC5gkkrKXA+/lTEU3 IDWSykgH3qrxjN4X5S81Q5RG5ykvdVRMa7RFCRA8+bXJ8UyouSxJof+25O+nF2Fw+sgW Jq1A== X-Gm-Message-State: APt69E0F8N4SnAPnAS1nJIgrVsCbow+oDQSowH8x8osioVl0z5jlejyO UXzN2Df0IbQp5DLw/3P4r9CM3w== X-Google-Smtp-Source: ADUXVKKR5vFQo+Ie2U5T/+P6vWrH+ix/bPBkxBVosLpjbv2YqXISbPE7Ei1/evj/LtcPzKS7oTWTrw== X-Received: by 2002:a1c:71db:: with SMTP id d88-v6mr2586324wmi.117.1529516421542; Wed, 20 Jun 2018 10:40:21 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id f18-v6sm4388598wro.1.2018.06.20.10.40.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 10:40:20 -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 Cc: Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Andrey Konovalov Subject: [PATCH v3 09/17] khwasan, arm64: enable top byte ignore for the kernel Date: Wed, 20 Jun 2018 19:39:55 +0200 Message-Id: <4d55f61003bfb55d2b37320a5127f182c3a71111.1529515183.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: References: Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.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 5f9a73a4452c..f3dfcd74a285 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)) /* @@ -439,7 +445,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 /*