Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp443236lqg; Fri, 1 Mar 2024 09:44:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWZmeA3qoA8bZhBr8JCH4jj9o2QrbVaKsPjLnYRJrmMBglhFQS9zuAMB9IJBU/bageTF+foPU/gN92IcIerwrx8IERCbX1TE+1vd6rRmA== X-Google-Smtp-Source: AGHT+IGqwSmEw30hlirvkiM+/0L/q0G4pIcumI4hEUq8/EaOsuiAhze2hifPCjFaa4wvVBFRxK1e X-Received: by 2002:a17:902:d4c9:b0:1db:f811:66f7 with SMTP id o9-20020a170902d4c900b001dbf81166f7mr2687960plg.60.1709315042978; Fri, 01 Mar 2024 09:44:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709315042; cv=pass; d=google.com; s=arc-20160816; b=AKK1F90KUTxUmG2Szw/suxXQzUAnGEmiKCfhFY6+d8ryjytN6M6aoi4AkvUUEDTs6t YYd/JxKiePfVuD/bKjq9WbHAT5jdTlX5D4vyfTa3PXxIEH6oY8vzpQ6KzSgvE8TMeh1d UvN1LU5LgMa4eDihpZl//Sq9X995g+NatcvNjuwDH037/n1o6+i3gfN6Ff2o9AyjUMAv n2RPco9nIcsCqk+mQxSKYMBGF0zRfOzHtReTygzf2JzziP4dihUD07x8iwdVge/JLCvV 8MCQIjOi5q97vDrM8ll0PsXdrIdv+kAre683UeIsNQziHrY0ub5t+3OKfy5YrgnRUPpZ StTQ== 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=3sJt4Q/IX4/mGXWiK3yB5ty+jIAkrKUtKFOUEp99ik4=; fh=niAehSMJk0S9tiAUu7wa5Eiw/RfVXqQX6b/Xpcsvz74=; b=BbFUJ+Gat5o7VPi2esAopC3LblkHBjlmvYfiu3P4DR3O7nn00OXE2m6O2jkRO0QrDS 3Xszr0DFF6yNv2Y7y72LK3t9nslwLTn6U2ZpCPXp8vIaqEF8TUhxEw2S0Qz6y6+prhUS gYy6GD8+9hyr8hurAe+cT8emeXGquYR8FjLPCe9Mcv3WAt95X6YVZ6gC4bzIMSwMgfrK QlKdRRihByWkibHYtEYf80CidYicxAVIG0Wgu98wajAJaFR0thj8+zIK3bxIzwfJayfM saTmfaPgBr8vVfUTjm7NRrzNNkwqHO0yhbzPK89bpJh2Jhqtlc52d/y4tqsWwFP8T1NJ 9/sg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ioruVSok; 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-88831-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88831-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t2-20020a17090340c200b001dc5676b43csi3938653pld.254.2024.03.01.09.44.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:44:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88831-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ioruVSok; 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-88831-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88831-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1549928A694 for ; Fri, 1 Mar 2024 17:32:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03E023B1A0; Fri, 1 Mar 2024 17:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ioruVSok" 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 620AA36135; Fri, 1 Mar 2024 17:29:48 +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=1709314190; cv=none; b=uU7PUEr/xDMjrZ6v2a8aiyqZPQ0e+pa0+tdVQug6IfUio+kXEvKWLCd1OkhTdKhcstl4znL90peCKH0D4Edirs2hVIKtjL+SJRd+bEayJw+5B7GgetmovN/ZGjhaLIsVeLh4AZvUt8hGvvIczTJIMdZ6mu4ritGSj1G1BSJGM2c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709314190; c=relaxed/simple; bh=4JuI8MhcUjFoTdzx1jxF5qxObLAyf716TjE4SfN0UR8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AbOhvBnyyPJZePSxMERcA6su7p8w8Y7c4N4e6m1wQi9xUaraBtBM1FCgsSUFleeRQCaqzt4T6PM7Al0D+u5wut5k4Fg8BlErFBXhzMlim9IRkMa+BE6VbX6nz0tALNxR886fcp0dS50OMYZ8parK4RthABMDNuLNqDQpWG9rZ5E= 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=ioruVSok; 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=1709314188; x=1740850188; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4JuI8MhcUjFoTdzx1jxF5qxObLAyf716TjE4SfN0UR8=; b=ioruVSokUA/DfuEdEp7rqk2zzcCrLJrdammXNqJckrsGfccHDsVUZG3d 2B6B+ABUu/q+vOyN6I/ENlPDG1JwupVYxcLbnjw2o2lLqs3feyk/A2/ru QC7mcsPGU4TavA/Uia5FpjoAXptadSI+2iIao34rsBA6mrUlp5HQ9tXP+ EnOnAXd6ox3ybHqGeOwo+FP0UZrLBpkuvqI6tRMdFNYkfEhBV7f1Af3hF I/DS3/lDr3uK7e3ACp2DzmBFBb1xy4ETYQWmh3akx6EENT+O3ZsYLYpo5 Mjgl1khkj/2rnXDxqaOwMCHMW9cZmQCGEy3TvfEfEKPRpr4yLKc5bFNVa w==; X-IronPort-AV: E=McAfee;i="6600,9927,11000"; a="6812433" X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="6812433" 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="12946571" 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 6/8] KVM: x86: Implement kvm_arch_{, pre_}vcpu_map_memory() Date: Fri, 1 Mar 2024 09:28:48 -0800 Message-Id: <66a957f4ec4a8591d2ff2550686e361ec648b308.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 Wire KVM_MAP_MEMORY ioctl to kvm_mmu_map_tdp_page() to populate guest memory. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/x86.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3b8cb69b04fa..6025c0e12d89 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4660,6 +4660,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_MAP_MEMORY: r = 1; break; case KVM_CAP_EXIT_HYPERCALL: @@ -5805,6 +5806,54 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, } } +int kvm_arch_vcpu_pre_map_memory(struct kvm_vcpu *vcpu) +{ + return kvm_mmu_reload(vcpu); +} + +int kvm_arch_vcpu_map_memory(struct kvm_vcpu *vcpu, + struct kvm_memory_mapping *mapping) +{ + u8 max_level, goal_level = PG_LEVEL_4K; + u32 error_code; + int r; + + error_code = 0; + if (mapping->flags & KVM_MEMORY_MAPPING_FLAG_WRITE) + error_code |= PFERR_WRITE_MASK; + if (mapping->flags & KVM_MEMORY_MAPPING_FLAG_EXEC) + error_code |= PFERR_FETCH_MASK; + if (mapping->flags & KVM_MEMORY_MAPPING_FLAG_USER) + error_code |= PFERR_USER_MASK; + if (mapping->flags & KVM_MEMORY_MAPPING_FLAG_PRIVATE) { +#ifdef PFERR_PRIVATE_ACCESS + error_code |= PFERR_PRIVATE_ACCESS; +#else + return -OPNOTSUPP; +#endif + } + + if (IS_ALIGNED(mapping->base_gfn, KVM_PAGES_PER_HPAGE(PG_LEVEL_1G)) && + mapping->nr_pages >= KVM_PAGES_PER_HPAGE(PG_LEVEL_1G)) + max_level = PG_LEVEL_1G; + else if (IS_ALIGNED(mapping->base_gfn, KVM_PAGES_PER_HPAGE(PG_LEVEL_2M)) && + mapping->nr_pages >= KVM_PAGES_PER_HPAGE(PG_LEVEL_2M)) + max_level = PG_LEVEL_2M; + else + max_level = PG_LEVEL_4K; + + r = kvm_mmu_map_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