Bug 279383 - riscv bounce_bus_dmamap_load_buffer() stopped working after a recent update to the riscv busdma_bounce.c
Summary: riscv bounce_bus_dmamap_load_buffer() stopped working after a recent update t...
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: riscv (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Mitchell Horne
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2024-05-29 16:57 UTC by Robert Morris
Modified: 2024-06-03 16:04 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Morris 2024-05-29 16:57:43 UTC
I use an old riscv simulator whose virtio block device doesn't support
the VIRTIO_BLK_F_SEG_MAX feature, so FreeBSD's
vtblk_maximum_segments() decides it supports only three segments. This
has worked, but stopped working after a recent update to
the riscv busdma_bounce.c.

The very first read of a virtio block device is 20 bytes (to read the
label?). The riscv bounce_bus_dmamap_load_buffer() decides a bounce
page is needed. But it rounds up the size from buflen=20 bytes to a
whole page (since dmat->common.alignment is 4096):

                sgsize = MIN(buflen, PAGE_SIZE - (curaddr & PAGE_MASK));
                if (((dmat->bounce_flags & BF_COULD_BOUNCE) != 0) &&
                    map->pagesneeded != 0 &&
                    addr_needs_bounce(dmat, curaddr)) {
                        sgsize = roundup2(sgsize, dmat->common.alignment);
                        curaddr = add_bounce_page(dmat, map, kvaddr, curaddr,
                            sgsize);

The immediate problem is that later the 

                buflen -= sgsize;

wraps (since buflen is 20 and sgsize is 4096), so that buflen is huge
and the while loop incorrectly makes a second iteration. 

A potential fix is to restore the bounce_bus_dmamap_load_buffer() code
from a few months ago that limits sgsize to be no more than buflen.

FreeBSD  15.0-CURRENT FreeBSD 15.0-CURRENT #312 main-n250991-01d33dbbb3f8-dirty: Wed May 29 12:49:02 EDT 2024     rtm@zika:/usr/obj/usr/rtm/symbsd/src/riscv.riscv64/sys/RTM riscv
Comment 1 Jessica Clarke freebsd_committer freebsd_triage 2024-05-29 17:02:31 UTC
Given busdma_bounce is more aligned across architectures these days, this probably isn't exclusive to RISC-V?