From owner-freebsd-current@freebsd.org Sat Feb 1 19:23:26 2020 Return-Path: Delivered-To: freebsd-current@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C0856228E57 for ; Sat, 1 Feb 2020 19:23:26 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4893sT2Ct8z3wcf for ; Sat, 1 Feb 2020 19:23:24 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id 011JNALf048538 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 1 Feb 2020 21:23:14 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 011JNALf048538 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id 011JNA4W048537; Sat, 1 Feb 2020 21:23:10 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 1 Feb 2020 21:23:09 +0200 From: Konstantin Belousov To: Hans Petter Selasky Cc: Rick Macklem , "freebsd-current@FreeBSD.org" Subject: Re: easy way to work around a lack of a direct map on i386 Message-ID: <20200201192309.GX4808@kib.kiev.ua> References: <20200130233734.GV4808@kib.kiev.ua> <20200131123144.GW4808@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4893sT2Ct8z3wcf X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-2.00 / 15.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FREEMAIL_FROM(0.00)[gmail.com]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_SPF_SOFTFAIL(0.00)[~all:c]; IP_SCORE_FREEMAIL(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; IP_SCORE(0.00)[ip: (-3.14), ipnet: 2001:470::/32(-4.66), asn: 6939(-3.58), country: US(-0.05)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVFROM(0.00)[gmail.com]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Feb 2020 19:23:26 -0000 On Sat, Feb 01, 2020 at 01:56:59PM +0100, Hans Petter Selasky wrote: > On 2020-01-31 13:31, Konstantin Belousov wrote: > > On Fri, Jan 31, 2020 at 10:13:58AM +0100, Hans Petter Selasky wrote: > > > On 2020-01-31 00:37, Konstantin Belousov wrote: > > > > On Thu, Jan 30, 2020 at 11:23:02PM +0000, Rick Macklem wrote: > > > > > Hi, > > > > > > > > > > The current code for KERN_TLS uses PHYS_TO_DMAP() > > > > > to access unmapped external pages on m_ext.ext_pgs > > > > > mbufs. > > > > > I also need to do this to implement RPC-over-TLS. > > > > > > > > > > The problem is that some arches, like i386, don't > > > > > support PHYS_TO_DMAP(). > > > > > > > > > > Since it appears that there will be at most 4 pages on > > > > > one of these mbufs, my thinking was... > > > > > - Acquire four pages of kva from the kernel_map during > > > > > booting. > > > > > - Then just use pmap_qenter() to fill in the physical page > > > > > mappings for long enough to copy the data. > > > > > > > > > > Does this sound reasonable? > > > > > Is there a better way? > > > > > > > > Use sfbufs, they should work on all arches. In essence, they provide MI > > > > interface to DMAP where possible. I do not remember did I bumped the > > > > limit for i386 after 4/4 went in. > > > > > > > > There is currently no limits for sfbufs use per subsystem, but I think it > > > > is not very likely to cause too much troubles. Main rule is to not sleep > > > > waiting for more sfbufs if you already own one.. > > > > > > In the DRM-KMS LinuxKPI we have: > > > > > > void * > > > kmap(vm_page_t page) > > > { > > > #ifdef LINUXKPI_HAVE_DMAP > > > vm_offset_t daddr; > > > > > > daddr = PHYS_TO_DMAP(VM_PAGE_TO_PHYS(page)); > > > > > > return ((void *)daddr); > > > #else > > > struct sf_buf *sf; > > > > > > sched_pin(); > > > sf = sf_buf_alloc(page, SFB_NOWAIT | SFB_CPUPRIVATE); > > > if (sf == NULL) { > > > sched_unpin(); > > > return (NULL); > > > } > > > return ((void *)sf_buf_kva(sf)); > > > #endif > > > } > > > > > > void > > > kunmap(vm_page_t page) > > > { > > > #ifdef LINUXKPI_HAVE_DMAP > > > /* NOP */ > > > #else > > > struct sf_buf *sf; > > > > > > /* lookup SF buffer in list */ > > > sf = sf_buf_alloc(page, SFB_NOWAIT | SFB_CPUPRIVATE); > > > > > > /* double-free */ > > > sf_buf_free(sf); > > > sf_buf_free(sf); > > > > > > sched_unpin(); > > > #endif > > > } > > > > > > I think that is the fastest way to do this. > > > > So the kmap address is only valid on the CPU that called the function ? > > This is strange, I was not able to find mention of it in references to > > kmap. > > Yes, only on the current CPU. See the SFB_CPUPRIVATE flag. I can read the FreeBSD code. But I did not found a mention that Linux kmap() only invalidates TLB on the core that called it.