From patchwork Tue Jul 20 14:46:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 481555 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5248342jao; Tue, 20 Jul 2021 08:39:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhl4+NclgDkvWHJaqj0Q5lhcyy0+Ll8tvktLYMGMs4ZT0828RWqzHVav5A1ekhLR241++t X-Received: by 2002:a50:aa97:: with SMTP id q23mr41100368edc.154.1626795575180; Tue, 20 Jul 2021 08:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626795575; cv=none; d=google.com; s=arc-20160816; b=HysgmLOP0QvAa3wLA7FzNjaDTx34NtXKPJk1E1blbkqM+ytU8bh6yPvQXuLLn8kT7Z Yn7/jOqjREvjiqn4fUCTfZXO2TIAxxzvXj3cugrF+BU8UICQ1uopw4lnJnCbOKdqSX/x paca3tcHs7fkxm5deOBeOsRFHfsB3bDGhEI4l4A79IPobYAMvt6SaIo2P2eNQDvX0/g4 5RFj/IxkAn1q32CvK9tgg47h+5lOMc5Ch5kfYELu2utiArzDl5tVDpvty635SNCVN/lq p9gZXIE67ZVVdk9TNhROy92rTyOsB3A2lWBUjGpi9g342AMRR2w1MFPEoFwRI89YXqoW uT9w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NubZKEeN3mIQcp2sONBL8gS6MTEWFY45uC2DNmiW1ms=; b=T4fLinZL1LNj89va01/ifqCcmgNuwKYoVcE94gWgRbT38OkMl3B8ESWu1b7pxaSypm qsfHPGymgw3HuMKjoR2SJgzWTvTdSdMY81JN66eC1UJ0iaQpo5d2QgHZ61jyprfOb77z hX/gFGEE0ETbINulBxlSIJAGDaqkYzJZUdubAXvMOG8p6LdgVwC0sjSIzT+6lSstfQ5x 32vWu8C/PO5qe/cv8StigdO62uvEaWL6A5JgZsiUCogvK90RtuohcGsiO3D7Z8RI6yr7 Eym4Qy3iWc1D25y7B/yctUjNmn68RjSvJDSp9r1hBDFuOCryj35ZAAO8VcEA/Embsydi I6Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ra1sWxY+; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b7si160517edd.497.2021.07.20.08.39.35; Tue, 20 Jul 2021 08:39:35 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-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=@kernel.org header.s=k20201202 header.b=Ra1sWxY+; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239790AbhGTOxl (ORCPT + 8 others); Tue, 20 Jul 2021 10:53:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:35606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239778AbhGTO2q (ORCPT ); Tue, 20 Jul 2021 10:28:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 06686611CE; Tue, 20 Jul 2021 14:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626792413; bh=0xGD3/0Zic0jjPeC/gHVRi/xMKxPymQtNrC/i4voqrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ra1sWxY+emH66IQfPc3sO8x0BftpDs/L+BEzlotpsa5tWd5Q+gafMr9Y24FEBLiX3 u+MNKMVJ/TH+v9jY0JAnzaqfdDfKUNX8VQi9J0BONc76TQHs3K9dMq9NpRM/kFgQ3i eoQBik/kfORyZUj2cn7FfVtd6/z9tgfuLVULCW0I288x1J/ofZHJCPPDvkOVj44ZaQ 3mbip7basT+jgifH7GZRBuV5cUJRoBHdCBWSHgqGjJszTkLZonbNj15sLNr1R7I0pb Ry1I3fTstaGnSg+HcEHkjpbQkDePaRRZor1jvdSrPA2QlOeBDGoV2f57UFHeSmN2Kj WC+He1IKHj2DQ== From: Arnd Bergmann To: netdev@vger.kernel.org Cc: Christoph Hellwig , Arnd Bergmann Subject: [PATCH net-next v2 01/31] net: split out SIOCDEVPRIVATE handling from dev_ioctl Date: Tue, 20 Jul 2021 16:46:08 +0200 Message-Id: <20210720144638.2859828-2-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210720144638.2859828-1-arnd@kernel.org> References: <20210720144638.2859828-1-arnd@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arnd Bergmann SIOCDEVPRIVATE ioctl commands are mainly used in really old drivers, and they have a number of problems: - They hide behind the normal .ndo_do_ioctl function that is also used for other things in modern drivers, so it's hard to spot a driver that actually uses one of these - Since drivers use a number different calling conventions, it is impossible to support compat mode for them in a generic way. - With all drivers using the same 16 commands codes, there is no way to introspect the data being passed through things like strace. Add a new net_device_ops callback pointer, to address the first two of these. Separating them from .ndo_do_ioctl makes it easy to grep for drivers with a .ndo_siocdevprivate callback, and the unwieldy name hopefully makes it easier to spot in code review. By passing the ifreq structure and the ifr_data pointer separately, it is no longer necessary to overload these, and the driver can use either one for a given command. Signed-off-by: Arnd Bergmann --- Documentation/networking/netdevices.rst | 7 +++++++ include/linux/netdevice.h | 3 +++ net/core/dev_ioctl.c | 25 ++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) -- 2.29.2 diff --git a/Documentation/networking/netdevices.rst b/Documentation/networking/netdevices.rst index 17bdcb746dcf..02f1faac839a 100644 --- a/Documentation/networking/netdevices.rst +++ b/Documentation/networking/netdevices.rst @@ -222,6 +222,13 @@ ndo_do_ioctl: Synchronization: rtnl_lock() semaphore. Context: process +ndo_siocdevprivate: + Synchronization: rtnl_lock() semaphore. + Context: process + + This is used to implement SIOCDEVPRIVATE ioctl helpers. + These should not be added to new drivers, so don't use. + ndo_get_stats: Synchronization: rtnl_lock() semaphore, dev_base_lock rwlock, or RCU. Context: atomic (can't sleep under rwlock or RCU) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 5c39129101c0..05d70143715b 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1361,6 +1361,9 @@ struct net_device_ops { int (*ndo_validate_addr)(struct net_device *dev); int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); + int (*ndo_siocdevprivate)(struct net_device *dev, + struct ifreq *ifr, + void __user *data, int cmd); int (*ndo_set_config)(struct net_device *dev, struct ifmap *map); int (*ndo_change_mtu)(struct net_device *dev, diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 0af7b9f09970..a54414590c81 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -258,6 +258,23 @@ static int dev_do_ioctl(struct net_device *dev, return err; } +static int dev_siocdevprivate(struct net_device *dev, + struct ifreq *ifr, unsigned int cmd) +{ + const struct net_device_ops *ops = dev->netdev_ops; + void __user *data = ifr->ifr_data; + + if (ops->ndo_siocdevprivate) { + if (netif_device_present(dev)) + return ops->ndo_siocdevprivate(dev, ifr, data, cmd); + else + return -ENODEV; + } + + /* fall back to do_ioctl for drivers not yet converted */ + return dev_do_ioctl(dev, ifr, cmd); +} + /* * Perform the SIOCxIFxxx calls, inside rtnl_lock() */ @@ -335,9 +352,11 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) * Unknown or private ioctl */ default: - if ((cmd >= SIOCDEVPRIVATE && - cmd <= SIOCDEVPRIVATE + 15) || - cmd == SIOCBONDENSLAVE || + if (cmd >= SIOCDEVPRIVATE && + cmd <= SIOCDEVPRIVATE + 15) + return dev_siocdevprivate(dev, ifr, cmd); + + if (cmd == SIOCBONDENSLAVE || cmd == SIOCBONDRELEASE || cmd == SIOCBONDSETHWADDR || cmd == SIOCBONDSLAVEINFOQUERY ||