From patchwork Sun Dec 3 13:29:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172946 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229050vqy; Sun, 3 Dec 2023 05:18:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQu7dOvYqEjGNuOKKpYeVx/x658Z+iKtEiH4fUG0Y3lmmoVl5T3SZcm/T7k4X6dbG5yV4d X-Received: by 2002:a05:6a20:a12b:b0:18c:f9f9:4198 with SMTP id q43-20020a056a20a12b00b0018cf9f94198mr2995952pzk.14.1701609493913; Sun, 03 Dec 2023 05:18:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609493; cv=none; d=google.com; s=arc-20160816; b=PZjlMeFNoaiM2WR7QnWFTwx72b6IOxWfk1s3NQ+SGvIgzr8RQOJ445hLoPCnr1Cvi4 sQKGOew02FbFZ5EDDO8zk7ldjGTIffo9qn+OJR4u3OYKZgjZUN4z7mJ30nlZFmkAL7dJ Wzh3l0s9tkkGbtoiUJv/c6GssuJJory8df53QItSv2JQbdDBJ4i3CD/2u2bDvz0MWjCN Bbc8ODf+FJbm80+WztqonT4wCiiGOB/MK+jL3CtTOLiRKYc4YUEOsEOqzctYHuJI5vTq auQNljeC9yTtOLitXScX/gfbyUCKWXiab+NYoVfTgMKlTTeFC+Xoxevz1rTOOhL8Xu0J mF+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d0+aX1ehJ1ea3eQXLNnFqnsRpWHU0i6XHvGRhDTETYQ=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=S6tTanfdT93pIq39DBmSkGVxhdm1cEPKYySZR01xE3F118eJWtyuIjmy0xqnWrjAPU BcWuR7Kqoj3q5dZDCG9t11uOhuD7jsek01izJhS0G4JPqDKje84RdNF2NkulP8jjZ6EG K+8NXegTyDNcVkdjXtyL0/5sQdXGADypmZrppV9m9ZZ74xpgtRK8ONIojZdi9kqFFR+p IUbhn+RP8b1LzvnB4Ir63QM58vOHK2gFi1GgqTOWP6M4/ao8srFVZ5M2QrsXAmBDiS3e Y2mVRbC1qS/fUBjJ8pY93bWBya1+Xvmq60z/1E1nUFLdI8GM5Cb4mGn2F824HD/g4O5J hUZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h8u8zRKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id a21-20020a656415000000b005c668c65401si1827850pgv.480.2023.12.03.05.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h8u8zRKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 77C0080859AC; Sun, 3 Dec 2023 05:18:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233534AbjLCNRq (ORCPT + 99 others); Sun, 3 Dec 2023 08:17:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233521AbjLCNRn (ORCPT ); Sun, 3 Dec 2023 08:17:43 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26FDB102 for ; Sun, 3 Dec 2023 05:17:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609469; x=1733145469; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RGMem3p2DJYsfNDR22BCHsoG0wKxhOHO8cUgjkpX0Tg=; b=h8u8zRKRGYeNE01Bp2yNO7wAD3ZuK3RNINwjE4Nr+tSbUwI0h5EkMEVq oykpi82UeZpHHKlPielrekhrN4WbPJjnWl1QM//SdnD+DjBgSWeCw0z5s bLaCOlTQRIGvg8qMf4JeInA8ajvz7WvwN6tKAG1oJWEiueiiRR51fMXIW VcgBIK6r++jkek3ouzTwgND6Y+vgYhWu+aJ99GtI7Tfasq6tOwTK8RnTv utn+2FpVA8ltRyJXDt0uIrwRkDG3l7dvpMD3LI0jnOsPQE0Y3IDgKAxba y/n6mBjztFJFWZGZLnZruZKjsN9QRpkqXKjhGvR0rXFHQJQSNEMqfk8G4 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498212" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498212" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:17:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262333" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262333" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:17:44 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 1/9] drm/i915: Use kmap_local_page() in gem/i915_gem_object.c Date: Sun, 3 Dec 2023 21:29:39 +0800 Message-Id: <20231203132947.2328805-2-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266876449720298 X-GMAIL-MSGID: 1784266876449720298 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the call from kmap_atomic() to kmap_local_page(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration). With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults and preemption disables. There're 2 reasons why i915_gem_object_read_from_page_kmap() doesn't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe. In drm/i915/gem/i915_gem_object.c, i915_gem_object_read_from_page_kmap() calls drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global. 2. Any context switch caused by preemption or page faults (page fault may cause sleep) doesn't affect the validity of local mapping. Therefore, i915_gem_object_read_from_page_kmap() is a function where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). And remove the redundant variable that stores the address of the mapped page since kunmap_local() can accept any pointer within the page. [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message and his description about why kmap_local_page() should be preferred. --- drivers/gpu/drm/i915/gem/i915_gem_object.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c b/drivers/gpu/drm/i915/gem/i915_gem_object.c index c26d87555825..a2a7e5005415 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c @@ -493,17 +493,15 @@ static void i915_gem_object_read_from_page_kmap(struct drm_i915_gem_object *obj, u64 offset, void *dst, int size) { pgoff_t idx = offset >> PAGE_SHIFT; - void *src_map; void *src_ptr; - src_map = kmap_atomic(i915_gem_object_get_page(obj, idx)); - - src_ptr = src_map + offset_in_page(offset); + src_ptr = kmap_local_page(i915_gem_object_get_page(obj, idx)) + + offset_in_page(offset); if (!(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_READ)) drm_clflush_virt_range(src_ptr, size); memcpy(dst, src_ptr, size); - kunmap_atomic(src_map); + kunmap_local(src_ptr); } static void From patchwork Sun Dec 3 13:29:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172948 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229079vqy; Sun, 3 Dec 2023 05:18:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9Na803pCEC0AJ1+gtTXj0odGYj8CGI2vUtZKnfI/fZLQObbb9BENPDk2Tg3cjaW8WxSuk X-Received: by 2002:a05:6358:5e14:b0:170:756:abc2 with SMTP id q20-20020a0563585e1400b001700756abc2mr2765347rwn.10.1701609497294; Sun, 03 Dec 2023 05:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609497; cv=none; d=google.com; s=arc-20160816; b=R6rXso0v+B5wM/SbYzaBG1wJu/q1v7ywT3v3rYa/0QD2uhX3amKrPYfz9jQlKrkoXq mI/UnY8g9wlmlgLeyvs6lMTJZSVCPpWfLk2T+NvL5fyr/FqIsjzce7tRiF4YDEAmcafI TDCuYECdV/pnEPUfaCSNs+Ffoyy1STWACfqcFmCBRWwf/2z0f4Uc5DsrUZGq4HisHwqg vf3H1cXSTJ2HgJD6l4vqYF4ji03gKMGZknWKHqMip1Jj+vmLPD35d65H+wOOku05VSjd ezXL2q/B9UyjSzf4WTLk7mSnpCZEtMuce+s86G43GR/ukU3YKPpSRw4/sIctEwZjT+lv 15LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FwahldSCzBp39kD8Bkdv9+qiCHKbNNjXbliSt1vKlG8=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=gD6GqK2byxsjfBInziNeHV7Qx7RZJJjlPrMVomY7wdoTi2faBdKuIoJ6Zl8nU/0wIV cf1aadMmaxXz5wXB89JjdUDPYTqiGukxeLKbgnMykJSDlvtcsVTDy4NrRjCo/u85xzvc 5R33sCQJICRpAMHBxVnIbrogN1PSzUfC7C1y5Tgaf1Ug8GOMDWQwwb85ilQYsKy9UrSj J9tifQEJUJTxMJw7WjAXMi80sXgs78Of2Vze4u2fA1llAU8cwVAEghSmWQrkB6dSbzKg JogNY2nuj8T+asOOly0/+R5Hdbp5zC/EiSML4GBS1lMKc40lopCAYdeCzIdBWGFlSmAD vsRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VHkGG84H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id q31-20020a63f95f000000b005c6001ec190si6546151pgk.892.2023.12.03.05.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VHkGG84H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 848EF8063151; Sun, 3 Dec 2023 05:18:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233546AbjLCNRt (ORCPT + 99 others); Sun, 3 Dec 2023 08:17:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233535AbjLCNRq (ORCPT ); Sun, 3 Dec 2023 08:17:46 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17E93E6 for ; Sun, 3 Dec 2023 05:17:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609473; x=1733145473; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5tg3umOvWMLFINtDpx9XgsbQvVEtzPNqeysIbkIpyE8=; b=VHkGG84HwYRKDy3VI5W+w+UcFBeP8CjLgmD2GONhM+F0cuHKPym9VJAb HGbjJcR6l8zO6A9g+Sx96gBV5tdmsui4FyUPRb6F2c3rs1nDfRN51pSVu GjTpZuvMVSxSqsrw/+rzfqMHHr54X3qyGOina56WeiJMZE0X10ZwZOQ0p Wrl+KCRaKH7rxK7bgeYxVbx3pjQviR/YaZD8ovJsFPrkIcK63MJ7WV6JI T37Q50dvE8TMsK07zhj6nEsxQpQD3dhrI/UQXMkfVJyH9n+qmZl0chYfU JJnAZEkN66tCa61Nah31Eg5410M05YUFciQx9JF2VVq4YbyxkBhGhCnrm Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498216" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498216" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:17:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262355" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262355" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:17:48 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 2/9] drm/i915: Use memcpy_[from/to]_page() in gem/i915_gem_pyhs.c Date: Sun, 3 Dec 2023 21:29:40 +0800 Message-Id: <20231203132947.2328805-3-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:11 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266880229261953 X-GMAIL-MSGID: 1784266880229261953 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the call from kmap_atomic() + memcpy() to memcpy_[from/to]_page(), which use kmap_local_page() to build local mapping and then do memcpy(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration). With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults and preemption disables. In drm/i915/gem/i915_gem_phys.c, the functions i915_gem_object_get_pages_phys() and i915_gem_object_put_pages_phys() don't need to disable pagefaults and preemption for mapping because of 2 reasons: 1. The flush operation is safe. In drm/i915/gem/i915_gem_object.c, i915_gem_object_get_pages_phys() and i915_gem_object_put_pages_phys() calls drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global. 2. Any context switch caused by preemption or page faults (page fault may cause sleep) doesn't affect the validity of local mapping. Therefore, i915_gem_object_get_pages_phys() and i915_gem_object_put_pages_phys() are two functions where the uses of local mappings in place of atomic mappings are correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() + memcpy() to memcpy_from_page() and memcpy_to_page(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message and his description about why kmap_local_page() should be preferred. --- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_phys.c b/drivers/gpu/drm/i915/gem/i915_gem_phys.c index 5df128e2f4dc..ef85c6dc9fd5 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_phys.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_phys.c @@ -65,16 +65,13 @@ static int i915_gem_object_get_pages_phys(struct drm_i915_gem_object *obj) dst = vaddr; for (i = 0; i < obj->base.size / PAGE_SIZE; i++) { struct page *page; - void *src; page = shmem_read_mapping_page(mapping, i); if (IS_ERR(page)) goto err_st; - src = kmap_atomic(page); - memcpy(dst, src, PAGE_SIZE); + memcpy_from_page(dst, page, 0, PAGE_SIZE); drm_clflush_virt_range(dst, PAGE_SIZE); - kunmap_atomic(src); put_page(page); dst += PAGE_SIZE; @@ -113,16 +110,13 @@ i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj, for (i = 0; i < obj->base.size / PAGE_SIZE; i++) { struct page *page; - char *dst; page = shmem_read_mapping_page(mapping, i); if (IS_ERR(page)) continue; - dst = kmap_atomic(page); drm_clflush_virt_range(src, PAGE_SIZE); - memcpy(dst, src, PAGE_SIZE); - kunmap_atomic(dst); + memcpy_to_page(page, 0, src, PAGE_SIZE); set_page_dirty(page); if (obj->mm.madv == I915_MADV_WILLNEED) From patchwork Sun Dec 3 13:29:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172947 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229078vqy; Sun, 3 Dec 2023 05:18:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+hPjQXFIIjXOyW9O8ud+g64t5cc+kD5kFxLxj4HSJWg7d9B280H1/y06n4bgOT7Qv8LRo X-Received: by 2002:a92:c609:0:b0:35d:6ea6:4cba with SMTP id p9-20020a92c609000000b0035d6ea64cbamr385415ilm.2.1701609497298; Sun, 03 Dec 2023 05:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609497; cv=none; d=google.com; s=arc-20160816; b=j+MnB2D9N/r05C269J4pa/t1FiOQbod3olikT7To/Rs1tw4VlFCwrImFsMG0LldJSg lU8ta6TsJavQOAVGk4Dm/NtqKGVvjvSQUfY5WZR4iWHuuOpCmtw+qspbabMRilytt8tf HN4oWn4zXK5ZSu+4kdZc/Y+kR9LTiBFwOGDnKfh/XZLGgevXtcBSi9TRmLfTe1XiSCgs VUETwDILopuFAbvm0WYiAv/h5UXiGlGDoYaSvRmNwp1oY8pOQSo8rPVG+VO/yt7C7l+5 dwSLDnwJyJUEjM8ahP9gwy0Cca6a2JqrFXTiSIH0qRV5HcJ7yktfqJp3ubc+6UQAhdnI sUag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xP3do6Qu8y1Gsi9NpJLfZtIdpYHPIed1DXj+Uqc/TZI=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=lZ+Kdm5T/R7U7RI/mTOJtw+QQRsWaWgyTZTEQEoiD1OGQVePLJrvUYbVZ2dE7OXdZs A0z1g3DWs6x85ihqTwS1C3zp0kfbReVY3oiGGWB5S4pwrfXlchJsGT4l5wotLwa8Vdkg ONN+XwJEkr09QjI6mn5lRYtFwKKGfc9W8Pnm9+GKuDoepx1cPkhqmOuHnkVnUs3+PfOZ wZ0eS2dbyyKICJBaO1vZQvUrguM+jIkv1hNTlgHiebFwJr5Ch8tT+qFsAfDMz3Ntkqq9 RkJDq3LdxY2veSDFp9ZrjGQ4LL70/31d4pfy5t6D6Rha/NIzF/dxlupGZJxGM9JIu9Bv VhYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BcHlv1lo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i17-20020a63d451000000b005c626072edfsi6329189pgj.773.2023.12.03.05.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BcHlv1lo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D17DC8068968; Sun, 3 Dec 2023 05:18:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233617AbjLCNSA (ORCPT + 99 others); Sun, 3 Dec 2023 08:18:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbjLCNRx (ORCPT ); Sun, 3 Dec 2023 08:17:53 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D6B1102 for ; Sun, 3 Dec 2023 05:17:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609477; x=1733145477; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xk0v3edNgmlsBbxSQneTxOyfsCMSJWY4MBCAqYlM+Qk=; b=BcHlv1loRqlFTYqxluUKp5CmOQMrgURAVq5XJuhi6Uf94Fmpm4srF0AG pDk35EvghzaGqapiFQjSSxehqNLIRn0mbzw59xzTb/WDAzJrkNNiCPW/4 umQaGd+kE76/XS0ktW42a8mxiPXJq+N9XFJNxFJtMKq/MTKQNtonhdSVk 9yVaJsLYRcA0ovomPJNyuKJOi0IsRmoQcDYa7cY/GUAN2gdcKfdkdCcil WmhLk3+c2wFiRXAfK3ZqAwHq4NvI+zrnkpVtWATqpp9cbWAzlBlu+zk+l xmbM/Nif592bdWqiRP+e+9+ywHCqQAICq92MV+NMw2VyGSvttsR3Kpcnx A==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498224" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498224" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:17:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262372" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262372" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:17:52 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 3/9] drm/i915: Use kmap_local_page() in gem/i915_gem_shmem.c Date: Sun, 3 Dec 2023 21:29:41 +0800 Message-Id: <20231203132947.2328805-4-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:13 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266880169239758 X-GMAIL-MSGID: 1784266880169239758 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1]. The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration). With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults or preemption disables. In drm/i915/gem/i915_gem_shmem.c, the function shmem_pwrite() need to disable pagefault to eliminate the potential recursion fault[2]. But here __copy_from_user_inatomic() doesn't need to disable preemption and local mapping is valid for sched in/out. So it can use kmap_local_page() / kunmap_local() with pagefault_disable() / pagefault_enable() to replace atomic mapping. [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com [2]: https://patchwork.freedesktop.org/patch/295840/ Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Ira: Referred to his suggestions about keeping pagefault_disable(). Fabio: Referred to his description about why kmap_local_page() should be preferred. --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index 73a4a4eb29e0..38b72d86560f 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -485,11 +485,13 @@ shmem_pwrite(struct drm_i915_gem_object *obj, if (err < 0) return err; - vaddr = kmap_atomic(page); + vaddr = kmap_local_page(page); + pagefault_disable(); unwritten = __copy_from_user_inatomic(vaddr + pg, user_data, len); - kunmap_atomic(vaddr); + pagefault_enable(); + kunmap_local(vaddr); err = aops->write_end(obj->base.filp, mapping, offset, len, len - unwritten, page, data); From patchwork Sun Dec 3 13:29:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172949 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229095vqy; Sun, 3 Dec 2023 05:18:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGr+agenH7psO5QDB9UWJmjRzGS03AQTKTCd/8egT2hpV2Byh6ilEICTany99RvopHHCJim X-Received: by 2002:a17:90b:3d6:b0:285:b78a:dbce with SMTP id go22-20020a17090b03d600b00285b78adbcemr1854120pjb.37.1701609499840; Sun, 03 Dec 2023 05:18:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609499; cv=none; d=google.com; s=arc-20160816; b=Z0wavywtu6bD3jbl71nL9c3xpmCycZXBnEOPlT8DKGryYzgYZLvBD7MfYMmmraw1cH OyMt7DcxXej2rCRCTIAxi2TSUF+jaolCnzRsmQ9uuYtsn+M2OegqG/4jXYkBIE6n54MI ud6t3OPgsoAAcP4xzGGRlWoNMMOZ4BI0SPzLe/e72ZGOwnsU4T5LhrSDM2wS1rZinsLH XC4WIwGcLfkYE18tVEMAxhCnTtVkWOQnYsT2GVrunPmRxwNA4f38V+B7Cf7PaKMlyLWq d6E1Lmsgx6h105XmJZzkE1T+NIJhlKSPjT9tZXCKLOnFsORQgUbpd+uw/JwbPssCbQzf eYGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MaX5GMHQMJxylNvNTERXXjqHoscb4WK5YMHo8s2t99Q=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=NMjgWKNF+LgtpfhRde02o+0pAhXIQN2c8Ni76Ft8vn63rbUlr0x19T9y27K/5pNddu yM1neMq749L8tHFqH3VMXKHf7JsCNfw+kbB3HPCSdfYphHagFM5a7tnSnfkQ4q3fyH7E qF1qQRYMxGWlBr5qiH/U0ujO8QSvrAGrXX+gwhf3JoejFzpaKLZ4AfIrAyc25qCFxrHV 5mnq07ravsctFBoTaFTQT8OZO9B2DSU/+q8OyEz+vvQFjG/P6ptlT5FL0BJRNoRcY9C8 o+mBLGQ9NYZIqO0WUvlOByMI1mkfkrPF26d1koADpc29PMd/bDrVFDr/t/k3tYDEBAiw QaKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RQg7DJAJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id cm5-20020a17090afa0500b002864c435447si5275109pjb.126.2023.12.03.05.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RQg7DJAJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DDC9480681CD; Sun, 3 Dec 2023 05:18:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233567AbjLCNSC (ORCPT + 99 others); Sun, 3 Dec 2023 08:18:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233559AbjLCNR7 (ORCPT ); Sun, 3 Dec 2023 08:17:59 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 670A0189 for ; Sun, 3 Dec 2023 05:18:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609481; x=1733145481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cJdGxmzajRRQz6VtsFZACeu7sS9itYjQTzis7aoFYwU=; b=RQg7DJAJCXHMBpeuo3qU218KfQEM3NfMavqV7/F37KsecZtVuPWxlods 2oKcKUfrVcQiOimAc5yqMQKHfH8hdTdt/Z9tn0Biz77vY33l3dTp8N9+F /MDbg3fBxkNfrqgGGKDRkkQVEFiAOqa2qhNIebi5DIbAizaXPRaHn8wYY 0An+hpemBqT8FbhcZshL1znxDUOagHk9k9d/WW7zhkmBoIbBXAv7z8+di uMtpkWOaLfPd3TWUUgiLmcb4bFbDU7bskix4zV+WWNbqor1Ky5z9LZsX7 4Mwg14J42Ae/lagO0d+eqFucefplioBZDApiRZnUGbaxo4nm55YF1TkFN Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498234" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498234" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:18:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262401" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262401" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:17:56 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 4/9] drm/i915: Use kmap_local_page() in gem/selftests/huge_pages.c Date: Sun, 3 Dec 2023 21:29:42 +0800 Message-Id: <20231203132947.2328805-5-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:15 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266882750479843 X-GMAIL-MSGID: 1784266882750479843 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the call from kmap_atomic() to kmap_local_page(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration). With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults or preemption disables. In drm/i915/gem/selftests/huge_pages.c, function __cpu_check_shmem() mainly uses mapping to flush cache and check the value. There're 2 reasons why __cpu_check_shmem() doesn't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe. Function __cpu_check_shmem() calls drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global. 2. Any context switch caused by preemption or page faults (page fault may cause sleep) doesn't affect the validity of local mapping. Therefore, __cpu_check_shmem() is a function where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message and his description about why kmap_local_page() should be preferred. --- drivers/gpu/drm/i915/gem/selftests/huge_pages.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c index 6b9f6cf50bf6..c9e6d77abab0 100644 --- a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c +++ b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c @@ -1082,7 +1082,7 @@ __cpu_check_shmem(struct drm_i915_gem_object *obj, u32 dword, u32 val) goto err_unlock; for (n = 0; n < obj->base.size >> PAGE_SHIFT; ++n) { - u32 *ptr = kmap_atomic(i915_gem_object_get_page(obj, n)); + u32 *ptr = kmap_local_page(i915_gem_object_get_page(obj, n)); if (needs_flush & CLFLUSH_BEFORE) drm_clflush_virt_range(ptr, PAGE_SIZE); @@ -1090,12 +1090,12 @@ __cpu_check_shmem(struct drm_i915_gem_object *obj, u32 dword, u32 val) if (ptr[dword] != val) { pr_err("n=%lu ptr[%u]=%u, val=%u\n", n, dword, ptr[dword], val); - kunmap_atomic(ptr); + kunmap_local(ptr); err = -EINVAL; break; } - kunmap_atomic(ptr); + kunmap_local(ptr); } i915_gem_object_finish_access(obj); From patchwork Sun Dec 3 13:29:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172951 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229242vqy; Sun, 3 Dec 2023 05:18:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcga1J4UrpJFaJU/Ow+AbhHHA8nUWjlHJUSq+uS3dnqJIRQQoKtfpNmKi/sED6HhaIbl5w X-Received: by 2002:a92:c092:0:b0:35d:59a2:2de with SMTP id h18-20020a92c092000000b0035d59a202demr4029260ile.126.1701609521180; Sun, 03 Dec 2023 05:18:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609521; cv=none; d=google.com; s=arc-20160816; b=akoXL2F5BmCkJ0F2N894ePgN3VvtsM2hOOcNojcSJ1QKuSeu7B3w8sly6egGf89ocI uvlmGstSMhExkd46/c/Kl/geqyO/6taqWbADouPgh7webaFUSvJJhMo+OXmEnd5O9jxN pggYhep+1lyUO3RISE9maxN3FmgaNqmDIuZy9MRTndHzwqpj8FyPnooYTRF016H9NUMl mdj3uoIXT4WKu0RjB6oqjISNFVdJgwx2LJDZVYdaoiTEQE/LjGGuO3ruPnCQSUiICt2Q 2Z1gwlTrcZebB9gTx/02SUuW3TPvL85tUSBseARbYrpbcNO9ZVBYhX8K5cknshwR39Ak +A2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Rcxa6yuDlNkIi2Y+ftp55A7mWhPK2a9m2Km0oqNSimo=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=SsjCktvUlqPtpIE/RyJk5QjArSElVVXMXIZOcrYMV7XQrlNEXPCZHnMETt3aChEOA2 KQ9OeGZ2hqD9oV6Mq9Azz9zDwdv6OxSjzGZmkfLHLFPivUXSYz/qLypHCtKL9I02k5+Z CYtQBLwcnyKiISl3s9kPlzzuCnU/0JM2uVBMfNO2nJEvvXVXmykHqYspvt2Ke+phiWW5 Sur3o3K+56jX+hY6hr3arSonBsrRRHXom+/8odT80IZOitFM3sKoAoJtcFS0cei0z1pX iPiveBUY7X8FNbLvM3wQzADgrFwMnOkVUKGcg7vE7uO4J5+is+14J0gKdsRGwk6AJsUZ Xyhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="lrm/hR5h"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id t23-20020a17090ad51700b002869b8f81acsi756183pju.136.2023.12.03.05.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="lrm/hR5h"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 390368067E3B; Sun, 3 Dec 2023 05:18:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233646AbjLCNSJ (ORCPT + 99 others); Sun, 3 Dec 2023 08:18:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233551AbjLCNSB (ORCPT ); Sun, 3 Dec 2023 08:18:01 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07FFA10FD for ; Sun, 3 Dec 2023 05:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609485; x=1733145485; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=09wp7qEie3hPA9tmFNTCYBM6WHJ7/7jxnVGZAD5l5W4=; b=lrm/hR5hpRqpudchOcSjnmPOSqPJ9eDK84FNkZwpWkb9TiIL1Yxvlgys J5q6HcYOovnWgAD90CGrS2Ihi9VGVTaAqFpv+KCpeYKh2v7xPRDbg5lbR MNulsPjgTgxwA0U7PpL3OgCXIiuChfcdxvgu0lyRk0m0LpdN8P8oZtHXq 98Igxy1jvu+n8CXWhRZSzHbufpqZjKOxalKxyn1+NeER/Tob8sKhFdS4J sDABQMSBjOVhH7pZyrIoQ5ixuRFSvWsSFX042+p/dCGiltcgRoBYvFff1 uHockDwE27s0g1+J6swPCgvhYPDaeVnc4uLAoHtqHI7XUiqkiCX4kWBbE A==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498241" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498241" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:18:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262426" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262426" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:18:00 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 5/9] drm/i915: Use kmap_local_page() in gem/selftests/i915_gem_coherency.c Date: Sun, 3 Dec 2023 21:29:43 +0800 Message-Id: <20231203132947.2328805-6-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266904865839821 X-GMAIL-MSGID: 1784266904865839821 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the call from kmap_atomic() to kmap_local_page(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration).. With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults or preemption disables. In drm/i915/gem/selftests/i915_gem_coherency.c, functions cpu_set() and cpu_get() mainly uses mapping to flush cache and assign the value. There're 2 reasons why cpu_set() and cpu_get() don't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe. cpu_set() and cpu_get() call drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global. 2. Any context switch caused by preemption or page faults (page fault may cause sleep) doesn't affect the validity of local mapping. Therefore, cpu_set() and cpu_get() are functions where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message and his description about why kmap_local_page() should be preferred. --- .../gpu/drm/i915/gem/selftests/i915_gem_coherency.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c index 3bef1beec7cb..beeb3e12eccc 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c @@ -24,7 +24,6 @@ static int cpu_set(struct context *ctx, unsigned long offset, u32 v) { unsigned int needs_clflush; struct page *page; - void *map; u32 *cpu; int err; @@ -34,8 +33,7 @@ static int cpu_set(struct context *ctx, unsigned long offset, u32 v) goto out; page = i915_gem_object_get_page(ctx->obj, offset >> PAGE_SHIFT); - map = kmap_atomic(page); - cpu = map + offset_in_page(offset); + cpu = kmap_local_page(page) + offset_in_page(offset); if (needs_clflush & CLFLUSH_BEFORE) drm_clflush_virt_range(cpu, sizeof(*cpu)); @@ -45,7 +43,7 @@ static int cpu_set(struct context *ctx, unsigned long offset, u32 v) if (needs_clflush & CLFLUSH_AFTER) drm_clflush_virt_range(cpu, sizeof(*cpu)); - kunmap_atomic(map); + kunmap_local(cpu); i915_gem_object_finish_access(ctx->obj); out: @@ -57,7 +55,6 @@ static int cpu_get(struct context *ctx, unsigned long offset, u32 *v) { unsigned int needs_clflush; struct page *page; - void *map; u32 *cpu; int err; @@ -67,15 +64,14 @@ static int cpu_get(struct context *ctx, unsigned long offset, u32 *v) goto out; page = i915_gem_object_get_page(ctx->obj, offset >> PAGE_SHIFT); - map = kmap_atomic(page); - cpu = map + offset_in_page(offset); + cpu = kmap_local_page(page) + offset_in_page(offset); if (needs_clflush & CLFLUSH_BEFORE) drm_clflush_virt_range(cpu, sizeof(*cpu)); *v = *cpu; - kunmap_atomic(map); + kunmap_local(cpu); i915_gem_object_finish_access(ctx->obj); out: From patchwork Sun Dec 3 13:29:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229274vqy; Sun, 3 Dec 2023 05:18:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHra+ZuVfHRXmVL0ou25y5hWYegv6XC8NpJ7oKZgOxQm3X6iYq1Es0RdYbc+2aQCoRJ3dkU X-Received: by 2002:a05:6a20:3c90:b0:180:e3f1:4f60 with SMTP id b16-20020a056a203c9000b00180e3f14f60mr30163028pzj.45.1701609525621; Sun, 03 Dec 2023 05:18:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609525; cv=none; d=google.com; s=arc-20160816; b=IHkepVhecZtLCS1ywK+JRuVezdwJlHLlJLYfBbHxOhTUagCodgiaiGpleczVs5jnau zBqN/VGkCe/4mbg6ew3aZ7+EUbEqlYdkBEhdoCOWptmvqZTUZ2i8TzOaG3B9M44ArM4Z lFghQGJjIArdhpmjVDj8PalCvo7f3nbOPciskdDzbcXVPl4jh2AtZRg4iQD+Cufjl6zS PWhtY7rHAu2tOeXC/42W0kZyvjmt2OtO5TgU2yMEBeBEPhtKe759YWXlLUJWZylc2lHd csLC9dNnbNTILDxBYCqwPswVgZhf203JCeHdBJC+IomXIOrqO/E0bJR96JYik0LGl7ut rAzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sqEHT2dgNS7DMYomacxDBsoEmRPhidC6Q/nAyHINzfw=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=zI1F/WX+jhHOmJttC3Ln92zvjTXE1wI/S6DZn6acWTYxJwgVjhx7K2DsyIOlVLuZKH 7XliBltMp6LL6taZjHca+qe/GKDQZ2HtP+mtyTXfBbm246WhaThj5PYuPoyzL9Lzmeec Pn9EVC8L7QB15zg325FhusmXnpXmK+HHTOqbC0wSzKYZp69XRVuXuUA5+GzsvLXVeHcY APVcIzUN7LF/ylDzSi2CgSFUI5s//Wm58Dr4FfwomoWy/D00u05Q8yAKENFWKbxLQ0TF 1k9lbCXtI/XZam3K0UI2npKbfzltgqkgnpzk2MNC5tGaGsS+WLHguANWGDfbNjYI/IcN TV8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KQdCGtR3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id j9-20020a056a00234900b006cbba705c9esi6346992pfj.207.2023.12.03.05.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KQdCGtR3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id F326E803E305; Sun, 3 Dec 2023 05:18:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233722AbjLCNSR (ORCPT + 99 others); Sun, 3 Dec 2023 08:18:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233673AbjLCNSH (ORCPT ); Sun, 3 Dec 2023 08:18:07 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08414198 for ; Sun, 3 Dec 2023 05:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609489; x=1733145489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fm2E31LppwjrR39Uy7KnRmjjwMXiEfdx6p7tDjCHHk8=; b=KQdCGtR3QXXuPDMGy8RSCKzxvZtdWMFGsy7Cncm/U/Mlqv5U9XEC57pf aeWdNWvgT1d1fra/IbupjWWwlefvJsh4GH2ZVb9PD8a67MiCw+639FVlY k4G2xNI6sH6mPjMgV9g7hDLHwG3zpttCxEVhe5c8f50IGD3HbseoYEBHq MAJlzaEPXAD9qlSEGodVotpE5RxwN1o4JEpJRc2ACQ4ytTdpJ4qfsCRJZ Z5aMAg+YRxBdrV4qVt5SMWVVCNVSErAjGIHdnTzSdWzfJ2Sqj5IOKOB6s mVFlSCdbLoIHR9vc5cGg3sNoqTj2YeioVufXOsUHIyaEwUHWLWR1p+RRE w==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498245" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498245" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:18:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262446" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262446" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:18:04 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 6/9] drm/i915: Use kmap_local_page() in gem/selftests/i915_gem_context.c Date: Sun, 3 Dec 2023 21:29:44 +0800 Message-Id: <20231203132947.2328805-7-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:40 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266910007838653 X-GMAIL-MSGID: 1784266910007838653 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the call from kmap_atomic() to kmap_local_page(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption. With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults or preemption disables. In drm/i915/gem/selftests/i915_gem_context.c, functions cpu_fill() and cpu_check() mainly uses mapping to flush cache and check/assign the value. There're 2 reasons why cpu_fill() and cpu_check() don't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe. cpu_fill() and cpu_check() call drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global. 2. Any context switch caused by preemption or page faults (page fault may cause sleep) doesn't affect the validity of local mapping. Therefore, cpu_fill() and cpu_check() are functions where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message and his description about why kmap_local_page() should be preferred. --- drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c index 7021b6e9b219..89d4dc8b60c6 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c @@ -489,12 +489,12 @@ static int cpu_fill(struct drm_i915_gem_object *obj, u32 value) for (n = 0; n < real_page_count(obj); n++) { u32 *map; - map = kmap_atomic(i915_gem_object_get_page(obj, n)); + map = kmap_local_page(i915_gem_object_get_page(obj, n)); for (m = 0; m < DW_PER_PAGE; m++) map[m] = value; if (!has_llc) drm_clflush_virt_range(map, PAGE_SIZE); - kunmap_atomic(map); + kunmap_local(map); } i915_gem_object_finish_access(obj); @@ -520,7 +520,7 @@ static noinline int cpu_check(struct drm_i915_gem_object *obj, for (n = 0; n < real_page_count(obj); n++) { u32 *map, m; - map = kmap_atomic(i915_gem_object_get_page(obj, n)); + map = kmap_local_page(i915_gem_object_get_page(obj, n)); if (needs_flush & CLFLUSH_BEFORE) drm_clflush_virt_range(map, PAGE_SIZE); @@ -546,7 +546,7 @@ static noinline int cpu_check(struct drm_i915_gem_object *obj, } out_unmap: - kunmap_atomic(map); + kunmap_local(map); if (err) break; } From patchwork Sun Dec 3 13:29:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172950 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229201vqy; Sun, 3 Dec 2023 05:18:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFg9/G7JtE+mfmtEyzlaQpbWM1U7c2wHKn8KNc8oGKUO6AYAhPB0vd8/a6wrB72ZZR+hJ/O X-Received: by 2002:a05:6e02:320d:b0:35d:5cf2:f54c with SMTP id cd13-20020a056e02320d00b0035d5cf2f54cmr4449800ilb.15.1701609514707; Sun, 03 Dec 2023 05:18:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609514; cv=none; d=google.com; s=arc-20160816; b=jNOJpmJUnZx1tsRNSBVpBHLIEQJ21M87BUKBxahaujk6WOpfS5lK5M4ddER79b52ih sfB+sxW0a/MIsTRE4pnr8F1PKNGTYvAWs1+za6acxNKNdBR6Nzfq1/HeRsLJx+1NFGpr DkhekLh/O19LlZim1zCnz8DEHM9VwKM+PAwqHDhvc4FmD1xB5Nx6esL1XIIwvFDmwmeJ zKehguNOP1Fh1GMGIytbcPaV00gg37NlKcC+9MoHf2Roqj00+Aq4EScM3u4ibzs9146C 5y3yvPJ8PEyefJs1D8MqW812lO2Jdngyi4OFMf7NIKICVwEM4L08cR0lAHgfyaukibYh A+CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Tea+A+DOusaEmlWZvu8nae3fpXcy1nynD0sfdjkLen8=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=c6Ud5LDGdgR/EsVvYhpwIHGsuO+NFu9x9RKWQmJXseW12MfnwoaoZ7iVzBo7f1CsHL hop3piNE+feqp0gP2aRCNG6gbQ6SkYkJNN9ryhD2PmJCuHYHzcdVsHJIc6ITLwiR+fKW 9P0AjcCZh10aLHxPBy4nuXKgG/g6ZazhvCpD+FYWO6ynYVAjpVlPrtojcBum1cB1F5SY d5ekrDmTo09gYtW5tFIhAeng68HIagrA03kmJ/GvFcb31gxdKmeNIrip1HdAzaxXIwx5 nrhPmPrjnhWC67sH6R1y+YMBuOP5BLPmXmG4ZYgRcc9rQoL82TLZ5lmdyAuBQz5CQaPa xB0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MszwCkU8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u64-20020a638543000000b005c6846aa679si531079pgd.666.2023.12.03.05.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MszwCkU8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4BC32806885D; Sun, 3 Dec 2023 05:18:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233593AbjLCNSV (ORCPT + 99 others); Sun, 3 Dec 2023 08:18:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233682AbjLCNSL (ORCPT ); Sun, 3 Dec 2023 08:18:11 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B09F1711 for ; Sun, 3 Dec 2023 05:18:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609493; x=1733145493; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n0RVul1j1ChdDPLa632W5FsA9VNrjI6ORXgE1LsiNbo=; b=MszwCkU85LYhOQvnZttPbF41LffBuS8WH5Ww4Se9kY76qOcuq9bCX5BT 8A47z2rmlYJ8TCtL5IdxedlHavkDk0/Q8wez/hVe1fkQiCiH0KfPtfNlK EX7pNFe3YxzgQFiWUE0ij7bPtGhdHlzIUfFW59+yHavsYo3QrhZPMQSQO 5z6J1iN2+Lxn7ke2UQkqJ6lSF0t9MRLOFHKRpfxjEicSnXWcDR41IbMVU pd26W2/ahtyt/1utuHN8nCgehYSw533cNxLgo5yaPIrkA0I5FSw+ttcQZ yAiIVTFWFCAo/PiHn1BdZxARcpYraDvMkQieczpnFYEEJlXa9729m91RI Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498252" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498252" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:18:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262464" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262464" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:18:08 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 7/9] drm/i915: Use memcpy_from_page() in gt/uc/intel_uc_fw.c Date: Sun, 3 Dec 2023 21:29:45 +0800 Message-Id: <20231203132947.2328805-8-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266898552569680 X-GMAIL-MSGID: 1784266898552569680 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the call from kmap_atomic() to kmap_local_page(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration). With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults or preemption disables. In drm/i915/gt/uc/intel_us_fw.c, the function intel_uc_fw_copy_rsa() just use the mapping to do memory copy so it doesn't need to disable pagefaults and preemption for mapping. Thus the local mapping without atomic context (not disable pagefaults / preemption) is enough. Therefore, intel_uc_fw_copy_rsa() is a function where the use of memcpy_from_page() with kmap_local_page() in place of memcpy() with kmap_atomic() is correctly suited. Convert the calls of memcpy() with kmap_atomic() / kunmap_atomic() to memcpy_from_page() which uses local mapping to copy. [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com/T/#u Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Ira: Referred to his task document and suggestions about using memcpy_from_page() directly. Fabio: Referred to his boiler plate commit message and his description about why kmap_local_page() should be preferred. --- drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c index 362639162ed6..756093eaf2ad 100644 --- a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +++ b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c @@ -1343,16 +1343,13 @@ size_t intel_uc_fw_copy_rsa(struct intel_uc_fw *uc_fw, void *dst, u32 max_len) for_each_sgt_page(page, iter, uc_fw->obj->mm.pages) { u32 len = min_t(u32, size, PAGE_SIZE - offset); - void *vaddr; if (idx > 0) { idx--; continue; } - vaddr = kmap_atomic(page); - memcpy(dst, vaddr + offset, len); - kunmap_atomic(vaddr); + memcpy_from_page(dst, page, offset, len); offset = 0; dst += len; From patchwork Sun Dec 3 13:29:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172953 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229309vqy; Sun, 3 Dec 2023 05:18:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHro2yya03gMpdgvYpWhtiZa3oTnOHl9wuEYILLIqYrdCpXVpySUU30bDJze0r2aChH81Kp X-Received: by 2002:a05:6a20:42a1:b0:18f:1d8b:fadc with SMTP id o33-20020a056a2042a100b0018f1d8bfadcmr2573571pzj.19.1701609530384; Sun, 03 Dec 2023 05:18:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609530; cv=none; d=google.com; s=arc-20160816; b=nLifjQlUquNRybTu4I0cUe2wMJjNAfI1oR1i/i5WkBEIU5T7sOOowrbuHF+r6OVowS L/ea7lLQ+EQVfbjTPKv4EWdY/c1/2zKMarxqKuFs0IeKw48b2fAlWAWXQd5zSyuIvSZ+ XJImzJkCbcxzbSo9yG+vv0XABQ4lctwo8h6/F+IXYICWeBkr1zOKms27Tc5xni4pWi+/ Hs20DZTUnxS0F+xov2l9G0nGbMRyu1weTusnecRMz4EEeT9a3AjSA+AzJ8dZdp2HKMDa j/ice4WKjyILn4FF/sDdsCDptULno8WeFcHdpz9bdR1LwodgIcqNI4kaC+HyIfPU8csB kyig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cpFJJ62nhZXxViT9wjr4rIi2YXSu0JLoDVwraCWB6z0=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=ejq/EX9JK+rMSDkHIiEmGtgxMVaKehzhY0Hxp8DWxgVUfIt6FHgDO9pf1fGQCMGQZT oczjeXMsDBjpPi8onqDlH2eM+d0577kqBxQRuO6OwKDkfIT8x1PdoZX2n9M++5Z47dRz LwltRPVPwTGdDH/1mYu6gVbMBw/Xo0K3v702K2op1ka3PRosJxw3baE647mnkA4YZDmw oJ+XU5VVN2NoPF4p/+ZcZSfy0yeRD7TdYC/cCHBJ259Q1gsoW+KPP4ErK1A3D6Gzt86/ 4XvEBzsz/RzUxmlYJiC12gHbL2mB19XLFeMeULMdwPPkMCwaM6V4tKI8wZOZVxPGdqGk 1xhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="OA/89Uy3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bx42-20020a056a02052a00b005c663e195d6si2048633pgb.446.2023.12.03.05.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="OA/89Uy3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 8DAF1806934C; Sun, 3 Dec 2023 05:18:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233802AbjLCNSe (ORCPT + 99 others); Sun, 3 Dec 2023 08:18:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233674AbjLCNSR (ORCPT ); Sun, 3 Dec 2023 08:18:17 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD61010F0 for ; Sun, 3 Dec 2023 05:18:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609497; x=1733145497; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EKKa4BOOnEyA4HUJAkWqKp5uSW09uVdvjZ+3UJneSag=; b=OA/89Uy3NIrSEw3ijxLzfAYfrpr5RrzPn8PJ9akyDrPM2unDkofxIj5S uxlfGxz0oF9swS92wMdsx93kypSNfpBX6vaOfOMEz9/4LLkmSHKVN6MDC lM6jG3gpCvk6eUO0YrfrDD0IbpH6JGwFeZ/xI6VIKLRPr7m+W0ZXuLx5A xpV0jLARztv2RF7kwq/Cp6t5HjTDXFae/6blhvPdOS0AmpNXYATvQ1Ctd BNwT+T8Zp0ycVjZ2u/OTiHw0a4fqqZo7kVvTig7f5//iz7RwPlkiUo0lu xIIPIi+/74PkwxydGY3VU9zGO+erq3D22vyRKQczL44mWOVT1zvgmWsd3 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498263" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498263" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:18:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262478" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262478" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:18:12 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 8/9] drm/i915: Use kmap_local_page() in i915_cmd_parser.c Date: Sun, 3 Dec 2023 21:29:46 +0800 Message-Id: <20231203132947.2328805-9-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:46 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266914574649654 X-GMAIL-MSGID: 1784266914574649654 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the call from kmap_atomic() to kmap_local_page(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration). With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults and preemption disables. There're 2 reasons why function copy_batch() doesn't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe. In i915_cmd_parser.c, copy_batch() calls drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global. 2. Any context switch caused by preemption or page faults (page fault may cause sleep) doesn't affect the validity of local mapping. Therefore, copy_batch() is a function where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Dave: Referred to his explanation about cache flush. Ira: Referred to his task document, review comments and explanation about cache flush. Fabio: Referred to his boiler plate commit message and his description about why kmap_local_page() should be preferred. --- drivers/gpu/drm/i915/i915_cmd_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c index ddf49c2dbb91..2905df83e180 100644 --- a/drivers/gpu/drm/i915/i915_cmd_parser.c +++ b/drivers/gpu/drm/i915/i915_cmd_parser.c @@ -1211,11 +1211,11 @@ static u32 *copy_batch(struct drm_i915_gem_object *dst_obj, for (n = offset >> PAGE_SHIFT; remain; n++) { int len = min(remain, PAGE_SIZE - x); - src = kmap_atomic(i915_gem_object_get_page(src_obj, n)); + src = kmap_local_page(i915_gem_object_get_page(src_obj, n)); if (src_needs_clflush) drm_clflush_virt_range(src + x, len); memcpy(ptr, src + x, len); - kunmap_atomic(src); + kunmap_local(src); ptr += len; remain -= len; From patchwork Sun Dec 3 13:29:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 172954 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2229333vqy; Sun, 3 Dec 2023 05:18:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwSmKhHAHhNqMhDdFx7U+5busgJfoa5HroRz7NU3ApZG8epsH6SazuJRDWqNbFxV7/03Am X-Received: by 2002:a17:902:a585:b0:1d0:6ffd:9e38 with SMTP id az5-20020a170902a58500b001d06ffd9e38mr2437811plb.138.1701609533127; Sun, 03 Dec 2023 05:18:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701609533; cv=none; d=google.com; s=arc-20160816; b=LBl62wDL3WvWP49asFNgGwAHI4VGU7arJcwFQiOhCALQWSQr+2xmsVxy+AhoK+s8xQ vZW0PpfZqkuOvi+lxnaQlZQFrjln+Ks4xLm9mI+vxMGwIu5osM4zXYhT35KCK31sgGbM HHGW1tP0KnffZMJoUiKqKJbFlAZBRjQfgkSaZc7V4P6fuN7+kx+0aFVOtR1njMGjg1+G GE7rXv/qPv1nrt7gFXLxOXT/sOoc07rBUoDD1cWzzLJ7B8cEo5P8rlsmM3gCy1/CgHxd 1WUSmczqFo4tKse+plJmB7QqUDbO967IiooxfKc4n6ykwG+Miz67g42HqFeD/mcNm+hE +Efg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iJIEx0LYAOfufoYVpyzh73LeZu//OEd7OpP4qbomYJc=; fh=aOKhvLhXHslfuzaDqJh6ZHsMiX4q2rttF8xXq/x74s8=; b=OF6J0sIdXEmrX9dItElESlQQt+gTRzQHqi7N8+PN5A/PiM3mgva9FQ5V2jQUWqP9mB TGSPOMFIK99VYlpuxTqDxKWIzfQy+l12K/pPjAoFV+BK0T0AJMxuGkZoT/6Mn8vWKg+Y 6KsCKKvH+OodakALUwvujqKokfmamUD9iNL4a16sLAa2PICjn7P5pOrRyewHeHoGCFtg frHIP3H7tzzYvV4EfOXkKzWrAYIo8uT4zktt56l9KxQaCiXl7+HPC0+wi8UdNVeYAWvb HO/3wkdnMbIA6ApeIjt7GDc+HuGXTKckDq124TPS77aYfdpJz3lUMocXQsLo4Vt4RM3E B0Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FFz0Ikiy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id y2-20020a170902864200b001cfb7ef2badsi6031554plt.155.2023.12.03.05.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 05:18:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FFz0Ikiy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 97D37805B2CD; Sun, 3 Dec 2023 05:18:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233619AbjLCNSj (ORCPT + 99 others); Sun, 3 Dec 2023 08:18:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233660AbjLCNSX (ORCPT ); Sun, 3 Dec 2023 08:18:23 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53B5E173E for ; Sun, 3 Dec 2023 05:18:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701609501; x=1733145501; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B+nJe1q6TxRa2V23foliRrj6Cka4wr6NofSF5rxQ4eQ=; b=FFz0Ikiy+KFB23gCmF0/Mzt5MHfYyqst7tqnChQk74r4UsEbxFMiIjo0 3d50oHbWxS9bLbl09vxd9U4pMLtMggU7W0ce4/JmUlkEy0pQ0ziAGRwIt mBmxCOaxF9giA6cupaaYpjbH2E60fl+PjZBfc/mW8hUbmhKx3m5GAxwt0 lT3ZBuwR5/EUbYb+cO2lgqHC4uKAycL7U3sFJZx8bSh5q+VjZdtoMMZXd 79zH9AxNIRVNft6jRwwRVag8L3OT7qHErfcNhylfnbj8SI9pO234vKSLb +xPhvTMPkYYlewsQoc44zlz0fxQBEkZ/QBreh6nKHzcLzCU+B2/jIW149 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="498268" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="498268" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2023 05:18:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10912"; a="770262492" X-IronPort-AV: E=Sophos;i="6.04,247,1695711600"; d="scan'208";a="770262492" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga002.jf.intel.com with ESMTP; 03 Dec 2023 05:18:16 -0800 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Ira Weiny , "Fabio M . De Francesco" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Dave Hansen , Zhenyu Wang , Zhao Liu Subject: [PATCH v3 9/9] drm/i915: Use kmap_local_page() in gem/i915_gem_execbuffer.c Date: Sun, 3 Dec 2023 21:29:47 +0800 Message-Id: <20231203132947.2328805-10-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> References: <20231203132947.2328805-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 03 Dec 2023 05:18:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784266917885543881 X-GMAIL-MSGID: 1784266917885543881 From: Zhao Liu The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the calls from kmap_atomic() to kmap_local_page(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration). With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults and preemption disables. In i915_gem_execbuffer.c, eb->reloc_cache.vaddr is mapped by kmap_atomic() in eb_relocate_entry(), and is unmapped by kunmap_atomic() in reloc_cache_reset(). And this mapping/unmapping occurs in two places: one is in eb_relocate_vma(), and another is in eb_relocate_vma_slow(). The function eb_relocate_vma() or eb_relocate_vma_slow() doesn't need to disable pagefaults and preemption during the above mapping/ unmapping. So it can simply use kmap_local_page() / kunmap_local() that can instead do the mapping / unmapping regardless of the context. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Ira Weiny Suggested-by: Fabio M. De Francesco Signed-off-by: Zhao Liu Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco --- Suggested by credits: Ira: Referred to his task document, review comments. Fabio: Referred to his boiler plate commit message and his description about why kmap_local_page() should be preferred. --- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 683fd8d3151c..18b0f3117074 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -1156,7 +1156,7 @@ static void reloc_cache_unmap(struct reloc_cache *cache) vaddr = unmask_page(cache->vaddr); if (cache->vaddr & KMAP) - kunmap_atomic(vaddr); + kunmap_local(vaddr); else io_mapping_unmap_atomic((void __iomem *)vaddr); } @@ -1172,7 +1172,7 @@ static void reloc_cache_remap(struct reloc_cache *cache, if (cache->vaddr & KMAP) { struct page *page = i915_gem_object_get_page(obj, cache->page); - vaddr = kmap_atomic(page); + vaddr = kmap_local_page(page); cache->vaddr = unmask_flags(cache->vaddr) | (unsigned long)vaddr; } else { @@ -1202,7 +1202,7 @@ static void reloc_cache_reset(struct reloc_cache *cache, struct i915_execbuffer if (cache->vaddr & CLFLUSH_AFTER) mb(); - kunmap_atomic(vaddr); + kunmap_local(vaddr); i915_gem_object_finish_access(obj); } else { struct i915_ggtt *ggtt = cache_to_ggtt(cache); @@ -1234,7 +1234,7 @@ static void *reloc_kmap(struct drm_i915_gem_object *obj, struct page *page; if (cache->vaddr) { - kunmap_atomic(unmask_page(cache->vaddr)); + kunmap_local(unmask_page(cache->vaddr)); } else { unsigned int flushes; int err; @@ -1256,7 +1256,7 @@ static void *reloc_kmap(struct drm_i915_gem_object *obj, if (!obj->mm.dirty) set_page_dirty(page); - vaddr = kmap_atomic(page); + vaddr = kmap_local_page(page); cache->vaddr = unmask_flags(cache->vaddr) | (unsigned long)vaddr; cache->page = pageno;