Bug 247327

Summary: i386 linuxulator doesn't support more than one LDT
Product: Base System Reporter: Edward Tomasz Napierala <trasz>
Component: kernAssignee: freebsd-emulation (Nobody) <emulation>
Status: New ---    
Severity: Affects Only Me CC: arrowd, emaste, iwtcex, kib
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   
Bug Depends on:    
Bug Blocks: 247219    
Attachments:
Description Flags
comment cleanup
none
comment cleanup (v2)
none
comment cleanup (v3)
none
set-thread-area-ubuntu.txt
none
comment cleanup (v4) none

Description Edward Tomasz Napierala freebsd_committer freebsd_triage 2020-06-16 20:25:46 UTC
Alex S reported that Proton (which is Wine distribution integrated with Steam) depends on functionality mentioned at https://github.com/freebsd/freebsd/blob/8989bc4581101acb0dda31d9c4f9b6ec4732c5cf/sys/i386/linux/linux_machdep.c#L582:

/*
 * Semantics of Linux version: every thread in the system has array of
 * 3 tls descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown. This
 * syscall loads one of the selected tls decriptors with a value and
 * also loads GDT descriptors 6, 7 and 8 with the content of the
 * per-thread descriptors.
 *
 * Semantics of FreeBSD version: I think we can ignore that Linux has 3
 * per-thread descriptors and use just the 1st one. The tls_array[]
 * is used only in set/get-thread_area() syscalls and for loading the
 * GDT descriptors. In FreeBSD we use just one GDT descriptor for TLS
 * so we will load just one.
 *
 * XXX: this doesn't work when a user space process tries to use more
 * than 1 TLS segment. Comment in the Linux sources says wine might do
 * this.
 */
Comment 1 Alex S 2024-02-04 23:19:19 UTC
Created attachment 248191 [details]
comment cleanup

I should probably use Phab instead, but, just in case I forget about it, here is a good-enough-for-me patch.
Comment 2 Alex S 2024-02-07 13:17:20 UTC
Created attachment 248228 [details]
comment cleanup (v2)

Removed TODO. I'd say linux_set_cloned_tls (in linux32) could use a bit of cleanup, but there is no conflict with this patch.
Comment 3 Alex S 2024-02-10 04:43:36 UTC
Created attachment 248297 [details]
comment cleanup (v3)

The slot counter was adjusted not to reset on forking.
Comment 4 Alex S 2024-02-10 04:47:25 UTC
Created attachment 248298 [details]
set-thread-area-ubuntu.txt

My actual test case (for people wondering wtf the patch is supposed to improve).
Comment 5 Alex S 2024-02-10 05:45:10 UTC
Created attachment 248299 [details]
comment cleanup (v4)

Make the patch actually apply to current (main?).
Comment 6 Konstantin Belousov freebsd_committer freebsd_triage 2024-02-10 07:14:12 UTC
https://reviews.freebsd.org/D43814