Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3054735pxb; Sat, 26 Mar 2022 10:01:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9seIi41FjrTrEdpqZAtE8pK6xfVtXL/0QXEKZE9UmfgpcYp+2MgMcLjFNQa2yeRfCZakv X-Received: by 2002:a17:907:2dab:b0:6db:f0a6:761a with SMTP id gt43-20020a1709072dab00b006dbf0a6761amr18243111ejc.584.1648314095562; Sat, 26 Mar 2022 10:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648314095; cv=none; d=google.com; s=arc-20160816; b=bmsRrLHppjyTaM88Qa/RGnpumJ6tUT9GoA5WqKXPKYF4PXT/z+ETes5vM9W2jrxKGZ tKRCo3gPYOtZKbaKu8vl6kUiK8YapWceMIqNBKbt8y6HhmEpPC4R/OLlWkwsGsTRPg4f qntv0mZ5cp7HybBVfVTvulg6b7sKEsOwnSrYLQrm0XHl5ourQ2Dq05vjq8pSgHL3u/23 u+Yi83gppviwHYVtz8WBYx2eeNuWBdS3aTerCflUVLzQLrKn/VxsjhTvjGrfAgSVQGmp PC9DK/pNKgtYILbgWaICoIycc7TZIOL14iL7dyHevWIlz2eNRDwDxGJaGjknDJGtg+ke jO8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:subject:cc:to:from:date :content-transfer-encoding:mime-version:dkim-signature; bh=qSkvkduEimyVrKzJ8Yv+VKXW8fAV/QUWUndikwdu5kU=; b=Zn0wTlWT2Uk1l3Ykh39Po7qmggCWowPU+kxJXfhmUoQkQXvYQ5UUMEMEGIR4Jxcfiy uksVoysrT46Lj1U3gFxyAhFVqY7qDwe+KdcFBmTARVRNy7Z0L3xnM/SgI0QVZOm5Laq6 js+ZiHf8CEK6xcf+wAEl3+SJFVXhoy3lfQc9Vq/bL6nAgtz8lmoShY+NSwhiHUl/EYp3 Jy/2r0JhBsRF5tjpMfmyXGyTW5xOHo2TYRcBKcpMF1qZZA/FIoH2mXzMcaItvUbmZX+N Feq0UTW6l16BtPB7iQJ+T3v0qihESnyTGBgUEXgH5prp4b5l9hfueTzeAh3gj+i64W+K qqFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=HSTeecf6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020a056402275000b00418c2b5bd74si8508004edd.86.2022.03.26.10.01.04; Sat, 26 Mar 2022 10:01:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=HSTeecf6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233176AbiCZOBe (ORCPT + 99 others); Sat, 26 Mar 2022 10:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231318AbiCZOBd (ORCPT ); Sat, 26 Mar 2022 10:01:33 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6775BE43AE; Sat, 26 Mar 2022 06:59:56 -0700 (PDT) Received: from ssl.serverraum.org (web.serverraum.org [172.16.0.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id F091822246; Sat, 26 Mar 2022 14:59:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1648303194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qSkvkduEimyVrKzJ8Yv+VKXW8fAV/QUWUndikwdu5kU=; b=HSTeecf6+9+ARwUDlRHJEir6Be0zMXoNOjcqQps6pc8OeJNXvZEFre2N+Me4wYvtlG73TT HidPd3bZGC6uP/8/kWNpE49JG/rReLiQp05UwEJC+s9FqLyPytL3e2BRst6CoiAkehLAAm zLwOLYJaDJ3Del+VHkndlfB7N/hRJ4k= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 26 Mar 2022 14:59:53 +0100 From: Michael Walle To: Andrew Lunn Cc: Horatiu Vultur , "David S . Miller" , Jakub Kicinski , Paolo Abeni , UNGLinuxDriver@microchip.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] net: lan966x: fix kernel oops on ioctl when I/F is down User-Agent: Roundcube Webmail/1.4.13 Message-ID: <1ee5aec079e3eefff8475017ff1044bf@walle.cc> X-Sender: michael@walle.cc X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 2022-03-26 03:17, schrieb Andrew Lunn: > On Sat, Mar 26, 2022 at 01:02:51AM +0100, Michael Walle wrote: >> A SIOCGMIIPHY ioctl will cause a kernel oops when the interface is >> down. >> Fix it by checking the state and if it's no running, return an error. > > s/no/not/ > > I don't think it is just SIOCGMIIPHY. phy_has_hwtstamp(dev->phydev) is > probably also an issue. The phy is connected in open, and disconnected > in stop. So dev->phydev is not valid outside of that time. phy_has_hwtstamp() handles NULL gracefully. And I guess the MAC timestamp handling is working if there is no phydev. Not sure if the interface has to be up though. > But i'm also not sure it is guaranteed to be valid while the interface > is up. The driver uses phylink, so there could be an SFP attached to a > port, in which case, dev->phydev will not be set. I wonder if we should use phylink_mii_ioctl() here. Maybe as a seperate patch for the net-next if its open again? > So rather than testing of running, it would be better to test if the > phydev is NULL or not. What about the following: static int lan966x_port_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { struct lan966x_port *port = netdev_priv(dev); if (!phy_has_hwtstamp(dev->phydev) && port->lan966x->ptp) { switch (cmd) { case SIOCSHWTSTAMP: return lan966x_ptp_hwtstamp_set(port, ifr); case SIOCGHWTSTAMP: return lan966x_ptp_hwtstamp_get(port, ifr); } } if (!dev->phydev) return -ENODEV; return phy_mii_ioctl(dev->phydev, ifr, cmd); } -michael