Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2800864ybb; Sun, 5 Apr 2020 17:17:35 -0700 (PDT) X-Google-Smtp-Source: APiQypJm90cgaHVjRtjN/+Us9FpwWiSr274gYq4Xti1HDmR5wQTNDU/epW/iYxaIw9OM21BPeBdV X-Received: by 2002:a9d:65d3:: with SMTP id z19mr656704oth.314.1586132254920; Sun, 05 Apr 2020 17:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586132254; cv=none; d=google.com; s=arc-20160816; b=ExhqvlBnd+NiGAeDLHNv5t8JUAuwvANdCIQEn9gy651bnhtD/iCYFdHceJ7ref598e xtwSvpYGdxdJQx8QpzyKCJd0KKPUkIYPQLTlvNU/SFKrdPHwUiJQhhWmg7vKI+Ea9X4m UVuKvZtQewShzC2NYYBHdPB+SAzy8/w7/g1CvDcEMKzlBOc88+HhdUhas1HB+KU9Vxye I/me9iDkfPkSQMYXylbKo9mtMuszJvQ88GsN90bVmolzrS2B08uY+PX+5ZMjszg2tx34 Svc4Czx2TToBTjpEKUew2LPhyyqw/1gq6xiYXji7AjkwUlA5ab7RH1xVYU9z1XHpqNKJ Znxw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FvMvQjpl3mBryOKnAJVIyuL3RVW4h7gov14bS75FPXw=; b=h48RCeB7iKuYCzrp1sgfv4lTKYMthk613ztwGfmjeAjn/+Fx7v/UPDDZUn0EvSqTiW 3JROga/WT8YaqjmmWoHuIPX8HdW8DkgZHuNXNcI+L2bbAOU1eOwEw+0uhRk3h9Ld5bKx tO6sxoXLc1WyHfVNq1F93yy+H8o35+3MHeY+AMOv1HxPAg57pahb7RlSdH0tdOc8fuaM cHVc+nFZGzDOnI/+UNbxlf87eR64l6EUjeTBAWnvVnMfu07fEKbhgsuyrnyrrlS1TPaP HcApJTgNKf2R40FVUlyE4pi1QYMaOEluvqiSD/fqeG/VcdWi/4cDBzlFoT1XSRY252nj hTXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=axToHqAO; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w203si6667604oie.193.2020.04.05.17.17.14; Sun, 05 Apr 2020 17:17:34 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=axToHqAO; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727983AbgDFAQu (ORCPT + 99 others); Sun, 5 Apr 2020 20:16:50 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44960 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727962AbgDFAQt (ORCPT ); Sun, 5 Apr 2020 20:16:49 -0400 Received: by mail-wr1-f67.google.com with SMTP id m17so15284771wrw.11; Sun, 05 Apr 2020 17:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FvMvQjpl3mBryOKnAJVIyuL3RVW4h7gov14bS75FPXw=; b=axToHqAOIoUW0tPCyPuw3kbwg+yxpmxuRs14EhH2H9LOXll04vRfBWWefKvv1mv3iK p9qmgBefhF/WhX2V6ehkGx2pws6u3Q8E4DfQ7ljlaEWVZBZHujGmRN592sjuq8NceZOR x6LSN/tyWbZBa4llilQohu4V7DpAp6bAsgI8CDLeSKscpcuZ33Ik94FJjltx67Bpvx+U TNFyfso74w67dnugOYpkzBk8IDwyAkpmgWM3JgZxnzc7/WUUqDaAADpz2zTh/m6iijz0 zSUkbD9m2pz95T+Gooy7TswRBjnkGuIwXzO3EHIAEoSGw4ljVW4oJX23UJ+IMBORmzmW Vk+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FvMvQjpl3mBryOKnAJVIyuL3RVW4h7gov14bS75FPXw=; b=GtyyrTzd0Snn5NSLJ1vuO9av4EtJxH6v8XXi6vGKB8l4nCMOP+4e5iGqnnaCwBxL+5 bXuCPPYlwFg5dS2qll1Jn4iJQW0O90cbfqwpVxKs7S55QKYYaHNndcOKWMZJ8OudRkcD e2ISRiPCvoSWE7bNJvKJdvrrlIQSGKFk4k+hJn4qaOlVmRILkmQgB18g533C9qCuvrSk Xe+/F0ppKVBuCInXcJgQr1eBl4h/19dJsPfQroy76NT6KMX5psmORLtjPjeH6hLfN7il 965kkauf5AGrfeWq0y0qTNPwgWTl1+H3waVygr71ZN9+QGoC0prMRFR4c8XmAG+i/Toe as7Q== X-Gm-Message-State: AGi0Pub29Xfh5/YbwBcIOvN4RgG3RwAfuZvJGSccHqPCE69j2vaBV10d SvPAKFWt6cDiO0XyKGdwoaxtrdcfOV0eZA== X-Received: by 2002:adf:e445:: with SMTP id t5mr21431205wrm.352.1586132207027; Sun, 05 Apr 2020 17:16:47 -0700 (PDT) Received: from andrea.corp.microsoft.com ([86.61.236.197]) by smtp.gmail.com with ESMTPSA id j9sm817432wrn.59.2020.04.05.17.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Apr 2020 17:16:46 -0700 (PDT) From: "Andrea Parri (Microsoft)" To: linux-kernel@vger.kernel.org Cc: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , linux-hyperv@vger.kernel.org, Michael Kelley , Dexuan Cui , Boqun Feng , Vitaly Kuznetsov , "Andrea Parri (Microsoft)" , Stephen Hemminger , "David S. Miller" , netdev@vger.kernel.org Subject: [PATCH 04/11] hv_netvsc: Disable NAPI before closing the VMBus channel Date: Mon, 6 Apr 2020 02:15:07 +0200 Message-Id: <20200406001514.19876-5-parri.andrea@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200406001514.19876-1-parri.andrea@gmail.com> References: <20200406001514.19876-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vmbus_chan_sched() might call the netvsc driver callback function that ends up scheduling NAPI work. This "work" can access the channel ring buffer, so we must ensure that any such work is completed and that the ring buffer is no longer being accessed before freeing the ring buffer data structure in the channel closure path. To this end, disable NAPI before calling vmbus_close() in netvsc_device_remove(). Suggested-by: Michael Kelley Signed-off-by: Andrea Parri (Microsoft) Acked-by: Stephen Hemminger Cc: "David S. Miller" Cc: --- drivers/hv/channel.c | 6 ++++++ drivers/net/hyperv/netvsc.c | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 23f358cb7f494..256ee90c74460 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -609,6 +609,12 @@ void vmbus_reset_channel_cb(struct vmbus_channel *channel) * the former is accessing channel->inbound.ring_buffer, the latter * could be freeing the ring_buffer pages, so here we must stop it * first. + * + * vmbus_chan_sched() might call the netvsc driver callback function + * that ends up scheduling NAPI work that accesses the ring buffer. + * At this point, we have to ensure that any such work is completed + * and that the channel ring buffer is no longer being accessed, cf. + * the calls to napi_disable() in netvsc_device_remove(). */ tasklet_disable(&channel->callback_event); diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 1b320bcf150a4..806cc85d10033 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -635,9 +635,12 @@ void netvsc_device_remove(struct hv_device *device) RCU_INIT_POINTER(net_device_ctx->nvdev, NULL); - /* And disassociate NAPI context from device */ - for (i = 0; i < net_device->num_chn; i++) + /* Disable NAPI and disassociate its context from the device. */ + for (i = 0; i < net_device->num_chn; i++) { + /* See also vmbus_reset_channel_cb(). */ + napi_disable(&net_device->chan_table[i].napi); netif_napi_del(&net_device->chan_table[i].napi); + } /* * At this point, no one should be accessing net_device -- 2.24.0