Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4490394rwb; Mon, 8 Aug 2022 01:42:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR5dxaptDfu1sapjN9FF2E8q02v063xsXYIsM4pUJedUUVlEOkZZUzEhN26srhhF+dOEu926 X-Received: by 2002:a05:6402:5193:b0:43e:1d52:fd70 with SMTP id q19-20020a056402519300b0043e1d52fd70mr16727457edd.150.1659948120694; Mon, 08 Aug 2022 01:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659948120; cv=none; d=google.com; s=arc-20160816; b=e7aBC80A2ZNtdXjfrjxrPfoBa69uKTku09ecgwXZonq254vcoNAnOs9bpBa8jV6uQ4 VX9Fr8l27u8UPCxTTDjGZILyAWfUNpYEzsP+q+POoesTWEpnYR5QFZgzO7kVwa5qwzLt J0n59zsZHLrnQNbO3++NptbPk0CQRFAGoQUdZ02ZvvLOajd7gwkPY3rsQZtoy0JcdgHh bmWbhRDxlNjiq8ZaW9C7KeSeiW2Eid9Ka0bA2JBmlYS6FhhCAJeK7aF6yLnuD2O2Pqvy l/vxWA1awHZKxg/fEqzdMtZCzg1muQCzdpywUB4K0rCacfFN8GibZnbRaH2gZZC/euym F7zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Z7E2N2s8bPEPGvkAyxtXl9V/M8/+looRAJqVMy9kWw4=; b=Ay3X9+l2IY4grvWgyQWG28NU8ZJm742ooHkeCMoKlzk2JAWSMULGtvaw5T0rQVWMdo G4JicwpQLq9bqg111qZyqeIX6zp6gPHBfNsBaYiynAGd0tjSxYpVvT20WUXYoZSFEqw1 D3xpqDPHxfJXPVNQpsZ6jmXR0xs+ybKcuIQQYdNplok7lCjsGnGtv3UlBcqbv+7LOPv5 Im1/nEVXOeZTze+tASsy/FeSM4YUFyJvrJFsVeg7YyAU+6BO0B6kevlhQFLF1ae0j1jq GxvfT/iEhSmXH0IcthDfxbgbDc/RPrLp5SxvhcR98Eyd1M0xcAYR6h9VXJmuWAtcl/Zv M/Pw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t18-20020a1709067c1200b007309910699bsi5790374ejo.673.2022.08.08.01.41.35; Mon, 08 Aug 2022 01:42:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242093AbiHHIMH (ORCPT + 99 others); Mon, 8 Aug 2022 04:12:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235829AbiHHIMF (ORCPT ); Mon, 8 Aug 2022 04:12:05 -0400 Received: from zju.edu.cn (mail.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4CCD610FE0; Mon, 8 Aug 2022 01:12:03 -0700 (PDT) Received: from localhost.localdomain (unknown [10.12.77.33]) by mail-app2 (Coremail) with SMTP id by_KCgC3v_c6xfBiCvV1Ag--.31789S4; Mon, 08 Aug 2022 16:11:38 +0800 (CST) From: Lin Ma To: jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: Lin Ma Subject: [PATCH v0] idb: Add rtnl_lock to avoid data race Date: Mon, 8 Aug 2022 16:10:50 +0800 Message-Id: <20220808081050.25229-1-linma@zju.edu.cn> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: by_KCgC3v_c6xfBiCvV1Ag--.31789S4 X-Coremail-Antispam: 1UD129KBjvJXoW7KF1rJr1kWFWDtF18Wr1DGFg_yoW8Ww4kpF s8GryxKr10qF47WaykJ3W8AFyYga1qy34rG3W7uw4ruan8JryjvrWUKFyrZ34FkrWru39I vr4Yvw4fAFyDArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvm1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJr0_GcWl84ACjcxK6I8E 87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c 8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_ Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwI xGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IY c2Ij64vIr41l42xK82IY6x8ErcxFaVAv8VW8uw4UJr1UMxC20s026xCaFVCjc4AY6r1j6r 4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF 67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2I x0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnU UI43ZEXa7VUbXdbUUUUUU== X-CM-SenderInfo: qtrwiiyqvtljo62m3hxhgxhubq/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 The commit c23d92b80e0b ("igb: Teardown SR-IOV before unregister_netdev()") places the unregister_netdev() call after the igb_disable_sriov() call to avoid functionality issue. However, it introduces several race conditions when detaching a device. For example, when .remove() is called, the below interleaving leads to use-after-free. (FREE from device detaching) | (USE from netdev core) igb_remove | igb_ndo_get_vf_config igb_disable_sriov | vf >= adapter->vfs_allocated_count? kfree(adapter->vf_data) | adapter->vfs_allocated_count = 0 | | memcpy(... adapter->vf_data[vf] In short, there are data races between read and write of adapter->vfs_allocated_count. To fix this, we can add a new lock to protect members in adapter object. However, we cau use the existing rtnl_lock just as other drivers do. (See how dpaa2_eth_disconnect_mac is protected in dpaa2_eth_remove function). This patch adopts similar fixes. Fixes: c23d92b80e0b ("igb: Teardown SR-IOV before unregister_netdev()") Signed-off-by: Lin Ma --- drivers/net/ethernet/intel/igb/igb_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index d8b836a85cc3..e86ea4de05f8 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -3814,7 +3814,9 @@ static void igb_remove(struct pci_dev *pdev) igb_release_hw_control(adapter); #ifdef CONFIG_PCI_IOV + rtnl_lock(); igb_disable_sriov(pdev); + rtnl_unlock(); #endif unregister_netdev(netdev); -- 2.36.1