From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B94413AD9 for ; Tue, 6 Feb 2024 19:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246036; cv=none; b=tt3BC/36Ft4pqWW9BAXR/qWs4VOUeeR7v+Z8y5qHlPWsxOLpgiLWtNGWySzhlx6cjEqGsw7vU7sl8qxfH7jNNTH3Cy9FcaayjntvZuNSCUM3cRBT9/q+9MNYdqDSaMD0o85Baz+PkAUtz6jxGUs9QajnoBCHT8nbJ9Ui+I8Kvfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246036; c=relaxed/simple; bh=iYscZKrjzq/VJEK3uGeFUSm3luENc+9pjzqH3KmL/aA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Pa4A0I56F3SJ5xsxMK4/9mKxU6GcDZBnOGjSg85fOwCO78B69m/sf307mNPP261mJfne/Qvmz/m5yNojCzrJ4NQBNdhrvxsB8WuutPPhfesmXYV5rbV3LJZ8EoFK1sFhMunb60jOvA5ZKY8jJGOPFTwBs0VJzdviE4FdqcGYzRw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hwCpZaN0; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hwCpZaN0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246028; 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=k/0Yk/GxZoG+c8QW/AJpba3YgbiqoE294HEaLbyeDao=; b=hwCpZaN07MckGbMME2oaHU1zf8z3mNp0oJYcSivLIlj3aVFfzOomQSNE8iMuKfW5daRyGj CDjx4Hx/8f9g2B2fGhG+rvViV7bPQNJZYGf+UqG1SHgkD6kXH1ew2qKhLjQ1bQfP5DySrs JOSTyl03wQExmTON7kjzD1O9RhrkTc4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-gj3_c91fPQq4lZqKhhmmNA-1; Tue, 06 Feb 2024 14:00:25 -0500 X-MC-Unique: gj3_c91fPQq4lZqKhhmmNA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E512881C85; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F36EB2026D06; Tue, 6 Feb 2024 19:00:24 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 19650401E0C72; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185709.849294306@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:12 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 01/12] cpu isolation: basic block interference infrastructure References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 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-isolation/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-isolation.orig/include/linux/sched/isolation.h +++ linux-isolation/include/linux/sched/isolation.h @@ -72,4 +72,28 @@ static inline bool cpu_is_isolated(int c cpuset_cpu_is_isolated(cpu); } =20 +#ifdef CONFIG_CPU_ISOLATION +extern cpumask_var_t block_interf_cpumask; +extern bool block_interf_cpumask_active; + +int block_interf_srcu_read_lock(void); +void block_interf_srcu_read_unlock(int idx); + +void block_interf_assert_held(void); + +#else +int block_interf_srcu_read_lock(void) { return 0; } +void block_interf_srcu_read_unlock(int idx) { } +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-isolation/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-isolation.orig/kernel/sched/isolation.c +++ linux-isolation/kernel/sched/isolation.c @@ -239,3 +239,109 @@ static int __init housekeeping_isolcpus_ return housekeeping_setup(str, flags); } __setup("isolcpus=3D", housekeeping_isolcpus_setup); + +struct srcu_struct block_interf_srcu; +EXPORT_SYMBOL_GPL(block_interf_srcu); + +cpumask_var_t block_interf_cpumask; +EXPORT_SYMBOL_GPL(block_interf_cpumask); + +bool block_interf_cpumask_active; +EXPORT_SYMBOL_GPL(block_interf_cpumask_active); + +int block_interf_srcu_read_lock(void) +{ + return srcu_read_lock(&block_interf_srcu); +} +EXPORT_SYMBOL(block_interf_srcu_read_lock); + +void block_interf_srcu_read_unlock(int idx) +{ + srcu_read_unlock(&block_interf_srcu, idx); +} +EXPORT_SYMBOL(block_interf_srcu_read_unlock); + +void block_interf_assert_held(void) +{ + WARN_ON_ONCE(!srcu_read_lock_held(&block_interf_srcu)); +} +EXPORT_SYMBOL(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; + + cpumask_copy(block_interf_cpumask, block_interf_cpumask_new); + synchronize_srcu(&block_interf_srcu); + 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) +{ + int ret; + + ret =3D init_srcu_struct(&block_interf_srcu); + if (ret) + return ret; + + 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 Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B18C13AEE for ; Tue, 6 Feb 2024 19:00:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246035; cv=none; b=jkEs+DbVVKaEWGTryQ88zqQLvzs+C2S+/gP6y/WCw1THt9ryQwGnHR2kbdnNG0ERSI1+i/W/6G/0SOmb03Q0YtQr+NRixutJIku2cSjuwrDUI6JPkpOFL6UllEgiTksiUr+Nll2zBpwzGQjYC80bPN9vgp/YwWiTBq6CHvvJ56w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246035; c=relaxed/simple; bh=uPC2rNLYVTQLQRKU50mz+VRM3plkRRFHphs5ErFIBks=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=IxfT36TbQwNLke+D05qkYqw2WFtX43Xl/sCZ6TW5EHpZKYSsulRkhAClkJIRzhWxmqlXnGV+O17NrmLU7yG8VLYH87YH5D64MLCPoYkegwendATXuI3j9dc0G/c6ULAfRtwPk5b5MUeqxXYN70Zn5xQhWLFKWHYe13fgY46Xgqw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZOvT5mEl; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZOvT5mEl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246030; 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=zLB3WYtViBcdTkVKTj38aoMTQk2dk2XqSaaUs30i/zM=; b=ZOvT5mEl+E+uao5IETJ2aNTqWOBmg6skbOLwPxcQtlczUYjLxIhTgqGI85ybfqUQkJqMFg TBE2xcXk3aoJPZ4gepwWwYRBOnALmA818VP+mY9MoUiUxmhcJOOaAGQESF4z9wii0LipNU 9cgHPvhBKNYefkoYbmVtgaknG3EQY84= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-487-HcEczxWENVW9MyNafmkoUA-1; Tue, 06 Feb 2024 14:00:25 -0500 X-MC-Unique: HcEczxWENVW9MyNafmkoUA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D791185A780; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05D2C4015465; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 1D5FF401E1111; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185709.876814623@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:13 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 02/12] introduce smp_call_func_single_fail References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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-isolation/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-isolation.orig/include/linux/smp.h +++ linux-isolation/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_function_single_fail(int cpuid, smp_call_func_t func, void *i= nfo, + 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-isolation/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-isolation.orig/kernel/smp.c +++ linux-isolation/kernel/smp.c @@ -25,6 +25,7 @@ #include #include #include +#include =20 #include #define CREATE_TRACE_POINTS @@ -655,6 +656,30 @@ int smp_call_function_single(int cpu, sm } EXPORT_SYMBOL(smp_call_function_single); =20 +/* + * smp_call_function_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_function_single_fail(int cpu, smp_call_func_t func, void *inf= o, + 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_function_single_fail); + /** * smp_call_function_single_async() - Run an asynchronous function on a * specific CPU. From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91CD913FE2 for ; Tue, 6 Feb 2024 19:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246036; cv=none; b=XQVEHOkFRK1L1eniXHnYIOQ6EJjoHhsaTia7xBQpxBIRoCyEdIFoXW7+3uZ974xk/noDtUiO3eK5Jn/8DKo6FhCDu9QyFWXEaH7wZlX84hSlkYVbaxzdBESnw2eYQcwLVY2W7RJ1P0T+ipliPt137DXQsQC5ZZ50VpbUhT5gh5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246036; c=relaxed/simple; bh=xMRGD+douvn1GyniumMUnx87zYhBacweAJuDukjwzso=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=mRNnYJctI6/Ht2p2hZc6vuiMloRVt7uvEdbTAyiqhvBPEsfpU5SMgL1womFV1j1H6RFf7OhfwE2q4sGsI2skN6XDFnyepCpoU3gTtZnDzA/gkraNIwo/GY7Qb2v1GgL/9xR+7oDzgN7L5H7BSRTZXI2EtgYEYKn+rFlTWTtHFx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=E5z81I8E; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E5z81I8E" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246031; 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=9S9tPpZAmseeiLZUrI+pVU9cbhqwZZw6DOXomnrNeHc=; b=E5z81I8EhMgvdkS3ckqz3BXP+LPGEuQVydiN1DmqKE9GgyNDHuYjGlz+5otWb7KMq+Yfzr C/Fd6+qCnN0YpR/iGfGLVXqDh4OWSgR+pDXcJCczbjow7uekZN9TvteqIqOQvYqmYMuN87 gG5ULneluL3Mk8dmO05F1SzURDgml+c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-uBtq7ULgOpq9Vlkm0gw09g-1; Tue, 06 Feb 2024 14:00:26 -0500 X-MC-Unique: uBtq7ULgOpq9Vlkm0gw09g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58E6F8489A6; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B6BA1103A; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 21F57401E1133; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185709.902281455@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:14 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 03/12] Introduce _fail variants of stop_machine functions References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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-isolation/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-isolation.orig/include/linux/stop_machine.h +++ linux-isolation/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-isolation/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-isolation.orig/kernel/stop_machine.c +++ linux-isolation/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 Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6086C13AF0 for ; Tue, 6 Feb 2024 19:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246035; cv=none; b=ATIGXjB59qklynLx61vZGzmr2C0xq8zwKj1/Te+iiyHixB36p7qkOw+90j23xETxHlLzSNtn1CHBKxNoqZMBMGtuKp11MmAjbVuImeiIWIa7EF5ZHil7w+7nz+2NvGRYd427Hkkx4VZYZpBv5sS0V6YN6O/kLoajw0qBKuAPkEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246035; c=relaxed/simple; bh=BYgVLfv6v/ttWx32QuJAxOjLWrclNlzBJvovbd6xDjw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=XcoQstIpi4mpYM40W8c68ZyQ9EWZ0udyaQ4l4B/JahHafX11cb1s3fE5rH4DP3/Cz6Wf4IlVA7FEikHwO5/cBcF9r5Mf7HPeGpbhDkvowza/+S7CQsYgCtRUhgUKEX+/RDDBaF4xn3RqSjN3hjtn60L9qBHLDBng5skISEwZdrQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Tii4fEL6; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Tii4fEL6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246030; 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=Ra7EGxeWV8AGneO4cyp0zFD1CrKmCahpgLqv1cR4INo=; b=Tii4fEL6HSrqbjLiWgNqB/TZEV5g56FfItQFZ2eaBFJ/q0ZK9DW8ekXUPcuyC60X79Tg0Y lQbJrvawTXHVq6NGrFAGvShmTH+gSb2NZEPyzvEouUrzS/6lsFPRLzz9K7MEdGcC0NKWu0 w4DT2MRQzkGofzUbgfnFVFIho+iDCks= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-54-dMpKcn1bNXyBXxUWz-pMEA-1; Tue, 06 Feb 2024 14:00:26 -0500 X-MC-Unique: dMpKcn1bNXyBXxUWz-pMEA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5D0933CBDF69; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1DE8F492BC7; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 25B48401E119E; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185709.928420669@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:15 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 04/12] clockevent unbind: use smp_call_func_single_fail References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 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-isolation/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-isolation.orig/kernel/time/clockevents.c +++ linux-isolation/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, idx; struct ce_unbind cu =3D { .ce =3D ced, .res =3D -ENODEV }; =20 - smp_call_function_single(cpu, __clockevents_unbind, &cu, 1); + idx =3D block_interf_srcu_read_lock(); + ret =3D smp_call_function_single_fail(cpu, __clockevents_unbind, &cu, 1); + block_interf_srcu_read_unlock(idx); + if (ret) + return ret; return cu.res; } From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0554B134D7 for ; Tue, 6 Feb 2024 19:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; cv=none; b=AltdgEpUFlwFSgoj1B2SHspA/murzuS553mLP7xpZR11A/d2AulTPbOVADU0cY5LqiJumnSmsedsPoeghob4FS9ZLWkKObIkdT9w/vUo22irgoWx7WRsJu1O/u1A3anXGRf6wwS+IW+8RWXWVg9W2jVmlJttWwb3M0lZld7+isI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; c=relaxed/simple; bh=eLiM7F0NYaYwEZdIKULrX5PquxR5xdCAZWcTr3ag9Ik=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=byk0BwZCn1sWqSwNWb+cpP0t7Q3EcGgkh3dj9ZiaOsG2jFFPDY35tXK5A1y2dviCScxaByjHXM1F5KKuS062FlfoGe3KlB1PESqw9VnY1oh2xrLwUf2AftOqpMy/ejC9fiZAfmgDuOYioYx8aJBACfIS/13fV4OrbP6wAvRnKLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WPw2AFI2; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WPw2AFI2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246027; 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=0tiqWczwl5gDbY1ngK0gOH79fYCUh1b4q8ALen4EPQo=; b=WPw2AFI2E07SLeC6A+RSTSGbk/v2sc3R5UDiDSc9GF/Z1/0sWkMx8HYCX3SqJ71npMOVxp MLYkpuJREYXPUUfshzLV0+ThplKGJJf7X1krqF2UABNmfnU/z0uHDdk4hHUeSp/nU3muLp Q9Ym5K59oVnB4igCzt5LeKX7OfpTIXo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-318-zKnh0DFhPey1tSZHQ2dJkg-1; Tue, 06 Feb 2024 14:00:26 -0500 X-MC-Unique: zKnh0DFhPey1tSZHQ2dJkg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FE63185A788; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 31769112132A; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 29FE0401E1202; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185709.955049547@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:16 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 05/12] timekeeping_notify: use stop_machine_fail when appropriate References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 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-isolation/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-isolation.orig/include/linux/clocksource.h +++ linux-isolation/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-isolation/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-isolation.orig/kernel/time/clocksource.c +++ linux-isolation/kernel/time/clocksource.c @@ -125,7 +125,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; @@ -679,7 +679,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; } @@ -976,7 +976,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; @@ -984,7 +984,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; @@ -1021,10 +1021,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 /** @@ -1035,14 +1041,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 /* @@ -1061,7 +1067,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; } @@ -1209,7 +1215,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); @@ -1238,7 +1244,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); @@ -1260,8 +1266,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; } @@ -1352,17 +1362,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-isolation/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-isolation.orig/kernel/time/timekeeping.c +++ linux-isolation/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, idx; + + idx =3D block_interf_srcu_read_lock(); + ret =3D stop_machine_fail(change_clocksource, clock, NULL); + block_interf_srcu_read_unlock(idx); + if (ret) + return ret; + } tick_clock_notify(); return tk->tkr_mono.clock =3D=3D clock ? 0 : -1; } From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C0DF13ADC for ; Tue, 6 Feb 2024 19:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; cv=none; b=XSouySv2QplC86NpB3UsrPbIW3xqLG6ftjTsIbfbxRVipripn6KPdNxB49VKoGylLy3RJ6LQrUeufMeFpFLl+bKymSZMsOotAHENnBoNcU8gr4pzIHgCEjk6N9aB3dOyi67f/TovyTwm1MrsYyE/QfMNI2ROuMLYewFHZKXYWTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; c=relaxed/simple; bh=fizsrzHxaXU1GtGsg9HdUfQ0mzShdaO7Z2jrr3v2pXo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ERhHzh7m8vi0kXVliKafxlsViA0UML1edFHn+B9QPDwzKjCos33ql0lDeF5rZCa8/BMZfRRwrwIAN1fwqnyEme+eVROBCfAdGweHFou1VwEIFlxq712dmHHWBTc+z3FBAV1Sa2gOD6LkS9tXOnxM8Q1vpYaLmDdpD/O0XLWTlso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EUgKMaEz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EUgKMaEz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246028; 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=zDeR10fmZO+DbmEW4JtrnK5ENqS+Plr4iUlLvXYdJcA=; b=EUgKMaEz9iikaJTKrpimn5CdZlm/17yaJJkySSnxZO6C0Vl0KQ9Z6csfBRj0xor5kIC52A 5+J96ymVmNoKU0dJir/b375WwJkTwslPTm/0n/qt8NvUJNiFzNjRgixqIQYvEdIrmWnhaK o2iFq8btGAaecI8o5du3plCc+y4SuE4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-RLA6xKScNFum7LdxfHlM3g-1; Tue, 06 Feb 2024 14:00:25 -0500 X-MC-Unique: RLA6xKScNFum7LdxfHlM3g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 352B538212C1; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01CF01C060B1; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 30B33401E12AB; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185709.981989497@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:17 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 06/12] perf_event_open: check for block interference CPUs References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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-isolation/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-isolation.orig/kernel/events/core.c +++ linux-isolation/kernel/events/core.c @@ -55,6 +55,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -12435,6 +12436,7 @@ SYSCALL_DEFINE5(perf_event_open, int err; int f_flags =3D O_RDWR; int cgroup_fd =3D -1; + int idx; =20 /* for future expandability... */ if (flags & ~PERF_FLAG_ALL) @@ -12712,6 +12714,26 @@ SYSCALL_DEFINE5(perf_event_open, goto err_context; } =20 + idx =3D block_interf_srcu_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. @@ -12775,6 +12797,8 @@ SYSCALL_DEFINE5(perf_event_open, put_task_struct(task); } =20 + block_interf_srcu_read_unlock(idx); + mutex_lock(¤t->perf_event_mutex); list_add_tail(&event->owner_entry, ¤t->perf_event_list); mutex_unlock(¤t->perf_event_mutex); @@ -12789,6 +12813,8 @@ SYSCALL_DEFINE5(perf_event_open, fd_install(event_fd, event_file); return event_fd; =20 +err_block_interf: + block_interf_srcu_read_unlock(idx); err_context: put_pmu_ctx(event->pmu_ctx); event->pmu_ctx =3D NULL; /* _free_event() */ From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A51113AE0 for ; Tue, 6 Feb 2024 19:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246036; cv=none; b=upT2KrnDEMqQV6xEFqdlJZltpNW+6RjitRPL+bWCFRpTSoX+GZVaWsmahCVIibLSZ+HrNQft5GkG6xtp9YSKcvR6rMfnIQOtVm/CGOlMpbCTjPcRXH3bCAWnJftwbytEyvUsBPtkoZQWp4KtS87+5/YjMUSKTLCMVbNX70qxx3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246036; c=relaxed/simple; bh=icPewUcb2uBXgi4rZb0hGb6xeddJDSC0Pp7yA5HYgmQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=a8Xtamo93yjaMuNXLA0H1L3kR73WWfJYD40SflhEeSrtjx+REmpfdZtXRxNwPjiaSr1SYsGg8JNByQu1WhzHdl86YlIFmIuahqgozT32Uf7q0o+teAH9KGoQTmc8lHTOYVRLBjVQGrtI0y3ILJHar+DW+0a+ffZghGmplciheLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DcaL1ltr; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DcaL1ltr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246029; 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=QzKKL7qGPdseF9/lZMuCLlvRdCnkIvTUaMYeYBwSpPA=; b=DcaL1ltr+NIIkSct8kOvbEnVhMC3TIS4fcAc1g0eY3GnZp9hMG7VXoZ0OPEBsEmMAvOvii 0jjmQA2ayVxOZOy+vGPpf1p0Y03fIeQgzeW08oGNAPHGwDfKcci+xGqXYtQlEVqUfLrd2p fgckXG5TTTz7jby4YYrW/4aySpKvCeE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-oKlgPp8xMzy1OkOBzLNl5Q-1; Tue, 06 Feb 2024 14:00:26 -0500 X-MC-Unique: oKlgPp8xMzy1OkOBzLNl5Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3FDE6101FA2C; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 09E071C060B2; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 3678E401E12BF; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185710.008903181@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:18 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 07/12] mtrr_add_page/mtrr_del_page: check for block interference CPUs References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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-isolation/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-isolation.orig/arch/x86/kernel/cpu/mtrr/mtrr.c +++ linux-isolation/arch/x86/kernel/cpu/mtrr/mtrr.c @@ -45,6 +45,7 @@ #include #include #include +#include =20 #include #include @@ -226,7 +227,7 @@ int mtrr_add_page(unsigned long base, un unsigned int type, bool increment) { unsigned long lbase, lsize; - int i, replace, error; + int i, replace, error, idx; mtrr_type ltype; =20 if (!mtrr_enabled()) @@ -261,6 +262,13 @@ int mtrr_add_page(unsigned long base, un error =3D -EINVAL; replace =3D -1; =20 + idx =3D block_interf_srcu_read_lock(); + + if (cpumask_intersects(block_interf_cpumask, cpu_online_mask)) { + block_interf_srcu_read_unlock(idx); + return -EPERM; + } + /* No CPU hotplug when we change MTRR entries */ cpus_read_lock(); =20 @@ -325,6 +333,7 @@ int mtrr_add_page(unsigned long base, un out: mutex_unlock(&mtrr_mutex); cpus_read_unlock(); + block_interf_srcu_read_unlock(idx); return error; } =20 @@ -405,11 +414,17 @@ int mtrr_del_page(int reg, unsigned long mtrr_type ltype; unsigned long lbase, lsize; int error =3D -EINVAL; + int idx; =20 if (!mtrr_enabled()) return -ENODEV; =20 max =3D num_var_ranges; + idx =3D block_interf_srcu_read_lock(); + if (cpumask_intersects(block_interf_cpumask, cpu_online_mask)) { + block_interf_srcu_read_unlock(idx); + return -EPERM; + } /* No CPU hotplug when we change MTRR entries */ cpus_read_lock(); mutex_lock(&mtrr_mutex); @@ -446,6 +461,7 @@ int mtrr_del_page(int reg, unsigned long out: mutex_unlock(&mtrr_mutex); cpus_read_unlock(); + block_interf_srcu_read_unlock(idx); return error; } From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9B9C14274 for ; Tue, 6 Feb 2024 19:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246035; cv=none; b=lpHa0/i1cUfojKM/RTX473fbw+4VeRRgQJ1SRMGFkkdcOdoK3XX7BICjP79ugnz/f2pcyf4aqW0v21ImXGA+YHMV4kef84PpwtwVDwNYNjQ4R6m/MozvJPdMMq84ijk/uoDUVJ34S7l84264j9ThY+dYUrlfjccpaUk7gRjtsHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246035; c=relaxed/simple; bh=i8Przs01+5+AauKouVnKvrVBH6MR9m6+MAbeEFlDNtM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=W79KgsjKXqHg4fCMA8DC/f1gw9ghhJniTzyiK5IzJuUmlG1sbXjfhyEQFj3HyQZlepVk5jL8Iv5NCE62sN3cpPpqOYx1sQwVH6xGMntbLkxbiojGpHcRxLw73mXxqcVyY3k9SrAZt0rEuu2NHzCpNAzu3zaibwfq7LYEFsg+ioE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NHgV8i8r; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NHgV8i8r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246027; 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=qlDKbMqWBelqVSfNEbh2M7kUdtgo3q7n46OC/sINoRo=; b=NHgV8i8rTEYOTCdK32YWg8f+MEB06M6kXWudEVkG+ozuOT8SV3G25niScsYCci2/1fY4Fr NOG0vnHAMoh0kMSACqXjuBuI1vKN5HiC0Iw3KR84Qlix2tJjsbtr9jSvCDSSlzdabk/XX5 NEhLplmu6anV8IYIVq/yGtGvs8v4JCA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-mjveR6rZPGOLWpW7CJvbBg-1; Tue, 06 Feb 2024 14:00:26 -0500 X-MC-Unique: mjveR6rZPGOLWpW7CJvbBg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 54F0638212C8; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D117C0FDCB; Tue, 6 Feb 2024 19:00:25 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 3F6B0401E1311; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185710.037579553@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:19 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 08/12] arm64 kernel/topology: use smp_call_function_single_fail References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert cpu_read_constcnt 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-isolation/arch/arm64/kernel/topology.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-isolation.orig/arch/arm64/kernel/topology.c +++ linux-isolation/arch/arm64/kernel/topology.c @@ -17,6 +17,7 @@ #include #include #include +#include =20 #include #include @@ -280,6 +281,8 @@ static void cpu_read_constcnt(void *val) static inline int counters_read_on_cpu(int cpu, smp_call_func_t func, u64 *val) { + int ret, idx; + /* * Abort call on counterless CPU or when interrupts are * disabled - can lead to deadlock in smp sync call. @@ -290,7 +293,11 @@ int counters_read_on_cpu(int cpu, smp_ca if (WARN_ON_ONCE(irqs_disabled())) return -EPERM; =20 - smp_call_function_single(cpu, func, val, 1); + idx =3D block_interf_srcu_read_lock(); + ret =3D smp_call_function_single_fail(cpu, func, val, 1); + block_interf_srcu_read_unlock(idx); + if (ret) + return ret; =20 return 0; } From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90DCA14273 for ; Tue, 6 Feb 2024 19:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; cv=none; b=nTes2B9+2jOBnkYnTGD+ETwouzdfaxDN255H1weK1Wp7JTImPBUcYAeD221pEVplhcet50uSK3wwOYfSJYpnIraBkKarz+ybOfP4XTG2dv7oi/1QFEgjfS24fvrTSeBNyJhbowhPlC4KGzgHzR/ConMMbRemAPhuQLcDM8mP3EE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; c=relaxed/simple; bh=gJcQ6d0CJSjr+e3ebKviNo9PpdJR4HFcHwPuBKfcgzA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=A3jo/VReULWfT21piLrzlHoYQEHj5o4C/ApoQ3OhPAlFfoqFti5m57MVXztAfhZIX0NZYAQyXQtlP1TLN2NC37/3EGT84S35OBzQSAug+IDIB+yOg32fBcHUNrUN/sqwNntQqzaiLzaLWJeDPiTuMHLDS5FccvNq/xNteoJ8PLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eBdiyzjH; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eBdiyzjH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246026; 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=uotV7Dk20V0zYM0ZFkt2nWrKOyUgPWQe516ZJcODW/0=; b=eBdiyzjHAQQgP/benxzc8TqtKNJpvcPVOpjzeETAYjKI8WISUF+/jIbivJWR6i9stNBSIZ sYIc5+IIwvFACKiXJghciDcUavldQOEDHto5cncPMXt8Ldf6bU4bW6l4sslazPOJWi5QKr wqtrOQBQMd3kAABnxkp/zwAUKkfB7yM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-599-Eof9qh4EP0ixu8pax6vqJw-1; Tue, 06 Feb 2024 14:00:24 -0500 X-MC-Unique: Eof9qh4EP0ixu8pax6vqJw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A5D28489A5; Tue, 6 Feb 2024 19:00:23 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 381E01C060B2; Tue, 6 Feb 2024 19:00:23 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 45FE1401E133E; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185710.062560408@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:20 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 09/12] AMD MCE: use smp_call_func_single_fail References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert arch/x86/kernel/cpu/mce/amd.c 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-isolation/arch/x86/kernel/cpu/mce/amd.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-isolation.orig/arch/x86/kernel/cpu/mce/amd.c +++ linux-isolation/arch/x86/kernel/cpu/mce/amd.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include #include @@ -970,6 +971,7 @@ store_interrupt_enable(struct threshold_ { struct thresh_restart tr; unsigned long new; + int ret, idx; =20 if (!b->interrupt_capable) return -EINVAL; @@ -982,8 +984,15 @@ store_interrupt_enable(struct threshold_ memset(&tr, 0, sizeof(tr)); tr.b =3D b; =20 - if (smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1)) + idx =3D block_interf_srcu_read_lock(); + ret =3D smp_call_function_single_fail(b->cpu, threshold_restart_bank, + &tr, 1); + block_interf_srcu_read_unlock(idx); + if (ret) { + if (ret =3D=3D -EPERM) + return ret; return -ENODEV; + } =20 return size; } @@ -993,6 +1002,7 @@ store_threshold_limit(struct threshold_b { struct thresh_restart tr; unsigned long new; + int ret, idx; =20 if (kstrtoul(buf, 0, &new) < 0) return -EINVAL; @@ -1007,8 +1017,14 @@ store_threshold_limit(struct threshold_b b->threshold_limit =3D new; tr.b =3D b; =20 - if (smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1)) + idx =3D block_interf_srcu_read_lock(); + ret =3D smp_call_function_single_fail(b->cpu, threshold_restart_bank, &tr= , 1); + block_interf_srcu_read_unlock(idx); + if (ret) { + if (ret =3D=3D -EPERM) + return ret; return -ENODEV; + } =20 return size; } From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C00471426E for ; Tue, 6 Feb 2024 19:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; cv=none; b=n92sx5oWLOolUuGm4aCgOyJ3wAzEiGu0vpSLuwJW1w9/bG+7/2a8sNINNgMQxnXUhn8i8hScuprp1//zshA0HTFPxQ7aWIRcH9k99QnoZIZ2fJF7qiIfpX/URiue0/jvkMpHQdY1ISlbCIy2LBB/eFRhwewSHsAJUhdv1v/o7Us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; c=relaxed/simple; bh=j28jEXAQ6BxQAteMhx/bhKW8iMfKVsyg8VIUsodhjeY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=T3HqrtYluTOSF/SSdD9fgLX5Yyxx5iOOW09kYybEKg9l3Ns5Vg+i5QaghMDUlMitrZsrdq6Vd4kwjFJz3QqhT0mYN2I5pebkVpX9+DZKQe0lbvLU7GzRVf3d6uK1uFspscS40CoGiuLKXHQdS0eRdbBieVc+7E2lhZ56rL+d1VY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bX2euxKk; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bX2euxKk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246025; 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=FG1YeQVX9cWWByEmGmyaeyChQB/mxYFgQkxnSBaUu8k=; b=bX2euxKkxDEaTxJpT8Zyp/T1k36VPfZOYUHxZzUaWSNRt0lGANQyK99ryIdp2lmirfcuBg fR1w6VSpd8Yw9MpnVp2ClNU7dJejrspAFSm8gWzD4YJs8JqfVap2x95fxcAEKS/Voj+/40 86NxxULdrdL5JimSo2YL8+d14Gr6HfI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-OUyrGmmSPYGPPPCdx93-jw-1; Tue, 06 Feb 2024 14:00:24 -0500 X-MC-Unique: OUyrGmmSPYGPPPCdx93-jw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9BEFA3CBDF65; Tue, 6 Feb 2024 19:00:23 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56C891121312; Tue, 6 Feb 2024 19:00:23 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 4DAB6401E134F; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185710.090317205@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:21 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 10/12] x86/mce/inject.c: fail if target cpu is block interference References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the codepaths leading to smp_call_function (including rdmsrl_on_cpu), check for, and fail if, a target cpu is marked as "block interference". Signed-off-by: Marcelo Tosatti Index: linux-isolation/arch/x86/kernel/cpu/mce/inject.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-isolation.orig/arch/x86/kernel/cpu/mce/inject.c +++ linux-isolation/arch/x86/kernel/cpu/mce/inject.c @@ -23,6 +23,7 @@ #include #include #include +#include =20 #include #include @@ -584,6 +585,13 @@ static int inj_bank_set(void *data, u64 struct mce *m =3D (struct mce *)data; u8 n_banks; u64 cap; + int idx, ret =3D 0; + + idx =3D block_interf_srcu_read_lock(); + if (block_interf_cpu(m->extcpu)) { + ret =3D -EPERM; + goto err; + } =20 /* Get bank count on target CPU so we can handle non-uniform values. */ rdmsrl_on_cpu(m->extcpu, MSR_IA32_MCG_CAP, &cap); @@ -591,7 +599,8 @@ static int inj_bank_set(void *data, u64 =20 if (val >=3D n_banks) { pr_err("MCA bank %llu non-existent on CPU%d\n", val, m->extcpu); - return -EINVAL; + ret =3D -EINVAL; + goto err; } =20 m->bank =3D val; @@ -612,12 +621,14 @@ static int inj_bank_set(void *data, u64 =20 if (rdmsrl_on_cpu(m->extcpu, MSR_AMD64_SMCA_MCx_IPID(val), &ipid)) { pr_err("Error reading IPID on CPU%d\n", m->extcpu); - return -EINVAL; + ret =3D -EINVAL; + goto err; } =20 if (!ipid) { pr_err("Cannot inject into unpopulated bank %llu\n", val); - return -ENODEV; + ret =3D -ENODEV; + goto err; } } =20 @@ -627,7 +638,9 @@ inject: /* Reset injection struct */ setup_inj_struct(&i_mce); =20 - return 0; +err: + block_interf_srcu_read_unlock(idx); + return ret; } =20 MCE_INJECT_GET(bank); From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 996ED13AE9 for ; Tue, 6 Feb 2024 19:00:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246035; cv=none; b=LbiGGkiLDm8L1PZBIK7VHVYHp8RavZNlk+RInT+6E0HPiYLqlyyIKA2WT69comSI0xYU4Vlzk5wdh91XRs9uuX8dyrAUpcUbnKl69FEGw12n8P13j6SpMw3gFqoF92w/bBjmILJ3iRY3zxYcs3N/aFTJu6PEWefesIfc01yj1aI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246035; c=relaxed/simple; bh=0oVR2iX1MWiDWezzOf++9ZQng2r7sLEq/QSolw3KecA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=XfwnEfybxd6/ZXjYdAbGA2oQg9oA03Xh6DoiYk8JwFiYYI3ojdf3juGbU1ythBqtzsOIooNQb4XqGzSAkFuUB4glXny83gNcQJWDob3hiFnJwfaaBjQy0utbTPxm4us6/SQNQ9MFsKRtuem4TXaDyccN0lbf1+9YKeD6tx7u408= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HlRKy6zc; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HlRKy6zc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246029; 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=k9Gh7G7xTrMd8YjXBJXK/0OngeF3ZzVghgrC9df1T2I=; b=HlRKy6zcw+AyOpNMeSdFy7/yMXCBFJf51XpPnfbKyyMOvfVvvM9/K5SPzX/K+0Go1URlf0 K0YbuJ4fjVluH6fjVAkg7TGLUPc9I/cqGrZbeoGoxWkfKAvD8vXwkro6t2pPHwQk6g1+yY Ow+hQItp3V2PlhotvW0gUWYCygMtFig= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-259--v_AD5UKOy2ld9z7HOoj2Q-1; Tue, 06 Feb 2024 14:00:24 -0500 X-MC-Unique: -v_AD5UKOy2ld9z7HOoj2Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C7DF185A780; Tue, 6 Feb 2024 19:00:23 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45A581C060B3; Tue, 6 Feb 2024 19:00:23 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 54400401DED49; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185710.116221062@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:22 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 11/12] x86/resctrl: use smp_call_function_single_fail References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert update_task_closid_rmid 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-isolation/arch/x86/kernel/cpu/resctrl/rdtgroup.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-isolation.orig/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ linux-isolation/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -26,6 +26,7 @@ #include #include #include +#include =20 #include =20 @@ -551,12 +552,20 @@ static void _update_task_closid_rmid(voi resctrl_sched_in(task); } =20 -static void update_task_closid_rmid(struct task_struct *t) +static int update_task_closid_rmid(struct task_struct *t) { - if (IS_ENABLED(CONFIG_SMP) && task_curr(t)) - smp_call_function_single(task_cpu(t), _update_task_closid_rmid, t, 1); - else + int idx, ret =3D 0; + + if (IS_ENABLED(CONFIG_SMP) && task_curr(t)) { + idx =3D block_interf_srcu_read_lock(); + ret =3D smp_call_function_single_fail(task_cpu(t), + _update_task_closid_rmid, + t, 1); + block_interf_srcu_read_unlock(idx); + } else _update_task_closid_rmid(t); + + return ret; } =20 static int __rdtgroup_move_task(struct task_struct *tsk, @@ -604,9 +613,7 @@ static int __rdtgroup_move_task(struct t * group go into effect. If the task is not current, the MSR will be * updated when the task is scheduled in. */ - update_task_closid_rmid(tsk); - - return 0; + return update_task_closid_rmid(tsk); } =20 static bool is_closid_match(struct task_struct *t, struct rdtgroup *r) From nobody Sat Feb 7 13:41:35 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 507701426F for ; Tue, 6 Feb 2024 19:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; cv=none; b=D12j/W/W+lp785RMWWubA5kY0aNBKSotB1bvTmi8MeeZOr4tCE8gJb7AtY35dVZzm813EiE1I5BFH9ZvmWCW/O9V6y4TR1Cf7jbDoXM7LpwJ1nFwl/a1CnDCbjq19sbvspYLBn2Mg8CGWz8CQXcClvfL6lHuynjA8DzcMW4lbfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707246034; c=relaxed/simple; bh=daz3lcICgKm4ORgHnwPvFe7sWvQh/KVh8kswKSeKAW0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=RNz3z6vUpIibPJsDkQzZis+RU1lCR9NwVUmbsQeewIaHZM6ZCaM4PkT4RuiMMVQRCFflNdB036qed8+7eoRgbLyggKrsmk0yz7/kKRJeIu7K11kBfRLn1zeAphocqHG2xmOU1DSTH/ii6CA1stIu07LvFcE5fw4sZRMNEo3QCys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HHHhdJTw; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HHHhdJTw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707246026; 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=XLGveArYXH+nDRK2eZvc/caQl6NFDd9KJm+PgMdFiUY=; b=HHHhdJTwKqyyMvQHJ9l7F2bTxNnPejgTj8QH7wNiZrQpHEziwGxtegGtVMln5cvEFYet2R 9hMmEdAd+7UjB+mRvtBrPzxXKdUJJH53IPOuVi1WkUDp8CJajYKqNH7niAxF5psNgr+Cxq vYaTQ9rhADEyZdiD2+c38FgXeBARlVg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-gLlXglagPQe6S18qGbwUog-1; Tue, 06 Feb 2024 14:00:24 -0500 X-MC-Unique: gLlXglagPQe6S18qGbwUog-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB69938212C8; Tue, 6 Feb 2024 19:00:23 +0000 (UTC) Received: from tpad.localdomain (unknown [10.96.133.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 688B4C1596E; Tue, 6 Feb 2024 19:00:23 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 5BD34401E140A; Tue, 6 Feb 2024 15:58:07 -0300 (-03) Message-ID: <20240206185710.142514323@redhat.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 15:49:23 -0300 From: Marcelo Tosatti To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , Juri Lelli , Valentin Schneider , Frederic Weisbecker , Leonardo Bras , Peter Zijlstra , Thomas Gleixner , Marcelo Tosatti Subject: [patch 12/12] x86/cacheinfo.c: check for block interference CPUs References: <20240206184911.248214633@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change amd_set_l3_disable_slot to check for block interference cpumask, and avoid the IPI if set. Also change wbinvd_on_cpu to use smp_call_function_single_fail. Signed-off-by: Marcelo Tosatti Index: linux-isolation/arch/x86/include/asm/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-isolation.orig/arch/x86/include/asm/smp.h +++ linux-isolation/arch/x86/include/asm/smp.h @@ -118,7 +118,7 @@ int native_cpu_disable(void); void __noreturn hlt_play_dead(void); void native_play_dead(void); void play_dead_common(void); -void wbinvd_on_cpu(int cpu); +int wbinvd_on_cpu(int cpu); int wbinvd_on_all_cpus(void); =20 void smp_kick_mwait_play_dead(void); Index: linux-isolation/arch/x86/kernel/cpu/cacheinfo.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-isolation.orig/arch/x86/kernel/cpu/cacheinfo.c +++ linux-isolation/arch/x86/kernel/cpu/cacheinfo.c @@ -17,6 +17,7 @@ #include #include #include +#include =20 #include #include @@ -396,6 +397,7 @@ static void amd_l3_disable_index(struct * disable index in all 4 subcaches */ for (i =3D 0; i < 4; i++) { + int ret; u32 reg =3D idx | (i << 20); =20 if (!nb->l3_cache.subcaches[i]) @@ -409,6 +411,7 @@ static void amd_l3_disable_index(struct * is not sufficient. */ ret =3D wbinvd_on_cpu(cpu); + WARN_ON(ret =3D=3D -EPERM); =20 reg |=3D BIT(31); pci_write_config_dword(nb->misc, 0x1BC + slot * 4, reg); @@ -428,7 +431,7 @@ static void amd_l3_disable_index(struct static int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot, unsigned long index) { - int ret =3D 0; + int idx, ret =3D 0; =20 /* check if @slot is already used or the index is already disabled */ ret =3D amd_get_l3_disable_slot(nb, slot); @@ -442,7 +445,15 @@ static int amd_set_l3_disable_slot(struc if (index =3D=3D amd_get_l3_disable_slot(nb, !slot)) return -EEXIST; =20 - amd_l3_disable_index(nb, cpu, slot, index); + ret =3D 0; + idx =3D block_interf_srcu_read_lock(); + + if (block_interf_cpu(cpu)) + ret =3D -EPERM; + else + amd_l3_disable_index(nb, cpu, slot, index); + + block_interf_srcu_read_unlock(idx); =20 return 0; } Index: linux-isolation/arch/x86/lib/cache-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-isolation.orig/arch/x86/lib/cache-smp.c +++ linux-isolation/arch/x86/lib/cache-smp.c @@ -7,9 +7,9 @@ static void __wbinvd(void *dummy) wbinvd(); } =20 -void wbinvd_on_cpu(int cpu) +int wbinvd_on_cpu(int cpu) { - smp_call_function_single(cpu, __wbinvd, NULL, 1); + return smp_call_function_single_fail(cpu, __wbinvd, NULL, 1); } EXPORT_SYMBOL(wbinvd_on_cpu);