Re: [RFC PATCH 2/6] kvm: Add guest memory Pkey initialization

Dave Hansen <[email protected]>
Newsgroups gmane.comp.emulators.kvm.devel,gmane.comp.emulators.qemu
Message-ID <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.