From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B4D9C5519F for ; Mon, 23 Nov 2020 03:17:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B60AE212CC for ; Mon, 23 Nov 2020 03:17:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Th6uCyML" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727496AbgKWDRb (ORCPT ); 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