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

kernel: pipe: simple test fails for pipe write / read of 3 bytes #24642

Closed
cfriedt opened this issue Apr 23, 2020 · 2 comments
Closed

kernel: pipe: simple test fails for pipe write / read of 3 bytes #24642

cfriedt opened this issue Apr 23, 2020 · 2 comments
Assignees
Labels
area: Kernel bug The issue is a bug, or the PR is fixing a bug

Comments

@cfriedt
Copy link
Member

cfriedt commented Apr 23, 2020

Describe the bug
There is a page fault when a simple test is run using k_pipe_put() and k_pipe_get(). No combination of static or __aligned(8) on the buffers or k_pipe resolves the issue.

If it were a stack smash, then making the pipe or the buffers static would presumably the issue.

Note: if BOARD=qemu_cortex_m3, then it works fine.

Also worrisome - test still passes with BOARD=qemu_x86_64 in spite of the page fault 🤨

void test_pipe_simple_write_read(void)
{
	int res;
	size_t bytes_written = 0;
	size_t bytes_read = 0;

	u8_t buf[16];
	u8_t rxbuf[16];
	u8_t txbuf[16];
	struct k_pipe p;

	txbuf[0] = 'H';
	txbuf[1] = 'i';
	txbuf[2] = '!';
	txbuf[3] = '\0';

	k_pipe_init(&p, buf, sizeof(buf));

	res = k_pipe_put(&p, txbuf, 3, &bytes_written,
			 3 /* min_xfer */, K_FOREVER);
	zassert_equal(res, 0, "did not write entire message");
	zassert_equal(bytes_written, 3, "did not write entire message");

	res = k_pipe_get(&p, rxbuf, 3, &bytes_read,
			 3 /* min_xfer */, K_FOREVER);
	zassert_equal(res, 0, "did not read at least one byte");
	zassert_equal(bytes_read, 3, "did not read all bytes available");

	zassert_equal(rxbuf[0], 'H',
		"rxbuf[0] expected: 'H' actual: 0x%02x", rxbuf[0]);
	zassert_equal(rxbuf[1], 'i',
		"rxbuf[1] expected: 'i' actual: 0x%02x", rxbuf[1]);
	zassert_equal(rxbuf[2], '!',
		"rxbuf[2] expected: '!' actual: 0x%02x", rxbuf[2]);
}

To Reproduce
Steps to reproduce the behavior:

  1. west build -b qemu_x86_64 -p always tests/kernel/pipe/pipe
  2. ninja -C build run
  3. See error

Expected behavior
Expect tests to pass

Impact
blocking #24486
blocking implementation of #24366

Screenshots or console output

starting test - test_pipe_simple_write_read
E: Page fault at address 0x15cf2f (error code 0x4)
E: Linear address not present in page tables
E: PML4E: 0x0000000000134827 Writable, User, Execute Enabled
E: PDPTE: 0x0000000000135827 Writable, User, Execute Enabled
E:   PDE: 0x0000000000136827 Writable, User, Execute Enabled
E:   PTE: Non-present
E: RAX: 0x00000000000000cf RBX: 0x000000000013cf58 RCX: 0x0000000000000000 RDX: 0x0000000000000010
E: RSI: 0x000000000013cf28 RDI: 0x000000000013cf58 RBP: 0x0000000000000000 RSP: 0x000000000013cef0
E:  R8: 0x000000000013cff0  R9: 0x000000000013b000 R10: 0x0000000000000000 R11: 0x0000000000000202
E: R12: 0x0000000000000000 R13: 0x0000000000000000 R14: 0x0000000000000000 R15: 0x0000000000000000
E: RSP: 0x000000000013cef0 RFLAGS: 0x0000000000000206 CS: 0x003b CR3: 0x0000000000116000
E: RIP: 0x000000000010f1c3
E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
E: Current thread: 0x00000000001283c0 (unknown)
Caught system error -- reason 0
PASS - test_pipe_simple_write_read

Environment (please complete the following information):

  • OS: Linux (Debian 10.2)
  • Toolchain: cross-compile (aarch64-linux-gnu -> x86_64-linux-gnu)
  • Toolchain: cross-compile (x86_64-linux-gnu -> x86_64-linux-gnu)
  • Commit SHA or Version used: 8d984b3

Additional context
detected in #24486

@cfriedt
Copy link
Member Author

cfriedt commented Apr 23, 2020

Aha!
So it seems that k_pipes and other objects for sure cannot be stack-allocated. I looked through some more of the documentation and saw k_object_alloc() and friends.

The example test should have been in tests/kernel/pipe/pipe_api rather than tests/kernel/pipe/pipe.

I'll need to adjust the code in my implementation of #24366 to use k_object_alloc() before I call k_pipe_init(). The test in #24486 can simply use the statically-defined / initialized test_pipe.

@cfriedt
Copy link
Member Author

cfriedt commented Apr 23, 2020

@carlescufi - feel free to assign to me and close, or I can close it later.

@cfriedt cfriedt closed this as completed Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Kernel bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

3 participants