Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1840125pxb; Mon, 13 Sep 2021 06:42:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtKTWZ2szw62xZSbc0RDTw3kAcHPvB9wOiDSDgkfUlHt4ecYvW3MKFU/BfRilxcAHwqTug X-Received: by 2002:a05:6e02:20e7:: with SMTP id q7mr8474934ilv.212.1631540533989; Mon, 13 Sep 2021 06:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631540533; cv=none; d=google.com; s=arc-20160816; b=PwuqaMaUmv6/J/jPgauOMPDlPM397Upo0C0gRLSnsTK/6FBiPtv9oVkbW23pdy0gJ8 OH1coj3eat7ZVrjIvfla8BpAsdvqhHpusggqHJaYHHZUDpemxeb4sOgsxHgjkfOfM+SN GGl85auK/nocw8gt/dLPtsPLrA0geyLD7EGF+CA3ZkhXErJudKMfr4h62o+Rw5SdEyLI xffwsoTHQKSa+Gj7iCYf90Y08xmms8KWXaJqRa9KvmTypBblY2shvfduaG8FqeDXADWZ DawNf/IlufTqzaGD2ftMWWFXeaQ6TJA2BgJy1k39rUC9p4DrsUrCSHU2rETJpAFH+3QR 3D9A== 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=I5BYuMuPDLGLx6TJu1cNf9YSHvxjHZW6rvBVgxFd8Hw=; b=lHEIEdUnX/ifir1iZsGVAaRI3UVDL6WViC692WbTsa2aC4+IfZETaM1JFjHjFluKDL ZH7ygY9n8XFBrKXPu9T4RZX9gFtYskQPGZKdcvE4dsPyu4i+6klz6rhPZztcEzqCnyWz 8LmE84pAGj69OC1pqz2PMEYDQYOddIRC3SnFMAyUF92N/IUJPRkX4C6lWLyXZIqWK67n iqcXJZnu4jj+i29ijG5COZ2QjsREM/QV0rhrHlS9rRUbwAziDRrVJzs1I3MiZENY6ZAP 4OzIP2oMpF3o3J3Mq1MmC33vEv+bJD/3qVgj8tZcpQTvhTX4P/XIS+/4inmx8GjijYLp 7XCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nZXJazo8; 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 f5si7327920ils.120.2021.09.13.06.42.02; Mon, 13 Sep 2021 06:42:13 -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=nZXJazo8; 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 S241204AbhIMNkS (ORCPT + 99 others); Mon, 13 Sep 2021 09:40:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:32892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242944AbhIMNeg (ORCPT ); Mon, 13 Sep 2021 09:34:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7F8EA61209; Mon, 13 Sep 2021 13:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539594; bh=uKrNE2LSeeJMdBjhDw/gA4UAWVuBNAGvWIlywK0v8aY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nZXJazo8rTZ6goqoGiyxcyFHngzR0SMZ8oTiXbdV4tq39WJcz5Wm1izIpyPweM/s0 1XxsOGUoiCn44yrgtX01LA9BvpVxWZiCN/7GgkXc3EZ7GY+QC0hqu0CobVO+TnURsy 7OfQkF0qdPmCsUNpmhFMqMo0rAeoPejdDKduPhTw= 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.10 084/236] i40e: improve locking of mac_filter_hash Date: Mon, 13 Sep 2021 15:13:09 +0200 Message-Id: <20210913131103.214694704@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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 e4f13a49c3df..a02167cce81e 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c @@ -1107,12 +1107,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; @@ -1125,6 +1125,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 @@ -1142,7 +1159,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