Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2788139rwd; Fri, 26 May 2023 11:10:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ734NQeL3cJfiKXLCoO1ZjeCmVH7npu8n8Vuw3X+lr9skbp7/20C1qd2bWtlMg5ex6IS+O7 X-Received: by 2002:a17:902:e806:b0:19d:297:f30b with SMTP id u6-20020a170902e80600b0019d0297f30bmr4697258plg.19.1685124658699; Fri, 26 May 2023 11:10:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685124658; cv=none; d=google.com; s=arc-20160816; b=BfVd9AGU2ngCWIHdBnjIwt4a6Rh1K/iOKggUkJtSby0oLkrnC+2JhTW2yBCWKDHmML CWwx2v8NojYUlK08E84osFK5+Kdv6OZAT3+nG4F/9CrrRV9lhfK0zNDkkUp94FmoeLSm qcbrFfmVPwwSEwt9+PdKNS/hH13uwLRIIvnzKQLsGDWHnURWwXwKk0DNgZNu5hlSejJ5 S+5HfLlOC31qDyVt2WG/TLee2KmTCpcJ3JjDeIWxqDRtnN2ToWtL8nHebTMEkxS07Uqk Qjni36LANGSbnus85xORuBMmor4VxgNwRsjPvrZmkkqkPa6oNlDi8drEYn1iVjPyy1R5 CGkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-filter; bh=dYeLF47soPl7A+3mco/KP4CbNt6s64UADpsf1OpQymM=; b=vSVDQ9EFOAaSTqwDa2SEBtW6PP44Or94tm5MqYWo1Bf6M5zB1BYGZ9ZHOZhtm9lMq4 Eo4mLO1aRkvVv5qoBwlYieCXZBbsEHKrgeJ92pvEdUAukH35Qp+GdPllI2Tn4lYmWFso irTLDCuptwCphNpPODnOqnmXLxQWm60OA0TEweVad4nD2ZwY2cfg9lFmV+W4opDdNoqm hvkC/YMoWR3ofULZIZtQpee8wAUiYhgF1Wbcpqk/ly6X6AcgM9MYBKwY+6PdiJAOr3do gxgAf56uOgwDBqj+EClQ/mF7/GEHrkqpJ/YjnKcBshxqe4UpYJglNa+hkKTCRwRx/Xlk Ztkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=pVeC0NSq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g18-20020a170902869200b001ae4b4527b3si4216748plo.290.2023.05.26.11.10.43; Fri, 26 May 2023 11:10:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=pVeC0NSq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237280AbjEZRfa (ORCPT + 99 others); Fri, 26 May 2023 13:35:30 -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 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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