Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp911795ybt; Fri, 19 Jun 2020 17:54:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk+Zx9+E/4/SW0+bnUnxUc93jW6NYgVRO8cUHUnYW4XVdJ3yhiCZc24HJYbvl123tX37u4 X-Received: by 2002:a17:906:af4d:: with SMTP id ly13mr5825706ejb.250.1592614466720; Fri, 19 Jun 2020 17:54:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592614466; cv=none; d=google.com; s=arc-20160816; b=BRaK1jcxlAwzF0DWoKSorL5KBHmKDCBiZU334HiR0liWL75qB+RkXc1NsQJbUwwqPN lYW/zKykR8UTs7L+WVLoEo9n7hCKi+G2yP6Ep4KjxK2mA83uewbgawC19kqZkvDwzjI7 OfVbWWXws/cS8AYwrsHcnrLe+7r6OKz6QozPe0TEXYjIpfcDeWc2PMQSWlNSsLdQ//Pl L8ntfcQQb7JIWEzHeTXkozJ2p02dTMk9Ayb58tpal7n5liD7l+A+38oYiMsLKZLcS7s0 HYnny5PhHSkVrg7dYJ0blANwkJRMxFML35iGIEU7q4dhXyYni9dUXvR9Gzhbg18NMNwR pBgg== 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 :dkim-signature; bh=SOfOPV+bdXo7ikGMHzW5QOm7ZJeCM7qYVz4ijnYJn9I=; b=yU7/aqOgC+isRVbG63gXBIckcJrI8oE80C2DelIHVoqJv9SnUR4/dyRatr6q0pixm1 jkZY9JTB08lnzyroa65wxq5XDEfMXgeaG3ckREuiy3ea+1wJV41FzyNVGmt5uZi7sdY3 r9s+VcYLDUfnViiPFSn5lzqubhZwuWn0maN6QG6XilrHit00nlIaGxCnawtisc7wGwCb TRmFO6RzScxm64GNKag6F3sfMGbVWHVyCA6jWd1dePl6wZ1FpW/uSL+ZTkBFyMS8+7+U LbxO36pqt/o+rF4aj0H7qIFhOFXpCH1ipxv9KGu9MDXwrD9xMsGT+RXlXhQOjtjocQ27 BcEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HCbSNcDG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si4154713ejx.370.2020.06.19.17.54.02; Fri, 19 Jun 2020 17:54:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HCbSNcDG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393965AbgFSPkQ (ORCPT + 99 others); Fri, 19 Jun 2020 11:40:16 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:43050 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2393915AbgFSPkO (ORCPT ); Fri, 19 Jun 2020 11:40:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592581212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SOfOPV+bdXo7ikGMHzW5QOm7ZJeCM7qYVz4ijnYJn9I=; b=HCbSNcDGQuwlnfVdkckMiXHr1u8ksXZVnPav78G29gd7ziZwfYWSrdb1W8z9ngzKG9X5LH DzM8e8rF6Ww0Yi4/djWkmBhVVl7zBmkS9kQP1lszlOhpbmr5Ra47qlbBISqVNJLcHT+4pc ewhJkqSkBA8NzoDTexstCIFIG0CeIvQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-CFnl1TpjP5uRKIsb9979Fg-1; Fri, 19 Jun 2020 11:40:08 -0400 X-MC-Unique: CFnl1TpjP5uRKIsb9979Fg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB77F835B48; Fri, 19 Jun 2020 15:40:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-254.ams2.redhat.com [10.36.112.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D4A860BF4; Fri, 19 Jun 2020 15:40:04 +0000 (UTC) From: Mohammed Gamal To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: linux-kernel@vger.kernel.org, vkuznets@redhat.com, sean.j.christopherson@intel.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, thomas.lendacky@amd.com, babu.moger@amd.com Subject: [PATCH v2 08/11] KVM: VMX: optimize #PF injection when MAXPHYADDR does not match Date: Fri, 19 Jun 2020 17:39:22 +0200 Message-Id: <20200619153925.79106-9-mgamal@redhat.com> In-Reply-To: <20200619153925.79106-1-mgamal@redhat.com> References: <20200619153925.79106-1-mgamal@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Bonzini Ignore non-present page faults, since those cannot have reserved bits set. When running access.flat with "-cpu Haswell,phys-bits=36", the number of trapped page faults goes down from 8872644 to 3978948. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/vmx/vmx.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index f38cbadcb3a5..8daf78b2d4cb 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4358,6 +4358,16 @@ static void init_vmcs(struct vcpu_vmx *vmx) vmx->pt_desc.guest.output_mask = 0x7F; vmcs_write64(GUEST_IA32_RTIT_CTL, 0); } + + /* + * If EPT is enabled, #PF is only trapped if MAXPHYADDR is mismatched + * between guest and host. In that case we only care about present + * faults. + */ + if (enable_ept) { + vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK, PFERR_PRESENT_MASK); + vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, PFERR_PRESENT_MASK); + } } static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) -- 2.26.2