Netdev List
 help / color / mirror / Atom feed
* Re: [PATCH 2/2] net: Fix potential memory leak
From: Eric Dumazet @ 2011-09-27 12:07 UTC (permalink / raw)
  To: Huajun Li; +Cc: David Miller, netdev
In-Reply-To: <CA+v9cxbd3GjAigHC+P8coconkdHxNF3dBgoRDtbxqZ6oK_Mw0A@mail.gmail.com>

Le mardi 27 septembre 2011 à 17:58 +0800, Huajun Li a écrit :

> To emulate memory allocation fail case, I added code to return
> '-ENOMEM' from flow_cache_cpu_prepare(...) even if it could allocate
> memory correctly, but did not find panic on my box, maybe the latest
> code changed greatly than 2.6.37. :)

To panic the box, you need to leave a NULL pointer somewhere and
dereference it later, when code assumes it cant be NULL ;)

^ permalink raw reply

* Re: [PATCH v2] net/flow: Fix potential memory leak
From: Eric Dumazet @ 2011-09-27 12:11 UTC (permalink / raw)
  To: Huajun Li; +Cc: David Miller, netdev
In-Reply-To: <CA+v9cxZMwTPXw-_pWc-SRsTs5GqmqK2-46Mr06HxhVN4aH93Yg@mail.gmail.com>

Le mardi 27 septembre 2011 à 18:34 +0800, Huajun Li a écrit :
> While preparing net flow caches, once fail may cause potential memory
> leak , fix it.
> 
> Acked-by: Eric Dumazet <eric.dumazet@gmail.com>


Hmm, please dont add "Acked-by" yourself, when submitting a new patch
version. Let us review the new version and ACK it eventually.

> Signed-off-by: Huajun Li <huajun.li.lee@gmail.com>
> ---
>  net/core/flow.c |   16 +++++++++++++++-
>  1 files changed, 15 insertions(+), 1 deletions(-)
> 
> diff --git a/net/core/flow.c b/net/core/flow.c
> index 555a456..4e60fce 100644
> --- a/net/core/flow.c
> +++ b/net/core/flow.c
> @@ -413,7 +413,7 @@ static int __init flow_cache_init(struct flow_cache *fc)
> 
>  	for_each_online_cpu(i) {
>  		if (flow_cache_cpu_prepare(fc, i))
> -			return -ENOMEM;
> +			goto err;
>  	}
>  	fc->hotcpu_notifier = (struct notifier_block){
>  		.notifier_call = flow_cache_cpu,
> @@ -426,6 +426,20 @@ static int __init flow_cache_init(struct flow_cache *fc)
>  	add_timer(&fc->rnd_timer);
> 
>  	return 0;
> +
> +err:
> +	for_each_possible_cpu(i) {
> +		struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, i);
> +		kfree(fcp->hash_table);
> +		fcp->hash_table = NULL;
> +	}
> +
> +	if (fc->percpu) {

test not needed here, fc->percpu is not NULL


> +		free_percpu(fc->percpu);
> +		fc->percpu = NULL;
> +	}
> +
> +	return -ENOMEM;
>  }
> 
>  static int __init flow_cache_init_global(void)

^ permalink raw reply

* Re: [PATCH 1/2] virtio-net: Verify page list size before fitting into skb
From: Michael S. Tsirkin @ 2011-09-27 12:37 UTC (permalink / raw)
  To: Sasha Levin; +Cc: linux-kernel, Rusty Russell, virtualization, netdev, kvm
In-Reply-To: <1317122429.3467.5.camel@lappy>

On Tue, Sep 27, 2011 at 02:20:29PM +0300, Sasha Levin wrote:
> On Tue, 2011-09-27 at 10:00 +0300, Michael S. Tsirkin wrote:
> > >               skb = page_to_skb(vi, page, len);
> > >               ...
> > 
> > Sorry I don't get it yet. Where is mergeable ignored here?
> 
> The NULL deref happens in page_to_skb(), before merge buffers are
> handled.

The len here is a single buffer length, so for mergeable
buffers it is <= the size of the buffer we gave to hardware,
which is PAGE_SIZE.

        err = virtqueue_add_buf_single(vi->rvq, page_address(page),
                                       PAGE_SIZE, false, page, gfp);
 

Unless of course we are trying to work around broken hardware again,
which I don't have a problem with, but should probably
get appropriate comments in code and trigger a warning.

> I'll test it and see if it's really the case.
> 
> -- 
> 
> Sasha.

^ permalink raw reply

* Re: linux-next: manual merge of the net tree with the wireless-current tree
From: John W. Linville @ 2011-09-27 13:09 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: David Miller, netdev, linux-next, linux-kernel, Johannes Berg,
	Wey-Yi Guy, Emmanuel Grumbach
In-Reply-To: <20110927125132.002db8176a66f85286dcd027@canb.auug.org.au>

On Tue, Sep 27, 2011 at 12:51:32PM +1000, Stephen Rothwell wrote:
> Hi all,
> 
> Today's linux-next merge of the net tree got a conflict in
> drivers/net/wireless/iwlwifi/iwl-scan.c between commit 6c80c39d9a69
> ("iwlagn: fix dangling scan request") from the wireless-current tree and
> commits 63013ae30159 ("iwlagn: priv->status moves to iwl_shared") and
> 6ac2f839b0b2 ("iwlagn: priv->mutex moves to iwl_shared") from the net
> tree.
> 
> I fixed it up (see below) and can carry the fix as necessary.

Looks good, thanks!

-- 
John W. Linville		Someday the world will need a hero, and you
linville@tuxdriver.com			might be all we have.  Be ready.

^ permalink raw reply

* Re: [PATCH 01/15] add Documentation/namespaces/user_namespace.txt (v3)
From: Serge E. Hallyn @ 2011-09-27 13:21 UTC (permalink / raw)
  To: Vasiliy Kulikov
  Cc: Serge Hallyn, akpm, linux-kernel, netdev, containers, dhowells,
	ebiederm, rdunlap, kernel-hardening
In-Reply-To: <20110926191737.GA4562@albatros>

Quoting Vasiliy Kulikov (segoon@openwall.com):
> (cc'ed kernel-hardening)
> 
> 
> Hi Serge,
> 
> I didn't deeply studied the patches yet (sorry!), but I have some
> long-term question about the technique in general.  I couldn't find
> answers to the questions in the documentation.

Great - thanks for your time, Vasiliy.

There is documentation at https://wiki.ubuntu.com/UserNamespace,
and I was adding a Documentation/namespaces/user_namespace.txt file
(which hasn't gone in yet) which you can see here:
https://lkml.org/lkml/2011/7/26/351

But those don't answer your questions sufficiently.

> First, the patches by design expose much kernel code to unprivileged
> userspace processes.  This code doesn't expect malformed data (e.g. VFS,
> specific filesystems, block layer, char drivers, sysadmin part of LSMs,
> etc. etc.).  By relaxing permission rules you greatly increase attack
> surface of the kernel from unprivileged users.  Are you (or somebody
> else) planning to audit this code?

I had wanted to (but didn't) propose a discussion at ksummit about how
best to approach the filesystem code.  That's not even just for user
namespaces - patches have been floated in the past to make mount an
unprivileged operation depending on the FS and the user's permission
over the device and target.  So I don't know if a combination of auditing
and fuzzing is the way to go, or what, and wanted to get input from
some people who are more knowledgeable on that topic than me.

You're right about other kernel code as well.

I'll certainly join in this effort, but don't want to go blindly
charging in without some advice/guidance about the best way to do
this and, if others are interested, coordinate it.

We can start by looking through all code which is currently under
ns_capable(), and analyzing that.  But what tools do we have
available to perform the analysis?

Do you think a kernel summit discussion (i suppose given the late
timing, a beer bof) would be beneficial?  (I wouldn't be there)

> Also, will it be possible to somehow restrict what specific kernel
> facilities are accessible from users (IOW, what root emulation
> limitations are in action)?  It is userful from both points of sysadmin,
> who might not want to allow users to do such things, and from the
> security POV in sense of attack surface reduction.

You're probably thinking along different lines, but this is why I've
been wanting seccomp2 to get pushed through.  So that we can deny a
container the syscalls we know it won't need, especially newer ones,
to reduce the attack surface available to it.

> The patches explicitly enable some features for users on white list
> basis.  It's possible to do it for simple cases, but what are you going
> to do with multiplexing functions where there is a permission check
> before the actual multiplexing?  FS, networking drivers, etc.  Are you
> going to do the same thing as net_namespace does? - For each multiplexed
> entity create bool ->ns_aware which is false by default for all
> "untrusted"/not prepared protocols and is true for audited/prepared
> protocols.  Or probably you have something else in mind?

Ah, I typed the bottom paragraph before realizing what you were actually
asking.  The filesystems are a good example.  In the unprivileged mounts
patchsets, for instance, a flag was added to each filesystem indicating
if it was safe for unprivileged mounting (turned off for all real block
filesystems :).  For targeted capabilities, my goal would be simply to
make sure that each non-netns-aware entity do a (untargeted) capable()
check.  Without pointing to a specific example it's hard to say what I
will do.  It depends on how the code was previously laid out, and what
the maintainer of that subsystem prefers.

The way we're approaching it right now is that by default everything
stays 'capable(X)', so that a non-init user namespace doesn't get the
privileges.  While some of my patchsets this summer didn't follow this,
Eric reminded me that we should first clamp down on the user namespaces
as much as possible, and relax permissions in child namespaces later.
So the small (1-2 patch sized) sets I've been sending the last few
weeks are just trying to fix existing inadequate userid or capability
checks.

-serge

^ permalink raw reply

* Re: linux-next: manual merge of the net tree with the wireless-current tree
From: wwguy @ 2011-09-27 14:41 UTC (permalink / raw)
  To: John W. Linville
  Cc: Stephen Rothwell, David Miller, netdev@vger.kernel.org,
	linux-next@vger.kernel.org, linux-kernel@vger.kernel.org,
	Berg, Johannes, Grumbach, Emmanuel
In-Reply-To: <20110927130926.GA2824@tuxdriver.com>

On Tue, 2011-09-27 at 06:09 -0700, John W. Linville wrote:
> On Tue, Sep 27, 2011 at 12:51:32PM +1000, Stephen Rothwell wrote:
> > Hi all,
> > 
> > Today's linux-next merge of the net tree got a conflict in
> > drivers/net/wireless/iwlwifi/iwl-scan.c between commit 6c80c39d9a69
> > ("iwlagn: fix dangling scan request") from the wireless-current tree and
> > commits 63013ae30159 ("iwlagn: priv->status moves to iwl_shared") and
> > 6ac2f839b0b2 ("iwlagn: priv->mutex moves to iwl_shared") from the net
> > tree.
> > 
> > I fixed it up (see below) and can carry the fix as necessary.
> 
> Looks good, thanks!
> 
Thanks a lot for fixing it.

Wey

^ permalink raw reply

* Re: [PATCH net-next-2.6] can/sja1000: driver for PEAK PCAN PCI/PCIe cards
From: Thomas Wiedemann @ 2011-09-27 14:58 UTC (permalink / raw)
  To: Wolfgang Grandegger
  Cc: linux, Netdev, Oliver Hartkopp, SocketCAN Core Mailing List
In-Reply-To: <4E6F0891.8030600@grandegger.com>

Hi together,

i'll test the patch as soon as the system is available again, which is not 
before next week.


Thomas 


Wolfgang Grandegger <wg@grandegger.com> schrieb am 13.09.2011 09:38:57:

> Hi Oliver,
> 
> On 09/12/2011 05:49 PM, Oliver Hartkopp wrote:
> > On 09/09/11 17:20, Wolfgang Grandegger wrote:
> > 
> > 
> >>
> >>> I'll also test your driver on Monday.
> >>
> >> Thanks,
> > 
> > 
> > Hi Wolfgang,
> > 
> > even if i only had my hardware-patched PEAK PCI ExpressCard hardware 
here
> > (which is to be removed in the supported PCI device list due to the 
missing
> > I2C initialization), i successfully tested your driver.
> > 
> > Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>
> 
> Thanks, I have just sent v2.
> 
> > So let's wait for some feedback from Thomas, when he's back to the 
office ;-)
> 
> Yep, some testing on a 4 channel card would be nice.
> 
> Wolfgang.
> 

^ permalink raw reply

* Re: intel 82599 multi-port performance
From: Martin Millnert @ 2011-09-27 15:30 UTC (permalink / raw)
  To: J.Hwan Kim; +Cc: Alexander Duyck, netdev
In-Reply-To: <4E811C8E.8020508@gmail.com>

Hi J.Hwan,

On Tue, Sep 27, 2011 at 2:45 AM, J.Hwan Kim <frog1120@gmail.com> wrote:
> I tested the 10G - 64byte frames.
> With ixgbe-modified driver, in single port, 92% of packet received in driver
> level and in 2 port we received around 42% packets.

Are you reading packet drops in the 82599's own registries (ie ethtool)?

Regards,
Martin

^ permalink raw reply

* Re: [PATCH 01/15] add Documentation/namespaces/user_namespace.txt (v3)
From: Vasiliy Kulikov @ 2011-09-27 15:56 UTC (permalink / raw)
  To: Serge E. Hallyn
  Cc: Serge Hallyn, akpm, linux-kernel, netdev, containers, dhowells,
	ebiederm, rdunlap, kernel-hardening
In-Reply-To: <20110927132157.GB3111@sergelap>

On Tue, Sep 27, 2011 at 08:21 -0500, Serge E. Hallyn wrote:
> > First, the patches by design expose much kernel code to unprivileged
> > userspace processes.  This code doesn't expect malformed data (e.g. VFS,
> > specific filesystems, block layer, char drivers, sysadmin part of LSMs,
> > etc. etc.).  By relaxing permission rules you greatly increase attack
> > surface of the kernel from unprivileged users.  Are you (or somebody
> > else) planning to audit this code?
> 
> I had wanted to (but didn't) propose a discussion at ksummit about how
> best to approach the filesystem code.  That's not even just for user
> namespaces - patches have been floated in the past to make mount an
> unprivileged operation depending on the FS and the user's permission
> over the device and target.

This is a dangerous operation by itself.  AFAICS, this is the reason why
e.g. FUSE doesn't pass user mount points to other users and even root.
Beginning from violating some rules like existance of single "." and
".." in each directory and ending with filename charsets with /, \000
and things like `, ", ', \ inside.


>  So I don't know if a combination of auditing
> and fuzzing is the way to go,

Maybe the combination of both.  There are no generic recommendations,
it's always limited to the subsystem, checked property, and the
auditor.


> > Also, will it be possible to somehow restrict what specific kernel
> > facilities are accessible from users (IOW, what root emulation
> > limitations are in action)?  It is userful from both points of sysadmin,
> > who might not want to allow users to do such things, and from the
> > security POV in sense of attack surface reduction.
> 
> You're probably thinking along different lines, but this is why I've
> been wanting seccomp2 to get pushed through.  So that we can deny a
> container the syscalls we know it won't need, especially newer ones,
> to reduce the attack surface available to it.

This dependency greatly complicates the things.

First, there is a big misunderstanding between Will and Ingo in what
needs seccompv2 should serve.  Will wants to reduce kernel attack
surface by limiting syscalls and syscall arguments available to a user
(a single task, btw).  Ingo wants to see a full featured filtering
engine, which needs code changes all over the kernel.  Given the needed
changes amounts, it will unlikely reduce attack surface.

You probably don't want Will's version as syscalls filtering is a very
bad abstraction in your case.  user_namespaces likely need Ingo's
version of seccomp as it will be possible to filter e.g. fs-specific
events, but even if it is implemented, it will take a looong time for
your needs IMHO.


Also, I'm afraid for _good_ user_namespace filtering the policy
definition will be too complicated (like SELinux policy definition for
non-trivial applications) if it is implemented in events filtering
terms.


> The way we're approaching it right now is that by default everything
> stays 'capable(X)', so that a non-init user namespace doesn't get the
> privileges.

Great.  I was not sure about it.


>  While some of my patchsets this summer didn't follow this,
> Eric reminded me that we should first clamp down on the user namespaces
> as much as possible, and relax permissions in child namespaces later.

I think it is the only sane way.


> So the small (1-2 patch sized) sets I've been sending the last few
> weeks are just trying to fix existing inadequate userid or capability
> checks.
> 
> -serge

Thanks,

-- 
Vasiliy Kulikov
http://www.openwall.com - bringing security into open computing environments

^ permalink raw reply

* RE: [net-next 02/10] ixgbevf: Fix broken trunk vlan
From: Rose, Gregory V @ 2011-09-27 16:39 UTC (permalink / raw)
  To: Jesse Gross
  Cc: Kirsher, Jeffrey T, davem@davemloft.net, netdev@vger.kernel.org,
	gospo@redhat.com, Jiri Pirko
In-Reply-To: <CAEP_g=-OhrQ5QMbj5_d4BhLHEdDim1_STgy96Vdx5mYFagpVGg@mail.gmail.com>

> -----Original Message-----
> From: Jesse Gross [mailto:jesse@nicira.com]
> Sent: Monday, September 26, 2011 5:54 PM
> To: Rose, Gregory V
> Cc: Kirsher, Jeffrey T; davem@davemloft.net; netdev@vger.kernel.org;
> gospo@redhat.com; Jiri Pirko
> Subject: Re: [net-next 02/10] ixgbevf: Fix broken trunk vlan
> 
> 
> OK, maybe due to hardware limitations what I'm looking for just really
> isn't possible.

From what I can tell that is the case.

>  However, what I'm trying to emphasize is that vconfig
> is not the only way that vlans can be consumed by the network stack
> and active_vlans is just an indication of whether a vlan filter was
> set, nothing more (perhaps I should have picked a better name when I
> originally designed this stuff).

Understood.  The VF is incapable of receiving VLAN traffic unless a filter has been set.  It doesn't do promiscuous mode and any path that doesn't actually end up setting a VLAN filter won't receive any VLAN traffic.

>  In particular, it is not intended to
> determine whether a tag should be stripped off or not because
> non-vconfig users don't necessarily know which vlans they care about
> (think tcpdump or trunking over a bridge).  A major goal of the
> existing vlan infrastructure is to avoid having drivers make
> assumptions about the consumer of the tag and instead just hand all
> information over to the network stack so it can behave in a consistent
> manner.  That's why I was looking for alternate ways to get this
> information without depending on active_vlans as this driver behaves
> quite a bit differently from others, include the ixgbe PF driver.

There are only two paths for the ixgbevf driver to receive VLAN traffic.  Either a VLAN filter has been set, which will result in a bit tag in active_vlans being set or the system administrator in the host VMM has put the VF device in trunk VLAN mode using the 'ip link set <dev> vf <n> <vlanid>' path.  There is no other way for it to receive VLAN traffic, so I think we're fine.  And keep in mind, once the system admin has put the VF device in trunk vlan mode, the VF is no longer allowed, as a policy implemented in the PF driver, to set any other VLAN filters.  Even if it did, it wouldn't work due to the operational characteristics of the VF device HW.

The methods by which the ixgbe driver, as a fully featured Physical Function device, are quite a bit more varied.  I believe you're thinking of the VF device as a typical Ethernet device and that is just not the case.

- Greg


^ permalink raw reply

* Re: [net-next 02/10] ixgbevf: Fix broken trunk vlan
From: Jesse Gross @ 2011-09-27 16:49 UTC (permalink / raw)
  To: Rose, Gregory V
  Cc: Kirsher, Jeffrey T, davem@davemloft.net, netdev@vger.kernel.org,
	gospo@redhat.com, Jiri Pirko
In-Reply-To: <43F901BD926A4E43B106BF17856F0755019C5E5E44@orsmsx508.amr.corp.intel.com>

On Tue, Sep 27, 2011 at 9:39 AM, Rose, Gregory V
<gregory.v.rose@intel.com> wrote:
>> -----Original Message-----
>> From: Jesse Gross [mailto:jesse@nicira.com]
>> Sent: Monday, September 26, 2011 5:54 PM
>> To: Rose, Gregory V
>> Cc: Kirsher, Jeffrey T; davem@davemloft.net; netdev@vger.kernel.org;
>> gospo@redhat.com; Jiri Pirko
>> Subject: Re: [net-next 02/10] ixgbevf: Fix broken trunk vlan
>>
>>
>> OK, maybe due to hardware limitations what I'm looking for just really
>> isn't possible.
>
> From what I can tell that is the case.
>
>>  However, what I'm trying to emphasize is that vconfig
>> is not the only way that vlans can be consumed by the network stack
>> and active_vlans is just an indication of whether a vlan filter was
>> set, nothing more (perhaps I should have picked a better name when I
>> originally designed this stuff).
>
> Understood.  The VF is incapable of receiving VLAN traffic unless a filter has been set.  It doesn't do promiscuous mode and any path that doesn't actually end up setting a VLAN filter won't receive any VLAN traffic.
>
>>  In particular, it is not intended to
>> determine whether a tag should be stripped off or not because
>> non-vconfig users don't necessarily know which vlans they care about
>> (think tcpdump or trunking over a bridge).  A major goal of the
>> existing vlan infrastructure is to avoid having drivers make
>> assumptions about the consumer of the tag and instead just hand all
>> information over to the network stack so it can behave in a consistent
>> manner.  That's why I was looking for alternate ways to get this
>> information without depending on active_vlans as this driver behaves
>> quite a bit differently from others, include the ixgbe PF driver.
>
> There are only two paths for the ixgbevf driver to receive VLAN traffic.  Either a VLAN filter has been set, which will result in a bit tag in active_vlans being set or the system administrator in the host VMM has put the VF device in trunk VLAN mode using the 'ip link set <dev> vf <n> <vlanid>' path.  There is no other way for it to receive VLAN traffic, so I think we're fine.  And keep in mind, once the system admin has put the VF device in trunk vlan mode, the VF is no longer allowed, as a policy implemented in the PF driver, to set any other VLAN filters.  Even if it did, it wouldn't work due to the operational characteristics of the VF device HW.
>
> The methods by which the ixgbe driver, as a fully featured Physical Function device, are quite a bit more varied.  I believe you're thinking of the VF device as a typical Ethernet device and that is just not the case.

Yes, I think you're right.  Thanks for the explanation.

^ permalink raw reply

* Re: Question about memory leak detector giving false positive report for net/core/flow.c
From: Catalin Marinas @ 2011-09-27 16:58 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Huajun Li, linux-mm@kvack.org, netdev, linux-kernel, Tejun Heo,
	Christoph Lameter
In-Reply-To: <1317102918.2796.22.camel@edumazet-laptop>

On Tue, Sep 27, 2011 at 06:55:18AM +0100, Eric Dumazet wrote:
> Yes, it was not a patch, but the general idea for Catalin ;)
> 
> You hit the fact that same zone (embedded percpu space) is now in a
> mixed state.
> 
> In current kernels, the embedded percpu zone is already known by
> kmemleak, but with a large granularity. kmemleak is not aware of
> individual allocations/freeing in this large zone.
> 
> Once kmemleak and percpu allocator are cooperating, we might find more
> kmemleaks. Right now, kmemleak can find pointers in percpu chunks that
> are not anymore reachable (they were freed), and therefore doesnt warn
> of possible memory leaks.

Thanks for suggestions. I need to understand the percpu code a bit
better as it looks that kmemleak is told about some memory blocks twice.

-- 
Catalin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply

* RE: Thanks
From: Song Li @ 2011-09-28  7:51 UTC (permalink / raw)
  To: Recipients

l am a Staff of Hang Seng Bank HongKong, I do not know if we can work
together in transferring $19,500,000.USD from my bank.
Finally if you are interested I shall provide you with more details.
Email: mrsong.lile@yahoo.cn

^ permalink raw reply

* Re: Question about memory leak detector giving false positive report for net/core/flow.c
From: Catalin Marinas @ 2011-09-27 17:01 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Huajun Li, linux-mm@kvack.org, netdev, linux-kernel, Tejun Heo,
	Christoph Lameter
In-Reply-To: <1317102918.2796.22.camel@edumazet-laptop>

On Tue, Sep 27, 2011 at 06:55:18AM +0100, Eric Dumazet wrote:
> Yes, it was not a patch, but the general idea for Catalin ;)
> 
> You hit the fact that same zone (embedded percpu space) is now in a
> mixed state.
> 
> In current kernels, the embedded percpu zone is already known by
> kmemleak, but with a large granularity. kmemleak is not aware of
> individual allocations/freeing in this large zone.

It looks like this comes via the bootmem allocator. Maybe we could
simply call kmemleak_free() on the embedded percpu space and just track
those via the standard percpu API.

-- 
Catalin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply

* Re: intel 82599 multi-port performance
From: Alexander Duyck @ 2011-09-27 17:14 UTC (permalink / raw)
  To: J.Hwan Kim; +Cc: netdev
In-Reply-To: <4E811C8E.8020508@gmail.com>

On 09/26/2011 05:45 PM, J.Hwan Kim wrote:
> On 2011년 09월 27일 01:04, Alexander Duyck wrote:
>> On 09/26/2011 08:42 AM, J.Hwan.Kim wrote:
>>> On 2011년 09월 26일 23:20, Chris Friesen wrote:
>>>> On 09/26/2011 04:26 AM, J.Hwan Kim wrote:
>>>>> Hi, everyone
>>>>>
>>>>> Now, I'm testing a network card including intel 82599.
>>>>> In our experiment, with the driver modified with ixgbe and multi-port
>>>>> enabled,
>>>>
>>>> What do you mean by "modified with ixgbe and multi-port enabled"? You
>>>> shouldn't need to do anything special to use both ports.
>>>>
>>>>> rx performance of each port with 10Gbps of 64bytes frame is
>>>>> a half than when only 1 port is used.
>>>>
>>>> Sounds like a cpu limitation. What is your cpu usage? How are your
>>>> interrupts routed? Are you using multiple rx queues?
>>>>
>>>
>>> Our server is XEON 2.4GHz with 8 cores.
>>> I'm using 4 RSS queues for each port and distributed it's interrupts 
>>> to different cores respectively.
>>> I checked the CPU utilization with TOP, I guess ,it is not cpu 
>>> imitation problem.
>>
>> What kind of rates are you seeing on a single port versus multiple 
>> ports?  There are multiple possibilities in terms of what could be 
>> limiting your performance.
>>
>
> I tested the 10G - 64byte frames.
> With ixgbe-modified driver, in single port, 92% of packet received in 
> driver level and in 2 port we received around 42% packets.

When you say 92% of packets are received are you talking about 92% of 
line rate which would be somewhere around 14.8Mpps?

>> It sounds like you are using a single card, would that be correct?
>
> Yes, I tested a single card with 2 ports.
>
>> If you are running close to line rate on both ports this could be 
>> causing you to saturate the PCIe x8 link.  If you have a second card 
>> available you may want to try installing that in a secondary Gen2 
>> PCIe slot and seeing if you can improve the performance by using 2 
>> PCIe slots instead of one.
>
> I tested it also, if it is tested with 2 card, it seems that the 
> performance of each port is almost same with a single port. (maximum 
> performance)

This more or less confirms what I was thinking.  You are likely hitting 
the PCIe limits of the adapters.  The overhead for 64 byte packets is 
too great and as a result you are exceeding the PCIe bandwidth available 
to the adapter.  In order to achieve line  rate on both ports you would 
likely need to increase your packet size to something along the lines of 
256 bytes so that the additional PCIe overhead only contributes 50% or 
less to the total PCIe traffic across the bus.  Then the 2.5Gb/s of 
network traffic should consume less than 4.0GT/s of PCIe traffic.

Thanks,

Alex

^ permalink raw reply

* Re: [PATCH net-next] tcp: rename tcp_skb_cb flags
From: David Miller @ 2011-09-27 17:25 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev
In-Reply-To: <1317117114.2541.13.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 27 Sep 2011 11:51:54 +0200

> Rename struct tcp_skb_cb "flags" to "tcp_flags" to ease code review and
> maintenance.
> 
> Its content is a combination of FIN/SYN/RST/PSH/ACK/URG/ECE/CWR flags
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied.

^ permalink raw reply

* [PATCH net-next] skge: handle irq better on single port card
From: Stephen Hemminger @ 2011-09-27 17:25 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Most boards with SysKonnect/Marvell Ethernet have only a single port.
For the single port case, use the standard Ethernet driver convention
of allocating IRQ when device is brought up rather than at probe time.

This patch also adds some additional read after writes to avoid any
PCI posting problems when setting the IRQ mask.

The error handling of dual port cards is also changed.  If second port
can not be brought up, then just fail. No point in continuing, since
the failure is most certainly because of out of memory.

It is worth noting that the dual port skge device has a single irq but two
seperate status rings and therefore has two NAPI objects, one for
each port.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

--- a/drivers/net/ethernet/marvell/skge.c	2011-09-27 08:46:08.893778800 -0700
+++ b/drivers/net/ethernet/marvell/skge.c	2011-09-27 10:23:37.557144935 -0700
@@ -113,6 +113,7 @@ static void yukon_init(struct skge_hw *h
 static void genesis_mac_init(struct skge_hw *hw, int port);
 static void genesis_link_up(struct skge_port *skge);
 static void skge_set_multicast(struct net_device *dev);
+static irqreturn_t skge_intr(int irq, void *dev_id);
 
 /* Avoid conditionals by using array */
 static const int txqaddr[] = { Q_XA1, Q_XA2 };
@@ -2568,6 +2569,16 @@ static int skge_up(struct net_device *de
 	if (err)
 		goto free_rx_ring;
 
+	if (hw->ports == 1) {
+		err = request_irq(hw->pdev->irq, skge_intr, IRQF_SHARED,
+				  dev->name, hw);
+		if (err) {
+			netdev_err(dev, "Unable to allocate interrupt %d error: %d\n",
+				   hw->pdev->irq, err);
+			goto free_tx_ring;
+		}
+	}
+
 	/* Initialize MAC */
 	spin_lock_bh(&hw->phy_lock);
 	if (is_genesis(hw))
@@ -2595,11 +2606,14 @@ static int skge_up(struct net_device *de
 	spin_lock_irq(&hw->hw_lock);
 	hw->intr_mask |= portmask[port];
 	skge_write32(hw, B0_IMSK, hw->intr_mask);
+	skge_read32(hw, B0_IMSK);
 	spin_unlock_irq(&hw->hw_lock);
 
 	napi_enable(&skge->napi);
 	return 0;
 
+ free_tx_ring:
+	kfree(skge->tx_ring.start);
  free_rx_ring:
 	skge_rx_clean(skge);
 	kfree(skge->rx_ring.start);
@@ -2640,9 +2654,13 @@ static int skge_down(struct net_device *
 
 	spin_lock_irq(&hw->hw_lock);
 	hw->intr_mask &= ~portmask[port];
-	skge_write32(hw, B0_IMSK, hw->intr_mask);
+	skge_write32(hw, B0_IMSK, (hw->ports == 1) ? 0 : hw->intr_mask);
+	skge_read32(hw, B0_IMSK);
 	spin_unlock_irq(&hw->hw_lock);
 
+	if (hw->ports == 1)
+		free_irq(hw->pdev->irq, hw);
+
 	skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
 	if (is_genesis(hw))
 		genesis_stop(skge);
@@ -3603,7 +3621,8 @@ static int skge_reset(struct skge_hw *hw
 	skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100));
 	skge_write32(hw, B2_IRQM_CTRL, TIM_START);
 
-	skge_write32(hw, B0_IMSK, hw->intr_mask);
+	/* Leave irq disabled until first port is brought up. */
+	skge_write32(hw, B0_IMSK, 0);
 
 	for (i = 0; i < hw->ports; i++) {
 		if (is_genesis(hw))
@@ -3930,31 +3949,39 @@ static int __devinit skge_probe(struct p
 		goto err_out_free_netdev;
 	}
 
-	err = request_irq(pdev->irq, skge_intr, IRQF_SHARED, hw->irq_name, hw);
-	if (err) {
-		dev_err(&pdev->dev, "%s: cannot assign irq %d\n",
-		       dev->name, pdev->irq);
-		goto err_out_unregister;
-	}
 	skge_show_addr(dev);
 
 	if (hw->ports > 1) {
 		dev1 = skge_devinit(hw, 1, using_dac);
-		if (dev1 && register_netdev(dev1) == 0)
-			skge_show_addr(dev1);
-		else {
-			/* Failure to register second port need not be fatal */
-			dev_warn(&pdev->dev, "register of second port failed\n");
-			hw->dev[1] = NULL;
-			hw->ports = 1;
-			if (dev1)
-				free_netdev(dev1);
+		if (!dev1) {
+			err = -ENOMEM;
+			goto err_out_unregister;
 		}
+
+		err = register_netdev(dev1);
+		if (err) {
+			dev_err(&pdev->dev, "cannot register second net device\n");
+			goto err_out_free_dev1;
+		}
+
+		err = request_irq(pdev->irq, skge_intr, IRQF_SHARED,
+				  hw->irq_name, hw);
+		if (err) {
+			dev_err(&pdev->dev, "cannot assign irq %d\n",
+				pdev->irq);
+			goto err_out_unregister_dev1;
+		}
+
+		skge_show_addr(dev1);
 	}
 	pci_set_drvdata(pdev, hw);
 
 	return 0;
 
+err_out_unregister_dev1:
+	unregister_netdev(dev1);
+err_out_free_dev1:
+	free_netdev(dev1);
 err_out_unregister:
 	unregister_netdev(dev);
 err_out_free_netdev:
@@ -3992,14 +4019,19 @@ static void __devexit skge_remove(struct
 
 	spin_lock_irq(&hw->hw_lock);
 	hw->intr_mask = 0;
-	skge_write32(hw, B0_IMSK, 0);
-	skge_read32(hw, B0_IMSK);
+
+	if (hw->ports > 1) {
+		skge_write32(hw, B0_IMSK, 0);
+		skge_read32(hw, B0_IMSK);
+		free_irq(pdev->irq, hw);
+	}
 	spin_unlock_irq(&hw->hw_lock);
 
 	skge_write16(hw, B0_LED, LED_STAT_OFF);
 	skge_write8(hw, B0_CTST, CS_RST_SET);
 
-	free_irq(pdev->irq, hw);
+	if (hw->ports > 1)
+		free_irq(pdev->irq, hw);
 	pci_release_regions(pdev);
 	pci_disable_device(pdev);
 	if (dev1)

^ permalink raw reply

* Re: [PATCH] net: fix a typo in Documentation/networking/scaling.txt
From: David Miller @ 2011-09-27 17:26 UTC (permalink / raw)
  To: jasowang; +Cc: netdev, linux-kernel, rdunlap, linux-doc
In-Reply-To: <20110927100354.18039.92505.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com>

From: Jason Wang <jasowang@redhat.com>
Date: Tue, 27 Sep 2011 18:03:55 +0800

> Signed-off-by: Jason Wang <jasowang@redhat.com>

Applied, thanks.

^ permalink raw reply

* Re: [PATCH] RDSRDMA: Fix cleanup of rds_iw_mr_pool
From: Jonathan Lallinger @ 2011-09-27 17:26 UTC (permalink / raw)
  To: David Miller; +Cc: netdev
In-Reply-To: <20110927.013247.336618301904552114.davem@davemloft.net>

Hello David,

I am ashamed I made the same mistake twice. This happened because I had 
two git trees (I made a second one when kernel.org went down based off 
the github remote). I fixed, built, and ran several tests on the patch, 
and then sent the wrong patch from an old git tree (which was never 
build tested).

I can assure you I have a working patch, and it has been tested by the 
QA group at Chelsio and it builds/runs but there are still additional 
bugs in rds. So once I resolve those I will resend the correct patch 
with some additional fixes.

I am sorry about this and it won't happen again.

Thanks,
  Jonathan

David Miller wrote:
> From: Jonathan Lallinger <jonathan@ogc.us>
> Date: Tue, 13 Sep 2011 14:41:01 -0500
>
>   
>> @@ -548,6 +550,7 @@ static int rds_iw_flush_mr_pool(struct rds_iw_mr_pool *pool, int free_all)
>>  		spin_unlock_irqrestore(&pool->list_lock, flags);
>>  	}
>>  
>> +	atomic_sub(unpinned, &poll->free_pinned);
>>  	atomic_sub(ncleaned, &pool->dirty_count);
>>  	atomic_sub(nfreed, &pool->item_count);
>>  
>>     
>
> net/rds/iw_rdma.c: In function ‘rds_iw_flush_mr_pool’:
> net/rds/iw_rdma.c:553:24: error: ‘poll’ undeclared (first use in this function)
> net/rds/iw_rdma.c:553:24: note: each undeclared identifier is reported only once for each function it appears in
>
> If you didn't even build test it, I know you didn't test it's
> functionality either.
>
> This is crazy.
>
> Well if it's not important enough to even build test this change
> before you post it, then it obviously doesn't matter if the RDMA
> module crashes the kernel when it's unloaded.
>   

^ permalink raw reply

* Re: [PATCH net-next 1/2] be2net: fix multicast filter programming Multicast programming has been broken since commit 5b8821b7. Setting the MULTICAST flag while sending the cmd to the FW was missing. Fixed this.
From: David Miller @ 2011-09-27 17:28 UTC (permalink / raw)
  To: sathya.perla; +Cc: netdev
In-Reply-To: <1317122035-5533-1-git-send-email-sathya.perla@emulex.com>

From: Sathya Perla <sathya.perla@emulex.com>
Date: Tue, 27 Sep 2011 16:43:54 +0530

> Also fixed-up some indentation in the adjacent lines.
> 
> Signed-off-by: Sathya Perla <sathya.perla@emulex.com>

Please don't create multi-line subjects, condense the subject into something that fits on
one 80-character line then put the details in the body of the commit message..

^ permalink raw reply

* Re: [PATCH net-next 1/2] be2net: fix multicast filter programming
From: David Miller @ 2011-09-27 17:29 UTC (permalink / raw)
  To: sathya.perla; +Cc: netdev
In-Reply-To: <1317122713-5640-1-git-send-email-sathya.perla@emulex.com>

From: Sathya Perla <sathya.perla@emulex.com>
Date: Tue, 27 Sep 2011 16:55:13 +0530

>  Re-posting with subject fixed!
> 
>  Multicast programming has been broken since commit 5b8821b7. Setting the
>  MULTICAST flag while sending the cmd to the FW was missing. Fixed this.
> 
> Also fixed-up some indentation in the adjacent lines.
> 
> Signed-off-by: Sathya Perla <sathya.perla@emulex.com>

Applied.

^ permalink raw reply

* Re: [PATCH net-next 2/2] be2net: Show newly flashed FW ver in ethtool
From: David Miller @ 2011-09-27 17:30 UTC (permalink / raw)
  To: sathya.perla; +Cc: netdev, Suresh.Reddy
In-Reply-To: <747547b9-60c7-41b7-9584-23d0374b4503@exht2.ad.emulex.com>

From: Sathya Perla <sathya.perla@emulex.com>
Date: Tue, 27 Sep 2011 16:43:55 +0530

> This fix provides a newly flashed FW version (appended, in braces) along with
> the currently running FW version via ethtool. The newly flashed version runs only after a system reset.
> 
> Signed-off-by: Suresh Reddy <Suresh.Reddy@emulex.com>
> Signed-off-by: Sathya Perla <sathya.perla@emulex.com>

Applied.

^ permalink raw reply

* Re: [PATCH net-next v2] candev: allow SJW user setting for bittiming calculation
From: Oliver Hartkopp @ 2011-09-27 17:32 UTC (permalink / raw)
  To: Wolfgang Grandegger; +Cc: SocketCAN Core Mailing List, Linux Netdev List
In-Reply-To: <4E7D8537.8010302-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>

On 09/24/11 09:22, Wolfgang Grandegger wrote:

> On 09/23/2011 11:32 AM, Pavel Pisa wrote:

>> On base of above analysis, I think that blindly set SJW
>> on maximum is not good idea. It should be at least limited
>> to 5% of bit time. 


(..)


>> SJW is more problematic, but may it be use of 2 or 5%
>> of bittime by default with assurance that zero is
>> replaced by one, would serve to most people pleasure.


(..)

>> But there is still unknown parameter
>> capacity/length of connected wires so there is still
>> something left to user consideration.
> 
> Thanks for your detailed explanation. It clearly shows that adjusting
> SJW is non-trivial and nothing a normal CAN user should deal with. When
> adjusting SJW, do you also need to tweek other bit-timing parameters,
> e.g. tq? I mean, would "ip link set can0 type can bitrate x
> sampling-point y sjw z" work for your setup or do you need to use the
> expert mode setting via "ip link set can0 type can tq ..." anyway?


Hello Wolfgang,

i double checked a specification where i got my requirement to influence the
SJW value from. It says (non literally):

    "Put the SJW to the highest possible value only reduced by tseg2."

The fact that this requirement might no fit to any CAN setup or may not be  in
best academical shape is not my problem. My requirement is to provide an easy
way to move the SJW away from it's default value, which is currently
hard-coded to 1 in the can-dev framework when using it's bittiming calculation
function.

As almost everything is already done (only the provided SJW is not evaluated
in dev.c) this patch is IMO an valid option to support it. If Joe user can
tune the sampling point, why should he not be able to influence the SJW if he
thinks, he knows what he's doing?

Especially as the good working bittiming calculation is not touched in any way
and the default SJW remains 1 (even if '0' is provided as user input).

Regards,
Oliver

^ permalink raw reply

* Re: [PATCH net-next] skge: handle irq better on single port card
From: David Miller @ 2011-09-27 17:41 UTC (permalink / raw)
  To: shemminger; +Cc: netdev
In-Reply-To: <20110927102523.5f8b7f2a@nehalam.linuxnetplumber.net>

From: Stephen Hemminger <shemminger@vyatta.com>
Date: Tue, 27 Sep 2011 10:25:23 -0700

> Most boards with SysKonnect/Marvell Ethernet have only a single port.
> For the single port case, use the standard Ethernet driver convention
> of allocating IRQ when device is brought up rather than at probe time.
> 
> This patch also adds some additional read after writes to avoid any
> PCI posting problems when setting the IRQ mask.
> 
> The error handling of dual port cards is also changed.  If second port
> can not be brought up, then just fail. No point in continuing, since
> the failure is most certainly because of out of memory.
> 
> It is worth noting that the dual port skge device has a single irq but two
> seperate status rings and therefore has two NAPI objects, one for
> each port.
> 
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

Applied.

^ permalink raw reply

* Re: [PATCH] w5300: add WIZnet W5300 Ethernet driver
From: Francois Romieu @ 2011-09-27 17:45 UTC (permalink / raw)
  To: Taehun Kim; +Cc: netdev, linux-kernel
In-Reply-To: <CAOkfWjcHxh60D9KvxLfgL0tw9XdPyDN9xr7q+9V+nM6B6g8tDA@mail.gmail.com>


Taehun Kim <kth3321@gmail.com> :
[...]
> Please check this patch. Not only it had been finished testing, but
> also confirmed by WIZnet(http://wiznet.co.kr).

(please don't include 1080 lines of continuous quote)

> If any problems, please let me know.

> WIZnet W5300 is a network chip into which 10/100 Ethernet controller, MAC,
> and TCP/IP are integrated.
> This driver supports just Ethernet function in W5300.
> 
> Signed-off-by: Taehun Kim <kth3321@gmail.com>
> ---
>  drivers/net/Kconfig  |    5 +
>  drivers/net/Makefile |    1 +
>  drivers/net/w5300.c  |  669 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  drivers/net/w5300.h  |  350 ++++++++++++++++++++++++++

The layout has changed. See David Miller's -next tree at :

git://github.com/davem330/net-next.git

It should probably go into drivers/net/ethernet/wiznet.

> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -2016,6 +2016,11 @@ config LANTIQ_ETOP
>  	help
>  	  Support for the MII0 inside the Lantiq SoC
>  
> +config W5300
> +	tristate "WIZnet W5300 ethernet driver"
> +	depends on ARM
> +	help

(nit)
	---help---
[...]
> diff --git a/drivers/net/w5300.c b/drivers/net/w5300.c
> new file mode 100644
> index 0000000..fcc2579
> --- /dev/null
> +++ b/drivers/net/w5300.c
[...]
> +#define DRV_VERSION "1.0"
> +#define DRV_RELDATE "Sept 17, 2011"
> +
> +static const char driver_info[] =
> +	KERN_INFO DEV_NAME ": Ethernet driver v" DRV_VERSION "("
> +	DRV_RELDATE ")\n";
> +
> +MODULE_AUTHOR("Taehun Kim <kth3321@gmail.com>");
> +MODULE_DESCRIPTION("WIZnet W5300 Ethernet driver");
> +MODULE_VERSION(DRV_VERSION);
> +MODULE_LICENSE("GPL");
> +
> +/* Transmit timeout, default 5 seconds. */
> +static int watchdog = 5000;
> +module_param(watchdog, int, 0400);
> +MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");
> +
> +/*
> + * This is W5300 information structure.
> + * Additional information is included in struct net_device.
> + */
> +struct wiz_private {
> +	void __iomem *base;
> +	struct net_device *dev;
> +	u8 rxbuf_conf[MAX_SOCK_NUM];
> +	u8 txbuf_conf[MAX_SOCK_NUM];
> +	struct net_device_stats stats;
> +	struct napi_struct napi;
> +	spinlock_t lock;
> +};
> +
> +/* Default MAC address. */
> +static const u8 w5300_defmac[6] = {0x00, 0x08, 0xDC, 0xA0, 0x00, 0x01};

__initdata ?

> +
> +/* Default RX/TX buffer size(KByte). */
> +static const u8 w5300_rxbuf_conf[MAX_SOCK_NUM] = { 64, 0, 0, 0, 0, 0, 0, 0 };
> +static const u8 w5300_txbuf_conf[MAX_SOCK_NUM] = { 64, 0, 0, 0, 0, 0, 0, 0 };

__initdata ?

The size is known: you can save some 0.

> +/* Notifying packet size in the RX FIFO */
> +static int
> +w5300_get_rxsize(struct wiz_private *wp, int s)
> +{
> +	u32 val;
> +
> +	val = w5300_read(wp, Sn_RX_RSR(s));
> +	val = (val << 16) + w5300_read(wp, Sn_RX_RSR2(s));
> +	return val;
> +}
> +
> +/* Packet Receive Function. It reads received packet from the Rx FIFO. */
> +static int
> +w5300_recv_data(struct wiz_private *wp, int s,
> +		u8 *buf, ssize_t len, int swap_enable)

The status code that this method returns is never checked.

> +{
> +	int i;
> +	u16 recv_data;
> +
> +	if (unlikely(len <= 0))
> +		return 0;
> +
> +	if (swap_enable) {
> +		/* read from RX FIFO */
> +		for (i = 0; i < len; i += 2) {
> +			recv_data = w5300_read(wp, Sn_RX_FIFO(s));
> +			buf[i] = (u8) ((recv_data & 0xFF00) >> 8);
> +			buf[i + 1] = (u8) (recv_data & 0x00FF);
> +		}
> +	} else {
> +		for (i = 0; i < len; i += 2) {
> +			recv_data = w5300_read(wp, Sn_RX_FIFO(s));
> +			buf[i] = (u8) (recv_data & 0x00FF);
> +			buf[i + 1] = (u8) ((recv_data & 0xFF00) >> 8);
> +		}
> +	}

You should use le{16/32}_to_cpu, swab16/32 and friends in place of this
'swap_enable' thing.

> +	return len;
> +}
> +
> +/* Setting MAC address of W5300 */
> +static void
> +w5300_set_macaddr(struct wiz_private *wp, u8 * addr)
> +{
> +	w5300_write(wp, SHAR, (u16) (addr[0] << 8) | (u16) addr[1]);
> +	w5300_write(wp, SHAR2, (u16) (addr[2] << 8) | (u16) addr[3]);
> +	w5300_write(wp, SHAR4, (u16) (addr[4] << 8) | (u16) addr[5]);
> +}
> +
> +/* Opening channels of W5300 */
> +static int
> +w5300_open(struct wiz_private *wp, u32 type)

Name it w5300_channel_open or more adequately w5300_channel_0_open 
as it is hardwired to channel 0 ?

The status code that this method returns is never checked.

> +{
> +	/* Which type will be used for open? */
> +	switch (type) {
> +	case Sn_MR_MACRAW:
> +	case Sn_MR_MACRAW_MF:
> +		w5300_write(wp, Sn_MR(0), type);
> +		break;
> +	default:
> +		printk(KERN_ERR "%s: Unknown socket type (%d)\n",
> +		       DEV_NAME, type);
> +		return -EFAULT;
> +	}
> +	w5300_write(wp, Sn_PORTR(0), 5300);
> +
> +	w5300_write(wp, Sn_CR(0), Sn_CR_OPEN);
> +	while (w5300_read(wp, Sn_CR(0)))
> +		udelay(1);
> +
> +	return 0;
> +}
> +
> +/* Activating the interrupt of related channel */
> +static void
> +w5300_interrupt_enable(struct wiz_private *wp, int s)
> +{
> +	u16 mask;
> +	mask = w5300_read(wp, IMR);

Please insert an empty line after the declaration.

> +	mask |= (0x01 << s);
> +	w5300_write(wp, IMR, mask);
> +}

It could imho fit in a single line.

> +
> +/* De-activating the interrupt of related channel */
> +static void
> +w5300_interrupt_disable(struct wiz_private *wp, int s)
> +{
> +	u16 mask;
> +	mask = w5300_read(wp, IMR);
> +	mask &= ~(0x01 << s);
> +	w5300_write(wp, IMR, mask);
> +}
> +
> +/* W5300 initialization function */
> +static int
> +w5300_reset(struct net_device *dev)

The status code that this method returns is never checked.

> +{
> +	struct wiz_private *wp = netdev_priv(dev);
> +	u32 txbuf_total = 0, i;
> +	u16 mem_cfg = 0;
> +
> +	DPRINTK("%s: w5300 chip reset\n", __func__);
> +
> +	/* W5300 is initialized by sending RESET command. */
> +	w5300_write(wp, MR, MR_RST);
> +	mdelay(5);
> +
> +	/* Mode Register Setting
> +	 * Ping uses S/W stack of the Linux kernel. Set the Ping Block.*/
> +	w5300_write(wp, MR, MR_WDF(1) | MR_PB);
> +
> +	/* Setting MAC address */
> +	w5300_set_macaddr(wp, dev->dev_addr);
> +
> +	/* Setting the size of Rx/Tx FIFO */
> +	for (i = 0; i < MAX_SOCK_NUM; ++i) {
> +		if (wp->rxbuf_conf[i] > 64) {
> +			printk(KERN_ERR "%s: Illegal Channel(%d) RX memory size.\n",
> +			       DEV_NAME, i);

You can use nice netif_{err/info/...} helpers.

> +			return -EINVAL;
> +		}
> +		if (wp->txbuf_conf[i] > 64) {
> +			printk(KERN_ERR "%s: Illegal Channel(%d) TX memory size.\n",
> +			       DEV_NAME, i);
> +			return -EINVAL;
> +		}
> +		txbuf_total += wp->txbuf_conf[i];
> +	}
> +
> +	if (txbuf_total % 8) {
> +		printk(KERN_ERR "%s: Illegal memory size register setting.\n",
> +		       DEV_NAME);
> +		return -EINVAL;
> +	}
> +	w5300_write(wp, RMSR0,
> +		    (u16) (wp->rxbuf_conf[0] << 8) | (u16) wp->rxbuf_conf[1]);
> +	w5300_write(wp, RMSR2,
> +		    (u16) (wp->rxbuf_conf[2] << 8) | (u16) wp->rxbuf_conf[3]);
> +	w5300_write(wp, RMSR4,
> +		    (u16) (wp->rxbuf_conf[4] << 8) | (u16) wp->rxbuf_conf[5]);
> +	w5300_write(wp, RMSR6,
> +		    (u16) (wp->rxbuf_conf[6] << 8) | (u16) wp->rxbuf_conf[7]);
> +	w5300_write(wp, TMSR0,
> +		    (u16) (wp->txbuf_conf[0] << 8) | (u16) wp->txbuf_conf[1]);
> +	w5300_write(wp, TMSR2,
> +		    (u16) (wp->txbuf_conf[2] << 8) | (u16) wp->txbuf_conf[3]);
> +	w5300_write(wp, TMSR4,
> +		    (u16) (wp->txbuf_conf[4] << 8) | (u16) wp->txbuf_conf[5]);
> +	w5300_write(wp, TMSR6,
> +		    (u16) (wp->txbuf_conf[6] << 8) | (u16) wp->txbuf_conf[7]);

w5300_write expects an u16: the u8 will be correctly expanded before the shift
even if you remove the casts.

Btw this is nothing more than

	for (i = 0; i < 4; i++) {
		u16 size = (wp->rxbuf_conf[2*i] << 8) | wp->rxbuf_conf[2*i + 1];

		w5300_write(wp, RMSR0 + 2*i, size);
	}

It may even save a few bytes if you factor it out with a method accepting
{ wp->rxbuf_conf, RMSR0 } (resp. { wp->txbuf_conf, TMSR0 }) as parameters.

> +
> +	/* Setting FIFO Memory Type (TX&RX) */
> +	for (i = 0; i < txbuf_total / 8; ++i) {
> +		mem_cfg <<= 1;
> +		mem_cfg |= 1;
> +	}
> +	w5300_write(wp, MTYPER, mem_cfg);
> +
> +	/* Masking all interrupts */
> +	w5300_write(wp, IMR, 0x0000);
> +
> +	return 0;
> +}
> +
> +/* Interrupt Handler(ISR) */
> +static irqreturn_t
> +wiz_interrupt(int irq, void *dev_instance)
> +{
> +	struct net_device *dev = dev_instance;
> +	struct wiz_private *wp = netdev_priv(dev);
> +	unsigned long isr, ssr;

s/unsigned long/u16/

> +	int s;
> +
> +	isr = w5300_read(wp, IR);
> +
> +	/* Completing all interrupts at a time. */
> +	while (isr) {
> +		w5300_write(wp, IR, isr);
> +
> +		/* Finding the channel to create the interrupt */
> +		s = find_first_bit(&isr, sizeof(u16));
> +		ssr = w5300_read(wp, Sn_IR(s));
> +		/* socket interrupt is cleared. */
> +		w5300_write(wp, Sn_IR(s), ssr);
> +		DPRINTK("%s: ISR = %X, SSR = %X, s = %X\n",
> +			__func__, isr, ssr, s);
> +		if (likely(!s)) {
> +			if (ssr & Sn_IR_RECV) {
> +				/* De-activation of interrupt */
> +				w5300_interrupt_disable(wp, 0);
> +				/* Receiving by polling method */
> +				napi_schedule(&wp->napi);
> +			}
> +		}
> +
> +		/* Is there any interrupt to be processed? */
> +		isr = w5300_read(wp, IR);
> +	}
> +
> +	return IRQ_HANDLED;

The hardware implementation is supposed to enforce that the 'while' is
always entered, right ?

> +}
> +
> +static int
> +wiz_open(struct net_device *dev)
> +{
> +	struct wiz_private *wp = netdev_priv(dev);
> +	int ret;
> +
> +	napi_enable(&wp->napi);
> +
> +	ret = request_irq(dev->irq, wiz_interrupt,
> +			  IRQF_IRQPOLL, dev->name, dev);

Why do you use IRQF_IRQPOLL ?

> +	if (ret < 0) {
> +		printk(KERN_ERR "%s: request_irq() error!\n", DEV_NAME);
> +		return ret;
> +	}
> +
> +	/* Activating the interrupt of channel 0 that is used for MACRAW. */
> +	w5300_interrupt_enable(wp, 0);
> +
> +	/* Sending OPEN command to use channel 0 as MACRAW mode. */
> +	w5300_open(wp, Sn_MR_MACRAW_MF);
> +
> +	netif_start_queue(dev);
> +
> +	return 0;
> +}
> +
> +static int
> +wiz_close(struct net_device *dev)
> +{
> +	struct wiz_private *wp = netdev_priv(dev);
> +
> +	DPRINTK("%s\n", __func__);
> +
> +	napi_disable(&wp->napi);
> +
> +	/* Interrupt masking of all channels */
> +	w5300_write(wp, IMR, 0x0000);
> +	netif_stop_queue(dev);

The upperlayer takes care of netif_stop_queue. It is not needed.

> +	w5300_write(wp, Sn_CR(0), Sn_CR_CLOSE);
> +	free_irq(dev->irq, dev);
> +
> +	return 0;
> +}
> +
> +static int
> +w5300_send_data(struct wiz_private *wp, u8 * buf, ssize_t len)
> +{
> +	int i;
> +	u16 send_data;
> +
> +	/* Writing packets in to Tx FIFO */
> +	for (i = 0; i < len; i += 2) {
> +		send_data = (buf[i] << 8) | buf[i+1];
> +		w5300_write(wp, Sn_TX_FIFO(0), send_data);
> +	}
> +
> +	w5300_write(wp, Sn_TX_WRSR(0), (u16)(len >> 16));
> +	w5300_write(wp, Sn_TX_WRSR2(0), (u16)len);
> +	w5300_write(wp, Sn_CR(0), Sn_CR_SEND);
> +	while (w5300_read(wp, Sn_CR(0)))
> +		udelay(1);
> +
> +	return len;
> +}
> +
> +/* Function to transmit data at the MACRAW mode */
> +static int
> +wiz_start_xmit(struct sk_buff *skb, struct net_device *dev)
> +{
> +	struct wiz_private *wp = netdev_priv(dev);
> +	int ret;
> +
> +	DPRINTK("%s: MAC_RAW SEND packet size = %d\n", __func__, skb->len);
> +
> +	ret = w5300_send_data(wp, skb->data, skb->len);
> +
> +	/* Statistical Process */
> +	if (ret < 0) {

Something is pretty wrong if ret (= skb->len) is < 0.

> +		wp->stats.tx_dropped++;
> +	} else {
> +		wp->stats.tx_bytes += skb->len;
> +		wp->stats.tx_packets++;
> +		dev->trans_start = jiffies;
> +	}
> +	dev_kfree_skb(skb);
> +
> +	return 0;

s/0/NETDEV_TX_OK/

> +}
> +
> +static struct net_device_stats *
> +wiz_get_stats(struct net_device *dev)
> +{
> +	struct wiz_private *wp = netdev_priv(dev);
> +	DPRINTK("%s: get status\n", __func__);
> +	return &wp->stats;
> +}
> +
> +/* It is called when multi-cast list or flag is changed. */
> +static void
> +wiz_set_multicast(struct net_device *dev)
> +{
> +	struct wiz_private *wp = netdev_priv(dev);
> +
> +	DPRINTK("%s: multicast\n", __func__);
> +	if (dev->flags & IFF_PROMISC)
> +		w5300_open(wp, Sn_MR_MACRAW);
> +	else
> +		w5300_open(wp, Sn_MR_MACRAW_MF);

Use a ternary operator ?

> +}
> +
> +static int
> +wiz_set_mac_address(struct net_device *dev, void *addr)
> +{
> +	struct wiz_private *wp = netdev_priv(dev);
> +	struct sockaddr *sock_addr = addr;
> +
> +	DPRINTK("%s: set mac address\n", __func__);
> +
> +	spin_lock(&wp->lock);
> +	/* Changing MAC address of W5300 */
> +	w5300_set_macaddr(wp, sock_addr->sa_data);
> +	/* Changing MAC address of material structure to manage W5300 */
> +	memcpy(dev->dev_addr, sock_addr->sa_data, dev->addr_len);
> +	spin_unlock(&wp->lock);
> +
> +	return 0;
> +}
> +
> +static void
> +wiz_tx_timeout(struct net_device *dev)
> +{
> +	struct wiz_private *wp = netdev_priv(dev);
> +	unsigned long flags;
> +
> +	printk(KERN_WARNING "%s: Transmit timeout\n", dev->name);
> +
> +	spin_lock_irqsave(&wp->lock, flags);
> +	/* Initializing W5300 chip. */
> +	w5300_reset(dev);
> +	/* Waking up network interface */
> +	netif_wake_queue(dev);
> +	spin_unlock_irqrestore(&wp->lock, flags);
> +}
> +
> +/*
> + * Polling Function to process only receiving at the MACRAW mode.
> + * De-activating the interrupt when recv interrupt occurs,
> + * and processing the RECEIVE with this Function
> + * Activating the interrupt after completing RECEIVE process
> + * As recv interrupt often occurs at short intervals,
> + * there will system load in case that interrupt handler process the RECEIVE.
> + */
> +static int
> +wiz_rx_poll(struct napi_struct *napi, int budget)
> +{
> +	struct sk_buff *skb;

It should be declared in the 'while' loop below.

> +	struct wiz_private *wp = container_of(napi, struct wiz_private, napi);
> +	struct net_device *dev = wp->dev;
> +	u16 rxbuf_len, pktlen;

These should be declared in the 'while' loop below.
rxbuf_len can go away.

> +	u32 crc;

It should be declared in the 'while' loop below.

> +	int npackets = 0;
> +
> +	/* Processing the RECEIVE during Rx FIFO is containing any packet */
> +	while (w5300_get_rxsize(wp, 0) > 0) {
> +
> +		/* The first 2byte is the information about packet lenth. */
> +		w5300_recv_data(wp, 0, (u8 *)&pktlen, 2, 0);
> +		DPRINTK("%s: pktlen = %d\n", __func__, pktlen);
> +
> +		/*
> +		 * Allotting the socket buffer in which packet will be contained
> +		 * Ethernet packet is of 14byte.
> +		 * In order to make it multiplied by 2, the buffer allocation
> +		 * should be 2bytes bigger than the packet.
> +		 */
> +		skb = dev_alloc_skb(pktlen + 2);

netdev_alloc_skb_ip_align

> +		if (!skb) {
> +			u8 *temp;
> +			printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n",
> +			       dev->name);
> +			temp = kmalloc(pktlen + 4, GFP_KERNEL);

- "Memory squeeze ? Let's allocate more..."
- unchecked kmalloc
- GFP_KERNEL in poll

Either you use an already allocated buffer (it could even be static) or
you loop with a small on-stack buffer.

> +			wp->stats.rx_dropped++;
> +			w5300_recv_data(wp, 0, temp, pktlen + 4, 1);
> +			kfree(temp);
> +			return -ENOMEM;

poll is supposed to return the work actually done, not -Exyz.

> +		}
> +
> +		/* Initializing the socket buffer */
> +		skb->dev = dev;
> +		skb_reserve(skb, 2);
> +		skb_put(skb, pktlen);
> +
> +		/* Reading packets from W5300 Rx FIFO into socket buffer. */
> +		w5300_recv_data(wp, 0, (u8 *)skb->data, pktlen, 1);
> +
> +		/* Reading and discarding 4byte CRC. */
> +		w5300_recv_data(wp, 0, (u8 *)&crc, 4, 0);
> +
> +		/* The packet type is Ethernet. */
> +		skb->protocol = eth_type_trans(skb, dev);
> +
> +		/* Passing packets to uppder stack (kernel). */
> +		netif_receive_skb(skb);
> +
> +		/* Processing statistical information */
> +		wp->stats.rx_packets++;
> +		wp->stats.rx_bytes += pktlen;
> +		wp->dev->last_rx = jiffies;
> +		rxbuf_len -= pktlen;
> +		npackets++;
> +
> +		if (npackets >= budget)
> +			break;
> +	}
> +
> +	/* If packet number is smaller than budget when getting out of loopback,
> +	 * the RECEIVE process is completed. */
> +	if (npackets < budget) {
> +		unsigned long flags;
> +		spin_lock_irqsave(&wp->lock, flags);
> +		w5300_interrupt_enable(wp, 0);
> +		__napi_complete(napi);
> +		spin_unlock_irqrestore(&wp->lock, flags);
> +	}
> +	return npackets;
> +}
> +
> +static const struct net_device_ops wiz_netdev_ops = {
> +	.ndo_open       = wiz_open,
> +	.ndo_stop       = wiz_close,
> +	.ndo_validate_addr      = eth_validate_addr,
> +	.ndo_set_mac_address    = wiz_set_mac_address,
> +	.ndo_set_multicast_list = wiz_set_multicast,
> +	.ndo_get_stats      = wiz_get_stats,
> +	.ndo_start_xmit     = wiz_start_xmit,
> +	.ndo_tx_timeout     = wiz_tx_timeout,

Please add more tabs and align everything.

> +};
> +
> +/* Initialize W5300 driver. */
> +static int __devinit
> +w5300_drv_probe(struct platform_device *pdev)
> +{
> +	struct net_device *dev;
> +	struct wiz_private *wp;
> +	struct resource *res;
> +	void __iomem *addr;
> +	int ret;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res) {
> +		ret  = -ENODEV;
> +		goto out;
> +	}
> +
> +	/* Request the chip register regions. */
> +	if (!request_mem_region(res->start, SZ_1M, DEV_NAME)) {
> +		ret = -EBUSY;
> +		goto out;
> +	}
> +
> +	/* Allocatting struct net_device structure which is managing W5300 */
> +	dev = alloc_etherdev(sizeof(struct wiz_private));
> +	if (!dev) {
> +		ret = -ENOMEM;
> +		goto release_region;
> +	}
> +
> +	dev->dma = (unsigned char)-1;
> +	dev->irq = platform_get_irq(pdev, 0);
> +	wp = netdev_priv(dev);
> +	wp->dev = dev;
> +	addr = ioremap(res->start, SZ_1M);
> +	if (!addr) {
> +		ret = -ENOMEM;
> +		goto release_both;
> +	}
> +
> +	platform_set_drvdata(pdev, dev);
> +	wp->base = addr;
> +
> +	spin_lock_init(&wp->lock);
> +
> +	/* Initialization of Rx/Tx FIFO size */
> +	memcpy(wp->rxbuf_conf, w5300_rxbuf_conf, MAX_SOCK_NUM * sizeof(u8));
> +	memcpy(wp->txbuf_conf, w5300_txbuf_conf, MAX_SOCK_NUM * sizeof(u8));

You can spare the sizeof(u8).

> +
> +	dev->base_addr = res->start;

Please leave base_addr rest in peace.

> +	dev->addr_len = 6;	/* MAC address length. */

Useless, it's already done through alloc_etherdev->ether_setup.

> +	memcpy(dev->dev_addr, w5300_defmac, dev->addr_len);
> +
> +	ether_setup(dev);

Useless, see alloc_etherdev.

> +	dev->netdev_ops = &wiz_netdev_ops;
> +	/* Setting napi. Enabling to process max 16 packets at a time. */
> +	netif_napi_add(dev, &wp->napi, wiz_rx_poll, 16);
> +
> +	dev->watchdog_timeo = msecs_to_jiffies(watchdog);
> +
> +	strcpy(dev->name, "eth%d");

Useless.

> +
> +	w5300_reset(dev);
> +
> +	ret = register_netdev(dev);
> +	if (ret != 0) {
> +		platform_set_drvdata(pdev, NULL);
> +		iounmap(addr);
> +release_both:
> +		free_netdev(dev);
> +release_region:
> +		release_resource(res);
> +	}
> +out:
> +	return ret;
> +}
> +
> +static int __devexit
> +w5300_drv_remove(struct platform_device *pdev)
> +{
> +	struct net_device *dev = platform_get_drvdata(pdev);
> +	struct wiz_private *wp = netdev_priv(dev);
> +	struct resource *res;
> +
> +	platform_set_drvdata(pdev, NULL);
> +	unregister_netdev(dev);
> +
> +	if (wp->base != NULL)
> +		iounmap(wp->base);

wp->base can not be NULL here.

> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (res != NULL)
> +		release_resource(res);

release_resource is supposed to balance request_resource, not
request_mem_resource.

> +
> +	free_netdev(dev);
> +
> +	return 0;
> +}
> +
> +static int
> +w5300_drv_suspend(struct platform_device *pdev, pm_message_t state)
> +{
> +	struct net_device *dev = platform_get_drvdata(pdev);
> +
> +	if (dev) {

Useless.

> +		struct wiz_private *wp = netdev_priv(dev);
> +
> +		if (netif_running(dev)) {
> +			netif_device_detach(dev);
> +			w5300_write(wp, IMR, 0x0000);
> +			w5300_write(wp, Sn_CR(0), Sn_CR_CLOSE);
> +		}
> +	}
> +	return 0;
> +}
> +
> +static int
> +w5300_drv_resume(struct platform_device *pdev)
> +{
> +	struct net_device *dev = platform_get_drvdata(pdev);
> +
> +	if (dev) {

Useless.

> +		struct wiz_private *wp = netdev_priv(dev);
> +
> +		if (netif_running(dev)) {
> +			w5300_reset(dev);
> +			w5300_interrupt_enable(wp, 0);
> +			w5300_open(wp, Sn_MR_MACRAW_MF);
> +			netif_device_attach(dev);
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static struct platform_driver w5300_driver = {
> +	.probe  = w5300_drv_probe,
> +	.remove = __devexit_p(w5300_drv_remove),
> +	.suspend	 = w5300_drv_suspend,
> +	.resume	 = w5300_drv_resume,
> +	.driver	 = {
> +		.name	 = DEV_NAME,
> +		.owner	= THIS_MODULE,
> +	},

Please fix the alignment and don't mix tabs and space.

> +};
> +
> +static int __init
> +wiz_module_init(void)

I don't get why you do not use the whole line length.

> +{
> +	return platform_driver_register(&w5300_driver);
> +}
> +
> +static void __exit
> +wiz_module_exit(void)
> +{
> +	platform_driver_unregister(&w5300_driver);
> +}
> +
> +module_init(wiz_module_init);
> +module_exit(wiz_module_exit);
> diff --git a/drivers/net/w5300.h b/drivers/net/w5300.h
> new file mode 100644
> index 0000000..d8583be
> --- /dev/null
> +++ b/drivers/net/w5300.h
[...]
> +#define Sn_IR_DISCON    0x02	/**< Disconnect bit of Sn_IR */
> +#define Sn_IR_CON       0x01	/**< Connect bit of Sn_IR */

So far, so good...

> +
> +/* Sn_SSR values */
> +#define SOCK_CLOSED      0x00	/**< SOCKETn is released */
> +#define SOCK_ARP         0x01	/**< ARP-request is transmitted in order to acquire destination hardware address. */
> +#define SOCK_INIT        0x13	/**< SOCKETn is open as TCP mode. */
[...]
> +/* IP PROTOCOL */
> +#define IPPROTO_IP	0	/* Dummy for IP */
> +#define IPPROTO_ICMP	1	/* Control message protocol */
> +#define IPPROTO_IGMP	2	/* Internet group management protocol */
> +#define IPPROTO_GGP	3	/* Gateway^2 (deprecated) */
> +#define IPPROTO_TCP	6	/* TCP */
> +#define IPPROTO_PUP	12	/* PUP */
> +#define IPPROTO_UDP	17	/* UDP */
> +#define IPPROTO_IDP	22	/* XNS idp */
> +#define IPPROTO_ND	77	/* UNOFFICIAL net disk protocol */
> +#define IPPROTO_RAW	255	/* Raw IP packet */

... but you can trim most of those.

No netif_carrier_{on/off} trough the whole driver ?

-- 
Ueimor

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox