Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp676767pxk; Thu, 24 Sep 2020 15:54:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDq8HCxHGgq8oR2ekyD2cK/+16qz+VInZZF3iicHYhMeKkbtZ3yrKStQq94OO/apFI27VB X-Received: by 2002:a50:e807:: with SMTP id e7mr1100166edn.84.1600988095460; Thu, 24 Sep 2020 15:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600988095; cv=none; d=google.com; s=arc-20160816; b=MClIm3VJfEQYpGuMOU+jvk/SPGsTfjzRPYoIod9Ur9eauPNinRm+eg0dulv1j/Mf1b QNWD4szjZYpRSVBH7d6pWd7Yi7/HXmdmnZq1P0ou+QPe71+gNrjU7frBDbjK3j3pmZux BwtiSJKEciSDYRP0S5e5LbfCuUru2ev7ZhDTG/i4Ys/oHLMOzqG3tou0W84RCVnrtnDG 5IaOzMSjVmndZHpkQMBdSJUVq8GaxzrsL4fWVR0ROEgWZh4oPQE4D4wxNkQR4H2F+0kg JFSGsMmuhebeynbP9H9PC3rkxDRGArOhZhIHGSZOOAiVDjm7Q5XMLqZ0lNsAg5dsolbV tIcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=2ZNxfm3ay5zbZVAoyeFT7OvnOs6QmAy2d7QmbFd4VOE=; b=BwWH1k2oyPzl5oDJhE1WTFan5cBXxD763cXbRahUxWjRRpNsc2akmQzrrUUScFNWYG U1vGYr8jlZBe7bfcO0emo1Bqr9Nx5w6J0nEts3h/7lcXLiHg82MizJ5VE6wXSdNBbmGE MJIu6dE31j2X0/zEnZuW0SSiX/fCaZgFqqnPrRdYH7OxCLMa9BzocoHDqJYULJGMNL7t L399Q4yeojDYUg8K+XNUVu3IOIvjLHvJ6mHL14wkGOKQhkLZ8dfZ1m7veYZqNZsYJHZo CnbfgoodqywrQlBsFjmvKbceJeYh6cT8CnXIic1i0b12j6EZ9QgUlKhSs8Vwtc6VEUVh I4Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Z8L7kQ44; 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 oq9si608614ejb.185.2020.09.24.15.54.32; Thu, 24 Sep 2020 15:54:55 -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=Z8L7kQ44; 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 S1727017AbgIXWwG (ORCPT + 99 others); Thu, 24 Sep 2020 18:52:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbgIXWwB (ORCPT ); Thu, 24 Sep 2020 18:52:01 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5D32C0613D5 for ; Thu, 24 Sep 2020 15:52:00 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id w8so465185qvt.18 for ; Thu, 24 Sep 2020 15:52:00 -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=2ZNxfm3ay5zbZVAoyeFT7OvnOs6QmAy2d7QmbFd4VOE=; b=Z8L7kQ44nyuIvfERbISlBdEpDhN/XfbDsHV4a99zPo0Vg4dEDCsvfVmuNfbQFFgxFk ZkK00zQGFAjll4+o2JgaQH1MgmuBEix0rl9THPhzRRa8d7oHk9R3XyE6xPF8EKMvXCB4 9hD6/l7orxic8F4AU/N2fFj9nxLd7nSfJmlQN9znl4ZYzMdhAOQNRmBjtlfQiJ0U/rGn 74dSPWgO70nBIvOH3EYX+NHTfsKLhXMOVM7Pwblgo8JmoJKKH4i9JnmxYmRifJmOmyox nqhx0TswaCyrRYW5QC1x8sfnS6UNgWe8I3H0+CerxXrmTWUuwby6w1La6v8Knov0pkDe 8tyQ== 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=2ZNxfm3ay5zbZVAoyeFT7OvnOs6QmAy2d7QmbFd4VOE=; b=HrTWuuRzQcu2yQboC4GCC7jrv0o8CoCsNP9j+rmsw20ku2CeO/crCRnV6hRUtaDMyc 5sjxv/NImnYBW7oUuRmGZoy8u59RP96/Q3/GAksqYWxfR0DuQ/CA3kBKlBweq4gepYei FnJDw0UAp8CxXbu7r85ZM1915yhYzbn9UvN9gjlQ7cqNojArZY7DM6eEXmzrLyh0kjbN 3vqt7ce/VJnKAUAVcTzi4nt9WzSqy0D1Padz+PFRxXkWAIF6aOtWUtLuh3Q8rQUvs3Ri Z96hzoSdlfsBEGKSL9J7ucpXb3zFVf7n8oQVr2E5VYYigmmUfwXYaJjC/+rMac78JjsQ scsA== X-Gm-Message-State: AOAM5307HklKb6I5/8vtlBs+lB9eJGIAX1s5d08w8zd6raURZG3LDy4i P8KQLjOGoJMERNWtwiaRqxebO9H5bacl+vLa Sender: "andreyknvl via sendgmr" X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:58aa:: with SMTP id ea10mr1648526qvb.58.1600987920066; Thu, 24 Sep 2020 15:52:00 -0700 (PDT) Date: Fri, 25 Sep 2020 00:50:35 +0200 In-Reply-To: Message-Id: <27e272bfd203cc0ff32181f07db588363ef3776b.1600987622.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog Subject: [PATCH v3 28/39] 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, Andrey Konovalov Content-Type: text/plain; charset="UTF-8" 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 Signed-off-by: Andrey Konovalov Reviewed-by: Catalin Marinas --- Change-Id: Id15c0b47582fb51594bb26fb8353d78c7d0953c1 --- 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 833b63fdd5e2..393d0c794be4 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -136,23 +136,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) @@ -167,7 +166,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) @@ -178,7 +177,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) @@ -186,13 +185,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; @@ -213,10 +213,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; @@ -225,11 +225,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.681.g6f77f65b4e-goog