Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6021618ybl; Tue, 14 Jan 2020 20:05:26 -0800 (PST) X-Google-Smtp-Source: APXvYqxemPHhU5NQ+QIPULqQJPQeb+9TCpC3zE/DYfLY5bVrzMngvDLmeMqb/Xk4I2S4CAzPJaSq X-Received: by 2002:aca:f20b:: with SMTP id q11mr18735954oih.78.1579061126026; Tue, 14 Jan 2020 20:05:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579061126; cv=none; d=google.com; s=arc-20160816; b=ozL2OMsAd5lyAXtU3rSWf/0qhsebDNTsZxSUDsoPOz9t5DJWy5OilFF1kwYo6xm8j1 v/kx1X2u+zHqbeY1rFpFNnJKeVh8yWISjW3UhHIcRJ9bXHAXDZXKKWKlZIbabSDGJK7g lwefuR1hzm6lxMqcQu4FrEd1tCD+1OWLFgcAKsmeqdieNS6rKCsrhT/qOjkNO5uM9X+D UsqrUBdb4Atmgi0MIEKKeRgRuimA5T9oHbJ6E7AYFHsGJ2RA6xmEmn2AljQv+kX4k9jI HiHUJ/PErL21C0JetG0CUh8cMQ2ptM5V2m4uRGQHGLeiZpqQH0/cXA53g54BciSTSrCr KvWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=KKGZYBFAm2JdGlGiKrjTLPzdnswuipHlAk1DvEL9Pr0=; b=cyt1X8w41jP2o7kAIlpMSlJiiK4KEc+syFhamT8nv2eXW+5hKb0XMSDnMyPRlNeHrW tbVwe22eZ0I9XAMnvwlmiO2vO9NZXjXSwVup1kQprwUq3lxHy6FdjEVzOvhDmkd8Qejl rA6QA67qDEAWhSYDMp4kQmzxCXYxF6fKUX0jPWNDKYOUE9HtKAA9BYfTGPSmsGO8Lz8t kBVfpEBdGZ+KiRyX+dNLZ2rAF0YUE+YwFqjbmLntUDro31goV0v3xc/RuGqSIZzQjGeL MKu+UOr8tkp7dQln8vMKTb9Zykd8Cb0IYoJVoasJ03IPEVuOHNqYGhjDAe4cxsTnzpDb L7xA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g14si9856306otj.10.2020.01.14.20.05.14; Tue, 14 Jan 2020 20:05:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729100AbgAOEEM (ORCPT + 99 others); Tue, 14 Jan 2020 23:04:12 -0500 Received: from mga06.intel.com ([134.134.136.31]:26364 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728879AbgAOEEM (ORCPT ); Tue, 14 Jan 2020 23:04:12 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2020 20:04:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,321,1574150400"; d="scan'208";a="217983429" Received: from unknown (HELO joy-OptiPlex-7040.sh.intel.com) ([10.239.13.9]) by orsmga008.jf.intel.com with ESMTP; 14 Jan 2020 20:04:09 -0800 From: Yan Zhao To: zhenyuw@linux.intel.com Cc: alex.williamson@redhat.com, intel-gvt-dev@lists.freedesktop.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, kevin.tian@intel.com, peterx@redhat.com, Yan Zhao Subject: [PATCH v2 2/2] drm/i915/gvt: subsitute kvm_read/write_guest with vfio_dma_rw Date: Tue, 14 Jan 2020 22:54:55 -0500 Message-Id: <20200115035455.12417-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200115034132.2753-1-yan.y.zhao@intel.com> References: <20200115034132.2753-1-yan.y.zhao@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As a device model, it is better to read/write guest memory using vfio interface, so that vfio is able to maintain dirty info of device IOVAs. Compared to kvm interfaces kvm_read/write_guest(), vfio_dma_rw() has ~600 cycles more overhead on average. ------------------------------------- | interface | avg cpu cycles | |-----------------------------------| | kvm_write_guest | 1554 | | ----------------------------------| | kvm_read_guest | 707 | |-----------------------------------| | vfio_dma_rw(w) | 2274 | |-----------------------------------| | vfio_dma_rw(r) | 1378 | ------------------------------------- Comparison of benchmarks scores are as blow: ------------------------------------------------------ | avg score | kvm_read/write_guest | vfio_dma_rw | |----------------------------------------------------| | Glmark2 | 1284 | 1296 | |----------------------------------------------------| | Lightsmark | 61.24 | 61.27 | |----------------------------------------------------| | OpenArena | 140.9 | 137.4 | |----------------------------------------------------| | Heaven | 671 | 670 | ------------------------------------------------------ No obvious performance downgrade found. Cc: Kevin Tian Signed-off-by: Yan Zhao --- drivers/gpu/drm/i915/gvt/kvmgt.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index bd79a9718cc7..17edc9a7ff05 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -1966,31 +1966,19 @@ static int kvmgt_rw_gpa(unsigned long handle, unsigned long gpa, void *buf, unsigned long len, bool write) { struct kvmgt_guest_info *info; - struct kvm *kvm; - int idx, ret; - bool kthread = current->mm == NULL; + int ret; + struct intel_vgpu *vgpu; + struct device *dev; if (!handle_valid(handle)) return -ESRCH; info = (struct kvmgt_guest_info *)handle; - kvm = info->kvm; - - if (kthread) { - if (!mmget_not_zero(kvm->mm)) - return -EFAULT; - use_mm(kvm->mm); - } - - idx = srcu_read_lock(&kvm->srcu); - ret = write ? kvm_write_guest(kvm, gpa, buf, len) : - kvm_read_guest(kvm, gpa, buf, len); - srcu_read_unlock(&kvm->srcu, idx); + vgpu = info->vgpu; + dev = mdev_dev(vgpu->vdev.mdev); - if (kthread) { - unuse_mm(kvm->mm); - mmput(kvm->mm); - } + ret = write ? vfio_dma_rw(dev, gpa, buf, len, true) : + vfio_dma_rw(dev, gpa, buf, len, false); return ret; } -- 2.17.1