Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp531428pxa; Fri, 14 Aug 2020 10:30:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCivXfp1wy1a4jqgzdhGDpWTzztZOvVEERiTgQHaFY9F1VZ6RdVfMZmwTF3KVitOeHtLyH X-Received: by 2002:a17:906:86c9:: with SMTP id j9mr3376055ejy.5.1597426220606; Fri, 14 Aug 2020 10:30:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597426220; cv=none; d=google.com; s=arc-20160816; b=fhd4rdgGkGtQY8E44qbaO00XmmiMCDF3bPVmHsf/aIQ4ea+kWqgjURsFF+IiK3Ab0X LCaavdJW/PxX5ikvEQ1PL2esZdVmZXekftOVyBewl+TvSd+jnuM/5yqT6mBoDNCPYIGw +qjDK7Jx/ixpfHvORchROguJnRtU1N5C50ze15YrZzx0Q8Nzd4MpLNaEOpbJEHDohBws cTWXDeNRYbMQeSc6zEXRsRvVcMoR/KeKdLg7ziR1FWLYtRsfP+fUnzgo70qsSmr6IXje TxzFOjKLgYFa8yScb+ccEW/Fjaj3OyvwbLsTZM1OvmqrYUXqXE6wVd4cvBH9qEQg5CdW VXtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=ZkzH9bOmKLetwfTAc91nMyZnzSTKk7nABhSXX08ok80=; b=S5faRQpYqz4Iv80+Zu0uDMdnrhjYGuHDzju9bj5ei67rB1T3yfHtgRDSSxlVJR2biE AB5LtAy8O8hh4Kti1c7EezEz0oSIXuZkvA3SNZ3yQPLv9p6XJVKujdHPQ9yE/mslAT2X ORxHfv4kuwSIX5FsF5hM2VGyClpN2+btPxN/oJiv5nCLjVR7Vz8aZ5+AC2xcHEWuC+sW AMFOksJDIjWXtzFGxQ+Z7Z8BjbFHXfzVcayYv90AWdhW2oNVSxrnDkGmojOfq2r9uoNX FakD5itoRXatMemhq88BVJAMiMuCCz4WwwXeN259QTc/njGeu5iQxc57lCWibauBNws7 SAeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wLdpPUJw; 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 d20si5953054ejz.445.2020.08.14.10.29.57; Fri, 14 Aug 2020 10:30:20 -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=wLdpPUJw; 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 S1728767AbgHNR23 (ORCPT + 99 others); Fri, 14 Aug 2020 13:28:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728590AbgHNR2U (ORCPT ); Fri, 14 Aug 2020 13:28:20 -0400 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF86EC061385 for ; Fri, 14 Aug 2020 10:28:19 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id s23so3593846wrb.12 for ; Fri, 14 Aug 2020 10:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ZkzH9bOmKLetwfTAc91nMyZnzSTKk7nABhSXX08ok80=; b=wLdpPUJww5Ou2gUNuObrOdFaQJnwk0f2wflLug0UxXjjB+JUFXEgy0pH9EJA0zc2Sa SV/JD6gXxYc8wagutHbT1eUXJ9ZAuMFvhoOliuhpaoQLHOz/NNoYpBIB4Na0gKA8ML/9 1IygqyNxrVi5xO4HBEfdG9bBZQt2GIQr9oN+HYuAyHMXgprw4bxZWFeJoyOjRVvNxO5T xY06EZ2RFKc4m+QOjEBnFNnkS47Tv3wDXKIY+t5vcT7jIKe5RGeipEE/Je9CVTeGOKPX 4tpGn5ZtbfVXXOeirPojx390N6o1GbaZYW/Pa2alwkhzB6IopgXoC2j5AIc8GQcYVYLi XytQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ZkzH9bOmKLetwfTAc91nMyZnzSTKk7nABhSXX08ok80=; b=r7YzURaRN8/e/umRlfg8mTtoRw8IlzYDU4yxd6SrQ4/qnrHO+s0xp/NcgDCoUV1QFV +jQ4tEeR85aWmf6UzAucmAmx/vdzZcEYINM9VUzB9LBdv/Tr4iWbKAxnfHmp4Kx/epT4 pNIzkfo7v8BgQG4S5pnTPP5pp1fTJRCwsjj1IXbN95UqO00EJTvdThc+OvFNhRoVJclL xbR963wiP7wpoF2RauOCZJt4kSk1F/S8UZ2Mx6YxY8veOvOeu1w4xQf1OPT0Mk/EjvMv 75l06FdU57EOhcb3zBStcIH6WXZScUt6Why/o0b5/W45rgogwVMC/yjrTbqb4GeWBXur aWmQ== X-Gm-Message-State: AOAM533KOcBdMjvkstHIPhPFVoXZG3NjBXRzQYXwx8jCNVfLOCL5IQ+v /H395bZk4wh5HF4BdcJnXfrJezpCxvWs1Qbz X-Received: by 2002:a05:6000:1085:: with SMTP id y5mr3627507wrw.100.1597426098448; Fri, 14 Aug 2020 10:28:18 -0700 (PDT) Date: Fri, 14 Aug 2020 19:27:05 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog Subject: [PATCH 23/35] arm64: mte: Convert gcr_user into an exclude mask From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincenzo Frascino The gcr_user mask is a per thread mask that represents the tags that are excluded from random generation when the Memory Tagging Extension is present and an 'irg' instruction is invoked. gcr_user affects the behavior on EL0 only. Currently that mask is an include mask and it is controlled by the user via prctl() while GCR_EL1 accepts an exclude mask. Convert the include mask into an exclude one to make it easier the register setting. Note: This change will affect gcr_kernel (for EL1) introduced with a future patch. Signed-off-by: Vincenzo Frascino --- arch/arm64/include/asm/processor.h | 2 +- arch/arm64/kernel/mte.c | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index fec204d28fce..ed9efa5be8eb 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -153,7 +153,7 @@ struct thread_struct { #endif #ifdef CONFIG_ARM64_MTE u64 sctlr_tcf0; - u64 gcr_user_incl; + u64 gcr_user_excl; #endif }; diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index e2d708b4583d..7717ea9bc2a7 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -135,23 +135,22 @@ static void set_sctlr_el1_tcf0(u64 tcf0) preempt_enable(); } -static void update_gcr_el1_excl(u64 incl) +static void update_gcr_el1_excl(u64 excl) { - u64 excl = ~incl & SYS_GCR_EL1_EXCL_MASK; /* - * Note that 'incl' is an include mask (controlled by the user via - * prctl()) while GCR_EL1 accepts an exclude mask. + * Note that the mask controlled by the user via prctl() is an + * include while GCR_EL1 accepts an exclude mask. * No need for ISB since this only affects EL0 currently, implicit * with ERET. */ sysreg_clear_set_s(SYS_GCR_EL1, SYS_GCR_EL1_EXCL_MASK, excl); } -static void set_gcr_el1_excl(u64 incl) +static void set_gcr_el1_excl(u64 excl) { - current->thread.gcr_user_incl = incl; - update_gcr_el1_excl(incl); + current->thread.gcr_user_excl = excl; + update_gcr_el1_excl(excl); } void flush_mte_state(void) @@ -166,7 +165,7 @@ void flush_mte_state(void) /* disable tag checking */ set_sctlr_el1_tcf0(SCTLR_EL1_TCF0_NONE); /* reset tag generation mask */ - set_gcr_el1_excl(0); + set_gcr_el1_excl(SYS_GCR_EL1_EXCL_MASK); } void mte_thread_switch(struct task_struct *next) @@ -177,7 +176,7 @@ void mte_thread_switch(struct task_struct *next) /* avoid expensive SCTLR_EL1 accesses if no change */ if (current->thread.sctlr_tcf0 != next->thread.sctlr_tcf0) update_sctlr_el1_tcf0(next->thread.sctlr_tcf0); - update_gcr_el1_excl(next->thread.gcr_user_incl); + update_gcr_el1_excl(next->thread.gcr_user_excl); } void mte_suspend_exit(void) @@ -185,13 +184,14 @@ void mte_suspend_exit(void) if (!system_supports_mte()) return; - update_gcr_el1_excl(current->thread.gcr_user_incl); + update_gcr_el1_excl(current->thread.gcr_user_excl); } long set_mte_ctrl(struct task_struct *task, unsigned long arg) { u64 tcf0; - u64 gcr_incl = (arg & PR_MTE_TAG_MASK) >> PR_MTE_TAG_SHIFT; + u64 gcr_excl = ~((arg & PR_MTE_TAG_MASK) >> PR_MTE_TAG_SHIFT) & + SYS_GCR_EL1_EXCL_MASK; if (!system_supports_mte()) return 0; @@ -212,10 +212,10 @@ long set_mte_ctrl(struct task_struct *task, unsigned long arg) if (task != current) { task->thread.sctlr_tcf0 = tcf0; - task->thread.gcr_user_incl = gcr_incl; + task->thread.gcr_user_excl = gcr_excl; } else { set_sctlr_el1_tcf0(tcf0); - set_gcr_el1_excl(gcr_incl); + set_gcr_el1_excl(gcr_excl); } return 0; @@ -224,11 +224,12 @@ long set_mte_ctrl(struct task_struct *task, unsigned long arg) long get_mte_ctrl(struct task_struct *task) { unsigned long ret; + u64 incl = ~task->thread.gcr_user_excl & SYS_GCR_EL1_EXCL_MASK; if (!system_supports_mte()) return 0; - ret = task->thread.gcr_user_incl << PR_MTE_TAG_SHIFT; + ret = incl << PR_MTE_TAG_SHIFT; switch (task->thread.sctlr_tcf0) { case SCTLR_EL1_TCF0_NONE: -- 2.28.0.220.ged08abb693-goog