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=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 3C8D3C0650E for ; Wed, 3 Jul 2019 14:16:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18C2D21881 for ; Wed, 3 Jul 2019 14:16:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727171AbfGCOQT (ORCPT ); Wed, 3 Jul 2019 10:16:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:38702 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726217AbfGCOQS (ORCPT ); Wed, 3 Jul 2019 10:16:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 22072AF2C; Wed, 3 Jul 2019 14:16:17 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id E765CE0159; Wed, 3 Jul 2019 16:16:14 +0200 (CEST) Date: Wed, 3 Jul 2019 16:16:14 +0200 From: Michal Kubecek To: netdev@vger.kernel.org Cc: Jiri Pirko , David Miller , Jakub Kicinski , Andrew Lunn , Florian Fainelli , John Linville , Stephen Hemminger , Johannes Berg , linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v6 07/15] ethtool: support for netlink notifications Message-ID: <20190703141614.GL20101@unicorn.suse.cz> References: <4dcac81783de8686edefa262a1db75f9e961b123.1562067622.git.mkubecek@suse.cz> <20190703133352.GY2250@nanopsycho> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190703133352.GY2250@nanopsycho> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 03, 2019 at 03:33:52PM +0200, Jiri Pirko wrote: > >+/* notifications */ > >+ > >+typedef void (*ethnl_notify_handler_t)(struct net_device *dev, > >+ struct netlink_ext_ack *extack, > >+ unsigned int cmd, u32 req_mask, > >+ const void *data); > >+ > >+static const ethnl_notify_handler_t ethnl_notify_handlers[] = { > >+}; > >+ > >+void ethtool_notify(struct net_device *dev, struct netlink_ext_ack *extack, > >+ unsigned int cmd, u32 req_mask, const void *data) > > What's "req_mask" ? It's infomask to interpret the same way as if it came from request header (the notification triggered by a SET request or its ioctl equivalent uses the same format as corresponding GET_REPLY message and is created by the same code). But it could be called infomask, I have no strong opinion about that. > >+{ > >+ if (unlikely(!ethnl_ok)) > >+ return; > >+ ASSERT_RTNL(); > >+ > >+ if (likely(cmd < ARRAY_SIZE(ethnl_notify_handlers) && > >+ ethnl_notify_handlers[cmd])) > > How it could be null? Notification message types share the enum with other kernel messages: /* message types - kernel to userspace */ enum { ETHTOOL_MSG_KERNEL_NONE, ETHTOOL_MSG_STRSET_GET_REPLY, ETHTOOL_MSG_SETTINGS_GET_REPLY, ETHTOOL_MSG_SETTINGS_NTF, ETHTOOL_MSG_SETTINGS_SET_REPLY, ETHTOOL_MSG_INFO_GET_REPLY, ETHTOOL_MSG_PARAMS_GET_REPLY, ETHTOOL_MSG_PARAMS_NTF, ETHTOOL_MSG_NWAYRST_NTF, ETHTOOL_MSG_PHYSID_NTF, ETHTOOL_MSG_RESET_NTF, ETHTOOL_MSG_RESET_ACT_REPLY, ETHTOOL_MSG_RXFLOW_GET_REPLY, ETHTOOL_MSG_RXFLOW_NTF, ETHTOOL_MSG_RXFLOW_SET_REPLY, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1) }; Only entries for *_NTF types are non-null in ethnl_notify_handlers[]: static const ethnl_notify_handler_t ethnl_notify_handlers[] = { [ETHTOOL_MSG_SETTINGS_NTF] = ethnl_std_notify, [ETHTOOL_MSG_PARAMS_NTF] = ethnl_std_notify, [ETHTOOL_MSG_NWAYRST_NTF] = ethnl_nwayrst_notify, [ETHTOOL_MSG_PHYSID_NTF] = ethnl_physid_notify, [ETHTOOL_MSG_RESET_NTF] = ethnl_reset_notify, [ETHTOOL_MSG_RXFLOW_NTF] = ethnl_rxflow_notify, }; If the check above fails, it means that kernel code tried to send a notification with type which does not exist or is not a notification, i.e. a bug in kernel; that's why the WARN_ONCE. Michal > >+ ethnl_notify_handlers[cmd](dev, extack, cmd, req_mask, data); > >+ else > >+ WARN_ONCE(1, "notification %u not implemented (dev=%s, req_mask=0x%x)\n", > >+ cmd, netdev_name(dev), req_mask); > >+} > >+EXPORT_SYMBOL(ethtool_notify);