Ordovician carbonate rocks of the Yijianfang Formation in the Tabei Uplift, Tarim Basin, contain deeply buried (>6000 m), highly productive oil and gas reservoirs associated with large cavities (>10 m). Previous workers inferred that large cavities are paleocaves (paleokarst) formed near the surface and subsequently buried. Alternately, caves may have formed by dissolution at depth along faults. Using 227 samples from 16 cores, we document textures and cement compositions bearing on cavity histories with petrographic, high-resolution scanning electron microscopy (SEM), isotopic, and fluid inclusion microthermometric observations. Results show that dissolution occurred at depth and was caused by (1) acidic fluids derived from Middle-Late Silurian and/or Devonian-Permian hydrocarbon generation and maturation, (2) high-temperature fluids, of which some were associated with Late Permian igneous activity, and (3) Mg-rich fluids that accompanied Jurassic-Cretaceous deformation and the formation of partially open fractures and stylobreccias (fault breccias). The relative paragenetic sequence of the structure-related diagenesis suggests seven stages of fracturing, dissolution, and cementation. Mottle fabrics in the Yijianfang Formation contain argillaceous carbonate-rich silt and are bioturbation features formed within the marine environment. Those mottled fabrics differ from clearly karstic features in the overlying Lianglitage Formation, which formed by near-surface dissolution and subsequent infilling of cavities by allochthonous sediment. Mottle fabrics are crosscut by compacted fractures filled with phreatic-vadose marine cements and followed by subsequent generations of cement-filled fractures and vugs indicating that some fractures and vugs became cement filled prior to later dissolution events. Calcite cements in fractures and vugs show progressively depleted values of δ18O documenting cement precipitation within the shallow (~220 m), intermediate (~625 m), and deep (~2000 m) diagenetic environments. Deep (mesogenetic) dissolution associated with fractures is therefore the principal source of the high porosity-permeability in the reservoir, consistent with other pieces of evidence for cavities localized near faults.