Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4201578rwi; Mon, 17 Oct 2022 03:03:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5U2pUXN75E8kVLNxDMEaTyxhtS/ERnilMvK5xZPvaklh2UJv4ieyfkZ1VBwL8NekiSBI7m X-Received: by 2002:a17:902:e5c3:b0:185:5100:26f3 with SMTP id u3-20020a170902e5c300b00185510026f3mr5402500plf.73.1666000982590; Mon, 17 Oct 2022 03:03:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666000982; cv=none; d=google.com; s=arc-20160816; b=wah51TCh7EzoE1pqZ+mILJC1Nyw0sHVQIiJysaVPn4oqx3+It+8dvuJY9N3/3ragGn LLRsV/kvY7owe09DQ/JXzngp4yEpHhu3vBg2wGnhfSZ8D91dFpsU961EFBOxRC4nAd0K Zzp03YXM07zTeyb4Ad+Yr5fcuyFf9sBFmsBVROWQxJzKaCnYFWZmFrjo0ymHkNe2TV64 LcC865vmFbaQx/o06xwC4Eq51SJO5b2pM4+ruUqqhSbLRXFI57EBlqJvHAMk59uxvuoB Cekugt+TQepe/bg0cPXkZylPo2lxgoLIcSJoFLO/C4zEtBgCWe/1QRB4Mygw5bc3N0Ae QMLw== 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=Tfq3bUoe5xAbnivYgs0Om88UaoQZh6VnTAQ9wYbZVRo=; b=Oy1tRqhGKDJY6nRXAHS9W9cqr11u34a8yenAYWb9u17yTNeUYYg+FN+NpKaNLZKJsg ebxVrSGhjWJPtNqoiy3DBVZkTLe8kyJdCgySckce/IIMuE0qmTNQs6+HfvZazcpBDMCS SsZVveucoe+0EoCkSxW272rNvRKO+iCPjrfIUZNGdVvIADUIg/DgUDzZcy5xZlACL3YB 9nG8sTd1HqcFM5Tt1SMBNXFV81pAh8tEFYvzADUZxMUWXUMaPCvxBOYtKqWRoWfSoTTE 33ZWpGpXYeI6mPtRUmAqoBo79MTZebtgYs0568XGhJwfl96mlXaJ4oeUQOy65V9Ecmnf Pwzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jgCItgeC; 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 k14-20020a633d0e000000b004391c09ba03si14010285pga.370.2022.10.17.03.02.49; Mon, 17 Oct 2022 03:03:02 -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=jgCItgeC; 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 S231371AbiJQJdY (ORCPT + 99 others); Mon, 17 Oct 2022 05:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231354AbiJQJdR (ORCPT ); Mon, 17 Oct 2022 05:33:17 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86D905A808 for ; Mon, 17 Oct 2022 02:32:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665999176; x=1697535176; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0Ch/gzI1CiEltsWtZiZ1vnI7GDsumr0SEFm747ErScU=; b=jgCItgeC1R/Zp94KyKUhQnOWheZ9NvWIOckwNkWRHkjNznPwLqAZsUb6 MEZtEmJhJNDS2ooI4yuMy3552pwR2w0zCOKFAGQF3Tgba+HmIP943UcIp pRsLLJsbPNNuwFAlO4blrePUBbUS4WaVAG4gCs2BiIL3Ks44SMPMXVxoO An5oaMC49vxjX+zh3Kk1BQPdJn+WJvOeoxG/y5elWau+SnSCGBJTy/6vn Dv3jZTT3ENkzf62GaMbrZAC9qbQkD1fla//f6X7HfJ9CRNtilZw/dduyz gAyQSxCLx7Fkf9IxoW7wi2hpRBK8KgYDXKpNdNBQsi/2hjEnQWwpXRS6r w==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="305741641" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="305741641" 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:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="717431333" X-IronPort-AV: E=Sophos;i="5.95,191,1661842800"; d="scan'208";a="717431333" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.132]) by FMSMGA003.fm.intel.com with ESMTP; 17 Oct 2022 02:32:52 -0700 From: Zhao Liu To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , =?UTF-8?q?Christian=20K=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 8/9] drm/i915: Use kmap_local_page() in i915_cmd_parser.c Date: Mon, 17 Oct 2022 17:37:24 +0800 Message-Id: <20221017093726.2070674-9-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 Content-Transfer-Encoding: 8bit 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 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. There're 2 reasons why function copy_batch() doesn't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe for CPU hotplug when preemption is not disabled. In i915_cmd_parser.c, the function 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 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, 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 --- 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/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 f93e6122f247..1a56000d7476 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; -- 2.34.1