From patchwork Mon Oct 17 09:37:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 3340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1355072wrs; Mon, 17 Oct 2022 02:43:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6U20QQbongpG2tjaxLrK+Wk586GX60CV1Gy21wsbzH7wrBtKZ5pBWwe3fzIveUvLk+Bq1O X-Received: by 2002:a63:4243:0:b0:439:2031:be87 with SMTP id p64-20020a634243000000b004392031be87mr10024853pga.592.1665999786600; Mon, 17 Oct 2022 02:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665999786; cv=none; d=google.com; s=arc-20160816; b=ISWtVhzyAiMi/YFMBYAIeEkM+xfQIukWsVUeqg4mVtluCuPekEKEYf4LtD4u/hLgKB D5qnlzLmN962rh+fDYj4gsNAZpwYGtkj/N2CTNgNjZhCCLq2qUue9zflggDSkJHgvwJw RnA5/fZAGSYtrjh/FTbP+fUdi6S5k08Mrh4g2IiP3qPVUWEAnZNYsJeqOFDP4oegsT0h YfC2h5GBSuexOyAWH3+A73g0Xfu2Z2mOjJxio/2RWx1lHXlJYkQvRpeEtwqRj05c2PJE oF7/XG4ZTt36Yt3JuP140T7BD+ruv8AhMbqK5ayeufxAmg71tqrOTBn62w1n7T0rizi0 YfQQ== 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=+3g8z+0RoiVz2xwg8u61rBprvqD0EXGgXxSlEkSy7j4=; b=dRnpg0qFQc0A9oEC4TEXO7G1D8R/jAUkxGMfGOwafHsOOieEEO66oj77QNpWk7nGS2 bc5tgrSrNmADsDFXVUTanmvxc22EZ+g9THYT1qby0kxF6HlnJ1PfKakXWz8pQ9x+AFoj c+j6HWmbF9Wk7ibmmx232TiCChaynLzmaCmc2GiqXy+cWAbqg3ZlFUbhZqNFhJrPn6dQ kGSfp/k92HPyrWkjrPJiyi74JMCdO/Nms38H75cetnupRCL+d+PpkTGu9hoxUvGJivFv 4avrm84XSkd9Eq5FEsuqNifPDj1Vb5GT3OHE8fvRUQzwYoyjyLaMlEXjFfvSVRhi5NJX XwYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZBVwtOMG; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a655203000000b004639c679346si10956294pgp.837.2022.10.17.02.42.53; Mon, 17 Oct 2022 02:43:06 -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=ZBVwtOMG; 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 S231312AbiJQJcw (ORCPT + 99 others); Mon, 17 Oct 2022 05:32:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231317AbiJQJcn (ORCPT ); Mon, 17 Oct 2022 05:32:43 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C95B58DD6 for ; Mon, 17 Oct 2022 02:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999160; x=1697535160; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZXOTrqnB1S2hiIrW6AdSeUKTfgzUpr1fFCYC+QaCffw=; b=ZBVwtOMGjrVr/Cz2gSBb3HB2GjVyFD7+JWmQLxCVebjsKl9DAgl7YpPt 3aMUVr4eAKuZFIVzGNxsy0Gv2mOr3nF+hcrazTVmdiQkVmHlyFCyeZet+ go+nOOlgUjQeGjbp5ioISj6r1FrAgAlN+HEGEeun8O+AiAQXNkLA99cv4 VpzaMc6Nzwe/WCTlyS3XBXIG0yKjaNK6oIcbPoFmckcs/K/5vZOC0PS8U BRHsMo5Ze2MQdZMksRnSJ6eIn9f5whqe1nWMeujyJiwxCiA+6o+FiKhsF QHXSG6ED1SuY2J62KZg3FwJc4Murj2fNefBEsek8n94BYaYkigU3EXRnB Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741593" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741593" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 02:32:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431262" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431262" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:35 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?utf-8?q?Christian_K=C3=B6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Ira Weiny , "Fabio M . De Francesco" , Zhenyu Wang , Zhao Liu , Dave Hansen Subject: [PATCH 4/9] drm/i915: Use kmap_local_page() in gem/selftests/huge_pages.c Date: Mon, 17 Oct 2022 17:37:20 +0800 Message-Id: <20221017093726.2070674-5-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746927392423508720?= X-GMAIL-MSGID: =?utf-8?q?1746927392423508720?= 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. 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 for CPU hotplug when preemption is not disabled. 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 and any issue with cpu's being added or removed can be handled safely. 2. Any context switch caused by preemption or sleep (pagefault 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 --- 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. --- 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 c570cf780079..6f4efe905105 100644 --- a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c +++ b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c @@ -1022,7 +1022,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); @@ -1030,12 +1030,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);