Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp553255pxu; Sun, 22 Nov 2020 19:21:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZO66Ww0kB5X4JYOcJZfCayTYEwc1vSSXed9+0fO7eFu6uj73EeEcZtvUKYL9W18U8WoGk X-Received: by 2002:a50:a1c6:: with SMTP id 64mr20203343edk.156.1606101664681; Sun, 22 Nov 2020 19:21:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606101664; cv=none; d=google.com; s=arc-20160816; b=vRpdOIMjXi8IO62HcPmA9FjaxLVm4QPLJiDB4vHmwUJWjKh5SVwsFp6IdG6XoeXDDS s/isfR2vKgE+S/y4jdjzfxNsG9f+kpztKCCmNTs4Hj66mREU8+ZfEssRW4PMXFG0HTAl RtTBBOd6oX5VOXwpFg1o09ZsnSKAXq8IRenTkkFCqGhEC41KAIH1n4IMJPMaaw9Cyf5i 6mHexlMMlctqFYt1MEdeoLnIdFt8Vr646hQ4jnUb7h8GkoCArjgUYmHc+bnAPwP4D+MT F106Uz4JlSkoLQTHTW6noYjNHHqus0CHrpe3uXOKnjVuDcPIqItTVj0pPKAsUFZx5ol2 SG6w== 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:dkim-signature; bh=IpGdwt8jdg4GGv7ektWNsDixKkYiXczr59YjdWQtig8=; b=i0tAtqIdofaHbRg6KP7jynmzICAY7xTrUOOIN8fDFozKQBaSyv5oUMICac5wzUFm3q GY3iQ88YZJCNX5qUqHGJ9p5aC63CYTE8I59Ciu1m6uANJwaJzg8hcW2Af85Iv843gyQ5 5C0K4RcLVT6WQ9EjAfZOt6SknY/wMmTnuFqHbEMGhvFPILOzizzWgLLzPdrNz9DGaaqS ZZCU7ogGUIGUfS2JlTQ8t+DYoO76Ei4T6AxU9kB10ifGBNRtuKGWimfsI5IzmKEtCn46 EPCp/xEIE8oyuDk9rf1X1GpIGkKUkN+hG9nBN6HdgUSLIKYmhbhjKmLJlrlwuEj+2a9o iZZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Th6uCyML; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p13si6134626edm.325.2020.11.22.19.20.42; Sun, 22 Nov 2020 19:21:04 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=Th6uCyML; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727477AbgKWDRb (ORCPT + 99 others); Sun, 22 Nov 2020 22:17:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35207 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727247AbgKWDRb (ORCPT ); Sun, 22 Nov 2020 22:17:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606101449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=IpGdwt8jdg4GGv7ektWNsDixKkYiXczr59YjdWQtig8=; b=Th6uCyMLFuWoV8ochgn8HEizx33lAife42G9bxFiQHv5xuedK24W9znOFUd9pBOiSJ0JtG Dt8MV7iETIeuQzvK8i/fkd3JvE3Wjqy3F3y9GrCkptKjP8BiiDv51y+3zHD5s+o587HEvy S6Gr4M0xpEe1iwUiDgxI5SVGPcvE/N0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-s5HL3oc_O7K-W82RV-NkAQ-1; Sun, 22 Nov 2020 22:17:28 -0500 X-MC-Unique: s5HL3oc_O7K-W82RV-NkAQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47B871005D71; Mon, 23 Nov 2020 03:17:26 +0000 (UTC) Received: from f33vm.wilsonet.com.wilsonet.com (dhcp-17-185.bos.redhat.com [10.18.17.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id 643F160BF3; Mon, 23 Nov 2020 03:17:21 +0000 (UTC) From: Jarod Wilson To: linux-kernel@vger.kernel.org Cc: Jarod Wilson , Ivan Vecera , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , "David S. Miller" , Jakub Kicinski , Thomas Davis , netdev@vger.kernel.org Subject: [PATCH net] bonding: fix feature flag setting at init time Date: Sun, 22 Nov 2020 22:17:16 -0500 Message-Id: <20201123031716.6179-1-jarod@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Have run into a case where bond_option_mode_set() gets called before hw_features has been filled in, and very bad things happen when netdev_change_features() then gets called, because the empty hw_features wipes out almost all features. Further reading of netdev feature flag documentation suggests drivers aren't supposed to touch wanted_features, so this changes bond_option_mode_set() to use netdev_increment_features() and &= ~BOND_XFRM_FEATURES on mode changes and then only calling netdev_features_change() if there was actually a change of features. This specifically fixes bonding on top of mlxsw interfaces, and has been regression-tested with ixgbe interfaces. This change also simplifies the xfrm-specific code in bond_setup() a little bit as well. Fixes: a3b658cfb664 ("bonding: allow xfrm offload setup post-module-load") Reported-by: Ivan Vecera Cc: Jay Vosburgh Cc: Veaceslav Falico Cc: Andy Gospodarek Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Thomas Davis Cc: netdev@vger.kernel.org Signed-off-by: Jarod Wilson --- drivers/net/bonding/bond_main.c | 10 ++++------ drivers/net/bonding/bond_options.c | 14 +++++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 71c9677d135f..b8e0cb4f9480 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -4721,15 +4721,13 @@ void bond_setup(struct net_device *bond_dev) NETIF_F_HW_VLAN_CTAG_FILTER; bond_dev->hw_features |= NETIF_F_GSO_ENCAP_ALL; -#ifdef CONFIG_XFRM_OFFLOAD - bond_dev->hw_features |= BOND_XFRM_FEATURES; -#endif /* CONFIG_XFRM_OFFLOAD */ bond_dev->features |= bond_dev->hw_features; bond_dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX; #ifdef CONFIG_XFRM_OFFLOAD - /* Disable XFRM features if this isn't an active-backup config */ - if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) - bond_dev->features &= ~BOND_XFRM_FEATURES; + bond_dev->hw_features |= BOND_XFRM_FEATURES; + /* Only enable XFRM features if this is an active-backup config */ + if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) + bond_dev->features |= BOND_XFRM_FEATURES; #endif /* CONFIG_XFRM_OFFLOAD */ } diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c index 9abfaae1c6f7..bce34648d97d 100644 --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -748,6 +748,9 @@ const struct bond_option *bond_opt_get(unsigned int option) static int bond_option_mode_set(struct bonding *bond, const struct bond_opt_value *newval) { + netdev_features_t features = bond->dev->features; + netdev_features_t mask = features & BOND_XFRM_FEATURES; + if (!bond_mode_uses_arp(newval->value)) { if (bond->params.arp_interval) { netdev_dbg(bond->dev, "%s mode is incompatible with arp monitoring, start mii monitoring\n", @@ -769,10 +772,15 @@ static int bond_option_mode_set(struct bonding *bond, #ifdef CONFIG_XFRM_OFFLOAD if (newval->value == BOND_MODE_ACTIVEBACKUP) - bond->dev->wanted_features |= BOND_XFRM_FEATURES; + features = netdev_increment_features(features, + BOND_XFRM_FEATURES, mask); else - bond->dev->wanted_features &= ~BOND_XFRM_FEATURES; - netdev_change_features(bond->dev); + features &= ~BOND_XFRM_FEATURES; + + if (bond->dev->features != features) { + bond->dev->features = features; + netdev_features_change(bond->dev); + } #endif /* CONFIG_XFRM_OFFLOAD */ /* don't cache arp_validate between modes */ -- 2.28.0