From patchwork Sun Jul 7 16:32:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13726036 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 19C7145BF1; Sun, 7 Jul 2024 16:32:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720369936; cv=none; b=S0M7HBMNsFfqoAzhS2J9siX6ZEgSzuD0R4Q/sGpFEkfvarh57em+b0gYxBqngBZts3R2sFKoifGMXjSndDfuGLFtCfdBZl+oqFFG3oczSe54I+jklbEKhEZNLMVaGkRPKqSZfEgNqfvNNuR5RPhYC2k1XAGrqXIXC2Klo4kqqkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720369936; c=relaxed/simple; bh=P+TJsos0wRuICzWhaMFgjmN4/yDzbtZJ6N0VJY3WNCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yv579bh6xBQpqW4/HF6h3N4hy4dQzbVRUAnHEUCiqgmU/wwBMTNShc4fNqGDySckHPLPwzS/HDClp/H3xgOcTqX552LRLh2esrwHDnmJAsP0dKqy7ESg8fqNkIvJGjGKWYg4C238fGRTEY2RV1ybXY1Mnf8l8QdC9mhVon+1zjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NPZYCClK; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NPZYCClK" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-426526d31a3so13428085e9.1; Sun, 07 Jul 2024 09:32:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720369933; x=1720974733; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ttgYBK7CIbyCBuvHefwURr58xYqG6L2p5WKp4rRTzQk=; b=NPZYCClKAvuT2t/NZf7TU5d6W0DaARUVGuU7QKJo3cIJPiZDsZuonTb6WARqmnn2UU Beq8eCTp1PK+Fici3Ewr4fGzwtE5lEt/wm7DIcwsDUOeO9jOIy3hihShRSQpSnLl4y65 OmwO9GrygHOQDCxDgjEQrwgDSflWrlTHP1ABH/Jt4pBVjTRu4L3CUffEOQpF5J9LaWrl IaGD1dIKV0XtyVUz7HxVVCbl+1G4qoU8XwA300w6zEreaXaNVj4N+qlCXEakTttNU6// NESpQZK9SQ23BTLYfW/GYpjrBv0nvMpATwGsl01LH3j7EiU7yoUrOBZ54jAFITPNwjrC 1VAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720369933; x=1720974733; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ttgYBK7CIbyCBuvHefwURr58xYqG6L2p5WKp4rRTzQk=; b=wgqlBLnjR3Md1H7jWv7m8VAHXg07xCVC1PLcNJxtN8XuVE1N1xsStqIVYzuCr0dY54 RuMuKSimGVtnjt3pKso4E4r11mplx41fxXJtL13UqF9A+RIBNQvKrf3Ji4X6JBGvhbKR bdquiMSqWzKlY4a2HXl3h1Z+QPA72ZulHwSUhDUMYhiXz2dyrke5W0Ezjm0QpQpgGr0q fA+ANj2e2UOAnka5LR6z+lizzz0icbRHOQlzyD4fIVe6mUnZZmpPMtFRN605J0cUFq2h nYjCWMa6mYILd52f//TrR9ybiOR5F4sxjyhrCmQFaWJOxcysGDeRTle/IikQdBbxz2OG KA1g== X-Forwarded-Encrypted: i=1; AJvYcCXADxOO0hd7D3PL5oXQ7yWz2kbA8BQEFFg+QYD6BjMkMTLWJok1wAvez7pogKxjYOOIPZePPu6BsaZy/VS0mr3GA/FGcbzVZ/+h/b2B X-Gm-Message-State: AOJu0YxBXGi3fUsA4pymZs/VDs/h+IrGcvTDBpHTUk+v6LPbvn3YKJRk EaF3yosHVN46XgViFYy5dcMEoZ4Dg9AbtkHDdog3dwkDs7XFO80yEuNgkw== X-Google-Smtp-Source: AGHT+IHcRGxDvEPgGFfogi371R45iMoEIDY0q+k1pqC79kdLTi8dpgOgxL3ldaHyg6IUDVzZWHo0uQ== X-Received: by 2002:a05:600c:4207:b0:426:5440:854f with SMTP id 5b1f17b1804b1-4265440881fmr51309915e9.25.1720369932568; Sun, 07 Jul 2024 09:32:12 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.218]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4264a1e8014sm134335215e9.21.2024.07.07.09.32.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jul 2024 09:32:11 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Oleg Nesterov , Andrew Morton , Christian Brauner , Tycho Andersen , Thomas Gleixner , linux-kernel@vger.kernel.org, Julian Orth Subject: [PATCH 1/2] io_uring/io-wq: limit retrying worker initialisation Date: Sun, 7 Jul 2024 17:32:10 +0100 Message-ID: <1af2a697b568f8cf77c5d527d183fa0ffe8fd9cc.1720368770.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If io-wq worker creation fails, we retry it by queueing up a task_work. tasK_work is needed because it should be done from the user process context. The problem is that retries are not limited, and if queueing a task_work is the reason for the failure, we might get into an infinite loop. It doesn't seem to happen now but it will with the following patch executing task_work in the freezing loop. For now, arbitrarily limit the number of attempts to create a worker. Cc: stable@vger.kernel.org Fixes: 3146cba99aa28 ("io-wq: make worker creation resilient against signals") Reported-by: Julian Orth Signed-off-by: Pavel Begunkov --- io_uring/io-wq.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c index 913c92249522..f1e7c670add8 100644 --- a/io_uring/io-wq.c +++ b/io_uring/io-wq.c @@ -23,6 +23,7 @@ #include "io_uring.h" #define WORKER_IDLE_TIMEOUT (5 * HZ) +#define WORKER_INIT_LIMIT 3 enum { IO_WORKER_F_UP = 0, /* up and active */ @@ -58,6 +59,7 @@ struct io_worker { unsigned long create_state; struct callback_head create_work; + int init_retries; union { struct rcu_head rcu; @@ -745,7 +747,7 @@ static bool io_wq_work_match_all(struct io_wq_work *work, void *data) return true; } -static inline bool io_should_retry_thread(long err) +static inline bool io_should_retry_thread(struct io_worker *worker, long err) { /* * Prevent perpetual task_work retry, if the task (or its group) is @@ -753,6 +755,8 @@ static inline bool io_should_retry_thread(long err) */ if (fatal_signal_pending(current)) return false; + if (worker->init_retries++ >= WORKER_INIT_LIMIT) + return false; switch (err) { case -EAGAIN: @@ -779,7 +783,7 @@ static void create_worker_cont(struct callback_head *cb) io_init_new_worker(wq, worker, tsk); io_worker_release(worker); return; - } else if (!io_should_retry_thread(PTR_ERR(tsk))) { + } else if (!io_should_retry_thread(worker, PTR_ERR(tsk))) { struct io_wq_acct *acct = io_wq_get_acct(worker); atomic_dec(&acct->nr_running); @@ -846,7 +850,7 @@ static bool create_io_worker(struct io_wq *wq, int index) tsk = create_io_thread(io_wq_worker, worker, NUMA_NO_NODE); if (!IS_ERR(tsk)) { io_init_new_worker(wq, worker, tsk); - } else if (!io_should_retry_thread(PTR_ERR(tsk))) { + } else if (!io_should_retry_thread(worker, PTR_ERR(tsk))) { kfree(worker); goto fail; } else { From patchwork Sun Jul 7 16:32:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13726037 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 A7F5F3FBA5; Sun, 7 Jul 2024 16:32:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720369938; cv=none; b=A+37wrnVHhtnE0zn6u714btswTOQPmZ61mL+WIxmNuFDjGyieXPwOb9GKjzJvzBvDFfc+un25DDWqe4s729NfVkQikruA7O/h01SVwaBWGKJC/g3rlhBvu4jmkvD5NvrF6g0gmX4YUcML9UxWLajgg5QxSo0e5VfrZFAwyKJR48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720369938; c=relaxed/simple; bh=GryIG9DNPkXL6dOI+O9Y9ATXRgOy1NZX/xATLMxFoNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H2E22vx11F76I/MnhETGvMQDdlY2P6D/bGz9dv2JQbBpuu3giLD+7CvgkCiU+SRub4Xz3aJX06CsegHamdDn2qON/VyIf09l5k1YOm7S6lsWkYILzFQaSkQt4BKjOnzB7RrQYNDUvVsQBW5ZF9JLDATO9au74zGw6RHOqC1on7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=N7LxEEfN; arc=none smtp.client-ip=209.85.208.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N7LxEEfN" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2ee88c4443eso34176081fa.3; Sun, 07 Jul 2024 09:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720369934; x=1720974734; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N1yNnFas/7Lr5aBFTus2w2lifc8IqGeG07znJipdmls=; b=N7LxEEfNrk/N0bPuBhsWhUbs9YeP/cgWjoNK9zGbSKwDyCZJJgVFH5NtdnFXIFtmJs rhxC15ZD4jJOvhWmX18t+sMM0zH+hCWLIvi+HnhqFAZCVVhofigK8vjWxcU70qJ3S/F6 R4u7hDGbU30buz4sQqlXwFq7z8HZcZtpovPCBJnGyJ87rd/fCiN4vw9EWjqaGDM+ANu4 aQw6DdzvGnqq4SWIUQVlkjtKvJ1WG5xDT+FCn25/MPeMCtJuIq7mwTv8AUFpJmVmnYHp vbXM0fe/wLu1usNR8ZcpqIhGgNlWL+Jbqj7XPRSRqhmNBzRw6FHQDwVDal3qKi6v7Uu9 V08Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720369934; x=1720974734; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N1yNnFas/7Lr5aBFTus2w2lifc8IqGeG07znJipdmls=; b=TkSqP6V/15tWnKvj2ZfC5uZ2c4egc8KUotZyi0x6zn2OqLKU+cYLU2H9pwpWcSS16m EJ8nZimDAZfbpy9PUNEbdjMd6sGvn9sueTeDwDl6tA4gcJdVf8HXqP9Xz2QGBJAteMyb hYU3LqAXDjgEatrJJcTzqtqXNI+kAUEhUZqUXQ0dBXDrzb827C1cLPvDyxk6tI24hU5W 3LnwdZXifpHYC3dURAYlni/ri9e/Eda5AucS0CPOygNTN6GzAfGRiPnSyuRhqLDnclB8 U3OitFVYUqgB+aHEdTS2h/mKFVCnwiQTiak1Mhm4YkjUsV3ZiD0mKlSX6R4+xBWtR/Yd tgNw== X-Forwarded-Encrypted: i=1; AJvYcCVbpVnKMLA82B9ATP6bYhzXvnqZ+6U9OhBCqTmav/N8MwlB9kok1+yyVKli3uo89C0HAqv8vYtjBQQz5BkChVlu0IymYR9TmbvjcDbo X-Gm-Message-State: AOJu0YwBeXxI0jeJhDWveJPjzE/nwnnYFngHo5VaH2Z+XAP/NbN6z8/F iz4LQEuNMPVV+fyVf552D5h8JWWQJYJ24tT+1BC+bvfWiD/dRN9FtcujQA== X-Google-Smtp-Source: AGHT+IGUQsjUK3JrjtflPS3usXPAkNfTEb/V/K3P6Ihn7Pt0WENpi/LQwrkKk9C0MjQrvW9McsbAeQ== X-Received: by 2002:a2e:9006:0:b0:2e9:768a:12b0 with SMTP id 38308e7fff4ca-2ee8ee13b14mr66713581fa.50.1720369934126; Sun, 07 Jul 2024 09:32:14 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.218]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4264a1e8014sm134335215e9.21.2024.07.07.09.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jul 2024 09:32:13 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Oleg Nesterov , Andrew Morton , Christian Brauner , Tycho Andersen , Thomas Gleixner , linux-kernel@vger.kernel.org, Julian Orth Subject: [PATCH 2/2] kernel: rerun task_work while freezing in get_signal() Date: Sun, 7 Jul 2024 17:32:11 +0100 Message-ID: <1d935e9d87fd8672ef3e8a9a0db340d355ea08b4.1720368770.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 io_uring can asynchronously add a task_work while the task is getting freezed. TIF_NOTIFY_SIGNAL will prevent the task from sleeping in do_freezer_trap(), and since the get_signal()'s relock loop doesn't retry task_work, the task will spin there not being able to sleep until the freezing is cancelled / the task is killed / etc. Cc: stable@vger.kernel.org Link: https://github.com/systemd/systemd/issues/33626 Fixes: 3146cba99aa28 ("io-wq: make worker creation resilient against signals") Reported-by: Julian Orth Signed-off-by: Pavel Begunkov --- kernel/signal.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/signal.c b/kernel/signal.c index 1f9dd41c04be..790d60fcfff0 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2694,6 +2694,10 @@ bool get_signal(struct ksignal *ksig) try_to_freeze(); relock: + clear_notify_signal(); + if (unlikely(task_work_pending(current))) + task_work_run(); + spin_lock_irq(&sighand->siglock); /*