From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 51B087BB01; Wed, 21 Feb 2024 14:29:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525756; cv=none; b=S6dxirNOx0c6/kBHodmNCCZx7SBz0YEDvwRohKZ2niIRy3oPtkBj9pqdNB3UesY8LPTc42/5+aExEMsvkySBp0kboCQkYMujSWYxsfh4uDpT7pkbdKXXVpa3iddja+4n2v7lcsd6ZCoA3TOSEQlY7BBCa0Hnp4DWvVbHmH2ve/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525756; c=relaxed/simple; bh=uJCAjZZU0IoyNnKiejbnvck7t9EsOPJvijpUjwb39Es=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QrDto8NdvCa+4CO5VcuXCHNekgY7ESWGeUP6Ptv6/+s59DTYq1vbubvbM3e6jF1DQh00flo9no8eYU4bteeAhYOc/9Jh04FHNt+FppCiJMlQpt86DWPEGJv6Cc37zEIUDKPagsDRYQBwF5+I2o7Dz7ryg0WYC9CzfEwFIMxgbKQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Ph4Je8bk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Ph4Je8bk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3CA7C433C7; Wed, 21 Feb 2024 14:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708525756; bh=uJCAjZZU0IoyNnKiejbnvck7t9EsOPJvijpUjwb39Es=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ph4Je8bkSXxsZPcOxtoTtj42GrsXxNqPwSAQAdwO2prbAOS0SKa4KD47X7YQG2J3X qO17c4sDQvNgBqDvOBA6n2TB5ayOuVNgnXIMGa1auNwtPesjPr1XcQhqoYXt/8D7V7 APYSiN+ZTwkbFIPPYSyPy8YVKTm9PTAEXEg9xoJM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Martijn Coenen , Alice Ryhl , Steven Moreland , Carlos Llamas Subject: [PATCH 5.4 227/267] binder: signal epoll threads of self-work Date: Wed, 21 Feb 2024 14:09:28 +0100 Message-ID: <20240221125947.367050402@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125940.058369148@linuxfoundation.org> References: <20240221125940.058369148@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Carlos Llamas commit 97830f3c3088638ff90b20dfba2eb4d487bf14d7 upstream. In (e)poll mode, threads often depend on I/O events to determine when data is ready for consumption. Within binder, a thread may initiate a command via BINDER_WRITE_READ without a read buffer and then make use of epoll_wait() or similar to consume any responses afterwards. It is then crucial that epoll threads are signaled via wakeup when they queue their own work. Otherwise, they risk waiting indefinitely for an event leaving their work unhandled. What is worse, subsequent commands won't trigger a wakeup either as the thread has pending work. Fixes: 457b9a6f09f0 ("Staging: android: add binder driver") Cc: Arve Hjønnevåg Cc: Martijn Coenen Cc: Alice Ryhl Cc: Steven Moreland Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Carlos Llamas Link: https://lore.kernel.org/r/20240131215347.1808751-1-cmllamas@google.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -840,6 +840,16 @@ binder_enqueue_thread_work_ilocked(struc { WARN_ON(!list_empty(&thread->waiting_thread_node)); binder_enqueue_work_ilocked(work, &thread->todo); + + /* (e)poll-based threads require an explicit wakeup signal when + * queuing their own work; they rely on these events to consume + * messages without I/O block. Without it, threads risk waiting + * indefinitely without handling the work. + */ + if (thread->looper & BINDER_LOOPER_STATE_POLL && + thread->pid == current->pid && !thread->process_todo) + wake_up_interruptible_sync(&thread->wait); + thread->process_todo = true; }