From patchwork Tue Apr 13 10:09:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Kazior?= X-Patchwork-Id: 1465694 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=dmVXu4m5; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKLv51KB4z9sTD for ; Tue, 13 Apr 2021 20:09:52 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id D740D60B95; Tue, 13 Apr 2021 10:09:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9LeXMw-6ccTh; Tue, 13 Apr 2021 10:09:49 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTP id D0E1560705; Tue, 13 Apr 2021 10:09:48 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 94B05C000C; Tue, 13 Apr 2021 10:09:48 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7CF1CC000A for ; Tue, 13 Apr 2021 10:09:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5C948405E1 for ; Tue, 13 Apr 2021 10:09:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9lZrKOo0o_B9 for ; Tue, 13 Apr 2021 10:09:44 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by smtp4.osuosl.org (Postfix) with ESMTPS id AD2F8405D7 for ; Tue, 13 Apr 2021 10:09:43 +0000 (UTC) Received: by mail-lj1-x229.google.com with SMTP id z8so18696438ljm.12 for ; Tue, 13 Apr 2021 03:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xO5lkSxNW4PqhevUdblfWhsTl8/GQt/0iIjagceI/vE=; b=dmVXu4m5/7WkyQWwZBYx8qrZL3KQodZqRSl3O8rB6TDmbt7VojrzshBTNf0YZU89Rb bhJ9KUafi1AiknmOvdy4e5ALjZiiI47pXD/tvnX0DLQAx8GsUhsge2sNk6gCiidcYZoq Jjr2OKD1txHtZCJP/q6SsrE6HAXNQKz5Ok9/s+LWOUFhT/+nFVF2aNIc+Qibef8Wpmwr V25TaZzkbp9JDysqbu9G+C07vzg0RB5Am6AiIt92vxiDPjmXuQTOB4pHC2gvwSnhJOtL 0AycLvQ1JUUV0ltiP58w5afO00x1dA1HwSeDEOR+mHpkXU4csgMnllMT0lJBOu541Y/u R0EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xO5lkSxNW4PqhevUdblfWhsTl8/GQt/0iIjagceI/vE=; b=LbDTwtOcUUPgjHqFumvLfjE1NcnWYoSa/Dki5hEqni511ynED3piwqGfg9wNfGUANu wXt+xz+qlrT8isq1f3MQRsECw9/gZLykzcVVDA8tnQbl+atx0Q2i5xpTaAT8V+kk3ysW A9Yyzjbv0Y4znAzcjqrHJXCPwqTmaCIVqj94cxUvN/6h0oU4la97cgWhGerWbSj0xVl/ LiaDAY74YvemmztAQUHCT9Cncve4aF1wMH0fdnaWwiyGbkcJ4gWaeIGN4X92YA488TVc qQ3/Gg9qNmt4hCEcMZs2acN+K6JM2cp4m3bX+gk3bIEVmm1C4ZbqFrRax8oQYuTXRpTt nfbg== X-Gm-Message-State: AOAM533AHAkhfAusdeNQSiHVVBSD4j+Y/YJlKgzdnKiJThLPsP5jI6GJ euAWiM0SAJjJRy/u8tPhcQg4iU+qbRPH5g== X-Google-Smtp-Source: ABdhPJwsC2dZNRb3c7fIgQRIM//pyR4ZlXQ1hS2o5z6MPO8Huo5zV/PDwkoZzEBbtjWaNFRhCkF1bw== X-Received: by 2002:a2e:88ca:: with SMTP id a10mr20423784ljk.55.1618308581213; Tue, 13 Apr 2021 03:09:41 -0700 (PDT) Received: from drun:home-michalkazior-docker-linux-alpine.pl.plumewifi.com ([2a03:4b00:0:4:692:26ff:fed9:4198]) by smtp.gmail.com with ESMTPSA id l13sm1636406lfc.270.2021.04.13.03.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 03:09:40 -0700 (PDT) From: Michal Kazior To: dev@openvswitch.org Date: Tue, 13 Apr 2021 10:09:22 +0000 Message-Id: <20210413100922.1221-1-kazikcz@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210304153254.1088-1-kazikcz@gmail.com> References: <20210304153254.1088-1-kazikcz@gmail.com> MIME-Version: 1.0 Cc: Michal Kazior Subject: [ovs-dev] [PATCH v5] netlink: ignore IFLA_WIRELESS events X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Michal Kazior Some older wireless drivers - ones relying on the old and long deprecated wireless extension ioctl system - can generate quite a bit of IFLA_WIRELESS events depending on their configuration and runtime conditions. These are delivered as RTNLGRP_LINK via RTM_NEWLINK messages. These tend to be relatively easily identifiable because they report the change mask being 0. This isn't guaranteed but in practice it shouldn't be a problem. None of the wireless events that I ever observed actually carry any unique information about netdev states that ovs-vswitchd is interested in. Hence ignoring these shouldn't cause any problems. These events can be responsible for a significant CPU churn as ovs-vswitchd attempts to do plenty of work for each and every netlink message regardless of what that message carries. On low-end devices such as consumer-grade routers these can lead to a lot of CPU cycles being wasted, adding up to heat output and reducing performance. It could be argued that wireless drivers in question should be fixed, but that isn't exactly a trivial thing to do. Patching ovs seems far more viable while still making sense. Signed-off-by: Michal Kazior --- Notes: v5: - added checks to avoid null deref of `change` [Ilya] - added missing period at end of comment [Ilya] - moved some checks closer to rtnetlink_parse() [Ilya] - made sure change->irrelevant is always initialized [Ilya] v4: - fixed comment-too-long checkpatch warnin [0day robot] v3: - dont change rtnetlink_parse() semantics, instead extend rtnetlink_change struct and update its consumers [Ilya] - adjusted commit log to reflect different approach [Ilya] v2: - fix bracing style [0day robot / checkpatch] lib/if-notifier.c | 7 ++++++- lib/netdev-linux.c | 3 ++- lib/route-table.c | 4 ++++ lib/rtnetlink.c | 16 ++++++++++++++++ lib/rtnetlink.h | 3 +++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/if-notifier.c b/lib/if-notifier.c index 9a64f9b15..f2d7157b9 100644 --- a/lib/if-notifier.c +++ b/lib/if-notifier.c @@ -26,9 +26,14 @@ struct if_notifier { }; static void -if_notifier_cb(const struct rtnetlink_change *change OVS_UNUSED, void *aux) +if_notifier_cb(const struct rtnetlink_change *change, void *aux) { struct if_notifier *notifier; + + if (change && change->irrelevant) { + return; + } + notifier = aux; notifier->cb(notifier->aux); } diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 6be23dbee..6713c6d68 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -742,7 +742,7 @@ netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) if (!error) { struct rtnetlink_change change; - if (rtnetlink_parse(&buf, &change)) { + if (rtnetlink_parse(&buf, &change) && !change.irrelevant) { struct netdev *netdev_ = NULL; char dev_name[IFNAMSIZ]; @@ -6344,6 +6344,7 @@ netdev_linux_update_via_netlink(struct netdev_linux *netdev) } if (rtnetlink_parse(reply, change) + && !change->irrelevant && change->nlmsg_type == RTM_NEWLINK) { bool changed = false; error = 0; diff --git a/lib/route-table.c b/lib/route-table.c index 6c82cdfdd..ac82cf262 100644 --- a/lib/route-table.c +++ b/lib/route-table.c @@ -342,6 +342,10 @@ static void name_table_change(const struct rtnetlink_change *change, void *aux OVS_UNUSED) { + if (change && change->irrelevant) { + return; + } + /* Changes to interface status can cause routing table changes that some * versions of the linux kernel do not advertise for some reason. */ route_table_valid = false; diff --git a/lib/rtnetlink.c b/lib/rtnetlink.c index 125802925..7e68edde9 100644 --- a/lib/rtnetlink.c +++ b/lib/rtnetlink.c @@ -99,6 +99,7 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change) [IFLA_MTU] = { .type = NL_A_U32, .optional = true }, [IFLA_ADDRESS] = { .type = NL_A_UNSPEC, .optional = true }, [IFLA_LINKINFO] = { .type = NL_A_NESTED, .optional = true }, + [IFLA_WIRELESS] = { .type = NL_A_UNSPEC, .optional = true }, }; struct nlattr *attrs[ARRAY_SIZE(policy)]; @@ -111,6 +112,21 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change) ifinfo = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *ifinfo); + /* Wireless events can be spammy and cause a + * lot of unnecessary churn and CPU load in + * ovs-vswitchd. The best way to filter them out + * is to rely on the IFLA_WIRELESS and + * ifi_change. As per rtnetlink_ifinfo_prep() in + * the kernel, the ifi_change = 0. That combined + * with the fact wireless events never really + * change interface state (as far as core + * networking is concerned) they can be ignored + * by ovs-vswitchd. It doesn't understand + * wireless extensions anyway and has no way of + * presenting these bits into ovsdb. + */ + change->irrelevant = (attrs[IFLA_WIRELESS] && + ifinfo->ifi_change == 0); change->nlmsg_type = nlmsg->nlmsg_type; change->if_index = ifinfo->ifi_index; change->ifname = nl_attr_get_string(attrs[IFLA_IFNAME]); diff --git a/lib/rtnetlink.h b/lib/rtnetlink.h index b6ddb4bd1..11f454ffc 100644 --- a/lib/rtnetlink.h +++ b/lib/rtnetlink.h @@ -45,6 +45,9 @@ struct rtnetlink_change { int mtu; /* Current MTU. */ struct eth_addr mac; unsigned int ifi_flags; /* Flags of network device. */ + bool irrelevant; /* Some events, notably wireless extensions, + don't really indicate real netdev change + that ovs should care about. */ /* Network device address status. */ /* xxx To be added when needed. */