From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (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 9C56B205E30 for ; Thu, 9 Jan 2025 23:27:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736465245; cv=none; b=vBpfy+ca9jT5pERU8cZ+3QlIRFhrdRiGAco35/F0vVpUIDkiQjoWcYX1eHldBsl8YO2uFIBKn4C1szeZMgzTWbdcTReBkOG/XlW4LGTAT28VwoK45ztReYHLFm8+YR4zrp5aIxgAzftU7jfhzRrAhM4kjToMchfy0foivzMZbPA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736465245; c=relaxed/simple; bh=Z1PpgiDck34ABzXJWDzfd/sphy0939FEnD+a4tItJo0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DPuKoSNQog0CiKsEBQbxhswwpYtCvCEvfvtCjRHkSGtFIYBmGXPelsW8V76An6MnWnwSdlDw4dIEiQf/r6vP03RokbhJVo/g8BqnWPvOiPO8/8FL5jl4eirzLZrGH6+P4erItPm4s+JI765rwvHPRHBg37oYf13CsytjIAJYhqY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=nhuf2GQ4; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="nhuf2GQ4" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 509LB2l7022798; Thu, 9 Jan 2025 23:27:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=corp-2023-11-20; bh=YCpKqbRavQ867Y8ZNkOWkIxHoW6Rl auySKiYMGdt0Og=; b=nhuf2GQ4F3sgq8cfDKrA4xgihTkYtSiHnElR4Xz5+SUjs 9UaufdDIP16eWPM+WdfI587CBJOTYCQ7xbzP72ULmez7VjuCVS7iAdcee+O3PBmH LFJKKAYAAzfAYxSctbtHNkoPq22SWPT3+UPgDAxf46YLFHM44HgU73NMlj8WFS8c 15bnOGAjkBfWu2T7WGdQ5jxYO17Ppobgwq4HxcNI/LXDE413VhNB2J2orua8bnJ9 6lxixy5YG/EoPHAtfJovFTBNGFzGNqbIy68+6qZQh3gw97cknynGxffbJnDWGgxj g7GQsZPFYJd961fdOUu8FdecOzyrSYQ4bwJ/pYEIw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 43xw1c1vrc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Jan 2025 23:27:18 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 509NK2oQ005499; Thu, 9 Jan 2025 23:27:17 GMT Received: from localhost.localdomain (dhcp-10-191-134-246.vpn.oracle.com [10.191.134.246]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 43xuebrdgv-1; Thu, 09 Jan 2025 23:27:17 +0000 From: Imran Khan To: tj@kernel.org, jiangshanlai@gmail.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2] workqueue: warn if delayed_work is queued to an offlined cpu. Date: Fri, 10 Jan 2025 10:27:11 +1100 Message-Id: <20250109232711.2081259-1-imran.f.khan@oracle.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-09_10,2025-01-09_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501090184 X-Proofpoint-ORIG-GUID: ycL9u158_RBUStBZz8cZlg-VmGvZFvht X-Proofpoint-GUID: ycL9u158_RBUStBZz8cZlg-VmGvZFvht delayed_work submitted to an offlined cpu, will not get executed, after the specified delay if the cpu remains offline. If the cpu never comes online the work will never get executed. checking for online cpu in __queue_delayed_work, does not sound like a good idea because to do this reliably we need hotplug lock and since work may be submitted from atomic contexts, we would have to use cpus_read_trylock. But if trylock fails we would queue the work on any cpu and this may not be optimal because our intended cpu might still be online. Putting a WARN_ON_ONCE for an already offlined cpu, will indicate users of queue_delayed_work_on, if they are (wrongly) trying to queue delayed_work on offlined cpu. Also indicate the problem of using offlined cpu with queue_delayed_work_on, in its description. Signed-off-by: Imran Khan --- changes since v1: - use WARN_ON_ONCE in place of WARN_ON. - modify description of queue_delayed_work_on, to include why the caller needs to ensure that specified CPU remains around for non-zero delays. kernel/workqueue.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 8e0bb3c608239..3c2c45313c886 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2508,6 +2508,7 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq, return; } + WARN_ON_ONCE(cpu != WORK_CPU_UNBOUND && !cpu_online(cpu)); dwork->wq = wq; dwork->cpu = cpu; timer->expires = jiffies + delay; @@ -2533,6 +2534,12 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq, * @dwork: work to queue * @delay: number of jiffies to wait before queueing * + * We queue the delayed_work to a specific CPU, for non-zero delays the + * caller must ensure it is online and can't go away. Callers that fail + * to ensure this, may get @dwork->timer queued to an offlined CPU and + * this will prevent queueing of @dwork->work unless the offlined CPU + * becomes online again. + * * Return: %false if @work was already on a queue, %true otherwise. If * @delay is zero and @dwork is idle, it will be scheduled for immediate * execution. base-commit: 6ecd20965bdc21b265a0671ccf36d9ad8043f5ab -- 2.34.1