From patchwork Wed Jan 23 22:23:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10778005 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 D341F1390 for ; Wed, 23 Jan 2019 22:23:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C39242C4E4 for ; Wed, 23 Jan 2019 22:23:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B79742C4FE; Wed, 23 Jan 2019 22:23:53 +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=ham 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 318482C4E4 for ; Wed, 23 Jan 2019 22:23:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 444F38E0055; Wed, 23 Jan 2019 17:23:51 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3545B8E0047; Wed, 23 Jan 2019 17:23:51 -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 1F7628E0055; Wed, 23 Jan 2019 17:23:51 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id CEF748E0047 for ; Wed, 23 Jan 2019 17:23:50 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id n95so4290103qte.16 for ; Wed, 23 Jan 2019 14:23:50 -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=Lzj9jwerKIllHI5/K1OIrzFaHxAO7K6V4cLHs1Jtprw=; b=Kx0k13kMk2Ll9HibXwR4I7ZjPAXRMEmfz6Q575OANxqxD9CvlaAOQvMbADtF+VrnAn nxa+i4UbokqrEE7inBfjejL41b7ZJM6b0SYF3CwnIZvy5OiEg720HSZoFckp0jcEh3H7 PYNgNuqvzx3xXcqnAv7bEfQ24hnrEx+d/SxFx8sb+tjgoLtoCfWIG2i+2mHu/mdCUKnS QHWHEfqx/DSFUPHjp4JzsVnRpZwRNuzNF5k2MXupGEjRMEdtOGnk13y7YRIihEUjr2Gx 3aze+ZnWxEoQ6KVvifZqJfCF54Q9ICowWPKoSVdGdkH6WInp8WP4+T2w0pVAZZRbiaH+ 93+g== 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: AJcUukcxQZVwTyQ+ED14diyMLIKRb6jOTgziKaSHA+bWYiMVBZbcGUpM igWbqXMedWP2WOMcTQujkGOFAVyipV9hn9PSZReOzL6A/wbBKKAyCKF8w7VWJWZSkf+UJIZMqKc vlFYi22CRKfcctmXEK54HqSKv0NuhJ2DQ8iB1/SeUCSidL/tFR7QtNHD/w+RWl5KWyw== X-Received: by 2002:ac8:7493:: with SMTP id v19mr4227321qtq.309.1548282230635; Wed, 23 Jan 2019 14:23:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN5COj3udJkKVpvIKUuKc3wOttWDNpbJyUU6vD0ACui4i7BhP2k6m3aaCp7U2C+gxTF31JBl X-Received: by 2002:ac8:7493:: with SMTP id v19mr4227303qtq.309.1548282230117; Wed, 23 Jan 2019 14:23:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548282230; cv=none; d=google.com; s=arc-20160816; b=XPZrBiunBiw9OD8nwN0nIwGDeguCBwUSfVk9TgGNCcAzOU+ekVzWImczvc4pbWtjfW HB0NRM44r4lUwxwuh2zWNmL+hju9MUyazbzgHDAEeY9j1gK5Thb8KEGDc+/Bq3pOnIXU pPEdAJXpcxx/18aKk74uioeBKvmcdTakQxIn+TeHNBNW1bws//K2puK5k06hGviFz4wN igMdSPOnoDsAAbi9wq6ABewSbacKezTjsNPh8cfZM9Sp2JxaFp1UNlXjGZ8MXML1Y49j enJXzqqoOjqFz+QF0+spdLWodjguPWYWgFYvJBV6z41kEs//ldYvZskgaSPLR0vRQ/b6 WQPQ== 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=Lzj9jwerKIllHI5/K1OIrzFaHxAO7K6V4cLHs1Jtprw=; b=zChagEjIePuLf97ZIRJUSti59+/QCGSGO9IYj5y5zfdkL3qG4nxJlTsSZGlk4qOZ0q AdlwAGbukw8jSWXOGu75M3PcIU9qDOOM2Nm752cpJOz/9QH7X+1ZzaLJwxRrVIu113vq FVQKQWQREtypvOyVLwXGLA6pjQG5Bp2jj9IwT7jEil1mZUoVs5Ytd/VnUZP81bvRCxci HAsd/suYMZDQZmE07hCU1URWwXfQw+DJkRFFY5LG7cAxYmQGsl4ltoArege627Y/ElWk 5RUrgATCMWn6LwfbRKcCkc7TgyHZZvLSrgpBxtXgGGyec3Ycm01yBEhvPfD6s9kUuG3p hF/Q== 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 l2si2315120qtj.22.2019.01.23.14.23.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 14:23:50 -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 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?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 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 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) 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/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,