From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 18E02428482 for ; Thu, 7 May 2026 14:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778165264; cv=none; b=ir8IPAVjJx+gucr9SCkNqxEwi8wTYHKTwtZ7cYcPQ4Th9c4DhQZgy+KvtLt8wDnDPxGpTYSDcJN+5riGT6N1/9BtLHHIToZDFme1LVRKflBn+anIkT3zQ2aiSrIqkXQq7SyVDvP6AjwtSw9Hf48C6RH/LyjUQTFpPmAXWN/GCZQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778165264; c=relaxed/simple; bh=xquPI6QPP/hbFDTiZH9dc4zpjGQDSZQDeuwR2/3lSaA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sefDfB2hoGiJgWunnCKkA2No71Tv4W4QNCphZ4LVNFLNWF0iwOGYz6OlqqnQMSIhDmZo/lh9LjHIrQZT2t4w20/N02L898se6bQJ4xprGCoqfHVKRvzzoWgrUkOvrclB+8b+fjOMyPXQQLE2umldceA9+gxxIlegrprrjJT3mzY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--joonwonkang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=L4PFkqMi; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--joonwonkang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="L4PFkqMi" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2b2e8bba2e6so12604905ad.1 for ; Thu, 07 May 2026 07:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778165259; x=1778770059; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=6MuSudfTdnilh+hmaWDc0E6+rXSvYD2Cazrxvm5Ba1I=; b=L4PFkqMiFeFDxJM2Ft9gRcNhf+nU4U7Ydur/hxvX/59wBm+OSifOZkLpO3451Za+5W zFGnIKRkAJY8w5JjYKjv2Y4Td2G2UMFjNInAqnfkszHrixXE6gtmSRCufTJZxhjgVXQM 0+bUkXYaPwY/gX6Vy3BKJB27YjiIofrZ9jTbrxMhqJ5vuZV/1g/QGwGiWzz2mPqO1pgS J3zAxh8g/d6ayUMiReLMJE6ULvaRepiSq5wSDQz20hQG3OuOCGS6Le51751s4Yz4Dk/O DdGOpmv6Ps2dfQF0oNXbbpTAMABg0hjGs4i4eluj0Z4IWwMtikQSwSQg+L6qXi+CloIe Xoyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778165259; x=1778770059; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=6MuSudfTdnilh+hmaWDc0E6+rXSvYD2Cazrxvm5Ba1I=; b=ini9JUyqmwZaipxBCAsJh8uaodRvr7Fb+mnU+1Wa83/qdnvxnQgxpoovCTEiyPBnWW eK2GC3Lo8rsDULqNLDUQIhHdWRub+fAayd5IRmIjXsKt6tProBpDBeRR5aL7CtO0IjlT J4lAEqcSjAG8P7c9CmEV4vJpFgPPG5llsHOU838VwojARtcYUjjyqarY9SKpuBqYUN/K Wq8t2ZPM6SVR8awzrIJ2sxMwcL/oynzhW0yzijhGl+qMoaSHpoi+zve298uHZmK1wOa6 /TjGcvibfaRCHJJOU0lLsD6BtGaiZzxjIa/X0nYSBU59TI9ma5nIbnHZWPcaRVwfhkpA RA3g== X-Forwarded-Encrypted: i=1; AFNElJ8+YilBNLJwhpEQZ2M5RyfU/XemF63ic48wNHSblqgPhPuFr7tqTLWWBKs2adTv1uT3vC7UKZt0htZEqWE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3zZytnicg2ypvqGDY4JIIY1jHTyT12eycH7NzuwEU+xeMVMYI 17jFdPz5SP7qT+0TGiu0/NCQLNBhv+e3Z+1mtFLttTU4m2wS3B72aBqjujI2Albi+x+cetXnfq2 m/96OfQr9dm0fhdI5XAJuS4xQvQ== X-Received: from plbkf16.prod.google.com ([2002:a17:903:5d0:b0:2ba:792a:18a7]) (user=joonwonkang job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1ae5:b0:2b4:59d4:9a with SMTP id d9443c01a7336-2ba78b4a778mr93766055ad.2.1778165258795; Thu, 07 May 2026 07:47:38 -0700 (PDT) Date: Thu, 7 May 2026 14:47:32 +0000 In-Reply-To: <20260507-large-wren-of-protection-93bb75@sudeepholla> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260507-large-wren-of-protection-93bb75@sudeepholla> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260507144737.3343314-1-joonwonkang@google.com> Subject: Re: [PATCH v4] mailbox: Make mbox_send_message() return error code when tx fails From: Joonwon Kang To: sudeep.holla@arm.com Cc: akpm@linux-foundation.org, jassisinghbrar@gmail.com, joonwonkang@google.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Sudeep, I appreciate your review! And I apologize that I missed some important context about this patch. > On Tue, Apr 21, 2026 at 10:46:52AM +0000, Joonwon Kang wrote: > > When the mailbox controller failed transmitting message, the error code > > was only passed to the client's tx done handler and not to > > mbox_send_message() in blocking mode. For this reason, the function cou= ld > > return a false success. This commit resolves the issue by introducing t= he > > tx status and checking it before mbox_send_message() returns. > > > `tx_complete` and `tx_status` are per-channel, not per-message. Although > `mbox_send_message()` can queue multiple messages, all blocking callers w= ait > on the same completion, so a completion is not associated with the thread= or > message that triggered it. >=20 > This creates two issues: >=20 > 1. Concurrent blocking senders can consume each other=E2=80=99s completio= ns. When > message A completes, `tx_tick()` may submit message B, then set > `chan->tx_status` and complete the shared completion. Any waiter may w= ake, > including B=E2=80=99s sender, which can return while B is still in fli= ght. It > happens even w/o this change but with possibly wrong return value afte= r > this change. >=20 > 2. `tx_status` can be stale or overwritten. Since it is a single channel = field > written just before `complete()`, a second(possibly fast) `tx_tick()` = can > update it before the first awakened sender reads it. Because `msg_subm= it()` > happens before status publication, the next message can complete befor= e the > previous status is observed if the controller re-enters `tx_tick()` fo= r the > same channel. >=20 > We need to see if there are other issue that needs fixing before you can > propagate the tx error code. Let me know if I am missing something. Yes, the current mbox_send_message() in blocking mode does not support multi-threads. I have tried adding the multi-threads support [1] since the first patchset and adding this patch on top of it [2], but the author was not convinced about the necessity of the multi-threads support and instead preferred that clients, instead of the mailbox APIs, serialize the multiple threads' access to the channel [3]. For this reason, I went with the author's preference [4] and clarified that multi-threads is not supported in the API doc [5] so that clients can be clearly aware of it and serialize its threads' access to the channel. So, this patch is based on the assumption that such multi-threads protection is given by the clients already, i.e. mbox_send_message() in blocking mode is called on the same channel only when the previous call has returned. What is your opinion on this? Should we support multi-threads in the mailbo= x APIs [1]? or should we go with the current decision [5]? I personally have been thinking the former is the way to go. [1] https://lore.kernel.org/all/20260402170641.2082547-1-joonwonkang@google= .com [2] https://lore.kernel.org/all/20260402170641.2082547-3-joonwonkang@google= .com/ [3] https://lore.kernel.org/all/CABb+yY0uDQh-3cadPQONV=3DNJKjMtc4mJekgjmHYV= aHnfHXvGZQ@mail.gmail.com/ [4] https://lore.kernel.org/all/20260404124428.3077670-1-joonwonkang@google= .com/ [5] https://lore.kernel.org/all/20260421104652.211276-1-joonwonkang@google.= com/ Thanks, Joonwon Kang