aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/boot/dts/am33xx.dtsi6
-rw-r--r--arch/arm/boot/dts/berlin2q-marvell-dmp.dts4
-rw-r--r--arch/arm/boot/dts/berlin2q.dtsi17
-rw-r--r--arch/arm/boot/dts/imx6sx.dtsi2
-rw-r--r--arch/arm/boot/dts/rk3188-radxarock.dts22
-rw-r--r--arch/arm/boot/dts/rk3188.dtsi22
-rw-r--r--arch/arm/boot/dts/rk3xxx.dtsi17
-rw-r--r--arch/arm/net/bpf_jit_32.c37
-rw-r--r--arch/arm/net/bpf_jit_32.h14
-rw-r--r--arch/arm/plat-orion/common.c2
-rw-r--r--arch/mips/bcm47xx/setup.c4
-rw-r--r--arch/mips/net/bpf_jit.c33
-rw-r--r--arch/powerpc/net/bpf_jit_comp.c5
-rw-r--r--arch/s390/net/bpf_jit_comp.c84
-rw-r--r--arch/sparc/include/asm/vio.h44
-rw-r--r--arch/sparc/kernel/ldc.c2
-rw-r--r--arch/sparc/kernel/viohs.c14
-rw-r--r--arch/sparc/net/bpf_jit_comp.c21
-rw-r--r--arch/x86/net/bpf_jit_comp.c129
-rw-r--r--arch/x86/syscalls/syscall_32.tbl1
-rw-r--r--arch/x86/syscalls/syscall_64.tbl1
21 files changed, 302 insertions, 179 deletions
diff --git a/arch/arm/boot/dts/am33xx.dtsi b/arch/arm/boot/dts/am33xx.dtsi
index 3a0a161342ba..13e44b0f5adc 100644
--- a/arch/arm/boot/dts/am33xx.dtsi
+++ b/arch/arm/boot/dts/am33xx.dtsi
@@ -132,6 +132,11 @@
132 }; 132 };
133 }; 133 };
134 134
135 cm: syscon@44e10000 {
136 compatible = "ti,am33xx-controlmodule", "syscon";
137 reg = <0x44e10000 0x800>;
138 };
139
135 intc: interrupt-controller@48200000 { 140 intc: interrupt-controller@48200000 {
136 compatible = "ti,omap2-intc"; 141 compatible = "ti,omap2-intc";
137 interrupt-controller; 142 interrupt-controller;
@@ -696,6 +701,7 @@
696 */ 701 */
697 interrupts = <40 41 42 43>; 702 interrupts = <40 41 42 43>;
698 ranges; 703 ranges;
704 syscon = <&cm>;
699 status = "disabled"; 705 status = "disabled";
700 706
701 davinci_mdio: mdio@4a101000 { 707 davinci_mdio: mdio@4a101000 {
diff --git a/arch/arm/boot/dts/berlin2q-marvell-dmp.dts b/arch/arm/boot/dts/berlin2q-marvell-dmp.dts
index a357ce02a64e..ea1f99b8eed6 100644
--- a/arch/arm/boot/dts/berlin2q-marvell-dmp.dts
+++ b/arch/arm/boot/dts/berlin2q-marvell-dmp.dts
@@ -45,3 +45,7 @@
45&uart0 { 45&uart0 {
46 status = "okay"; 46 status = "okay";
47}; 47};
48
49&eth0 {
50 status = "okay";
51};
diff --git a/arch/arm/boot/dts/berlin2q.dtsi b/arch/arm/boot/dts/berlin2q.dtsi
index 400c40fceccc..891d56b03922 100644
--- a/arch/arm/boot/dts/berlin2q.dtsi
+++ b/arch/arm/boot/dts/berlin2q.dtsi
@@ -114,6 +114,23 @@
114 #interrupt-cells = <3>; 114 #interrupt-cells = <3>;
115 }; 115 };
116 116
117 eth0: ethernet@b90000 {
118 compatible = "marvell,pxa168-eth";
119 reg = <0xb90000 0x10000>;
120 clocks = <&chip CLKID_GETH0>;
121 interrupts = <GIC_SPI 24 IRQ_TYPE_LEVEL_HIGH>;
122 /* set by bootloader */
123 local-mac-address = [00 00 00 00 00 00];
124 #address-cells = <1>;
125 #size-cells = <0>;
126 phy-handle = <&ethphy0>;
127 status = "disabled";
128
129 ethphy0: ethernet-phy@0 {
130 reg = <0>;
131 };
132 };
133
117 cpu-ctrl@dd0000 { 134 cpu-ctrl@dd0000 {
118 compatible = "marvell,berlin-cpu-ctrl"; 135 compatible = "marvell,berlin-cpu-ctrl";
119 reg = <0xdd0000 0x10000>; 136 reg = <0xdd0000 0x10000>;
diff --git a/arch/arm/boot/dts/imx6sx.dtsi b/arch/arm/boot/dts/imx6sx.dtsi
index f4b9da65bc0f..0a03260c1707 100644
--- a/arch/arm/boot/dts/imx6sx.dtsi
+++ b/arch/arm/boot/dts/imx6sx.dtsi
@@ -776,6 +776,8 @@
776 <&clks IMX6SX_CLK_ENET_PTP>; 776 <&clks IMX6SX_CLK_ENET_PTP>;
777 clock-names = "ipg", "ahb", "ptp", 777 clock-names = "ipg", "ahb", "ptp",
778 "enet_clk_ref", "enet_out"; 778 "enet_clk_ref", "enet_out";
779 fsl,num-tx-queues=<3>;
780 fsl,num-rx-queues=<3>;
779 status = "disabled"; 781 status = "disabled";
780 }; 782 };
781 783
diff --git a/arch/arm/boot/dts/rk3188-radxarock.dts b/arch/arm/boot/dts/rk3188-radxarock.dts
index 5e4e3c238b2d..d63d685ea6cc 100644
--- a/arch/arm/boot/dts/rk3188-radxarock.dts
+++ b/arch/arm/boot/dts/rk3188-radxarock.dts
@@ -76,6 +76,22 @@
76 }; 76 };
77}; 77};
78 78
79&emac {
80 status = "okay";
81
82 pinctrl-names = "default";
83 pinctrl-0 = <&emac_xfer>, <&emac_mdio>, <&phy_int>;
84
85 phy = <&phy0>;
86 phy-supply = <&vcc_rmii>;
87
88 phy0: ethernet-phy@0 {
89 reg = <0>;
90 interrupt-parent = <&gpio3>;
91 interrupts = <26 IRQ_TYPE_LEVEL_LOW>;
92 };
93};
94
79&i2c1 { 95&i2c1 {
80 status = "okay"; 96 status = "okay";
81 clock-frequency = <400000>; 97 clock-frequency = <400000>;
@@ -201,6 +217,12 @@
201 }; 217 };
202 }; 218 };
203 219
220 lan8720a {
221 phy_int: phy-int {
222 rockchip,pins = <RK_GPIO3 26 RK_FUNC_GPIO &pcfg_pull_up>;
223 };
224 };
225
204 ir-receiver { 226 ir-receiver {
205 ir_recv_pin: ir-recv-pin { 227 ir_recv_pin: ir-recv-pin {
206 rockchip,pins = <RK_GPIO0 10 RK_FUNC_GPIO &pcfg_pull_none>; 228 rockchip,pins = <RK_GPIO0 10 RK_FUNC_GPIO &pcfg_pull_none>;
diff --git a/arch/arm/boot/dts/rk3188.dtsi b/arch/arm/boot/dts/rk3188.dtsi
index ee801a9c6b74..7f25bc51f2ee 100644
--- a/arch/arm/boot/dts/rk3188.dtsi
+++ b/arch/arm/boot/dts/rk3188.dtsi
@@ -147,6 +147,24 @@
147 bias-disable; 147 bias-disable;
148 }; 148 };
149 149
150 emac {
151 emac_xfer: emac-xfer {
152 rockchip,pins = <RK_GPIO3 16 RK_FUNC_2 &pcfg_pull_none>, /* tx_en */
153 <RK_GPIO3 17 RK_FUNC_2 &pcfg_pull_none>, /* txd1 */
154 <RK_GPIO3 18 RK_FUNC_2 &pcfg_pull_none>, /* txd0 */
155 <RK_GPIO3 19 RK_FUNC_2 &pcfg_pull_none>, /* rxd0 */
156 <RK_GPIO3 20 RK_FUNC_2 &pcfg_pull_none>, /* rxd1 */
157 <RK_GPIO3 21 RK_FUNC_2 &pcfg_pull_none>, /* mac_clk */
158 <RK_GPIO3 22 RK_FUNC_2 &pcfg_pull_none>, /* rx_err */
159 <RK_GPIO3 23 RK_FUNC_2 &pcfg_pull_none>; /* crs_dvalid */
160 };
161
162 emac_mdio: emac-mdio {
163 rockchip,pins = <RK_GPIO3 24 RK_FUNC_2 &pcfg_pull_none>,
164 <RK_GPIO3 25 RK_FUNC_2 &pcfg_pull_none>;
165 };
166 };
167
150 i2c0 { 168 i2c0 {
151 i2c0_xfer: i2c0-xfer { 169 i2c0_xfer: i2c0-xfer {
152 rockchip,pins = <RK_GPIO1 24 RK_FUNC_1 &pcfg_pull_none>, 170 rockchip,pins = <RK_GPIO1 24 RK_FUNC_1 &pcfg_pull_none>,
@@ -323,6 +341,10 @@
323 }; 341 };
324}; 342};
325 343
344&emac {
345 compatible = "rockchip,rk3188-emac";
346};
347
326&global_timer { 348&global_timer {
327 interrupts = <GIC_PPI 11 0xf04>; 349 interrupts = <GIC_PPI 11 0xf04>;
328}; 350};
diff --git a/arch/arm/boot/dts/rk3xxx.dtsi b/arch/arm/boot/dts/rk3xxx.dtsi
index 8caf85d83901..208b1df6bcb0 100644
--- a/arch/arm/boot/dts/rk3xxx.dtsi
+++ b/arch/arm/boot/dts/rk3xxx.dtsi
@@ -91,6 +91,23 @@
91 status = "disabled"; 91 status = "disabled";
92 }; 92 };
93 93
94 emac: ethernet@10204000 {
95 compatible = "snps,arc-emac";
96 reg = <0x10204000 0x3c>;
97 interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>;
98 #address-cells = <1>;
99 #size-cells = <0>;
100
101 rockchip,grf = <&grf>;
102
103 clocks = <&cru HCLK_EMAC>, <&cru SCLK_MAC>;
104 clock-names = "hclk", "macref";
105 max-speed = <100>;
106 phy-mode = "rmii";
107
108 status = "disabled";
109 };
110
94 mmc0: dwmmc@10214000 { 111 mmc0: dwmmc@10214000 {
95 compatible = "rockchip,rk2928-dw-mshc"; 112 compatible = "rockchip,rk2928-dw-mshc";
96 reg = <0x10214000 0x1000>; 113 reg = <0x10214000 0x1000>;
diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
index a37b989a2f91..e1268f905026 100644
--- a/arch/arm/net/bpf_jit_32.c
+++ b/arch/arm/net/bpf_jit_32.c
@@ -12,11 +12,11 @@
12#include <linux/compiler.h> 12#include <linux/compiler.h>
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/filter.h> 14#include <linux/filter.h>
15#include <linux/moduleloader.h>
16#include <linux/netdevice.h> 15#include <linux/netdevice.h>
17#include <linux/string.h> 16#include <linux/string.h>
18#include <linux/slab.h> 17#include <linux/slab.h>
19#include <linux/if_vlan.h> 18#include <linux/if_vlan.h>
19
20#include <asm/cacheflush.h> 20#include <asm/cacheflush.h>
21#include <asm/hwcap.h> 21#include <asm/hwcap.h>
22#include <asm/opcodes.h> 22#include <asm/opcodes.h>
@@ -174,6 +174,14 @@ static inline bool is_load_to_a(u16 inst)
174 } 174 }
175} 175}
176 176
177static void jit_fill_hole(void *area, unsigned int size)
178{
179 u32 *ptr;
180 /* We are guaranteed to have aligned memory. */
181 for (ptr = area; size >= sizeof(u32); size -= sizeof(u32))
182 *ptr++ = __opcode_to_mem_arm(ARM_INST_UDF);
183}
184
177static void build_prologue(struct jit_ctx *ctx) 185static void build_prologue(struct jit_ctx *ctx)
178{ 186{
179 u16 reg_set = saved_regs(ctx); 187 u16 reg_set = saved_regs(ctx);
@@ -859,9 +867,11 @@ b_epilogue:
859 867
860void bpf_jit_compile(struct bpf_prog *fp) 868void bpf_jit_compile(struct bpf_prog *fp)
861{ 869{
870 struct bpf_binary_header *header;
862 struct jit_ctx ctx; 871 struct jit_ctx ctx;
863 unsigned tmp_idx; 872 unsigned tmp_idx;
864 unsigned alloc_size; 873 unsigned alloc_size;
874 u8 *target_ptr;
865 875
866 if (!bpf_jit_enable) 876 if (!bpf_jit_enable)
867 return; 877 return;
@@ -897,13 +907,15 @@ void bpf_jit_compile(struct bpf_prog *fp)
897 /* there's nothing after the epilogue on ARMv7 */ 907 /* there's nothing after the epilogue on ARMv7 */
898 build_epilogue(&ctx); 908 build_epilogue(&ctx);
899#endif 909#endif
900
901 alloc_size = 4 * ctx.idx; 910 alloc_size = 4 * ctx.idx;
902 ctx.target = module_alloc(alloc_size); 911 header = bpf_jit_binary_alloc(alloc_size, &target_ptr,
903 if (unlikely(ctx.target == NULL)) 912 4, jit_fill_hole);
913 if (header == NULL)
904 goto out; 914 goto out;
905 915
916 ctx.target = (u32 *) target_ptr;
906 ctx.idx = 0; 917 ctx.idx = 0;
918
907 build_prologue(&ctx); 919 build_prologue(&ctx);
908 build_body(&ctx); 920 build_body(&ctx);
909 build_epilogue(&ctx); 921 build_epilogue(&ctx);
@@ -919,8 +931,9 @@ void bpf_jit_compile(struct bpf_prog *fp)
919 /* there are 2 passes here */ 931 /* there are 2 passes here */
920 bpf_jit_dump(fp->len, alloc_size, 2, ctx.target); 932 bpf_jit_dump(fp->len, alloc_size, 2, ctx.target);
921 933
934 set_memory_ro((unsigned long)header, header->pages);
922 fp->bpf_func = (void *)ctx.target; 935 fp->bpf_func = (void *)ctx.target;
923 fp->jited = 1; 936 fp->jited = true;
924out: 937out:
925 kfree(ctx.offsets); 938 kfree(ctx.offsets);
926 return; 939 return;
@@ -928,7 +941,15 @@ out:
928 941
929void bpf_jit_free(struct bpf_prog *fp) 942void bpf_jit_free(struct bpf_prog *fp)
930{ 943{
931 if (fp->jited) 944 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
932 module_free(NULL, fp->bpf_func); 945 struct bpf_binary_header *header = (void *)addr;
933 kfree(fp); 946
947 if (!fp->jited)
948 goto free_filter;
949
950 set_memory_rw(addr, header->pages);
951 bpf_jit_binary_free(header);
952
953free_filter:
954 bpf_prog_unlock_free(fp);
934} 955}
diff --git a/arch/arm/net/bpf_jit_32.h b/arch/arm/net/bpf_jit_32.h
index afb84621ff6f..b2d7d92859d3 100644
--- a/arch/arm/net/bpf_jit_32.h
+++ b/arch/arm/net/bpf_jit_32.h
@@ -114,6 +114,20 @@
114 114
115#define ARM_INST_UMULL 0x00800090 115#define ARM_INST_UMULL 0x00800090
116 116
117/*
118 * Use a suitable undefined instruction to use for ARM/Thumb2 faulting.
119 * We need to be careful not to conflict with those used by other modules
120 * (BUG, kprobes, etc) and the register_undef_hook() system.
121 *
122 * The ARM architecture reference manual guarantees that the following
123 * instruction space will produce an undefined instruction exception on
124 * all CPUs:
125 *
126 * ARM: xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx ARMv7-AR, section A5.4
127 * Thumb: 1101 1110 xxxx xxxx ARMv7-M, section A5.2.6
128 */
129#define ARM_INST_UDF 0xe7fddef1
130
117/* register */ 131/* register */
118#define _AL3_R(op, rd, rn, rm) ((op ## _R) | (rd) << 12 | (rn) << 16 | (rm)) 132#define _AL3_R(op, rd, rn, rm) ((op ## _R) | (rd) << 12 | (rn) << 16 | (rm))
119/* immediate */ 133/* immediate */
diff --git a/arch/arm/plat-orion/common.c b/arch/arm/plat-orion/common.c
index 3ec6e8e8d368..f5b00f41c4f6 100644
--- a/arch/arm/plat-orion/common.c
+++ b/arch/arm/plat-orion/common.c
@@ -499,7 +499,7 @@ void __init orion_ge00_switch_init(struct dsa_platform_data *d, int irq)
499 499
500 d->netdev = &orion_ge00.dev; 500 d->netdev = &orion_ge00.dev;
501 for (i = 0; i < d->nr_chips; i++) 501 for (i = 0; i < d->nr_chips; i++)
502 d->chip[i].mii_bus = &orion_ge00_shared.dev; 502 d->chip[i].host_dev = &orion_ge00_shared.dev;
503 orion_switch_device.dev.platform_data = d; 503 orion_switch_device.dev.platform_data = d;
504 504
505 platform_device_register(&orion_switch_device); 505 platform_device_register(&orion_switch_device);
diff --git a/arch/mips/bcm47xx/setup.c b/arch/mips/bcm47xx/setup.c
index ad439c273003..c00585d915bc 100644
--- a/arch/mips/bcm47xx/setup.c
+++ b/arch/mips/bcm47xx/setup.c
@@ -211,6 +211,10 @@ static void __init bcm47xx_register_bcma(void)
211 211
212 err = bcma_host_soc_register(&bcm47xx_bus.bcma); 212 err = bcma_host_soc_register(&bcm47xx_bus.bcma);
213 if (err) 213 if (err)
214 panic("Failed to register BCMA bus (err %d)", err);
215
216 err = bcma_host_soc_init(&bcm47xx_bus.bcma);
217 if (err)
214 panic("Failed to initialize BCMA bus (err %d)", err); 218 panic("Failed to initialize BCMA bus (err %d)", err);
215 219
216 bcm47xx_fill_bcma_boardinfo(&bcm47xx_bus.bcma.bus.boardinfo, NULL); 220 bcm47xx_fill_bcma_boardinfo(&bcm47xx_bus.bcma.bus.boardinfo, NULL);
diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
index 9f7ecbda250c..7edc08398c4a 100644
--- a/arch/mips/net/bpf_jit.c
+++ b/arch/mips/net/bpf_jit.c
@@ -765,27 +765,6 @@ static u64 jit_get_skb_w(struct sk_buff *skb, unsigned offset)
765 return (u64)err << 32 | ntohl(ret); 765 return (u64)err << 32 | ntohl(ret);
766} 766}
767 767
768#ifdef __BIG_ENDIAN_BITFIELD
769#define PKT_TYPE_MAX (7 << 5)
770#else
771#define PKT_TYPE_MAX 7
772#endif
773static int pkt_type_offset(void)
774{
775 struct sk_buff skb_probe = {
776 .pkt_type = ~0,
777 };
778 u8 *ct = (u8 *)&skb_probe;
779 unsigned int off;
780
781 for (off = 0; off < sizeof(struct sk_buff); off++) {
782 if (ct[off] == PKT_TYPE_MAX)
783 return off;
784 }
785 pr_err_once("Please fix pkt_type_offset(), as pkt_type couldn't be found\n");
786 return -1;
787}
788
789static int build_body(struct jit_ctx *ctx) 768static int build_body(struct jit_ctx *ctx)
790{ 769{
791 void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w}; 770 void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w};
@@ -793,7 +772,6 @@ static int build_body(struct jit_ctx *ctx)
793 const struct sock_filter *inst; 772 const struct sock_filter *inst;
794 unsigned int i, off, load_order, condt; 773 unsigned int i, off, load_order, condt;
795 u32 k, b_off __maybe_unused; 774 u32 k, b_off __maybe_unused;
796 int tmp;
797 775
798 for (i = 0; i < prog->len; i++) { 776 for (i = 0; i < prog->len; i++) {
799 u16 code; 777 u16 code;
@@ -1333,11 +1311,7 @@ jmp_cmp:
1333 case BPF_ANC | SKF_AD_PKTTYPE: 1311 case BPF_ANC | SKF_AD_PKTTYPE:
1334 ctx->flags |= SEEN_SKB; 1312 ctx->flags |= SEEN_SKB;
1335 1313
1336 tmp = off = pkt_type_offset(); 1314 emit_load_byte(r_tmp, r_skb, PKT_TYPE_OFFSET(), ctx);
1337
1338 if (tmp < 0)
1339 return -1;
1340 emit_load_byte(r_tmp, r_skb, off, ctx);
1341 /* Keep only the last 3 bits */ 1315 /* Keep only the last 3 bits */
1342 emit_andi(r_A, r_tmp, PKT_TYPE_MAX, ctx); 1316 emit_andi(r_A, r_tmp, PKT_TYPE_MAX, ctx);
1343#ifdef __BIG_ENDIAN_BITFIELD 1317#ifdef __BIG_ENDIAN_BITFIELD
@@ -1418,7 +1392,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
1418 bpf_jit_dump(fp->len, alloc_size, 2, ctx.target); 1392 bpf_jit_dump(fp->len, alloc_size, 2, ctx.target);
1419 1393
1420 fp->bpf_func = (void *)ctx.target; 1394 fp->bpf_func = (void *)ctx.target;
1421 fp->jited = 1; 1395 fp->jited = true;
1422 1396
1423out: 1397out:
1424 kfree(ctx.offsets); 1398 kfree(ctx.offsets);
@@ -1428,5 +1402,6 @@ void bpf_jit_free(struct bpf_prog *fp)
1428{ 1402{
1429 if (fp->jited) 1403 if (fp->jited)
1430 module_free(NULL, fp->bpf_func); 1404 module_free(NULL, fp->bpf_func);
1431 kfree(fp); 1405
1406 bpf_prog_unlock_free(fp);
1432} 1407}
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index 3afa6f4c1957..cbae2dfd053c 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -686,7 +686,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
686 ((u64 *)image)[0] = (u64)code_base; 686 ((u64 *)image)[0] = (u64)code_base;
687 ((u64 *)image)[1] = local_paca->kernel_toc; 687 ((u64 *)image)[1] = local_paca->kernel_toc;
688 fp->bpf_func = (void *)image; 688 fp->bpf_func = (void *)image;
689 fp->jited = 1; 689 fp->jited = true;
690 } 690 }
691out: 691out:
692 kfree(addrs); 692 kfree(addrs);
@@ -697,5 +697,6 @@ void bpf_jit_free(struct bpf_prog *fp)
697{ 697{
698 if (fp->jited) 698 if (fp->jited)
699 module_free(NULL, fp->bpf_func); 699 module_free(NULL, fp->bpf_func);
700 kfree(fp); 700
701 bpf_prog_unlock_free(fp);
701} 702}
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index 61e45b7c04d7..c52ac77408ca 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -5,11 +5,9 @@
5 * 5 *
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> 6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
7 */ 7 */
8#include <linux/moduleloader.h>
9#include <linux/netdevice.h> 8#include <linux/netdevice.h>
10#include <linux/if_vlan.h> 9#include <linux/if_vlan.h>
11#include <linux/filter.h> 10#include <linux/filter.h>
12#include <linux/random.h>
13#include <linux/init.h> 11#include <linux/init.h>
14#include <asm/cacheflush.h> 12#include <asm/cacheflush.h>
15#include <asm/facility.h> 13#include <asm/facility.h>
@@ -148,6 +146,12 @@ struct bpf_jit {
148 ret; \ 146 ret; \
149}) 147})
150 148
149static void bpf_jit_fill_hole(void *area, unsigned int size)
150{
151 /* Fill whole space with illegal instructions */
152 memset(area, 0, size);
153}
154
151static void bpf_jit_prologue(struct bpf_jit *jit) 155static void bpf_jit_prologue(struct bpf_jit *jit)
152{ 156{
153 /* Save registers and create stack frame if necessary */ 157 /* Save registers and create stack frame if necessary */
@@ -223,37 +227,6 @@ static void bpf_jit_epilogue(struct bpf_jit *jit)
223 EMIT2(0x07fe); 227 EMIT2(0x07fe);
224} 228}
225 229
226/* Helper to find the offset of pkt_type in sk_buff
227 * Make sure its still a 3bit field starting at the MSBs within a byte.
228 */
229#define PKT_TYPE_MAX 0xe0
230static int pkt_type_offset;
231
232static int __init bpf_pkt_type_offset_init(void)
233{
234 struct sk_buff skb_probe = {
235 .pkt_type = ~0,
236 };
237 char *ct = (char *)&skb_probe;
238 int off;
239
240 pkt_type_offset = -1;
241 for (off = 0; off < sizeof(struct sk_buff); off++) {
242 if (!ct[off])
243 continue;
244 if (ct[off] == PKT_TYPE_MAX)
245 pkt_type_offset = off;
246 else {
247 /* Found non matching bit pattern, fix needed. */
248 WARN_ON_ONCE(1);
249 pkt_type_offset = -1;
250 return -1;
251 }
252 }
253 return 0;
254}
255device_initcall(bpf_pkt_type_offset_init);
256
257/* 230/*
258 * make sure we dont leak kernel information to user 231 * make sure we dont leak kernel information to user
259 */ 232 */
@@ -753,12 +726,10 @@ call_fn: /* lg %r1,<d(function)>(%r13) */
753 } 726 }
754 break; 727 break;
755 case BPF_ANC | SKF_AD_PKTTYPE: 728 case BPF_ANC | SKF_AD_PKTTYPE:
756 if (pkt_type_offset < 0)
757 goto out;
758 /* lhi %r5,0 */ 729 /* lhi %r5,0 */
759 EMIT4(0xa7580000); 730 EMIT4(0xa7580000);
760 /* ic %r5,<d(pkt_type_offset)>(%r2) */ 731 /* ic %r5,<d(pkt_type_offset)>(%r2) */
761 EMIT4_DISP(0x43502000, pkt_type_offset); 732 EMIT4_DISP(0x43502000, PKT_TYPE_OFFSET());
762 /* srl %r5,5 */ 733 /* srl %r5,5 */
763 EMIT4_DISP(0x88500000, 5); 734 EMIT4_DISP(0x88500000, 5);
764 break; 735 break;
@@ -780,38 +751,6 @@ out:
780 return -1; 751 return -1;
781} 752}
782 753
783/*
784 * Note: for security reasons, bpf code will follow a randomly
785 * sized amount of illegal instructions.
786 */
787struct bpf_binary_header {
788 unsigned int pages;
789 u8 image[];
790};
791
792static struct bpf_binary_header *bpf_alloc_binary(unsigned int bpfsize,
793 u8 **image_ptr)
794{
795 struct bpf_binary_header *header;
796 unsigned int sz, hole;
797
798 /* Most BPF filters are really small, but if some of them fill a page,
799 * allow at least 128 extra bytes for illegal instructions.
800 */
801 sz = round_up(bpfsize + sizeof(*header) + 128, PAGE_SIZE);
802 header = module_alloc(sz);
803 if (!header)
804 return NULL;
805 memset(header, 0, sz);
806 header->pages = sz / PAGE_SIZE;
807 hole = min(sz - (bpfsize + sizeof(*header)), PAGE_SIZE - sizeof(*header));
808 /* Insert random number of illegal instructions before BPF code
809 * and make sure the first instruction starts at an even address.
810 */
811 *image_ptr = &header->image[(prandom_u32() % hole) & -2];
812 return header;
813}
814
815void bpf_jit_compile(struct bpf_prog *fp) 754void bpf_jit_compile(struct bpf_prog *fp)
816{ 755{
817 struct bpf_binary_header *header = NULL; 756 struct bpf_binary_header *header = NULL;
@@ -850,7 +789,8 @@ void bpf_jit_compile(struct bpf_prog *fp)
850 size = prg_len + lit_len; 789 size = prg_len + lit_len;
851 if (size >= BPF_SIZE_MAX) 790 if (size >= BPF_SIZE_MAX)
852 goto out; 791 goto out;
853 header = bpf_alloc_binary(size, &jit.start); 792 header = bpf_jit_binary_alloc(size, &jit.start,
793 2, bpf_jit_fill_hole);
854 if (!header) 794 if (!header)
855 goto out; 795 goto out;
856 jit.prg = jit.mid = jit.start + prg_len; 796 jit.prg = jit.mid = jit.start + prg_len;
@@ -869,7 +809,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
869 if (jit.start) { 809 if (jit.start) {
870 set_memory_ro((unsigned long)header, header->pages); 810 set_memory_ro((unsigned long)header, header->pages);
871 fp->bpf_func = (void *) jit.start; 811 fp->bpf_func = (void *) jit.start;
872 fp->jited = 1; 812 fp->jited = true;
873 } 813 }
874out: 814out:
875 kfree(addrs); 815 kfree(addrs);
@@ -884,8 +824,8 @@ void bpf_jit_free(struct bpf_prog *fp)
884 goto free_filter; 824 goto free_filter;
885 825
886 set_memory_rw(addr, header->pages); 826 set_memory_rw(addr, header->pages);
887 module_free(NULL, header); 827 bpf_jit_binary_free(header);
888 828
889free_filter: 829free_filter:
890 kfree(fp); 830 bpf_prog_unlock_free(fp);
891} 831}
diff --git a/arch/sparc/include/asm/vio.h b/arch/sparc/include/asm/vio.h
index e0f6c399f1d0..6b135a8ab07b 100644
--- a/arch/sparc/include/asm/vio.h
+++ b/arch/sparc/include/asm/vio.h
@@ -65,6 +65,7 @@ struct vio_dring_register {
65 u16 options; 65 u16 options;
66#define VIO_TX_DRING 0x0001 66#define VIO_TX_DRING 0x0001
67#define VIO_RX_DRING 0x0002 67#define VIO_RX_DRING 0x0002
68#define VIO_RX_DRING_DATA 0x0004
68 u16 resv; 69 u16 resv;
69 u32 num_cookies; 70 u32 num_cookies;
70 struct ldc_trans_cookie cookies[0]; 71 struct ldc_trans_cookie cookies[0];
@@ -80,6 +81,8 @@ struct vio_dring_unregister {
80#define VIO_PKT_MODE 0x01 /* Packet based transfer */ 81#define VIO_PKT_MODE 0x01 /* Packet based transfer */
81#define VIO_DESC_MODE 0x02 /* In-band descriptors */ 82#define VIO_DESC_MODE 0x02 /* In-band descriptors */
82#define VIO_DRING_MODE 0x03 /* Descriptor rings */ 83#define VIO_DRING_MODE 0x03 /* Descriptor rings */
84/* in vers >= 1.2, VIO_DRING_MODE is 0x04 and transfer mode is a bitmask */
85#define VIO_NEW_DRING_MODE 0x04
83 86
84struct vio_dring_data { 87struct vio_dring_data {
85 struct vio_msg_tag tag; 88 struct vio_msg_tag tag;
@@ -205,10 +208,20 @@ struct vio_net_attr_info {
205 u8 addr_type; 208 u8 addr_type;
206#define VNET_ADDR_ETHERMAC 0x01 209#define VNET_ADDR_ETHERMAC 0x01
207 u16 ack_freq; 210 u16 ack_freq;
208 u32 resv1; 211 u8 plnk_updt;
212#define PHYSLINK_UPDATE_NONE 0x00
213#define PHYSLINK_UPDATE_STATE 0x01
214#define PHYSLINK_UPDATE_STATE_ACK 0x02
215#define PHYSLINK_UPDATE_STATE_NACK 0x03
216 u8 options;
217 u16 resv1;
209 u64 addr; 218 u64 addr;
210 u64 mtu; 219 u64 mtu;
211 u64 resv2[3]; 220 u16 cflags;
221#define VNET_LSO_IPV4_CAPAB 0x0001
222 u16 ipv4_lso_maxlen;
223 u32 resv2;
224 u64 resv3[2];
212}; 225};
213 226
214#define VNET_NUM_MCAST 7 227#define VNET_NUM_MCAST 7
@@ -366,6 +379,33 @@ struct vio_driver_state {
366 struct vio_driver_ops *ops; 379 struct vio_driver_ops *ops;
367}; 380};
368 381
382static inline bool vio_version_before(struct vio_driver_state *vio,
383 u16 major, u16 minor)
384{
385 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
386 u32 want = (u32)major << 16 | minor;
387
388 return have < want;
389}
390
391static inline bool vio_version_after(struct vio_driver_state *vio,
392 u16 major, u16 minor)
393{
394 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
395 u32 want = (u32)major << 16 | minor;
396
397 return have > want;
398}
399
400static inline bool vio_version_after_eq(struct vio_driver_state *vio,
401 u16 major, u16 minor)
402{
403 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
404 u32 want = (u32)major << 16 | minor;
405
406 return have >= want;
407}
408
369#define viodbg(TYPE, f, a...) \ 409#define viodbg(TYPE, f, a...) \
370do { if (vio->debug & VIO_DEBUG_##TYPE) \ 410do { if (vio->debug & VIO_DEBUG_##TYPE) \
371 printk(KERN_INFO "vio: ID[%lu] " f, \ 411 printk(KERN_INFO "vio: ID[%lu] " f, \
diff --git a/arch/sparc/kernel/ldc.c b/arch/sparc/kernel/ldc.c
index 66dacd56bb10..0af28b984695 100644
--- a/arch/sparc/kernel/ldc.c
+++ b/arch/sparc/kernel/ldc.c
@@ -2159,7 +2159,7 @@ int ldc_map_single(struct ldc_channel *lp,
2159 state.pte_idx = (base - iommu->page_table); 2159 state.pte_idx = (base - iommu->page_table);
2160 state.nc = 0; 2160 state.nc = 0;
2161 fill_cookies(&state, (pa & PAGE_MASK), (pa & ~PAGE_MASK), len); 2161 fill_cookies(&state, (pa & PAGE_MASK), (pa & ~PAGE_MASK), len);
2162 BUG_ON(state.nc != 1); 2162 BUG_ON(state.nc > ncookies);
2163 2163
2164 return state.nc; 2164 return state.nc;
2165} 2165}
diff --git a/arch/sparc/kernel/viohs.c b/arch/sparc/kernel/viohs.c
index f8e7dd53e1c7..7ef081a185b1 100644
--- a/arch/sparc/kernel/viohs.c
+++ b/arch/sparc/kernel/viohs.c
@@ -426,6 +426,13 @@ static int process_dreg_info(struct vio_driver_state *vio,
426 if (vio->dr_state & VIO_DR_STATE_RXREG) 426 if (vio->dr_state & VIO_DR_STATE_RXREG)
427 goto send_nack; 427 goto send_nack;
428 428
429 /* v1.6 and higher, ACK with desired, supported mode, or NACK */
430 if (vio_version_after_eq(vio, 1, 6)) {
431 if (!(pkt->options & VIO_TX_DRING))
432 goto send_nack;
433 pkt->options = VIO_TX_DRING;
434 }
435
429 BUG_ON(vio->desc_buf); 436 BUG_ON(vio->desc_buf);
430 437
431 vio->desc_buf = kzalloc(pkt->descr_size, GFP_ATOMIC); 438 vio->desc_buf = kzalloc(pkt->descr_size, GFP_ATOMIC);
@@ -453,8 +460,11 @@ static int process_dreg_info(struct vio_driver_state *vio,
453 pkt->tag.stype = VIO_SUBTYPE_ACK; 460 pkt->tag.stype = VIO_SUBTYPE_ACK;
454 pkt->dring_ident = ++dr->ident; 461 pkt->dring_ident = ++dr->ident;
455 462
456 viodbg(HS, "SEND DRING_REG ACK ident[%llx]\n", 463 viodbg(HS, "SEND DRING_REG ACK ident[%llx] "
457 (unsigned long long) pkt->dring_ident); 464 "ndesc[%u] dsz[%u] opt[0x%x] ncookies[%u]\n",
465 (unsigned long long) pkt->dring_ident,
466 pkt->num_descr, pkt->descr_size, pkt->options,
467 pkt->num_cookies);
458 468
459 len = (sizeof(*pkt) + 469 len = (sizeof(*pkt) +
460 (dr->ncookies * sizeof(struct ldc_trans_cookie))); 470 (dr->ncookies * sizeof(struct ldc_trans_cookie)));
diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
index ece4af0575e9..f33e7c7a3bf7 100644
--- a/arch/sparc/net/bpf_jit_comp.c
+++ b/arch/sparc/net/bpf_jit_comp.c
@@ -585,16 +585,11 @@ void bpf_jit_compile(struct bpf_prog *fp)
585 case BPF_ANC | SKF_AD_PROTOCOL: 585 case BPF_ANC | SKF_AD_PROTOCOL:
586 emit_skb_load16(protocol, r_A); 586 emit_skb_load16(protocol, r_A);
587 break; 587 break;
588#if 0
589 /* GCC won't let us take the address of
590 * a bit field even though we very much
591 * know what we are doing here.
592 */
593 case BPF_ANC | SKF_AD_PKTTYPE: 588 case BPF_ANC | SKF_AD_PKTTYPE:
594 __emit_skb_load8(pkt_type, r_A); 589 __emit_skb_load8(__pkt_type_offset, r_A);
590 emit_andi(r_A, PKT_TYPE_MAX, r_A);
595 emit_alu_K(SRL, 5); 591 emit_alu_K(SRL, 5);
596 break; 592 break;
597#endif
598 case BPF_ANC | SKF_AD_IFINDEX: 593 case BPF_ANC | SKF_AD_IFINDEX:
599 emit_skb_loadptr(dev, r_A); 594 emit_skb_loadptr(dev, r_A);
600 emit_cmpi(r_A, 0); 595 emit_cmpi(r_A, 0);
@@ -629,7 +624,12 @@ void bpf_jit_compile(struct bpf_prog *fp)
629 emit_and(r_A, r_TMP, r_A); 624 emit_and(r_A, r_TMP, r_A);
630 } 625 }
631 break; 626 break;
632 627 case BPF_LD | BPF_W | BPF_LEN:
628 emit_skb_load32(len, r_A);
629 break;
630 case BPF_LDX | BPF_W | BPF_LEN:
631 emit_skb_load32(len, r_X);
632 break;
633 case BPF_LD | BPF_IMM: 633 case BPF_LD | BPF_IMM:
634 emit_loadimm(K, r_A); 634 emit_loadimm(K, r_A);
635 break; 635 break;
@@ -812,7 +812,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf];
812 if (image) { 812 if (image) {
813 bpf_flush_icache(image, image + proglen); 813 bpf_flush_icache(image, image + proglen);
814 fp->bpf_func = (void *)image; 814 fp->bpf_func = (void *)image;
815 fp->jited = 1; 815 fp->jited = true;
816 } 816 }
817out: 817out:
818 kfree(addrs); 818 kfree(addrs);
@@ -823,5 +823,6 @@ void bpf_jit_free(struct bpf_prog *fp)
823{ 823{
824 if (fp->jited) 824 if (fp->jited)
825 module_free(NULL, fp->bpf_func); 825 module_free(NULL, fp->bpf_func);
826 kfree(fp); 826
827 bpf_prog_unlock_free(fp);
827} 828}
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 5c8cb8043c5a..d56cd1f515bd 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -8,12 +8,10 @@
8 * as published by the Free Software Foundation; version 2 8 * as published by the Free Software Foundation; version 2
9 * of the License. 9 * of the License.
10 */ 10 */
11#include <linux/moduleloader.h>
12#include <asm/cacheflush.h>
13#include <linux/netdevice.h> 11#include <linux/netdevice.h>
14#include <linux/filter.h> 12#include <linux/filter.h>
15#include <linux/if_vlan.h> 13#include <linux/if_vlan.h>
16#include <linux/random.h> 14#include <asm/cacheflush.h>
17 15
18int bpf_jit_enable __read_mostly; 16int bpf_jit_enable __read_mostly;
19 17
@@ -109,39 +107,6 @@ static inline void bpf_flush_icache(void *start, void *end)
109#define CHOOSE_LOAD_FUNC(K, func) \ 107#define CHOOSE_LOAD_FUNC(K, func) \
110 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset) 108 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
111 109
112struct bpf_binary_header {
113 unsigned int pages;
114 /* Note : for security reasons, bpf code will follow a randomly
115 * sized amount of int3 instructions
116 */
117 u8 image[];
118};
119
120static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
121 u8 **image_ptr)
122{
123 unsigned int sz, hole;
124 struct bpf_binary_header *header;
125
126 /* Most of BPF filters are really small,
127 * but if some of them fill a page, allow at least
128 * 128 extra bytes to insert a random section of int3
129 */
130 sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
131 header = module_alloc(sz);
132 if (!header)
133 return NULL;
134
135 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
136
137 header->pages = sz / PAGE_SIZE;
138 hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
139
140 /* insert a random number of int3 instructions before BPF code */
141 *image_ptr = &header->image[prandom_u32() % hole];
142 return header;
143}
144
145/* pick a register outside of BPF range for JIT internal work */ 110/* pick a register outside of BPF range for JIT internal work */
146#define AUX_REG (MAX_BPF_REG + 1) 111#define AUX_REG (MAX_BPF_REG + 1)
147 112
@@ -206,6 +171,12 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
206 return byte + reg2hex[dst_reg] + (reg2hex[src_reg] << 3); 171 return byte + reg2hex[dst_reg] + (reg2hex[src_reg] << 3);
207} 172}
208 173
174static void jit_fill_hole(void *area, unsigned int size)
175{
176 /* fill whole space with int3 instructions */
177 memset(area, 0xcc, size);
178}
179
209struct jit_context { 180struct jit_context {
210 unsigned int cleanup_addr; /* epilogue code offset */ 181 unsigned int cleanup_addr; /* epilogue code offset */
211 bool seen_ld_abs; 182 bool seen_ld_abs;
@@ -393,6 +364,23 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
393 EMIT1_off32(add_1reg(0xB8, dst_reg), imm32); 364 EMIT1_off32(add_1reg(0xB8, dst_reg), imm32);
394 break; 365 break;
395 366
367 case BPF_LD | BPF_IMM | BPF_DW:
368 if (insn[1].code != 0 || insn[1].src_reg != 0 ||
369 insn[1].dst_reg != 0 || insn[1].off != 0) {
370 /* verifier must catch invalid insns */
371 pr_err("invalid BPF_LD_IMM64 insn\n");
372 return -EINVAL;
373 }
374
375 /* movabsq %rax, imm64 */
376 EMIT2(add_1mod(0x48, dst_reg), add_1reg(0xB8, dst_reg));
377 EMIT(insn[0].imm, 4);
378 EMIT(insn[1].imm, 4);
379
380 insn++;
381 i++;
382 break;
383
396 /* dst %= src, dst /= src, dst %= imm32, dst /= imm32 */ 384 /* dst %= src, dst /= src, dst %= imm32, dst /= imm32 */
397 case BPF_ALU | BPF_MOD | BPF_X: 385 case BPF_ALU | BPF_MOD | BPF_X:
398 case BPF_ALU | BPF_DIV | BPF_X: 386 case BPF_ALU | BPF_DIV | BPF_X:
@@ -515,6 +503,48 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
515 EMIT3(0xC1, add_1reg(b3, dst_reg), imm32); 503 EMIT3(0xC1, add_1reg(b3, dst_reg), imm32);
516 break; 504 break;
517 505
506 case BPF_ALU | BPF_LSH | BPF_X:
507 case BPF_ALU | BPF_RSH | BPF_X:
508 case BPF_ALU | BPF_ARSH | BPF_X:
509 case BPF_ALU64 | BPF_LSH | BPF_X:
510 case BPF_ALU64 | BPF_RSH | BPF_X:
511 case BPF_ALU64 | BPF_ARSH | BPF_X:
512
513 /* check for bad case when dst_reg == rcx */
514 if (dst_reg == BPF_REG_4) {
515 /* mov r11, dst_reg */
516 EMIT_mov(AUX_REG, dst_reg);
517 dst_reg = AUX_REG;
518 }
519
520 if (src_reg != BPF_REG_4) { /* common case */
521 EMIT1(0x51); /* push rcx */
522
523 /* mov rcx, src_reg */
524 EMIT_mov(BPF_REG_4, src_reg);
525 }
526
527 /* shl %rax, %cl | shr %rax, %cl | sar %rax, %cl */
528 if (BPF_CLASS(insn->code) == BPF_ALU64)
529 EMIT1(add_1mod(0x48, dst_reg));
530 else if (is_ereg(dst_reg))
531 EMIT1(add_1mod(0x40, dst_reg));
532
533 switch (BPF_OP(insn->code)) {
534 case BPF_LSH: b3 = 0xE0; break;
535 case BPF_RSH: b3 = 0xE8; break;
536 case BPF_ARSH: b3 = 0xF8; break;
537 }
538 EMIT2(0xD3, add_1reg(b3, dst_reg));
539
540 if (src_reg != BPF_REG_4)
541 EMIT1(0x59); /* pop rcx */
542
543 if (insn->dst_reg == BPF_REG_4)
544 /* mov dst_reg, r11 */
545 EMIT_mov(insn->dst_reg, AUX_REG);
546 break;
547
518 case BPF_ALU | BPF_END | BPF_FROM_BE: 548 case BPF_ALU | BPF_END | BPF_FROM_BE:
519 switch (imm32) { 549 switch (imm32) {
520 case 16: 550 case 16:
@@ -900,7 +930,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
900 if (proglen <= 0) { 930 if (proglen <= 0) {
901 image = NULL; 931 image = NULL;
902 if (header) 932 if (header)
903 module_free(NULL, header); 933 bpf_jit_binary_free(header);
904 goto out; 934 goto out;
905 } 935 }
906 if (image) { 936 if (image) {
@@ -910,7 +940,8 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
910 break; 940 break;
911 } 941 }
912 if (proglen == oldproglen) { 942 if (proglen == oldproglen) {
913 header = bpf_alloc_binary(proglen, &image); 943 header = bpf_jit_binary_alloc(proglen, &image,
944 1, jit_fill_hole);
914 if (!header) 945 if (!header)
915 goto out; 946 goto out;
916 } 947 }
@@ -924,29 +955,23 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
924 bpf_flush_icache(header, image + proglen); 955 bpf_flush_icache(header, image + proglen);
925 set_memory_ro((unsigned long)header, header->pages); 956 set_memory_ro((unsigned long)header, header->pages);
926 prog->bpf_func = (void *)image; 957 prog->bpf_func = (void *)image;
927 prog->jited = 1; 958 prog->jited = true;
928 } 959 }
929out: 960out:
930 kfree(addrs); 961 kfree(addrs);
931} 962}
932 963
933static void bpf_jit_free_deferred(struct work_struct *work) 964void bpf_jit_free(struct bpf_prog *fp)
934{ 965{
935 struct bpf_prog *fp = container_of(work, struct bpf_prog, work);
936 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK; 966 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
937 struct bpf_binary_header *header = (void *)addr; 967 struct bpf_binary_header *header = (void *)addr;
938 968
969 if (!fp->jited)
970 goto free_filter;
971
939 set_memory_rw(addr, header->pages); 972 set_memory_rw(addr, header->pages);
940 module_free(NULL, header); 973 bpf_jit_binary_free(header);
941 kfree(fp);
942}
943 974
944void bpf_jit_free(struct bpf_prog *fp) 975free_filter:
945{ 976 bpf_prog_unlock_free(fp);
946 if (fp->jited) {
947 INIT_WORK(&fp->work, bpf_jit_free_deferred);
948 schedule_work(&fp->work);
949 } else {
950 kfree(fp);
951 }
952} 977}
diff --git a/arch/x86/syscalls/syscall_32.tbl b/arch/x86/syscalls/syscall_32.tbl
index 028b78168d85..9fe1b5d002f0 100644
--- a/arch/x86/syscalls/syscall_32.tbl
+++ b/arch/x86/syscalls/syscall_32.tbl
@@ -363,3 +363,4 @@
363354 i386 seccomp sys_seccomp 363354 i386 seccomp sys_seccomp
364355 i386 getrandom sys_getrandom 364355 i386 getrandom sys_getrandom
365356 i386 memfd_create sys_memfd_create 365356 i386 memfd_create sys_memfd_create
366357 i386 bpf sys_bpf
diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl
index 35dd922727b9..281150b539a2 100644
--- a/arch/x86/syscalls/syscall_64.tbl
+++ b/arch/x86/syscalls/syscall_64.tbl
@@ -327,6 +327,7 @@
327318 common getrandom sys_getrandom 327318 common getrandom sys_getrandom
328319 common memfd_create sys_memfd_create 328319 common memfd_create sys_memfd_create
329320 common kexec_file_load sys_kexec_file_load 329320 common kexec_file_load sys_kexec_file_load
330321 common bpf sys_bpf
330 331
331# 332#
332# x32-specific system call numbers start at 512 to avoid cache impact 333# x32-specific system call numbers start at 512 to avoid cache impact