Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp447853lqg; Fri, 1 Mar 2024 09:53:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUGrLgO5z5P1b/7nHn3TO6AwuAhJzboKSqXjZvnzODoIRUmjP4yGec6mf0P9rpUhJMetVxy6YNhgrpkrzqc4h66/V4MTedPY7XH8ePEEw== X-Google-Smtp-Source: AGHT+IHO03uGr5HfslWY5+Boq0kLyIuKNaOB5jMD/OS/A8IMrnRBVbOhTGrWl9EMMCAaESuXF3K4 X-Received: by 2002:a05:6e02:1ca5:b0:365:b8f9:6a36 with SMTP id x5-20020a056e021ca500b00365b8f96a36mr2665141ill.32.1709315605467; Fri, 01 Mar 2024 09:53:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709315605; cv=pass; d=google.com; s=arc-20160816; b=xQVi9kcK+gNk7WSR43O7LhjjQoHs2/X4ZMYHRJYbql6lLgnqohTWAUnOR/plbFIhgz dFSPxq4npYmml2W8E434Q0HEkn+lGr+bvtX+ml8fbkXFrOS7tqSufT5BOqzXZ54S86+e 2MvIglXlKq9uxCwCW58KFU0luRghCPayXfTePG+Cvrkf4HCXgo5k8rVNDXfpNZjb3rX6 WE0Ern/YSSed/Np6fWpJw4n0gUpoebeotsF/aIw/fWZmJEzrrIqEiwQALn/6tyLQZyzA koYaGYWmxXFQb9V5ailnQsZZ1coSGM5AHo6+Jwy3OkSR2XThhFTK7VhqZVReyg7WBE4d UJKQ== 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=m8c8+VlP14TZTKLndPqOtWYWm7ovBQQB9BnPsms6acc=; fh=niAehSMJk0S9tiAUu7wa5Eiw/RfVXqQX6b/Xpcsvz74=; b=belQrf/AOkarAgZD2fub5o4v1wI3KlZ1WV39P1sWOiA+zGwUSwy2PMT5w93HAhBdTe cXiRsQa9M40uo++WmpDRT84WABG4kqUnNhCPAYUjJ8cPFVeCXE16xd+i7ECs6DiGAgvQ eKAXJ1c0oj6Op/rrNkWpFv8AXywzGBFOlox0ZFywevGNmGfQ53N/2QViZWabuEMeIo/0 +M3N3t7q4f1LWS4psNdU5ebVA/nHmNWhJfA5CgCHjkKs4Nv6Ax+jywSbUygkJ/MQnfrO ItyTuejyHFibw+JhgSz4JipvrxftIqyCKSSxyBt+E7fpGE7CYBGtwpsSK1YjvZz6JYfk y+TQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QWyc+v2g; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-88829-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88829-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z129-20020a636587000000b005ce06ca3538si3831795pgb.873.2024.03.01.09.53.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:53:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88829-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QWyc+v2g; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-88829-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88829-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 37228B25FCE for ; Fri, 1 Mar 2024 17:31:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2574C38FBA; Fri, 1 Mar 2024 17:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QWyc+v2g" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 71CB211C88; Fri, 1 Mar 2024 17:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709314188; cv=none; b=AhUp6G/Ofonb9TyvaiBokzIPJV9daW2EZ+G5TNMlzuZuWLxRj9jlhYAQAQUivTWWyZcvT/DN0qKHgG03H1uf++Jx3jWgOM6AO/WPUaDgIBPDgobkFLQQo8i1oGuRsYvLMbtYN443Fsph2E5r4Wh/et5qTPzZstt3ptKSX7e3ucs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709314188; c=relaxed/simple; bh=7zgHhzoa1cUt+d95umTjGfJYGkjrgy8xI3Zn8UQJKIo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X/8DAndSmyjDrg2NovLqnT2Pfc4JiwitCAN+aRoShgZzoczX0MhCVijj0+p6Rvfjug/kvYki0EAWRqpBclrhp2jXmUeeATeY4TG7eZuwl0lemziDKlbN1YSr3gDShuQZ59/Zqf3746gS+S2oE/89z6crYab3KevB0kRFxdPa/Rw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QWyc+v2g; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709314186; x=1740850186; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7zgHhzoa1cUt+d95umTjGfJYGkjrgy8xI3Zn8UQJKIo=; b=QWyc+v2gQcKo2NE42H/ottxHRk9cVzUTvuDaqvOvezlkPh6/G0FPUpa3 Wyynh51KYKA+lu0sv95BQTOY2LtQM77wCL6wJ5rvshKaxZcCXFIRjXknB Ne+t6Dvxa7E0+yePTBqw1B/KSItfLcbb0RT/96VOobTWVkc12xIKLAWrW rxQH6eB6lKwsyDVDxWHeLsWheHJSr3hwc/9hU5Spb0PI5S0IRxS/2egYN n6cL4wYGfOJjOV64io4HJ5LIKhqtnKG0gp2adZyMjBvLPOIziRfTOxfnf 4eqIodnflWQmoLgbadJyDMHD6BsREQQyehCnkvP2bFMHcfcw0GzL9rE/n Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11000"; a="6812421" X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="6812421" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 09:29:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="12946563" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 09:29:26 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Michael Roth , David Matlack , Federico Parola Subject: [RFC PATCH 5/8] KVM: x86/mmu: Introduce kvm_mmu_map_page() for prepopulating guest memory Date: Fri, 1 Mar 2024 09:28:47 -0800 Message-Id: <7b7dd4d56249028aa0b84d439ffdf1b79e67322a.1709288671.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Isaku Yamahata Introduce a helper function to call kvm fault handler. This allows a new ioctl to invoke kvm fault handler to populate without seeing RET_PF_* enums or other KVM MMU internal definitions. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu.h | 3 +++ arch/x86/kvm/mmu/mmu.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 60f21bb4c27b..48870c5e08ec 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_mmu_map_page(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, + u8 max_level, u8 *goal_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 e4cc7f764980..7d5e80d17977 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4659,6 +4659,36 @@ int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) return direct_page_fault(vcpu, fault); } +int kvm_mmu_map_page(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, + u8 max_level, u8 *goal_level) +{ + struct kvm_page_fault fault = KVM_PAGE_FAULT_INIT(vcpu, gpa, error_code, + false, max_level); + int r; + + r = __kvm_mmu_do_page_fault(vcpu, &fault); + + if (is_error_noslot_pfn(fault.pfn) || vcpu->kvm->vm_bugged) + return -EFAULT; + + switch (r) { + case RET_PF_RETRY: + return -EAGAIN; + + case RET_PF_FIXED: + case RET_PF_SPURIOUS: + *goal_level = fault.goal_level; + return 0; + + case RET_PF_CONTINUE: + case RET_PF_EMULATE: + case RET_PF_INVALID: + default: + return -EIO; + } +} +EXPORT_SYMBOL_GPL(kvm_mmu_map_page); + static void nonpaging_init_context(struct kvm_mmu *context) { context->page_fault = nonpaging_page_fault; -- 2.25.1