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

lib/posix-process: Fix off-by-one error in tid check #1377

Conversation

michpappas
Copy link
Member

@michpappas michpappas commented Apr 4, 2024

Prerequisite checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.uk on your commit series before opening this PR;
  • Updated relevant documentation.

Base target

  • Architecture(s): [N/A]
  • Platform(s): [N/A]
  • Application(s): [N/A]

Additional configuration

Description of changes

Fix an off-by-one error in tid2pthread() that returns failure when the passed tid is the maximum allowed value.

Show error message when CONFIG_LIBPOSIX_PROCESS_MAX_PID is reached.

Fix an off-by-one error in tid2pthread() that returns failure when
the passed tid is the maximum allowed value.

Show error message when CONFIG_LIBPOSIX_PROCESS_MAX_PID is
reached.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
@michpappas michpappas requested a review from a team as a code owner April 4, 2024 14:17
@github-actions github-actions bot added area/lib Internal Unikraft Microlibrary lang/c Issues or PRs to do with C/C++ lib/posix-process Information about system parameters labels Apr 4, 2024
@razvand razvand self-assigned this Apr 28, 2024
@razvand razvand removed the request for review from a team April 28, 2024 05:41
@razvand razvand added this to the v0.17.0 (Calypso) milestone Apr 28, 2024
Copy link
Contributor

@DeliaPavel DeliaPavel left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Reviewed-by: Delia Pavel delia_maria.pavel@stud.acs.upb.ro

Copy link
Contributor

@RaduNichita RaduNichita left a comment

Choose a reason for hiding this comment

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

It looks good to me, I left some nit. I am not sure if we should also include this one in the current PR or create another one.

@@ -110,6 +110,8 @@ static inline pid_t find_free_tid(void)
}
if (found == TIDMAP_SIZE) {
/* no free PID */
uk_pr_err("Could not allocate TID: Out of TIDs (configured max: %d)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

Not much related, but I think we may move the second if that is checking if (found == TIDMAP_SIZE) inside the first one.

If we have found something with the first search, there is no need to check the condition if (found == TIDMAP_SIZE) two times.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @RaduNichita, yes, I added that message here while preserving the existing logic, but I think you're right. git blame shows that this pattern originates since inception of process.c, and until a1c73be both conditionals checked against CONFIG_LIBPOSIX_PROCESS_MAX_PID. Before making any changes I would like to check on the reasoning with @skuenzer who is the original author, but given that he's away this week I would prefer if we considered that change on a follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree.

@razvand razvand requested a review from RaduNichita May 29, 2024 08:00
Copy link
Contributor

@RaduNichita RaduNichita left a comment

Choose a reason for hiding this comment

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

Let's merge this and discuss with @skuenzer based on our discussion. Thanks @michpappas.

Reviewed-by: Radu Nichita radunichita99@gmail.com

Copy link
Contributor

@razvand razvand left a comment

Choose a reason for hiding this comment

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

Approved-by: Razvan Deaconescu razvand@unikraft.io

@razvand razvand added the merge Label to trigger merge action label May 29, 2024
@unikraft-bot unikraft-bot changed the base branch from staging to staging-1377 May 29, 2024 20:57
@unikraft-bot unikraft-bot merged commit e8bedd8 into unikraft:staging-1377 May 29, 2024
13 checks passed
unikraft-bot pushed a commit that referenced this pull request May 29, 2024
Fix an off-by-one error in tid2pthread() that returns failure when
the passed tid is the maximum allowed value.

Show error message when CONFIG_LIBPOSIX_PROCESS_MAX_PID is
reached.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1377
@unikraft-bot unikraft-bot added ci/merged Merged by CI and removed merge Label to trigger merge action labels May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lib Internal Unikraft Microlibrary ci/merged Merged by CI lang/c Issues or PRs to do with C/C++ lib/posix-process Information about system parameters
Projects
Status: Done!
Development

Successfully merging this pull request may close these issues.

5 participants