* Re: [PATCH v3 bpf-next 2/9] libbpf: introduce concept of bpf_link
From: Andrii Nakryiko @ 2019-06-28 16:42 UTC (permalink / raw)
To: Stanislav Fomichev
Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann, Networking,
bpf, Kernel Team
In-Reply-To: <20190628160230.GG4866@mini-arch>
On Fri, Jun 28, 2019 at 9:02 AM Stanislav Fomichev <sdf@fomichev.me> wrote:
>
> On 06/27, Andrii Nakryiko wrote:
> > bpf_link is and abstraction of an association of a BPF program and one
> > of many possible BPF attachment points (hooks). This allows to have
> > uniform interface for detaching BPF programs regardless of the nature of
> > link and how it was created. Details of creation and setting up of
> > a specific bpf_link is handled by corresponding attachment methods
> > (bpf_program__attach_xxx) added in subsequent commits. Once successfully
> > created, bpf_link has to be eventually destroyed with
> > bpf_link__destroy(), at which point BPF program is disassociated from
> > a hook and all the relevant resources are freed.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> > tools/lib/bpf/libbpf.c | 17 +++++++++++++++++
> > tools/lib/bpf/libbpf.h | 4 ++++
> > tools/lib/bpf/libbpf.map | 3 ++-
> > 3 files changed, 23 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 6e6ebef11ba3..455795e6f8af 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -3941,6 +3941,23 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
> > return 0;
> > }
> >
> > +struct bpf_link {
> Maybe call it bpf_attachment? You call the bpf_program__attach_to_blah
> and you get an attachment?
I wanted to keep it as short as possible, bpf_attachment is way too
long (it's also why as an alternative I've proposed bpf_assoc, not
bpf_association, but bpf_attach isn't great shortening).
>
> > + int (*destroy)(struct bpf_link *link);
> > +};
> > +
> > +int bpf_link__destroy(struct bpf_link *link)
> > +{
> > + int err;
> > +
> > + if (!link)
> > + return 0;
> > +
> > + err = link->destroy(link);
> > + free(link);
> > +
> > + return err;
> > +}
> > +
> > enum bpf_perf_event_ret
> > bpf_perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size,
> > void **copy_mem, size_t *copy_size,
> > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> > index d639f47e3110..5082a5ebb0c2 100644
> > --- a/tools/lib/bpf/libbpf.h
> > +++ b/tools/lib/bpf/libbpf.h
> > @@ -165,6 +165,10 @@ LIBBPF_API int bpf_program__pin(struct bpf_program *prog, const char *path);
> > LIBBPF_API int bpf_program__unpin(struct bpf_program *prog, const char *path);
> > LIBBPF_API void bpf_program__unload(struct bpf_program *prog);
> >
> > +struct bpf_link;
> > +
> > +LIBBPF_API int bpf_link__destroy(struct bpf_link *link);
> > +
> > struct bpf_insn;
> >
> > /*
> > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> > index 2c6d835620d2..3cde850fc8da 100644
> > --- a/tools/lib/bpf/libbpf.map
> > +++ b/tools/lib/bpf/libbpf.map
> > @@ -167,10 +167,11 @@ LIBBPF_0.0.3 {
> >
> > LIBBPF_0.0.4 {
> > global:
> > + bpf_link__destroy;
> > + bpf_object__load_xattr;
> > btf_dump__dump_type;
> > btf_dump__free;
> > btf_dump__new;
> > btf__parse_elf;
> > - bpf_object__load_xattr;
> > libbpf_num_possible_cpus;
> > } LIBBPF_0.0.3;
> > --
> > 2.17.1
> >
^ permalink raw reply
* Re: [PATCH net-next 00/12] net: hns3: some code optimizations & cleanups & bugfixes
From: David Miller @ 2019-06-28 16:40 UTC (permalink / raw)
To: tanhuazhong; +Cc: netdev, linux-kernel, salil.mehta, yisen.zhuang, linuxarm
In-Reply-To: <1561722618-12168-1-git-send-email-tanhuazhong@huawei.com>
From: Huazhong Tan <tanhuazhong@huawei.com>
Date: Fri, 28 Jun 2019 19:50:06 +0800
> [patch 01/12] fixes a TX timeout issue.
>
> [patch 02/12 - 04/12] adds some patch related to TM module.
>
> [patch 05/12] fixes a compile warning.
>
> [patch 06/12] adds Asym Pause support for autoneg
>
> [patch 07/12] optimizes the error handler for VF reset.
>
> [patch 08/12] deals with the empty interrupt case.
>
> [patch 09/12 - 12/12] adds some cleanups & optimizations.
Looks good, series applied, thanks.
^ permalink raw reply
* Re: [PATCH 0/5] net: dsa: microchip: Further regmap cleanups
From: Marek Vasut @ 2019-06-28 16:36 UTC (permalink / raw)
To: Vivien Didelot
Cc: netdev, Andrew Lunn, Florian Fainelli, Tristram Ha, Woojung Huh
In-Reply-To: <20190628113130.GB14087@t480s.localdomain>
On 6/28/19 5:31 PM, Vivien Didelot wrote:
> Hi Marek,
>
> On Thu, 27 Jun 2019 23:55:51 +0200, Marek Vasut <marex@denx.de> wrote:
>> This patchset cleans up KSZ9477 switch driver by replacing various
>> ad-hoc polling implementations and register RMW with regmap functions.
>>
>> Each polling function is replaced separately to make it easier to review
>> and possibly bisect, but maybe the patches can be squashed.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> Cc: Andrew Lunn <andrew@lunn.ch>
>> Cc: Florian Fainelli <f.fainelli@gmail.com>
>> Cc: Tristram Ha <Tristram.Ha@microchip.com>
>> Cc: Woojung Huh <Woojung.Huh@microchip.com>
>
> Please copy me next time, as per the MAINTAINERS file.
Will do. I plan to submit KSZ8795 support next.
--
Best regards,
Marek Vasut
^ permalink raw reply
* net: check before dereferencing netdev_ops during busy poll
From: Matteo Croce @ 2019-06-28 16:34 UTC (permalink / raw)
To: stable, Sasha Levin; +Cc: Greg Kroah-Hartman, Josh Elsasser, netdev, LKML
Hi,
Is there any reason for this panic fix not being applied in stable?
https://lore.kernel.org/netdev/20180313053248.13654-1-jelsasser@appneta.com/T/
It seems that linux 4.9.184 has the bug too.
Regards,
--
Matteo Croce
per aspera ad upstream
^ permalink raw reply
* Re: [PATCH] hinic: reduce rss_init stack usage
From: David Miller @ 2019-06-28 16:32 UTC (permalink / raw)
To: arnd
Cc: aviad.krawczyk, xuechaojing, jesse.brandeburg, zhaochen6,
edumazet, dann.frazier, netdev, linux-kernel
In-Reply-To: <20190628103158.2446356-1-arnd@arndb.de>
From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 28 Jun 2019 12:31:44 +0200
> On 32-bit architectures, putting an array of 256 u32 values on the
> stack uses more space than the warning limit:
>
> drivers/net/ethernet/huawei/hinic/hinic_main.c: In function 'hinic_rss_init':
> drivers/net/ethernet/huawei/hinic/hinic_main.c:286:1: error: the frame size of 1068 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
>
> I considered changing the code to use u8 values here, since that's
> all the hardware supports, but dynamically allocating the array is
> a more isolated fix here.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Applied to net-next.
Arnd, please make it clear what tree you are targetting in the
future. Thank you.
^ permalink raw reply
* Re: [PATCH v2 net-next 0/3] Better PHYLINK compliance for SJA1105 DSA
From: David Miller @ 2019-06-28 16:31 UTC (permalink / raw)
To: linux; +Cc: olteanv, f.fainelli, vivien.didelot, andrew, netdev
In-Reply-To: <20190628100542.hmzqnp4bsnkikcvv@shell.armlinux.org.uk>
From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Date: Fri, 28 Jun 2019 11:05:42 +0100
> On Fri, Jun 28, 2019 at 12:46:34AM +0300, Vladimir Oltean wrote:
>> After discussing with Russell King, it appears this driver is making a
>> few confusions and not performing some checks for consistent operation.
>>
>> Changes in v2:
>> - Removed redundant print in the phylink_validate callback (in 2/3).
>>
>> Vladimir Oltean (3):
>> net: dsa: sja1105: Don't check state->link in phylink_mac_config
>> net: dsa: sja1105: Check for PHY mode mismatches with what PHYLINK
>> reports
>> net: dsa: sja1105: Mark in-band AN modes not supported for PHYLINK
>>
>> drivers/net/dsa/sja1105/sja1105_main.c | 56 +++++++++++++++++++++++++-
>> 1 file changed, 54 insertions(+), 2 deletions(-)
>
> Thanks. For the whole series:
>
> Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Series applied, thanks all.
^ permalink raw reply
* Re: [RFC] longer netdev names proposal
From: Michal Kubecek @ 2019-06-28 16:27 UTC (permalink / raw)
To: netdev
Cc: Jiri Pirko, Andrew Lunn, Stephen Hemminger, David Ahern, davem,
jakub.kicinski, mlxsw
In-Reply-To: <20190628135553.GA6640@nanopsycho>
On Fri, Jun 28, 2019 at 03:55:53PM +0200, Jiri Pirko wrote:
> Fri, Jun 28, 2019 at 03:14:01PM CEST, andrew@lunn.ch wrote:
> >
> >What is your user case for having multiple IFLA_ALT_NAME for the same
> >IFLA_NAME?
>
> I don't know about specific usecase for having more. Perhaps Michal
> does.
One use case that comes to my mind are the "predictable names"
implemented by udev/systemd which can be based on different naming
schemes (bus address, BIOS numbering, MAC address etc.) and it's not
always obvious which scheme is going to be used. I have even seen
multiple times that one schemed was used during system installation and
another in the installed system so that network configuration created by
installer did not work.
For block devices, current practice is not to rename the device and only
create multiple symlinks based on different naming schemes (by id, by
uuid, by label, etc.). With support for multiple altnames, we could also
identify the network device in different ways (all applicable ones).
Michal
^ permalink raw reply
* Re: [RFC iproute2 1/1] ip: netns: add mounted state file for each netns
From: David Howells @ 2019-06-28 16:26 UTC (permalink / raw)
To: nicolas.dichtel; +Cc: dhowells, Alexander Aring, netdev, linux-fsdevel, kernel
In-Reply-To: <293c9bd3-f530-d75e-c353-ddeabac27cf6@6wind.com>
Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:
> David Howells was working on a mount notification mechanism:
> https://lwn.net/Articles/760714/
> https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=notifications
>
> I don't know what is the status of this series.
It's still alive. I just posted a new version on it. I'm hoping, possibly
futiley, to get it in in this merge window.
David
^ permalink raw reply
* [PATCH bpf-next] bpf: fix precision tracking
From: Alexei Starovoitov @ 2019-06-28 16:24 UTC (permalink / raw)
To: davem; +Cc: daniel, netdev, bpf, kernel-team
When equivalent state is found the current state needs to propagate precision marks.
Otherwise the verifier will prune the search incorrectly.
There is a price for correctness:
before before broken fixed
cnst spill precise precise
bpf_lb-DLB_L3.o 1923 8128 1863 1898
bpf_lb-DLB_L4.o 3077 6707 2468 2666
bpf_lb-DUNKNOWN.o 1062 1062 544 544
bpf_lxc-DDROP_ALL.o 166729 380712 22629 36823
bpf_lxc-DUNKNOWN.o 174607 440652 28805 45325
bpf_netdev.o 8407 31904 6801 7002
bpf_overlay.o 5420 23569 4754 4858
bpf_lxc_jit.o 39389 359445 50925 69631
Overall precision tracking is still very effective.
Fixes: b5dc0163d8fd ("bpf: precise scalar_value tracking")
Reported-by: Lawrence Brakmo <brakmo@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
Sending the fix early w/o tests, since I'm traveling.
Will add proper tests when I'm back.
---
kernel/bpf/verifier.c | 121 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 107 insertions(+), 14 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 6b5623d320f9..62afc4058ced 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1659,16 +1659,18 @@ static void mark_all_scalars_precise(struct bpf_verifier_env *env,
}
}
-static int mark_chain_precision(struct bpf_verifier_env *env, int regno)
+static int __mark_chain_precision(struct bpf_verifier_env *env, int regno,
+ int spi)
{
struct bpf_verifier_state *st = env->cur_state;
int first_idx = st->first_insn_idx;
int last_idx = env->insn_idx;
struct bpf_func_state *func;
struct bpf_reg_state *reg;
- u32 reg_mask = 1u << regno;
- u64 stack_mask = 0;
+ u32 reg_mask = regno >= 0 ? 1u << regno : 0;
+ u64 stack_mask = spi >= 0 ? 1ull << spi : 0;
bool skip_first = true;
+ bool new_marks = false;
int i, err;
if (!env->allow_ptr_leaks)
@@ -1676,18 +1678,43 @@ static int mark_chain_precision(struct bpf_verifier_env *env, int regno)
return 0;
func = st->frame[st->curframe];
- reg = &func->regs[regno];
- if (reg->type != SCALAR_VALUE) {
- WARN_ONCE(1, "backtracing misuse");
- return -EFAULT;
+ if (regno >= 0) {
+ reg = &func->regs[regno];
+ if (reg->type != SCALAR_VALUE) {
+ WARN_ONCE(1, "backtracing misuse");
+ return -EFAULT;
+ }
+ if (!reg->precise)
+ new_marks = true;
+ else
+ reg_mask = 0;
+ reg->precise = true;
}
- if (reg->precise)
- return 0;
- func->regs[regno].precise = true;
+ while (spi >= 0) {
+ if (func->stack[spi].slot_type[0] != STACK_SPILL) {
+ stack_mask = 0;
+ break;
+ }
+ reg = &func->stack[spi].spilled_ptr;
+ if (reg->type != SCALAR_VALUE) {
+ stack_mask = 0;
+ break;
+ }
+ if (!reg->precise)
+ new_marks = true;
+ else
+ stack_mask = 0;
+ reg->precise = true;
+ break;
+ }
+
+ if (!new_marks)
+ return 0;
+ if (!reg_mask && !stack_mask)
+ return 0;
for (;;) {
DECLARE_BITMAP(mask, 64);
- bool new_marks = false;
u32 history = st->jmp_history_cnt;
if (env->log.level & BPF_LOG_LEVEL)
@@ -1730,12 +1757,15 @@ static int mark_chain_precision(struct bpf_verifier_env *env, int regno)
if (!st)
break;
+ new_marks = false;
func = st->frame[st->curframe];
bitmap_from_u64(mask, reg_mask);
for_each_set_bit(i, mask, 32) {
reg = &func->regs[i];
- if (reg->type != SCALAR_VALUE)
+ if (reg->type != SCALAR_VALUE) {
+ reg_mask &= ~(1u << i);
continue;
+ }
if (!reg->precise)
new_marks = true;
reg->precise = true;
@@ -1756,11 +1786,15 @@ static int mark_chain_precision(struct bpf_verifier_env *env, int regno)
return -EFAULT;
}
- if (func->stack[i].slot_type[0] != STACK_SPILL)
+ if (func->stack[i].slot_type[0] != STACK_SPILL) {
+ stack_mask &= ~(1ull << i);
continue;
+ }
reg = &func->stack[i].spilled_ptr;
- if (reg->type != SCALAR_VALUE)
+ if (reg->type != SCALAR_VALUE) {
+ stack_mask &= ~(1ull << i);
continue;
+ }
if (!reg->precise)
new_marks = true;
reg->precise = true;
@@ -1772,6 +1806,8 @@ static int mark_chain_precision(struct bpf_verifier_env *env, int regno)
reg_mask, stack_mask);
}
+ if (!reg_mask && !stack_mask)
+ break;
if (!new_marks)
break;
@@ -1781,6 +1817,15 @@ static int mark_chain_precision(struct bpf_verifier_env *env, int regno)
return 0;
}
+static int mark_chain_precision(struct bpf_verifier_env *env, int regno)
+{
+ return __mark_chain_precision(env, regno, -1);
+}
+
+static int mark_chain_precision_stack(struct bpf_verifier_env *env, int spi)
+{
+ return __mark_chain_precision(env, -1, spi);
+}
static bool is_spillable_regtype(enum bpf_reg_type type)
{
@@ -7114,6 +7159,46 @@ static int propagate_liveness(struct bpf_verifier_env *env,
return 0;
}
+/* find precise scalars in the previous equivalent state and
+ * propagate them into the current state
+ */
+static int propagate_precision(struct bpf_verifier_env *env,
+ const struct bpf_verifier_state *old)
+{
+ struct bpf_reg_state *state_reg;
+ struct bpf_func_state *state;
+ int i, err = 0;
+
+ state = old->frame[old->curframe];
+ state_reg = state->regs;
+ for (i = 0; i < BPF_REG_FP; i++, state_reg++) {
+ if (state_reg->type != SCALAR_VALUE ||
+ !state_reg->precise)
+ continue;
+ if (env->log.level & BPF_LOG_LEVEL2)
+ verbose(env, "propagating r%d\n", i);
+ err = mark_chain_precision(env, i);
+ if (err < 0)
+ return err;
+ }
+
+ for (i = 0; i < state->allocated_stack / BPF_REG_SIZE; i++) {
+ if (state->stack[i].slot_type[0] != STACK_SPILL)
+ continue;
+ state_reg = &state->stack[i].spilled_ptr;
+ if (state_reg->type != SCALAR_VALUE ||
+ !state_reg->precise)
+ continue;
+ if (env->log.level & BPF_LOG_LEVEL2)
+ verbose(env, "propagating fp%d\n",
+ (-i - 1) * BPF_REG_SIZE);
+ err = mark_chain_precision_stack(env, i);
+ if (err < 0)
+ return err;
+ }
+ return 0;
+}
+
static bool states_maybe_looping(struct bpf_verifier_state *old,
struct bpf_verifier_state *cur)
{
@@ -7206,6 +7291,14 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx)
* this state and will pop a new one.
*/
err = propagate_liveness(env, &sl->state, cur);
+
+ /* if previous state reached the exit with precision and
+ * current state is equivalent to it (except precsion marks)
+ * the precision needs to be propagated back in
+ * the current state.
+ */
+ err = err ? : push_jmp_history(env, cur);
+ err = err ? : propagate_precision(env, &sl->state);
if (err)
return err;
return 1;
--
2.20.0
^ permalink raw reply related
* Re: [PATCH net-next v2 00/10] net: stmmac: 10GbE using XGMAC
From: David Miller @ 2019-06-28 16:24 UTC (permalink / raw)
To: Jose.Abreu
Cc: linux-kernel, netdev, Joao.Pinto, peppe.cavallaro,
alexandre.torgue
In-Reply-To: <cover.1561706800.git.joabreu@synopsys.com>
From: Jose Abreu <Jose.Abreu@synopsys.com>
Date: Fri, 28 Jun 2019 09:29:11 +0200
> Support for 10Gb Link using XGMAC core plus some performance tweaks.
>
> Tested in a PCI based setup.
>
> iperf3 TCP results:
> TSO ON, MTU=1500, TX Queues = 1, RX Queues = 1, Flow Control ON
> Pinned CPU (-A), Zero-Copy (-Z)
>
> [ ID] Interval Transfer Bitrate Retr
> [ 5] 0.00-600.00 sec 643 GBytes 9.21 Gbits/sec 1 sender
> [ 5] 0.00-600.00 sec 643 GBytes 9.21 Gbits/sec receiver
Series applied, thanks Jose.
About the Kconfig change, maybe it just doesn't make sense to list all
of the various speeds the chip supports... just a thought.
^ permalink raw reply
* Re: [PATCH net-next v2] net: stmmac: Fix case when PHY handle is not present
From: David Miller @ 2019-06-28 16:19 UTC (permalink / raw)
To: Jose.Abreu
Cc: linux-kernel, netdev, Joao.Pinto, peppe.cavallaro,
alexandre.torgue, sergei.shtylyov
In-Reply-To: <654cfe790807c6dfcc69c610c9692efb8c9a6179.1561706654.git.joabreu@synopsys.com>
From: Jose Abreu <Jose.Abreu@synopsys.com>
Date: Fri, 28 Jun 2019 09:25:07 +0200
> Some DT bindings do not have the PHY handle. Let's fallback to manually
> discovery in case phylink_of_phy_connect() fails.
>
> Changes from v1:
> - Fixup comment style (Sergei)
>
> Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
> Reported-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
> Tested-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
> Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Applied, thanks.
^ permalink raw reply
* Re: [PATCH 00/11] XDP unaligned chunk placement support
From: Laatz, Kevin @ 2019-06-28 16:19 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Jonathan Lemon, netdev, ast, daniel, bjorn.topel, magnus.karlsson,
bpf, intel-wired-lan, bruce.richardson, ciara.loftus
In-Reply-To: <20190627142534.4f4b8995@cakuba.netronome.com>
On 27/06/2019 22:25, Jakub Kicinski wrote:
> On Thu, 27 Jun 2019 12:14:50 +0100, Laatz, Kevin wrote:
>> On the application side (xdpsock), we don't have to worry about the user
>> defined headroom, since it is 0, so we only need to account for the
>> XDP_PACKET_HEADROOM when computing the original address (in the default
>> scenario).
> That assumes specific layout for the data inside the buffer. Some NICs
> will prepend information like timestamp to the packet, meaning the
> packet would start at offset XDP_PACKET_HEADROOM + metadata len..
Yes, if NICs prepend extra data to the packet that would be a problem for
using this feature in isolation. However, if we also add in support for
in-order
RX and TX rings, that would no longer be an issue. However, even for NICs
which do prepend data, this patchset should not break anything that is
currently
working.
>
> I think that's very limiting. What is the challenge in providing
> aligned addresses, exactly?
The challenges are two-fold:
1) it prevents using arbitrary buffer sizes, which will be an issue
supporting e.g. jumbo frames in future.
2) higher level user-space frameworks which may want to use AF_XDP, such
as DPDK, do not currently support having buffers with 'fixed' alignment.
The reason that DPDK uses arbitrary placement is that:
- it would stop things working on certain NICs which need the
actual writable space specified in units of 1k - therefore we need 2k +
metadata space.
- we place padding between buffers to avoid constantly hitting
the same memory channels when accessing memory.
- it allows the application to choose the actual buffer size it
wants to use.
We make use of the above to allow us to speed up processing
significantly and also reduce the packet buffer memory size.
Not having arbitrary buffer alignment also means an AF_XDP driver
for DPDK cannot be a drop-in replacement for existing drivers in those
frameworks. Even with a new capability to allow an arbitrary buffer
alignment, existing apps will need to be modified to use that new
capability.
^ permalink raw reply
* Re: pull-request: wireless-drivers 2019-06-28
From: David Miller @ 2019-06-28 16:15 UTC (permalink / raw)
To: kvalo; +Cc: linux-wireless, netdev, linux-kernel
In-Reply-To: <87woh6fa93.fsf@kamboji.qca.qualcomm.com>
From: Kalle Valo <kvalo@codeaurora.org>
Date: Fri, 28 Jun 2019 10:18:48 +0300
> here's a pull request to net tree for 5.2, more info below. Please let
> me know if there are any problems.
Pulled, thanks Kalle.
^ permalink raw reply
* Re: [PATCH] net: stmmac: add sanity check to device_property_read_u32_array call
From: Martin Blumenstingl @ 2019-06-28 16:05 UTC (permalink / raw)
To: Colin Ian King
Cc: alexandre.torgue, davem, joabreu, kernel-janitors,
linux-arm-kernel, linux-kernel, linux-stm32, mcoquelin.stm32,
netdev, peppe.cavallaro
In-Reply-To: <26646ff1-059f-fb2d-e05d-43009aeb2150@canonical.com>
Hi Colin,
On Fri, Jun 28, 2019 at 10:32 AM Colin Ian King
<colin.king@canonical.com> wrote:
>
> On 28/06/2019 05:15, Martin Blumenstingl wrote:
> > On Tue, Jun 25, 2019 at 9:58 AM Colin Ian King <colin.king@canonical.com> wrote:
> >>
> >> On 25/06/2019 05:44, Martin Blumenstingl wrote:
> >>> Hi Colin,
> >>>
> >>> On Thu, Jun 20, 2019 at 3:34 AM Martin Blumenstingl
> >>> <martin.blumenstingl@googlemail.com> wrote:
> >>>>
> >>>> Hi Colin,
> >>>>
> >>>> On Wed, Jun 19, 2019 at 8:55 AM Colin Ian King <colin.king@canonical.com> wrote:
> >>>>>
> >>>>> On 19/06/2019 06:13, Martin Blumenstingl wrote:
> >>>>>> Hi Colin,
> >>>>>>
> >>>>>>> Currently the call to device_property_read_u32_array is not error checked
> >>>>>>> leading to potential garbage values in the delays array that are then used
> >>>>>>> in msleep delays. Add a sanity check to the property fetching.
> >>>>>>>
> >>>>>>> Addresses-Coverity: ("Uninitialized scalar variable")
> >>>>>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> >>>>>> I have also sent a patch [0] to fix initialize the array.
> >>>>>> can you please look at my patch so we can work out which one to use?
> >>>>>>
> >>>>>> my concern is that the "snps,reset-delays-us" property is optional,
> >>>>>> the current dt-bindings documentation states that it's a required
> >>>>>> property. in reality it isn't, there are boards (two examples are
> >>>>>> mentioned in my patch: [0]) without it.
> >>>>>>
> >>>>>> so I believe that the resulting behavior has to be:
> >>>>>> 1. don't delay if this property is missing (instead of delaying for
> >>>>>> <garbage value> ms)
> >>>>>> 2. don't error out if this property is missing
> >>>>>>
> >>>>>> your patch covers #1, can you please check whether #2 is also covered?
> >>>>>> I tested case #2 when submitting my patch and it worked fine (even
> >>>>>> though I could not reproduce the garbage values which are being read
> >>>>>> on some boards)
> >>> in the meantime I have tested your patch.
> >>> when I don't set the "snps,reset-delays-us" property then I get the
> >>> following error:
> >>> invalid property snps,reset-delays-us
> >>>
> >>> my patch has landed in the meantime: [0]
> >>> how should we proceed with your patch?
>
> Your fix is good, so I think we should just drop/forget about my fix.
thank you for looking at the situation
as far I understand the -net/-net-next tree all commits are immutable
so if we want to remove your patch we need to send a revert
do you want me to do that (I can do it on Monday) or will you take care of that?
Martin
^ permalink raw reply
* Re: [PATCH v3 bpf-next 3/9] libbpf: add ability to attach/detach BPF program to perf event
From: Stanislav Fomichev @ 2019-06-28 16:04 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: andrii.nakryiko, ast, daniel, netdev, bpf, kernel-team
In-Reply-To: <20190628055303.1249758-4-andriin@fb.com>
On 06/27, Andrii Nakryiko wrote:
> bpf_program__attach_perf_event allows to attach BPF program to existing
> perf event hook, providing most generic and most low-level way to attach BPF
> programs. It returns struct bpf_link, which should be passed to
> bpf_link__destroy to detach and free resources, associated with a link.
>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
> tools/lib/bpf/libbpf.c | 58 ++++++++++++++++++++++++++++++++++++++++
> tools/lib/bpf/libbpf.h | 3 +++
> tools/lib/bpf/libbpf.map | 1 +
> 3 files changed, 62 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 455795e6f8af..606705f878ba 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -32,6 +32,7 @@
> #include <linux/limits.h>
> #include <linux/perf_event.h>
> #include <linux/ring_buffer.h>
> +#include <sys/ioctl.h>
> #include <sys/stat.h>
> #include <sys/types.h>
> #include <sys/vfs.h>
> @@ -3958,6 +3959,63 @@ int bpf_link__destroy(struct bpf_link *link)
> return err;
> }
>
> +struct bpf_link_fd {
> + struct bpf_link link; /* has to be at the top of struct */
[..]
> + int fd; /* hook FD */
> +};
Any cons to storing everything in bpf_link, instead of creating a
"subclass"? Less things to worry about.
> +static int bpf_link__destroy_perf_event(struct bpf_link *link)
> +{
> + struct bpf_link_fd *l = (void *)link;
> + int err;
> +
> + if (l->fd < 0)
> + return 0;
> +
> + err = ioctl(l->fd, PERF_EVENT_IOC_DISABLE, 0);
> + close(l->fd);
> + return err;
> +}
> +
> +struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog,
> + int pfd)
> +{
> + char errmsg[STRERR_BUFSIZE];
> + struct bpf_link_fd *link;
> + int bpf_fd, err;
> +
> + bpf_fd = bpf_program__fd(prog);
> + if (bpf_fd < 0) {
> + pr_warning("program '%s': can't attach before loaded\n",
> + bpf_program__title(prog, false));
> + return ERR_PTR(-EINVAL);
> + }
> +
> + link = malloc(sizeof(*link));
> + if (!link)
> + return ERR_PTR(-ENOMEM);
> + link->link.destroy = &bpf_link__destroy_perf_event;
> + link->fd = pfd;
> +
> + if (ioctl(pfd, PERF_EVENT_IOC_SET_BPF, bpf_fd) < 0) {
> + err = -errno;
> + free(link);
> + pr_warning("program '%s': failed to attach to pfd %d: %s\n",
> + bpf_program__title(prog, false), pfd,
> + libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
> + return ERR_PTR(err);
> + }
> + if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) {
> + err = -errno;
> + free(link);
> + pr_warning("program '%s': failed to enable pfd %d: %s\n",
> + bpf_program__title(prog, false), pfd,
> + libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
> + return ERR_PTR(err);
> + }
> + return (struct bpf_link *)link;
> +}
> +
> enum bpf_perf_event_ret
> bpf_perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size,
> void **copy_mem, size_t *copy_size,
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index 5082a5ebb0c2..1bf66c4a9330 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -169,6 +169,9 @@ struct bpf_link;
>
> LIBBPF_API int bpf_link__destroy(struct bpf_link *link);
>
> +LIBBPF_API struct bpf_link *
> +bpf_program__attach_perf_event(struct bpf_program *prog, int pfd);
> +
> struct bpf_insn;
>
> /*
> diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> index 3cde850fc8da..756f5aa802e9 100644
> --- a/tools/lib/bpf/libbpf.map
> +++ b/tools/lib/bpf/libbpf.map
> @@ -169,6 +169,7 @@ LIBBPF_0.0.4 {
> global:
> bpf_link__destroy;
> bpf_object__load_xattr;
> + bpf_program__attach_perf_event;
> btf_dump__dump_type;
> btf_dump__free;
> btf_dump__new;
> --
> 2.17.1
>
^ permalink raw reply
* [PATCH iproute2-next] utils: move parse_percent() to tc_util
From: Andrea Claudi @ 2019-06-28 16:03 UTC (permalink / raw)
To: netdev; +Cc: stephen, dsahern
As parse_percent() is used only in tc.
This reduces ip, bridge and genl binaries size:
$ bloat-o-meter -t bridge/bridge bridge/bridge.new
add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-109 (-109)
Total: Before=50973, After=50864, chg -0.21%
$ bloat-o-meter -t genl/genl genl/genl.new
add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-109 (-109)
Total: Before=30298, After=30189, chg -0.36%
$ bloat-o-meter ip/ip ip/ip.new
add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-109 (-109)
Total: Before=674164, After=674055, chg -0.02%
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
---
include/utils.h | 1 -
lib/utils.c | 16 ----------------
tc/tc_util.c | 16 ++++++++++++++++
tc/tc_util.h | 1 +
4 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/include/utils.h b/include/utils.h
index ec0231f9772d0..1d9c11276bbe6 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -146,7 +146,6 @@ int get_addr_rta(inet_prefix *dst, const struct rtattr *rta, int family);
int get_addr_ila(__u64 *val, const char *arg);
int read_prop(const char *dev, char *prop, long *value);
-int parse_percent(double *val, const char *str);
int get_hex(char c);
int get_integer(int *val, const char *arg, int base);
int get_unsigned(unsigned *val, const char *arg, int base);
diff --git a/lib/utils.c b/lib/utils.c
index be0f11b00280d..5da9a47848966 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -101,22 +101,6 @@ out:
return -1;
}
-/* Parse a percent e.g: '30%'
- * return: 0 = ok, -1 = error, 1 = out of range
- */
-int parse_percent(double *val, const char *str)
-{
- char *p;
-
- *val = strtod(str, &p) / 100.;
- if (*val == HUGE_VALF || *val == HUGE_VALL)
- return 1;
- if (*p && strcmp(p, "%"))
- return -1;
-
- return 0;
-}
-
int get_hex(char c)
{
if (c >= 'A' && c <= 'F')
diff --git a/tc/tc_util.c b/tc/tc_util.c
index e5d15281581df..53d15e08e9734 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -190,6 +190,22 @@ static const struct rate_suffix {
{ NULL }
};
+/* Parse a percent e.g: '30%'
+ * return: 0 = ok, -1 = error, 1 = out of range
+ */
+int parse_percent(double *val, const char *str)
+{
+ char *p;
+
+ *val = strtod(str, &p) / 100.;
+ if (*val == HUGE_VALF || *val == HUGE_VALL)
+ return 1;
+ if (*p && strcmp(p, "%"))
+ return -1;
+
+ return 0;
+}
+
static int parse_percent_rate(char *rate, size_t len,
const char *str, const char *dev)
{
diff --git a/tc/tc_util.h b/tc/tc_util.h
index 825fea36a0809..eb4b60db3fdd7 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -101,6 +101,7 @@ int print_tc_classid(char *buf, int len, __u32 h);
char *sprint_tc_classid(__u32 h, char *buf);
int tc_print_police(FILE *f, struct rtattr *tb);
+int parse_percent(double *val, const char *str);
int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n);
int parse_action_control(int *argc_p, char ***argv_p,
--
2.20.1
^ permalink raw reply related
* Re: [PATCH v3 bpf-next 2/9] libbpf: introduce concept of bpf_link
From: Stanislav Fomichev @ 2019-06-28 16:02 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: andrii.nakryiko, ast, daniel, netdev, bpf, kernel-team
In-Reply-To: <20190628055303.1249758-3-andriin@fb.com>
On 06/27, Andrii Nakryiko wrote:
> bpf_link is and abstraction of an association of a BPF program and one
> of many possible BPF attachment points (hooks). This allows to have
> uniform interface for detaching BPF programs regardless of the nature of
> link and how it was created. Details of creation and setting up of
> a specific bpf_link is handled by corresponding attachment methods
> (bpf_program__attach_xxx) added in subsequent commits. Once successfully
> created, bpf_link has to be eventually destroyed with
> bpf_link__destroy(), at which point BPF program is disassociated from
> a hook and all the relevant resources are freed.
>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
> tools/lib/bpf/libbpf.c | 17 +++++++++++++++++
> tools/lib/bpf/libbpf.h | 4 ++++
> tools/lib/bpf/libbpf.map | 3 ++-
> 3 files changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 6e6ebef11ba3..455795e6f8af 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -3941,6 +3941,23 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
> return 0;
> }
>
> +struct bpf_link {
Maybe call it bpf_attachment? You call the bpf_program__attach_to_blah
and you get an attachment?
> + int (*destroy)(struct bpf_link *link);
> +};
> +
> +int bpf_link__destroy(struct bpf_link *link)
> +{
> + int err;
> +
> + if (!link)
> + return 0;
> +
> + err = link->destroy(link);
> + free(link);
> +
> + return err;
> +}
> +
> enum bpf_perf_event_ret
> bpf_perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size,
> void **copy_mem, size_t *copy_size,
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index d639f47e3110..5082a5ebb0c2 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -165,6 +165,10 @@ LIBBPF_API int bpf_program__pin(struct bpf_program *prog, const char *path);
> LIBBPF_API int bpf_program__unpin(struct bpf_program *prog, const char *path);
> LIBBPF_API void bpf_program__unload(struct bpf_program *prog);
>
> +struct bpf_link;
> +
> +LIBBPF_API int bpf_link__destroy(struct bpf_link *link);
> +
> struct bpf_insn;
>
> /*
> diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> index 2c6d835620d2..3cde850fc8da 100644
> --- a/tools/lib/bpf/libbpf.map
> +++ b/tools/lib/bpf/libbpf.map
> @@ -167,10 +167,11 @@ LIBBPF_0.0.3 {
>
> LIBBPF_0.0.4 {
> global:
> + bpf_link__destroy;
> + bpf_object__load_xattr;
> btf_dump__dump_type;
> btf_dump__free;
> btf_dump__new;
> btf__parse_elf;
> - bpf_object__load_xattr;
> libbpf_num_possible_cpus;
> } LIBBPF_0.0.3;
> --
> 2.17.1
>
^ permalink raw reply
* Re: [RFC] longer netdev names proposal
From: Jiri Pirko @ 2019-06-28 15:56 UTC (permalink / raw)
To: Stephen Hemminger
Cc: Andrew Lunn, Michal Kubecek, netdev, David Ahern, davem,
jakub.kicinski, mlxsw
In-Reply-To: <20190628084447.186a0efb@hermes.lan>
Fri, Jun 28, 2019 at 05:44:47PM CEST, stephen@networkplumber.org wrote:
>On Fri, 28 Jun 2019 15:55:53 +0200
>Jiri Pirko <jiri@resnulli.us> wrote:
>
>> Fri, Jun 28, 2019 at 03:14:01PM CEST, andrew@lunn.ch wrote:
>> >On Fri, Jun 28, 2019 at 01:12:16PM +0200, Jiri Pirko wrote:
>> >> Thu, Jun 27, 2019 at 09:20:41PM CEST, stephen@networkplumber.org wrote:
>> >> >On Thu, 27 Jun 2019 20:39:48 +0200
>> >> >Michal Kubecek <mkubecek@suse.cz> wrote:
>> >> >
>> >> >> >
>> >> >> > $ ip li set dev enp3s0 alias "Onboard Ethernet"
>> >> >> > # ip link show "Onboard Ethernet"
>> >> >> > Device "Onboard Ethernet" does not exist.
>> >> >> >
>> >> >> > So it does not really appear to be an alias, it is a label. To be
>> >> >> > truly useful, it needs to be more than a label, it needs to be a real
>> >> >> > alias which you can use.
>> >> >>
>> >> >> That's exactly what I meant: to be really useful, one should be able to
>> >> >> use the alias(es) for setting device options, for adding routes, in
>> >> >> netfilter rules etc.
>> >> >>
>> >> >> Michal
>> >> >
>> >> >The kernel doesn't enforce uniqueness of alias.
>> >> >Also current kernel RTM_GETLINK doesn't do filter by alias (easily fixed).
>> >> >
>> >> >If it did, then handling it in iproute would be something like:
>> >>
>> >> I think that it is desired for kernel to work with "real alias" as a
>> >> handle. Userspace could either pass ifindex, IFLA_NAME or "real alias".
>> >> Userspace mapping like you did here might be perhaps okay for iproute2,
>> >> but I think that we need something and easy to use for all.
>> >>
>> >> Let's call it "altname". Get would return:
>> >>
>> >> IFLA_NAME eth0
>> >> IFLA_ALT_NAME_LIST
>> >> IFLA_ALT_NAME eth0
>> >> IFLA_ALT_NAME somethingelse
>> >> IFLA_ALT_NAME somenamethatisreallylong
>> >
>> >Hi Jiri
>> >
>> >What is your user case for having multiple IFLA_ALT_NAME for the same
>> >IFLA_NAME?
>>
>> I don't know about specific usecase for having more. Perhaps Michal
>> does.
>>
>> From the implementation perspective it is handy to have the ifname as
>> the first alt name in kernel, so the userspace would just pass
>> IFLA_ALT_NAME always. Also for avoiding name collisions etc.
>
>I like the alternate name proposal. The kernel would have to impose uniqueness.
>Does alt_name have to be unique across both regular and alt_name?
Yes. That is my idea. To have one big hashtable to contain them all.
>Having multiple names list seems less interesting but it could be useful.
Yeah. Okay, I'm going to jump on this.
^ permalink raw reply
* Re: [RFC] longer netdev names proposal
From: Stephen Hemminger @ 2019-06-28 15:44 UTC (permalink / raw)
To: Jiri Pirko
Cc: Andrew Lunn, Michal Kubecek, netdev, David Ahern, davem,
jakub.kicinski, mlxsw
In-Reply-To: <20190628135553.GA6640@nanopsycho>
On Fri, 28 Jun 2019 15:55:53 +0200
Jiri Pirko <jiri@resnulli.us> wrote:
> Fri, Jun 28, 2019 at 03:14:01PM CEST, andrew@lunn.ch wrote:
> >On Fri, Jun 28, 2019 at 01:12:16PM +0200, Jiri Pirko wrote:
> >> Thu, Jun 27, 2019 at 09:20:41PM CEST, stephen@networkplumber.org wrote:
> >> >On Thu, 27 Jun 2019 20:39:48 +0200
> >> >Michal Kubecek <mkubecek@suse.cz> wrote:
> >> >
> >> >> >
> >> >> > $ ip li set dev enp3s0 alias "Onboard Ethernet"
> >> >> > # ip link show "Onboard Ethernet"
> >> >> > Device "Onboard Ethernet" does not exist.
> >> >> >
> >> >> > So it does not really appear to be an alias, it is a label. To be
> >> >> > truly useful, it needs to be more than a label, it needs to be a real
> >> >> > alias which you can use.
> >> >>
> >> >> That's exactly what I meant: to be really useful, one should be able to
> >> >> use the alias(es) for setting device options, for adding routes, in
> >> >> netfilter rules etc.
> >> >>
> >> >> Michal
> >> >
> >> >The kernel doesn't enforce uniqueness of alias.
> >> >Also current kernel RTM_GETLINK doesn't do filter by alias (easily fixed).
> >> >
> >> >If it did, then handling it in iproute would be something like:
> >>
> >> I think that it is desired for kernel to work with "real alias" as a
> >> handle. Userspace could either pass ifindex, IFLA_NAME or "real alias".
> >> Userspace mapping like you did here might be perhaps okay for iproute2,
> >> but I think that we need something and easy to use for all.
> >>
> >> Let's call it "altname". Get would return:
> >>
> >> IFLA_NAME eth0
> >> IFLA_ALT_NAME_LIST
> >> IFLA_ALT_NAME eth0
> >> IFLA_ALT_NAME somethingelse
> >> IFLA_ALT_NAME somenamethatisreallylong
> >
> >Hi Jiri
> >
> >What is your user case for having multiple IFLA_ALT_NAME for the same
> >IFLA_NAME?
>
> I don't know about specific usecase for having more. Perhaps Michal
> does.
>
> From the implementation perspective it is handy to have the ifname as
> the first alt name in kernel, so the userspace would just pass
> IFLA_ALT_NAME always. Also for avoiding name collisions etc.
I like the alternate name proposal. The kernel would have to impose uniqueness.
Does alt_name have to be unique across both regular and alt_name?
Having multiple names list seems less interesting but it could be useful.
^ permalink raw reply
* Re: [PATCH v3 1/4] kbuild: compile-test UAPI headers to ensure they are self-contained
From: Sam Ravnborg @ 2019-06-28 15:43 UTC (permalink / raw)
To: Masahiro Yamada
Cc: linux-kbuild, Jani Nikula, Song Liu, Alexei Starovoitov, netdev,
Yonghong Song, linux-kernel, linux-riscv, Michal Marek,
Martin KaFai Lau, Palmer Dabbelt, bpf, Daniel Borkmann, Albert Ou
In-Reply-To: <20190627163903.28398-2-yamada.masahiro@socionext.com>
Hi Masahiro.
On Fri, Jun 28, 2019 at 01:38:59AM +0900, Masahiro Yamada wrote:
> Multiple people have suggested compile-testing UAPI headers to ensure
> they can be really included from user-space. "make headers_check" is
> obviously not enough to catch bugs, and we often leak references to
> kernel-space definition to user-space.
>
> Use the new header-test-y syntax to implement it. Please note exported
> headers are compile-tested with a completely different set of compiler
> flags. The header search path is set to $(objtree)/usr/include since
> exported headers should not include unexported ones.
This patchset introduce a new set of tests for uapi headers.
Can we somehow consolidate so we have only one way to verify the uapi
headers?
It can be confusing for users that they see errors from testing the
uapi headers during normal build and a new class or error if they
run a "make headers_check" sometimes later.
This can be a next step to consolidate this.
With the suggestions below considered you can add my:
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
>
> We use -std=gnu89 for the kernel space since the kernel code highly
> depends on GNU extensions. On the other hand, UAPI headers should be
> written in more standardized C, so they are compiled with -std=c90.
> This will emit errors if C++ style comments, the keyword 'inline', etc.
> are used. Please use C style comments (/* ... */), '__inline__', etc.
> in UAPI headers.
>
> There is additional compiler requirement to enable this test because
> many of UAPI headers include <stdlib.h>, <sys/ioctl.h>, <sys/time.h>,
> etc. directly or indirectly. You cannot use kernel.org pre-built
> toolchains [1] since they lack <stdlib.h>.
>
> I added scripts/cc-system-headers.sh to check the system header
> availability, which CONFIG_UAPI_HEADER_TEST depends on.
>
> For now, a lot of headers need to be excluded because they cannot
> be compiled standalone, but this is a good start point.
>
> [1] https://mirrors.edge.kernel.org/pub/tools/crosstool/index.html
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> Changes in v3: None
> Changes in v2:
> - Add CONFIG_CPU_{BIG,LITTLE}_ENDIAN guard to avoid build error
> - Use 'header-test-' instead of 'no-header-test'
> - Avoid weird 'find' warning when cleaning
>
> Makefile | 2 +-
> init/Kconfig | 11 +++
> scripts/cc-system-headers.sh | 8 +++
> usr/.gitignore | 1 -
> usr/Makefile | 2 +
> usr/include/.gitignore | 3 +
> usr/include/Makefile | 134 +++++++++++++++++++++++++++++++++++
> 7 files changed, 159 insertions(+), 2 deletions(-)
> create mode 100755 scripts/cc-system-headers.sh
> create mode 100644 usr/include/.gitignore
> create mode 100644 usr/include/Makefile
>
> diff --git a/Makefile b/Makefile
> index 1f35aca4fe05..f23516980796 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1363,7 +1363,7 @@ CLEAN_DIRS += $(MODVERDIR) include/ksym
> CLEAN_FILES += modules.builtin.modinfo
>
> # Directories & files removed with 'make mrproper'
> -MRPROPER_DIRS += include/config usr/include include/generated \
> +MRPROPER_DIRS += include/config include/generated \
> arch/$(SRCARCH)/include/generated .tmp_objdiff
> MRPROPER_FILES += .config .config.old .version \
> Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
> diff --git a/init/Kconfig b/init/Kconfig
> index df5bba27e3fe..667d68e1cdf4 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -105,6 +105,17 @@ config HEADER_TEST
> If you are a developer or tester and want to ensure the requested
> headers are self-contained, say Y here. Otherwise, choose N.
>
> +config UAPI_HEADER_TEST
> + bool "Compile test UAPI headers"
> + depends on HEADER_TEST && HEADERS_INSTALL
> + depends on $(success,$(srctree)/scripts/cc-system-headers.sh $(CC))
> + help
> + Compile test headers exported to user-space to ensure they are
> + self-contained, i.e. compilable as standalone units.
> +
> + If you are a developer or tester and want to ensure the exported
> + headers are self-contained, say Y here. Otherwise, choose N.
> +
> config LOCALVERSION
> string "Local version - append to kernel release"
> help
> diff --git a/scripts/cc-system-headers.sh b/scripts/cc-system-headers.sh
> new file mode 100755
> index 000000000000..1b3db369828c
> --- /dev/null
> +++ b/scripts/cc-system-headers.sh
> @@ -0,0 +1,8 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +cat << "END" | $@ -E -x c - -o /dev/null >/dev/null 2>&1
> +#include <stdlib.h>
> +#include <sys/ioctl.h>
> +#include <sys/time.h>
> +END
Add comment to this file that explains that it is used to verify that the
toolchain provides the minimal set of header-files required by uapi
headers.
> diff --git a/usr/.gitignore b/usr/.gitignore
> index 8e48117a3f3d..be5eae1df7eb 100644
> --- a/usr/.gitignore
> +++ b/usr/.gitignore
> @@ -7,4 +7,3 @@ initramfs_data.cpio.gz
> initramfs_data.cpio.bz2
> initramfs_data.cpio.lzma
> initramfs_list
> -include
> diff --git a/usr/Makefile b/usr/Makefile
> index 4a70ae43c9cb..6a89eb019275 100644
> --- a/usr/Makefile
> +++ b/usr/Makefile
> @@ -56,3 +56,5 @@ $(deps_initramfs): klibcdirs
> $(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
> $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y)
> $(call if_changed,initfs)
> +
> +subdir-$(CONFIG_UAPI_HEADER_TEST) += include
> diff --git a/usr/include/.gitignore b/usr/include/.gitignore
> new file mode 100644
> index 000000000000..a0991ff4402b
> --- /dev/null
> +++ b/usr/include/.gitignore
> @@ -0,0 +1,3 @@
> +*
> +!.gitignore
> +!Makefile
> diff --git a/usr/include/Makefile b/usr/include/Makefile
> new file mode 100644
> index 000000000000..58ce96fa1701
> --- /dev/null
> +++ b/usr/include/Makefile
> @@ -0,0 +1,134 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +# Unlike the kernel space, uapi headers are written in standard C.
> +# - Forbid C++ style comments
> +# - Use '__inline__', '__asm__' instead of 'inline', 'asm'
> +#
> +# -std=c90 (equivalent to -ansi) catches the violation of those.
> +# We cannot go as far as adding -Wpedantic since it emits too many warnings.
> +#
> +# REVISIT: re-consider the proper set of compiler flags for uapi compile-test.
> +
> +UAPI_CFLAGS := -std=c90 -Wall -Werror=implicit-function-declaration
> +
> +override c_flags = $(UAPI_CFLAGS) -Wp,-MD,$(depfile) -I$(objtree)/usr/include
> +
> +# The following are excluded for now because they fail to build.
> +# The cause of errors are mostly missing include directives.
> +# Check one by one, and send a patch to each subsystem.
> +#
> +# Do not add a new header to the blacklist without legitimate reason.
> +# Please consider to fix the header first.
Maybe add comment that the alphabetical sort by filename must be preserved.
Not too relevant, as we hopefully do not see files being added.
> +header-test- += asm/ipcbuf.h
> +header-test- += asm/msgbuf.h
Consider same syntax like in include/Makefile where you use
header-test-<tab><tab>...+= file
Then the alignment looks betters.
> +header-test- += asm/sembuf.h
> +header-test- += asm/shmbuf.h
> +header-test- += asm/signal.h
> +header-test- += asm/ucontext.h
> +header-test- += drm/vmwgfx_drm.h
> +header-test- += linux/am437x-vpfe.h
> +header-test- += linux/android/binderfs.h
> +header-test- += linux/android/binder.h
> +header-test-$(CONFIG_CPU_BIG_ENDIAN) += linux/byteorder/big_endian.h
> +header-test-$(CONFIG_CPU_LITTLE_ENDIAN) += linux/byteorder/little_endian.h
> +header-test- += linux/coda.h
...
List is shorter than I feared. Seems quite doable to get down to a
small number of files.
> +
> +# more headers are broken in some architectures
> +
> +ifeq ($(SRCARCH),arc)
> +header-test- += linux/bpf_perf_event.h
> +endif
Again a manageable number.
> +
> +
> +# asm-generic/*.h is used by asm/*.h, and should not be included directly
> +header-test- += asm-generic/%
> +
> +# The rest are compile-tested
> +header-test-y += $(filter-out $(header-test-), \
> + $(patsubst $(obj)/%,%, $(wildcard \
> + $(addprefix $(obj)/, *.h */*.h */*/*.h */*/*/*.h))))
Could you use header-test-pattern-y here?
Sam
^ permalink raw reply
* Re: [PATCH 0/5] net: dsa: microchip: Further regmap cleanups
From: Vivien Didelot @ 2019-06-28 15:31 UTC (permalink / raw)
To: Marek Vasut
Cc: netdev, Marek Vasut, Andrew Lunn, Florian Fainelli, Tristram Ha,
Woojung Huh
In-Reply-To: <20190627215556.23768-1-marex@denx.de>
Hi Marek,
On Thu, 27 Jun 2019 23:55:51 +0200, Marek Vasut <marex@denx.de> wrote:
> This patchset cleans up KSZ9477 switch driver by replacing various
> ad-hoc polling implementations and register RMW with regmap functions.
>
> Each polling function is replaced separately to make it easier to review
> and possibly bisect, but maybe the patches can be squashed.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: Tristram Ha <Tristram.Ha@microchip.com>
> Cc: Woojung Huh <Woojung.Huh@microchip.com>
Please copy me next time, as per the MAINTAINERS file.
Thanks,
Vivien
^ permalink raw reply
* [PATCH v2 bpf-next 4/4] selftests/bpf: convert legacy BPF maps to BTF-defined ones
From: Andrii Nakryiko @ 2019-06-28 15:25 UTC (permalink / raw)
To: andrii.nakryiko, ast, daniel, bpf, netdev, songliubraving; +Cc: Andrii Nakryiko
In-Reply-To: <20190628152539.3014719-1-andriin@fb.com>
Convert selftests that were originally left out and new ones added
recently to consistently use BTF-defined maps.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
.../selftests/bpf/progs/get_cgroup_id_kern.c | 26 ++---
tools/testing/selftests/bpf/progs/pyperf.h | 90 +++++++-------
.../selftests/bpf/progs/sample_map_ret0.c | 24 ++--
.../bpf/progs/sockmap_verdict_prog.c | 48 ++++----
.../testing/selftests/bpf/progs/strobemeta.h | 68 +++++------
.../selftests/bpf/progs/test_map_in_map.c | 30 ++---
.../testing/selftests/bpf/progs/test_obj_id.c | 12 +-
.../selftests/bpf/progs/test_xdp_loop.c | 26 ++---
.../selftests/bpf/progs/xdp_redirect_map.c | 12 +-
.../testing/selftests/bpf/progs/xdping_kern.c | 12 +-
.../selftests/bpf/test_queue_stack_map.h | 30 ++---
.../testing/selftests/bpf/test_sockmap_kern.h | 110 +++++++++---------
12 files changed, 240 insertions(+), 248 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c b/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c
index 014dba10b8a5..d7f4003ac3a2 100644
--- a/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c
+++ b/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c
@@ -4,19 +4,19 @@
#include <linux/bpf.h>
#include "bpf_helpers.h"
-struct bpf_map_def SEC("maps") cg_ids = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u64),
- .max_entries = 1,
-};
-
-struct bpf_map_def SEC("maps") pidmap = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u32),
- .max_entries = 1,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u64);
+} cg_ids SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u32);
+} pidmap SEC(".maps");
SEC("tracepoint/syscalls/sys_enter_nanosleep")
int trace(void *ctx)
diff --git a/tools/testing/selftests/bpf/progs/pyperf.h b/tools/testing/selftests/bpf/progs/pyperf.h
index 6b0781391be5..f0c7250ab045 100644
--- a/tools/testing/selftests/bpf/progs/pyperf.h
+++ b/tools/testing/selftests/bpf/progs/pyperf.h
@@ -58,14 +58,6 @@ typedef struct {
} Event;
-struct bpf_elf_map {
- __u32 type;
- __u32 size_key;
- __u32 size_value;
- __u32 max_elem;
- __u32 flags;
-};
-
typedef int pid_t;
typedef struct {
@@ -119,47 +111,47 @@ get_frame_data(void* frame_ptr, PidData* pidData, FrameData* frame, Symbol* symb
return true;
}
-struct bpf_elf_map SEC("maps") pidmap = {
- .type = BPF_MAP_TYPE_HASH,
- .size_key = sizeof(int),
- .size_value = sizeof(PidData),
- .max_elem = 1,
-};
-
-struct bpf_elf_map SEC("maps") eventmap = {
- .type = BPF_MAP_TYPE_HASH,
- .size_key = sizeof(int),
- .size_value = sizeof(Event),
- .max_elem = 1,
-};
-
-struct bpf_elf_map SEC("maps") symbolmap = {
- .type = BPF_MAP_TYPE_HASH,
- .size_key = sizeof(Symbol),
- .size_value = sizeof(int),
- .max_elem = 1,
-};
-
-struct bpf_elf_map SEC("maps") statsmap = {
- .type = BPF_MAP_TYPE_ARRAY,
- .size_key = sizeof(Stats),
- .size_value = sizeof(int),
- .max_elem = 1,
-};
-
-struct bpf_elf_map SEC("maps") perfmap = {
- .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
- .size_key = sizeof(int),
- .size_value = sizeof(int),
- .max_elem = 32,
-};
-
-struct bpf_elf_map SEC("maps") stackmap = {
- .type = BPF_MAP_TYPE_STACK_TRACE,
- .size_key = sizeof(int),
- .size_value = sizeof(long long) * 127,
- .max_elem = 1000,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, PidData);
+} pidmap SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, Event);
+} eventmap SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 1);
+ __type(key, Symbol);
+ __type(value, int);
+} symbolmap SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, Stats);
+} statsmap SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
+ __int(max_entries, 32);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(int));
+} perfmap SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_STACK_TRACE);
+ __int(max_entries, 1000);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(long long) * 127);
+} stackmap SEC(".maps");
static inline __attribute__((__always_inline__)) int __on_event(struct pt_regs *ctx)
{
diff --git a/tools/testing/selftests/bpf/progs/sample_map_ret0.c b/tools/testing/selftests/bpf/progs/sample_map_ret0.c
index 0756303676ac..7099f3b847d7 100644
--- a/tools/testing/selftests/bpf/progs/sample_map_ret0.c
+++ b/tools/testing/selftests/bpf/progs/sample_map_ret0.c
@@ -2,19 +2,19 @@
#include <linux/bpf.h>
#include "bpf_helpers.h"
-struct bpf_map_def SEC("maps") htab = {
- .type = BPF_MAP_TYPE_HASH,
- .key_size = sizeof(__u32),
- .value_size = sizeof(long),
- .max_entries = 2,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 2);
+ __type(key, __u32);
+ __type(value, long);
+} htab SEC(".maps");
-struct bpf_map_def SEC("maps") array = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(long),
- .max_entries = 2,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 2);
+ __type(key, __u32);
+ __type(value, long);
+} array SEC(".maps");
/* Sample program which should always load for testing control paths. */
SEC(".text") int func()
diff --git a/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c b/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c
index d85c874ef25e..e356d5095f99 100644
--- a/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c
+++ b/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c
@@ -4,33 +4,33 @@
int _version SEC("version") = 1;
-struct bpf_map_def SEC("maps") sock_map_rx = {
- .type = BPF_MAP_TYPE_SOCKMAP,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 20,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_SOCKMAP);
+ __int(max_entries, 20);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(int));
+} sock_map_rx SEC(".maps");
-struct bpf_map_def SEC("maps") sock_map_tx = {
- .type = BPF_MAP_TYPE_SOCKMAP,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 20,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_SOCKMAP);
+ __int(max_entries, 20);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(int));
+} sock_map_tx SEC(".maps");
-struct bpf_map_def SEC("maps") sock_map_msg = {
- .type = BPF_MAP_TYPE_SOCKMAP,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 20,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_SOCKMAP);
+ __int(max_entries, 20);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(int));
+} sock_map_msg SEC(".maps");
-struct bpf_map_def SEC("maps") sock_map_break = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 20,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 20);
+ __type(key, int);
+ __type(value, int);
+} sock_map_break SEC(".maps");
SEC("sk_skb2")
int bpf_prog2(struct __sk_buff *skb)
diff --git a/tools/testing/selftests/bpf/progs/strobemeta.h b/tools/testing/selftests/bpf/progs/strobemeta.h
index 1ff73f60a3e4..2a49fa61d0a3 100644
--- a/tools/testing/selftests/bpf/progs/strobemeta.h
+++ b/tools/testing/selftests/bpf/progs/strobemeta.h
@@ -204,40 +204,40 @@ struct strobelight_bpf_sample {
char dummy_safeguard;
};
-struct bpf_map_def SEC("maps") samples = {
- .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 32,
-};
-
-struct bpf_map_def SEC("maps") stacks_0 = {
- .type = BPF_MAP_TYPE_STACK_TRACE,
- .key_size = sizeof(uint32_t),
- .value_size = sizeof(uint64_t) * PERF_MAX_STACK_DEPTH,
- .max_entries = 16,
-};
-
-struct bpf_map_def SEC("maps") stacks_1 = {
- .type = BPF_MAP_TYPE_STACK_TRACE,
- .key_size = sizeof(uint32_t),
- .value_size = sizeof(uint64_t) * PERF_MAX_STACK_DEPTH,
- .max_entries = 16,
-};
-
-struct bpf_map_def SEC("maps") sample_heap = {
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
- .key_size = sizeof(uint32_t),
- .value_size = sizeof(struct strobelight_bpf_sample),
- .max_entries = 1,
-};
-
-struct bpf_map_def SEC("maps") strobemeta_cfgs = {
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
- .key_size = sizeof(pid_t),
- .value_size = sizeof(struct strobemeta_cfg),
- .max_entries = STROBE_MAX_CFGS,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
+ __int(max_entries, 32);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(int));
+} samples SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_STACK_TRACE);
+ __int(max_entries, 16);
+ __int(key_size, sizeof(uint32_t));
+ __int(value_size, sizeof(uint64_t) * PERF_MAX_STACK_DEPTH);
+} stacks_0 SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_STACK_TRACE);
+ __int(max_entries, 16);
+ __int(key_size, sizeof(uint32_t));
+ __int(value_size, sizeof(uint64_t) * PERF_MAX_STACK_DEPTH);
+} stacks_1 SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __int(max_entries, 1);
+ __type(key, uint32_t);
+ __type(value, struct strobelight_bpf_sample);
+} sample_heap SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __int(max_entries, STROBE_MAX_CFGS);
+ __type(key, pid_t);
+ __type(value, struct strobemeta_cfg);
+} strobemeta_cfgs SEC(".maps");
/* Type for the dtv. */
/* https://github.com/lattera/glibc/blob/master/nptl/sysdeps/x86_64/tls.h#L34 */
diff --git a/tools/testing/selftests/bpf/progs/test_map_in_map.c b/tools/testing/selftests/bpf/progs/test_map_in_map.c
index 2985f262846e..e0028b6457c1 100644
--- a/tools/testing/selftests/bpf/progs/test_map_in_map.c
+++ b/tools/testing/selftests/bpf/progs/test_map_in_map.c
@@ -5,23 +5,23 @@
#include <linux/types.h>
#include "bpf_helpers.h"
-struct bpf_map_def SEC("maps") mim_array = {
- .type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
- .key_size = sizeof(int),
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
+ __int(max_entries, 1);
+ __int(map_flags, 0);
+ __int(key_size, sizeof(__u32));
/* must be sizeof(__u32) for map in map */
- .value_size = sizeof(__u32),
- .max_entries = 1,
- .map_flags = 0,
-};
-
-struct bpf_map_def SEC("maps") mim_hash = {
- .type = BPF_MAP_TYPE_HASH_OF_MAPS,
- .key_size = sizeof(int),
+ __int(value_size, sizeof(__u32));
+} mim_array SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_HASH_OF_MAPS);
+ __int(max_entries, 1);
+ __int(map_flags, 0);
+ __int(key_size, sizeof(int));
/* must be sizeof(__u32) for map in map */
- .value_size = sizeof(__u32),
- .max_entries = 1,
- .map_flags = 0,
-};
+ __int(value_size, sizeof(__u32));
+} mim_hash SEC(".maps");
SEC("xdp_mimtest")
int xdp_mimtest0(struct xdp_md *ctx)
diff --git a/tools/testing/selftests/bpf/progs/test_obj_id.c b/tools/testing/selftests/bpf/progs/test_obj_id.c
index 726340fa6fe0..df3c3d9d251c 100644
--- a/tools/testing/selftests/bpf/progs/test_obj_id.c
+++ b/tools/testing/selftests/bpf/progs/test_obj_id.c
@@ -13,12 +13,12 @@
int _version SEC("version") = 1;
-struct bpf_map_def SEC("maps") test_map_id = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u64),
- .max_entries = 1,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u64);
+} test_map_id SEC(".maps");
SEC("test_obj_id_dummy")
int test_obj_id(struct __sk_buff *skb)
diff --git a/tools/testing/selftests/bpf/progs/test_xdp_loop.c b/tools/testing/selftests/bpf/progs/test_xdp_loop.c
index 7fa4677df22e..45bd5ab25dfd 100644
--- a/tools/testing/selftests/bpf/progs/test_xdp_loop.c
+++ b/tools/testing/selftests/bpf/progs/test_xdp_loop.c
@@ -18,19 +18,19 @@
int _version SEC("version") = 1;
-struct bpf_map_def SEC("maps") rxcnt = {
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u64),
- .max_entries = 256,
-};
-
-struct bpf_map_def SEC("maps") vip2tnl = {
- .type = BPF_MAP_TYPE_HASH,
- .key_size = sizeof(struct vip),
- .value_size = sizeof(struct iptnl_info),
- .max_entries = MAX_IPTNL_ENTRIES,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __int(max_entries, 256);
+ __type(key, __u32);
+ __type(value, __u64);
+} rxcnt SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, MAX_IPTNL_ENTRIES);
+ __type(key, struct vip);
+ __type(value, struct iptnl_info);
+} vip2tnl SEC(".maps");
static __always_inline void count_tx(__u32 protocol)
{
diff --git a/tools/testing/selftests/bpf/progs/xdp_redirect_map.c b/tools/testing/selftests/bpf/progs/xdp_redirect_map.c
index e87a985b9df9..8f05369b1034 100644
--- a/tools/testing/selftests/bpf/progs/xdp_redirect_map.c
+++ b/tools/testing/selftests/bpf/progs/xdp_redirect_map.c
@@ -3,12 +3,12 @@
#include <linux/bpf.h>
#include "bpf_helpers.h"
-struct bpf_map_def SEC("maps") tx_port = {
- .type = BPF_MAP_TYPE_DEVMAP,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 8,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_DEVMAP);
+ __int(max_entries, 8);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(int));
+} tx_port SEC(".maps");
SEC("redirect_map_0")
int xdp_redirect_map_0(struct xdp_md *xdp)
diff --git a/tools/testing/selftests/bpf/progs/xdping_kern.c b/tools/testing/selftests/bpf/progs/xdping_kern.c
index 87393e7c667c..3b0adfe8d685 100644
--- a/tools/testing/selftests/bpf/progs/xdping_kern.c
+++ b/tools/testing/selftests/bpf/progs/xdping_kern.c
@@ -17,12 +17,12 @@
#include "xdping.h"
-struct bpf_map_def SEC("maps") ping_map = {
- .type = BPF_MAP_TYPE_HASH,
- .key_size = sizeof(__u32),
- .value_size = sizeof(struct pinginfo),
- .max_entries = 256,
-};
+struct {
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 256);
+ __type(key, __u32);
+ __type(value, struct pinginfo);
+} ping_map SEC(".maps");
static __always_inline void swap_src_dst_mac(void *data)
{
diff --git a/tools/testing/selftests/bpf/test_queue_stack_map.h b/tools/testing/selftests/bpf/test_queue_stack_map.h
index 295b9b3bc5c7..5eb376bbbbb3 100644
--- a/tools/testing/selftests/bpf/test_queue_stack_map.h
+++ b/tools/testing/selftests/bpf/test_queue_stack_map.h
@@ -10,21 +10,21 @@
int _version SEC("version") = 1;
-struct bpf_map_def __attribute__ ((section("maps"), used)) map_in = {
- .type = MAP_TYPE,
- .key_size = 0,
- .value_size = sizeof(__u32),
- .max_entries = 32,
- .map_flags = 0,
-};
-
-struct bpf_map_def __attribute__ ((section("maps"), used)) map_out = {
- .type = MAP_TYPE,
- .key_size = 0,
- .value_size = sizeof(__u32),
- .max_entries = 32,
- .map_flags = 0,
-};
+struct {
+ __int(type, MAP_TYPE);
+ __int(max_entries, 32);
+ __int(map_flags, 0);
+ __int(key_size, 0);
+ __int(value_size, sizeof(__u32));
+} map_in SEC(".maps");
+
+struct {
+ __int(type, MAP_TYPE);
+ __int(max_entries, 32);
+ __int(map_flags, 0);
+ __int(key_size, 0);
+ __int(value_size, sizeof(__u32));
+} map_out SEC(".maps");
SEC("test")
int _test(struct __sk_buff *skb)
diff --git a/tools/testing/selftests/bpf/test_sockmap_kern.h b/tools/testing/selftests/bpf/test_sockmap_kern.h
index 4e7d3da21357..d5e472780dcd 100644
--- a/tools/testing/selftests/bpf/test_sockmap_kern.h
+++ b/tools/testing/selftests/bpf/test_sockmap_kern.h
@@ -28,61 +28,61 @@
* are established and verdicts are decided.
*/
-struct bpf_map_def SEC("maps") sock_map = {
- .type = TEST_MAP_TYPE,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 20,
-};
-
-struct bpf_map_def SEC("maps") sock_map_txmsg = {
- .type = TEST_MAP_TYPE,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 20,
-};
-
-struct bpf_map_def SEC("maps") sock_map_redir = {
- .type = TEST_MAP_TYPE,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 20,
-};
-
-struct bpf_map_def SEC("maps") sock_apply_bytes = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 1
-};
-
-struct bpf_map_def SEC("maps") sock_cork_bytes = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 1
-};
-
-struct bpf_map_def SEC("maps") sock_bytes = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 6
-};
-
-struct bpf_map_def SEC("maps") sock_redir_flags = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 1
-};
-
-struct bpf_map_def SEC("maps") sock_skb_opts = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
- .max_entries = 1
-};
+struct {
+ __int(type, TEST_MAP_TYPE);
+ __int(max_entries, 20);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(int));
+} sock_map SEC(".maps");
+
+struct {
+ __int(type, TEST_MAP_TYPE);
+ __int(max_entries, 20);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(int));
+} sock_map_txmsg SEC(".maps");
+
+struct {
+ __int(type, TEST_MAP_TYPE);
+ __int(max_entries, 20);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(int));
+} sock_map_redir SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, int);
+} sock_apply_bytes SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, int);
+} sock_cork_bytes SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 6);
+ __type(key, int);
+ __type(value, int);
+} sock_bytes SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, int);
+} sock_redir_flags SEC(".maps");
+
+struct {
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, int);
+} sock_skb_opts SEC(".maps");
SEC("sk_skb1")
int bpf_prog1(struct __sk_buff *skb)
--
2.17.1
^ permalink raw reply related
* [PATCH v2 bpf-next 3/4] selftests/bpf: convert selftests using BTF-defined maps to new syntax
From: Andrii Nakryiko @ 2019-06-28 15:25 UTC (permalink / raw)
To: andrii.nakryiko, ast, daniel, bpf, netdev, songliubraving; +Cc: Andrii Nakryiko
In-Reply-To: <20190628152539.3014719-1-andriin@fb.com>
Convert all the existing selftests that are already using BTF-defined
maps to use new syntax (with no static data initialization).
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
tools/testing/selftests/bpf/progs/bpf_flow.c | 28 +++----
.../testing/selftests/bpf/progs/netcnt_prog.c | 20 ++---
.../selftests/bpf/progs/socket_cookie_prog.c | 13 ++-
.../selftests/bpf/progs/test_btf_newkv.c | 13 ++-
.../bpf/progs/test_get_stack_rawtp.c | 39 ++++-----
.../selftests/bpf/progs/test_global_data.c | 37 ++++-----
tools/testing/selftests/bpf/progs/test_l4lb.c | 65 ++++++---------
.../selftests/bpf/progs/test_l4lb_noinline.c | 65 ++++++---------
.../selftests/bpf/progs/test_map_lock.c | 26 +++---
.../bpf/progs/test_select_reuseport_kern.c | 67 ++++++---------
.../bpf/progs/test_send_signal_kern.c | 26 +++---
.../bpf/progs/test_sock_fields_kern.c | 78 +++++++-----------
.../selftests/bpf/progs/test_spin_lock.c | 36 ++++-----
.../bpf/progs/test_stacktrace_build_id.c | 55 +++++--------
.../selftests/bpf/progs/test_stacktrace_map.c | 52 +++++-------
.../selftests/bpf/progs/test_tcp_estats.c | 13 ++-
.../selftests/bpf/progs/test_tcpbpf_kern.c | 26 +++---
.../selftests/bpf/progs/test_tcpnotify_kern.c | 28 +++----
tools/testing/selftests/bpf/progs/test_xdp.c | 26 +++---
.../selftests/bpf/progs/test_xdp_noinline.c | 81 +++++++------------
20 files changed, 300 insertions(+), 494 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/bpf_flow.c b/tools/testing/selftests/bpf/progs/bpf_flow.c
index 849f42e548b5..a5564a90525d 100644
--- a/tools/testing/selftests/bpf/progs/bpf_flow.c
+++ b/tools/testing/selftests/bpf/progs/bpf_flow.c
@@ -58,26 +58,18 @@ struct frag_hdr {
};
struct {
- __u32 type;
- __u32 max_entries;
- __u32 key_size;
- __u32 value_size;
-} jmp_table SEC(".maps") = {
- .type = BPF_MAP_TYPE_PROG_ARRAY,
- .max_entries = 8,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u32),
-};
+ __int(type, BPF_MAP_TYPE_PROG_ARRAY);
+ __int(max_entries, 8);
+ __int(key_size, sizeof(__u32));
+ __int(value_size, sizeof(__u32));
+} jmp_table SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct bpf_flow_keys *value;
-} last_dissection SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, struct bpf_flow_keys);
+} last_dissection SEC(".maps");
static __always_inline int export_flow_keys(struct bpf_flow_keys *keys,
int ret)
diff --git a/tools/testing/selftests/bpf/progs/netcnt_prog.c b/tools/testing/selftests/bpf/progs/netcnt_prog.c
index a25c82a5b7c8..31afe01ca52e 100644
--- a/tools/testing/selftests/bpf/progs/netcnt_prog.c
+++ b/tools/testing/selftests/bpf/progs/netcnt_prog.c
@@ -11,20 +11,16 @@
#define NS_PER_SEC 1000000000
struct {
- __u32 type;
- struct bpf_cgroup_storage_key *key;
- struct percpu_net_cnt *value;
-} percpu_netcnt SEC(".maps") = {
- .type = BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
-};
+ __int(type, BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE);
+ __type(key, struct bpf_cgroup_storage_key);
+ __type(value, struct percpu_net_cnt);
+} percpu_netcnt SEC(".maps");
struct {
- __u32 type;
- struct bpf_cgroup_storage_key *key;
- struct net_cnt *value;
-} netcnt SEC(".maps") = {
- .type = BPF_MAP_TYPE_CGROUP_STORAGE,
-};
+ __int(type, BPF_MAP_TYPE_CGROUP_STORAGE);
+ __type(key, struct bpf_cgroup_storage_key);
+ __type(value, struct net_cnt);
+} netcnt SEC(".maps");
SEC("cgroup/skb")
int bpf_nextcnt(struct __sk_buff *skb)
diff --git a/tools/testing/selftests/bpf/progs/socket_cookie_prog.c b/tools/testing/selftests/bpf/progs/socket_cookie_prog.c
index 6aabb681fb9a..6cd0a9457175 100644
--- a/tools/testing/selftests/bpf/progs/socket_cookie_prog.c
+++ b/tools/testing/selftests/bpf/progs/socket_cookie_prog.c
@@ -13,14 +13,11 @@ struct socket_cookie {
};
struct {
- __u32 type;
- __u32 map_flags;
- int *key;
- struct socket_cookie *value;
-} socket_cookies SEC(".maps") = {
- .type = BPF_MAP_TYPE_SK_STORAGE,
- .map_flags = BPF_F_NO_PREALLOC,
-};
+ __int(type, BPF_MAP_TYPE_SK_STORAGE);
+ __int(map_flags, BPF_F_NO_PREALLOC);
+ __type(key, int);
+ __type(value, struct socket_cookie);
+} socket_cookies SEC(".maps");
SEC("cgroup/connect6")
int set_cookie(struct bpf_sock_addr *ctx)
diff --git a/tools/testing/selftests/bpf/progs/test_btf_newkv.c b/tools/testing/selftests/bpf/progs/test_btf_newkv.c
index 28c16bb583b6..572ee1050e61 100644
--- a/tools/testing/selftests/bpf/progs/test_btf_newkv.c
+++ b/tools/testing/selftests/bpf/progs/test_btf_newkv.c
@@ -21,14 +21,11 @@ struct bpf_map_def SEC("maps") btf_map_legacy = {
BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts);
struct {
- int *key;
- struct ipv_counts *value;
- unsigned int type;
- unsigned int max_entries;
-} btf_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 4,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 4);
+ __type(key, int);
+ __type(value, struct ipv_counts);
+} btf_map SEC(".maps");
struct dummy_tracepoint_args {
unsigned long long pad;
diff --git a/tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c b/tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c
index aaa6ec250e15..1bf73cf264b8 100644
--- a/tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c
+++ b/tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c
@@ -16,26 +16,18 @@ struct stack_trace_t {
};
struct {
- __u32 type;
- __u32 max_entries;
- __u32 key_size;
- __u32 value_size;
-} perfmap SEC(".maps") = {
- .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
- .max_entries = 2,
- .key_size = sizeof(int),
- .value_size = sizeof(__u32),
-};
+ __int(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
+ __int(max_entries, 2);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(__u32));
+} perfmap SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct stack_trace_t *value;
-} stackdata_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, struct stack_trace_t);
+} stackdata_map SEC(".maps");
/* Allocate per-cpu space twice the needed. For the code below
* usize = bpf_get_stack(ctx, raw_data, max_len, BPF_F_USER_STACK);
@@ -56,14 +48,11 @@ struct {
* This is an acceptable workaround since there is one entry here.
*/
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
+ __int(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
__u64 (*value)[2 * MAX_STACK_RAWTP];
-} rawdata_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
- .max_entries = 1,
-};
+} rawdata_map SEC(".maps");
SEC("tracepoint/raw_syscalls/sys_enter")
int bpf_prog1(void *ctx)
diff --git a/tools/testing/selftests/bpf/progs/test_global_data.c b/tools/testing/selftests/bpf/progs/test_global_data.c
index 866cc7ddbe43..aee3a3167d16 100644
--- a/tools/testing/selftests/bpf/progs/test_global_data.c
+++ b/tools/testing/selftests/bpf/progs/test_global_data.c
@@ -8,24 +8,18 @@
#include "bpf_helpers.h"
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u64 *value;
-} result_number SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 11,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 11);
+ __type(key, __u32);
+ __type(value, __u64);
+} result_number SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 5);
+ __type(key, __u32);
const char (*value)[32];
-} result_string SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 5,
-};
+} result_string SEC(".maps");
struct foo {
__u8 a;
@@ -34,14 +28,11 @@ struct foo {
};
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct foo *value;
-} result_struct SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 5,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 5);
+ __type(key, __u32);
+ __type(value, struct foo);
+} result_struct SEC(".maps");
/* Relocation tests for __u64s. */
static __u64 num0;
diff --git a/tools/testing/selftests/bpf/progs/test_l4lb.c b/tools/testing/selftests/bpf/progs/test_l4lb.c
index 848cbb90f581..6d6c5659f147 100644
--- a/tools/testing/selftests/bpf/progs/test_l4lb.c
+++ b/tools/testing/selftests/bpf/progs/test_l4lb.c
@@ -170,54 +170,39 @@ struct eth_hdr {
};
struct {
- __u32 type;
- __u32 max_entries;
- struct vip *key;
- struct vip_meta *value;
-} vip_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_HASH,
- .max_entries = MAX_VIPS,
-};
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, MAX_VIPS);
+ __type(key, struct vip);
+ __type(value, struct vip_meta);
+} vip_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} ch_rings SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = CH_RINGS_SIZE,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, CH_RINGS_SIZE);
+ __type(key, __u32);
+ __type(value, __u32);
+} ch_rings SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct real_definition *value;
-} reals SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = MAX_REALS,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, MAX_REALS);
+ __type(key, __u32);
+ __type(value, struct real_definition);
+} reals SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct vip_stats *value;
-} stats SEC(".maps") = {
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
- .max_entries = MAX_VIPS,
-};
+ __int(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __int(max_entries, MAX_VIPS);
+ __type(key, __u32);
+ __type(value, struct vip_stats);
+} stats SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct ctl_value *value;
-} ctl_array SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = CTL_MAP_SIZE,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, CTL_MAP_SIZE);
+ __type(key, __u32);
+ __type(value, struct ctl_value);
+} ctl_array SEC(".maps");
static __always_inline __u32 get_packet_hash(struct packet_description *pckt,
bool ipv6)
diff --git a/tools/testing/selftests/bpf/progs/test_l4lb_noinline.c b/tools/testing/selftests/bpf/progs/test_l4lb_noinline.c
index c63ecf3ca573..1780e92955be 100644
--- a/tools/testing/selftests/bpf/progs/test_l4lb_noinline.c
+++ b/tools/testing/selftests/bpf/progs/test_l4lb_noinline.c
@@ -166,54 +166,39 @@ struct eth_hdr {
};
struct {
- __u32 type;
- __u32 max_entries;
- struct vip *key;
- struct vip_meta *value;
-} vip_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_HASH,
- .max_entries = MAX_VIPS,
-};
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, MAX_VIPS);
+ __type(key, struct vip);
+ __type(value, struct vip_meta);
+} vip_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} ch_rings SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = CH_RINGS_SIZE,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, CH_RINGS_SIZE);
+ __type(key, __u32);
+ __type(value, __u32);
+} ch_rings SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct real_definition *value;
-} reals SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = MAX_REALS,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, MAX_REALS);
+ __type(key, __u32);
+ __type(value, struct real_definition);
+} reals SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct vip_stats *value;
-} stats SEC(".maps") = {
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
- .max_entries = MAX_VIPS,
-};
+ __int(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __int(max_entries, MAX_VIPS);
+ __type(key, __u32);
+ __type(value, struct vip_stats);
+} stats SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct ctl_value *value;
-} ctl_array SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = CTL_MAP_SIZE,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, CTL_MAP_SIZE);
+ __type(key, __u32);
+ __type(value, struct ctl_value);
+} ctl_array SEC(".maps");
static __u32 get_packet_hash(struct packet_description *pckt,
bool ipv6)
diff --git a/tools/testing/selftests/bpf/progs/test_map_lock.c b/tools/testing/selftests/bpf/progs/test_map_lock.c
index 40d9c2853393..7cfd21477d29 100644
--- a/tools/testing/selftests/bpf/progs/test_map_lock.c
+++ b/tools/testing/selftests/bpf/progs/test_map_lock.c
@@ -12,14 +12,11 @@ struct hmap_elem {
};
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct hmap_elem *value;
-} hash_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_HASH,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, struct hmap_elem);
+} hash_map SEC(".maps");
struct array_elem {
struct bpf_spin_lock lock;
@@ -27,14 +24,11 @@ struct array_elem {
};
struct {
- __u32 type;
- __u32 max_entries;
- int *key;
- struct array_elem *value;
-} array_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, struct array_elem);
+} array_map SEC(".maps");
SEC("map_lock_demo")
int bpf_map_lock_test(struct __sk_buff *skb)
diff --git a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
index 435a9527733e..4e7bca8c8239 100644
--- a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
@@ -22,56 +22,39 @@ int _version SEC("version") = 1;
#endif
struct {
- __u32 type;
- __u32 max_entries;
- __u32 key_size;
- __u32 value_size;
-} outer_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
- .max_entries = 1,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u32),
-};
+ __int(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
+ __int(max_entries, 1);
+ __int(key_size, sizeof(__u32));
+ __int(value_size, sizeof(__u32));
+} outer_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} result_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = NR_RESULTS,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, NR_RESULTS);
+ __type(key, __u32);
+ __type(value, __u32);
+} result_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- int *value;
-} tmp_index_ovr_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, int);
+} tmp_index_ovr_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} linum_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u32);
+} linum_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct data_check *value;
-} data_check_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, struct data_check);
+} data_check_map SEC(".maps");
#define GOTO_DONE(_result) ({ \
result = (_result); \
diff --git a/tools/testing/selftests/bpf/progs/test_send_signal_kern.c b/tools/testing/selftests/bpf/progs/test_send_signal_kern.c
index 6ac68be5d68b..230c6c7e0928 100644
--- a/tools/testing/selftests/bpf/progs/test_send_signal_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_send_signal_kern.c
@@ -5,24 +5,18 @@
#include "bpf_helpers.h"
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u64 *value;
-} info_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u64);
+} info_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u64 *value;
-} status_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u64);
+} status_map SEC(".maps");
SEC("send_signal_demo")
int bpf_send_signal_test(void *ctx)
diff --git a/tools/testing/selftests/bpf/progs/test_sock_fields_kern.c b/tools/testing/selftests/bpf/progs/test_sock_fields_kern.c
index c3d383d650cb..472b7e637a7a 100644
--- a/tools/testing/selftests/bpf/progs/test_sock_fields_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_sock_fields_kern.c
@@ -28,44 +28,32 @@ enum bpf_linum_array_idx {
};
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct sockaddr_in6 *value;
-} addr_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = __NR_BPF_ADDR_ARRAY_IDX,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, __NR_BPF_ADDR_ARRAY_IDX);
+ __type(key, __u32);
+ __type(value, struct sockaddr_in6);
+} addr_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct bpf_sock *value;
-} sock_result_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = __NR_BPF_RESULT_ARRAY_IDX,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, __NR_BPF_RESULT_ARRAY_IDX);
+ __type(key, __u32);
+ __type(value, struct bpf_sock);
+} sock_result_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct bpf_tcp_sock *value;
-} tcp_sock_result_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = __NR_BPF_RESULT_ARRAY_IDX,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, __NR_BPF_RESULT_ARRAY_IDX);
+ __type(key, __u32);
+ __type(value, struct bpf_tcp_sock);
+} tcp_sock_result_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} linum_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = __NR_BPF_LINUM_ARRAY_IDX,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, __NR_BPF_LINUM_ARRAY_IDX);
+ __type(key, __u32);
+ __type(value, __u32);
+} linum_map SEC(".maps");
struct bpf_spinlock_cnt {
struct bpf_spin_lock lock;
@@ -73,24 +61,18 @@ struct bpf_spinlock_cnt {
};
struct {
- __u32 type;
- __u32 map_flags;
- int *key;
- struct bpf_spinlock_cnt *value;
-} sk_pkt_out_cnt SEC(".maps") = {
- .type = BPF_MAP_TYPE_SK_STORAGE,
- .map_flags = BPF_F_NO_PREALLOC,
-};
+ __int(type, BPF_MAP_TYPE_SK_STORAGE);
+ __int(map_flags, BPF_F_NO_PREALLOC);
+ __type(key, int);
+ __type(value, struct bpf_spinlock_cnt);
+} sk_pkt_out_cnt SEC(".maps");
struct {
- __u32 type;
- __u32 map_flags;
- int *key;
- struct bpf_spinlock_cnt *value;
-} sk_pkt_out_cnt10 SEC(".maps") = {
- .type = BPF_MAP_TYPE_SK_STORAGE,
- .map_flags = BPF_F_NO_PREALLOC,
-};
+ __int(type, BPF_MAP_TYPE_SK_STORAGE);
+ __int(map_flags, BPF_F_NO_PREALLOC);
+ __type(key, int);
+ __type(value, struct bpf_spinlock_cnt);
+} sk_pkt_out_cnt10 SEC(".maps");
static bool is_loopback6(__u32 *a6)
{
diff --git a/tools/testing/selftests/bpf/progs/test_spin_lock.c b/tools/testing/selftests/bpf/progs/test_spin_lock.c
index 0a77ae36d981..6341cec3fb49 100644
--- a/tools/testing/selftests/bpf/progs/test_spin_lock.c
+++ b/tools/testing/selftests/bpf/progs/test_spin_lock.c
@@ -11,14 +11,11 @@ struct hmap_elem {
};
struct {
- __u32 type;
- __u32 max_entries;
- int *key;
- struct hmap_elem *value;
-} hmap SEC(".maps") = {
- .type = BPF_MAP_TYPE_HASH,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, struct hmap_elem);
+} hmap SEC(".maps");
struct cls_elem {
struct bpf_spin_lock lock;
@@ -26,12 +23,10 @@ struct cls_elem {
};
struct {
- __u32 type;
- struct bpf_cgroup_storage_key *key;
- struct cls_elem *value;
-} cls_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_CGROUP_STORAGE,
-};
+ __int(type, BPF_MAP_TYPE_CGROUP_STORAGE);
+ __type(key, struct bpf_cgroup_storage_key);
+ __type(value, struct cls_elem);
+} cls_map SEC(".maps");
struct bpf_vqueue {
struct bpf_spin_lock lock;
@@ -42,14 +37,11 @@ struct bpf_vqueue {
};
struct {
- __u32 type;
- __u32 max_entries;
- int *key;
- struct bpf_vqueue *value;
-} vqueue SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, int);
+ __type(value, struct bpf_vqueue);
+} vqueue SEC(".maps");
#define CREDIT_PER_NS(delta, rate) (((delta) * rate) >> 20)
diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c b/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c
index fcf2280bb60c..38697b58ae66 100644
--- a/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c
+++ b/tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c
@@ -9,51 +9,36 @@
#endif
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} control_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u32);
+} control_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} stackid_hmap SEC(".maps") = {
- .type = BPF_MAP_TYPE_HASH,
- .max_entries = 16384,
-};
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 16384);
+ __type(key, __u32);
+ __type(value, __u32);
+} stackid_hmap SEC(".maps");
typedef struct bpf_stack_build_id stack_trace_t[PERF_MAX_STACK_DEPTH];
struct {
- __u32 type;
- __u32 max_entries;
- __u32 map_flags;
- __u32 key_size;
- __u32 value_size;
-} stackmap SEC(".maps") = {
- .type = BPF_MAP_TYPE_STACK_TRACE,
- .max_entries = 128,
- .map_flags = BPF_F_STACK_BUILD_ID,
- .key_size = sizeof(__u32),
- .value_size = sizeof(stack_trace_t),
-};
+ __int(type, BPF_MAP_TYPE_STACK_TRACE);
+ __int(max_entries, 128);
+ __int(map_flags, BPF_F_STACK_BUILD_ID);
+ __int(key_size, sizeof(__u32));
+ __int(value_size, sizeof(stack_trace_t));
+} stackmap SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 128);
+ __type(key, __u32);
/* there seems to be a bug in kernel not handling typedef properly */
struct bpf_stack_build_id (*value)[PERF_MAX_STACK_DEPTH];
-} stack_amap SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 128,
-};
+} stack_amap SEC(".maps");
/* taken from /sys/kernel/debug/tracing/events/random/urandom_read/format */
struct random_urandom_args {
diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c
index 7ad09adbf648..b3133855adff 100644
--- a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c
+++ b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c
@@ -9,48 +9,34 @@
#endif
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} control_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 1,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u32);
+} control_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} stackid_hmap SEC(".maps") = {
- .type = BPF_MAP_TYPE_HASH,
- .max_entries = 16384,
-};
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 16384);
+ __type(key, __u32);
+ __type(value, __u32);
+} stackid_hmap SEC(".maps");
typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH];
struct {
- __u32 type;
- __u32 max_entries;
- __u32 key_size;
- __u32 value_size;
-} stackmap SEC(".maps") = {
- .type = BPF_MAP_TYPE_STACK_TRACE,
- .max_entries = 16384,
- .key_size = sizeof(__u32),
- .value_size = sizeof(stack_trace_t),
-};
+ __int(type, BPF_MAP_TYPE_STACK_TRACE);
+ __int(max_entries, 16384);
+ __int(key_size, sizeof(__u32));
+ __int(value_size, sizeof(stack_trace_t));
+} stackmap SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 16384);
+ __type(key, __u32);
__u64 (*value)[PERF_MAX_STACK_DEPTH];
-} stack_amap SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 16384,
-};
+} stack_amap SEC(".maps");
/* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
struct sched_switch_args {
diff --git a/tools/testing/selftests/bpf/progs/test_tcp_estats.c b/tools/testing/selftests/bpf/progs/test_tcp_estats.c
index df98f7e32832..9b0c1ddb2fdf 100644
--- a/tools/testing/selftests/bpf/progs/test_tcp_estats.c
+++ b/tools/testing/selftests/bpf/progs/test_tcp_estats.c
@@ -149,14 +149,11 @@ struct tcp_estats_basic_event {
};
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct tcp_estats_basic_event *value;
-} ev_record_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_HASH,
- .max_entries = 1024,
-};
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 1024);
+ __type(key, __u32);
+ __type(value, struct tcp_estats_basic_event);
+} ev_record_map SEC(".maps");
struct dummy_tracepoint_args {
unsigned long long pad;
diff --git a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c
index 38e10c9fd996..229bc249bbb9 100644
--- a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c
@@ -15,24 +15,18 @@
#include "test_tcpbpf.h"
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct tcpbpf_globals *value;
-} global_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 4,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 4);
+ __type(key, __u32);
+ __type(value, struct tcpbpf_globals);
+} global_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- int *value;
-} sockopt_results SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 2,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 2);
+ __type(key, __u32);
+ __type(value, int);
+} sockopt_results SEC(".maps");
static inline void update_event_map(int event)
{
diff --git a/tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c b/tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c
index d073d37d4e27..68ea98f0384f 100644
--- a/tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c
@@ -15,26 +15,18 @@
#include "test_tcpnotify.h"
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct tcpnotify_globals *value;
-} global_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 4,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 4);
+ __type(key, __u32);
+ __type(value, struct tcpnotify_globals);
+} global_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 key_size;
- __u32 value_size;
-} perf_event_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
- .max_entries = 2,
- .key_size = sizeof(int),
- .value_size = sizeof(__u32),
-};
+ __int(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
+ __int(max_entries, 2);
+ __int(key_size, sizeof(int));
+ __int(value_size, sizeof(__u32));
+} perf_event_map SEC(".maps");
int _version SEC("version") = 1;
diff --git a/tools/testing/selftests/bpf/progs/test_xdp.c b/tools/testing/selftests/bpf/progs/test_xdp.c
index ec3d2c1c8cf9..f1a29d7a17fd 100644
--- a/tools/testing/selftests/bpf/progs/test_xdp.c
+++ b/tools/testing/selftests/bpf/progs/test_xdp.c
@@ -23,24 +23,18 @@
int _version SEC("version") = 1;
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u64 *value;
-} rxcnt SEC(".maps") = {
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
- .max_entries = 256,
-};
+ __int(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __int(max_entries, 256);
+ __type(key, __u32);
+ __type(value, __u64);
+} rxcnt SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- struct vip *key;
- struct iptnl_info *value;
-} vip2tnl SEC(".maps") = {
- .type = BPF_MAP_TYPE_HASH,
- .max_entries = MAX_IPTNL_ENTRIES,
-};
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, MAX_IPTNL_ENTRIES);
+ __type(key, struct vip);
+ __type(value, struct iptnl_info);
+} vip2tnl SEC(".maps");
static __always_inline void count_tx(__u32 protocol)
{
diff --git a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c
index d2eddb5553d1..07a3148e44dc 100644
--- a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c
+++ b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c
@@ -164,66 +164,47 @@ struct lb_stats {
};
struct {
- __u32 type;
- __u32 max_entries;
- struct vip_definition *key;
- struct vip_meta *value;
-} vip_map SEC(".maps") = {
- .type = BPF_MAP_TYPE_HASH,
- .max_entries = 512,
-};
+ __int(type, BPF_MAP_TYPE_HASH);
+ __int(max_entries, 512);
+ __type(key, struct vip_definition);
+ __type(value, struct vip_meta);
+} vip_map SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 map_flags;
- struct flow_key *key;
- struct real_pos_lru *value;
-} lru_cache SEC(".maps") = {
- .type = BPF_MAP_TYPE_LRU_HASH,
- .max_entries = 300,
- .map_flags = 1U << 1,
-};
+ __int(type, BPF_MAP_TYPE_LRU_HASH);
+ __int(max_entries, 300);
+ __int(map_flags, 1U << 1);
+ __type(key, struct flow_key);
+ __type(value, struct real_pos_lru);
+} lru_cache SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- __u32 *value;
-} ch_rings SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 12 * 655,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 12 * 655);
+ __type(key, __u32);
+ __type(value, __u32);
+} ch_rings SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct real_definition *value;
-} reals SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 40,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 40);
+ __type(key, __u32);
+ __type(value, struct real_definition);
+} reals SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct lb_stats *value;
-} stats SEC(".maps") = {
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
- .max_entries = 515,
-};
+ __int(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+ __int(max_entries, 515);
+ __type(key, __u32);
+ __type(value, struct lb_stats);
+} stats SEC(".maps");
struct {
- __u32 type;
- __u32 max_entries;
- __u32 *key;
- struct ctl_value *value;
-} ctl_array SEC(".maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .max_entries = 16,
-};
+ __int(type, BPF_MAP_TYPE_ARRAY);
+ __int(max_entries, 16);
+ __type(key, __u32);
+ __type(value, struct ctl_value);
+} ctl_array SEC(".maps");
struct eth_hdr {
unsigned char eth_dest[6];
--
2.17.1
^ permalink raw reply related
* [PATCH v2 bpf-next 2/4] selftests/bpf: add __int and __type macro for BTF-defined maps
From: Andrii Nakryiko @ 2019-06-28 15:25 UTC (permalink / raw)
To: andrii.nakryiko, ast, daniel, bpf, netdev, songliubraving; +Cc: Andrii Nakryiko
In-Reply-To: <20190628152539.3014719-1-andriin@fb.com>
Add simple __int and __type macro that hide details of how type and
integer values are captured in BTF-defined maps.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
tools/testing/selftests/bpf/bpf_helpers.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
index 1a5b1accf091..aa5ddf58c088 100644
--- a/tools/testing/selftests/bpf/bpf_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_helpers.h
@@ -8,6 +8,9 @@
*/
#define SEC(NAME) __attribute__((section(NAME), used))
+#define __int(name, val) int (*name)[val]
+#define __type(name, val) val *name
+
/* helper macro to print out debug messages */
#define bpf_printk(fmt, ...) \
({ \
--
2.17.1
^ permalink raw reply related
* [PATCH v2 bpf-next 1/4] libbpf: capture value in BTF type info for BTF-defined map defs
From: Andrii Nakryiko @ 2019-06-28 15:25 UTC (permalink / raw)
To: andrii.nakryiko, ast, daniel, bpf, netdev, songliubraving; +Cc: Andrii Nakryiko
In-Reply-To: <20190628152539.3014719-1-andriin@fb.com>
Change BTF-defined map definitions to capture compile-time integer
values as part of BTF type definition, to avoid split of key/value type
information and actual type/size/flags initialization for maps.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
tools/lib/bpf/libbpf.c | 58 ++++++++++++++++++++----------------------
1 file changed, 28 insertions(+), 30 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 6e6ebef11ba3..9e099ecb2c2b 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1028,40 +1028,40 @@ static const struct btf_type *skip_mods_and_typedefs(const struct btf *btf,
}
}
-static bool get_map_field_int(const char *map_name,
- const struct btf *btf,
+/*
+ * Fetch integer attribute of BTF map definition. Such attributes are
+ * represented using a pointer to an array, in which dimensionality of array
+ * encodes specified integer value. E.g., int (*type)[BPF_MAP_TYPE_ARRAY];
+ * encodes `type => BPF_MAP_TYPE_ARRAY` key/value pair completely using BTF
+ * type definition, while using only sizeof(void *) space in ELF data section.
+ */
+static bool get_map_field_int(const char *map_name, const struct btf *btf,
const struct btf_type *def,
- const struct btf_member *m,
- const void *data, __u32 *res) {
+ const struct btf_member *m, __u32 *res) {
const struct btf_type *t = skip_mods_and_typedefs(btf, m->type);
const char *name = btf__name_by_offset(btf, m->name_off);
- __u32 int_info = *(const __u32 *)(const void *)(t + 1);
+ const struct btf_array *arr_info;
+ const struct btf_type *arr_t;
- if (BTF_INFO_KIND(t->info) != BTF_KIND_INT) {
- pr_warning("map '%s': attr '%s': expected INT, got %u.\n",
+ if (BTF_INFO_KIND(t->info) != BTF_KIND_PTR) {
+ pr_warning("map '%s': attr '%s': expected PTR, got %u.\n",
map_name, name, BTF_INFO_KIND(t->info));
return false;
}
- if (t->size != 4 || BTF_INT_BITS(int_info) != 32 ||
- BTF_INT_OFFSET(int_info)) {
- pr_warning("map '%s': attr '%s': expected 32-bit non-bitfield integer, "
- "got %u-byte (%d-bit) one with bit offset %d.\n",
- map_name, name, t->size, BTF_INT_BITS(int_info),
- BTF_INT_OFFSET(int_info));
- return false;
- }
- if (BTF_INFO_KFLAG(def->info) && BTF_MEMBER_BITFIELD_SIZE(m->offset)) {
- pr_warning("map '%s': attr '%s': bitfield is not supported.\n",
- map_name, name);
+
+ arr_t = btf__type_by_id(btf, t->type);
+ if (!arr_t) {
+ pr_warning("map '%s': attr '%s': type [%u] not found.\n",
+ map_name, name, t->type);
return false;
}
- if (m->offset % 32) {
- pr_warning("map '%s': attr '%s': unaligned fields are not supported.\n",
- map_name, name);
+ if (BTF_INFO_KIND(arr_t->info) != BTF_KIND_ARRAY) {
+ pr_warning("map '%s': attr '%s': expected ARRAY, got %u.\n",
+ map_name, name, BTF_INFO_KIND(arr_t->info));
return false;
}
-
- *res = *(const __u32 *)(data + m->offset / 8);
+ arr_info = (const void *)(arr_t + 1);
+ *res = arr_info->nelems;
return true;
}
@@ -1074,7 +1074,6 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
const struct btf_var_secinfo *vi;
const struct btf_var *var_extra;
const struct btf_member *m;
- const void *def_data;
const char *map_name;
struct bpf_map *map;
int vlen, i;
@@ -1131,7 +1130,6 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
pr_debug("map '%s': at sec_idx %d, offset %zu.\n",
map_name, map->sec_idx, map->sec_offset);
- def_data = data->d_buf + vi->offset;
vlen = BTF_INFO_VLEN(def->info);
m = (const void *)(def + 1);
for (i = 0; i < vlen; i++, m++) {
@@ -1144,19 +1142,19 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
}
if (strcmp(name, "type") == 0) {
if (!get_map_field_int(map_name, obj->btf, def, m,
- def_data, &map->def.type))
+ &map->def.type))
return -EINVAL;
pr_debug("map '%s': found type = %u.\n",
map_name, map->def.type);
} else if (strcmp(name, "max_entries") == 0) {
if (!get_map_field_int(map_name, obj->btf, def, m,
- def_data, &map->def.max_entries))
+ &map->def.max_entries))
return -EINVAL;
pr_debug("map '%s': found max_entries = %u.\n",
map_name, map->def.max_entries);
} else if (strcmp(name, "map_flags") == 0) {
if (!get_map_field_int(map_name, obj->btf, def, m,
- def_data, &map->def.map_flags))
+ &map->def.map_flags))
return -EINVAL;
pr_debug("map '%s': found map_flags = %u.\n",
map_name, map->def.map_flags);
@@ -1164,7 +1162,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
__u32 sz;
if (!get_map_field_int(map_name, obj->btf, def, m,
- def_data, &sz))
+ &sz))
return -EINVAL;
pr_debug("map '%s': found key_size = %u.\n",
map_name, sz);
@@ -1207,7 +1205,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
__u32 sz;
if (!get_map_field_int(map_name, obj->btf, def, m,
- def_data, &sz))
+ &sz))
return -EINVAL;
pr_debug("map '%s': found value_size = %u.\n",
map_name, sz);
--
2.17.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox