Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp495490lqt; Fri, 19 Apr 2024 02:00:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVInQ90nqtqkST3d5NyNa2zgL1cUtVemFdxNyN/31cBKXdawUuSv9BNSIjm5zqaaCb9EjJuwoIgA2pMgdeRV9rAgQ5dJpXcXGrWPKWYZQ== X-Google-Smtp-Source: AGHT+IHZzRUdUCWDpM6ftI7Qbu5AShXietr92WCOD3xXQ+vWW7idNTynOc+wrqfEtqlV+sSP6PuO X-Received: by 2002:a54:4599:0:b0:3c7:ec8:8eb7 with SMTP id z25-20020a544599000000b003c70ec88eb7mr1301308oib.27.1713517217045; Fri, 19 Apr 2024 02:00:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713517217; cv=pass; d=google.com; s=arc-20160816; b=SPxrpIw9G61cmVcvZ4xoemcgHw8r7LYVkjy6fRDe/5lmtHiG3drjOjKdSJBH52kGiR B83hdnt4cy5D20ikWDOuDGaLu0GyGvIVhi0Z2uhU5exx4OozUFfnpPZXT4gLFqpRVaK7 Cs0YP0wxd4obWluele+Q0urLsc/jU1NckRJ0hBi+42zCmyI9HiSdcbA+WwGQaZC5Yi1u 62oSPpN+Rh3r3Lv0hHHn39FbCCWgyKHuqMofNQoS8uzK6wf7RgvJb9t5beUKq2HLGS2Y gA/iS7KZzb5FrfuzUQIppq7u+oO9VNOBHtct0wI50QDrrgneZ6ipb1EJMZwQYkSIK/Mn qTOw== 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=otExSoiFgVMzLYgIYpvIwimsI5D4FF0c+uBWyLnFbGw=; fh=fhNDg/rgS8N1tOOUFS+PxlxZhbe2WE6Cy8nO5yBhacU=; b=K2OirUusyfpkjH+cJy/o2IkFAL2GZ/R4q2OJziVnizEF84QRaq+9/+ZaYVaBcwQ4n9 gkhE3EehW0372swCAa6hd8f10gT8g3Xlc8H+JtoKDjeArF0PpO1H4mAmrKbZbNhHFe6Y 3tzSFxGxOFmvtfrNbh5d21EmOv3FZOHupg9gtCytccTEijEJp2UAtf3RXRrSfkaVwqme fD9hDHr7OECfdOxiMESHNvGl97RZs6utKfx9w0XiPrphWtp3DVkDVnzgK+uivASP3Wf9 qseFXr1QMELt/5yFLY6Tz7ftJsPWpqGzgmf1GXz+bANBMxYPTmG82tb6i5flKfD+98ud lofg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QrhhNx24; 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-151199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151199-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r13-20020a63d90d000000b005f3f312f17dsi2859636pgg.593.2024.04.19.02.00.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 02:00:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QrhhNx24; 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-151199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151199-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C7B54B20E5F for ; Fri, 19 Apr 2024 08:59:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31C7A762F7; Fri, 19 Apr 2024 08:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QrhhNx24" 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 05D42745C5 for ; Fri, 19 Apr 2024 08:59:33 +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=1713517175; cv=none; b=DxZLfAk/71AodjnfjhIjkBIAgCGMSBh/pBJN7nSsMEpAjFhqwctXRgHwhgGbgfAK74NFi+7V0f0JKAbL1JVbVneU9TFzcTupmh6KnEtSh1BPgc8W3nKVVNDgmfegD5mYQNtzyHM5YNYte6WChNst6O4uXsDbN+i/fFjkOeks4X0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713517175; c=relaxed/simple; bh=81mARjUpw+KVyq4vQ1KQan74CjOK+s4dvQQ+ghYUVsU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EXP15XBU8vj8YCqRUebGEzIt0BTx6lOzfHKtEzb0xNnpfc13DA8iZQUjoY7JRT2ePyHx1+Uu1tpmVXVfDnmP2LXNI1iiaGtqg2yYIyIqZjPVq+vHmWeNC1vZG/VwgAJhtQ9Lz1J13VjK4N9QMkmvRR0ouS0xV9I325msMljIZ8U= 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=QrhhNx24; 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=1713517173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=otExSoiFgVMzLYgIYpvIwimsI5D4FF0c+uBWyLnFbGw=; b=QrhhNx24N0hyEewHwPG7V4v+UNcUa6IRO5irJRQsWzosUYfzJUqwuDEPwRnCmjL4+1SDjF lGesDi2jC0jdkKj9JYt7DUmBKS9kZH2O/j+KZ8lMx2pxEx3lQaqT4jOJUL2oEa7txqdeyj z5KZfRXHwScdsd0QTHVJrmLTqObwubQ= 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-303-5ngrdknaO0GW3SWem-b2zA-1; Fri, 19 Apr 2024 04:59:29 -0400 X-MC-Unique: 5ngrdknaO0GW3SWem-b2zA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 6B59D8ABE0C; Fri, 19 Apr 2024 08:59:29 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AAF620368AC; Fri, 19 Apr 2024 08:59:29 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, xiaoyao.li@intel.com, binbin.wu@linux.intel.com, seanjc@google.com, rick.p.edgecombe@intel.com Subject: [PATCH 4/6] KVM: x86/mmu: Make __kvm_mmu_do_page_fault() return mapped level Date: Fri, 19 Apr 2024 04:59:25 -0400 Message-ID: <20240419085927.3648704-5-pbonzini@redhat.com> In-Reply-To: <20240419085927.3648704-1-pbonzini@redhat.com> References: <20240419085927.3648704-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 From: Isaku Yamahata The guest memory population logic will need to know what page size or level (4K, 2M, ...) is mapped. Signed-off-by: Isaku Yamahata Message-ID: Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/mmu_internal.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 9baae6c223ee..b0a10f5a40dd 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -288,7 +288,8 @@ static inline void kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, } static inline int __kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, - u64 err, bool prefetch, int *emulation_type) + u64 err, bool prefetch, + int *emulation_type, u8 *level) { struct kvm_page_fault fault = { .addr = cr2_or_gpa, @@ -330,6 +331,8 @@ static inline int __kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gp if (fault.write_fault_to_shadow_pgtable && emulation_type) *emulation_type |= EMULTYPE_WRITE_PF_TO_SP; + if (level) + *level = fault.goal_level; return r; } @@ -347,7 +350,8 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, if (!prefetch) vcpu->stat.pf_taken++; - r = __kvm_mmu_do_page_fault(vcpu, cr2_or_gpa, err, prefetch, emulation_type); + r = __kvm_mmu_do_page_fault(vcpu, cr2_or_gpa, err, prefetch, + emulation_type, NULL); /* * Similar to above, prefetch faults aren't truly spurious, and the -- 2.43.0