Skip to content

Commit b4381c3

Browse files
committed
prog: fix shadowing log size variable in verifier log retry loop
When ProgramOptions.LogSize was removed in 0.16, the tests weren't updated to exercise the retry loop, since a minimum log size was chosen that was larger than what the test program could generate. With the addition of LogSizeStart, this notoriously fragile code broke when logSize was again tracked as a separate variable, while being accidentally shadowed within the scope of the for loop. This resulted in an endless loop on kernels without the LogTrueSize field. Remove the shadowing and fix the tests. Signed-off-by: Timo Beckers <timo@isovalent.com>
1 parent 228bb4e commit b4381c3

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

prog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func newProgramWithOptions(spec *ProgramSpec, opts ProgramOptions) (*Program, er
451451
// Make an educated guess how large the buffer should be by multiplying.
452452
// Ensure the size doesn't overflow.
453453
const factor = 2
454-
logSize := internal.Between(logSize, minVerifierLogSize, maxVerifierLogSize/factor)
454+
logSize = internal.Between(logSize, minVerifierLogSize, maxVerifierLogSize/factor)
455455
logSize *= factor
456456

457457
if attr.LogTrueSize != 0 {

prog_test.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,16 @@ func TestProgramVerifierLog(t *testing.T) {
469469

470470
var ve *internal.VerifierError
471471
qt.Assert(t, qt.ErrorAs(err, &ve))
472+
473+
loglen := len(fmt.Sprintf("%+v", ve))
474+
qt.Assert(t, qt.IsTrue(loglen > minVerifierLogSize),
475+
qt.Commentf("Log buffer didn't grow past minimum, got %d bytes", loglen))
472476
}
473477

474478
// Generate a base program of sufficient size whose verifier log does not fit
475-
// a 128-byte buffer. This should always result in ENOSPC.
479+
// in the minimum buffer size. Stay under 4096 insn limit of older kernels.
476480
var base asm.Instructions
477-
for i := 0; i < 32; i++ {
481+
for i := 0; i < 4093; i++ {
478482
base = append(base, asm.Mov.Reg(asm.R0, asm.R1))
479483
}
480484

@@ -493,8 +497,7 @@ func TestProgramVerifierLog(t *testing.T) {
493497
Instructions: invalid,
494498
}
495499

496-
// Set an undersized log buffer without explicitly requesting a verifier log
497-
// for an invalid program.
500+
// Don't explicitly request a verifier log for an invalid program.
498501
_, err := NewProgramWithOptions(spec, ProgramOptions{})
499502
check(t, err)
500503

@@ -528,6 +531,16 @@ func TestProgramVerifierLog(t *testing.T) {
528531
LogLevel: LogLevelInstruction,
529532
})
530533
qt.Assert(t, qt.IsNil(err))
534+
qt.Assert(t, qt.IsTrue(len(prog.VerifierLog) > minVerifierLogSize))
535+
prog.Close()
536+
537+
// Repeat the previous test with a larger starting buffer size.
538+
prog, err = NewProgramWithOptions(spec, ProgramOptions{
539+
LogLevel: LogLevelInstruction,
540+
LogSizeStart: minVerifierLogSize * 2,
541+
})
542+
qt.Assert(t, qt.IsNil(err))
543+
qt.Assert(t, qt.IsTrue(len(prog.VerifierLog) > minVerifierLogSize))
531544
prog.Close()
532545
}
533546

0 commit comments

Comments
 (0)