From nobody Tue Jan 02 21:15:30 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4T4QcL3zJZz55qmt; Tue, 2 Jan 2024 21:15:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4T4QcL2rGHz4gDj; Tue, 2 Jan 2024 21:15:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704230130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fiJquB+Wcv5A8gv617I83YBFAOZNVWdcseVNJQ9GTuc=; b=UkaafGuTkmLj3lFuyJrVgdkvicl/SH1+rqGprngls0pgZGc20LiJEPHUHMC5F3/jurVdW4 bdlax/Bi57LXnzmnPeaPnUPwdFtCOaCo8oANe9PhypyjpUIfpz5Y302GHWi/rpwk1ujaUB hxVvbjnuzNEYN0M21TH7Z6dMmSN0WuFQI712qEeID4tydDtxoZAEo2R/Lp2tT6PoMxY+2t COAlykQ+oZZVVnu1i835Y0pYULeC0J51j1gifOBizWm53ekT+FMB3zh7MYeZDo6bKROG0+ /3tpkk3Pr4ZoHQllwGu9Pq0N9UcKg1sD5dMSFTTJEGfxEsiWkbDOLJ3l8PISbQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704230130; a=rsa-sha256; cv=none; b=g6BSv5TXrXMRyiTiYUtVeBVk3eUr3cWcpY2hFnHMPUwSIfQqQAb2512uthTQbjbPEtwZhJ fiis8DxiIEFQEEhUkMY8SI0eXvxxP3y3RrDorqVxJRJW7uQkVSzECbq46EycokyUBM8ctE 6DHa6japGEOZkc1AhuXAUlN4/c+aOG0gADFgxK5zrPOoUifMIYWEn3hY62S59794VJAhtR 1EE6hY67W2VoImPv9mQrk7QgHs8/BDEERmzu3hXNDuC7PjdE8YJopBW/Wkz+IomKdi+K7j M4eyOw3//pViRZ/mIBmQKx6U+H3v1AP5M5+nSJs3lsuiGd7h6ncm/y8Tubbm9g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704230130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fiJquB+Wcv5A8gv617I83YBFAOZNVWdcseVNJQ9GTuc=; b=u4VWaIe+2qfj/N79V4Irm3ZnKJAoR4hQbP+aQHxMH4/ETwwPaMImWfN9UrswfknhoNjbHT flWs4JcuLZLiVLCVUoj0GPGkOM11Gw7IXkRilPFBWvN2llKF1LFLSooZxLRZTzs1Q+rB9J RUfePCixEeJklqc+LX4exDDihGDvCzgaJhvHgozxOqnb+sSDlQUyE5Du1URz4HBwqkvd/u 9fJHq+uNqB1GKSskITnSmcSgAYHmV3axT3vg/AejRymvN86Ldd2SsirT3F8VTA3pk+hGeg ERrjqq0clOFyg0rSEYkLz3WdsnGCTGK79OOlRLgco3haOrVzybZEANTHf9HpWw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4T4QcL1dRVz1GYJ; Tue, 2 Jan 2024 21:15:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 402LFUk7072704; Tue, 2 Jan 2024 21:15:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 402LFUAQ072701; Tue, 2 Jan 2024 21:15:30 GMT (envelope-from git) Date: Tue, 2 Jan 2024 21:15:30 GMT Message-Id: <202401022115.402LFUAQ072701@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 67b0b907854a - main - i386: Always bounce DMA requests above 4G for !PAE kernels List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 67b0b907854af42788ec0ae24d5bd4d5c70b72d7 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=67b0b907854af42788ec0ae24d5bd4d5c70b72d7 commit 67b0b907854af42788ec0ae24d5bd4d5c70b72d7 Author: John Baldwin AuthorDate: 2024-01-02 21:15:13 +0000 Commit: John Baldwin CommitDate: 2024-01-02 21:15:13 +0000 i386: Always bounce DMA requests above 4G for !PAE kernels i386 kernels without 'options PAE' will still use PAE page tables if the CPU supports PAE both to support larger amounts of RAM and for PG_NX permissions. However, to avoid changing the API, bus_addr_t and related constants (e.g. BUS_SPACE_MAXADDR) are still limited to 32 bits. To cope with this, the x86 bus_dma code included an extra check to bounce requests for addresses above BUS_SPACE_MAXADDR. This check was elided (probably because it looks always-true on its face and had no comment explaining its purpose) in recent refactoring. To fix, restore a custom address-validation function for i386 kernels without options PAE that includes this check. Reported by: ci.freebsd.org Reviewed by: markj Fixes: 3933ff56f9b6 busdma: tidy bus_dma_run_filter() functions Differential Revision: https://reviews.freebsd.org/D43277 --- sys/x86/x86/busdma_bounce.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/sys/x86/x86/busdma_bounce.c b/sys/x86/x86/busdma_bounce.c index 10e9e0b36602..f56ecd9e7e1e 100644 --- a/sys/x86/x86/busdma_bounce.c +++ b/sys/x86/x86/busdma_bounce.c @@ -117,6 +117,23 @@ static MALLOC_DEFINE(M_BUSDMA, "busdma", "busdma metadata"); #include "../../kern/subr_busdma_bounce.c" +/* + * On i386 kernels without 'options PAE' we need to also bounce any + * physical addresses above 4G. + * + * NB: vm_paddr_t is required here since bus_addr_t is only 32 bits in + * i386 kernels without 'options PAE'. + */ +static __inline bool +must_bounce(bus_dma_tag_t dmat, vm_paddr_t paddr) +{ +#if defined(__i386__) && !defined(PAE) + if (paddr > BUS_SPACE_MAXADDR) + return (true); +#endif + return (addr_needs_bounce(dmat, paddr)); +} + static int bounce_bus_dma_zone_setup(bus_dma_tag_t dmat) { @@ -491,7 +508,7 @@ _bus_dmamap_pagesneeded(bus_dma_tag_t dmat, vm_paddr_t buf, bus_size_t buflen, curaddr = buf; while (buflen != 0) { sgsize = MIN(buflen, dmat->common.maxsegsz); - if (addr_needs_bounce(dmat, curaddr)) { + if (must_bounce(dmat, curaddr)) { sgsize = MIN(sgsize, PAGE_SIZE - (curaddr & PAGE_MASK)); if (pagesneeded == NULL) @@ -547,7 +564,7 @@ _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map, pmap_t pmap, paddr = pmap_kextract(vaddr); else paddr = pmap_extract(pmap, vaddr); - if (addr_needs_bounce(dmat, paddr)) { + if (must_bounce(dmat, paddr)) { sg_len = roundup2(sg_len, dmat->common.alignment); map->pagesneeded++; @@ -584,7 +601,7 @@ _bus_dmamap_count_ma(bus_dma_tag_t dmat, bus_dmamap_t map, struct vm_page **ma, sg_len = PAGE_SIZE - ma_offs; max_sgsize = MIN(buflen, dmat->common.maxsegsz); sg_len = MIN(sg_len, max_sgsize); - if (addr_needs_bounce(dmat, paddr)) { + if (must_bounce(dmat, paddr)) { sg_len = roundup2(sg_len, dmat->common.alignment); sg_len = MIN(sg_len, max_sgsize); @@ -685,7 +702,7 @@ bounce_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, sgsize = MIN(buflen, dmat->common.maxsegsz); if ((dmat->bounce_flags & BUS_DMA_COULD_BOUNCE) != 0 && map->pagesneeded != 0 && - addr_needs_bounce(dmat, curaddr)) { + must_bounce(dmat, curaddr)) { sgsize = MIN(sgsize, PAGE_SIZE - (curaddr & PAGE_MASK)); curaddr = add_bounce_page(dmat, map, 0, curaddr, 0, sgsize); @@ -753,7 +770,7 @@ bounce_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, sgsize = PAGE_SIZE - (curaddr & PAGE_MASK); if ((dmat->bounce_flags & BUS_DMA_COULD_BOUNCE) != 0 && map->pagesneeded != 0 && - addr_needs_bounce(dmat, curaddr)) { + must_bounce(dmat, curaddr)) { sgsize = roundup2(sgsize, dmat->common.alignment); sgsize = MIN(sgsize, max_sgsize); curaddr = add_bounce_page(dmat, map, kvaddr, curaddr, 0, @@ -820,7 +837,7 @@ bounce_bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map, sgsize = PAGE_SIZE - ma_offs; if ((dmat->bounce_flags & BUS_DMA_COULD_BOUNCE) != 0 && map->pagesneeded != 0 && - addr_needs_bounce(dmat, paddr)) { + must_bounce(dmat, paddr)) { sgsize = roundup2(sgsize, dmat->common.alignment); sgsize = MIN(sgsize, max_sgsize); KASSERT(vm_addr_align_ok(sgsize,