From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-112.ptr.blmpb.com (va-1-112.ptr.blmpb.com [209.127.230.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76D1D3F1AA1 for ; Tue, 9 Jun 2026 09:20:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780996803; cv=none; b=A1B6sDnxW8xZVhBJiYJd30OpB/llj4BdKfbdXBQqn3HFEJC7/hYsCDmL5PFEqyx+cJsYGBKehguglQDOBWHszhiJRWRGtJPwQdNyao9O1LMbgtn8vIRA+KkSwVLM74kMTSt0T7McS71O71j2gqxsM9A9MqZx1TowomDNy1l1u8Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780996803; c=relaxed/simple; bh=UTSUUiWJQtN66NoyNijoYhg+u0HAIyMdPCLucB2WvoY=; h=Message-Id:Mime-Version:Content-Type:Cc:From:Date:References: In-Reply-To:To:Subject; b=lRG+dCQb1P7Z8bKv21mUwCNfiXowbADYIS6tYTnERJPG1Mm1N03ZDwblbnorAl9NQD9VzF0WbuqEqmUwk2oBzmPv2KlggSgvE/P7lmh74A0Al65xQlA2LKyj08c/FMIEjKqwlKUqMswdY+hyBi6JuTdHXoO94sF8EdSdIU2FQ10= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=EttjsHFL; arc=none smtp.client-ip=209.127.230.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="EttjsHFL" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1780996797; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=uifNtWWqCdcLbeQJ1BoOjbBYSTB4/ehdbPbI/vJscJc=; b=EttjsHFLNkRIPM6UEUkLS7gEJtJFlmKxJcRgSYQfCXoJl/hcGI9jLFEwdur25Z8xA6MPSM tI0JejCY/7nCKeMzkzDpd12rHV0jGg5o+qYfuNkm3goaFBgjXwPp+5y61fd9kYYixkrKaw c8Ho3tOhVGrg9ttYJ/74fUcsykunx1Nqid7VSMfd3RFoI9XLcEhO3mFqRIB+Wh1g00vEEo wO4zYgi1eqCKsmB3y3c+nWXDCrU2bHGpXRk8AzJnFYWhR5ust5A1P01MCCA3mY9LJoefOP EW70BSZA18ZSZqaGCF5Wa5l4fo9m6xid2eMXccC5DmepRxm+sr04Z8/64s+hQQ== Message-Id: <20260609091710.404083-10-zhouchuyi@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1 Content-Type: text/plain; charset=UTF-8 Cc: , "Chuyi Zhou" From: "Chuyi Zhou" Date: Tue, 9 Jun 2026 17:17:05 +0800 References: <20260609091710.404083-1-zhouchuyi@bytedance.com> In-Reply-To: <20260609091710.404083-1-zhouchuyi@bytedance.com> X-Lms-Return-Path: To: , , , , , , , , , , , , , Subject: [PATCH v7 09/14] scftorture: Remove preempt_disable() in scftorture_invoke_one() X-Original-From: Chuyi Zhou Content-Transfer-Encoding: 7bit Previous patches make smp_call*() functions handle preemption logic internally. Thus, the explicit preempt_disable() surrounding these calls becomes unnecessary. Furthermore, keeping the external preempt_disable() would prevent scftorture from exercising the newly narrowed internal preemption-disabled regions during IPI dispatch. This patch removes the preempt_{enable, disable} pairs in scftorture_invoke_one(). Removing this preemption protection could expose a race condition with CPU hotplug when use_cpus_read_lock is false. Specifically, for multi-cast operations (SCF_PRIM_MANY or SCF_PRIM_ALL), if only 1 CPU is online, smp_call_function_many() correctly skips sending IPIs and leaves scfc_out as false. Without preemption disabled, a CPU hotplug thread could preempt the test thread, bring a second CPU online, and increment num_online_cpus(). When the test thread resumes, the validation check would see num_online_cpus() > 1 and falsely trigger the memory-ordering warning, leaking the scfcp structure. To avoid this potential false positive, restrict the num_online_cpus() > 1 condition to only apply when use_cpus_read_lock is true, ensuring the CPU count remains stable during evaluation. Signed-off-by: Chuyi Zhou Reviewed-by: Sebastian Andrzej Siewior Tested-by: Paul E. McKenney --- kernel/scftorture.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/kernel/scftorture.c b/kernel/scftorture.c index 327c315f411c..2082f9b44370 100644 --- a/kernel/scftorture.c +++ b/kernel/scftorture.c @@ -348,6 +348,8 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra int ret = 0; struct scf_check *scfcp = NULL; struct scf_selector *scfsp = scf_sel_rand(trsp); + bool is_single = (scfsp->scfs_prim == SCF_PRIM_SINGLE || + scfsp->scfs_prim == SCF_PRIM_SINGLE_RPC); if (scfsp->scfs_prim == SCF_PRIM_SINGLE || scfsp->scfs_wait) { scfcp = kmalloc_obj(*scfcp, GFP_ATOMIC); @@ -364,8 +366,6 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra } if (use_cpus_read_lock) cpus_read_lock(); - else - preempt_disable(); switch (scfsp->scfs_prim) { case SCF_PRIM_RESCHED: if (IS_BUILTIN(CONFIG_SCF_TORTURE_TEST)) { @@ -411,13 +411,10 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra if (!ret) { if (use_cpus_read_lock) cpus_read_unlock(); - else - preempt_enable(); + wait_for_completion(&scfcp->scfc_completion); if (use_cpus_read_lock) cpus_read_lock(); - else - preempt_disable(); } else { scfp->n_single_rpc_ofl++; scf_add_to_free_list(scfcp); @@ -452,7 +449,7 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra scfcp->scfc_out = true; } if (scfcp && scfsp->scfs_wait) { - if (WARN_ON_ONCE((num_online_cpus() > 1 || scfsp->scfs_prim == SCF_PRIM_SINGLE) && + if (WARN_ON_ONCE(((use_cpus_read_lock && num_online_cpus() > 1) || is_single) && !scfcp->scfc_out)) { pr_warn("%s: Memory-ordering failure, scfs_prim: %d.\n", __func__, scfsp->scfs_prim); atomic_inc(&n_mb_out_errs); // Leak rather than trash! @@ -463,8 +460,6 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra } if (use_cpus_read_lock) cpus_read_unlock(); - else - preempt_enable(); if (allocfail) schedule_timeout_idle((1 + longwait) * HZ); // Let no-wait handlers complete. else if (!(torture_random(trsp) & 0xfff)) -- 2.20.1