Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1076338rwn; Thu, 8 Sep 2022 13:03:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR61GUcbfDYLJTeov2sXbIdPHOoKdVmr1Gys6nChosv7M2gCKKRxvvBvz9jfrYWi1i0Jc5nt X-Received: by 2002:a05:6512:298a:b0:498:ec73:39c3 with SMTP id du10-20020a056512298a00b00498ec7339c3mr1379097lfb.44.1662667417051; Thu, 08 Sep 2022 13:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662667417; cv=none; d=google.com; s=arc-20160816; b=tytE02M1aCtSmNdUEqEG+gzrTIi8NoGAqaCl1gSFp+kfO0ZiP3N6VejY1dGZurP2fi AZD/xJKeCiqIzkk2zNg4c3dSEBvmvQv8xHlk96dHsohSRd63SlGPvmIuxDBO6I4YOXLU DF47MXP36QphbQF6sTtaj0G24SV1UD+mcRcfZqwan6OJU03tk9lnDQtIcH7CWMLhbPxi G7FusZWxHQG0ebkjLffI8mXECFDBMBqUxE6pGW2ucvGcyIFUggS+NEP62+Fuw6nEB+r/ igZQWu5HnSFDs34GT+t4qZwR9devvUf0BY7yZQnFSUbyuga+oEiQ7veNZFQB//7uhDMS pSlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=POf439emxhXrOrr156ZeESPCz55AZP+6XMtLj7BfFZI=; b=F2uNJTRhJQmvOmN6qKcO4LNLvhuAQF3BBD/FMc5IQXafJyQmniA0eakmocWV218YXd Q6QKFLu/45BcVR3C2TE9lGmxsJlJvHsAFKV4ApyIpeKzHQl8AbuDQQUTWYa0IhthQ/pa dQlBQwOSA01xHOWDvTjrnKPjf5VLLcje8uZE73TZihX83x9m9l5vr4HWfYoeqRjjwxxv t1TlYJZulMD7q4DEV5olg9tMU5a+c2jNy5oWIP5zF4dWKAtzfwZqbccM7rJ/89EG/Pgg qCx2nrJmUDgP4dEYc6XgunNsOZNOEntxuq74hDpoSf8EksFagKVUeD/ndrNzyXA9fSxh +ZZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CJDmlm4X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h20-20020a05651c125400b00268b560a14csi8499912ljh.446.2022.09.08.13.03.05; Thu, 08 Sep 2022 13:03:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CJDmlm4X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbiIHT5i (ORCPT + 99 others); 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 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 =================================================================== --- linux-2.6.orig/include/linux/sched/isolation.h +++ linux-2.6/include/linux/sched/isolation.h @@ -58,4 +58,33 @@ static inline bool housekeeping_cpu(int return true; } +#ifdef CONFIG_CPU_ISOLATION +extern cpumask_var_t block_interf_cpumask; +extern bool block_interf_cpumask_active; + +void block_interf_read_lock(void); +void block_interf_read_unlock(void); + +void block_interf_write_lock(void); +void block_interf_write_unlock(void); + +void block_interf_assert_held(void); + +#else +static inline void block_interf_read_lock(void) { } +static inline void block_interf_read_unlock(void) { } +static inline void block_interf_write_lock(void) { } +static inline void block_interf_write_unlock(void) { } +static inline void block_interf_assert_held(void) { } +#endif + +static inline bool block_interf_cpu(int cpu) +{ +#ifdef CONFIG_CPU_ISOLATION + if (block_interf_cpumask_active) + return cpumask_test_cpu(cpu, block_interf_cpumask); +#endif + return false; +} + #endif /* _LINUX_SCHED_ISOLATION_H */ Index: linux-2.6/kernel/sched/isolation.c =================================================================== --- linux-2.6.orig/kernel/sched/isolation.c +++ linux-2.6/kernel/sched/isolation.c @@ -239,3 +239,116 @@ static int __init housekeeping_isolcpus_ return housekeeping_setup(str, flags); } __setup("isolcpus=", housekeeping_isolcpus_setup); + +DEFINE_STATIC_PERCPU_RWSEM(block_interf_lock); + +cpumask_var_t block_interf_cpumask; +EXPORT_SYMBOL_GPL(block_interf_cpumask); + +bool block_interf_cpumask_active; +EXPORT_SYMBOL_GPL(block_interf_cpumask_active); + +void block_interf_read_lock(void) +{ + percpu_down_read(&block_interf_lock); +} +EXPORT_SYMBOL_GPL(block_interf_read_lock); + +void block_interf_read_unlock(void) +{ + percpu_up_read(&block_interf_lock); +} +EXPORT_SYMBOL_GPL(block_interf_read_unlock); + +void block_interf_write_lock(void) +{ + percpu_down_write(&block_interf_lock); +} +EXPORT_SYMBOL_GPL(block_interf_write_lock); + +void block_interf_write_unlock(void) +{ + percpu_up_write(&block_interf_lock); +} +EXPORT_SYMBOL_GPL(block_interf_write_unlock); + +void block_interf_assert_held(void) +{ + percpu_rwsem_assert_held(&block_interf_lock); +} +EXPORT_SYMBOL_GPL(block_interf_assert_held); + +static ssize_t +block_interf_cpumask_read(struct file *filp, char __user *ubuf, + size_t count, loff_t *ppos) +{ + char *mask_str; + int len; + + len = snprintf(NULL, 0, "%*pb\n", + cpumask_pr_args(block_interf_cpumask)) + 1; + mask_str = kmalloc(len, GFP_KERNEL); + if (!mask_str) + return -ENOMEM; + + len = snprintf(mask_str, len, "%*pb\n", + cpumask_pr_args(block_interf_cpumask)); + if (len >= count) { + count = -EINVAL; + goto out_err; + } + count = simple_read_from_buffer(ubuf, count, ppos, mask_str, len); + +out_err: + kfree(mask_str); + + return count; +} + +static ssize_t +block_interf_cpumask_write(struct file *filp, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + cpumask_var_t block_interf_cpumask_new; + int err; + + if (!zalloc_cpumask_var(&block_interf_cpumask_new, GFP_KERNEL)) + return -ENOMEM; + + err = cpumask_parse_user(ubuf, count, block_interf_cpumask_new); + if (err) + goto err_free; + + block_interf_write_lock(); + cpumask_copy(block_interf_cpumask, block_interf_cpumask_new); + block_interf_write_unlock(); + free_cpumask_var(block_interf_cpumask_new); + + return count; + +err_free: + free_cpumask_var(block_interf_cpumask_new); + + return err; +} + +static const struct file_operations block_interf_cpumask_fops = { + .read = block_interf_cpumask_read, + .write = block_interf_cpumask_write, +}; + + +static int __init block_interf_cpumask_init(void) +{ + if (!zalloc_cpumask_var(&block_interf_cpumask, GFP_KERNEL)) + return -ENOMEM; + + debugfs_create_file_unsafe("block_interf_cpumask", 0644, NULL, NULL, + &block_interf_cpumask_fops); + + block_interf_cpumask_active = true; + return 0; +} + +late_initcall(block_interf_cpumask_init); +