From 6fd04eff667b3bb07bb44143978caafde8df3e82 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sat, 25 Jul 2015 15:00:14 +0000 Subject: [PATCH] With the removal of b_saveaddr in the r285819, b_data must be reset to b_kvabase when the buffer is reclaimed. Otherwise, if b_data for the mapped buffer was adjusted with the page-offset portion of b_offset, nothing would re-adjust the b_data, which breaks buffer management code which expects page-aligned b_data (see e.g. bpman_qenter(), which skips partial pages). Fix a minor issue with the GB_KVAALLOC requests, which could result in returning the mapped buffer if the reused buffer is mapped and have the right amount of KVA reserved. Improve assertion in the vfs_buf_check_mapped() to catch unmapped buffers which have their b_data incorrectly adjusted with offset. Reported and tested by: pho (previous version) Reviewed by: jeff (previous version) Sponsored by: The FreeBSD Foundation --- sys/kern/vfs_bio.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index ae357e6deee..d29c308d825 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -956,6 +956,8 @@ vfs_buf_check_mapped(struct buf *bp) ("mapped buf: b_kvabase was not updated %p", bp)); KASSERT(bp->b_data != unmapped_buf, ("mapped buf: b_data was not updated %p", bp)); + KASSERT(bp->b_data < unmapped_buf || bp->b_data > unmapped_buf + + MAXPHYS, ("b_data + b_offset unmapped %p", bp)); } static inline void @@ -2241,6 +2243,7 @@ getnewbuf_reuse_bp(struct buf *bp, int qindex) bp->b_dirtyoff = bp->b_dirtyend = 0; bp->b_bufobj = NULL; bp->b_pin_count = 0; + bp->b_data = bp->b_kvabase; bp->b_fsprivate1 = NULL; bp->b_fsprivate2 = NULL; bp->b_fsprivate3 = NULL; @@ -2528,6 +2531,10 @@ restart: bp->b_flags |= B_INVAL; brelse(bp); goto restart; + } else if ((gbflags & (GB_UNMAPPED | GB_KVAALLOC)) == + (GB_UNMAPPED | GB_KVAALLOC)) { + bp->b_data = unmapped_buf; + BUF_CHECK_UNMAPPED(bp); } atomic_add_int(&bufreusecnt, 1); }