From: "Leizhen (ThunderTown)" <thunder.leizhen@huawei.com>
To: kernel test robot <lkp@intel.com>
Cc: <kbuild-all@lists.01.org>,
Linux Memory Management List <linux-mm@kvack.org>,
"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Subject: Re: [linux-next:master 8145/11162] arch/arm/kernel/traps.c:198:37: sparse: sparse: incorrect type in assignment (different base types)
Date: Sat, 8 Oct 2022 11:53:00 +0800 [thread overview]
Message-ID: <0426e063-003c-d961-7ce9-fb63b16839a1@huawei.com> (raw)
In-Reply-To: <202209292229.yDd7W4uU-lkp@intel.com>
On 2022/9/29 23:07, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
> head: de90d455a35e474a184c898e66a6a108c3a99434
> commit: f640b1a57f8e9e513e26aa5b3ee0b905dfebfcf2 [8145/11162] ARM: 9225/1: Make the dumped instructions are consistent with the disassembled ones
> config: arm-randconfig-s043-20220925
> compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0
> reproduce:
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # apt-get install sparse
> # sparse version: v0.6.4-39-gce1a6720-dirty
> # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=f640b1a57f8e9e513e26aa5b3ee0b905dfebfcf2
> git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
> git fetch --no-tags linux-next master
> git checkout f640b1a57f8e9e513e26aa5b3ee0b905dfebfcf2
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <lkp@intel.com>
>
> sparse warnings: (new ones prefixed by >>)
> arch/arm/kernel/traps.c:191:39: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void const volatile [noderef] __user *ptr @@ got unsigned short [usertype] * @@
> arch/arm/kernel/traps.c:191:39: sparse: expected void const volatile [noderef] __user *ptr
> arch/arm/kernel/traps.c:191:39: sparse: got unsigned short [usertype] *
> arch/arm/kernel/traps.c:193:39: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void const volatile [noderef] __user *ptr @@ got unsigned int [usertype] * @@
> arch/arm/kernel/traps.c:193:39: sparse: expected void const volatile [noderef] __user *ptr
> arch/arm/kernel/traps.c:193:39: sparse: got unsigned int [usertype] *
These warnings are not caused by this patch. I will use another patch to fix them.
if (thumb)
- bad = get_user(val, &((u16 *)addr)[i]);
+ bad = get_user(val, &((u16 __user *)addr)[i]);
else
- bad = get_user(val, &((u32 *)addr)[i]);
+ bad = get_user(val, &((u32 __user *)addr)[i]);
>>> arch/arm/kernel/traps.c:198:37: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [addressable] [assigned] val @@ got restricted __le16 [usertype] @@
> arch/arm/kernel/traps.c:198:37: sparse: expected unsigned int [addressable] [assigned] val
> arch/arm/kernel/traps.c:198:37: sparse: got restricted __le16 [usertype]
>>> arch/arm/kernel/traps.c:200:37: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [addressable] [assigned] val @@ got restricted __le32 [usertype] @@
> arch/arm/kernel/traps.c:200:37: sparse: expected unsigned int [addressable] [assigned] val
> arch/arm/kernel/traps.c:200:37: sparse: got restricted __le32 [usertype]
OK, to clear this static check warning, I need to add "(__force unsigned int)"
to perform the forced type conversion, because it requires that the type of
'val' be "__le16" or "__le32".
> arch/arm/kernel/traps.c:465:33: sparse: sparse: cast removes address space '__user' of expression
> arch/arm/kernel/traps.c:468:41: sparse: sparse: cast removes address space '__user' of expression
> arch/arm/kernel/traps.c:473:33: sparse: sparse: cast removes address space '__user' of expression
>
> vim +198 arch/arm/kernel/traps.c
>
> 164
> 165 static void dump_instr(const char *lvl, struct pt_regs *regs)
> 166 {
> 167 unsigned long addr = instruction_pointer(regs);
> 168 const int thumb = thumb_mode(regs);
> 169 const int width = thumb ? 4 : 8;
> 170 char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str;
> 171 int i;
> 172
> 173 /*
> 174 * Note that we now dump the code first, just in case the backtrace
> 175 * kills us.
> 176 */
> 177
> 178 for (i = -4; i < 1 + !!thumb; i++) {
> 179 unsigned int val, bad;
> 180
> 181 if (!user_mode(regs)) {
> 182 if (thumb) {
> 183 u16 val16;
> 184 bad = get_kernel_nofault(val16, &((u16 *)addr)[i]);
> 185 val = val16;
> 186 } else {
> 187 bad = get_kernel_nofault(val, &((u32 *)addr)[i]);
> 188 }
> 189 } else {
> 190 if (thumb)
> 191 bad = get_user(val, &((u16 *)addr)[i]);
> 192 else
> 193 bad = get_user(val, &((u32 *)addr)[i]);
> 194 }
> 195
> 196 if (IS_ENABLED(CONFIG_CPU_ENDIAN_BE8)) {
> 197 if (thumb)
> > 198 val = cpu_to_le16(val);
> 199 else
> > 200 val = cpu_to_le32(val);
> 201 }
> 202
> 203 if (!bad)
> 204 p += sprintf(p, i == 0 ? "(%0*x) " : "%0*x ",
> 205 width, val);
> 206 else {
> 207 p += sprintf(p, "bad PC value");
> 208 break;
> 209 }
> 210 }
> 211 printk("%sCode: %s\n", lvl, str);
> 212 }
> 213
>
--
Regards,
Zhen Lei
prev parent reply other threads:[~2022-10-08 3:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-29 15:07 kernel test robot
2022-10-08 3:53 ` Leizhen (ThunderTown) [this message]
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=0426e063-003c-d961-7ce9-fb63b16839a1@huawei.com \
--to=thunder.leizhen@huawei.com \
--cc=kbuild-all@lists.01.org \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=rmk+kernel@armlinux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox