Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1859756pxb; Mon, 13 Sep 2021 07:05:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwronizZIai9yrX5IWvb7wQ+y23tqtAdw4t8Rj0S7IIkrWUjFo4FB4BUZU6PFfyO7NCl1ZA X-Received: by 2002:a05:6638:32a0:: with SMTP id f32mr9773855jav.69.1631541949332; Mon, 13 Sep 2021 07:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631541949; cv=none; d=google.com; s=arc-20160816; b=UKDx9+Is1WktyyRmueeiYt78OIVICrzN5RRfueGGGq0/1nGEJCYsyTsHG5JNlzRU8f oP5fqcaaTTPbsA9fVFPzWj0ecLlkyRDsFz01Tsr2cuAhQGNl3ROfRZPDouSGpWMAkjlR +K4+qfZX0q3Y3lGAfiyiLGJeWXRasricW0j5tBBjTW3uYmhm2/3c76xQasqumaq+77mu Q4abpjoATLo7X4t3e9A4ZC/3ZHkj0LI8LGjXbvsLaJ/YWakt+5maZmAh4j+hRwXNPe9a WtxHrMgr2TOGQBCXmRR8kB7AtOgVKgxZ/X2XiiK78xoF/yAYfrrr4q2X4Xrvd52GqI2z 86dQ== 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=poVXImIfyTnyFQZosN2lhjjYF6Ra7caE8x/YivTXzWkRPSvvtkD4KeLWR1GAuj/pTM zE4XXpmcpnUlEokO2za+WBT9O++oO4tKfLqditj3eGGJmJzP0bkCElOa3xr1QdVOH3Zd OsJJtMG+7p/w5GGFKrVcjRYSTaMll4rDen+A87F3oxnV/kXiu0nzGmDUfagHw2c0q8vA USMoyZeToVwC7QoZoYNF6zu/3GIgoWWrKt3xpwVfchtgwXGuJAx9a0QBETQfbfwWKlnl 0MaTFhGT8btt/y8/didPhBzPErEarnsYOjULGTb5lUBVtRx7VsR8WuQ6WqfzNXWFp74z kZNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WJLb3Mu0; 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 h15si7828970ili.51.2021.09.13.07.05.35; Mon, 13 Sep 2021 07:05:49 -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=WJLb3Mu0; 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 S244864AbhIMOFc (ORCPT + 99 others); Mon, 13 Sep 2021 10:05:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:50984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244423AbhIMOBf (ORCPT ); Mon, 13 Sep 2021 10:01:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A0690613CD; Mon, 13 Sep 2021 13:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540284; bh=tvAYll6S3yFcBQZWiU3XvFXaCtGmkSUeThnCmg2wkBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WJLb3Mu0qaz8bF55ITEvY0NB7j+Ue0hcrIasja8lKMYw1CODdC9DcLukyyT1KWGGy me9UNdRBVQmbjFOXgBAAl4zbhALVxtgoRE1fV5+yGkC6ZmFNvJLS2+orHHj0D5mM1O s1Wn7BuP5WP5VRglbIzuphFdmdWO4XysCo+Bc7v8= 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.13 097/300] i40e: improve locking of mac_filter_hash Date: Mon, 13 Sep 2021 15:12:38 +0200 Message-Id: <20210913131112.650079077@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@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