Skip to content

Conversation

ricardobranco777
Copy link

@ricardobranco777 ricardobranco777 commented Feb 16, 2025

Adapt existing code in compat_linux for close_range and make it use the new native system call.

The existing test code for closefrom(3) was adapted and extended for close_range(2).

The manpage was adapted from FreeBSD using the Linux names for the parameters:
https://man.freebsd.org/cgi/man.cgi?query=close_range&sektion=2&n=1

Fixes kern/59081

CLOSE_RANGE_UNSHARE was removed as it doesn't make sense on NetBSD which lacks unshare(2). From the Linux documentation:

       CLOSE_RANGE_UNSHARE is conceptually equivalent to
           unshare(CLONE_FILES);
           close_range(first, last, 0);

@ricardobranco777 ricardobranco777 force-pushed the close_range branch 7 times, most recently from 673e298 to 4b530cb Compare February 16, 2025 21:37
@zoulasc
Copy link
Contributor

zoulasc commented Mar 25, 2025

I think UNSHARE was implemented before and it was the same way sharing is done and undone in the clone system call. I added it back. I patched, I am doing a build now and will fix the sets.

@ricardobranco777 ricardobranco777 force-pushed the close_range branch 3 times, most recently from 5898156 to 5774026 Compare July 19, 2025 08:49
netbsd-srcmastr pushed a commit that referenced this pull request Oct 1, 2025
	sys/arch/i386/i386/locore.S: revision 1.202
	sys/arch/i386/i386/locore.S: revision 1.203
	sys/arch/i386/i386/locore.S: revision 1.204
	sys/arch/amd64/amd64/locore.S: revision 1.231
	sys/arch/amd64/amd64/locore.S: revision 1.232
	sys/arch/amd64/amd64/locore.S: revision 1.233
	sys/arch/xen/xen/hypervisor.c: revision 1.100

Our PVH bootstrap code assumed that the hvm_start_info structure provided
by Xen is just after the end of the symbol case. With Xen 4.20 it's not
always the case, so:
- get the symbol table size from the first byte of the symbol table area
  provided by Xen. As we don't know if there is a symbol table or not,
  do a minimal sanity check on the size.
- if the hvm_start_info structure is not in the page after kernel_end or
  esym, copy it there (this was already done in the genpvh case). While
  there, if we copy we can easily compute the size and not assume it all fits
  in one page.

With this, a NetBSD PVH dom0 can boot on Xen 4.20

Fix some issues with symbol table detection on Xen PVH:
- the stack grows down so the last pushed value is at 0(%esp), not -4(%esp).
  Pointed out by Joachim Kuebart.
- 0x3fffffff is 1GB-1, not 1MB-1. Test the symtab size against 16MB
  (amd64 generic symbol table is just above 1MB these days)
- I got confused by cmp's arguments order between intel and gas syntax,
  so the tests did the opposite of intended and the symtab was always
  considered valid.
While there use unsigned conditions.

Should fix booting in PVH mode with netbsd-INSTALL (which is stripped)

Fix various typos, mainly in comments.
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