Article View: linux.kernel.netdev
Article #9787Re: [PATCH net] nfc: st21nfca: complete a pending SE APDU request only once
From: Simon Horman
Date: Mon, 02 Nov 2026 15:53
Date: Mon, 02 Nov 2026 15:53
47 lines
9919 bytes
9919 bytes
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. ...
Technical Details
Message-ID:
<20261102155322.GB865646@horms.kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354915-linux-kernel-netdev=dewy.ruReferences:
<179332800288.52644.8728400883396719965@gmail.com> <20261031182504.GW257209@horms.kernel.org> <CAOCBhwGBrPxLPukgH7UAoy--sOXyoWL5XsC6CmUroy0T2xujXA@mail.gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354915-linux-kernel-netdev=dewy.ru From: horms@kernel.org (Simon Horman) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] nfc: st21nfca: complete a pending SE APDU request only once Date: Mon, 2 Nov 2026 15:53:22 +0000 Organization: Usenet Network Message-ID: <20261102155322.GB865646@horms.kernel.org> References: <179332800288.52644.8728400883396719965@gmail.com> <20261031182504.GW257209@horms.kernel.org> <CAOCBhwGBrPxLPukgH7UAoy--sOXyoWL5XsC6CmUroy0T2xujXA@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="2977226"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:onuv9wvBA2z8plE8luj879mPvw4= sha256:aWsBozFREUS11aGK8TpWyZnBoqWKHpkok4OUNVNXxuM= sha1:is4c31bnCE2nY3YA81KjCM9/kP0= sha256:ZtK1STYsD+P3jXlIiRsN8MJjqV3EZ4X6BTRYPfoOsTQ= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id AA5301125B6; Mon, 2 Nov 2026 20:06:32 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qL8XtEZzV3R1; Mon, 2 Nov 2026 20:06:30 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-354915-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 0B2441125B4; Mon, 2 Nov 2026 20:06:21 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 5646D606E87; Mon, 2 Nov 2026 16:55:24 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793634823; b=pWHCRNZTzauCq99sM355wU0RByc+oX8CI5B+9QIoJxs9bseMRVGgSj63WWT7JbeJw2Yc dzEjf6A3julmQTcZMZPiAVLogC/naDXwGYDh+QQq9DyBRvlCLjeVjkIwURg14mScbL167 DK7nm0zSL/vZFpuh9kpyqW0dkoPiaCXw1/EFZEed3kV0E1SIWCz9to57BSwZk13DGXJ5B EKcwsbGB6YvWiOsWsSW/5RDdxzP/l0XjmpPrOLQO9gfF2SaAERW6lGpBXNyti9qEL4sfI eE42Dbwhn4vcatN3CNsA78aRFe2A8UpTbZKFbMSBOmdljAi82q942nTWu8FcnJ9vz9Q== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793634823; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=XjFbOul/AfljpdG+9e7gMBqa1iZSXAush8G4aABI3ZE=; b=3VxgnwDFQ4l8iouspe7Q+Ol4nUqfzXfrPjssR0Qo41zw7hnuJIEi7OkNXZF0Ko15eZk5 w9qTbGKrrtOf/NwUeCPE8vdkA2d4fWGNHXJO2adwsdLiGRWsdKC5xEFJqtHfnU15p6zpS ewT3+zQYTMHc2nUZA5Hpw+OwkDC5eqabxCWk+oVK5LP0b94CVBcsBGH4xcR8kdRtWijdC 99JNspdlx5XbIpgtA+WbYrwKv9PIUtjEwg1NM73LIoNx9k4L2jMy9bAk/Tf+2DQAHy8/z H45OTn2UUQDqxDAhsN8jl0Z38Uz59DkPZpADdkmQ7VihJ+f5YQpSnduGEmHH9VBHZ9g== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FrgaYHLo; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F357F6093D1F; Mon, 2 Nov 2026 15:53:42 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FrgaYHLo X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793634807; b=cisvb12VIZtnj7ueSkAfKyR8ddipg+4+6qVlsv8ZTq0tvMl2hOHk1E7s49EcH550ohk+ d/70b9qiit/oSZChLmc1pI5246IfIeX7Cvmd8aLq09M3eLkBeJn69PeHwDQCqk+8kw0OV ERwhkszJWIUo9PGS2AbUDLV3ZIRJvCOdZD9SyWWqbIlOvNSAa8rzdP6Cc+r3EH1g3ZrrL qOBNlAJlBdY4jjGhr3kOFIeFHocOZ6GSYHFIYm9Gz3knlXIRAKZc5ks/k+XLB4+9Z091s VkbNJYrAciRt9QnQZ2m4dqFVtmGFiD4fIhZJpAXNaz3W7zhAqAqqtavx7G85+rUze9A== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793634807; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=XjFbOul/AfljpdG+9e7gMBqa1iZSXAush8G4aABI3ZE=; b=y2S+ajTkxAymteGAf5E/SfiuBu+RN9QlCCERbDz5z08xaQ55g6I8+pUrtO7yiVrg3aQz Tw2oeqxR7OfSLx/cAdZxXB+Tl3B10jCSWvnrj3Q/R726bXrKH+FPM079gV/9Q3T7qkQSh iC9sWHg4Xf7lG6ByLmQGDwroUXxmbg5reDyT3a8mh04ys4XVW+LhGf4sWX0K/9p/tLX1k 0OaoQdFY2O8fkGhzCtlg1n4ElmvkCkxwU1qSXsX2BCOCfVrYtbWk/ba8Z6YfmTOf5DHrH v2u5qcSy910OEqAGiZaVbwEl+tNPjdPPSYVXTBwIoCl1Wu6/ylflPOMdJ/tFpIem3sw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FrgaYHLo; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D83EE60AED02; Mon, 2 Nov 2026 15:53:26 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E3051F01579; Mon, 2 Nov 2026 15:53:24 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793634806; bh=XjFbOul/AfljpdG+9e7gMBqa1iZSXAush8G4aABI3ZE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=FrgaYHLoE0kqDMnh8dClQWdKdQKBr/kCfbbo5QLWmmLlQ3CfhXx5wA3iZKX88tetL i+RoLiVZGgsnOfj8uWXJYyptOqDBFiUhOe46l0t3sFkUcDvL/d6lMlPw/dyjKkFRK6 keE43Nro9pLLcux7E0rJaTT8LuINmk2c5jokILcb2AahAwi12YovTgcA+gU5/BaHl7 pLVTqwC45905Bq6OrU2Ss87cBbi7SVof32oLIsUuWVNPuZKyrvG89VIuyJWnSo5yyU vwNPVBMHNIyGtM+K8O1Rx3y3End+UfJdDgLb6XTnPK6/GvAVv2VoPAHWmb8142VIl+ 64A0r6EhQzamQ== X-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 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <CAOCBhwGBrPxLPukgH7UAoy--sOXyoWL5XsC6CmUroy0T2xujXA@mail.gmail.com>