Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2260742pxm; Fri, 4 Mar 2022 12:33:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbZXViJBgXM8O16Mr3L+K9NiS46zAUHI4ZiHkUvIkEzBaSLKvE1ZvZiyzy5o1x9XhwnNDf X-Received: by 2002:a63:788c:0:b0:374:87b6:a9d2 with SMTP id t134-20020a63788c000000b0037487b6a9d2mr138022pgc.303.1646426000618; Fri, 04 Mar 2022 12:33:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646426000; cv=none; d=google.com; s=arc-20160816; b=b9dVBgBg2E+GXpCGnVAatJhpnpNjjYC/aU+OgQ1XAOVsdLD2+kjyz3Jl8Q7hGDIKOC +0qX4guoGpvEhYxeZiqYs2mYs0jw7IvQGv8qfV6c7cN06WkScvFild5R1/OX8zt4ZLXb cJpqO2xqilc2Cgn8CnidChzMqi0hmcWMoVMLdjvHofR+I0TXQoisGdCkD7Rwn2pD4Tdy ESyaj8Gw5OrqbJxpPyJ63VfxxSG5DPOjcsOIRQbq0Q1FZrrZzRudgu7M46S9/ZmnzOkT FbBuc65K/FNlzg4ywXjc2WGoieAE5cWhojeU/HLrXDFLMsaMai18w0o4m9Z+UKJW/3YP B3Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=XPo646Lh4bAU5kxG3smqO0CDWOi5ehE4dmIoAiLUrjE=; b=TlYNPQ8AS7xh8nlsCzsRycbmSaJY15TKV6vyOtF4DITm/EyJejjaOFlGRG/pbrByDA Bf6ie/X6uZj9tdlVVuz6HODJ9j9TS3cKhkRg+B6RFUIlV7yZyAnYlxn4zmocT2WFfvCq JdOUBCt7/vbqxnbjmyuXs/jULBpQgL4afL5JwrE/ZK8P169ENQ4xHDFu7htvi0qozv9j 4qqpVgQQFNHzdFdMwUne5DUWqKk/xGGk1eRoQ581bQIYB/WGVNcYSZeCRbpQSg6MgGoM gfgWHXUlj4j1bvDKvLBlMPQA4WKME8oO7IIhItA2Psox7SOwpHHYfuln6IUpHbsAH/97 qlmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=aM+zvgew; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=dvG6jG9B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l11-20020a63f30b000000b0036508fa5174si3960082pgh.440.2022.03.04.12.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 12:33:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=aM+zvgew; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=dvG6jG9B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 019BB2C1B7E; Fri, 4 Mar 2022 11:37:44 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234883AbiCDKbr (ORCPT + 99 others); Fri, 4 Mar 2022 05:31:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234464AbiCDKbo (ORCPT ); Fri, 4 Mar 2022 05:31:44 -0500 X-Greylist: delayed 328 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 04 Mar 2022 02:30:57 PST Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3780116BCE6 for ; Fri, 4 Mar 2022 02:30:57 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 889845C0368; Fri, 4 Mar 2022 05:25:27 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 04 Mar 2022 05:25:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; bh=XPo646Lh4bAU5kxG3smqO0CDWOi5eh E4dmIoAiLUrjE=; b=aM+zvgewHBBuWFY0jI9+VlTD5h0RwmPbUhfGfTQ875169S O/BYkm+f5Gmh0+1nJAEguccAKlCOeHgN+WyDmBLOXvw6W0fHeCdeGvjfv8kEw2y6 WMPRu10tUbVb6DPVS2rePVjVKL26hcWdAxv4xnwqdLpLxgmnZWHooGamvB5/oYhm f3L0eFRmy8TxWhmJBgiM5vgvMzWQz1Pbo13diU2XcTFCy8jxlD0srDc4979q8ts+ oTHBXZHxG55avJ8xpFbQKLqbikhWzJzqNIBkG0y4OWt3GQ+wWID+agVcVNfddmp7 ND3ShSGYHMQ0cF82D0MIYBQCyc5ZcIyxWPz2FVsg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=XPo646Lh4bAU5kxG3 smqO0CDWOi5ehE4dmIoAiLUrjE=; b=dvG6jG9BHHGf8pbvATEXsXL0EgPg+I63O fpUgKLr5PR93kcEbr5Vh19kj32UK071+iOADjRiN3qO1m3y1p+jv0ePdFsj9vd12 HEBboxKVy4aKLV0yjAbrrqe9cP6ertJ3Qw1+pvAypax8Dmv6dwXMOs9P6iQ2FGDr 6vgfZdrhpYj/XKj5KZFkA3fvEJDqRSqoviy24GGhnV4d3RRGC+mz+XGPN2m/4mia z/t927NflYaQOI/+1CH+30FT6CPa6A8Tn/Kavb068rnNjGoLhwTBu6cw3GZkxfaE fz0M23begueXYjGXu+JkNDhgk0QwQJuPsc2O5vXHJ4HzFzUykVppg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddruddtkedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefvrghkrghs hhhiucfurghkrghmohhtohcuoehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjh hpqeenucggtffrrghtthgvrhhnpeelhfeugedvjefgjefgudekfedutedvtddutdeuieev tddtgeetjeekvdefgeefhfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 4 Mar 2022 05:25:26 -0500 (EST) Date: Fri, 4 Mar 2022 19:25:23 +0900 From: Takashi Sakamoto To: Niels Dossche Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] firewire: core: extend card->lock in fw_core_handle_bus_reset Message-ID: Mail-Followup-To: Niels Dossche , linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <20220303183038.54126-1-dossche.niels@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220303183038.54126-1-dossche.niels@gmail.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hi, On Thu, Mar 03, 2022 at 07:30:38PM +0100, Niels Dossche wrote: > card->local_node and card->bm_retries are both always accessed under > card->lock. > fw_core_handle_bus_reset has a check whose condition depends on > card->local_node and whose body writes to card->bm_retries. > Both of these accesses are not under card->lock. Move the lock acquiring > of card->lock to before this check such that these accesses do happen > when card->lock is held. > fw_destroy_nodes is called inside the check. > Since fw_destroy_nodes already acquires card->lock inside its function > body, move this out to the callsites of fw_destroy_nodes. > Also add a comment to indicate which locking is necessary when calling > fw_destroy_nodes. > > Signed-off-by: Niels Dossche > --- > drivers/firewire/core-card.c | 3 +++ > drivers/firewire/core-topology.c | 9 +++------ > 2 files changed, 6 insertions(+), 6 deletions(-) It looks good to me and is preferable as Niels said. Reviewed-by: Takashi Sakamoto Tested-by: Takashi Sakamoto I think the patch is for minor code refactoring rather than bug fix since it is unlikely that the rate condition occurs. The bus_reset_work is synchronously canceled in the beginning of pci_remove(). ``` pci_remove() ->cancel_work_sync(&ohci->bus_reset_work); ->fw_core_remove_card(&ohci->card); ->software_reset(ohci); ->free_irq(dev->irq, ohci); ``` But I have no confidence that the above calls are done in the order by processor... > diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c > index 54be88167c60..f3b3953cac83 100644 > --- a/drivers/firewire/core-card.c > +++ b/drivers/firewire/core-card.c > @@ -668,6 +668,7 @@ EXPORT_SYMBOL_GPL(fw_card_release); > void fw_core_remove_card(struct fw_card *card) > { > struct fw_card_driver dummy_driver = dummy_driver_template; > + unsigned long flags; > > card->driver->update_phy_reg(card, 4, > PHY_LINK_ACTIVE | PHY_CONTENDER, 0); > @@ -682,7 +683,9 @@ void fw_core_remove_card(struct fw_card *card) > dummy_driver.stop_iso = card->driver->stop_iso; > card->driver = &dummy_driver; > > + spin_lock_irqsave(&card->lock, flags); > fw_destroy_nodes(card); > + spin_unlock_irqrestore(&card->lock, flags); > > /* Wait for all users, especially device workqueue jobs, to finish. */ > fw_card_put(card); > diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topology.c > index b63d55f5ebd3..f40c81534381 100644 > --- a/drivers/firewire/core-topology.c > +++ b/drivers/firewire/core-topology.c > @@ -375,16 +375,13 @@ static void report_found_node(struct fw_card *card, > card->bm_retries = 0; > } > > +/* Must be called with card->lock held */ > void fw_destroy_nodes(struct fw_card *card) > { > - unsigned long flags; > - > - spin_lock_irqsave(&card->lock, flags); > card->color++; > if (card->local_node != NULL) > for_each_fw_node(card, card->local_node, report_lost_node); > card->local_node = NULL; > - spin_unlock_irqrestore(&card->lock, flags); > } > > static void move_tree(struct fw_node *node0, struct fw_node *node1, int port) > @@ -510,6 +507,8 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation, > struct fw_node *local_node; > unsigned long flags; > > + spin_lock_irqsave(&card->lock, flags); > + > /* > * If the selfID buffer is not the immediate successor of the > * previously processed one, we cannot reliably compare the > @@ -521,8 +520,6 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation, > card->bm_retries = 0; > } > > - spin_lock_irqsave(&card->lock, flags); > - > card->broadcast_channel_allocated = card->broadcast_channel_auto_allocated; > card->node_id = node_id; > /* > -- > 2.35.1 Regards Takashi Sakamoto