Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4619874iob; Sun, 8 May 2022 19:28:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrpZUdsBYYdHQu5H0QAiygS7aD9IJMDt6bB6Jm6LavGZQbA9Sdg5ch1fwJyR9WTBsdbZQd X-Received: by 2002:a17:903:2344:b0:15e:bc62:bda7 with SMTP id c4-20020a170903234400b0015ebc62bda7mr14346412plh.120.1652063332087; Sun, 08 May 2022 19:28:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652063332; cv=none; d=google.com; s=arc-20160816; b=TJiXjSssc2Z67n8TiIqb295F+22pi0nR4V3PI4HoaCG8vGw1YV4g0kEoczEo7Jhw06 v1MmZQna78/HGAmAFtRLkmYtq1HgZsVBz31Uc2yHwfrYdwEjfrO/CJJ9GxxFSTib1AGJ wkHII4bwLfNUeooiGRSkWfu9s8ME9l/jBOignAuevbkJvuVUuSeYrE7duWAkTsUzit56 1hC9Of2oVlyq5hxDWb5ZGWs5jg32Z8Jse8lz9ra0tVeUKwSGmBRakBAjTrO86x8bqtGc 6/IJWUl1hlqAfduu9iAJHcxe36GLtxZA0/8hminHvtktyEy8zbYvbdB1IAqdk2u7GU0H E9GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OiKP99KtC7HRJj+1KAHA0WguULRv6Eau21Kc1AwjCEI=; b=nTK33LKzlxkq9da/+C/9lQ0r8H2NLHN7KYynxxrt5/bRf6+mHMjim+CUCBowrVuPLS urSbn0Onkgf4OmK00ZjQvxX/D62LHXAwP0awYpZAVl5od8TvJgfK5Hj/SxPLq7cQu29o irwSvUQ+UXfzZA27zGocfObtM7m5rrSG/vFy+7RYgSVmp/9RGe7+T5KUK1a2ym1hl/tW pSS2HxFFmp+pyYRjlOkzXaPsGMchNs1o2ACJi1Hv0IaIxICdMKzXzaAh8Cb7fSuetoYu YA+WY/vzu1wDqFEDKT1gtDUf4mfmEdjFbd8Q+D+/X4jEnD9RaopFkDrr9NjHE4bAz/aZ 0FKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fPr0kekT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d10-20020a170903230a00b0015874dc3247si12255219plh.170.2022.05.08.19.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 19:28:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fPr0kekT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA44D68301; Sun, 8 May 2022 19:28:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388047AbiEFBoi (ORCPT + 99 others); Thu, 5 May 2022 21:44:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387990AbiEFBo2 (ORCPT ); Thu, 5 May 2022 21:44:28 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD1DA57131; Thu, 5 May 2022 18:40:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651801246; x=1683337246; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DhSGJxGF7SsqY8pphIVSqqNZ4YAjw315eAisL8CT1kQ=; b=fPr0kekTtZlb6ev9xVR1yxPYnLXFFJCJS7vydOlnSfHpPpY0CmBA4krx HJZoL11h3fRvGZBvaDw+6BLrn3g5H3pWTe+1WbEG4BsfmnSViXwiHmCZJ fZG8hzuyiW+GRahPBPqsPdbnjxhUzdBce9k9mz1Bozsq1JWxzRg2EgWxF QhMR5T8lJBRlH8VVE/gueWNhZMlENyth7LsiHv8osYDoGqAyLIszj0GAa TxvdrbYBChC8fM4geL+WQQRhPrbZ4tcKEKRkRxbSo86m5keRTL3Kure7I iwyrWgqfUwPd/kXaqr/XqDD5ugnWYMS58TnJ2z625zWxYOxUWDGodCym8 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="293519426" X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="293519426" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 18:40:45 -0700 X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="537645025" Received: from agluck-desk3.sc.intel.com ([172.25.222.78]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 18:40:44 -0700 From: Tony Luck To: hdegoede@redhat.com, markgross@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, corbet@lwn.net, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, jithu.joseph@intel.com, ashok.raj@intel.com, tony.luck@intel.com, rostedt@goodmis.org, dan.j.williams@intel.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, platform-driver-x86@vger.kernel.org, patches@lists.linux.dev, ravi.v.shankar@intel.com, Peter Zijlstra Subject: [PATCH v6 03/11] stop_machine: Add stop_core_cpuslocked() for per-core operations Date: Thu, 5 May 2022 18:40:27 -0700 Message-Id: <20220506014035.1173578-4-tony.luck@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220506014035.1173578-1-tony.luck@intel.com> References: <20220428153849.295779-1-tony.luck@intel.com> <20220506014035.1173578-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Peter Zijlstra Hardware core level testing features require near simultaneous execution of WRMSR instructions on all threads of a core to initiate a test. Provide a customized cut down version of stop_machine_cpuslocked() that just operates on the threads of a single core. Suggested-by: Thomas Gleixner Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Tony Luck --- include/linux/stop_machine.h | 16 ++++++++++++++++ kernel/stop_machine.c | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h index 46fb3ebdd16e..ea7a74ea7389 100644 --- a/include/linux/stop_machine.h +++ b/include/linux/stop_machine.h @@ -124,6 +124,22 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus); */ int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus); +/** + * stop_core_cpuslocked: - stop all threads on just one core + * @cpu: any cpu in the targeted core + * @fn: the function to run + * @data: the data ptr for @fn() + * + * Same as above, but instead of every CPU, only the logical CPUs of a + * single core are affected. + * + * Context: Must be called from within a cpus_read_lock() protected region. + * + * Return: 0 if all executions of @fn returned 0, any non zero return + * value if any returned non zero. + */ +int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data); + int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus); #else /* CONFIG_SMP || CONFIG_HOTPLUG_CPU */ diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index cbc30271ea4d..579761729836 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -633,6 +633,25 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus) } EXPORT_SYMBOL_GPL(stop_machine); +int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data) +{ + const struct cpumask *smt_mask = cpu_smt_mask(cpu); + + struct multi_stop_data msdata = { + .fn = fn, + .data = data, + .num_threads = cpumask_weight(smt_mask), + .active_cpus = smt_mask, + }; + + lockdep_assert_cpus_held(); + + /* Set the initial state and stop all online cpus. */ + set_state(&msdata, MULTI_STOP_PREPARE); + return stop_cpus(smt_mask, multi_cpu_stop, &msdata); +} +EXPORT_SYMBOL_GPL(stop_core_cpuslocked); + /** * stop_machine_from_inactive_cpu - stop_machine() from inactive CPU * @fn: the function to run -- 2.35.1