Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp15954lfv; Tue, 12 Apr 2022 15:22:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMs6ElQEj29nU2zzudLiJ3UFyEMCqJkjavUF/1IwVmNrzWUq57nDb59k7uNb0UUz0GDRWr X-Received: by 2002:aa7:8d47:0:b0:4f6:a7f9:1ead with SMTP id s7-20020aa78d47000000b004f6a7f91eadmr39843557pfe.42.1649802147433; Tue, 12 Apr 2022 15:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649802147; cv=none; d=google.com; s=arc-20160816; b=aiPl/MUOM5F0RTD6UT6AuGtmLbIBgOoBBlvYxpjvmXD8XD41f/+HcMB1dCsUu60Cbo OnvYR9tGEj33VlwzT9FL3OcU4iVNS3gS9LL/4pp/T2yffyBAI6JmP4ypxzCaC2gNILrR vB7RdTlRgqle8Msir3+rYcJfmRPqALrxZXZkWCPNFs+PmIpX9r7POTVFL8+GqWZlMMY+ acI16SRSy5Qp8li9sg2fRsVQVbHj0PHnuCMWHrL3RXEmB/Ki9C9FA70OrRRa4qJclTFG 5hly2iPb7bmKfXD1Qq4nY/0siudcM9X8Lt9msg+6++QR4dxA6BuTfYs2/4Y4+n/VGrcK kaAA== 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=goHHpI3WnE67v8nanm/rENsJPIStZtr1Ul7m3vMBtJ0=; b=UZdY9qHss1Ysp70VsGB2vn1jhMGnMjKu83EbtMm1jB2asw4odKA/W5X6B6dm2sN3ma 4K5Ih3xhGdDHTv8b3aTCYe4ESz6OIka2z51F08deL7qFl3/MWCsanRvlNhk5zXKfDNJW bCfa7yIWSWHS5xBVcaHGHgoddi4ZLPLtyVbN1njD0GRe0yftUCNDtMCmUids1pkLzH9d L8sxNYjim9HKDoCiWEb/3zZy7GGPZwI7zquKhKAuxU+gD0Kf1b4yD+cJOtWR6gea0fBm Y4dXGde3DJy3DH68Df66E3oAXi/21jPyAW828LCU1iwRy/U7jkwQs1gOwU0RGYRr+qyL +5fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=2NAGCqhd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k4-20020aa788c4000000b00505cdd19af1si6207502pff.51.2022.04.12.15.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 15:22:27 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=2NAGCqhd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 13A991786B9; Tue, 12 Apr 2022 14:03:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347227AbiDKOUF (ORCPT + 99 others); Mon, 11 Apr 2022 10:20:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347217AbiDKORb (ORCPT ); Mon, 11 Apr 2022 10:17:31 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B8FB15739 for ; Mon, 11 Apr 2022 07:15:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=goHHpI3WnE67v8nanm/rENsJPIStZtr1Ul7m3vMBtJ0=; b=2NAGCqhdgB8b4F/2Rwvj+R/2vh FDxGE8GIqEc3iEY9AGV6dI/c27YINZkmGyuMub2dU57o44VOhfs2RGgGZ+CJwz2JGxneizChac1gt BIQKnvuJTeKYTPNIS7d6enp6drlcqJYS1gP0zy58pcvDCwnwMDbZsXzELvbxlOcu1MrZCfE3YnhBk DcJyHlbEH4UfK6zxgVEhjfdbir2jrWPuL45lx2psjwiEnA27ypUHqC9d/+cMNo74/DmRfuK9pdu8M jF6duHGQTNyShG++26BoAr28sufIcfCl4JK0IkdGPpKjQbq3XmsUElsS9K3YdbzlSIjJY1DRIldkr fffkfBrA==; Received: from [2001:4bb8:18e:76f5:3747:ef85:d03d:53e4] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nduoo-009Ki9-Ao; Mon, 11 Apr 2022 14:15:02 +0000 From: Christoph Hellwig To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Zhenyu Wang , Zhi Wang Cc: Jason Gunthorpe , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 18/34] drm/i915/gvt: devirtualize ->is_valid_gfn Date: Mon, 11 Apr 2022 16:13:47 +0200 Message-Id: <20220411141403.86980-19-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220411141403.86980-1-hch@lst.de> References: <20220411141403.86980-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Just call the code directly and move towards the callers. Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/i915/gvt/gtt.c | 20 ++++++++++++++++++-- drivers/gpu/drm/i915/gvt/hypercall.h | 1 - drivers/gpu/drm/i915/gvt/kvmgt.c | 17 ----------------- drivers/gpu/drm/i915/gvt/mpt.h | 17 ----------------- 4 files changed, 18 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c index 9b696e5705eb7..1360412f8ef8a 100644 --- a/drivers/gpu/drm/i915/gvt/gtt.c +++ b/drivers/gpu/drm/i915/gvt/gtt.c @@ -49,6 +49,22 @@ static bool enable_out_of_sync = false; static int preallocated_oos_pages = 8192; +static bool intel_gvt_is_valid_gfn(struct intel_vgpu *vgpu, unsigned long gfn) +{ + struct kvm *kvm = vgpu->kvm; + int idx; + bool ret; + + if (!vgpu->attached) + return false; + + idx = srcu_read_lock(&kvm->srcu); + ret = kvm_is_visible_gfn(kvm, gfn); + srcu_read_unlock(&kvm->srcu, idx); + + return ret; +} + /* * validate a gm address and related range size, * translate it to host gm address @@ -1331,7 +1347,7 @@ static int ppgtt_populate_spt(struct intel_vgpu_ppgtt_spt *spt) ppgtt_set_shadow_entry(spt, &se, i); } else { gfn = ops->get_pfn(&ge); - if (!intel_gvt_hypervisor_is_valid_gfn(vgpu, gfn)) { + if (!intel_gvt_is_valid_gfn(vgpu, gfn)) { ops->set_pfn(&se, gvt->gtt.scratch_mfn); ppgtt_set_shadow_entry(spt, &se, i); continue; @@ -2315,7 +2331,7 @@ static int emulate_ggtt_mmio_write(struct intel_vgpu *vgpu, unsigned int off, /* one PTE update may be issued in multiple writes and the * first write may not construct a valid gfn */ - if (!intel_gvt_hypervisor_is_valid_gfn(vgpu, gfn)) { + if (!intel_gvt_is_valid_gfn(vgpu, gfn)) { ops->set_pfn(&m, gvt->gtt.scratch_mfn); goto out; } diff --git a/drivers/gpu/drm/i915/gvt/hypercall.h b/drivers/gpu/drm/i915/gvt/hypercall.h index de63bd8dd05ba..c1a9eeed04607 100644 --- a/drivers/gpu/drm/i915/gvt/hypercall.h +++ b/drivers/gpu/drm/i915/gvt/hypercall.h @@ -55,7 +55,6 @@ struct intel_gvt_mpt { dma_addr_t dma_addr); int (*dma_pin_guest_page)(struct intel_vgpu *vgpu, dma_addr_t dma_addr); - bool (*is_valid_gfn)(struct intel_vgpu *vgpu, unsigned long gfn); }; #endif /* _GVT_HYPERCALL_H_ */ diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 1d1c026fd8258..93fd7f997c8a1 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -1980,22 +1980,6 @@ static void kvmgt_dma_unmap_guest_page(struct intel_vgpu *vgpu, mutex_unlock(&vgpu->cache_lock); } -static bool kvmgt_is_valid_gfn(struct intel_vgpu *vgpu, unsigned long gfn) -{ - struct kvm *kvm = vgpu->kvm; - int idx; - bool ret; - - if (!vgpu->attached) - return false; - - idx = srcu_read_lock(&kvm->srcu); - ret = kvm_is_visible_gfn(kvm, gfn); - srcu_read_unlock(&kvm->srcu, idx); - - return ret; -} - static const struct intel_gvt_mpt kvmgt_mpt = { .host_init = kvmgt_host_init, .host_exit = kvmgt_host_exit, @@ -2005,7 +1989,6 @@ static const struct intel_gvt_mpt kvmgt_mpt = { .dma_map_guest_page = kvmgt_dma_map_guest_page, .dma_unmap_guest_page = kvmgt_dma_unmap_guest_page, .dma_pin_guest_page = kvmgt_dma_pin_guest_page, - .is_valid_gfn = kvmgt_is_valid_gfn, }; struct intel_gvt_host intel_gvt_host = { diff --git a/drivers/gpu/drm/i915/gvt/mpt.h b/drivers/gpu/drm/i915/gvt/mpt.h index 59369e8b3b692..1a796f2181ba8 100644 --- a/drivers/gpu/drm/i915/gvt/mpt.h +++ b/drivers/gpu/drm/i915/gvt/mpt.h @@ -157,21 +157,4 @@ intel_gvt_hypervisor_dma_pin_guest_page(struct intel_vgpu *vgpu, return intel_gvt_host.mpt->dma_pin_guest_page(vgpu, dma_addr); } -/** - * intel_gvt_hypervisor_is_valid_gfn - check if a visible gfn - * @vgpu: a vGPU - * @gfn: guest PFN - * - * Returns: - * true on valid gfn, false on not. - */ -static inline bool intel_gvt_hypervisor_is_valid_gfn( - struct intel_vgpu *vgpu, unsigned long gfn) -{ - if (!intel_gvt_host.mpt->is_valid_gfn) - return true; - - return intel_gvt_host.mpt->is_valid_gfn(vgpu, gfn); -} - #endif /* _GVT_MPT_H_ */ -- 2.30.2