From patchwork Wed Nov 4 23:18:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883191 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.7 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 1C426C00A89 for ; Thu, 5 Nov 2020 04:41:18 +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 727CF2083B for ; Thu, 5 Nov 2020 04:41:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="yWTq7Mmr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="SzaIUmJF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="q/Ff3ASA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 727CF2083B 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=sTEy38SpJkAIUGOWABHjNkpEmaNu5zi3v3hhbNlG5KU=; b=yWTq7MmrWec6+LrXTrNaBuqwW 8gJEADU0+ZTnZEg6yULhuXxYi0DWw9rzFMn4tId1D66fnBKCaf+9NH7UiTtf7QvnR8U49fQd1JTeo r4MjJ8OAdjG7E9J4Sl3vLV/9lxfpWivSiimPHLyDYmEsG+C6YWeJpSrpg9i0sXgWbPt/fC50PEzu/ 7TDZ9LG0CEL2XG/baZgIxId5vuaTu3pvyBKuMnu6P6ajka2Yie+EpXW58UVCYBigJ37lFq7j6QJQi Yt9lmBwy61d0PARt5dHBWl/ZeHnRNr0TC7L6lAw6JcX9g9v52EvgRgF+A7WxOT9Eqt8oFiX3D+nAL KVy/OYclg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaX4g-0005Ch-TX; Thu, 05 Nov 2020 04:40:38 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW58-000145-NI for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=sU5rZNeX083+m80V53yNOXDsSYa9T2iypaGHB0m7hOE=; b=SzaIUmJFwvwVDlAnRO8rJmSMcH kmRHce8b0FVMQWFfnZAgOYdplS4DYLQpitlwAlSaTRlpdggXkFd8GUMyoiIu6xdcQ/j/i4dTxXF+C LeWa2+ZbZGal+H2B6dtiuag++2AQ3zrtccdqiI01Xv87lDR3KlHPwE3iK5mL9tKuumFOzDStxNH8o FpFvoG/KdM9N9FR9Halha9GSZPr5zFCyamwtYtVUnAvvd9tDZn/3jwN/43B6qoeCzuXZBqlgtE5tv ttJqlTVTkbU88NPk9A4PLcn0XmCJt/LXiusR2eDO93+2Zwxj0zs6Qs9yytXauhM2AIMC8hI+4ArTw +0jyKPkw==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5i-00047Z-OO for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:25 +0000 Received: by mail-wm1-x34a.google.com with SMTP id t201so30326wmt.1 for ; Wed, 04 Nov 2020 15:21:22 -0800 (PST) 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=sU5rZNeX083+m80V53yNOXDsSYa9T2iypaGHB0m7hOE=; b=q/Ff3ASAciRWZb8tsH8KTLoieiRnH7KurmPMylbDP5XZOagsZRqGAr0Yi0qg3eiivZ TvaKD9/du4JTbSGdI5q6L9PY7nLk+Nz3TdUr8quShGDOOfHLLOC3nVbn+LxnT1jfwV1l bMFo+xbGJUmhn2jRI5z9exaPVO/JmTcTiN7bks0x8IasPR4TZOGafb9n4YN6xLEGAplZ Ru9ZscByEvCo7cD00BSlJUmMcAfWjoOY0wr+rsN3SAuHr4TDebcTaHGCo5Uw/lc1xlRM ipr6afQUNVT3FSrBR7sv/HA7Wzq19Hl2Ip0gaPsGYsRrgCoeBXGLs5to0iVS0INuKsC4 HwTg== 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=sU5rZNeX083+m80V53yNOXDsSYa9T2iypaGHB0m7hOE=; b=hfimvxF9UMr946MYPNH+aCt8Y757hcE9klAO4fWm3bIUvOvsREY/YKsAe2xQkDoN8h iP34iaJUvXyajGoCJFXIQzPohDrGe2KyoGOLW/soOpJxUBYHLtYLc/HhxIXlmaMX0dL/ 1v1hhHhuT13QnUP5EkddMTaJtPZ/63J4pb8arEg+usp/+gfvcXlkYmNRKLXafvslbxYh /W3KvifZEUtlAkWUsQyNF4EJ5bOCpBtJMxPBb1KsVxTaJtEENkGJYd6k/L2OnnshEplq JjK7bvVjc4DIf2U7zaAYF77Frla5NiUGBBTKmxGqfaFfztIZt5zona63sW6BmvYiH/Zm az9w== X-Gm-Message-State: AOAM5339CfnVBW1+0SPm5KiUnKqOkawt4yh1GALOhf0cqxrD5G1tUziv WtdzlSBRzQieTk9RQ0D1MYW5hpJbjahUPIP1 X-Google-Smtp-Source: ABdhPJzXaFXqJdDU7XkP+DMecnDkRhOF/rW4w4gZwKN6yZFHfUkvmvl9KpoIQaKf6ID2aoTzsKtlRPzVuGHagwF3 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:2ec6:: with SMTP id u189mr57375wmu.85.1604532021347; Wed, 04 Nov 2020 15:20:21 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:46 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 31/43] arm64: mte: Convert gcr_user into an exclude mask From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232122_961927_64B55092 X-CRM114-Status: GOOD ( 17.07 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 fce8cbecd6bc..e8cfc41a92d4 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -154,7 +154,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 fcfbefcc3174..14b0c19a33e3 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -148,23 +148,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) @@ -179,7 +178,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) @@ -190,7 +189,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) @@ -198,13 +197,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; @@ -225,10 +225,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; @@ -237,11 +237,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: