From patchwork Fri Nov 13 22:15:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11904907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 707F9697 for ; Fri, 13 Nov 2020 22:17:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 27BBD206F9 for ; Fri, 13 Nov 2020 22:17:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="bplSDuCY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27BBD206F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 996DA6B006E; Fri, 13 Nov 2020 17:17:27 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 94BD86B0070; Fri, 13 Nov 2020 17:17:27 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BF806B0071; Fri, 13 Nov 2020 17:17:27 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0100.hostedemail.com [216.40.44.100]) by kanga.kvack.org (Postfix) with ESMTP id 4F4696B006E for ; Fri, 13 Nov 2020 17:17:27 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E07E933CD for ; Fri, 13 Nov 2020 22:17:26 +0000 (UTC) X-FDA: 77480807292.12.month61_1307ce927312 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id C2B6B18014498 for ; Fri, 13 Nov 2020 22:17:26 +0000 (UTC) X-Spam-Summary: 1,0,0,66c6b248937bd0cb,d41d8cd98f00b204,39qwvxwokcmagtjxk4qt1rmuumrk.iusrot03-ssq1giq.uxm@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1544:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3355:3865:3867:3868:3871:3872:3874:4118:4250:4321:4605:5007:6261:6653:6742:7576:7901:7903:9036:9969:10004:11026:11232:11473:11657:11658:11914:12043:12296:12297:12438:12555:12679:12895:13149:13161:13180:13229:13230:13972:14181:14394:14659:14721:21063:21080:21365:21433:21444:21451:21627:21795:21990:30051:30054:30070,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8f7obcshpr7swwdenbpeceof65ocgprbxnrd48dq1wo6epqnn9xiqakbxpgq.xitp3y7a95hr6pbbsgkm3sjj6h94ug7mwznx8rguynqswbytftsjn6pnrw37mj7.n-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF :not bul X-HE-Tag: month61_1307ce927312 X-Filterd-Recvd-Size: 7819 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Nov 2020 22:17:26 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id o81so4010236wma.0 for ; Fri, 13 Nov 2020 14:17:26 -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=towGrnACjVFWXBLIg9UmlGyfIuoY75eHqBtKUJMwnvM=; b=bplSDuCYE1Qi2YtmvVg1QBkoAAmZVSDTneeauTw7BXI6Oaak9pdE5fXDD5SxsN9Id1 ooJ++dVjXUU8U9OhaNV1r7Iz/MfDZApA/cg8TBSoBW7ijl9j8+Lt6K5QxSH323COEUsR zLSYY6z2ebdawDqio7MTVQ/kMN0gEcqSAIVJzRYlRcz0PI8OPQGBxXJPZG2penYZ0QNp 3sqV0iYOXQXmLWJdO2o2bJ4OULZdvuOwJSxNItEoeotf4/7W36NXZcNB3hsyQ2dEiZnt oUPv2tT1UvRj4THDKpteQtCFKkdzuu3Ah4h5AYi8p30blUF/WWqwAJR0Y4GGa7t24k37 vQiA== 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=towGrnACjVFWXBLIg9UmlGyfIuoY75eHqBtKUJMwnvM=; b=UjLuDl0GthQ83EUfkh8EesLWtFVfIU0VJW/ZYJoAMF/RUj8GRL4m5Y2ezljb/UXECy +uGVLAbiwQVHV4kJ4MSycYYoXnk7aCy9D08Hzax7jTrCgHyUxN6hS0UoS0cn3On5gL+R 2aRmJpD5g0kpYrjdxAKXF0rOCvxBJP6CTtSiWewqn6d5DdNdghYjvB0hqKnQa6zSPZcn BJ2m9BKBnfKsq+1EPmJCQKFQS2riSZxp56SUlGmbvz7uLed/e9xDYLHHqTdgEngqw9bl i4mAY7gSXsc1itrfqkowY/um/wWnrJf+ZqJhp4NPKRmkaFiPjt/Vf5W70xAgnnMehcvP PCIg== X-Gm-Message-State: AOAM5335w2heMs15Nv3t6XeZG77CGz8j/CX+yTH/vxmBL2aAIZsUYGeQ N4CiVRbJCBt+dj0ZG41Il+wt+fHMvNfZFDJX X-Google-Smtp-Source: ABdhPJz0iRtQgceUV32L+qbszTTKXgBo7cVkIhZwOpLxU1wSU2JydSo1/pYLpsfpVCFLioy0Z0XuXRb5cfxMIWTW X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:de05:: with SMTP id b5mr5951444wrm.131.1605305845232; Fri, 13 Nov 2020 14:17:25 -0800 (PST) Date: Fri, 13 Nov 2020 23:15:57 +0100 In-Reply-To: Message-Id: <1d853f7f1e9284af23023fb4ce628a26b9b3752e.1605305705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH mm v10 29/42] arm64: mte: Convert gcr_user into an exclude mask From: Andrey Konovalov To: Andrew Morton Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 7899e165f30a..6a7adb986b52 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -156,23 +156,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) @@ -187,7 +186,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) @@ -198,7 +197,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) @@ -206,13 +205,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; @@ -233,10 +233,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; @@ -245,11 +245,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: