From patchwork Tue Jul 13 23:48:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12375409 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, 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 504AEC07E95 for ; Tue, 13 Jul 2021 23:50:43 +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 1D7AF6100C for ; Tue, 13 Jul 2021 23:50:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D7AF6100C 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=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=WkLbNVdXl+I9OF0a5OmGI98rHy4Kedxneq64UrJXAmo=; b=l97e1SXE8MIH8WHtUkqCxqCnDm vGnSTWb+PEC4gOQxL5QYcYHZVx9Vc9MyLBZ15p1Jhkk0kyge9lmy95q5aZeAto+pB1BbSIysVvGV/ 8a3m54F22tBNwNufmkirveuu8suOjmP3q0c76PpBqSmX/puinXfj7+Fs/WOTV10uPL6LqgnbWQoyy wB930bjlEOBqtpRxMeD+ojp9x++osDRolD9iDPOywtPjdqT1yn3Nwlso+bvYJ/ULnD74RVA1SK7cp tiqxoUA2tCBtEhVIIlDwBASkU7gELdqIShTEqNXtPN4CopQ4X60XEGOF6eOxr8i8bLbQSHobeHj4C vqIKcaxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3S96-00BgoD-O4; Tue, 13 Jul 2021 23:49:01 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3S8O-00Bgfb-Ht for linux-arm-kernel@lists.infradead.org; Tue, 13 Jul 2021 23:48:18 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id t15-20020a056214036fb02902dc72b5283dso221322qvu.23 for ; Tue, 13 Jul 2021 16:48: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=0I/fw/N5vkRou4jOquJnkoOvJZrGZlJhMkd9V4c9gW8=; b=U/YW1wOjj6cTKNDZQk4o0IMEjot2yut30LzM61JjqOuEVePBOnuVprKz88BO49YhuE LL2bmDNSp111qCvMsWiWjymjH7YzCyiWAsnYOqzvXXdDsgoNN3E6sCWK7ABkv0wX/mb9 2u982Hii0nYssLo3nwFrpw7kiCBeGUCoFZ4UhWbt8Bt5d8c8Q/MlYRKsoTqNluSSDeKl W2HQ8iB0z7LP+qHbQB6e1emOLmmJMidf2Uy+9oQGS7eUKmWbUzINX/VJyM71Mei9hkjo ao+YvHJImGWplCXNteWOn6t2ygoL1h+jwCGjw4kSiuBFQV/kunPnk5ENcu3CSKCyFlMj ldZA== 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=0I/fw/N5vkRou4jOquJnkoOvJZrGZlJhMkd9V4c9gW8=; b=tKsQC6B9jlNYRTtLu3nfr+AORfMhsY5xk/2us1hLqKqHQGl9NJCBSI8d1T5v8i2IxI lpGBzpvoSc0kIFm77O6fjDTAhW/+D4+4RfV5d9XYMjCEVwLJXvELEoge2jpqYTFPYXQh ujTR7nMX4/3pzB+ZKVDxfh60wE2t8KNvWl68k9NunkAG5P8IHqjLW8sX6iescjV5RDbU dAeBH3Ow4ZqQdyoVvAlfXf0uDIEap2oFthU0dO609BO8yJ7ezSUvVVc02ThS3tF2n0dG MMxvEq3S5EolYMJgH1q0T/PC1F6T+begID7+9IzszOr9N8AeLjlT+YHIBsj8iefWflzi fgIw== X-Gm-Message-State: AOAM5310YbO2NNEN+8xEnLRdVeog6HFAqvHnwfmiQzb5mTqrqOiIgBGm oOcP1kZpLgqnmScDku7+Pb8ZoHQ= X-Google-Smtp-Source: ABdhPJyQo4s+Fanu8SP0gzCwsHt+ldWMPq7w08L+R2/xlGJnu2kviDTJl4R1eQn8CdrNd1Yr51BaG9k= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:99b9:48f7:dbe6:8670]) (user=pcc job=sendgmr) by 2002:a05:6214:e6e:: with SMTP id jz14mr7557531qvb.55.1626220094704; Tue, 13 Jul 2021 16:48:14 -0700 (PDT) Date: Tue, 13 Jul 2021 16:48:00 -0700 In-Reply-To: <20210713234801.3858018-1-pcc@google.com> Message-Id: <20210713234801.3858018-5-pcc@google.com> Mime-Version: 1.0 References: <20210713234801.3858018-1-pcc@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v10 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-20210713_164816_634056_1867A045 X-CRM114-Status: GOOD ( 16.34 ) 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 Acked-by: Will Deacon --- 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 432d9b641e9c..50ae1a7435ae 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); @@ -199,11 +202,18 @@ static void update_gcr_el1_excl(u64 excl) 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; @@ -441,3 +451,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);