Bug 247327 - i386 linuxulator doesn't support more than one LDT
Summary: i386 linuxulator doesn't support more than one LDT
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-emulation (Nobody)
URL:
Keywords:
Depends on:
Blocks: 247219
  Show dependency treegraph
 
Reported: 2020-06-16 20:25 UTC by Edward Tomasz Napierala
Modified: 2024-02-10 07:14 UTC (History)
4 users (show)

See Also:


Attachments
comment cleanup (4.57 KB, patch)
2024-02-04 23:19 UTC, Alex S
no flags Details | Diff
comment cleanup (v2) (4.44 KB, patch)
2024-02-07 13:17 UTC, Alex S
no flags Details | Diff
comment cleanup (v3) (5.35 KB, patch)
2024-02-10 04:43 UTC, Alex S
no flags Details | Diff
set-thread-area-ubuntu.txt (2.35 KB, text/plain)
2024-02-10 04:47 UTC, Alex S
no flags Details
comment cleanup (v4) (5.35 KB, patch)
2024-02-10 05:45 UTC, Alex S
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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