Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2875485pxu; Sat, 19 Dec 2020 05:02:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqq9uV026rQLPw8u/jt5NEBXYySsH1wOzkEUdCXhdXMH7cF0147f9QZs4Sceqr+UxEz/Kx X-Received: by 2002:a17:906:179a:: with SMTP id t26mr8528528eje.49.1608382966310; Sat, 19 Dec 2020 05:02:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608382966; cv=none; d=google.com; s=arc-20160816; b=XS43mDlkq0h0Dk1USLOdDPHjXbEHkkUqppeQgWEFZfXtWH3ByiYw5khqpxTqmvpi6j /9gRh3u860qVwIlg6Zpvq0YV7m8zeBp5RbA0hET81U+ts8XPWHuRaAt/ptFfcXrbDcv9 XTfMpDnFim0FtjfSTzmurQv7rh9TiUD3c6r/0R3PSUp7lP6R+60cvvLlS4TIQhCcbc+K lHqOaJx6w7INERgSMOudY0ZuZtaeXUkVhSstlYyewp+6SNbkbAY06iLVrv1uC9fJvA8O Z/1NnT0+zGFIJ4iE1yBG8cLskRJaOxxbD4x1Z0Yf/FuDOD4uOSO8cMxTWisHA6vvdOyH jcmw== 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; bh=rALn0dYJPBKR/T1n5YV6H/yZBcSNHclZonTQUOTrpVg=; b=fJQlc5YjTkmv81BJy3ghyB7Ow0AkPV/+qMaIkJWBsgL1Z8jglljrG3JqrHvnn9WjUY r0Pn60ZtMIZienBHbEFbjVpS9CTsVQfiLsF0epGeudc6s07TDuVnLQDgJEJqBaASy3MV +yw++cgmWHNaYkD+/ReY9exQb2/zDtYHvDnWAF/8ldSImKatbdRXjTjc/Y4ZkxaHxgig y4YP3ys6R0VlW2xRbl/9b39ZFZ86JURVvdeXHP7s3nWmdjkdWgfD82QCTV9AKFoXH72M vYdeezjd6PgAbKS0xsnTzjl+HPd4ZjXlg4zwPngUL/j+rleP1hdm8Kb3F1y2o6dv2vHZ XbPg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 mf27si6129751ejb.129.2020.12.19.05.02.23; Sat, 19 Dec 2020 05:02:46 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbgLSNA5 (ORCPT + 99 others); Sat, 19 Dec 2020 08:00:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:47030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728310AbgLSM7u (ORCPT ); Sat, 19 Dec 2020 07:59:50 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ivan Vecera , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Jarod Wilson , Jakub Kicinski Subject: [PATCH 5.9 28/49] bonding: fix feature flag setting at init time Date: Sat, 19 Dec 2020 13:58:32 +0100 Message-Id: <20201219125346.056624222@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201219125344.671832095@linuxfoundation.org> References: <20201219125344.671832095@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: Jarod Wilson [ Upstream commit 007ab5345545aba2f9cbe4c096cc35d2fd3275ac ] Don't try to adjust XFRM support flags if the bond device isn't yet registered. Bad things can currently happen when netdev_change_features() is called without having wanted_features fully filled in yet. This code runs both on post-module-load mode changes, as well as at module init time, and when run at module init time, it is before register_netdevice() has been called and filled in wanted_features. The empty wanted_features led to features also getting emptied out, which was definitely not the intended behavior, so prevent that from happening. Originally, I'd hoped to stop adjusting wanted_features at all in the bonding driver, as it's documented as being something only the network core should touch, but we actually do need to do this to properly update both the features and wanted_features fields when changing the bond type, or we get to a situation where ethtool sees: esp-hw-offload: off [requested on] I do think we should be using netdev_update_features instead of netdev_change_features here though, so we only send notifiers when the features actually changed. Fixes: a3b658cfb664 ("bonding: allow xfrm offload setup post-module-load") Reported-by: Ivan Vecera Suggested-by: Ivan Vecera Cc: Jay Vosburgh Cc: Veaceslav Falico Cc: Andy Gospodarek Signed-off-by: Jarod Wilson Link: https://lore.kernel.org/r/20201205172229.576587-1-jarod@redhat.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/bonding/bond_options.c | 22 +++++++++++++++------- include/net/bonding.h | 2 -- 2 files changed, 15 insertions(+), 9 deletions(-) --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -745,6 +745,19 @@ const struct bond_option *bond_opt_get(u return &bond_opts[option]; } +static void bond_set_xfrm_features(struct net_device *bond_dev, u64 mode) +{ + if (!IS_ENABLED(CONFIG_XFRM_OFFLOAD)) + return; + + if (mode == BOND_MODE_ACTIVEBACKUP) + bond_dev->wanted_features |= BOND_XFRM_FEATURES; + else + bond_dev->wanted_features &= ~BOND_XFRM_FEATURES; + + netdev_update_features(bond_dev); +} + static int bond_option_mode_set(struct bonding *bond, const struct bond_opt_value *newval) { @@ -767,13 +780,8 @@ static int bond_option_mode_set(struct b if (newval->value == BOND_MODE_ALB) bond->params.tlb_dynamic_lb = 1; -#ifdef CONFIG_XFRM_OFFLOAD - if (newval->value == BOND_MODE_ACTIVEBACKUP) - bond->dev->wanted_features |= BOND_XFRM_FEATURES; - else - bond->dev->wanted_features &= ~BOND_XFRM_FEATURES; - netdev_change_features(bond->dev); -#endif /* CONFIG_XFRM_OFFLOAD */ + if (bond->dev->reg_state == NETREG_REGISTERED) + bond_set_xfrm_features(bond->dev, newval->value); /* don't cache arp_validate between modes */ bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; --- a/include/net/bonding.h +++ b/include/net/bonding.h @@ -86,10 +86,8 @@ #define bond_for_each_slave_rcu(bond, pos, iter) \ netdev_for_each_lower_private_rcu((bond)->dev, pos, iter) -#ifdef CONFIG_XFRM_OFFLOAD #define BOND_XFRM_FEATURES (NETIF_F_HW_ESP | NETIF_F_HW_ESP_TX_CSUM | \ NETIF_F_GSO_ESP) -#endif /* CONFIG_XFRM_OFFLOAD */ #ifdef CONFIG_NET_POLL_CONTROLLER extern atomic_t netpoll_block_tx;