On 8/18/26 13:44, Jacky Li wrote:
> +__attribute__((target("pku"))) void qemu_init_guest_memory_pkey(void)
> +{
> + if (guest_memory_pkey != -1) {
> + return;
> + }
> +
> + const char *enable_pkey = getenv("QEMU_ENABLE_PKEY_GUEST_MEMORY");
> + if (enable_pkey && strcmp(enable_pkey, "1") == 0) {
> + int pkey = pkey_alloc(0, 0);
> + if (pkey == -1) {
> + error_report("pkey_alloc failed for guest memory: %s",
> + strerror(errno));
> + } else {
> + guest_memory_pkey = pkey;
> + }
> + }
> +}
Is an environment variable a normal way of enabling qemu features? It
seems a bit unusual to me.
I would also guess that you might want some kind of an enabling mode
that lets users opportunistically enable pkeys when running on
pkey-enabled hardware, but not complain too loudly if they are unavailable.