Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1695020lql; Wed, 13 Mar 2024 05:59:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWlf8PUi00TnET51j59I0oC6H7KHQv8bcOes5LB6XUhDk1lxlq7TEHeQgeFvS/Vsjz/cTy74BmlGYZPf76M94NFjtduE5W6cROKg9TigQ== X-Google-Smtp-Source: AGHT+IHyd98Het0jnqYlvKEPD8/YUoPK2FqeKHwFOqN2e4dkOuhUmb2gyEeZ4zo9HrCfEuJSsYm6 X-Received: by 2002:ad4:58a2:0:b0:690:ab6b:3a38 with SMTP id ea2-20020ad458a2000000b00690ab6b3a38mr2858672qvb.4.1710334769895; Wed, 13 Mar 2024 05:59:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710334769; cv=pass; d=google.com; s=arc-20160816; b=snfnuZrIGdBVdZ8dg/qHM+91p231CSaXI7txaxJvuF6Y87pOtC+nUzu1f+VXPyPM+Q +n/7fb5UPs9I0sXYUE84DBDYdWnwqISvtAxER/8WLRpJyDSnPDz3FI8J8rFRHi97eyRy 9ierHFtAM4FiW5Dw7A/oHbhvTIP+Anz1wAk5usJEw73gKpjc4ZkdIgrKAj26ShtgwHMg ptRUnXcFYwDLwQuS4P+qt7eKrMuyX+4B4VoMBcLy/mnLj1x92pDm/dJqqm71Xvji0YcQ B4Fu+GUqNGL7N0Aq6D+0m3a96TPyDvMFfyeHyedkLm4JwDa4vONtJWF/4yELhSmemTc3 YkRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JbI1Q06i15zBNLDlBPV6XMPyx/dQKcp3tORlZ+sJxOA=; fh=+0nuhWk4EeR9G54N0UU2EER7DXdpp14CTwi+HUVZv40=; b=GXm/6opvh3CBKVWrA1/xxSAhzlAjpwBS7yzBycb6+Jjma6zQm+b2dwD/2Hvw4eqEd9 Yzxt/v92jeZ4v2Urh+zrTtbnPUmTJJVnkn+5k9ZLqea6+oVMtPga+4FzwL+OHHvNc73s Ou7YCJhGBj+DUBSLXMAbgAPm6wXCgiu0KoMZHYHzakbPQ6dcJzbOYiXdoTHaa9dHo7H+ vWzNVVriXyoLzrilbWuWZbpAccQJOiJ/eGVI+F2OEJA+fRPhT81oszVoTSZy1Y85m2Qa i+xF6ERZgJHeEkB7kESd7ctEHPN7VaXFspjOC4KQRecApJaASr6aWuHg72qxm2QbYjBe YTAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B1swGbGD; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-101502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101502-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gm8-20020a056214268800b0068f4261e47dsi10056007qvb.84.2024.03.13.05.59.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 05:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B1swGbGD; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-101502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101502-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8EB2F1C2186B for ; Wed, 13 Mar 2024 12:59:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 79E464436C; Wed, 13 Mar 2024 12:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B1swGbGD" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 309CD4120B for ; Wed, 13 Mar 2024 12:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710334735; cv=none; b=inEtBu1DUAznaMcw9qvLoBltVeRF3vLWSWanyayPIRhZCOJFTYKlla3+NJDP57xMMJY0VQH7TsNn2ZnDl0WC/dayY/H3coS8kWTEBe/GPbRoxD9bxiEXWRUr9E+fvKyhELTVln9gpkvsInx90Atnw8U5Amo2GLlr2aP+NP0fpNw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710334735; c=relaxed/simple; bh=bSFQ6x++qyOcoKzfit8hgsY3myR8zf21zdavtZSurFc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BCCTWQL9kzWdZx/UBIj4KRbtcpVOc9EZtK9k/d5PzN8qcBJa4MNCmm1zxKYClxq48nZDNQ6Cl7lBsb9pvWuSwZtaXSXRZTh4VARFAf55KXfQ3I4i1pvJOPCUy4VmMiTdda9yRwXRKRo9Up8K07PzVPfJT6c0e+b0+1YRpXSipw8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=B1swGbGD; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710334733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JbI1Q06i15zBNLDlBPV6XMPyx/dQKcp3tORlZ+sJxOA=; b=B1swGbGDeP2D41xHyCbrI9YGZyRFZG38sp3JJYVsZWtrzfkw6OQMaZF+8MomXO3oczvdoD 1rbPBFOLBopcR9cqNb1SXSXYmUJ/NcazP/fxz6XM1zCdpZ12VsGhNgtOlpS0nTKDDdOe/d kAlNaLO7/raZfE/MFrb4ep133lJrnro= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-505-JLbUjwwnNaKfpbgL-Pza5w-1; Wed, 13 Mar 2024 08:58:47 -0400 X-MC-Unique: JLbUjwwnNaKfpbgL-Pza5w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5BDE3101A5B3; Wed, 13 Mar 2024 12:58:46 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.160]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BEA831C060A4; Wed, 13 Mar 2024 12:58:45 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id CBFCC1800D6A; Wed, 13 Mar 2024 13:58:44 +0100 (CET) From: Gerd Hoffmann To: kvm@vger.kernel.org Cc: Tom Lendacky , Gerd Hoffmann , Xiaoyao Li , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH v4 1/2] kvm/cpuid: remove GuestPhysBits code. Date: Wed, 13 Mar 2024 13:58:42 +0100 Message-ID: <20240313125844.912415-2-kraxel@redhat.com> In-Reply-To: <20240313125844.912415-1-kraxel@redhat.com> References: <20240313125844.912415-1-kraxel@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 GuestPhysBits (cpuid leaf 80000008, eax[23:16]) is intended for software use. Physical CPUs do not set that field. The current code which propagates the host's GuestPhysBits to the guest's PhysBits does not make sense. Remove it. Signed-off-by: Gerd Hoffmann Reviewed-by: Xiaoyao Li --- arch/x86/kvm/cpuid.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index adba49afb5fe..3235254724cf 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -1221,9 +1221,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) entry->eax = entry->ebx = entry->ecx = 0; break; case 0x80000008: { - unsigned g_phys_as = (entry->eax >> 16) & 0xff; - unsigned virt_as = max((entry->eax >> 8) & 0xff, 48U); - unsigned phys_as = entry->eax & 0xff; + unsigned int virt_as = max((entry->eax >> 8) & 0xff, 48U); + unsigned int phys_as; /* * If TDP (NPT) is disabled use the adjusted host MAXPHYADDR as @@ -1231,16 +1230,16 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) * reductions in MAXPHYADDR for memory encryption affect shadow * paging, too. * - * If TDP is enabled but an explicit guest MAXPHYADDR is not - * provided, use the raw bare metal MAXPHYADDR as reductions to - * the HPAs do not affect GPAs. + * If TDP is enabled, use the raw bare metal MAXPHYADDR as + * reductions to the HPAs do not affect GPAs. */ - if (!tdp_enabled) - g_phys_as = boot_cpu_data.x86_phys_bits; - else if (!g_phys_as) - g_phys_as = phys_as; + if (!tdp_enabled) { + phys_as = boot_cpu_data.x86_phys_bits; + } else { + phys_as = entry->eax & 0xff; + } - entry->eax = g_phys_as | (virt_as << 8); + entry->eax = phys_as | (virt_as << 8); entry->ecx &= ~(GENMASK(31, 16) | GENMASK(11, 8)); entry->edx = 0; cpuid_entry_override(entry, CPUID_8000_0008_EBX); -- 2.44.0