Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp468575yba; Wed, 15 May 2019 04:39:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsTz4mslnecWtVUU16KmTYp1T2fi40ajZZMflsQifNBl89xKf5lNM7bAE4Av9nDYRsPEnC X-Received: by 2002:a17:902:4101:: with SMTP id e1mr44390409pld.25.1557920382030; Wed, 15 May 2019 04:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920382; cv=none; d=google.com; s=arc-20160816; b=kwcUFFWEe11Asw0bCnbln6bwpvDVSAUM4V8fR3ZTInzt9usS0BPNaBrbfHV3Tj+yHz h3thVkTv+Z+Ud/WDT6dIJJXJYKnHt71xWW6999zKhMi87g4lFPXPTIdTZMpl3Wb45pQB kR+bs7OwDNTtkHL2y+aKv8nb5J7HWEiazeZYGw7vIULQRwsEIlyPoSnIBzFXbFHselWj GrI63q+My6G34R54mAow7nRFd1kv5WJ9Cmvv6JgvW3VZJXLjgzSZ2PPxos/UiAMoolAI uZh5qnmJB912P0Y4z8VKwCbP8nHKk3+ECuCVVx701zQDH083rU+3/7Xq4F5Wn+m2V3VL Wxqw== 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=DDXBBtfJrMn3n8DueWhP5ajGvZ4CiFXh6LjLc3BVqMc=; b=b/1ZXJrZusNqhMSI8t8pyfW1VE75BrmobjFhnwFoJUdTW6QfhcDuReu+LC/MlBBpYr 6UDaRfST/2NDbujLXwJAVHRZNjVxVlAM3H9gH9WPAbf/buIkCPOL2HgS0FW+hdGLRlXU GTqhXh9sSfCpaVnM+VJvmy0+pecLHr3F0k4WSCXCb6ezYpsxdRbVJlVWu9oeOQxmVtbM np9EpnLex9SH+fr7KqJRdfMXNZjDJedNeEQU/Ch/lO27/zSFVL3ImOJxOhOd/oI1CQzU 66z1X+V1TOJl33ymScVTEGF0oomg6fsExzznY/4f8vQKakkuwuRk8AEoD4MQsPSGPrw0 QdOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1JkxUj9+; 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 f62si1594025plb.339.2019.05.15.04.39.27; Wed, 15 May 2019 04:39:42 -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=1JkxUj9+; 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 S1732653AbfEOLbq (ORCPT + 99 others); Wed, 15 May 2019 07:31:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:43556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732389AbfEOLbp (ORCPT ); Wed, 15 May 2019 07:31:45 -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 96DCF206BF; Wed, 15 May 2019 11:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919905; bh=XEBQsgEMtGwqV0S4Aabkcag4Y+CbX6J+lt0ONluxREA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1JkxUj9+DshaTjIOtyXgy42ev8uZLmkVcVg8l9BMawmnv9BvjSig+RpvdxuxuFn+L Wstnk33kjY4zU3RYHHiVc3huWYqAtW/33VQHVii44TK5qoXyzb7UMysAV3qqrSHFZO Wc9Q7GlVGe+zCw9GxBd8WtUU+Fv6s5bheQ2JX3Ok= 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 5.0 124/137] tuntap: synchronize through tfiles array instead of tun->numqueues Date: Wed, 15 May 2019 12:56:45 +0200 Message-Id: <20190515090702.734469763@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@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 @@ -705,6 +705,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) { @@ -1087,7 +1089,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)) @@ -1310,6 +1312,7 @@ static int tun_xdp_xmit(struct net_devic rcu_read_lock(); +resample: numqueues = READ_ONCE(tun->numqueues); if (!numqueues) { rcu_read_unlock(); @@ -1318,6 +1321,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++) {