Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5582788img; Wed, 27 Mar 2019 11:07:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9DSdULUG8m4JW2L07woOLbpE6WaBwDdV8i8m5fsd2RLwL4ExCPQBeNvRhIyK+/lG1s3pX X-Received: by 2002:a65:624c:: with SMTP id q12mr34671225pgv.75.1553710057225; Wed, 27 Mar 2019 11:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553710057; cv=none; d=google.com; s=arc-20160816; b=Hq8zWu2C2p/9C/8zauvwbYqB6w8tokbGQ7c5CJ8nY5JQo4r/4EqigQHPxJTTftDji2 MsTcDKWEDCIviiHuEGvVg+RahF0UPgZ1HqUgs5+wpOCwHlHvJGWCAKrTaPeCsg2zG0pk CH6V80Uvm0ydf0t1q64auIeoUitwx4mMGkf60w4mdtWLxnQe5GL5iXWqCt9NJq+QE4xz BVhinZK/Cl1eQbpDl/zMCtfJt6IHdbWbrZKPpH78UKo94G9dW6V18466AzfIb3Tq4Cgt 9XSPn/G1HQphuIv1lmXwRhEWv+XpGoiJ2+npS/5Niw8m/ZdrKm7fjSiUKoxXS1EjX9oG DVMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kIWdUE4YU6/gVXHzCeF8rTunV6XCijBbHxDM0akXVcA=; b=jsyuqgwUF0+nEUf8fMD0qh6kfR1mrVxR5fz/aYx+AKHgjKUFxYbQaOqozDoqziXA2w A/kDPNXjDXbhY/jM1dWJhaxLIxBiEGGbmSgkZE8TWmwKKX4LQp3jd3LzxP35Ysh4X8lq irnvSo3b5sGfFPw0H98AdxGhcSaLXJReXlMMze8xOE/tuvuMHOEp7KaoFbK1nMz5VL48 fPorLeb5E0dtTz7mZejfMpu3yZy/AaIp3mVu84KoVVnEr70/qYPQWeP7PiLZDp9ieZxH pJk+kDRSXX7iPXNkWGHdB5efqlIsQU2iEf25kknGXWE+sKN/gIrgkuZT1QcteDLavKLR mtqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iEPeH2HC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7si19195266pfb.69.2019.03.27.11.07.21; Wed, 27 Mar 2019 11:07:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iEPeH2HC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387462AbfC0SEr (ORCPT + 99 others); Wed, 27 Mar 2019 14:04:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:45530 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387434AbfC0SEo (ORCPT ); Wed, 27 Mar 2019 14:04:44 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1CE1C2063F; Wed, 27 Mar 2019 18:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709883; bh=/oYZVCgnCBklrRFTrSv6nhFinr/JaO+dksrUsFlPl2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iEPeH2HC8Uzfw45DZK9xQgYvIEJM8qdHTFIm8xqWhYH+8/RbVtsLVoqPu1anfvbHh xYPzfw/QEFgYpGD4256PJk9BuolwH+0W9KtvCqGH6jHV3y4a4kw1tANe734Zfj7rGc kiXvinOfx7kNmtWgwPlmbtt6RynDlBtkNaBp5XwM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jacob Keller , Anirudh Venkataramanan , Jeff Kirsher , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 088/262] ice: fix ice_remove_rule_internal vsi_list handling Date: Wed, 27 Mar 2019 13:59:03 -0400 Message-Id: <20190327180158.10245-88-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jacob Keller [ Upstream commit f9264dd687f8d3f9104c9900f8f3e5e419f27c55 ] When adding multiple VLANs to the same VSI, the ice_add_vlan code will share the VSI list, so as not to create multiple unnecessary VSI lists. Consider the following flow ice_add_vlan(hw, ) Where we add three VLAN filters for VIDs 7, 8, and 9, all for VSI 0. The ice_add_vlan will create a single vsi_list and share it among all the filters. Later, if we try to remove a VLAN, ice_remove_vlan(hw, ) Then the removal code will update the vsi_list and remove VSI 0 from it. But, since the vsi_list is shared, this breaks the list for the other users who reference it. We actually even free the VSI list memory, and may result in segmentation faults. This is due to the way that VLAN rule share VSI lists with reference counts, and is caused because we call ice_rem_update_vsi_list even when the ref_cnt is greater than one. To fix this, handle the case where ref_cnt is greater than one separately. In this case, we need to remove the associated rule without modifying the vsi_list, since it is currently being referenced by another rule. Instead, we just need to decrement the VSI list ref_cnt. The case for handling sharing of VSI lists with multiple VSIs is not currently supported by this code. No such rules will be created today, and this code will require changes if/when such code is added. Signed-off-by: Jacob Keller Reviewed-by: Bruce Allan Signed-off-by: Anirudh Venkataramanan Tested-by: Andrew Bowers Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/ice/ice_switch.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c index 2e5693107fa4..8d602247eb44 100644 --- a/drivers/net/ethernet/intel/ice/ice_switch.c +++ b/drivers/net/ethernet/intel/ice/ice_switch.c @@ -1538,9 +1538,20 @@ ice_remove_rule_internal(struct ice_hw *hw, u8 recp_id, } else if (!list_elem->vsi_list_info) { status = ICE_ERR_DOES_NOT_EXIST; goto exit; + } else if (list_elem->vsi_list_info->ref_cnt > 1) { + /* a ref_cnt > 1 indicates that the vsi_list is being + * shared by multiple rules. Decrement the ref_cnt and + * remove this rule, but do not modify the list, as it + * is in-use by other rules. + */ + list_elem->vsi_list_info->ref_cnt--; + remove_rule = true; } else { - if (list_elem->vsi_list_info->ref_cnt > 1) - list_elem->vsi_list_info->ref_cnt--; + /* a ref_cnt of 1 indicates the vsi_list is only used + * by one rule. However, the original removal request is only + * for a single VSI. Update the vsi_list first, and only + * remove the rule if there are no further VSIs in this list. + */ vsi_handle = f_entry->fltr_info.vsi_handle; status = ice_rem_update_vsi_list(hw, vsi_handle, list_elem); if (status) -- 2.19.1