From: Vlad Efanov <vefanov@ispras.ru>
To: "Keller, Jacob E" <jacob.e.keller@intel.com>,
Jakub Kicinski <kuba@kernel.org>,
Simon Wunderlich <sw@simonwunderlich.de>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"b.a.t.m.a.n@lists.open-mesh.org"
<b.a.t.m.a.n@lists.open-mesh.org>,
"stable@kernel.org" <stable@kernel.org>
Subject: Re: [PATCH 1/1] batman-adv: Broken sync while rescheduling delayed work
Date: Thu, 8 Jun 2023 12:01:15 +0300 [thread overview]
Message-ID: <ff68da6a-8594-b218-c62b-4ae8e1ffae0a@ispras.ru> (raw)
In-Reply-To: <CO1PR11MB5089F99A62265CE85CCB413CD650A@CO1PR11MB5089.namprd11.prod.outlook.com>
As far as I found the synchronization is provided by delayed work
subsystem. It is based on the WORK_STRUCT_PENDING_BIT in work->data field.
The cancel_delayed_work_sync() atomically sets this bit and
queue_delayed_work() checks it before scheduling new delayed work.
The problem is caused by the INIT_DELAYED_WORK() call inside
batadv_dat_start_timer(). This call happens before the
queue_delayed_work() call and clears this bit.
Best regards,
Vlad
On 08.06.2023 08:24, Keller, Jacob E wrote:
>
>> -----Original Message-----
>> From: Jakub Kicinski <kuba@kernel.org>
>> Sent: Wednesday, June 7, 2023 10:01 PM
>> To: Simon Wunderlich <sw@simonwunderlich.de>
>> Cc: davem@davemloft.net; netdev@vger.kernel.org; b.a.t.m.a.n@lists.open-
>> mesh.org; Vladislav Efanov <VEfanov@ispras.ru>; stable@kernel.org; Sven
>> Eckelmann <sven@narfation.org>
>> Subject: Re: [PATCH 1/1] batman-adv: Broken sync while rescheduling delayed
>> work
>>
>> On Wed, 7 Jun 2023 17:55:15 +0200 Simon Wunderlich wrote:
>>> The reason for these issues is the lack of synchronization. Delayed
>>> work (batadv_dat_purge) schedules new timer/work while the device
>>> is being deleted. As the result new timer/delayed work is set after
>>> cancel_delayed_work_sync() was called. So after the device is freed
>>> the timer list contains pointer to already freed memory.
>> I guess this is better than status quo but is the fix really complete?
>> We're still not preventing the timer / work from getting scheduled
>> and staying alive after the netdev has been freed, right?
> Yea, I would expect some synchronization mechanism to ensure that after cancel_delayed_work_sync() you can't queue the work again.
>
> I know for timers there is recently timer_shutdown_sync() which can be used to guarantee a timer can't re-arm at all, and its intended for some situations where there is a cyclic dependency...
>
> Thanks,
> Jake
next prev parent reply other threads:[~2023-06-08 9:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 15:55 [PATCH 0/1] pull request for net: batman-adv 2023-06-07 Simon Wunderlich
[not found] ` <20230607155515.548120-2-sw@simonwunderlich.de>
2023-06-08 5:00 ` [PATCH 1/1] batman-adv: Broken sync while rescheduling delayed work patchwork-bot+netdevbpf
2023-06-08 5:01 ` Jakub Kicinski
2023-06-08 5:24 ` Keller, Jacob E
2023-06-08 9:01 ` Vlad Efanov [this message]
2023-06-08 9:27 ` Paolo Abeni
2023-06-08 16:57 ` Sven Eckelmann
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=ff68da6a-8594-b218-c62b-4ae8e1ffae0a@ispras.ru \
--to=vefanov@ispras.ru \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=jacob.e.keller@intel.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stable@kernel.org \
--cc=sw@simonwunderlich.de \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).