From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 A610832C94A for ; Tue, 25 Aug 2026 16:54:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787676844; cv=none; b=i9yZdFHuUw3WtKcaRPDjNueV/NuGihCsf/ek9bFh6guTu/iCDKXr4f9JKCPm6F/H9YJ3hbNDsAWQ689vy/dOMxMATzyhsfZ/spvJw+j+D8khsgMCfUW0k/tyTTIwEqw62jnkcmvn5soIK8Ym5v/A/x5LixntceLwU4d6f4UCxnU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787676844; c=relaxed/simple; bh=Ca37yuRHz/MjCH4jQokbkUInXVw9LqDJxavtQ0LvVQs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bc8DwCFEzKextQAgRFO+0ohBXIG35koa9dTx2wEu7Wwadep4Jy9CCAc/xgvOD8lnB+tVFoMpFRM8ny9KMWCOjiO3UUb0fTfrHEICPOpSKd3V+O1O6hlF/sB3ReUJ3jIw9W+BU0/GO8LOeT6AJdlw5xOCAXo6xM6CVWI/bY8H6ic= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=nhdn4QCf; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nhdn4QCf" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-84862b0d5aeso65434b3a.2 for ; Tue, 25 Aug 2026 09:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787676841; x=1788281641; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=b0HNwMNcfxr0yy/VrvRBV5In/7S/p3PA0JfIjamu/jU=; b=nhdn4QCfpRQMP64206vMrIz7tD546apcrKMB6Vqyq6bAi8AhrPFzk1QvIGeAiRz/XG X7j18koufGd/hvQFacu1IUrz505Z0P4eu4UfA1DNWsOzQHOedz9xJDrsq7fg5jA+bNnu f9Ww4G0f+EIVD37M5zwaz5AiWqvlq+9DiDf0KZek92MPKhNzUn2QG9GzZPkYpWYyhlka 5L2zQ5AKCpAqd3AV9E75X3xNVVK/djlHtFcOWGR+B8UDXLNpN74rh9D5H5191/NcrV5Y BPioohd9dnm+G5ikuVSZozpl69dkDJjnRTRprlMasMHIPkq3dMhU9YflIJ443Ea9+xkw JptQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787676841; x=1788281641; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=b0HNwMNcfxr0yy/VrvRBV5In/7S/p3PA0JfIjamu/jU=; b=KNtNti0b2fxPkAOmBROnocaJYc7R9kc3Whs7IqHg6+RdU11oV8XhTYFs9Z+PhLdpDi 6WccsF5CCrZA3Ur3g6g74Uw4hpX3BSzzC62CZAqMsg0Q3gsJ7nLTn0rPdAbxhMPyTpMH PjKOpngivxUV1vQjx3uTzFY8rLmvIX+wPzo39YlBkGUbLTFMtRLTezoALPKUz+3X2eF0 Bh1Dgj6zLj+spfqw+PgpFRuA/351qz4dIktV+2bOQ4YVWwIAiPCpgF7ZBdRzB7LQRIpE bwo4luM3Gs8zY8w3zYJDOU337LmCZYnXguYCul7IfF28mW6cXcLOEFUyg6cp2+5jFmJI BoJg== X-Forwarded-Encrypted: i=1; AHgh+RpTjMVxcv/oHAw8eU3wapF0wFaUV/h6sJoJKgqNmUfjjR46zc1oaSAJhV8SvAbfeYKZ/XHYdvxof8eIHsY=@vger.kernel.org X-Gm-Message-State: AFuF++m4WOi3V/NXJcZPmai/5uJgCVFEhyx2n1cRH+nG2Qq+I9/YGJDQ FsTUyrFBNj3juojieQ9SfvEHapaErRVtxxwqenLKd3JthWhqLpq1lcws1GlvLqW6HU8= X-Gm-Gg: AR+sD11xcKFRwG4W8P8CWuY9Cy4+gSaSGNuud0yXw85N71O6Uv4U2UFF0Ef4tFKkdkD uBmzttoHAn0V+IZ0Dl0LS5cR+PnNxHcHVI8yAT/wCHHOOX/C9ERTsPr3s8jsXIoQ8jO9fecU8b/ npkHlkn8Zp0q3czcuAjYLrsDOA6sF3CILLv0xnHorIF8C9uaCRaAIQmbZF1vRJjaQR7wGXXIdZH QhpZInOHWaJzmbDybDK4t0JKQ9iUuYENFgnqIWgDsxYz27dJKeAyfi1/ALWQL0mfxxmFmHr4U7S obsKsFfovHxV5bEbFQVPppxLxXm1zaCmzMEvsDE9vRo2eLOXkVJdettVSpVHBoo3rIbhfGg7A8T lTeEL2WxI6wiRjlQFMGaBbtNZwAx1P1jz4cKsu4jnXblGcSh95YBKPzvmB/Ae4Ai5bmyoJiTSn6 DzAX9g1hCw7YBTPrJhXxQjAIRK1e6Mp1NjNoF1X3SfuHey87vJzQUo6R8hjWyPUBN+ X-Received: by 2002:a05:6a00:6c87:b0:845:bda6:574b with SMTP id d2e1a72fcca58-853736ab6abmr158400b3a.5.1787676840868; Tue, 25 Aug 2026 09:54:00 -0700 (PDT) Received: from p14s ([2604:3d09:148c:c800:a37a:292f:1363:c0af]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8535ceee96fsm97869b3a.41.2026.08.25.09.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 09:54:00 -0700 (PDT) Date: Tue, 25 Aug 2026 10:53:57 -0600 From: Mathieu Poirier To: Runyu Xiao Cc: Bjorn Andersson , Tanmay Shah , Jianhao Xu , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v3] remoteproc: xlnx: initialize mailbox work before requesting channels Message-ID: References: <20260619074835.2069212-1-runyu.xiao@seu.edu.cn> <20260818101201.1603947-1-runyu.xiao@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260818101201.1603947-1-runyu.xiao@seu.edu.cn> On Tue, Aug 18, 2026 at 06:12:01PM +0800, Runyu Xiao wrote: > zynqmp_r5_setup_mbox() installs zynqmp_r5_mb_rx_cb() as the mailbox RX > callback before requesting the mailbox channels, but initializes > ipi->mbox_work only after both channels have been requested. Once the RX > channel is active, a notification delivered before the late INIT_WORK() > would make the callback queue an uninitialized work item. > > Initialize the work item before requesting channels. Also drain the work > before freeing the mailbox state, after the channels have been released so > no new callbacks can queue it. Use the same drain before freeing ipi from > the channel request error paths, since the callback is already published > there as well. > > This issue was found by our static analysis tool and then confirmed by > manual review of the mailbox setup sequence. The callback is published > before the channel requests complete, so the work item should be ready > before the mailbox provider can invoke it. > > A QEMU PoC modeled a mailbox notification delivered after the RX callback > became reachable but before the delayed INIT_WORK(). DEBUG_OBJECTS reported > queueing an uninitialized work item from the zynqmp_r5_setup_mbox() path. > > This is sent as an RFC because the practical trigger depends on the ZynqMP > IPI mailbox provider and firmware delivery timing. If the provider cannot > invoke the RX callback until after setup returns, this is a defensive > lifecycle cleanup rather than a reachable race on current systems. > > Fixes: 5dfb28c257b7 ("remoteproc: xilinx: Add mailbox channels for rpmsg") > Signed-off-by: Runyu Xiao > --- > Changes in v3: > - Follow Mathieu's feedback and call cancel_work_sync() before freeing ipi > from the tx/rx channel request error paths. > > Changes in v2: > - Follow Tanmay's suggestion and keep zynqmp_r5_setup_mbox() taking the > child device pointer. Do not move the r5_core assignment in this patch. > - Only move INIT_WORK() before channel requests and drain the work in > zynqmp_r5_free_mbox(). > > drivers/remoteproc/xlnx_r5_remoteproc.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > I will pick this up when RC1 comes out next week. Thanks, Mathieu > diff --git a/drivers/remoteproc/xlnx_r5_remoteproc.c b/drivers/remoteproc/xlnx_r5_remoteproc.c > index c685bb5fa62c..d47fbf143acd 100644 > --- a/drivers/remoteproc/xlnx_r5_remoteproc.c > +++ b/drivers/remoteproc/xlnx_r5_remoteproc.c > @@ -318,6 +318,8 @@ static struct mbox_info *zynqmp_r5_setup_mbox(struct device *cdev) > if (!ipi) > return NULL; > > + INIT_WORK(&ipi->mbox_work, handle_event_notified); > + > mbox_cl = &ipi->mbox_cl; > mbox_cl->rx_callback = zynqmp_r5_mb_rx_cb; > mbox_cl->tx_block = false; > @@ -329,6 +331,7 @@ static struct mbox_info *zynqmp_r5_setup_mbox(struct device *cdev) > ipi->tx_chan = mbox_request_channel_byname(mbox_cl, "tx"); > if (IS_ERR(ipi->tx_chan)) { > ipi->tx_chan = NULL; > + cancel_work_sync(&ipi->mbox_work); > kfree(ipi); > dev_warn(cdev, "mbox tx channel request failed\n"); > return NULL; > @@ -339,13 +342,12 @@ static struct mbox_info *zynqmp_r5_setup_mbox(struct device *cdev) > mbox_free_channel(ipi->tx_chan); > ipi->rx_chan = NULL; > ipi->tx_chan = NULL; > + cancel_work_sync(&ipi->mbox_work); > kfree(ipi); > dev_warn(cdev, "mbox rx channel request failed\n"); > return NULL; > } > > - INIT_WORK(&ipi->mbox_work, handle_event_notified); > - > return ipi; > } > > @@ -364,6 +366,8 @@ static void zynqmp_r5_free_mbox(struct mbox_info *ipi) > ipi->rx_chan = NULL; > } > > + cancel_work_sync(&ipi->mbox_work); > + > kfree(ipi); > } > > -- > 2.34.1 >