Olivia did this from about 6-8.5 mos. Nothing too severe (looking back now), but I was worried. She seemed to do it when she was overtired, mostly at nap time. I just started singing quietly to her & pat her bummy so she would concentrate on my voice & touch (hoping it would not become a crutch later on), seemed to work or she just out grew it. Head banging seems to be common, depending on how long & when/why factors too. Talk to your doc if you are really worried.
PS, I also rolled up receiving blankets & tucked them around the crib between the mattress because she rolled around so much when sleeping, banging her head on the crib rails etc. & waking up several times at night especially. HTH