From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41198C7EE2C for ; Fri, 26 May 2023 17:35:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237536AbjEZRfb (ORCPT ); Fri, 26 May 2023 13:35:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbjEZRf1 (ORCPT ); Fri, 26 May 2023 13:35:27 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E519CA4; Fri, 26 May 2023 10:35:26 -0700 (PDT) Received: from [10.10.2.69] (unknown [10.10.2.69]) by mail.ispras.ru (Postfix) with ESMTPSA id 25D1144C1026; Fri, 26 May 2023 17:35:25 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 25D1144C1026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1685122525; bh=dYeLF47soPl7A+3mco/KP4CbNt6s64UADpsf1OpQymM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=pVeC0NSqyg0BQdlFdDE7MRCx9srs21kp9uSABHpC+mn3dAYyafLGtt/eD76tf+2Cc GkzTa70/deJoETlL7/UJCZXxzSQB+7co8if99rWDXJD4aCK3oJu7c5W7LBs0HHDBQx g5rpo9OEg2lALO1J/ndZkhVMg1Mpxn+mNxWXoOpY= Message-ID: <09834e8d-ca48-e21d-fd96-9de87294a7f4@ispras.ru> Date: Fri, 26 May 2023 20:35:25 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] batman-adv: Broken sync while rescheduling delayed work Content-Language: ru To: Sven Eckelmann , Marek Lindner Cc: Simon Wunderlich , Antonio Quartulli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , b.a.t.m.a.n@lists.open-mesh.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org References: <20230526161632.1460753-1-VEfanov@ispras.ru> <5834562.MhkbZ0Pkbq@bentobox> From: Vlad Efanov In-Reply-To: <5834562.MhkbZ0Pkbq@bentobox> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sven, cancel_delayed_work_sync() and queue_delayed_work() use WORK_STRUCT_PENDING_BIT in work->data to synchronize. INIT_DELAYED_WORK() clears this bit. The situation is :  __cancel_work_timer() sets WORK_STRUCT_PENDING_BIT but INIT_DELAYED_WORK() in batadv_dat_start_timer() clears it and queue_delayed_work() schedules new work. Best regards, Vlad. On 26.05.2023 19:49, Sven Eckelmann wrote: > On Friday, 26 May 2023 18:16:32 CEST Vladislav Efanov 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. > You are most likely right but could you please point out what in the worker is > checked by the workqueue code that prevents it from being scheduled again? > (and which seems to be overwritten as your patch seems to suggest) > > I think __cancel_work_timer marked the work as canceling but > batadv_dat_start_timer reinitialized the worked (thus removing this important > state). Would be nice if you could either correct me or confirm what I think to > remember. > > Kind regards, > Sven