From patchwork Thu Mar 14 23:26:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13592951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93355C54E6A for ; Fri, 15 Mar 2024 00:32:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XAr4yddQTCDQsTGnaZB/4RoFg2ICWr5pgkD3KKP9ykA=; b=oEoNSitGQWa8Nt N9qBBUx1bDYoCOZ2x6xtP8wfyNX+dNhVGDSrXm00RwcRbsAnyTbx/u8GZbSJfufbAoeY8fHTJSaOG DV078MV9H8jI2JY+WJ2GJXFhmM1ssCWXnPoDNhkLFBGYvJ2opJkuYouKvwxvyMel2Cn72S8pARSU3 nIwJzky2ClAsshKdEDWrqnkK3ckHyYSNpMCsooa5duHw8hTPMGdIBSsTwTVuL+ypP8bmCcl8M8bl7 AfdczI1JwTfL1eWqUu424AK3cCK/8RLPEIN6UmymIjCrEYH5TFAqahK65HWYraptAqaVC3k47vW6J ubLQJ1sNsxtG3bL0Cmzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkvUa-0000000GAur-21gV; Fri, 15 Mar 2024 00:32:12 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkuTd-0000000G0BR-3wUh for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2024 23:27:15 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-60ab69a9e6fso28081897b3.0 for ; Thu, 14 Mar 2024 16:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710458826; x=1711063626; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=ugMj11YssaThk53XXo2XJuyaCSbRC3vd2rkkLMOH5EU=; b=jPSW0HpVQFuHVWYD/N7G/zyXWpFkjbR8iFtPyzx/U3KDTeIx92xnxGq1jeuCGw0rFc j0E7l4gquQnrwRF72Zzil/hrxR7scsi6w7DneNo84D18eDwM58RFbxJcore8JZZQ8+sO iWBU+TPRlbfmvY9cYeJZbZiQuQr3JXHbeD/+/10q1nMYFtIbiePpIZPDhTH0yEmqGvH2 9FSzNNDIzAAW24owdLF+NeCEL8YzkwSb4d8rbJAt1I3FQ3/loj7IKHo4byZLgrsKmX+N 3S2BJ4U9rvBKsmIbwLvB2mmpJyq3K+1C28kkZBtdZ36+xyy+3pvmJenujMWDaTAgYWpa U+vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710458826; x=1711063626; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ugMj11YssaThk53XXo2XJuyaCSbRC3vd2rkkLMOH5EU=; b=WjGsW7ccKJUTyxJUvzesgdXstAQVA0Ag0vtjHJ2Qxs2Fv+FUKcKmQ489wfIq/YCWY3 S9ds34DuILl338/FLlUmBxR1aTcobBiaDQBMh+lN1DspHi8vZP0bCxbM3iNy9sHlD3/i RT07qsQty0Uu6hLUtqet8P8yDAPZ7aEVCEs1ZF4B7yJlYRIlBKhZQlGSzTK+YRmX1yHl U1QqjgiukYVbpkExMuX7IWAE6QmIVtjaKnQQLTjf7Fg46BrdLXFk1iN0y1ZU9XsxYg/W 5wIjnmIfXqeltrNUKEj7eMIxlFsAeK/UUN1SvghsudhWssb9qFZrOA8sV8P8LIPmoIo6 YGFw== X-Gm-Message-State: AOJu0YywDixLvzc2YbH22mr47Q8urLBGMnct0mOztpW/NP38cWKpdQWM QYFvTDLDagQHOtXNjO7IGeYh6Ddy7nhIqZfpahMK3Gjdr6O9rG7De5rkeL4fMQWKYt13Of2P5fm 3bw== X-Google-Smtp-Source: AGHT+IE5/WiqwibvrYrQwLJotN6HL86HBYfSMTMXmq7TGIVKVjhGwMzToGYfAqrqDOL2A5xHSs/EAtgRugA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:bc0a:0:b0:60a:13b8:6a5c with SMTP id a10-20020a81bc0a000000b0060a13b86a5cmr1757713ywi.0.1710458825983; Thu, 14 Mar 2024 16:27:05 -0700 (PDT) Date: Thu, 14 Mar 2024 16:26:33 -0700 In-Reply-To: <20240314232637.2538648-1-seanjc@google.com> Mime-Version: 1.0 References: <20240314232637.2538648-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240314232637.2538648-15-seanjc@google.com> Subject: [PATCH 14/18] KVM: selftests: Fold x86's descriptor tables helpers into vcpu_init_sregs() From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Ackerley Tng X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240314_162710_277883_0A7471CC X-CRM114-Status: GOOD ( 11.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Now that the per-VM, on-demand allocation logic in kvm_setup_gdt() and vcpu_init_descriptor_tables() is gone, fold them into vcpu_init_sregs(). Note, both kvm_setup_gdt() and vcpu_init_descriptor_tables() configured the GDT, which is why it looks like kvm_setup_gdt() disappears. Opportunistically delete the pointless zeroing of the IDT limit (it was being unconditionally overwritten by vcpu_init_descriptor_tables()). Signed-off-by: Sean Christopherson Reviewed-by: Ackerley Tng --- .../selftests/kvm/lib/x86_64/processor.c | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 561c0aa93608..5cf845975f66 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -516,12 +516,6 @@ vm_paddr_t addr_arch_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva) return vm_untag_gpa(vm, PTE_GET_PA(*pte)) | (gva & ~HUGEPAGE_MASK(level)); } -static void kvm_setup_gdt(struct kvm_vm *vm, struct kvm_dtable *dt) -{ - dt->base = vm->arch.gdt; - dt->limit = getpagesize() - 1; -} - static void kvm_setup_tss_64bit(struct kvm_vm *vm, struct kvm_segment *segp, int selector) { @@ -537,32 +531,19 @@ static void kvm_setup_tss_64bit(struct kvm_vm *vm, struct kvm_segment *segp, kvm_seg_fill_gdt_64bit(vm, segp); } -static void vcpu_init_descriptor_tables(struct kvm_vcpu *vcpu) +static void vcpu_init_sregs(struct kvm_vm *vm, struct kvm_vcpu *vcpu) { - struct kvm_vm *vm = vcpu->vm; struct kvm_sregs sregs; + TEST_ASSERT_EQ(vm->mode, VM_MODE_PXXV48_4K); + + /* Set mode specific system register values. */ vcpu_sregs_get(vcpu, &sregs); + sregs.idt.base = vm->arch.idt; sregs.idt.limit = NUM_INTERRUPTS * sizeof(struct idt_entry) - 1; sregs.gdt.base = vm->arch.gdt; sregs.gdt.limit = getpagesize() - 1; - kvm_seg_set_kernel_data_64bit(NULL, DEFAULT_DATA_SELECTOR, &sregs.gs); - vcpu_sregs_set(vcpu, &sregs); -} - -static void vcpu_init_sregs(struct kvm_vm *vm, struct kvm_vcpu *vcpu) -{ - struct kvm_sregs sregs; - - TEST_ASSERT_EQ(vm->mode, VM_MODE_PXXV48_4K); - - /* Set mode specific system register values. */ - vcpu_sregs_get(vcpu, &sregs); - - sregs.idt.limit = 0; - - kvm_setup_gdt(vm, &sregs.gdt); sregs.cr0 = X86_CR0_PE | X86_CR0_NE | X86_CR0_PG; sregs.cr4 |= X86_CR4_PAE | X86_CR4_OSFXSR; @@ -572,12 +553,11 @@ static void vcpu_init_sregs(struct kvm_vm *vm, struct kvm_vcpu *vcpu) 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_seg_set_kernel_data_64bit(NULL, DEFAULT_DATA_SELECTOR, &sregs.gs); kvm_setup_tss_64bit(vm, &sregs.tr, 0x18); sregs.cr3 = vm->pgd; vcpu_sregs_set(vcpu, &sregs); - - vcpu_init_descriptor_tables(vcpu); } static void set_idt_entry(struct kvm_vm *vm, int vector, unsigned long addr,