Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp735517pxb; Thu, 21 Oct 2021 08:31:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPUYqlmTFHIe/qrQ3VRnO2utXpP1GPU6xhD8KZb46BVIJJgBrQQ9CU0wAeIKlru0SmA8IX X-Received: by 2002:a17:90b:388a:: with SMTP id mu10mr7195038pjb.221.1634830272371; Thu, 21 Oct 2021 08:31:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634830272; cv=none; d=google.com; s=arc-20160816; b=SIbOdZDF+ddu2C3m0KQUO0hBu7GqtkcyytOkWJIxIb4imZz1NDs6kUXtqLjGElIaBK KJcQmK0s6Tm2LBEHl4IqQ20jSVTgU1tQOkbgGIGmAno0Y9+lDdsfklKwN9zzz9enesFz CknAWKzd/+6G/fHv6J/bOIoZwreC0LlCHPgIbgitLMN06KEtCe3x760kZDpNjjJMJp0k 7jytgIghS5yjjCzQHV64CpMg1oialzrAvnl79jif6xrK8/tRGdCO0N1SiNTGwYjS7tS4 GFdNYC7RDS7F5CHnZ+8sHYWUvnAQ59Fb9FQL4FPS5HmthWEFisdSkSsYyZIZoMRNwZRN sr1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=z7CxwAzzEIQOd3qBht/PpbJEZOuniLXSJ6BnX0TmD6o=; b=zbUOdnvliRRfWCoy3F4HG2+9GAhNZbq+ns2IlLeQ/rMVT87zM3pcfeqpJexXXIg5Aj eenATj4oKaNNkaA6wiokU94qDIwrROJpdlcYHxVWAu7IZrbzjI7BYVFKGKfLJoJqnxQ7 liRm2rKWiPEKZk3Lgr8iE0HMRC4kRXNI9dx964gzywjuaexU5t+O8eyCIV08R5dGU0iB OisrROmTZvG1X98n5zfxY0ad4VvWxAirfRySw2JLtmxnwgqtdDZX+rr/irlb94ohyxNI kwF4f7NGlg93SfVi5M7jyL7z3R9besOgvuz5DQ5z1u/dew5chiD3DI9/uwGjucBfpGzU iClg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PBRBFRZ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id m13si499641pgq.429.2021.10.21.08.30.57; Thu, 21 Oct 2021 08:31:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PBRBFRZ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231847AbhJUPcG (ORCPT + 99 others); Thu, 21 Oct 2021 11:32:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20087 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhJUPcF (ORCPT ); Thu, 21 Oct 2021 11:32:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634830189; 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=z7CxwAzzEIQOd3qBht/PpbJEZOuniLXSJ6BnX0TmD6o=; b=PBRBFRZ5GbIYceOMDtzy9xEstNzJEhUJGWcZoabvcHGqpqDhyj3rqIVUm6PhgCsiBwlxh4 pcc+3TSdxEeu0SQpWyX5Ym5aC7AS93yV1S38S5VNBccvE6myEGh0e7+oZRHb4A2gS+iGny PYVl5X7pIawWGgb5YUcl76N0v4aTYa4= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-111-jaDerVU9PZWcM6I6DsXcyQ-1; Thu, 21 Oct 2021 11:29:48 -0400 X-MC-Unique: jaDerVU9PZWcM6I6DsXcyQ-1 Received: by mail-ed1-f69.google.com with SMTP id h19-20020aa7de13000000b003db6ad5245bso745184edv.9 for ; Thu, 21 Oct 2021 08:29:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=z7CxwAzzEIQOd3qBht/PpbJEZOuniLXSJ6BnX0TmD6o=; b=1EqaUBzzpLWksiys40ExZDUhm+l/+UBV7WaZIXMmHQ5BTLwLF4xXe8bvLQv6Kf6fWJ 8NHo6lWV+29PmydKmYGG0wL09htzlJruyc6H2ffUzfrfQBZY6TAT/TqYsozulvoPQaJ9 ZnJExmicI/jJBK6wAUwNNLpYKivFRe0/6JwLtBR5B+M7XUBwqxiy4KXoeVMue7tf356d bf8cmwMmomi2/0q/ttFZxQ/vPfIj6oVHaqPQmlod6XdxkurdG0MYIdyzvoKSr84aqVER /gwAApT6Ok3oCO34Mkpr6XjqyTvSpu7BzwkCiMOk8pYPnm6lTsXQ+GgBEkJpgQJttwPR UsJQ== X-Gm-Message-State: AOAM530x6rig49OVJT2HbsgCfLHlzSfppIUm5xEveiA3FxjZZrSCejCZ DBqeASxeVK3H83VCfZB1magRTYN/Hb8Q84zBuo8U9ERMN51xbH187AJqeAAbvXnX24+2Pn384rF 87xr4rQFKkYT7BsVEd4TwUl+3 X-Received: by 2002:a17:907:118d:: with SMTP id uz13mr8613411ejb.382.1634830187143; Thu, 21 Oct 2021 08:29:47 -0700 (PDT) X-Received: by 2002:a17:907:118d:: with SMTP id uz13mr8613378ejb.382.1634830186861; Thu, 21 Oct 2021 08:29:46 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:63a7:c72e:ea0e:6045? ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id ke12sm2681160ejc.32.2021.10.21.08.29.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Oct 2021 08:29:45 -0700 (PDT) Message-ID: <545b753f-a11f-b6fb-2c33-49a99875d72f@redhat.com> Date: Thu, 21 Oct 2021 17:29:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [RFC 04/16] KVM: selftests: set CPUID before setting sregs in vcpu creation Content-Language: en-US To: Michael Roth , linux-kselftest@vger.kernel.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Nathan Tempelman , Marc Orr , Steve Rutherford , Sean Christopherson , Mingwei Zhang , Brijesh Singh , Tom Lendacky , Varad Gautam , Shuah Khan , Vitaly Kuznetsov , David Woodhouse , Ricardo Koller , Jim Mattson , Wanpeng Li , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" References: <20211005234459.430873-1-michael.roth@amd.com> <20211006203617.13045-1-michael.roth@amd.com> From: Paolo Bonzini In-Reply-To: <20211006203617.13045-1-michael.roth@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/10/21 22:36, Michael Roth wrote: > Recent kernels have checks to ensure the GPA values in special-purpose > registers like CR3 are within the maximum physical address range and > don't overlap with anything in the upper/reserved range. In the case of > SEV kselftest guests booting directly into 64-bit mode, CR3 needs to be > initialized to the GPA of the page table root, with the encryption bit > set. The kernel accounts for this encryption bit by removing it from > reserved bit range when the guest advertises the bit position via > KVM_SET_CPUID*, but kselftests currently call KVM_SET_SREGS as part of > vm_vcpu_add_default(), *prior* to vCPU creation, so there's no > opportunity to call KVM_SET_CPUID* in advance. As a result, > KVM_SET_SREGS will return an error in these cases. > > Address this by moving vcpu_set_cpuid() (which calls KVM_SET_CPUID*) > ahead of vcpu_setup() (which calls KVM_SET_SREGS). > > While there, address a typo in the assertion that triggers when > KVM_SET_SREGS fails. > > Suggested-by: Sean Christopherson > Signed-off-by: Michael Roth > --- > tools/testing/selftests/kvm/lib/kvm_util.c | 2 +- > tools/testing/selftests/kvm/lib/x86_64/processor.c | 4 +--- > 2 files changed, 2 insertions(+), 4 deletions(-) > > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > index ef88fdc7e46b..646cffd86d09 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > @@ -1906,7 +1906,7 @@ void vcpu_sregs_get(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs) > void vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs) > { > int ret = _vcpu_sregs_set(vm, vcpuid, sregs); > - TEST_ASSERT(ret == 0, "KVM_RUN IOCTL failed, " > + TEST_ASSERT(ret == 0, "KVM_SET_SREGS IOCTL failed, " > "rc: %i errno: %i", ret, errno); > } > > diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c > index 0bbd88fe1127..1ab4c20f5d12 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c > @@ -660,6 +660,7 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) > > /* Create VCPU */ > vm_vcpu_add(vm, vcpuid); > + vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid()); > vcpu_setup(vm, vcpuid); > > /* Setup guest general purpose registers */ > @@ -672,9 +673,6 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) > /* Setup the MP state */ > mp_state.mp_state = 0; > vcpu_set_mp_state(vm, vcpuid, &mp_state); > - > - /* Setup supported CPUIDs */ > - vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid()); > } > > /* > Queued, thanks. Paolo