Black holes grow by mergers and by accreting mass in the form of gas. The latter offers the biggest reservoir of available mass - as you say, the black hole is a small fraction of the mass of its host galaxy.
Feeding a black hole is not necessarily easy. There may be a limit to the accretion rate caused by radiative feedback and pressure from the hot gas as it is funneled into the black hole. A common way if thinking about this is to talk about the Eddington limit, which is the maximum accretion rate allowed at the Eddington luminosity for spherical accretion. Since this limiting accretion rate is proportional to the mass of the black hole, it implies an exponential growth with a characteristic
timescale known as the Salpeter time, which has a numerical value of about 50 million years (see also https://physics.stackexchange.com/a/167279/43351 ).
If a black hole is $4\times 10^{10} M_{\odot}$ after say 10 billion years of growth (this galaxy is in the relatively local universe), then it has had 200 e-folding times to grow - i.e. it can have grown by a factor of $e^{200}$. Thus given a gas supply, there is no reason such a black hole cannot grow from a small, stellar-sized black hole, formed early in the galaxy's history.
The more problematic cases are the billion solar mass black holes inferred to be present in young, high redshift quasars ($z>6$), which have had a limited time to grow in this way (see for example Yang et al. 2020). There, it may be that you have to start off with larger seed black holes (primordial stars may have produced 1000 solar-mass black holes) or black holes may have initially merged to produce even larger seed black holes, or there are various ways (e.g. non-spherical accretion; low radiative efficiency) that the Eddington limit might be exceeded.