From nobody Mon Apr 6 08:13:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D30DFC38145 for ; Thu, 8 Sep 2022 19:57:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229437AbiIHT5i (ORCPT ); Thu, 8 Sep 2022 15:57:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229657AbiIHT5X (ORCPT ); Thu, 8 Sep 2022 15:57:23 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C92BFDBA5 for ; Thu, 8 Sep 2022 12:57:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662667040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=POf439emxhXrOrr156ZeESPCz55AZP+6XMtLj7BfFZI=; b=CJDmlm4XAOlVEDeFNHeRJOYtJYCW7zUPNV6lylZ9hpTz+VBDppZa/MAKSrDBRnTX5JRA2p 74dvQ+McvgrwEiQmCHHQl95QkcmeAYi04qA/SvFKmdCVKd/Yp5xV8i8s0BnRbvfpyG0PJo Zj/eEXWCyYweUN6CJE3/i/z0TETyQx8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-556-BuWPzhxhMsCXfUGpofza8Q-1; Thu, 08 Sep 2022 15:57:17 -0400 X-MC-Unique: BuWPzhxhMsCXfUGpofza8Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A67D985A589; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: from fuller.cnet (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47908945D2; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 215FF415CD54; Thu, 8 Sep 2022 16:54:07 -0300 (-03) Message-ID: <20220908195111.661824729@redhat.com> User-Agent: quilt/0.66 Date: Thu, 08 Sep 2022 16:29:00 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Frederic Weisbecker , Juri Lelli , Daniel Bristot de Oliveira , Prasad Pandit , Valentin Schneider , Yair Podemsky , Thomas Gleixner , Marcelo Tosatti Subject: [RFC PATCH 1/7] cpu isolation: basic block interference infrastructure References: <20220908192859.546633738@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Index: linux-2.6/include/linux/sched/isolation.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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; } =20 +#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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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=3D", 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 =3D snprintf(NULL, 0, "%*pb\n", + cpumask_pr_args(block_interf_cpumask)) + 1; + mask_str =3D kmalloc(len, GFP_KERNEL); + if (!mask_str) + return -ENOMEM; + + len =3D snprintf(mask_str, len, "%*pb\n", + cpumask_pr_args(block_interf_cpumask)); + if (len >=3D count) { + count =3D -EINVAL; + goto out_err; + } + count =3D 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 =3D 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 =3D { + .read =3D block_interf_cpumask_read, + .write =3D 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 =3D true; + return 0; +} + +late_initcall(block_interf_cpumask_init); + From nobody Mon Apr 6 08:13:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62774C38145 for ; Thu, 8 Sep 2022 19:57:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229715AbiIHT52 (ORCPT ); Thu, 8 Sep 2022 15:57:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbiIHT5V (ORCPT ); Thu, 8 Sep 2022 15:57:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3986EC746 for ; Thu, 8 Sep 2022 12:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662667039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=N67gQ2stRWxvjqfXz9K3AlWY+C92r6fHBrkzUs9pLqs=; b=Co6dkypuTdSVukUFYt2C3Q28Onke/zFEl/M3GX9W2MDj3WmmRVS3L0kRnBfC0fmIC32W+A SgSB8HdPKK+KLBwy/yFvYJGXtYltMlUN6en+pFTzmUjp7k2Ln8AocHOr12WJgshEAODDpU adRYPGPZeFCpYaL87xbBi+pXdTMrpAo= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-554-sRHX6peHPD2Jw5Q--Fz5Ug-1; Thu, 08 Sep 2022 15:57:16 -0400 X-MC-Unique: sRHX6peHPD2Jw5Q--Fz5Ug-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5D3973C0CD54; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: from fuller.cnet (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E0F2909FF; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 230D9415CD60; Thu, 8 Sep 2022 16:54:07 -0300 (-03) Message-ID: <20220908195111.710559374@redhat.com> User-Agent: quilt/0.66 Date: Thu, 08 Sep 2022 16:29:01 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Frederic Weisbecker , Juri Lelli , Daniel Bristot de Oliveira , Prasad Pandit , Valentin Schneider , Yair Podemsky , Thomas Gleixner , Marcelo Tosatti Subject: [RFC PATCH 2/7] introduce smp_call_func_single_fail References: <20220908192859.546633738@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce smp_call_func_single_fail, which checks if the target CPU is tagged as a "block interference" CPU, and returns an error if so. Signed-off-by: Marcelo Tosatti Index: linux-2.6/include/linux/smp.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/include/linux/smp.h +++ linux-2.6/include/linux/smp.h @@ -50,6 +50,9 @@ extern unsigned int total_cpus; int smp_call_function_single(int cpuid, smp_call_func_t func, void *info, int wait); =20 +int smp_call_func_single_fail(int cpuid, smp_call_func_t func, void *info, + int wait); + void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func, void *info, bool wait, const struct cpumask *mask); =20 Index: linux-2.6/kernel/smp.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/kernel/smp.c +++ linux-2.6/kernel/smp.c @@ -25,6 +25,7 @@ #include #include #include +#include =20 #include "smpboot.h" #include "sched/smp.h" @@ -782,6 +783,30 @@ int smp_call_function_single(int cpu, sm } EXPORT_SYMBOL(smp_call_function_single); =20 +/* + * smp_call_func_single_fail - Run a function on a specific CPU, + * failing if any target CPU is marked as "no ipi". + * @func: The function to run. This must be fast and non-blocking. + * @info: An arbitrary pointer to pass to the function. + * @wait: If true, wait until function has completed on other CPUs. + * + * Returns 0 on success, else a negative status code. + */ +int smp_call_func_single_fail(int cpu, smp_call_func_t func, void *info, + int wait) +{ + int err; + + block_interf_assert_held(); + if (block_interf_cpu(cpu)) + return -EPERM; + + err =3D smp_call_function_single(cpu, func, info, wait); + + return err; +} +EXPORT_SYMBOL(smp_call_func_single_fail); + /** * smp_call_function_single_async() - Run an asynchronous function on a * specific CPU. From nobody Mon Apr 6 08:13:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2224C38145 for ; Thu, 8 Sep 2022 19:57:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229590AbiIHT5V (ORCPT ); Thu, 8 Sep 2022 15:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbiIHT5T (ORCPT ); Thu, 8 Sep 2022 15:57:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AED03A50D4 for ; Thu, 8 Sep 2022 12:57:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662667037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=BV5ynmETQj//VSEXh0fAfYZTasPgvMiaUOPYWaeZfe8=; b=IxIYD+a6OeNXzu5ZKuXRHPgSH238iRqTxUpp9fZtmNkGpyOmhm7bNoKAVkCw21P54Z/ayN jOT1SuCCC2Cnbp8kyGj/CYGiPZfzfYn/S0ZlepWrKguCF1aXvZG4rtJBp7czi4AX0E3+aR 6835wstLEyn2LyPv59il7/hPv5UnrW0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-554-vW0eyKDYPEa9FwmV1xQMqQ-1; Thu, 08 Sep 2022 15:57:16 -0400 X-MC-Unique: vW0eyKDYPEa9FwmV1xQMqQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 76DD785A596; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: from fuller.cnet (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 44C7D2026D4C; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 24234415CD7D; Thu, 8 Sep 2022 16:54:07 -0300 (-03) Message-ID: <20220908195111.760134219@redhat.com> User-Agent: quilt/0.66 Date: Thu, 08 Sep 2022 16:29:02 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Frederic Weisbecker , Juri Lelli , Daniel Bristot de Oliveira , Prasad Pandit , Valentin Schneider , Yair Podemsky , Thomas Gleixner , Marcelo Tosatti Subject: [RFC PATCH 3/7] introduce _fail variants of stop_machine functions References: <20220908192859.546633738@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce stop_machine_fail and stop_machine_cpuslocked_fail, which check if any online CPU in the system is tagged as=20 a block interference CPU.=20 If so, returns an error. Signed-off-by: Marcelo Tosatti Index: linux-2.6/include/linux/stop_machine.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/include/linux/stop_machine.h +++ linux-2.6/include/linux/stop_machine.h @@ -113,6 +113,9 @@ static inline void print_stop_info(const */ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus); =20 + +int stop_machine_fail(cpu_stop_fn_t fn, void *data, const struct cpumask *= cpus); + /** * stop_machine_cpuslocked: freeze the machine on all CPUs and run this fu= nction * @fn: the function to run @@ -124,6 +127,9 @@ int stop_machine(cpu_stop_fn_t fn, void */ int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, const struct cpu= mask *cpus); =20 + +int stop_machine_cpuslocked_fail(cpu_stop_fn_t fn, void *data, const struc= t cpumask *cpus); + /** * stop_core_cpuslocked: - stop all threads on just one core * @cpu: any cpu in the targeted core Index: linux-2.6/kernel/stop_machine.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/kernel/stop_machine.c +++ linux-2.6/kernel/stop_machine.c @@ -22,6 +22,7 @@ #include #include #include +#include =20 /* * Structure to determine completion condition and record errors. May @@ -619,6 +620,17 @@ int stop_machine_cpuslocked(cpu_stop_fn_ return stop_cpus(cpu_online_mask, multi_cpu_stop, &msdata); } =20 +int stop_machine_cpuslocked_fail(cpu_stop_fn_t fn, void *data, + const struct cpumask *cpus) +{ + block_interf_assert_held(); + + if (cpumask_intersects(block_interf_cpumask, cpu_online_mask)) + return -EPERM; + + return stop_machine_cpuslocked(fn, data, cpus); +} + int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus) { int ret; @@ -631,6 +643,19 @@ int stop_machine(cpu_stop_fn_t fn, void } EXPORT_SYMBOL_GPL(stop_machine); =20 +int stop_machine_fail(cpu_stop_fn_t fn, void *data, const struct cpumask *= cpus) +{ + int ret; + + /* No CPUs can come up or down during this. */ + cpus_read_lock(); + ret =3D stop_machine_cpuslocked_fail(fn, data, cpus); + cpus_read_unlock(); + return ret; +} +EXPORT_SYMBOL_GPL(stop_machine_fail); + + #ifdef CONFIG_SCHED_SMT int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data) { From nobody Mon Apr 6 08:13:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE8D8C38145 for ; Thu, 8 Sep 2022 19:57:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbiIHT50 (ORCPT ); Thu, 8 Sep 2022 15:57:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229647AbiIHT5V (ORCPT ); Thu, 8 Sep 2022 15:57:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81CACA50D4 for ; Thu, 8 Sep 2022 12:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662667039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=omuRsfdH4SASi5AXCw7JGKydIaf3lsqyRLYETVJdhrw=; b=Pp4Dugk6jLOzeoauI8kv3tyjeJOeUUTAuCuGWqwKPeuxGKAe5g12Pd4o2BmQ1APk+ahimi n0DNTuJV3cdX8AafJKtocV55gWKuruaydaQtlLZeMv4i5tPQ2iAcMqVMeItfYq26hnDGSy 2lTkujP0075cPwOiIKFdW+S5MH4A92s= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-554-L6ZgRyXdPK-C3UIZmB_0JA-1; Thu, 08 Sep 2022 15:57:16 -0400 X-MC-Unique: L6ZgRyXdPK-C3UIZmB_0JA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A2B680231E; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: from fuller.cnet (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 287F21121315; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 253E1415BE29; Thu, 8 Sep 2022 16:54:07 -0300 (-03) Message-ID: <20220908195111.813208840@redhat.com> User-Agent: quilt/0.66 Date: Thu, 08 Sep 2022 16:29:03 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Frederic Weisbecker , Juri Lelli , Daniel Bristot de Oliveira , Prasad Pandit , Valentin Schneider , Yair Podemsky , Thomas Gleixner , Marcelo Tosatti Subject: [RFC PATCH 4/7] clockevent unbind: use smp_call_func_single_fail References: <20220908192859.546633738@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert clockevents_unbind from smp_call_function_single to smp_call_func_single_fail, which will fail in case the target CPU is tagged as block interference CPU. Signed-off-by: Marcelo Tosatti Index: linux-2.6/kernel/time/clockevents.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/kernel/time/clockevents.c +++ linux-2.6/kernel/time/clockevents.c @@ -13,6 +13,7 @@ #include #include #include +#include =20 #include "tick-internal.h" =20 @@ -416,9 +417,14 @@ static void __clockevents_unbind(void *a */ static int clockevents_unbind(struct clock_event_device *ced, int cpu) { + int ret; struct ce_unbind cu =3D { .ce =3D ced, .res =3D -ENODEV }; =20 - smp_call_function_single(cpu, __clockevents_unbind, &cu, 1); + block_interf_read_lock(); + ret =3D smp_call_func_single_fail(cpu, __clockevents_unbind, &cu, 1); + block_interf_read_unlock(); + if (ret) + return ret; return cu.res; } From nobody Mon Apr 6 08:13:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF992C38145 for ; Thu, 8 Sep 2022 19:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229674AbiIHT5l (ORCPT ); Thu, 8 Sep 2022 15:57:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiIHT5Y (ORCPT ); Thu, 8 Sep 2022 15:57:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 174C5FDBB5 for ; Thu, 8 Sep 2022 12:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662667043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=QC2tmXzT7QIRjzdKgE4/pERRUFQxFSVesMKVk8CU1SU=; b=VaPEZ+XotEWJtrJF7PPmW+naR71NCxha82FFLaw+BspULhkzYuiV+7eEtSgKPT7IYxBeGr tYFl6QdomCugEf7djDjJ0gefFb9ekrlDBk/Ss/crGXy8YrjKf9mEDIBOLTyJ1h/s7Vbshf VBpdShiT+L4X9P4zg5MaRkqMf6u8MUw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-tmdfuIpbMDqxT-iOHC72Rg-1; Thu, 08 Sep 2022 15:57:19 -0400 X-MC-Unique: tmdfuIpbMDqxT-iOHC72Rg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2094101AA46; Thu, 8 Sep 2022 19:57:18 +0000 (UTC) Received: from fuller.cnet (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E74D2026D64; Thu, 8 Sep 2022 19:57:18 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 26424415BE32; Thu, 8 Sep 2022 16:54:07 -0300 (-03) Message-ID: <20220908195111.863334407@redhat.com> User-Agent: quilt/0.66 Date: Thu, 08 Sep 2022 16:29:04 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Frederic Weisbecker , Juri Lelli , Daniel Bristot de Oliveira , Prasad Pandit , Valentin Schneider , Yair Podemsky , Thomas Gleixner , Marcelo Tosatti Subject: [RFC PATCH 5/7] timekeeping_notify: use stop_machine_fail when appropriate References: <20220908192859.546633738@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change timekeeping_notify to use stop_machine_fail when appropriate, which will fail in case the target CPU is tagged as block interference CPU. Signed-off-by: Marcelo Tosatti Index: linux-2.6/include/linux/clocksource.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/include/linux/clocksource.h +++ linux-2.6/include/linux/clocksource.h @@ -267,7 +267,7 @@ extern void clocksource_arch_init(struct static inline void clocksource_arch_init(struct clocksource *cs) { } #endif =20 -extern int timekeeping_notify(struct clocksource *clock); +extern int timekeeping_notify(struct clocksource *clock, bool fail); =20 extern u64 clocksource_mmio_readl_up(struct clocksource *); extern u64 clocksource_mmio_readl_down(struct clocksource *); Index: linux-2.6/kernel/time/clocksource.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/kernel/time/clocksource.c +++ linux-2.6/kernel/time/clocksource.c @@ -117,7 +117,7 @@ static u64 suspend_start; =20 #ifdef CONFIG_CLOCKSOURCE_WATCHDOG static void clocksource_watchdog_work(struct work_struct *work); -static void clocksource_select(void); +static int clocksource_select(bool fail); =20 static LIST_HEAD(watchdog_list); static struct clocksource *watchdog; @@ -649,7 +649,7 @@ static int clocksource_watchdog_kthread( { mutex_lock(&clocksource_mutex); if (__clocksource_watchdog_kthread()) - clocksource_select(); + clocksource_select(false); mutex_unlock(&clocksource_mutex); return 0; } @@ -946,7 +946,7 @@ static struct clocksource *clocksource_f return NULL; } =20 -static void __clocksource_select(bool skipcur) +static int __clocksource_select(bool skipcur, bool fail) { bool oneshot =3D tick_oneshot_mode_active(); struct clocksource *best, *cs; @@ -954,7 +954,7 @@ static void __clocksource_select(bool sk /* Find the best suitable clocksource */ best =3D clocksource_find_best(oneshot, skipcur); if (!best) - return; + return 0; =20 if (!strlen(override_name)) goto found; @@ -991,10 +991,16 @@ static void __clocksource_select(bool sk } =20 found: - if (curr_clocksource !=3D best && !timekeeping_notify(best)) { + if (curr_clocksource !=3D best) { + int ret; + + ret =3D timekeeping_notify(best, fail); + if (ret) + return ret; pr_info("Switched to clocksource %s\n", best->name); curr_clocksource =3D best; } + return 0; } =20 /** @@ -1005,14 +1011,14 @@ found: * Select the clocksource with the best rating, or the clocksource, * which is selected by userspace override. */ -static void clocksource_select(void) +static int clocksource_select(bool fail) { - __clocksource_select(false); + return __clocksource_select(false, fail); } =20 -static void clocksource_select_fallback(void) +static int clocksource_select_fallback(void) { - __clocksource_select(true); + return __clocksource_select(true, true); } =20 /* @@ -1031,7 +1037,7 @@ static int __init clocksource_done_booti * Run the watchdog first to eliminate unstable clock sources */ __clocksource_watchdog_kthread(); - clocksource_select(); + clocksource_select(false); mutex_unlock(&clocksource_mutex); return 0; } @@ -1179,7 +1185,7 @@ int __clocksource_register_scale(struct clocksource_enqueue_watchdog(cs); clocksource_watchdog_unlock(&flags); =20 - clocksource_select(); + clocksource_select(false); clocksource_select_watchdog(false); __clocksource_suspend_select(cs); mutex_unlock(&clocksource_mutex); @@ -1208,7 +1214,7 @@ void clocksource_change_rating(struct cl __clocksource_change_rating(cs, rating); clocksource_watchdog_unlock(&flags); =20 - clocksource_select(); + clocksource_select(false); clocksource_select_watchdog(false); clocksource_suspend_select(false); mutex_unlock(&clocksource_mutex); @@ -1230,8 +1236,12 @@ static int clocksource_unbind(struct clo } =20 if (cs =3D=3D curr_clocksource) { + int ret; + /* Select and try to install a replacement clock source */ - clocksource_select_fallback(); + ret =3D clocksource_select_fallback(); + if (ret) + return ret; if (curr_clocksource =3D=3D cs) return -EBUSY; } @@ -1322,17 +1332,17 @@ static ssize_t current_clocksource_store struct device_attribute *attr, const char *buf, size_t count) { - ssize_t ret; + ssize_t ret, err; =20 mutex_lock(&clocksource_mutex); =20 ret =3D sysfs_get_uname(buf, override_name, count); if (ret >=3D 0) - clocksource_select(); + err =3D clocksource_select(true); =20 mutex_unlock(&clocksource_mutex); =20 - return ret; + return err ? err : ret; } static DEVICE_ATTR_RW(current_clocksource); =20 Index: linux-2.6/kernel/time/timekeeping.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/kernel/time/timekeeping.c +++ linux-2.6/kernel/time/timekeeping.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1497,13 +1498,24 @@ static int change_clocksource(void *data * This function is called from clocksource.c after a new, better clock * source has been registered. The caller holds the clocksource_mutex. */ -int timekeeping_notify(struct clocksource *clock) +int timekeeping_notify(struct clocksource *clock, bool fail) { struct timekeeper *tk =3D &tk_core.timekeeper; =20 if (tk->tkr_mono.clock =3D=3D clock) return 0; - stop_machine(change_clocksource, clock, NULL); + + if (!fail) + stop_machine(change_clocksource, clock, NULL); + else { + int ret; + + block_interf_read_lock(); + ret =3D stop_machine_fail(change_clocksource, clock, NULL); + block_interf_read_unlock(); + if (ret) + return ret; + } tick_clock_notify(); return tk->tkr_mono.clock =3D=3D clock ? 0 : -1; } From nobody Mon Apr 6 08:13:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DE36C38145 for ; Thu, 8 Sep 2022 19:57:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229455AbiIHT5f (ORCPT ); Thu, 8 Sep 2022 15:57:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbiIHT5W (ORCPT ); Thu, 8 Sep 2022 15:57:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28843FDBA3 for ; Thu, 8 Sep 2022 12:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662667040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=JcghkbSjULMePVbzbb4JaxRiOu/Uf2FtD3sfj5LZVkY=; b=cHa49sv3fkI7hTHTiyFhaGQbK2Tm1UFHNh0rAyhbRrAj5uahOVl/DBFDVtB3PazSCRY/NE gccRFMFYeUEj14JSZdxa8rRegGxf0xPV42I/R6pbY4EW6JRPhgf9B4i0vMq2sxpttBSsQb u8nvzo3O+UwMBFFqsLuy2sccwFkIKIg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-411-7U62WPpDN0OgBWAW-PRmqQ-1; Thu, 08 Sep 2022 15:57:16 -0400 X-MC-Unique: 7U62WPpDN0OgBWAW-PRmqQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 773313C0CD59; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: from fuller.cnet (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 44D85112131E; Thu, 8 Sep 2022 19:57:16 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 27B84418859B; Thu, 8 Sep 2022 16:54:07 -0300 (-03) Message-ID: <20220908195111.915923599@redhat.com> User-Agent: quilt/0.66 Date: Thu, 08 Sep 2022 16:29:05 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Frederic Weisbecker , Juri Lelli , Daniel Bristot de Oliveira , Prasad Pandit , Valentin Schneider , Yair Podemsky , Thomas Gleixner , Marcelo Tosatti Subject: [RFC PATCH 6/7] perf_event_open: check for block interference CPUs References: <20220908192859.546633738@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When creating perf events, return an error rather than interfering with CPUs tagged as block interference. Note: this patch is incomplete, installation of perf context=20 on block interference CPUs via task context is not performed. Signed-off-by: Marcelo Tosatti Index: linux-2.6/kernel/events/core.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/kernel/events/core.c +++ linux-2.6/kernel/events/core.c @@ -54,6 +54,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -12391,6 +12392,26 @@ not_move_group: =20 WARN_ON_ONCE(ctx->parent_ctx); =20 + block_interf_read_lock(); + if (!task) { + if (move_group) { + for_each_sibling_event(sibling, group_leader) { + if (block_interf_cpu(sibling->cpu)) { + err =3D -EPERM; + goto err_block_interf; + } + } + if (block_interf_cpu(group_leader->cpu)) { + err =3D -EPERM; + goto err_block_interf; + } + } + if (block_interf_cpu(event->cpu)) { + err =3D -EPERM; + goto err_block_interf; + } + } + /* * This is the point on no return; we cannot fail hereafter. This is * where we start modifying current state. @@ -12464,6 +12485,8 @@ not_move_group: put_task_struct(task); } =20 + block_interf_read_unlock(); + mutex_lock(¤t->perf_event_mutex); list_add_tail(&event->owner_entry, ¤t->perf_event_list); mutex_unlock(¤t->perf_event_mutex); @@ -12478,6 +12501,8 @@ not_move_group: fd_install(event_fd, event_file); return event_fd; =20 +err_block_interf: + block_interf_read_unlock(); err_locked: if (move_group) perf_event_ctx_unlock(group_leader, gctx); From nobody Mon Apr 6 08:13:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0148C38145 for ; Thu, 8 Sep 2022 19:57:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbiIHT5b (ORCPT ); Thu, 8 Sep 2022 15:57:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbiIHT5W (ORCPT ); Thu, 8 Sep 2022 15:57:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 288E4FDBA4 for ; Thu, 8 Sep 2022 12:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662667040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=K3kPDvRnZ5sJSBggdbe1FgXRWBmDeuCU2G3Z/g5bs1o=; b=Ls0xReApBHVSoTHb4yJhCxtj7UitCuWbho/V5XksyuOXKwBW83Zq6DTTzT4BNoWp7WtXt3 iylqggFYfLo3vmN04hBBVilBsBXTRFFLA3vGRq13JEU2EcHFuAPbgCYLfN0kaClkvO72GW 8wKX8AlrqMhfXNhei1I6Zzr2aPIdj8M= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-207-L21TuuGmPeWsliL34oBB_g-1; Thu, 08 Sep 2022 15:57:19 -0400 X-MC-Unique: L21TuuGmPeWsliL34oBB_g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E9A218A6522; Thu, 8 Sep 2022 19:57:18 +0000 (UTC) Received: from fuller.cnet (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E4201121315; Thu, 8 Sep 2022 19:57:18 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 292F84148B8E; Thu, 8 Sep 2022 16:54:07 -0300 (-03) Message-ID: <20220908195111.966739489@redhat.com> User-Agent: quilt/0.66 Date: Thu, 08 Sep 2022 16:29:06 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Frederic Weisbecker , Juri Lelli , Daniel Bristot de Oliveira , Prasad Pandit , Valentin Schneider , Yair Podemsky , Thomas Gleixner , Marcelo Tosatti Subject: [RFC PATCH 7/7] mtrr_add_page/mtrr_del_page: check for block interference CPUs References: <20220908192859.546633738@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Check if any online CPU in the system is tagged as a block interference CPU, and if so return an error to mtrr_add_page/mtrr_del_page.=20 This can avoid interference to such CPUs (while allowing userspace to handle the failures). Signed-off-by: Marcelo Tosatti Index: linux-2.6/arch/x86/kernel/cpu/mtrr/mtrr.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/arch/x86/kernel/cpu/mtrr/mtrr.c +++ linux-2.6/arch/x86/kernel/cpu/mtrr/mtrr.c @@ -45,6 +45,7 @@ #include #include #include +#include =20 #include #include @@ -335,6 +336,13 @@ int mtrr_add_page(unsigned long base, un error =3D -EINVAL; replace =3D -1; =20 + block_interf_read_lock(); + + if (cpumask_intersects(block_interf_cpumask, cpu_online_mask)) { + block_interf_read_unlock(); + return -EPERM; + } + /* No CPU hotplug when we change MTRR entries */ cpus_read_lock(); =20 @@ -399,6 +407,7 @@ int mtrr_add_page(unsigned long base, un out: mutex_unlock(&mtrr_mutex); cpus_read_unlock(); + block_interf_read_unlock(); return error; } =20 @@ -484,6 +493,11 @@ int mtrr_del_page(int reg, unsigned long return -ENODEV; =20 max =3D num_var_ranges; + block_interf_read_lock(); + if (cpumask_intersects(block_interf_cpumask, cpu_online_mask)) { + block_interf_read_unlock(); + return -EPERM; + } /* No CPU hotplug when we change MTRR entries */ cpus_read_lock(); mutex_lock(&mtrr_mutex); @@ -521,6 +535,7 @@ int mtrr_del_page(int reg, unsigned long out: mutex_unlock(&mtrr_mutex); cpus_read_unlock(); + block_interf_read_unlock(); return error; }