Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2041262pxb; Fri, 24 Sep 2021 18:51:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLApiyd/HrFet1XwFL+J8USK+dfryuQt6oHQQOBXSiY84Jp0To78SVOhdb10+8ChGt8Uus X-Received: by 2002:a17:906:1c99:: with SMTP id g25mr14658523ejh.521.1632534669611; Fri, 24 Sep 2021 18:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632534669; cv=none; d=google.com; s=arc-20160816; b=CZug/Sienk5IwfTaztbLsyNhOr8xUyFWcS4FGKWRs9pUO+BYTR6LzWWf/wi/iO4XEo n7OZLrrpvr5aNphSCfj9BflZfgFTeNWLiirlDJbpM4dM3z1HFegFz6ls5f98MwL3065b 53wjryb+QRj0817yCJ8Rxd4gna+oXbGaBITccn3herXMz+GCXqCbJV4+MLbim0ELsNES B6/kYlizMS7GhmrHIf/Xu/yiwm6kD3mEi3rl0E2JWOGryD/Ch1NchZSeV2vRJnulAiEJ W55uQM8mpSG0ATcbZ84y5aEj/PIkOlzfyV6AIh+RZw+sNiAAu0gpKhJRpAtFx+ePExzO 8+Sw== 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=iM8RwW4DuJD/gTDxpnUKn09Mj0cXhEPEhrCBKhqSA4M=; b=cJKRX/bevmicKfXtKJKnlYDMz0DDV1OTZ1WX3Q3fhq/BtozLKNsipFnBkRJvCZ6HAM BlHHfK9ZOb+1RBWrBnKNosWQEwRIgb/Fyjtkpu3YxDn3923fOPSh4i4uQtBNDAZwN/H9 b3Wcfgyuen8VeK7B6VtLNzIiV93HbsRPLY4fFkfRYT6iRxaHDJZvTHUfDIQBGkdr/diE hMuwh9Mi/MGlj4F+NSIuf2iu3Wi7I+SCPCkDqwH4AcOV08ma1D1/V4ZrUFAIjqh5UC/m etUR1CFRZAhREUF7sZ7ADcnEOo5Qr3hwrHCcwcv1rp1drDf5oXmBBcc/1+FkyDwUVwer J7Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ftX3Cc2N; 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 v2si10772765ejk.783.2021.09.24.18.50.46; Fri, 24 Sep 2021 18:51:09 -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=ftX3Cc2N; 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 S1347933AbhIXQe3 (ORCPT + 99 others); Fri, 24 Sep 2021 12:34:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36177 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347561AbhIXQdo (ORCPT ); Fri, 24 Sep 2021 12:33:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632501131; 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=iM8RwW4DuJD/gTDxpnUKn09Mj0cXhEPEhrCBKhqSA4M=; b=ftX3Cc2NPj3kvckBsuAqB8KfZ81Nk5mZH/By4AotYtw7cDKmi+ngBe+CV3Ki7FrHgr0Ex3 tvJM5wvUHBZavbbEBWlqwerVrJ3JSW6iJBUKPIbgZzJryjQQT826XSY8Fc6ZgKVBpyjDrn eUaYZSbHN4sNMdhKOBvwIxfPYWRbX2U= 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-220-MbgS6LCRNH-j2-OYfPUF6A-1; Fri, 24 Sep 2021 12:32:06 -0400 X-MC-Unique: MbgS6LCRNH-j2-OYfPUF6A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D078991275; Fri, 24 Sep 2021 16:32:05 +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 4CFC75C1CF; Fri, 24 Sep 2021 16:32:05 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: dmatlack@google.com, seanjc@google.com Subject: [PATCH v3 21/31] KVM: x86/mmu: Avoid memslot lookup in page_fault_handle_page_track Date: Fri, 24 Sep 2021 12:31:42 -0400 Message-Id: <20210924163152.289027-22-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.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Matlack Now that kvm_page_fault has a pointer to the memslot it can be passed down to the page tracking code to avoid a redundant slot lookup. No functional change intended. Signed-off-by: David Matlack Message-Id: <20210813203504.2742757-5-dmatlack@google.com> Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm_page_track.h | 2 ++ arch/x86/kvm/mmu/mmu.c | 2 +- arch/x86/kvm/mmu/page_track.c | 20 +++++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/kvm_page_track.h b/arch/x86/include/asm/kvm_page_track.h index 6a5f3acf2b33..9cd9230e5cc8 100644 --- a/arch/x86/include/asm/kvm_page_track.h +++ b/arch/x86/include/asm/kvm_page_track.h @@ -61,6 +61,8 @@ void kvm_slot_page_track_remove_page(struct kvm *kvm, enum kvm_page_track_mode mode); bool kvm_page_track_is_active(struct kvm_vcpu *vcpu, gfn_t gfn, enum kvm_page_track_mode mode); +bool kvm_slot_page_track_is_active(struct kvm_memory_slot *slot, gfn_t gfn, + enum kvm_page_track_mode mode); void kvm_page_track_register_notifier(struct kvm *kvm, diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 754578458cb7..d63fe7b10bd1 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3819,7 +3819,7 @@ static bool page_fault_handle_page_track(struct kvm_vcpu *vcpu, * guest is writing the page which is write tracked which can * not be fixed by page fault handler. */ - if (kvm_page_track_is_active(vcpu, fault->gfn, KVM_PAGE_TRACK_WRITE)) + if (kvm_slot_page_track_is_active(fault->slot, fault->gfn, KVM_PAGE_TRACK_WRITE)) return true; return false; diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c index 21427e84a82e..859800f7bb95 100644 --- a/arch/x86/kvm/mmu/page_track.c +++ b/arch/x86/kvm/mmu/page_track.c @@ -136,19 +136,14 @@ void kvm_slot_page_track_remove_page(struct kvm *kvm, } EXPORT_SYMBOL_GPL(kvm_slot_page_track_remove_page); -/* - * check if the corresponding access on the specified guest page is tracked. - */ -bool kvm_page_track_is_active(struct kvm_vcpu *vcpu, gfn_t gfn, - enum kvm_page_track_mode mode) +bool kvm_slot_page_track_is_active(struct kvm_memory_slot *slot, gfn_t gfn, + enum kvm_page_track_mode mode) { - struct kvm_memory_slot *slot; int index; if (WARN_ON(!page_track_mode_is_valid(mode))) return false; - slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn); if (!slot) return false; @@ -156,6 +151,17 @@ bool kvm_page_track_is_active(struct kvm_vcpu *vcpu, gfn_t gfn, return !!READ_ONCE(slot->arch.gfn_track[mode][index]); } +/* + * check if the corresponding access on the specified guest page is tracked. + */ +bool kvm_page_track_is_active(struct kvm_vcpu *vcpu, gfn_t gfn, + enum kvm_page_track_mode mode) +{ + struct kvm_memory_slot *slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn); + + return kvm_slot_page_track_is_active(slot, gfn, mode); +} + void kvm_page_track_cleanup(struct kvm *kvm) { struct kvm_page_track_notifier_head *head; -- 2.27.0