Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp312738lql; Mon, 11 Mar 2024 03:41:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmuiimDtJ3C+YKJUeMMNtUZ/lB7saJDo6jwVad4nxX++j9jF5VDafHhmJHV+WzufXPBDATL0IOhwJZ4BFRMjEFWxCWYryYVjys3zc5Hw== X-Google-Smtp-Source: AGHT+IF9LvpDLLeD7BFySsKML+zKlXd30roX3WAggpJvS6yqLZhKDQwdoGMuLluC4GS6KmD253kE X-Received: by 2002:a50:9b17:0:b0:565:a6a4:5f7a with SMTP id o23-20020a509b17000000b00565a6a45f7amr4862517edi.4.1710153697701; Mon, 11 Mar 2024 03:41:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710153697; cv=pass; d=google.com; s=arc-20160816; b=bKjqQeT+aIIWMIrmcfW3h+spm6H2mlqvH/+/gLThYMnBx3rW+0upexfGJSOP4F3k7o mHMFyiedYw0Xf+KU+Xq7TUT+cCmAUQgrUchXGemACTiPHqfSdOdnqTkWfbvdHpFPCPSQ K9PpGZkxSqyvhmWwxsiZXZHB0tQXXXUwy86MUTKscdRuub3aUSbYY9BZvfrDYo1fIATY km/nj2bVxgV10UDu8E/2l4YPLHyMlhOigojpQYemmA70rF+pjiTpAHz47F2e6G9d8wKa wywuKhFN68CMGWGA9cJAZZFv89wTsnuwy7+oxeEQSwOtPiDXWVtSGnyROpM8fhuCs8JL Qaeg== 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=hlLFoX1P5jTKtS2weQZan201tuv3XXgj03SclaGMt18=; fh=xIEQLB2inP02AVT4siOgme+TLzVja6G/aeC4gwiWfh8=; b=sUo7TnVjC1PoZxH1YP/Dbcz6iyPFZjj/gKRJgzT6+aONm6awJcGWa4vNxISmFJAGbx hhg3oPaPH24rAKBhh2MWotSJyHL6ek0Ma1UKsl9A3vzAyxGzy2i7impWvLrOFjIIeH+4 4Wcd88FN6uxVg2J58tf37O6Ct3GzOTEw7Le0ElF21hhKDIOpG/gSH0fOs25J1ZnSynnx 3wm/4wma9M6cq9ESnTCHXegUBqpVBcw+YZogEvAs82EiapmuohcxYWMwFGSRGP++YkoJ WkJtyN5cHsnWq/48EHIHfNrgG/3WK7LoXUVYYujBEAWLgxjGhg7zKf6hBXBGYqyFXafg SYWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YNnpRHoA; 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-98707-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98707-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u18-20020a056402065200b005666a9de1f4si2353494edx.545.2024.03.11.03.41.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 03:41:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98707-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YNnpRHoA; 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-98707-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98707-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 70C301F21889 for ; Mon, 11 Mar 2024 10:41:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A90E237169; Mon, 11 Mar 2024 10:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YNnpRHoA" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 24C728494 for ; Mon, 11 Mar 2024 10:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710153685; cv=none; b=N8fidFgOEqllciSiyF7M+dagRLSHvRDJpoBeMdrFz+Unk+CsRPgHQozjbIcjF7r7Tkk/QYrSWeByuBPj/hEEup5kc1NDChJhnIw0HHNbX3uFfT59E/DBtnTGAKZ8uLGxyCvkKLCAXd8SYeIHyYhg4JhPZHSklIah9mLrp4Pb4BY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710153685; c=relaxed/simple; bh=MSKDyAI0xCcsSThDCwZZVUd6rs3dtSQH0t2OgHt/rGc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sWjRJ6kHIlTybpz6R7KOX1Hu8NHLQzxPGp1V36dmUnb0wPAFydAJYi8K+U1C6ijZ0DyWHrSs0Qlrg+oL3rqL+Z7eGOEwBrGfX7q/Gp7ERch7shpGcCOrAEgitAaENV1bIa/Q04gZo/5UfFUnkqxJrPQqfsP8hngcEBcgQmrVEm4= 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=YNnpRHoA; arc=none smtp.client-ip=170.10.133.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=1710153683; 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=hlLFoX1P5jTKtS2weQZan201tuv3XXgj03SclaGMt18=; b=YNnpRHoAeE5re+WVRT2rkYpCpiUOJrgF6M+wzRTxogZDE9kK+PZUBvNlhn6+/63YczeFzp 8FZ0ZOfmfCY9x8frp2N0Srs0zVGkD9usroZZnKlXEjz/IdP3hksZpJG69gT3F61nLDgxrQ HtgVAJ9FvyKMTIrYr7QJYzHXNlrG87U= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-132-kXFcFobtOHuxPc7jyORB9Q-1; Mon, 11 Mar 2024 06:41:21 -0400 X-MC-Unique: kXFcFobtOHuxPc7jyORB9Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 C94131C02D26; Mon, 11 Mar 2024 10:41:20 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.160]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 85A3D8173; Mon, 11 Mar 2024 10:41:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 639251801A8E; Mon, 11 Mar 2024 11:41:18 +0100 (CET) From: Gerd Hoffmann To: kvm@vger.kernel.org Cc: Tom Lendacky , Gerd Hoffmann , 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 v3 1/2] kvm/cpuid: remove GuestPhysBits code. Date: Mon, 11 Mar 2024 11:41:16 +0100 Message-ID: <20240311104118.284054-2-kraxel@redhat.com> In-Reply-To: <20240311104118.284054-1-kraxel@redhat.com> References: <20240311104118.284054-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.5 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 --- arch/x86/kvm/cpuid.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index adba49afb5fe..c638b5fb2144 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -1221,26 +1221,22 @@ 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 - * the guest operates in the same PA space as the host, i.e. - * 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_enabled) - g_phys_as = boot_cpu_data.x86_phys_bits; - else if (!g_phys_as) - g_phys_as = phys_as; + if (!tdp_enabled) { + /* + * If TDP (NPT) is disabled use the adjusted host + * MAXPHYADDR as the guest operates in the same PA + * space as the host, i.e. reductions in MAXPHYADDR + * for memory encryption affect shadow paging, too. + */ + 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