All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: guang.zeng@intel.com, jing2.liu@intel.com, kevin.tian@intel.com,
	seanjc@google.com, tglx@linutronix.de, wei.w.wang@intel.com,
	yang.zhong@intel.com
Subject: Re: [PATCH v6 19/21] kvm: selftests: Add support for KVM_CAP_XSAVE2
Date: Mon, 17 Jan 2022 17:51:14 +0100	[thread overview]
Message-ID: <d47dc156-405f-77c5-787a-99073053a06b@linux.ibm.com> (raw)
In-Reply-To: <20220107185512.25321-20-pbonzini@redhat.com>

On 1/7/22 19:55, Paolo Bonzini wrote:
> From: Wei Wang <wei.w.wang@intel.com>
> 
> When KVM_CAP_XSAVE2 is supported, userspace is expected to allocate
> buffer for KVM_GET_XSAVE2 and KVM_SET_XSAVE using the size returned
> by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2).
> 
> Signed-off-by: Wei Wang <wei.w.wang@intel.com>
> Signed-off-by: Guang Zeng <guang.zeng@intel.com>
> Signed-off-by: Jing Liu <jing2.liu@intel.com>
> Signed-off-by: Yang Zhong <yang.zhong@intel.com>
> Message-Id: <20220105123532.12586-20-yang.zhong@intel.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tools/arch/x86/include/uapi/asm/kvm.h         | 16 ++++-
>  tools/include/uapi/linux/kvm.h                |  3 +
>  .../selftests/kvm/include/kvm_util_base.h     |  2 +
>  .../selftests/kvm/include/x86_64/processor.h  | 10 +++
>  tools/testing/selftests/kvm/lib/kvm_util.c    | 32 +++++++++
>  .../selftests/kvm/lib/x86_64/processor.c      | 67 ++++++++++++++++++-
>  .../testing/selftests/kvm/x86_64/evmcs_test.c |  2 +-
>  tools/testing/selftests/kvm/x86_64/smm_test.c |  2 +-
>  .../testing/selftests/kvm/x86_64/state_test.c |  2 +-
>  .../kvm/x86_64/vmx_preemption_timer_test.c    |  2 +-
>  10 files changed, 130 insertions(+), 8 deletions(-)
> 

[...]

> diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h
> index 1e5ab6a92848..66775de26952 100644
> --- a/tools/testing/selftests/kvm/include/kvm_util_base.h
> +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h
> @@ -103,6 +103,7 @@ extern const struct vm_guest_mode_params vm_guest_mode_params[];
>  int open_path_or_exit(const char *path, int flags);
>  int open_kvm_dev_path_or_exit(void);
>  int kvm_check_cap(long cap);
> +int vm_check_cap(struct kvm_vm *vm, long cap);
>  int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap);
>  int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id,
>  		    struct kvm_enable_cap *cap);
> @@ -344,6 +345,7 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
>   *   guest_code - The vCPU's entry point
>   */
>  void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code);
> +void vm_xsave_req_perm(void);
> 
>  bool vm_is_unrestricted_guest(struct kvm_vm *vm);
> 

[...]

> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index ecc53d108ad8..4a645dc77f34 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -85,6 +85,33 @@ int kvm_check_cap(long cap)
>  	return ret;
>  }
> 
> +/* VM Check Capability
> + *
> + * Input Args:
> + *   vm - Virtual Machine
> + *   cap - Capability
> + *
> + * Output Args: None
> + *
> + * Return:
> + *   On success, the Value corresponding to the capability (KVM_CAP_*)
> + *   specified by the value of cap.  On failure a TEST_ASSERT failure
> + *   is produced.
> + *
> + * Looks up and returns the value corresponding to the capability
> + * (KVM_CAP_*) given by cap.
> + */
> +int vm_check_cap(struct kvm_vm *vm, long cap)
> +{
> +	int ret;
> +
> +	ret = ioctl(vm->fd, KVM_CHECK_EXTENSION, cap);
> +	TEST_ASSERT(ret >= 0, "KVM_CHECK_EXTENSION VM IOCTL failed,\n"
> +		"  rc: %i errno: %i", ret, errno);
> +
> +	return ret;
> +}
> +
>  /* VM Enable Capability
>   *
>   * Input Args:
> @@ -366,6 +393,11 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
>  	struct kvm_vm *vm;
>  	int i;
> 
> +	/*
> +	 * Permission needs to be requested before KVM_SET_CPUID2.
> +	 */
> +	vm_xsave_req_perm();
> +

Since

79e06c4c4950 (Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm)

on s390x I'm getting:

/usr/bin/ld: tools/testing/selftests/kvm/libkvm.a(kvm_util.o): in function `vm_create_with_vcpus':
tools/testing/selftests/kvm/lib/kvm_util.c:399: undefined reference to `vm_xsave_req_perm'
collect2: error: ld returned 1 exit status
make: *** [../lib.mk:146: tools/testing/selftests/kvm/s390x/memop] Error 1

Looks like it only exists for x86.
v2 had a comment about unconditional enablement:
https://lore.kernel.org/kvm/e20f590b-b9d9-237d-3b9c-77dd82a24b40@redhat.com/

Thanks for having a look.

>  	/* Force slot0 memory size not small than DEFAULT_GUEST_PHY_PAGES */
>  	if (slot0_mem_pages < DEFAULT_GUEST_PHY_PAGES)
>  		slot0_mem_pages = DEFAULT_GUEST_PHY_PAGES;
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> index eef7b34756d5..f19d6d201977 100644
> --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> @@ -650,6 +650,45 @@ static void vcpu_setup(struct kvm_vm *vm, int vcpuid)
>  	vcpu_sregs_set(vm, vcpuid, &sregs);
>  }
> 
> +#define CPUID_XFD_BIT (1 << 4)
> +static bool is_xfd_supported(void)
> +{
> +	int eax, ebx, ecx, edx;
> +	const int leaf = 0xd, subleaf = 0x1;
> +
> +	__asm__ __volatile__(
> +		"cpuid"
> +		: /* output */ "=a"(eax), "=b"(ebx),
> +		  "=c"(ecx), "=d"(edx)
> +		: /* input */ "0"(leaf), "2"(subleaf));
> +
> +	return !!(eax & CPUID_XFD_BIT);
> +}
> +
> +void vm_xsave_req_perm(void)
> +{
> +	unsigned long bitmask;
> +	long rc;
> +
> +	if (!is_xfd_supported())
> +		return;
> +
> +	rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM,
> +		     XSTATE_XTILE_DATA_BIT);
> +	/*
> +	 * The older kernel version(<5.15) can't support
> +	 * ARCH_REQ_XCOMP_GUEST_PERM and directly return.
> +	 */
> +	if (rc)
> +		return;
> +
> +	rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &bitmask);
> +	TEST_ASSERT(rc == 0, "prctl(ARCH_GET_XCOMP_GUEST_PERM) error: %ld", rc);
> +	TEST_ASSERT(bitmask & XFEATURE_XTILE_MASK,
> +		    "prctl(ARCH_REQ_XCOMP_GUEST_PERM) failure bitmask=0x%lx",
> +		    bitmask);
> +}
> +

[...]

  reply	other threads:[~2022-01-17 16:51 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07 18:54 [PATCH v6 00/21] AMX support for KVM Paolo Bonzini
2022-01-07 18:54 ` [PATCH v6 01/21] x86/fpu: Extend fpu_xstate_prctl() with guest permissions Paolo Bonzini
2022-01-07 18:54 ` [PATCH v6 02/21] x86/fpu: Prepare guest FPU for dynamically enabled FPU features Paolo Bonzini
2022-01-07 18:54 ` [PATCH v6 03/21] kvm: x86: Fix xstate_required_size() to follow XSTATE alignment rule Paolo Bonzini
2022-01-07 18:54 ` [PATCH v6 04/21] kvm: x86: Exclude unpermitted xfeatures at KVM_GET_SUPPORTED_CPUID Paolo Bonzini
2022-01-23  6:22   ` Like Xu
2022-01-24  7:18     ` Tian, Kevin
2022-01-07 18:54 ` [PATCH v6 05/21] x86/fpu: Make XFD initialization in __fpstate_reset() a function argument Paolo Bonzini
2022-01-07 19:43   ` Borislav Petkov
2022-01-10  5:15     ` Tian, Kevin
2022-01-10  8:52       ` Borislav Petkov
2022-01-10 14:18         ` Paolo Bonzini
2022-01-10 15:25           ` Borislav Petkov
2022-01-10 15:55             ` Paolo Bonzini
2022-01-10 18:18               ` Borislav Petkov
2022-01-11  1:45                 ` Tian, Kevin
2022-01-07 18:54 ` [PATCH v6 06/21] x86/fpu: Add guest support to xfd_enable_feature() Paolo Bonzini
2022-01-07 18:54 ` [PATCH v6 07/21] x86/fpu: Provide fpu_enable_guest_xfd_features() for KVM Paolo Bonzini
2022-01-10  5:25   ` Tian, Kevin
2022-01-07 18:54 ` [PATCH v6 08/21] kvm: x86: Enable dynamic xfeatures at KVM_SET_CPUID2 Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 09/21] x86/fpu: Provide fpu_update_guest_xfd() for IA32_XFD emulation Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 10/21] kvm: x86: Add emulation for IA32_XFD Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 11/21] x86/fpu: Prepare xfd_err in struct fpu_guest Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 12/21] kvm: x86: Intercept #NM for saving IA32_XFD_ERR Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 13/21] kvm: x86: Emulate IA32_XFD_ERR for guest Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 14/21] kvm: x86: Disable RDMSR interception of IA32_XFD_ERR Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 15/21] kvm: x86: Add XCR0 support for Intel AMX Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 16/21] kvm: x86: Add CPUID " Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 17/21] x86/fpu: Add uabi_size to guest_fpu Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 18/21] kvm: x86: Add support for getting/setting expanded xstate buffer Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 19/21] kvm: selftests: Add support for KVM_CAP_XSAVE2 Paolo Bonzini
2022-01-17 16:51   ` Janis Schoetterl-Glausch [this message]
2022-01-18  2:06     ` Wang, Wei W
2022-01-07 18:55 ` [PATCH v6 20/21] x86/fpu: Provide fpu_sync_guest_vmexit_xfd_state() Paolo Bonzini
2022-01-07 18:55 ` [PATCH v6 21/21] kvm: x86: Disable interception for IA32_XFD on demand Paolo Bonzini

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=d47dc156-405f-77c5-787a-99073053a06b@linux.ibm.com \
    --to=scgl@linux.ibm.com \
    --cc=guang.zeng@intel.com \
    --cc=jing2.liu@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=wei.w.wang@intel.com \
    --cc=yang.zhong@intel.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.