Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3606375ybl; Mon, 3 Feb 2020 03:23:20 -0800 (PST) X-Google-Smtp-Source: APXvYqz29t8Erd4jvWoIlWQxNZFPMu0G54f5Cr57RKPsPufI/Aklyl12r3q0qBHKROBz33ZTLgMr X-Received: by 2002:a05:6808:7dd:: with SMTP id f29mr892794oij.67.1580729000673; Mon, 03 Feb 2020 03:23:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580729000; cv=none; d=google.com; s=arc-20160816; b=wp1w5TO3tlM3uAfgxlemNsWePcvo87T6LfkrXZ8bVYjyKGBSE+SxZIVxY54mwgE+H3 wQ6Xwt7GyJWItIK8zgqkU38YyuvjgGILsR7aOZ0P6TDCstdyisbghuyNhj83P7sex7PN WzQNxYVa27z4agVa60GNQ4TbaYJkyJTmzbM21iStUl14EUtGEG2+bm/hckkbyXm86lxc uj1zVp1c7tKAXfRjzKdSdZQPyTD2L5nwH7zQyvoCAkB84lNom/S6nXhoP9uTkVZ8UA4c NhNk+2RZ92pMG2QjgkuFOZRmE3oUBbrOkufMYw6T201tww2HJbO86sc22Mm4K/gYkIVt RTGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=U8lPnHaheFWGl2YTbG1NopUSDMIBfXgmeIW560W2LqE=; b=IwXSHHjLkqc2X+ZPjnDWOtIduSh+Vv5ZPW/Br5E/Vv4XUjC27YpgwiEb7Av5Up/u4W Bti+zVvOom6yuK7TMFgQflFaYsbVzyYb2O7bWRyl5/DMGQOTN1wLvEUoTITGWPISRBnJ aIJ25UsCz8tvyZDPGB9RoK1bLbLdQwYxc/J/2wAirmWKnd9aycLpJaKK+thFVF47PE+1 pMGuEYR1vnfg6gh+V9NNVwBX9+8Zq6coiLsQAYFu+oEY4g3nXpY8z+KdlJLxemzWEh2P abvzWLHFPdzqTsjHLQCx6mMrCP2dfoWE4OIjroqaNN+S5URhy0elzfXjiUOZTCoxsV1/ AOiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BTdQmaaH; 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 p83si8095652oih.198.2020.02.03.03.23.08; Mon, 03 Feb 2020 03:23:20 -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=BTdQmaaH; 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 S1727979AbgBCJos (ORCPT + 99 others); Mon, 3 Feb 2020 04:44:48 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:23060 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726653AbgBCJos (ORCPT ); Mon, 3 Feb 2020 04:44:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580723086; 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: in-reply-to:in-reply-to:references:references; bh=U8lPnHaheFWGl2YTbG1NopUSDMIBfXgmeIW560W2LqE=; b=BTdQmaaH8UVKPJx0YnkfCK6BGhQf9CLvH6uqS8j/NJ7Uu9dxe4xG54eZflcgVEqdcdrB9w OgqBXgrqOhGEwNROD9LuU54LvRX2HyELmaqIXCuZl/hlSoqdiGJg2KxvNohruQiOY+qDDE SGzmu6LfVaocQTgALIfs8g0TOZ6rwpo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-AcYkQ24iNPCMsJBa1uZn0g-1; Mon, 03 Feb 2020 04:44:45 -0500 X-MC-Unique: AcYkQ24iNPCMsJBa1uZn0g-1 Received: by mail-wr1-f69.google.com with SMTP id z15so8007173wrw.0 for ; Mon, 03 Feb 2020 01:44:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=U8lPnHaheFWGl2YTbG1NopUSDMIBfXgmeIW560W2LqE=; b=G9qaTpTkaahW/0t0UfPNV5G2KaQSd7n94fXD64knSSaRMBX3stldxJUdxFm7DzvtUE Y+FIzfGTRryiCFVvT3N6qL/HOxzPZyJnqO8Nx0mGf89aFYSgW8YoPgAdbG41HmCfS1n9 uOgyO6XDOQruCngR5rIBRl9ngwQ7nJjMEayYa8JRfVNL5/xcXKY8nSUKNmHt855WpZtr nwFgskMvSxS40qhjARGgJIjxbDhNj6KI/ZdlPX4hAPrl+ehDmGaxqMBDmtpBjKmFfRtt SfbFiy2xFxaA++4FuXYkbTHa0bC3woTvtFSwgCgrpJoVd0zkFVy4XXe1+E4YBQo7Rmsj YgBQ== X-Gm-Message-State: APjAAAXoEHjepgsjY3s4PxonJrbNWXz4Of5s5XLrSg8p/BxmzRK9vxoG OdBHxImPTmbw9FgM4RceFdRzrnTeuvQi+MXNl53w+TJjMRjHOBnyvv1Tbdl1Qn4O4cn9PGCzY3+ acCeuJYzkk5O1DS2CHLkj4D3v X-Received: by 2002:a7b:c249:: with SMTP id b9mr27894125wmj.74.1580723084289; Mon, 03 Feb 2020 01:44:44 -0800 (PST) X-Received: by 2002:a7b:c249:: with SMTP id b9mr27894091wmj.74.1580723083992; Mon, 03 Feb 2020 01:44:43 -0800 (PST) Received: from vitty.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id a5sm22769393wmb.37.2020.02.03.01.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 01:44:43 -0800 (PST) From: Vitaly Kuznetsov To: Eric Auger Cc: thuth@redhat.com, drjones@redhat.com, wei.huang2@amd.com, eric.auger.pro@gmail.com, eric.auger@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com Subject: Re: [PATCH v2 2/2] selftests: KVM: SVM: Add vmcall test In-Reply-To: <20200203090851.19938-3-eric.auger@redhat.com> References: <20200203090851.19938-1-eric.auger@redhat.com> <20200203090851.19938-3-eric.auger@redhat.com> Date: Mon, 03 Feb 2020 10:44:42 +0100 Message-ID: <875zgoovhx.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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! -- Vitaly