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

Fix usr hrt #866

Merged
merged 4 commits into from
Jan 10, 2025
Merged

Fix usr hrt #866

merged 4 commits into from
Jan 10, 2025

Conversation

jlaitine
Copy link

No description provided.

/* Remove potential inflight entry as well */
sq_rem(&e->list_item, &callout_inflight);
kmm_free(e);
Copy link

Choose a reason for hiding this comment

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

Is there some reason this was removed? It's not immediately obvious.

Copy link
Author

@jlaitine jlaitine Jan 10, 2025

Choose a reason for hiding this comment

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

I was thinking that it is not safe to do that inside of the loop, where the next iteration pointer is taken from the e which was just deleted (even though inside spinlock and assuming that "free" doesn't alter the contents of that memory).

The deletion should be unnecessary anyways, since it should not grow the maximum used kernel heap; the next allocation is anyhow taken from the freelist

Copy link
Author

Choose a reason for hiding this comment

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

I can, of course, do the deletion as well in safe manner if you like!

Copy link
Author

Choose a reason for hiding this comment

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

pushed a suggestion on top

Copy link

Choose a reason for hiding this comment

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

It is fine to me to not free the entries at all, was just wondering why the line was removed

struct usr_hrt_call *e;
irqstate_t flags;

flags = spin_lock_irqsave_wo_note(&g_hrt_ioctl_lock);

while ((e = (void *)sq_remfirst(&callout_queue))) {
sq_for_every(&callout_queue, queued) {
kmm_free(deleted);
Copy link

Choose a reason for hiding this comment

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

Should this be:

if (deleted) {
kmm_free(deleted);
deleted = NULL;
}

Copy link
Author

Choose a reason for hiding this comment

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

could be... freeing a NULLptr should be ok with every free function though, so it is redundant to add if

Copy link

@pussuw pussuw Jan 10, 2025

Choose a reason for hiding this comment

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

I think kmm_free has some kind of debugassert i.e. not posix compliant. Fine by me either way.

jlaitine and others added 3 commits January 10, 2025 17:56
1. When moving the list item to "inflight" queue, it must be also removed from "callout" queue. Otherwise the "callout" queue is corrupt

2. In HRT_CANCEL, the items need to be removed also from the inflight queue, in case the HRT has been triggered already, but the client is not waiting for the event

3. HRT_UNREGISTER can't just clear the whole callout_queue, since it is a kernel list shared between processes

Signed-off-by: Jukka Laitinen <[email protected]>
Unsubscribe & unadvertise topics which were subscribed/advertised in the constructor

Signed-off-by: Jukka Laitinen <[email protected]>
The interrupt handler needs to take the spinlock as well, as another
CPU can be futzing around with the lists when another CPU takes the
HRT trap.
@jlaitine
Copy link
Author

added checking of "deleted" ptr acc. to the suggestion and for clarity, and squashed the commits. should be okayish now?

@jlaitine jlaitine merged commit f6a190d into main Jan 10, 2025
27 checks passed
@jlaitine jlaitine deleted the fix_usr_hrt branch January 10, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants