For two decades, companies that buy software patents in order to sue technology giants have been the scourge of Silicon Valley. Reviled as "patent trolls," they have attacked everything from Google's online ads to Apple's iPhone features, sometimes winning hundreds of millions of dollars.

But now the trolls are in retreat from the tech titans.

In the wake of several changes in U.S. law making it easier to challenge software patents, patent prices are plummeting, the number of court fights is down and stock prices of many patent-holding companies have fallen. Some tech firms are increasing research budgets as legal costs shrink. Support for major patent reform is waning as the trolls get trounced.