Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5366210imw; Wed, 20 Jul 2022 04:28:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t/lKv/UVhoi2vK6SFL0SX7ETIAMPNR/gCsoH8n0/z30Ej1QGQ3E3iojsZa07a0zfR9ZFGK X-Received: by 2002:a17:90a:b703:b0:1dd:1e2f:97d7 with SMTP id l3-20020a17090ab70300b001dd1e2f97d7mr4837160pjr.62.1658316531586; Wed, 20 Jul 2022 04:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658316531; cv=none; d=google.com; s=arc-20160816; b=esEuuwUK7mjDJWo+XB9eo+aqATrKD7EmniA/5jLa7UxKn3L2o+IZTAst/VWu4MLZSj d78MeGq/kcNaXsnyk1oWb1pfO6oJnsRf75+Jm+5JieaYo+U58+n4gxCBDegiNKt8uxFc B6LbBQPQ7k/qjXNJDkAIuED251wc+c+m0FGxdimTiEDYxV9uyd+KwY1qRa9os2zyqFM9 pKBFuhx6txby2HD39Thr6lJhlkoVcjO5hQthxgDqIcm91j3ZHEHi/ddBERek0GHZE6rA 6tOpme8UUJTaOZZL91MDD676Vp9bAOaueubT5M6raJnhvrkBHNYB9ZUqyAHYj0/XEL3u AFZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=9DRwvbgJY1wXOc2HObGumML2CORZU3Pgh2U62MNWMcU=; b=U1Pf6Ny3TRN8o1JZ8VNcwOI0q4XRJCJJx7UbTkCuc824PsW5Fk1SGK5MpuZLXK6gwB sZQFvvBr1pYdReGNn1QD621woJa0AlLjxR8LEsH87oKHgNxE1MzN0Ds4dHMqxrxlduT8 CzWPV1V/whzZxTM/tKrCaTC4jkp6wKSQV6cItAXKR390BYAd6XlPvV9FfAWBd1qEFehg EETO1eQ2TGyw7rzhBKKOX/8f2kXdBw/MJOmK2fAK39OvWiAGATz1weBpgcPXz2zJL2nJ JMSiMZkLNdGZGXZO5kDLFqlukzOp9SmNWaprfAVW/mWEjPhchqrqNG1h0l6TifjLyttM +uXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Snetx5rZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q1-20020a17090aa00100b001f2146025c6si2090324pjp.162.2022.07.20.04.28.36; Wed, 20 Jul 2022 04:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Snetx5rZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233067AbiGTKuU (ORCPT + 99 others); Wed, 20 Jul 2022 06:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231944AbiGTKuS (ORCPT ); Wed, 20 Jul 2022 06:50:18 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DCD51B783; Wed, 20 Jul 2022 03:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658314215; x=1689850215; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=eg1H8HXl4bo5sbqv6QtUBh6VCLBJoEPGZh2Ov9xgfkE=; b=Snetx5rZhbN3ktjGfihdKgSB8m1fITtWDAAz4RLHHx1DzU0I1CpyEXEx Bs8LU38X0y2xVTuKeXKCKTPbafJarg0pOzh+1wUUWDH2XupyWnNHtPTtF 7WgJogVp+QYdX10kLLHYmPXDKYdH5LnOEJteg5wXTtWjmrK7pd3DDRxxP dRpbjmea0x94DRWotADA4CewrZAoaPnztKlXISnfuOQl28LTxUEFf0G2f fz0hg+B6wqvVHMzWQ9Ow1RPadK3FE4gJ78u9/2qT0Ypi3Nk0hBoj1lSr8 Cpt6eIRMiHIjIMbucXqBa6zXAK2vA/WoTuG42xvNJVBwtQfvjdbndU/FR Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10413"; a="286753524" X-IronPort-AV: E=Sophos;i="5.92,286,1650956400"; d="scan'208";a="286753524" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2022 03:50:04 -0700 X-IronPort-AV: E=Sophos;i="5.92,286,1650956400"; d="scan'208";a="630727631" Received: from spmccann-mobl.ger.corp.intel.com (HELO [10.213.200.99]) ([10.213.200.99]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2022 03:50:00 -0700 Message-ID: <6b064764-6d4c-bbbb-f8b0-8a125a59a4a0@linux.intel.com> Date: Wed, 20 Jul 2022 11:49:59 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [Intel-gfx] [PATCH v2 06/21] drm/i915/gt: Batch TLB invalidations Content-Language: en-US To: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , David Airlie , dri-devel@lists.freedesktop.org, Sumit Semwal , Chris Wilson , Dave Airlie , Tomas Winkler , Matthew Auld , =?UTF-8?Q?Thomas_Hellstr=c3=b6m?= , Lucas De Marchi , intel-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Rodrigo Vivi , linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-media@vger.kernel.org, =?UTF-8?Q?Christian_K=c3=b6nig?= References: <9f535a97f32320a213a619a30c961ba44b595453.1657800199.git.mchehab@kernel.org> <605ab738-42df-c8fe-efb3-654d5792d3cc@linux.intel.com> <20220720091304.14b5186b@maurocar-mobl2> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc In-Reply-To: <20220720091304.14b5186b@maurocar-mobl2> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, NICE_REPLY_A,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/07/2022 08:13, Mauro Carvalho Chehab wrote: > On Mon, 18 Jul 2022 14:52:05 +0100 > Tvrtko Ursulin wrote: > >> >> On 14/07/2022 13:06, Mauro Carvalho Chehab wrote: >>> From: Chris Wilson >>> >>> Invalidate TLB in patch, in order to reduce performance regressions. >> >> "in batches"? > > Yeah. Will fix it. > >>> diff --git a/drivers/gpu/drm/i915/gt/intel_ppgtt.c b/drivers/gpu/drm/i915/gt/intel_ppgtt.c >>> index d8b94d638559..2da6c82a8bd2 100644 >>> --- a/drivers/gpu/drm/i915/gt/intel_ppgtt.c >>> +++ b/drivers/gpu/drm/i915/gt/intel_ppgtt.c >>> @@ -206,8 +206,12 @@ void ppgtt_bind_vma(struct i915_address_space *vm, >>> void ppgtt_unbind_vma(struct i915_address_space *vm, >>> struct i915_vma_resource *vma_res) >>> { >>> - if (vma_res->allocated) >>> - vm->clear_range(vm, vma_res->start, vma_res->vma_size); >>> + if (!vma_res->allocated) >>> + return; >>> + >>> + vm->clear_range(vm, vma_res->start, vma_res->vma_size); >>> + if (vma_res->tlb) >>> + vma_invalidate_tlb(vm, *vma_res->tlb); >> >> The patch is about more than batching? If there is a security hole in >> this area (unbind) with the current code? > > No, I don't think there's a security hole. The rationale for this is > not due to it. In this case obvious question is why are these changes in the patch which declares itself to be about batching invalidations? Because... > Since commit 2f6b90da9192 ("drm/i915: Use vma resources for async unbinding"), > VMA unbind can happen either sync or async. > > So, the logic needs to do TLB invalidate on two places. After this > patch, the code at __i915_vma_evict is: > > struct dma_fence *__i915_vma_evict(struct i915_vma *vma, bool async) > { > ... > if (async) > unbind_fence = i915_vma_resource_unbind(vma_res, > &vma->obj->mm.tlb); > else > unbind_fence = i915_vma_resource_unbind(vma_res, NULL); > > vma->resource = NULL; > > atomic_and(~(I915_VMA_BIND_MASK | I915_VMA_ERROR | I915_VMA_GGTT_WRITE), > &vma->flags); > > i915_vma_detach(vma); > > if (!async) { > if (unbind_fence) { > dma_fence_wait(unbind_fence, false); > dma_fence_put(unbind_fence); > unbind_fence = NULL; > } > vma_invalidate_tlb(vma->vm, vma->obj->mm.tlb); > } > ... > > So, basically, if !async, __i915_vma_evict() will do TLB cache invalidation. > > However, when async is used, the actual page release will happen later, > at this function: > > void ppgtt_unbind_vma(struct i915_address_space *vm, > struct i915_vma_resource *vma_res) > { > if (!vma_res->allocated) > return; > > vm->clear_range(vm, vma_res->start, vma_res->vma_size); > if (vma_res->tlb) > vma_invalidate_tlb(vm, *vma_res->tlb); > } .. frankly I don't follow since I don't see any page release happening in here. Just PTE clearing. I am explaining why it looks to me that the patch is doing two things. Implementing batching _and_ adding invalidation points at VMA unbind sites, while so far we had it at backing store release only. Maybe I am wrong and perhaps I am too slow to pick up on the explanation here. So if the patch is doing two things please split it up. I am further confused by the invalidation call site in evict and in unbind - why there can't be one logical site since the logical sequence is evict -> unbind. Regards, Tvrtko