From nobody Sun Sep 10 09:31:48 2023 X-Original-To: bugs@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 4Rk4P120yCz4s6q2 for ; Sun, 10 Sep 2023 09:31:49 +0000 (UTC) (envelope-from bugzilla-noreply@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 4Rk4P101KKz4gJ5 for ; Sun, 10 Sep 2023 09:31:49 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694338309; a=rsa-sha256; cv=none; b=v7z2hdiMgNsZX6xSuxvVxRHBF91NUal12nbKIWx9MNwJ3DBLPf26HzEI38uLZNp38oBLni DyeZkW8PswlioKkrJJsPni7fNVuPN9a57FyBpw4LEsMErXKKpRgtsWzTluOk3Fw4f+FqJy YgWapOTZ61DXCF0UHsiPoDyt4jNcir/xjAch4ZYD4WV28JZG8xhP/bRcEEgNjDLZgxUtUu 1zAf5QOxRxTiwgzhUeIT0/Tpe6g441XgWU2spnWZnzmTA9LwhrdPRvVEIzMG89MVelr0/u ANNNgVMsYTf5QQK9Nvh/slDgUtxk3TIQIdvKlk45OvFkZBOYkUNS3DpQut8rMw== 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=1694338309; 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=yZ7E352zZ6Pelftb2kPNHfb25wpWwwGcJXTVtKuKQFE=; b=KQGmHxLzgkWagLeL3U6KIICjTnGt2T5h0+4ObN5mT5EWXsNCez2sNFKwqq/JlneIZfIbD3 qiJZuZtvR/o1OHMRXs53HaCEikEmamuF/2c6lmGtbFCPMKUJEMvIHEkhd8cIvgwvXAyZ2y IfLpMtgUFZsitA0fx441RWxK04mlOsRQDYdtKO6sPctIZ9dgzGKrw4BjNDM/T0S25XqGSl 1V48QvwI3rXisLv5Uqs2RWVD7Bek9DEn9sCOcyZshgwLbKkb1GO6g28G7FfwrIdAB1wYxF U8uO1d+Jd2XYMSCiicvotlzNqtX4mGj4yvMQoIJwrxvdvDLiB7GB7j7fSVgjeA== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 4Rk4P06CWKz128L for ; Sun, 10 Sep 2023 09:31:48 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 38A9VmZq064110 for ; Sun, 10 Sep 2023 09:31:48 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 38A9VmLZ064109 for bugs@FreeBSD.org; Sun, 10 Sep 2023 09:31:48 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 273694] [patch] _bus_dmamap_count_pages() may miscount Date: Sun, 10 Sep 2023 09:31:48 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 14.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: jsihv@gmx.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D273694 Bug ID: 273694 Summary: [patch] _bus_dmamap_count_pages() may miscount Product: Base System Version: 14.0-CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: jsihv@gmx.com Created attachment 244746 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D244746&action= =3Dedit patch files for different architectures While debugging jh7110 board's MMC driver I found out that the problem had = been a faulty algorithm in DMA code. _bus_dmamap_count_pages() in sys/riscv/riscv/busdma_bounce.c is called to c= ount a number of new bounce pages needed in order to complete the DMA transfer (= this happens at least when physical addresses used for data segments go out of D= MA address range). However, unlike a function bounce_bus_dmapmap_load_buffer() which calls it, _bus_dmamap_count_pages() does not take into account that segment size may be limited by dmat->common.maxsegsz which is set when crea= ting bus_dma_tag_t in the driver code. This may lead to a wrong number of pages counted and thus some needed bounce pages will not be created. In my case the consequence was that some addresses outside of device's 32-b= it DMA range were assigned to descriptors (IO data structures read by DMA controller) which nevertheless can only contain first 32 bits of those addresses. This causes the whole booting process to halt. After a failed transfer MMC driver code stays waiting for a next interrupt that never arri= ves. I found that the _bus_dmamap_count_pages() is similarly deficient in other architectures though it's possible this bug hasn't surfaced previously. My actual case is related to charcteristics of Designware's MMC devices (see comments on file dwmmc.c, line 140) which imply maximum size for data segme= nts. I don't see any reason why this issue couldn't affect other architectures as well if circumstances are right, so I've supplied patches for each architec= ture in an attachment file. ARM and powerpc have the _bus_dmamap_count_pages() function in file busdma_machdep.c while other archs (including ARM64) have = it in busdma_bounce.c --=20 You are receiving this mail because: You are the assignee for the bug.=