Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1173042rbb; Mon, 26 Feb 2024 00:33:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXgwBeDYLmCjpyaCRgDlueOM5bPG9aHWZBDz04IaN+yuwITWR69RNFC9+6CUKKEV0BCZnxWZY3rtXr4O7OCx0OZR7YBj/DN+LyEc6fueg== X-Google-Smtp-Source: AGHT+IHwCdrEaGf8mqtx3QB3uhLoc28cjUzbOkMdWqu6OjoW3ysE+xZonvA7tn05LfsVSh7V4p1f X-Received: by 2002:a05:620a:1596:b0:787:c6ca:e15b with SMTP id d22-20020a05620a159600b00787c6cae15bmr5282356qkk.21.1708936419492; Mon, 26 Feb 2024 00:33:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708936419; cv=pass; d=google.com; s=arc-20160816; b=nUNBqOkHcJ7K+E+OAfyN9NOlZCfQKfdoum31ytaIx4lFTsabIX++kBNhKSbNtU8iKK +2KTeALTAOmK7veVpijNGG6s/rUHKd+4kRaJ9zu18foJw1Po/6juEL7ejzYdyBxyg621 oXfaszT4IJgJUKUSZXVtWT+MC64oREowhyHJx330Xa6HXtjY2r6G9g1bXpVAjAkUamM4 k690Wat6yMI6dh4nxW3D6pdjNWEBW4jAuxqmJPFBb6q7uaVSFFBZBpTYftWKlDh1SaST ZcJpt6a6sEzxQmj0k3b7qbXWMxekyPbl82QXndlCxUeNhpAtr395+UuqxNl5Zlbqvurb JuLA== 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=sWisP1oF0jYjSwTkHzCijbyYbjD34f4AsHQe0ODvwkA=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=IXQyECfChKFZNYPugCHRayccnWkzR9gGuKlGgwVKGZgBImgIOT6g1oTWWsNCA4/6ca +7Rak6kjqHDtubyVlBJPhDRe7RbRU/OebFghBCrXSMKAhbO0x8xa5AifBELXXtIk9OjS dAS5GkhV3CcEh8Yi6tE/ydW+dJ/b4D9ehZpea41WzDv5lFIPwClI5ZUx9QfsqYHvJ5Ax 4V6rsLW7qH8tZAqVp4pD43WoH1inH5xRa9LGyuSKswETW1Vpf16/ITKEUMieSoAl/MWt LfQclCfHVxQCovWOJ/vP1E0jh4Krox3CeGQbJbejRfanCL4FE5tyEMCfRflD77BhHMYv +nPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aj5qsrUs; 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-80778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80778-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l5-20020a05620a0c0500b00787c0bb00ecsi4543356qki.126.2024.02.26.00.33.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:33:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aj5qsrUs; 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-80778-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80778-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2E5B11C21DFE for ; Mon, 26 Feb 2024 08:33:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69DD353E06; Mon, 26 Feb 2024 08:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="aj5qsrUs" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 7010951C4C; Mon, 26 Feb 2024 08:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936070; cv=none; b=WYQTY+BDKmL9DtW3m6Ui+zw9b0+77douwVH3Bwc97w4YarW0/ke7fOf0MWFwFtdMJP+LvqzVM1XvbNQuOd2x7h3DeiEp4o5pqRvtvv1Jx88SRnV0QGeSMNDK6fTx9PGH1Zc/WjivMTkllaEFuSMsOOT2vO45GiRdMjTNosuKHg4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936070; c=relaxed/simple; bh=o8YPZiq6LeeZQGwQQQuIE5wqxkP0AxPJNMylilPEjus=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=POK9SGWXNt5Pwsg8gV1AZkU3XtTILmPlmFpI5BibedFfnK1JgWj7qyIDW9FAyMC9JjODoEGmUe+cF0zj+ajF5vJNGbtzMzWM1wzv7OrNxyCaFTgAfFLpuLVSqwRv574d0gCiPNaLHUASTiaUGniGbXPwwczEw3+ju6hsnOrMilk= 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=aj5qsrUs; arc=none smtp.client-ip=192.198.163.7 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=1708936068; x=1740472068; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o8YPZiq6LeeZQGwQQQuIE5wqxkP0AxPJNMylilPEjus=; b=aj5qsrUsb0uB8pdy59w+SY8cx0gRe8kKqrf8ZYPVrwbz9hnCAOmktJmO kTXuh3VyIqc1hgpzb5sDU+hAtP9mDnWEoS21FYufyDUPq6bcjHOtYONl3 +QQFzsm/1KWbp/HOMtQ+pw03csWPVaFzC1K/+VFdho9uz5KzmzYdchFi1 QjS3i8FKtjYafwk86Rk44pHbvVk6SIeQuOVYsG6f6nLnQCJwsItL5XuUq 4XUVnRSGWuJhL46IFluOpZQAQIT12Exjg/KHVmDmtpYslZboM1c8tBFJJ mn1MpLOQX3+gMUclX71+AKnrIItX5lpK9hNJtacZUUQ6Nm12yUZ4PQ7Ge w==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="28631497" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="28631497" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6474348" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:43 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v19 017/130] KVM: x86: Implement kvm_arch_{, pre_}vcpu_memory_mapping() Date: Mon, 26 Feb 2024 00:25:19 -0800 Message-Id: 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 Wire KVM_MEMORY_MAPPING ioctl to kvm_mmu_map_tdp_page() to populate guest memory. Signed-off-by: Isaku Yamahata --- v19: - newly added --- arch/x86/kvm/x86.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 48a61d283406..03dab4266172 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4663,6 +4663,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_VM_DISABLE_NX_HUGE_PAGES: case KVM_CAP_IRQFD_RESAMPLE: case KVM_CAP_MEMORY_FAULT_INFO: + case KVM_CAP_MEMORY_MAPPING: r = 1; break; case KVM_CAP_EXIT_HYPERCALL: @@ -5801,6 +5802,31 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, } } +void kvm_arch_vcpu_pre_memory_mapping(struct kvm_vcpu *vcpu) +{ + kvm_mmu_reload(vcpu); +} + +int kvm_arch_vcpu_memory_mapping(struct kvm_vcpu *vcpu, + struct kvm_memory_mapping *mapping) +{ + u8 max_level = KVM_MAX_HUGEPAGE_LEVEL; + u64 error_code = PFERR_WRITE_MASK; + u8 goal_level = PG_LEVEL_4K; + int r; + + r = kvm_mmu_map_tdp_page(vcpu, gfn_to_gpa(mapping->base_gfn), error_code, + max_level, &goal_level); + if (r) + return r; + + if (mapping->source) + mapping->source += KVM_HPAGE_SIZE(goal_level); + mapping->base_gfn += KVM_PAGES_PER_HPAGE(goal_level); + mapping->nr_pages -= KVM_PAGES_PER_HPAGE(goal_level); + return r; +} + long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { -- 2.25.1