Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp226931rwl; Wed, 29 Mar 2023 00:27:48 -0700 (PDT) X-Google-Smtp-Source: AKy350agTsSKsiU94TpwsasnDjXRg77w6FEpoyN4L42ZJRPrsEIkffbMW8yl0ap79xstGxfmahSs X-Received: by 2002:a17:906:cd12:b0:930:f149:7865 with SMTP id oz18-20020a170906cd1200b00930f1497865mr16700212ejb.21.1680074868280; Wed, 29 Mar 2023 00:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680074868; cv=none; d=google.com; s=arc-20160816; b=RfaZamz9/XAUTXExhztAuoAYpUBGJ2jjGpxes77N+iqNE1Km94RwQZh6rHXOmIr8uP 3RKyQt1EYz48CVL2U9bmoc2orjEyT2CGnu2jvG+cPglNSvRKBWTYsNXdsiXuS7AkW869 UAA0ZEgFa7mZZBSiVGsJZFO/nleKefpaZlVXEYDQrsOzJvoM/bXfVmsftP3gTfH92m0W ibMbTPVC4a6eSj+j4+bKN4yiDVyBpffoo9ibUsrq7Yuqus2Cc74wRu0B5PJUgA9ajcmo M2c36uG1IPsgv+LHlLgTnRToEh0vbLcujjfaC+065z5CK7nPnrwL850ai1GkFS01hiJU HabA== 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=hs9dHNJpIkp3M/B9LJxbX02sewWNQS2xtEMq65vr8cI=; b=n8MnGuVnFr/Vq58nTlsuUCH8AuKpJaOu+cHBvEAw+nJ0wS9hs5GxFolfpSf8jabJ1I M0FmtbrW1m/DZtH3D7r1iGDfMoiinE8qhDFsRsAP5sstaikMP4u1sPgsf+dCUZz+LLwg JP49ZCudJx67J3RWcCyruIe18jHCVP0ecxQrZYlQj3k2o/oc/+7tOKmpAJLeBzx2Wxr0 EQdRmwpWTASTLi468x4gn37LvV5NYH/VzZT44s6WjC88WF6QeXua0qnT6S0V0yZ0RYAG GrYMyBKgFzpi2Fu2O6hMUgQ2uLKySo+eVBcDlHYBMWnFYtzF6jzIfTzypK9rh6GNq8Mp +Qpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G2hggRGu; 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 v20-20020a1709063bd400b0092f55812555si31421681ejf.586.2023.03.29.00.27.21; Wed, 29 Mar 2023 00:27:48 -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=G2hggRGu; 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 S229994AbjC2HY7 (ORCPT + 99 others); Wed, 29 Mar 2023 03:24:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229956AbjC2HYa (ORCPT ); Wed, 29 Mar 2023 03:24:30 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFCDB213A for ; Wed, 29 Mar 2023 00:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680074669; x=1711610669; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lZB7D+9oAqqUk803oQiOFCr0X6utrKVFTvfta1a/CQQ=; b=G2hggRGu5eXem7cemsyrXbUwebGh8sXC4ws42/S8YubBv+V++lBn5mt/ 7wjuSClFs/Up0rK+EdCXfQbNYHpcXDMXxlGdhJW3h2SwDIPIp+XKycs5L y+pat0/YK9ObD7X8MxbmquTOeznO0fqGaAbrFILARQqmMz4HSclPrGfCR py+N+bExBAvEPeuLMOtkx56FTiGfO9LhczUXuu/9IIYUpb5Eq0qkrPkT+ 68vu6DCFOSRpH/0gMAdREgf4ngRB0d/U9gUH1G36dRKR2S3MkbNPA/kAE eBU6EEB2tyJIj5tY1mGpmB+rIP51lNJfp3P0PiXrGYKiw4nr9RLYB3eqK g==; X-IronPort-AV: E=McAfee;i="6600,9927,10663"; a="405745889" X-IronPort-AV: E=Sophos;i="5.98,300,1673942400"; d="scan'208";a="405745889" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2023 00:24:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10663"; a="684160559" X-IronPort-AV: E=Sophos;i="5.98,300,1673942400"; d="scan'208";a="684160559" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.112]) by orsmga002.jf.intel.com with ESMTP; 29 Mar 2023 00:24:24 -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 Subject: [PATCH v2 3/9] drm/i915: Use kmap_local_page() in gem/i915_gem_shmem.c Date: Wed, 29 Mar 2023 15:32:14 +0800 Message-Id: <20230329073220.3982460-4-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230329073220.3982460-1-zhao1.liu@linux.intel.com> References: <20230329073220.3982460-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 (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/ v2: No code change since v1, and added description of the motivation of using kmap_local_page(). Suggested-by: Ira Weiny Reviewed-by: Ira Weiny Reviewed-by: Fabio M. De Francesco Signed-off-by: Zhao Liu --- 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 37d1efcd3ca6..ad69a79c8b31 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -475,11 +475,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); -- 2.34.1