Skip to contentSkip to conversation

radeonfb: remove reg_lock nonsense

PATCH In review David Eger 2 participants 4 messages Jul 6, 2004 – Jul 7, 2004 2 messages not in the archive Framebuffer layer

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

David Eger

author
#2 lore raw

PATCH 1/1 radeonfb: remove reg_lock nonsense

Quoted 11 lines · Linus Torvalds
Quoted 6 lines · On Mon, 5 Jul 2004 [email protected] wrote:

From: David Eger <[email protected]>

radeonfb: the Stanford lock checker found us double-locking rinfo->reg_lock via sequences like OUTPLL(foo, INPLL(bar) | baz ), as both OUTPLL and INPLL grab the register lock. This should fix the problem.

Ok, I applied it, since I don't have a better tested alternative, but it's really very very ugly.

[ generally well-meaning suggestions - snip ]

Quoted 3 lines

Ben, any comments? How did this code ever survive? Why didn't my G5 lock up?

I agree, the patch is horrid. In fact, now that I really look at it, it seems that the spinlock is totally bogus. This patch removes it. Details below.

BenH: thoughts, objections?

-dte

This patch removes all of the reg_lock nonsense in radeonfb, reversing the ugliness of my previous patch to placate the Stanford lock checker, and getting rid of any false sense of security we had seeing a spinlock in the radeonfb_info.

The truth seems, there's no rhyme nor reason to the use of the register lock in radeonfb_info. It becomes apparent when you look past your nose ;-)

The macros INREG() and OUTREG() don't touch it while INPLL(), OUTPLL(), OUTPLLP(), and OUTREGP() do. Nonetheless, we have:

* radeonfb_engine_reset() writes to CLOCK_CNTL_INDEX without taking the register lock, while radeon_write_pll_regs() uses OUTREGP() to modify it.

* there are these nonsensical quick-successions of grabbing the same lock with OUTPLL() calls

I think the only places where sane register access arbitration takes place is over in *cough* drivers/char/drm *cough* and the VC code (which, AFAIK, already serializes access to the FB device, no?)

drivers/video/aty/radeon_base.c +0 -1
diff -Nru a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
@@ -2087,7 +2087,6 @@
 	rinfo->info = info;	
 	rinfo->pdev = pdev;
 	
-	spin_lock_init(&rinfo->reg_lock);
 	init_timer(&rinfo->lvds_timer);
 	rinfo->lvds_timer.function = radeon_lvds_timer_func;
 	rinfo->lvds_timer.data = (unsigned long)rinfo;
drivers/video/aty/radeon_pm.c +18 -25

88 lines not on this page · raw message

drivers/video/aty/radeonfb.h +8 -35

77 lines not on this page · raw message

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#3 lore raw
Quoted 6 lines

I agree, the patch is horrid. In fact, now that I really look at it, it seems that the spinlock is totally bogus. This patch removes it. Details below.

BenH: thoughts, objections?

The lock is meant to keep writes to the PLL index register followed with a read/write of the PLL data register together. It is necessay for OUTPLL/INPLL as long as radeonfb can be re-entered.

I recently fixed a whole bunch of races at the VT & fbdev level that would cause such re-entering, but we still, I think, have a potential issue with the cursor code, maybe the blanking code, and with the timer I setup for the LVDS updates.

Ben.

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

author
#4 lore raw
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines

I agree, the patch is horrid. In fact, now that I really look at it, it seems that the spinlock is totally bogus. This patch removes it. Details below.

BenH: thoughts, objections?

The lock is meant to keep writes to the PLL index register followed with a read/write of the PLL data register together. It is necessay for OUTPLL/INPLL as long as radeonfb can be re-entered.

Hmmm :-/

In that case, I have a patch which implements both of Linus's suggestions, making OUTPLL()/INPLL() inlines and making the caller responsible for taking the register lock when calling OUTPLL()/INPLL().

On the upside, the number of lockings goes down from 159 to 24. On the downside, that means about 70 more lines of code via:
from 48 spin lock & unlock lines and 17 'flags' decls

I'll leave it up to your discretion whether to apply.

-dte

radeonfb: make the PLL locking the responsibility of the caller,

	so as to avoid grabbing rinfo->reg_lock 100 times during
	a sequence of OUTPLL()'s
drivers/video/aty/radeon_accel.c +3 -0
diff -Nru a/drivers/video/aty/radeon_accel.c b/drivers/video/aty/radeon_accel.c
@@ -147,6 +147,7 @@
 {
 	u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
 	u32 host_path_cntl;
+	unsigned long flags;
 
 	radeon_engine_flush (rinfo);
 
@@ -156,6 +157,7 @@
      	 * We don't do that on macs, things just work here with dynamic
      	 * clocking... --BenH
 	 */
+	spin_lock_irqsave(&rinfo->reg_lock, flags);
 #ifdef CONFIG_ALL_PPC
 	if (_machine != _MACH_Pmac && rinfo->hasCRTC2)
 #else
@@ -237,6 +239,7 @@
 	OUTPLL(MCLK_CNTL, mclk_cntl);
 	if (rinfo->R300_cg_workaround)
 		R300_cg_workardound(rinfo);
+	spin_unlock_irqrestore(&rinfo->reg_lock, flags);
 }
 
 void radeonfb_engine_init (struct radeonfb_info *rinfo)
drivers/video/aty/radeon_base.c +45 -4

195 lines not on this page · raw message

drivers/video/aty/radeon_monitor.c +3 -0
diff -Nru a/drivers/video/aty/radeon_monitor.c b/drivers/video/aty/radeon_monitor.c
@@ -293,7 +293,9 @@
 	unsigned long ulOrigCRTC_EXT_CNTL;
 	unsigned long ulData;
 	unsigned long ulMask;
+	unsigned long flags;
 
+	spin_lock_irqsave(&rinfo->reg_lock, flags);
 	ulOrigVCLK_ECP_CNTL = INPLL(VCLK_ECP_CNTL);
 
 	ulData              = ulOrigVCLK_ECP_CNTL;
@@ -342,6 +344,7 @@
 	OUTREG(DAC_CNTL,      ulOrigDAC_CNTL     );
 	OUTREG(DAC_EXT_CNTL,  ulOrigDAC_EXT_CNTL );
 	OUTREG(CRTC_EXT_CNTL, ulOrigCRTC_EXT_CNTL);
+	spin_unlock_irqrestore(&rinfo->reg_lock, flags);
     }
 
     return connected ? MT_CRT : MT_NONE;
drivers/video/aty/radeon_pm.c +48 -25

218 lines not on this page · raw message

drivers/video/aty/radeonfb.h +12 -34

80 lines not on this page · raw message

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#5 lore raw
Quoted 8 lines

radeonfb can be re-entered.

Hmmm :-/

In that case, I have a patch which implements both of Linus's suggestions, making OUTPLL()/INPLL() inlines and making the caller responsible for taking the register lock when calling OUTPLL()/INPLL().

Quoted 5 lines

On the upside, the number of lockings goes down from 159 to 24. On the downside, that means about 70 more lines of code via:
from 48 spin lock & unlock lines and 17 'flags' decls

I'll leave it up to your discretion whether to apply.

It's probably better to move to such locking, indeed. Just make sure you don't keep the lock on the wait_for_* loops though (haven't looked at the code in detail yet).

Ben.

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com