Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp1306105pxt; Sat, 7 Aug 2021 06:51:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyI05wPI7RQF5wVjRyi6qU/bZ/aGPVO+QnDuw0z8os4vAfaCCABGCrGiBFByyNSEz0qrYi X-Received: by 2002:a05:6638:1928:: with SMTP id p40mr14699810jal.93.1628344264129; Sat, 07 Aug 2021 06:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628344264; cv=none; d=google.com; s=arc-20160816; b=EbXhyaof2WvXKT5rmLWulG/dN8BTSA8ab4QiFdoI1NyWf0EayDlk3jIVrL4o4FtItS SqSnPOwg3ImC/v5dpui50vfOg0xHNqamPLJtNNvyShYRgYgXWO4+5p4HHe14VzzjXt/n eKd4TW4S/xds9RhbiTxtxd0Y6ewV7O1NH1ZvXhOqX8hySgY+BIc+PzGsatLjp4bvAQ4A byUPuKgIf+HY9JP9a42mHM2B3a3iDr9AeWh68ME70Ko8o2pOG/g/7yXYYqJwJnzXMDb9 q1qWbEgtPksmN+68/xuYXJyxcknvoxHo2RPx/jP0jlhJz1J6A5ujsFn/toB5gA1UuETS OrDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YV9HL89pSqp0PtCqOD4/gmmSWtLC0E19+93loFbwPUo=; b=phpH8+6rM8aizNzCdGvSppdE/5riMYjkFaoAak8DmU9DfH4hgav4O8iKt8yZb8Lb2f 4ksId38hadEdAsbd9rekIvTfUfSe4ThBG7YvP3mmimZTRTViazXpG70PSRihJErVWWMK JIXkALIP7dKhZjgCMqX62roEmzu1metJy7U6kUBPgXE8TjmEVLLuAeWwkxul5z4cgsHo xjffXEDWqXcobZfkpSectenHrqh/UAy0QrBOPKLQIwbjVNwQEA7Y1KqD0wNz+VMCF22V xvfVaRURaX5kVJlFLYySuEHhibwB0R7GkxI+eZrb9KRLgE+UeOK/BRSUi1GLf1pfnfTo ggcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=efjmnSz5; 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 r7si9607332ilg.55.2021.08.07.06.50.41; Sat, 07 Aug 2021 06:51:04 -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=efjmnSz5; 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 S232395AbhHGNuG (ORCPT + 99 others); Sat, 7 Aug 2021 09:50:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50183 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232371AbhHGNuD (ORCPT ); Sat, 7 Aug 2021 09:50:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628344186; 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=YV9HL89pSqp0PtCqOD4/gmmSWtLC0E19+93loFbwPUo=; b=efjmnSz59un7RkUYwVvSO9e28jndL8owkKWPIJE3psaWH4SfJcHK9/gaMv+TKY6Oj5V9/w miQCj6NCot0h1kxGjfFN5LxerqLFPNmGmrAWJJC1S8Hd56CmvSe8ig3HWKLqDRebKnYcqD dcXVNReRhtNwHt3VAkO8uhyL7tL9Ozs= 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-446-kg29abJcOwyaF7CXh894Fg-1; Sat, 07 Aug 2021 09:49:44 -0400 X-MC-Unique: kg29abJcOwyaF7CXh894Fg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C48B9107465F; Sat, 7 Aug 2021 13:49:43 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 363891700F; Sat, 7 Aug 2021 13:49:43 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, David Matlack , seanjc@google.com, peterx@redhat.com Subject: [PATCH 03/16] KVM: MMU: Introduce struct kvm_page_fault Date: Sat, 7 Aug 2021 09:49:23 -0400 Message-Id: <20210807134936.3083984-4-pbonzini@redhat.com> In-Reply-To: <20210807134936.3083984-1-pbonzini@redhat.com> References: <20210807134936.3083984-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create a single structure for arguments that are passed from kvm_mmu_do_page_fault to the page fault handlers. Later the structure will grow to include various output parameters that are passed back to the next steps in the page fault handling. Suggested-by: Isaku Yamahata Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu.h | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 83e6c6965f1e..5c06e059e483 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -114,17 +114,45 @@ static inline void kvm_mmu_load_pgd(struct kvm_vcpu *vcpu) vcpu->arch.mmu->shadow_root_level); } +struct kvm_page_fault { + /* arguments to kvm_mmu_do_page_fault. */ + const gpa_t addr; + const u32 error_code; + const bool prefault; + + /* Derived from error_code. */ + const bool exec; + const bool write; + const bool present; + const bool rsvd; + const bool user; + + /* Derived from mmu. */ + const bool is_tdp; +}; + int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, bool prefault); static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u32 err, bool prefault) { + struct kvm_page_fault fault = { + .addr = cr2_or_gpa, + .error_code = err, + .exec = err & PFERR_FETCH_MASK, + .write = err & PFERR_WRITE_MASK, + .present = err & PFERR_PRESENT_MASK, + .rsvd = err & PFERR_RSVD_MASK, + .user = err & PFERR_USER_MASK, + .prefault = prefault, + .is_tdp = likely(vcpu->arch.mmu->page_fault == kvm_tdp_page_fault), + }; #ifdef CONFIG_RETPOLINE - if (likely(vcpu->arch.mmu->page_fault == kvm_tdp_page_fault)) - return kvm_tdp_page_fault(vcpu, cr2_or_gpa, err, prefault); + if (fault.is_tdp) + return kvm_tdp_page_fault(vcpu, fault.addr, fault.error_code, fault.prefault); #endif - return vcpu->arch.mmu->page_fault(vcpu, cr2_or_gpa, err, prefault); + return vcpu->arch.mmu->page_fault(vcpu, fault.addr, fault.error_code, fault.prefault); } /* -- 2.27.0