* [PATCH] net: sched: Add support for packet bursting.
@ 2021-06-25 12:03 Niclas Hedam
2021-06-25 20:54 ` kernel test robot
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Niclas Hedam @ 2021-06-25 12:03 UTC (permalink / raw)
To: stephen@networkplumber.org; +Cc: netdev@vger.kernel.org
Hello,
This patch implements packet bursting in the NetEm scheduler.
This allows system administrators to hold back outgoing
packets and release them at a multiple of a time quantum.
This feature can be used to prevent timing attacks caused
by network latency.
I'm currently publishing a paper on this, which is currently not
publicly available, but the idea is based on Predictive Black-Box
Mitigation of Timing Channels
(https://dl.acm.org/doi/pdf/10.1145/1866307.1866341).
Signed-off-by: Niclas Hedam <niclas@hed.am>
---
include/uapi/linux/pkt_sched.h | 2 ++
net/sched/sch_netem.c | 24 +++++++++++++++++++++---
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h
index 79a699f106b1..826d1dee6601 100644
--- a/include/uapi/linux/pkt_sched.h
+++ b/include/uapi/linux/pkt_sched.h
@@ -594,6 +594,7 @@ enum {
TCA_NETEM_DELAY_DIST,
TCA_NETEM_REORDER,
TCA_NETEM_CORRUPT,
+ TCA_NETEM_BURSTING,
TCA_NETEM_LOSS,
TCA_NETEM_RATE,
TCA_NETEM_ECN,
@@ -615,6 +616,7 @@ struct tc_netem_qopt {
__u32 gap; /* re-ordering gap (0 for none) */
__u32 duplicate; /* random packet dup (0=none ~0=100%) */
__u32 jitter; /* random jitter in latency (us) */
+ __u32 bursting; /* send packets in bursts (us) */
};
struct tc_netem_corr {
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 0c345e43a09a..52d796287b86 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -85,6 +85,7 @@ struct netem_sched_data {
s64 latency;
s64 jitter;
+ u32 bursting;
u32 loss;
u32 ecn;
u32 limit;
@@ -467,7 +468,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
/* If a delay is expected, orphan the skb. (orphaning usually takes
* place at TX completion time, so _before_ the link transit delay)
*/
- if (q->latency || q->jitter || q->rate)
+ if (q->latency || q->jitter || q->rate || q->bursting)
skb_orphan_partial(skb);
/*
@@ -527,8 +528,17 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
qdisc_qstats_backlog_inc(sch, skb);
cb = netem_skb_cb(skb);
- if (q->gap == 0 || /* not doing reordering */
- q->counter < q->gap - 1 || /* inside last reordering gap */
+ if (q->bursting > 0) {
+ u64 now;
+
+ now = ktime_get_ns();
+
+ cb->time_to_send = now - (now % q->bursting) + q->bursting;
+
+ ++q->counter;
+ tfifo_enqueue(skb, sch);
+ } else if (q->gap == 0 || /* not doing reordering */
+ q->counter < q->gap - 1 || /* inside last reordering gap */
q->reorder < get_crandom(&q->reorder_cor)) {
u64 now;
s64 delay;
@@ -927,6 +937,7 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
[TCA_NETEM_ECN] = { .type = NLA_U32 },
[TCA_NETEM_RATE64] = { .type = NLA_U64 },
[TCA_NETEM_LATENCY64] = { .type = NLA_S64 },
+ [TCA_NETEM_BURSTING] = { .type = NLA_U64 },
[TCA_NETEM_JITTER64] = { .type = NLA_S64 },
[TCA_NETEM_SLOT] = { .len = sizeof(struct tc_netem_slot) },
};
@@ -1001,6 +1012,7 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt,
q->latency = PSCHED_TICKS2NS(qopt->latency);
q->jitter = PSCHED_TICKS2NS(qopt->jitter);
+ q->bursting = PSCHED_TICKS2NS(qopt->bursting);
q->limit = qopt->limit;
q->gap = qopt->gap;
q->counter = 0;
@@ -1032,6 +1044,9 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt,
if (tb[TCA_NETEM_LATENCY64])
q->latency = nla_get_s64(tb[TCA_NETEM_LATENCY64]);
+ if (tb[TCA_NETEM_BURSTING])
+ q->bursting = nla_get_u64(tb[TCA_NETEM_BURSTING]);
+
if (tb[TCA_NETEM_JITTER64])
q->jitter = nla_get_s64(tb[TCA_NETEM_JITTER64]);
@@ -1150,6 +1165,9 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
UINT_MAX);
qopt.jitter = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->jitter),
UINT_MAX);
+ qopt.bursting = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->bursting),
+ UINT_MAX);
+
qopt.limit = q->limit;
qopt.loss = q->loss;
qopt.gap = q->gap;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] net: sched: Add support for packet bursting. 2021-06-25 12:03 [PATCH] net: sched: Add support for packet bursting Niclas Hedam @ 2021-06-25 20:54 ` kernel test robot 2021-06-25 22:34 ` kernel test robot 2021-06-27 18:32 ` Cong Wang 2 siblings, 0 replies; 5+ messages in thread From: kernel test robot @ 2021-06-25 20:54 UTC (permalink / raw) To: Niclas Hedam, stephen@networkplumber.org Cc: kbuild-all, netdev@vger.kernel.org [-- Attachment #1: Type: text/plain, Size: 1742 bytes --] Hi Niclas, Thank you for the patch! Yet something to improve: [auto build test ERROR on net/master] [also build test ERROR on ipvs/master net-next/master linus/master v5.13-rc7 next-20210625] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/Niclas-Hedam/net-sched-Add-support-for-packet-bursting/20210625-200450 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git be7f62eebaff2f86c1467a2d33930a0a7a87675b config: m68k-allyesconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/0day-ci/linux/commit/dca330eed26fd2835927462dcca58379dd5599a5 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Niclas-Hedam/net-sched-Add-support-for-packet-bursting/20210625-200450 git checkout dca330eed26fd2835927462dcca58379dd5599a5 # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): m68k-linux-ld: net/sched/sch_netem.o: in function `netem_enqueue': >> sch_netem.c:(.text+0x10aa): undefined reference to `__umoddi3' --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 60708 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: sched: Add support for packet bursting. 2021-06-25 12:03 [PATCH] net: sched: Add support for packet bursting Niclas Hedam 2021-06-25 20:54 ` kernel test robot @ 2021-06-25 22:34 ` kernel test robot 2021-06-27 18:32 ` Cong Wang 2 siblings, 0 replies; 5+ messages in thread From: kernel test robot @ 2021-06-25 22:34 UTC (permalink / raw) To: Niclas Hedam, stephen@networkplumber.org Cc: kbuild-all, netdev@vger.kernel.org [-- Attachment #1: Type: text/plain, Size: 2247 bytes --] Hi Niclas, Thank you for the patch! Yet something to improve: [auto build test ERROR on net/master] [also build test ERROR on ipvs/master net-next/master linus/master v5.13-rc7 next-20210625] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/Niclas-Hedam/net-sched-Add-support-for-packet-bursting/20210625-200450 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git be7f62eebaff2f86c1467a2d33930a0a7a87675b config: sh-allmodconfig (attached as .config) compiler: sh4-linux-gcc (GCC) 9.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/0day-ci/linux/commit/dca330eed26fd2835927462dcca58379dd5599a5 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Niclas-Hedam/net-sched-Add-support-for-packet-bursting/20210625-200450 git checkout dca330eed26fd2835927462dcca58379dd5599a5 # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>, old ones prefixed by <<): >> ERROR: modpost: "__umoddi3" [net/sched/sch_netem.ko] undefined! ERROR: modpost: "__delay" [drivers/net/mdio/mdio-cavium.ko] undefined! ERROR: modpost: "__udivdi3" [fs/btrfs/btrfs.ko] undefined! ERROR: modpost: "__umoddi3" [fs/btrfs/btrfs.ko] undefined! Kconfig warnings: (for reference only) WARNING: unmet direct dependencies detected for SND_ATMEL_SOC_PDC Depends on SOUND && !UML && SND && SND_SOC && SND_ATMEL_SOC && HAS_DMA Selected by - SND_ATMEL_SOC_SSC && SOUND && !UML && SND && SND_SOC && SND_ATMEL_SOC - SND_ATMEL_SOC_SSC_PDC && SOUND && !UML && SND && SND_SOC && SND_ATMEL_SOC && ATMEL_SSC --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 54789 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: sched: Add support for packet bursting. 2021-06-25 12:03 [PATCH] net: sched: Add support for packet bursting Niclas Hedam 2021-06-25 20:54 ` kernel test robot 2021-06-25 22:34 ` kernel test robot @ 2021-06-27 18:32 ` Cong Wang 2021-06-27 19:12 ` Niclas Hedam 2 siblings, 1 reply; 5+ messages in thread From: Cong Wang @ 2021-06-27 18:32 UTC (permalink / raw) To: Niclas Hedam; +Cc: stephen@networkplumber.org, netdev@vger.kernel.org On Fri, Jun 25, 2021 at 5:03 AM Niclas Hedam <nhed@itu.dk> wrote: > diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h > index 79a699f106b1..826d1dee6601 100644 > --- a/include/uapi/linux/pkt_sched.h > +++ b/include/uapi/linux/pkt_sched.h > @@ -594,6 +594,7 @@ enum { > TCA_NETEM_DELAY_DIST, > TCA_NETEM_REORDER, > TCA_NETEM_CORRUPT, > + TCA_NETEM_BURSTING, > TCA_NETEM_LOSS, > TCA_NETEM_RATE, > TCA_NETEM_ECN, You can't add a new enum in the middle, as it is UAPI. Thanks. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: sched: Add support for packet bursting. 2021-06-27 18:32 ` Cong Wang @ 2021-06-27 19:12 ` Niclas Hedam 0 siblings, 0 replies; 5+ messages in thread From: Niclas Hedam @ 2021-06-27 19:12 UTC (permalink / raw) To: Cong Wang; +Cc: stephen@networkplumber.org, netdev@vger.kernel.org Hi Cong, Good point. Here is a new patch. From 71843907bdb9cdc4e24358f0c16a8778f2762dc7 Mon Sep 17 00:00:00 2001 From: Niclas Hedam <nhed@itu.dk> Date: Fri, 25 Jun 2021 13:37:18 +0200 Subject: [PATCH] net: sched: Add support for packet bursting. This commit implements packet bursting in the NetEm scheduler. This allows system administrators to hold back outgoing packets and release them at a multiple of a time quantum. This feature can be used to prevent timing attacks caused by network latency. Signed-off-by: Niclas Hedam <niclas@hed.am> --- include/uapi/linux/pkt_sched.h | 2 ++ net/sched/sch_netem.c | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h index 79a699f106b1..1ba49f141dae 100644 --- a/include/uapi/linux/pkt_sched.h +++ b/include/uapi/linux/pkt_sched.h @@ -603,6 +603,7 @@ enum { TCA_NETEM_JITTER64, TCA_NETEM_SLOT, TCA_NETEM_SLOT_DIST, + TCA_NETEM_BURSTING, __TCA_NETEM_MAX, }; @@ -615,6 +616,7 @@ struct tc_netem_qopt { __u32 gap; /* re-ordering gap (0 for none) */ __u32 duplicate; /* random packet dup (0=none ~0=100%) */ __u32 jitter; /* random jitter in latency (us) */ + __u32 bursting; /* send packets in bursts (us) */ }; struct tc_netem_corr { diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index 0c345e43a09a..52d796287b86 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -85,6 +85,7 @@ struct netem_sched_data { s64 latency; s64 jitter; + u32 bursting; u32 loss; u32 ecn; u32 limit; @@ -467,7 +468,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch, /* If a delay is expected, orphan the skb. (orphaning usually takes * place at TX completion time, so _before_ the link transit delay) */ - if (q->latency || q->jitter || q->rate) + if (q->latency || q->jitter || q->rate || q->bursting) skb_orphan_partial(skb); /* @@ -527,8 +528,17 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch, qdisc_qstats_backlog_inc(sch, skb); cb = netem_skb_cb(skb); - if (q->gap == 0 || /* not doing reordering */ - q->counter < q->gap - 1 || /* inside last reordering gap */ + if (q->bursting > 0) { + u64 now; + + now = ktime_get_ns(); + + cb->time_to_send = now - (now % q->bursting) + q->bursting; + + ++q->counter; + tfifo_enqueue(skb, sch); + } else if (q->gap == 0 || /* not doing reordering */ + q->counter < q->gap - 1 || /* inside last reordering gap */ q->reorder < get_crandom(&q->reorder_cor)) { u64 now; s64 delay; @@ -927,6 +937,7 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = { [TCA_NETEM_ECN] = { .type = NLA_U32 }, [TCA_NETEM_RATE64] = { .type = NLA_U64 }, [TCA_NETEM_LATENCY64] = { .type = NLA_S64 }, + [TCA_NETEM_BURSTING] = { .type = NLA_U64 }, [TCA_NETEM_JITTER64] = { .type = NLA_S64 }, [TCA_NETEM_SLOT] = { .len = sizeof(struct tc_netem_slot) }, }; @@ -1001,6 +1012,7 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt, q->latency = PSCHED_TICKS2NS(qopt->latency); q->jitter = PSCHED_TICKS2NS(qopt->jitter); + q->bursting = PSCHED_TICKS2NS(qopt->bursting); q->limit = qopt->limit; q->gap = qopt->gap; q->counter = 0; @@ -1032,6 +1044,9 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt, if (tb[TCA_NETEM_LATENCY64]) q->latency = nla_get_s64(tb[TCA_NETEM_LATENCY64]); + if (tb[TCA_NETEM_BURSTING]) + q->bursting = nla_get_u64(tb[TCA_NETEM_BURSTING]); + if (tb[TCA_NETEM_JITTER64]) q->jitter = nla_get_s64(tb[TCA_NETEM_JITTER64]); @@ -1150,6 +1165,9 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb) UINT_MAX); qopt.jitter = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->jitter), UINT_MAX); + qopt.bursting = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->bursting), + UINT_MAX); + qopt.limit = q->limit; qopt.loss = q->loss; qopt.gap = q->gap; -- 2.25.1 > On 27 Jun 2021, at 20:32, Cong Wang <xiyou.wangcong@gmail.com> wrote: > > On Fri, Jun 25, 2021 at 5:03 AM Niclas Hedam <nhed@itu.dk> wrote: >> diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h >> index 79a699f106b1..826d1dee6601 100644 >> --- a/include/uapi/linux/pkt_sched.h >> +++ b/include/uapi/linux/pkt_sched.h >> @@ -594,6 +594,7 @@ enum { >> TCA_NETEM_DELAY_DIST, >> TCA_NETEM_REORDER, >> TCA_NETEM_CORRUPT, >> + TCA_NETEM_BURSTING, >> TCA_NETEM_LOSS, >> TCA_NETEM_RATE, >> TCA_NETEM_ECN, > > You can't add a new enum in the middle, as it is UAPI. > > Thanks. ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-06-27 19:12 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-06-25 12:03 [PATCH] net: sched: Add support for packet bursting Niclas Hedam 2021-06-25 20:54 ` kernel test robot 2021-06-25 22:34 ` kernel test robot 2021-06-27 18:32 ` Cong Wang 2021-06-27 19:12 ` Niclas Hedam
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).