Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp211787lqb; Tue, 16 Apr 2024 13:20:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXuk05nVpZfHM3nFzOZWzeoznSi62qROL8ATdsv0l0dSG4rxPchfAKT3zlnP2t1MouMinPhJzaDIwEn5g/4hGkcDFRLSuhWGOi1Zap+Yg== X-Google-Smtp-Source: AGHT+IEoqNYkpvg4auNLB4gknDxi5WTPMQZSGz8Lbp40h8C69JpEP4ddyI0phtPqTYmE6yv9mEwU X-Received: by 2002:a17:90a:cb09:b0:2a4:833f:2c1b with SMTP id z9-20020a17090acb0900b002a4833f2c1bmr12729136pjt.9.1713298812570; Tue, 16 Apr 2024 13:20:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713298812; cv=pass; d=google.com; s=arc-20160816; b=UHaxzmtxVPwzjFFgpOdVObOIjq+dJi251LmfoVzV9CbFSmT3ESJ7kGVNojL4OjxkSj 50FPq8jUjon/OiyNPsIxh0TuciXJUAOiyndauE4h9QZRqDmyNeiwqr49Qn8J3FRc6+UC UPqi5gzXqndB3IoKnCDkwprKPxSx9bvdXBpHQ6jV4EjgpRLkaBaWIhK5dLfFxUBjoT1x YTbQWIFTygq12V+6mGOVOxa64zAHTzxhu0tVy+T3Auas2x0RzcKST7butC3mVQPl4uZw NIo188xNMh8EYfMgLfa62zgS5eSfsMtxDHftQrh9/xlmtn/CCSc59lr8xtJhrvQDSeiZ 4yYQ== 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=Gcy2zYEU2Nttf/7LgpSSDLqdYIwKEk1g2jq5D1zfg24=; fh=hiwZghU/9gHWLIOcUoXWPwBScabQfbinyGWwl7SSPCo=; b=IWxIAeol2U+tGsKN0GOMYGaNdolO991GwU/YM8FUgQv9BW3rJth/lcsa4/c1la1Yj5 LSWi6ppoC9ZM6cH9LQ03EU6/VpXh8sfiZq7rCaz90YZEf7QJ3l8SIU2VME0Il6qHyPyw Yptn1VZEWMqFYLszJ6axy1F2rJyXpPwReocI/I0romHofPQ7mwStGx5GqSvbqBd3ECne neMPZK1rWV+WsbP21wAFj+FdIENxxUpw9p9QqM9wvDeMrJuMOcbL4I3Zs3uY4LrtAAX/ +A0pxItc6VlqikTyyK/z0IBQfpoNXOe5b1drf+8OskUkH+NdeRrYFg6N4YIiWEzo/uyV BWng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NxlYu9Q2; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-147505-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147505-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e7-20020a17090a684700b002a60efe265asi10158199pjm.187.2024.04.16.13.20.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 13:20:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147505-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NxlYu9Q2; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-147505-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147505-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 09668B21235 for ; Tue, 16 Apr 2024 20:20:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B5E013A86C; Tue, 16 Apr 2024 20:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NxlYu9Q2" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 8FB1211181 for ; Tue, 16 Apr 2024 20:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713298783; cv=none; b=VC6ih5C+ygwBG94VGz3a5WUvwL1RWbwbtMy+QNiCoajWOHu9hDxkNSTR8PPl3DQ4CpaJFN2iIwuh7SkRJfmRT7jkrzWBMyNv7nsEP0GRubn2NfXl0WwnS+3XMQKK6WTBTOoy3bt1nFqiHOwKWs3eImhVf/wAs/I/Y+p+YXU5KtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713298783; c=relaxed/simple; bh=2b9VxgtI5DOLz9r614k8oRTCR8Jyg8IeosuO6eo7xZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gHf9pqs1qGKY2JT+MbztcznmUtxb5J6KWlaxBXU88vS7eKgJguJ6B2BVtwpBE3oaEfzVGIozW5nP3VBDslPbmIbDzt5s8ROpG0m9nImt8TxTCtA1ow+I7PagsZVjEcgRKOaNcO268uOjIIbpZ/O6On1ygqNl1GyjL2wJdvXrmPc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NxlYu9Q2; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713298780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gcy2zYEU2Nttf/7LgpSSDLqdYIwKEk1g2jq5D1zfg24=; b=NxlYu9Q2hBAZVpI5Hd2qjInz7nXrxIpc9tYN4l1vgUAvo7CZDLNhMA2TwJ+WhXnrgHALos kOA9kuhM6u6iHIdRP6uXEKRwp4qVH3am+PtRR+zM2MJ1o7gjU9PHptybi12MvXP7ghKaIS if+/rEpoD7V/PNnyvaSLsDGBpJVezXs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-oGvGiUmrNUK8ck4rMXKbXQ-1; Tue, 16 Apr 2024 16:19:38 -0400 X-MC-Unique: oGvGiUmrNUK8ck4rMXKbXQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 79FC41C0AF40; Tue, 16 Apr 2024 20:19:38 +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 49C174910E; Tue, 16 Apr 2024 20:19:38 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, xiaoyao.li@intel.com, binbin.wu@linux.intel.com, chao.gao@intel.com, Michael Roth Subject: [PATCH v2 08/10] KVM: x86/mmu: Pass around full 64-bit error code for KVM page faults Date: Tue, 16 Apr 2024 16:19:33 -0400 Message-ID: <20240416201935.3525739-9-pbonzini@redhat.com> In-Reply-To: <20240416201935.3525739-1-pbonzini@redhat.com> References: <20240416201935.3525739-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 From: Isaku Yamahata In some cases the full 64-bit error code for the KVM page fault will be needed to determine things like whether or not a fault was for a private or shared guest page, so update related code to accept the full 64-bit value so it can be plumbed all the way through to where it is needed. The use of lower_32_bits() moves from kvm_mmu_page_fault() to FNAME(page_fault), since walking is independent of the data in the upper bits of the error code. Signed-off-by: Isaku Yamahata Link: https://lore.kernel.org/kvm/20230612042559.375660-1-michael.roth@amd.com/T/#mbd0b20c9a2cf50319d5d2a27b63f73c772112076 [mdr: drop references/changes to code not in current gmem tree, update commit message] Signed-off-by: Michael Roth Message-Id: <20231230172351.574091-7-michael.roth@amd.com> Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/mmu.c | 3 +-- arch/x86/kvm/mmu/mmu_internal.h | 4 ++-- arch/x86/kvm/mmu/mmutrace.h | 2 +- arch/x86/kvm/mmu/paging_tmpl.h | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 45b6d8f9e359..00eef18ca1ae 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5816,8 +5816,7 @@ int noinline kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 err } if (r == RET_PF_INVALID) { - r = kvm_mmu_do_page_fault(vcpu, cr2_or_gpa, - lower_32_bits(error_code), false, + r = kvm_mmu_do_page_fault(vcpu, cr2_or_gpa, error_code, false, &emulation_type); if (KVM_BUG_ON(r == RET_PF_INVALID, vcpu->kvm)) return -EIO; diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 5390a591a571..49b428cca04e 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -190,7 +190,7 @@ static inline bool is_nx_huge_page_enabled(struct kvm *kvm) struct kvm_page_fault { /* arguments to kvm_mmu_do_page_fault. */ const gpa_t addr; - const u32 error_code; + const u64 error_code; const bool prefetch; /* Derived from error_code. */ @@ -280,7 +280,7 @@ enum { }; static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, - u32 err, bool prefetch, int *emulation_type) + u64 err, bool prefetch, int *emulation_type) { struct kvm_page_fault fault = { .addr = cr2_or_gpa, diff --git a/arch/x86/kvm/mmu/mmutrace.h b/arch/x86/kvm/mmu/mmutrace.h index ae86820cef69..195d98bc8de8 100644 --- a/arch/x86/kvm/mmu/mmutrace.h +++ b/arch/x86/kvm/mmu/mmutrace.h @@ -260,7 +260,7 @@ TRACE_EVENT( TP_STRUCT__entry( __field(int, vcpu_id) __field(gpa_t, cr2_or_gpa) - __field(u32, error_code) + __field(u64, error_code) __field(u64 *, sptep) __field(u64, old_spte) __field(u64, new_spte) diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index 9aac3aa93d88..37c4f3d95738 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -787,7 +787,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault * The bit needs to be cleared before walking guest page tables. */ r = FNAME(walk_addr)(&walker, vcpu, fault->addr, - fault->error_code & ~PFERR_RSVD_MASK); + lower_32_bits(fault->error_code) & ~PFERR_RSVD_MASK); /* * The page is not mapped by the guest. Let the guest handle it. -- 2.43.0