Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp708927lqb; Wed, 17 Apr 2024 08:35:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVDHzYyd6Qp7Y2PIGPWGhiVSlkAj/AmsbuSLc6KBgCPNc562BN272/YHhlxEHEGMJUFlKbEMGjlV2FPynyni3eZbdQFt9mQB/K6FT2MMA== X-Google-Smtp-Source: AGHT+IENaNGqXBN42Lxfv7Y0AmyKWpdsK3AkoHgHUah1OIV7i+Ov4i6T+5sv9xhpUHWz0AAtLvie X-Received: by 2002:a05:620a:458c:b0:78b:cc53:3097 with SMTP id bp12-20020a05620a458c00b0078bcc533097mr22472174qkb.51.1713368143722; Wed, 17 Apr 2024 08:35:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713368143; cv=pass; d=google.com; s=arc-20160816; b=kOa8iZzYRVu7RwPG8iyU7RhvWCQaLkFe/PXhQTJn79CaJTc4kBfXJD3V6N4DrVfQqv OYSYc5SmR5PKdo7mpytWhsmeviA3NmIZw2gNvB4Xw9tpTt2+tidmVtGxCallyoc6h4eh Q0tetc0Ia/LGHma9ZTE+cjyhOx2h9cPqQceXHw5opf5QmZvUWF5yrsd5RjWOFCUQajRx CazMlK8VlUT3XUhxo7u0wrBGDMeSlOacO7AzJI4YATQwRUFueKv7d8X5QkqCEwCGP7Dr R4P0isGeQxizwj0eERSSQbYrhC6iH2yjHMEmZqYc4fTP5ORZvMGXk2QfOie/oi7qOQYT l87w== 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=T3Uwoo1D+A7Ab673wp0hlYFDcZEPH2tfTFOyRGJRlS0=; fh=fhNDg/rgS8N1tOOUFS+PxlxZhbe2WE6Cy8nO5yBhacU=; b=iFHvYe+Shy53ABbasLiI/FZInBeSNGkpMOt48ySbZ5Lo2PUtZv+CtpWmXRnEfG6DxG ZPwkQF/gFAUemYBzHiBLCww8xB/PMupW4I7Lzl6arvEgrj4c7QKOKdmv5IU5nedu/8bN Ss5AV+nIDMzIogW+DQPFN9qTI/OLg0wJ/O/G0cMLPmilRecG+68wL1J3CRH3r1IQYMSR BpF1YpR2dFopYtDwDumiiFK9DElvrqUw2eaGauu+5AMzB2A0HF7O4kUtemTN9/FoxPv7 DLuBMuzfNYdn8tPm8etbi+bRH+sn1Il/mYKxpeXfBxTDZD+yF3RsGOsGpIw6o15MrIw2 H26Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HdUkiF5e; 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-148817-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148817-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ya3-20020a05620a5e4300b0078ec311648fsi14640520qkn.364.2024.04.17.08.35.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 08:35:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148817-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=@redhat.com header.s=mimecast20190719 header.b=HdUkiF5e; 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-148817-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148817-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 708521C21AFD for ; Wed, 17 Apr 2024 15:35:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF951148FFB; Wed, 17 Apr 2024 15:34:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HdUkiF5e" 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 4CCA6147C7B for ; Wed, 17 Apr 2024 15:34:57 +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=1713368098; cv=none; b=Lhzl5Pj6nfiM+7zb05QfgqJROGvnAkRzFbpSgYJC5KDoInG0x4SgzYot+tUwep+SgCrV6xZ16BLbCERpJsHWZ6SJ84RU38D4USGTfSQ8XJG6i3Ufzbn+bVF6oWtymW2Zn3fRga+kp+XoZ70URJJBKXan/BDkMGwgFtbYE7uC6GU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713368098; c=relaxed/simple; bh=18C3fkjaGUjut87lyhCZwmA7W+1+Z8WNC7ozIOguMAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e1bNwgZ6a8HDYDVS5zNX+Bzp6LlsQ9m1mveeDUnx8hAQEiA2/hxdmoKv3LO7e7HqyjHMOr0KzlaKlK853cMwshj8Sc5cxulsB7n4tJfeM4x/JCQjcua6wJhztUYc/Dy4x+j+keMUcRQeMDMGoIp/FsFl4QmKFmTAn/RKYdmUUGU= 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=HdUkiF5e; 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=1713368096; 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=T3Uwoo1D+A7Ab673wp0hlYFDcZEPH2tfTFOyRGJRlS0=; b=HdUkiF5eBnIHQHKD2xqCHmR4CGAsy01WLLucd5jOfn8NLmAqwt/1OgZvhjPzDahqgSAEMb dOHUCkEuLYCoJ/FzgkXQFU3v55PR+zrDqos6FVysnGyY2UFrgMJOQ1PQzX8rcHif5vLRz7 ocdKgla2HjdHoOu5Q/dzeHv1641PKIc= 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-390-S1qZy3LON1i0HI-0c5KOUA-1; Wed, 17 Apr 2024 11:34:53 -0400 X-MC-Unique: S1qZy3LON1i0HI-0c5KOUA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 717CD811000; Wed, 17 Apr 2024 15:34:52 +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 40BF1581DE; Wed, 17 Apr 2024 15:34:52 +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 5/7] KVM: x86/mmu: Introduce kvm_tdp_map_page() to populate guest memory Date: Wed, 17 Apr 2024 11:34:48 -0400 Message-ID: <20240417153450.3608097-6-pbonzini@redhat.com> In-Reply-To: <20240417153450.3608097-1-pbonzini@redhat.com> References: <20240417153450.3608097-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.1 From: Isaku Yamahata Introduce a helper function to call the KVM fault handler. It allows a new ioctl to invoke the KVM fault handler to populate without seeing RET_PF_* enums or other KVM MMU internal definitions because RET_PF_* are internal to x86 KVM MMU. The implementation is restricted to two-dimensional paging for simplicity. The shadow paging uses GVA for faulting instead of L1 GPA. It makes the API difficult to use. Signed-off-by: Isaku Yamahata Message-ID: <9b866a0ae7147f96571c439e75429a03dcb659b6.1712785629.git.isaku.yamahata@intel.com> Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu.h | 3 +++ arch/x86/kvm/mmu/mmu.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index e8b620a85627..51ff4f67e115 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -183,6 +183,9 @@ static inline void kvm_mmu_refresh_passthrough_bits(struct kvm_vcpu *vcpu, __kvm_mmu_refresh_passthrough_bits(vcpu, mmu); } +int kvm_tdp_map_page(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code, + u8 *level); + /* * Check if a given access (described through the I/D, W/R and U/S bits of a * page fault error code pfec) causes a permission fault with the given PTE diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 7fbcfc97edcc..fb2149d16f8d 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4646,6 +4646,38 @@ int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) return direct_page_fault(vcpu, fault); } +int kvm_tdp_map_page(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code, + u8 *level) +{ + int r; + + /* Restrict to TDP page fault. */ + if (vcpu->arch.mmu->page_fault != kvm_tdp_page_fault) + return -EOPNOTSUPP; + + r = __kvm_mmu_do_page_fault(vcpu, gpa, error_code, true, NULL, level); + if (r < 0) + return r; + + switch (r) { + case RET_PF_RETRY: + return -EAGAIN; + + case RET_PF_FIXED: + case RET_PF_SPURIOUS: + return 0; + + case RET_PF_EMULATE: + return -EINVAL; + + case RET_PF_CONTINUE: + case RET_PF_INVALID: + default: + WARN_ON_ONCE(r); + return -EIO; + } +} + static void nonpaging_init_context(struct kvm_mmu *context) { context->page_fault = nonpaging_page_fault; -- 2.43.0