Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1904653lqg; Mon, 4 Mar 2024 07:17:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU0PG3y+jXFq+jBoLsn9OWr2RW+Hfwb/JtIrOqq/plwblmDEqONHyaVLMGxr0n+ohwZN6YINE7nYTd41lBOz8nfIC9prWiQgB+yC3EUPw== X-Google-Smtp-Source: AGHT+IF3Z8cbSCen9QAtxgF3WiLJIDo+IsUE8G34jJkXqsS6zTZpOYOFeqf5Dstf8JdGEAmw9TpA X-Received: by 2002:a05:6359:4121:b0:17b:f1c7:1521 with SMTP id kh33-20020a056359412100b0017bf1c71521mr11019374rwc.18.1709565425866; Mon, 04 Mar 2024 07:17:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709565425; cv=pass; d=google.com; s=arc-20160816; b=YGl41uDr0kMfDvg938qIuz+uzMXxhNgWAkYLiPcjK39s2Dtz69LtduvTU6P+PpkMMf jZudxH1l2kJgk8R8wNxzryl3NNngxMb8xt4AbrFBGjZ5H3wZX1nMHD9ph81WBuIJUFeE fsZtKfA4A3tyNQDBaPFFOMbapUVYOyArRSxNnqNJbZuIpzti7vS3vaapT+K3nNS60EhA 5J22RpHvTaugLJ6Ww/PBXvQNxDEOwGfD8hE3ZWgC6yZz62SUjAXHcInPisUbcDbXfayf lVyD7ojDQJJeGNgVzKrkiJ2gNWF0DTM1Eoyg7RfImFfHp5f9nyQ4ZSdoafeNU2R1q2NE hRQw== 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 :dkim-signature; bh=pFO6+UywViZZyvnPAa9tMMRLlhb9803+MwFU94Wmgk4=; fh=2AwDXTJSoZ7Z9PZKfU0baGOng8MHHWRfcYlb2TLLr5E=; b=GSdU24bL+Bd8NhhfDYoofvLFvByMVkBLsOVyyEquZwrQr91aexYoAOG6vV8GdtZfSV QsD+aLABxjCne0Ke+qARQpOre5qTTcZ3V/79npAEFUbtnSTuBt3ww7R9UikUOqCAXysi +jCkTlHXFPcxvbdGsN2FhDuZbGjrEM5PKsUwZcsHe/CJ1g9RTR9BXmlN+rfNg+zfqDTB yKJIaAIEmCbdD7c+G8TKW2Xse0Y0+o1xnpyB+YGrpg0OhvkS6EcTVtIJ2+CnGJzqcFYS sgM7HltjrFu/SGTWuWGp8W6srsvFEGFoKmuTYqmcPqJNYuOuxvQIvGApOGNniMda+83w R9UA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Kd4b+qkS; 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-90796-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90796-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s1-20020ac85cc1000000b0042ef806d090si927301qta.111.2024.03.04.07.17.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 07:17:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90796-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Kd4b+qkS; 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-90796-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90796-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8F1F91C23204 for ; Mon, 4 Mar 2024 15:17:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 973454D59C; Mon, 4 Mar 2024 15:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Kd4b+qkS" Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 2948747772 for ; Mon, 4 Mar 2024 15:15:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709565348; cv=none; b=jOoMf/otwhOrB2tiqK/lGbocGuYa9ZhqsHMq6xawxO6i1hHVohGDME67tXghpD/r7aKNEwtO6i2Tuh5fuQjUUCA8wSPr9y49BZ85amrHl0wW+TnVXc45r/DJEvOX5jLq7fix83z6v7tRc9mxNw+xnoMAliiINAXnGUCEUeyHPAo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709565348; c=relaxed/simple; bh=PHagvGZN49C8CopjtNuDmKmGFqr3kmXN7R8kWRH/HsA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nOVje8SJyfIG32kILBznAgsLyRXcDeHHLCJxSx5abAUKGRJdBjNt4J/mFuWwO+1tpQBkjKJ2JDh9p//xAL76jVBOAcEQ+bIMqqY4OcWkvsRIIvIQcdHRpuVmD7+02CHf7y+w8fB/Ch/b6xCxNZgAinYAwxtDM/mK1WAdCW9liV4= 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=Kd4b+qkS; arc=none smtp.client-ip=209.85.214.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-pl1-f201.google.com with SMTP id d9443c01a7336-1dcfc3ae5d9so23728415ad.3 for ; Mon, 04 Mar 2024 07:15:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709565346; x=1710170146; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pFO6+UywViZZyvnPAa9tMMRLlhb9803+MwFU94Wmgk4=; b=Kd4b+qkSPT44csNE/JIMN3qr5t0cBmih5H7hsQQpfsihY4rIBv+OLNhz/2uD9gcMa2 +5+0nBMfAxzZLlhm9SyuHLmXO1ifG1CT57cSFaV/lJXkMWeZH1VWVFH+ciC/0vk7VgtK vizuUJr0u2eA76d1aqYy8tI1MSxWxGfVM4el+ydURYfImxTE1seRKetCyevUToXbD3a7 abIjNEY/yXF8Y8etFIb5Kx/Myrk/t2NQBgWmvYzeFTPaGHIuOAUCiPjrtM0CiLQrpad+ BOYKWG2BtAj+iX1znxEwm3n54lLSpbhIE+1HDXwpq0pdDV68rjCKUx3nhvaC9hGZ2lRC H9Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709565346; x=1710170146; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pFO6+UywViZZyvnPAa9tMMRLlhb9803+MwFU94Wmgk4=; b=PR430IYtM426utBSZjmi4eMpaFrMT8VNhj3z5ychodGz9dgWG9lT3+U5NlhrCSeyN3 9RFAqc37C75b/vqYpavJHxnRJoS171E2e+tT5zKPNwY01IvLM6Ij6KtGKkahQmEqeVUt KEmBJrf8oZMtVVEz1W9deeZ9NnWzsDuF1lBeJU/yDcoqJRfGUT5Of0xsEsEriMDmhOBY vEToRqvSgfUuvW513TJm1TwiEihgTUeNcctwzRDqL2XqYLmsaYaccENj7Ef54sjxcpXe 6oFcp11H5LjV2MAiAQrxKviOtI51SzNDUpAswTgIMPK9xZGNhNBdmnXPcDM00LNal3pJ 0Lvw== X-Forwarded-Encrypted: i=1; AJvYcCUFJr7iR5uIr3aJHIX68BXBzOychjbzAJ+qb5SKuYCn0f7mnLOHe5Lf4o1fH1KCVvzY/kDd03Wq4pZYqlBt/ps7JPpMq0Ogay2xmsXx X-Gm-Message-State: AOJu0YxhLkLhqeVw/QZNqp/IR/ytTn0ZAJt6e5ZHAjFO9E/JrgJVaG6Q YIl7cnFJgS54PcvbYuyUXnpJa81tstXJbNe0qWUpnaDNWsbeiNskh+FfC02XwhJK0HURtmog3xY w0A== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:e5c8:b0:1dc:e9e:374e with SMTP id u8-20020a170902e5c800b001dc0e9e374emr91930plf.12.1709565346183; Mon, 04 Mar 2024 07:15:46 -0800 (PST) Date: Mon, 4 Mar 2024 07:15:44 -0800 In-Reply-To: <20240301101410.356007-2-kraxel@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301101410.356007-1-kraxel@redhat.com> <20240301101410.356007-2-kraxel@redhat.com> Message-ID: Subject: Re: [PATCH 1/3] kvm: wire up KVM_CAP_VM_GPA_BITS for x86 From: Sean Christopherson To: Gerd Hoffmann Cc: kvm@vger.kernel.org, Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Content-Type: text/plain; charset="us-ascii" On Fri, Mar 01, 2024, Gerd Hoffmann wrote: > Add new guest_phys_bits field to kvm_caps, return the value to > userspace when asked for KVM_CAP_VM_GPA_BITS capability. > > Initialize guest_phys_bits with boot_cpu_data.x86_phys_bits. > Vendor modules (i.e. vmx and svm) can adjust this field in case > additional restrictions apply, for example in case EPT has no > support for 5-level paging. > > Signed-off-by: Gerd Hoffmann > --- > arch/x86/kvm/x86.h | 2 ++ > arch/x86/kvm/x86.c | 5 +++++ > 2 files changed, 7 insertions(+) > > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index 2f7e19166658..e03aec3527f8 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -24,6 +24,8 @@ struct kvm_caps { > bool has_bus_lock_exit; > /* notify VM exit supported? */ > bool has_notify_vmexit; > + /* usable guest phys bits */ > + u32 guest_phys_bits; > > u64 supported_mce_cap; > u64 supported_xcr0; > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 48a61d283406..e270b9b708d1 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -4784,6 +4784,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) > if (kvm_is_vm_type_supported(KVM_X86_SW_PROTECTED_VM)) > r |= BIT(KVM_X86_SW_PROTECTED_VM); > break; > + case KVM_CAP_VM_GPA_BITS: > + r = kvm_caps.guest_phys_bits; This is not a fast path, just compute the effective guest.MAXPHYADDR on the fly using tdp_root_level and max_tdp_level. But as pointed out and discussed in the previous thread, adverising a guest.MAXPHYADDR that is smaller than host.MAXPHYADDR simply doesn't work[*]. I thought the plan was to add a way for KVM to advertise the maximum *addressable* GPA, and figure out a way to communicate that to the guest, e.g. so that firmware doesn't try to use legal GPAs that the host cannot address. Paolo, any update on this? [*] https://lore.kernel.org/all/CALMp9eTutnTxCjQjs-nxP=XC345vTmJJODr+PcSOeaQpBW0Skw@mail.gmail.com