Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp609930rwl; Fri, 4 Nov 2022 04:26:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM55SsxEn+Ce5PmBXP15br78Nszi2dLNdRQaY2Kj4LERWdeoPBObAho7Q1XF2cmjjueT4/so X-Received: by 2002:aa7:de9a:0:b0:44d:8191:44c5 with SMTP id j26-20020aa7de9a000000b0044d819144c5mr34164908edv.232.1667561218856; Fri, 04 Nov 2022 04:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667561218; cv=none; d=google.com; s=arc-20160816; b=Lmm5cCLN+6e8aStH+fU8WYupNCgs79p7f19DMjshxWo4+nuS5JSldyNTU6Lff298s5 Mql1CTPZqcvFeeguiyi/qQuZt78chFz0ikItLFAGsI39rB8mhGOyJUAVqEw/RgldU4r5 y3FJiJTpaMyWUWI+Bq+tHmEEpe2umToOwnn5c2+Ddnsw4qQaTbAgiMB1Saf8FMzvbtXV JBP+7Z7+JOL+j4hhNuge9FGYdEbGeFd4kVdPe6T4t79R3vISu/NaINsZdL9Pf+r+qvvX A+HVQBN+p8fHzwmx/9p27r9G7uKxE5HBEmAL8rtQ4MWI6esku4K9qFClLWjlmP77xDvS /ETA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UrgWQZkMeP/XUdpujDLWc5eHD1me2lwG+UtHebB+9YU=; b=hIbx/KOO6U4/g8cxCbPud2lmifU04MiLaGGKrU5R8B4pMTt47bKRPCwMM9/WNXuojt V9aqvKGA8keIl3iZ6RDY1QaaJzelPCiXL22tdUC58216nAumSDyEEd3J81+H50oAa8XR aga2v2ze+6IPGukqoGy6MelhzrRwATdo8I8xuHiStZqvjGC+nnlKLvoP5h0QjU50aFhq eYIZkZ6I3QvpeHi3EXClQjWmkAvds7kTt9KN3D79ZM/vRi1mirhZVUmXMM2v04Z7lDva lLRLStAse3H+n5mL+4HCEPylRDH63IGf12wne+LrZ/MapXuT+FqRggMOtY0sa5Vr9cYa XffA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SCneiT3x; 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-20020aa7c04e000000b00461237816efsi2515707edo.120.2022.11.04.04.26.35; Fri, 04 Nov 2022 04:26:58 -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=SCneiT3x; 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 S231530AbiKDLYQ (ORCPT + 97 others); Fri, 4 Nov 2022 07:24:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231605AbiKDLYO (ORCPT ); Fri, 4 Nov 2022 07:24:14 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A90762982F for ; Fri, 4 Nov 2022 04:24:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667561053; x=1699097053; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=G1aTmrVsZ8ad6jZu8lVyYIHH8cHgqIzYfaRarwXYjQk=; b=SCneiT3xN0Bsoti0hyQxR5KXCF7ydlB+RMWqry8TFgsTjExD4yKTQLXp +Qxex91FBP9OtvcoGniPf7piaGnm4mlZbNdNJHBDB84taw9VRmVWSh5Kr yYDCygzf6GZUkIG8TTXNoyuU92sbkM/pWTrV/2tAk/RgqUn9Sx57h+sH9 KfvpAn+UNpXwvLd7Vocx/YIkWVJQNcIJR2w9QWf8+qBcdhhBaZjFm3IMH 1ojwnVfyQeftmQRDpydX8IU15dP/yw32p0iHW0LsQ0LgIzCqaSh05TTvr ssTqejqtvgwRstkXf/AQqYpD7dDLYo0ExSOYHfMXvt4QQMThFVwAP3h+n g==; X-IronPort-AV: E=McAfee;i="6500,9779,10520"; a="309934148" X-IronPort-AV: E=Sophos;i="5.96,137,1665471600"; d="scan'208";a="309934148" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2022 04:24:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10520"; a="740590212" X-IronPort-AV: E=Sophos;i="5.96,137,1665471600"; d="scan'208";a="740590212" Received: from liuzhao-optiplex-7080.sh.intel.com (HELO localhost) ([10.239.160.132]) by fmsmga002.fm.intel.com with ESMTP; 04 Nov 2022 04:24:09 -0700 Date: Fri, 4 Nov 2022 19:29:54 +0800 From: Zhao Liu To: "Fabio M. De Francesco" , Ira Weiny Cc: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Matthew Auld , Thomas =?iso-8859-1?Q?Hellstr=F6m?= , Nirmoy Das , Maarten Lankhorst , Chris Wilson , Christian =?iso-8859-1?Q?K=F6nig?= , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhao Liu , Dave Hansen Subject: Re: [PATCH 1/9] drm/i915: Use kmap_local_page() in gem/i915_gem_object.c Message-ID: References: <20221017093726.2070674-1-zhao1.liu@linux.intel.com> <20221017093726.2070674-2-zhao1.liu@linux.intel.com> <2541717.Lt9SDvczpP@suse> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2541717.Lt9SDvczpP@suse> X-Spam-Status: No, score=-8.0 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 On Sat, Oct 29, 2022 at 01:17:03PM +0200, Fabio M. De Francesco wrote: > Date: Sat, 29 Oct 2022 13:17:03 +0200 > From: "Fabio M. De Francesco" > Subject: Re: [PATCH 1/9] drm/i915: Use kmap_local_page() in > gem/i915_gem_object.c > > On luned? 17 ottobre 2022 11:37:17 CEST Zhao Liu wrote: > > 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. > > You are right about about page faults which are never disabled by > kmap_local_page(). However kmap_atomic might not disable preemption. It > depends on CONFIG_PREEMPT_RT. > > Please refer to how kmap_atomic_prot() works (this function is called by > kmap_atomic() when kernels have HIGHMEM enabled). Yes, there is some ambiguity here. What about "The main difference between atomic and local mappings is that local mappings never disable page faults or preemption"? > > > > > 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 for CPU hotplug when preemption is not > > disabled. > > I'm confused here. Why are you talking about CPU hotplug? > In any case, developers should never rely on implicit calls of > preempt_disable() for the reasons said above. Therefore, flush operations > should be allowed regardless that kmap_atomic() potential side effect. Sorry, it's my fault, my misunderstanding about the connection between hotplug and flush here. When mapping exists, the cpu cannot be unplugged via CPU-hotplug. But whether plug or unplug, it has nothing to do with flush. I will delete this wrong description. My initial consideration is that this interface of flush may require an atomic context, so I want to explain more from the details of its implementation that cache consistency can be guaranteed without atomic context. Is this consideration redundant? Also, do I need to state that migration is still ok for this flush interface here (since __kmap_local_page_prot() doesn't always disable migration)? > > In drm/i915/gem/i915_gem_object.c, the function > > i915_gem_object_read_from_page_kmap() calls drm_clflush_virt_range() > > If I recall correctly, drm_clflush_virt_range() can always be called with page > faults and preemption enabled. If so, this is enough to say that the > conversion is safe. > > Is this code explicitly related to flushing the cache lines before removing / > adding CPUs? If I recall correctly, there are several other reasons behind the > need to issue cache lines flushes. Am I wrong about this? > > Can you please say more about what I'm missing here? > > > 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. > > Again your main concern is about CPU hotplug. > > Even if I'm missing something, do we really need all these details about the > inner workings of drm_clflush_virt_range()? > > I'm not an expert, so may be that I'm wrong about all I wrote above. > > Therefore, can you please elaborate a little more for readers with very little > knowledge of these kinds of things (like me and perhaps others)? > > > 2. Any context switch caused by preemption or sleep (pagefault may > > cause sleep) doesn't affect the validity of local mapping. > > I'd replace "preemption or sleep" with "preemption and page faults" since > yourself then added that page faults lead to tasks being put to sleep. Thanks, good advice. Zhao