Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp161086pxb; Mon, 13 Sep 2021 15:55:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVFjaNU3PQJitvAAbEkyGoHVLVRzXfy8TxmOAcpuNnj+bxozafngUDwz0Pve4qqV3Z3BVm X-Received: by 2002:a05:6402:5:: with SMTP id d5mr15816964edu.359.1631573757811; Mon, 13 Sep 2021 15:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631573757; cv=none; d=google.com; s=arc-20160816; b=W/gWOklp2cDjBU7DEwPtZ516Jw2fXMj2kfAUcTMcMtHePvPKmO+MTv4Y8txQnYhpPi gC4vQG39HCIocDX2YF3W0G1OSH5dOXHdXA4yYOEX3eU9lUhEcUPd6ijz9HoUeS5YxA4v 1kQ0rfDmLvWFNrz8lGvNzBJbkWDP57HA/kUhVt2QxyLwnjM7ADcugheCHezMt+9Of/si TqAtyy7iWZbN8Gw/YmMHUjeGXrCG2xKos5p8K2z9rrbvoJhRFq33/kH8Ei8YXRUYJM6s nL3jKNHPzh0lpoPx6TOtHmTDS9u6U9bstv5/k+RM3vZ6Rg75KeArlkdQq57GGXDT+cmU Nrxg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YTT/cYfpvrEF5xKIunadSjpnAwIx9j7bXY/Jy+fgTNE=; b=PRMBFI03o2NZ5ZD+xqPU/oZCA+srdtgFtwLjBiitbnkwrWmJahkt3DUKnLsUjJ3ftu +PMp7R0sKjAZgMzT5HGAmmkax6Uyqlz2tXwOLbLPvqDbGJnhdNKehERyfb/YJ7agn7Q2 i6tHHslgdXMSG5hlrzSi94nu6rG0hPJ4sUFjVSayr96yW+xXnYV7yDOWHH1pyX5HX/+p 4nTZAVzZ891vwLqmTB066rJoT8hwl7sqQJ7iLPS6Dho2mldjpH7OrGiPcqq6LQo/Ur38 eM7LNvUpiYUgk1zszulxMMiQHm/SaFV0X2lARfGTF40xhyYB1xdmud7qtCU4/pXP2vRh Lc7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="g/ut4ZFB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u18si8675272ejk.196.2021.09.13.15.55.32; Mon, 13 Sep 2021 15:55:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="g/ut4ZFB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245024AbhIMOdU (ORCPT + 99 others); Mon, 13 Sep 2021 10:33:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:48696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346764AbhIMO3f (ORCPT ); Mon, 13 Sep 2021 10:29:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7962161368; Mon, 13 Sep 2021 13:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631541032; bh=tvAYll6S3yFcBQZWiU3XvFXaCtGmkSUeThnCmg2wkBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g/ut4ZFBMYrRqhI78HP6s6DL5pCktr95tz/4lj5S1lVKrxrjsZEboJLTNdo+zHu4a DwwvpmOm8G3gjUmE+DgOM1eOM/cTIwqNq6yFo9dTB4ikPUg9kc85fIYozh0unZGDYw W6NtRpPCm+IIet41zfhx+rwR0U27PjQZtq8fjSJw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefan Assmann , Konrad Jankowski , Tony Nguyen , Sasha Levin , Paolo Abeni Subject: [PATCH 5.14 101/334] i40e: improve locking of mac_filter_hash Date: Mon, 13 Sep 2021 15:12:35 +0200 Message-Id: <20210913131116.785913637@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131113.390368911@linuxfoundation.org> References: <20210913131113.390368911@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Assmann [ Upstream commit 8b4b06919fd66caf49fdf4fe59f9d6312cf7956d ] i40e_config_vf_promiscuous_mode() calls i40e_getnum_vf_vsi_vlan_filters() without acquiring the mac_filter_hash_lock spinlock. This is unsafe because mac_filter_hash may get altered in another thread while i40e_getnum_vf_vsi_vlan_filters() traverses the hashes. Simply adding the spinlock in i40e_getnum_vf_vsi_vlan_filters() is not possible as it already gets called in i40e_get_vlan_list_sync() with the spinlock held. Therefore adding a wrapper that acquires the spinlock and call the correct function where appropriate. Fixes: 37d318d7805f ("i40e: Remove scheduling while atomic possibility") Fix-suggested-by: Paolo Abeni Signed-off-by: Stefan Assmann Tested-by: Konrad Jankowski Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- .../ethernet/intel/i40e/i40e_virtchnl_pf.c | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c index eff0a30790dd..472f56b360b8 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c @@ -1160,12 +1160,12 @@ static int i40e_quiesce_vf_pci(struct i40e_vf *vf) } /** - * i40e_getnum_vf_vsi_vlan_filters + * __i40e_getnum_vf_vsi_vlan_filters * @vsi: pointer to the vsi * * called to get the number of VLANs offloaded on this VF **/ -static int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi) +static int __i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi) { struct i40e_mac_filter *f; u16 num_vlans = 0, bkt; @@ -1178,6 +1178,23 @@ static int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi) return num_vlans; } +/** + * i40e_getnum_vf_vsi_vlan_filters + * @vsi: pointer to the vsi + * + * wrapper for __i40e_getnum_vf_vsi_vlan_filters() with spinlock held + **/ +static int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi) +{ + int num_vlans; + + spin_lock_bh(&vsi->mac_filter_hash_lock); + num_vlans = __i40e_getnum_vf_vsi_vlan_filters(vsi); + spin_unlock_bh(&vsi->mac_filter_hash_lock); + + return num_vlans; +} + /** * i40e_get_vlan_list_sync * @vsi: pointer to the VSI @@ -1195,7 +1212,7 @@ static void i40e_get_vlan_list_sync(struct i40e_vsi *vsi, u16 *num_vlans, int bkt; spin_lock_bh(&vsi->mac_filter_hash_lock); - *num_vlans = i40e_getnum_vf_vsi_vlan_filters(vsi); + *num_vlans = __i40e_getnum_vf_vsi_vlan_filters(vsi); *vlan_list = kcalloc(*num_vlans, sizeof(**vlan_list), GFP_ATOMIC); if (!(*vlan_list)) goto err; -- 2.30.2