Minecraft wiki entry for Mushroom_farming, associated text: The wood above illustrates the minimum height required to grow a huge mushroom of that size. Huge mushrooms can be 5, 6, or 7 blocks tall, with the maximum height being 1 block shorter than the available space above it. Thus, if there is a block 7 meters above, the huge mushroom will always grow to be 5 blocks tall.
The slabs below illustrate the area required, 7×7, as well as the fact that the blocks immediately adjacent to the stalk must be free, but not the rest of the bottom row.
The mycelium on the right shows the area where the required space overlaps due to the smaller footprint of the huge red mushroom.
The mushroom must be planted on a dirt, grass, podzol, mycelium, or nylium blocks (not shown).
Placing blocks where the inside of a red mushroom would be does not hinder the growth of the mushroom substantially, only if the blocks are directly in the way or lie outside of the mushroom will it not grow. Occasionally much taller (11+ blocks) mushrooms will grow when blocked by blocks in the normal growth space below, however this is unreliable and takes significant bone meal.
By placing dirt blocks around where the stem of the mushroom is supposed to be, you can block the light allowing you to place the mushroom even closer to the surface - then fill up your tunnel and remove the dirt inside of the mushroom once it's grown.