Netdev List
 help / color / mirror / Atom feed
* Re: [PATCH] stmmac ethernet: remove cut & paste code
From: Pavel Machek @ 2016-11-28 14:35 UTC (permalink / raw)
  To: Joe Perches
  Cc: peppe.cavallaro, netdev, kernel list, ezequiel, sonic.zhang,
	fabrice.gasnier
In-Reply-To: <1480343068.14294.5.camel@perches.com>

[-- Attachment #1: Type: text/plain, Size: 2695 bytes --]

On Mon 2016-11-28 06:24:28, Joe Perches wrote:
> On Mon, 2016-11-28 at 12:50 +0100, Pavel Machek wrote:
> > On Thu 2016-11-24 14:27:13, Joe Perches wrote:
> > > On Thu, 2016-11-24 at 22:44 +0100, Pavel Machek wrote:
> > > > On Thu 2016-11-24 12:05:25, Joe Perches wrote:
> > > > > On Thu, 2016-11-24 at 12:05 +0100, Pavel Machek wrote:
> > > > > > Remove duplicate code from _tx routines.
> > > > > 
> > > > > trivia:
> > > > > 
> > > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > > > > 
> > > > > []
> > > > > > @@ -1960,6 +1960,38 @@ static void stmmac_tso_allocator(struct stmmac_priv *priv, unsigned int des,
> > > > > >  	}
> > > > > >  }
> > > > > >  
> > > > > > +static void stmmac_xmit_common(struct sk_buff *skb, struct net_device *dev, int nfrags, struct dma_desc *desc)
> > > > > > +{
> > > > > > +	struct stmmac_priv *priv = netdev_priv(dev);
> > > > > > +
> > > > > > +	if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) {
> > > > > > +		if (netif_msg_hw(priv))
> > > > > > +			pr_debug("%s: stop transmitted packets\n", __func__);
> > > > > 
> > > > > 		netif_dbg(priv, hw, dev, "%s: stop transmitted packets\n",
> > > > > 			  __func__);
> > > > 
> > > > Not now. Modifying the code while de-duplicating would be bad idea.
> > > 
> > > Too many people think overly granular patches are the
> > > best and only way to make changes.
> > > Deduplication and consolidation can happen simultaneously.
> > 
> > Can, but should not at this point. Please take a look at the driver in
> > question before commenting on trivial printk style.
> 
> I had.
> 
> It's perfectly acceptable and already uses netif_<level> properly.
> 
> This consolidation now introduces the _only_ instance where it is
> now improperly using a netif_msg_<type> then single pr_<level>
> function sequence that should be consolidated into netif_dbg.

> Every other use of netif_msg_<level> then either emits multiple
> lines or is used in an if/else.

Are you looking at right driver? I don't see single use of
netif_msg_<level>, but see this at stmmac_main.c:756. Code is actually
pretty consistent using pr_*.

                                if (netif_msg_link(priv))
                                        pr_warn("%s: Speed (%d) not 10/100\n",
                                                dev->name, phydev->speed);

Anyway, I'm moving code around, if you want to do trivial cleanups, do
them yourself.
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply

* Re: net/sctp: vmalloc allocation failure in sctp_setsockopt/xt_alloc_table_info
From: Andrey Konovalov @ 2016-11-28 14:33 UTC (permalink / raw)
  To: Neil Horman
  Cc: Vlad Yasevich, linux-sctp, netdev, LKML, Pablo Neira Ayuso,
	Patrick McHardy, Jozsef Kadlecsik, David S. Miller,
	netfilter-devel, coreteam, Dmitry Vyukov, Kostya Serebryany,
	Eric Dumazet, syzkaller
In-Reply-To: <20161128141340.GA29839@hmsreliant.think-freely.org>

On Mon, Nov 28, 2016 at 3:13 PM, Neil Horman <nhorman@tuxdriver.com> wrote:
> On Mon, Nov 28, 2016 at 02:00:19PM +0100, Andrey Konovalov wrote:
>> Hi!
>>
>> I've got the following error report while running the syzkaller fuzzer.
>>
>> On commit d8e435f3ab6fea2ea324dce72b51dd7761747523 (Nov 26).
>>
>> A reproducer is attached.
>>
>> a.out: vmalloc: allocation failure, allocated 823562240 of 1427091456
>> bytes, mode:0x24000c2(GFP_KERNEL|__GFP_HIGHMEM)
>>
> How much total ram do you have in this system?  The call appears to be
> attempting to allocate 1.3 Gb of data.  Even using vmalloc to allow
> discontiguous allocation, thats alot of memory, and if enough is in use already,
> I could make the argument that this might be expected behavior.

Hi Neail,

I have 2 Gb.

Just tested with 4 Gb, everything seems to be working fine.
So I guess this is not actually a bug and allocating 1.3 Gb is OK.

Thanks!

>
> Neil
>
>> oom_reaper: reaped process 3810 (a.out), now anon-rss:0kB,
>> file-rss:0kB, shmem-rss:0kB
>> a.out invoked oom-killer:
>> gfp_mask=0x24002c2(GFP_KERNEL|__GFP_HIGHMEM|__GFP_NOWARN), nodemask=0,
>> order=0, oom_score_adj=0
>> a.out cpuset=/ mems_allowed=0
>> CPU: 0 PID: 3814 Comm: a.out Not tainted 4.9.0-rc6+ #457
>> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
>>  ffff880068667380 ffffffff81c73b14 ffff880068667710 ffff88006b469018
>>  ffff880068667718 0000000000000000 ffff880068667400 ffffffff81641a87
>>  0000000000000000 0000000000000000 0000000000000297 ffffffff84d37280
>> Call Trace:
>>  [<     inline     >] __dump_stack lib/dump_stack.c:15
>>  [<ffffffff81c73b14>] dump_stack+0xb3/0x10f lib/dump_stack.c:51
>>  [<ffffffff81641a87>] dump_header.isra.21+0x16f/0x5f5 mm/oom_kill.c:416
>>  [<ffffffff8154bad8>] oom_kill_process+0x4d8/0xab0 mm/oom_kill.c:835
>>  [<ffffffff8154c77c>] out_of_memory+0x2dc/0x1790 mm/oom_kill.c:1044
>>  [<     inline     >] __alloc_pages_may_oom mm/page_alloc.c:3086
>>  [<ffffffff8155afb6>] __alloc_pages_slowpath+0x1886/0x1bf0 mm/page_alloc.c:3683
>>  [<ffffffff8155b8e2>] __alloc_pages_nodemask+0x5c2/0x710 mm/page_alloc.c:3781
>>  [<ffffffff816236a4>] alloc_pages_current+0xf4/0x400 mm/mempolicy.c:2072
>>  [<     inline     >] alloc_pages ./include/linux/gfp.h:469
>>  [<     inline     >] __vmalloc_area_node mm/vmalloc.c:1631
>>  [<ffffffff815f8eab>] __vmalloc_node_range+0x33b/0x690 mm/vmalloc.c:1691
>>  [<     inline     >] __vmalloc_node mm/vmalloc.c:1734
>>  [<     inline     >] __vmalloc_node_flags mm/vmalloc.c:1748
>>  [<ffffffff815f92cb>] vmalloc+0x5b/0x70 mm/vmalloc.c:1763
>>  [<ffffffff82fd0893>] xt_alloc_table_info+0x83/0x120
>> net/netfilter/x_tables.c:961
>>  [<     inline     >] do_replace net/ipv4/netfilter/ip_tables.c:1140
>>  [<ffffffff8335b420>] do_ipt_set_ctl+0x210/0x420
>> net/ipv4/netfilter/ip_tables.c:1687
>>  [<     inline     >] nf_sockopt net/netfilter/nf_sockopt.c:105
>>  [<ffffffff82efdab7>] nf_setsockopt+0x67/0xc0 net/netfilter/nf_sockopt.c:114
>>  [<ffffffff831be741>] ip_setsockopt+0xa1/0xb0 net/ipv4/ip_sockglue.c:1231
>>  [<ffffffff832700d5>] udp_setsockopt+0x45/0x80 net/ipv4/udp.c:2085
>>  [<ffffffff8346b31f>] ipv6_setsockopt+0x11f/0x140 net/ipv6/ipv6_sockglue.c:892
>>  [<ffffffff83a6cd5d>] sctp_setsockopt+0x15d/0x3d70 net/sctp/socket.c:3788
>>  [<ffffffff82ca40e6>] sock_common_setsockopt+0x96/0xd0 net/core/sock.c:2690
>>  [<     inline     >] SYSC_setsockopt net/socket.c:1757
>>  [<ffffffff82ca10c4>] SyS_setsockopt+0x154/0x240 net/socket.c:1736
>>  [<ffffffff840f2c41>] entry_SYSCALL_64_fastpath+0x1f/0xc2
>> arch/x86/entry/entry_64.S:209
>> CPU: 1 PID: 3810 Comm: a.out Not tainted 4.9.0-rc6+ #457
>> Mem-Info:
>> active_anon:1938 inactive_anon:75 isolated_anon:0
>>  active_file:14 inactive_file:30 isolated_file:4
>>  unevictable:0 dirty:0 writeback:0 unstable:0
>>  slab_reclaimable:3316 slab_unreclaimable:9767
>>  mapped:21 shmem:81 pagetables:309 bounce:0
>>  free:1 free_pcp:75 free_cma:0
>> Node 0 active_anon:7752kB inactive_anon:300kB active_file:56kB
>> inactive_file:120kB unevictable:0kB isolated(anon):0kB
>> isolated(file):16kB mapped:84kB dirty:0kB writeback:0kB shmem:324kB
>> writeback_tmp:0kB unstable:0kB pages_scanned:134 all_unreclaimable? no
>> Node 0 DMA free:4kB min:48kB low:60kB high:72kB active_anon:0kB
>> inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB
>> writepending:0kB present:15992kB managed:15908kB mlocked:0kB
>> slab_reclaimable:0kB slab_unreclaimable:8kB kernel_stack:0kB
>> pagetables:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
>> lowmem_reserve[]: 0 1641 1641 1641
>> Node 0 DMA32 free:0kB min:5156kB low:6836kB high:8516kB
>> active_anon:7752kB inactive_anon:300kB active_file:56kB
>> inactive_file:120kB unevictable:0kB writepending:0kB present:2080760kB
>> managed:1684640kB mlocked:0kB slab_reclaimable:13264kB
>> slab_unreclaimable:39060kB kernel_stack:2944kB pagetables:1236kB
>> bounce:0kB free_pcp:300kB local_pcp:120kB free_cma:0kB
>> lowmem_reserve[]: 0 0 0 0
>> Node 0 DMA: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB
>> 0*1024kB 0*2048kB 0*4096kB = 0kB
>> Node 0 DMA32: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB
>> 0*1024kB 0*2048kB 0*4096kB = 0kB
>> Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB
>> 148 total pagecache pages
>> 0 pages in swap cache
>> Swap cache stats: add 0, delete 0, find 0/0
>> Free swap  = 0kB
>> Total swap = 0kB
>> 524188 pages RAM
>> 0 pages HighMem/MovableOnly
>> 99051 pages reserved
>> [ pid ]   uid  tgid total_vm      rss nr_ptes nr_pmds swapents
>> oom_score_adj name
>>     0  1767     5346      133      16       3        0         -1000 udevd
>>     0  1876     5315      122      15       3        0         -1000 udevd
>>     0  1877     5315      122      15       3        0         -1000 udevd
>>     0  3541     2493      573       8       3        0             0 dhclient
>>     0  3676    13231      171      22       3        0             0 rsyslogd
>>     0  3725     4725       52      15       3        0             0 cron
>>     0  3751    12490      155      28       3        0         -1000 sshd
>>     0  3775     3694       43      13       3        0             0 getty
>>     0  3776     3694       43      13       3        0             0 getty
>>     0  3777     3694       42      13       3        0             0 getty
>>     0  3778     3694       41      13       3        0             0 getty
>>     0  3779     3694       44      13       3        0             0 getty
>>     0  3780     3694       43      13       3        0             0 getty
>>     0  3785     3649       44      12       3        0             0 getty
>>     0  3797    17818      205      39       3        0             0 sshd
>>     0  3800     4474      126      15       3        0             0 bash
>>     0  3804     2053       22       9       3        0             0 a.out
>>     0  3805     2053       26       9       3        0             0 a.out
>>     0  3806    18488        0      18       3        0             0 a.out
>
>> // autogenerated by syzkaller (http://github.com/google/syzkaller)
>>
>> #ifndef __NR_mmap
>> #define __NR_mmap 9
>> #endif
>> #ifndef __NR_setsockopt
>> #define __NR_setsockopt 54
>> #endif
>> #ifndef __NR_syz_fuse_mount
>> #define __NR_syz_fuse_mount 1000004
>> #endif
>> #ifndef __NR_socket
>> #define __NR_socket 41
>> #endif
>> #ifndef __NR_syz_emit_ethernet
>> #define __NR_syz_emit_ethernet 1000006
>> #endif
>> #ifndef __NR_syz_fuseblk_mount
>> #define __NR_syz_fuseblk_mount 1000005
>> #endif
>> #ifndef __NR_syz_open_dev
>> #define __NR_syz_open_dev 1000002
>> #endif
>> #ifndef __NR_syz_open_pts
>> #define __NR_syz_open_pts 1000003
>> #endif
>> #ifndef __NR_syz_test
>> #define __NR_syz_test 1000001
>> #endif
>>
>> #define SYZ_SANDBOX_NONE 1
>> #define SYZ_REPEAT 1
>>
>> #define _GNU_SOURCE
>>
>> #include <sys/ioctl.h>
>> #include <sys/mount.h>
>> #include <sys/prctl.h>
>> #include <sys/resource.h>
>> #include <sys/socket.h>
>> #include <sys/stat.h>
>> #include <sys/syscall.h>
>> #include <sys/time.h>
>> #include <sys/types.h>
>> #include <sys/wait.h>
>>
>> #include <linux/capability.h>
>> #include <linux/if.h>
>> #include <linux/if_tun.h>
>> #include <linux/sched.h>
>> #include <net/if_arp.h>
>>
>> #include <assert.h>
>> #include <dirent.h>
>> #include <errno.h>
>> #include <fcntl.h>
>> #include <grp.h>
>> #include <pthread.h>
>> #include <setjmp.h>
>> #include <signal.h>
>> #include <stdarg.h>
>> #include <stddef.h>
>> #include <stdint.h>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <string.h>
>> #include <unistd.h>
>>
>> const int kFailStatus = 67;
>> const int kErrorStatus = 68;
>> const int kRetryStatus = 69;
>>
>> __attribute__((noreturn)) void fail(const char* msg, ...)
>> {
>>   int e = errno;
>>   fflush(stdout);
>>   va_list args;
>>   va_start(args, msg);
>>   vfprintf(stderr, msg, args);
>>   va_end(args);
>>   fprintf(stderr, " (errno %d)\n", e);
>>   exit(kFailStatus);
>> }
>>
>> __attribute__((noreturn)) void exitf(const char* msg, ...)
>> {
>>   int e = errno;
>>   fflush(stdout);
>>   va_list args;
>>   va_start(args, msg);
>>   vfprintf(stderr, msg, args);
>>   va_end(args);
>>   fprintf(stderr, " (errno %d)\n", e);
>>   exit(kRetryStatus);
>> }
>>
>> static int flag_debug;
>>
>> void debug(const char* msg, ...)
>> {
>>   if (!flag_debug)
>>     return;
>>   va_list args;
>>   va_start(args, msg);
>>   vfprintf(stdout, msg, args);
>>   va_end(args);
>>   fflush(stdout);
>> }
>>
>> __thread int skip_segv;
>> __thread jmp_buf segv_env;
>>
>> static void segv_handler(int sig, siginfo_t* info, void* uctx)
>> {
>>   if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED))
>>     _longjmp(segv_env, 1);
>>   exit(sig);
>> }
>>
>> static void install_segv_handler()
>> {
>>   struct sigaction sa;
>>   memset(&sa, 0, sizeof(sa));
>>   sa.sa_sigaction = segv_handler;
>>   sa.sa_flags = SA_NODEFER | SA_SIGINFO;
>>   sigaction(SIGSEGV, &sa, NULL);
>>   sigaction(SIGBUS, &sa, NULL);
>> }
>>
>> #define NONFAILING(...)                                                \
>>   {                                                                    \
>>     __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST);               \
>>     if (_setjmp(segv_env) == 0) {                                      \
>>       __VA_ARGS__;                                                     \
>>     }                                                                  \
>>     __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST);               \
>>   }
>>
>> static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2)
>> {
>>   if (a0 == 0xc || a0 == 0xb) {
>>     char buf[128];
>>     sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block",
>>             (uint8_t)a1, (uint8_t)a2);
>>     return open(buf, O_RDWR, 0);
>>   } else {
>>     char buf[1024];
>>     char* hash;
>>     strncpy(buf, (char*)a0, sizeof(buf));
>>     buf[sizeof(buf) - 1] = 0;
>>     while ((hash = strchr(buf, '#'))) {
>>       *hash = '0' + (char)(a1 % 10);
>>       a1 /= 10;
>>     }
>>     return open(buf, a2, 0);
>>   }
>> }
>>
>> static uintptr_t syz_open_pts(uintptr_t a0, uintptr_t a1)
>> {
>>   int ptyno = 0;
>>   if (ioctl(a0, TIOCGPTN, &ptyno))
>>     return -1;
>>   char buf[128];
>>   sprintf(buf, "/dev/pts/%d", ptyno);
>>   return open(buf, a1, 0);
>> }
>>
>> static uintptr_t syz_fuse_mount(uintptr_t a0, uintptr_t a1,
>>                                 uintptr_t a2, uintptr_t a3,
>>                                 uintptr_t a4, uintptr_t a5)
>> {
>>   uint64_t target = a0;
>>   uint64_t mode = a1;
>>   uint64_t uid = a2;
>>   uint64_t gid = a3;
>>   uint64_t maxread = a4;
>>   uint64_t flags = a5;
>>
>>   int fd = open("/dev/fuse", O_RDWR);
>>   if (fd == -1)
>>     return fd;
>>   char buf[1024];
>>   sprintf(buf, "fd=%d,user_id=%ld,group_id=%ld,rootmode=0%o", fd,
>>           (long)uid, (long)gid, (unsigned)mode & ~3u);
>>   if (maxread != 0)
>>     sprintf(buf + strlen(buf), ",max_read=%ld", (long)maxread);
>>   if (mode & 1)
>>     strcat(buf, ",default_permissions");
>>   if (mode & 2)
>>     strcat(buf, ",allow_other");
>>   syscall(SYS_mount, "", target, "fuse", flags, buf);
>>   return fd;
>> }
>>
>> static uintptr_t syz_fuseblk_mount(uintptr_t a0, uintptr_t a1,
>>                                    uintptr_t a2, uintptr_t a3,
>>                                    uintptr_t a4, uintptr_t a5,
>>                                    uintptr_t a6, uintptr_t a7)
>> {
>>   uint64_t target = a0;
>>   uint64_t blkdev = a1;
>>   uint64_t mode = a2;
>>   uint64_t uid = a3;
>>   uint64_t gid = a4;
>>   uint64_t maxread = a5;
>>   uint64_t blksize = a6;
>>   uint64_t flags = a7;
>>
>>   int fd = open("/dev/fuse", O_RDWR);
>>   if (fd == -1)
>>     return fd;
>>   if (syscall(SYS_mknodat, AT_FDCWD, blkdev, S_IFBLK, makedev(7, 199)))
>>     return fd;
>>   char buf[256];
>>   sprintf(buf, "fd=%d,user_id=%ld,group_id=%ld,rootmode=0%o", fd,
>>           (long)uid, (long)gid, (unsigned)mode & ~3u);
>>   if (maxread != 0)
>>     sprintf(buf + strlen(buf), ",max_read=%ld", (long)maxread);
>>   if (blksize != 0)
>>     sprintf(buf + strlen(buf), ",blksize=%ld", (long)blksize);
>>   if (mode & 1)
>>     strcat(buf, ",default_permissions");
>>   if (mode & 2)
>>     strcat(buf, ",allow_other");
>>   syscall(SYS_mount, blkdev, target, "fuseblk", flags, buf);
>>   return fd;
>> }
>>
>> static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1,
>>                                  uintptr_t a2, uintptr_t a3,
>>                                  uintptr_t a4, uintptr_t a5,
>>                                  uintptr_t a6, uintptr_t a7,
>>                                  uintptr_t a8)
>> {
>>   switch (nr) {
>>   default:
>>     return syscall(nr, a0, a1, a2, a3, a4, a5);
>>   case __NR_syz_test:
>>     return 0;
>>   case __NR_syz_open_dev:
>>     return syz_open_dev(a0, a1, a2);
>>   case __NR_syz_open_pts:
>>     return syz_open_pts(a0, a1);
>>   case __NR_syz_fuse_mount:
>>     return syz_fuse_mount(a0, a1, a2, a3, a4, a5);
>>   case __NR_syz_fuseblk_mount:
>>     return syz_fuseblk_mount(a0, a1, a2, a3, a4, a5, a6, a7);
>>   }
>> }
>>
>> static void setup_main_process()
>> {
>>   struct sigaction sa;
>>   memset(&sa, 0, sizeof(sa));
>>   sa.sa_handler = SIG_IGN;
>>   syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
>>   syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
>>   install_segv_handler();
>>
>>   char tmpdir_template[] = "./syzkaller.XXXXXX";
>>   char* tmpdir = mkdtemp(tmpdir_template);
>>   if (!tmpdir)
>>     fail("failed to mkdtemp");
>>   if (chmod(tmpdir, 0777))
>>     fail("failed to chmod");
>>   if (chdir(tmpdir))
>>     fail("failed to chdir");
>> }
>>
>> static void loop();
>>
>> static void sandbox_common()
>> {
>>   prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
>>   setpgrp();
>>   setsid();
>>
>>   struct rlimit rlim;
>>   rlim.rlim_cur = rlim.rlim_max = 128 << 20;
>>   setrlimit(RLIMIT_AS, &rlim);
>>   rlim.rlim_cur = rlim.rlim_max = 1 << 20;
>>   setrlimit(RLIMIT_FSIZE, &rlim);
>>   rlim.rlim_cur = rlim.rlim_max = 1 << 20;
>>   setrlimit(RLIMIT_STACK, &rlim);
>>   rlim.rlim_cur = rlim.rlim_max = 0;
>>   setrlimit(RLIMIT_CORE, &rlim);
>>
>>   unshare(CLONE_NEWNS);
>>   unshare(CLONE_NEWIPC);
>>   unshare(CLONE_IO);
>> }
>>
>> static int do_sandbox_none()
>> {
>>   int pid = fork();
>>   if (pid)
>>     return pid;
>>   sandbox_common();
>>   loop();
>>   exit(1);
>> }
>>
>> static void remove_dir(const char* dir)
>> {
>>   DIR* dp;
>>   struct dirent* ep;
>>   int iter = 0;
>>   int i;
>> retry:
>>   dp = opendir(dir);
>>   if (dp == NULL) {
>>     if (errno == EMFILE) {
>>       exitf("opendir(%s) failed due to NOFILE, exiting");
>>     }
>>     exitf("opendir(%s) failed", dir);
>>   }
>>   while ((ep = readdir(dp))) {
>>     if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
>>       continue;
>>     char filename[FILENAME_MAX];
>>     snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
>>     struct stat st;
>>     if (lstat(filename, &st))
>>       exitf("lstat(%s) failed", filename);
>>     if (S_ISDIR(st.st_mode)) {
>>       remove_dir(filename);
>>       continue;
>>     }
>>     for (i = 0;; i++) {
>>       debug("unlink(%s)\n", filename);
>>       if (unlink(filename) == 0)
>>         break;
>>       if (errno == EROFS) {
>>         debug("ignoring EROFS\n");
>>         break;
>>       }
>>       if (errno != EBUSY || i > 100)
>>         exitf("unlink(%s) failed", filename);
>>       debug("umount(%s)\n", filename);
>>       if (umount2(filename, MNT_DETACH))
>>         exitf("umount(%s) failed", filename);
>>     }
>>   }
>>   closedir(dp);
>>   for (i = 0;; i++) {
>>     debug("rmdir(%s)\n", dir);
>>     if (rmdir(dir) == 0)
>>       break;
>>     if (i < 100) {
>>       if (errno == EROFS) {
>>         debug("ignoring EROFS\n");
>>         break;
>>       }
>>       if (errno == EBUSY) {
>>         debug("umount(%s)\n", dir);
>>         if (umount2(dir, MNT_DETACH))
>>           exitf("umount(%s) failed", dir);
>>         continue;
>>       }
>>       if (errno == ENOTEMPTY) {
>>         if (iter < 100) {
>>           iter++;
>>           goto retry;
>>         }
>>       }
>>     }
>>     exitf("rmdir(%s) failed", dir);
>>   }
>> }
>>
>> static uint64_t current_time_ms()
>> {
>>   struct timespec ts;
>>
>>   if (clock_gettime(CLOCK_MONOTONIC, &ts))
>>     fail("clock_gettime failed");
>>   return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
>> }
>>
>> static void test();
>>
>> void loop()
>> {
>>   int iter;
>>   for (iter = 0;; iter++) {
>>     char cwdbuf[256];
>>     sprintf(cwdbuf, "./%d", iter);
>>     if (mkdir(cwdbuf, 0777))
>>       fail("failed to mkdir");
>>     int pid = fork();
>>     if (pid < 0)
>>       fail("clone failed");
>>     if (pid == 0) {
>>       prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
>>       setpgrp();
>>       if (chdir(cwdbuf))
>>         fail("failed to chdir");
>>       test();
>>       exit(0);
>>     }
>>     int status = 0;
>>     uint64_t start = current_time_ms();
>>     for (;;) {
>>       int res = waitpid(pid, &status, __WALL | WNOHANG);
>>       int errno0 = errno;
>>       if (res == pid)
>>         break;
>>       usleep(1000);
>>       if (current_time_ms() - start > 5 * 1000) {
>>         kill(-pid, SIGKILL);
>>         kill(pid, SIGKILL);
>>         waitpid(pid, &status, __WALL);
>>         break;
>>       }
>>     }
>>     remove_dir(cwdbuf);
>>   }
>> }
>>
>> long r[5];
>> void* thr(void* arg)
>> {
>>   switch ((long)arg) {
>>   case 0:
>>     r[0] =
>>         execute_syscall(__NR_mmap, 0x20000000ul, 0xa000ul, 0x3ul,
>>                         0x32ul, 0xfffffffffffffffful, 0x0ul, 0, 0, 0);
>>     break;
>>   case 1:
>>     r[1] = execute_syscall(__NR_socket, 0xaul, 0x5ul, 0x84ul, 0, 0, 0,
>>                            0, 0, 0);
>>     break;
>>   case 2:
>>     r[2] = execute_syscall(__NR_socket, 0x1ful, 0x3ul, 0x6ul, 0, 0, 0,
>>                            0, 0, 0);
>>     break;
>>   case 3:
>>     NONFAILING(memcpy(
>>         (void*)0x20009000,
>>         "\x83\x15\xf6\xdb\x47\x14\xae\xe2\x8d\xb8\x4d\xb9\x0f\x32\xe7"
>>         "\xf5\xbc\xa6\xae\x9a\x2f\x19\xed\xf0\x75\x6a\x0b\xf0\x00\xe9"
>>         "\xe1\x0e\xb4\xa5\x19\x08\x88\xfc\x8b\x2d\xe2\x9a\x0f\x55\x00"
>>         "\x00\x00\x00\x00\x08\x27\xab\x8e\x7d\xcb\xcc\x15\x4e\x79\xe2"
>>         "\xd9\xca\x15\xc3\x66\xbd\x44\xa8\x53\x1f\xda\xab\xce\x98\x39"
>>         "\x40\x4e\x75\x57\xfd\x57\xc0\x01\x0b\xb0",
>>         85));
>>     r[4] = execute_syscall(__NR_setsockopt, r[1], 0x0ul, 0x40ul,
>>                            0x20009000ul, 0x55ul, 0, 0, 0, 0);
>>     break;
>>   }
>>   return 0;
>> }
>>
>> void test()
>> {
>>   long i;
>>   pthread_t th[8];
>>
>>   memset(r, -1, sizeof(r));
>>   srand(getpid());
>>   for (i = 0; i < 4; i++) {
>>     pthread_create(&th[i], 0, thr, (void*)i);
>>     usleep(10000);
>>   }
>>   for (i = 0; i < 4; i++) {
>>     pthread_create(&th[4 + i], 0, thr, (void*)i);
>>     if (rand() % 2)
>>       usleep(rand() % 10000);
>>   }
>>   usleep(100000);
>> }
>>
>> int main()
>> {
>>   setup_main_process();
>>   int pid = do_sandbox_none();
>>   int status = 0;
>>   while (waitpid(pid, &status, __WALL) != pid) {
>>   }
>>   return 0;
>> }
>

^ permalink raw reply

* [patch net] net: fec: cache statistics while device is down
From: Nikita Yushchenko @ 2016-11-28 14:27 UTC (permalink / raw)
  To: David S. Miller, Fugang Duan, Troy Kisky, Andrew Lunn,
	Eric Nelson, Philippe Reynes, Johannes Berg, netdev
  Cc: Chris Healy, Fabio Estevam, linux-kernel, Nikita Yushchenko

Execution 'ethtool -S' on fec device that is down causes OOPS on Vybrid
board:

Unhandled fault: external abort on non-linefetch (0x1008) at 0xe0898200
pgd = ddecc000
[e0898200] *pgd=9e406811, *pte=400d1653, *ppte=400d1453
Internal error: : 1008 [#1] SMP ARM
...

Reason of OOPS is that fec_enet_get_ethtool_stats() accesses fec
registers while IPG clock is stopped by PM.

Fix that by caching statistics in fec_enet_private. Cache is updated
just before statistics request if device is up, and also just before
turning device off on down path.

Additional locking is not needed, since cached statistics is always
updated under rtnl_lock().

Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
---
 drivers/net/ethernet/freescale/fec.h      |  2 ++
 drivers/net/ethernet/freescale/fec_main.c | 21 +++++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index c865135f3cb9..5ea740b4cf14 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -574,6 +574,8 @@ struct fec_enet_private {
 	unsigned int reload_period;
 	int pps_enable;
 	unsigned int next_counter;
+
+	u64 ethtool_stats[0];
 };
 
 void fec_ptp_init(struct platform_device *pdev);
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 5aa9d4ded214..7da2d94ec8e5 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -2313,14 +2313,24 @@ static const struct fec_stat {
 	{ "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK },
 };
 
-static void fec_enet_get_ethtool_stats(struct net_device *dev,
-	struct ethtool_stats *stats, u64 *data)
+static void fec_enet_update_ethtool_stats(struct net_device *dev)
 {
 	struct fec_enet_private *fep = netdev_priv(dev);
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
-		data[i] = readl(fep->hwp + fec_stats[i].offset);
+		fep->ethtool_stats[i] = readl(fep->hwp + fec_stats[i].offset);
+}
+
+static void fec_enet_get_ethtool_stats(struct net_device *dev,
+				       struct ethtool_stats *stats, u64 *data)
+{
+	struct fec_enet_private *fep = netdev_priv(dev);
+
+	if (netif_running(dev))
+		fec_enet_update_ethtool_stats(dev);
+
+	memcpy(data, fep->ethtool_stats, ARRAY_SIZE(fec_stats) * sizeof(u64));
 }
 
 static void fec_enet_get_strings(struct net_device *netdev,
@@ -2874,6 +2884,8 @@ fec_enet_close(struct net_device *ndev)
 	if (fep->quirks & FEC_QUIRK_ERR006687)
 		imx6q_cpuidle_fec_irqs_unused();
 
+	fec_enet_update_ethtool_stats(ndev);
+
 	fec_enet_clk_enable(ndev, false);
 	pinctrl_pm_select_sleep_state(&fep->pdev->dev);
 	pm_runtime_mark_last_busy(&fep->pdev->dev);
@@ -3278,7 +3290,8 @@ fec_probe(struct platform_device *pdev)
 	fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs);
 
 	/* Init network device */
-	ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private),
+	ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private) +
+				  ARRAY_SIZE(fec_stats) * sizeof(u64),
 				  num_tx_qs, num_rx_qs);
 	if (!ndev)
 		return -ENOMEM;
-- 
2.1.4

^ permalink raw reply related

* [PATCH net] net/dccp: fix use-after-free in dccp_invalid_packet
From: Eric Dumazet @ 2016-11-28 14:26 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Gerrit Renker, David S. Miller, dccp, netdev, LKML, Dmitry Vyukov,
	Kostya Serebryany, Eric Dumazet, syzkaller
In-Reply-To: <CAAeHK+zYNyuFUU+w0rLWvvZqivSedrqMpS5UYt=c4uqajS_Stw@mail.gmail.com>

From: Eric Dumazet <edumazet@google.com>

pskb_may_pull() can reallocate skb->head, we need to reload dh pointer
in dccp_invalid_packet() or risk use after free.

Bug found by Andrey Konovalov using syzkaller.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Andrey Konovalov <andreyknvl@google.com>
---
 net/dccp/ipv4.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index b567c8725aea..edbe59d203ef 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -700,6 +700,7 @@ int dccp_invalid_packet(struct sk_buff *skb)
 {
 	const struct dccp_hdr *dh;
 	unsigned int cscov;
+	u8 dccph_doff;
 
 	if (skb->pkt_type != PACKET_HOST)
 		return 1;
@@ -721,18 +722,19 @@ int dccp_invalid_packet(struct sk_buff *skb)
 	/*
 	 * If P.Data Offset is too small for packet type, drop packet and return
 	 */
-	if (dh->dccph_doff < dccp_hdr_len(skb) / sizeof(u32)) {
-		DCCP_WARN("P.Data Offset(%u) too small\n", dh->dccph_doff);
+	dccph_doff = dh->dccph_doff;
+	if (dccph_doff < dccp_hdr_len(skb) / sizeof(u32)) {
+		DCCP_WARN("P.Data Offset(%u) too small\n", dccph_doff);
 		return 1;
 	}
 	/*
 	 * If P.Data Offset is too too large for packet, drop packet and return
 	 */
-	if (!pskb_may_pull(skb, dh->dccph_doff * sizeof(u32))) {
-		DCCP_WARN("P.Data Offset(%u) too large\n", dh->dccph_doff);
+	if (!pskb_may_pull(skb, dccph_doff * sizeof(u32))) {
+		DCCP_WARN("P.Data Offset(%u) too large\n", dccph_doff);
 		return 1;
 	}
-
+	dh = dccp_hdr(skb);
 	/*
 	 * If P.type is not Data, Ack, or DataAck and P.X == 0 (the packet
 	 * has short sequence numbers), drop packet and return

^ permalink raw reply related

* [PATCH net-next v2] mlxsw: switchib: add MLXSW_PCI dependency
From: Arnd Bergmann @ 2016-11-28 14:26 UTC (permalink / raw)
  To: David Miller
  Cc: Arnd Bergmann, Jiri Pirko, Ido Schimmel, Vadim Pasternak,
	Ivan Vecera, Elad Raz, netdev, linux-kernel

The newly added switchib driver fails to link if MLXSW_PCI=m:

drivers/net/ethernet/mellanox/mlxsw/mlxsw_switchib.o: In function^Cmlxsw_sib_module_exit':
switchib.c:(.exit.text+0x8): undefined reference to `mlxsw_pci_driver_unregister'
switchib.c:(.exit.text+0x10): undefined reference to `mlxsw_pci_driver_unregister'
drivers/net/ethernet/mellanox/mlxsw/mlxsw_switchib.o: In function `mlxsw_sib_module_init':
switchib.c:(.init.text+0x28): undefined reference to `mlxsw_pci_driver_register'
switchib.c:(.init.text+0x38): undefined reference to `mlxsw_pci_driver_register'
switchib.c:(.init.text+0x48): undefined reference to `mlxsw_pci_driver_unregister'

The other two such sub-drivers have a dependency, so add the same one
here. In theory we could allow this driver if MLXSW_PCI is disabled,
but it's probably not worth it.

Fixes: d1ba52638456 ("mlxsw: switchib: Introduce SwitchIB and SwitchIB silicon driver")
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: add Fixes tag

 drivers/net/ethernet/mellanox/mlxsw/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/Kconfig b/drivers/net/ethernet/mellanox/mlxsw/Kconfig
index 95ae4c0d3a18..16f44b9aa076 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/Kconfig
+++ b/drivers/net/ethernet/mellanox/mlxsw/Kconfig
@@ -50,7 +50,7 @@ config MLXSW_I2C
 
 config MLXSW_SWITCHIB
 	tristate "Mellanox Technologies SwitchIB and SwitchIB-2 support"
-	depends on MLXSW_CORE && NET_SWITCHDEV
+	depends on MLXSW_CORE && MLXSW_PCI && NET_SWITCHDEV
 	default m
 	---help---
 	  This driver supports Mellanox Technologies SwitchIB and SwitchIB-2
-- 
2.9.0

^ permalink raw reply related

* Re: [PATCH] stmmac ethernet: remove cut & paste code
From: Joe Perches @ 2016-11-28 14:24 UTC (permalink / raw)
  To: Pavel Machek
  Cc: peppe.cavallaro, netdev, kernel list, ezequiel, sonic.zhang,
	fabrice.gasnier
In-Reply-To: <20161128115023.GA15034@amd>

On Mon, 2016-11-28 at 12:50 +0100, Pavel Machek wrote:
> On Thu 2016-11-24 14:27:13, Joe Perches wrote:
> > On Thu, 2016-11-24 at 22:44 +0100, Pavel Machek wrote:
> > > On Thu 2016-11-24 12:05:25, Joe Perches wrote:
> > > > On Thu, 2016-11-24 at 12:05 +0100, Pavel Machek wrote:
> > > > > Remove duplicate code from _tx routines.
> > > > 
> > > > trivia:
> > > > 
> > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > > > 
> > > > []
> > > > > @@ -1960,6 +1960,38 @@ static void stmmac_tso_allocator(struct stmmac_priv *priv, unsigned int des,
> > > > >  	}
> > > > >  }
> > > > >  
> > > > > +static void stmmac_xmit_common(struct sk_buff *skb, struct net_device *dev, int nfrags, struct dma_desc *desc)
> > > > > +{
> > > > > +	struct stmmac_priv *priv = netdev_priv(dev);
> > > > > +
> > > > > +	if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) {
> > > > > +		if (netif_msg_hw(priv))
> > > > > +			pr_debug("%s: stop transmitted packets\n", __func__);
> > > > 
> > > > 		netif_dbg(priv, hw, dev, "%s: stop transmitted packets\n",
> > > > 			  __func__);
> > > 
> > > Not now. Modifying the code while de-duplicating would be bad idea.
> > 
> > Too many people think overly granular patches are the
> > best and only way to make changes.
> > Deduplication and consolidation can happen simultaneously.
> 
> Can, but should not at this point. Please take a look at the driver in
> question before commenting on trivial printk style.

I had.

It's perfectly acceptable and already uses netif_<level> properly.

This consolidation now introduces the _only_ instance where it is
now improperly using a netif_msg_<type> then single pr_<level>
function sequence that should be consolidated into netif_dbg.

Every other use of netif_msg_<level> then either emits multiple
lines or is used in an if/else.

cheers, Joe

^ permalink raw reply

* [PATCH] irda: w83977af_ir: fix damaged whitespace
From: Arnd Bergmann @ 2016-11-28 14:19 UTC (permalink / raw)
  To: David Miller; +Cc: Arnd Bergmann, Samuel Ortiz, netdev, linux-kernel

As David Miller pointed out for for the previous patch, the whitespace
in some functions looks rather odd. This was caused by commit 6329da5f258a
("obsolete config in kernel source: USE_INTERNAL_TIMER"), which removed
some conditions but did not reindent the code.

This fixes the indentation in the file and removes extraneous whitespace
at the end of the lines and before tabs.

There are many other minor coding style problems in the driver, but I'm
not touching those here.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/irda/w83977af_ir.c | 404 ++++++++++++++++++++---------------------
 1 file changed, 202 insertions(+), 202 deletions(-)

diff --git a/drivers/net/irda/w83977af_ir.c b/drivers/net/irda/w83977af_ir.c
index e8c3a8c32534..96745888a4fc 100644
--- a/drivers/net/irda/w83977af_ir.c
+++ b/drivers/net/irda/w83977af_ir.c
@@ -1,5 +1,5 @@
 /*********************************************************************
- *                
+ *
  * Filename:      w83977af_ir.c
  * Version:       1.0
  * Description:   FIR driver for the Winbond W83977AF Super I/O chip
@@ -8,31 +8,31 @@
  * Created at:    Wed Nov  4 11:46:16 1998
  * Modified at:   Fri Jan 28 12:10:59 2000
  * Modified by:   Dag Brattli <dagb@cs.uit.no>
- * 
+ *
  *     Copyright (c) 1998-2000 Dag Brattli <dagb@cs.uit.no>
  *     Copyright (c) 1998-1999 Rebel.com
- *      
- *     This program is free software; you can redistribute it and/or 
- *     modify it under the terms of the GNU General Public License as 
- *     published by the Free Software Foundation; either version 2 of 
+ *
+ *     This program is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License as
+ *     published by the Free Software Foundation; either version 2 of
  *     the License, or (at your option) any later version.
- *  
+ *
  *     Neither Paul VanderSpek nor Rebel.com admit liability nor provide
  *     warranty for any of this software. This material is provided "AS-IS"
  *     and at no charge.
- *     
+ *
  *     If you find bugs in this file, its very likely that the same bug
  *     will also be in pc87108.c since the implementations are quite
  *     similar.
  *
  *     Notice that all functions that needs to access the chip in _any_
- *     way, must save BSR register on entry, and restore it on exit. 
+ *     way, must save BSR register on entry, and restore it on exit.
  *     It is _very_ important to follow this policy!
  *
  *         __u8 bank;
- *     
+ *
  *         bank = inb( iobase+BSR);
- *  
+ *
  *         do_your_stuff_here();
  *
  *         outb( bank, iobase+BSR);
@@ -63,7 +63,7 @@
 #include "w83977af_ir.h"
 
 #define CONFIG_USE_W977_PNP        /* Currently needed */
-#define PIO_MAX_SPEED       115200 
+#define PIO_MAX_SPEED       115200
 
 static char *driver_name = "w83977af_ir";
 static int  qos_mtt_bits = 0x07;   /* 1 ms or more */
@@ -83,11 +83,11 @@ static unsigned int efio = W977_EFIO_BASE;
 static struct w83977af_ir *dev_self[] = { NULL, NULL, NULL, NULL};
 
 /* Some prototypes */
-static int  w83977af_open(int i, unsigned int iobase, unsigned int irq, 
+static int  w83977af_open(int i, unsigned int iobase, unsigned int irq,
                           unsigned int dma);
 static int  w83977af_close(struct w83977af_ir *self);
 static int  w83977af_probe(int iobase, int irq, int dma);
-static int  w83977af_dma_receive(struct w83977af_ir *self); 
+static int  w83977af_dma_receive(struct w83977af_ir *self);
 static int  w83977af_dma_receive_complete(struct w83977af_ir *self);
 static netdev_tx_t  w83977af_hard_xmit(struct sk_buff *skb,
 					     struct net_device *dev);
@@ -108,7 +108,7 @@ static int  w83977af_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd
  */
 static int __init w83977af_init(void)
 {
-        int i;
+	int i;
 
 	for (i=0; i < ARRAY_SIZE(dev_self) && io[i] < 2000; i++) {
 		if (w83977af_open(i, io[i], irq[i], dma[i]) == 0)
@@ -150,7 +150,7 @@ static int w83977af_open(int i, unsigned int iobase, unsigned int irq,
 			 unsigned int dma)
 {
 	struct net_device *dev;
-        struct w83977af_ir *self;
+	struct w83977af_ir *self;
 	int err;
 
 	/* Lock the port that we need */
@@ -177,18 +177,18 @@ static int w83977af_open(int i, unsigned int iobase, unsigned int irq,
 
 	self = netdev_priv(dev);
 	spin_lock_init(&self->lock);
-   
+
 
 	/* Initialize IO */
-	self->io.fir_base   = iobase;
-        self->io.irq       = irq;
-        self->io.fir_ext   = CHIP_IO_EXTENT;
-        self->io.dma       = dma;
-        self->io.fifo_size = 32;
+	self->io.fir_base = iobase;
+	self->io.irq = irq;
+	self->io.fir_ext = CHIP_IO_EXTENT;
+	self->io.dma = dma;
+	self->io.fifo_size = 32;
 
 	/* Initialize QoS for this device */
 	irda_init_max_qos_capabilies(&self->qos);
-	
+
 	/* The only value we must override it the baudrate */
 
 	/* FIXME: The HP HDLS-1100 does not support 1152000! */
@@ -198,11 +198,11 @@ static int w83977af_open(int i, unsigned int iobase, unsigned int irq,
 	/* The HP HDLS-1100 needs 1 ms according to the specs */
 	self->qos.min_turn_time.bits = qos_mtt_bits;
 	irda_qos_bits_to_value(&self->qos);
-	
+
 	/* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
-	self->rx_buff.truesize = 14384; 
+	self->rx_buff.truesize = 14384;
 	self->tx_buff.truesize = 4000;
-	
+
 	/* Allocate memory if needed */
 	self->rx_buff.head =
 		dma_zalloc_coherent(NULL, self->rx_buff.truesize,
@@ -238,12 +238,12 @@ static int w83977af_open(int i, unsigned int iobase, unsigned int irq,
 
 	/* Need to store self somewhere */
 	dev_self[i] = self;
-	
+
 	return 0;
 err_out3:
 	dma_free_coherent(NULL, self->tx_buff.truesize,
 			  self->tx_buff.head, self->tx_buff_dma);
-err_out2:	
+err_out2:
 	dma_free_coherent(NULL, self->rx_buff.truesize,
 			  self->rx_buff.head, self->rx_buff_dma);
 err_out1:
@@ -288,7 +288,7 @@ static int w83977af_close(struct w83977af_ir *self)
 	if (self->tx_buff.head)
 		dma_free_coherent(NULL, self->tx_buff.truesize,
 				  self->tx_buff.head, self->tx_buff_dma);
-	
+
 	if (self->rx_buff.head)
 		dma_free_coherent(NULL, self->rx_buff.truesize,
 				  self->rx_buff.head, self->rx_buff_dma);
@@ -300,106 +300,106 @@ static int w83977af_close(struct w83977af_ir *self)
 
 static int w83977af_probe(int iobase, int irq, int dma)
 {
-  	int version;
+	int version;
 	int i;
-  	
- 	for (i=0; i < 2; i++) {
+
+	for (i=0; i < 2; i++) {
 #ifdef CONFIG_USE_W977_PNP
- 		/* Enter PnP configuration mode */
+		/* Enter PnP configuration mode */
 		w977_efm_enter(efbase[i]);
-  
- 		w977_select_device(W977_DEVICE_IR, efbase[i]);
-  
- 		/* Configure PnP port, IRQ, and DMA channel */
- 		w977_write_reg(0x60, (iobase >> 8) & 0xff, efbase[i]);
- 		w977_write_reg(0x61, (iobase) & 0xff, efbase[i]);
-  
- 		w977_write_reg(0x70, irq, efbase[i]);
+
+		w977_select_device(W977_DEVICE_IR, efbase[i]);
+
+		/* Configure PnP port, IRQ, and DMA channel */
+		w977_write_reg(0x60, (iobase >> 8) & 0xff, efbase[i]);
+		w977_write_reg(0x61, (iobase) & 0xff, efbase[i]);
+
+		w977_write_reg(0x70, irq, efbase[i]);
 #ifdef CONFIG_ARCH_NETWINDER
 		/* Netwinder uses 1 higher than Linux */
- 		w977_write_reg(0x74, dma+1, efbase[i]);
+		w977_write_reg(0x74, dma+1, efbase[i]);
 #else
- 		w977_write_reg(0x74, dma, efbase[i]);   
+		w977_write_reg(0x74, dma, efbase[i]);
 #endif /* CONFIG_ARCH_NETWINDER */
- 		w977_write_reg(0x75, 0x04, efbase[i]);  /* Disable Tx DMA */
-  	
- 		/* Set append hardware CRC, enable IR bank selection */	
- 		w977_write_reg(0xf0, APEDCRC|ENBNKSEL, efbase[i]);
-  
- 		/* Activate device */
- 		w977_write_reg(0x30, 0x01, efbase[i]);
-  
- 		w977_efm_exit(efbase[i]);
+		w977_write_reg(0x75, 0x04, efbase[i]);/* Disable Tx DMA */
+
+		/* Set append hardware CRC, enable IR bank selection */
+		w977_write_reg(0xf0, APEDCRC | ENBNKSEL, efbase[i]);
+
+		/* Activate device */
+		w977_write_reg(0x30, 0x01, efbase[i]);
+
+		w977_efm_exit(efbase[i]);
 #endif /* CONFIG_USE_W977_PNP */
-  		/* Disable Advanced mode */
-  		switch_bank(iobase, SET2);
-  		outb(iobase+2, 0x00);  
- 
- 		/* Turn on UART (global) interrupts */
- 		switch_bank(iobase, SET0);
-  		outb(HCR_EN_IRQ, iobase+HCR);
-  	
-  		/* Switch to advanced mode */
-  		switch_bank(iobase, SET2);
-  		outb(inb(iobase+ADCR1) | ADCR1_ADV_SL, iobase+ADCR1);
-  
-  		/* Set default IR-mode */
-  		switch_bank(iobase, SET0);
-  		outb(HCR_SIR, iobase+HCR);
-  
-  		/* Read the Advanced IR ID */
-  		switch_bank(iobase, SET3);
-  		version = inb(iobase+AUID);
-  	
-  		/* Should be 0x1? */
-  		if (0x10 == (version & 0xf0)) {
- 			efio = efbase[i];
- 
- 			/* Set FIFO size to 32 */
- 			switch_bank(iobase, SET2);
- 			outb(ADCR2_RXFS32|ADCR2_TXFS32, iobase+ADCR2);	
- 	
- 			/* Set FIFO threshold to TX17, RX16 */
- 			switch_bank(iobase, SET0);	
- 			outb(UFR_RXTL|UFR_TXTL|UFR_TXF_RST|UFR_RXF_RST|
+		/* Disable Advanced mode */
+		switch_bank(iobase, SET2);
+		outb(iobase+2, 0x00);
+
+		/* Turn on UART (global) interrupts */
+		switch_bank(iobase, SET0);
+		outb(HCR_EN_IRQ, iobase+HCR);
+
+		/* Switch to advanced mode */
+		switch_bank(iobase, SET2);
+		outb(inb(iobase+ADCR1) | ADCR1_ADV_SL, iobase+ADCR1);
+
+		/* Set default IR-mode */
+		switch_bank(iobase, SET0);
+		outb(HCR_SIR, iobase+HCR);
+
+		/* Read the Advanced IR ID */
+		switch_bank(iobase, SET3);
+		version = inb(iobase+AUID);
+
+		/* Should be 0x1? */
+		if (0x10 == (version & 0xf0)) {
+			efio = efbase[i];
+
+			/* Set FIFO size to 32 */
+			switch_bank(iobase, SET2);
+			outb(ADCR2_RXFS32|ADCR2_TXFS32, iobase+ADCR2);
+
+			/* Set FIFO threshold to TX17, RX16 */
+			switch_bank(iobase, SET0);
+			outb(UFR_RXTL|UFR_TXTL|UFR_TXF_RST|UFR_RXF_RST|
 			     UFR_EN_FIFO,iobase+UFR);
- 
- 			/* Receiver frame length */
- 			switch_bank(iobase, SET4);
+
+			/* Receiver frame length */
+			switch_bank(iobase, SET4);
 			outb(2048 & 0xff, iobase+6);
 			outb((2048 >> 8) & 0x1f, iobase+7);
 
-			/* 
-			 * Init HP HSDL-1100 transceiver. 
-			 * 
-			 * Set IRX_MSL since we have 2 * receive paths IRRX, 
-			 * and IRRXH. Clear IRSL0D since we want IRSL0 * to 
-			 * be a input pin used for IRRXH 
+			/*
+			 * Init HP HSDL-1100 transceiver.
 			 *
-			 *   IRRX  pin 37 connected to receiver 
+			 * Set IRX_MSL since we have 2 * receive paths IRRX,
+			 * and IRRXH. Clear IRSL0D since we want IRSL0 * to
+			 * be a input pin used for IRRXH
+			 *
+			 *   IRRX  pin 37 connected to receiver
 			 *   IRTX  pin 38 connected to transmitter
-			 *   FIRRX pin 39 connected to receiver      (IRSL0) 
+			 *   FIRRX pin 39 connected to receiver      (IRSL0)
 			 *   CIRRX pin 40 connected to pin 37
 			 */
 			switch_bank(iobase, SET7);
 			outb(0x40, iobase+7);
-			
+
 			net_info_ratelimited("W83977AF (IR) driver loaded. Version: 0x%02x\n",
 					     version);
-			
+
 			return 0;
 		} else {
 			/* Try next extented function register address */
 			pr_debug("%s(), Wrong chip version", __func__);
 		}
-  	}   	
+	}
 	return -1;
 }
 
 static void w83977af_change_speed(struct w83977af_ir *self, __u32 speed)
 {
 	int ir_mode = HCR_SIR;
-	int iobase; 
+	int iobase;
 	__u8 set;
 
 	iobase = self->io.fir_base;
@@ -448,8 +448,8 @@ static void w83977af_change_speed(struct w83977af_ir *self, __u32 speed)
 
 	/* set FIFO size to 32 */
 	switch_bank(iobase, SET2);
-	outb(ADCR2_RXFS32|ADCR2_TXFS32, iobase+ADCR2);	
-	
+	outb(ADCR2_RXFS32|ADCR2_TXFS32, iobase+ADCR2);
+
 	/* set FIFO threshold to TX17, RX16 */
 	switch_bank(iobase, SET0);
 	outb(0x00, iobase+UFR);        /* Reset */
@@ -457,7 +457,7 @@ static void w83977af_change_speed(struct w83977af_ir *self, __u32 speed)
 	outb(0xa7, iobase+UFR);
 
 	netif_wake_queue(self->netdev);
-		
+
 	/* Enable some interrupts so we can receive frames */
 	switch_bank(iobase, SET0);
 	if (speed > PIO_MAX_SPEED) {
@@ -465,7 +465,7 @@ static void w83977af_change_speed(struct w83977af_ir *self, __u32 speed)
 		w83977af_dma_receive(self);
 	} else
 		outb(ICR_ERBRI, iobase+ICR);
-    	
+
 	/* Restore SSR */
 	outb(set, iobase+SSR);
 }
@@ -484,23 +484,23 @@ static netdev_tx_t w83977af_hard_xmit(struct sk_buff *skb,
 	int iobase;
 	__u8 set;
 	int mtt;
-	
+
 	self = netdev_priv(dev);
 
 	iobase = self->io.fir_base;
 
 	pr_debug("%s(%ld), skb->len=%d\n", __func__ , jiffies,
 		 (int)skb->len);
-	
+
 	/* Lock transmit buffer */
 	netif_stop_queue(dev);
-	
+
 	/* Check if we need to change the speed */
 	speed = irda_get_next_speed(skb);
 	if ((speed != self->io.speed) && (speed != -1)) {
 		/* Check for empty frame */
 		if (!skb->len) {
-			w83977af_change_speed(self, speed); 
+			w83977af_change_speed(self, speed);
 			dev_kfree_skb(skb);
 			return NETDEV_TX_OK;
 		} else
@@ -509,29 +509,29 @@ static netdev_tx_t w83977af_hard_xmit(struct sk_buff *skb,
 
 	/* Save current set */
 	set = inb(iobase+SSR);
-	
+
 	/* Decide if we should use PIO or DMA transfer */
 	if (self->io.speed > PIO_MAX_SPEED) {
 		self->tx_buff.data = self->tx_buff.head;
 		skb_copy_from_linear_data(skb, self->tx_buff.data, skb->len);
 		self->tx_buff.len = skb->len;
-		
+
 		mtt = irda_get_mtt(skb);
 		pr_debug("%s(%ld), mtt=%d\n", __func__ , jiffies, mtt);
-			if (mtt > 1000)
-				mdelay(mtt/1000);
-			else if (mtt)
-				udelay(mtt);
+		if (mtt > 1000)
+			mdelay(mtt/1000);
+		else if (mtt)
+			udelay(mtt);
 
-			/* Enable DMA interrupt */
-			switch_bank(iobase, SET0);
-	 		outb(ICR_EDMAI, iobase+ICR);
-	     		w83977af_dma_write(self, iobase);
+		/* Enable DMA interrupt */
+		switch_bank(iobase, SET0);
+		outb(ICR_EDMAI, iobase+ICR);
+		w83977af_dma_write(self, iobase);
 	} else {
 		self->tx_buff.data = self->tx_buff.head;
-		self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data, 
+		self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
 						   self->tx_buff.truesize);
-		
+
 		/* Add interrupt on tx low level (will fire immediately) */
 		switch_bank(iobase, SET0);
 		outb(ICR_ETXTHI, iobase+ICR);
@@ -562,15 +562,15 @@ static void w83977af_dma_write(struct w83977af_ir *self, int iobase)
 	switch_bank(iobase, SET0);
 	outb(inb(iobase+HCR) & ~HCR_EN_DMA, iobase+HCR);
 
-	/* Choose transmit DMA channel  */ 
+	/* Choose transmit DMA channel  */
 	switch_bank(iobase, SET2);
 	outb(ADCR1_D_CHSW|/*ADCR1_DMA_F|*/ADCR1_ADV_SL, iobase+ADCR1);
 	irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
-		       DMA_MODE_WRITE);	
+		       DMA_MODE_WRITE);
 	self->io.direction = IO_XMIT;
-	
+
 	/* Enable DMA */
- 	switch_bank(iobase, SET0);
+	switch_bank(iobase, SET0);
 	outb(inb(iobase+HCR) | HCR_EN_DMA | HCR_TX_WT, iobase+HCR);
 
 	/* Restore set register */
@@ -580,14 +580,14 @@ static void w83977af_dma_write(struct w83977af_ir *self, int iobase)
 /*
  * Function w83977af_pio_write (iobase, buf, len, fifo_size)
  *
- *    
+ *
  *
  */
 static int w83977af_pio_write(int iobase, __u8 *buf, int len, int fifo_size)
 {
 	int actual = 0;
 	__u8 set;
-	
+
 	/* Save current bank */
 	set = inb(iobase+SSR);
 
@@ -605,7 +605,7 @@ static int w83977af_pio_write(int iobase, __u8 *buf, int len, int fifo_size)
 		/* Transmit next byte */
 		outb(buf[actual++], iobase+TBR);
 	}
-        
+
 	pr_debug("%s(), fifo_size %d ; %d sent of %d\n",
 		 __func__ , fifo_size, actual, len);
 
@@ -620,7 +620,7 @@ static int w83977af_pio_write(int iobase, __u8 *buf, int len, int fifo_size)
  *
  *    The transfer of a frame in finished. So do the necessary things
  *
- *    
+ *
  */
 static void w83977af_dma_xmit_complete(struct w83977af_ir *self)
 {
@@ -639,11 +639,11 @@ static void w83977af_dma_xmit_complete(struct w83977af_ir *self)
 	/* Disable DMA */
 	switch_bank(iobase, SET0);
 	outb(inb(iobase+HCR) & ~HCR_EN_DMA, iobase+HCR);
-	
+
 	/* Check for underrun! */
 	if (inb(iobase+AUDR) & AUDR_UNDR) {
 		pr_debug("%s(), Transmit underrun!\n", __func__);
-		
+
 		self->netdev->stats.tx_errors++;
 		self->netdev->stats.tx_fifo_errors++;
 
@@ -652,7 +652,7 @@ static void w83977af_dma_xmit_complete(struct w83977af_ir *self)
 	} else
 		self->netdev->stats.tx_packets++;
 
-	
+
 	if (self->new_speed) {
 		w83977af_change_speed(self, self->new_speed);
 		self->new_speed = 0;
@@ -661,7 +661,7 @@ static void w83977af_dma_xmit_complete(struct w83977af_ir *self)
 	/* Unlock tx_buff and request another frame */
 	/* Tell the network layer, that we want more frames */
 	netif_wake_queue(self->netdev);
-	
+
 	/* Restore set */
 	outb(set, iobase+SSR);
 }
@@ -714,15 +714,15 @@ static int w83977af_dma_receive(struct w83977af_ir *self)
 	irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
 		       DMA_MODE_READ);
 #endif
-	/* 
-	 * Reset Rx FIFO. This will also flush the ST_FIFO, it's very 
+	/*
+	 * Reset Rx FIFO. This will also flush the ST_FIFO, it's very
 	 * important that we don't reset the Tx FIFO since it might not
 	 * be finished transmitting yet
 	 */
 	switch_bank(iobase, SET0);
 	outb(UFR_RXTL|UFR_TXTL|UFR_RXF_RST|UFR_EN_FIFO, iobase+UFR);
 	self->st_fifo.len = self->st_fifo.tail = self->st_fifo.head = 0;
-	
+
 	/* Enable DMA */
 	switch_bank(iobase, SET0);
 #ifdef CONFIG_ARCH_NETWINDER
@@ -730,7 +730,7 @@ static int w83977af_dma_receive(struct w83977af_ir *self)
 	outb(hcr | HCR_EN_DMA, iobase+HCR);
 	enable_dma(self->io.dma);
 	spin_unlock_irqrestore(&self->lock, flags);
-#else	
+#else
 	outb(inb(iobase+HCR) | HCR_EN_DMA, iobase+HCR);
 #endif
 	/* Restore set */
@@ -762,21 +762,21 @@ static int w83977af_dma_receive_complete(struct w83977af_ir *self)
 
 	/* Save current set */
 	set = inb(iobase+SSR);
-	
+
 	iobase = self->io.fir_base;
 
 	/* Read status FIFO */
 	switch_bank(iobase, SET5);
 	while ((status = inb(iobase+FS_FO)) & FS_FO_FSFDR) {
 		st_fifo->entries[st_fifo->tail].status = status;
-		
+
 		st_fifo->entries[st_fifo->tail].len  = inb(iobase+RFLFL);
 		st_fifo->entries[st_fifo->tail].len |= inb(iobase+RFLFH) << 8;
-		
+
 		st_fifo->tail++;
 		st_fifo->len++;
 	}
-	
+
 	while (st_fifo->len) {
 		/* Get first entry */
 		status = st_fifo->entries[st_fifo->head].status;
@@ -792,32 +792,32 @@ static int w83977af_dma_receive_complete(struct w83977af_ir *self)
 			} else {
 				/* Skip frame */
 				self->netdev->stats.rx_errors++;
-				
+
 				self->rx_buff.data += len;
-				
+
 				if (status & FS_FO_MX_LEX)
 					self->netdev->stats.rx_length_errors++;
-				
-				if (status & FS_FO_PHY_ERR) 
+
+				if (status & FS_FO_PHY_ERR)
 					self->netdev->stats.rx_frame_errors++;
-				
-				if (status & FS_FO_CRC_ERR) 
+
+				if (status & FS_FO_CRC_ERR)
 					self->netdev->stats.rx_crc_errors++;
 			}
 			/* The errors below can be reported in both cases */
 			if (status & FS_FO_RX_OV)
 				self->netdev->stats.rx_fifo_errors++;
-			
+
 			if (status & FS_FO_FSF_OV)
 				self->netdev->stats.rx_fifo_errors++;
-			
+
 		} else {
 			/* Check if we have transferred all data to memory */
 			switch_bank(iobase, SET0);
 			if (inb(iobase+USR) & USR_RDR) {
 				udelay(80); /* Should be enough!? */
 			}
-						
+
 			skb = dev_alloc_skb(len+1);
 			if (skb == NULL)  {
 				printk(KERN_INFO
@@ -827,10 +827,10 @@ static int w83977af_dma_receive_complete(struct w83977af_ir *self)
 
 				return FALSE;
 			}
-			
+
 			/*  Align to 20 bytes */
-			skb_reserve(skb, 1); 
-			
+			skb_reserve(skb, 1);
+
 			/* Copy frame without CRC */
 			if (self->io.speed < 4000000) {
 				skb_put(skb, len-2);
@@ -847,7 +847,7 @@ static int w83977af_dma_receive_complete(struct w83977af_ir *self)
 			/* Move to next frame */
 			self->rx_buff.data += len;
 			self->netdev->stats.rx_packets++;
-			
+
 			skb->dev = self->netdev;
 			skb_reset_mac_header(skb);
 			skb->protocol = htons(ETH_P_IRDA);
@@ -866,21 +866,21 @@ static int w83977af_dma_receive_complete(struct w83977af_ir *self)
  *    Receive all data in receiver FIFO
  *
  */
-static void w83977af_pio_receive(struct w83977af_ir *self) 
+static void w83977af_pio_receive(struct w83977af_ir *self)
 {
 	__u8 byte = 0x00;
 	int iobase;
 
 	IRDA_ASSERT(self != NULL, return;);
-	
+
 	iobase = self->io.fir_base;
-	
+
 	/*  Receive all characters in Rx FIFO */
 	do {
 		byte = inb(iobase+RBR);
 		async_unwrap_char(self->netdev, &self->netdev->stats, &self->rx_buff,
 				  byte);
-	} while (inb(iobase+USR) & USR_RDR); /* Data available */	
+	} while (inb(iobase+USR) & USR_RDR); /* Data available */
 }
 
 /*
@@ -897,19 +897,19 @@ static __u8 w83977af_sir_interrupt(struct w83977af_ir *self, int isr)
 	int iobase;
 
 	pr_debug("%s(), isr=%#x\n", __func__ , isr);
-	
+
 	iobase = self->io.fir_base;
 	/* Transmit FIFO low on data */
 	if (isr & ISR_TXTH_I) {
 		/* Write data left in transmit buffer */
-		actual = w83977af_pio_write(self->io.fir_base, 
-					    self->tx_buff.data, 
-					    self->tx_buff.len, 
+		actual = w83977af_pio_write(self->io.fir_base,
+					    self->tx_buff.data,
+					    self->tx_buff.len,
 					    self->io.fifo_size);
 
 		self->tx_buff.data += actual;
 		self->tx_buff.len  -= actual;
-		
+
 		self->io.direction = IO_XMIT;
 
 		/* Check if finished */
@@ -919,7 +919,7 @@ static __u8 w83977af_sir_interrupt(struct w83977af_ir *self, int isr)
 			set = inb(iobase+SSR);
 			switch_bank(iobase, SET0);
 			outb(AUDR_SFEND, iobase+AUDR);
-			outb(set, iobase+SSR); 
+			outb(set, iobase+SSR);
 
 			self->netdev->stats.tx_packets++;
 
@@ -929,7 +929,7 @@ static __u8 w83977af_sir_interrupt(struct w83977af_ir *self, int isr)
 		}
 	}
 	/* Check if transmission has completed */
-	if (isr & ISR_TXEMP_I) {		
+	if (isr & ISR_TXEMP_I) {
 		/* Check if we need to change the speed? */
 		if (self->new_speed) {
 			pr_debug("%s(), Changing speed!\n", __func__);
@@ -966,11 +966,11 @@ static __u8 w83977af_fir_interrupt(struct w83977af_ir *self, int isr)
 
 	iobase = self->io.fir_base;
 	set = inb(iobase+SSR);
-	
+
 	/* End of frame detected in FIFO */
 	if (isr & (ISR_FEND_I|ISR_FSF_I)) {
 		if (w83977af_dma_receive_complete(self)) {
-			
+
 			/* Wait for next status FIFO interrupt */
 			new_icr |= ICR_EFSFI;
 		} else {
@@ -995,7 +995,7 @@ static __u8 w83977af_fir_interrupt(struct w83977af_ir *self, int isr)
 
 		/* Clear timer event */
 		/* switch_bank(iobase, SET0); */
-/* 		outb(ASCR_CTE, iobase+ASCR); */
+/*		outb(ASCR_CTE, iobase+ASCR); */
 
 		/* Check if this is a TX timer interrupt */
 		if (self->io.direction == IO_XMIT) {
@@ -1008,23 +1008,23 @@ static __u8 w83977af_fir_interrupt(struct w83977af_ir *self, int isr)
 
 			new_icr |= ICR_EFSFI;
 		}
-	}	
+	}
 	/* Finished with DMA */
 	if (isr & ISR_DMA_I) {
 		w83977af_dma_xmit_complete(self);
 
 		/* Check if there are more frames to be transmitted */
 		/* if (irda_device_txqueue_empty(self)) { */
-		
-		/* Prepare for receive 
-		 * 
+
+		/* Prepare for receive
+		 *
 		 * ** Netwinder Tx DMA likes that we do this anyway **
 		 */
 		w83977af_dma_receive(self);
 		new_icr = ICR_EFSFI;
-	       /* } */
+		/* } */
 	}
-	
+
 	/* Restore set */
 	outb(set, iobase+SSR);
 
@@ -1051,12 +1051,12 @@ static irqreturn_t w83977af_interrupt(int irq, void *dev_id)
 	/* Save current bank */
 	set = inb(iobase+SSR);
 	switch_bank(iobase, SET0);
-	
-	icr = inb(iobase+ICR); 
-	isr = inb(iobase+ISR) & icr; /* Mask out the interesting ones */ 
+
+	icr = inb(iobase+ICR);
+	isr = inb(iobase+ISR) & icr; /* Mask out the interesting ones */
 
 	outb(0, iobase+ICR); /* Disable interrupts */
-	
+
 	if (isr) {
 		/* Dispatch interrupt handler for the current speed */
 		if (self->io.speed > PIO_MAX_SPEED )
@@ -1095,9 +1095,9 @@ static int w83977af_is_receiving(struct w83977af_ir *self)
 			status =  TRUE;
 		}
 		outb(set, iobase+SSR);
-	} else 
+	} else
 		status = (self->rx_buff.state != OUTSIDE_FRAME);
-	
+
 	return status;
 }
 
@@ -1113,16 +1113,16 @@ static int w83977af_net_open(struct net_device *dev)
 	int iobase;
 	char hwname[32];
 	__u8 set;
-	
-	
+
+
 	IRDA_ASSERT(dev != NULL, return -1;);
 	self = netdev_priv(dev);
-	
+
 	IRDA_ASSERT(self != NULL, return 0;);
-	
+
 	iobase = self->io.fir_base;
 
-	if (request_irq(self->io.irq, w83977af_interrupt, 0, dev->name, 
+	if (request_irq(self->io.irq, w83977af_interrupt, 0, dev->name,
 			(void *) dev)) {
 		return -EAGAIN;
 	}
@@ -1134,30 +1134,30 @@ static int w83977af_net_open(struct net_device *dev)
 		free_irq(self->io.irq, dev);
 		return -EAGAIN;
 	}
-		
+
 	/* Save current set */
 	set = inb(iobase+SSR);
 
- 	/* Enable some interrupts so we can receive frames again */
- 	switch_bank(iobase, SET0);
- 	if (self->io.speed > 115200) {
- 		outb(ICR_EFSFI, iobase+ICR);
- 		w83977af_dma_receive(self);
- 	} else
- 		outb(ICR_ERBRI, iobase+ICR);
+	/* Enable some interrupts so we can receive frames again */
+	switch_bank(iobase, SET0);
+	if (self->io.speed > 115200) {
+		outb(ICR_EFSFI, iobase+ICR);
+		w83977af_dma_receive(self);
+	} else
+		outb(ICR_ERBRI, iobase+ICR);
 
 	/* Restore bank register */
 	outb(set, iobase+SSR);
 
 	/* Ready to play! */
 	netif_start_queue(dev);
-	
+
 	/* Give self a hardware name */
 	sprintf(hwname, "w83977af @ 0x%03x", self->io.fir_base);
 
-	/* 
+	/*
 	 * Open new IrLAP layer instance, now that everything should be
-	 * initialized properly 
+	 * initialized properly
 	 */
 	self->irlap = irlap_open(dev, &self->qos, hwname);
 
@@ -1177,16 +1177,16 @@ static int w83977af_net_close(struct net_device *dev)
 	__u8 set;
 
 	IRDA_ASSERT(dev != NULL, return -1;);
-	
+
 	self = netdev_priv(dev);
-	
+
 	IRDA_ASSERT(self != NULL, return 0;);
-	
+
 	iobase = self->io.fir_base;
 
 	/* Stop device */
 	netif_stop_queue(dev);
-	
+
 	/* Stop and remove instance of IrLAP */
 	if (self->irlap)
 		irlap_close(self->irlap);
@@ -1196,10 +1196,10 @@ static int w83977af_net_close(struct net_device *dev)
 
 	/* Save current set */
 	set = inb(iobase+SSR);
-	
+
 	/* Disable interrupts */
 	switch_bank(iobase, SET0);
-	outb(0, iobase+ICR); 
+	outb(0, iobase+ICR);
 
 	free_irq(self->io.irq, dev);
 	free_dma(self->io.dma);
@@ -1230,7 +1230,7 @@ static int w83977af_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 	IRDA_ASSERT(self != NULL, return -1;);
 
 	pr_debug("%s(), %s, (cmd=0x%X)\n", __func__ , dev->name, cmd);
-	
+
 	spin_lock_irqsave(&self->lock, flags);
 
 	switch (cmd) {
@@ -1274,7 +1274,7 @@ MODULE_PARM_DESC(irq, "IRQ lines");
 /*
  * Function init_module (void)
  *
- *    
+ *
  *
  */
 module_init(w83977af_init);
@@ -1282,7 +1282,7 @@ module_init(w83977af_init);
 /*
  * Function cleanup_module (void)
  *
- *    
+ *
  *
  */
 module_exit(w83977af_cleanup);
-- 
2.9.0

^ permalink raw reply related

* [PATCH v2] net: phy: Fix use after free in phy_detach()
From: Geert Uytterhoeven @ 2016-11-28 14:18 UTC (permalink / raw)
  To: Florian Fainelli, David S. Miller, Josh Cartwright,
	Nathan Sullivan, Zach Brown
  Cc: Woojung Huh, netdev, linux-renesas-soc, linux-kernel,
	Geert Uytterhoeven

If device_release_driver(&phydev->mdio.dev) is called, it releases all
resources belonging to the PHY device. Hence the subsequent call to
phy_led_triggers_unregister() will access already freed memory when
unregistering the LEDs.

Move the call to phy_led_triggers_unregister() before the possible call
to device_release_driver() to fix this.

Fixes: 2e0bc452f4721520 ("net: phy: leds: add support for led triggers on phy link state change")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
This is v2 of "[RFC] net: phy: Fix double free in phy_detach()".

v2:
  - Dropped RFC,
  - Reworded, as commit a7dac9f9c1695d74 ("phy: fix error case of
    phy_led_triggers_(un)register") fixed the double free, and thus the
    warning I was seeing during "poweroff" on sh73a0/kzm9g,
  - Verified use after free using CONFIG_DEBUG_DEVRES, log_devres = 1,
    and additional debug code printing the address of
    phy->phy_led_triggers. Adding poisoning of freed memory to
    devres_log() will cause a crash.
---
 drivers/net/phy/phy_device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index ba86c191a13ea81c..a1d6e13b1b4113a4 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -981,6 +981,8 @@ void phy_detach(struct phy_device *phydev)
 	phydev->attached_dev = NULL;
 	phy_suspend(phydev);
 
+	phy_led_triggers_unregister(phydev);
+
 	/* If the device had no specific driver before (i.e. - it
 	 * was using the generic driver), we unbind the device
 	 * from the generic driver so that there's a chance a
@@ -994,8 +996,6 @@ void phy_detach(struct phy_device *phydev)
 		}
 	}
 
-	phy_led_triggers_unregister(phydev);
-
 	/*
 	 * The phydev might go away on the put_device() below, so avoid
 	 * a use-after-free bug by reading the underlying bus first.
-- 
1.9.1

^ permalink raw reply related

* Re: [PATCH net-next 1/3] ethtool: (uapi) Add ETHTOOL_PHY_LOOPBACK to PHY tunables
From: Andrew Lunn @ 2016-11-28 14:14 UTC (permalink / raw)
  To: Allan W. Nielsen; +Cc: netdev, f.fainelli, raju.lakkaraju
In-Reply-To: <1480339472-5823-2-git-send-email-allan.nielsen@microsemi.com>

On Mon, Nov 28, 2016 at 02:24:30PM +0100, Allan W. Nielsen wrote:
> From: Raju Lakkaraju <Raju.Lakkaraju@microsemi.com>
> 
> 3 types of PHY loopback are supported.
> i.e. Near-End Loopback, Far-End Loopback and External Loopback.

Hi Allan

Is this integrated with ethtool --test? You only want the PHY to go
into loopback mode when running ethtool --test external_lb or maybe
ethtool --test offline.

What i think should happen is that this tunable sets the mode the PHY
will go into when loopback is enabled. It does not however enable
loopback. It is running ethtool --test which actually enables the
loopback, probably by setting BMCR_LOOPBACK. Once the test is
finished, the bit is cleared and the PHY goes back into normal
operation.

	Andrew

^ permalink raw reply

* Re: net/sctp: vmalloc allocation failure in sctp_setsockopt/xt_alloc_table_info
From: Neil Horman @ 2016-11-28 14:13 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Vlad Yasevich, linux-sctp, netdev, LKML, Pablo Neira Ayuso,
	Patrick McHardy, Jozsef Kadlecsik, David S. Miller,
	netfilter-devel, coreteam, Dmitry Vyukov, Kostya Serebryany,
	Eric Dumazet, syzkaller
In-Reply-To: <CAAeHK+wecw6ST_DWJQBLFNwVsOVgderGE-EEJiN0-kf796XHtw@mail.gmail.com>

On Mon, Nov 28, 2016 at 02:00:19PM +0100, Andrey Konovalov wrote:
> Hi!
> 
> I've got the following error report while running the syzkaller fuzzer.
> 
> On commit d8e435f3ab6fea2ea324dce72b51dd7761747523 (Nov 26).
> 
> A reproducer is attached.
> 
> a.out: vmalloc: allocation failure, allocated 823562240 of 1427091456
> bytes, mode:0x24000c2(GFP_KERNEL|__GFP_HIGHMEM)
> 
How much total ram do you have in this system?  The call appears to be
attempting to allocate 1.3 Gb of data.  Even using vmalloc to allow
discontiguous allocation, thats alot of memory, and if enough is in use already,
I could make the argument that this might be expected behavior.

Neil

> oom_reaper: reaped process 3810 (a.out), now anon-rss:0kB,
> file-rss:0kB, shmem-rss:0kB
> a.out invoked oom-killer:
> gfp_mask=0x24002c2(GFP_KERNEL|__GFP_HIGHMEM|__GFP_NOWARN), nodemask=0,
> order=0, oom_score_adj=0
> a.out cpuset=/ mems_allowed=0
> CPU: 0 PID: 3814 Comm: a.out Not tainted 4.9.0-rc6+ #457
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
>  ffff880068667380 ffffffff81c73b14 ffff880068667710 ffff88006b469018
>  ffff880068667718 0000000000000000 ffff880068667400 ffffffff81641a87
>  0000000000000000 0000000000000000 0000000000000297 ffffffff84d37280
> Call Trace:
>  [<     inline     >] __dump_stack lib/dump_stack.c:15
>  [<ffffffff81c73b14>] dump_stack+0xb3/0x10f lib/dump_stack.c:51
>  [<ffffffff81641a87>] dump_header.isra.21+0x16f/0x5f5 mm/oom_kill.c:416
>  [<ffffffff8154bad8>] oom_kill_process+0x4d8/0xab0 mm/oom_kill.c:835
>  [<ffffffff8154c77c>] out_of_memory+0x2dc/0x1790 mm/oom_kill.c:1044
>  [<     inline     >] __alloc_pages_may_oom mm/page_alloc.c:3086
>  [<ffffffff8155afb6>] __alloc_pages_slowpath+0x1886/0x1bf0 mm/page_alloc.c:3683
>  [<ffffffff8155b8e2>] __alloc_pages_nodemask+0x5c2/0x710 mm/page_alloc.c:3781
>  [<ffffffff816236a4>] alloc_pages_current+0xf4/0x400 mm/mempolicy.c:2072
>  [<     inline     >] alloc_pages ./include/linux/gfp.h:469
>  [<     inline     >] __vmalloc_area_node mm/vmalloc.c:1631
>  [<ffffffff815f8eab>] __vmalloc_node_range+0x33b/0x690 mm/vmalloc.c:1691
>  [<     inline     >] __vmalloc_node mm/vmalloc.c:1734
>  [<     inline     >] __vmalloc_node_flags mm/vmalloc.c:1748
>  [<ffffffff815f92cb>] vmalloc+0x5b/0x70 mm/vmalloc.c:1763
>  [<ffffffff82fd0893>] xt_alloc_table_info+0x83/0x120
> net/netfilter/x_tables.c:961
>  [<     inline     >] do_replace net/ipv4/netfilter/ip_tables.c:1140
>  [<ffffffff8335b420>] do_ipt_set_ctl+0x210/0x420
> net/ipv4/netfilter/ip_tables.c:1687
>  [<     inline     >] nf_sockopt net/netfilter/nf_sockopt.c:105
>  [<ffffffff82efdab7>] nf_setsockopt+0x67/0xc0 net/netfilter/nf_sockopt.c:114
>  [<ffffffff831be741>] ip_setsockopt+0xa1/0xb0 net/ipv4/ip_sockglue.c:1231
>  [<ffffffff832700d5>] udp_setsockopt+0x45/0x80 net/ipv4/udp.c:2085
>  [<ffffffff8346b31f>] ipv6_setsockopt+0x11f/0x140 net/ipv6/ipv6_sockglue.c:892
>  [<ffffffff83a6cd5d>] sctp_setsockopt+0x15d/0x3d70 net/sctp/socket.c:3788
>  [<ffffffff82ca40e6>] sock_common_setsockopt+0x96/0xd0 net/core/sock.c:2690
>  [<     inline     >] SYSC_setsockopt net/socket.c:1757
>  [<ffffffff82ca10c4>] SyS_setsockopt+0x154/0x240 net/socket.c:1736
>  [<ffffffff840f2c41>] entry_SYSCALL_64_fastpath+0x1f/0xc2
> arch/x86/entry/entry_64.S:209
> CPU: 1 PID: 3810 Comm: a.out Not tainted 4.9.0-rc6+ #457
> Mem-Info:
> active_anon:1938 inactive_anon:75 isolated_anon:0
>  active_file:14 inactive_file:30 isolated_file:4
>  unevictable:0 dirty:0 writeback:0 unstable:0
>  slab_reclaimable:3316 slab_unreclaimable:9767
>  mapped:21 shmem:81 pagetables:309 bounce:0
>  free:1 free_pcp:75 free_cma:0
> Node 0 active_anon:7752kB inactive_anon:300kB active_file:56kB
> inactive_file:120kB unevictable:0kB isolated(anon):0kB
> isolated(file):16kB mapped:84kB dirty:0kB writeback:0kB shmem:324kB
> writeback_tmp:0kB unstable:0kB pages_scanned:134 all_unreclaimable? no
> Node 0 DMA free:4kB min:48kB low:60kB high:72kB active_anon:0kB
> inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB
> writepending:0kB present:15992kB managed:15908kB mlocked:0kB
> slab_reclaimable:0kB slab_unreclaimable:8kB kernel_stack:0kB
> pagetables:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
> lowmem_reserve[]: 0 1641 1641 1641
> Node 0 DMA32 free:0kB min:5156kB low:6836kB high:8516kB
> active_anon:7752kB inactive_anon:300kB active_file:56kB
> inactive_file:120kB unevictable:0kB writepending:0kB present:2080760kB
> managed:1684640kB mlocked:0kB slab_reclaimable:13264kB
> slab_unreclaimable:39060kB kernel_stack:2944kB pagetables:1236kB
> bounce:0kB free_pcp:300kB local_pcp:120kB free_cma:0kB
> lowmem_reserve[]: 0 0 0 0
> Node 0 DMA: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB
> 0*1024kB 0*2048kB 0*4096kB = 0kB
> Node 0 DMA32: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB
> 0*1024kB 0*2048kB 0*4096kB = 0kB
> Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB
> 148 total pagecache pages
> 0 pages in swap cache
> Swap cache stats: add 0, delete 0, find 0/0
> Free swap  = 0kB
> Total swap = 0kB
> 524188 pages RAM
> 0 pages HighMem/MovableOnly
> 99051 pages reserved
> [ pid ]   uid  tgid total_vm      rss nr_ptes nr_pmds swapents
> oom_score_adj name
>     0  1767     5346      133      16       3        0         -1000 udevd
>     0  1876     5315      122      15       3        0         -1000 udevd
>     0  1877     5315      122      15       3        0         -1000 udevd
>     0  3541     2493      573       8       3        0             0 dhclient
>     0  3676    13231      171      22       3        0             0 rsyslogd
>     0  3725     4725       52      15       3        0             0 cron
>     0  3751    12490      155      28       3        0         -1000 sshd
>     0  3775     3694       43      13       3        0             0 getty
>     0  3776     3694       43      13       3        0             0 getty
>     0  3777     3694       42      13       3        0             0 getty
>     0  3778     3694       41      13       3        0             0 getty
>     0  3779     3694       44      13       3        0             0 getty
>     0  3780     3694       43      13       3        0             0 getty
>     0  3785     3649       44      12       3        0             0 getty
>     0  3797    17818      205      39       3        0             0 sshd
>     0  3800     4474      126      15       3        0             0 bash
>     0  3804     2053       22       9       3        0             0 a.out
>     0  3805     2053       26       9       3        0             0 a.out
>     0  3806    18488        0      18       3        0             0 a.out

> // autogenerated by syzkaller (http://github.com/google/syzkaller)
> 
> #ifndef __NR_mmap
> #define __NR_mmap 9
> #endif
> #ifndef __NR_setsockopt
> #define __NR_setsockopt 54
> #endif
> #ifndef __NR_syz_fuse_mount
> #define __NR_syz_fuse_mount 1000004
> #endif
> #ifndef __NR_socket
> #define __NR_socket 41
> #endif
> #ifndef __NR_syz_emit_ethernet
> #define __NR_syz_emit_ethernet 1000006
> #endif
> #ifndef __NR_syz_fuseblk_mount
> #define __NR_syz_fuseblk_mount 1000005
> #endif
> #ifndef __NR_syz_open_dev
> #define __NR_syz_open_dev 1000002
> #endif
> #ifndef __NR_syz_open_pts
> #define __NR_syz_open_pts 1000003
> #endif
> #ifndef __NR_syz_test
> #define __NR_syz_test 1000001
> #endif
> 
> #define SYZ_SANDBOX_NONE 1
> #define SYZ_REPEAT 1
> 
> #define _GNU_SOURCE
> 
> #include <sys/ioctl.h>
> #include <sys/mount.h>
> #include <sys/prctl.h>
> #include <sys/resource.h>
> #include <sys/socket.h>
> #include <sys/stat.h>
> #include <sys/syscall.h>
> #include <sys/time.h>
> #include <sys/types.h>
> #include <sys/wait.h>
> 
> #include <linux/capability.h>
> #include <linux/if.h>
> #include <linux/if_tun.h>
> #include <linux/sched.h>
> #include <net/if_arp.h>
> 
> #include <assert.h>
> #include <dirent.h>
> #include <errno.h>
> #include <fcntl.h>
> #include <grp.h>
> #include <pthread.h>
> #include <setjmp.h>
> #include <signal.h>
> #include <stdarg.h>
> #include <stddef.h>
> #include <stdint.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <unistd.h>
> 
> const int kFailStatus = 67;
> const int kErrorStatus = 68;
> const int kRetryStatus = 69;
> 
> __attribute__((noreturn)) void fail(const char* msg, ...)
> {
>   int e = errno;
>   fflush(stdout);
>   va_list args;
>   va_start(args, msg);
>   vfprintf(stderr, msg, args);
>   va_end(args);
>   fprintf(stderr, " (errno %d)\n", e);
>   exit(kFailStatus);
> }
> 
> __attribute__((noreturn)) void exitf(const char* msg, ...)
> {
>   int e = errno;
>   fflush(stdout);
>   va_list args;
>   va_start(args, msg);
>   vfprintf(stderr, msg, args);
>   va_end(args);
>   fprintf(stderr, " (errno %d)\n", e);
>   exit(kRetryStatus);
> }
> 
> static int flag_debug;
> 
> void debug(const char* msg, ...)
> {
>   if (!flag_debug)
>     return;
>   va_list args;
>   va_start(args, msg);
>   vfprintf(stdout, msg, args);
>   va_end(args);
>   fflush(stdout);
> }
> 
> __thread int skip_segv;
> __thread jmp_buf segv_env;
> 
> static void segv_handler(int sig, siginfo_t* info, void* uctx)
> {
>   if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED))
>     _longjmp(segv_env, 1);
>   exit(sig);
> }
> 
> static void install_segv_handler()
> {
>   struct sigaction sa;
>   memset(&sa, 0, sizeof(sa));
>   sa.sa_sigaction = segv_handler;
>   sa.sa_flags = SA_NODEFER | SA_SIGINFO;
>   sigaction(SIGSEGV, &sa, NULL);
>   sigaction(SIGBUS, &sa, NULL);
> }
> 
> #define NONFAILING(...)                                                \
>   {                                                                    \
>     __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST);               \
>     if (_setjmp(segv_env) == 0) {                                      \
>       __VA_ARGS__;                                                     \
>     }                                                                  \
>     __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST);               \
>   }
> 
> static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2)
> {
>   if (a0 == 0xc || a0 == 0xb) {
>     char buf[128];
>     sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block",
>             (uint8_t)a1, (uint8_t)a2);
>     return open(buf, O_RDWR, 0);
>   } else {
>     char buf[1024];
>     char* hash;
>     strncpy(buf, (char*)a0, sizeof(buf));
>     buf[sizeof(buf) - 1] = 0;
>     while ((hash = strchr(buf, '#'))) {
>       *hash = '0' + (char)(a1 % 10);
>       a1 /= 10;
>     }
>     return open(buf, a2, 0);
>   }
> }
> 
> static uintptr_t syz_open_pts(uintptr_t a0, uintptr_t a1)
> {
>   int ptyno = 0;
>   if (ioctl(a0, TIOCGPTN, &ptyno))
>     return -1;
>   char buf[128];
>   sprintf(buf, "/dev/pts/%d", ptyno);
>   return open(buf, a1, 0);
> }
> 
> static uintptr_t syz_fuse_mount(uintptr_t a0, uintptr_t a1,
>                                 uintptr_t a2, uintptr_t a3,
>                                 uintptr_t a4, uintptr_t a5)
> {
>   uint64_t target = a0;
>   uint64_t mode = a1;
>   uint64_t uid = a2;
>   uint64_t gid = a3;
>   uint64_t maxread = a4;
>   uint64_t flags = a5;
> 
>   int fd = open("/dev/fuse", O_RDWR);
>   if (fd == -1)
>     return fd;
>   char buf[1024];
>   sprintf(buf, "fd=%d,user_id=%ld,group_id=%ld,rootmode=0%o", fd,
>           (long)uid, (long)gid, (unsigned)mode & ~3u);
>   if (maxread != 0)
>     sprintf(buf + strlen(buf), ",max_read=%ld", (long)maxread);
>   if (mode & 1)
>     strcat(buf, ",default_permissions");
>   if (mode & 2)
>     strcat(buf, ",allow_other");
>   syscall(SYS_mount, "", target, "fuse", flags, buf);
>   return fd;
> }
> 
> static uintptr_t syz_fuseblk_mount(uintptr_t a0, uintptr_t a1,
>                                    uintptr_t a2, uintptr_t a3,
>                                    uintptr_t a4, uintptr_t a5,
>                                    uintptr_t a6, uintptr_t a7)
> {
>   uint64_t target = a0;
>   uint64_t blkdev = a1;
>   uint64_t mode = a2;
>   uint64_t uid = a3;
>   uint64_t gid = a4;
>   uint64_t maxread = a5;
>   uint64_t blksize = a6;
>   uint64_t flags = a7;
> 
>   int fd = open("/dev/fuse", O_RDWR);
>   if (fd == -1)
>     return fd;
>   if (syscall(SYS_mknodat, AT_FDCWD, blkdev, S_IFBLK, makedev(7, 199)))
>     return fd;
>   char buf[256];
>   sprintf(buf, "fd=%d,user_id=%ld,group_id=%ld,rootmode=0%o", fd,
>           (long)uid, (long)gid, (unsigned)mode & ~3u);
>   if (maxread != 0)
>     sprintf(buf + strlen(buf), ",max_read=%ld", (long)maxread);
>   if (blksize != 0)
>     sprintf(buf + strlen(buf), ",blksize=%ld", (long)blksize);
>   if (mode & 1)
>     strcat(buf, ",default_permissions");
>   if (mode & 2)
>     strcat(buf, ",allow_other");
>   syscall(SYS_mount, blkdev, target, "fuseblk", flags, buf);
>   return fd;
> }
> 
> static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1,
>                                  uintptr_t a2, uintptr_t a3,
>                                  uintptr_t a4, uintptr_t a5,
>                                  uintptr_t a6, uintptr_t a7,
>                                  uintptr_t a8)
> {
>   switch (nr) {
>   default:
>     return syscall(nr, a0, a1, a2, a3, a4, a5);
>   case __NR_syz_test:
>     return 0;
>   case __NR_syz_open_dev:
>     return syz_open_dev(a0, a1, a2);
>   case __NR_syz_open_pts:
>     return syz_open_pts(a0, a1);
>   case __NR_syz_fuse_mount:
>     return syz_fuse_mount(a0, a1, a2, a3, a4, a5);
>   case __NR_syz_fuseblk_mount:
>     return syz_fuseblk_mount(a0, a1, a2, a3, a4, a5, a6, a7);
>   }
> }
> 
> static void setup_main_process()
> {
>   struct sigaction sa;
>   memset(&sa, 0, sizeof(sa));
>   sa.sa_handler = SIG_IGN;
>   syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
>   syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
>   install_segv_handler();
> 
>   char tmpdir_template[] = "./syzkaller.XXXXXX";
>   char* tmpdir = mkdtemp(tmpdir_template);
>   if (!tmpdir)
>     fail("failed to mkdtemp");
>   if (chmod(tmpdir, 0777))
>     fail("failed to chmod");
>   if (chdir(tmpdir))
>     fail("failed to chdir");
> }
> 
> static void loop();
> 
> static void sandbox_common()
> {
>   prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
>   setpgrp();
>   setsid();
> 
>   struct rlimit rlim;
>   rlim.rlim_cur = rlim.rlim_max = 128 << 20;
>   setrlimit(RLIMIT_AS, &rlim);
>   rlim.rlim_cur = rlim.rlim_max = 1 << 20;
>   setrlimit(RLIMIT_FSIZE, &rlim);
>   rlim.rlim_cur = rlim.rlim_max = 1 << 20;
>   setrlimit(RLIMIT_STACK, &rlim);
>   rlim.rlim_cur = rlim.rlim_max = 0;
>   setrlimit(RLIMIT_CORE, &rlim);
> 
>   unshare(CLONE_NEWNS);
>   unshare(CLONE_NEWIPC);
>   unshare(CLONE_IO);
> }
> 
> static int do_sandbox_none()
> {
>   int pid = fork();
>   if (pid)
>     return pid;
>   sandbox_common();
>   loop();
>   exit(1);
> }
> 
> static void remove_dir(const char* dir)
> {
>   DIR* dp;
>   struct dirent* ep;
>   int iter = 0;
>   int i;
> retry:
>   dp = opendir(dir);
>   if (dp == NULL) {
>     if (errno == EMFILE) {
>       exitf("opendir(%s) failed due to NOFILE, exiting");
>     }
>     exitf("opendir(%s) failed", dir);
>   }
>   while ((ep = readdir(dp))) {
>     if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
>       continue;
>     char filename[FILENAME_MAX];
>     snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
>     struct stat st;
>     if (lstat(filename, &st))
>       exitf("lstat(%s) failed", filename);
>     if (S_ISDIR(st.st_mode)) {
>       remove_dir(filename);
>       continue;
>     }
>     for (i = 0;; i++) {
>       debug("unlink(%s)\n", filename);
>       if (unlink(filename) == 0)
>         break;
>       if (errno == EROFS) {
>         debug("ignoring EROFS\n");
>         break;
>       }
>       if (errno != EBUSY || i > 100)
>         exitf("unlink(%s) failed", filename);
>       debug("umount(%s)\n", filename);
>       if (umount2(filename, MNT_DETACH))
>         exitf("umount(%s) failed", filename);
>     }
>   }
>   closedir(dp);
>   for (i = 0;; i++) {
>     debug("rmdir(%s)\n", dir);
>     if (rmdir(dir) == 0)
>       break;
>     if (i < 100) {
>       if (errno == EROFS) {
>         debug("ignoring EROFS\n");
>         break;
>       }
>       if (errno == EBUSY) {
>         debug("umount(%s)\n", dir);
>         if (umount2(dir, MNT_DETACH))
>           exitf("umount(%s) failed", dir);
>         continue;
>       }
>       if (errno == ENOTEMPTY) {
>         if (iter < 100) {
>           iter++;
>           goto retry;
>         }
>       }
>     }
>     exitf("rmdir(%s) failed", dir);
>   }
> }
> 
> static uint64_t current_time_ms()
> {
>   struct timespec ts;
> 
>   if (clock_gettime(CLOCK_MONOTONIC, &ts))
>     fail("clock_gettime failed");
>   return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
> }
> 
> static void test();
> 
> void loop()
> {
>   int iter;
>   for (iter = 0;; iter++) {
>     char cwdbuf[256];
>     sprintf(cwdbuf, "./%d", iter);
>     if (mkdir(cwdbuf, 0777))
>       fail("failed to mkdir");
>     int pid = fork();
>     if (pid < 0)
>       fail("clone failed");
>     if (pid == 0) {
>       prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
>       setpgrp();
>       if (chdir(cwdbuf))
>         fail("failed to chdir");
>       test();
>       exit(0);
>     }
>     int status = 0;
>     uint64_t start = current_time_ms();
>     for (;;) {
>       int res = waitpid(pid, &status, __WALL | WNOHANG);
>       int errno0 = errno;
>       if (res == pid)
>         break;
>       usleep(1000);
>       if (current_time_ms() - start > 5 * 1000) {
>         kill(-pid, SIGKILL);
>         kill(pid, SIGKILL);
>         waitpid(pid, &status, __WALL);
>         break;
>       }
>     }
>     remove_dir(cwdbuf);
>   }
> }
> 
> long r[5];
> void* thr(void* arg)
> {
>   switch ((long)arg) {
>   case 0:
>     r[0] =
>         execute_syscall(__NR_mmap, 0x20000000ul, 0xa000ul, 0x3ul,
>                         0x32ul, 0xfffffffffffffffful, 0x0ul, 0, 0, 0);
>     break;
>   case 1:
>     r[1] = execute_syscall(__NR_socket, 0xaul, 0x5ul, 0x84ul, 0, 0, 0,
>                            0, 0, 0);
>     break;
>   case 2:
>     r[2] = execute_syscall(__NR_socket, 0x1ful, 0x3ul, 0x6ul, 0, 0, 0,
>                            0, 0, 0);
>     break;
>   case 3:
>     NONFAILING(memcpy(
>         (void*)0x20009000,
>         "\x83\x15\xf6\xdb\x47\x14\xae\xe2\x8d\xb8\x4d\xb9\x0f\x32\xe7"
>         "\xf5\xbc\xa6\xae\x9a\x2f\x19\xed\xf0\x75\x6a\x0b\xf0\x00\xe9"
>         "\xe1\x0e\xb4\xa5\x19\x08\x88\xfc\x8b\x2d\xe2\x9a\x0f\x55\x00"
>         "\x00\x00\x00\x00\x08\x27\xab\x8e\x7d\xcb\xcc\x15\x4e\x79\xe2"
>         "\xd9\xca\x15\xc3\x66\xbd\x44\xa8\x53\x1f\xda\xab\xce\x98\x39"
>         "\x40\x4e\x75\x57\xfd\x57\xc0\x01\x0b\xb0",
>         85));
>     r[4] = execute_syscall(__NR_setsockopt, r[1], 0x0ul, 0x40ul,
>                            0x20009000ul, 0x55ul, 0, 0, 0, 0);
>     break;
>   }
>   return 0;
> }
> 
> void test()
> {
>   long i;
>   pthread_t th[8];
> 
>   memset(r, -1, sizeof(r));
>   srand(getpid());
>   for (i = 0; i < 4; i++) {
>     pthread_create(&th[i], 0, thr, (void*)i);
>     usleep(10000);
>   }
>   for (i = 0; i < 4; i++) {
>     pthread_create(&th[4 + i], 0, thr, (void*)i);
>     if (rand() % 2)
>       usleep(rand() % 10000);
>   }
>   usleep(100000);
> }
> 
> int main()
> {
>   setup_main_process();
>   int pid = do_sandbox_none();
>   int status = 0;
>   while (waitpid(pid, &status, __WALL) != pid) {
>   }
>   return 0;
> }

^ permalink raw reply

* Re: [PATCH] net: fec: turn on device when extracting statistics
From: David Miller @ 2016-11-28 14:11 UTC (permalink / raw)
  To: nikita.yoush
  Cc: fugang.duan, troy.kisky, andrew, eric, tremyfr, johannes, netdev,
	linux-kernel, cphealy, fabio.estevam
In-Reply-To: <4ddb5842-0ece-2950-214f-f56db808ffbd@cogentembedded.com>

From: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
Date: Mon, 28 Nov 2016 10:06:31 +0300

> 
> 
> 28.11.2016 04:29, David Miller пишет:
>> From: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
>> Date: Fri, 25 Nov 2016 13:02:00 +0300
>> 
>>> +	int i, ret;
>>> +
>>> +	ret = pm_runtime_get_sync(&fep->pdev->dev);
>>> +	if (IS_ERR_VALUE(ret)) {
>>> +		memset(data, 0, sizeof(*data) * ARRAY_SIZE(fec_stats));
>>> +		return;
>>> +	}
>> 
>> This really isn't the way to do this.
>> 
>> When the device is suspended and the clocks are going to be stopped,
>> you must fetch the statistic values into a software copy and provide
>> those if the device is suspended when statistics are requested.
> 
> Ok, can do that, although can't see what's wrong with waking device
> here. The situation of requesting stats on down device isn't something
> widely used, thus keeping handling of that as local as possible looks
> better for me.

The issue is the fact that you need error handling at all and might
therefore provide a set of zero stats to the user when that entire
possibility could have been avoided in the first place by recording
the stats at suspend time.

^ permalink raw reply

* Re: [PATCH v2 1/1] net: macb: ensure ordering write to re-enable RX smoothly
From: Nicolas Ferre @ 2016-11-28 14:04 UTC (permalink / raw)
  To: Zumeng Chen
  Cc: davem, netdev, linux-kernel, Cyrille Pitchen, Andrei Pistirica
In-Reply-To: <1480341300-17384-1-git-send-email-zumeng.chen@windriver.com>

Le 28/11/2016 à 14:55, Zumeng Chen a écrit :
> When a hardware issue happened as described by inline comments, the register
> write pattern looks like the following:
> 
> <write ~MACB_BIT(RE)>
> + wmb();
> <write MACB_BIT(RE)>
> 
> There might be a memory barrier between these two write operations, so add wmb
> to ensure an flip from 0 to 1 for NCR.
> 
> Signed-off-by: Zumeng Chen <zumeng.chen@windriver.com>

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>

Thanks, best regards,

> ---
> 
> V2 changes:
> 
> Add the same wmb for at91ether as well based on reviewer's suggestion.
> 
> Cheers,
>  drivers/net/ethernet/cadence/macb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
> index 533653b..6d7cfa7 100644
> --- a/drivers/net/ethernet/cadence/macb.c
> +++ b/drivers/net/ethernet/cadence/macb.c
> @@ -1156,6 +1156,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
>  		if (status & MACB_BIT(RXUBR)) {
>  			ctrl = macb_readl(bp, NCR);
>  			macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE));
> +			wmb();
>  			macb_writel(bp, NCR, ctrl | MACB_BIT(RE));
>  
>  			if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)
> @@ -2770,6 +2771,7 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
>  	if (intstatus & MACB_BIT(RXUBR)) {
>  		ctl = macb_readl(lp, NCR);
>  		macb_writel(lp, NCR, ctl & ~MACB_BIT(RE));
> +		wmb();
>  		macb_writel(lp, NCR, ctl | MACB_BIT(RE));
>  	}
>  
> 


-- 
Nicolas Ferre

^ permalink raw reply

* [PATCH v2 1/1] net: macb: ensure ordering write to re-enable RX smoothly
From: Zumeng Chen @ 2016-11-28 13:55 UTC (permalink / raw)
  To: nicolas.ferre; +Cc: davem, netdev, linux-kernel

When a hardware issue happened as described by inline comments, the register
write pattern looks like the following:

<write ~MACB_BIT(RE)>
+ wmb();
<write MACB_BIT(RE)>

There might be a memory barrier between these two write operations, so add wmb
to ensure an flip from 0 to 1 for NCR.

Signed-off-by: Zumeng Chen <zumeng.chen@windriver.com>
---

V2 changes:

Add the same wmb for at91ether as well based on reviewer's suggestion.

Cheers,
 drivers/net/ethernet/cadence/macb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 533653b..6d7cfa7 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -1156,6 +1156,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
 		if (status & MACB_BIT(RXUBR)) {
 			ctrl = macb_readl(bp, NCR);
 			macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE));
+			wmb();
 			macb_writel(bp, NCR, ctrl | MACB_BIT(RE));
 
 			if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)
@@ -2770,6 +2771,7 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
 	if (intstatus & MACB_BIT(RXUBR)) {
 		ctl = macb_readl(lp, NCR);
 		macb_writel(lp, NCR, ctl & ~MACB_BIT(RE));
+		wmb();
 		macb_writel(lp, NCR, ctl | MACB_BIT(RE));
 	}
 
-- 
2.4.11

^ permalink raw reply related

* Re: [PATCH net-next 0/5] net: add protocol level recvmmsg support
From: Jesper Dangaard Brouer @ 2016-11-28 13:52 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: netdev, David S. Miller, Eric Dumazet, Hannes Frederic Sowa,
	Sabrina Dubroca, brouer
In-Reply-To: <20161128132141.217aef39@redhat.com>


On Mon, 28 Nov 2016 13:21:41 +0100 Jesper Dangaard Brouer <brouer@redhat.com> wrote:
> On Mon, 28 Nov 2016 11:52:38 +0100 Paolo Abeni <pabeni@redhat.com> wrote:
> >   
> > > > [2] like [1], but using the minimum number of flows to saturate the user space
> > > >  sink, that is 1 flow for the old kernel and 3 for the patched one.
> > > >  the tput increases since the contention on the rx lock is low.
> > > > [3] like [1] but using a single flow with both old and new kernel. All the
> > > >  packets land on the same rx queue and there is a single ksoftirqd instance
> > > >  running    
[...]
> > 
> > We also used connected socket for test[3], with relative little
> > difference (the tput increased for both unpatched and patched kernel, 
> > and the difference was roughly the same).  
> 
> When I use connected sockets (RX side) and ip_early_demux enabled, I do
> see a performance boost for recvmmsg.  With these patches applied,
> forced ksoftirqd on CPU0 and udp_sink on CPU2, pktgen single flow
> sending size 1472 bytes.
> 
> $ sysctl net/ipv4/ip_early_demux
> net.ipv4.ip_early_demux = 1
> 
> $ grep -H . /proc/sys/net/core/{r,w}mem_max
> /proc/sys/net/core/rmem_max:1048576
> /proc/sys/net/core/wmem_max:1048576
> 
> # taskset -c 2 ./udp_sink --count $((10**7)) --port 9 --repeat 1
> #                               ns      pps             cycles
> recvMmsg/32  	run: 0 10000000	462.51	2162095.23	1853
> recvmsg   	run: 0 10000000	536.47	1864041.75	2150
> read      	run: 0 10000000	492.01	2032460.71	1972
> recvfrom  	run: 0 10000000	553.94	1805262.84	2220
> 
> # taskset -c 2 ./udp_sink --count $((10**7)) --port 9 --repeat 1 --connect
> #                               ns      pps             cycles
> recvMmsg/32  	run: 0 10000000	405.15	2468225.03	1623
> recvmsg   	run: 0 10000000	548.23	1824049.58	2197
> read      	run: 0 10000000	489.76	2041825.27	1962
> recvfrom  	run: 0 10000000	466.18	2145091.77	1868
> 
> My theory is that by enabling connect'ed RX socket, the ksoftirqd gets
> faster (no fib_lookup) and is no-longer a bottleneck.  This is
> confirmed by nstat.

Paolo asked me to do a test with small packets with pktgen, and I was
actually surprised by the result.

# taskset -c 2 ./udp_sink --count $((10**7)) --port 9 --repeat 1 --connect
recvMmsg/32  	run: 0 10000000	426.61	2344076.59	1709	17098657328
recvmsg   	run: 0 10000000	533.49	1874449.82	2138	21382574965
read      	run: 0 10000000	470.22	2126651.13	1884	18846797802
recvfrom  	run: 0 10000000	513.74	1946499.83	2059	20591095477

Notice how recvMmsg/32, got slower with 124kpps (2468225 pps -> 2344076 pps).
I was expecting it to get faster, given we just established udp_sink
was the bottleneck, and smaller packet should mean less copy of bytes
to userspace (copy_user_enhanced_fast_string). (With nstat I observe
ksoftirq is again the bottleneck).

Looking at perf diff of CPU2 (baseline=64Bytes) we do see an increase
of copy_user_enhanced_fast_string.  More interestingly we see a
decrease in the locking cost when using big packets (see ** below)

# Event 'cycles:ppp'
#
# Baseline    Delta  Shared Object     Symbol                                   
# ........  .......  ................  .........................................
#
    15.09%   +0.33%  [kernel.vmlinux]  [k] copy_msghdr_from_user
    12.36%  +21.89%  [kernel.vmlinux]  [k] copy_user_enhanced_fast_string
     8.65%   -0.63%  [kernel.vmlinux]  [k] udp_process_skb
     7.33%   -1.88%  [kernel.vmlinux]  [k] __skb_try_recv_datagram_batch
 **  7.12%   -6.66%  [kernel.vmlinux]  [k] udp_rmem_release **
 **  6.71%   -6.52%  [kernel.vmlinux]  [k] _raw_spin_lock_bh **
     6.35%   +1.36%  [kernel.vmlinux]  [k] __free_page_frag
     4.39%   +0.29%  [kernel.vmlinux]  [k] copy_msghdr_to_user_gen
     2.87%   -1.52%  [kernel.vmlinux]  [k] skb_release_data
     2.60%   +0.14%  [kernel.vmlinux]  [k] __put_user_4
     2.27%   -2.18%  [kernel.vmlinux]  [k] __sk_mem_reduce_allocated
     2.11%   +0.08%  [kernel.vmlinux]  [k] cmpxchg_double_slab.isra.68
     1.90%   +2.40%  [kernel.vmlinux]  [k] __slab_free
     1.73%   +0.20%  [kernel.vmlinux]  [k] __udp_recvmmsg
     1.62%   -1.62%  [kernel.vmlinux]  [k] intel_idle
     1.52%   +0.22%  [kernel.vmlinux]  [k] copy_to_iter
     1.20%   -0.03%  [kernel.vmlinux]  [k] import_iovec
     1.14%   +0.05%  [kernel.vmlinux]  [k] rw_copy_check_uvector
     0.80%   -0.04%  [kernel.vmlinux]  [k] recvmmsg_ctx_to_user
     0.75%   -0.69%  [kernel.vmlinux]  [k] __local_bh_enable_ip
     0.71%   +0.18%  [kernel.vmlinux]  [k] skb_copy_datagram_iter
     0.70%   -0.07%  [kernel.vmlinux]  [k] recvmmsg_ctx_from_user
     0.67%   +0.08%  [kernel.vmlinux]  [k] kmem_cache_free
     0.56%   +0.42%  [kernel.vmlinux]  [k] udp_process_msg
     0.48%   +0.05%  [kernel.vmlinux]  [k] skb_release_head_state
     0.46%           [kernel.vmlinux]  [k] lapic_next_deadline
     0.36%           [kernel.vmlinux]  [k] __switch_to
     0.34%   -0.03%  [kernel.vmlinux]  [k] consume_skb
     0.32%   -0.05%  [kernel.vmlinux]  [k] skb_consume_udp


The perf diff from CPU0, also show less lock congestion:

# Event 'cycles:ppp'
#
# Baseline    Delta  Shared Object     Symbol                                   
# ........  .......  ................  .........................................
#
    11.04%   -3.02%  [kernel.vmlinux]  [k] __udp_enqueue_schedule_skb
     9.98%   +2.16%  [mlx5_core]       [k] mlx5e_handle_rx_cqe
     7.23%   -1.85%  [kernel.vmlinux]  [k] udp_v4_early_demux
     3.90%   +0.73%  [kernel.vmlinux]  [k] build_skb
     3.85%   -1.77%  [kernel.vmlinux]  [k] udp_queue_rcv_skb
     3.83%   +0.02%  [kernel.vmlinux]  [k] sock_def_readable
 **  3.26%   -3.19%  [kernel.vmlinux]  [k] queued_spin_lock_slowpath **
     2.99%   +0.55%  [kernel.vmlinux]  [k] __build_skb
     2.97%   +0.11%  [kernel.vmlinux]  [k] __udp4_lib_rcv
 **  2.87%   -1.39%  [kernel.vmlinux]  [k] _raw_spin_lock **
     2.67%   +0.60%  [kernel.vmlinux]  [k] ip_rcv
     2.65%   +0.61%  [kernel.vmlinux]  [k] __netif_receive_skb_core
     2.64%   +0.79%  [ip_tables]       [k] ipt_do_table
     2.37%   +0.37%  [kernel.vmlinux]  [k] read_tsc
     2.26%   +0.52%  [mlx5_core]       [k] mlx5e_get_cqe
     2.11%   -1.15%  [kernel.vmlinux]  [k] __sk_mem_raise_allocated
     2.10%   +0.37%  [kernel.vmlinux]  [k] __rcu_read_unlock
     2.04%   +0.67%  [mlx5_core]       [k] mlx5e_alloc_rx_wqe
     1.86%   +0.40%  [kernel.vmlinux]  [k] inet_gro_receive
     1.57%   +0.11%  [kernel.vmlinux]  [k] kmem_cache_alloc
     1.53%   +0.28%  [kernel.vmlinux]  [k] _raw_read_lock
     1.53%   +0.25%  [kernel.vmlinux]  [k] dev_gro_receive
     1.38%   -0.18%  [kernel.vmlinux]  [k] udp_gro_receive
     1.19%   +0.37%  [kernel.vmlinux]  [k] __rcu_read_lock
     1.14%   +0.31%  [kernel.vmlinux]  [k] _raw_read_unlock
     1.14%   +0.12%  [kernel.vmlinux]  [k] ip_rcv_finish
     1.13%   +0.20%  [kernel.vmlinux]  [k] __udp4_lib_lookup
     1.05%   +0.16%  [kernel.vmlinux]  [k] ktime_get_with_offset
     0.94%   +0.38%  [kernel.vmlinux]  [k] ip_local_deliver_finish
     0.91%   +0.22%  [kernel.vmlinux]  [k] do_csum
     0.86%   -0.04%  [kernel.vmlinux]  [k] ipv4_pktinfo_prepare
     0.84%   +0.05%  [kernel.vmlinux]  [k] sk_filter_trim_cap
     0.84%   +0.20%  [kernel.vmlinux]  [k] ip_local_deliver
     0.84%   +0.19%  [kernel.vmlinux]  [k] udp4_gro_receive

-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  Author of http://www.iptv-analyzer.org
  LinkedIn: http://www.linkedin.com/in/brouer

^ permalink raw reply

* Re: [PATCH 1/1] net: macb: ensure ordering write to re-enable RX smoothly
From: Zumeng Chen @ 2016-11-28 13:47 UTC (permalink / raw)
  To: Nicolas Ferre; +Cc: davem, netdev, linux-kernel, Cyrille Pitchen
In-Reply-To: <599275f8-f40c-e550-cef6-f902e80d1738@atmel.com>

On 2016年11月28日 17:22, Nicolas Ferre wrote:
> Le 28/11/2016 à 08:57, Zumeng Chen a écrit :
>> When a hardware issue happened as described by inline comments, the register
>> write pattern looks like the following:
>>
>>    <write ~MACB_BIT(RE)>
>>    + wmb();
>>    <write MACB_BIT(RE)>
>>
>> There might be a memory barrier between these two write operations, so add wmb
>> to ensure an flip from 0 to 1 for NCR.
>>
>> Signed-off-by: Zumeng Chen <zumeng.chen@windriver.com>
>> ---
>>   drivers/net/ethernet/cadence/macb.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
>> index 533653b..2f9c5b2 100644
>> --- a/drivers/net/ethernet/cadence/macb.c
>> +++ b/drivers/net/ethernet/cadence/macb.c
>> @@ -1156,6 +1156,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
>>   		if (status & MACB_BIT(RXUBR)) {
>>   			ctrl = macb_readl(bp, NCR);
>>   			macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE));
>> +			wmb();
>>   			macb_writel(bp, NCR, ctrl | MACB_BIT(RE));
>>   
>>   			if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)
> It seems that there is exactly the same pattern in function
> at91ether_interrupt() can you fix both locations in your patch please?

Indeed, I'll send v2 soon, thanks Nicolas.

Although I only have the environment to re-produce the error report
as follows: "not whole frame pointed by descriptor" for macb_interrupt.

Cheers,
Zumeng

>
> Thanks, best regards,

^ permalink raw reply

* Re: [PATCH 1/1] net: macb: fix the RX queue reset in macb_rx()
From: Cyrille Pitchen @ 2016-11-28 13:43 UTC (permalink / raw)
  To: David Miller
  Cc: nicolas.ferre, netdev, soren.brinkmann, Andrei.Pistirica,
	linux-arm-kernel, linux-kernel
In-Reply-To: <20161127.202549.1887792653016840262.davem@davemloft.net>

Hi David,

Le 28/11/2016 à 02:25, David Miller a écrit :
> From: Cyrille Pitchen <cyrille.pitchen@atmel.com>
> Date: Fri, 25 Nov 2016 09:49:32 +0100
> 
>> On macb only (not gem), when a RX queue corruption was detected from
>> macb_rx(), the RX queue was reset: during this process the RX ring
>> buffer descriptor was initialized by macb_init_rx_ring() but we forgot
>> to also set bp->rx_tail to 0.
>>
>> Indeed, when processing the received frames, bp->rx_tail provides the
>> macb driver with the index in the RX ring buffer of the next buffer to
>> process. So when the whole ring buffer is reset we must also reset
>> bp->rx_tail so the driver is synchronized again with the hardware.
>>
>> Since macb_init_rx_ring() is called from many locations, currently from
>> macb_rx() and macb_init_rings(), we'd rather add the "bp->rx_tail = 0;"
>> line inside macb_init_rx_ring() than add the very same line after each
>> call of this function.
>>
>> Without this fix, the rx queue is not reset properly to recover from
>> queue corruption and connection drop may occur.
>>
>> Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
>> Fixes: 9ba723b081a2 ("net: macb: remove BUG_ON() and reset the queue to handle RX errors")
> 
> This doesn't apply cleanly to the 'net' tree, where
> RX_RING_SIZE is used instead of bp->rx_ring_size. It seems
> you generated this against net-next, however you didn't say
> that either in your Subject line nor the commit message.
> 
> As a bug fix this should be targetted at 'net'.
> 

Indeed, sorry. I've just sent a v2 based on net/master.

Best regards,

Cyrille

^ permalink raw reply

* Re: [PATCH net-next 8/9] liquidio CN23XX: VF interrupt
From: kbuild test robot @ 2016-11-28 13:42 UTC (permalink / raw)
  To: Raghu Vatsavayi
  Cc: kbuild-all, davem, netdev, Raghu Vatsavayi, Raghu Vatsavayi,
	Derek Chickles, Satanand Burla, Felix Manlunas
In-Reply-To: <1480308702-6261-9-git-send-email-rvatsavayi@caviumnetworks.com>

[-- Attachment #1: Type: text/plain, Size: 3338 bytes --]

Hi Raghu,

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Raghu-Vatsavayi/liquidio-VF-operations/20161128-133447
config: powerpc-allyesconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   drivers/built-in.o: In function `.liquidio_vf_remove':
>> lio_vf_main.c:(.text+0x1644f6c): undefined reference to `.cn23xx_vf_ask_pf_to_do_flr'
   drivers/built-in.o: In function `.liquidio_vf_probe':
   lio_vf_main.c:(.text+0x1645484): undefined reference to `.cn23xx_setup_octeon_vf_device'
>> lio_vf_main.c:(.text+0x16458b8): undefined reference to `.cn23xx_octeon_pfvf_handshake'
   drivers/built-in.o: In function `.brcmf_rx_frame':
   (.text+0x1ffa0fc): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `.memcmp' defined in .text section in arch/powerpc/lib/built-in.o
   drivers/built-in.o: In function `.brcmf_rx_event':
   (.text+0x1ffa238): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `.memcmp' defined in .text section in arch/powerpc/lib/built-in.o
   drivers/built-in.o: In function `.brcmf_netdev_start_xmit':
   core.c:(.text+0x1ffa5d0): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `.skb_realloc_headroom' defined in .text section in net/built-in.o
   core.c:(.text+0x1ffa63c): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `.skb_realloc_headroom' defined in .text section in net/built-in.o
   drivers/built-in.o: In function `.brcmf_net_setcarrier':
   (.text+0x1ffa9dc): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `._mcount' defined in .text section in arch/powerpc/kernel/entry_64.o
   drivers/built-in.o: In function `.brcmf_net_setcarrier':
   (.text+0x1ffaa34): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `.netif_carrier_on' defined in .text section in net/built-in.o
   drivers/built-in.o: In function `.brcmf_netdev_stop':
   core.c:(.text+0x1ffaa84): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `._mcount' defined in .text section in arch/powerpc/kernel/entry_64.o
   drivers/built-in.o: In function `.brcmf_add_if':
   (.text+0x1ffab48): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `._mcount' defined in .text section in arch/powerpc/kernel/entry_64.o
   drivers/built-in.o: In function `.brcmf_add_if':
   (.text+0x1ffac68): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `.kmem_cache_alloc_trace' defined in .text section in mm/built-in.o
   drivers/built-in.o: In function `.brcmf_remove_interface':
   (.text+0x1ffae2c): relocation truncated to fit: R_PPC64_REL24 (stub) against symbol `._mcount' defined in .text section in arch/powerpc/kernel/entry_64.o
   drivers/built-in.o: In function `.brcmf_bus_add_txhdrlen':
   (.text+0x1ffb04c): additional relocation overflows omitted from the output

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 51098 bytes --]

^ permalink raw reply

* Re: [PATCH net-next v3 0/4] Fix OdroidC2 Gigabit Tx link issue
From: Neil Armstrong @ 2016-11-28 13:42 UTC (permalink / raw)
  To: Jerome Brunet, netdev-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Florian Fainelli
  Cc: Carlo Caione, Kevin Hilman, Giuseppe Cavallaro, Alexandre TORGUE,
	Martin Blumenstingl, Andre Roth, Andrew Lunn,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <1480326409-25419-1-git-send-email-jbrunet-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>

On 11/28/2016 10:46 AM, Jerome Brunet wrote:
> This patchset fixes an issue with the OdroidC2 board (DWMAC + RTL8211F).
> The platform seems to enter LPI on the Rx path too often while performing
> relatively high TX transfer. This eventually break the link (both Tx and
> Rx), and require to bring the interface down and up again to get the Rx
> path working again.
> 
> The root cause of this issue is not fully understood yet but disabling EEE
> advertisement on the PHY prevent this feature to be negotiated.
> With this change, the link is stable and reliable, with the expected
> throughput performance.
> 
> The patchset adds options in the generic phy driver to disable EEE
> advertisement, through device tree. The way it is done is very similar
> to the handling of the max-speed property.
> 
> Changes since V2: [2]
>  - Rename "eee-advert-disable" to "eee-broken-modes" to make the intended
>    purpose of this option clear (flag broken configuration, not a
>    configuration option)
>  - Add DT bindings constants so the DT configuration is more user friendly
>  - Submit to net-next instead of net.
> 
> Changes since V1: [1]
>  - Disable the advertisement of EEE in the generic code instead of the
>    realtek driver.
> 
> [1] : http://lkml.kernel.org/r/1479220154-25851-1-git-send-email-jbrunet-rdvid1DuHRBWk0Htik3J/w@public.gmane.org
> [2] : http://lkml.kernel.org/r/1479742524-30222-1-git-send-email-jbrunet-rdvid1DuHRBWk0Htik3J/w@public.gmane.org
> 
> 
> Jerome Brunet (4):
>   net: phy: add an option to disable EEE advertisement
>   dt-bindings: net: add EEE capability constants
>   dt: bindings: add ethernet phy eee-broken-modes option documentation
>   ARM64: dts: meson: odroidc2: disable advertisement EEE for GbE.
> 
>  Documentation/devicetree/bindings/net/phy.txt      |  2 +
>  .../arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts | 16 +++++
>  drivers/net/phy/phy.c                              |  3 +
>  drivers/net/phy/phy_device.c                       | 80 +++++++++++++++++++---
>  include/dt-bindings/net/mdio.h                     | 19 +++++
>  include/linux/phy.h                                |  3 +
>  6 files changed, 114 insertions(+), 9 deletions(-)
>  create mode 100644 include/dt-bindings/net/mdio.h
> 

Tested using Nexbox A1 (S912) and Amlogic P230 (S905D) devices (DWMAC + RTL8211F).

Tested-by: Neil Armstrong <narmstrong-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* [PATCH net v2 1/1] net: macb: fix the RX queue reset in macb_rx()
From: Cyrille Pitchen @ 2016-11-28 13:40 UTC (permalink / raw)
  To: nicolas.ferre, davem, netdev, soren.brinkmann
  Cc: Andrei.Pistirica, linux-arm-kernel, linux-kernel, Cyrille Pitchen

On macb only (not gem), when a RX queue corruption was detected from
macb_rx(), the RX queue was reset: during this process the RX ring
buffer descriptor was initialized by macb_init_rx_ring() but we forgot
to also set bp->rx_tail to 0.

Indeed, when processing the received frames, bp->rx_tail provides the
macb driver with the index in the RX ring buffer of the next buffer to
process. So when the whole ring buffer is reset we must also reset
bp->rx_tail so the driver is synchronized again with the hardware.

Since macb_init_rx_ring() is called from many locations, currently from
macb_rx() and macb_init_rings(), we'd rather add the "bp->rx_tail = 0;"
line inside macb_init_rx_ring() than add the very same line after each
call of this function.

Without this fix, the rx queue is not reset properly to recover from
queue corruption and connection drop may occur.

Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
Fixes: 9ba723b081a2 ("net: macb: remove BUG_ON() and reset the queue to handle RX errors")
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---

ChangeLog:

v1 -> v2:
- rebase on net/master (v1 was based on net-next/master)
- add "Acked-by:" tag from Nicolas Ferre.

 drivers/net/ethernet/cadence/macb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 533653bd7aec..3ede59c9cae0 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -975,6 +975,7 @@ static inline void macb_init_rx_ring(struct macb *bp)
 		addr += bp->rx_buffer_size;
 	}
 	bp->rx_ring[RX_RING_SIZE - 1].addr |= MACB_BIT(RX_WRAP);
+	bp->rx_tail = 0;
 }
 
 static int macb_rx(struct macb *bp, int budget)
@@ -1616,8 +1617,6 @@ static void macb_init_rings(struct macb *bp)
 	bp->queues[0].tx_head = 0;
 	bp->queues[0].tx_tail = 0;
 	bp->queues[0].tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP);
-
-	bp->rx_tail = 0;
 }
 
 static void macb_reset_hw(struct macb *bp)
-- 
2.7.4

^ permalink raw reply related

* [PATCH] ethernet :mellanox :mlx5: Replace pci_pool_alloc by pci_pool_zalloc
From: Souptick Joarder @ 2016-11-28 13:37 UTC (permalink / raw)
  To: saeedm, matanb, leonro; +Cc: netdev, linux-rdma, sahu.rameshwar73

In alloc_cmd_box(), pci_pool_alloc() followed by memset will be
replaced by pci_pool_zalloc()

Signed-off-by: Souptick joarder <jrdr.linux@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 1e639f8..d96ebd4 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -1063,14 +1063,13 @@ static struct mlx5_cmd_mailbox *alloc_cmd_box(struct mlx5_core_dev *dev,
 	if (!mailbox)
 		return ERR_PTR(-ENOMEM);
 
-	mailbox->buf = pci_pool_alloc(dev->cmd.pool, flags,
+	mailbox->buf = pci_pool_zalloc(dev->cmd.pool, flags,
 				      &mailbox->dma);
 	if (!mailbox->buf) {
 		mlx5_core_dbg(dev, "failed allocation\n");
 		kfree(mailbox);
 		return ERR_PTR(-ENOMEM);
 	}
-	memset(mailbox->buf, 0, sizeof(struct mlx5_cmd_prot_block));
 	mailbox->next = NULL;
 
 	return mailbox;
-- 
1.9.1

^ permalink raw reply related

* [PATCH] ethernet :mellanox :mlx4: Replace pci_pool_alloc by pci_pool_zalloc
From: Souptick Joarder @ 2016-11-28 13:28 UTC (permalink / raw)
  To: yishaih-VPRAkNaXOzVWk0Htik3J/w
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	sahu.rameshwar73-Re5JQEeQqe8AvxtiuMwx3w

In mlx4_alloc_cmd_mailbox(), pci_pool_alloc() followed by memset will be
replaced by pci_pool_zalloc()

Signed-off-by: Souptick joarder <jrdr.linux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/net/ethernet/mellanox/mlx4/cmd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index e36bebc..ee3bd76 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c
@@ -2679,14 +2679,13 @@ struct mlx4_cmd_mailbox *mlx4_alloc_cmd_mailbox(struct mlx4_dev *dev)
 	if (!mailbox)
 		return ERR_PTR(-ENOMEM);
 
-	mailbox->buf = pci_pool_alloc(mlx4_priv(dev)->cmd.pool, GFP_KERNEL,
+	mailbox->buf = pci_pool_zalloc(mlx4_priv(dev)->cmd.pool, GFP_KERNEL,
 				      &mailbox->dma);
 	if (!mailbox->buf) {
 		kfree(mailbox);
 		return ERR_PTR(-ENOMEM);
 	}
 
-	memset(mailbox->buf, 0, MLX4_MAILBOX_SIZE);
 
 	return mailbox;
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related

* [PATCH ethtool 2/2] Ethtool: Implements PHY Loopback
From: Allan W. Nielsen @ 2016-11-28 13:25 UTC (permalink / raw)
  To: netdev
  Cc: linville, andrew, f.fainelli, raju.lakkaraju, allan.nielsen,
	Raju Lakkaraju
In-Reply-To: <1480339512-5882-1-git-send-email-allan.nielsen@microsemi.com>

From: Raju Lakkaraju <Raju.Lakkaraju@microsemi.com>

Add loopback in ethtool tunables to access PHY drivers.

Ethtool Help: ethtool -h for PHY tunables
    ethtool --set-phy-tunable DEVNAME      Set PHY tunable
                [ loopback off|near|far|extn ]
    ethtool --get-phy-tunable DEVNAME      Get PHY tunable
                [ loopback ]

Ethtool ex:
  ethtool --set-phy-tunable eth0 loopback near
  ethtool --set-phy-tunable eth0 loopback far
  ethtool --set-phy-tunable eth0 loopback extn
  ethtool --set-phy-tunable eth0 loopback off

  ethtool --get-phy-tunable eth0 loopback

Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microsemi.com>
Signed-off-by: Allan W. Nielsen <allan.nielsen@microsemi.com>
---
 ethtool.8.in |  49 +++++++++++++++++++++
 ethtool.c    | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 188 insertions(+)

diff --git a/ethtool.8.in b/ethtool.8.in
index 9631847..83e6b97 100644
--- a/ethtool.8.in
+++ b/ethtool.8.in
@@ -340,6 +340,15 @@ ethtool \- query or control network driver and hardware settings
 .B2 tx-lpi on off
 .BN tx-timer
 .BN advertise
+.HP
+.B ethtool \-\-set\-phy\-tunable
+.I devname
+.B4 loopback off near far extn
+.HP
+.B ethtool \-\-get\-phy\-tunable
+.I devname
+.RB [ loopback ]
+.HP
 .
 .\" Adjust lines (i.e. full justification) and hyphenate.
 .ad
@@ -947,6 +956,46 @@ Values are as for
 Sets the amount of time the device should stay in idle mode prior to asserting
 its Tx LPI (in microseconds). This has meaning only when Tx LPI is enabled.
 .RE
+.TP
+.B \-\-set\-phy\-tunable
+Sets the PHY tunable parameters.
+.RS 4
+.TP
+.A4 loopback off near far extn
+Specifies whether the type of loopback should be enabled
+.RE
+.TP
+.B \-\-get\-phy\-tunable
+Gets the PHY tunable parameters.
+.RS 4
+.TP
+.B loopback
+PHY supports 3 types of the Loopbacks. i.e near, far and external.
+
+Near-End Loopback:
+Transmitted data (TXD) is looped back in the PCS block onto the receive data
+signal (RXD). When Near-End loopback enable, no data is transmitted over
+the network. no data receive from the network.
+
+Far-End Loopback:
+This loopback is a special test mode to allow testing the PHY from link
+partner side. In this mode data that is received from the link partner pass
+through the PHY's receiver, looped back on the MII and transmitted back to
+the link partner.
+
+External Loopback:
+An RJ45 loopback cable can be used to route the transmit signals an the
+output of the trnsformer back to the receiver inputs and this loopback will
+work at either 10 or 100 or 1000 Mbps speed.
+RJ45 Loopback cable created by conncting pin 1 to pin 3 and connecting pin
+2 to pin 6.
+
+Gets the PHY Loopback status.
+.TS
+.PD
+.RE
+.TE
+.RE
 .SH BUGS
 Not supported (in part or whole) on all network drivers.
 .SH AUTHOR
diff --git a/ethtool.c b/ethtool.c
index 62f86ef..a4e6c0d 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4522,6 +4522,141 @@ static int do_seee(struct cmd_context *ctx)
 	return 0;
 }
 
+static int do_get_phy_tunable(struct cmd_context *ctx)
+{
+	int argc = ctx->argc;
+	char **argp = ctx->argp;
+	int err = 0, i;
+	u8 lpbk_changed = 0;
+	struct ethtool_tunable tunable;
+
+	if (argc < 1)
+		exit_bad_args();
+	for (i = 0; i < argc; i++) {
+		if (!strcmp(argp[i], "loopback")) {
+			lpbk_changed = 1;
+			i += 1;
+			if (i < argc)
+				exit_bad_args();
+		} else  {
+			exit_bad_args();
+		}
+	}
+
+	if (lpbk_changed) {
+		u8 type;
+
+		tunable.cmd = ETHTOOL_PHY_GTUNABLE;
+		tunable.id = ETHTOOL_PHY_LOOPBACK;
+		tunable.type_id = ETHTOOL_TUNABLE_U8;
+		tunable.len = 1;
+		tunable.data[0] = &type;
+		err = send_ioctl(ctx, &tunable);
+		if (err < 0) {
+			perror("Cannot Get PHY Loopback status");
+			return 87;
+		}
+		type = *((u8 *)&tunable.data[0]);
+		switch (type) {
+		case ETHTOOL_PHY_LOOPBACK_NEAR:
+			fprintf(stdout, "Near-end Loopback enabled\n");
+			break;
+		case ETHTOOL_PHY_LOOPBACK_FAR:
+			fprintf(stdout, "Far-end Loopback enabled\n");
+			break;
+		case ETHTOOL_PHY_LOOPBACK_EXTN:
+			fprintf(stdout, "External Loopback enabled\n");
+			break;
+		case ETHTOOL_PHY_LOOPBACK_DISABLE:
+			fprintf(stdout, "All PHY Loopbacks disabled\n");
+			break;
+		default:
+			fprintf(stdout, "Invalid Loopback type\n");
+			break;
+		}
+	}
+
+	return err;
+}
+
+static int parse_named_flag(struct cmd_context *ctx, const char *name,
+			    const struct flag_info *flags, size_t size,
+			    u8 *type)
+{
+	size_t idx;
+	int found = 0;
+
+	if (ctx->argc < 2)
+		return 0;
+
+	if (strcmp(*ctx->argp, name))
+		return 0;
+	ctx->argc -= 1;
+	ctx->argp += 1;
+
+	for (idx = 0; idx < size; idx++) {
+		if (!strcmp(flags[idx].name, *ctx->argp)) {
+			*type = flags[idx].value;
+			ctx->argc -= 1;
+			ctx->argp += 1;
+			found = 1;
+			break;
+		}
+	}
+
+	if (!found)
+		exit_bad_args();
+
+	return 1;
+}
+
+static const struct flag_info lpbk_flags[] = {
+	{ "off", ETHTOOL_PHY_LOOPBACK_DISABLE },
+	{ "near", ETHTOOL_PHY_LOOPBACK_NEAR },
+	{ "far",  ETHTOOL_PHY_LOOPBACK_FAR },
+	{ "extn",  ETHTOOL_PHY_LOOPBACK_EXTN },
+};
+
+static int do_set_phy_tunable(struct cmd_context *ctx)
+{
+	int err = 0;
+	u8 lpbk_changed = 0, lpbk_type = ETHTOOL_PHY_LOOPBACK_DISABLE;
+	struct ethtool_tunable tunable;
+
+	if (ctx->argc == 0)
+		exit_bad_args();
+
+	/* Parse arguments */
+	while (ctx->argc) {
+		if (parse_named_flag(ctx, "loopback", lpbk_flags,
+					    ARRAY_SIZE(lpbk_flags),
+					    &lpbk_type)) {
+			lpbk_changed = 1;
+		} else {
+			exit_bad_args();
+		}
+	}
+
+	/* Do it */
+	if (lpbk_changed) {
+		u8 type;
+
+		tunable.cmd = ETHTOOL_PHY_STUNABLE;
+		tunable.id = ETHTOOL_PHY_LOOPBACK;
+		tunable.type_id = ETHTOOL_TUNABLE_U8;
+		tunable.len = sizeof(type);
+		tunable.data[0] = &type;
+		*((u8 *)&tunable.data[0]) = lpbk_type;
+		err = send_ioctl(ctx, &tunable);
+		if (err < 0) {
+			perror("Cannot Set PHY Loopback");
+			err = 87;
+		}
+	}
+
+	return err;
+}
+
 #ifndef TEST_ETHTOOL
 int send_ioctl(struct cmd_context *ctx, void *cmd)
 {
@@ -4683,6 +4818,10 @@ static const struct option {
 	  "		[ advertise %x ]\n"
 	  "		[ tx-lpi on|off ]\n"
 	  "		[ tx-timer %d ]\n"},
+	{ "--set-phy-tunable", 1, do_set_phy_tunable, "Set PHY tunable",
+	  "		[ loopback off|near|far|extn ]\n"},
+	{ "--get-phy-tunable", 1, do_get_phy_tunable, "Get PHY tunable",
+	  "		[ loopback ]\n"},
 	{ "-h|--help", 0, show_usage, "Show this help" },
 	{ "--version", 0, do_version, "Show version number" },
 	{}
-- 
2.7.3

^ permalink raw reply related

* [PATCH ethtool 1/2] ethtool-copy.h:sync with net
From: Allan W. Nielsen @ 2016-11-28 13:25 UTC (permalink / raw)
  To: netdev
  Cc: linville, andrew, f.fainelli, raju.lakkaraju, allan.nielsen,
	Raju Lakkaraju
In-Reply-To: <1480339512-5882-1-git-send-email-allan.nielsen@microsemi.com>

From: Raju Lakkaraju <Raju.Lakkaraju@microsemi.com>

This covers kernel changes upto:

commit ef05e4c22648c141298f51aab00eb22066838b47
Author: Raju Lakkaraju <Raju.Lakkaraju@microsemi.com>
Date:   Wed Nov 23 15:20:28 2016 +0530

    ethtool: (uapi) Add ETHTOOL_PHY_LOOPBACK to PHYtunables

    3 types of PHY loopback are supported.
    i.e. Near-End Loopback, Far-End Loopback and External Loopback.

    Near-End Loopback:
    Transmitted data (TXD) is looped back in the PCS block onto the receive
    data signal (RXD). When Near-End loopback enable, no data is transmitted
    over the network. no data receive from the network.

    Far-End Loopback:
    This loopback is a special test mode to allow testing the PHY from link
    partner side. In this mode data that is received from the link partner pass
    through the PHY's receiver, looped back on the MII and transmitted back to
    the link partner.
    Data present on the transmit data pins of the MAC interface is ignored when
    using this test.

    External Loopback:
    An RJ45 loopback cable can be used to route the transmit signals an the
    output of the trnsformer back to the receiver inputs and this loopback will
    work at either 10 or 100 or 1000 Mbps speed.
    RJ45 Loopback cable created by conncting pin 1 to pin 3 and connecting pin
    2 to pin 6.

Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microsemi.com>
Signed-off-by: Allan W. Nielsen <allan.nielsen@microsemi.com>
---
 ethtool-copy.h | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/ethtool-copy.h b/ethtool-copy.h
index 70748f5..1ebdc72 100644
--- a/ethtool-copy.h
+++ b/ethtool-copy.h
@@ -247,6 +247,24 @@ struct ethtool_tunable {
 	void	*data[0];
 };
 
+enum phy_tunable_id {
+	ETHTOOL_PHY_ID_UNSPEC,
+	ETHTOOL_PHY_DOWNSHIFT,
+	ETHTOOL_PHY_LOOPBACK,
+	/*
+	 * Add your fresh new phy tunable attribute above and remember to update
+	 * phy_tunable_strings[] in net/core/ethtool.c
+	 */
+	__ETHTOOL_PHY_TUNABLE_COUNT,
+};
+
+enum phy_loopback_type {
+	ETHTOOL_PHY_LOOPBACK_DISABLE,
+	ETHTOOL_PHY_LOOPBACK_NEAR,
+	ETHTOOL_PHY_LOOPBACK_FAR,
+	ETHTOOL_PHY_LOOPBACK_EXTN
+};
+
 /**
  * struct ethtool_regs - hardware register dump
  * @cmd: Command number = %ETHTOOL_GREGS
@@ -547,6 +565,7 @@ struct ethtool_pauseparam {
  * @ETH_SS_FEATURES: Device feature names
  * @ETH_SS_RSS_HASH_FUNCS: RSS hush function names
  * @ETH_SS_PHY_STATS: Statistic names, for use with %ETHTOOL_GPHYSTATS
+ * @ETH_SS_PHY_TUNABLES: PHY tunable names
  */
 enum ethtool_stringset {
 	ETH_SS_TEST		= 0,
@@ -557,6 +576,7 @@ enum ethtool_stringset {
 	ETH_SS_RSS_HASH_FUNCS,
 	ETH_SS_TUNABLES,
 	ETH_SS_PHY_STATS,
+	ETH_SS_PHY_TUNABLES,
 };
 
 /**
@@ -1312,7 +1332,8 @@ struct ethtool_per_queue_op {
 
 #define ETHTOOL_GLINKSETTINGS	0x0000004c /* Get ethtool_link_settings */
 #define ETHTOOL_SLINKSETTINGS	0x0000004d /* Set ethtool_link_settings */
-
+#define ETHTOOL_PHY_GTUNABLE	0x0000004e /* Get PHY tunable configuration */
+#define ETHTOOL_PHY_STUNABLE	0x0000004f /* Set PHY tunable configuration */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET
-- 
2.7.3

^ permalink raw reply related

* [PATCH ethtool 0/2] Adding PHY Loopback tunable
From: Allan W. Nielsen @ 2016-11-28 13:25 UTC (permalink / raw)
  To: netdev; +Cc: linville, andrew, f.fainelli, raju.lakkaraju, allan.nielsen

Hi All,

This patch implements for support for PHY Loopback using PHY-Tunables.

The patch will add the following options:

    ethtool --set-phy-tunable DEVNAME      Set PHY tunable
                [ loopback off|near|far|extn ]
    ethtool --get-phy-tunable DEVNAME      Get PHY tunable
                [ loopback ]

Please review.

Best regards
Allan and Raju

Raju Lakkaraju (2):
  ethtool-copy.h:sync with net
  Ethtool: Implements PHY Loopback

 ethtool-copy.h |  23 +++++++++-
 ethtool.8.in   |  49 ++++++++++++++++++++
 ethtool.c      | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 210 insertions(+), 1 deletion(-)

-- 
2.7.3

^ permalink raw reply

* [PATCH net-next 1/1] driver: ipvlan: Add the sanity check for ipvlan mode
From: fgao @ 2016-11-28 13:23 UTC (permalink / raw)
  To: davem, maheshb, edumazet, netdev, gfree.wind; +Cc: Gao Feng

From: Gao Feng <fgao@ikuai8.com>

The ipvlan mode variable "nval" is from userspace, so the ipvlan codes
should check if the mode variable "nval" is valid.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 drivers/net/ipvlan/ipvlan_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c
index ab90b22..537b5a9 100644
--- a/drivers/net/ipvlan/ipvlan_main.c
+++ b/drivers/net/ipvlan/ipvlan_main.c
@@ -65,6 +65,9 @@ static int ipvlan_set_port_mode(struct ipvl_port *port, u16 nval)
 	struct net_device *mdev = port->dev;
 	int err = 0;
 
+	if (nval >= IPVLAN_MODE_MAX)
+		return -EINVAL;
+
 	ASSERT_RTNL();
 	if (port->mode != nval) {
 		if (nval == IPVLAN_MODE_L3S) {
-- 
1.9.1

^ permalink raw reply related


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