Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3639920pxb; Mon, 9 Nov 2020 17:15:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJya0MlqogK5CX+OaUu4DJA3GTfJZCdkcGLDzCEzAS05SGCv9QVIlo1wqZsHZkyIF8KSSJZR X-Received: by 2002:a17:906:6013:: with SMTP id o19mr17360338ejj.348.1604970959576; Mon, 09 Nov 2020 17:15:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604970959; cv=none; d=google.com; s=arc-20160816; b=NSk1uMpBzJZ+XU+0QkGIKGgoBEb1lQhSs6NACmdVsJDWkp5QlxxUBEYlwA198yP6YH lda5nPCfAc+CewmyvJ38ggV/2CPlQQxsnmSjt9dn0d/UsB1Ylk2RvYCXOL/lyxSRnLyh Un3VYijUjUydV/z/CgpO61XH4lCDDXtu+GND6Tl8sXeRqT8zdxT9QAHkS5eMxExCm1TQ AyG0R3vPm8t91ORoG+jCZ3GsezQ6XMlcCizms71aYSh89R8yOk/ye16jSH7iTUIpbEPl GhBCE+btTLH91snOkmDpr2rQULyUAjWCZmFVZd46/s3xcv/LYfrUDlDG5aasqo7OVZUc 1l3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=UkwosGD4CNwpr5O4mn7FToWEjHCGounmVIqa5vjwzhQ=; b=LhPZQH98AJbTe0VyprskO8+HxrlbIW33NcjGze+J3enNHXwu220B9JW2wB1KLYwEW5 A8b+/8HKAbj4pJDVBsawoKeUwWjLHsVM+Y9gWs9DfMFLubDuGH1veQISY9KOtPpORwqf PdkdO6O4Qplgt/PifewiJgcPC4IdBnPbaEAdT2pA9P1zXlR0E17shL5un6XE58ZtDTgb xEUG0gmKNLNA+GI6hApO6c4V3t0Pe8/r6RGL52EixDmKQNfi6K5tiT+BUytcrMIp0YGw qUg63yK+fSHKk1clWRIPVTZr69afk4YTgSs+nyQHtFEPrjGvf0N5ayT3mHs2L5E3pLTl i8ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DRjXCHfa; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="acv/dHWH"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q7si9038384ejy.607.2020.11.09.17.15.27; Mon, 09 Nov 2020 17:15:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DRjXCHfa; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="acv/dHWH"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731886AbgKJBON (ORCPT + 99 others); Mon, 9 Nov 2020 20:14:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731267AbgKJBOA (ORCPT ); Mon, 9 Nov 2020 20:14:00 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCE2DC0613CF; Mon, 9 Nov 2020 17:13:59 -0800 (PST) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1604970836; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UkwosGD4CNwpr5O4mn7FToWEjHCGounmVIqa5vjwzhQ=; b=DRjXCHfaWTV+37wSriT1BjBgrVPE6jdQ5QSgYOIapfxJkFIwaFOAyxB9axkmnF7jwFoYyj IwVALzvZ0PuA7RxNph9leDCS6B9rTa4rL3nKcIBy/Am24PTMh01e/A2SQWp6LTkOQfBaj6 TPNYDFf29DCqNiv3sgD8nE6enYeIlsYkCGyKDzwB1FGN01/Y3vKoJQtpchwkYWrvNb9W70 4PCnBA8S0oYM/XwkwwZotKzR9vmT9oC6FdGvh5lMI1bLUaS0qdB+ZPTGprUeJSBjnvH0Xv xyRk7zOTS6b0OUuDBNt+X1xYcMB1KSB7gGowiPoSA5hPR5omsqQ5g20Kt4+uKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1604970836; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UkwosGD4CNwpr5O4mn7FToWEjHCGounmVIqa5vjwzhQ=; b=acv/dHWHYYmtT1/z0brDNSAmBtlvEk8c07ItXmS/RUDap25yEm8biO9jTMWItRsTlNRTeF x/KI3sqvslL8SkDg== To: ira.weiny@intel.com, Andrew Morton , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Cc: Ira Weiny , Randy Dunlap , x86@kernel.org, Dave Hansen , Dan Williams , Fenghua Yu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, kexec@lists.infradead.org, linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org, devel@driverdev.osuosl.org, linux-efi@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-aio@kvack.org, io-uring@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-um@lists.infradead.org, linux-ntfs-dev@lists.sourceforge.net, reiserfs-devel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-nilfs@vger.kernel.org, cluster-devel@redhat.com, ecryptfs@vger.kernel.org, linux-cifs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-afs@lists.infradead.org, linux-rdma@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, xen-devel@lists.xenproject.org, linux-cachefs@redhat.com, samba-technical@lists.samba.org, intel-wired-lan@lists.osuosl.org Subject: Re: [PATCH RFC PKS/PMEM 05/58] kmap: Introduce k[un]map_thread In-Reply-To: <20201009195033.3208459-6-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> <20201009195033.3208459-6-ira.weiny@intel.com> Date: Tue, 10 Nov 2020 02:13:56 +0100 Message-ID: <87h7pyhv3f.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Ira, On Fri, Oct 09 2020 at 12:49, ira weiny wrote: > From: Ira Weiny > > To correctly support the semantics of kmap() with Kernel protection keys > (PKS), kmap() may be required to set the protections on multiple > processors (globally). Enabling PKS globally can be very expensive > depending on the requested operation. Furthermore, enabling a domain > globally reduces the protection afforded by PKS. > > Most kmap() (Aprox 209 of 229) callers use the map within a single thread and > have no need for the protection domain to be enabled globally. However, the > remaining callers do not follow this pattern and, as best I can tell, expect > the mapping to be 'global' and available to any thread who may access the > mapping.[1] > > We don't anticipate global mappings to pmem, however in general there is a > danger in changing the semantics of kmap(). Effectively, this would cause an > unresolved page fault with little to no information about why the failure > occurred. > > To resolve this a number of options were considered. > > 1) Attempt to change all the thread local kmap() calls to kmap_atomic()[2] > 2) Introduce a flags parameter to kmap() to indicate if the mapping should be > global or not > 3) Change ~20 call sites to 'kmap_global()' to indicate that they require a > global enablement of the pages. > 4) Change ~209 call sites to 'kmap_thread()' to indicate that the mapping is to > be used within that thread of execution only > > Option 1 is simply not feasible. Option 2 would require all of the call sites > of kmap() to change. Option 3 seems like a good minimal change but there is a > danger that new code may miss the semantic change of kmap() and not get the > behavior the developer intended. Therefore, #4 was chosen. There is Option #5: Convert the thread local kmap() invocations to the proposed kmap_local() interface which is coming along [1]. That solves a couple of issues: 1) It relieves the current kmap_atomic() usage sites from the implict pagefault/preempt disable semantics which apply even when CONFIG_HIGHMEM is disabled. kmap_local() still can be invoked from atomic context. 2) Due to #1 it allows to replace the conditional usage of kmap() and kmap_atomic() for purely thread local mappings. 3) It puts the burden on the HIGHMEM inflicted systems 4) It is actually more efficient for most of the pure thread local use cases on HIGHMEM inflicted systems because it avoids the overhead of the global lock and the potential kmap slot exhaustion. A potential preemption will be more expensive, but that's not really the case we want to optimize for. 5) It solves the RT issue vs. kmap_atomic() So instead of creating yet another variety of kmap() which is just scratching the particular PKRS itch, can we please consolidate all of that on the wider reaching kmap_local() approach? Thanks, tglx [1] https://lore.kernel.org/lkml/20201103092712.714480842@linutronix.de/