Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1880503pxb; Fri, 24 Sep 2021 14:17:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx61aJvkWzU49lYumaTKXp1GP6d4cAeaFu4l9b3r/QDiQjaI2XkXPA/O+OeKyYIkJ5wtxoH X-Received: by 2002:a17:906:6403:: with SMTP id d3mr13395762ejm.37.1632518232294; Fri, 24 Sep 2021 14:17:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632518232; cv=none; d=google.com; s=arc-20160816; b=BcvEyiVO8Kej6gICXu/B1ByOEUH+TELrtaA/bfYKigO5Qc/h+x5qbJ7Z3/faM48UDR mITovKcMvYXXE6oUIbYUO9uCriZpjr4BXNEct0wK4fSYTmnNJglEfhPBpc8v3foB8ybN 2K07VwYfpih4bz72G1Z2x+zK6FsaVwNnVT7qbhv9rc9X/WPeJ5ebrrEukwAa89a3z0w5 l8FGamYuY9a6ff5AkNRYd7faWq1Z40JAMwv2dvirjkAIxhwnYyIa/UHe/XkDqAey66Jm lVEQGdBqpbxAYzMF4lYaUxH7EMGSU72PdH1x7idSwV3iP3u5aTZsUGTxdIrqL9uL/SMO /QlQ== 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=3qBSDkkSxaXnwERh9nmkQRCVYCw3rkjz6D3rgLk8m0I=; b=SiECAllOOwMfz4itJuIVAez0PFC76G899Wz80HSgw/bi0+p2d9l3rA8ShgebqSLW2/ Z0aBpWnarRE2Yeb1sJebOYS8Ul540oke/DHByMjmXXH6mrX9UcmAKlD/hMp5lbRwc8LH SPCBDpIZg6U0OQUX5K8AKVojJjueNTQspoHiUYwM5npf6jXhRwIn2W19LW/4l+1E9a0L figagNss9lnbZw3dMv7xT73iKXBDrBzjgPjuZe/KO18OIJPg7c3xf9B+9CyAvBCqq+O3 6V/VCfGdvxv/7PmJ2PaDE8D+uwR5KcWmfBoLH07uzm3iQVgKJ1S48qt8UufbNOBkwTp3 Zy4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NKEAZyEJ; 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 d29si10222520ejo.704.2021.09.24.14.16.48; Fri, 24 Sep 2021 14:17:12 -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=NKEAZyEJ; 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 S1347455AbhIXQdf (ORCPT + 99 others); Fri, 24 Sep 2021 12:33:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46175 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240890AbhIXQdb (ORCPT ); Fri, 24 Sep 2021 12:33:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632501117; 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=3qBSDkkSxaXnwERh9nmkQRCVYCw3rkjz6D3rgLk8m0I=; b=NKEAZyEJKKpjZhV8AaSXfrpt1tO1Kf3iPIB9SRJq4owHryrHOyF0vkDjZfQKxijUTacqGA l0Fy22Qmk4Z2vQlukNxwaSOBZHfnohljleum75NL2SOKx0tZgF5pMiKgIEWIxJ1FrQ1jTM vcOvWzkPuNQmzVryY+htxaQtKpwGmiA= 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-321-JpK6WN3jPaqhw_Bv0VghqQ-1; Fri, 24 Sep 2021 12:31:55 -0400 X-MC-Unique: JpK6WN3jPaqhw_Bv0VghqQ-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 A0401802935; Fri, 24 Sep 2021 16:31:54 +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 31B3B60E1C; Fri, 24 Sep 2021 16:31:54 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: dmatlack@google.com, seanjc@google.com, Isaku Yamahata Subject: [PATCH v3 02/31] KVM: MMU: Introduce struct kvm_page_fault Date: Fri, 24 Sep 2021 12:31:23 -0400 Message-Id: <20210924163152.289027-3-pbonzini@redhat.com> In-Reply-To: <20210924163152.289027-1-pbonzini@redhat.com> References: <20210924163152.289027-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 e9688a9f7b57..0553ef92946e 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