From patchwork Wed Jan 23 22:23:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10778011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C6511390 for ; Wed, 23 Jan 2019 22:23:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E9512C4E4 for ; Wed, 23 Jan 2019 22:23:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 625462C4FE; Wed, 23 Jan 2019 22:23:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD0922C4E4 for ; Wed, 23 Jan 2019 22:23:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1AC038E0056; Wed, 23 Jan 2019 17:23:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 132A68E0047; Wed, 23 Jan 2019 17:23:54 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F193E8E0056; Wed, 23 Jan 2019 17:23:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id B703A8E0047 for ; Wed, 23 Jan 2019 17:23:53 -0500 (EST) Received: by mail-qt1-f199.google.com with SMTP id n39so4243353qtn.18 for ; Wed, 23 Jan 2019 14:23:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=34YO05DWvZaBCpecq87OHHtqkWxKN3JMaZNkpjw+OvE=; b=DwH/48u4sQX62ClPyx+MUU8BX6GE26t2acAhWwlgVd9DISW9rC9mb92SDnTclZq73M aDbI7Q25MsnLXbHmPDUct1+q78qRI55XlzCuQVgqbXrPxA0dl24G485z55d/ZdG/6KDf v7OF9alq4K4BsncwArNtiNiIxY1JEmwQIuZHqUrTX7qVzMjdrHwWximyAkdOS1hWFUXD ZQt2w/oDcJJT0DbFWikCy/xKQYcChxg5L4uoJTVsetKVq9yDG4x/nyZdRsw7ozPa8O4f AMzSEK2FCoZlSax5d+IMesHrrpaqwaFtNmDFh6e2Y4alW3qTzc9MxylWps5dJ0CLHShh FefQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AJcUukegj5w36pISwRwDVpl2WofXsY79U6RaV+Pj2y2PgU1BNQ86UhBk 2IJflBcc6QuwfzQyDqsZf4Gx27po2dJQZqIjUUfcALjka+qReewPC0Wo2bJRWEhIMpw1iKniuoj AogoBv0Fhd0SEe0GDU3riLSrY+besE2SuiOIHvZvBOkof5/ZImPNeNElf1G5mbB1FSw== X-Received: by 2002:a37:9906:: with SMTP id b6mr3502733qke.208.1548282233509; Wed, 23 Jan 2019 14:23:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN53tt8wz8lyZLBFP7iy4aUT1lmixNDy+L94+LwAU1gLaCV7lZ3ktmnUHJqStozMJHI8KpWP X-Received: by 2002:a37:9906:: with SMTP id b6mr3502719qke.208.1548282233043; Wed, 23 Jan 2019 14:23:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548282233; cv=none; d=google.com; s=arc-20160816; b=HS0a4nzM2WnvDdQ0j+3wbYiGhybXr/pxwfLq/OPd/vj0O1kbWzrLbG9JsGSjpmMb5q ooriEu3cWgwS/1w4Jm+ZlW40kRnz8R5Fvr7o0x1GWsa+HlQ9eUswW4RtBzbK7sHb/dg9 kTbp8yuLlFvr87zU7tXINYIQqEsiE0MVc9IlwhEJ1Q2gutTB5j98jtK7ujskU96KGd4Y BdwSY3f0qUhiFAnYtpiEUArCTvyGsZID3PcmsiJdoRku5hIRQHsF8KVm4JnTzf4JxTKJ kyWoD3yBwHqfnuzGEsmlPMtFCuF1LlwEaNYuSpm4mamHT41ZeRC80jskcRvIyRTYj322 HWsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=34YO05DWvZaBCpecq87OHHtqkWxKN3JMaZNkpjw+OvE=; b=rQfpShvetw755d0C2pQHoP6cLeWkU2y3UxrCCBorumvuWWE/OAsJm/eNdPWOXEPXh8 k0WRgiJNGPa/dnED/OHPolBrFImT24oalwESl+NJTtN5jVPQNaTVRKS5xb3QFd0enrkl iYDyLoDcgatk6oM6BJ7OEsrVnpl5Pyny+AK+T9C0pExrryIpXmXiZjNtE5rCu/4U0m0M oaq3K4AQwr3YmzAFri6KME37p+ECyzkAGuPUMVOs/rtL5mMNooYMxs/KG2iVlOJtJTaM hsb1gX/wElk8XjvreY8UJswfnjtQQjJudBjrYg8s2TOuAV7vBG0dpFeBysoZpIpAkoPZ Rx3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id f20si323926qtm.242.2019.01.23.14.23.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 14:23:53 -0800 (PST) Received-SPF: pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 067D8432C1; Wed, 23 Jan 2019 22:23:52 +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 5CF0E5D965; Wed, 23 Jan 2019 22:23:49 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org Cc: Andrew Morton , linux-kernel@vger.kernel.org, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , =?utf-8?q?Christian_?= =?utf-8?q?K=C3=B6nig?= , Jan Kara , Felix Kuehling , Jason Gunthorpe , Matthew Wilcox , Ross Zwisler , Dan Williams , Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , 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 8/9] gpu/drm/i915: optimize out the case when a range is updated to read only Date: Wed, 23 Jan 2019 17:23:14 -0500 Message-Id: <20190123222315.1122-9-jglisse@redhat.com> In-Reply-To: <20190123222315.1122-1-jglisse@redhat.com> References: <20190123222315.1122-1-jglisse@redhat.com> MIME-Version: 1.0 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:52 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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/i915/i915_gem_userptr.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c index 9558582c105e..23330ac3d7ea 100644 --- a/drivers/gpu/drm/i915/i915_gem_userptr.c +++ b/drivers/gpu/drm/i915/i915_gem_userptr.c @@ -59,6 +59,7 @@ struct i915_mmu_object { struct interval_tree_node it; struct list_head link; struct work_struct work; + bool read_only; bool attached; }; @@ -119,6 +120,7 @@ static int i915_gem_userptr_mn_invalidate_range_start(struct mmu_notifier *_mn, container_of(_mn, struct i915_mmu_notifier, mn); struct i915_mmu_object *mo; struct interval_tree_node *it; + bool update_to_read_only; LIST_HEAD(cancelled); unsigned long end; @@ -128,6 +130,8 @@ static int i915_gem_userptr_mn_invalidate_range_start(struct mmu_notifier *_mn, /* interval ranges are inclusive, but invalidate range is exclusive */ end = range->end - 1; + update_to_read_only = mmu_notifier_range_update_to_read_only(range); + spin_lock(&mn->lock); it = interval_tree_iter_first(&mn->objects, range->start, end); while (it) { @@ -145,6 +149,17 @@ static int i915_gem_userptr_mn_invalidate_range_start(struct mmu_notifier *_mn, * object if it is not in the process of being destroyed. */ mo = container_of(it, struct i915_mmu_object, it); + + /* + * 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. + */ + if (update_to_read_only && mo->read_only) { + it = interval_tree_iter_next(it, range->start, end); + continue; + } + if (kref_get_unless_zero(&mo->obj->base.refcount)) queue_work(mn->wq, &mo->work); @@ -270,6 +285,7 @@ i915_gem_userptr_init__mmu_notifier(struct drm_i915_gem_object *obj, mo->mn = mn; mo->obj = obj; mo->it.start = obj->userptr.ptr; + mo->read_only = i915_gem_object_is_readonly(obj); mo->it.last = obj->userptr.ptr + obj->base.size - 1; INIT_WORK(&mo->work, cancel_userptr);