All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Frederic Weisbecker <frederic@kernel.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Daniel Bristot de Oliveira <bristot@kernel.org>,
	Prasad Pandit <ppandit@redhat.com>,
	Valentin Schneider <vschneid@redhat.com>,
	Yair Podemsky <ypodemsk@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Marcelo Tosatti <mtosatti@redhat.com>
Subject: [RFC PATCH 1/7] cpu isolation: basic block interference infrastructure
Date: Thu, 08 Sep 2022 16:29:00 -0300	[thread overview]
Message-ID: <20220908195111.661824729@redhat.com> (raw)
In-Reply-To: 20220908192859.546633738@redhat.com

There are a number of codepaths in the kernel that interrupt
code execution in remote CPUs. A subset of such codepaths are
triggered from userspace and can therefore return errors.

Introduce a cpumask named "block interference", writable from userspace.

This cpumask (and associated helpers) can be used by code that executes
code on remote CPUs to optionally return an error.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: linux-2.6/include/linux/sched/isolation.h
===================================================================
--- linux-2.6.orig/include/linux/sched/isolation.h
+++ linux-2.6/include/linux/sched/isolation.h
@@ -58,4 +58,33 @@ static inline bool housekeeping_cpu(int
 	return true;
 }
 
+#ifdef CONFIG_CPU_ISOLATION
+extern cpumask_var_t block_interf_cpumask;
+extern bool block_interf_cpumask_active;
+
+void block_interf_read_lock(void);
+void block_interf_read_unlock(void);
+
+void block_interf_write_lock(void);
+void block_interf_write_unlock(void);
+
+void block_interf_assert_held(void);
+
+#else
+static inline void block_interf_read_lock(void)		{ }
+static inline void block_interf_read_unlock(void)	{ }
+static inline void block_interf_write_lock(void)	{ }
+static inline void block_interf_write_unlock(void)	{ }
+static inline void block_interf_assert_held(void)	{ }
+#endif
+
+static inline bool block_interf_cpu(int cpu)
+{
+#ifdef CONFIG_CPU_ISOLATION
+	if (block_interf_cpumask_active)
+		return cpumask_test_cpu(cpu, block_interf_cpumask);
+#endif
+	return false;
+}
+
 #endif /* _LINUX_SCHED_ISOLATION_H */
Index: linux-2.6/kernel/sched/isolation.c
===================================================================
--- linux-2.6.orig/kernel/sched/isolation.c
+++ linux-2.6/kernel/sched/isolation.c
@@ -239,3 +239,116 @@ static int __init housekeeping_isolcpus_
 	return housekeeping_setup(str, flags);
 }
 __setup("isolcpus=", housekeeping_isolcpus_setup);
+
+DEFINE_STATIC_PERCPU_RWSEM(block_interf_lock);
+
+cpumask_var_t block_interf_cpumask;
+EXPORT_SYMBOL_GPL(block_interf_cpumask);
+
+bool block_interf_cpumask_active;
+EXPORT_SYMBOL_GPL(block_interf_cpumask_active);
+
+void block_interf_read_lock(void)
+{
+	percpu_down_read(&block_interf_lock);
+}
+EXPORT_SYMBOL_GPL(block_interf_read_lock);
+
+void block_interf_read_unlock(void)
+{
+	percpu_up_read(&block_interf_lock);
+}
+EXPORT_SYMBOL_GPL(block_interf_read_unlock);
+
+void block_interf_write_lock(void)
+{
+	percpu_down_write(&block_interf_lock);
+}
+EXPORT_SYMBOL_GPL(block_interf_write_lock);
+
+void block_interf_write_unlock(void)
+{
+	percpu_up_write(&block_interf_lock);
+}
+EXPORT_SYMBOL_GPL(block_interf_write_unlock);
+
+void block_interf_assert_held(void)
+{
+	percpu_rwsem_assert_held(&block_interf_lock);
+}
+EXPORT_SYMBOL_GPL(block_interf_assert_held);
+
+static ssize_t
+block_interf_cpumask_read(struct file *filp, char __user *ubuf,
+		     size_t count, loff_t *ppos)
+{
+	char *mask_str;
+	int len;
+
+	len = snprintf(NULL, 0, "%*pb\n",
+		       cpumask_pr_args(block_interf_cpumask)) + 1;
+	mask_str = kmalloc(len, GFP_KERNEL);
+	if (!mask_str)
+		return -ENOMEM;
+
+	len = snprintf(mask_str, len, "%*pb\n",
+		       cpumask_pr_args(block_interf_cpumask));
+	if (len >= count) {
+		count = -EINVAL;
+		goto out_err;
+	}
+	count = simple_read_from_buffer(ubuf, count, ppos, mask_str, len);
+
+out_err:
+	kfree(mask_str);
+
+	return count;
+}
+
+static ssize_t
+block_interf_cpumask_write(struct file *filp, const char __user *ubuf,
+			   size_t count, loff_t *ppos)
+{
+	cpumask_var_t block_interf_cpumask_new;
+	int err;
+
+	if (!zalloc_cpumask_var(&block_interf_cpumask_new, GFP_KERNEL))
+		return -ENOMEM;
+
+	err = cpumask_parse_user(ubuf, count, block_interf_cpumask_new);
+	if (err)
+		goto err_free;
+
+	block_interf_write_lock();
+	cpumask_copy(block_interf_cpumask, block_interf_cpumask_new);
+	block_interf_write_unlock();
+	free_cpumask_var(block_interf_cpumask_new);
+
+	return count;
+
+err_free:
+	free_cpumask_var(block_interf_cpumask_new);
+
+	return err;
+}
+
+static const struct file_operations block_interf_cpumask_fops = {
+	.read		= block_interf_cpumask_read,
+	.write		= block_interf_cpumask_write,
+};
+
+
+static int __init block_interf_cpumask_init(void)
+{
+	if (!zalloc_cpumask_var(&block_interf_cpumask, GFP_KERNEL))
+		return -ENOMEM;
+
+	debugfs_create_file_unsafe("block_interf_cpumask", 0644, NULL, NULL,
+				   &block_interf_cpumask_fops);
+
+	block_interf_cpumask_active = true;
+	return 0;
+}
+
+late_initcall(block_interf_cpumask_init);
+



  reply	other threads:[~2022-09-08 19:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-08 19:28 [RFC PATCH 0/7] cpu isolation: infra to block interference to select CPUs Marcelo Tosatti
2022-09-08 19:29 ` Marcelo Tosatti [this message]
2022-09-08 19:29 ` [RFC PATCH 2/7] introduce smp_call_func_single_fail Marcelo Tosatti
2022-09-08 19:29 ` [RFC PATCH 3/7] introduce _fail variants of stop_machine functions Marcelo Tosatti
2022-09-08 19:29 ` [RFC PATCH 4/7] clockevent unbind: use smp_call_func_single_fail Marcelo Tosatti
2022-09-08 19:29 ` [RFC PATCH 5/7] timekeeping_notify: use stop_machine_fail when appropriate Marcelo Tosatti
2022-09-08 19:29 ` [RFC PATCH 6/7] perf_event_open: check for block interference CPUs Marcelo Tosatti
2022-09-08 19:29 ` [RFC PATCH 7/7] mtrr_add_page/mtrr_del_page: " Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220908195111.661824729@redhat.com \
    --to=mtosatti@redhat.com \
    --cc=bristot@kernel.org \
    --cc=frederic@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ppandit@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=vschneid@redhat.com \
    --cc=ypodemsk@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.