Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2320722pxu; Mon, 7 Dec 2020 03:39:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/Alj8TDMs4dBRDxd95+ehDfRbDDqov3YyDZMrkXTrt/93Uz9kd0rwfCXqlQ0cOC9p9K7t X-Received: by 2002:a17:906:eb49:: with SMTP id mc9mr17835047ejb.487.1607341189287; Mon, 07 Dec 2020 03:39:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607341189; cv=none; d=google.com; s=arc-20160816; b=u7dc5UqDYqIrRGi9AJI5xaIFeQ5+0kkkC6Jib3dSIvvEzkoJIpe5M3HPL0q2pfY2gS Az9wxPwziu1wW+z10UxksbwfUgbYwJ+27Q/NmJCqAifX7XMPv2i2ff5v7eaY8kCOjkI+ TSUeAE9nQ2rJhG7+fbpFiTEpA1LRyGI5TIQEgBg/txghoZhc5+3kRV4UBEvd2y+JuTvE 3ekj/FWdSrfRqhM7EN7bg145aLyOswQM/oYN8LQVVQZLa3OWUbzAA9Z2+Z+VApiZjPI3 QNUxrBz+53HhZh1OpPylcZxeHBH0jsHPJvuJPeC2IGbBJMno6vLIvzdhMFWjGsy9Hj8k TLeg== 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=01Z5fklCLxTkAgFCaz6nAUEBM28bmnYK87yE7XDoghk=; b=Ix9JGb5ogJ2pfl2eHbwS4DZ+K0lLzhcJtO2Xyz0gZ66CWmhd7duswMTtpTJdswZ9t0 06CiGQdEoLXo+QEURByHvi2GHBqPuOQdZVWZFoGh4iVpjW+8AabRwZOK+jzBhzByoNO2 od2qLhJ3IxAtaYRnYm+J8jxB/reG+qEqrU5WdYZuNieVs0w8uKmfq3MmE2gTcFkQMYsD lLW9Eecb7Sz6RkAi4Ka7KQVR4e0BamD2TlQvskvZRQyvGDXpMwfppBPV2QsraZbQTgLb 0wDWW7lWp1qOGbRYTEPy/DdEuVfP7WJt/70phOrEGQ237N0GxLOE5Q0pksFCrgef+TkJ LShQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ow37ASks; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x17si6548926ejw.478.2020.12.07.03.39.26; Mon, 07 Dec 2020 03:39:49 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=Ow37ASks; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727685AbgLGLgY (ORCPT + 99 others); Mon, 7 Dec 2020 06:36:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbgLGLgW (ORCPT ); Mon, 7 Dec 2020 06:36:22 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F203C0613D4; Mon, 7 Dec 2020 03:35:42 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id f17so8656765pge.6; Mon, 07 Dec 2020 03:35:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=01Z5fklCLxTkAgFCaz6nAUEBM28bmnYK87yE7XDoghk=; b=Ow37ASksRvhh9CbdtCHIUcexMF92+y/fcxUo4cp1Hcu1OVAkm4VgeqQuRQn3wk6HYw HBIvMgI3NhxdwdBCKwt5Iq4O8LCN4Ax1wiG4DsCvRan0q4fRQKL8bzXsSjED1ZZnfPtW i2fYicNCYucP2yFhvKqZO390HegOf8okFuF473TH47NWnU5wevHxKx8xWUmYQMv1OtGt 0lIXeFTqGZWaY2z+qKMSdfJnMGbGjjHGIm7bp+KVSSw1iX8dSHyykquckNwiMQ3vazJb w8osDFx9fg+nq686wIqW3v7PfEnSUS4MCwgVJ3Vx8c8qTcTONTPefKk36TylgEAY+cPI pfmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=01Z5fklCLxTkAgFCaz6nAUEBM28bmnYK87yE7XDoghk=; b=PR0MrBiA9//P1Ma7RKw7i/yhY1UhpcAh980wx1c3fqfEF5wF0Xjdlgzmnvm+W3aWwR f2KSBT+r0OuyDsYCKs18bjudL6dqBgs88wVbf4AisVEgtvr3zPLqIASAwQoADNqcPV+d RXktpWd8Ww6jlCNmaIIdiNDrXXydbWalOQ13JxgFEt7KpTpoM9mnt2ktkVp3gBxhplbk kQ8LGcgo7/ebm/CDLykjb825w8tKL695Cz1zzVYzRBX2z6+3UM7vnnH9cBfK8cMFhlia RUJrBnkS2AUgQOIcqGGO27voFpPivp20rz6mWJXhL4HCNW9vGS5pRA2/F5FLgvsRPq9S Hulw== X-Gm-Message-State: AOAM5322XJ3Lvmry8oFXCykZNgd1cpJ2fCGY/YU0BX1rGZt0UTeHEk+X 6H5k8XGOGbqupDhdPo4au3Q= X-Received: by 2002:a63:a551:: with SMTP id r17mr3001298pgu.13.1607340942035; Mon, 07 Dec 2020 03:35:42 -0800 (PST) Received: from localhost.localdomain ([203.205.141.39]) by smtp.gmail.com with ESMTPSA id d4sm14219822pfo.127.2020.12.07.03.35.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Dec 2020 03:35:41 -0800 (PST) From: yulei.kernel@gmail.com X-Google-Original-From: yuleixzhang@tencent.com To: linux-mm@kvack.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, naoya.horiguchi@nec.com, viro@zeniv.linux.org.uk, pbonzini@redhat.com Cc: joao.m.martins@oracle.com, rdunlap@infradead.org, sean.j.christopherson@intel.com, xiaoguangrong.eric@gmail.com, kernellwp@gmail.com, lihaiwei.kernel@gmail.com, Yulei Zhang , Chen Zhuo Subject: [RFC V2 36/37] vfio: support dmempage refcount for vfio Date: Mon, 7 Dec 2020 19:31:29 +0800 Message-Id: <0e5dd1479a55d8af7adfe44390f8e45186295dce.1607332046.git.yuleixzhang@tencent.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yulei Zhang Add get/put_dmem_pfn(), each time when vfio module reference/release dmempages. Signed-off-by: Chen Zhuo Signed-off-by: Yulei Zhang --- drivers/vfio/vfio_iommu_type1.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index c465d1a..4856a89 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -39,6 +39,7 @@ #include #include #include +#include #define DRIVER_VERSION "0.2" #define DRIVER_AUTHOR "Alex Williamson " @@ -411,7 +412,10 @@ static int put_pfn(unsigned long pfn, int prot) unpin_user_pages_dirty_lock(&page, 1, prot & IOMMU_WRITE); return 1; - } + } else if (is_dmem_pfn(pfn)) + put_dmem_pfn(pfn); + + /* Dmem page is not counted against user. */ return 0; } @@ -477,6 +481,9 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, if (!ret && !is_invalid_reserved_pfn(*pfn)) ret = -EFAULT; + + if (!ret && is_dmem_pfn(*pfn)) + get_dmem_pfn(*pfn); } done: mmap_read_unlock(mm); -- 1.8.3.1