Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1759420imm; Thu, 27 Sep 2018 01:57:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV62bA/XNyTdZN405ONgCucm/9JxMdV3Os44Z52YtUKvSOAy0ovCvJXE8Uts6rWezdRUHIpxA X-Received: by 2002:a17:902:b411:: with SMTP id x17-v6mr9789010plr.248.1538038655598; Thu, 27 Sep 2018 01:57:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038655; cv=none; d=google.com; s=arc-20160816; b=WXCs9UwjyVR0Qrv5u3XVuuZ/pTginnDK4Fc4W7UvOY/VE9iI11MohP1eLqs0c280f0 lvTF67FEuLHnlCfdjG1kpZk8UmMNeFKQ0qoWKz/IGMAT2j2iC2SUoVSLGXnZyhvLb43T WYkzS9PGl8sDus4yRcdoBFBZDQtocR51MUiD1TpZyvTsrK3z8Hc4VnnCUF75F3KW1aF+ DO2GnKBw5bIgbRGNmQX+ywf/zBNlGqC9z8tRdn+IU+JmYQNX2xUJwlgehDa3TetMZ4Js /Zx/P0TwzhCiZYT0er56wdx0sVW5lD8jmS7TQ5w6Af783vsHitDSHItgwT7J3nNXQR1q lJTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:reply-to:from :subject:message-id; bh=hfjcyy/bDSmsvZFaQS12bMD7BonLruVM+s2PQCiTvz0=; b=vvzmTZKh5EhIAmrWzq7uGOV6WFf8WVn4CyVN0+CncrX6GjwhjCGZhbrfhaiReoDWW8 SdpCnCp6bxXn2+VHzM6JfS8h0asbtSblmOpmmjgg3Yo9B6pdLQ7crxGQJKrRakoG7OsB fVslK1EEFqH3ydfYDwvKPXCD7Iq2kzMsC7jQAZKiu2klo4EdBSy5wUHkNGwACH9b+kj4 K6ueHhc60LcD/tkpgLOmzPZh2TvcmGdmKG6aMH3sUXby8yFZCR8Y6CTCAcmhKkcGj/nD gFqOZbZ9Qv6PcqJ/NcUm19E94cvirXE6ltL9DQ2hUQj9C5ISRSyTSctg8ZV7SF/wH8CC 6TsQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j14-v6si1447478pgh.22.2018.09.27.01.57.19; Thu, 27 Sep 2018 01:57:35 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727169AbeI0POX (ORCPT + 99 others); Thu, 27 Sep 2018 11:14:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53066 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726929AbeI0POX (ORCPT ); Thu, 27 Sep 2018 11:14:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2DE3792C0; Thu, 27 Sep 2018 08:57:12 +0000 (UTC) Received: from ovpn-112-72.ams2.redhat.com (ovpn-112-72.ams2.redhat.com [10.36.112.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EEF160D62; Thu, 27 Sep 2018 08:57:06 +0000 (UTC) Message-ID: <1538038625.19334.2.camel@redhat.com> Subject: Re: [PATCH] hv_netvsc: Make sure out channel is fully opened on send From: Mohammed Gamal Reply-To: mgamal@redhat.com To: Haiyang Zhang , Stephen Hemminger , "netdev@vger.kernel.org" Cc: KY Srinivasan , vkuznets , "otubo@redhat.com" , cavery , "linux-kernel@vger.kernel.org" , "devel@linuxdriverproject.org" Date: Thu, 27 Sep 2018 10:57:05 +0200 In-Reply-To: References: <1537979659-26979-1-git-send-email-mgamal@redhat.com> Organization: Red Hat Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 27 Sep 2018 08:57:12 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-09-26 at 17:13 +0000, Haiyang Zhang wrote: > > -----Original Message----- > > From: Mohammed Gamal > > Sent: Wednesday, September 26, 2018 12:34 PM > > To: Stephen Hemminger ; netdev@vger.kernel. > > org > > Cc: KY Srinivasan ; Haiyang Zhang > > ; vkuznets ; > > otubo@redhat.com; cavery ; linux- > > kernel@vger.kernel.org; devel@linuxdriverproject.org; Mohammed > > Gamal > > > > Subject: [PATCH] hv_netvsc: Make sure out channel is fully opened > > on send > > > > Dring high network traffic changes to network interface parameters > > such as > > number of channels or MTU can cause a kernel panic with a NULL > > pointer > > dereference. This is due to netvsc_device_remove() being called and > > deallocating the channel ring buffers, which can then be accessed > > by > > netvsc_send_pkt() before they're allocated on calling > > netvsc_device_add() > > > > The patch fixes this problem by checking the channel state and > > returning > > ENODEV if not yet opened. We also move the call to > > hv_ringbuf_avail_percent() > > which may access the uninitialized ring buffer. > > > > Signed-off-by: Mohammed Gamal > > --- > >  drivers/net/hyperv/netvsc.c | 7 ++++++- > >  1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/net/hyperv/netvsc.c > > b/drivers/net/hyperv/netvsc.c index > > fe01e14..75f1b31 100644 > > --- a/drivers/net/hyperv/netvsc.c > > +++ b/drivers/net/hyperv/netvsc.c > > @@ -825,7 +825,12 @@ static inline int netvsc_send_pkt( > >   struct netdev_queue *txq = netdev_get_tx_queue(ndev, > > packet->q_idx); > >   u64 req_id; > >   int ret; > > - u32 ring_avail = > > hv_get_avail_to_write_percent(&out_channel- > > > outbound); > > > > + u32 ring_avail; > > + > > + if (out_channel->state != CHANNEL_OPENED_STATE) > > + return -ENODEV; > > + > > + ring_avail = hv_get_avail_to_write_percent(&out_channel- > > >outbound); > > When you reproducing the NULL ptr panic, does your kernel include the > following patch? > hv_netvsc: common detach logic > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/c > ommit/?id=7b2ee50c0cd513a176a26a71f2989facdd75bfea > Yes it is included. And the commit did reduce the occurrence of this race condition, but it still nevertheless occurs albeit rarely. > We call netif_tx_disable(ndev) and netif_device_detach(ndev) before > doing the changes  > on MTU or #channels. So there should be no call to start_xmit() when > channel is not ready. > > If you see the check for CHANNEL_OPENED_STATE is still necessary on > upstream kernel (including  > the patch " common detach logic "), we should debug further on the > code and find out the  > root cause. > > Thanks, > - Haiyang >