From: Simon Horman <horms@kernel.org>
To: Joas Antonio <joasantonio108@gmail.com>
Cc: David Heidelberg <david@ixit.cz>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Fan Wu <fanwu01@zju.edu.cn>,
oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] nfc: st21nfca: complete a pending SE APDU request only once
Date: Mon, 2 Nov 2026 15:53:22 +0000 [thread overview]
Message-ID: <20261102155322.GB865646@horms.kernel.org> (raw)
In-Reply-To: <CAOCBhwGBrPxLPukgH7UAoy--sOXyoWL5XsC6CmUroy0T2xujXA@mail.gmail.com>
On Sat, Oct 31, 2026 at 04:44:28PM -0300, Joas Antonio wrote:
> Hi Simon,
>
> Thanks, you're right.
>
> The two completion paths are serialised against each other:
> st21nfca_apdu_reader_event_received() does timer_delete_sync() and
> cancel_work_sync() before it looks at bwi_active, and the timer is only
> re-armed from the same HCI rx work (EVT_WTX_REQUEST). But
> st21nfca_hci_se_io() runs from the netlink path under device_lock()
> only (nfc_se_io() in net/nfc/netlink.c), which neither the rx work nor
> the timeout work takes. So:
>
> - bwi_active, cb and cb_context are plain fields written by
> st21nfca_hci_se_io() while the rx work or the timeout work may be
> reading them;
> - a second SE_IO issued while one is pending overwrites cb and
> cb_context, so a completion running at the same time can pair one
> request's callback with the other's context, and the first context is
> never completed. That is not new with this patch, but the bwi_active
> check does not cover it either;
> - st21nfca_hci_se_io() sets bwi_active only after mod_timer().
>
> For v2 I plan to add a spinlock to se_info that covers bwi_active, cb
> and cb_context: st21nfca_hci_se_io() fails with -EBUSY (freeing
> cb_context, as on the existing error path) if a request is already
> pending, otherwise records it and sets bwi_active before arming the
> timer; the timeout work and the EVT_TRANSMIT_DATA handler take the
> pending request out under the lock (test and clear bwi_active, copy cb
> and cb_context) and call the callback after dropping it, so exactly one
> of them completes it.
>
> Does that sound reasonable? I'll rerun the emulator tests on it before
> sending.
Thanks Joas,
I am wary of scope creep. But as some locking does seem necessary
for using bwi_active to be non-racy in this patch, then yes, I agree
this is a good approach.
You may want to consider two patches in a patch-set: one to add the lock,
and another being v2 of this patch, if the changes seem to be distict even
if one is dependent on the other.
...
prev parent reply other threads:[~2026-11-02 15:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 2:40 Joas Antonio dos Santos
2026-10-31 18:25 ` Simon Horman
2026-10-31 19:44 ` Joas Antonio
2026-11-02 15:53 ` Simon Horman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261102155322.GB865646@horms.kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=david@ixit.cz \
--cc=edumazet@kernel.org \
--cc=fanwu01@zju.edu.cn \
--cc=joasantonio108@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®