From patchwork Sat Jul 29 01:35:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13332950 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44A14C001DE for ; Sat, 29 Jul 2023 01:36:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 33A2F10E7CE; Sat, 29 Jul 2023 01:36:31 +0000 (UTC) Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by gabe.freedesktop.org (Postfix) with ESMTPS id 35B9A10E7CC for ; Sat, 29 Jul 2023 01:36:21 +0000 (UTC) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1bb982d2603so24621875ad.3 for ; Fri, 28 Jul 2023 18:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690594581; x=1691199381; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=uiEB/kQUv0ir0mfmtivhGXvmCVUeZ0u7hnCpQaqn4t4=; b=W1WZttu6R8I/jENPLMiq750pAPjCMMHtOHh60LBbYPpNTeCH0ePA0H+jt6+kfLVsE/ hjHYcM7jdTFnI5wdJLWy4mdFWEzvMyZ9anQ2EAvPbF2qJ7U38NamwLi1U7pfo057CNuL 2AyKDyj7uTqX0DsUcbae5I58jCUo+YVEiXj2LM9V/Ida88PEMWuE/vyDO6jjBeYyYFSf qdmjxt1/nTKtgrrq/DztwAtgNoSuQje8eJIRPHzT4zNsxPsaP1nnXSXxV+Qj6+5miIHC 9hBFHCE/Pz6DrBA5toquhFoXIF0k6X710ptrk4VIl44Wbxnqtawa8NKi1CkuxdBwbW8Y wa4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690594581; x=1691199381; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uiEB/kQUv0ir0mfmtivhGXvmCVUeZ0u7hnCpQaqn4t4=; b=c+YanUGcAmJL4HzUUoiuY2Xkt0wHWDjkCfEf6Vll/7FBXOQBvG3ltWwDqE85H8nsL2 JnZK+qw6sXSdX3S1DWPktyfncrFgPfK4XJUak4dD3gQW0p+wNPVadK02oatSquXXbiuw RJvhmhrEbyxKmrDOlswit9PJy25LNfEhCSjuYBGzQgKP6GvUt25PuRFGnMzx1VQgzARK HuTpdOrqhlbf4Z3s3S13IbtxCqQ/w9GwT4uZN52WCucetfP/3ji3oN2FShYOSQJax8Iv XG1XbsM3DrMclgmDEzWR6mh3qxDjJuKuxTZyFgQYPoLbpK35FgHO89LAzrbwJYOTIydu jtmg== X-Gm-Message-State: ABy/qLan6Su7o4QxqVim2JjhRTjnUGcVxKwU/FgMeD5jZ6mSHr5KOSFk 0YcU2etZEwu0of8UD3Sji0T7mN4WBkw= X-Google-Smtp-Source: APBJJlGXeVSCywK4IEJvnvwRYK3nnhvZFsuPXvnKZt5S6oIw94vJeB4OV6O4ynLG7j1W7KhxRTCUgMkCtis= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:da86:b0:1ba:a36d:f82c with SMTP id j6-20020a170902da8600b001baa36df82cmr12754plx.7.1690594580835; Fri, 28 Jul 2023 18:36:20 -0700 (PDT) Date: Fri, 28 Jul 2023 18:35:25 -0700 In-Reply-To: <20230729013535.1070024-1-seanjc@google.com> Mime-Version: 1.0 References: <20230729013535.1070024-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230729013535.1070024-20-seanjc@google.com> From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Zhenyu Wang , Zhi Wang Subject: [Intel-gfx] [PATCH v4 19/29] drm/i915/gvt: switch from ->track_flush_slot() to ->track_remove_region() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Cc: Yan Zhao , kvm@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Yongwei Ma , Ben Gardon , intel-gvt-dev@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Yan Zhao Switch from the poorly named and flawed ->track_flush_slot() to the newly introduced ->track_remove_region(). From KVMGT's perspective, the two hooks are functionally equivalent, the only difference being that ->track_remove_region() is called only when KVM is 100% certain the memory region will be removed, i.e. is invoked slightly later in KVM's memslot modification flow. Cc: Zhenyu Wang Suggested-by: Sean Christopherson Signed-off-by: Yan Zhao [sean: handle name change, massage changelog, rebase] Tested-by: Yan Zhao Tested-by: Yongwei Ma Signed-off-by: Sean Christopherson Reviewed-by: Zhi Wang --- drivers/gpu/drm/i915/gvt/kvmgt.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 3ea3cb9eb599..3f2327455d85 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -108,9 +108,8 @@ struct gvt_dma { static void kvmgt_page_track_write(gpa_t gpa, const u8 *val, int len, struct kvm_page_track_notifier_node *node); -static void kvmgt_page_track_flush_slot(struct kvm *kvm, - struct kvm_memory_slot *slot, - struct kvm_page_track_notifier_node *node); +static void kvmgt_page_track_remove_region(gfn_t gfn, unsigned long nr_pages, + struct kvm_page_track_notifier_node *node); static ssize_t intel_vgpu_show_description(struct mdev_type *mtype, char *buf) { @@ -666,7 +665,7 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev) return -EEXIST; vgpu->track_node.track_write = kvmgt_page_track_write; - vgpu->track_node.track_flush_slot = kvmgt_page_track_flush_slot; + vgpu->track_node.track_remove_region = kvmgt_page_track_remove_region; kvm_get_kvm(vgpu->vfio_device.kvm); kvm_page_track_register_notifier(vgpu->vfio_device.kvm, &vgpu->track_node); @@ -1617,22 +1616,20 @@ static void kvmgt_page_track_write(gpa_t gpa, const u8 *val, int len, mutex_unlock(&info->vgpu_lock); } -static void kvmgt_page_track_flush_slot(struct kvm *kvm, - struct kvm_memory_slot *slot, - struct kvm_page_track_notifier_node *node) +static void kvmgt_page_track_remove_region(gfn_t gfn, unsigned long nr_pages, + struct kvm_page_track_notifier_node *node) { unsigned long i; - gfn_t gfn; struct intel_vgpu *info = container_of(node, struct intel_vgpu, track_node); mutex_lock(&info->vgpu_lock); - for (i = 0; i < slot->npages; i++) { - gfn = slot->base_gfn + i; - if (kvmgt_gfn_is_write_protected(info, gfn)) - kvmgt_protect_table_del(info, gfn); + for (i = 0; i < nr_pages; i++) { + if (kvmgt_gfn_is_write_protected(info, gfn + i)) + kvmgt_protect_table_del(info, gfn + i); } + mutex_unlock(&info->vgpu_lock); }