From owner-freebsd-current@freebsd.org Sat Feb 1 12:57:05 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 D482D24E37E for ; Sat, 1 Feb 2020 12:57:05 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (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 488vHj1rGYz4WVZ for ; Sat, 1 Feb 2020 12:57:04 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2020.home.selasky.org (unknown [62.141.129.235]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 65DBA2600FB; Sat, 1 Feb 2020 13:57:03 +0100 (CET) Subject: Re: easy way to work around a lack of a direct map on i386 To: Konstantin Belousov Cc: Rick Macklem , "freebsd-current@FreeBSD.org" References: <20200130233734.GV4808@kib.kiev.ua> <20200131123144.GW4808@kib.kiev.ua> From: Hans Petter Selasky Message-ID: Date: Sat, 1 Feb 2020 13:56:59 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: <20200131123144.GW4808@kib.kiev.ua> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 488vHj1rGYz4WVZ X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of hps@selasky.org designates 2a01:4f8:c17:6c4b::2 as permitted sender) smtp.mailfrom=hps@selasky.org X-Spamd-Result: default: False [-4.96 / 15.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_SPF_ALLOW(-0.20)[+a:mail.turbocat.net:c]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[selasky.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; IP_SCORE(-2.66)[ip: (-9.22), ipnet: 2a01:4f8::/29(-2.53), asn: 24940(-1.55), country: DE(-0.02)]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/29, country:DE]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] 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 12:57:05 -0000 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. --HPS