1*8fc5ddd4SSong Liu#!/bin/bash 2*8fc5ddd4SSong Liu# SPDX-License-Identifier: GPL-2.0 3*8fc5ddd4SSong Liu# 4*8fc5ddd4SSong Liu# A patch may introduce a static branch where the original function had none. 5*8fc5ddd4SSong Liu# 6*8fc5ddd4SSong Liu# That is not the same case as patching a function which already has one. The 7*8fc5ddd4SSong Liu# __jump_table entry is itself new, so there is no counterpart in the original 8*8fc5ddd4SSong Liu# to correlate it against: klp diff has to carry the entry and the key into the 9*8fc5ddd4SSong Liu# patch from scratch, and the key has to be reached the way any other reference 10*8fc5ddd4SSong Liu# to a vmlinux symbol is. 11*8fc5ddd4SSong Liu# 12*8fc5ddd4SSong Liu# Get it wrong and the entry is dropped, leaving a static branch the kernel 13*8fc5ddd4SSong Liu# never patches -- the code takes the wrong arm forever, silently. 14*8fc5ddd4SSong Liu# 15*8fc5ddd4SSong Liu# Where the key lives still decides whether that is allowed, exactly as it does 16*8fc5ddd4SSong Liu# for a key the original already had: a module-owned one cannot be reached, so 17*8fc5ddd4SSong Liu# introducing one has to stop the build rather than emit an entry nothing will 18*8fc5ddd4SSong Liu# resolve. 19*8fc5ddd4SSong Liu# 20*8fc5ddd4SSong Liu# Covers the same ground as corpus/x86_64/static-branch-vmlinux-new and 21*8fc5ddd4SSong Liu# static-branch-module-new in Joe Lawrence's klp-build unit test corpus. 22*8fc5ddd4SSong Liu 23*8fc5ddd4SSong Liu. "$(dirname "$0")/../lib.sh" 24*8fc5ddd4SSong Liu 25*8fc5ddd4SSong Liusetup klp_test_key 26*8fc5ddd4SSong Liubuild_pair jump_label.c -DNEW_KEY 27*8fc5ddd4SSong Liu 28*8fc5ddd4SSong Liu# The premise: the original really has no jump table, and the patched one does. 29*8fc5ddd4SSong Liuhas_input_section orig.o __jump_table && 30*8fc5ddd4SSong Liu fail "fixture put a __jump_table in the original; nothing new to add" 31*8fc5ddd4SSong Liuhas_input_section patched.o __jump_table || 32*8fc5ddd4SSong Liu probe_skip "compiler produced no __jump_table on this arch" 33*8fc5ddd4SSong Liu 34*8fc5ddd4SSong Liurun_diff 35*8fc5ddd4SSong Liu 36*8fc5ddd4SSong Liuassert_patched target 37*8fc5ddd4SSong Liuassert_section __jump_table 38*8fc5ddd4SSong Liuassert_reloc_sym __jump_table target 39*8fc5ddd4SSong Liu 40*8fc5ddd4SSong Liu# The same new branch, with the key owned by a module. Drop the vmlinux export 41*8fc5ddd4SSong Liu# first: while it is exported the key is reachable and being new changes 42*8fc5ddd4SSong Liu# nothing, which is what the first version of this got wrong. 43*8fc5ddd4SSong Liuexport_syms 44*8fc5ddd4SSong Liurm -f "$workdir/out.o" 45*8fc5ddd4SSong Liubuild_pair jump_label.c -DNEW_KEY -DMODNAME='"klp_testmod"' 46*8fc5ddd4SSong Liurun_diff 255 47*8fc5ddd4SSong Liuassert_diff_log 'unsupported static branch key klp_test_key' 48*8fc5ddd4SSong Liu[ -e "$workdir/out.o" ] && 49*8fc5ddd4SSong Liu fail "output object produced for a rejected input" 50*8fc5ddd4SSong Liu 51*8fc5ddd4SSong Liupass "static branch introduced by the patch carried in, or rejected for a module key" 52