Re: [PATCH 10/13] timer: Remove expires and data arguments from DEFINE_TIMER

2017-10-04 Thread Greg Kroah-Hartman
On Wed, Oct 04, 2017 at 04:27:04PM -0700, Kees Cook wrote:
> Drop the arguments from the macro and adjust all callers with the
> following script:
> 
>   perl -pi -e 's/DEFINE_TIMER\((.*), 0, 0\);/DEFINE_TIMER($1);/g;' \
> $(git grep DEFINE_TIMER | cut -d: -f1 | sort -u | grep -v timer.h)
> 
> Signed-off-by: Kees Cook 
> Acked-by: Geert Uytterhoeven  # for m68k parts
> ---
>  arch/arm/mach-ixp4xx/dsmg600-setup.c  | 2 +-
>  arch/arm/mach-ixp4xx/nas100d-setup.c  | 2 +-
>  arch/m68k/amiga/amisound.c| 2 +-
>  arch/m68k/mac/macboing.c  | 2 +-
>  arch/mips/mti-malta/malta-display.c   | 2 +-
>  arch/parisc/kernel/pdc_cons.c | 2 +-
>  arch/s390/mm/cmm.c| 2 +-
>  drivers/atm/idt77105.c| 4 ++--
>  drivers/atm/iphase.c  | 2 +-
>  drivers/block/ataflop.c   | 8 
>  drivers/char/dtlk.c   | 2 +-
>  drivers/char/hangcheck-timer.c| 2 +-
>  drivers/char/nwbutton.c   | 2 +-
>  drivers/char/rtc.c| 2 +-
>  drivers/input/touchscreen/s3c2410_ts.c| 2 +-
>  drivers/net/cris/eth_v10.c| 6 +++---
>  drivers/net/hamradio/yam.c| 2 +-
>  drivers/net/wireless/atmel/at76c50x-usb.c | 2 +-
>  drivers/staging/speakup/main.c| 2 +-
>  drivers/staging/speakup/synth.c   | 2 +-
>  drivers/tty/cyclades.c| 2 +-
>  drivers/tty/isicom.c  | 2 +-
>  drivers/tty/moxa.c| 2 +-
>  drivers/tty/rocket.c  | 2 +-
>  drivers/tty/vt/keyboard.c | 2 +-
>  drivers/tty/vt/vt.c   | 2 +-
>  drivers/watchdog/alim7101_wdt.c   | 2 +-
>  drivers/watchdog/machzwd.c| 2 +-
>  drivers/watchdog/mixcomwd.c   | 2 +-
>  drivers/watchdog/sbc60xxwdt.c | 2 +-
>  drivers/watchdog/sc520_wdt.c  | 2 +-
>  drivers/watchdog/via_wdt.c| 2 +-
>  drivers/watchdog/w83877f_wdt.c| 2 +-
>  drivers/xen/grant-table.c | 2 +-
>  fs/pstore/platform.c  | 2 +-
>  include/linux/timer.h | 4 ++--
>  kernel/irq/spurious.c | 2 +-
>  lib/random32.c| 2 +-
>  net/atm/mpc.c | 2 +-
>  net/decnet/dn_route.c | 2 +-
>  net/ipv6/ip6_flowlabel.c  | 2 +-
>  net/netrom/nr_loopback.c  | 2 +-
>  security/keys/gc.c| 2 +-
>  sound/oss/midibuf.c   | 2 +-
>  sound/oss/soundcard.c | 2 +-
>  sound/oss/sys_timer.c | 2 +-
>  sound/oss/uart6850.c  | 2 +-
>  47 files changed, 54 insertions(+), 54 deletions(-)

Acked-by: Greg Kroah-Hartman 


Re: [PATCH] net: ethernet: stmmac: Convert timers to use

2017-10-04 Thread Giuseppe CAVALLARO

On 10/5/2017 2:50 AM, Kees Cook wrote:

In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 

Acked-by:  Giuseppe Cavallaro 

---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
  drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c | 22 ++
  1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c 
b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c
index 6a9c954492f2..8b50afcdb52d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c
@@ -118,10 +118,9 @@ int tse_pcs_init(void __iomem *base, struct tse_pcs *pcs)
return ret;
  }
  
-static void pcs_link_timer_callback(unsigned long data)

+static void pcs_link_timer_callback(struct tse_pcs *pcs)
  {
u16 val = 0;
-   struct tse_pcs *pcs = (struct tse_pcs *)data;
void __iomem *tse_pcs_base = pcs->tse_pcs_base;
void __iomem *sgmii_adapter_base = pcs->sgmii_adapter_base;
  
@@ -138,12 +137,11 @@ static void pcs_link_timer_callback(unsigned long data)

}
  }
  
-static void auto_nego_timer_callback(unsigned long data)

+static void auto_nego_timer_callback(struct tse_pcs *pcs)
  {
u16 val = 0;
u16 speed = 0;
u16 duplex = 0;
-   struct tse_pcs *pcs = (struct tse_pcs *)data;
void __iomem *tse_pcs_base = pcs->tse_pcs_base;
void __iomem *sgmii_adapter_base = pcs->sgmii_adapter_base;
  
@@ -201,14 +199,14 @@ static void auto_nego_timer_callback(unsigned long data)

}
  }
  
-static void aneg_link_timer_callback(unsigned long data)

+static void aneg_link_timer_callback(struct timer_list *t)
  {
-   struct tse_pcs *pcs = (struct tse_pcs *)data;
+   struct tse_pcs *pcs = from_timer(pcs, t, aneg_link_timer);
  
  	if (pcs->autoneg == AUTONEG_ENABLE)

-   auto_nego_timer_callback(data);
+   auto_nego_timer_callback(pcs);
else if (pcs->autoneg == AUTONEG_DISABLE)
-   pcs_link_timer_callback(data);
+   pcs_link_timer_callback(pcs);
  }
  
  void tse_pcs_fix_mac_speed(struct tse_pcs *pcs, struct phy_device *phy_dev,

@@ -237,8 +235,8 @@ void tse_pcs_fix_mac_speed(struct tse_pcs *pcs, struct 
phy_device *phy_dev,
  
  		tse_pcs_reset(tse_pcs_base, pcs);
  
-		setup_timer(>aneg_link_timer,

-   aneg_link_timer_callback, (unsigned long)pcs);
+   timer_setup(>aneg_link_timer, aneg_link_timer_callback,
+   0);
mod_timer(>aneg_link_timer, jiffies +
  msecs_to_jiffies(AUTONEGO_LINK_TIMER));
} else if (phy_dev->autoneg == AUTONEG_DISABLE) {
@@ -270,8 +268,8 @@ void tse_pcs_fix_mac_speed(struct tse_pcs *pcs, struct 
phy_device *phy_dev,
  
  		tse_pcs_reset(tse_pcs_base, pcs);
  
-		setup_timer(>aneg_link_timer,

-   aneg_link_timer_callback, (unsigned long)pcs);
+   timer_setup(>aneg_link_timer, aneg_link_timer_callback,
+   0);
mod_timer(>aneg_link_timer, jiffies +
  msecs_to_jiffies(AUTONEGO_LINK_TIMER));
}





Re: Linux 4.12+ memory leak on router with i40e NICs

2017-10-04 Thread Anders K. Pedersen | Cohaesio
On ons, 2017-10-04 at 08:32 -0700, Alexander Duyck wrote:
> On Wed, Oct 4, 2017 at 5:56 AM, Anders K. Pedersen | Cohaesio
>  wrote:
> > Hello,
> > 
> > After updating one of our Linux based routers to kernel 4.13 it
> > began
> > leaking memory quite fast (about 1 GB every half hour). To narrow
> > we
> > tried various kernel versions and found that 4.11.12 is okay, while
> > 4.12 also leaks, so we did a bisection between 4.11 and 4.12.
> > 
> > The first bisection ended at
> > "[6964e53f55837b0c49ed60d36656d2e0ee4fc27b] i40e: fix handling of
> > HW
> > ATR eviction", which fixes some flag handling that was broken by
> > 47994c119a36 "i40e: remove hw_disabled_flags in favor of using
> > separate
> > flag bits", so I did a second bisection, where I added 6964e53f5583
> > "i40e: fix handling of HW ATR eviction" to the steps that had
> > 47994c119a36 "i40e: remove hw_disabled_flags in favor of using
> > separate
> > flag bits" in them.
> > 
> > The second bisection ended at
> > "[0e626ff7ccbfc43c6cc4aeea611c40b899682382] i40e: Fix support for
> > flow
> > director programming status", where I don't see any obvious
> > problems,
> > so I'm hoping for some assistance.
> > 
> > The router is a PowerEdge R730 server (Haswell based) with three
> > Intel
> > NICs (all using the i40e driver):
> > 
> > X710 quad port 10 GbE SFP+: eth0 eth1 eth2 eth3
> > X710 quad port 10 GbE SFP+: eth4 eth5 eth6 eth7
> > XL710 dual port 40 GbE QSFP+: eth8 eth9
> > 
> > The NICs are aggregated with LACP with the team driver:
> > 
> > team0: eth9 (40 GbE selected primary), and eth3, eth7 (10 GbE non-
> > selected backups)
> > team1: eth0, eth1, eth4, eth5 (all 10 GbE selected)
> > 
> > team0 is used for internal networks and has one untagged and four
> > tagged VLAN interfaces, while team1 has an external uplink
> > connection
> > without any VLANs.
> > 
> > The router runs an eBGP session on team1 to one of our uplinks, and
> > iBGP via team0 to our other border routers. It also runs OSPF on
> > the
> > internal VLANs on team0. One thing I've noticed is that when OSPF
> > is
> > not announcing a default gateway to the internal networks, so there
> > is
> > almost no traffic coming in on team0 and out on team1, but still
> > plenty
> > of traffic coming in on team1 and out via team0, there's no memory
> > leak
> > (or at least it is so small that we haven't detected it). But as
> > soon
> > as we configure OSPF to announce a default gateway to the internal
> > VLANs, so we get traffic from team0 to team1 the leaking begins.
> > Stopping the OSPF default gateway announcement again also stops the
> > leaking, but does not release already leaked memory.
> > 
> > So this leads to me suspect that the leaking is related to RX on
> > team0
> > (where XL710 eth9 is normally the only active interface) or TX on
> > team1
> > (X710 eth0, eth1, eth4, eth5). The first bad commit is related to
> > RX
> > cleaning, which suggests RX on team0. Since we're only seeing the
> > leak
> > for our outbound traffic, I suspect either a difference between the
> > X710 vs. XL710 NICs, or that the inbound traffic is for relatively
> > few
> > destination addresses (only our own systems) while the outbound
> > traffic
> > is for many different addresses on the internet. But I'm just
> > guessing
> > here.
> > 
> > I've tried kmemleak, but it only found a few kB of suspected memory
> > leaks (several of which disappeared again after a while).
> > 
> > Below I've included more details - git bisect logs, ethtool -i,
> > dmesg,
> > Kernel .config, and various memory related /proc files. Any help or
> > suggestions would be much appreciated, and please let me know if
> > more
> > information is needed or there's something I should try.
> > 
> > Regards,
> > Anders K. Pedersen
> > 
> 
> Hi Anders,
> 
> I think I see the problem and should have a patch submitted shortly
> to
> address it. From what I can tell it looks like the issue is that we
> weren't properly recycling the pages associated with descriptors that
> contained an Rx programming status. For now the workaround would be
> to
> try disabling ATR via the "ethtool --set-priv-flags" command. I
> should
> have a patch out in the next hour or so that you can try testing to
> verify if it addresses the issue.
> 
> Thanks.
> 
> - Alex

Thanks Alex,

I will test the patch in our next service window on Tuesday morning.

Regards,
Anders

[GIT] Networking

2017-10-04 Thread David Miller

1) Check iwlwifi 9000 reorder buffer out-of-space condition properly,
   from Sara Sharon.

2) Fix RCU splat in qualcomm rmnet driver, from Subash Abhinov
   Kasiviswanathan.

3) Fix session and tunnel release races in l2tp, from Guillaume Nault
   and Sabrina Dubroca.

4) Fix endian bug in sctp_diag_dump(), from Dan Carpenter.

5) Several mlx5 driver fixes from the Mellanox folks (max flow
   counters cap check, invalid memory access in IPoIB support, etc.)

6) tun_get_user() should bail if skb->len is zero, from Alexander
   Potapenko.

7) Fix RCU lookups in inetpeer, from Eric Dumazet.

8) Fix locking in packet_do_bund().

9) Handle cb->start() error properly in netlink dump code, from
   Jason A. Donenfeld.

10) Handle multicast properly in UDP socket early demux code.
From Paolo Abeni.

11) Several erspan bug fixes in ip_gre, from Xin Long.

12) Fix use-after-free in socket filter code, in order to handle the
face that listener lock is no longer taken during the three-way
TCP handshake.  From Eric Dumazet.

13) Fix infoleak in RTM_GETSTATS, from Nikolay Aleksandrov.

14) Fix tail call generation in x86-64 BPF JIT, from Alexei
Starovoitov.

Please pull, thanks a lot!

The following changes since commit cd4175b11685b11c40e31a03e05084cc212b0649:

  Merge branch 'parisc-4.14-2' of 
git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux (2017-09-23 
06:14:06 -1000)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 

for you to fetch changes up to e769fcec6bc4bdd1b0e2cf817680148f9c40b1c4:

  net: 8021q: skip packets if the vlan is down (2017-10-04 18:16:48 -0700)


Aleksander Morgado (1):
  rndis_host: support Novatel Verizon USB730L

Alexander Potapenko (1):
  tun: bail out from tun_get_user() if the skb is empty

Alexei Starovoitov (1):
  bpf: fix bpf_tail_call() x64 JIT

Alexey Kodanev (1):
  vti: fix use after free in vti_tunnel_xmit/vti6_tnl_xmit

Andrew Lunn (1):
  net: dsa: mv88e6xxx: Allow dsa and cpu ports in multiple vlans

Antoine Tenart (1):
  net: mvpp2: do not select the internal source clock

Arend Van Spriel (2):
  brcmfmac: add length check in brcmf_cfg80211_escan_handler()
  brcmfmac: setup passive scan if requested by user-space

Arnd Bergmann (3):
  ath10k: mark PM functions as __maybe_unused
  rocker: fix rocker_tlv_put_* functions for KASAN
  netlink: fix nla_put_{u8,u16,u32} for KASAN

Avraham Stern (2):
  iwlwifi: mvm: send all non-bufferable frames on the probe queue
  iwlwifi: mvm: wake the correct mac80211 queue

Christoph Paasch (1):
  net: Set sk_prot_creator when cloning sockets to the right proto

Christophe JAILLET (2):
  cnic: Fix an error handling path in 'cnic_alloc_bnx2x_resc()'
  net: hns3: Fix an error handling path in 'hclge_rss_init_hw()'

Dan Carpenter (1):
  sctp: Fix a big endian bug in sctp_diag_dump()

David S. Miller (8):
  Merge branch 'l2tp-fix-some-races-in-session-deletion'
  Merge branch 'aquantia-fixes'
  Merge tag 'wireless-drivers-for-davem-2017-09-25' of 
git://git.kernel.org/.../kvalo/wireless-drivers
  Merge branch 'mvpp2-various-fixes'
  Merge tag 'mlx5-fixes-2017-09-28' of git://git.kernel.org/.../saeed/linux
  Merge branch 'udp-fix-early-demux-for-mcast-packets'
  Merge branch 'erspan-fixes'
  Merge branch 'mlxsw-gre-fixes'

David Spinadel (1):
  iwlwifi: mvm: Flush non STA TX queues

David Wu (1):
  net: stmmac: dwmac-rk: Add RK3128 GMAC support

Ed Blake (2):
  net: stmmac: dwc-qos: Add suspend / resume support
  net: stmmac: dwmac4: Re-enable MAC Rx before powering down

Eric Dumazet (2):
  inetpeer: fix RCU lookup() again
  socket, bpf: fix possible use after free

Florian Fainelli (1):
  net: dsa: Fix network device registration order

Gal Pressman (3):
  net/mlx5e: Print netdev features correctly in error message
  net/mlx5e: Don't add/remove 802.1ad rules when changing 802.1Q VLAN filter
  net/mlx5e: Fix calculated checksum offloads counters

Grant Grundler (1):
  r8152: add Linksys USB3GIGV1 id

Gregory CLEMENT (1):
  net: mvpp2: Fix clock resource by adding an optional bus clock

Guillaume Nault (4):
  l2tp: ensure sessions are freed after their PPPOL2TP socket
  l2tp: fix race between l2tp_session_delete() and l2tp_tunnel_closeall()
  ppp: fix __percpu annotation
  l2tp: fix l2tp_eth module loading

Igor Russkikh (3):
  aquantia: Setup max_mtu in ndev to enable jumbo frames
  aquantia: Fix Tx queue hangups
  aquantia: Fix transient invalid link down/up indications

Inbar Karmy (1):
  net/mlx5: Fix FPGA capability location

Jason A. Donenfeld (1):
  netlink: do not proceed if dump's start() errs

Kalle Valo (2):
  Merge tag 'iwlwifi-for-kalle-2017-09-15' of 
git://git.kernel.org/.../iwlwifi/iwlwifi-fixes
  

Re: [PATCH net-next v4 0/3] tools: add bpftool

2017-10-04 Thread David Miller
From: Jakub Kicinski 
Date: Wed,  4 Oct 2017 20:10:02 -0700

> Hi!
> 
> This set adds bpftool to the tools/ directory.  The first 
> patch renames tools/net to tools/bpf, the second one adds 
> the new code, while the third adds simple documentation.
> 
> v4:
>  - rename docs *.txt -> *.rst (Jesper).
> v3:
>  - address Alexei's comments about output and docs.
> v2:
>  - report names, map ids, load time, uid;
>  - add docs/man pages;
>  - general cleanups & fixes.

Series applied, although there was some trailing whitespace I had to fix
up in patch #3.


Re: [PATCH v2 net-next 0/7] net: Plumb extack error reporting to enslavements

2017-10-04 Thread David Miller
From: David Ahern 
Date: Wed,  4 Oct 2017 17:48:44 -0700

> Another round of extending extack error reporting, this time for
> enslavements through ndo_add_slave and notifiers.
> 
> v2
> - changed how the messages are added to bonding driver per Jiri's request
> - fixed spectrum message for LAG overflow per Ido's comment

Series applied, thanks David.


Re: [PATCH V2] Fix a sleep-in-atomic bug in shash_setkey_unaligned

2017-10-04 Thread David Miller
From: Herbert Xu 
Date: Thu, 5 Oct 2017 11:40:54 +0800

> On Tue, Oct 03, 2017 at 07:45:06PM -0300, Marcelo Ricardo Leitner wrote:
>>
>> > Usually if you're invoking setkey from a non-sleeping code-path
>> > you're probably doing something wrong.
>> 
>> Usually but not always. There are 3 calls to that function on SCTP
>> code:
>> - pack a cookie, which is sent on an INIT_ACK packet to the client
>> - unpack the cookie above, after it is sent back by the client on a
>>   COOKIE_ECHO packet
>> - send a chunk authenticated by a hash
> 
> I'm not talking about the code-path in question.  I'm talking
> about the function which generates the secret key in the first
> place.  AFAICS that's only called in GFP_KERNEL context.  What
> am I missing?

The setkey happens in functions like sctp_pack_cookie() and
sctp_unpack_cookie(), which seems to run from software interrupts.


3% Interest Rate

2017-10-04 Thread Vancity Loan Firm
We can help you with a genuine loan to meet your needs.
Do you need a personal or business loan without stress and quick approval?
Do you need an urgent loan today? No Credit Checks

* LOAN APPROVAL IN 60MINS !!
* GUARANTEED SAME DAY TRANSFER !!
* 100% APPROVAL RATE !!
*LOW INTEREST RATE !!

Contact US for more information about loan offer and we will solve your
financial problem.


[RESEND PATCH 4/7] net: qrtr: Pass source and destination to enqueue functions

2017-10-04 Thread Bjorn Andersson
Defer writing the message header to the skb until its time to enqueue
the packet. As the receive path is reworked to decode the message header
as it's received from the transport and only pass around the payload in
the skb this change means that we do not have to fill out the full
message header just to decode it immediately in qrtr_local_enqueue().

In the future this change also makes it possible to prepend message
headers based on the version of each link.

Signed-off-by: Bjorn Andersson 
---
 net/qrtr/qrtr.c | 120 
 1 file changed, 69 insertions(+), 51 deletions(-)

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index d85ca7170b8f..82dc83789310 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -97,8 +97,12 @@ struct qrtr_node {
struct list_head item;
 };
 
-static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb);
-static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb);
+static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+ int type, struct sockaddr_qrtr *from,
+ struct sockaddr_qrtr *to);
+static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+ int type, struct sockaddr_qrtr *from,
+ struct sockaddr_qrtr *to);
 
 /* Release node resources and free the node.
  *
@@ -136,10 +140,27 @@ static void qrtr_node_release(struct qrtr_node *node)
 }
 
 /* Pass an outgoing packet socket buffer to the endpoint driver. */
-static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb)
+static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
+int type, struct sockaddr_qrtr *from,
+struct sockaddr_qrtr *to)
 {
+   struct qrtr_hdr *hdr;
+   size_t len = skb->len;
int rc = -ENODEV;
 
+   hdr = skb_push(skb, QRTR_HDR_SIZE);
+   hdr->version = cpu_to_le32(QRTR_PROTO_VER);
+   hdr->type = cpu_to_le32(type);
+   hdr->src_node_id = cpu_to_le32(from->sq_node);
+   hdr->src_port_id = cpu_to_le32(from->sq_port);
+   hdr->dst_node_id = cpu_to_le32(to->sq_node);
+   hdr->dst_port_id = cpu_to_le32(to->sq_port);
+
+   hdr->size = cpu_to_le32(len);
+   hdr->confirm_rx = 0;
+
+   skb_put_padto(skb, ALIGN(len, 4));
+
mutex_lock(>ep_lock);
if (node->ep)
rc = node->ep->xmit(node->ep, skb);
@@ -237,23 +258,13 @@ EXPORT_SYMBOL_GPL(qrtr_endpoint_post);
 static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len,
  u32 src_node, u32 dst_node)
 {
-   struct qrtr_hdr *hdr;
struct sk_buff *skb;
 
skb = alloc_skb(QRTR_HDR_SIZE + pkt_len, GFP_KERNEL);
if (!skb)
return NULL;
-   skb_reset_transport_header(skb);
 
-   hdr = skb_put(skb, QRTR_HDR_SIZE);
-   hdr->version = cpu_to_le32(QRTR_PROTO_VER);
-   hdr->type = cpu_to_le32(type);
-   hdr->src_node_id = cpu_to_le32(src_node);
-   hdr->src_port_id = cpu_to_le32(QRTR_PORT_CTRL);
-   hdr->confirm_rx = cpu_to_le32(0);
-   hdr->size = cpu_to_le32(pkt_len);
-   hdr->dst_node_id = cpu_to_le32(dst_node);
-   hdr->dst_port_id = cpu_to_le32(QRTR_PORT_CTRL);
+   skb_reserve(skb, QRTR_HDR_SIZE);
 
return skb;
 }
@@ -326,6 +337,8 @@ static void qrtr_port_put(struct qrtr_sock *ipc);
 static void qrtr_node_rx_work(struct work_struct *work)
 {
struct qrtr_node *node = container_of(work, struct qrtr_node, work);
+   struct sockaddr_qrtr dst;
+   struct sockaddr_qrtr src;
struct sk_buff *skb;
 
while ((skb = skb_dequeue(>rx_queue)) != NULL) {
@@ -341,6 +354,11 @@ static void qrtr_node_rx_work(struct work_struct *work)
dst_port = le32_to_cpu(phdr->dst_port_id);
confirm = !!phdr->confirm_rx;
 
+   src.sq_node = src_node;
+   src.sq_port = le32_to_cpu(phdr->src_port_id);
+   dst.sq_node = dst_node;
+   dst.sq_port = dst_port;
+
qrtr_node_assign(node, src_node);
 
ipc = qrtr_port_lookup(dst_port);
@@ -357,7 +375,9 @@ static void qrtr_node_rx_work(struct work_struct *work)
skb = qrtr_alloc_resume_tx(dst_node, node->nid, 
dst_port);
if (!skb)
break;
-   if (qrtr_node_enqueue(node, skb))
+
+   if (qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX,
+ , ))
break;
}
}
@@ -407,6 +427,8 @@ EXPORT_SYMBOL_GPL(qrtr_endpoint_register);
 void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
 {
struct qrtr_node *node = ep->node;
+   struct sockaddr_qrtr 

[RESEND PATCH 0/7] net: qrtr: Fixes and support receiving version 2 packets

2017-10-04 Thread Bjorn Andersson
On the latest Qualcomm platforms remote processors are sending packets with
version 2 of the message header. This series starts off with some fixes and
then refactors the qrtr code to support receiving messages of both version 1
and version 2.

As all remotes are backwards compatible transmitted packets continues to be
send as version 1, but some groundwork has been done to make this a per-link
property.

Bjorn Andersson (7):
  net: qrtr: Invoke sk_error_report() after setting sk_err
  net: qrtr: Move constants to header file
  net: qrtr: Add control packet definition to uapi
  net: qrtr: Pass source and destination to enqueue functions
  net: qrtr: Clean up control packet handling
  net: qrtr: Use sk_buff->cb in receive path
  net: qrtr: Support decoding incoming v2 packets

 include/uapi/linux/qrtr.h |  35 +
 net/qrtr/qrtr.c   | 377 +-
 2 files changed, 241 insertions(+), 171 deletions(-)

-- 
2.12.0



[RESEND PATCH 1/7] net: qrtr: Invoke sk_error_report() after setting sk_err

2017-10-04 Thread Bjorn Andersson
Rather than manually waking up any context sleeping on the sock to
signal an error we should call sk_error_report(). This has the added
benefit that in-kernel consumers can override this notification with
its own callback.

Signed-off-by: Bjorn Andersson 
---
 net/qrtr/qrtr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index c2f5c13550c0..7e4b49a8349e 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -541,7 +541,7 @@ static void qrtr_reset_ports(void)
 
sock_hold(>sk);
ipc->sk.sk_err = ENETRESET;
-   wake_up_interruptible(sk_sleep(>sk));
+   ipc->sk.sk_error_report(>sk);
sock_put(>sk);
}
mutex_unlock(_port_lock);
-- 
2.12.0



[RESEND PATCH 2/7] net: qrtr: Move constants to header file

2017-10-04 Thread Bjorn Andersson
The constants are used by both the name server and clients, so clarify
their value and move them to the uapi header.

Signed-off-by: Bjorn Andersson 
---
 include/uapi/linux/qrtr.h | 3 +++
 net/qrtr/qrtr.c   | 2 --
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h
index 9d76c566f66e..63e8803e4d90 100644
--- a/include/uapi/linux/qrtr.h
+++ b/include/uapi/linux/qrtr.h
@@ -4,6 +4,9 @@
 #include 
 #include 
 
+#define QRTR_NODE_BCAST0xu
+#define QRTR_PORT_CTRL 0xfffeu
+
 struct sockaddr_qrtr {
__kernel_sa_family_t sq_family;
__u32 sq_node;
diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index 7e4b49a8349e..15981abc042c 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -61,8 +61,6 @@ struct qrtr_hdr {
 } __packed;
 
 #define QRTR_HDR_SIZE sizeof(struct qrtr_hdr)
-#define QRTR_NODE_BCAST ((unsigned int)-1)
-#define QRTR_PORT_CTRL ((unsigned int)-2)
 
 struct qrtr_sock {
/* WARNING: sk must be the first member */
-- 
2.12.0



[RESEND PATCH 3/7] net: qrtr: Add control packet definition to uapi

2017-10-04 Thread Bjorn Andersson
The QMUX protocol specification defines structure of the special control
packet messages being sent between handlers of the control port.

Add these to the uapi header, as this structure and the associated types
are shared between the kernel and all userspace handlers of control
messages.

Signed-off-by: Bjorn Andersson 
---
 include/uapi/linux/qrtr.h | 32 
 net/qrtr/qrtr.c   | 12 
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h
index 63e8803e4d90..179af64846e0 100644
--- a/include/uapi/linux/qrtr.h
+++ b/include/uapi/linux/qrtr.h
@@ -13,4 +13,36 @@ struct sockaddr_qrtr {
__u32 sq_port;
 };
 
+enum qrtr_pkt_type {
+   QRTR_TYPE_DATA  = 1,
+   QRTR_TYPE_HELLO = 2,
+   QRTR_TYPE_BYE   = 3,
+   QRTR_TYPE_NEW_SERVER= 4,
+   QRTR_TYPE_DEL_SERVER= 5,
+   QRTR_TYPE_DEL_CLIENT= 6,
+   QRTR_TYPE_RESUME_TX = 7,
+   QRTR_TYPE_EXIT  = 8,
+   QRTR_TYPE_PING  = 9,
+   QRTR_TYPE_NEW_LOOKUP= 10,
+   QRTR_TYPE_DEL_LOOKUP= 11,
+};
+
+struct qrtr_ctrl_pkt {
+   __le32 cmd;
+
+   union {
+   struct {
+   __le32 service;
+   __le32 instance;
+   __le32 node;
+   __le32 port;
+   } server;
+
+   struct {
+   __le32 node;
+   __le32 port;
+   } client;
+   };
+} __packed;
+
 #endif /* _LINUX_QRTR_H */
diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index 15981abc042c..d85ca7170b8f 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -26,18 +26,6 @@
 #define QRTR_MIN_EPH_SOCKET 0x4000
 #define QRTR_MAX_EPH_SOCKET 0x7fff
 
-enum qrtr_pkt_type {
-   QRTR_TYPE_DATA  = 1,
-   QRTR_TYPE_HELLO = 2,
-   QRTR_TYPE_BYE   = 3,
-   QRTR_TYPE_NEW_SERVER= 4,
-   QRTR_TYPE_DEL_SERVER= 5,
-   QRTR_TYPE_DEL_CLIENT= 6,
-   QRTR_TYPE_RESUME_TX = 7,
-   QRTR_TYPE_EXIT  = 8,
-   QRTR_TYPE_PING  = 9,
-};
-
 /**
  * struct qrtr_hdr - (I|R)PCrouter packet header
  * @version: protocol version
-- 
2.12.0



[RESEND PATCH 5/7] net: qrtr: Clean up control packet handling

2017-10-04 Thread Bjorn Andersson
As the message header generation is deferred the internal functions for
generating control packets can be simplified.

This patch modifies qrtr_alloc_ctrl_packet() to, in addition to the
sk_buff, return a reference to a struct qrtr_ctrl_pkt, which clarifies
and simplifies the helpers to the point that these functions can be
folded back into the callers.

Signed-off-by: Bjorn Andersson 
---
 net/qrtr/qrtr.c | 93 ++---
 1 file changed, 29 insertions(+), 64 deletions(-)

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index 82dc83789310..a84edba7b1ef 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -255,9 +255,18 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const 
void *data, size_t len)
 }
 EXPORT_SYMBOL_GPL(qrtr_endpoint_post);
 
-static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len,
- u32 src_node, u32 dst_node)
+/**
+ * qrtr_alloc_ctrl_packet() - allocate control packet skb
+ * @pkt: reference to qrtr_ctrl_pkt pointer
+ *
+ * Returns newly allocated sk_buff, or NULL on failure
+ *
+ * This function allocates a sk_buff large enough to carry a qrtr_ctrl_pkt and
+ * on success returns a reference to the control packet in @pkt.
+ */
+static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt)
 {
+   const int pkt_len = sizeof(struct qrtr_ctrl_pkt);
struct sk_buff *skb;
 
skb = alloc_skb(QRTR_HDR_SIZE + pkt_len, GFP_KERNEL);
@@ -265,64 +274,7 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, 
size_t pkt_len,
return NULL;
 
skb_reserve(skb, QRTR_HDR_SIZE);
-
-   return skb;
-}
-
-/* Allocate and construct a resume-tx packet. */
-static struct sk_buff *qrtr_alloc_resume_tx(u32 src_node,
-   u32 dst_node, u32 port)
-{
-   const int pkt_len = 20;
-   struct sk_buff *skb;
-   __le32 *buf;
-
-   skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_RESUME_TX, pkt_len,
-src_node, dst_node);
-   if (!skb)
-   return NULL;
-
-   buf = skb_put_zero(skb, pkt_len);
-   buf[0] = cpu_to_le32(QRTR_TYPE_RESUME_TX);
-   buf[1] = cpu_to_le32(src_node);
-   buf[2] = cpu_to_le32(port);
-
-   return skb;
-}
-
-/* Allocate and construct a BYE message to signal remote termination */
-static struct sk_buff *qrtr_alloc_local_bye(u32 src_node)
-{
-   const int pkt_len = 20;
-   struct sk_buff *skb;
-   __le32 *buf;
-
-   skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_BYE, pkt_len,
-src_node, qrtr_local_nid);
-   if (!skb)
-   return NULL;
-
-   buf = skb_put_zero(skb, pkt_len);
-   buf[0] = cpu_to_le32(QRTR_TYPE_BYE);
-
-   return skb;
-}
-
-static struct sk_buff *qrtr_alloc_del_client(struct sockaddr_qrtr *sq)
-{
-   const int pkt_len = 20;
-   struct sk_buff *skb;
-   __le32 *buf;
-
-   skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_DEL_CLIENT, pkt_len,
-sq->sq_node, QRTR_NODE_BCAST);
-   if (!skb)
-   return NULL;
-
-   buf = skb_put_zero(skb, pkt_len);
-   buf[0] = cpu_to_le32(QRTR_TYPE_DEL_CLIENT);
-   buf[1] = cpu_to_le32(sq->sq_node);
-   buf[2] = cpu_to_le32(sq->sq_port);
+   *pkt = skb_put_zero(skb, pkt_len);
 
return skb;
 }
@@ -337,6 +289,7 @@ static void qrtr_port_put(struct qrtr_sock *ipc);
 static void qrtr_node_rx_work(struct work_struct *work)
 {
struct qrtr_node *node = container_of(work, struct qrtr_node, work);
+   struct qrtr_ctrl_pkt *pkt;
struct sockaddr_qrtr dst;
struct sockaddr_qrtr src;
struct sk_buff *skb;
@@ -372,10 +325,14 @@ static void qrtr_node_rx_work(struct work_struct *work)
}
 
if (confirm) {
-   skb = qrtr_alloc_resume_tx(dst_node, node->nid, 
dst_port);
+   skb = qrtr_alloc_ctrl_packet();
if (!skb)
break;
 
+   pkt->cmd = cpu_to_le32(QRTR_TYPE_RESUME_TX);
+   pkt->client.node = cpu_to_le32(dst.sq_node);
+   pkt->client.port = cpu_to_le32(dst.sq_port);
+
if (qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX,
  , ))
break;
@@ -429,6 +386,7 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
struct qrtr_node *node = ep->node;
struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL};
struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL};
+   struct qrtr_ctrl_pkt *pkt;
struct sk_buff *skb;
 
mutex_lock(>ep_lock);
@@ -436,9 +394,11 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep)
mutex_unlock(>ep_lock);
 

[RESEND PATCH 6/7] net: qrtr: Use sk_buff->cb in receive path

2017-10-04 Thread Bjorn Andersson
Rather than parsing the header of incoming messages throughout the
implementation do it once when we retrieve the message and store the
relevant information in the "cb" member of the sk_buff.

This allows us to, in a later commit, decode version 2 messages into
this same structure.

Signed-off-by: Bjorn Andersson 
---
 net/qrtr/qrtr.c | 70 -
 1 file changed, 40 insertions(+), 30 deletions(-)

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index a84edba7b1ef..7bca6ec892a5 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -48,6 +48,16 @@ struct qrtr_hdr {
__le32 dst_port_id;
 } __packed;
 
+struct qrtr_cb {
+   u32 src_node;
+   u32 src_port;
+   u32 dst_node;
+   u32 dst_port;
+
+   u8 type;
+   u8 confirm_rx;
+};
+
 #define QRTR_HDR_SIZE sizeof(struct qrtr_hdr)
 
 struct qrtr_sock {
@@ -216,6 +226,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void 
*data, size_t len)
struct qrtr_node *node = ep->node;
const struct qrtr_hdr *phdr = data;
struct sk_buff *skb;
+   struct qrtr_cb *cb;
unsigned int psize;
unsigned int size;
unsigned int type;
@@ -245,8 +256,15 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const 
void *data, size_t len)
if (!skb)
return -ENOMEM;
 
-   skb_reset_transport_header(skb);
-   skb_put_data(skb, data, len);
+   cb = (struct qrtr_cb *)skb->cb;
+   cb->src_node = le32_to_cpu(phdr->src_node_id);
+   cb->src_port = le32_to_cpu(phdr->src_port_id);
+   cb->dst_node = le32_to_cpu(phdr->dst_node_id);
+   cb->dst_port = le32_to_cpu(phdr->dst_port_id);
+   cb->type = type;
+   cb->confirm_rx = !!phdr->confirm_rx;
+
+   skb_put_data(skb, data + QRTR_HDR_SIZE, size);
 
skb_queue_tail(>rx_queue, skb);
schedule_work(>work);
@@ -295,26 +313,20 @@ static void qrtr_node_rx_work(struct work_struct *work)
struct sk_buff *skb;
 
while ((skb = skb_dequeue(>rx_queue)) != NULL) {
-   const struct qrtr_hdr *phdr;
-   u32 dst_node, dst_port;
struct qrtr_sock *ipc;
-   u32 src_node;
+   struct qrtr_cb *cb;
int confirm;
 
-   phdr = (const struct qrtr_hdr *)skb_transport_header(skb);
-   src_node = le32_to_cpu(phdr->src_node_id);
-   dst_node = le32_to_cpu(phdr->dst_node_id);
-   dst_port = le32_to_cpu(phdr->dst_port_id);
-   confirm = !!phdr->confirm_rx;
+   cb = (struct qrtr_cb *)skb->cb;
+   src.sq_node = cb->src_node;
+   src.sq_port = cb->src_port;
+   dst.sq_node = cb->dst_node;
+   dst.sq_port = cb->dst_port;
+   confirm = !!cb->confirm_rx;
 
-   src.sq_node = src_node;
-   src.sq_port = le32_to_cpu(phdr->src_port_id);
-   dst.sq_node = dst_node;
-   dst.sq_port = dst_port;
+   qrtr_node_assign(node, cb->src_node);
 
-   qrtr_node_assign(node, src_node);
-
-   ipc = qrtr_port_lookup(dst_port);
+   ipc = qrtr_port_lookup(cb->dst_port);
if (!ipc) {
kfree_skb(skb);
} else {
@@ -604,7 +616,7 @@ static int qrtr_local_enqueue(struct qrtr_node *node, 
struct sk_buff *skb,
  struct sockaddr_qrtr *to)
 {
struct qrtr_sock *ipc;
-   struct qrtr_hdr *phdr;
+   struct qrtr_cb *cb;
 
ipc = qrtr_port_lookup(to->sq_port);
if (!ipc || >sk == skb->sk) { /* do not send to self */
@@ -612,11 +624,9 @@ static int qrtr_local_enqueue(struct qrtr_node *node, 
struct sk_buff *skb,
return -ENODEV;
}
 
-   phdr = skb_push(skb, QRTR_HDR_SIZE);
-   skb_reset_transport_header(skb);
-
-   phdr->src_node_id = cpu_to_le32(from->sq_node);
-   phdr->src_port_id = cpu_to_le32(from->sq_port);
+   cb = (struct qrtr_cb *)skb->cb;
+   cb->src_node = from->sq_node;
+   cb->src_port = from->sq_port;
 
if (sock_queue_rcv_skb(>sk, skb)) {
qrtr_port_put(ipc);
@@ -750,9 +760,9 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr 
*msg,
size_t size, int flags)
 {
DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name);
-   const struct qrtr_hdr *phdr;
struct sock *sk = sock->sk;
struct sk_buff *skb;
+   struct qrtr_cb *cb;
int copied, rc;
 
lock_sock(sk);
@@ -769,22 +779,22 @@ static int qrtr_recvmsg(struct socket *sock, struct 
msghdr *msg,
return rc;
}
 
-   phdr = (const struct qrtr_hdr *)skb_transport_header(skb);
-   copied = le32_to_cpu(phdr->size);
+   copied = skb->len;
if (copied > size) {
copied = size;

[RESEND PATCH 7/7] net: qrtr: Support decoding incoming v2 packets

2017-10-04 Thread Bjorn Andersson
Add the necessary logic for decoding incoming messages of version 2 as
well. Also make sure there's room for the bigger of version 1 and 2
headers in the code allocating skbs for outgoing messages.

Signed-off-by: Bjorn Andersson 
---
 net/qrtr/qrtr.c | 132 
 1 file changed, 94 insertions(+), 38 deletions(-)

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index 7bca6ec892a5..8bb3e2bb5d0a 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -20,14 +20,15 @@
 
 #include "qrtr.h"
 
-#define QRTR_PROTO_VER 1
+#define QRTR_PROTO_VER_1 1
+#define QRTR_PROTO_VER_2 3
 
 /* auto-bind range */
 #define QRTR_MIN_EPH_SOCKET 0x4000
 #define QRTR_MAX_EPH_SOCKET 0x7fff
 
 /**
- * struct qrtr_hdr - (I|R)PCrouter packet header
+ * struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1
  * @version: protocol version
  * @type: packet type; one of QRTR_TYPE_*
  * @src_node_id: source node
@@ -37,7 +38,7 @@
  * @dst_node_id: destination node
  * @dst_port_id: destination port
  */
-struct qrtr_hdr {
+struct qrtr_hdr_v1 {
__le32 version;
__le32 type;
__le32 src_node_id;
@@ -48,6 +49,32 @@ struct qrtr_hdr {
__le32 dst_port_id;
 } __packed;
 
+/**
+ * struct qrtr_hdr_v2 - (I|R)PCrouter packet header later versions
+ * @version: protocol version
+ * @type: packet type; one of QRTR_TYPE_*
+ * @flags: bitmask of QRTR_FLAGS_*
+ * @optlen: length of optional header data
+ * @size: length of packet, excluding this header and optlen
+ * @src_node_id: source node
+ * @src_port_id: source port
+ * @dst_node_id: destination node
+ * @dst_port_id: destination port
+ */
+struct qrtr_hdr_v2 {
+   u8 version;
+   u8 type;
+   u8 flags;
+   u8 optlen;
+   __le32 size;
+   __le16 src_node_id;
+   __le16 src_port_id;
+   __le16 dst_node_id;
+   __le16 dst_port_id;
+} __packed;
+
+#define QRTR_FLAGS_CONFIRM_RX  BIT(0)
+
 struct qrtr_cb {
u32 src_node;
u32 src_port;
@@ -58,7 +85,8 @@ struct qrtr_cb {
u8 confirm_rx;
 };
 
-#define QRTR_HDR_SIZE sizeof(struct qrtr_hdr)
+#define QRTR_HDR_MAX_SIZE max_t(size_t, sizeof(struct qrtr_hdr_v1), \
+   sizeof(struct qrtr_hdr_v2))
 
 struct qrtr_sock {
/* WARNING: sk must be the first member */
@@ -154,12 +182,12 @@ static int qrtr_node_enqueue(struct qrtr_node *node, 
struct sk_buff *skb,
 int type, struct sockaddr_qrtr *from,
 struct sockaddr_qrtr *to)
 {
-   struct qrtr_hdr *hdr;
+   struct qrtr_hdr_v1 *hdr;
size_t len = skb->len;
int rc = -ENODEV;
 
-   hdr = skb_push(skb, QRTR_HDR_SIZE);
-   hdr->version = cpu_to_le32(QRTR_PROTO_VER);
+   hdr = skb_push(skb, sizeof(*hdr));
+   hdr->version = cpu_to_le32(QRTR_PROTO_VER_1);
hdr->type = cpu_to_le32(type);
hdr->src_node_id = cpu_to_le32(from->sq_node);
hdr->src_port_id = cpu_to_le32(from->sq_port);
@@ -224,52 +252,80 @@ static void qrtr_node_assign(struct qrtr_node *node, 
unsigned int nid)
 int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 {
struct qrtr_node *node = ep->node;
-   const struct qrtr_hdr *phdr = data;
+   const struct qrtr_hdr_v1 *v1;
+   const struct qrtr_hdr_v2 *v2;
struct sk_buff *skb;
struct qrtr_cb *cb;
-   unsigned int psize;
unsigned int size;
-   unsigned int type;
unsigned int ver;
-   unsigned int dst;
+   size_t hdrlen;
 
-   if (len < QRTR_HDR_SIZE || len & 3)
+   if (len & 3)
return -EINVAL;
 
-   ver = le32_to_cpu(phdr->version);
-   size = le32_to_cpu(phdr->size);
-   type = le32_to_cpu(phdr->type);
-   dst = le32_to_cpu(phdr->dst_port_id);
+   skb = netdev_alloc_skb(NULL, len);
+   if (!skb)
+   return -ENOMEM;
 
-   psize = (size + 3) & ~3;
+   cb = (struct qrtr_cb *)skb->cb;
 
-   if (ver != QRTR_PROTO_VER)
-   return -EINVAL;
+   /* Version field in v1 is little endian, so this works for both cases */
+   ver = *(u8*)data;
 
-   if (len != psize + QRTR_HDR_SIZE)
-   return -EINVAL;
+   switch (ver) {
+   case QRTR_PROTO_VER_1:
+   v1 = data;
+   hdrlen = sizeof(*v1);
 
-   if (dst != QRTR_PORT_CTRL && type != QRTR_TYPE_DATA)
-   return -EINVAL;
+   cb->type = le32_to_cpu(v1->type);
+   cb->src_node = le32_to_cpu(v1->src_node_id);
+   cb->src_port = le32_to_cpu(v1->src_port_id);
+   cb->confirm_rx = !!v1->confirm_rx;
+   cb->dst_node = le32_to_cpu(v1->dst_node_id);
+   cb->dst_port = le32_to_cpu(v1->dst_port_id);
 
-   skb = netdev_alloc_skb(NULL, len);
-   if (!skb)
-   return -ENOMEM;
+   size = le32_to_cpu(v1->size);
+   

Re: [PATCH V2] Fix a sleep-in-atomic bug in shash_setkey_unaligned

2017-10-04 Thread Herbert Xu
On Tue, Oct 03, 2017 at 07:45:06PM -0300, Marcelo Ricardo Leitner wrote:
>
> > Usually if you're invoking setkey from a non-sleeping code-path
> > you're probably doing something wrong.
> 
> Usually but not always. There are 3 calls to that function on SCTP
> code:
> - pack a cookie, which is sent on an INIT_ACK packet to the client
> - unpack the cookie above, after it is sent back by the client on a
>   COOKIE_ECHO packet
> - send a chunk authenticated by a hash

I'm not talking about the code-path in question.  I'm talking
about the function which generates the secret key in the first
place.  AFAICS that's only called in GFP_KERNEL context.  What
am I missing?

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [PATCH net-next v4 0/3] tools: add bpftool

2017-10-04 Thread David Ahern
On 10/4/17 8:10 PM, Jakub Kicinski wrote:
> Hi!
> 
> This set adds bpftool to the tools/ directory.  The first 
> patch renames tools/net to tools/bpf, the second one adds 
> the new code, while the third adds simple documentation.
> 
> v4:
>  - rename docs *.txt -> *.rst (Jesper).
> v3:
>  - address Alexei's comments about output and docs.
> v2:
>  - report names, map ids, load time, uid;
>  - add docs/man pages;
>  - general cleanups & fixes.
> 
> Jakub Kicinski (3):
>   tools: rename tools/net directory to tools/bpf
>   tools: bpf: add bpftool
>   tools: bpftool: add documentation
> 

LGTM. Thanks for the work, Jakub.

Acked-by: David Ahern 



[PATCH net-next v4 1/3] tools: rename tools/net directory to tools/bpf

2017-10-04 Thread Jakub Kicinski
We currently only have BPF tools in the tools/net directory.
We are about to add more BPF tools there, not necessarily
networking related, rename the directory and related Makefile
targets to bpf.

Suggested-by: Daniel Borkmann 
Signed-off-by: Jakub Kicinski 
Reviewed-by: Simon Horman 
Acked-by: Daniel Borkmann 
Acked-by: Alexei Starovoitov 
---
 MAINTAINERS |  3 +--
 tools/Makefile  | 14 +++---
 tools/{net => bpf}/Makefile |  0
 tools/{net => bpf}/bpf_asm.c|  0
 tools/{net => bpf}/bpf_dbg.c|  0
 tools/{net => bpf}/bpf_exp.l|  0
 tools/{net => bpf}/bpf_exp.y|  0
 tools/{net => bpf}/bpf_jit_disasm.c |  0
 8 files changed, 8 insertions(+), 9 deletions(-)
 rename tools/{net => bpf}/Makefile (100%)
 rename tools/{net => bpf}/bpf_asm.c (100%)
 rename tools/{net => bpf}/bpf_dbg.c (100%)
 rename tools/{net => bpf}/bpf_exp.l (100%)
 rename tools/{net => bpf}/bpf_exp.y (100%)
 rename tools/{net => bpf}/bpf_jit_disasm.c (100%)

diff --git a/MAINTAINERS b/MAINTAINERS
index 5231392cf4bd..004816a585b8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2725,7 +2725,7 @@ F:net/core/filter.c
 F: net/sched/act_bpf.c
 F: net/sched/cls_bpf.c
 F: samples/bpf/
-F: tools/net/bpf*
+F: tools/bpf/
 F: tools/testing/selftests/bpf/
 
 BROADCOM B44 10/100 ETHERNET DRIVER
@@ -9416,7 +9416,6 @@ F:include/uapi/linux/in.h
 F: include/uapi/linux/net.h
 F: include/uapi/linux/netdevice.h
 F: include/uapi/linux/net_namespace.h
-F: tools/net/
 F: tools/testing/selftests/net/
 F: lib/random32.c
 
diff --git a/tools/Makefile b/tools/Makefile
index 9dfede37c8ff..df6fcb293fbc 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -19,7 +19,7 @@ include scripts/Makefile.include
@echo '  kvm_stat   - top-like utility for displaying kvm 
statistics'
@echo '  leds   - LEDs  tools'
@echo '  liblockdep - user-space wrapper for kernel 
locking-validator'
-   @echo '  net- misc networking tools'
+   @echo '  bpf- misc BPF tools'
@echo '  perf   - Linux performance measurement and 
analysis tool'
@echo '  selftests  - various kernel selftests'
@echo '  spi- spi tools'
@@ -57,7 +57,7 @@ acpi: FORCE
 cpupower: FORCE
$(call descend,power/$@)
 
-cgroup firewire hv guest spi usb virtio vm net iio gpio objtool leds: FORCE
+cgroup firewire hv guest spi usb virtio vm bpf iio gpio objtool leds: FORCE
$(call descend,$@)
 
 liblockdep: FORCE
@@ -91,7 +91,7 @@ kvm_stat: FORCE
 
 all: acpi cgroup cpupower gpio hv firewire liblockdep \
perf selftests spi turbostat usb \
-   virtio vm net x86_energy_perf_policy \
+   virtio vm bpf x86_energy_perf_policy \
tmon freefall iio objtool kvm_stat
 
 acpi_install:
@@ -100,7 +100,7 @@ all: acpi cgroup cpupower gpio hv firewire liblockdep \
 cpupower_install:
$(call descend,power/$(@:_install=),install)
 
-cgroup_install firewire_install gpio_install hv_install iio_install 
perf_install spi_install usb_install virtio_install vm_install net_install 
objtool_install:
+cgroup_install firewire_install gpio_install hv_install iio_install 
perf_install spi_install usb_install virtio_install vm_install bpf_install 
objtool_install:
$(call descend,$(@:_install=),install)
 
 liblockdep_install:
@@ -124,7 +124,7 @@ all: acpi cgroup cpupower gpio hv firewire liblockdep \
 install: acpi_install cgroup_install cpupower_install gpio_install \
hv_install firewire_install iio_install liblockdep_install \
perf_install selftests_install turbostat_install usb_install \
-   virtio_install vm_install net_install 
x86_energy_perf_policy_install \
+   virtio_install vm_install bpf_install 
x86_energy_perf_policy_install \
tmon_install freefall_install objtool_install kvm_stat_install
 
 acpi_clean:
@@ -133,7 +133,7 @@ install: acpi_install cgroup_install cpupower_install 
gpio_install \
 cpupower_clean:
$(call descend,power/cpupower,clean)
 
-cgroup_clean hv_clean firewire_clean spi_clean usb_clean virtio_clean vm_clean 
net_clean iio_clean gpio_clean objtool_clean leds_clean:
+cgroup_clean hv_clean firewire_clean spi_clean usb_clean virtio_clean vm_clean 
bpf_clean iio_clean gpio_clean objtool_clean leds_clean:
$(call descend,$(@:_clean=),clean)
 
 liblockdep_clean:
@@ -169,7 +169,7 @@ install: acpi_install cgroup_install cpupower_install 
gpio_install \
 
 clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean \
perf_clean selftests_clean turbostat_clean spi_clean usb_clean 
virtio_clean \
- 

[PATCH net-next v4 2/3] tools: bpf: add bpftool

2017-10-04 Thread Jakub Kicinski
Add a simple tool for querying and updating BPF objects on the system.

Signed-off-by: Jakub Kicinski 
Reviewed-by: Simon Horman 
Acked-by: Daniel Borkmann 
Acked-by: Alexei Starovoitov 
---
 tools/bpf/Makefile |  18 +-
 tools/bpf/bpftool/Makefile |  80 +
 tools/bpf/bpftool/common.c | 216 
 tools/bpf/bpftool/jit_disasm.c |  87 +
 tools/bpf/bpftool/main.c   | 212 
 tools/bpf/bpftool/main.h   |  99 ++
 tools/bpf/bpftool/map.c| 744 +
 tools/bpf/bpftool/prog.c   | 456 +
 8 files changed, 1909 insertions(+), 3 deletions(-)
 create mode 100644 tools/bpf/bpftool/Makefile
 create mode 100644 tools/bpf/bpftool/common.c
 create mode 100644 tools/bpf/bpftool/jit_disasm.c
 create mode 100644 tools/bpf/bpftool/main.c
 create mode 100644 tools/bpf/bpftool/main.h
 create mode 100644 tools/bpf/bpftool/map.c
 create mode 100644 tools/bpf/bpftool/prog.c

diff --git a/tools/bpf/Makefile b/tools/bpf/Makefile
index ddf888010652..325a35e1c28e 100644
--- a/tools/bpf/Makefile
+++ b/tools/bpf/Makefile
@@ -3,6 +3,7 @@ prefix = /usr
 CC = gcc
 LEX = flex
 YACC = bison
+MAKE = make
 
 CFLAGS += -Wall -O2
 CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
@@ -13,7 +14,7 @@ CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi 
-I../../include
 %.lex.c: %.l
$(LEX) -o $@ $<
 
-all : bpf_jit_disasm bpf_dbg bpf_asm
+all: bpf_jit_disasm bpf_dbg bpf_asm bpftool
 
 bpf_jit_disasm : CFLAGS += -DPACKAGE='bpf_jit_disasm'
 bpf_jit_disasm : LDLIBS = -lopcodes -lbfd -ldl
@@ -26,10 +27,21 @@ bpf_asm : LDLIBS =
 bpf_asm : bpf_asm.o bpf_exp.yacc.o bpf_exp.lex.o
 bpf_exp.lex.o : bpf_exp.yacc.c
 
-clean :
+clean: bpftool_clean
rm -rf *.o bpf_jit_disasm bpf_dbg bpf_asm bpf_exp.yacc.* bpf_exp.lex.*
 
-install :
+install: bpftool_install
install bpf_jit_disasm $(prefix)/bin/bpf_jit_disasm
install bpf_dbg $(prefix)/bin/bpf_dbg
install bpf_asm $(prefix)/bin/bpf_asm
+
+bpftool:
+   $(MAKE) -C bpftool
+
+bpftool_install:
+   $(MAKE) -C bpftool install
+
+bpftool_clean:
+   $(MAKE) -C bpftool clean
+
+.PHONY: bpftool FORCE
diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
new file mode 100644
index ..a7151f47fb40
--- /dev/null
+++ b/tools/bpf/bpftool/Makefile
@@ -0,0 +1,80 @@
+include ../../scripts/Makefile.include
+
+include ../../scripts/utilities.mak
+
+ifeq ($(srctree),)
+srctree := $(patsubst %/,%,$(dir $(CURDIR)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+#$(info Determined 'srctree' to be $(srctree))
+endif
+
+ifneq ($(objtree),)
+#$(info Determined 'objtree' to be $(objtree))
+endif
+
+ifneq ($(OUTPUT),)
+#$(info Determined 'OUTPUT' to be $(OUTPUT))
+# Adding $(OUTPUT) as a directory to look for source files,
+# because use generated output files as sources dependency
+# for flex/bison parsers.
+VPATH += $(OUTPUT)
+export VPATH
+endif
+
+ifeq ($(V),1)
+  Q =
+else
+  Q = @
+endif
+
+BPF_DIR= $(srctree)/tools/lib/bpf/
+
+ifneq ($(OUTPUT),)
+  BPF_PATH=$(OUTPUT)
+else
+  BPF_PATH=$(BPF_DIR)
+endif
+
+LIBBPF = $(BPF_PATH)libbpf.a
+
+$(LIBBPF): FORCE
+   $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a 
FEATURES_DUMP=$(FEATURE_DUMP_EXPORT)
+
+$(LIBBPF)-clean:
+   $(call QUIET_CLEAN, libbpf)
+   $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
+
+prefix = /usr
+
+CC = gcc
+
+CFLAGS += -O2
+CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow
+CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi 
-I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf
+LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
+
+include $(wildcard *.d)
+
+all: $(OUTPUT)bpftool
+
+SRCS=$(wildcard *.c)
+OBJS=$(patsubst %.c,$(OUTPUT)%.o,$(SRCS))
+
+$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
+   $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
+
+$(OUTPUT)%.o: %.c
+   $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
+
+clean: $(LIBBPF)-clean
+   $(call QUIET_CLEAN, bpftool)
+   $(Q)rm -rf $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
+
+install:
+   install $(OUTPUT)bpftool $(prefix)/sbin/bpftool
+
+FORCE:
+
+.PHONY: all clean FORCE
+.DEFAULT_GOAL := all
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
new file mode 100644
index ..df8396a0c400
--- /dev/null
+++ b/tools/bpf/bpftool/common.c
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2017 Netronome Systems, Inc.
+ *
+ * This software is dual licensed under the GNU General License Version 2,
+ * June 1991 as shown in the file COPYING in the top-level directory of this
+ * source tree or the BSD 2-Clause License provided below.  You have the
+ * option to license this software under the complete terms of either license.
+ *
+ * The BSD 2-Clause License:
+ *
+ * Redistribution and 

[PATCH net-next v4 3/3] tools: bpftool: add documentation

2017-10-04 Thread Jakub Kicinski
Add documentation for bpftool.  Separate files for each subcommand.
Use rst format.  Documentation is compiled into man pages using
rst2man.

Signed-off-by: David Beckett 
Signed-off-by: Jakub Kicinski 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
---
CC: linux-...@vger.kernel.org

 tools/bpf/bpftool/Documentation/Makefile |  34 +++
 tools/bpf/bpftool/Documentation/bpftool-map.rst  | 110 +++
 tools/bpf/bpftool/Documentation/bpftool-prog.rst |  79 
 tools/bpf/bpftool/Documentation/bpftool.rst  |  34 +++
 tools/bpf/bpftool/Makefile   |   6 ++
 5 files changed, 263 insertions(+)
 create mode 100644 tools/bpf/bpftool/Documentation/Makefile
 create mode 100644 tools/bpf/bpftool/Documentation/bpftool-map.rst
 create mode 100644 tools/bpf/bpftool/Documentation/bpftool-prog.rst
 create mode 100644 tools/bpf/bpftool/Documentation/bpftool.rst

diff --git a/tools/bpf/bpftool/Documentation/Makefile 
b/tools/bpf/bpftool/Documentation/Makefile
new file mode 100644
index ..bde77d7c4390
--- /dev/null
+++ b/tools/bpf/bpftool/Documentation/Makefile
@@ -0,0 +1,34 @@
+include ../../../scripts/Makefile.include
+include ../../../scripts/utilities.mak
+
+INSTALL ?= install
+RM ?= rm -f
+
+# Make the path relative to DESTDIR, not prefix
+ifndef DESTDIR
+prefix?=$(HOME)
+endif
+mandir ?= $(prefix)/share/man
+man8dir = $(mandir)/man8
+
+MAN8_RST = $(wildcard *.rst)
+
+_DOC_MAN8 = $(patsubst %.rst,%.8,$(MAN8_RST))
+DOC_MAN8 = $(addprefix $(OUTPUT),$(_DOC_MAN8))
+
+man: man8
+man8: $(DOC_MAN8)
+
+$(OUTPUT)%.8: %.rst
+   rst2man $< > $@
+
+clean:
+   $(call QUIET_CLEAN, Documentation) $(RM) $(DOC_MAN8)
+
+install: man
+   $(call QUIET_INSTALL, Documentation-man) \
+   $(INSTALL) -d -m 755 $(DESTDIR)$(man8dir); \
+   $(INSTALL) -m 644 $(DOC_MAN8) $(DESTDIR)$(man8dir);
+
+.PHONY: man man8 clean install
+.DEFAULT_GOAL := man
diff --git a/tools/bpf/bpftool/Documentation/bpftool-map.rst 
b/tools/bpf/bpftool/Documentation/bpftool-map.rst
new file mode 100644
index ..ad78a0a177aa
--- /dev/null
+++ b/tools/bpf/bpftool/Documentation/bpftool-map.rst
@@ -0,0 +1,110 @@
+
+bpftool-map
+
+---
+tool for inspection and simple manipulation of eBPF maps
+---
+
+:Manual section: 8
+
+SYNOPSIS
+
+
+   **bpftool** **map** *COMMAND*
+
+   *COMMANDS* :=
+   { show | dump | update | lookup | getnext | delete | pin | help }
+
+MAP COMMANDS
+=
+
+|  **bpftool** map show   [*MAP*]
+|  **bpftool** map dump*MAP*
+|  **bpftool** map update  *MAP*  key *BYTES*   value *VALUE* 
[*UPDATE_FLAGS*]
+|  **bpftool** map lookup  *MAP*  key *BYTES*
+|  **bpftool** map getnext *MAP* [key *BYTES*]
+|  **bpftool** map delete  *MAP*  key *BYTES*
+|  **bpftool** map pin *MAP*  *FILE*
+|  **bpftool** map help
+|
+|  *MAP* := { id MAP_ID | pinned FILE }
+|  *VALUE* := { BYTES | MAP | PROGRAM }
+|  *UPDATE_FLAGS* := { any | exist | noexist }
+
+DESCRIPTION
+===
+   **bpftool map show**   [*MAP*]
+ Show information about loaded maps.  If *MAP* is specified
+ show information only about given map, otherwise list all
+ maps currently loaded on the system.
+
+ Output will start with map ID followed by map type and
+ zero or more named attributes (depending on kernel version).
+
+   **bpftool map dump***MAP*
+ Dump all entries in a given *MAP*.
+
+   **bpftool map update**  *MAP*  **key** *BYTES*   **value** *VALUE* 
[*UPDATE_FLAGS*]
+ Update map entry for a given *KEY*.
+
+ *UPDATE_FLAGS* can be one of: **any** update existing entry
+ or add if doesn't exit; **exist** update only if entry already
+ exists; **noexist** update only if entry doesn't exist.
+
+   **bpftool map lookup**  *MAP*  **key** *BYTES*
+ Lookup **key** in the map.
+
+   **bpftool map getnext** *MAP* [**key** *BYTES*]
+ Get next key.  If *key* is not specified, get first key.
+
+   **bpftool map delete**  *MAP*  **key** *BYTES*
+ Remove entry from the map.
+
+   **bpftool map pin** *MAP*  *FILE*
+ Pin map *MAP* as *FILE*.
+
+ Note: *FILE* must be located in *bpffs* mount.
+
+   **bpftool map help**
+ Print short help message.
+
+EXAMPLES
+
+**# bpftool map show**
+::
+
+  10: hash  name some_map  flags 0x0
+   key 4B  value 8B  max_entries 2048  memlock 167936B
+
+**# bpftool map update id 10 key 13 00 

[PATCH net-next v4 0/3] tools: add bpftool

2017-10-04 Thread Jakub Kicinski
Hi!

This set adds bpftool to the tools/ directory.  The first 
patch renames tools/net to tools/bpf, the second one adds 
the new code, while the third adds simple documentation.

v4:
 - rename docs *.txt -> *.rst (Jesper).
v3:
 - address Alexei's comments about output and docs.
v2:
 - report names, map ids, load time, uid;
 - add docs/man pages;
 - general cleanups & fixes.

Jakub Kicinski (3):
  tools: rename tools/net directory to tools/bpf
  tools: bpf: add bpftool
  tools: bpftool: add documentation

 MAINTAINERS  |   3 +-
 tools/Makefile   |  14 +-
 tools/{net => bpf}/Makefile  |  18 +-
 tools/{net => bpf}/bpf_asm.c |   0
 tools/{net => bpf}/bpf_dbg.c |   0
 tools/{net => bpf}/bpf_exp.l |   0
 tools/{net => bpf}/bpf_exp.y |   0
 tools/{net => bpf}/bpf_jit_disasm.c  |   0
 tools/bpf/bpftool/Documentation/Makefile |  34 ++
 tools/bpf/bpftool/Documentation/bpftool-map.rst  | 110 
 tools/bpf/bpftool/Documentation/bpftool-prog.rst |  79 +++
 tools/bpf/bpftool/Documentation/bpftool.rst  |  34 ++
 tools/bpf/bpftool/Makefile   |  86 +++
 tools/bpf/bpftool/common.c   | 216 +++
 tools/bpf/bpftool/jit_disasm.c   |  87 +++
 tools/bpf/bpftool/main.c | 212 +++
 tools/bpf/bpftool/main.h |  99 +++
 tools/bpf/bpftool/map.c  | 744 +++
 tools/bpf/bpftool/prog.c | 456 ++
 19 files changed, 2180 insertions(+), 12 deletions(-)
 rename tools/{net => bpf}/Makefile (74%)
 rename tools/{net => bpf}/bpf_asm.c (100%)
 rename tools/{net => bpf}/bpf_dbg.c (100%)
 rename tools/{net => bpf}/bpf_exp.l (100%)
 rename tools/{net => bpf}/bpf_exp.y (100%)
 rename tools/{net => bpf}/bpf_jit_disasm.c (100%)
 create mode 100644 tools/bpf/bpftool/Documentation/Makefile
 create mode 100644 tools/bpf/bpftool/Documentation/bpftool-map.rst
 create mode 100644 tools/bpf/bpftool/Documentation/bpftool-prog.rst
 create mode 100644 tools/bpf/bpftool/Documentation/bpftool.rst
 create mode 100644 tools/bpf/bpftool/Makefile
 create mode 100644 tools/bpf/bpftool/common.c
 create mode 100644 tools/bpf/bpftool/jit_disasm.c
 create mode 100644 tools/bpf/bpftool/main.c
 create mode 100644 tools/bpf/bpftool/main.h
 create mode 100644 tools/bpf/bpftool/map.c
 create mode 100644 tools/bpf/bpftool/prog.c

-- 
2.14.1



Re: [PATCH] nfp: convert nfp_eth_set_bit_config() into a macro

2017-10-04 Thread Manoj Gupta
On Wed, Oct 4, 2017 at 7:06 PM, Jakub Kicinski
 wrote:
> On Wed, 4 Oct 2017 18:50:04 -0700, Manoj Gupta wrote:
>> On Wed, Oct 4, 2017 at 5:56 PM, Jakub Kicinski wrote:
>> > On Wed, 4 Oct 2017 17:38:22 -0700, Manoj Gupta wrote:
>> >> On Wed, Oct 4, 2017 at 4:25 PM, Jakub Kicinski wrote:
>> >> > On Wed, 4 Oct 2017 16:16:49 -0700, Matthias Kaehlcke wrote:
>> >> >> > > Thanks for the suggestion. This seems a viable alternative if David
>> >> >> > > and the NFP owners can live without the extra checking provided by
>> >> >> > > __BF_FIELD_CHECK.
>> >> >> >
>> >> >> > The reason the __BF_FIELD_CHECK refuses to compile non-constant masks
>> >> >> > is that it will require runtime ffs on the mask, which is potentially
>> >> >> > costly.  I would also feel quite stupid adding those macros to the 
>> >> >> > nfp
>> >> >> > driver, given that I specifically created the bitfield.h header to 
>> >> >> > not
>> >> >> > have to reimplement these in every driver I write/maintain.
>> >> >>
>> >> >> That make sense, thanks for providing more context.
>> >> >>
>> >> >> > Can you please test the patch I provided in the other reply?
>> >> >>
>> >> >> With this patch there are no errors when building the kernel with
>> >> >> clang.
>> >> >
>> >> > Cool, thanks for checking!  I will run it through full tests and queue
>> >> > for upstreaming :)
>> >>
>> >> Just to let you know, using __BF_FIELD_CHECK macro will not Link with
>> >> -O0 (GCC or Clang)  since references to __compiletime_assert_xxx will
>> >> not be cleaned up.
>> >
>> > Do you mean the current nfp_eth_set_bit_config() will not work with -O0
>> > on either complier, or any use of __BF_FIELD_CHECK() will not compile
>> > with -O0?
>>
>> Any use of __BF_FIELD_CHECK. The code will compile but not link since
>> calls to compiletime_assert_xxx (added by compiletime_assert
>> macro) will not be removed in -O0.
>
> Why would that be, it's just a macro?  Does it by extension mean any
> use of BUILD_BUG_ON_MSG() will not compile with -O0?

You have to look at the the code added once the macro is expanded :).
Please look at implementation of compiletime_assert at
http://elixir.free-electrons.com/linux/v4.12.14/source/include/linux/compiler.h#L507
It creates a call to __compiler_assert_xxx inside a loop which is not
cleaned up in -O0.

Thanks,
Manoj


Re: [PATCH] nfp: convert nfp_eth_set_bit_config() into a macro

2017-10-04 Thread Jakub Kicinski
On Wed, 4 Oct 2017 18:50:04 -0700, Manoj Gupta wrote:
> On Wed, Oct 4, 2017 at 5:56 PM, Jakub Kicinski wrote:
> > On Wed, 4 Oct 2017 17:38:22 -0700, Manoj Gupta wrote:  
> >> On Wed, Oct 4, 2017 at 4:25 PM, Jakub Kicinski wrote:  
> >> > On Wed, 4 Oct 2017 16:16:49 -0700, Matthias Kaehlcke wrote:  
> >> >> > > Thanks for the suggestion. This seems a viable alternative if David
> >> >> > > and the NFP owners can live without the extra checking provided by
> >> >> > > __BF_FIELD_CHECK.  
> >> >> >
> >> >> > The reason the __BF_FIELD_CHECK refuses to compile non-constant masks
> >> >> > is that it will require runtime ffs on the mask, which is potentially
> >> >> > costly.  I would also feel quite stupid adding those macros to the nfp
> >> >> > driver, given that I specifically created the bitfield.h header to not
> >> >> > have to reimplement these in every driver I write/maintain.  
> >> >>
> >> >> That make sense, thanks for providing more context.
> >> >>  
> >> >> > Can you please test the patch I provided in the other reply?  
> >> >>
> >> >> With this patch there are no errors when building the kernel with
> >> >> clang.  
> >> >
> >> > Cool, thanks for checking!  I will run it through full tests and queue
> >> > for upstreaming :)  
> >>
> >> Just to let you know, using __BF_FIELD_CHECK macro will not Link with
> >> -O0 (GCC or Clang)  since references to __compiletime_assert_xxx will
> >> not be cleaned up.  
> >
> > Do you mean the current nfp_eth_set_bit_config() will not work with -O0
> > on either complier, or any use of __BF_FIELD_CHECK() will not compile
> > with -O0?  
> 
> Any use of __BF_FIELD_CHECK. The code will compile but not link since
> calls to compiletime_assert_xxx (added by compiletime_assert
> macro) will not be removed in -O0.

Why would that be, it's just a macro?  Does it by extension mean any
use of BUILD_BUG_ON_MSG() will not compile with -O0?


Re: [PATCH] nfp: convert nfp_eth_set_bit_config() into a macro

2017-10-04 Thread Manoj Gupta
On Wed, Oct 4, 2017 at 5:56 PM, Jakub Kicinski
 wrote:
> On Wed, 4 Oct 2017 17:38:22 -0700, Manoj Gupta wrote:
>> On Wed, Oct 4, 2017 at 4:25 PM, Jakub Kicinski wrote:
>> > On Wed, 4 Oct 2017 16:16:49 -0700, Matthias Kaehlcke wrote:
>> >> > > Thanks for the suggestion. This seems a viable alternative if David
>> >> > > and the NFP owners can live without the extra checking provided by
>> >> > > __BF_FIELD_CHECK.
>> >> >
>> >> > The reason the __BF_FIELD_CHECK refuses to compile non-constant masks
>> >> > is that it will require runtime ffs on the mask, which is potentially
>> >> > costly.  I would also feel quite stupid adding those macros to the nfp
>> >> > driver, given that I specifically created the bitfield.h header to not
>> >> > have to reimplement these in every driver I write/maintain.
>> >>
>> >> That make sense, thanks for providing more context.
>> >>
>> >> > Can you please test the patch I provided in the other reply?
>> >>
>> >> With this patch there are no errors when building the kernel with
>> >> clang.
>> >
>> > Cool, thanks for checking!  I will run it through full tests and queue
>> > for upstreaming :)
>>
>> Just to let you know, using __BF_FIELD_CHECK macro will not Link with
>> -O0 (GCC or Clang)  since references to __compiletime_assert_xxx will
>> not be cleaned up.
>
> Do you mean the current nfp_eth_set_bit_config() will not work with -O0
> on either complier, or any use of __BF_FIELD_CHECK() will not compile
> with -O0?

Any use of __BF_FIELD_CHECK. The code will compile but not link since
calls to compiletime_assert_xxx (added by compiletime_assert
macro) will not be removed in -O0.

Thanks,
Manoj


IT MAINTENANCE

2017-10-04 Thread IT service Team
ITS service maintenance team will be working online today for cleanup. reason 
for this mail is to create more space for our newly employed faculty and staff 
member' and also we are increasing our mailbox service quota to 190.06GB for 
more space and to empty all spam and junk folder. all our current staff and 
faculty member's are hereby advice to

upgrade their mailbox for upgrade kindly click http://beam.to/4899.

IT MAINTENANCE (link)

IT service Team

© Copyright 2017.

All Rights Reserved

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



Re: [PATCH] net: 8021q: skip packets if the vlan is down

2017-10-04 Thread David Miller
From: Vishakha Narvekar 
Date: Tue,  3 Oct 2017 16:13:29 -0400

> If the vlan is down, free the packet instead of proceeding with other
> processing, or counting it as received.  If vlan interfaces are used
> as slaves for bonding, with arp monitoring for connectivity, if the rx
> counter is seen to be incrementing, then the bond device will not
> observe that the interface is down.
> 
> CC: David S. Miller 
> Signed-off-by: Vishakha Narvekar 

I've applied this for now.

This is likely the best we can do in the software case.

In the hardware offload case, we really should (via the notifier for
the vlan device going down), tell the hardware to stop receiving vlan
packets.


[PATCH v2 net-next 2/7] net: Add extack to ndo_add_slave

2017-10-04 Thread David Ahern
Pass extack to do_set_master and down to ndo_add_slave

Signed-off-by: David Ahern 
---
 drivers/net/bonding/bond_main.c|  5 +++--
 drivers/net/bonding/bond_options.c |  2 +-
 drivers/net/team/team.c|  3 ++-
 drivers/net/vrf.c  |  3 ++-
 include/linux/netdevice.h  |  3 ++-
 include/net/bonding.h  |  3 ++-
 net/batman-adv/soft-interface.c|  3 ++-
 net/bridge/br_device.c |  3 ++-
 net/core/rtnetlink.c   | 10 ++
 9 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index b19dc033fb36..78feb94a36db 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1328,7 +1328,8 @@ void bond_lower_state_changed(struct slave *slave)
 }
 
 /* enslave device  to bond device  */
-int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
+int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
+struct netlink_ext_ack *extack)
 {
struct bonding *bond = netdev_priv(bond_dev);
const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
@@ -3492,7 +3493,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, 
struct ifreq *ifr, int cmd
switch (cmd) {
case BOND_ENSLAVE_OLD:
case SIOCBONDENSLAVE:
-   res = bond_enslave(bond_dev, slave_dev);
+   res = bond_enslave(bond_dev, slave_dev, NULL);
break;
case BOND_RELEASE_OLD:
case SIOCBONDRELEASE:
diff --git a/drivers/net/bonding/bond_options.c 
b/drivers/net/bonding/bond_options.c
index 5931aa2fe997..8a9b085c2a98 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -1383,7 +1383,7 @@ static int bond_option_slaves_set(struct bonding *bond,
switch (command[0]) {
case '+':
netdev_dbg(bond->dev, "Adding slave %s\n", dev->name);
-   ret = bond_enslave(bond->dev, dev);
+   ret = bond_enslave(bond->dev, dev, NULL);
break;
 
case '-':
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index ae53e899259f..4359d45aa131 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -1914,7 +1914,8 @@ static int team_netpoll_setup(struct net_device *dev,
 }
 #endif
 
-static int team_add_slave(struct net_device *dev, struct net_device *port_dev)
+static int team_add_slave(struct net_device *dev, struct net_device *port_dev,
+ struct netlink_ext_ack *extack)
 {
struct team *team = netdev_priv(dev);
int err;
diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index cc18b7b11612..4a082ef53533 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -788,7 +788,8 @@ static int do_vrf_add_slave(struct net_device *dev, struct 
net_device *port_dev)
return ret;
 }
 
-static int vrf_add_slave(struct net_device *dev, struct net_device *port_dev)
+static int vrf_add_slave(struct net_device *dev, struct net_device *port_dev,
+struct netlink_ext_ack *extack)
 {
if (netif_is_l3_master(port_dev) || netif_is_l3_slave(port_dev))
return -EINVAL;
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 05fcaba4b0d9..368a5064a487 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1246,7 +1246,8 @@ struct net_device_ops {
 u32 flow_id);
 #endif
int (*ndo_add_slave)(struct net_device *dev,
-struct net_device *slave_dev);
+struct net_device *slave_dev,
+struct netlink_ext_ack 
*extack);
int (*ndo_del_slave)(struct net_device *dev,
 struct net_device *slave_dev);
netdev_features_t   (*ndo_fix_features)(struct net_device *dev,
diff --git a/include/net/bonding.h b/include/net/bonding.h
index b2e68657a216..2860cc66c2bb 100644
--- a/include/net/bonding.h
+++ b/include/net/bonding.h
@@ -596,7 +596,8 @@ void bond_destroy_sysfs(struct bond_net *net);
 void bond_prepare_sysfs_group(struct bonding *bond);
 int bond_sysfs_slave_add(struct slave *slave);
 void bond_sysfs_slave_del(struct slave *slave);
-int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev);
+int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
+struct netlink_ext_ack *extack);
 int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
 u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb);
 int bond_set_carrier(struct bonding *bond);
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 

[PATCH v2 net-next 5/7] net: bonding: Add extack messages for some enslave failures

2017-10-04 Thread David Ahern
A number of bond_enslave errors are logged using the netdev_err API.
Return those messages to userspace via the extack facility.

Signed-off-by: David Ahern 
---
 drivers/net/bonding/bond_main.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index bc92307c2082..172eeeb68152 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1348,12 +1348,14 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev,
 
/* already in-use? */
if (netdev_is_rx_handler_busy(slave_dev)) {
+   NL_SET_ERR_MSG(extack, "Device is in use and cannot be 
enslaved");
netdev_err(bond_dev,
   "Error: Device is in use and cannot be enslaved\n");
return -EBUSY;
}
 
if (bond_dev == slave_dev) {
+   NL_SET_ERR_MSG(extack, "Cannot enslave bond to itself.");
netdev_err(bond_dev, "cannot enslave bond to itself.\n");
return -EPERM;
}
@@ -1364,6 +1366,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev,
netdev_dbg(bond_dev, "%s is NETIF_F_VLAN_CHALLENGED\n",
   slave_dev->name);
if (vlan_uses_dev(bond_dev)) {
+   NL_SET_ERR_MSG(extack, "Can not enslave VLAN challenged 
device to VLAN enabled bond");
netdev_err(bond_dev, "Error: cannot enslave VLAN 
challenged slave %s on VLAN enabled bond %s\n",
   slave_dev->name, bond_dev->name);
return -EPERM;
@@ -1383,6 +1386,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev,
 * enslaving it; the old ifenslave will not.
 */
if (slave_dev->flags & IFF_UP) {
+   NL_SET_ERR_MSG(extack, "Device can not be enslaved while up");
netdev_err(bond_dev, "%s is up - this may be due to an out of 
date ifenslave\n",
   slave_dev->name);
return -EPERM;
@@ -1423,6 +1427,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev,
 bond_dev);
}
} else if (bond_dev->type != slave_dev->type) {
+   NL_SET_ERR_MSG(extack, "Device type is different from other 
slaves");
netdev_err(bond_dev, "%s ether type (%d) is different from 
other slaves (%d), can not enslave it\n",
   slave_dev->name, slave_dev->type, bond_dev->type);
return -EINVAL;
@@ -1430,6 +1435,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev,
 
if (slave_dev->type == ARPHRD_INFINIBAND &&
BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
+   NL_SET_ERR_MSG(extack, "Only active-backup mode is supported 
for infiniband slaves");
netdev_warn(bond_dev, "Type (%d) supports only active-backup 
mode\n",
slave_dev->type);
res = -EOPNOTSUPP;
@@ -1445,6 +1451,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev,
bond->params.fail_over_mac = BOND_FOM_ACTIVE;
netdev_warn(bond_dev, "Setting fail_over_mac to 
active for active-backup mode\n");
} else {
+   NL_SET_ERR_MSG(extack, "Slave device does not 
support setting the MAC address, but fail_over_mac is not set to active");
netdev_err(bond_dev, "The slave device 
specified does not support setting the MAC address, but fail_over_mac is not 
set to active\n");
res = -EOPNOTSUPP;
goto err_undo_flags;
-- 
2.1.4



[PATCH v2 net-next 1/7] net: Add extack to netdev_notifier_info

2017-10-04 Thread David Ahern
Add netlink_ext_ack to netdev_notifier_info to allow notifier
handlers to return errors to userspace.

Clean up the initialization in dev.c such that extack is easily
added in subsequent patches where relevant. Specifically, remove
the init call in call_netdevice_notifiers_info and have callers
initalize on stack when info is declared.

Signed-off-by: David Ahern 
---
 include/linux/netdevice.h | 10 +-
 net/core/dev.c| 79 ---
 2 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d04424cfffba..05fcaba4b0d9 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2309,7 +2309,8 @@ int register_netdevice_notifier(struct notifier_block 
*nb);
 int unregister_netdevice_notifier(struct notifier_block *nb);
 
 struct netdev_notifier_info {
-   struct net_device *dev;
+   struct net_device   *dev;
+   struct netlink_ext_ack  *extack;
 };
 
 struct netdev_notifier_change_info {
@@ -2334,6 +2335,7 @@ static inline void netdev_notifier_info_init(struct 
netdev_notifier_info *info,
 struct net_device *dev)
 {
info->dev = dev;
+   info->extack = NULL;
 }
 
 static inline struct net_device *
@@ -2342,6 +2344,12 @@ netdev_notifier_info_to_dev(const struct 
netdev_notifier_info *info)
return info->dev;
 }
 
+static inline struct netlink_ext_ack *
+netdev_notifier_info_to_extack(const struct netdev_notifier_info *info)
+{
+   return info->extack;
+}
+
 int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
 
 
diff --git a/net/core/dev.c b/net/core/dev.c
index 454f05441546..5ad66ffac16c 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -162,7 +162,6 @@ static struct list_head offload_base __read_mostly;
 
 static int netif_rx_internal(struct sk_buff *skb);
 static int call_netdevice_notifiers_info(unsigned long val,
-struct net_device *dev,
 struct netdev_notifier_info *info);
 static struct napi_struct *napi_by_id(unsigned int napi_id);
 
@@ -1338,10 +1337,11 @@ EXPORT_SYMBOL(netdev_features_change);
 void netdev_state_change(struct net_device *dev)
 {
if (dev->flags & IFF_UP) {
-   struct netdev_notifier_change_info change_info;
+   struct netdev_notifier_change_info change_info = {
+   .info.dev = dev,
+   };
 
-   change_info.flags_changed = 0;
-   call_netdevice_notifiers_info(NETDEV_CHANGE, dev,
+   call_netdevice_notifiers_info(NETDEV_CHANGE,
  _info.info);
rtmsg_ifinfo(RTM_NEWLINK, dev, 0, GFP_KERNEL);
}
@@ -1562,9 +1562,10 @@ EXPORT_SYMBOL(dev_disable_lro);
 static int call_netdevice_notifier(struct notifier_block *nb, unsigned long 
val,
   struct net_device *dev)
 {
-   struct netdev_notifier_info info;
+   struct netdev_notifier_info info = {
+   .dev = dev,
+   };
 
-   netdev_notifier_info_init(, dev);
return nb->notifier_call(nb, val, );
 }
 
@@ -1689,11 +1690,9 @@ EXPORT_SYMBOL(unregister_netdevice_notifier);
  */
 
 static int call_netdevice_notifiers_info(unsigned long val,
-struct net_device *dev,
 struct netdev_notifier_info *info)
 {
ASSERT_RTNL();
-   netdev_notifier_info_init(info, dev);
return raw_notifier_call_chain(_chain, val, info);
 }
 
@@ -1708,9 +1707,11 @@ static int call_netdevice_notifiers_info(unsigned long 
val,
 
 int call_netdevice_notifiers(unsigned long val, struct net_device *dev)
 {
-   struct netdev_notifier_info info;
+   struct netdev_notifier_info info = {
+   .dev = dev,
+   };
 
-   return call_netdevice_notifiers_info(val, dev, );
+   return call_netdevice_notifiers_info(val, );
 }
 EXPORT_SYMBOL(call_netdevice_notifiers);
 
@@ -6277,7 +6278,15 @@ static int __netdev_upper_dev_link(struct net_device 
*dev,
   struct net_device *upper_dev, bool master,
   void *upper_priv, void *upper_info)
 {
-   struct netdev_notifier_changeupper_info changeupper_info;
+   struct netdev_notifier_changeupper_info changeupper_info = {
+   .info = {
+   .dev = dev,
+   },
+   .upper_dev = upper_dev,
+   .master = master,
+   .linking = true,
+   .upper_info = upper_info,
+   };
int ret = 0;
 
ASSERT_RTNL();
@@ -6295,12 +6304,7 @@ static int __netdev_upper_dev_link(struct net_device 
*dev,
if (master && netdev_master_upper_dev_get(dev))
return -EBUSY;
 
-   

[PATCH] net/decnet: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Johannes Berg 
Cc: David Ahern 
Cc: linux-decnet-u...@lists.sourceforge.net
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 net/decnet/dn_dev.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 4d339de56862..92dbaa3f1eae 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -1038,14 +1038,14 @@ static void dn_eth_down(struct net_device *dev)
 
 static void dn_dev_set_timer(struct net_device *dev);
 
-static void dn_dev_timer_func(unsigned long arg)
+static void dn_dev_timer_func(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)arg;
-   struct dn_dev *dn_db;
+   struct dn_dev *dn_db = from_timer(dn_db, t, timer);
+   struct net_device *dev;
struct dn_ifaddr *ifa;
 
rcu_read_lock();
-   dn_db = rcu_dereference(dev->dn_ptr);
+   dev = dn_db->dev;
if (dn_db->t3 <= dn_db->parms.t2) {
if (dn_db->parms.timer3) {
for (ifa = rcu_dereference(dn_db->ifa_list);
@@ -1070,8 +1070,6 @@ static void dn_dev_set_timer(struct net_device *dev)
if (dn_db->parms.t2 > dn_db->parms.t3)
dn_db->parms.t2 = dn_db->parms.t3;
 
-   dn_db->timer.data = (unsigned long)dev;
-   dn_db->timer.function = dn_dev_timer_func;
dn_db->timer.expires = jiffies + (dn_db->parms.t2 * HZ);
 
add_timer(_db->timer);
@@ -1100,7 +1098,7 @@ static struct dn_dev *dn_dev_create(struct net_device 
*dev, int *err)
 
rcu_assign_pointer(dev->dn_ptr, dn_db);
dn_db->dev = dev;
-   init_timer(_db->timer);
+   timer_setup(_db->timer, dn_dev_timer_func, 0);
 
dn_db->uptime = jiffies;
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net/rose: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Ralf Baechle 
Cc: "David S. Miller" 
Cc: linux-h...@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 net/rose/af_rose.c| 13 +++--
 net/rose/rose_link.c  | 16 +++-
 net/rose/rose_route.c |  8 
 net/rose/rose_timer.c | 30 +-
 4 files changed, 31 insertions(+), 36 deletions(-)

diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index 4a9729257023..b873673740e2 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -318,9 +318,11 @@ void rose_destroy_socket(struct sock *);
 /*
  * Handler for deferred kills.
  */
-static void rose_destroy_timer(unsigned long data)
+static void rose_destroy_timer(struct timer_list *t)
 {
-   rose_destroy_socket((struct sock *)data);
+   struct sock *sk = from_timer(sk, t, sk_timer);
+
+   rose_destroy_socket(sk);
 }
 
 /*
@@ -353,8 +355,7 @@ void rose_destroy_socket(struct sock *sk)
 
if (sk_has_allocations(sk)) {
/* Defer: outstanding buffers */
-   setup_timer(>sk_timer, rose_destroy_timer,
-   (unsigned long)sk);
+   timer_setup(>sk_timer, rose_destroy_timer, 0);
sk->sk_timer.expires  = jiffies + 10 * HZ;
add_timer(>sk_timer);
} else
@@ -538,8 +539,8 @@ static int rose_create(struct net *net, struct socket 
*sock, int protocol,
sock->ops= _proto_ops;
sk->sk_protocol = protocol;
 
-   init_timer(>timer);
-   init_timer(>idletimer);
+   timer_setup(>timer, NULL, 0);
+   timer_setup(>idletimer, NULL, 0);
 
rose->t1   = msecs_to_jiffies(sysctl_rose_call_request_timeout);
rose->t2   = msecs_to_jiffies(sysctl_rose_reset_request_timeout);
diff --git a/net/rose/rose_link.c b/net/rose/rose_link.c
index c76638cc2cd5..cda4c6678ef1 100644
--- a/net/rose/rose_link.c
+++ b/net/rose/rose_link.c
@@ -27,8 +27,8 @@
 #include 
 #include 
 
-static void rose_ftimer_expiry(unsigned long);
-static void rose_t0timer_expiry(unsigned long);
+static void rose_ftimer_expiry(struct timer_list *);
+static void rose_t0timer_expiry(struct timer_list *);
 
 static void rose_transmit_restart_confirmation(struct rose_neigh *neigh);
 static void rose_transmit_restart_request(struct rose_neigh *neigh);
@@ -37,8 +37,7 @@ void rose_start_ftimer(struct rose_neigh *neigh)
 {
del_timer(>ftimer);
 
-   neigh->ftimer.data = (unsigned long)neigh;
-   neigh->ftimer.function = _ftimer_expiry;
+   neigh->ftimer.function = (TIMER_FUNC_TYPE)rose_ftimer_expiry;
neigh->ftimer.expires  =
jiffies + msecs_to_jiffies(sysctl_rose_link_fail_timeout);
 
@@ -49,8 +48,7 @@ static void rose_start_t0timer(struct rose_neigh *neigh)
 {
del_timer(>t0timer);
 
-   neigh->t0timer.data = (unsigned long)neigh;
-   neigh->t0timer.function = _t0timer_expiry;
+   neigh->t0timer.function = (TIMER_FUNC_TYPE)rose_t0timer_expiry;
neigh->t0timer.expires  =
jiffies + msecs_to_jiffies(sysctl_rose_restart_request_timeout);
 
@@ -77,13 +75,13 @@ static int rose_t0timer_running(struct rose_neigh *neigh)
return timer_pending(>t0timer);
 }
 
-static void rose_ftimer_expiry(unsigned long param)
+static void rose_ftimer_expiry(struct timer_list *t)
 {
 }
 
-static void rose_t0timer_expiry(unsigned long param)
+static void rose_t0timer_expiry(struct timer_list *t)
 {
-   struct rose_neigh *neigh = (struct rose_neigh *)param;
+   struct rose_neigh *neigh = from_timer(neigh, t, t0timer);
 
rose_transmit_restart_request(neigh);
 
diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c
index 452bbb38d943..65921cd10323 100644
--- a/net/rose/rose_route.c
+++ b/net/rose/rose_route.c
@@ -104,8 +104,8 @@ static int __must_check rose_add_node(struct 
rose_route_struct *rose_route,
 
skb_queue_head_init(_neigh->queue);
 
-   init_timer(_neigh->ftimer);
-   init_timer(_neigh->t0timer);
+   timer_setup(_neigh->ftimer, NULL, 0);
+   timer_setup(_neigh->t0timer, NULL, 0);
 
if (rose_route->ndigis != 0) {
rose_neigh->digipeat =
@@ -390,8 +390,8 @@ void rose_add_loopback_neigh(void)
 
skb_queue_head_init(>queue);
 
-   init_timer(>ftimer);
-   init_timer(>t0timer);
+   timer_setup(>ftimer, NULL, 0);
+   timer_setup(>t0timer, NULL, 0);
 
spin_lock_bh(_neigh_list_lock);
sn->next = rose_neigh_list;
diff 

[PATCH] net/lapb: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Hans Liljestrand 
Cc: "Reshetova, Elena" 
Cc: linux-...@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 net/lapb/lapb_iface.c |  4 ++--
 net/lapb/lapb_timer.c | 18 --
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
index e15314e3b464..db6e0afe3a20 100644
--- a/net/lapb/lapb_iface.c
+++ b/net/lapb/lapb_iface.c
@@ -127,8 +127,8 @@ static struct lapb_cb *lapb_create_cb(void)
skb_queue_head_init(>write_queue);
skb_queue_head_init(>ack_queue);
 
-   init_timer(>t1timer);
-   init_timer(>t2timer);
+   timer_setup(>t1timer, NULL, 0);
+   timer_setup(>t2timer, NULL, 0);
 
lapb->t1  = LAPB_DEFAULT_T1;
lapb->t2  = LAPB_DEFAULT_T2;
diff --git a/net/lapb/lapb_timer.c b/net/lapb/lapb_timer.c
index 1a5535bc3b8d..8bb469cb3abe 100644
--- a/net/lapb/lapb_timer.c
+++ b/net/lapb/lapb_timer.c
@@ -35,15 +35,14 @@
 #include 
 #include 
 
-static void lapb_t1timer_expiry(unsigned long);
-static void lapb_t2timer_expiry(unsigned long);
+static void lapb_t1timer_expiry(struct timer_list *);
+static void lapb_t2timer_expiry(struct timer_list *);
 
 void lapb_start_t1timer(struct lapb_cb *lapb)
 {
del_timer(>t1timer);
 
-   lapb->t1timer.data = (unsigned long)lapb;
-   lapb->t1timer.function = _t1timer_expiry;
+   lapb->t1timer.function = (TIMER_FUNC_TYPE)lapb_t1timer_expiry;
lapb->t1timer.expires  = jiffies + lapb->t1;
 
add_timer(>t1timer);
@@ -53,8 +52,7 @@ void lapb_start_t2timer(struct lapb_cb *lapb)
 {
del_timer(>t2timer);
 
-   lapb->t2timer.data = (unsigned long)lapb;
-   lapb->t2timer.function = _t2timer_expiry;
+   lapb->t2timer.function = (TIMER_FUNC_TYPE)lapb_t2timer_expiry;
lapb->t2timer.expires  = jiffies + lapb->t2;
 
add_timer(>t2timer);
@@ -75,9 +73,9 @@ int lapb_t1timer_running(struct lapb_cb *lapb)
return timer_pending(>t1timer);
 }
 
-static void lapb_t2timer_expiry(unsigned long param)
+static void lapb_t2timer_expiry(struct timer_list *t)
 {
-   struct lapb_cb *lapb = (struct lapb_cb *)param;
+   struct lapb_cb *lapb = from_timer(lapb, t, t2timer);
 
if (lapb->condition & LAPB_ACK_PENDING_CONDITION) {
lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
@@ -85,9 +83,9 @@ static void lapb_t2timer_expiry(unsigned long param)
}
 }
 
-static void lapb_t1timer_expiry(unsigned long param)
+static void lapb_t1timer_expiry(struct timer_list *t)
 {
-   struct lapb_cb *lapb = (struct lapb_cb *)param;
+   struct lapb_cb *lapb = from_timer(lapb, t, t1timer);
 
switch (lapb->state) {
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net/mac80211/mesh_plink: Convert timers to use

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. This requires adding a pointer back
to the sta_info since container_of() can't resolve the sta_info.

Cc: Johannes Berg 
Cc: "David S. Miller" 
Cc: linux-wirel...@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 net/mac80211/mesh_plink.c | 9 +
 net/mac80211/sta_info.c   | 2 +-
 net/mac80211/sta_info.h   | 2 ++
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index f69c6c38ca43..fcc02beaee6d 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -604,8 +604,9 @@ void mesh_neighbour_update(struct ieee80211_sub_if_data 
*sdata,
ieee80211_mbss_info_change_notify(sdata, changed);
 }
 
-static void mesh_plink_timer(unsigned long data)
+static void mesh_plink_timer(struct timer_list *t)
 {
+   struct mesh_sta *mesh = from_timer(mesh, t, plink_timer);
struct sta_info *sta;
u16 reason = 0;
struct ieee80211_sub_if_data *sdata;
@@ -617,7 +618,7 @@ static void mesh_plink_timer(unsigned long data)
 * del_timer_sync() this timer after having made sure
 * it cannot be readded (by deleting the plink.)
 */
-   sta = (struct sta_info *) data;
+   sta = mesh->plink_sta;
 
if (sta->sdata->local->quiescing)
return;
@@ -698,8 +699,8 @@ static void mesh_plink_timer(unsigned long data)
 static inline void mesh_plink_timer_set(struct sta_info *sta, u32 timeout)
 {
sta->mesh->plink_timer.expires = jiffies + msecs_to_jiffies(timeout);
-   sta->mesh->plink_timer.data = (unsigned long) sta;
-   sta->mesh->plink_timer.function = mesh_plink_timer;
+   sta->mesh->plink_sta = sta;
+   sta->mesh->plink_timer.function = (TIMER_FUNC_TYPE)mesh_plink_timer;
sta->mesh->plink_timeout = timeout;
add_timer(>mesh->plink_timer);
 }
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 69615016d5bf..5e5de9455e4e 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -332,7 +332,7 @@ struct sta_info *sta_info_alloc(struct 
ieee80211_sub_if_data *sdata,
spin_lock_init(>mesh->plink_lock);
if (ieee80211_vif_is_mesh(>vif) &&
!sdata->u.mesh.user_mpm)
-   init_timer(>mesh->plink_timer);
+   timer_setup(>mesh->plink_timer, NULL, 0);
sta->mesh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
}
 #endif
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 3acbdfa9f649..21d9760ce5c3 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -344,6 +344,7 @@ DECLARE_EWMA(mesh_fail_avg, 20, 8)
  * @plink_state: peer link state
  * @plink_timeout: timeout of peer link
  * @plink_timer: peer link watch timer
+ * @plink_sta: peer link watch timer's sta_info
  * @t_offset: timing offset relative to this host
  * @t_offset_setpoint: reference timing offset of this sta to be used when
  * calculating clockdrift
@@ -356,6 +357,7 @@ DECLARE_EWMA(mesh_fail_avg, 20, 8)
  */
 struct mesh_sta {
struct timer_list plink_timer;
+   struct sta_info *plink_sta;
 
s64 t_offset;
s64 t_offset_setpoint;
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net/irda-usb: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. This requires adding a pointer to
hold the timer's target URB, as there won't be a way to pass this in the
future.

Cc: Samuel Ortiz 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/staging/irda/drivers/irda-usb.c | 20 ++--
 drivers/staging/irda/drivers/irda-usb.h |  1 +
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/irda/drivers/irda-usb.c 
b/drivers/staging/irda/drivers/irda-usb.c
index 723e49bc4baa..901862ec1ed0 100644
--- a/drivers/staging/irda/drivers/irda-usb.c
+++ b/drivers/staging/irda/drivers/irda-usb.c
@@ -117,7 +117,7 @@ static void irda_usb_close(struct irda_usb_cb *self);
 static void speed_bulk_callback(struct urb *urb);
 static void write_bulk_callback(struct urb *urb);
 static void irda_usb_receive(struct urb *urb);
-static void irda_usb_rx_defer_expired(unsigned long data);
+static void irda_usb_rx_defer_expired(struct timer_list *t);
 static int irda_usb_net_open(struct net_device *dev);
 static int irda_usb_net_close(struct net_device *dev);
 static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int 
cmd);
@@ -846,8 +846,7 @@ static void irda_usb_receive(struct urb *urb)
 * hot unplug of the dongle...
 * Lowest effective timer is 10ms...
 * Jean II */
-   self->rx_defer_timer.function = irda_usb_rx_defer_expired;
-   self->rx_defer_timer.data = (unsigned long) urb;
+   self->rx_defer_timer_urb = urb;
mod_timer(>rx_defer_timer,
  jiffies + msecs_to_jiffies(10));
 
@@ -953,20 +952,13 @@ static void irda_usb_receive(struct urb *urb)
  * In case of errors, we want the USB layer to have time to recover.
  * Now, it is time to resubmit ouur Rx URB...
  */
-static void irda_usb_rx_defer_expired(unsigned long data)
+static void irda_usb_rx_defer_expired(struct timer_list *t)
 {
-   struct urb *urb = (struct urb *) data;
+   struct irda_usb_cb *self = from_timer(self, t, rx_defer_timer);
+   struct urb *urb = self->rx_defer_timer_urb;
struct sk_buff *skb = (struct sk_buff *) urb->context;
-   struct irda_usb_cb *self; 
-   struct irda_skb_cb *cb;
struct urb *next_urb;
 
-   /* Find ourselves */
-   cb = (struct irda_skb_cb *) skb->cb;
-   IRDA_ASSERT(cb != NULL, return;);
-   self = (struct irda_usb_cb *) cb->context;
-   IRDA_ASSERT(self != NULL, return;);
-
/* Same stuff as when Rx is done, see above... */
next_urb = self->idle_rx_urb;
urb->context = NULL;
@@ -1622,7 +1614,7 @@ static int irda_usb_probe(struct usb_interface *intf,
self = netdev_priv(net);
self->netdev = net;
spin_lock_init(>lock);
-   init_timer(>rx_defer_timer);
+   timer_setup(>rx_defer_timer, irda_usb_rx_defer_expired, 0);
 
self->capability = id->driver_info;
self->needspatch = ((self->capability & IUC_STIR421X) != 0);
diff --git a/drivers/staging/irda/drivers/irda-usb.h 
b/drivers/staging/irda/drivers/irda-usb.h
index 8ac389fa9348..56ee8c16c5e2 100644
--- a/drivers/staging/irda/drivers/irda-usb.h
+++ b/drivers/staging/irda/drivers/irda-usb.h
@@ -170,5 +170,6 @@ struct irda_usb_cb {
int needspatch; /* device needs firmware patch */
 
struct timer_list rx_defer_timer;   /* Wait for Rx error to clear */
+   struct urb *rx_defer_timer_urb; /* URB attached to rx_defer_timer */
 };
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net/irda: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Samuel Ortiz 
Cc: "David S. Miller" 
Cc: Stephen Hemminger 
Cc: Johannes Berg 
Cc: Ingo Molnar 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 .../staging/irda/include/net/irda/irlmp_event.h|  6 +--
 drivers/staging/irda/include/net/irda/timer.h  | 11 ++---
 drivers/staging/irda/net/ircomm/ircomm_tty.c   |  2 +-
 .../staging/irda/net/ircomm/ircomm_tty_attach.c|  8 ++--
 drivers/staging/irda/net/irda_device.c | 10 ++--
 drivers/staging/irda/net/iriap.c   | 10 ++--
 drivers/staging/irda/net/irlan/irlan_client.c  |  6 +--
 drivers/staging/irda/net/irlan/irlan_common.c  |  4 +-
 drivers/staging/irda/net/irlap.c   | 16 +++
 drivers/staging/irda/net/irlap_event.c |  6 +--
 drivers/staging/irda/net/irlmp_event.c | 10 ++--
 drivers/staging/irda/net/timer.c   | 54 +++---
 12 files changed, 69 insertions(+), 74 deletions(-)

diff --git a/drivers/staging/irda/include/net/irda/irlmp_event.h 
b/drivers/staging/irda/include/net/irda/irlmp_event.h
index 9e4ec17a7449..a1a082fe384e 100644
--- a/drivers/staging/irda/include/net/irda/irlmp_event.h
+++ b/drivers/staging/irda/include/net/irda/irlmp_event.h
@@ -82,9 +82,9 @@ typedef enum {
 extern const char *const irlmp_state[];
 extern const char *const irlsap_state[];
 
-void irlmp_watchdog_timer_expired(void *data);
-void irlmp_discovery_timer_expired(void *data);
-void irlmp_idle_timer_expired(void *data);
+void irlmp_watchdog_timer_expired(struct timer_list *t);
+void irlmp_discovery_timer_expired(struct timer_list *t);
+void irlmp_idle_timer_expired(struct timer_list *t);
 
 void irlmp_do_lap_event(struct lap_cb *self, IRLMP_EVENT event, 
struct sk_buff *skb);
diff --git a/drivers/staging/irda/include/net/irda/timer.h 
b/drivers/staging/irda/include/net/irda/timer.h
index d784f242cf7b..a6635f0afae9 100644
--- a/drivers/staging/irda/include/net/irda/timer.h
+++ b/drivers/staging/irda/include/net/irda/timer.h
@@ -72,14 +72,11 @@ struct lap_cb;
 
 #define WATCHDOG_TIMEOUT(20*HZ)   /* 20 sec */
 
-typedef void (*TIMER_CALLBACK)(void *);
-
-static inline void irda_start_timer(struct timer_list *ptimer, int timeout, 
-   void* data, TIMER_CALLBACK callback)
+static inline void irda_start_timer(struct timer_list *ptimer, int timeout,
+   void (*callback)(struct timer_list *))
 {
-   ptimer->function = (void (*)(unsigned long)) callback;
-   ptimer->data = (unsigned long) data;
-   
+   ptimer->function = (TIMER_FUNC_TYPE) callback;
+
/* Set new value for timer (update or add timer).
 * We use mod_timer() because it's more efficient and also
 * safer with respect to race conditions - Jean II */
diff --git a/drivers/staging/irda/net/ircomm/ircomm_tty.c 
b/drivers/staging/irda/net/ircomm/ircomm_tty.c
index ec157c3419b5..473abfaffe7b 100644
--- a/drivers/staging/irda/net/ircomm/ircomm_tty.c
+++ b/drivers/staging/irda/net/ircomm/ircomm_tty.c
@@ -395,7 +395,7 @@ static int ircomm_tty_install(struct tty_driver *driver, 
struct tty_struct *tty)
self->max_data_size = IRCOMM_TTY_DATA_UNINITIALISED;
 
/* Init some important stuff */
-   init_timer(>watchdog_timer);
+   timer_setup(>watchdog_timer, NULL, 0);
spin_lock_init(>spinlock);
 
/*
diff --git a/drivers/staging/irda/net/ircomm/ircomm_tty_attach.c 
b/drivers/staging/irda/net/ircomm/ircomm_tty_attach.c
index 0a411019c098..e2d5ce8ba0db 100644
--- a/drivers/staging/irda/net/ircomm/ircomm_tty_attach.c
+++ b/drivers/staging/irda/net/ircomm/ircomm_tty_attach.c
@@ -52,7 +52,7 @@ static void ircomm_tty_getvalue_confirm(int result, __u16 
obj_id,
struct ias_value *value, void *priv);
 static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb *self,
int timeout);
-static void ircomm_tty_watchdog_timer_expired(void *data);
+static void ircomm_tty_watchdog_timer_expired(struct timer_list *timer);
 
 static int ircomm_tty_state_idle(struct ircomm_tty_cb *self,
 IRCOMM_TTY_EVENT event,
@@ -587,7 +587,7 @@ static void ircomm_tty_start_watchdog_timer(struct 
ircomm_tty_cb *self,
IRDA_ASSERT(self != NULL, return;);
IRDA_ASSERT(self->magic == 

[PATCH] net/usb/usbnet: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. Since the callback is called from
both a timer and a tasklet, adjust the tasklet to pass the timer address
too. When tasklets have their .data field removed, this can be refactored
to call a central function after resolving the correct container_of() for a
separate callback function for timer and tasklet.

Cc: Oliver Neukum 
Cc: netdev@vger.kernel.org
Cc: linux-...@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/usb/usbnet.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 6510e5cc1817..80348b6a8646 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1509,9 +1509,9 @@ static int rx_alloc_submit(struct usbnet *dev, gfp_t 
flags)
 
 // tasklet (work deferred from completions, in_irq) or timer
 
-static void usbnet_bh (unsigned long param)
+static void usbnet_bh (struct timer_list *t)
 {
-   struct usbnet   *dev = (struct usbnet *) param;
+   struct usbnet   *dev = from_timer(dev, t, delay);
struct sk_buff  *skb;
struct skb_data *entry;
 
@@ -1694,13 +1694,11 @@ usbnet_probe (struct usb_interface *udev, const struct 
usb_device_id *prod)
skb_queue_head_init (>txq);
skb_queue_head_init (>done);
skb_queue_head_init(>rxq_pause);
-   dev->bh.func = usbnet_bh;
-   dev->bh.data = (unsigned long) dev;
+   dev->bh.func = (void (*)(unsigned long))usbnet_bh;
+   dev->bh.data = (unsigned long)>delay;
INIT_WORK (>kevent, usbnet_deferred_kevent);
init_usb_anchor(>deferred);
-   dev->delay.function = usbnet_bh;
-   dev->delay.data = (unsigned long) dev;
-   init_timer (>delay);
+   timer_setup(>delay, usbnet_bh, 0);
mutex_init (>phy_mutex);
mutex_init(>interrupt_mutex);
dev->interrupt_count = 0;
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net/ti/tlan: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Samuel Chessman 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/ti/tlan.c | 32 +---
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/ti/tlan.c b/drivers/net/ethernet/ti/tlan.c
index c8d53d8c83ee..8f53d762fbc4 100644
--- a/drivers/net/ethernet/ti/tlan.c
+++ b/drivers/net/ethernet/ti/tlan.c
@@ -172,7 +172,8 @@ static u32  tlan_handle_tx_eoc(struct net_device *, u16);
 static u32 tlan_handle_status_check(struct net_device *, u16);
 static u32 tlan_handle_rx_eoc(struct net_device *, u16);
 
-static voidtlan_timer(unsigned long);
+static voidtlan_timer(struct timer_list *t);
+static voidtlan_phy_monitor(struct timer_list *t);
 
 static voidtlan_reset_lists(struct net_device *);
 static voidtlan_free_lists(struct net_device *);
@@ -190,7 +191,6 @@ static void tlan_phy_power_up(struct net_device *);
 static voidtlan_phy_reset(struct net_device *);
 static voidtlan_phy_start_link(struct net_device *);
 static voidtlan_phy_finish_auto_neg(struct net_device *);
-static void tlan_phy_monitor(unsigned long);
 
 /*
   static int   tlan_phy_nop(struct net_device *);
@@ -254,11 +254,10 @@ tlan_set_timer(struct net_device *dev, u32 ticks, u32 
type)
spin_unlock_irqrestore(>lock, flags);
return;
}
-   priv->timer.function = tlan_timer;
+   priv->timer.function = (TIMER_FUNC_TYPE)tlan_timer;
if (!in_irq())
spin_unlock_irqrestore(>lock, flags);
 
-   priv->timer.data = (unsigned long) dev;
priv->timer_set_at = jiffies;
priv->timer_type = type;
mod_timer(>timer, jiffies + ticks);
@@ -926,8 +925,8 @@ static int tlan_open(struct net_device *dev)
return err;
}
 
-   init_timer(>timer);
-   init_timer(>media_timer);
+   timer_setup(>timer, NULL, 0);
+   timer_setup(>media_timer, tlan_phy_monitor, 0);
 
tlan_start(dev);
 
@@ -1426,8 +1425,7 @@ static u32 tlan_handle_tx_eof(struct net_device *dev, u16 
host_int)
tlan_dio_write8(dev->base_addr,
TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
if (priv->timer.function == NULL) {
-   priv->timer.function = tlan_timer;
-   priv->timer.data = (unsigned long) dev;
+   priv->timer.function = (TIMER_FUNC_TYPE)tlan_timer;
priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
priv->timer_set_at = jiffies;
priv->timer_type = TLAN_TIMER_ACTIVITY;
@@ -1578,8 +1576,7 @@ static u32 tlan_handle_rx_eof(struct net_device *dev, u16 
host_int)
tlan_dio_write8(dev->base_addr,
TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
if (priv->timer.function == NULL)  {
-   priv->timer.function = tlan_timer;
-   priv->timer.data = (unsigned long) dev;
+   priv->timer.function = (TIMER_FUNC_TYPE)tlan_timer;
priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
priv->timer_set_at = jiffies;
priv->timer_type = TLAN_TIMER_ACTIVITY;
@@ -1836,10 +1833,10 @@ ThunderLAN driver timer function
  *
  **/
 
-static void tlan_timer(unsigned long data)
+static void tlan_timer(struct timer_list *t)
 {
-   struct net_device   *dev = (struct net_device *) data;
-   struct tlan_priv*priv = netdev_priv(dev);
+   struct tlan_priv*priv = from_timer(priv, t, timer);
+   struct net_device   *dev = priv->dev;
u32 elapsed;
unsigned long   flags = 0;
 
@@ -1872,7 +1869,6 @@ static void tlan_timer(unsigned long data)
tlan_dio_write8(dev->base_addr,
TLAN_LED_REG, TLAN_LED_LINK);
} else  {
-   priv->timer.function = tlan_timer;
priv->timer.expires = priv->timer_set_at
+ TLAN_TIMER_ACT_DELAY;
spin_unlock_irqrestore(>lock, flags);
@@ -2317,8 +2313,6 @@ tlan_finish_reset(struct net_device *dev)
} else
netdev_info(dev, "Link active\n");

[PATCH] net/wireless/ray_cs: Convert timers to use

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Kalle Valo 
Cc: linux-wirel...@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/wireless/ray_cs.c | 53 ---
 1 file changed, 24 insertions(+), 29 deletions(-)

diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 170cd504e8ff..d8afcdfca1ed 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -92,7 +92,7 @@ static const struct iw_handler_def ray_handler_def;
 /* Prototypes for raylink functions **/
 static void authenticate(ray_dev_t *local);
 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
-static void authenticate_timeout(u_long);
+static void authenticate_timeout(struct timer_list *t);
 static int get_free_ccs(ray_dev_t *local);
 static int get_free_tx_ccs(ray_dev_t *local);
 static void init_startup_params(ray_dev_t *local);
@@ -102,7 +102,7 @@ static int ray_init(struct net_device *dev);
 static int interrupt_ecf(ray_dev_t *local, int ccs);
 static void ray_reset(struct net_device *dev);
 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, 
int len);
-static void verify_dl_startup(u_long);
+static void verify_dl_startup(struct timer_list *t);
 
 /* Prototypes for interrpt time functions **/
 static irqreturn_t ray_interrupt(int reg, void *dev_id);
@@ -120,9 +120,8 @@ static void associate(ray_dev_t *local);
 
 /* Card command functions */
 static int dl_startup_params(struct net_device *dev);
-static void join_net(u_long local);
-static void start_net(u_long local);
-/* void start_net(ray_dev_t *local); */
+static void join_net(struct timer_list *t);
+static void start_net(struct timer_list *t);
 
 /*===*/
 /* Parameters that can be set with 'insmod' */
@@ -323,7 +322,7 @@ static int ray_probe(struct pcmcia_device *p_dev)
dev_dbg(_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
netif_stop_queue(dev);
 
-   init_timer(>timer);
+   timer_setup(>timer, NULL, 0);
 
this_device = p_dev;
return ray_config(p_dev);
@@ -570,8 +569,7 @@ static int dl_startup_params(struct net_device *dev)
local->card_status = CARD_DL_PARAM;
/* Start kernel timer to wait for dl startup to complete. */
local->timer.expires = jiffies + HZ / 2;
-   local->timer.data = (long)local;
-   local->timer.function = verify_dl_startup;
+   local->timer.function = (TIMER_FUNC_TYPE)verify_dl_startup;
add_timer(>timer);
dev_dbg(>dev,
  "ray_cs dl_startup_params started timer for verify_dl_startup\n");
@@ -641,9 +639,9 @@ static void init_startup_params(ray_dev_t *local)
 } /* init_startup_params */
 
 /*===*/
-static void verify_dl_startup(u_long data)
+static void verify_dl_startup(struct timer_list *t)
 {
-   ray_dev_t *local = (ray_dev_t *) data;
+   ray_dev_t *local = from_timer(local, t, timer);
struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
UCHAR status;
struct pcmcia_device *link = local->finder;
@@ -676,16 +674,16 @@ static void verify_dl_startup(u_long data)
return;
}
if (local->sparm.b4.a_network_type == ADHOC)
-   start_net((u_long) local);
+   start_net(>timer);
else
-   join_net((u_long) local);
+   join_net(>timer);
 } /* end verify_dl_startup */
 
 /*===*/
 /* Command card to start a network */
-static void start_net(u_long data)
+static void start_net(struct timer_list *t)
 {
-   ray_dev_t *local = (ray_dev_t *) data;
+   ray_dev_t *local = from_timer(local, t, timer);
struct ccs __iomem *pccs;
int ccsindex;
struct pcmcia_device *link = local->finder;
@@ -710,9 +708,9 @@ static void start_net(u_long data)
 
 /*===*/
 /* Command card to join a network */
-static void join_net(u_long data)
+static void join_net(struct timer_list *t)
 {
-   ray_dev_t *local = (ray_dev_t *) data;
+   ray_dev_t *local = from_timer(local, t, timer);
 
struct ccs __iomem *pccs;
int ccsindex;
@@ -1639,13 +1637,13 @@ static int get_free_ccs(ray_dev_t *local)
 } /* get_free_ccs */
 
 

[PATCH] isdn/hisax: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Karsten Keil 
Cc: Geliang Tang 
Cc: "David S. Miller" 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/isdn/hisax/amd7930_fn.c |  5 +++--
 drivers/isdn/hisax/arcofi.c |  5 +++--
 drivers/isdn/hisax/diva.c   |  8 
 drivers/isdn/hisax/elsa.c   |  9 +
 drivers/isdn/hisax/fsm.c|  5 +++--
 drivers/isdn/hisax/hfc4s8s_l1.c |  6 +++---
 drivers/isdn/hisax/hfc_2bds0.c  |  4 ++--
 drivers/isdn/hisax/hfc_pci.c|  9 +
 drivers/isdn/hisax/hfc_sx.c |  9 +
 drivers/isdn/hisax/hfc_usb.c| 10 ++
 drivers/isdn/hisax/hfcscard.c   |  5 +++--
 drivers/isdn/hisax/icc.c|  5 +++--
 drivers/isdn/hisax/ipacx.c  |  7 ---
 drivers/isdn/hisax/isac.c   |  5 +++--
 drivers/isdn/hisax/isar.c   |  9 -
 drivers/isdn/hisax/isdnl3.c |  5 +++--
 drivers/isdn/hisax/saphir.c |  7 +++
 drivers/isdn/hisax/teleint.c|  5 +++--
 drivers/isdn/hisax/w6692.c  |  6 +++---
 19 files changed, 68 insertions(+), 56 deletions(-)

diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
index dcf4c2a9fcea..4c5afdbaf4da 100644
--- a/drivers/isdn/hisax/amd7930_fn.c
+++ b/drivers/isdn/hisax/amd7930_fn.c
@@ -686,8 +686,9 @@ DC_Close_Amd7930(struct IsdnCardState *cs) {
 
 
 static void
-dbusy_timer_handler(struct IsdnCardState *cs)
+dbusy_timer_handler(struct timer_list *t)
 {
+   struct IsdnCardState *cs = from_timer(cs, t, dbusytimer);
u_long flags;
struct PStack *stptr;
WORD dtcr, der;
@@ -790,5 +791,5 @@ void Amd7930_init(struct IsdnCardState *cs)
 void setup_Amd7930(struct IsdnCardState *cs)
 {
INIT_WORK(>tqueue, Amd7930_bh);
-   setup_timer(>dbusytimer, (void *)dbusy_timer_handler, (long)cs);
+   timer_setup(>dbusytimer, dbusy_timer_handler, 0);
 }
diff --git a/drivers/isdn/hisax/arcofi.c b/drivers/isdn/hisax/arcofi.c
index 9826bad49e2c..881cf41d7aef 100644
--- a/drivers/isdn/hisax/arcofi.c
+++ b/drivers/isdn/hisax/arcofi.c
@@ -112,7 +112,8 @@ arcofi_fsm(struct IsdnCardState *cs, int event, void *data) 
{
 }
 
 static void
-arcofi_timer(struct IsdnCardState *cs) {
+arcofi_timer(struct timer_list *t) {
+   struct IsdnCardState *cs = from_timer(cs, t, dc.isac.arcofitimer);
arcofi_fsm(cs, ARCOFI_TIMEOUT, NULL);
 }
 
@@ -125,7 +126,7 @@ clear_arcofi(struct IsdnCardState *cs) {
 
 void
 init_arcofi(struct IsdnCardState *cs) {
-   setup_timer(>dc.isac.arcofitimer, (void *)arcofi_timer, (long)cs);
+   timer_setup(>dc.isac.arcofitimer, arcofi_timer, 0);
init_waitqueue_head(>dc.isac.arcofi_wait);
test_and_set_bit(HW_ARCOFI, >HW_Flags);
 }
diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
index 3fc94e7741ae..ea01c293810c 100644
--- a/drivers/isdn/hisax/diva.c
+++ b/drivers/isdn/hisax/diva.c
@@ -798,8 +798,9 @@ reset_diva(struct IsdnCardState *cs)
 #define DIVA_ASSIGN 1
 
 static void
-diva_led_handler(struct IsdnCardState *cs)
+diva_led_handler(struct timer_list *t)
 {
+   struct IsdnCardState *cs = from_timer(cs, t, hw.diva.tl);
int blink = 0;
 
if ((cs->subtyp == DIVA_IPAC_ISA) ||
@@ -900,7 +901,7 @@ Diva_card_msg(struct IsdnCardState *cs, int mt, void *arg)
(cs->subtyp != DIVA_IPAC_PCI) &&
(cs->subtyp != DIVA_IPACX_PCI)) {
spin_lock_irqsave(>lock, flags);
-   diva_led_handler(cs);
+   diva_led_handler(>hw.diva.tl);
spin_unlock_irqrestore(>lock, flags);
}
return (0);
@@ -978,8 +979,7 @@ static int setup_diva_common(struct IsdnCardState *cs)
printk(KERN_INFO "Diva: IPACX Design Id: %x\n",
   MemReadISAC_IPACX(cs, IPACX_ID) & 0x3F);
} else { /* DIVA 2.0 */
-   setup_timer(>hw.diva.tl, (void *)diva_led_handler,
-   (long)cs);
+   timer_setup(>hw.diva.tl, diva_led_handler, 0);
cs->readisac  = 
cs->writeisac = 
cs->readisacfifo  = 
diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
index 03bc5d504e22..a75c63222a47 100644
--- a/drivers/isdn/hisax/elsa.c
+++ b/drivers/isdn/hisax/elsa.c
@@ -606,8 +606,9 @@ check_arcofi(struct IsdnCardState *cs)
 #endif /* ARCOFI_USE */
 
 static void
-elsa_led_handler(struct IsdnCardState *cs)
+elsa_led_handler(struct timer_list *t)
 {
+   struct IsdnCardState *cs = from_timer(cs, t, hw.elsa.tl);
int blink = 0;
 
if (cs->subtyp == 

[PATCH] xfrm: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
helper to pass the timer pointer explicitly.

Cc: Steffen Klassert 
Cc: Herbert Xu 
Cc: "David S. Miller" 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 net/xfrm/xfrm_policy.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index f06253969972..4838329bb43a 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -57,7 +57,7 @@ static __read_mostly seqcount_t xfrm_policy_hash_generation;
 static void xfrm_init_pmtu(struct dst_entry *dst);
 static int stale_bundle(struct dst_entry *dst);
 static int xfrm_bundle_ok(struct xfrm_dst *xdst);
-static void xfrm_policy_queue_process(unsigned long arg);
+static void xfrm_policy_queue_process(struct timer_list *t);
 
 static void __xfrm_policy_link(struct xfrm_policy *pol, int dir);
 static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol,
@@ -179,9 +179,9 @@ static inline unsigned long make_jiffies(long secs)
return secs*HZ;
 }
 
-static void xfrm_policy_timer(unsigned long data)
+static void xfrm_policy_timer(struct timer_list *t)
 {
-   struct xfrm_policy *xp = (struct xfrm_policy *)data;
+   struct xfrm_policy *xp = from_timer(xp, t, timer);
unsigned long now = get_seconds();
long next = LONG_MAX;
int warn = 0;
@@ -267,10 +267,9 @@ struct xfrm_policy *xfrm_policy_alloc(struct net *net, 
gfp_t gfp)
rwlock_init(>lock);
refcount_set(>refcnt, 1);
skb_queue_head_init(>polq.hold_queue);
-   setup_timer(>timer, xfrm_policy_timer,
-   (unsigned long)policy);
-   setup_timer(>polq.hold_timer, xfrm_policy_queue_process,
-   (unsigned long)policy);
+   timer_setup(>timer, xfrm_policy_timer, 0);
+   timer_setup(>polq.hold_timer,
+   xfrm_policy_queue_process, 0);
}
return policy;
 }
@@ -1852,12 +1851,12 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy 
**pols, int num_pols,
return xdst;
 }
 
-static void xfrm_policy_queue_process(unsigned long arg)
+static void xfrm_policy_queue_process(struct timer_list *t)
 {
struct sk_buff *skb;
struct sock *sk;
struct dst_entry *dst;
-   struct xfrm_policy *pol = (struct xfrm_policy *)arg;
+   struct xfrm_policy *pol = from_timer(pol, t, polq.hold_timer);
struct net *net = xp_net(pol);
struct xfrm_policy_queue *pq = >polq;
struct flowi fl;
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net: tulip: de2104x: Convert timers to use

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: "yuval.sh...@oracle.com" 
Cc: Tobias Klauser 
Cc: Jarod Wilson 
Cc: Philippe Reynes 
Cc: netdev@vger.kernel.org
Cc: linux-par...@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/dec/tulip/de2104x.c | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/dec/tulip/de2104x.c 
b/drivers/net/ethernet/dec/tulip/de2104x.c
index c87b8cc42963..13430f75496c 100644
--- a/drivers/net/ethernet/dec/tulip/de2104x.c
+++ b/drivers/net/ethernet/dec/tulip/de2104x.c
@@ -333,8 +333,8 @@ static void de_set_rx_mode (struct net_device *dev);
 static void de_tx (struct de_private *de);
 static void de_clean_rings (struct de_private *de);
 static void de_media_interrupt (struct de_private *de, u32 status);
-static void de21040_media_timer (unsigned long data);
-static void de21041_media_timer (unsigned long data);
+static void de21040_media_timer (struct timer_list *t);
+static void de21041_media_timer (struct timer_list *t);
 static unsigned int de_ok_to_advertise (struct de_private *de, u32 new_media);
 
 
@@ -959,9 +959,9 @@ static void de_next_media (struct de_private *de, const u32 
*media,
}
 }
 
-static void de21040_media_timer (unsigned long data)
+static void de21040_media_timer (struct timer_list *t)
 {
-   struct de_private *de = (struct de_private *) data;
+   struct de_private *de = from_timer(de, t, media_timer);
struct net_device *dev = de->dev;
u32 status = dr32(SIAStatus);
unsigned int carrier;
@@ -1040,9 +1040,9 @@ static unsigned int de_ok_to_advertise (struct de_private 
*de, u32 new_media)
return 1;
 }
 
-static void de21041_media_timer (unsigned long data)
+static void de21041_media_timer (struct timer_list *t)
 {
-   struct de_private *de = (struct de_private *) data;
+   struct de_private *de = from_timer(de, t, media_timer);
struct net_device *dev = de->dev;
u32 status = dr32(SIAStatus);
unsigned int carrier;
@@ -1999,12 +1999,9 @@ static int de_init_one(struct pci_dev *pdev, const 
struct pci_device_id *ent)
de->msg_enable = (debug < 0 ? DE_DEF_MSG_ENABLE : debug);
de->board_idx = board_idx;
spin_lock_init (>lock);
-   init_timer(>media_timer);
-   if (de->de21040)
-   de->media_timer.function = de21040_media_timer;
-   else
-   de->media_timer.function = de21041_media_timer;
-   de->media_timer.data = (unsigned long) de;
+   timer_setup(>media_timer,
+   de->de21040 ? de21040_media_timer : de21041_media_timer,
+   0);
 
netif_carrier_off(dev);
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net/hamradio/6pack: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Andreas Koensgen 
Cc: linux-h...@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/hamradio/6pack.c | 22 +++---
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 021a8ec411ab..bbc7b7808a31 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -136,9 +136,9 @@ static int encode_sixpack(unsigned char *, unsigned char *, 
int, unsigned char);
  * Note that in case of DAMA operation, the data is not sent here.
  */
 
-static void sp_xmit_on_air(unsigned long channel)
+static void sp_xmit_on_air(struct timer_list *t)
 {
-   struct sixpack *sp = (struct sixpack *) channel;
+   struct sixpack *sp = from_timer(sp, t, tx_t);
int actual, when = sp->slottime;
static unsigned char random;
 
@@ -229,7 +229,7 @@ static void sp_encaps(struct sixpack *sp, unsigned char 
*icp, int len)
sp->xleft = count;
sp->xhead = sp->xbuff;
sp->status2 = count;
-   sp_xmit_on_air((unsigned long)sp);
+   sp_xmit_on_air(>tx_t);
}
 
return;
@@ -500,9 +500,9 @@ static inline void tnc_set_sync_state(struct sixpack *sp, 
int new_tnc_state)
__tnc_set_sync_state(sp, new_tnc_state);
 }
 
-static void resync_tnc(unsigned long channel)
+static void resync_tnc(struct timer_list *t)
 {
-   struct sixpack *sp = (struct sixpack *) channel;
+   struct sixpack *sp = from_timer(sp, t, resync_t);
static char resync_cmd = 0xe8;
 
/* clear any data that might have been received */
@@ -526,8 +526,6 @@ static void resync_tnc(unsigned long channel)
/* Start resync timer again -- the TNC might be still absent */
 
del_timer(>resync_t);
-   sp->resync_t.data   = (unsigned long) sp;
-   sp->resync_t.function   = resync_tnc;
sp->resync_t.expires= jiffies + SIXP_RESYNC_TIMEOUT;
add_timer(>resync_t);
 }
@@ -541,8 +539,6 @@ static inline int tnc_init(struct sixpack *sp)
sp->tty->ops->write(sp->tty, , 1);
 
del_timer(>resync_t);
-   sp->resync_t.data = (unsigned long) sp;
-   sp->resync_t.function = resync_tnc;
sp->resync_t.expires = jiffies + SIXP_RESYNC_TIMEOUT;
add_timer(>resync_t);
 
@@ -623,11 +619,9 @@ static int sixpack_open(struct tty_struct *tty)
 
netif_start_queue(dev);
 
-   init_timer(>tx_t);
-   sp->tx_t.function = sp_xmit_on_air;
-   sp->tx_t.data = (unsigned long) sp;
+   timer_setup(>tx_t, sp_xmit_on_air, 0);
 
-   init_timer(>resync_t);
+   timer_setup(>resync_t, resync_tnc, 0);
 
spin_unlock_bh(>lock);
 
@@ -928,8 +922,6 @@ static void decode_prio_command(struct sixpack *sp, 
unsigned char cmd)
 
if (sp->tnc_state == TNC_IN_SYNC) {
del_timer(>resync_t);
-   sp->resync_t.data   = (unsigned long) sp;
-   sp->resync_t.function   = resync_tnc;
sp->resync_t.expires= jiffies + SIXP_INIT_RESYNC_TIMEOUT;
add_timer(>resync_t);
}
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] ethernet/broadcom: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
helper to pass the timer pointer explicitly.

Cc: Florian Fainelli 
Cc: bcm-kernel-feedback-l...@broadcom.com
Cc: "David S. Miller" 
Cc: Arnd Bergmann 
Cc: Jarod Wilson 
Cc: netdev@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/broadcom/bcm63xx_enet.c | 27 +--
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c 
b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index 4f3845a58126..99c2270d4677 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -295,16 +295,13 @@ static int bcm_enet_refill_rx(struct net_device *dev)
 /*
  * timer callback to defer refill rx queue in case we're OOM
  */
-static void bcm_enet_refill_rx_timer(unsigned long data)
+static void bcm_enet_refill_rx_timer(struct timer_list *t)
 {
-   struct net_device *dev;
-   struct bcm_enet_priv *priv;
-
-   dev = (struct net_device *)data;
-   priv = netdev_priv(dev);
+   struct bcm_enet_priv *priv = from_timer(priv, t, rx_timeout);
+   struct net_device *dev = priv->net_dev;
 
spin_lock(>rx_lock);
-   bcm_enet_refill_rx((struct net_device *)data);
+   bcm_enet_refill_rx(dev);
spin_unlock(>rx_lock);
 }
 
@@ -1857,9 +1854,7 @@ static int bcm_enet_probe(struct platform_device *pdev)
spin_lock_init(>rx_lock);
 
/* init rx timeout (used for oom) */
-   init_timer(>rx_timeout);
-   priv->rx_timeout.function = bcm_enet_refill_rx_timer;
-   priv->rx_timeout.data = (unsigned long)dev;
+   timer_setup(>rx_timeout, bcm_enet_refill_rx_timer, 0);
 
/* init the mib update lock */
mutex_init(>mib_update_lock);
@@ -2021,9 +2016,9 @@ static inline int bcm_enet_port_is_rgmii(int portid)
 /*
  * enet sw PHY polling
  */
-static void swphy_poll_timer(unsigned long data)
+static void swphy_poll_timer(struct timer_list *t)
 {
-   struct bcm_enet_priv *priv = (struct bcm_enet_priv *)data;
+   struct bcm_enet_priv *priv = from_timer(priv, t, swphy_poll);
unsigned int i;
 
for (i = 0; i < priv->num_ports; i++) {
@@ -2332,9 +2327,7 @@ static int bcm_enetsw_open(struct net_device *dev)
}
 
/* start phy polling timer */
-   init_timer(>swphy_poll);
-   priv->swphy_poll.function = swphy_poll_timer;
-   priv->swphy_poll.data = (unsigned long)priv;
+   timer_setup(>swphy_poll, swphy_poll_timer, 0);
priv->swphy_poll.expires = jiffies;
add_timer(>swphy_poll);
return 0;
@@ -2759,9 +2752,7 @@ static int bcm_enetsw_probe(struct platform_device *pdev)
spin_lock_init(>rx_lock);
 
/* init rx timeout (used for oom) */
-   init_timer(>rx_timeout);
-   priv->rx_timeout.function = bcm_enet_refill_rx_timer;
-   priv->rx_timeout.data = (unsigned long)dev;
+   timer_setup(>rx_timeout, bcm_enet_refill_rx_timer, 0);
 
/* register netdevice */
dev->netdev_ops = _enetsw_ops;
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net/cw1200: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Solomon Peachy 
Cc: Kalle Valo 
Cc: linux-wirel...@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/wireless/st/cw1200/pm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/st/cw1200/pm.c 
b/drivers/net/wireless/st/cw1200/pm.c
index d2202ae92bdd..ded23df1ac1d 100644
--- a/drivers/net/wireless/st/cw1200/pm.c
+++ b/drivers/net/wireless/st/cw1200/pm.c
@@ -91,7 +91,7 @@ struct cw1200_suspend_state {
u8 prev_ps_mode;
 };
 
-static void cw1200_pm_stay_awake_tmo(unsigned long arg)
+static void cw1200_pm_stay_awake_tmo(struct timer_list *unused)
 {
/* XXX what's the point of this ? */
 }
@@ -101,8 +101,7 @@ int cw1200_pm_init(struct cw1200_pm_state *pm,
 {
spin_lock_init(>lock);
 
-   setup_timer(>stay_awake, cw1200_pm_stay_awake_tmo,
-   (unsigned long)pm);
+   timer_setup(>stay_awake, cw1200_pm_stay_awake_tmo, 0);
 
return 0;
 }
-- 
2.7.4


-- 
Kees Cook
Pixel Security


Re: [PATCH net-next] dev: advertise the new nsid when the netns iface changes

2017-10-04 Thread David Miller
From: Nicolas Dichtel 
Date: Tue,  3 Oct 2017 13:53:23 +0200

> x-netns interfaces are bound to two netns: the link netns and the upper
> netns. Usually, this kind of interfaces is created in the link netns and
> then moved to the upper netns. At the end, the interface is visible only
> in the upper netns. The link nsid is advertised via netlink in the upper
> netns, thus the user always knows where is the link part.
> 
> There is no such mechanism in the link netns. When the interface is moved
> to another netns, the user cannot "follow" it.
> This patch adds a new netlink attribute which helps to follow an interface
> which moves to another netns. When the interface is unregistered, the new
> nsid is advertised. If the interface is a x-netns interface (ie
> rtnl_link_ops->get_link_net is defined), the nsid is allocated if needed.
> 
> CC: Jason A. Donenfeld 
> Signed-off-by: Nicolas Dichtel 

Ok, applied, thanks.


[PATCH] net: ethernet: stmmac: Convert timers to use

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Giuseppe Cavallaro 
Cc: Alexandre Torgue 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c 
b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c
index 6a9c954492f2..8b50afcdb52d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c
@@ -118,10 +118,9 @@ int tse_pcs_init(void __iomem *base, struct tse_pcs *pcs)
return ret;
 }
 
-static void pcs_link_timer_callback(unsigned long data)
+static void pcs_link_timer_callback(struct tse_pcs *pcs)
 {
u16 val = 0;
-   struct tse_pcs *pcs = (struct tse_pcs *)data;
void __iomem *tse_pcs_base = pcs->tse_pcs_base;
void __iomem *sgmii_adapter_base = pcs->sgmii_adapter_base;
 
@@ -138,12 +137,11 @@ static void pcs_link_timer_callback(unsigned long data)
}
 }
 
-static void auto_nego_timer_callback(unsigned long data)
+static void auto_nego_timer_callback(struct tse_pcs *pcs)
 {
u16 val = 0;
u16 speed = 0;
u16 duplex = 0;
-   struct tse_pcs *pcs = (struct tse_pcs *)data;
void __iomem *tse_pcs_base = pcs->tse_pcs_base;
void __iomem *sgmii_adapter_base = pcs->sgmii_adapter_base;
 
@@ -201,14 +199,14 @@ static void auto_nego_timer_callback(unsigned long data)
}
 }
 
-static void aneg_link_timer_callback(unsigned long data)
+static void aneg_link_timer_callback(struct timer_list *t)
 {
-   struct tse_pcs *pcs = (struct tse_pcs *)data;
+   struct tse_pcs *pcs = from_timer(pcs, t, aneg_link_timer);
 
if (pcs->autoneg == AUTONEG_ENABLE)
-   auto_nego_timer_callback(data);
+   auto_nego_timer_callback(pcs);
else if (pcs->autoneg == AUTONEG_DISABLE)
-   pcs_link_timer_callback(data);
+   pcs_link_timer_callback(pcs);
 }
 
 void tse_pcs_fix_mac_speed(struct tse_pcs *pcs, struct phy_device *phy_dev,
@@ -237,8 +235,8 @@ void tse_pcs_fix_mac_speed(struct tse_pcs *pcs, struct 
phy_device *phy_dev,
 
tse_pcs_reset(tse_pcs_base, pcs);
 
-   setup_timer(>aneg_link_timer,
-   aneg_link_timer_callback, (unsigned long)pcs);
+   timer_setup(>aneg_link_timer, aneg_link_timer_callback,
+   0);
mod_timer(>aneg_link_timer, jiffies +
  msecs_to_jiffies(AUTONEGO_LINK_TIMER));
} else if (phy_dev->autoneg == AUTONEG_DISABLE) {
@@ -270,8 +268,8 @@ void tse_pcs_fix_mac_speed(struct tse_pcs *pcs, struct 
phy_device *phy_dev,
 
tse_pcs_reset(tse_pcs_base, pcs);
 
-   setup_timer(>aneg_link_timer,
-   aneg_link_timer_callback, (unsigned long)pcs);
+   timer_setup(>aneg_link_timer, aneg_link_timer_callback,
+   0);
mod_timer(>aneg_link_timer, jiffies +
  msecs_to_jiffies(AUTONEGO_LINK_TIMER));
}
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] drivers/atm/suni: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. Passes NULL timer when doing non-
timer call.

Cc: Chas Williams <3ch...@gmail.com>
Cc: linux-atm-gene...@lists.sourceforge.net
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/atm/suni.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
index b0363149b2fd..b8825f2d79e0 100644
--- a/drivers/atm/suni.c
+++ b/drivers/atm/suni.c
@@ -53,7 +53,7 @@ static DEFINE_SPINLOCK(sunis_lock);
 if (atomic_read(>s) < 0) atomic_set(>s,INT_MAX);
 
 
-static void suni_hz(unsigned long from_timer)
+static void suni_hz(struct timer_list *timer)
 {
struct suni_priv *walk;
struct atm_dev *dev;
@@ -85,7 +85,7 @@ static void suni_hz(unsigned long from_timer)
((GET(TACP_TCC) & 0xff) << 8) |
((GET(TACP_TCCM) & 7) << 16));
}
-   if (from_timer) mod_timer(_timer,jiffies+HZ);
+   if (timer) mod_timer(_timer,jiffies+HZ);
 }
 
 
@@ -322,13 +322,11 @@ static int suni_start(struct atm_dev *dev)
printk(KERN_WARNING "%s(itf %d): no signal\n",dev->type,
dev->number);
PRIV(dev)->loop_mode = ATM_LM_NONE;
-   suni_hz(0); /* clear SUNI counters */
+   suni_hz(NULL); /* clear SUNI counters */
(void) fetch_stats(dev,NULL,1); /* clear kernel counters */
if (first) {
-   init_timer(_timer);
+   timer_setup(_timer, suni_hz, 0);
poll_timer.expires = jiffies+HZ;
-   poll_timer.function = suni_hz;
-   poll_timer.data = 1;
 #if 0
 printk(KERN_DEBUG "[u] p=0x%lx,n=0x%lx\n",(unsigned long) poll_timer.list.prev,
 (unsigned long) poll_timer.list.next);
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] atm: idt77252: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. This required adding a pointer back
to vc_map, and adjusting the locking around removal a bit.

Cc: Chas Williams <3ch...@gmail.com>
Cc: linux-atm-gene...@lists.sourceforge.net
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/atm/idt77252.c | 21 -
 drivers/atm/idt77252.h |  3 +++
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index 47f3c4ae0594..0e3b9c44c808 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -2073,21 +2073,19 @@ idt77252_rate_logindex(struct idt77252_dev *card, int 
pcr)
 }
 
 static void
-idt77252_est_timer(unsigned long data)
+idt77252_est_timer(struct timer_list *t)
 {
-   struct vc_map *vc = (struct vc_map *)data;
+   struct rate_estimator *est = from_timer(est, t, timer);
+   struct vc_map *vc = est->vc;
struct idt77252_dev *card = vc->card;
-   struct rate_estimator *est;
unsigned long flags;
u32 rate, cps;
u64 ncells;
u8 lacr;
 
spin_lock_irqsave(>lock, flags);
-   est = vc->estimator;
-   if (!est)
+   if (!vc->estimator)
goto out;
-
ncells = est->cells;
 
rate = ((u32)(ncells - est->last_cells)) << (7 - est->interval);
@@ -2126,10 +2124,11 @@ idt77252_init_est(struct vc_map *vc, int pcr)
est->maxcps = pcr < 0 ? -pcr : pcr;
est->cps = est->maxcps;
est->avcps = est->cps << 5;
+   est->vc = vc;
 
est->interval = 2;  /* XXX: make this configurable */
est->ewma_log = 2;  /* XXX: make this configurable */
-   setup_timer(>timer, idt77252_est_timer, (unsigned long)vc);
+   timer_setup(>timer, idt77252_est_timer, 0);
mod_timer(>timer, jiffies + ((HZ / 4) << est->interval));
 
return est;
@@ -2209,16 +2208,20 @@ static int
 idt77252_init_ubr(struct idt77252_dev *card, struct vc_map *vc,
  struct atm_vcc *vcc, struct atm_qos *qos)
 {
+   struct rate_estimator *est = NULL;
unsigned long flags;
int tcr;
 
spin_lock_irqsave(>lock, flags);
if (vc->estimator) {
-   del_timer(>estimator->timer);
-   kfree(vc->estimator);
+   est = vc->estimator;
vc->estimator = NULL;
}
spin_unlock_irqrestore(>lock, flags);
+   if (est) {
+   del_timer_sync(>timer);
+   kfree(est);
+   }
 
tcr = atm_pcr_goal(>txtp);
if (tcr == 0)
diff --git a/drivers/atm/idt77252.h b/drivers/atm/idt77252.h
index 3a82cc23a053..9339197d701c 100644
--- a/drivers/atm/idt77252.h
+++ b/drivers/atm/idt77252.h
@@ -184,6 +184,8 @@ struct aal1 {
unsigned char   sequence;
 };
 
+struct vc_map;
+
 struct rate_estimator {
struct timer_list   timer;
unsigned intinterval;
@@ -193,6 +195,7 @@ struct rate_estimator {
longavcps;
u32 cps;
u32 maxcps;
+   struct vc_map   *vc;
 };
 
 struct vc_map {
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net: tulip: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: David Howells 
Cc: Jarod Wilson 
Cc: Stephen Hemminger 
Cc: Johannes Berg 
Cc: Eric Dumazet 
Cc: Philippe Reynes 
Cc: "yuval.sh...@oracle.com" 
Cc: netdev@vger.kernel.org
Cc: linux-par...@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/dec/tulip/de4x5.c   | 13 ++---
 drivers/net/ethernet/dec/tulip/dmfe.c| 12 +---
 drivers/net/ethernet/dec/tulip/interrupt.c   |  6 +++---
 drivers/net/ethernet/dec/tulip/pnic.c|  6 +++---
 drivers/net/ethernet/dec/tulip/pnic2.c   |  6 +++---
 drivers/net/ethernet/dec/tulip/timer.c   | 12 ++--
 drivers/net/ethernet/dec/tulip/tulip.h   | 12 ++--
 drivers/net/ethernet/dec/tulip/tulip_core.c  | 14 ++
 drivers/net/ethernet/dec/tulip/uli526x.c | 12 +---
 drivers/net/ethernet/dec/tulip/winbond-840.c | 14 ++
 10 files changed, 49 insertions(+), 58 deletions(-)

diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c 
b/drivers/net/ethernet/dec/tulip/de4x5.c
index 0affee9c8aa2..a31b4df3e7ff 100644
--- a/drivers/net/ethernet/dec/tulip/de4x5.c
+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
@@ -912,7 +912,7 @@ static int de4x5_init(struct net_device *dev);
 static int de4x5_sw_reset(struct net_device *dev);
 static int de4x5_rx(struct net_device *dev);
 static int de4x5_tx(struct net_device *dev);
-static voidde4x5_ast(struct net_device *dev);
+static voidde4x5_ast(struct timer_list *t);
 static int de4x5_txur(struct net_device *dev);
 static int de4x5_rx_ovfc(struct net_device *dev);
 
@@ -1147,9 +1147,7 @@ de4x5_hw_init(struct net_device *dev, u_long iobase, 
struct device *gendev)
lp->timeout = -1;
lp->gendev = gendev;
spin_lock_init(>lock);
-   init_timer(>timer);
-   lp->timer.function = (void (*)(unsigned long))de4x5_ast;
-   lp->timer.data = (unsigned long)dev;
+   timer_setup(>timer, de4x5_ast, 0);
de4x5_parse_params(dev);
 
/*
@@ -1742,9 +1740,10 @@ de4x5_tx(struct net_device *dev)
 }
 
 static void
-de4x5_ast(struct net_device *dev)
+de4x5_ast(struct timer_list *t)
 {
-   struct de4x5_private *lp = netdev_priv(dev);
+   struct de4x5_private *lp = from_timer(lp, t, timer);
+   struct net_device *dev = dev_get_drvdata(lp->gendev);
int next_tick = DE4X5_AUTOSENSE_MS;
int dt;
 
@@ -2370,7 +2369,7 @@ autoconf_media(struct net_device *dev)
lp->media = INIT;
lp->tcount = 0;
 
-   de4x5_ast(dev);
+   de4x5_ast(>timer);
 
return lp->media;
 }
diff --git a/drivers/net/ethernet/dec/tulip/dmfe.c 
b/drivers/net/ethernet/dec/tulip/dmfe.c
index 07e10a45beaa..17ef7a28873d 100644
--- a/drivers/net/ethernet/dec/tulip/dmfe.c
+++ b/drivers/net/ethernet/dec/tulip/dmfe.c
@@ -331,7 +331,7 @@ static void dmfe_phy_write_1bit(void __iomem *, u32);
 static u16 dmfe_phy_read_1bit(void __iomem *);
 static u8 dmfe_sense_speed(struct dmfe_board_info *);
 static void dmfe_process_mode(struct dmfe_board_info *);
-static void dmfe_timer(unsigned long);
+static void dmfe_timer(struct timer_list *);
 static inline u32 cal_CRC(unsigned char *, unsigned int, u8);
 static void dmfe_rx_packet(struct net_device *, struct dmfe_board_info *);
 static void dmfe_free_tx_pkt(struct net_device *, struct dmfe_board_info *);
@@ -596,10 +596,8 @@ static int dmfe_open(struct net_device *dev)
netif_wake_queue(dev);
 
/* set and active a timer process */
-   init_timer(>timer);
+   timer_setup(>timer, dmfe_timer, 0);
db->timer.expires = DMFE_TIMER_WUT + HZ * 2;
-   db->timer.data = (unsigned long)dev;
-   db->timer.function = dmfe_timer;
add_timer(>timer);
 
return 0;
@@ -1130,10 +1128,10 @@ static const struct ethtool_ops netdev_ethtool_ops = {
  * Dynamic media sense, allocate Rx buffer...
  */
 
-static void dmfe_timer(unsigned long data)
+static void dmfe_timer(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)data;
-   struct dmfe_board_info *db = netdev_priv(dev);
+   struct dmfe_board_info *db = from_timer(db, t, timer);
+   struct net_device *dev = pci_get_drvdata(db->pdev);
void __iomem *ioaddr = db->ioaddr;
u32 tmp_cr8;
unsigned char tmp_cr12;
diff --git a/drivers/net/ethernet/dec/tulip/interrupt.c 
b/drivers/net/ethernet/dec/tulip/interrupt.c

[PATCH] chelsio: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Johannes Berg 
Cc: Eric Dumazet 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/chelsio/cxgb/sge.c | 30 +-
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb/sge.c 
b/drivers/net/ethernet/chelsio/cxgb/sge.c
index 0f13a7f7c1d3..30de26ef3da4 100644
--- a/drivers/net/ethernet/chelsio/cxgb/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb/sge.c
@@ -1882,10 +1882,10 @@ netdev_tx_t t1_start_xmit(struct sk_buff *skb, struct 
net_device *dev)
 /*
  * Callback for the Tx buffer reclaim timer.  Runs with softirqs disabled.
  */
-static void sge_tx_reclaim_cb(unsigned long data)
+static void sge_tx_reclaim_cb(struct timer_list *t)
 {
int i;
-   struct sge *sge = (struct sge *)data;
+   struct sge *sge = from_timer(sge, t, tx_reclaim_timer);
 
for (i = 0; i < SGE_CMDQ_N; ++i) {
struct cmdQ *q = >cmdQ[i];
@@ -1978,10 +1978,10 @@ void t1_sge_start(struct sge *sge)
 /*
  * Callback for the T2 ESPI 'stuck packet feature' workaorund
  */
-static void espibug_workaround_t204(unsigned long data)
+static void espibug_workaround_t204(struct timer_list *t)
 {
-   struct adapter *adapter = (struct adapter *)data;
-   struct sge *sge = adapter->sge;
+   struct sge *sge = from_timer(sge, t, espibug_timer);
+   struct adapter *adapter = sge->adapter;
unsigned int nports = adapter->params.nports;
u32 seop[MAX_NPORTS];
 
@@ -2021,10 +2021,10 @@ static void espibug_workaround_t204(unsigned long data)
mod_timer(>espibug_timer, jiffies + sge->espibug_timeout);
 }
 
-static void espibug_workaround(unsigned long data)
+static void espibug_workaround(struct timer_list *t)
 {
-   struct adapter *adapter = (struct adapter *)data;
-   struct sge *sge = adapter->sge;
+   struct sge *sge = from_timer(sge, t, espibug_timer);
+   struct adapter *adapter = sge->adapter;
 
if (netif_running(adapter->port[0].dev)) {
struct sk_buff *skb = sge->espibug_skb[0];
@@ -2075,19 +2075,15 @@ struct sge *t1_sge_create(struct adapter *adapter, 
struct sge_params *p)
goto nomem_port;
}
 
-   init_timer(>tx_reclaim_timer);
-   sge->tx_reclaim_timer.data = (unsigned long)sge;
-   sge->tx_reclaim_timer.function = sge_tx_reclaim_cb;
+   timer_setup(>tx_reclaim_timer, sge_tx_reclaim_cb, 0);
 
if (is_T2(sge->adapter)) {
-   init_timer(>espibug_timer);
+   timer_setup(>espibug_timer,
+   adapter->params.nports > 1 ? 
espibug_workaround_t204 : espibug_workaround,
+   0);
 
-   if (adapter->params.nports > 1) {
+   if (adapter->params.nports > 1)
tx_sched_init(sge);
-   sge->espibug_timer.function = espibug_workaround_t204;
-   } else
-   sge->espibug_timer.function = espibug_workaround;
-   sge->espibug_timer.data = (unsigned long)sge->adapter;
 
sge->espibug_timeout = 1;
/* for T204, every 10ms */
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net: can: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Oliver Hartkopp 
Cc: Marc Kleine-Budde 
Cc: "David S. Miller" 
Cc: linux-...@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 net/can/af_can.c | 4 ++--
 net/can/af_can.h | 2 +-
 net/can/proc.c   | 8 
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index 88edac0f3e36..1f75e11ac35a 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -882,8 +882,8 @@ static int can_pernet_init(struct net *net)
if (IS_ENABLED(CONFIG_PROC_FS)) {
/* the statistics are updated every second (timer triggered) */
if (stats_timer) {
-   setup_timer(>can.can_stattimer, can_stat_update,
-   (unsigned long)net);
+   timer_setup(>can.can_stattimer, can_stat_update,
+   0);
mod_timer(>can.can_stattimer,
  round_jiffies(jiffies + HZ));
}
diff --git a/net/can/af_can.h b/net/can/af_can.h
index d0ef45bb2a72..eca6463c6213 100644
--- a/net/can/af_can.h
+++ b/net/can/af_can.h
@@ -113,6 +113,6 @@ struct s_pstats {
 /* function prototypes for the CAN networklayer procfs (proc.c) */
 void can_init_proc(struct net *net);
 void can_remove_proc(struct net *net);
-void can_stat_update(unsigned long data);
+void can_stat_update(struct timer_list *t);
 
 #endif /* AF_CAN_H */
diff --git a/net/can/proc.c b/net/can/proc.c
index 83045f00c63c..d979b3dc49a6 100644
--- a/net/can/proc.c
+++ b/net/can/proc.c
@@ -115,9 +115,9 @@ static unsigned long calc_rate(unsigned long oldjif, 
unsigned long newjif,
return rate;
 }
 
-void can_stat_update(unsigned long data)
+void can_stat_update(struct timer_list *t)
 {
-   struct net *net = (struct net *)data;
+   struct net *net = from_timer(net, t, can.can_stattimer);
struct s_stats *can_stats = net->can.can_stats;
unsigned long j = jiffies; /* snapshot */
 
@@ -221,7 +221,7 @@ static int can_stats_proc_show(struct seq_file *m, void *v)
 
seq_putc(m, '\n');
 
-   if (net->can.can_stattimer.function == can_stat_update) {
+   if (net->can.can_stattimer.function == 
(TIMER_FUNC_TYPE)can_stat_update) {
seq_printf(m, " %8ld %% total match ratio (RXMR)\n",
can_stats->total_rx_match_ratio);
 
@@ -291,7 +291,7 @@ static int can_reset_stats_proc_show(struct seq_file *m, 
void *v)
 
user_reset = 1;
 
-   if (net->can.can_stattimer.function == can_stat_update) {
+   if (net->can.can_stattimer.function == 
(TIMER_FUNC_TYPE)can_stat_update) {
seq_printf(m, "Scheduled statistic reset #%ld.\n",
can_pstats->stats_reset + 1);
} else {
-- 
2.7.4


-- 
Kees Cook
Pixel Security


Re: [PATCH 05/13] timer: Remove init_timer_deferrable() in favor of timer_setup()

2017-10-04 Thread Sebastian Reichel
Hi,

On Wed, Oct 04, 2017 at 04:26:59PM -0700, Kees Cook wrote:
> This refactors the only users of init_timer_deferrable() to use
> the new timer_setup() and from_timer(). Removes definition of
> init_timer_deferrable().

[...]

>  drivers/hsi/clients/ssi_protocol.c   | 32 
> 

Acked-by: Sebastian Reichel 

-- Sebastian


signature.asc
Description: PGP signature


[PATCH] net: amd8111e: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Eric Dumazet 
Cc: Jarod Wilson 
Cc: Philippe Reynes 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/amd/amd8111e.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/amd/amd8111e.c 
b/drivers/net/ethernet/amd/amd8111e.c
index 7b5df562f30f..358f7ab77c70 100644
--- a/drivers/net/ethernet/amd/amd8111e.c
+++ b/drivers/net/ethernet/amd/amd8111e.c
@@ -1669,9 +1669,9 @@ static int amd8111e_resume(struct pci_dev *pci_dev)
return 0;
 }
 
-static void amd8111e_config_ipg(struct net_device *dev)
+static void amd8111e_config_ipg(struct timer_list *t)
 {
-   struct amd8111e_priv *lp = netdev_priv(dev);
+   struct amd8111e_priv *lp = from_timer(lp, t, ipg_data.ipg_timer);
struct ipg_info *ipg_data = >ipg_data;
void __iomem *mmio = lp->mmio;
unsigned int prev_col_cnt = ipg_data->col_cnt;
@@ -1883,9 +1883,7 @@ static int amd8111e_probe_one(struct pci_dev *pdev,
 
/* Initialize software ipg timer */
if(lp->options & OPTION_DYN_IPG_ENABLE){
-   init_timer(>ipg_data.ipg_timer);
-   lp->ipg_data.ipg_timer.data = (unsigned long) dev;
-   lp->ipg_data.ipg_timer.function = (void *)_config_ipg;
+   timer_setup(>ipg_data.ipg_timer, amd8111e_config_ipg, 0);
lp->ipg_data.ipg_timer.expires = jiffies +
 IPG_CONVERGE_JIFFIES;
lp->ipg_data.ipg = DEFAULT_IPG;
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] drivers/net/3com: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Steffen Klassert 
Cc: "David S. Miller" 
Cc: Jarod Wilson 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/3com/3c574_cs.c | 12 +---
 drivers/net/ethernet/3com/3c589_cs.c | 10 +-
 drivers/net/ethernet/3com/3c59x.c| 20 ++--
 3 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/3com/3c574_cs.c 
b/drivers/net/ethernet/3com/3c574_cs.c
index 47c844cc9d27..48bc7fa0258c 100644
--- a/drivers/net/ethernet/3com/3c574_cs.c
+++ b/drivers/net/ethernet/3com/3c574_cs.c
@@ -225,7 +225,7 @@ static unsigned short read_eeprom(unsigned int ioaddr, int 
index);
 static void tc574_wait_for_completion(struct net_device *dev, int cmd);
 
 static void tc574_reset(struct net_device *dev);
-static void media_check(unsigned long arg);
+static void media_check(struct timer_list *t);
 static int el3_open(struct net_device *dev);
 static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
struct net_device *dev);
@@ -377,7 +377,7 @@ static int tc574_config(struct pcmcia_device *link)
lp->autoselect = config & Autoselect ? 1 : 0;
}
 
-   init_timer(>media);
+   timer_setup(>media, media_check, 0);
 
{
int phy;
@@ -681,8 +681,6 @@ static int el3_open(struct net_device *dev)
netif_start_queue(dev);

tc574_reset(dev);
-   lp->media.function = media_check;
-   lp->media.data = (unsigned long) dev;
lp->media.expires = jiffies + HZ;
add_timer(>media);

@@ -859,10 +857,10 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
(and as a last resort, poll the NIC for events), and to monitor
the MII, reporting changes in cable status.
 */
-static void media_check(unsigned long arg)
+static void media_check(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *) arg;
-   struct el3_private *lp = netdev_priv(dev);
+   struct el3_private *lp = from_timer(lp, t, media);
+   struct net_device *dev = lp->p_dev->priv;
unsigned int ioaddr = dev->base_addr;
unsigned long flags;
unsigned short /* cable, */ media, partner;
diff --git a/drivers/net/ethernet/3com/3c589_cs.c 
b/drivers/net/ethernet/3com/3c589_cs.c
index e28254a00599..2b2695311bda 100644
--- a/drivers/net/ethernet/3com/3c589_cs.c
+++ b/drivers/net/ethernet/3com/3c589_cs.c
@@ -163,7 +163,7 @@ static void tc589_release(struct pcmcia_device *link);
 
 static u16 read_eeprom(unsigned int ioaddr, int index);
 static void tc589_reset(struct net_device *dev);
-static void media_check(unsigned long arg);
+static void media_check(struct timer_list *t);
 static int el3_config(struct net_device *dev, struct ifmap *map);
 static int el3_open(struct net_device *dev);
 static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
@@ -517,7 +517,7 @@ static int el3_open(struct net_device *dev)
netif_start_queue(dev);
 
tc589_reset(dev);
-   setup_timer(>media, media_check, (unsigned long)dev);
+   timer_setup(>media, media_check, 0);
mod_timer(>media, jiffies + HZ);
 
dev_dbg(>dev, "%s: opened, status %4.4x.\n",
@@ -676,10 +676,10 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
return IRQ_RETVAL(handled);
 }
 
-static void media_check(unsigned long arg)
+static void media_check(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)(arg);
-   struct el3_private *lp = netdev_priv(dev);
+   struct el3_private *lp = from_timer(lp, t, media);
+   struct net_device *dev = lp->p_dev->priv;
unsigned int ioaddr = dev->base_addr;
u16 media, errs;
unsigned long flags;
diff --git a/drivers/net/ethernet/3com/3c59x.c 
b/drivers/net/ethernet/3com/3c59x.c
index 402d9090ad29..f4e13a7014bd 100644
--- a/drivers/net/ethernet/3com/3c59x.c
+++ b/drivers/net/ethernet/3com/3c59x.c
@@ -759,8 +759,8 @@ static int vortex_open(struct net_device *dev);
 static void mdio_sync(struct vortex_private *vp, int bits);
 static int mdio_read(struct net_device *dev, int phy_id, int location);
 static void mdio_write(struct net_device *vp, int phy_id, int location, int 
value);
-static void vortex_timer(unsigned long arg);
-static void rx_oom_timer(unsigned long arg);
+static void vortex_timer(struct timer_list *t);
+static void rx_oom_timer(struct timer_list *t);
 static netdev_tx_t vortex_start_xmit(struct sk_buff *skb,
  

[PATCH] net/mlx4_core: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Tariq Toukan 
Cc: netdev@vger.kernel.org
Cc: linux-r...@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/mellanox/mlx4/catas.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/catas.c 
b/drivers/net/ethernet/mellanox/mlx4/catas.c
index 53daa6ca5d83..e2b6b0cac1ac 100644
--- a/drivers/net/ethernet/mellanox/mlx4/catas.c
+++ b/drivers/net/ethernet/mellanox/mlx4/catas.c
@@ -231,10 +231,10 @@ static void dump_err_buf(struct mlx4_dev *dev)
 i, swab32(readl(priv->catas_err.map + i)));
 }
 
-static void poll_catas(unsigned long dev_ptr)
+static void poll_catas(struct timer_list *t)
 {
-   struct mlx4_dev *dev = (struct mlx4_dev *) dev_ptr;
-   struct mlx4_priv *priv = mlx4_priv(dev);
+   struct mlx4_priv *priv = from_timer(priv, t, catas_err.timer);
+   struct mlx4_dev *dev = >dev;
u32 slave_read;
 
if (mlx4_is_slave(dev)) {
@@ -277,7 +277,7 @@ void mlx4_start_catas_poll(struct mlx4_dev *dev)
phys_addr_t addr;
 
INIT_LIST_HEAD(>catas_err.list);
-   init_timer(>catas_err.timer);
+   timer_setup(>catas_err.timer, poll_catas, 0);
priv->catas_err.map = NULL;
 
if (!mlx4_is_slave(dev)) {
@@ -293,8 +293,6 @@ void mlx4_start_catas_poll(struct mlx4_dev *dev)
}
}
 
-   priv->catas_err.timer.data = (unsigned long) dev;
-   priv->catas_err.timer.function = poll_catas;
priv->catas_err.timer.expires  =
round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL);
add_timer(>catas_err.timer);
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net: dl2k: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Jarod Wilson 
Cc: Tobias Klauser 
Cc: Philippe Reynes 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/dlink/dl2k.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/dlink/dl2k.c 
b/drivers/net/ethernet/dlink/dl2k.c
index 778f974e2928..a2f6758d38dd 100644
--- a/drivers/net/ethernet/dlink/dl2k.c
+++ b/drivers/net/ethernet/dlink/dl2k.c
@@ -68,7 +68,7 @@ static const int max_intrloop = 50;
 static const int multicast_filter_limit = 0x40;
 
 static int rio_open (struct net_device *dev);
-static void rio_timer (unsigned long data);
+static void rio_timer (struct timer_list *t);
 static void rio_tx_timeout (struct net_device *dev);
 static netdev_tx_t start_xmit (struct sk_buff *skb, struct net_device *dev);
 static irqreturn_t rio_interrupt (int irq, void *dev_instance);
@@ -644,7 +644,7 @@ static int rio_open(struct net_device *dev)
return i;
}
 
-   setup_timer(>timer, rio_timer, (unsigned long)dev);
+   timer_setup(>timer, rio_timer, 0);
np->timer.expires = jiffies + 1 * HZ;
add_timer(>timer);
 
@@ -655,10 +655,10 @@ static int rio_open(struct net_device *dev)
 }
 
 static void
-rio_timer (unsigned long data)
+rio_timer (struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *)data;
-   struct netdev_private *np = netdev_priv(dev);
+   struct netdev_private *np = from_timer(np, t, timer);
+   struct net_device *dev = pci_get_drvdata(np->pdev);
unsigned int entry;
int next_tick = 1*HZ;
unsigned long flags;
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] mISDN: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Karsten Keil 
Cc: Geliang Tang 
Cc: "David S. Miller" 
Cc: Masahiro Yamada 
Cc: Andrew Morton 
Cc: Anton Vasilyev 
Cc: Ingo Molnar 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/isdn/mISDN/dsp.h|  2 +-
 drivers/isdn/mISDN/dsp_core.c   |  6 ++
 drivers/isdn/mISDN/dsp_tones.c  |  4 ++--
 drivers/isdn/mISDN/fsm.c|  5 +++--
 drivers/isdn/mISDN/l1oip_core.c | 15 +++
 drivers/isdn/mISDN/timerdev.c   |  6 +++---
 6 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/drivers/isdn/mISDN/dsp.h b/drivers/isdn/mISDN/dsp.h
index fc1733a08845..fa09d511a8ed 100644
--- a/drivers/isdn/mISDN/dsp.h
+++ b/drivers/isdn/mISDN/dsp.h
@@ -259,7 +259,7 @@ extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 
*data, int len,
 
 extern int dsp_tone(struct dsp *dsp, int tone);
 extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len);
-extern void dsp_tone_timeout(void *arg);
+extern void dsp_tone_timeout(struct timer_list *t);
 
 extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len);
 extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len);
diff --git a/drivers/isdn/mISDN/dsp_core.c b/drivers/isdn/mISDN/dsp_core.c
index 880e9d367a39..cd036e87335a 100644
--- a/drivers/isdn/mISDN/dsp_core.c
+++ b/drivers/isdn/mISDN/dsp_core.c
@@ -1092,7 +1092,7 @@ dspcreate(struct channel_req *crq)
ndsp->pcm_bank_tx = -1;
ndsp->hfc_conf = -1; /* current conference number */
/* set tone timer */
-   setup_timer(>tone.tl, (void *)dsp_tone_timeout, (long)ndsp);
+   timer_setup(>tone.tl, dsp_tone_timeout, 0);
 
if (dtmfthreshold < 20 || dtmfthreshold > 500)
dtmfthreshold = 200;
@@ -1202,9 +1202,7 @@ static int __init dsp_init(void)
}
 
/* set sample timer */
-   dsp_spl_tl.function = (void *)dsp_cmx_send;
-   dsp_spl_tl.data = 0;
-   init_timer(_spl_tl);
+   timer_setup(_spl_tl, (void *)dsp_cmx_send, 0);
dsp_spl_tl.expires = jiffies + dsp_tics;
dsp_spl_jiffies = dsp_spl_tl.expires;
add_timer(_spl_tl);
diff --git a/drivers/isdn/mISDN/dsp_tones.c b/drivers/isdn/mISDN/dsp_tones.c
index 057e0d6a369b..263e8886703d 100644
--- a/drivers/isdn/mISDN/dsp_tones.c
+++ b/drivers/isdn/mISDN/dsp_tones.c
@@ -457,9 +457,9 @@ dsp_tone_hw_message(struct dsp *dsp, u8 *sample, int len)
  * timer expires *
  */
 void
-dsp_tone_timeout(void *arg)
+dsp_tone_timeout(struct timer_list *t)
 {
-   struct dsp *dsp = arg;
+   struct dsp *dsp = from_timer(dsp, t, tone.tl);
struct dsp_tone *tone = >tone;
struct pattern *pat = (struct pattern *)tone->pattern;
int index = tone->index;
diff --git a/drivers/isdn/mISDN/fsm.c b/drivers/isdn/mISDN/fsm.c
index 92e6570b1143..613df2638eab 100644
--- a/drivers/isdn/mISDN/fsm.c
+++ b/drivers/isdn/mISDN/fsm.c
@@ -100,8 +100,9 @@ mISDN_FsmChangeState(struct FsmInst *fi, int newstate)
 EXPORT_SYMBOL(mISDN_FsmChangeState);
 
 static void
-FsmExpireTimer(struct FsmTimer *ft)
+FsmExpireTimer(struct timer_list *t)
 {
+   struct FsmTimer *ft = from_timer(ft, t, tl);
 #if FSM_TIMER_DEBUG
if (ft->fi->debug)
ft->fi->printdebug(ft->fi, "FsmExpireTimer %lx", (long) ft);
@@ -117,7 +118,7 @@ mISDN_FsmInitTimer(struct FsmInst *fi, struct FsmTimer *ft)
if (ft->fi->debug)
ft->fi->printdebug(ft->fi, "mISDN_FsmInitTimer %lx", (long) ft);
 #endif
-   setup_timer(>tl, (void *)FsmExpireTimer, (long)ft);
+   timer_setup(>tl, FsmExpireTimer, 0);
 }
 EXPORT_SYMBOL(mISDN_FsmInitTimer);
 
diff --git a/drivers/isdn/mISDN/l1oip_core.c b/drivers/isdn/mISDN/l1oip_core.c
index 6be2041248d3..b5d590e378ac 100644
--- a/drivers/isdn/mISDN/l1oip_core.c
+++ b/drivers/isdn/mISDN/l1oip_core.c
@@ -842,17 +842,18 @@ l1oip_send_bh(struct work_struct *work)
  * timer stuff
  */
 static void
-l1oip_keepalive(void *data)
+l1oip_keepalive(struct timer_list *t)
 {
-   struct l1oip *hc = (struct l1oip *)data;
+   struct l1oip *hc = from_timer(hc, t, keep_tl);
 
schedule_work(>workq);
 }
 
 static void
-l1oip_timeout(void *data)
+l1oip_timeout(struct timer_list *t)
 {
-   struct l1oip*hc = (struct l1oip *)data;
+   struct l1oip*hc = from_timer(hc, t,
+ timeout_tl);
struct dchannel *dch = 

[PATCH] net: ksz884x: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Johannes Berg 
Cc: Jarod Wilson 
Cc: Masahiro Yamada 
Cc: Philippe Reynes 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/micrel/ksz884x.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/micrel/ksz884x.c 
b/drivers/net/ethernet/micrel/ksz884x.c
index e798fbe08600..52207508744c 100644
--- a/drivers/net/ethernet/micrel/ksz884x.c
+++ b/drivers/net/ethernet/micrel/ksz884x.c
@@ -4338,11 +4338,11 @@ static void ksz_stop_timer(struct ksz_timer_info *info)
 }
 
 static void ksz_init_timer(struct ksz_timer_info *info, int period,
-   void (*function)(unsigned long), void *data)
+   void (*function)(struct timer_list *))
 {
info->max = 0;
info->period = period;
-   setup_timer(>timer, function, (unsigned long)data);
+   timer_setup(>timer, function, 0);
 }
 
 static void ksz_update_timer(struct ksz_timer_info *info)
@@ -6689,9 +6689,9 @@ static void mib_read_work(struct work_struct *work)
}
 }
 
-static void mib_monitor(unsigned long ptr)
+static void mib_monitor(struct timer_list *t)
 {
-   struct dev_info *hw_priv = (struct dev_info *) ptr;
+   struct dev_info *hw_priv = from_timer(hw_priv, t, mib_timer_info.timer);
 
mib_read_work(_priv->mib_read);
 
@@ -6716,10 +6716,10 @@ static void mib_monitor(unsigned long ptr)
  *
  * This routine is run in a kernel timer to monitor the network device.
  */
-static void dev_monitor(unsigned long ptr)
+static void dev_monitor(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *) ptr;
-   struct dev_priv *priv = netdev_priv(dev);
+   struct dev_priv *priv = from_timer(priv, t, monitor_timer_info.timer);
+   struct net_device *dev = priv->mii_if.dev;
struct dev_info *hw_priv = priv->adapter;
struct ksz_hw *hw = _priv->hw;
struct ksz_port *port = >port;
@@ -6789,7 +6789,7 @@ static int __init netdev_init(struct net_device *dev)
 
/* 500 ms timeout */
ksz_init_timer(>monitor_timer_info, 500 * HZ / 1000,
-   dev_monitor, dev);
+   dev_monitor);
 
/* 500 ms timeout */
dev->watchdog_timeo = HZ / 2;
@@ -7065,7 +7065,7 @@ static int pcidev_init(struct pci_dev *pdev, const struct 
pci_device_id *id)
 
/* 500 ms timeout */
ksz_init_timer(_priv->mib_timer_info, 500 * HZ / 1000,
-   mib_monitor, hw_priv);
+   mib_monitor);
 
for (i = 0; i < hw->dev_count; i++) {
dev = alloc_etherdev(sizeof(struct dev_priv));
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] isdn/gigaset: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. Also uses kzmalloc to replace open-
coded field assignments to NULL and zero.

Cc: Paul Bolle 
Cc: Karsten Keil 
Cc: "David S. Miller" 
Cc: Johan Hovold 
Cc: gigaset307x-com...@lists.sourceforge.net
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/isdn/gigaset/bas-gigaset.c | 45 ++
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/drivers/isdn/gigaset/bas-gigaset.c 
b/drivers/isdn/gigaset/bas-gigaset.c
index 2da3ff650e1d..f92a0d972ce7 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -433,10 +433,11 @@ static void check_pending(struct bas_cardstate *ucs)
  * argument:
  * controller state structure
  */
-static void cmd_in_timeout(unsigned long data)
+static void cmd_in_timeout(struct timer_list *t)
 {
-   struct cardstate *cs = (struct cardstate *) data;
-   struct bas_cardstate *ucs = cs->hw.bas;
+   struct bas_cardstate *ucs = from_timer(ucs, t, timer_cmd_in);
+   struct urb *urb = ucs->urb_int_in;
+   struct cardstate *cs = urb->context;
int rc;
 
if (!ucs->rcvbuf_size) {
@@ -639,10 +640,11 @@ static void int_in_work(struct work_struct *work)
  * argument:
  * controller state structure
  */
-static void int_in_resubmit(unsigned long data)
+static void int_in_resubmit(struct timer_list *t)
 {
-   struct cardstate *cs = (struct cardstate *) data;
-   struct bas_cardstate *ucs = cs->hw.bas;
+   struct bas_cardstate *ucs = from_timer(ucs, t, timer_int_in);
+   struct urb *urb = ucs->urb_int_in;
+   struct cardstate *cs = urb->context;
int rc;
 
if (ucs->retry_int_in++ >= BAS_RETRY) {
@@ -1441,10 +1443,11 @@ static void read_iso_tasklet(unsigned long data)
  * argument:
  * controller state structure
  */
-static void req_timeout(unsigned long data)
+static void req_timeout(struct timer_list *t)
 {
-   struct cardstate *cs = (struct cardstate *) data;
-   struct bas_cardstate *ucs = cs->hw.bas;
+   struct bas_cardstate *ucs = from_timer(ucs, t, timer_ctrl);
+   struct urb *urb = ucs->urb_int_in;
+   struct cardstate *cs = urb->context;
int pending;
unsigned long flags;
 
@@ -1837,10 +1840,11 @@ static void write_command_callback(struct urb *urb)
  * argument:
  * controller state structure
  */
-static void atrdy_timeout(unsigned long data)
+static void atrdy_timeout(struct timer_list *t)
 {
-   struct cardstate *cs = (struct cardstate *) data;
-   struct bas_cardstate *ucs = cs->hw.bas;
+   struct bas_cardstate *ucs = from_timer(ucs, t, timer_atrdy);
+   struct urb *urb = ucs->urb_int_in;
+   struct cardstate *cs = urb->context;
 
dev_warn(cs->dev, "timeout waiting for HD_READY_SEND_ATDATA\n");
 
@@ -2200,7 +2204,7 @@ static int gigaset_initcshw(struct cardstate *cs)
 {
struct bas_cardstate *ucs;
 
-   cs->hw.bas = ucs = kmalloc(sizeof *ucs, GFP_KERNEL);
+   cs->hw.bas = ucs = kzalloc(sizeof *ucs, GFP_KERNEL);
if (!ucs) {
pr_err("out of memory\n");
return -ENOMEM;
@@ -2212,19 +2216,12 @@ static int gigaset_initcshw(struct cardstate *cs)
return -ENOMEM;
}
 
-   ucs->urb_cmd_in = NULL;
-   ucs->urb_cmd_out = NULL;
-   ucs->rcvbuf = NULL;
-   ucs->rcvbuf_size = 0;
-
spin_lock_init(>lock);
-   ucs->pending = 0;
 
-   ucs->basstate = 0;
-   setup_timer(>timer_ctrl, req_timeout, (unsigned long) cs);
-   setup_timer(>timer_atrdy, atrdy_timeout, (unsigned long) cs);
-   setup_timer(>timer_cmd_in, cmd_in_timeout, (unsigned long) cs);
-   setup_timer(>timer_int_in, int_in_resubmit, (unsigned long) cs);
+   timer_setup(>timer_ctrl, req_timeout, 0);
+   timer_setup(>timer_atrdy, atrdy_timeout, 0);
+   timer_setup(>timer_cmd_in, cmd_in_timeout, 0);
+   timer_setup(>timer_int_in, int_in_resubmit, 0);
init_waitqueue_head(>waitqueue);
INIT_WORK(>int_in_wq, int_in_work);
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net: sched: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. Add pointer back to Qdisc.

Cc: Jamal Hadi Salim 
Cc: Cong Wang 
Cc: Jiri Pirko 
Cc: "David S. Miller" 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 net/sched/sch_pie.c | 10 ++
 net/sched/sch_red.c | 10 ++
 net/sched/sch_sfq.c | 10 +-
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/net/sched/sch_pie.c b/net/sched/sch_pie.c
index 6c2791d6102d..776c694c77c7 100644
--- a/net/sched/sch_pie.c
+++ b/net/sched/sch_pie.c
@@ -74,6 +74,7 @@ struct pie_sched_data {
struct pie_vars vars;
struct pie_stats stats;
struct timer_list adapt_timer;
+   struct Qdisc *sch;
 };
 
 static void pie_params_init(struct pie_params *params)
@@ -422,10 +423,10 @@ static void calculate_probability(struct Qdisc *sch)
pie_vars_init(>vars);
 }
 
-static void pie_timer(unsigned long arg)
+static void pie_timer(struct timer_list *t)
 {
-   struct Qdisc *sch = (struct Qdisc *)arg;
-   struct pie_sched_data *q = qdisc_priv(sch);
+   struct pie_sched_data *q = from_timer(q, t, adapt_timer);
+   struct Qdisc *sch = q->sch;
spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch));
 
spin_lock(root_lock);
@@ -446,7 +447,8 @@ static int pie_init(struct Qdisc *sch, struct nlattr *opt)
pie_vars_init(>vars);
sch->limit = q->params.limit;
 
-   setup_timer(>adapt_timer, pie_timer, (unsigned long)sch);
+   q->sch = sch;
+   timer_setup(>adapt_timer, pie_timer, 0);
 
if (opt) {
int err = pie_change(sch, opt);
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index 93b9d70a9b28..fdfdb56aaae2 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -40,6 +40,7 @@ struct red_sched_data {
u32 limit;  /* HARD maximal queue length */
unsigned char   flags;
struct timer_list   adapt_timer;
+   struct Qdisc*sch;
struct red_parmsparms;
struct red_vars vars;
struct red_statsstats;
@@ -221,10 +222,10 @@ static int red_change(struct Qdisc *sch, struct nlattr 
*opt)
return 0;
 }
 
-static inline void red_adaptative_timer(unsigned long arg)
+static inline void red_adaptative_timer(struct timer_list *t)
 {
-   struct Qdisc *sch = (struct Qdisc *)arg;
-   struct red_sched_data *q = qdisc_priv(sch);
+   struct red_sched_data *q = from_timer(q, t, adapt_timer);
+   struct Qdisc *sch = q->sch;
spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch));
 
spin_lock(root_lock);
@@ -238,7 +239,8 @@ static int red_init(struct Qdisc *sch, struct nlattr *opt)
struct red_sched_data *q = qdisc_priv(sch);
 
q->qdisc = _qdisc;
-   setup_timer(>adapt_timer, red_adaptative_timer, (unsigned long)sch);
+   q->sch = sch;
+   timer_setup(>adapt_timer, red_adaptative_timer, 0);
return red_change(sch, opt);
 }
 
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index 74ea863b8240..42293412dc25 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -145,6 +145,7 @@ struct sfq_sched_data {
int perturb_period;
unsigned intquantum;/* Allotment per round: MUST BE >= MTU 
*/
struct timer_list perturb_timer;
+   struct Qdisc*sch;
 };
 
 /*
@@ -604,10 +605,10 @@ static void sfq_rehash(struct Qdisc *sch)
qdisc_tree_reduce_backlog(sch, dropped, drop_len);
 }
 
-static void sfq_perturbation(unsigned long arg)
+static void sfq_perturbation(struct timer_list *t)
 {
-   struct Qdisc *sch = (struct Qdisc *)arg;
-   struct sfq_sched_data *q = qdisc_priv(sch);
+   struct sfq_sched_data *q = from_timer(q, t, perturb_timer);
+   struct Qdisc *sch = q->sch;
spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch));
 
spin_lock(root_lock);
@@ -722,8 +723,7 @@ static int sfq_init(struct Qdisc *sch, struct nlattr *opt)
int i;
int err;
 
-   setup_deferrable_timer(>perturb_timer, sfq_perturbation,
-  (unsigned long)sch);
+   timer_setup(>perturb_timer, sfq_perturbation, TIMER_DEFERRABLE);
 
err = tcf_block_get(>block, >filter_list);
if (err)
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] inet/connection_sock: Convert timers to use

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Gerrit Renker 
Cc: Alexey Kuznetsov 
Cc: Hideaki YOSHIFUJI 
Cc: netdev@vger.kernel.org
Cc: d...@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 include/net/inet_connection_sock.h |  6 +++---
 net/dccp/timer.c   | 18 ++
 net/ipv4/inet_connection_sock.c| 14 ++
 net/ipv4/tcp_timer.c   | 18 +++---
 4 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/include/net/inet_connection_sock.h 
b/include/net/inet_connection_sock.h
index 13e4c89a8231..0358745ea059 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -169,9 +169,9 @@ enum inet_csk_ack_state_t {
 };
 
 void inet_csk_init_xmit_timers(struct sock *sk,
-  void (*retransmit_handler)(unsigned long),
-  void (*delack_handler)(unsigned long),
-  void (*keepalive_handler)(unsigned long));
+  void (*retransmit_handler)(struct timer_list *),
+  void (*delack_handler)(struct timer_list *),
+  void (*keepalive_handler)(struct timer_list *));
 void inet_csk_clear_xmit_timers(struct sock *sk);
 
 static inline void inet_csk_schedule_ack(struct sock *sk)
diff --git a/net/dccp/timer.c b/net/dccp/timer.c
index 3a2c34027758..1e35526bf436 100644
--- a/net/dccp/timer.c
+++ b/net/dccp/timer.c
@@ -125,10 +125,11 @@ static void dccp_retransmit_timer(struct sock *sk)
__sk_dst_reset(sk);
 }
 
-static void dccp_write_timer(unsigned long data)
+static void dccp_write_timer(struct timer_list *t)
 {
-   struct sock *sk = (struct sock *)data;
-   struct inet_connection_sock *icsk = inet_csk(sk);
+   struct inet_connection_sock *icsk =
+   from_timer(icsk, t, icsk_retransmit_timer);
+   struct sock *sk = >icsk_inet.sk;
int event = 0;
 
bh_lock_sock(sk);
@@ -161,19 +162,20 @@ static void dccp_write_timer(unsigned long data)
sock_put(sk);
 }
 
-static void dccp_keepalive_timer(unsigned long data)
+static void dccp_keepalive_timer(struct timer_list *t)
 {
-   struct sock *sk = (struct sock *)data;
+   struct sock *sk = from_timer(sk, t, sk_timer);
 
pr_err("dccp should not use a keepalive timer !\n");
sock_put(sk);
 }
 
 /* This is the same as tcp_delack_timer, sans prequeue & mem_reclaim stuff */
-static void dccp_delack_timer(unsigned long data)
+static void dccp_delack_timer(struct timer_list *t)
 {
-   struct sock *sk = (struct sock *)data;
-   struct inet_connection_sock *icsk = inet_csk(sk);
+   struct inet_connection_sock *icsk =
+   from_timer(icsk, t, icsk_delack_timer);
+   struct sock *sk = >icsk_inet.sk;
 
bh_lock_sock(sk);
if (sock_owned_by_user(sk)) {
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index c039c937ba90..c838988eee04 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -494,17 +494,15 @@ EXPORT_SYMBOL(inet_csk_accept);
  * to optimize.
  */
 void inet_csk_init_xmit_timers(struct sock *sk,
-  void (*retransmit_handler)(unsigned long),
-  void (*delack_handler)(unsigned long),
-  void (*keepalive_handler)(unsigned long))
+  void (*retransmit_handler)(struct timer_list *t),
+  void (*delack_handler)(struct timer_list *t),
+  void (*keepalive_handler)(struct timer_list *t))
 {
struct inet_connection_sock *icsk = inet_csk(sk);
 
-   setup_timer(>icsk_retransmit_timer, retransmit_handler,
-   (unsigned long)sk);
-   setup_timer(>icsk_delack_timer, delack_handler,
-   (unsigned long)sk);
-   setup_timer(>sk_timer, keepalive_handler, (unsigned long)sk);
+   timer_setup(>icsk_retransmit_timer, retransmit_handler, 0);
+   timer_setup(>icsk_delack_timer, delack_handler, 0);
+   timer_setup(>sk_timer, keepalive_handler, 0);
icsk->icsk_pending = icsk->icsk_ack.pending = 0;
 }
 EXPORT_SYMBOL(inet_csk_init_xmit_timers);
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 655dd8d7f064..d24c29f73146 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -283,15 +283,17 @@ void tcp_delack_timer_handler(struct 

[PATCH] netfilter: ipset: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. This introduces a pointer back to the
struct ip_set, which is used instead of the struct timer_list .data field.

Cc: Pablo Neira Ayuso 
Cc: Jozsef Kadlecsik 
Cc: Florian Westphal 
Cc: "David S. Miller" 
Cc: Stephen Hemminger 
Cc: simran singhal 
Cc: Muhammad Falak R Wani 
Cc: netfilter-de...@vger.kernel.org
Cc: coret...@netfilter.org
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 net/netfilter/ipset/ip_set_bitmap_gen.h   | 10 +-
 net/netfilter/ipset/ip_set_bitmap_ip.c|  2 ++
 net/netfilter/ipset/ip_set_bitmap_ipmac.c |  2 ++
 net/netfilter/ipset/ip_set_bitmap_port.c  |  2 ++
 net/netfilter/ipset/ip_set_hash_gen.h | 12 +++-
 5 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/net/netfilter/ipset/ip_set_bitmap_gen.h 
b/net/netfilter/ipset/ip_set_bitmap_gen.h
index 8ad2b52a0b32..5ca18f07683b 100644
--- a/net/netfilter/ipset/ip_set_bitmap_gen.h
+++ b/net/netfilter/ipset/ip_set_bitmap_gen.h
@@ -37,11 +37,11 @@
 #define get_ext(set, map, id)  ((map)->extensions + ((set)->dsize * (id)))
 
 static void
-mtype_gc_init(struct ip_set *set, void (*gc)(unsigned long ul_set))
+mtype_gc_init(struct ip_set *set, void (*gc)(struct timer_list *t))
 {
struct mtype *map = set->data;
 
-   setup_timer(>gc, gc, (unsigned long)set);
+   timer_setup(>gc, gc, 0);
mod_timer(>gc, jiffies + IPSET_GC_PERIOD(set->timeout) * HZ);
 }
 
@@ -272,10 +272,10 @@ mtype_list(const struct ip_set *set,
 }
 
 static void
-mtype_gc(unsigned long ul_set)
+mtype_gc(struct timer_list *t)
 {
-   struct ip_set *set = (struct ip_set *)ul_set;
-   struct mtype *map = set->data;
+   struct mtype *map = from_timer(map, t, gc);
+   struct ip_set *set = map->set;
void *x;
u32 id;
 
diff --git a/net/netfilter/ipset/ip_set_bitmap_ip.c 
b/net/netfilter/ipset/ip_set_bitmap_ip.c
index 4783efff0bde..d8975a0b4282 100644
--- a/net/netfilter/ipset/ip_set_bitmap_ip.c
+++ b/net/netfilter/ipset/ip_set_bitmap_ip.c
@@ -48,6 +48,7 @@ struct bitmap_ip {
size_t memsize; /* members size */
u8 netmask; /* subnet netmask */
struct timer_list gc;   /* garbage collection */
+   struct ip_set *set; /* attached to this ip_set */
unsigned char extensions[0] /* data extensions */
__aligned(__alignof__(u64));
 };
@@ -232,6 +233,7 @@ init_map_ip(struct ip_set *set, struct bitmap_ip *map,
map->netmask = netmask;
set->timeout = IPSET_NO_TIMEOUT;
 
+   map->set = set;
set->data = map;
set->family = NFPROTO_IPV4;
 
diff --git a/net/netfilter/ipset/ip_set_bitmap_ipmac.c 
b/net/netfilter/ipset/ip_set_bitmap_ipmac.c
index 9a065f672d3a..4c279fbd2d5d 100644
--- a/net/netfilter/ipset/ip_set_bitmap_ipmac.c
+++ b/net/netfilter/ipset/ip_set_bitmap_ipmac.c
@@ -52,6 +52,7 @@ struct bitmap_ipmac {
u32 elements;   /* number of max elements in the set */
size_t memsize; /* members size */
struct timer_list gc;   /* garbage collector */
+   struct ip_set *set; /* attached to this ip_set */
unsigned char extensions[0] /* MAC + data extensions */
__aligned(__alignof__(u64));
 };
@@ -307,6 +308,7 @@ init_map_ipmac(struct ip_set *set, struct bitmap_ipmac *map,
map->elements = elements;
set->timeout = IPSET_NO_TIMEOUT;
 
+   map->set = set;
set->data = map;
set->family = NFPROTO_IPV4;
 
diff --git a/net/netfilter/ipset/ip_set_bitmap_port.c 
b/net/netfilter/ipset/ip_set_bitmap_port.c
index 7f0c733358a4..7f9bbd7c98b5 100644
--- a/net/netfilter/ipset/ip_set_bitmap_port.c
+++ b/net/netfilter/ipset/ip_set_bitmap_port.c
@@ -40,6 +40,7 @@ struct bitmap_port {
u32 elements;   /* number of max elements in the set */
size_t memsize; /* members size */
struct timer_list gc;   /* garbage collection */
+   struct ip_set *set; /* attached to this ip_set */
unsigned char extensions[0] /* data extensions */
__aligned(__alignof__(u64));
 };
@@ -214,6 +215,7 @@ init_map_port(struct ip_set *set, struct bitmap_port *map,
map->last_port = last_port;
set->timeout = IPSET_NO_TIMEOUT;
 
+   map->set = set;
set->data = map;
set->family = NFPROTO_UNSPEC;
 
diff --git a/net/netfilter/ipset/ip_set_hash_gen.h 
b/net/netfilter/ipset/ip_set_hash_gen.h

[PATCH] inet: frags: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Alexander Aring 
Cc: Stefan Schmidt 
Cc: "David S. Miller" 
Cc: Alexey Kuznetsov 
Cc: Hideaki YOSHIFUJI 
Cc: Pablo Neira Ayuso 
Cc: Jozsef Kadlecsik 
Cc: Florian Westphal 
Cc: linux-w...@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: netfilter-de...@vger.kernel.org
Cc: coret...@netfilter.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 include/net/inet_frag.h | 2 +-
 net/ieee802154/6lowpan/reassembly.c | 5 +++--
 net/ipv4/inet_fragment.c| 4 ++--
 net/ipv4/ip_fragment.c  | 5 +++--
 net/ipv6/netfilter/nf_conntrack_reasm.c | 5 +++--
 net/ipv6/reassembly.c   | 5 +++--
 6 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/include/net/inet_frag.h b/include/net/inet_frag.h
index fc59e0775e00..c695807ca707 100644
--- a/include/net/inet_frag.h
+++ b/include/net/inet_frag.h
@@ -95,7 +95,7 @@ struct inet_frags {
void(*constructor)(struct inet_frag_queue *q,
   const void *arg);
void(*destructor)(struct inet_frag_queue *);
-   void(*frag_expire)(unsigned long data);
+   void(*frag_expire)(struct timer_list *t);
struct kmem_cache   *frags_cachep;
const char  *frags_cache_name;
 };
diff --git a/net/ieee802154/6lowpan/reassembly.c 
b/net/ieee802154/6lowpan/reassembly.c
index f85b08baff16..85bf86ad6b18 100644
--- a/net/ieee802154/6lowpan/reassembly.c
+++ b/net/ieee802154/6lowpan/reassembly.c
@@ -80,12 +80,13 @@ static void lowpan_frag_init(struct inet_frag_queue *q, 
const void *a)
fq->daddr = *arg->dst;
 }
 
-static void lowpan_frag_expire(unsigned long data)
+static void lowpan_frag_expire(struct timer_list *t)
 {
+   struct inet_frag_queue *frag = from_timer(frag, t, timer);
struct frag_queue *fq;
struct net *net;
 
-   fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q);
+   fq = container_of(frag, struct frag_queue, q);
net = container_of(fq->q.net, struct net, ieee802154_lowpan.frags);
 
spin_lock(>q.lock);
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index af74d0433453..7f3ef5c287a1 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -147,7 +147,7 @@ inet_evict_bucket(struct inet_frags *f, struct 
inet_frag_bucket *hb)
spin_unlock(>chain_lock);
 
hlist_for_each_entry_safe(fq, n, , list_evictor)
-   f->frag_expire((unsigned long) fq);
+   f->frag_expire(>timer);
 
return evicted;
 }
@@ -366,7 +366,7 @@ static struct inet_frag_queue *inet_frag_alloc(struct 
netns_frags *nf,
f->constructor(q, arg);
add_frag_mem_limit(nf, f->qsize);
 
-   setup_timer(>timer, f->frag_expire, (unsigned long)q);
+   timer_setup(>timer, f->frag_expire, 0);
spin_lock_init(>lock);
refcount_set(>refcnt, 1);
 
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index 46408c220d9d..9215654a401f 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -190,12 +190,13 @@ static bool frag_expire_skip_icmp(u32 user)
 /*
  * Oops, a fragment queue timed out.  Kill it and send an ICMP reply.
  */
-static void ip_expire(unsigned long arg)
+static void ip_expire(struct timer_list *t)
 {
+   struct inet_frag_queue *frag = from_timer(frag, t, timer);
struct ipq *qp;
struct net *net;
 
-   qp = container_of((struct inet_frag_queue *) arg, struct ipq, q);
+   qp = container_of(frag, struct ipq, q);
net = container_of(qp->q.net, struct net, ipv4.frags);
 
rcu_read_lock();
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c 
b/net/ipv6/netfilter/nf_conntrack_reasm.c
index b263bf3a19f7..977d8900cfd1 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -169,12 +169,13 @@ static unsigned int nf_hashfn(const struct 
inet_frag_queue *q)
return nf_hash_frag(nq->id, >saddr, >daddr);
 }
 
-static void nf_ct_frag6_expire(unsigned long data)
+static void nf_ct_frag6_expire(struct timer_list *t)
 {
+   struct inet_frag_queue *frag = from_timer(frag, t, timer);
struct frag_queue *fq;
struct net *net;
 
-   fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q);
+   fq = container_of(frag, struct 

[PATCH] net/core: Collapse redundant sk_timer callback data

2017-10-04 Thread Kees Cook
The core sk_timer initializer can provide the common .data assignment
instead of it being set separately in users.

Cc: "David S. Miller" 
Cc: Ralf Baechle 
Cc: Andrew Hendry 
Cc: Eric Dumazet 
Cc: Paolo Abeni 
Cc: David Howells 
Cc: Colin Ian King 
Cc: Ingo Molnar 
Cc: linzhang 
Cc: netdev@vger.kernel.org
Cc: linux-h...@vger.kernel.org
Cc: linux-...@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 net/core/sock.c   | 2 +-
 net/netrom/nr_timer.c | 1 -
 net/rose/rose_timer.c | 1 -
 net/x25/af_x25.c  | 1 -
 net/x25/x25_timer.c   | 1 -
 5 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/net/core/sock.c b/net/core/sock.c
index 9b7b6bbb2a23..3a0233106f62 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2678,7 +2678,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
sk_init_common(sk);
sk->sk_send_head=   NULL;
 
-   init_timer(>sk_timer);
+   setup_timer(>sk_timer, NULL, (unsigned long)sk);
 
sk->sk_allocation   =   GFP_KERNEL;
sk->sk_rcvbuf   =   sysctl_rmem_default;
diff --git a/net/netrom/nr_timer.c b/net/netrom/nr_timer.c
index 94d05806a9a2..f84ce71f1f5f 100644
--- a/net/netrom/nr_timer.c
+++ b/net/netrom/nr_timer.c
@@ -45,7 +45,6 @@ void nr_init_timers(struct sock *sk)
setup_timer(>idletimer, nr_idletimer_expiry, (unsigned long)sk);
 
/* initialized by sock_init_data */
-   sk->sk_timer.data = (unsigned long)sk;
sk->sk_timer.function = _heartbeat_expiry;
 }
 
diff --git a/net/rose/rose_timer.c b/net/rose/rose_timer.c
index 3b89d66f15bb..e08201185214 100644
--- a/net/rose/rose_timer.c
+++ b/net/rose/rose_timer.c
@@ -36,7 +36,6 @@ void rose_start_heartbeat(struct sock *sk)
 {
del_timer(>sk_timer);
 
-   sk->sk_timer.data = (unsigned long)sk;
sk->sk_timer.function = _heartbeat_expiry;
sk->sk_timer.expires  = jiffies + 5 * HZ;
 
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index ac095936552d..c590c0bd1393 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -414,7 +414,6 @@ static void __x25_destroy_socket(struct sock *sk)
/* Defer: outstanding buffers */
sk->sk_timer.expires  = jiffies + 10 * HZ;
sk->sk_timer.function = x25_destroy_timer;
-   sk->sk_timer.data = (unsigned long)sk;
add_timer(>sk_timer);
} else {
/* drop last reference so sock_put will free */
diff --git a/net/x25/x25_timer.c b/net/x25/x25_timer.c
index 5c5db1a36399..de5cec41d100 100644
--- a/net/x25/x25_timer.c
+++ b/net/x25/x25_timer.c
@@ -36,7 +36,6 @@ void x25_init_timers(struct sock *sk)
setup_timer(>timer, x25_timer_expiry, (unsigned long)sk);
 
/* initialized by sock_init_data */
-   sk->sk_timer.data = (unsigned long)sk;
sk->sk_timer.function = _heartbeat_expiry;
 }
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


Re: [PATCH] nfp: convert nfp_eth_set_bit_config() into a macro

2017-10-04 Thread Jakub Kicinski
On Wed, 4 Oct 2017 17:38:22 -0700, Manoj Gupta wrote:
> On Wed, Oct 4, 2017 at 4:25 PM, Jakub Kicinski wrote:
> > On Wed, 4 Oct 2017 16:16:49 -0700, Matthias Kaehlcke wrote:  
> >> > > Thanks for the suggestion. This seems a viable alternative if David
> >> > > and the NFP owners can live without the extra checking provided by
> >> > > __BF_FIELD_CHECK.  
> >> >
> >> > The reason the __BF_FIELD_CHECK refuses to compile non-constant masks
> >> > is that it will require runtime ffs on the mask, which is potentially
> >> > costly.  I would also feel quite stupid adding those macros to the nfp
> >> > driver, given that I specifically created the bitfield.h header to not
> >> > have to reimplement these in every driver I write/maintain.  
> >>
> >> That make sense, thanks for providing more context.
> >>  
> >> > Can you please test the patch I provided in the other reply?  
> >>
> >> With this patch there are no errors when building the kernel with
> >> clang.  
> >
> > Cool, thanks for checking!  I will run it through full tests and queue
> > for upstreaming :)  
> 
> Just to let you know, using __BF_FIELD_CHECK macro will not Link with
> -O0 (GCC or Clang)  since references to __compiletime_assert_xxx will
> not be cleaned up.

Do you mean the current nfp_eth_set_bit_config() will not work with -O0
on either complier, or any use of __BF_FIELD_CHECK() will not compile
with -O0?


[PATCH] forcedeth: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: "David S. Miller" 
Cc: Zhu Yanjun 
Cc: Philippe Reynes 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/nvidia/forcedeth.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 994a83a1f0a5..277b233c781f 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -1884,10 +1884,9 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
 }
 
 /* If rx bufs are exhausted called after 50ms to attempt to refresh */
-static void nv_do_rx_refill(unsigned long data)
+static void nv_do_rx_refill(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *) data;
-   struct fe_priv *np = netdev_priv(dev);
+   struct fe_priv *np = from_timer(np, t, oom_kick);
 
/* Just reschedule NAPI rx processing */
napi_schedule(>napi);
@@ -4061,10 +4060,10 @@ static void nv_free_irq(struct net_device *dev)
}
 }
 
-static void nv_do_nic_poll(unsigned long data)
+static void nv_do_nic_poll(struct timer_list *t)
 {
-   struct net_device *dev = (struct net_device *) data;
-   struct fe_priv *np = netdev_priv(dev);
+   struct fe_priv *np = from_timer(np, t, nic_poll);
+   struct net_device *dev = np->dev;
u8 __iomem *base = get_hwbase(dev);
u32 mask = 0;
unsigned long flags;
@@ -4172,16 +4171,18 @@ static void nv_do_nic_poll(unsigned long data)
 #ifdef CONFIG_NET_POLL_CONTROLLER
 static void nv_poll_controller(struct net_device *dev)
 {
-   nv_do_nic_poll((unsigned long) dev);
+   struct fe_priv *np = netdev_priv(dev);
+
+   nv_do_nic_poll(>nic_poll);
 }
 #endif
 
-static void nv_do_stats_poll(unsigned long data)
+static void nv_do_stats_poll(struct timer_list *t)
__acquires(_priv(dev)->hwstats_lock)
__releases(_priv(dev)->hwstats_lock)
 {
-   struct net_device *dev = (struct net_device *) data;
-   struct fe_priv *np = netdev_priv(dev);
+   struct fe_priv *np = from_timer(np, t, stats_poll);
+   struct net_device *dev = np->dev;
 
/* If lock is currently taken, the stats are being refreshed
 * and hence fresh enough */
@@ -5627,10 +5628,9 @@ static int nv_probe(struct pci_dev *pci_dev, const 
struct pci_device_id *id)
u64_stats_init(>swstats_rx_syncp);
u64_stats_init(>swstats_tx_syncp);
 
-   setup_timer(>oom_kick, nv_do_rx_refill, (unsigned long)dev);
-   setup_timer(>nic_poll, nv_do_nic_poll, (unsigned long)dev);
-   setup_deferrable_timer(>stats_poll, nv_do_stats_poll,
-  (unsigned long)dev);
+   timer_setup(>oom_kick, nv_do_rx_refill, 0);
+   timer_setup(>nic_poll, nv_do_nic_poll, 0);
+   timer_setup(>stats_poll, nv_do_stats_poll, TIMER_DEFERRABLE);
 
err = pci_enable_device(pci_dev);
if (err)
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] bna: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Rasesh Mody 
Cc: Sudarsana Kalluru 
Cc: dept-gelinuxnic...@cavium.com
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/brocade/bna/bnad.c | 43 +++--
 1 file changed, 19 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ethernet/brocade/bna/bnad.c 
b/drivers/net/ethernet/brocade/bna/bnad.c
index 6e13c937d715..a843076597ec 100644
--- a/drivers/net/ethernet/brocade/bna/bnad.c
+++ b/drivers/net/ethernet/brocade/bna/bnad.c
@@ -1693,9 +1693,9 @@ bnad_rx_res_alloc(struct bnad *bnad, struct bna_res_info 
*res_info,
 /* Timer callbacks */
 /* a) IOC timer */
 static void
-bnad_ioc_timeout(unsigned long data)
+bnad_ioc_timeout(struct timer_list *t)
 {
-   struct bnad *bnad = (struct bnad *)data;
+   struct bnad *bnad = from_timer(bnad, t, bna.ioceth.ioc.ioc_timer);
unsigned long flags;
 
spin_lock_irqsave(>bna_lock, flags);
@@ -1704,9 +1704,9 @@ bnad_ioc_timeout(unsigned long data)
 }
 
 static void
-bnad_ioc_hb_check(unsigned long data)
+bnad_ioc_hb_check(struct timer_list *t)
 {
-   struct bnad *bnad = (struct bnad *)data;
+   struct bnad *bnad = from_timer(bnad, t, bna.ioceth.ioc.hb_timer);
unsigned long flags;
 
spin_lock_irqsave(>bna_lock, flags);
@@ -1715,9 +1715,9 @@ bnad_ioc_hb_check(unsigned long data)
 }
 
 static void
-bnad_iocpf_timeout(unsigned long data)
+bnad_iocpf_timeout(struct timer_list *t)
 {
-   struct bnad *bnad = (struct bnad *)data;
+   struct bnad *bnad = from_timer(bnad, t, bna.ioceth.ioc.iocpf_timer);
unsigned long flags;
 
spin_lock_irqsave(>bna_lock, flags);
@@ -1726,9 +1726,9 @@ bnad_iocpf_timeout(unsigned long data)
 }
 
 static void
-bnad_iocpf_sem_timeout(unsigned long data)
+bnad_iocpf_sem_timeout(struct timer_list *t)
 {
-   struct bnad *bnad = (struct bnad *)data;
+   struct bnad *bnad = from_timer(bnad, t, bna.ioceth.ioc.sem_timer);
unsigned long flags;
 
spin_lock_irqsave(>bna_lock, flags);
@@ -1748,9 +1748,9 @@ bnad_iocpf_sem_timeout(unsigned long data)
 
 /* b) Dynamic Interrupt Moderation Timer */
 static void
-bnad_dim_timeout(unsigned long data)
+bnad_dim_timeout(struct timer_list *t)
 {
-   struct bnad *bnad = (struct bnad *)data;
+   struct bnad *bnad = from_timer(bnad, t, dim_timer);
struct bnad_rx_info *rx_info;
struct bnad_rx_ctrl *rx_ctrl;
int i, j;
@@ -1781,9 +1781,9 @@ bnad_dim_timeout(unsigned long data)
 
 /* c)  Statistics Timer */
 static void
-bnad_stats_timeout(unsigned long data)
+bnad_stats_timeout(struct timer_list *t)
 {
-   struct bnad *bnad = (struct bnad *)data;
+   struct bnad *bnad = from_timer(bnad, t, stats_timer);
unsigned long flags;
 
if (!netif_running(bnad->netdev) ||
@@ -1804,8 +1804,7 @@ bnad_dim_timer_start(struct bnad *bnad)
 {
if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED &&
!test_bit(BNAD_RF_DIM_TIMER_RUNNING, >run_flags)) {
-   setup_timer(>dim_timer, bnad_dim_timeout,
-   (unsigned long)bnad);
+   timer_setup(>dim_timer, bnad_dim_timeout, 0);
set_bit(BNAD_RF_DIM_TIMER_RUNNING, >run_flags);
mod_timer(>dim_timer,
  jiffies + msecs_to_jiffies(BNAD_DIM_TIMER_FREQ));
@@ -1823,8 +1822,7 @@ bnad_stats_timer_start(struct bnad *bnad)
 
spin_lock_irqsave(>bna_lock, flags);
if (!test_and_set_bit(BNAD_RF_STATS_TIMER_RUNNING, >run_flags)) {
-   setup_timer(>stats_timer, bnad_stats_timeout,
-   (unsigned long)bnad);
+   timer_setup(>stats_timer, bnad_stats_timeout, 0);
mod_timer(>stats_timer,
  jiffies + msecs_to_jiffies(BNAD_STATS_TIMER_FREQ));
}
@@ -3692,14 +3690,11 @@ bnad_pci_probe(struct pci_dev *pdev,
goto res_free;
 
/* Set up timers */
-   setup_timer(>bna.ioceth.ioc.ioc_timer, bnad_ioc_timeout,
-   (unsigned long)bnad);
-   setup_timer(>bna.ioceth.ioc.hb_timer, bnad_ioc_hb_check,
-   (unsigned long)bnad);
-   setup_timer(>bna.ioceth.ioc.iocpf_timer, bnad_iocpf_timeout,
-   (unsigned long)bnad);
-   setup_timer(>bna.ioceth.ioc.sem_timer, bnad_iocpf_sem_timeout,
-   (unsigned long)bnad);
+   timer_setup(>bna.ioceth.ioc.ioc_timer, bnad_ioc_timeout, 0);
+   timer_setup(>bna.ioceth.ioc.hb_timer, bnad_ioc_hb_check, 0);
+   

Re: [PATCH net-next 1/4] bpf: Add file mode configuration into bpf maps

2017-10-04 Thread Daniel Borkmann

On 10/05/2017 01:58 AM, Chenbo Feng wrote:

On Wed, Oct 4, 2017 at 4:29 PM, Daniel Borkmann  wrote:

On 10/04/2017 08:29 PM, Chenbo Feng wrote:

From: Chenbo Feng 

Introduce the map read/write flags to the eBPF syscalls that returns the
map fd. The flags is used to set up the file mode when construct a new
file descriptor for bpf maps. To not break the backward capability, the
f_flags is set to O_RDWR if the flag passed by syscall is 0. Otherwise
it should be O_RDONLY or O_WRONLY. When the userspace want to modify or
read the map content, it will check the file mode to see if it is
allowed to make the change.


[...]


+int bpf_get_file_flag(int flags)
+{
+   if ((flags & BPF_F_RDONLY) && (flags & BPF_F_WRONLY))
+   return -EINVAL;
+   if (flags & BPF_F_RDONLY)
+   return O_RDONLY;
+   if (flags & BPF_F_WRONLY)
+   return O_WRONLY;
+   return O_RDWR;
   }

   /* helper macro to check that unused fields 'union bpf_attr' are zero */
@@ -345,12 +376,17 @@ static int map_create(union bpf_attr *attr)
   {
 int numa_node = bpf_map_attr_numa_node(attr);
 struct bpf_map *map;
+   int f_flags;
 int err;

 err = CHECK_ATTR(BPF_MAP_CREATE);
 if (err)
 return -EINVAL;

+   f_flags = bpf_get_file_flag(attr->map_flags);
+   if (f_flags < 0)
+   return f_flags;


Wait, I just noticed, given you add BPF_F_RDONLY/BPF_F_WRONLY
to attr->map_flags, and later go into find_and_alloc_map(),
for map alloc, which is e.g. array_map_alloc(). There, we
bail out with EINVAL on attr->map_flags & ~BPF_F_NUMA_NODE,
which is the case for both BPF_F_RDONLY/BPF_F_WRONLY ... I
would have expected that the entire code was tested properly;
what was tested exactly in the set?


Thanks for pointing out this, my test for the patch create the map
with RD/WR flag which is 0 that's why I didn't catch this. And
bpf_obj_get do not have similar checks for map_flags.


Ok, please make sure to extend tools/testing/selftests/bpf/test_maps.c
regarding the two added flags, should be really straight forward to
integrate there and it would also help tracking potential regressions
in future as it's run by various ci bots (like 0day bot).

Thanks,
Daniel


[PATCH] net: vxge: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Jon Mason 
Cc: "David S. Miller" 
Cc: Miroslav Lichvar 
Cc: Jarod Wilson 
Cc: Eric Dumazet 
Cc: stephen hemminger 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/net/ethernet/neterion/vxge/vxge-main.c | 12 ++--
 drivers/net/ethernet/neterion/vxge/vxge-main.h |  8 +++-
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/neterion/vxge/vxge-main.c 
b/drivers/net/ethernet/neterion/vxge/vxge-main.c
index 50ea69d88480..5d5b9855e24e 100644
--- a/drivers/net/ethernet/neterion/vxge/vxge-main.c
+++ b/drivers/net/ethernet/neterion/vxge/vxge-main.c
@@ -2597,9 +2597,9 @@ static int vxge_add_isr(struct vxgedev *vdev)
return VXGE_HW_OK;
 }
 
-static void vxge_poll_vp_reset(unsigned long data)
+static void vxge_poll_vp_reset(struct timer_list *t)
 {
-   struct vxgedev *vdev = (struct vxgedev *)data;
+   struct vxgedev *vdev = from_timer(vdev, t, vp_reset_timer);
int i, j = 0;
 
for (i = 0; i < vdev->no_of_vpath; i++) {
@@ -2616,9 +2616,9 @@ static void vxge_poll_vp_reset(unsigned long data)
mod_timer(>vp_reset_timer, jiffies + HZ / 2);
 }
 
-static void vxge_poll_vp_lockup(unsigned long data)
+static void vxge_poll_vp_lockup(struct timer_list *t)
 {
-   struct vxgedev *vdev = (struct vxgedev *)data;
+   struct vxgedev *vdev = from_timer(vdev, t, vp_lockup_timer);
enum vxge_hw_status status = VXGE_HW_OK;
struct vxge_vpath *vpath;
struct vxge_ring *ring;
@@ -2858,12 +2858,12 @@ static int vxge_open(struct net_device *dev)
vdev->config.rx_pause_enable);
 
if (vdev->vp_reset_timer.function == NULL)
-   vxge_os_timer(>vp_reset_timer, vxge_poll_vp_reset, vdev,
+   vxge_os_timer(>vp_reset_timer, vxge_poll_vp_reset,
  HZ / 2);
 
/* There is no need to check for RxD leak and RxD lookup on Titan1A */
if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
-   vxge_os_timer(>vp_lockup_timer, vxge_poll_vp_lockup, vdev,
+   vxge_os_timer(>vp_lockup_timer, vxge_poll_vp_lockup,
  HZ / 2);
 
set_bit(__VXGE_STATE_CARD_UP, >state);
diff --git a/drivers/net/ethernet/neterion/vxge/vxge-main.h 
b/drivers/net/ethernet/neterion/vxge/vxge-main.h
index 3a79d93b8445..59a57ff5e96a 100644
--- a/drivers/net/ethernet/neterion/vxge/vxge-main.h
+++ b/drivers/net/ethernet/neterion/vxge/vxge-main.h
@@ -417,12 +417,10 @@ struct vxge_tx_priv {
module_param(p, int, 0)
 
 static inline
-void vxge_os_timer(struct timer_list *timer, void (*func)(unsigned long data),
-  struct vxgedev *vdev, unsigned long timeout)
+void vxge_os_timer(struct timer_list *timer, void (*func)(struct timer_list *),
+  unsigned long timeout)
 {
-   init_timer(timer);
-   timer->function = func;
-   timer->data = (unsigned long)vdev;
+   timer_setup(timer, func, 0);
mod_timer(timer, jiffies + timeout);
 }
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH] net/irda/bfin_sir: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Samuel Ortiz 
Cc: netdev@vger.kernel.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/staging/irda/drivers/bfin_sir.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/irda/drivers/bfin_sir.c 
b/drivers/staging/irda/drivers/bfin_sir.c
index 3151b580dbd6..59e409b68349 100644
--- a/drivers/staging/irda/drivers/bfin_sir.c
+++ b/drivers/staging/irda/drivers/bfin_sir.c
@@ -22,6 +22,8 @@ static int max_rate = 57600;
 static int max_rate = 115200;
 #endif
 
+static void bfin_sir_rx_dma_timeout(struct timer_list *t);
+
 static void turnaround_delay(int mtt)
 {
long ticks;
@@ -57,7 +59,7 @@ static void bfin_sir_init_ports(struct bfin_sir_port *sp, 
struct platform_device
sp->clk = get_sclk();
 #ifdef CONFIG_SIR_BFIN_DMA
sp->tx_done= 1;
-   init_timer(&(sp->rx_dma_timer));
+   timer_setup(>rx_dma_timer, bfin_sir_rx_dma_timeout, 0);
 #endif
 }
 
@@ -317,10 +319,12 @@ static void bfin_sir_dma_rx_chars(struct net_device *dev)
async_unwrap_char(dev, >stats, >rx_buff, 
port->rx_dma_buf.buf[i]);
 }
 
-void bfin_sir_rx_dma_timeout(struct net_device *dev)
+static void bfin_sir_rx_dma_timeout(struct timer_list *t)
 {
+   struct bfin_sir_port *port = from_timer(port, t, rx_dma_timer);
+   struct net_device *dev = port->dev;
struct bfin_sir_self *self = netdev_priv(dev);
-   struct bfin_sir_port *port = self->sir_port;
+
int x_pos, pos;
unsigned long flags;
 
@@ -405,8 +409,6 @@ static int bfin_sir_startup(struct bfin_sir_port *port, 
struct net_device *dev)
set_dma_start_addr(port->rx_dma_channel, (unsigned 
long)port->rx_dma_buf.buf);
enable_dma(port->rx_dma_channel);
 
-   port->rx_dma_timer.data = (unsigned long)(dev);
-   port->rx_dma_timer.function = (void *)bfin_sir_rx_dma_timeout;
 
 #else
 
-- 
2.7.4


-- 
Kees Cook
Pixel Security


[PATCH v2 net-next 4/7] net: vrf: Add extack messages for enslave errors

2017-10-04 Thread David Ahern
Signed-off-by: David Ahern 
---
 drivers/net/vrf.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index 77d0655a0250..0b54f553228e 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -772,8 +772,11 @@ static int do_vrf_add_slave(struct net_device *dev, struct 
net_device *port_dev,
/* do not allow loopback device to be enslaved to a VRF.
 * The vrf device acts as the loopback for the vrf.
 */
-   if (port_dev == dev_net(dev)->loopback_dev)
+   if (port_dev == dev_net(dev)->loopback_dev) {
+   NL_SET_ERR_MSG(extack,
+  "Can not enslave loopback device to a VRF");
return -EOPNOTSUPP;
+   }
 
port_dev->priv_flags |= IFF_L3MDEV_SLAVE;
ret = netdev_master_upper_dev_link(port_dev, dev, NULL, NULL, extack);
@@ -792,7 +795,13 @@ static int do_vrf_add_slave(struct net_device *dev, struct 
net_device *port_dev,
 static int vrf_add_slave(struct net_device *dev, struct net_device *port_dev,
 struct netlink_ext_ack *extack)
 {
-   if (netif_is_l3_master(port_dev) || netif_is_l3_slave(port_dev))
+   if (netif_is_l3_master(port_dev)) {
+   NL_SET_ERR_MSG(extack,
+  "Can not enslave an L3 master device to a VRF");
+   return -EINVAL;
+   }
+
+   if (netif_is_l3_slave(port_dev))
return -EINVAL;
 
return do_vrf_add_slave(dev, port_dev, extack);
-- 
2.1.4



[PATCH v2 net-next 6/7] net: bridge: Pass extack to down to netdev_master_upper_dev_link

2017-10-04 Thread David Ahern
Pass extack arg to br_add_if. Add messages for a couple of failures
and pass arg to netdev_master_upper_dev_link.

Signed-off-by: David Ahern 
Acked-by: Stephen Hemminger 
---
 net/bridge/br_device.c  |  2 +-
 net/bridge/br_if.c  | 15 +++
 net/bridge/br_ioctl.c   |  2 +-
 net/bridge/br_private.h |  3 ++-
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index cb0131d70ab1..7acb77c9bd65 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -326,7 +326,7 @@ static int br_add_slave(struct net_device *dev, struct 
net_device *slave_dev,
 {
struct net_bridge *br = netdev_priv(dev);
 
-   return br_add_if(br, slave_dev);
+   return br_add_if(br, slave_dev, extack);
 }
 
 static int br_del_slave(struct net_device *dev, struct net_device *slave_dev)
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 0a3fd727048d..59a74a414e20 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -480,7 +480,8 @@ netdev_features_t br_features_recompute(struct net_bridge 
*br,
 }
 
 /* called with RTNL */
-int br_add_if(struct net_bridge *br, struct net_device *dev)
+int br_add_if(struct net_bridge *br, struct net_device *dev,
+ struct netlink_ext_ack *extack)
 {
struct net_bridge_port *p;
int err = 0;
@@ -500,16 +501,22 @@ int br_add_if(struct net_bridge *br, struct net_device 
*dev)
return -EINVAL;
 
/* No bridging of bridges */
-   if (dev->netdev_ops->ndo_start_xmit == br_dev_xmit)
+   if (dev->netdev_ops->ndo_start_xmit == br_dev_xmit) {
+   NL_SET_ERR_MSG(extack,
+  "Can not enslave a bridge to a bridge");
return -ELOOP;
+   }
 
/* Device is already being bridged */
if (br_port_exists(dev))
return -EBUSY;
 
/* No bridging devices that dislike that (e.g. wireless) */
-   if (dev->priv_flags & IFF_DONT_BRIDGE)
+   if (dev->priv_flags & IFF_DONT_BRIDGE) {
+   NL_SET_ERR_MSG(extack,
+  "Device does not allow enslaving to a bridge");
return -EOPNOTSUPP;
+   }
 
p = new_nbp(br, dev);
if (IS_ERR(p))
@@ -540,7 +547,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
 
dev->priv_flags |= IFF_BRIDGE_PORT;
 
-   err = netdev_master_upper_dev_link(dev, br->dev, NULL, NULL, NULL);
+   err = netdev_master_upper_dev_link(dev, br->dev, NULL, NULL, extack);
if (err)
goto err5;
 
diff --git a/net/bridge/br_ioctl.c b/net/bridge/br_ioctl.c
index 66cd98772051..8f29103935a3 100644
--- a/net/bridge/br_ioctl.c
+++ b/net/bridge/br_ioctl.c
@@ -98,7 +98,7 @@ static int add_del_if(struct net_bridge *br, int ifindex, int 
isadd)
return -EINVAL;
 
if (isadd)
-   ret = br_add_if(br, dev);
+   ret = br_add_if(br, dev, NULL);
else
ret = br_del_if(br, dev);
 
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 020c709a017f..ab4df24f7bba 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -566,7 +566,8 @@ void br_flood(struct net_bridge *br, struct sk_buff *skb,
 void br_port_carrier_check(struct net_bridge_port *p);
 int br_add_bridge(struct net *net, const char *name);
 int br_del_bridge(struct net *net, const char *name);
-int br_add_if(struct net_bridge *br, struct net_device *dev);
+int br_add_if(struct net_bridge *br, struct net_device *dev,
+ struct netlink_ext_ack *extack);
 int br_del_if(struct net_bridge *br, struct net_device *dev);
 int br_min_mtu(const struct net_bridge *br);
 netdev_features_t br_features_recompute(struct net_bridge *br,
-- 
2.1.4



[PATCH v2 net-next 7/7] mlxsw: spectrum: Add extack messages for enslave failures

2017-10-04 Thread David Ahern
mlxsw fails device enslavement for a number of reasons. Use the extack
facility to return an error message to the user stating why the enslave
is failing.

Messages are prefixed with "spectrum" so users know it is a constraint
imposed by the hardware driver. For example:
$ ip li add br0.11 link br0 type vlan id 11
$ ip li set swp11 master br0
Error: spectrum: Enslaving a port to a device that already has an upper 
device is not supported.

Signed-off-by: David Ahern 
Reviewed-by: Ido Schimmel 
Tested-by: Ido Schimmel 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 47 --
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 3adf237c951a..5cd4df08ce97 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -4019,14 +4019,21 @@ static int mlxsw_sp_lag_index_get(struct mlxsw_sp 
*mlxsw_sp,
 static bool
 mlxsw_sp_master_lag_check(struct mlxsw_sp *mlxsw_sp,
  struct net_device *lag_dev,
- struct netdev_lag_upper_info *lag_upper_info)
+ struct netdev_lag_upper_info *lag_upper_info,
+ struct netlink_ext_ack *extack)
 {
u16 lag_id;
 
-   if (mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, _id) != 0)
+   if (mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, _id) != 0) {
+   NL_SET_ERR_MSG(extack,
+  "spectrum: Exceeded number of supported LAG 
devices");
return false;
-   if (lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
+   }
+   if (lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
+   NL_SET_ERR_MSG(extack,
+  "spectrum: LAG device using unsupported Tx 
type");
return false;
+   }
return true;
 }
 
@@ -4231,6 +4238,7 @@ static int mlxsw_sp_netdevice_port_upper_event(struct 
net_device *lower_dev,
 {
struct netdev_notifier_changeupper_info *info;
struct mlxsw_sp_port *mlxsw_sp_port;
+   struct netlink_ext_ack *extack;
struct net_device *upper_dev;
struct mlxsw_sp *mlxsw_sp;
int err = 0;
@@ -4238,6 +4246,7 @@ static int mlxsw_sp_netdevice_port_upper_event(struct 
net_device *lower_dev,
mlxsw_sp_port = netdev_priv(dev);
mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
info = ptr;
+   extack = netdev_notifier_info_to_extack(>info);
 
switch (event) {
case NETDEV_PRECHANGEUPPER:
@@ -4245,25 +4254,43 @@ static int mlxsw_sp_netdevice_port_upper_event(struct 
net_device *lower_dev,
if (!is_vlan_dev(upper_dev) &&
!netif_is_lag_master(upper_dev) &&
!netif_is_bridge_master(upper_dev) &&
-   !netif_is_ovs_master(upper_dev))
+   !netif_is_ovs_master(upper_dev)) {
+   NL_SET_ERR_MSG(extack,
+  "spectrum: Unknown upper device type");
return -EINVAL;
+   }
if (!info->linking)
break;
-   if (netdev_has_any_upper_dev(upper_dev))
+   if (netdev_has_any_upper_dev(upper_dev)) {
+   NL_SET_ERR_MSG(extack,
+  "spectrum: Enslaving a port to a device 
that already has an upper device is not supported");
return -EINVAL;
+   }
if (netif_is_lag_master(upper_dev) &&
!mlxsw_sp_master_lag_check(mlxsw_sp, upper_dev,
-  info->upper_info))
+  info->upper_info, extack))
return -EINVAL;
-   if (netif_is_lag_master(upper_dev) && vlan_uses_dev(dev))
+   if (netif_is_lag_master(upper_dev) && vlan_uses_dev(dev)) {
+   NL_SET_ERR_MSG(extack,
+  "spectrum: Master device is a LAG master 
and this device has a VLAN");
return -EINVAL;
+   }
if (netif_is_lag_port(dev) && is_vlan_dev(upper_dev) &&
-   !netif_is_lag_master(vlan_dev_real_dev(upper_dev)))
+   !netif_is_lag_master(vlan_dev_real_dev(upper_dev))) {
+   NL_SET_ERR_MSG(extack,
+  "spectrum: Can not put a VLAN on a LAG 
port");
return -EINVAL;
-   if (netif_is_ovs_master(upper_dev) && vlan_uses_dev(dev))
+   }
+   if (netif_is_ovs_master(upper_dev) && vlan_uses_dev(dev)) {
+   NL_SET_ERR_MSG(extack,
+  

[PATCH v2 net-next 3/7] net: Add extack to upper device linking

2017-10-04 Thread David Ahern
Add extack arg to netdev_upper_dev_link and netdev_master_upper_dev_link

Signed-off-by: David Ahern 
---
 drivers/net/bonding/bond_main.c|  7 ---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c |  2 +-
 drivers/net/hyperv/netvsc_drv.c|  2 +-
 drivers/net/ipvlan/ipvlan_main.c   |  2 +-
 drivers/net/macsec.c   |  2 +-
 drivers/net/macvlan.c  |  7 ---
 drivers/net/macvtap.c  |  2 +-
 drivers/net/team/team.c|  2 +-
 drivers/net/usb/qmi_wwan.c |  2 +-
 drivers/net/vrf.c  |  7 ---
 include/linux/if_macvlan.h |  3 ++-
 include/linux/netdevice.h  |  6 --
 net/8021q/vlan.c   |  6 +++---
 net/8021q/vlan.h   |  2 +-
 net/8021q/vlan_netlink.c   |  2 +-
 net/batman-adv/hard-interface.c|  2 +-
 net/bridge/br_if.c |  2 +-
 net/core/dev.c | 15 ++-
 net/openvswitch/vport-netdev.c |  3 ++-
 19 files changed, 44 insertions(+), 32 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 78feb94a36db..bc92307c2082 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1217,14 +1217,15 @@ static enum netdev_lag_tx_type bond_lag_tx_type(struct 
bonding *bond)
}
 }
 
-static int bond_master_upper_dev_link(struct bonding *bond, struct slave 
*slave)
+static int bond_master_upper_dev_link(struct bonding *bond, struct slave 
*slave,
+ struct netlink_ext_ack *extack)
 {
struct netdev_lag_upper_info lag_upper_info;
int err;
 
lag_upper_info.tx_type = bond_lag_tx_type(bond);
err = netdev_master_upper_dev_link(slave->dev, bond->dev, slave,
-  _upper_info);
+  _upper_info, extack);
if (err)
return err;
rtmsg_ifinfo(RTM_NEWLINK, slave->dev, IFF_SLAVE, GFP_KERNEL);
@@ -1710,7 +1711,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev,
goto err_detach;
}
 
-   res = bond_master_upper_dev_link(bond, new_slave);
+   res = bond_master_upper_dev_link(bond, new_slave, extack);
if (res) {
netdev_dbg(bond_dev, "Error %d calling 
bond_master_upper_dev_link\n", res);
goto err_unregister;
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c 
b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
index 98f22551eb45..1af326a60cbb 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
@@ -178,7 +178,7 @@ static int rmnet_newlink(struct net *src_net, struct 
net_device *dev,
if (err)
goto err1;
 
-   err = netdev_master_upper_dev_link(dev, real_dev, NULL, NULL);
+   err = netdev_master_upper_dev_link(dev, real_dev, NULL, NULL, extack);
if (err)
goto err2;
 
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index f300ae61c6c6..dfb986421ec6 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1748,7 +1748,7 @@ static int netvsc_vf_join(struct net_device *vf_netdev,
goto rx_handler_failed;
}
 
-   ret = netdev_upper_dev_link(vf_netdev, ndev);
+   ret = netdev_upper_dev_link(vf_netdev, ndev, NULL);
if (ret != 0) {
netdev_err(vf_netdev,
   "can not set master device %s (err = %d)\n",
diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c
index c74893c1e620..57c3856bab05 100644
--- a/drivers/net/ipvlan/ipvlan_main.c
+++ b/drivers/net/ipvlan/ipvlan_main.c
@@ -584,7 +584,7 @@ int ipvlan_link_new(struct net *src_net, struct net_device 
*dev,
if (err < 0)
goto remove_ida;
 
-   err = netdev_upper_dev_link(phy_dev, dev);
+   err = netdev_upper_dev_link(phy_dev, dev, extack);
if (err) {
goto unregister_netdev;
}
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 98e4deaa3a6a..ccbe4eaffe4d 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -3244,7 +3244,7 @@ static int macsec_newlink(struct net *net, struct 
net_device *dev,
   _netdev_addr_lock_key,
   macsec_get_nest_level(dev));
 
-   err = netdev_upper_dev_link(real_dev, dev);
+   err = netdev_upper_dev_link(real_dev, dev, extack);
if (err < 0)
goto unregister;
 

[PATCH v2 net-next 0/7] net: Plumb extack error reporting to enslavements

2017-10-04 Thread David Ahern
Another round of extending extack error reporting, this time for
enslavements through ndo_add_slave and notifiers.

v2
- changed how the messages are added to bonding driver per Jiri's request
- fixed spectrum message for LAG overflow per Ido's comment

David Ahern (7):
  net: Add extack to netdev_notifier_info
  net: Add extack to ndo_add_slave
  net: Add extack to upper device linking
  net: vrf: Add extack messages for enslave errors
  net: bonding: Add extack messages for some enslave failures
  net: bridge: Pass extack to down to netdev_master_upper_dev_link
  mlxsw: spectrum: Add extack messages for enslave failures

 drivers/net/bonding/bond_main.c| 19 +++--
 drivers/net/bonding/bond_options.c |  2 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 47 ---
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c |  2 +-
 drivers/net/hyperv/netvsc_drv.c|  2 +-
 drivers/net/ipvlan/ipvlan_main.c   |  2 +-
 drivers/net/macsec.c   |  2 +-
 drivers/net/macvlan.c  |  7 +-
 drivers/net/macvtap.c  |  2 +-
 drivers/net/team/team.c|  5 +-
 drivers/net/usb/qmi_wwan.c |  2 +-
 drivers/net/vrf.c  | 23 --
 include/linux/if_macvlan.h |  3 +-
 include/linux/netdevice.h  | 19 -
 include/net/bonding.h  |  3 +-
 net/8021q/vlan.c   |  6 +-
 net/8021q/vlan.h   |  2 +-
 net/8021q/vlan_netlink.c   |  2 +-
 net/batman-adv/hard-interface.c|  2 +-
 net/batman-adv/soft-interface.c|  3 +-
 net/bridge/br_device.c |  5 +-
 net/bridge/br_if.c | 15 +++-
 net/bridge/br_ioctl.c  |  2 +-
 net/bridge/br_private.h|  3 +-
 net/core/dev.c | 96 +-
 net/core/rtnetlink.c   | 10 ++-
 net/openvswitch/vport-netdev.c |  3 +-
 27 files changed, 192 insertions(+), 97 deletions(-)

-- 
2.1.4



Re: [PATCH 05/13] timer: Remove init_timer_deferrable() in favor of timer_setup()

2017-10-04 Thread David Miller
From: Kees Cook 
Date: Wed,  4 Oct 2017 16:26:59 -0700

> This refactors the only users of init_timer_deferrable() to use
> the new timer_setup() and from_timer(). Removes definition of
> init_timer_deferrable().
> 
> Cc: Benjamin Herrenschmidt 
> Cc: Michael Ellerman 
> Cc: Sebastian Reichel 
> Cc: Harish Patil 
> Cc: Manish Chopra 
> Cc: Kalle Valo 
> Cc: linuxppc-...@lists.ozlabs.org
> Cc: netdev@vger.kernel.org
> Cc: linux-wirel...@vger.kernel.org
> Signed-off-by: Kees Cook 

For networking:

Acked-by: David S. Miller 


Re: [PATCH 10/13] timer: Remove expires and data arguments from DEFINE_TIMER

2017-10-04 Thread David Miller
From: Kees Cook 
Date: Wed,  4 Oct 2017 16:27:04 -0700

> Drop the arguments from the macro and adjust all callers with the
> following script:
> 
>   perl -pi -e 's/DEFINE_TIMER\((.*), 0, 0\);/DEFINE_TIMER($1);/g;' \
> $(git grep DEFINE_TIMER | cut -d: -f1 | sort -u | grep -v timer.h)
> 
> Signed-off-by: Kees Cook 
> Acked-by: Geert Uytterhoeven  # for m68k parts

For networking:

Acked-by: David S. Miller 


Re: [PATCH 04/13] timer: Remove init_timer_pinned() in favor of timer_setup()

2017-10-04 Thread David Miller
From: Kees Cook 
Date: Wed,  4 Oct 2017 16:26:58 -0700

> This refactors the only users of init_timer_pinned() to use
> the new timer_setup() and from_timer(). Drops the definition of
> init_timer_pinned().
> 
> Cc: Chris Metcalf 
> Cc: Thomas Gleixner 
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook 

For networking:

Acked-by: David S. Miller 


Re: [PATCH] nfp: convert nfp_eth_set_bit_config() into a macro

2017-10-04 Thread Manoj Gupta
Hi Jakub,

On Wed, Oct 4, 2017 at 4:25 PM, Jakub Kicinski
 wrote:
> On Wed, 4 Oct 2017 16:16:49 -0700, Matthias Kaehlcke wrote:
>> > > Thanks for the suggestion. This seems a viable alternative if David
>> > > and the NFP owners can live without the extra checking provided by
>> > > __BF_FIELD_CHECK.
>> >
>> > The reason the __BF_FIELD_CHECK refuses to compile non-constant masks
>> > is that it will require runtime ffs on the mask, which is potentially
>> > costly.  I would also feel quite stupid adding those macros to the nfp
>> > driver, given that I specifically created the bitfield.h header to not
>> > have to reimplement these in every driver I write/maintain.
>>
>> That make sense, thanks for providing more context.
>>
>> > Can you please test the patch I provided in the other reply?
>>
>> With this patch there are no errors when building the kernel with
>> clang.
>
> Cool, thanks for checking!  I will run it through full tests and queue
> for upstreaming :)

Just to let you know, using __BF_FIELD_CHECK macro will not Link with
-O0 (GCC or Clang)  since references to __compiletime_assert_xxx will
not be cleaned up.

Thanks,
Manoj


Re: [PATCH 10/13] timer: Remove expires and data arguments from DEFINE_TIMER

2017-10-04 Thread Guenter Roeck

On 10/04/2017 04:27 PM, Kees Cook wrote:

Drop the arguments from the macro and adjust all callers with the
following script:

   perl -pi -e 's/DEFINE_TIMER\((.*), 0, 0\);/DEFINE_TIMER($1);/g;' \
 $(git grep DEFINE_TIMER | cut -d: -f1 | sort -u | grep -v timer.h)

Signed-off-by: Kees Cook 
Acked-by: Geert Uytterhoeven  # for m68k parts


For watchdog:

Acked-by: Guenter Roeck 


---
  arch/arm/mach-ixp4xx/dsmg600-setup.c  | 2 +-
  arch/arm/mach-ixp4xx/nas100d-setup.c  | 2 +-
  arch/m68k/amiga/amisound.c| 2 +-
  arch/m68k/mac/macboing.c  | 2 +-
  arch/mips/mti-malta/malta-display.c   | 2 +-
  arch/parisc/kernel/pdc_cons.c | 2 +-
  arch/s390/mm/cmm.c| 2 +-
  drivers/atm/idt77105.c| 4 ++--
  drivers/atm/iphase.c  | 2 +-
  drivers/block/ataflop.c   | 8 
  drivers/char/dtlk.c   | 2 +-
  drivers/char/hangcheck-timer.c| 2 +-
  drivers/char/nwbutton.c   | 2 +-
  drivers/char/rtc.c| 2 +-
  drivers/input/touchscreen/s3c2410_ts.c| 2 +-
  drivers/net/cris/eth_v10.c| 6 +++---
  drivers/net/hamradio/yam.c| 2 +-
  drivers/net/wireless/atmel/at76c50x-usb.c | 2 +-
  drivers/staging/speakup/main.c| 2 +-
  drivers/staging/speakup/synth.c   | 2 +-
  drivers/tty/cyclades.c| 2 +-
  drivers/tty/isicom.c  | 2 +-
  drivers/tty/moxa.c| 2 +-
  drivers/tty/rocket.c  | 2 +-
  drivers/tty/vt/keyboard.c | 2 +-
  drivers/tty/vt/vt.c   | 2 +-
  drivers/watchdog/alim7101_wdt.c   | 2 +-
  drivers/watchdog/machzwd.c| 2 +-
  drivers/watchdog/mixcomwd.c   | 2 +-
  drivers/watchdog/sbc60xxwdt.c | 2 +-
  drivers/watchdog/sc520_wdt.c  | 2 +-
  drivers/watchdog/via_wdt.c| 2 +-
  drivers/watchdog/w83877f_wdt.c| 2 +-
  drivers/xen/grant-table.c | 2 +-
  fs/pstore/platform.c  | 2 +-
  include/linux/timer.h | 4 ++--
  kernel/irq/spurious.c | 2 +-
  lib/random32.c| 2 +-
  net/atm/mpc.c | 2 +-
  net/decnet/dn_route.c | 2 +-
  net/ipv6/ip6_flowlabel.c  | 2 +-
  net/netrom/nr_loopback.c  | 2 +-
  security/keys/gc.c| 2 +-
  sound/oss/midibuf.c   | 2 +-
  sound/oss/soundcard.c | 2 +-
  sound/oss/sys_timer.c | 2 +-
  sound/oss/uart6850.c  | 2 +-
  47 files changed, 54 insertions(+), 54 deletions(-)

diff --git a/arch/arm/mach-ixp4xx/dsmg600-setup.c 
b/arch/arm/mach-ixp4xx/dsmg600-setup.c
index b3bd0e137f6d..b3689a141ec6 100644
--- a/arch/arm/mach-ixp4xx/dsmg600-setup.c
+++ b/arch/arm/mach-ixp4xx/dsmg600-setup.c
@@ -174,7 +174,7 @@ static int power_button_countdown;
  #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
  
  static void dsmg600_power_handler(unsigned long data);

-static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
+static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler);
  
  static void dsmg600_power_handler(unsigned long data)

  {
diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c 
b/arch/arm/mach-ixp4xx/nas100d-setup.c
index 4e0f762bc651..562d05f9888e 100644
--- a/arch/arm/mach-ixp4xx/nas100d-setup.c
+++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
@@ -197,7 +197,7 @@ static int power_button_countdown;
  #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
  
  static void nas100d_power_handler(unsigned long data);

-static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
+static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler);
  
  static void nas100d_power_handler(unsigned long data)

  {
diff --git a/arch/m68k/amiga/amisound.c b/arch/m68k/amiga/amisound.c
index 90a60d758f8b..a23f48181fd6 100644
--- a/arch/m68k/amiga/amisound.c
+++ b/arch/m68k/amiga/amisound.c
@@ -66,7 +66,7 @@ void __init amiga_init_sound(void)
  }
  
  static void nosound( unsigned long ignored );

-static DEFINE_TIMER(sound_timer, nosound, 0, 0);
+static DEFINE_TIMER(sound_timer, nosound);
  
  void amiga_mksound( unsigned int hz, unsigned int ticks )

  {
diff --git a/arch/m68k/mac/macboing.c b/arch/m68k/mac/macboing.c
index ffaa1f6439ae..9a52aff183d0 100644
--- a/arch/m68k/mac/macboing.c
+++ b/arch/m68k/mac/macboing.c
@@ -56,7 +56,7 @@ static void ( *mac_special_bell )( unsigned int, unsigned 
int, unsigned int );
  /*
   * our timer to start/continue/stop the bell
   */
-static DEFINE_TIMER(mac_sound_timer, mac_nosound, 0, 0);
+static DEFINE_TIMER(mac_sound_timer, mac_nosound);
  
  /*

   * Sort of initialize 

[PATCH net-next] ip_gre: check packet length and mtu correctly in erspan_fb_xmit

2017-10-04 Thread William Tu
Similarly to early patch for erspan_xmit(), the ARPHDR_ETHER device
is the length of the whole ether packet.  So skb->len should subtract
the dev->hard_header_len.

Fixes: 1a66a836da63 ("gre: add collect_md mode to ERSPAN tunnel")
Signed-off-by: William Tu 
Cc: Xin Long 
---
 net/ipv4/ip_gre.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index b279c325c7f6..10b21fe5b3a6 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -579,7 +579,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct 
net_device *dev,
if (gre_handle_offloads(skb, false))
goto err_free_rt;
 
-   if (skb->len > dev->mtu) {
+   if (skb->len - dev->hard_header_len > dev->mtu) {
pskb_trim(skb, dev->mtu);
truncate = true;
}
-- 
2.7.4



Re: [PATCH 09/13] timer: Remove users of expire and data arguments to DEFINE_TIMER

2017-10-04 Thread Guenter Roeck

On 10/04/2017 04:27 PM, Kees Cook wrote:

The expire and data arguments of DEFINE_TIMER are only used in two places
and are ignored by the code (malta-display.c only uses mod_timer(),
never add_timer(), so the preset expires value is ignored). Set both
sets of arguments to zero.

Cc: Ralf Baechle 
Cc: Wim Van Sebroeck 
Cc: Guenter Roeck 
Cc: Geert Uytterhoeven 
Cc: linux-m...@linux-mips.org
Cc: linux-watch...@vger.kernel.org
Signed-off-by: Kees Cook 


For watchdog:

Acked-by: Guenter Roeck 


---
  arch/mips/mti-malta/malta-display.c | 6 +++---
  drivers/watchdog/alim7101_wdt.c | 4 ++--
  2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/mips/mti-malta/malta-display.c 
b/arch/mips/mti-malta/malta-display.c
index d4f807191ecd..ac813158b9b8 100644
--- a/arch/mips/mti-malta/malta-display.c
+++ b/arch/mips/mti-malta/malta-display.c
@@ -36,10 +36,10 @@ void mips_display_message(const char *str)
}
  }
  
-static void scroll_display_message(unsigned long data);

-static DEFINE_TIMER(mips_scroll_timer, scroll_display_message, HZ, 0);
+static void scroll_display_message(unsigned long unused);
+static DEFINE_TIMER(mips_scroll_timer, scroll_display_message, 0, 0);
  
-static void scroll_display_message(unsigned long data)

+static void scroll_display_message(unsigned long unused)
  {
mips_display_message(_string[display_count++]);
if (display_count == max_display_count)
diff --git a/drivers/watchdog/alim7101_wdt.c b/drivers/watchdog/alim7101_wdt.c
index 665e0e7dfe1e..3c1f6ac68ea9 100644
--- a/drivers/watchdog/alim7101_wdt.c
+++ b/drivers/watchdog/alim7101_wdt.c
@@ -71,7 +71,7 @@ MODULE_PARM_DESC(use_gpio,
"Use the gpio watchdog (required by old cobalt boards).");
  
  static void wdt_timer_ping(unsigned long);

-static DEFINE_TIMER(timer, wdt_timer_ping, 0, 1);
+static DEFINE_TIMER(timer, wdt_timer_ping, 0, 0);
  static unsigned long next_heartbeat;
  static unsigned long wdt_is_open;
  static char wdt_expect_close;
@@ -87,7 +87,7 @@ MODULE_PARM_DESC(nowayout,
   *Whack the dog
   */
  
-static void wdt_timer_ping(unsigned long data)

+static void wdt_timer_ping(unsigned long unused)
  {
/* If we got a heartbeat pulse within the WDT_US_INTERVAL
 * we agree to ping the WDT





[PATCHv2 net-next] openvswitch: Add erspan tunnel support.

2017-10-04 Thread William Tu
Add erspan netlink interface for OVS.

Signed-off-by: William Tu 
Cc: Pravin B Shelar 
---
v1->v2: remove unnecessary compat code.
---
 include/uapi/linux/openvswitch.h |  1 +
 net/openvswitch/flow_netlink.c   | 51 +++-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h
index 156ee4cab82e..efdbfbfd3ee2 100644
--- a/include/uapi/linux/openvswitch.h
+++ b/include/uapi/linux/openvswitch.h
@@ -359,6 +359,7 @@ enum ovs_tunnel_key_attr {
OVS_TUNNEL_KEY_ATTR_IPV6_SRC,   /* struct in6_addr src IPv6 
address. */
OVS_TUNNEL_KEY_ATTR_IPV6_DST,   /* struct in6_addr dst IPv6 
address. */
OVS_TUNNEL_KEY_ATTR_PAD,
+   OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS,/* be32 ERSPAN index. */
__OVS_TUNNEL_KEY_ATTR_MAX
 };
 
diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c
index e8eb427ce6d1..fc0ca9a89b8e 100644
--- a/net/openvswitch/flow_netlink.c
+++ b/net/openvswitch/flow_netlink.c
@@ -48,6 +48,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "flow_netlink.h"
 
@@ -319,7 +320,8 @@ size_t ovs_tun_key_attr_size(void)
 * OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS and covered by it.
 */
+ nla_total_size(2)/* OVS_TUNNEL_KEY_ATTR_TP_SRC */
-   + nla_total_size(2);   /* OVS_TUNNEL_KEY_ATTR_TP_DST */
+   + nla_total_size(2)/* OVS_TUNNEL_KEY_ATTR_TP_DST */
+   + nla_total_size(4);   /* OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS */
 }
 
 size_t ovs_key_attr_size(void)
@@ -371,6 +373,7 @@ static const struct ovs_len_tbl 
ovs_tunnel_key_lens[OVS_TUNNEL_KEY_ATTR_MAX + 1]
.next = ovs_vxlan_ext_key_lens 
},
[OVS_TUNNEL_KEY_ATTR_IPV6_SRC]  = { .len = sizeof(struct in6_addr) 
},
[OVS_TUNNEL_KEY_ATTR_IPV6_DST]  = { .len = sizeof(struct in6_addr) 
},
+   [OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS]   = { .len = sizeof(u32) },
 };
 
 /* The size of the argument for each %OVS_KEY_ATTR_* Netlink attribute.  */
@@ -593,6 +596,33 @@ static int vxlan_tun_opt_from_nlattr(const struct nlattr 
*attr,
return 0;
 }
 
+static int erspan_tun_opt_from_nlattr(const struct nlattr *attr,
+ struct sw_flow_match *match, bool is_mask,
+ bool log)
+{
+   unsigned long opt_key_offset;
+   struct erspan_metadata opts;
+
+   BUILD_BUG_ON(sizeof(opts) > sizeof(match->key->tun_opts));
+
+   memset(, 0, sizeof(opts));
+   opts.index = nla_get_be32(attr);
+
+   /* Index has only 20-bit */
+   if (ntohl(opts.index) & ~INDEX_MASK) {
+   OVS_NLERR(log, "ERSPAN index number %x too large.",
+ ntohl(opts.index));
+   return -EINVAL;
+   }
+
+   SW_FLOW_KEY_PUT(match, tun_opts_len, sizeof(opts), is_mask);
+   opt_key_offset = TUN_METADATA_OFFSET(sizeof(opts));
+   SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, , sizeof(opts),
+ is_mask);
+
+   return 0;
+}
+
 static int ip_tun_from_nlattr(const struct nlattr *attr,
  struct sw_flow_match *match, bool is_mask,
  bool log)
@@ -700,6 +730,19 @@ static int ip_tun_from_nlattr(const struct nlattr *attr,
break;
case OVS_TUNNEL_KEY_ATTR_PAD:
break;
+   case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS:
+   if (opts_type) {
+   OVS_NLERR(log, "Multiple metadata blocks 
provided");
+   return -EINVAL;
+   }
+
+   err = erspan_tun_opt_from_nlattr(a, match, is_mask, 
log);
+   if (err)
+   return err;
+
+   tun_flags |= TUNNEL_ERSPAN_OPT;
+   opts_type = type;
+   break;
default:
OVS_NLERR(log, "Unknown IP tunnel attribute %d",
  type);
@@ -824,6 +867,10 @@ static int __ip_tun_to_nlattr(struct sk_buff *skb,
else if (output->tun_flags & TUNNEL_VXLAN_OPT &&
 vxlan_opt_to_nlattr(skb, tun_opts, swkey_tun_opts_len))
return -EMSGSIZE;
+   else if (output->tun_flags & TUNNEL_ERSPAN_OPT &&
+nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS,
+ ((struct erspan_metadata 
*)tun_opts)->index))
+   return -EMSGSIZE;
}
 
return 0;
@@ -2195,6 +2242,8 @@ static int validate_and_copy_set_tun(const struct nlattr 
*attr,
break;
case OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS:
 

Re: [PATCH net-next 1/4] bpf: Add file mode configuration into bpf maps

2017-10-04 Thread Chenbo Feng
On Wed, Oct 4, 2017 at 4:29 PM, Daniel Borkmann  wrote:
> On 10/04/2017 08:29 PM, Chenbo Feng wrote:
>>
>> From: Chenbo Feng 
>>
>> Introduce the map read/write flags to the eBPF syscalls that returns the
>> map fd. The flags is used to set up the file mode when construct a new
>> file descriptor for bpf maps. To not break the backward capability, the
>> f_flags is set to O_RDWR if the flag passed by syscall is 0. Otherwise
>> it should be O_RDONLY or O_WRONLY. When the userspace want to modify or
>> read the map content, it will check the file mode to see if it is
>> allowed to make the change.
>
> [...]
>>
>> +int bpf_get_file_flag(int flags)
>> +{
>> +   if ((flags & BPF_F_RDONLY) && (flags & BPF_F_WRONLY))
>> +   return -EINVAL;
>> +   if (flags & BPF_F_RDONLY)
>> +   return O_RDONLY;
>> +   if (flags & BPF_F_WRONLY)
>> +   return O_WRONLY;
>> +   return O_RDWR;
>>   }
>>
>>   /* helper macro to check that unused fields 'union bpf_attr' are zero */
>> @@ -345,12 +376,17 @@ static int map_create(union bpf_attr *attr)
>>   {
>> int numa_node = bpf_map_attr_numa_node(attr);
>> struct bpf_map *map;
>> +   int f_flags;
>> int err;
>>
>> err = CHECK_ATTR(BPF_MAP_CREATE);
>> if (err)
>> return -EINVAL;
>>
>> +   f_flags = bpf_get_file_flag(attr->map_flags);
>> +   if (f_flags < 0)
>> +   return f_flags;
>
>
> Wait, I just noticed, given you add BPF_F_RDONLY/BPF_F_WRONLY
> to attr->map_flags, and later go into find_and_alloc_map(),
> for map alloc, which is e.g. array_map_alloc(). There, we
> bail out with EINVAL on attr->map_flags & ~BPF_F_NUMA_NODE,
> which is the case for both BPF_F_RDONLY/BPF_F_WRONLY ... I
> would have expected that the entire code was tested properly;
> what was tested exactly in the set?
>

Thanks for pointing out this, my test for the patch create the map
with RD/WR flag which is 0 that's why I didn't catch this. And
bpf_obj_get do not have similar checks for map_flags.
>> if (numa_node != NUMA_NO_NODE &&
>> ((unsigned int)numa_node >= nr_node_ids ||
>>  !node_online(numa_node)))
>> @@ -376,7 +412,7 @@ static int map_create(union bpf_attr *attr)
>> if (err)
>> goto free_map;
>>
>> -   err = bpf_map_new_fd(map);
>> +   err = bpf_map_new_fd(map, f_flags);
>> if (err < 0) {
>> /* failed to allocate fd.
>>  * bpf_map_put() is needed because the above
>> @@ -491,6 +527,11 @@ static int map_lookup_elem(union bpf_attr *attr)
>
> [...]


devlink dump of mlxsw_adj table triggers a panic

2017-10-04 Thread David Ahern
The following devlink command on a 2700 triggers a panic every time.
Kernel is net-next at 26873308b21654b6e0785b9f9e2c5414d37a4c4c

$ devlink  dpipe table dump pci/:03:00.0 name mlxsw_adj
devlink answers: No buffer space available


I have seen several different stack traces and varying amounts of EMAD
errors on console:

[   77.453364] mlxsw_spectrum :03:00.0: EMAD reg access failed
(tid=64c24a43688,reg_id=200b(sfn),type=query,status=0(operation
performed))
[   77.466568] mlxsw_spectrum :03:00.0: Failed to get FDB notifications

If it does not reproduce for you let me know and I'll grab a trace.

David


Re: [PATCH 2/3 v2] net: phy: DP83822 initial driver submission

2017-10-04 Thread Andrew Lunn
On Wed, Oct 04, 2017 at 10:44:36PM +, woojung@microchip.com wrote:
> > +static int dp83822_suspend(struct phy_device *phydev)
> > +{
> > +   int value;
> > +
> > +   mutex_lock(>lock);
> > +   value = phy_read_mmd(phydev, DP83822_DEVADDR,
> > MII_DP83822_WOL_CFG);
> > +   mutex_unlock(>lock);

> Would we need mutex to access phy_read_mmd()?
> phy_read_mmd() has mdio_lock for indirect access.

Hi Woojung

The mdio lock is not sufficient. It protects against two mdio
accesses. But here we need to protect against two phy operations.
There is a danger something else tries to access the phy during
suspend.

> > +   if (!(value & DP83822_WOL_EN))
> > +   genphy_suspend(phydev);

Releasing the lock before calling genphy_suspend() is not so nice.
Maybe add a version which assumes the lock has already been taken?

  Andrew


Re: [PATCH net-next 4/4] selinux: bpf: Add addtional check for bpf object file receive

2017-10-04 Thread Daniel Borkmann

On 10/05/2017 01:44 AM, Daniel Borkmann wrote:

On 10/04/2017 08:29 PM, Chenbo Feng wrote:

From: Chenbo Feng 

Introduce a bpf object related check when sending and receiving files
through unix domain socket as well as binder. It checks if the receiving
process have privilege to read/write the bpf map or use the bpf program.
This check is necessary because the bpf maps and programs are using a
anonymous inode as their shared inode so the normal way of checking the
files and sockets when passing between processes cannot work properly on
eBPF object. This check only works when the BPF_SYSCALL is configured.


[...]

+/* This function will check the file pass through unix socket or binder to see
+ * if it is a bpf related object. And apply correspinding checks on the bpf
+ * object based on the type. The bpf maps and programs, not like other files 
and
+ * socket, are using a shared anonymous inode inside the kernel as their inode.
+ * So checking that inode cannot identify if the process have privilege to
+ * access the bpf object and that's why we have to add this additional check in
+ * selinux_file_receive and selinux_binder_transfer_files.
+ */

[...]

If selinux/lsm folks have some input on this one in particular, would
be great. The issue is not really tied to bpf specifically, but to the
use of anon-inodes wrt fd passing. Maybe some generic resolution can
be found to tackle this ...


Perhaps even just a generic callback in struct file_operations might be
better in order to just retrieve the secctx from the underlying object
in case of anon-inodes and then have a generic check in selinux_file_receive()
for the case when such callback is set, such that we don't need to put
specific bpf logic there.


Re: [PATCH net-next 4/4] selinux: bpf: Add addtional check for bpf object file receive

2017-10-04 Thread Daniel Borkmann

On 10/04/2017 08:29 PM, Chenbo Feng wrote:

From: Chenbo Feng 

Introduce a bpf object related check when sending and receiving files
through unix domain socket as well as binder. It checks if the receiving
process have privilege to read/write the bpf map or use the bpf program.
This check is necessary because the bpf maps and programs are using a
anonymous inode as their shared inode so the normal way of checking the
files and sockets when passing between processes cannot work properly on
eBPF object. This check only works when the BPF_SYSCALL is configured.


[...]

+/* This function will check the file pass through unix socket or binder to see
+ * if it is a bpf related object. And apply correspinding checks on the bpf
+ * object based on the type. The bpf maps and programs, not like other files 
and
+ * socket, are using a shared anonymous inode inside the kernel as their inode.
+ * So checking that inode cannot identify if the process have privilege to
+ * access the bpf object and that's why we have to add this additional check in
+ * selinux_file_receive and selinux_binder_transfer_files.
+ */

[...]

If selinux/lsm folks have some input on this one in particular, would
be great. The issue is not really tied to bpf specifically, but to the
use of anon-inodes wrt fd passing. Maybe some generic resolution can
be found to tackle this ...


[PATCH 00/13] timer: Start conversion to timer_setup()

2017-10-04 Thread Kees Cook
Hi,

This is the first of many timer infrastructure cleanups to simplify the
timer API[1]. All of these patches are expected to land via the timer
tree, so Acks (or corrections) appreciated.

These patches refactor various users of timer API that are NOT just using
init_timer() or setup_timer() (which is the vast majority of users,
and are being converted separately). These changes are focused on the
lesser-used init_timer_*(), TIMER_*INITIALIZER(), and DEFINE_TIMER()
methods of preparing a timer.

Thanks!

-Kees

[1] https://git.kernel.org/linus/686fef928bba6be13cabe639f154af7d72b63120



[PATCH 04/13] timer: Remove init_timer_pinned() in favor of timer_setup()

2017-10-04 Thread Kees Cook
This refactors the only users of init_timer_pinned() to use
the new timer_setup() and from_timer(). Drops the definition of
init_timer_pinned().

Cc: Chris Metcalf 
Cc: Thomas Gleixner 
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/net/ethernet/tile/tilepro.c | 9 -
 include/linux/timer.h   | 2 --
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/tile/tilepro.c 
b/drivers/net/ethernet/tile/tilepro.c
index 49ccee4b9aec..56d06282fbde 100644
--- a/drivers/net/ethernet/tile/tilepro.c
+++ b/drivers/net/ethernet/tile/tilepro.c
@@ -608,9 +608,9 @@ static void tile_net_schedule_egress_timer(struct 
tile_net_cpu *info)
  * ISSUE: Maybe instead track number of expected completions, and free
  * only that many, resetting to zero if "pending" is ever false.
  */
-static void tile_net_handle_egress_timer(unsigned long arg)
+static void tile_net_handle_egress_timer(struct timer_list *t)
 {
-   struct tile_net_cpu *info = (struct tile_net_cpu *)arg;
+   struct tile_net_cpu *info = from_timer(info, t, egress_timer);
struct net_device *dev = info->napi.dev;
 
/* The timer is no longer scheduled. */
@@ -1004,9 +1004,8 @@ static void tile_net_register(void *dev_ptr)
BUG();
 
/* Initialize the egress timer. */
-   init_timer_pinned(>egress_timer);
-   info->egress_timer.data = (long)info;
-   info->egress_timer.function = tile_net_handle_egress_timer;
+   timer_setup(>egress_timer, tile_net_handle_egress_timer,
+   TIMER_PINNED);
 
u64_stats_init(>stats.syncp);
 
diff --git a/include/linux/timer.h b/include/linux/timer.h
index b10c4bdc6fbd..9da903562ed4 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -128,8 +128,6 @@ static inline void init_timer_on_stack_key(struct 
timer_list *timer,
 
 #define init_timer(timer)  \
__init_timer((timer), 0)
-#define init_timer_pinned(timer)   \
-   __init_timer((timer), TIMER_PINNED)
 #define init_timer_deferrable(timer)   \
__init_timer((timer), TIMER_DEFERRABLE)
 
-- 
2.7.4



[PATCH 03/13] timer: Remove init_timer_on_stack() in favor of timer_setup_on_stack()

2017-10-04 Thread Kees Cook
Remove uses of init_timer_on_stack() with open-coded function and data
assignments that could be expressed using timer_setup_on_stack(). Several
were removed from the stack entirely since there was a one-to-one mapping
of parent structure to timer, those are switched to using timer_setup()
instead. All related callbacks were adjusted to use from_timer().

Cc: "Rafael J. Wysocki" 
Cc: Pavel Machek 
Cc: Len Brown 
Cc: Greg Kroah-Hartman 
Cc: Stefan Richter 
Cc: Sudip Mukherjee 
Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: Julian Wiedmann 
Cc: Ursula Braun 
Cc: Michael Reed 
Cc: "James E.J. Bottomley" 
Cc: "Martin K. Petersen" 
Cc: Thomas Gleixner 
Cc: linux...@vger.kernel.org
Cc: linux1394-de...@lists.sourceforge.net
Cc: linux-s...@vger.kernel.org
Cc: linux-s...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 drivers/base/power/main.c   |  8 +++-
 drivers/firewire/core-transaction.c | 10 +-
 drivers/parport/ieee1284.c  | 21 +++--
 drivers/s390/char/tape.h|  1 +
 drivers/s390/char/tape_std.c| 18 ++
 drivers/s390/net/lcs.c  | 16 ++--
 drivers/s390/net/lcs.h  |  1 +
 drivers/scsi/qla1280.c  | 14 +-
 drivers/scsi/qla1280.h  |  1 +
 include/linux/parport.h |  1 +
 include/linux/timer.h   |  2 --
 11 files changed, 36 insertions(+), 57 deletions(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 770b1539a083..ae47b2ec84b4 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -478,9 +478,9 @@ struct dpm_watchdog {
  * There's not much we can do here to recover so panic() to
  * capture a crash-dump in pstore.
  */
-static void dpm_watchdog_handler(unsigned long data)
+static void dpm_watchdog_handler(struct timer_list *t)
 {
-   struct dpm_watchdog *wd = (void *)data;
+   struct dpm_watchdog *wd = from_timer(wd, t, timer);
 
dev_emerg(wd->dev, " DPM device timeout \n");
show_stack(wd->tsk, NULL);
@@ -500,11 +500,9 @@ static void dpm_watchdog_set(struct dpm_watchdog *wd, 
struct device *dev)
wd->dev = dev;
wd->tsk = current;
 
-   init_timer_on_stack(timer);
+   timer_setup_on_stack(timer, dpm_watchdog_handler, 0);
/* use same timeout value for both suspend and resume */
timer->expires = jiffies + HZ * CONFIG_DPM_WATCHDOG_TIMEOUT;
-   timer->function = dpm_watchdog_handler;
-   timer->data = (unsigned long)wd;
add_timer(timer);
 }
 
diff --git a/drivers/firewire/core-transaction.c 
b/drivers/firewire/core-transaction.c
index d6a09b9cd8cc..4372f9e4b0da 100644
--- a/drivers/firewire/core-transaction.c
+++ b/drivers/firewire/core-transaction.c
@@ -137,9 +137,9 @@ int fw_cancel_transaction(struct fw_card *card,
 }
 EXPORT_SYMBOL(fw_cancel_transaction);
 
-static void split_transaction_timeout_callback(unsigned long data)
+static void split_transaction_timeout_callback(struct timer_list *timer)
 {
-   struct fw_transaction *t = (struct fw_transaction *)data;
+   struct fw_transaction *t = from_timer(t, timer, split_timeout_timer);
struct fw_card *card = t->card;
unsigned long flags;
 
@@ -373,8 +373,8 @@ void fw_send_request(struct fw_card *card, struct 
fw_transaction *t, int tcode,
t->tlabel = tlabel;
t->card = card;
t->is_split_transaction = false;
-   setup_timer(>split_timeout_timer,
-   split_transaction_timeout_callback, (unsigned long)t);
+   timer_setup(>split_timeout_timer,
+   split_transaction_timeout_callback, 0);
t->callback = callback;
t->callback_data = callback_data;
 
@@ -423,7 +423,7 @@ int fw_run_transaction(struct fw_card *card, int tcode, int 
destination_id,
struct transaction_callback_data d;
struct fw_transaction t;
 
-   init_timer_on_stack(_timeout_timer);
+   timer_setup_on_stack(_timeout_timer, NULL, 0);
init_completion();
d.payload = payload;
fw_send_request(card, , tcode, destination_id, generation, speed,
diff --git a/drivers/parport/ieee1284.c b/drivers/parport/ieee1284.c
index 74cc6dd982d2..2d1a5c737c6e 100644
--- a/drivers/parport/ieee1284.c
+++ b/drivers/parport/ieee1284.c
@@ -44,10 +44,11 @@ static void parport_ieee1284_wakeup (struct parport *port)
up (>physport->ieee1284.irq);
 }
 
-static struct parport *port_from_cookie[PARPORT_MAX];
-static void timeout_waiting_on_port (unsigned long cookie)
+static void timeout_waiting_on_port (struct timer_list *t)
 {
-   

[PATCH 01/13] timer: Convert schedule_timeout() to use from_timer()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new from_timer() helper and passing
the timer pointer explicitly. Since this special timer is on the stack, it
needs to have a wrapper structure to carry state once .data is eliminated.

Cc: John Stultz 
Cc: Thomas Gleixner 
Cc: Stephen Boyd 
Signed-off-by: Kees Cook 
---
 include/linux/timer.h |  8 
 kernel/time/timer.c   | 26 +++---
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/include/linux/timer.h b/include/linux/timer.h
index 6383c528b148..5ef5c9e41a09 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -179,6 +179,14 @@ static inline void timer_setup(struct timer_list *timer,
  (TIMER_DATA_TYPE)timer, flags);
 }
 
+static inline void timer_setup_on_stack(struct timer_list *timer,
+  void (*callback)(struct timer_list *),
+  unsigned int flags)
+{
+   __setup_timer_on_stack(timer, (TIMER_FUNC_TYPE)callback,
+  (TIMER_DATA_TYPE)timer, flags);
+}
+
 #define from_timer(var, callback_timer, timer_fieldname) \
container_of(callback_timer, typeof(*var), timer_fieldname)
 
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index f2674a056c26..38613ced2324 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1668,9 +1668,20 @@ void run_local_timers(void)
raise_softirq(TIMER_SOFTIRQ);
 }
 
-static void process_timeout(unsigned long __data)
+/*
+ * Since schedule_timeout()'s timer is defined on the stack, it must store
+ * the target task on the stack as well.
+ */
+struct process_timer {
+   struct timer_list timer;
+   struct task_struct *task;
+};
+
+static void process_timeout(struct timer_list *t)
 {
-   wake_up_process((struct task_struct *)__data);
+   struct process_timer *timeout = from_timer(timeout, t, timer);
+
+   wake_up_process(timeout->task);
 }
 
 /**
@@ -1704,7 +1715,7 @@ static void process_timeout(unsigned long __data)
  */
 signed long __sched schedule_timeout(signed long timeout)
 {
-   struct timer_list timer;
+   struct process_timer timer;
unsigned long expire;
 
switch (timeout)
@@ -1738,13 +1749,14 @@ signed long __sched schedule_timeout(signed long 
timeout)
 
expire = timeout + jiffies;
 
-   setup_timer_on_stack(, process_timeout, (unsigned long)current);
-   __mod_timer(, expire, false);
+   timer.task = current;
+   timer_setup_on_stack(, process_timeout, 0);
+   __mod_timer(, expire, false);
schedule();
-   del_singleshot_timer_sync();
+   del_singleshot_timer_sync();
 
/* Remove the timer from the object tracker */
-   destroy_timer_on_stack();
+   destroy_timer_on_stack();
 
timeout = expire - jiffies;
 
-- 
2.7.4



[PATCH 08/13] timer: Remove unused static initializer macros

2017-10-04 Thread Kees Cook
This removes the now unused TIMER_*INITIALIZER macros:

TIMER_INITIALIZER
TIMER_PINNED_INITIALIZER
TIMER_DEFERRED_INITIALIZER
TIMER_PINNED_DEFERRED_INITIALIZER

Signed-off-by: Kees Cook 
---
 include/linux/timer.h | 12 
 1 file changed, 12 deletions(-)

diff --git a/include/linux/timer.h b/include/linux/timer.h
index 4f7476e4a727..a33220311361 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -73,18 +73,6 @@ struct timer_list {
__FILE__ ":" __stringify(__LINE__)) \
}
 
-#define TIMER_INITIALIZER(_function, _expires, _data)  \
-   __TIMER_INITIALIZER((_function), (_expires), (_data), 0)
-
-#define TIMER_PINNED_INITIALIZER(_function, _expires, _data)   \
-   __TIMER_INITIALIZER((_function), (_expires), (_data), TIMER_PINNED)
-
-#define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) \
-   __TIMER_INITIALIZER((_function), (_expires), (_data), TIMER_DEFERRABLE)
-
-#define TIMER_PINNED_DEFERRED_INITIALIZER(_function, _expires, _data)  \
-   __TIMER_INITIALIZER((_function), (_expires), (_data), TIMER_DEFERRABLE 
| TIMER_PINNED)
-
 #define DEFINE_TIMER(_name, _function, _expires, _data)\
struct timer_list _name =   \
__TIMER_INITIALIZER(_function, _expires, _data, 0)
-- 
2.7.4



[PATCH 05/13] timer: Remove init_timer_deferrable() in favor of timer_setup()

2017-10-04 Thread Kees Cook
This refactors the only users of init_timer_deferrable() to use
the new timer_setup() and from_timer(). Removes definition of
init_timer_deferrable().

Cc: Benjamin Herrenschmidt 
Cc: Michael Ellerman 
Cc: Sebastian Reichel 
Cc: Harish Patil 
Cc: Manish Chopra 
Cc: Kalle Valo 
Cc: linuxppc-...@lists.ozlabs.org
Cc: netdev@vger.kernel.org
Cc: linux-wirel...@vger.kernel.org
Signed-off-by: Kees Cook 
---
 arch/powerpc/mm/numa.c   | 12 +--
 drivers/hsi/clients/ssi_protocol.c   | 32 
 drivers/net/ethernet/qlogic/qlge/qlge_main.c | 11 --
 drivers/net/vxlan.c  |  8 +++
 drivers/net/wireless/ath/ath6kl/recovery.c   |  9 
 include/linux/timer.h|  2 --
 6 files changed, 34 insertions(+), 40 deletions(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index b95c584ce19d..f9b6107d6854 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -1453,7 +1453,7 @@ static void topology_schedule_update(void)
schedule_work(_work);
 }
 
-static void topology_timer_fn(unsigned long ignored)
+static void topology_timer_fn(struct timer_list *unused)
 {
if (prrn_enabled && cpumask_weight(_associativity_changes_mask))
topology_schedule_update();
@@ -1463,14 +1463,11 @@ static void topology_timer_fn(unsigned long ignored)
reset_topology_timer();
}
 }
-static struct timer_list topology_timer =
-   TIMER_INITIALIZER(topology_timer_fn, 0, 0);
+static struct timer_list topology_timer;
 
 static void reset_topology_timer(void)
 {
-   topology_timer.data = 0;
-   topology_timer.expires = jiffies + 60 * HZ;
-   mod_timer(_timer, topology_timer.expires);
+   mod_timer(_timer, jiffies + 60 * HZ);
 }
 
 #ifdef CONFIG_SMP
@@ -1530,7 +1527,8 @@ int start_topology_update(void)
prrn_enabled = 0;
vphn_enabled = 1;
setup_cpu_associativity_change_counters();
-   init_timer_deferrable(_timer);
+   timer_setup(_timer, topology_timer_fn,
+   TIMER_DEFERRABLE);
reset_topology_timer();
}
}
diff --git a/drivers/hsi/clients/ssi_protocol.c 
b/drivers/hsi/clients/ssi_protocol.c
index 93d28c0ec8bf..67af03d3aeb3 100644
--- a/drivers/hsi/clients/ssi_protocol.c
+++ b/drivers/hsi/clients/ssi_protocol.c
@@ -464,10 +464,10 @@ static void ssip_error(struct hsi_client *cl)
hsi_async_read(cl, msg);
 }
 
-static void ssip_keep_alive(unsigned long data)
+static void ssip_keep_alive(struct timer_list *t)
 {
-   struct hsi_client *cl = (struct hsi_client *)data;
-   struct ssi_protocol *ssi = hsi_client_drvdata(cl);
+   struct ssi_protocol *ssi = from_timer(ssi, t, keep_alive);
+   struct hsi_client *cl = ssi->cl;
 
dev_dbg(>device, "Keep alive kick in: m(%d) r(%d) s(%d)\n",
ssi->main_state, ssi->recv_state, ssi->send_state);
@@ -490,9 +490,19 @@ static void ssip_keep_alive(unsigned long data)
spin_unlock(>lock);
 }
 
-static void ssip_wd(unsigned long data)
+static void ssip_rx_wd(struct timer_list *t)
+{
+   struct ssi_protocol *ssi = from_timer(ssi, t, rx_wd);
+   struct hsi_client *cl = ssi->cl;
+
+   dev_err(>device, "Watchdog trigerred\n");
+   ssip_error(cl);
+}
+
+static void ssip_tx_wd(unsigned long data)
 {
-   struct hsi_client *cl = (struct hsi_client *)data;
+   struct ssi_protocol *ssi = from_timer(ssi, t, tx_wd);
+   struct hsi_client *cl = ssi->cl;
 
dev_err(>device, "Watchdog trigerred\n");
ssip_error(cl);
@@ -1084,15 +1094,9 @@ static int ssi_protocol_probe(struct device *dev)
}
 
spin_lock_init(>lock);
-   init_timer_deferrable(>rx_wd);
-   init_timer_deferrable(>tx_wd);
-   init_timer(>keep_alive);
-   ssi->rx_wd.data = (unsigned long)cl;
-   ssi->rx_wd.function = ssip_wd;
-   ssi->tx_wd.data = (unsigned long)cl;
-   ssi->tx_wd.function = ssip_wd;
-   ssi->keep_alive.data = (unsigned long)cl;
-   ssi->keep_alive.function = ssip_keep_alive;
+   timer_setup(>rx_wd, ssip_rx_wd, TIMER_DEFERRABLE);
+   timer_setup(>tx_wd, ssip_tx_wd, TIMER_DEFERRABLE);
+   timer_setup(>keep_alive, ssip_keep_alive, 0);
INIT_LIST_HEAD(>txqueue);
INIT_LIST_HEAD(>cmdqueue);
atomic_set(>tx_usecnt, 0);
diff --git a/drivers/net/ethernet/qlogic/qlge/qlge_main.c 
b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
index 9feec7009443..29fea74bff2e 100644
--- a/drivers/net/ethernet/qlogic/qlge/qlge_main.c
+++ b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
@@ -4725,9 +4725,9 @@ static const struct net_device_ops qlge_netdev_ops = 

[PATCH 02/13] timer: Remove init_timer_pinned_deferrable() in favor of timer_setup()

2017-10-04 Thread Kees Cook
This refactors the only user of init_timer_pinned_deferrable() to use the
new timer_setup() and from_timer(). Adds a pointer back to the policy,
and drops the definition of init_timer_pinned_deferrable().

Cc: "Rafael J. Wysocki" 
Cc: Viresh Kumar 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: Thomas Gleixner 
Cc: linux...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Signed-off-by: Kees Cook 
---
 drivers/cpufreq/powernv-cpufreq.c | 13 +++--
 include/linux/timer.h |  2 --
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/cpufreq/powernv-cpufreq.c 
b/drivers/cpufreq/powernv-cpufreq.c
index 3ff5160451b4..b6d7c4c98d0a 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -90,6 +90,7 @@ struct global_pstate_info {
int last_gpstate_idx;
spinlock_t gpstate_lock;
struct timer_list timer;
+   struct cpufreq_policy *policy;
 };
 
 static struct cpufreq_frequency_table powernv_freqs[POWERNV_MAX_PSTATES+1];
@@ -625,10 +626,10 @@ static inline void  queue_gpstate_timer(struct 
global_pstate_info *gpstates)
  * according quadratic equation. Queues a new timer if it is still not equal
  * to local pstate
  */
-void gpstate_timer_handler(unsigned long data)
+void gpstate_timer_handler(struct timer_list *t)
 {
-   struct cpufreq_policy *policy = (struct cpufreq_policy *)data;
-   struct global_pstate_info *gpstates = policy->driver_data;
+   struct global_pstate_info *gpstates = from_timer(gpstates, t, timer);
+   struct cpufreq_policy *policy = gpstates->policy;
int gpstate_idx, lpstate_idx;
unsigned long val;
unsigned int time_diff = jiffies_to_msecs(jiffies)
@@ -800,9 +801,9 @@ static int powernv_cpufreq_cpu_init(struct cpufreq_policy 
*policy)
policy->driver_data = gpstates;
 
/* initialize timer */
-   init_timer_pinned_deferrable(>timer);
-   gpstates->timer.data = (unsigned long)policy;
-   gpstates->timer.function = gpstate_timer_handler;
+   gpstates->policy = policy;
+   timer_setup(>timer, gpstate_timer_handler,
+   TIMER_PINNED | TIMER_DEFERRABLE);
gpstates->timer.expires = jiffies +
msecs_to_jiffies(GPSTATE_TIMER_INTERVAL);
spin_lock_init(>gpstate_lock);
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 5ef5c9e41a09..d11e819a86e2 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -132,8 +132,6 @@ static inline void init_timer_on_stack_key(struct 
timer_list *timer,
__init_timer((timer), TIMER_PINNED)
 #define init_timer_deferrable(timer)   \
__init_timer((timer), TIMER_DEFERRABLE)
-#define init_timer_pinned_deferrable(timer)\
-   __init_timer((timer), TIMER_DEFERRABLE | TIMER_PINNED)
 #define init_timer_on_stack(timer) \
__init_timer_on_stack((timer), 0)
 
-- 
2.7.4



[PATCH 10/13] timer: Remove expires and data arguments from DEFINE_TIMER

2017-10-04 Thread Kees Cook
Drop the arguments from the macro and adjust all callers with the
following script:

  perl -pi -e 's/DEFINE_TIMER\((.*), 0, 0\);/DEFINE_TIMER($1);/g;' \
$(git grep DEFINE_TIMER | cut -d: -f1 | sort -u | grep -v timer.h)

Signed-off-by: Kees Cook 
Acked-by: Geert Uytterhoeven  # for m68k parts
---
 arch/arm/mach-ixp4xx/dsmg600-setup.c  | 2 +-
 arch/arm/mach-ixp4xx/nas100d-setup.c  | 2 +-
 arch/m68k/amiga/amisound.c| 2 +-
 arch/m68k/mac/macboing.c  | 2 +-
 arch/mips/mti-malta/malta-display.c   | 2 +-
 arch/parisc/kernel/pdc_cons.c | 2 +-
 arch/s390/mm/cmm.c| 2 +-
 drivers/atm/idt77105.c| 4 ++--
 drivers/atm/iphase.c  | 2 +-
 drivers/block/ataflop.c   | 8 
 drivers/char/dtlk.c   | 2 +-
 drivers/char/hangcheck-timer.c| 2 +-
 drivers/char/nwbutton.c   | 2 +-
 drivers/char/rtc.c| 2 +-
 drivers/input/touchscreen/s3c2410_ts.c| 2 +-
 drivers/net/cris/eth_v10.c| 6 +++---
 drivers/net/hamradio/yam.c| 2 +-
 drivers/net/wireless/atmel/at76c50x-usb.c | 2 +-
 drivers/staging/speakup/main.c| 2 +-
 drivers/staging/speakup/synth.c   | 2 +-
 drivers/tty/cyclades.c| 2 +-
 drivers/tty/isicom.c  | 2 +-
 drivers/tty/moxa.c| 2 +-
 drivers/tty/rocket.c  | 2 +-
 drivers/tty/vt/keyboard.c | 2 +-
 drivers/tty/vt/vt.c   | 2 +-
 drivers/watchdog/alim7101_wdt.c   | 2 +-
 drivers/watchdog/machzwd.c| 2 +-
 drivers/watchdog/mixcomwd.c   | 2 +-
 drivers/watchdog/sbc60xxwdt.c | 2 +-
 drivers/watchdog/sc520_wdt.c  | 2 +-
 drivers/watchdog/via_wdt.c| 2 +-
 drivers/watchdog/w83877f_wdt.c| 2 +-
 drivers/xen/grant-table.c | 2 +-
 fs/pstore/platform.c  | 2 +-
 include/linux/timer.h | 4 ++--
 kernel/irq/spurious.c | 2 +-
 lib/random32.c| 2 +-
 net/atm/mpc.c | 2 +-
 net/decnet/dn_route.c | 2 +-
 net/ipv6/ip6_flowlabel.c  | 2 +-
 net/netrom/nr_loopback.c  | 2 +-
 security/keys/gc.c| 2 +-
 sound/oss/midibuf.c   | 2 +-
 sound/oss/soundcard.c | 2 +-
 sound/oss/sys_timer.c | 2 +-
 sound/oss/uart6850.c  | 2 +-
 47 files changed, 54 insertions(+), 54 deletions(-)

diff --git a/arch/arm/mach-ixp4xx/dsmg600-setup.c 
b/arch/arm/mach-ixp4xx/dsmg600-setup.c
index b3bd0e137f6d..b3689a141ec6 100644
--- a/arch/arm/mach-ixp4xx/dsmg600-setup.c
+++ b/arch/arm/mach-ixp4xx/dsmg600-setup.c
@@ -174,7 +174,7 @@ static int power_button_countdown;
 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
 
 static void dsmg600_power_handler(unsigned long data);
-static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
+static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler);
 
 static void dsmg600_power_handler(unsigned long data)
 {
diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c 
b/arch/arm/mach-ixp4xx/nas100d-setup.c
index 4e0f762bc651..562d05f9888e 100644
--- a/arch/arm/mach-ixp4xx/nas100d-setup.c
+++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
@@ -197,7 +197,7 @@ static int power_button_countdown;
 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
 
 static void nas100d_power_handler(unsigned long data);
-static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
+static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler);
 
 static void nas100d_power_handler(unsigned long data)
 {
diff --git a/arch/m68k/amiga/amisound.c b/arch/m68k/amiga/amisound.c
index 90a60d758f8b..a23f48181fd6 100644
--- a/arch/m68k/amiga/amisound.c
+++ b/arch/m68k/amiga/amisound.c
@@ -66,7 +66,7 @@ void __init amiga_init_sound(void)
 }
 
 static void nosound( unsigned long ignored );
-static DEFINE_TIMER(sound_timer, nosound, 0, 0);
+static DEFINE_TIMER(sound_timer, nosound);
 
 void amiga_mksound( unsigned int hz, unsigned int ticks )
 {
diff --git a/arch/m68k/mac/macboing.c b/arch/m68k/mac/macboing.c
index ffaa1f6439ae..9a52aff183d0 100644
--- a/arch/m68k/mac/macboing.c
+++ b/arch/m68k/mac/macboing.c
@@ -56,7 +56,7 @@ static void ( *mac_special_bell )( unsigned int, unsigned 
int, unsigned int );
 /*
  * our timer to start/continue/stop the bell
  */
-static DEFINE_TIMER(mac_sound_timer, mac_nosound, 0, 0);
+static DEFINE_TIMER(mac_sound_timer, mac_nosound);
 
 /*
  * Sort of initialize the sound chip (called from mac_mksound on the first
diff --git a/arch/mips/mti-malta/malta-display.c 
b/arch/mips/mti-malta/malta-display.c
index ac813158b9b8..063de44675ce 100644
--- 

[PATCH 12/13] kthread: Convert callback to use from_timer()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer
to all timer callbacks, switch kthread to use from_timer() and pass the
timer pointer explicitly.

Cc: Andrew Morton 
Cc: Petr Mladek 
Cc: Tejun Heo 
Cc: Thomas Gleixner 
Cc: Oleg Nesterov 
Signed-off-by: Kees Cook 
---
 include/linux/kthread.h | 10 +-
 kernel/kthread.c| 10 --
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 0d622b350d3f..35cbe3b0ce5b 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -75,7 +75,7 @@ extern int tsk_fork_get_node(struct task_struct *tsk);
  */
 struct kthread_work;
 typedef void (*kthread_work_func_t)(struct kthread_work *work);
-void kthread_delayed_work_timer_fn(unsigned long __data);
+void kthread_delayed_work_timer_fn(struct timer_list *t);
 
 enum {
KTW_FREEZABLE   = 1 << 0,   /* freeze during suspend */
@@ -116,8 +116,8 @@ struct kthread_delayed_work {
 
 #define KTHREAD_DELAYED_WORK_INIT(dwork, fn) { \
.work = KTHREAD_WORK_INIT((dwork).work, (fn)),  \
-   .timer = __TIMER_INITIALIZER(kthread_delayed_work_timer_fn, \
-(unsigned long)&(dwork),   \
+   .timer = 
__TIMER_INITIALIZER((TIMER_FUNC_TYPE)kthread_delayed_work_timer_fn,\
+(TIMER_DATA_TYPE)&(dwork.timer),   \
 TIMER_IRQSAFE),\
}
 
@@ -164,8 +164,8 @@ extern void __kthread_init_worker(struct kthread_worker 
*worker,
do {\
kthread_init_work(&(dwork)->work, (fn));\
__setup_timer(&(dwork)->timer,  \
- kthread_delayed_work_timer_fn,\
- (unsigned long)(dwork),   \
+ (TIMER_FUNC_TYPE)kthread_delayed_work_timer_fn,\
+ (TIMER_DATA_TYPE)&(dwork)->timer, \
  TIMER_IRQSAFE);   \
} while (0)
 
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 1c19edf82427..ba3992c8c375 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -798,15 +798,14 @@ EXPORT_SYMBOL_GPL(kthread_queue_work);
 /**
  * kthread_delayed_work_timer_fn - callback that queues the associated kthread
  * delayed work when the timer expires.
- * @__data: pointer to the data associated with the timer
+ * @t: pointer to the expired timer
  *
  * The format of the function is defined by struct timer_list.
  * It should have been called from irqsafe timer with irq already off.
  */
-void kthread_delayed_work_timer_fn(unsigned long __data)
+void kthread_delayed_work_timer_fn(struct timer_list *t)
 {
-   struct kthread_delayed_work *dwork =
-   (struct kthread_delayed_work *)__data;
+   struct kthread_delayed_work *dwork = from_timer(dwork, t, timer);
struct kthread_work *work = >work;
struct kthread_worker *worker = work->worker;
 
@@ -837,8 +836,7 @@ void __kthread_queue_delayed_work(struct kthread_worker 
*worker,
struct timer_list *timer = >timer;
struct kthread_work *work = >work;
 
-   WARN_ON_ONCE(timer->function != kthread_delayed_work_timer_fn ||
-timer->data != (unsigned long)dwork);
+   WARN_ON_ONCE(timer->function != 
(TIMER_FUNC_TYPE)kthread_delayed_work_timer_fn);
 
/*
 * If @delay is 0, queue @dwork->work immediately.  This is for
-- 
2.7.4



[PATCH 13/13] workqueue: Convert callback to use from_timer()

2017-10-04 Thread Kees Cook
In preparation for unconditionally passing the struct timer_list pointer
to all timer callbacks, switch workqueue to use from_timer() and pass the
timer pointer explicitly.

Cc: Tejun Heo 
Cc: Lai Jiangshan 
Signed-off-by: Kees Cook 
---
 include/linux/workqueue.h | 15 ---
 kernel/workqueue.c|  7 +++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index f4960260feaf..f3c47a05fd06 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -17,7 +17,7 @@ struct workqueue_struct;
 
 struct work_struct;
 typedef void (*work_func_t)(struct work_struct *work);
-void delayed_work_timer_fn(unsigned long __data);
+void delayed_work_timer_fn(struct timer_list *t);
 
 /*
  * The first word is the work queue pointer and the flags rolled into
@@ -175,8 +175,8 @@ struct execute_work {
 
 #define __DELAYED_WORK_INITIALIZER(n, f, tflags) { \
.work = __WORK_INITIALIZER((n).work, (f)),  \
-   .timer = __TIMER_INITIALIZER(delayed_work_timer_fn, \
-(unsigned long)&(n),   \
+   .timer = __TIMER_INITIALIZER((TIMER_FUNC_TYPE)delayed_work_timer_fn,\
+(TIMER_DATA_TYPE)&(n.timer),   \
 (tflags) | TIMER_IRQSAFE), \
}
 
@@ -241,8 +241,9 @@ static inline unsigned int work_static(struct work_struct 
*work) { return 0; }
 #define __INIT_DELAYED_WORK(_work, _func, _tflags) \
do {\
INIT_WORK(&(_work)->work, (_func)); \
-   __setup_timer(&(_work)->timer, delayed_work_timer_fn,   \
- (unsigned long)(_work),   \
+   __setup_timer(&(_work)->timer,  \
+ (TIMER_FUNC_TYPE)delayed_work_timer_fn,   \
+ (TIMER_DATA_TYPE)&(_work)->timer, \
  (_tflags) | TIMER_IRQSAFE);   \
} while (0)
 
@@ -250,8 +251,8 @@ static inline unsigned int work_static(struct work_struct 
*work) { return 0; }
do {\
INIT_WORK_ONSTACK(&(_work)->work, (_func)); \
__setup_timer_on_stack(&(_work)->timer, \
-  delayed_work_timer_fn,   \
-  (unsigned long)(_work),  \
+  (TIMER_FUNC_TYPE)delayed_work_timer_fn,\
+  (TIMER_DATA_TYPE)&(_work)->timer,\
   (_tflags) | TIMER_IRQSAFE);  \
} while (0)
 
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index a5361fc6215d..c77fdf6bf24f 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1492,9 +1492,9 @@ bool queue_work_on(int cpu, struct workqueue_struct *wq,
 }
 EXPORT_SYMBOL(queue_work_on);
 
-void delayed_work_timer_fn(unsigned long __data)
+void delayed_work_timer_fn(struct timer_list *t)
 {
-   struct delayed_work *dwork = (struct delayed_work *)__data;
+   struct delayed_work *dwork = from_timer(dwork, t, timer);
 
/* should have been called from irqsafe timer with irq already off */
__queue_work(dwork->cpu, dwork->wq, >work);
@@ -1508,8 +1508,7 @@ static void __queue_delayed_work(int cpu, struct 
workqueue_struct *wq,
struct work_struct *work = >work;
 
WARN_ON_ONCE(!wq);
-   WARN_ON_ONCE(timer->function != delayed_work_timer_fn ||
-timer->data != (unsigned long)dwork);
+   WARN_ON_ONCE(timer->function != (TIMER_FUNC_TYPE)delayed_work_timer_fn);
WARN_ON_ONCE(timer_pending(timer));
WARN_ON_ONCE(!list_empty(>entry));
 
-- 
2.7.4



[PATCH 11/13] timer: Remove expires argument from __TIMER_INITIALIZER()

2017-10-04 Thread Kees Cook
The expires field is normally initialized during the first mod_timer()
call. It was unused by all callers, so remove it from the macro.

Signed-off-by: Kees Cook 
---
 include/linux/kthread.h   | 2 +-
 include/linux/timer.h | 5 ++---
 include/linux/workqueue.h | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 82e197eeac91..0d622b350d3f 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -117,7 +117,7 @@ struct kthread_delayed_work {
 #define KTHREAD_DELAYED_WORK_INIT(dwork, fn) { \
.work = KTHREAD_WORK_INIT((dwork).work, (fn)),  \
.timer = __TIMER_INITIALIZER(kthread_delayed_work_timer_fn, \
-0, (unsigned long)&(dwork),\
+(unsigned long)&(dwork),   \
 TIMER_IRQSAFE),\
}
 
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 91e5a2cc81b5..10685c33e679 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -63,10 +63,9 @@ struct timer_list {
 
 #define TIMER_TRACE_FLAGMASK   (TIMER_MIGRATING | TIMER_DEFERRABLE | 
TIMER_PINNED | TIMER_IRQSAFE)
 
-#define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \
+#define __TIMER_INITIALIZER(_function, _data, _flags) {\
.entry = { .next = TIMER_ENTRY_STATIC },\
.function = (_function),\
-   .expires = (_expires),  \
.data = (_data),\
.flags = (_flags),  \
__TIMER_LOCKDEP_MAP_INITIALIZER(\
@@ -75,7 +74,7 @@ struct timer_list {
 
 #define DEFINE_TIMER(_name, _function) \
struct timer_list _name =   \
-   __TIMER_INITIALIZER(_function, 0, 0, 0)
+   __TIMER_INITIALIZER(_function, 0, 0)
 
 void init_timer_key(struct timer_list *timer, unsigned int flags,
const char *name, struct lock_class_key *key);
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 1c49431f3121..f4960260feaf 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -176,7 +176,7 @@ struct execute_work {
 #define __DELAYED_WORK_INITIALIZER(n, f, tflags) { \
.work = __WORK_INITIALIZER((n).work, (f)),  \
.timer = __TIMER_INITIALIZER(delayed_work_timer_fn, \
-0, (unsigned long)&(n),\
+(unsigned long)&(n),   \
 (tflags) | TIMER_IRQSAFE), \
}
 
-- 
2.7.4



  1   2   3   >