From patchwork Thu Oct 20 14:26:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 120821 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B1E05B70BE for ; Fri, 21 Oct 2011 01:26:18 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755699Ab1JTO0N (ORCPT ); Thu, 20 Oct 2011 10:26:13 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:51566 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755693Ab1JTO0L (ORCPT ); Thu, 20 Oct 2011 10:26:11 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1RGtZP-0002ph-WF; Thu, 20 Oct 2011 08:26:08 -0600 Received: from c-98-207-153-68.hsd1.ca.comcast.net ([98.207.153.68] helo=x61.ebiederm.org) by in02.mta.xmission.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1RGtZP-0004FM-8d; Thu, 20 Oct 2011 08:26:07 -0600 Received: from fess.ebiederm.org (fess.int.ebiederm.org [192.168.4.7]) by x61.ebiederm.org (Postfix) with ESMTP id D476939D7A; Thu, 20 Oct 2011 07:24:51 -0700 (PDT) Received: by fess.ebiederm.org (Postfix, from userid 502) id A6A0FC04A1; Thu, 20 Oct 2011 07:26:39 -0700 (PDT) From: ebiederm@xmission.com (Eric W. Biederman) To: David Miller Cc: , Arnd Bergmann , Jason Wang , "Michael S. Tsirkin" , Ian Campbell , Shirly Ma References: Date: Thu, 20 Oct 2011 07:26:39 -0700 In-Reply-To: (Eric W. Biederman's message of "Thu, 20 Oct 2011 07:26:01 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=; ; ; mid=; ; ; hst=in02.mta.xmission.com; ; ; ip=98.207.153.68; ; ; frm=ebiederm@xmission.com; ; ; spf=neutral X-XM-AID: U2FsdGVkX198bG/uBhf2yp9b5Kw+wcUd0m6BmbyDjNg= X-SA-Exim-Connect-IP: 98.207.153.68 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sa02.xmission.com X-Spam-Level: X-Spam-Status: No, score=-1.1 required=8.0 tests=BAYES_00, DCC_CHECK_NEGATIVE, T_TooManySym_01, T_TooManySym_02, UNTRUSTED_Relay, XMNoVowels autolearn=disabled version=3.3.1 X-Spam-Report: * 1.5 XMNoVowels Alpha-numberic number with no vowels * -3.0 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa02 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.4 UNTRUSTED_Relay Comes from a non-trusted relay X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;David Miller X-Spam-Relay-Country: ** Subject: [PATCH 2/5] macvtap: Fix macvtap_open races in the zero copy enable code. X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Fri, 06 Aug 2010 16:31:04 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To see if it is appropriate to enable the macvtap zero copy feature don't test the lowerdev network device flags. Instead test the macvtap network device flags which are a direct copy of the lowerdev flags. This is important because nothing holds a reference to lowerdev and on a very bad day we lowerdev could be a pointer to stale memory. Signed-off-by: Eric W. Biederman --- drivers/net/macvtap.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c index 70aa628..1d9c9c2 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c @@ -343,7 +343,6 @@ static int macvtap_open(struct inode *inode, struct file *file) { struct net *net = current->nsproxy->net_ns; struct net_device *dev = dev_get_by_index(net, iminor(inode)); - struct macvlan_dev *vlan = netdev_priv(dev); struct macvtap_queue *q; int err; @@ -376,12 +375,12 @@ static int macvtap_open(struct inode *inode, struct file *file) /* * so far only KVM virtio_net uses macvtap, enable zero copy between * guest kernel and host kernel when lower device supports zerocopy + * + * The macvlan supports zerocopy iff the lower device supports zero + * copy so we don't have to look at the lower device directly. */ - if (vlan) { - if ((vlan->lowerdev->features & NETIF_F_HIGHDMA) && - (vlan->lowerdev->features & NETIF_F_SG)) - sock_set_flag(&q->sk, SOCK_ZEROCOPY); - } + if ((dev->features & NETIF_F_HIGHDMA) && (dev->features & NETIF_F_SG)) + sock_set_flag(&q->sk, SOCK_ZEROCOPY); err = macvtap_set_queue(dev, file, q); if (err)