Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: linked_list: add examples #345

Closed
ojeda opened this issue Jun 4, 2021 · 6 comments
Closed

rust: linked_list: add examples #345

ojeda opened this issue Jun 4, 2021 · 6 comments
Labels
• docs Related to `Documentation/rust/`, `samples/`, generated docs, doctests, typos... good first issue Good for newcomers

Comments

@ojeda
Copy link
Member

ojeda commented Jun 4, 2021

Add usage examples to rust/kernel/linked_list.rs's List.

@ojeda ojeda added • docs Related to `Documentation/rust/`, `samples/`, generated docs, doctests, typos... prio: normal good first issue Good for newcomers labels Jun 4, 2021
@ojeda
Copy link
Member Author

ojeda commented Jun 4, 2021

Pinging @wedsonaf in case he wants to comment (e.g. it may be too early to add usage examples if he wants to change the module, since it is a work in progress).

@wedsonaf
Copy link

wedsonaf commented Jun 8, 2021

I'm working on the rbtree submodule now and we may need to change the linked list for consistency. There are constraints in rbtree that we didn't have with lists but that dictate certain aspects of the solution. For example, links (prev/next) point to links themselves or the outer object? Here we had a choice, but we don't in rbtree as we're using the kernel implementation.

@devillove084
Copy link

@wedsonaf Is the linked list still inconsistent with the red-black tree to a certain extent as you said? Need to continue to improve? Is it necessary to use the kernel to implement a linked list? I hope to contribute to the community from this issue. Thank you very much.

JoseExposito added a commit to JoseExposito/linux that referenced this issue Dec 8, 2022
Illustrate how to use the linked list adding an example that uses all
methods the linked list currently supports.

Link: Rust-for-Linux/linux#345
Signed-off-by: José Expósito <[email protected]>
JoseExposito added a commit to JoseExposito/linux-rust that referenced this issue Dec 9, 2022
Illustrate how to use the linked list adding an example that uses all
methods the linked list currently supports.

Link: Rust-for-Linux#345
Signed-off-by: José Expósito <[email protected]>
JoseExposito added a commit to JoseExposito/linux-rust that referenced this issue Dec 19, 2022
Illustrate how to use the linked list adding an example that uses all
methods the linked list currently supports.

Link: Rust-for-Linux#345
Reviewed-by: David Gow <[email protected]>
Signed-off-by: José Expósito <[email protected]>
@RoKu1
Copy link

RoKu1 commented Jan 28, 2023

Is this still open to take ??

@ojeda
Copy link
Member Author

ojeda commented Feb 27, 2023

Is this still open to take ??

José submitted a PR as shown above (#937).

metaspace pushed a commit to metaspace/linux that referenced this issue Apr 16, 2024
A64_LDRSW() takes three registers: Xt, Xn, Xm as arguments and it loads
and sign extends the value at address Xn + Xm into register Xt.

Currently, the offset is being directly used in place of the tmp
register which has the offset already loaded by the last emitted
instruction.

This will cause JIT failures. The easiest way to reproduce this is to
test the following code through test_bpf module:

{
	"BPF_LDX_MEMSX | BPF_W",
	.u.insns_int = {
		BPF_LD_IMM64(R1, 0x00000000deadbeefULL),
		BPF_LD_IMM64(R2, 0xffffffffdeadbeefULL),
		BPF_STX_MEM(BPF_DW, R10, R1, -7),
		BPF_LDX_MEMSX(BPF_W, R0, R10, -7),
		BPF_JMP_REG(BPF_JNE, R0, R2, 1),
		BPF_ALU64_IMM(BPF_MOV, R0, 0),
		BPF_EXIT_INSN(),
	},
	INTERNAL,
	{ },
	{ { 0, 0 } },
	.stack_depth = 7,
},

We need to use the offset as -7 to trigger this code path, there could
be other valid ways to trigger this from proper BPF programs as well.

This code is rejected by the JIT because -7 is passed to A64_LDRSW() but
it expects a valid register (0 - 31).

 roott@pjy:~# modprobe test_bpf test_name="BPF_LDX_MEMSX | BPF_W"
 [11300.490371] test_bpf: test_bpf: set 'test_bpf' as the default test_suite.
 [11300.491750] test_bpf: Rust-for-Linux#345 BPF_LDX_MEMSX | BPF_W
 [11300.493179] aarch64_insn_encode_register: unknown register encoding -7
 [11300.494133] aarch64_insn_encode_register: unknown register encoding -7
 [11300.495292] FAIL to select_runtime err=-524
 [11300.496804] test_bpf: Summary: 0 PASSED, 1 FAILED, [0/0 JIT'ed]
 modprobe: ERROR: could not insert 'test_bpf': Invalid argument

Applying this patch fixes the issue.

 root@pjy:~# modprobe test_bpf test_name="BPF_LDX_MEMSX | BPF_W"
 [  292.837436] test_bpf: test_bpf: set 'test_bpf' as the default test_suite.
 [  292.839416] test_bpf: Rust-for-Linux#345 BPF_LDX_MEMSX | BPF_W jited:1 156 PASS
 [  292.844794] test_bpf: Summary: 1 PASSED, 0 FAILED, [1/1 JIT'ed]

Fixes: cc88f54 ("bpf, arm64: Support sign-extension load instructions")
Signed-off-by: Puranjay Mohan <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
ojeda pushed a commit that referenced this issue Jun 11, 2024
Add a test case to assert that the skb->pkt_type which was set from the BPF
program is retained from the netkit xmit side to the peer's device at tcx
ingress location.

  # ./vmtest.sh -- ./test_progs -t netkit
  [...]
  ./test_progs -t netkit
  [    1.140780] bpf_testmod: loading out-of-tree module taints kernel.
  [    1.141127] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
  [    1.284601] tsc: Refined TSC clocksource calibration: 3408.006 MHz
  [    1.286672] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x311fd9b189d, max_idle_ns: 440795225691 ns
  [    1.290384] clocksource: Switched to clocksource tsc
  #345     tc_netkit_basic:OK
  #346     tc_netkit_device:OK
  #347     tc_netkit_multi_links:OK
  #348     tc_netkit_multi_opts:OK
  #349     tc_netkit_neigh_links:OK
  #350     tc_netkit_pkt_type:OK
  Summary: 6/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Daniel Borkmann <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
@ojeda
Copy link
Member Author

ojeda commented Sep 1, 2024

Closing, since it does not apply anymore (it was from the out-of-tree days) -- though more examples in the upcoming doubly-linked list in mainline (currently in rust-next) would not hurt! :)

@ojeda ojeda closed this as completed Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
• docs Related to `Documentation/rust/`, `samples/`, generated docs, doctests, typos... good first issue Good for newcomers
Development

No branches or pull requests

4 participants