All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: "Mike Rapoport (IBM)" <rppt@kernel.org>
Cc: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	Mike Rapoport <rppt@kernel.org>
Subject: [rppt:execmem/x86-rox/rfc-v2 21/25] arch/x86/kernel/alternative.c:417:17: error: call to undeclared function 'module_writable_address'; ISO C99 and later do not support implicit function declarations
Date: Mon, 6 May 2024 23:43:06 +0800	[thread overview]
Message-ID: <202405062340.eU4eWKR3-lkp@intel.com> (raw)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git execmem/x86-rox/rfc-v2
head:   0caa8ac5e8f2f6de2e75cd2ddd552e8756779944
commit: 4527045f6e1892edac12176b8d82094c35427cdf [21/25] x86/module: perpare module loading for ROX allocations of text
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20240506/202405062340.eU4eWKR3-lkp@intel.com/config)
compiler: clang version 18.1.4 (https://github.com/llvm/llvm-project e6c3289804a67ea0bb6a86fadbe454dd93b8d855)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240506/202405062340.eU4eWKR3-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405062340.eU4eWKR3-lkp@intel.com/

All errors (new ones prefixed by >>):

>> arch/x86/kernel/alternative.c:417:17: error: call to undeclared function 'module_writable_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     417 |         u8 *wr_instr = module_writable_address(mod, instr);
         |                        ^
>> arch/x86/kernel/alternative.c:417:6: error: incompatible integer to pointer conversion initializing 'u8 *' (aka 'unsigned char *') with an expression of type 'int' [-Wint-conversion]
     417 |         u8 *wr_instr = module_writable_address(mod, instr);
         |             ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/x86/kernel/alternative.c:500:14: error: call to undeclared function 'module_writable_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     500 |                 wr_instr = module_writable_address(mod, instr);
         |                            ^
>> arch/x86/kernel/alternative.c:500:12: error: incompatible integer to pointer conversion assigning to 'u8 *' (aka 'unsigned char *') from 'int' [-Wint-conversion]
     500 |                 wr_instr = module_writable_address(mod, instr);
         |                          ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/x86/kernel/alternative.c:503:18: error: incompatible integer to pointer conversion assigning to 'u8 *' (aka 'unsigned char *') from 'int' [-Wint-conversion]
     503 |                 wr_replacement = module_writable_address(mod, replacement);
         |                                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   5 errors generated.


vim +/module_writable_address +417 arch/x86/kernel/alternative.c

   409	
   410	/*
   411	 * Rewrite the "call BUG_func" replacement to point to the target of the
   412	 * indirect pv_ops call "call *disp(%ip)".
   413	 */
   414	static int alt_replace_call(u8 *instr, u8 *insn_buff, struct alt_instr *a,
   415				    struct module *mod)
   416	{
 > 417		u8 *wr_instr = module_writable_address(mod, instr);
   418		void *target, *bug = &BUG_func;
   419		s32 disp;
   420	
   421		if (a->replacementlen != 5 || insn_buff[0] != CALL_INSN_OPCODE) {
   422			pr_err("ALT_FLAG_DIRECT_CALL set for a non-call replacement instruction\n");
   423			BUG();
   424		}
   425	
   426		if (a->instrlen != 6 ||
   427		    wr_instr[0] != CALL_RIP_REL_OPCODE ||
   428		    wr_instr[1] != CALL_RIP_REL_MODRM) {
   429			pr_err("ALT_FLAG_DIRECT_CALL set for unrecognized indirect call\n");
   430			BUG();
   431		}
   432	
   433		/* Skip CALL_RIP_REL_OPCODE and CALL_RIP_REL_MODRM */
   434		disp = *(s32 *)(wr_instr + 2);
   435	#ifdef CONFIG_X86_64
   436		/* ff 15 00 00 00 00   call   *0x0(%rip) */
   437		/* target address is stored at "next instruction + disp". */
   438		target = *(void **)(instr + a->instrlen + disp);
   439	#else
   440		/* ff 15 00 00 00 00   call   *0x0 */
   441		/* target address is stored at disp. */
   442		target = *(void **)disp;
   443	#endif
   444		if (!target)
   445			target = bug;
   446	
   447		/* (BUG_func - .) + (target - BUG_func) := target - . */
   448		*(s32 *)(insn_buff + 1) += target - bug;
   449	
   450		if (target == &nop_func)
   451			return 0;
   452	
   453		return 5;
   454	}
   455	
   456	/*
   457	 * Replace instructions with better alternatives for this CPU type. This runs
   458	 * before SMP is initialized to avoid SMP problems with self modifying code.
   459	 * This implies that asymmetric systems where APs have less capabilities than
   460	 * the boot processor are not handled. Tough. Make sure you disable such
   461	 * features by hand.
   462	 *
   463	 * Marked "noinline" to cause control flow change and thus insn cache
   464	 * to refetch changed I$ lines.
   465	 */
   466	void __init_or_module noinline apply_alternatives(struct alt_instr *start,
   467							  struct alt_instr *end,
   468							  struct module *mod)
   469	{
   470		struct alt_instr *a;
   471		u8 *instr, *replacement;
   472		u8 insn_buff[MAX_PATCH_LEN];
   473	
   474		DPRINTK(ALT, "alt table %px, -> %px", start, end);
   475	
   476		/*
   477		 * In the case CONFIG_X86_5LEVEL=y, KASAN_SHADOW_START is defined using
   478		 * cpu_feature_enabled(X86_FEATURE_LA57) and is therefore patched here.
   479		 * During the process, KASAN becomes confused seeing partial LA57
   480		 * conversion and triggers a false-positive out-of-bound report.
   481		 *
   482		 * Disable KASAN until the patching is complete.
   483		 */
   484		kasan_disable_current();
   485	
   486		/*
   487		 * The scan order should be from start to end. A later scanned
   488		 * alternative code can overwrite previously scanned alternative code.
   489		 * Some kernel functions (e.g. memcpy, memset, etc) use this order to
   490		 * patch code.
   491		 *
   492		 * So be careful if you want to change the scan order to any other
   493		 * order.
   494		 */
   495		for (a = start; a < end; a++) {
   496			int insn_buff_sz = 0;
   497			u8 *wr_instr, *wr_replacement;
   498	
   499			instr = (u8 *)&a->instr_offset + a->instr_offset;
 > 500			wr_instr = module_writable_address(mod, instr);
   501	
   502			replacement = (u8 *)&a->repl_offset + a->repl_offset;
   503			wr_replacement = module_writable_address(mod, replacement);
   504	
   505			BUG_ON(a->instrlen > sizeof(insn_buff));
   506			BUG_ON(a->cpuid >= (NCAPINTS + NBUGINTS) * 32);
   507	
   508			/*
   509			 * Patch if either:
   510			 * - feature is present
   511			 * - feature not present but ALT_FLAG_NOT is set to mean,
   512			 *   patch if feature is *NOT* present.
   513			 */
   514			if (!boot_cpu_has(a->cpuid) == !(a->flags & ALT_FLAG_NOT)) {
   515				optimize_nops_inplace(wr_instr, a->instrlen);
   516				continue;
   517			}
   518	
   519			DPRINTK(ALT, "feat: %d*32+%d, old: (%pS (%px) len: %d), repl: (%px, len: %d) flags: 0x%x",
   520				a->cpuid >> 5,
   521				a->cpuid & 0x1f,
   522				instr, instr, a->instrlen,
   523				replacement, a->replacementlen, a->flags);
   524	
   525			memcpy(insn_buff, wr_replacement, a->replacementlen);
   526			insn_buff_sz = a->replacementlen;
   527	
   528			if (a->flags & ALT_FLAG_DIRECT_CALL) {
   529				insn_buff_sz = alt_replace_call(instr, insn_buff, a,
   530								mod);
   531				if (insn_buff_sz < 0)
   532					continue;
   533			}
   534	
   535			for (; insn_buff_sz < a->instrlen; insn_buff_sz++)
   536				insn_buff[insn_buff_sz] = 0x90;
   537	
   538			apply_relocation(insn_buff, a->instrlen, instr, replacement, a->replacementlen);
   539	
   540			DUMP_BYTES(ALT, wr_instr, a->instrlen, "%px:   old_insn: ", instr);
   541			DUMP_BYTES(ALT, replacement, a->replacementlen, "%px:   rpl_insn: ", replacement);
   542			DUMP_BYTES(ALT, insn_buff, insn_buff_sz, "%px: final_insn: ", instr);
   543	
   544			text_poke_early(wr_instr, insn_buff, insn_buff_sz);
   545		}
   546	
   547		kasan_enable_current();
   548	}
   549	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

                 reply	other threads:[~2024-05-06 15:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202405062340.eU4eWKR3-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=rppt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.