Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1298381imu; Wed, 23 Jan 2019 14:26:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN730f3mJk0JiwkONgYDmZ+xHdA8muLm+N9iWKCieZR0LPlDiImY5AkaEYkgW9/PO5txPQ2S X-Received: by 2002:a17:902:3143:: with SMTP id w61mr4155464plb.253.1548282378627; Wed, 23 Jan 2019 14:26:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548282378; cv=none; d=google.com; s=arc-20160816; b=0JGlVqPdDUSS+LIy1xzz5UrvmjErE3Po/eDlM5KO8gBJjqem1xAm+a2yFAYblsFidg V/YKM7G+dMclvY3gDOzBRW0US2MDZjpfE7r7BWKh4w+kllN5JDUtcKqK81LAvQkJp1+T QLph1e2Vl9xuO4GK17r6ce0fmalmE6u9WQZNB5mMMngdxfKspL2h0SDZiN6CMi7+RZZs Umc0j2A+zDR+YKI+MzTgefF9Pfev+Ync2zNptD1clP4cEUHNkVdWEilSbQjJAAFLfD8y aeTOcJEaXoQJggO3lLcoUVqQ2jrfvIT8qUuGC7MvdiBa5cfG4gm+1jfpC86lmc9HvWCy iymA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Lzj9jwerKIllHI5/K1OIrzFaHxAO7K6V4cLHs1Jtprw=; b=twNYOR6VG8foSnlcTgx0oU50nUkvTOjLrNORyDfc5V+5poSlYOSXo2xEXzxdFg7q4y QFcjmBDy/nSTJdpf6VJKKkQhy+zinSd0CXcCQFyL8ACPa0ScabvLMVZ/aO/PafeBI5ej Delp3375eMI3ubLauJ9s+flvvwtta8RuazCSTGdvmLTJzPA4IrHf3dSvOoUBQU0CqQVP 8v8EejnFIdDWmXr3mW+AdZZDCzVr3uEXVWUepQ1iKFMf+vvLrFsM1Kn9aKWwBkaauj6I YMd3WipSdjOqqOYrRtdHKypcZuBXnEGzJKmZEet+YrID0wMfZx8l1w0Uo8dC31pnYkNq fXYw== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o192si14742854pgo.129.2019.01.23.14.26.03; Wed, 23 Jan 2019 14:26:18 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727414AbfAWWYQ (ORCPT + 99 others); Wed, 23 Jan 2019 17:24:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54486 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727297AbfAWWXt (ORCPT ); Wed, 23 Jan 2019 17:23:49 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DA69432A0; Wed, 23 Jan 2019 22:23:49 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-120-127.rdu2.redhat.com [10.10.120.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87EAF6A685; Wed, 23 Jan 2019 22:23:46 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org Cc: Andrew Morton , linux-kernel@vger.kernel.org, =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jan Kara , Felix Kuehling , Jason Gunthorpe , Matthew Wilcox , Ross Zwisler , Dan Williams , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Michal Hocko , Ralph Campbell , John Hubbard , kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v4 7/9] gpu/drm/amdgpu: optimize out the case when a range is updated to read only Date: Wed, 23 Jan 2019 17:23:13 -0500 Message-Id: <20190123222315.1122-8-jglisse@redhat.com> In-Reply-To: <20190123222315.1122-1-jglisse@redhat.com> References: <20190123222315.1122-1-jglisse@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 23 Jan 2019 22:23:49 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jérôme Glisse When range of virtual address is updated read only and corresponding user ptr object are already read only it is pointless to do anything. Optimize this case out. Signed-off-by: Jérôme Glisse Cc: Christian König Cc: Jan Kara Cc: Felix Kuehling Cc: Jason Gunthorpe Cc: Andrew Morton Cc: Matthew Wilcox Cc: Ross Zwisler Cc: Dan Williams Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Michal Hocko Cc: Ralph Campbell Cc: John Hubbard Cc: kvm@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linux-rdma@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: Arnd Bergmann --- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c index 3e6823fdd939..7880eda064cd 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c @@ -294,6 +294,7 @@ static int amdgpu_mn_invalidate_range_start_hsa(struct mmu_notifier *mn, { struct amdgpu_mn *amn = container_of(mn, struct amdgpu_mn, mn); struct interval_tree_node *it; + bool update_to_read_only; unsigned long end; /* notification is exclusive, but interval is inclusive */ @@ -302,6 +303,8 @@ static int amdgpu_mn_invalidate_range_start_hsa(struct mmu_notifier *mn, if (amdgpu_mn_read_lock(amn, range->blockable)) return -EAGAIN; + update_to_read_only = mmu_notifier_range_update_to_read_only(range); + it = interval_tree_iter_first(&amn->objects, range->start, end); while (it) { struct amdgpu_mn_node *node; @@ -317,6 +320,16 @@ static int amdgpu_mn_invalidate_range_start_hsa(struct mmu_notifier *mn, list_for_each_entry(bo, &node->bos, mn_list) { struct kgd_mem *mem = bo->kfd_bo; + bool read_only; + + /* + * If it is already read only and we are updating to + * read only then we do not need to change anything. + * So save time and skip this one. + */ + read_only = amdgpu_ttm_tt_is_readonly(bo->tbo.ttm); + if (update_to_read_only && read_only) + continue; if (amdgpu_ttm_tt_affect_userptr(bo->tbo.ttm, range->start, -- 2.17.2