From patchwork Wed Jan 23 22:23:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10778001 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 3BDBF1515 for ; Wed, 23 Jan 2019 22:23:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BF6E2C4E2 for ; Wed, 23 Jan 2019 22:23:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EE502C4F8; Wed, 23 Jan 2019 22:23:51 +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 908602C4E4 for ; Wed, 23 Jan 2019 22:23:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D2C48E0054; Wed, 23 Jan 2019 17:23:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 885A58E0047; Wed, 23 Jan 2019 17:23:48 -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 6409A8E0054; Wed, 23 Jan 2019 17:23:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 220258E0047 for ; Wed, 23 Jan 2019 17:23:48 -0500 (EST) Received: by mail-qk1-f198.google.com with SMTP id y27so3418545qkj.21 for ; Wed, 23 Jan 2019 14:23:48 -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=3BKZ/v2XLYl6bJCscr3vEcuiItOFgg+U4duPRXYMcZs=; b=jJiYILb7XNTaIyZh3IO9G2b6e5IdaY0J5FV689LhKJXrU9HxRR7zAemCc+tpR1dhxM y+eGKt8H/SfxZjn4FrhZ26iisftVMV8KQxsBimTU7onVxvaiLlufTXUlWQscMd5dgqbh VMcrK2C0Wv5x0HFfmD3tMYAwq4xo7vgQPq2g2CWanlphbARG/uVcGTjj4D5EsFWM2xQC z3Jg9IxJ8TBGNG7E5lnF8zKdoqr9c8qlTjeFsGEe1MLJbZp1mAEhc5FnFF9EcBMdcdT/ tvgFgoBKBT8ghwYAy6Hj1LBR/blRiL37HsDPMiz4GAy4F/4iIbMdAk+lfkBTULvFxPNy IAXA== 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: AJcUukdA2CrdJ+32hFx0xV8AYQkyGJy645NN9r1izEi3ygRml1wClu7L iagn2ow0IKJoU6X+dEGEGW74E/55SQJrpipbdHIW8Ep6/M43Xe11Wt+q+f+IjO2aF9ixXtWichw hlarbexDCT1U60lRCMIccq5vt/kmI7BDR0Wb5lCXFFCRJ6uoEuqoovCupUHroX/Ur/A== X-Received: by 2002:a0c:df12:: with SMTP id g18mr3594221qvl.208.1548282227915; Wed, 23 Jan 2019 14:23:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN6UBInzbwTJYV+HJAMgFEB6g/5mMCWnOKz7i+QRJi/ezADdQyZUJXAcf77CPU5UEJPS0M2y X-Received: by 2002:a0c:df12:: with SMTP id g18mr3594201qvl.208.1548282227476; Wed, 23 Jan 2019 14:23:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548282227; cv=none; d=google.com; s=arc-20160816; b=T8J4cDwIDjCdNVmICh1E5/GK+9BNNDbpGaBfJ275OZ8Lri7wxDzsql9yuDVRmvHPDS +OfzAJvhmmD2BCGyLo5cqm++BL7r8KJ16jPfH+jPzYNrXQIYLp9aysC95ZvXKVANXuDr dyKLrSBkNaz1eTqhLz1zCb6DwQEfWhroIh6e6nVu4nviXOsWLFeKczVS0ruB8ayiuBg+ RS8b3g5yMU1T3/5rKlZvqtslRJE5/6Vxa1Wyh4yM7yjEsrAR46zsteOaso8bFLl7h+Ma WLJZ34oi6mReeu/PISPrGnKtE4BWghu/8g2mB65E7EuZ/0xduL7Y6NbPseY8NRKvKZOF Pm7A== 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=3BKZ/v2XLYl6bJCscr3vEcuiItOFgg+U4duPRXYMcZs=; b=B2C2UZ5NpN3I9JNFqw28//N9s7ahE3ol+o7HHIJS2Mno86nC5CzRstlgJFKG2EFUCe gEjc5v9adFDeP1vlhR09Su04rek7ppvx5vCx6fhcu1vlJO3qwhBKKgtIw6i+QBdtdH4L zT1g2PrmbbFwMrwMwX5a2F2h9zAib3zOzDqFusWxpTKRwsKuAtEg+7d4S/E1hG/nrt1z YyHx9gtLmluDaNJ8/HVsNfwtGKfpwnYW5jIx/E3SNR79GErVzmmbvxtkRq0IidgytV39 m08lV7YIqsahT4D8Kcj8ZQS9v9UltwN88Cgu9JWnHxOjx0fEKI4jG2ro+pWIxXcS3o13 TTtA== 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 h10si8990634qtc.140.2019.01.23.14.23.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 14:23:47 -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 61CC618DF61; Wed, 23 Jan 2019 22:23:46 +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 B5EAC5D965; Wed, 23 Jan 2019 22:23:43 +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 6/9] gpu/drm/radeon: optimize out the case when a range is updated to read only Date: Wed, 23 Jan 2019 17:23:12 -0500 Message-Id: <20190123222315.1122-7-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.29]); Wed, 23 Jan 2019 22:23:46 +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/radeon/radeon_mn.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c index b3019505065a..f77294f58e63 100644 --- a/drivers/gpu/drm/radeon/radeon_mn.c +++ b/drivers/gpu/drm/radeon/radeon_mn.c @@ -124,6 +124,7 @@ static int radeon_mn_invalidate_range_start(struct mmu_notifier *mn, struct radeon_mn *rmn = container_of(mn, struct radeon_mn, mn); struct ttm_operation_ctx ctx = { false, false }; struct interval_tree_node *it; + bool update_to_read_only; unsigned long end; int ret = 0; @@ -138,6 +139,8 @@ static int radeon_mn_invalidate_range_start(struct mmu_notifier *mn, else if (!mutex_trylock(&rmn->lock)) return -EAGAIN; + update_to_read_only = mmu_notifier_range_update_to_read_only(range); + it = interval_tree_iter_first(&rmn->objects, range->start, end); while (it) { struct radeon_mn_node *node; @@ -153,10 +156,20 @@ static int radeon_mn_invalidate_range_start(struct mmu_notifier *mn, it = interval_tree_iter_next(it, range->start, end); list_for_each_entry(bo, &node->bos, mn_list) { + bool read_only; if (!bo->tbo.ttm || bo->tbo.ttm->state != tt_bound) continue; + /* + * 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 = radeon_ttm_tt_is_readonly(bo->tbo.ttm); + if (update_to_read_only && read_only) + continue; + r = radeon_bo_reserve(bo, true); if (r) { DRM_ERROR("(%ld) failed to reserve user bo\n", r);