Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp458122yba; Wed, 15 May 2019 04:27:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6Nrjh2Gg0BBZ8bKdmfJ3g7qHVPsK3b1dG6xL8bGz2tQZjFolUvO+RuIIaMrBevcf9ib82 X-Received: by 2002:aa7:9563:: with SMTP id x3mr46166680pfq.118.1557919667400; Wed, 15 May 2019 04:27:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557919667; cv=none; d=google.com; s=arc-20160816; b=L81FchCVCZ6hWOH2pjeWOJWp1b/T839Mbv3NsqpM4H4qwsjD6DcdJu/bh7EIN3cQjA VEE2yyeQ5l1+GkgULW3FfZfQFwYaUlNbEVrSNfObYQWyy5pKFTfn47ZCkiF/dviuY3pR kU8/GJkq4Rb6DXHHIYojB7ch9MxbhL5Umj0NQiWIPrmvaEKy+ZJl24QEfFKkSQn/HnOC nfSay4XnWkH07mfsna8DoHcJKVc+9nI26ewN88OLaXPRzaBPEWmT/m8/yQERZQmWeG/o pQQQHizR3PMXaYX/fiGfzQNPS1ewL1JeQHAqPrD3h6TZGSoYEy0ip0AhBXnt8/DcD8rv C+lw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Mo0Gfv6qTMFF9ARRMDyA3cTlfSz6Zrv+AvJLYvViuC4=; b=vX7ki1v+SulB0ENOPbHt3ipYaQNcKPz+EWnCOFe9YCayzOVP1nYYHlwopNcTzDGHHz tjYevqtbsPXiAg9neJjb+Gpuf+cT32F7ACAzljrMhelQjx9EHBBCD2ki2IPHwsFhtUJT M3HUEi+hjDQI7PusLFd7pKs82CgTVP4WOwN4KEcl2SIls5TbtEw6LQO2YL0428jXJ5E1 +RdaPeYZK5H2+d02dBW4EHQnZndtK9wi55IAiN6VuT97vWDj0HbV3/ecRO06lP8jeFpm WmKwD/cn/2ao1s/GxoV6M1B5zEg3wTpzQTzQGyw9Fng0+h3pffDEUx1D+wadXxnu3f4j BKfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bEBUITnF; 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 f1si1550543pgq.4.2019.05.15.04.27.32; Wed, 15 May 2019 04:27:47 -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=@kernel.org header.s=default header.b=bEBUITnF; 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 S1731569AbfEOLZM (ORCPT + 99 others); Wed, 15 May 2019 07:25:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:35864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731937AbfEOLZK (ORCPT ); Wed, 15 May 2019 07:25:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E98E220881; Wed, 15 May 2019 11:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919509; bh=IAEDZlt8A6hzSw6P9V2pngCWWFZv96wHAGTdZ7IvUfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bEBUITnFhn2Dvvk3a2Oux1LG9ntkCAulzqyRWumlndkJG48D6756hzmNp/g9NgDZJ rlqzHT4zqK7BE+xvkq7oSJtT2iiXiEGOVXnomQFLKMatAICjw+b9XV5QKtcMh9oCwP qOgd8e0eua2XybBKT2VyIQkDg4r08XancXUHJjmQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, YueHaibing , Cong Wang , "weiyongjun (A)" , Eric Dumazet , Jason Wang , "David S. Miller" Subject: [PATCH 4.19 103/113] tuntap: synchronize through tfiles array instead of tun->numqueues Date: Wed, 15 May 2019 12:56:34 +0200 Message-Id: <20190515090701.460414501@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090652.640988966@linuxfoundation.org> References: <20190515090652.640988966@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Wang [ Upstream commit 9871a9e47a2646fe30ae7fd2e67668a8d30912f6 ] When a queue(tfile) is detached through __tun_detach(), we move the last enabled tfile to the position where detached one sit but don't NULL out last position. We expect to synchronize the datapath through tun->numqueues. Unfortunately, this won't work since we're lacking sufficient mechanism to order or synchronize the access to tun->numqueues. To fix this, NULL out the last position during detaching and check RCU protected tfile against NULL instead of checking tun->numqueues in datapath. Cc: YueHaibing Cc: Cong Wang Cc: weiyongjun (A) Cc: Eric Dumazet Fixes: c8d68e6be1c3b ("tuntap: multiqueue support") Signed-off-by: Jason Wang Reviewed-by: Wei Yongjun Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/tun.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -708,6 +708,8 @@ static void __tun_detach(struct tun_file tun->tfiles[tun->numqueues - 1]); ntfile = rtnl_dereference(tun->tfiles[index]); ntfile->queue_index = index; + rcu_assign_pointer(tun->tfiles[tun->numqueues - 1], + NULL); --tun->numqueues; if (clean) { @@ -1090,7 +1092,7 @@ static netdev_tx_t tun_net_xmit(struct s tfile = rcu_dereference(tun->tfiles[txq]); /* Drop packet if interface is not attached */ - if (txq >= tun->numqueues) + if (!tfile) goto drop; if (!rcu_dereference(tun->steering_prog)) @@ -1281,6 +1283,7 @@ static int tun_xdp_xmit(struct net_devic rcu_read_lock(); +resample: numqueues = READ_ONCE(tun->numqueues); if (!numqueues) { rcu_read_unlock(); @@ -1289,6 +1292,8 @@ static int tun_xdp_xmit(struct net_devic tfile = rcu_dereference(tun->tfiles[smp_processor_id() % numqueues]); + if (unlikely(!tfile)) + goto resample; spin_lock(&tfile->tx_ring.producer_lock); for (i = 0; i < n; i++) {