Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp965859ybi; Wed, 3 Jul 2019 07:18:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxc2cr9FgpyVbgSI0J5pnN8Z06bo4ilnXNSjb6+/Wufg3s05Q8cboXZ6hbLkuRqadR+6C1q X-Received: by 2002:a17:90a:5887:: with SMTP id j7mr12981621pji.136.1562163530680; Wed, 03 Jul 2019 07:18:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562163530; cv=none; d=google.com; s=arc-20160816; b=GlxgfNvTSPZldI3+GyizRSTAmSETW2lvjyMXGzbwGeTdM7Vy1O6xXEsc631SiJHZOK aOLFodZLai74zH1lBtAUbKn/GWeWj1UXfpeXGiw2847hOsxv6WsMJddP/UQQeGSHi6lv +6GadzaVfMKKfwd1qDKbBpRkxXlDUv+V41gYC4bnnpArx6tKCmTCLkVw3oCAL8FqBHmQ qTOMuEGZDylz62lUyBUNQOshHX320Mu16/O+2y7Bz2cxYUwGp58SWWM1Nl/HkFamZySI 8DYTCjA9kYgcEqO2cDbNJxek9BkEhIVVJNWoUaide5YhbYMTMxcldA041FQfNWfvDfR8 +pgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=w0poYHnOMbALG0kTNsLPF72owtU419TR8VmETZKdxgc=; b=NRqF27A7p7JbXgdjLV6U9z3NLffAecrZtHFlus1YkFobvSyWjCGVDk4xdyiFm4/L9V Y4n2BpS+kTUqsPhBv0f7IKmO2SbsUi1GbLscAOJJQpEasHM3FRAW5E4OUP6QJ0+kwsvF q7fqRdPAyLNsPvoTAlYBZ8Z0xQmmueCtYWvgrh59u+OpTJjV59lSisiyE58pHJ6ipW8y AbS8bBhDS4P6ft4UzMLyTcLAgD2VwTRb00ePMXo8MEJ9Sc10JBnhtsrd8pTCqg8cf+al 0P5OCzRkUNzWhDm3m36Fc70AtFnSsuL3vPFGm01oxEiQ4PBuWU5qPRZsGtQzPueqtk3K 0rRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z25si2285955pgv.418.2019.07.03.07.18.35; Wed, 03 Jul 2019 07:18:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727165AbfGCOQS (ORCPT + 99 others); Wed, 3 Jul 2019 10:16:18 -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);