aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Duyck <alexander.h.duyck@intel.com>2014-09-04 13:31:35 -0400
committerDavid S. Miller <davem@davemloft.net>2014-09-05 20:43:45 -0400
commit62bccb8cdb69051b95a55ab0c489e3cab261c8ef (patch)
treef1a545f5635070e5022e2bc0ab7b1260644c8588
parent37846ef0188335e49f2491a5bbf4e0dc7d407ea0 (diff)
net-timestamp: Make the clone operation stand-alone from phy timestamping
The phy timestamping takes a different path than the regular timestamping does in that it will create a clone first so that the packets needing to be timestamped can be placed in a queue, or the context block could be used. In order to support these use cases I am pulling the core of the code out so it can be used in other drivers beyond just phy devices. In addition I have added a destructor named sock_efree which is meant to provide a simple way for dropping the reference to skb exceptions that aren't part of either the receive or send windows for the socket, and I have removed some duplication in spots where this destructor could be used in place of sock_edemux. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/phy/dp83640.c6
-rw-r--r--include/linux/skbuff.h2
-rw-r--r--include/net/sock.h1
-rw-r--r--net/core/skbuff.c32
-rw-r--r--net/core/sock.c6
-rw-r--r--net/core/timestamping.c14
6 files changed, 40 insertions, 21 deletions
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index d5991ac46ab0..87648b306551 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -1148,7 +1148,7 @@ static void dp83640_remove(struct phy_device *phydev)
1148 kfree_skb(skb); 1148 kfree_skb(skb);
1149 1149
1150 while ((skb = skb_dequeue(&dp83640->tx_queue)) != NULL) 1150 while ((skb = skb_dequeue(&dp83640->tx_queue)) != NULL)
1151 skb_complete_tx_timestamp(skb, NULL); 1151 kfree_skb(skb);
1152 1152
1153 clock = dp83640_clock_get(dp83640->clock); 1153 clock = dp83640_clock_get(dp83640->clock);
1154 1154
@@ -1405,7 +1405,7 @@ static void dp83640_txtstamp(struct phy_device *phydev,
1405 1405
1406 case HWTSTAMP_TX_ONESTEP_SYNC: 1406 case HWTSTAMP_TX_ONESTEP_SYNC:
1407 if (is_sync(skb, type)) { 1407 if (is_sync(skb, type)) {
1408 skb_complete_tx_timestamp(skb, NULL); 1408 kfree_skb(skb);
1409 return; 1409 return;
1410 } 1410 }
1411 /* fall through */ 1411 /* fall through */
@@ -1416,7 +1416,7 @@ static void dp83640_txtstamp(struct phy_device *phydev,
1416 1416
1417 case HWTSTAMP_TX_OFF: 1417 case HWTSTAMP_TX_OFF:
1418 default: 1418 default:
1419 skb_complete_tx_timestamp(skb, NULL); 1419 kfree_skb(skb);
1420 break; 1420 break;
1421 } 1421 }
1422} 1422}
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 02529fcad1ac..1cf0cfaef10a 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2690,6 +2690,8 @@ static inline ktime_t net_invalid_timestamp(void)
2690 return ktime_set(0, 0); 2690 return ktime_set(0, 0);
2691} 2691}
2692 2692
2693struct sk_buff *skb_clone_sk(struct sk_buff *skb);
2694
2693#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING 2695#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
2694 2696
2695void skb_clone_tx_timestamp(struct sk_buff *skb); 2697void skb_clone_tx_timestamp(struct sk_buff *skb);
diff --git a/include/net/sock.h b/include/net/sock.h
index 3fde6130789d..e02be37a3d91 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1574,6 +1574,7 @@ struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
1574void sock_wfree(struct sk_buff *skb); 1574void sock_wfree(struct sk_buff *skb);
1575void skb_orphan_partial(struct sk_buff *skb); 1575void skb_orphan_partial(struct sk_buff *skb);
1576void sock_rfree(struct sk_buff *skb); 1576void sock_rfree(struct sk_buff *skb);
1577void sock_efree(struct sk_buff *skb);
1577void sock_edemux(struct sk_buff *skb); 1578void sock_edemux(struct sk_buff *skb);
1578 1579
1579int sock_setsockopt(struct socket *sock, int level, int op, 1580int sock_setsockopt(struct socket *sock, int level, int op,
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 697e696c914b..a936a401564e 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3511,6 +3511,27 @@ struct sk_buff *sock_dequeue_err_skb(struct sock *sk)
3511} 3511}
3512EXPORT_SYMBOL(sock_dequeue_err_skb); 3512EXPORT_SYMBOL(sock_dequeue_err_skb);
3513 3513
3514struct sk_buff *skb_clone_sk(struct sk_buff *skb)
3515{
3516 struct sock *sk = skb->sk;
3517 struct sk_buff *clone;
3518
3519 if (!sk || !atomic_inc_not_zero(&sk->sk_refcnt))
3520 return NULL;
3521
3522 clone = skb_clone(skb, GFP_ATOMIC);
3523 if (!clone) {
3524 sock_put(sk);
3525 return NULL;
3526 }
3527
3528 clone->sk = sk;
3529 clone->destructor = sock_efree;
3530
3531 return clone;
3532}
3533EXPORT_SYMBOL(skb_clone_sk);
3534
3514static void __skb_complete_tx_timestamp(struct sk_buff *skb, 3535static void __skb_complete_tx_timestamp(struct sk_buff *skb,
3515 struct sock *sk, 3536 struct sock *sk,
3516 int tstype) 3537 int tstype)
@@ -3540,14 +3561,11 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
3540{ 3561{
3541 struct sock *sk = skb->sk; 3562 struct sock *sk = skb->sk;
3542 3563
3543 skb->sk = NULL; 3564 /* take a reference to prevent skb_orphan() from freeing the socket */
3565 sock_hold(sk);
3544 3566
3545 if (hwtstamps) { 3567 *skb_hwtstamps(skb) = *hwtstamps;
3546 *skb_hwtstamps(skb) = *hwtstamps; 3568 __skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND);
3547 __skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND);
3548 } else {
3549 kfree_skb(skb);
3550 }
3551 3569
3552 sock_put(sk); 3570 sock_put(sk);
3553} 3571}
diff --git a/net/core/sock.c b/net/core/sock.c
index f1a638ee93d9..d04005c51724 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1637,6 +1637,12 @@ void sock_rfree(struct sk_buff *skb)
1637} 1637}
1638EXPORT_SYMBOL(sock_rfree); 1638EXPORT_SYMBOL(sock_rfree);
1639 1639
1640void sock_efree(struct sk_buff *skb)
1641{
1642 sock_put(skb->sk);
1643}
1644EXPORT_SYMBOL(sock_efree);
1645
1640void sock_edemux(struct sk_buff *skb) 1646void sock_edemux(struct sk_buff *skb)
1641{ 1647{
1642 struct sock *sk = skb->sk; 1648 struct sock *sk = skb->sk;
diff --git a/net/core/timestamping.c b/net/core/timestamping.c
index f48a59fd8f39..43d3dd62fcc8 100644
--- a/net/core/timestamping.c
+++ b/net/core/timestamping.c
@@ -36,10 +36,9 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
36{ 36{
37 struct phy_device *phydev; 37 struct phy_device *phydev;
38 struct sk_buff *clone; 38 struct sk_buff *clone;
39 struct sock *sk = skb->sk;
40 unsigned int type; 39 unsigned int type;
41 40
42 if (!sk) 41 if (!skb->sk)
43 return; 42 return;
44 43
45 type = classify(skb); 44 type = classify(skb);
@@ -48,16 +47,9 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
48 47
49 phydev = skb->dev->phydev; 48 phydev = skb->dev->phydev;
50 if (likely(phydev->drv->txtstamp)) { 49 if (likely(phydev->drv->txtstamp)) {
51 if (!atomic_inc_not_zero(&sk->sk_refcnt)) 50 clone = skb_clone_sk(skb);
51 if (!clone)
52 return; 52 return;
53
54 clone = skb_clone(skb, GFP_ATOMIC);
55 if (!clone) {
56 sock_put(sk);
57 return;
58 }
59
60 clone->sk = sk;
61 phydev->drv->txtstamp(phydev, clone, type); 53 phydev->drv->txtstamp(phydev, clone, type);
62 } 54 }
63} 55}