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

cpu/stm32/periph_eth: fix typo in initialization code #18416

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

maribu
Copy link
Member

@maribu maribu commented Aug 8, 2022

Contribution description

A single character type resulted in way fewer TX descriptors being available than allocated. Not only resulted this in wasting memory, but also when more iolist chunks than descriptors are send, the

    assert(iolist_count(iolist) <= ETH_TX_DESCRIPTOR_COUNT);

does not trigger. As a result, old TX descriptors are being overwritten in this case.

Testing procedure

@fabian18 has a test that reliably triggers the bug. He should be able to confirm it is gone now. But actually, it should be pretty obvious from the code that this fixes a typo.

Issues/PRs references

None

@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch labels Aug 8, 2022
@maribu maribu requested a review from fabian18 August 8, 2022 12:37
@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms and removed Area: network Area: Networking labels Aug 8, 2022
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 8, 2022
@maribu
Copy link
Member Author

maribu commented Aug 8, 2022

Good catch!

took many hours of debugging over the course of a couple of days 😢

@chrysn: Since I need to ping you anyway due to this being backport material: Would this be a memory corruption that rust could catch? The corruption takes place in the DMA, not in the CPU, so this may be tricky to check.

@maribu
Copy link
Member Author

maribu commented Aug 8, 2022

The PR and commit description makes zero sense.

@maribu maribu force-pushed the cpu/stm32/periph/stm32_eth/bugfix branch from ddffbc8 to 0086283 Compare August 8, 2022 13:02
@maribu maribu changed the title cpu/stm32/periph_eth: fix horrible memory corruption bug cpu/stm32/periph_eth: fix type in initialization code Aug 8, 2022
@maribu
Copy link
Member Author

maribu commented Aug 8, 2022

@chrysn: Since I need to ping you anyway due to this being backport material: Would this be a memory corruption that rust could catch? The corruption takes place in the DMA, not in the CPU, so this may be tricky to check.

No, it doesn't. The typo is in the index, not in the variable name. I was jumping to incorrect conclusions here.

@fabian18 gnrc_ndp_opt_sl2a_build adds new pktsnip_t *s (or from the point of the netdev new io_list_t * elements). Hence, it results in overflowing the 8 possible chunks the STM32 can send per frame without triggering the assert() that is indented to for users to increase ETH_TX_DESCRIPTOR_COUNT so that more chunks can be send per frame.

@benpicco benpicco changed the title cpu/stm32/periph_eth: fix type in initialization code cpu/stm32/periph_eth: fix typo in initialization code Aug 8, 2022
A single character type resulted in way fewer TX descriptors being
available than allocated. Not only resulted this in wasting memory,
but also when more iolist chunks than descriptors are send, the

```C
    assert(iolist_count(iolist) <= ETH_TX_DESCRIPTOR_COUNT);
```

does not trigger. As a result, old TX descriptors are being overwritten
in this case.
@maribu maribu force-pushed the cpu/stm32/periph/stm32_eth/bugfix branch from 0086283 to 82fbe08 Compare August 8, 2022 13:13
@chrysn
Copy link
Member

chrysn commented Aug 8, 2022

On the Rust question: Depends on how it'd be implemented. Bounds checks are generally done in Rust (with provisions to optimize them out often), so if it were to write out of bounds, that would have resulted in a runtime error, or in this case likely even a build error. In the "wasting memory" case, if I understand it correctly, it wouldn't have caught anything, but there's also nothing worse happening than not using some memory.

Took me a while to see what's happening, but yes I agree this is backport material. As we need to have an RC3 anyway due to #18413, this is not creating much overhead. I'm taking the liberty to prioritize this in the build queue to enable a speedy backport. (edit: only moved #18403 as the others should be quick enough; #18396 turned out to be 200 and not 20 tests but was already some way in when I saw that)

@chrysn
Copy link
Member

chrysn commented Aug 8, 2022

No, it doesn't. The typo is in the index

Oh, I missed that part. If the error were in the name ... well, I think it's hard to compare, for in Rust that list might be initialized statically, so there'd be no danger of confusion. Such linked lists are generally not very idiomatic Rust, though, and if DMA requires them, it might be that one'd use and initialize them either through some local unsafe code (in which things like that could easily happen) or an abstraction for this kind of DMA lists.

@fabian18
Copy link
Contributor

fabian18 commented Aug 8, 2022

Hurray, thank you for spotting and fixing this!

@fabian18 fabian18 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Aug 8, 2022
@fabian18
Copy link
Contributor

fabian18 commented Aug 8, 2022

restarted Murdock, due to binary hashes mismatching with and without Kconfig

@benpicco benpicco merged commit 26faa88 into RIOT-OS:master Aug 9, 2022
@maribu maribu deleted the cpu/stm32/periph/stm32_eth/bugfix branch August 9, 2022 05:16
@maribu
Copy link
Member Author

maribu commented Aug 9, 2022

Thx :)

@maribu
Copy link
Member Author

maribu commented Aug 9, 2022

Backport provided in #18420

@maribu maribu added this to the Release 2022.10 milestone Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants