Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2294284pxb; Fri, 5 Feb 2021 14:08:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4uIJCjqxF6ZBK5FoR3YYa7mvWghWLiOZO+4UKsd7b8hwp5kw4Kp4KoluGg4JAMNQmqwuc X-Received: by 2002:a50:bc15:: with SMTP id j21mr5633521edh.187.1612562895270; Fri, 05 Feb 2021 14:08:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612562895; cv=none; d=google.com; s=arc-20160816; b=LYq7m6cVTVDDyF4Av3MXvazeqfwnRKFhinOUEyTCSMfFI1lXbW9BTsLw2u1bYUhgCG v4lAJ4JfKfwf3rCDYt+NbEO9NvTKrroE+zkcdbwxYZBsk4v2uTYPSRH2ZHto+j82lOrH lX6ADCsCZEZRntyjvfNMsmn7rk2OwL/1gQWhkgH2GUZuFfo7FgnxrCc6x0k/P6oEZm81 OgBsKPRxmMM3Q993Nts42K3ekD4A/FZHDhjQFokXcho2MyeBxDqt4OOQ+BEHAhTw/AuP iwzf5XT5GRtObgDDmxY76pROMSDdrCU8Tj9apVq1sLhf4g7lQ4IvDgraXcP4jNCizzX7 WX3Q== 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=v6t1ZZ47vgJZ+9QojQ3eANGeC0J6SDAAokL1Na5CF9w=; b=kXkdYqEJ4xdP0G7AqJaa8suH073HG0XGXprunZFaCzYonS9IEQB6IL1tRiqwZLwevV tr6+YJbMnZvgnjOCalKQO+OgPn2d+GlTeqxmXfSoWSYLzvx+G4ews0Oens0q/58tS13D oiE4gBkT89O/Du5W5Iw0R/FhfxXdJlIs3eVSwl7I0ph1wk6+Es3HqMt1xbag4JnS191c H3zNLNgARPiMOOGwmPyNusb/I9SVSvMncXp712mcldrKvwl0PnuPXlx9WTcgpAk8AdyW C7Ks8NCNBNamXku6R9B4DKqv9O71BmhI0jDAOEYh/wq/PK+U1vv8ylbQE6VNRXa3R7fx RMlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sUkVVOmG; 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 m7si6235769ejc.466.2021.02.05.14.07.49; Fri, 05 Feb 2021 14:08:15 -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=@linuxfoundation.org header.s=korg header.b=sUkVVOmG; 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 S233108AbhBEWFk (ORCPT + 99 others); Fri, 5 Feb 2021 17:05:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:45340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbhBEO5g (ORCPT ); Fri, 5 Feb 2021 09:57:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 32BFE64FEA; Fri, 5 Feb 2021 14:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612534224; bh=Cj/B1VP4Nq9rLzQuLhmLU1FGWwvS+ujJdZzf7lCA0VQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sUkVVOmGPGwyU1gddlOO4GfZf1EcjO3v/RkOukN2hMImX3GFB7T7vER/cP1MWvhab Q6eOCK2VmWtDecLEb0sZaY8FemTv778XH8Ne2w7AIaD9F3qQ/VdKBy/atAqTjLMSH0 6mX/sByozjsj8vjMG/weYJJ3zehVwEqhdnFh4KZM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Petr Machata , Rasmus Villemoes , Jakub Kicinski Subject: [PATCH 5.10 08/57] net: switchdev: dont set port_obj_info->handled true when -EOPNOTSUPP Date: Fri, 5 Feb 2021 15:06:34 +0100 Message-Id: <20210205140656.336002214@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205140655.982616732@linuxfoundation.org> References: <20210205140655.982616732@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: Rasmus Villemoes commit 20776b465c0c249f5e5b5b4fe077cd24ef1cda86 upstream. It's not true that switchdev_port_obj_notify() only inspects the ->handled field of "struct switchdev_notifier_port_obj_info" if call_switchdev_blocking_notifiers() returns 0 - there's a WARN_ON() triggering for a non-zero return combined with ->handled not being true. But the real problem here is that -EOPNOTSUPP is not being properly handled. The wrapper functions switchdev_handle_port_obj_add() et al change a return value of -EOPNOTSUPP to 0, and the treatment of ->handled in switchdev_port_obj_notify() seems to be designed to change that back to -EOPNOTSUPP in case nobody actually acted on the notifier (i.e., everybody returned -EOPNOTSUPP). Currently, as soon as some device down the stack passes the check_cb() check, ->handled gets set to true, which means that switchdev_port_obj_notify() cannot actually ever return -EOPNOTSUPP. This, for example, means that the detection of hardware offload support in the MRP code is broken: switchdev_port_obj_add() used by br_mrp_switchdev_send_ring_test() always returns 0, so since the MRP code thinks the generation of MRP test frames has been offloaded, no such frames are actually put on the wire. Similarly, br_mrp_switchdev_set_ring_role() also always returns 0, causing mrp->ring_role_offloaded to be set to 1. To fix this, continue to set ->handled true if any callback returns success or any error distinct from -EOPNOTSUPP. But if all the callbacks return -EOPNOTSUPP, make sure that ->handled stays false, so the logic in switchdev_port_obj_notify() can propagate that information. Fixes: 9a9f26e8f7ea ("bridge: mrp: Connect MRP API with the switchdev API") Fixes: f30f0601eb93 ("switchdev: Add helpers to aid traversal through lower devices") Reviewed-by: Petr Machata Signed-off-by: Rasmus Villemoes Link: https://lore.kernel.org/r/20210125124116.102928-1-rasmus.villemoes@prevas.dk Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/switchdev/switchdev.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c @@ -460,10 +460,11 @@ static int __switchdev_handle_port_obj_a extack = switchdev_notifier_info_to_extack(&port_obj_info->info); if (check_cb(dev)) { - /* This flag is only checked if the return value is success. */ - port_obj_info->handled = true; - return add_cb(dev, port_obj_info->obj, port_obj_info->trans, - extack); + err = add_cb(dev, port_obj_info->obj, port_obj_info->trans, + extack); + if (err != -EOPNOTSUPP) + port_obj_info->handled = true; + return err; } /* Switch ports might be stacked under e.g. a LAG. Ignore the @@ -515,9 +516,10 @@ static int __switchdev_handle_port_obj_d int err = -EOPNOTSUPP; if (check_cb(dev)) { - /* This flag is only checked if the return value is success. */ - port_obj_info->handled = true; - return del_cb(dev, port_obj_info->obj); + err = del_cb(dev, port_obj_info->obj); + if (err != -EOPNOTSUPP) + port_obj_info->handled = true; + return err; } /* Switch ports might be stacked under e.g. a LAG. Ignore the @@ -568,9 +570,10 @@ static int __switchdev_handle_port_attr_ int err = -EOPNOTSUPP; if (check_cb(dev)) { - port_attr_info->handled = true; - return set_cb(dev, port_attr_info->attr, - port_attr_info->trans); + err = set_cb(dev, port_attr_info->attr, port_attr_info->trans); + if (err != -EOPNOTSUPP) + port_attr_info->handled = true; + return err; } /* Switch ports might be stacked under e.g. a LAG. Ignore the