From owner-freebsd-current@freebsd.org Fri Jan 31 09:14:08 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 B92BA2394BF for ; Fri, 31 Jan 2020 09:14:08 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [88.99.82.50]) (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 488BNv3L3mz4Kpf for ; Fri, 31 Jan 2020 09:14:06 +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 1AB3026003E; Fri, 31 Jan 2020 10:14:03 +0100 (CET) Subject: Re: easy way to work around a lack of a direct map on i386 To: Konstantin Belousov , Rick Macklem Cc: "freebsd-current@FreeBSD.org" References: <20200130233734.GV4808@kib.kiev.ua> From: Hans Petter Selasky Message-ID: Date: Fri, 31 Jan 2020 10:13:58 +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: <20200130233734.GV4808@kib.kiev.ua> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 488BNv3L3mz4Kpf X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of hps@selasky.org designates 88.99.82.50 as permitted sender) smtp.mailfrom=hps@selasky.org X-Spamd-Result: default: False [-5.42 / 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(-3.12)[ip: (-9.34), ipnet: 88.99.0.0/16(-4.71), 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:88.99.0.0/16, 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: Fri, 31 Jan 2020 09:14:08 -0000 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. --HPS