From patchwork Tue Jul 27 20:52:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12403609 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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 88530C4338F for ; Tue, 27 Jul 2021 20:56:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 503AC60F5E for ; Tue, 27 Jul 2021 20:56:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 503AC60F5E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc: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=qRBNXD9EP8jHYmFIVQ2aHgbWeNN8zaHWz3Skc+HV9V0=; b=XzKoHsWvMYQmHb3LetmaQcLksE d2PY9Ea9E8Zvqwc6u0b59OrBePUwXGBKgBdhLZCRJxYRdd/91SS9Ro+Kb5evGTUFnO2NODMwKEI4t Dy4Q4WcwiHMvJN/YaYqjMegdE+g1bCWLdDy1V/540ygLr1Hfguj494nG8hrLU0T6CM9v0PIFDuN0K XJK4CURKhYogb0JW7h+ncx6WKpYV5aspDuuOc0bR9rLCrU0/T98hl5R0sBAyLSVhgqXwnmVlpVI4q l8pGgZfOit9xHtuPYJE6GSutuIZQc+r2tLt3loPkamlVq+4112kSqvBd0RxLeqSwquItA4sYUGNK7 +DO0pmow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8U5Y-00GHdn-Fo; Tue, 27 Jul 2021 20:54:08 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8U4i-00GHP1-3Z for linux-arm-kernel@lists.infradead.org; Tue, 27 Jul 2021 20:53:17 +0000 Received: by mail-qv1-xf49.google.com with SMTP id b6-20020a0cbf460000b02902dbb4e0a8f2so471760qvj.6 for ; Tue, 27 Jul 2021 13:53:15 -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=566AaQu3N8mRJNv52SrYwj6schntyDwnGY9YvqGFQzA=; b=M/gbFRQHbMINPLpi6SnM8hBI5JlqLq16u+EhMhT0DtG60pJCm4Nv63aar8kObCZKRB bPV8La0TJoHe9lAYnmUwsr3w7kpNxHUooBIddqUQiCBRx3dXjAJ8GR0q44c3bkkJMuLp dJTfdLFw1RqVtIpq2LZzn/0ojjds0xGsCY4887U08UYqR8Ae/oD4D5nXRxA2ky6XUCnw ZlAnG15Qu98UgqXbYSv9feT19FDcBMBwTb0B79g9ApavoXR5fzoGDi4dO+cQLtpjT6js bSux9mxXBfx5MC8He2JH6nbnUhWODuWW30Ip7LCP1jkU8iNhKILPfjb9DJ0n1y8roX3g o8bA== 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=566AaQu3N8mRJNv52SrYwj6schntyDwnGY9YvqGFQzA=; b=Q1BXgr5HtSdk+AzGn3Nudl8dX5fmMF+0R7yP8PwxgyoJrw/7IJ77v47P5fkL/UBoI6 EGGQVqc/jpHU+wRdulYCgWeU42+ofsOB1SinMhvxHq1oYR3NUGSDeJSuqRIa81vsWbLJ e/SpLQ59luJjByiGl/hALRRALmUpbZMxV8wext+vjvrL9TQnBF3URhmakIbTbqSPMHCz 4v55FhBXv+nIFgSVPvBL25Ug2m5UC+4m4wORjHnYVJ/OzyiJnkcA4pF9rhmGfW4uI29Q HuSAP+uH9e+Xl5DhkylhmFbrOzXiR71B/uKt2TxEuLPcyB+CwNlUpyKeBOxv5lkYR9/G tCzA== X-Gm-Message-State: AOAM5321vbj1OTZPqSM6MTXqJ3yWCVOD/XlHvSC7VcoQBYqNEGSrxleY 3uMqs879jNryPQPFHe3EVuT//6s= X-Google-Smtp-Source: ABdhPJxwc3E/g+pb2PdxFhFyh/9Jwx1bbvTksAScFS0jXW2WLeyljjvZ1xx2OYUE+uS2tlfd1igxQ54= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:538:aa52:9b59:413b]) (user=pcc job=sendgmr) by 2002:a05:6214:262f:: with SMTP id gv15mr24566037qvb.36.1627419194117; Tue, 27 Jul 2021 13:53:14 -0700 (PDT) Date: Tue, 27 Jul 2021 13:52:58 -0700 In-Reply-To: <20210727205300.2554659-1-pcc@google.com> Message-Id: <20210727205300.2554659-5-pcc@google.com> Mime-Version: 1.0 References: <20210727205300.2554659-1-pcc@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v11 4/5] arm64: mte: introduce a per-CPU tag checking mode preference From: Peter Collingbourne To: Catalin Marinas , Vincenzo Frascino , Will Deacon Cc: Peter Collingbourne , Evgenii Stepanov , Szabolcs Nagy , Tejas Belagod , linux-arm-kernel@lists.infradead.org, Greg Kroah-Hartman X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210727_135316_192894_9A18D73F X-CRM114-Status: GOOD ( 16.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a per-CPU sysfs node, mte_tcf_preferred, that allows the preferred tag checking mode to be configured. The current possible values are async and sync. Link: https://linux-review.googlesource.com/id/I7493dcd533a2785a1437b16c3f6b50919f840854 Signed-off-by: Peter Collingbourne Reviewed-by: Catalin Marinas --- v10: - stop calling smp_call_function_single arch/arm64/kernel/mte.c | 65 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 737503a148bb..20a40e5a14fa 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -26,6 +27,8 @@ u64 gcr_kernel_excl __ro_after_init; static bool report_fault_once = true; +static DEFINE_PER_CPU_READ_MOSTLY(u64, mte_tcf_preferred); + #ifdef CONFIG_KASAN_HW_TAGS /* Whether the MTE asynchronous mode is enabled. */ DEFINE_STATIC_KEY_FALSE(mte_async_mode); @@ -195,11 +198,18 @@ void mte_check_tfsr_el1(void) static void mte_update_sctlr_user(struct task_struct *task) { + /* + * This must be called with preemption disabled and can only be called + * on the current or next task since the CPU must match where the thread + * is going to run. The caller is responsible for calling + * update_sctlr_el1() later in the same preemption disabled block. + */ unsigned long sctlr = task->thread.sctlr_user; - unsigned long pref = MTE_CTRL_TCF_ASYNC; unsigned long mte_ctrl = task->thread.mte_ctrl; - unsigned long resolved_mte_tcf = (mte_ctrl & pref) ? pref : mte_ctrl; + unsigned long pref, resolved_mte_tcf; + pref = __this_cpu_read(mte_tcf_preferred); + resolved_mte_tcf = (mte_ctrl & pref) ? pref : mte_ctrl; sctlr &= ~SCTLR_EL1_TCF0_MASK; if (resolved_mte_tcf & MTE_CTRL_TCF_ASYNC) sctlr |= SCTLR_EL1_TCF0_ASYNC; @@ -438,3 +448,54 @@ int mte_ptrace_copy_tags(struct task_struct *child, long request, return ret; } + +static ssize_t mte_tcf_preferred_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + switch (per_cpu(mte_tcf_preferred, dev->id)) { + case MTE_CTRL_TCF_ASYNC: + return sysfs_emit(buf, "async\n"); + case MTE_CTRL_TCF_SYNC: + return sysfs_emit(buf, "sync\n"); + default: + return sysfs_emit(buf, "???\n"); + } +} + +static ssize_t mte_tcf_preferred_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u64 tcf; + + if (sysfs_streq(buf, "async")) + tcf = MTE_CTRL_TCF_ASYNC; + else if (sysfs_streq(buf, "sync")) + tcf = MTE_CTRL_TCF_SYNC; + else + return -EINVAL; + + device_lock(dev); + per_cpu(mte_tcf_preferred, dev->id) = tcf; + device_unlock(dev); + + return count; +} +static DEVICE_ATTR_RW(mte_tcf_preferred); + +static int register_mte_tcf_preferred_sysctl(void) +{ + unsigned int cpu; + + if (!system_supports_mte()) + return 0; + + for_each_possible_cpu(cpu) { + per_cpu(mte_tcf_preferred, cpu) = MTE_CTRL_TCF_ASYNC; + device_create_file(get_cpu_device(cpu), + &dev_attr_mte_tcf_preferred); + } + + return 0; +} +subsys_initcall(register_mte_tcf_preferred_sysctl);