From patchwork Thu Jan 14 09:09:38 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: 1427432 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=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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=nDYh3EVW; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DHflP0g9Jz9sVn for ; Sat, 16 Jan 2021 11:57:04 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id CE5E22E19E; Sat, 16 Jan 2021 00:57:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eDYxdIE+Fy08; Sat, 16 Jan 2021 00:57:00 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 82E9B2285E; Sat, 16 Jan 2021 00:57:00 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 59B69C0893; Sat, 16 Jan 2021 00:57:00 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 29649C013A for ; Thu, 14 Jan 2021 09:13:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 24D4387397 for ; Thu, 14 Jan 2021 09:13:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TKC-PkpIqfh1 for ; Thu, 14 Jan 2021 09:12:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by hemlock.osuosl.org (Postfix) with ESMTPS id 09B3187234 for ; Thu, 14 Jan 2021 09:12:59 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id n11so5632879lji.5 for ; Thu, 14 Jan 2021 01:12:58 -0800 (PST) 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=R0PdCNZfYLuQGUJbs54XSNf+kOtezP10ykAQlCLU+ow=; b=nDYh3EVWDuXxohc0e7DxqVRae3gNk+LLWmhDw1DiynkeaAYNIcHqvm+eF9dn0Kj9gr wgr0oPw9/a6vtRbN6ADrWdSbQxLSMktDL3R3x9sxSZ/Ft9zE2NePqTxicCpI62uOR/B7 my7Vnevr1qxDSGUlxLUBFw7zw41zFnQxrPhH+smmn0dFNq5Icrdsmudin1VJcyAcW27/ 3TCEbqdC4NLQI13EXYzIGLpwYRBI9KVomXdZ5RYtPZcpjkTm9A0UJb5bQFaNovX/aNYi uRQIygU8aoI/bsx6W8P28F3jBmDzg2shYrbFJOd6UIDg9/YPtB6CFy5TO0JCtlLMyG54 eDBQ== 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=R0PdCNZfYLuQGUJbs54XSNf+kOtezP10ykAQlCLU+ow=; b=E+LzEaIZ0+XRrbl0bu3CU//+BP5havvVUXSc4S6rEWsPxAqHP9wsFnZamFdUPem2fG 8kPQmYl/bEohgcqM38BHA5KmDIGxRKyAzSytm7AdEWiLX72THZmxS/VxzT2xjQ3eSGvc q0kR3q9ndGRuMhVdIBbgnHyBKYpiLz0l4ZzRxWlKBE0VmRdbTxhfB+XQO/R/bjVaqlCT 5pitqamWJNo23Iqtd9Sql49/iicyYUPaHgnwlbhL0fxMFMXqR4EISSRVkdE4KgMfe3qf 7Xjdmmup7fAYs9vZV30J2Kyt0cyEQKVTMqOrzOuX5s6G7+B2J6zxoP2Emo2xdtK+swYU uPBw== X-Gm-Message-State: AOAM531yfZBM31Tu/6ySkS2oLGuDkdJIgu+g43BCL2JiL6pzKLHoZbiE FqWdV4ZU/CicMDh7zcDJQAM3COxKlSY= X-Google-Smtp-Source: ABdhPJxO97OetJsyybhQhqdLiCJF5iRV1k59w8ryltSa5TJ8raPCUomdhPBFtpVUabnY8mArbTQrTw== X-Received: by 2002:a2e:6e11:: with SMTP id j17mr2606738ljc.337.1610615576473; Thu, 14 Jan 2021 01:12:56 -0800 (PST) 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 19sm494069lft.90.2021.01.14.01.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jan 2021 01:12:55 -0800 (PST) From: Michal Kazior To: dev@openvswitch.org Date: Thu, 14 Jan 2021 09:09:38 +0000 Message-Id: <20210114090938.6996-1-kazikcz@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201215095712.52341-1-kazikcz@gmail.com> References: <20201215095712.52341-1-kazikcz@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 16 Jan 2021 00:56:59 +0000 Cc: Michal Kazior Subject: [ovs-dev] [PATCH v2] 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. This change requires a slight tweak to the netlink abstraction code so that the events can be discarded as soon as possible before getting a chance to cause the churn. Signed-off-by: Michal Kazior Acked-by: Greg Rose --- Notes: v2: - fix bracing style [0day robot / checkpatch] lib/netdev-linux.c | 4 ++-- lib/netlink-notifier.c | 4 +++- lib/rtnetlink.c | 24 +++++++++++++++++++++--- lib/rtnetlink.h | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 6be23dbee..301dd9060 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) > 0) { struct netdev *netdev_ = NULL; char dev_name[IFNAMSIZ]; @@ -6343,7 +6343,7 @@ netdev_linux_update_via_netlink(struct netdev_linux *netdev) return error; } - if (rtnetlink_parse(reply, change) + if (rtnetlink_parse(reply, change) > 0 && change->nlmsg_type == RTM_NEWLINK) { bool changed = false; error = 0; diff --git a/lib/netlink-notifier.c b/lib/netlink-notifier.c index dfecb9778..ab5a84abb 100644 --- a/lib/netlink-notifier.c +++ b/lib/netlink-notifier.c @@ -189,8 +189,10 @@ nln_run(struct nln *nln) if (!error) { int group = nln->parse(&buf, nln->change); - if (group != 0) { + if (group > 0) { nln_report(nln, nln->change, group); + } else if (group == 0) { + /* ignore some events */ } else { VLOG_WARN_RL(&rl, "unexpected netlink message contents"); nln_report(nln, NULL, 0); diff --git a/lib/rtnetlink.c b/lib/rtnetlink.c index 125802925..316524c0f 100644 --- a/lib/rtnetlink.c +++ b/lib/rtnetlink.c @@ -82,7 +82,7 @@ rtnetlink_parse_link_info(const struct nlattr *nla, /* Parses a rtnetlink message 'buf' into 'change'. If 'buf' is unparseable, * leaves 'change' untouched and returns false. Otherwise, populates 'change' * and returns true. */ -bool +int rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change) { const struct nlmsghdr *nlmsg = buf->data; @@ -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,23 @@ 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. + */ + if (attrs[IFLA_WIRELESS] && ifinfo->ifi_change == 0) { + return RTNLGRP_NONE; + } + change->nlmsg_type = nlmsg->nlmsg_type; change->if_index = ifinfo->ifi_index; change->ifname = nl_attr_get_string(attrs[IFLA_IFNAME]); @@ -165,14 +183,14 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change) } } - return parsed; + return parsed ? RTNLGRP_LINK : -1; } /* Return RTNLGRP_LINK on success, 0 on parse error. */ static int rtnetlink_parse_cb(struct ofpbuf *buf, void *change) { - return rtnetlink_parse(buf, change) ? RTNLGRP_LINK : 0; + return rtnetlink_parse(buf, change); } /* Registers 'cb' to be called with auxiliary data 'aux' with network device diff --git a/lib/rtnetlink.h b/lib/rtnetlink.h index b6ddb4bd1..23921a63b 100644 --- a/lib/rtnetlink.h +++ b/lib/rtnetlink.h @@ -65,7 +65,7 @@ void rtnetlink_notify_func(const struct rtnetlink_change *change, bool rtnetlink_type_is_rtnlgrp_link(uint16_t type); bool rtnetlink_type_is_rtnlgrp_addr(uint16_t type); -bool rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change); +int rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change); struct nln_notifier * rtnetlink_notifier_create(rtnetlink_notify_func *, void *aux); void rtnetlink_notifier_destroy(struct nln_notifier *);