[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8c57204e-385e-1f54-cb15-760e174d122e@redhat.com>
Date: Tue, 6 Jul 2021 16:03:09 +0200
From: Paolo Bonzini <pbonzini@...hat.com>
To: isaku.yamahata@...el.com, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
"H . Peter Anvin" <hpa@...or.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>, erdemaktas@...gle.com,
Connor Kuehl <ckuehl@...hat.com>,
Sean Christopherson <seanjc@...gle.com>, x86@...nel.org,
linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
Brijesh Singh <brijesh.singh@....com>
Cc: isaku.yamahata@...il.com,
Sean Christopherson <sean.j.christopherson@...el.com>
Subject: Re: [RFC PATCH v2 28/69] KVM: Add per-VM flag to mark read-only
memory as unsupported
On 03/07/21 00:04, isaku.yamahata@...el.com wrote:
> From: Isaku Yamahata <isaku.yamahata@...el.com>
>
> Add a flag for TDX to flag RO memory as unsupported and propagate it to
> KVM_MEM_READONLY to allow reporting RO memory as unsupported on a per-VM
> basis. TDX1 doesn't expose permission bits to the VMM in the SEPT
> tables, i.e. doesn't support read-only private memory.
>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@...el.com>
> Co-developed-by: Sean Christopherson <sean.j.christopherson@...el.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@...el.com>
> ---
> arch/x86/kvm/x86.c | 4 +++-
> include/linux/kvm_host.h | 4 ++++
> virt/kvm/kvm_main.c | 8 +++++---
> 3 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index cd9407982366..87212d7563ae 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3897,7 +3897,6 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
> case KVM_CAP_ASYNC_PF_INT:
> case KVM_CAP_GET_TSC_KHZ:
> case KVM_CAP_KVMCLOCK_CTRL:
> - case KVM_CAP_READONLY_MEM:
> case KVM_CAP_HYPERV_TIME:
> case KVM_CAP_IOAPIC_POLARITY_IGNORED:
> case KVM_CAP_TSC_DEADLINE_TIMER:
> @@ -4009,6 +4008,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
> if (static_call(kvm_x86_is_vm_type_supported)(KVM_X86_TDX_VM))
> r |= BIT(KVM_X86_TDX_VM);
> break;
> + case KVM_CAP_READONLY_MEM:
> + r = kvm && kvm->readonly_mem_unsupported ? 0 : 1;
> + break;
> default:
> break;
> }
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index ddd4d0f68cdf..7ee7104b4b59 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -597,6 +597,10 @@ struct kvm {
> unsigned int max_halt_poll_ns;
> u32 dirty_ring_size;
>
> +#ifdef __KVM_HAVE_READONLY_MEM
> + bool readonly_mem_unsupported;
> +#endif
> +
> bool vm_bugged;
> };
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 52d40ea75749..63d0c2833913 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1258,12 +1258,14 @@ static void update_memslots(struct kvm_memslots *slots,
> }
> }
>
> -static int check_memory_region_flags(const struct kvm_userspace_memory_region *mem)
> +static int check_memory_region_flags(struct kvm *kvm,
> + const struct kvm_userspace_memory_region *mem)
> {
> u32 valid_flags = KVM_MEM_LOG_DIRTY_PAGES;
>
> #ifdef __KVM_HAVE_READONLY_MEM
> - valid_flags |= KVM_MEM_READONLY;
> + if (!kvm->readonly_mem_unsupported)
> + valid_flags |= KVM_MEM_READONLY;
> #endif
>
> if (mem->flags & ~valid_flags)
> @@ -1436,7 +1438,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
> int as_id, id;
> int r;
>
> - r = check_memory_region_flags(mem);
> + r = check_memory_region_flags(kvm, mem);
> if (r)
> return r;
>
>
For all these flags, which of these limitations will be common to SEV-ES
and SEV-SNP (ExtINT injection, MCE injection, changing TSC, read-only
memory, dirty logging)? Would it make sense to use vm_type instead of
all of them? I guess this also guides the choice of whether to use a
single vm-type for TDX and SEV-SNP or two. Probably two is better, and
there can be static inline bool functions to derive the support flags
from the vm-type.
Paolo
Powered by blists - more mailing lists