mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Harald Hoyer <harald@profian.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH 1/1] feat(x86_64): use wrfsbase if AT_HWCAP2 allows usage
Date: Tue, 29 Mar 2022 11:54:53 -0400	[thread overview]
Message-ID: <20220329155453.GF7074@brightrain.aerifal.cx> (raw)
In-Reply-To: <20220329122416.925516-2-harald@profian.com>

On Tue, Mar 29, 2022 at 02:24:16PM +0200, Harald Hoyer wrote:
> If `AT_HWCAP2` has `HWCAP2_FSGSBASE` set, then instead of calling
> `arch_prctl()`, the `wrfsbase` instruction will be used.
> 
> This is helpful in SGX contexts, where inside the enclave no other
> mechanism is possible.

Thanks for including this motivation, since otherwise I don't think it
makes any sense to use this feature. BTW what happens with other
syscalls in such a context (at least set_tid_address is called
unconditionally), and how does the process communicate any information
or even exit?

> diff --git a/src/thread/x86_64/__set_thread_area.c b/src/thread/x86_64/__set_thread_area.c
> new file mode 100644
> index 00000000..dcc5d116
> --- /dev/null
> +++ b/src/thread/x86_64/__set_thread_area.c
> @@ -0,0 +1,14 @@
> +#include <libc.h>
> +#include <syscall.h>
> +#include <bits/hwcap.h>
> +
> +hidden int __set_thread_area(void *p)
> +{
> +	if (__hwcap2 & HWCAP2_FSGSBASE) {
> +		__asm__ ("wrfsbase %0" :: "r" (p) : "memory");
> +		return 0;
> +	}
> +
> +	// arch_prctl(SET_FS, arg)
> +	return syscall(__NR_arch_prctl, 0x1002, p);
> +}

I'm guessing this breaks build on anything but recent assembler
versions, no? If so, it should probably be written with a .byte
directive or something.

There's also a question of whether the existence of the hwcap flag is
intended to document a contract for the kernel to permit the process
to perform this operation, and a contract for the kernel to accept it
being set this way (rather than creating a possible inconsistency
between the kernel's idea of the process's %fs base and the actual %fs
base that's active. Is this documented somewhere on the kernel side?
If so then this should be okay, but this needs checking before it can
be merged.

Rich

  reply	other threads:[~2022-03-29 15:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29 12:24 [musl] [PATCH V3 0/1] " Harald Hoyer
2022-03-29 12:24 ` [musl] [PATCH 1/1] " Harald Hoyer
2022-03-29 15:54   ` Rich Felker [this message]
2022-03-30  6:57     ` Harald Hoyer
2022-03-30 12:32       ` Rich Felker
  -- strict thread matches above, loose matches on Subject: below --
2022-03-29 11:42 [musl] [PATCH] " Harald Hoyer
2022-03-29 11:54 ` [musl] [PATCH V2 0/1] " Harald Hoyer
2022-03-29 11:54   ` [musl] [PATCH 1/1] " Harald Hoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220329155453.GF7074@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=harald@profian.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).