DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ferruh Yigit <ferruh.yigit@intel.com>
To: zhouyangchao <zhouyates@gmail.com>
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] kni: unregister an unregisterd net_device could cause a kernel crash
Date: Thu, 8 Sep 2016 18:07:08 +0100	[thread overview]
Message-ID: <d343e369-8997-8227-9936-d99dce1a13bf@intel.com> (raw)
In-Reply-To: <1473389167-2758-1-git-send-email-zhouyates@gmail.com>

On 9/9/2016 3:46 AM, zhouyangchao wrote:
> Signed-off-by: zhouyangchao <zhouyates@gmail.com>
> ---
>  lib/librte_eal/linuxapp/kni/kni_misc.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
> index 67e9b7d..ad4e603 100644
> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> @@ -361,7 +361,9 @@ kni_dev_remove(struct kni_dev *dev)
>  		igb_kni_remove(dev->pci_dev);
>  
>  	if (dev->net_dev) {
> -		unregister_netdev(dev->net_dev);
> +		if (dev->netdev->reg_state == NETREG_REGISTERED){

Although this will work, I believe we shouldn't know more about netdev
internals unless we don't have to, and for this case we don't need to
know it. More Linux internal knowledge means more ways to be broken in
the future.
Also I am not sure if reg_state intended to be used by network drivers.

I am for first version of your patch, with missing free_netdev() added
into rollback code.

pseudo code:
net_dev = alloc_netdev()
...
ret = register_netdev()
if (ret)
	kni_dev_remove()
	free_netdev()
	return
kni->net_dev = net_dev


OR if don't want to move where kni->net_dev assigned

net_dev = alloc_netdev()
kni->net_dev = net_dev
...
ret = register_netdev()
if (ret)
	kni->net_dev = NULL
	kni_dev_remove()
	free_netdev()
	return




> +			unregister_netdev(dev->net_dev);
> +		}
>  		free_netdev(dev->net_dev);
>  	}
>  
> 

  parent reply	other threads:[~2016-09-08 17:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-09  2:46 zhouyangchao
2016-09-08 16:44 ` Stephen Hemminger
2016-09-08 17:15   ` Ferruh Yigit
2016-09-09 12:40     ` Thomas Monjalon
2016-09-09 14:33       ` Mcnamara, John
2016-09-10  7:57         ` Thomas Monjalon
2016-09-08 17:07 ` Ferruh Yigit [this message]
2016-09-11  9:59   ` zhouyangchao
2016-09-13 13:13     ` Ferruh Yigit
2016-09-21 16:41       ` Thomas Monjalon
  -- strict thread matches above, loose matches on Subject: below --
2016-09-09  2:42 zhouyangchao
2016-09-08 16:47 ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d343e369-8997-8227-9936-d99dce1a13bf@intel.com \
    --to=ferruh.yigit@intel.com \
    --cc=dev@dpdk.org \
    --cc=zhouyates@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).