Received: by 2002:ab2:7104:0:b0:1f7:f6c3:9cb1 with SMTP id z4csp39766lql; Tue, 7 May 2024 09:12:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVR8tmqXdTJVYK4KWQZSq/bWFRadqNZEklSHp7JOCc2mI4lDxG6u7NbMPiW9tzVw5d7KYYVggqn3IsBkkGrRlASVkI/QJfsJpA+gO8QGw== X-Google-Smtp-Source: AGHT+IGv1/MKWwXGHEsLHbIzIKRLN573XVnOkSpdJtpolw6pO32ogkib9WAuco8cnrCza5gM0w87 X-Received: by 2002:a50:d758:0:b0:572:df77:c1bf with SMTP id 4fb4d7f45d1cf-5731d9a7c88mr144041a12.3.1715098340346; Tue, 07 May 2024 09:12:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715098340; cv=pass; d=google.com; s=arc-20160816; b=k2EOX2DYsLHg8Th7qpcb9uXjE0EJlVQJpEwkmCOTVthSBSEnrDUrfb5N/APqbpWP8y 45fN3ANOFDr0lhvPbVT1+34PmCRI1TPBh2JhpYOTJxJ1sfNpec3s6mCFPfTlDvotZpc7 C3jfxEjnqS9bOV65zGMBuV+KGz37TJI30uie4eu4gQ9fOlaYIVgxHJgnjXSpCoqXzZyV xCLFyXn886UauDQ27LrzAXtCVHJpCLBQs64BtKaWzIUEt2nzIn6Nx/uGIruLlw2btWk3 XYuJ0hXrJWzVjSElFLTJEvZws3Pzho5PAOUIbmqPAV5WON1nKrVrf4h9rlTX8uyPu2st 1PVA== 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=3lnkqGa7h/6nD25Z7o+7/CTEjU22pWMiKsKWmTnmff0=; fh=9NRedfrmOLozADBmVc5EhfAW69weqWqRT7TMs+/dX4Q=; b=A3F5z8pboX8Tn4TEWC2AapuCsftpzdgzwDMADlu6i2/3BKpVEXMy1sYk6Hi8MYjNlq YctD71ZcisGoSkA6IRF8mlCEkZueNO9ch+HVgkHn00HyjIQegqRCC2eCiYdbZWSWyndb aI0FRAlnXm8E5/keuEd/0bxfKofv7OX9zxEA9mpq+N/Ok2qe2LUE+7LFeSYl8Wpf5mw3 94xVm4tEZrg6CJB+b5Qp9P0Vp6Cxwyt7UGjyaw099U+Avv4P6p6q+tgv4BKzVJmfyq5L 5TURYG+IiZ5TnuKpyVLRHXcm5wDpogjhng/2Hec38jdye3fjoxcUjEWs5VtR0EKk2EwQ tD9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dTq2JN4q; 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-171751-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171751-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a11-20020a50e70b000000b005730fe546cdsi1262332edn.27.2024.05.07.09.12.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 09:12:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171751-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dTq2JN4q; 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-171751-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171751-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DE8A51F2B03D for ; Tue, 7 May 2024 16:03:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF91316F84B; Tue, 7 May 2024 15:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dTq2JN4q" 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 1ED6B16C843 for ; Tue, 7 May 2024 15:58:24 +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=1715097507; cv=none; b=lgSPx50rh3xkhi0GfsOrBfK0y/Rfr7WGKIZOPH0hwnKzFdFEbrDG6qx8DKke8RnWsTX/qlirD3wp+bQ4T6mHHbEDwstSMEiHkTbpnIuXG/O3Cbo4kTh9H68EIekAFKZH2oiw5CwtFJ9fmNeR1ScCKb+oFZhEK0xpxDD1xmmC+fE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715097507; c=relaxed/simple; bh=pa6UQFs5IVqPGa1HubYZhaKzaBNQ3H+E9fxCfy0yxHw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nXkJyIHz+ZpxccAWzSp+4ESr+Ur4+cmrXiZUBgNUVXhEA2wNhMiy8QBU0cpoiNn8Qk+rH1wyrPa7u2U7U28wmjdNoq3ecYM5x/XchujNaw2F9Znz6Wq9kBPmN9tWRQNnQwbfK1b75iG/3XXSobsoBocOiOhvrkaIJz/kdQa+GCk= 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=dTq2JN4q; 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=1715097504; 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=3lnkqGa7h/6nD25Z7o+7/CTEjU22pWMiKsKWmTnmff0=; b=dTq2JN4qaSL8BAxATTuuG7c6Y2bsb+mBjFiigpmLvBdQq+Fm60eGU9Wr3rxw3BlPZSldTI vnBI6dIG7sfpB6eLif48y8BHoKTwzNX092IKgosYNbR0H80NEcX+3E5JKFrU5L4o0rYCkf k42U1WGjPLpCfyqA6+H8pkUVmZkXO58= 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-516-6rijs2KbNaCTbq9qJq9sKg-1; Tue, 07 May 2024 11:58:19 -0400 X-MC-Unique: 6rijs2KbNaCTbq9qJq9sKg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 DBED01C031AC; Tue, 7 May 2024 15:58:18 +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 B0F242141800; Tue, 7 May 2024 15:58:18 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Isaku Yamahata , Michael Roth , Sean Christopherson , Xiaoyao Li Subject: [PATCH 05/17] KVM: x86/mmu: Pass full 64-bit error code when handling page faults Date: Tue, 7 May 2024 11:58:05 -0400 Message-ID: <20240507155817.3951344-6-pbonzini@redhat.com> In-Reply-To: <20240507155817.3951344-1-pbonzini@redhat.com> References: <20240507155817.3951344-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.6 From: Isaku Yamahata Plumb the full 64-bit error code throughout the page fault handling code so that KVM can use the upper 32 bits, e.g. SNP's PFERR_GUEST_ENC_MASK will be used to determine whether or not a fault is private vs. shared. Note, passing the 64-bit error code to FNAME(walk_addr)() does NOT change the behavior of permission_fault() when invoked in the page fault path, as KVM explicitly clears PFERR_IMPLICIT_ACCESS in kvm_mmu_page_fault(). Continue passing '0' from the async #PF worker, as guest_memfd and thus private memory doesn't support async page faults. Signed-off-by: Isaku Yamahata [mdr: drop references/changes on rebase, update commit message] Signed-off-by: Michael Roth [sean: drop truncation in call to FNAME(walk_addr)(), rewrite changelog] Signed-off-by: Sean Christopherson Reviewed-by: Xiaoyao Li Message-ID: <20240228024147.41573-5-seanjc@google.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 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 5562d693880a..28b1e7657d7f 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5800,8 +5800,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 61f49967047a..797b80f996a7 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. */ @@ -288,7 +288,7 @@ static inline void kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, } 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) -- 2.43.0