The ultimate aim of closed-loop brain-machine systems for pain is to directly titrate the ongoing level of an intervention to pain-related neural activity. However pain is highly susceptible to endogenous modulation, raising the possibility that active or passive changes in neural activity provoked by the operation of the system could enhance or interfere with the signals upon which it is based. We studied healthy subjects receiving intermittent pain stimuli in a real-time fMRI-based closed-loop feedback-stimulation task. We showed that multi-voxel pattern decoding of pain intensity could be used to train a control algorithm to learn to deliver less painful stimuli (adaptive decoded neurofeedback). However, the system engaged two types of endogenous processes in the brain. First, despite the inherent incentive for subjects to enhance the neural decodability of pain, decodability was either reduced or unchanged in classic pain-processing regions, including insula, dorsolateral prefrontal, and somatosensory cortices. However, increased decodability was observed in a putative pain modulatory region - the pregenual anterior cingulate cortex (pgACC). Second, we found that pain perception itself was modulated by an endogenous computational uncertainty signal engaged as subjects learned the success rate of the system in reducing pain - an effect that also correlated with pgACC responses. The results illustrate how regionally and computationally specific co-adaptive brain-machine learning influences the efficacy of closed-loop systems for pain, and shows that pgACC acts as a key hub in the endogenous controllability of pain.