Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp68789lqp; Fri, 12 Apr 2024 10:38:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWcwHq9X/dOnaTEy8kFy7Bnsa/xMip0LlT6UU7ZqZ7dSztM+MDWybuigOK6IMtR6ejsb0rqzJ6NDE0kpTVpyeCAvJCyo5/j9WljKfLxrQ== X-Google-Smtp-Source: AGHT+IH1+iguzx//uxLSKK+IfCNvzzOPtobncOr/WjpyGzPSsP3oFbI4h5cIkVXBuH3Bb+UeyBV5 X-Received: by 2002:a05:6a21:3103:b0:1a9:c39a:c3bb with SMTP id yz3-20020a056a21310300b001a9c39ac3bbmr832325pzb.11.1712943504073; Fri, 12 Apr 2024 10:38:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712943504; cv=pass; d=google.com; s=arc-20160816; b=DIMKNNoUBGn2rda05b9b4Yh5Osy5jOtBHpsWp3HEu+ZB4KulN2QNdp9bz/liTj6N+g h1EHPnqMKg95419KHx/D0T0FHLu0UlR37XxweJZOgIawqKAB6EOn7/hqW5WgsclZnN/f GWbX/++Ic5WuNjqzQRXLQcesLDJCEaL9bO2WddZOf1WrkQQQ/dFMVlIF0noy2Sznl14C 3yjdJ4IAKHpZPQ7+PMUbA3uI6LsiFBnf1mb7yo/9v+MBPA8/2ipaxMt7RA9XMHq9Sl/L vnCJ9+Tp6iiJ48FK2ugR89W0DVrGpVJxn39v+jjM40v/G6OMpWPBy3yNgIcJhEFNIoxN IcbQ== 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=75waKXSmIYtMtrXauv2s2wb+S8RC+sVEfUlq8dP5Jvo=; fh=zVvSBexHjxcvLAwjWG71aIOv3mNItzAuy0ISQr9xODI=; b=HURH5IvbvuTSY2GpnGsBydG/Oho1Ih14vtLYmIteS3Dx//qj+0tChYfPg/HIfJW2rH btzffF4ZO0vJdGUoEXdFYheU1HdgD5FpoQhOndqJDiNDSRQv2zIpAaZrL9LU83Ze7jN4 c5XLdUygSQfIOc6sus2/78Ppw5lBfuClXh4CGAd70in+if2FSkgi2XUA6QUAFDavY+a/ wSchrtEM16YuB3PN2/7dRBjrWC2hR8kpWIf6wQ6XbhQdIu35W3AzeVv7hdjhu6eaUDKF FXBT5unBCpvJqlqpjLyKt8yx1jwikxYpJOeeSEqE/w9CRQCZPy0xRMMwmJNx/6sSWVWb xtaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f+1R5hv5; 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-143139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143139-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 lp3-20020a056a003d4300b006edabe82a75si3876183pfb.137.2024.04.12.10.38.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 10:38:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143139-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=f+1R5hv5; 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-143139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143139-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 E2035B23559 for ; Fri, 12 Apr 2024 17:37:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01C4B152183; Fri, 12 Apr 2024 17:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="f+1R5hv5" 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 DC2F714EC60 for ; Fri, 12 Apr 2024 17:35:39 +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=1712943341; cv=none; b=lrk7wBRbnXtYtf5Wpxh41Cieh7cfg52qR5KimzuLHYf0cXzHYJHrJIpGVy0snutibsYtTM0xBEUrP1P3Js+OVlhL9kGq8RD1Ky7ZKYAzvKOwx7KqDcSFgX8sV3C2dEz2IAYOs+ldgRMFNhD3ufXr9JeK+8UAnZASpT5ImWw1gBI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712943341; c=relaxed/simple; bh=ufzS21/7youUNMjyVUvni0StGellwHU8hcLjTR6wauA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QpArrsD2NFI58+TGMA77O0zJGX8/shPTGA2f0akGuGsZ4R2aNeMi1ec82r64m1g7xEUOkibwtln1CJEngIV9nu0iJtwpgff9GWKjzPSMPG7hKsX+olmqB43eztXgea+E0QcvdI8GicE3pIi3QuWrn77ZigfJE7XA+MJ3eHb9kek= 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=f+1R5hv5; 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=1712943338; 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=75waKXSmIYtMtrXauv2s2wb+S8RC+sVEfUlq8dP5Jvo=; b=f+1R5hv59tFyBebakd5UfcAkgV+mklyGtmFhxka3IhG8BoaZbhIOEkVZ1xzJGF1QxjfL8l wRvNIygJpjy/QhjDCfXFreLeOSX2bBSIFvi4WsyFod6hWqkxM5VcwZDuU+FoljWqPkp1SZ BUQptJVTG29o1RtsffU4tAyVng222DA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-226-9pAF9ZHjMvGpQH_CH-Vjkg-1; Fri, 12 Apr 2024 13:35:34 -0400 X-MC-Unique: 9pAF9ZHjMvGpQH_CH-Vjkg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 86E2A80171B; Fri, 12 Apr 2024 17:35:34 +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 652CD492BC7; Fri, 12 Apr 2024 17:35:34 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Isaku Yamahata , Michael Roth Subject: [PATCH 08/10] KVM: x86/mmu: Pass around full 64-bit error code for KVM page faults Date: Fri, 12 Apr 2024 13:35:30 -0400 Message-ID: <20240412173532.3481264-9-pbonzini@redhat.com> In-Reply-To: <20240412173532.3481264-1-pbonzini@redhat.com> References: <20240412173532.3481264-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.9 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 edfc6d67692b..8c56d278d8a2 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5824,8 +5824,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 bebd73cd61bb..ed2923d9a934 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