Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp446171lqb; Thu, 14 Mar 2024 16:35:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUikzd+N84W5HdzP3+FgOxJE58d2+DV50ULUHp8csiuS25+zE+zThGX7TQ8GyZkEWc4BJvyse6jSzizH/2sp/Y5WA9k6YC35BYnQH0uXA== X-Google-Smtp-Source: AGHT+IGbLGn1mJw0U8YvR7GRXOgdEVA48OAReeBOSqqEL2iejvjzxyrjzXmdm77RRHJ7zD8fFLtM X-Received: by 2002:a05:6402:3713:b0:568:a05c:9ec3 with SMTP id ek19-20020a056402371300b00568a05c9ec3mr2002753edb.6.1710459327201; Thu, 14 Mar 2024 16:35:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710459327; cv=pass; d=google.com; s=arc-20160816; b=Uw0bWo7Gy+POE2/Cy8+eRXreHaTGPFpMJzCABElcTaK/ldad8IzaJwhmjOy5joIMQi nkatBVztn19GKXDcqBBrE2ex7qACWHf8QAsM0mf2C+6nNqcz5peg+jA+8PWOTK5vZI+R npOhH9VQjbk/cM16IFSJc98O9EdXYtlFr+Tq/sC+5RVoF7O5DjMf8jJobHgzeW8EE1LB XuYgjaHGbIxDu6O2yWYy+IWvWpp15JbkngFvaWkH47J60cgEFnX/GiAzR7b3usbRZoV3 OK+x6p4eCt5knx3Ep89Oj6uoDIWkqnWNjWxvA+yzGxCXAVF52uzhkZkRhpiW850/a1Tw H/gA== 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=WoFzTDbs1SGZWiz/BWvPtXOQrZCNvORTtjaiRTPj8cA=; fh=8IQ392ZyvUnYNGMkxGHl1J75b8/cHkNDEjG+HleAULM=; b=bmPB758PAbMwLmkmNAmyD1TQ83nT4slBjm5zdzD3PM4BySJABSUUDahOGme6I0H/iQ dGc5JSFdVsMXeAQbBOETVLIQXAJ/99t3lIz3NqLsa5qFZPZZ+UTQjDH+8gmtFDx5xxo+ PAMgh3EMJxynSeiqY9MqA7STz/xLw0BPoz48f6anzR1HHLO6spM9dtkkCfvNoYXZTaNW /NTAkXVua1DX7bB09ocazvBIc8O02bPwgU4q3/2WG40DBw9p1mbYK8rMc9V0TRFfZd6c 9+qbrlnQfdERlZXBy9eCd2kPYGu4axZ0Ci2xmGcxU1qHdAmFZ8+g8xmAnmUCmoRZ90Pb /Zjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=j8Nsw8Xg; 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-103905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103905-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 q25-20020aa7d459000000b005686417984fsi1139804edr.579.2024.03.14.16.35.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 16:35:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103905-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=j8Nsw8Xg; 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-103905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103905-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 DF1DD1F214CF for ; Thu, 14 Mar 2024 23:35:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA64D54916; Thu, 14 Mar 2024 23:27:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="j8Nsw8Xg" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 329E9537F1 for ; Thu, 14 Mar 2024 23:27:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710458826; cv=none; b=UL9eQ60P931SBy//o8YIN0kpQhYurmaTkrPb4URDMwvt9BXGtd7ZDJCTZjBfjpnazR4NWR1rAbkX4YFYVn00a9Lw1viu8wTPHEYCFcLYfFdPz3IdLxy70cL29LIQabEhnEB+ZP4a41kd6fHFrYBO0SDQF1VWW3GCKzf9W395gw4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710458826; c=relaxed/simple; bh=rKle47E4nZDDqOFkGZ++A7yOb91DTrGSOJRrZ2XcVV8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kTZoHxMJCV4bKn5F/GHI9jNzrv8RDPm+/TU3Kb8m0hXwpWsmVxRahQiPTDzpsmSxO87NHGF8YNJbn157GsR8NtyEXDRQmzhbLJ6H4IFR2wZezamEOedkg8sgwuWV/MA/H4snn++TElBtdhIlUW0gOhJA1OwdL4LFFq3WqP9W+iQ= 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=j8Nsw8Xg; arc=none smtp.client-ip=209.85.219.202 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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc74ac7d015so1663763276.0 for ; Thu, 14 Mar 2024 16:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710458824; x=1711063624; 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=WoFzTDbs1SGZWiz/BWvPtXOQrZCNvORTtjaiRTPj8cA=; b=j8Nsw8XgYz98IxPIuOucqiB8hDxfbOlXh8KQgi6thRV9O9bUYiEA2WmEzvak8CGZui xGgUYBiXgbOcOdVu5NKbvRN6cDwrHT7bIg+sy+1ruv3m1BOw3vj2FRmTI9sw3Vb0JhEL sbeJXN3ES50gyuAzuPyEYrv2V5eMHny01AqxK/VmsZDmxbV/sEeT2b9IocmHL5Mgv+Ex p70N0os1uXF67VStutvoZkufK0Wqnui+8mdLly7GV6TJMPrE4KqQqAQ7VDGEBTstYlPu VY760/mmXBReSWQc9Cu2RcHy93cxgydrQA3EihlWddwNkZwyET/oR3j4egCOp8MPcjOg 7FBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710458824; x=1711063624; 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=WoFzTDbs1SGZWiz/BWvPtXOQrZCNvORTtjaiRTPj8cA=; b=GWEj1QsQeR1O8fk7W1SGjnJy4p14CvR5JZ8NYr0pFtWgRnMNRQAOmZRgq3smUaCjKa O+PXANBESBq39/BMY++kpXpolUCUG1jKSrfsIZIGjav1i3Iz7+riWreNMJxacl6GoG/t Ijwe1ZVc3xvygJM6NSxOyA0Kq7v6o441RX3jRajkGHnIX2WuBAj1qXjle2ge4MAEVKTB 140ATbDMiHJWbplWOIPbdASrtpdTVUMv54agYtd/jiSNTGu3hpmy4sYvKpB8ch4K6crG 24WL5C4KE1FKbVKAgYW94z7AgT/khi8f45W26C5SMpRXQWm0eQ7fuwtt9fWyAbchobrd lTQg== X-Forwarded-Encrypted: i=1; AJvYcCVPyZwevQu7rDQkQqsz4GpqGh3Tk0HIVla2SKBA13GwMqhO4sUXRCURMTdUmn7CgWTzBGfDDvZIk3nF63ljvCUKZVb18ZEL2c6jnqz3 X-Gm-Message-State: AOJu0Yz6NFrVrXzODlkyiVN7o4ld8nKA3oJnzvMwqjzrav1LevsfR2wo 2KpAqWMf7w0KVL1mMhQyVcqxWZV18g6Gwr4HalP+MMsbJoIgrss2oqwcDpJjaTEJCqgAgXKjetJ rZg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:2009:b0:dcd:c091:e86 with SMTP id dh9-20020a056902200900b00dcdc0910e86mr147737ybb.13.1710458824203; Thu, 14 Mar 2024 16:27:04 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 14 Mar 2024 16:26:32 -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-14-seanjc@google.com> Subject: [PATCH 13/18] KVM: selftests: Drop superfluous switch() on vm->mode in 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" Replace the switch statement on vm->mode in x86's vcpu_init_sregs()'s with a simple assert that the VM has a 48-bit virtual address space. A switch statement is both overkill and misleading, as the existing code incorrectly implies that VMs with LA57 would need different to configuration for the LDT, TSS, and flat segments. In all likelihood, the only difference that would be needed for selftests is CR4.LA57 itself. Signed-off-by: Sean Christopherson --- .../selftests/kvm/lib/x86_64/processor.c | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 8547833ffa26..561c0aa93608 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -555,6 +555,8 @@ 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); @@ -562,22 +564,15 @@ static void vcpu_init_sregs(struct kvm_vm *vm, struct kvm_vcpu *vcpu) 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); + 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); - } + 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.cr3 = vm->pgd; vcpu_sregs_set(vcpu, &sregs); -- 2.44.0.291.gc1ea87d7ee-goog