Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp234868rwb; Tue, 25 Jul 2023 15:05:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlE+BdfSfgOANHUgnR5WtylUobpa2hYqKSH2ZWZv/XzmQxFh961Ea1fAmcz5OagOtj7EAeP1 X-Received: by 2002:a05:6e02:12b2:b0:348:ce4f:c842 with SMTP id f18-20020a056e0212b200b00348ce4fc842mr290857ilr.23.1690322701962; Tue, 25 Jul 2023 15:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690322701; cv=none; d=google.com; s=arc-20160816; b=BHjlPID6OGsY0/viAtfCT+T9bT2UNrkxlqojuPknMupfqxwDHm9kVwU4MuUcHmaEht yKt1ViO3jA+t4vE76z9l3cKbnt3vYfkwJi16WDPA3/Chi1wKL33N+WGR5JdU6WOl1N6c MmMXmT0/p4pW50vMN8nNdRFodZsa8tshUAR+orNgm2wAV4jZiGB7aCRTRMcirWH7s976 Il58NtL27mbiaX9QQOyFfEWWKkdOdc0vUDdnvP9kzsnnC7KutZ3NdYdgAVSJ9AOrO1k7 ZUE+bHDABwGtNfxOy6H/MofnAQIsaSyIbSCPO8HXO7Emptmd/EPKfUOsCHzsLMC3T++p jMpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=amJG0j0ZI/e1O59M3k1Hf7ZdfPU64t6LHG2FDq6Qz+c=; fh=1/sgOwi5AuU8IZymeFKs1Rjnf4QELnrK+C7GntqU2hA=; b=I49QWl2lRrigGG2ZjFcTSzGiHDXh4MGph4PMxCMjXMiVR4LUuiBI3MFLOlBc5ChOQN tKEO/yWRumNz/6ATmWWo/BHzCRjjQ9nDtjvByCx6phmw6Bru+6FkGrHpW94bxiBCS+WS aRPxmMF5CEJvEegoQLC65+zSfa7KkRRvaJIUSfpcdh6M8mrZl1vChMHhPp/zNOrvgbaZ wYdEPOW6sRnRMUGE2S7aPQ1i7/7FsCNCdRCOF7/vZSt/LpnLBRWT8fyY+S9sUvgBpq0O 5/g3ek5Cv3q7mY6n8jbJ2J0CepjrFMBmKaWYWSAEDCO0+fJJP/97xBDjpCW0AkIg+TX/ UaWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=RmM9zNeJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4-20020a633c44000000b00563adca5169si125849pgn.741.2023.07.25.15.04.48; Tue, 25 Jul 2023 15:05:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=RmM9zNeJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229930AbjGYWCj (ORCPT + 99 others); Tue, 25 Jul 2023 18:02:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjGYWCY (ORCPT ); Tue, 25 Jul 2023 18:02:24 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E78783C0D for ; Tue, 25 Jul 2023 15:01:51 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5635233876bso3130007a12.0 for ; Tue, 25 Jul 2023 15:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690322510; x=1690927310; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=amJG0j0ZI/e1O59M3k1Hf7ZdfPU64t6LHG2FDq6Qz+c=; b=RmM9zNeJGgNQ6Dg0hG2kUvnQNUvz+59r34LYANdjx54Oc8ei1YJim1aGMEsg1ujbCS V1NxEOeai31JFi3RkBsjx94jNfom7fsQm9vCgEFxTo0ZZcaT6Vgt46LSlRWQIRPpSPRW 2eyUT1oupa5fKF5wIERZL5tsCoFpWVnbAZnwq/Azqu1mygvT7Klvxn5uj6olYT3nZdgr yqimJznJSc+eyuqesINnrfTjrllzECBfrI5vFsdsJyp8giPiRym2119Craavf5MgLLmz Jbe+UiAmRw1Bbnsn0jZQpwaD9X6uF+plfF+twsIUORWZY08KMX+essSi401RbwUuEN7e gNaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690322510; x=1690927310; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=amJG0j0ZI/e1O59M3k1Hf7ZdfPU64t6LHG2FDq6Qz+c=; b=SFf/WXdE9BsqVKhs4/Ua9w0McCR617xcBQf8nqchzuW4nFWfvl3HHWrQpY5DwyqpTC intBJcxSfhPYpeAgbwynj2/JX3cxz2UfzH39D2z/CsOD0Fi4iEww0hGicYVB0tl5sxH+ 7FljQdothdXNO72PI/P9ZV8SoEi3qZdRLzQp8qCZyWTR7PNda8KvWgkSVSftvF17Q48M yMAcTFoWwm2MTs3Byc8L8sgrPGQNe23aCLzyBwk1R8E+zpYPXRQHcQ87UvQal/lO4ZBf 3S6YgvrkAv+p5QeAQUloonyuMszGJSF6v44tmsizRTytHtE2F8HaaxbceLn53wD52ivj 6UjA== X-Gm-Message-State: ABy/qLYkO0h+rZyTBKYFcJ0d8BPIAui9a3nCZtcfyP6B05ii54duXN0J HF955hJawJKx5A5PzJvKLwTYRY/HIjoh X-Received: from afranji.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:47f1]) (user=afranji job=sendgmr) by 2002:a63:6486:0:b0:55b:3391:2293 with SMTP id y128-20020a636486000000b0055b33912293mr1868pgb.4.1690322510412; Tue, 25 Jul 2023 15:01:50 -0700 (PDT) Date: Tue, 25 Jul 2023 22:00:55 +0000 In-Reply-To: <20230725220132.2310657-1-afranji@google.com> Mime-Version: 1.0 References: <20230725220132.2310657-1-afranji@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230725220132.2310657-3-afranji@google.com> Subject: [PATCH v4 02/28] KVM: selftests: Expose function that sets up sregs based on VM's mode From: Ryan Afranji To: linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, isaku.yamahata@intel.com, sagis@google.com, erdemaktas@google.com, afranji@google.com, runanwang@google.com, shuah@kernel.org, drjones@redhat.com, maz@kernel.org, bgardon@google.com, jmattson@google.com, dmatlack@google.com, peterx@redhat.com, oupton@google.com, ricarkol@google.com, yang.zhong@intel.com, wei.w.wang@intel.com, xiaoyao.li@intel.com, pgonda@google.com, eesposit@redhat.com, borntraeger@de.ibm.com, eric.auger@redhat.com, wangyanan55@huawei.com, aaronlewis@google.com, vkuznets@redhat.com, pshier@google.com, axelrasmussen@google.com, zhenzhong.duan@intel.com, maciej.szmigiero@oracle.com, like.xu@linux.intel.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, ackerleytng@google.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ackerley Tng This allows initializing sregs without setting vCPU registers in KVM. No functional change intended. Signed-off-by: Ackerley Tng Change-Id: Id20d51ea80aab2e22b8be14e977969aa0bd3cbba Signed-off-by: Ryan Afranji --- .../selftests/kvm/include/x86_64/processor.h | 2 + .../selftests/kvm/lib/x86_64/processor.c | 39 ++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index a1a9e34746c0..a4923f92460d 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -930,6 +930,8 @@ static inline struct kvm_cpuid2 *allocate_kvm_cpuid2(int nr_entries) void vcpu_init_cpuid(struct kvm_vcpu *vcpu, const struct kvm_cpuid2 *cpuid); void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu); +void vcpu_setup_mode_sregs(struct kvm_vm *vm, struct kvm_sregs *sregs); + static inline struct kvm_cpuid_entry2 *__vcpu_get_cpuid_entry(struct kvm_vcpu *vcpu, uint32_t function, uint32_t index) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 2a1dbe4b41c3..e3a9366d4f80 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -534,35 +534,38 @@ static void kvm_setup_tss_64bit(struct kvm_vm *vm, struct kvm_segment *segp, kvm_seg_fill_gdt_64bit(vm, segp); } -static void vcpu_setup(struct kvm_vm *vm, struct kvm_vcpu *vcpu) +void vcpu_setup_mode_sregs(struct kvm_vm *vm, struct kvm_sregs *sregs) { - struct kvm_sregs sregs; - - /* Set mode specific system register values. */ - vcpu_sregs_get(vcpu, &sregs); - - sregs.idt.limit = 0; + sregs->idt.limit = 0; - kvm_setup_gdt(vm, &sregs.gdt); + kvm_setup_gdt(vm, &sregs->gdt); switch (vm->mode) { case VM_MODE_PXXV48_4K: - sregs.cr0 = X86_CR0_PE | X86_CR0_NE | X86_CR0_PG; - sregs.cr4 |= X86_CR4_PAE | X86_CR4_OSFXSR; - sregs.efer |= (EFER_LME | EFER_LMA | EFER_NX); - - kvm_seg_set_unusable(&sregs.ldt); - kvm_seg_set_kernel_code_64bit(vm, DEFAULT_CODE_SELECTOR, &sregs.cs); - kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs.ds); - kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs.es); - kvm_setup_tss_64bit(vm, &sregs.tr, 0x18); + sregs->cr0 = X86_CR0_PE | X86_CR0_NE | X86_CR0_PG; + sregs->cr4 |= X86_CR4_PAE | X86_CR4_OSFXSR; + sregs->efer |= (EFER_LME | EFER_LMA | EFER_NX); + + kvm_seg_set_unusable(&sregs->ldt); + kvm_seg_set_kernel_code_64bit(vm, DEFAULT_CODE_SELECTOR, &sregs->cs); + kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs->ds); + kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs->es); + kvm_setup_tss_64bit(vm, &sregs->tr, 0x18); break; default: TEST_FAIL("Unknown guest mode, mode: 0x%x", vm->mode); } - sregs.cr3 = vm->pgd; + sregs->cr3 = vm->pgd; +} + +static void vcpu_setup(struct kvm_vm *vm, struct kvm_vcpu *vcpu) +{ + struct kvm_sregs sregs; + + vcpu_sregs_get(vcpu, &sregs); + vcpu_setup_mode_sregs(vm, &sregs); vcpu_sregs_set(vcpu, &sregs); } -- 2.41.0.487.g6d72f3e995-goog