sstatesig: Fix hash equivlanency locked signature issues
PATCH 1/4 sstatesig: Fix hash equivlanency locked signature issues
Using locked signatures with the hash equivalency server ran into problems. We need to:
a) Ensure the lockedhashes data object is passed from the core to any individual tasks using the get/set_taskdata methods
b) Return a locked singature instead of a unihash
c) Write the unihash being used to locked signature lists rather than the calculated taskhash
d) Skip warnings of hash mismatch if the hash is a unihash
These changes fix esdk builds (which use locked sigs) when a hash equivalence server is in use.
--- meta/lib/oe/sstatesig.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
meta/lib/oe/sstatesig.py +10 -4
@@ -130,10 +130,10 @@ class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash): def get_taskdata(self): data = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskdata() - return (data, self.lockedpnmap, self.lockedhashfn) + return (data, self.lockedpnmap, self.lockedhashfn, self.lockedhashes) def set_taskdata(self, data): - coredata, self.lockedpnmap, self.lockedhashfn = data + coredata, self.lockedpnmap, self.lockedhashfn, self.lockedhashes = data super(bb.siggen.SignatureGeneratorBasicHash, self).set_taskdata(coredata) def dump_sigs(self, dataCache, options):
@@ -171,10 +171,11 @@ class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash): h_locked = self.lockedsigs[recipename][task][0] var = self.lockedsigs[recipename][task][1] self.lockedhashes[tid] = h_locked + unihash = super().get_unihash(tid) self.taskhash[tid] = h_locked #bb.warn("Using %s %s %s" % (recipename, task, h)) - if h != h_locked: + if h != h_locked and h_locked != unihash: self.mismatch_msgs.append('The %s:%s sig is computed to be %s, but the sig is locked to %s in %s' % (recipename, task, h, h_locked, var))
@@ -182,6 +183,11 @@ class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash): #bb.warn("%s %s %s" % (recipename, task, h)) return h + def get_unihash(self, tid): + if tid in self.lockedhashes: + return self.lockedhashes[tid] + return super().get_unihash(tid) + def dump_sigtask(self, fn, task, stampbase, runtime): tid = fn + ":" + task if tid in self.lockedhashes:
@@ -211,7 +217,7 @@ class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash): (_, _, task, fn) = bb.runqueue.split_tid_mcfn(tid) if tid not in self.taskhash: continue - f.write(" " + self.lockedpnmap[fn] + ":" + task + ":" + self.taskhash[tid] + " \\\n") + f.write(" " + self.lockedpnmap[fn] + ":" + task + ":" + self.get_unihash(tid) + " \\\n") f.write(' "\n') f.write('SIGGEN_LOCKEDSIGS_TYPES_%s = "%s"' % (self.machine, " ".join(l)))
Signature · 1 line
2.20.1
PATCH 2/4 oeqa/selftest/signing: Fix for hash equivlance server
There were two issues with the test one is that an equivalent hash could come from the server meaning the signature didn't change when it should. A uuid string is injected to ensure this does not happen.
If there were multiple warnings the test would also fail as only the first is prefixed with WARNING. Tweak the string to avoid that failure mode.
--- meta/lib/oeqa/selftest/cases/signing.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
meta/lib/oeqa/selftest/cases/signing.py +5 -2
@@ -180,6 +180,8 @@ class LockedSignatures(OESelftestTestCase): AutomatedBy: Daniel Istrate <[email protected]> """ + import uuid + test_recipe = 'ed' locked_sigs_file = 'locked-sigs.inc'
@@ -197,9 +199,10 @@ class LockedSignatures(OESelftestTestCase): bitbake(test_recipe) # Make a change that should cause the locked task signature to change + # Use uuid so hash equivalance server isn't triggered recipe_append_file = test_recipe + '_' + get_bb_var('PV', test_recipe) + '.bbappend' recipe_append_path = os.path.join(self.testlayer_path, 'recipes-test', test_recipe, recipe_append_file) - feature = 'SUMMARY += "test locked signature"\n' + feature = 'SUMMARY_${PN} = "test locked signature%s"\n' % uuid.uuid4() os.mkdir(os.path.join(self.testlayer_path, 'recipes-test', test_recipe)) write_file(recipe_append_path, feature)
@@ -210,7 +213,7 @@ class LockedSignatures(OESelftestTestCase): ret = bitbake(test_recipe) # Verify you get the warning and that the real task *isn't* run (i.e. the locked signature has worked) - patt = r'WARNING: The %s:do_package sig is computed to be \S+, but the sig is locked to \S+ in SIGGEN_LOCKEDSIGS\S+' % test_recipe + patt = r'The %s:do_package sig is computed to be \S+, but the sig is locked to \S+ in SIGGEN_LOCKEDSIGS\S+' % test_recipe found_warn = re.search(patt, ret.output) self.assertIsNotNone(found_warn, "Didn't find the expected warning message. Output: %s" % ret.output)
Signature · 1 line
2.20.1
PATCH 3/4 lib/sstatesig: Fix class inheritance problems
In reply to Richard PurdieThe locked sigs class needs to be inherited after the hashequiv mixin so that get_unihash can correctly wrap the underlying hashequiv function.
To do this turn the locked sigs class into a second mixin, then the order can be correctly handled. Tweak the get/set_taskdata to match.
--- meta/lib/oe/sstatesig.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
meta/lib/oe/sstatesig.py +8 -7
@@ -90,8 +90,7 @@ class SignatureGeneratorOEBasic(bb.siggen.SignatureGeneratorBasic): def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None): return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache) -class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash): - name = "OEBasicHash" +class SignatureGeneratorOEBasicHashMixIn(object): def init_rundepcheck(self, data): self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE") or "").split() self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS") or "").split()
@@ -129,12 +128,11 @@ class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash): return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache) def get_taskdata(self): - data = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskdata() - return (data, self.lockedpnmap, self.lockedhashfn, self.lockedhashes) + return (self.lockedpnmap, self.lockedhashfn, self.lockedhashes) + super().get_taskdata() def set_taskdata(self, data): - coredata, self.lockedpnmap, self.lockedhashfn, self.lockedhashes = data - super(bb.siggen.SignatureGeneratorBasicHash, self).set_taskdata(coredata) + self.lockedpnmap, self.lockedhashfn, self.lockedhashes = data[:3] + super().set_taskdata(data[3:]) def dump_sigs(self, dataCache, options): sigfile = os.getcwd() + "/locked-sigs.inc"
@@ -263,7 +261,10 @@ class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash): if error_msgs: bb.fatal("\n".join(error_msgs)) -class SignatureGeneratorOEEquivHash(bb.siggen.SignatureGeneratorUniHashMixIn, SignatureGeneratorOEBasicHash): +class SignatureGeneratorOEBasicHash(SignatureGeneratorOEBasicHashMixIn, bb.siggen.SignatureGeneratorBasicHash): + name = "OEBasicHash" + +class SignatureGeneratorOEEquivHash(SignatureGeneratorOEBasicHashMixIn, bb.siggen.SignatureGeneratorUniHashMixIn, bb.siggen.SignatureGeneratorBasicHash): name = "OEEquivHash" def init_rundepcheck(self, data):
Signature · 1 line
2.20.1
PATCH 4/4 populate_sdk_ext: Fix for hash equiv
In reply to Richard PurdieWrite out the hash equiv cache file into any eSDK so that it doesn't rely on having to call the hash server for the basic data requests.
--- meta/classes/populate_sdk_ext.bbclass | 10 ++++++++++ 1 file changed, 10 insertions(+)
meta/classes/populate_sdk_ext.bbclass +10 -0
@@ -379,6 +379,11 @@ python copy_buildsystem () { f.write('require conf/locked-sigs.inc\n') f.write('require conf/unlocked-sigs.inc\n') + if os.path.exists(builddir + '/cache/bb_unihashes.dat'): + bb.parse.siggen.save_unitaskhashes() + bb.utils.mkdirhier(os.path.join(baseoutpath, 'cache')) + shutil.copyfile(builddir + '/cache/bb_unihashes.dat', baseoutpath + '/cache/bb_unihashes.dat') + # Write a templateconf.cfg with open(baseoutpath + '/conf/templateconf.cfg', 'w') as f: f.write('meta/conf\n')
@@ -440,6 +445,11 @@ python copy_buildsystem () { else: tasklistfn = None + if os.path.exists(builddir + '/cache/bb_unihashes.dat'): + bb.parse.siggen.save_unitaskhashes() + bb.utils.mkdirhier(os.path.join(baseoutpath, 'cache')) + shutil.copyfile(builddir + '/cache/bb_unihashes.dat', baseoutpath + '/cache/bb_unihashes.dat') + # Add packagedata if enabled if d.getVar('SDK_INCLUDE_PKGDATA') == '1': lockedsigs_base = d.getVar('WORKDIR') + '/locked-sigs-base.inc'
Signature · 1 line
2.20.1