Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1182842ybl; Wed, 8 Jan 2020 12:30:05 -0800 (PST) X-Google-Smtp-Source: APXvYqyW0zKfN1HpecII+Jy2vTDekNmXge8zKfn7pXYwr4QP05WWSIfraeeKp4neeWd3Gmhox9Q6 X-Received: by 2002:aca:b943:: with SMTP id j64mr346456oif.155.1578515405179; Wed, 08 Jan 2020 12:30:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578515405; cv=none; d=google.com; s=arc-20160816; b=Nuw2m7s7SejQ3JDT4af85ORPpwLFSVhwMAcjDZ1q6VgFH72Hd6gn3IRinZPHNJN24L TuoIKYnvVLG4nwpkUXR2CBPg62SGZIebiyKQVN6ZkLxhjuHa2DjSEht7mgK1uGSF+gp0 Sb8kA49r8NfXQFw5g4Q9Zu33xKQfHICu0GjbR7lQuBvNh0m1ryuPiBkIoHfitGyUfgbB oq1sLV/t5iA/ckTNOLa89meqqW9sJoMfcW0loP+pHuJ+TkWBoVpQkwPhTfsI2zl1eiOl SmGnWFnGxrWk68CNHqNpsEKkHR/8hQ6Y0RsAsL/869mZFK2z5qmTCOynGcxHn9wVrevI LWRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gx7hXT5jDbBvHRc0CodJxkWJb+HOJV06QjOrEj6e2bU=; b=U8wW68F3vFIy8giyQggxGfUJeCuW/V4zm+4fLE6DKpajjEElRdZP1HtRxQLGEz3GvA 52faB9lC5JQy2YpmD7ofFW5t71WsvJqCcyxDXy4HMTAlRuB+z5JfZ+rO6sHxqnwuq77S /1ctxAtj8PaCVJyxB4q+cPLLl6cfEsvAcp4TTJIyTWGpWVL4vLSs3IASienJzcz83Rgt LrhUg+kK8heJt7pX03PvpCsyv8J3HKGeLh2NO2GeEp7VK2hevGv72yUNijpOISlY53Dv B0HUYT1V4urYEnCPelRDS/1Aff/FZZA5Re9pxAYBZ4EBMJJnTEjp/vThvX4H0ScZn7FW i5gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k84si2344457oib.46.2020.01.08.12.29.53; Wed, 08 Jan 2020 12:30:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727282AbgAHU1H (ORCPT + 99 others); Wed, 8 Jan 2020 15:27:07 -0500 Received: from mga01.intel.com ([192.55.52.88]:57134 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgAHU1G (ORCPT ); Wed, 8 Jan 2020 15:27:06 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jan 2020 12:27:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,411,1571727600"; d="scan'208";a="211658356" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.202]) by orsmga007.jf.intel.com with ESMTP; 08 Jan 2020 12:27:05 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Paul Mackerras , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, syzbot+c9d1fb51ac9d0d10c39d@syzkaller.appspotmail.com, Andrea Arcangeli , Dan Williams , Barret Rhoden , David Hildenbrand , Jason Zeng , Dave Jiang , Liran Alon , linux-nvdimm Subject: [PATCH 01/14] KVM: x86/mmu: Enforce max_level on HugeTLB mappings Date: Wed, 8 Jan 2020 12:24:35 -0800 Message-Id: <20200108202448.9669-2-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200108202448.9669-1-sean.j.christopherson@intel.com> References: <20200108202448.9669-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Limit KVM's mapping level for HugeTLB based on its calculated max_level. The max_level check prior to invoking host_mapping_level() only filters out the case where KVM cannot create a 2mb mapping, it doesn't handle the scenario where KVM can create a 2mb but not 1gb mapping, and the host is using a 1gb HugeTLB mapping. Fixes: ad163aa8903d ("KVM: x86/mmu: Persist gfn_lpage_is_disallowed() to max_level") Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 7269130ea5e2..8e822c09170d 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1330,7 +1330,7 @@ gfn_to_memslot_dirty_bitmap(struct kvm_vcpu *vcpu, gfn_t gfn, static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn, int *max_levelp) { - int max_level = *max_levelp; + int host_level, max_level = *max_levelp; struct kvm_memory_slot *slot; if (unlikely(max_level == PT_PAGE_TABLE_LEVEL)) @@ -1362,7 +1362,8 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn, * So, do not propagate host_mapping_level() to max_level as KVM can * still promote the guest mapping to a huge page in the THP case. */ - return host_mapping_level(vcpu->kvm, large_gfn); + host_level = host_mapping_level(vcpu->kvm, large_gfn); + return min(host_level, max_level); } /* -- 2.24.1