Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp446278lqb; Thu, 14 Mar 2024 16:35:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUae9DpM4TMKrtXA7ZJ2epOGQHIMOrQPI6K8vtkwfH8cShgTUMedrmSg5hCjxt65afb+hM+PnE/MESE5JEb15hgETEqS0KZt5fCAKo81Q== X-Google-Smtp-Source: AGHT+IERp1vDAKtDJVQrHubENr3wXcWM/yvh12OY0/f+q5BIH17+NjsR0SCzfhABSwlw9w+01TXR X-Received: by 2002:ac2:4d99:0:b0:513:d381:65d6 with SMTP id g25-20020ac24d99000000b00513d38165d6mr1795742lfe.17.1710459342547; Thu, 14 Mar 2024 16:35:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710459342; cv=pass; d=google.com; s=arc-20160816; b=MDqdLtHh2uaGDzy1/A5RDV53CrqnKB0N8+29yHhjsOJZBkm1ZZwBWGvQXRjSjL7O7G eNhOO77bGWMa68+aIhX83jaFsyWvmLyyY8dgDvD5PMgowiAIcGUv3rIKFMysFnIn0ftL jOk8nafLiEIxP3Jz4PJqOwKHtGEk2zjVS/LhVPbobDkZjJJSSx1dq1F0kKv5W0/o9EuZ a8WJau9QPG32IPrP6HTDhbDK9Z/O1rATJCvUqj5WAJ7kN4gQnH+8tuLJFWANfZdoR+Fv AROCZYM9o768x0MdJMGww+BzdPlBwihW2D3fcxJgIm5pzwScvK3zJT1PCdH3fuVL6YNb fGMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=ugMj11YssaThk53XXo2XJuyaCSbRC3vd2rkkLMOH5EU=; fh=xNHegl9VWoBBDIfDmldcrWgX3Iuucvs3dSwZGRB/BrU=; b=u+G0X5t4lNwo13fL2anwT+3GLj/Aj+oGIbP65Vgh/5izxVk49v8JwAnHV9KXvU8HX7 DMoyUa0BHX7I/RIHJ5sQeg4uSKsEFTPLt+z4nCwPRu1AzFH9uAc4uGQ2FHMN8kKZYSX4 dIRkchRszXkrxSXkWBQRgAy3vfLCkZml+IDJbZbqjMUf+1OjO0jjlEmG8aDu2gVgT7+v jBC1IsEYyYmlJR6u8HcUDkNOtZR9jhqhxifN/xRk9IcjHSqzwhNtk0oBI6QoHDBT2T/v sYSDemrArmUUKJkx79Mw1T4t08HCLvbbaf99UMOdT5O7bV3udYPJbZRVY7Jl0DGWviJl 98bA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=igkw4nuE; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-103906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kh24-20020a170906f81800b00a464caa1040si1132051ejb.737.2024.03.14.16.35.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 16:35:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=igkw4nuE; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-103906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0DCCA1F2165C for ; Thu, 14 Mar 2024 23:35:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D15F55C33; Thu, 14 Mar 2024 23:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="igkw4nuE" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C10B7548EC for ; Thu, 14 Mar 2024 23:27:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710458828; cv=none; b=TXgkEmudM9OBcbeXzpSqmuRJBy43n3FN5ORz31/XIssntVA4zBJLvpdmZNcV3h4X7TthU0FpcshsFo1z0zLSbpJ763Jf4PMCeq++KHSnKzkZEkFeMv4yySLLFOiBMARPqVLWp3E24zNtEnsAfYcuGOOSDjyJl6T2si7EPcd1ha0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710458828; c=relaxed/simple; bh=PqA36j9IQANN0GTDJLwJ7hsqDDDFB01NLUyYfZ1HmNs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=j2zN1dswANUjg1qi9/aciqX9q3LXwAgM9gyk8g4siiAZC5dbtp2+D2uPu87EeNWvdL93hiaXKrqUZFqy6dJPbrtG3FsXCwN32zq7xXGSiH2u57NF9oerbuv7RhTLM8V1sBMv8KQjCcSStZsF8jW27u8/KRASbqdPCUKfjFlTn4Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=igkw4nuE; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60ab69a9e6fso28081917b3.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=vger.kernel.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=igkw4nuEnDrK94g5ybsx14WxA7MYzRuWXqcSTJQZCOVmkKBWmfJ2yp410joBh2Gly3 eh24ueNeqRQcOTdifcERYMIREfvDIPKNjmo+Ei6RnDp7N2pQkQtOiQ4NzS4IkkorsbGk 5ncMTetg11+ZqyOKKeunqIIEGXCcaHigRPF3PRTRzEgWXLsvMoNzcnjTHAKpoImV9+B7 8MliT02Z8mWTc7LwRkgGvZ2HjrL6WIjeNHXSaY/Ai0HuQKmqANa+pouxG4VDW+6LVzRG +tY2upUPFZUBOkW5IGpbLeKMuOxzFRxa9LyoVI3eTdqz1ojdSfwkgtTGw8zfEb5WNFtm qiqA== 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=oLfOirQp1K8fUUZCzUuqFTrat9gT7H9XCUpBQtNAnl1TzP2MByIJGzVdZzC2JI2RhA zu3JhakrY+nfVtlWIxX159wsxsz3UNnyBAu4y0S7nu55u3Pk1daMrMwr7k8hQYF/li+g rEqoxZ5rP0WDxdUla4oDwHJX+PRGLOmyghsY3HlOm1q2wLTwsqZd1l6bhPxBa0dQTj1x DAx6qfvAz+w+thN5pHPC9h6kAmdsh+bN6s8sIsA62q3N8QO/qjNIU2ob9nIhuf5rnaYi yNYQ+u62t7fhLsSEyPxkiRKivb6b9GX33KCJ8j+/7K7AT0Nb/sc3E+JkRuOQwvy2eau6 copA== X-Forwarded-Encrypted: i=1; AJvYcCXjr35iHsKakrRAxIErT3tLQbl0KcIjPaJULD7WUG/1ihypBFDBYLEdLzcisIpxfzOsGE1hrztC3UcCBWYnXdVa5uWgRouMyGUpWaZ1 X-Gm-Message-State: AOJu0YxSUBtE4ioDII0VrybXRuLCoXknGkcKAWxdl3K3KANa99LR1uyz o3zqjmJ1HnAE/dK9lZWD5/wg+XPQgtE6wSF8H4kSzqJbhDqYdt778Q1DlxI1e/S70T51UzMOJgK 6ag== 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) Reply-To: Sean Christopherson Date: Thu, 14 Mar 2024 16:26:33 -0700 In-Reply-To: <20240314232637.2538648-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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 --- .../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, -- 2.44.0.291.gc1ea87d7ee-goog