Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3607868ybl; Mon, 3 Feb 2020 03:24:57 -0800 (PST) X-Google-Smtp-Source: APXvYqz6g2fYeEp98Y+Ry1uaYf+JCkOXvYuboSQxHzzSmkzpbY4UgNz4Vh89Nws/WgDP+Zj2SEvz X-Received: by 2002:a05:6830:612:: with SMTP id w18mr17703248oti.160.1580729097341; Mon, 03 Feb 2020 03:24:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580729097; cv=none; d=google.com; s=arc-20160816; b=VIA5Jyc9uc/PxlAofa8nFzNIBLCCgEhZaCDnkDBe+l6UTrSNtQ6R7eQv7qHGx4SU1A oM/dHqkp+gpewxFKDRXZaMoprxsiPy1EOMu8+kQ6uWRtsT0KXFzWuNBvDGMd7LGJCNhm WYsRlWnsf7pTdfUah38Q8VI4TRv/oyvyyp95qM291ucYBEdDkebkD3IcNFdA3cHTf16T oXbUfEJcuc+k96rIpEGJIgKsBgWcSQ6fzUxSJ2QYb5vRCxMvlID8gyN+xA0Kqk6iTyO6 PqMclGnwzb0wv2G/D0ObkvWa2wfQ3OpuQ+EkFdss49Tz13QGASAYO3K28YxS1EJjwB5M Dd3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=B1NfG/wEwzb4qfvuHz92YFVlPl1qDYt7tfMRCttPhDs=; b=KH/heDHKDD9wtGIYPZUjCwKsGa97X150PMK4RuiavvhwWRRd5JxIkvRe/vvwHA1UX7 eeOPv3tgn1K9Ec4x0LkRPQ0h8Lo8y00UkhR4zKbiFWk+3MRLA3oPA7QXBfOPrc6XcA4n GXgYJ31tYLDJcqprihDLPbf5h3Y2PsXQL6CunzIJntM9MDMOJUzbX+saqF9DB5B6+W/6 mOXIu0+AX03rdtjseVK2I8eZIm9BCvFTOK77DP4Th8yQMVFhCDVKE9PmVab7R5wg4jgY IMXziYCNWeRA4bhskXFa+EMuTpk9X4fnId8LHUHAcGEg619xsXKf0Yb7tVUvgZeItBKc TINA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="jTZr/216"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si8356226oih.141.2020.02.03.03.24.45; Mon, 03 Feb 2020 03:24:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="jTZr/216"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727404AbgBCJ7w (ORCPT + 99 others); Mon, 3 Feb 2020 04:59:52 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:45242 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727337AbgBCJ7w (ORCPT ); Mon, 3 Feb 2020 04:59:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580723991; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B1NfG/wEwzb4qfvuHz92YFVlPl1qDYt7tfMRCttPhDs=; b=jTZr/216G/OvQ9NRmHVP3ss+2cLTmSZ3yMCLAZsFnpapvD6f/W3ylsULnMRUnLVh8lMMKz 94TRatWqGM424zKV1oB/3GJ5QY8MF3vcn4UeANAmNCGlX1S5oWYSDKF+2RBgm5pjmamHX2 /NuWfPT7C4CtFztfYuU4QG9eDtZewJI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-83-aKRMZUjMNWmebPHpb5B_3w-1; Mon, 03 Feb 2020 04:59:50 -0500 X-MC-Unique: aKRMZUjMNWmebPHpb5B_3w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 48B67800D41; Mon, 3 Feb 2020 09:59:49 +0000 (UTC) Received: from [10.36.116.37] (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D55FE7792E; Mon, 3 Feb 2020 09:59:45 +0000 (UTC) Subject: Re: [PATCH v2 2/2] selftests: KVM: SVM: Add vmcall test To: Vitaly Kuznetsov Cc: thuth@redhat.com, drjones@redhat.com, wei.huang2@amd.com, eric.auger.pro@gmail.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com References: <20200203090851.19938-1-eric.auger@redhat.com> <20200203090851.19938-3-eric.auger@redhat.com> <875zgoovhx.fsf@vitty.brq.redhat.com> From: Auger Eric Message-ID: Date: Mon, 3 Feb 2020 10:59:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <875zgoovhx.fsf@vitty.brq.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2/3/20 10:44 AM, Vitaly Kuznetsov wrote: > Eric Auger writes: > >> L2 guest calls vmcall and L1 checks the exit status does >> correspond. >> >> Signed-off-by: Eric Auger >> --- >> tools/testing/selftests/kvm/Makefile | 1 + >> .../selftests/kvm/x86_64/svm_vmcall_test.c | 86 +++++++++++++++++++ >> 2 files changed, 87 insertions(+) >> create mode 100644 tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c >> >> diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile >> index 2e770f554cae..b529d3b42c02 100644 >> --- a/tools/testing/selftests/kvm/Makefile >> +++ b/tools/testing/selftests/kvm/Makefile >> @@ -26,6 +26,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test >> TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test >> TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test >> TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test >> +TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test >> TEST_GEN_PROGS_x86_64 += clear_dirty_log_test >> TEST_GEN_PROGS_x86_64 += dirty_log_test >> TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus >> diff --git a/tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c b/tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c >> new file mode 100644 >> index 000000000000..75e66f3bbbc0 >> --- /dev/null >> +++ b/tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c >> @@ -0,0 +1,86 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> +/* >> + * svm_vmcall_test >> + * >> + * Copyright (C) 2020, Red Hat, Inc. >> + * >> + * Nested SVM testing: VMCALL >> + */ >> + >> +#include "test_util.h" >> +#include "kvm_util.h" >> +#include "processor.h" >> +#include "svm.h" >> + >> +#include >> +#include >> + >> +#include "kselftest.h" >> +#include >> + >> +#define VCPU_ID 5 >> + >> +/* The virtual machine object. */ > > I'm not sure this comment is any helpful, the virus is probably > spreading from vmx_close_while_nested_test.c/vmx_tsc_adjust_test.c :-) ;-) > >> +static struct kvm_vm *vm; >> + >> +static inline void l2_vmcall(struct svm_test_data *svm) >> +{ >> + __asm__ __volatile__("vmcall"); >> +} >> + >> +static void l1_guest_code(struct svm_test_data *svm) >> +{ >> + #define L2_GUEST_STACK_SIZE 64 >> + unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; >> + struct vmcb *vmcb = svm->vmcb; >> + >> + /* Prepare for L2 execution. */ >> + generic_svm_setup(svm, l2_vmcall, >> + &l2_guest_stack[L2_GUEST_STACK_SIZE]); >> + >> + run_guest(vmcb, svm->vmcb_gpa); >> + >> + GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL); >> + GUEST_DONE(); >> +} >> + >> +int main(int argc, char *argv[]) >> +{ >> + vm_vaddr_t svm_gva; >> + >> + nested_svm_check_supported(); >> + >> + vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code); >> + vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid()); >> + >> + vcpu_alloc_svm(vm, &svm_gva); >> + vcpu_args_set(vm, VCPU_ID, 1, svm_gva); >> + >> + for (;;) { >> + volatile struct kvm_run *run = vcpu_state(vm, VCPU_ID); >> + struct ucall uc; >> + >> + vcpu_run(vm, VCPU_ID); >> + TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, >> + "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", >> + run->exit_reason, >> + exit_reason_str(run->exit_reason)); >> + >> + switch (get_ucall(vm, VCPU_ID, &uc)) { >> + case UCALL_ABORT: >> + TEST_ASSERT(false, "%s", >> + (const char *)uc.args[0]); >> + /* NOT REACHED */ >> + case UCALL_SYNC: >> + break; >> + case UCALL_DONE: >> + goto done; >> + default: >> + TEST_ASSERT(false, >> + "Unknown ucall 0x%x.", uc.cmd); >> + } >> + } >> +done: >> + kvm_vm_free(vm); >> + return 0; >> +} > > Reviewed-by: Vitaly Kuznetsov Thanks! I will respin quickly Eric > > Thanks! >