All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Christoph Hellwig <hch@lst.de>,
	Russell King <rmk@arm.linux.org.uk>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linus.walleij@linaro.org,
	Russell King <linux@armlinux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/9] ARM: traps: use get_kernel_nofault instead of set_fs()
Date: Tue, 8 Sep 2020 08:15:28 +0200	[thread overview]
Message-ID: <20200908061528.GB13930@lst.de> (raw)
In-Reply-To: <20200907153701.2981205-3-arnd@arndb.de>

> +static void dump_mem(const char *, const char *, unsigned long, unsigned long, bool kernel_mode);

This adds a pointlessly long line.  

And looking at the code I don't see why the argument is even needed.

dump_mem() currently does an unconditional set_fs(KERNEL_DS), so it
should always use get_kernel_nofault.

> +static void dump_instr(const char *lvl, struct pt_regs *regs)
>  {
>  	unsigned long addr = instruction_pointer(regs);
>  	const int thumb = thumb_mode(regs);
> @@ -173,10 +169,20 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs)
>  	for (i = -4; i < 1 + !!thumb; i++) {
>  		unsigned int val, bad;
>  
> -		if (thumb)
> -			bad = get_user(val, &((u16 *)addr)[i]);
> -		else
> -			bad = get_user(val, &((u32 *)addr)[i]);
> +		if (!user_mode(regs)) {
> +			if (thumb) {
> +				u16 val16;
> +				bad = get_kernel_nofault(val16, &((u16 *)addr)[i]);
> +				val = val16;
> +			} else {
> +				bad = get_kernel_nofault(val, &((u32 *)addr)[i]);
> +			}
> +		} else {
> +			if (thumb)
> +				bad = get_user(val, &((u16 *)addr)[i]);
> +			else
> +				bad = get_user(val, &((u32 *)addr)[i]);
> +		}

When I looked at this earlier I just added a little helper to make
this a little easier to read.   Here is my patch from an old tree:

http://git.infradead.org/users/hch/misc.git/commitdiff/67413030ccb7a64a7eb828e13ff0795f4eadfeb7

WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arch@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com>,
	linus.walleij@linaro.org, kernel@vger.kernel.org,
	Russell King <linux@armlinux.org.uk>,
	linux-kernel@vger.kernel.org, Russell King <rmk@arm.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christoph Hellwig <hch@lst.de>,
	linux-arm-kernel@lists.infradead.org,
	Alexander Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH 2/9] ARM: traps: use get_kernel_nofault instead of set_fs()
Date: Tue, 8 Sep 2020 08:15:28 +0200	[thread overview]
Message-ID: <20200908061528.GB13930@lst.de> (raw)
In-Reply-To: <20200907153701.2981205-3-arnd@arndb.de>

> +static void dump_mem(const char *, const char *, unsigned long, unsigned long, bool kernel_mode);

This adds a pointlessly long line.  

And looking at the code I don't see why the argument is even needed.

dump_mem() currently does an unconditional set_fs(KERNEL_DS), so it
should always use get_kernel_nofault.

> +static void dump_instr(const char *lvl, struct pt_regs *regs)
>  {
>  	unsigned long addr = instruction_pointer(regs);
>  	const int thumb = thumb_mode(regs);
> @@ -173,10 +169,20 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs)
>  	for (i = -4; i < 1 + !!thumb; i++) {
>  		unsigned int val, bad;
>  
> -		if (thumb)
> -			bad = get_user(val, &((u16 *)addr)[i]);
> -		else
> -			bad = get_user(val, &((u32 *)addr)[i]);
> +		if (!user_mode(regs)) {
> +			if (thumb) {
> +				u16 val16;
> +				bad = get_kernel_nofault(val16, &((u16 *)addr)[i]);
> +				val = val16;
> +			} else {
> +				bad = get_kernel_nofault(val, &((u32 *)addr)[i]);
> +			}
> +		} else {
> +			if (thumb)
> +				bad = get_user(val, &((u16 *)addr)[i]);
> +			else
> +				bad = get_user(val, &((u32 *)addr)[i]);
> +		}

When I looked at this earlier I just added a little helper to make
this a little easier to read.   Here is my patch from an old tree:

http://git.infradead.org/users/hch/misc.git/commitdiff/67413030ccb7a64a7eb828e13ff0795f4eadfeb7

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-09-08  6:15 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-07 15:36 [PATCH 0/9] ARM: remove set_fs callers and implementation Arnd Bergmann
2020-09-07 15:36 ` Arnd Bergmann
2020-09-07 15:36 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann
2020-09-07 15:36   ` Arnd Bergmann
2020-09-08  6:11   ` Christoph Hellwig
2020-09-08  6:11     ` Christoph Hellwig
2020-09-27  9:25   ` Linus Walleij
2020-09-27  9:25     ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from, to}_kernel_nofault Linus Walleij
2020-09-07 15:36 ` [PATCH 2/9] ARM: traps: use get_kernel_nofault instead of set_fs() Arnd Bergmann
2020-09-07 15:36   ` Arnd Bergmann
2020-09-08  6:15   ` Christoph Hellwig [this message]
2020-09-08  6:15     ` Christoph Hellwig
2020-09-17 17:29     ` Arnd Bergmann
2020-09-17 17:29       ` Arnd Bergmann
2020-09-18  7:42       ` Russell King - ARM Linux admin
2020-09-18  7:42         ` Russell King - ARM Linux admin
2020-09-18 12:36         ` Arnd Bergmann
2020-09-18 12:36           ` Arnd Bergmann
2020-09-07 15:36 ` [PATCH 3/9] ARM: oabi-compat: add epoll_pwait handler Arnd Bergmann
2020-09-07 15:36   ` Arnd Bergmann
2020-09-08  6:16   ` Christoph Hellwig
2020-09-08  6:16     ` Christoph Hellwig
2020-09-07 15:36 ` [PATCH 4/9] ARM: syscall: always store thread_info->syscall Arnd Bergmann
2020-09-07 15:36   ` Arnd Bergmann
2020-09-28  9:41   ` Linus Walleij
2020-09-28  9:41     ` Linus Walleij
2020-09-28 12:42     ` Arnd Bergmann
2020-09-28 12:42       ` Arnd Bergmann
2020-09-28 15:08       ` Russell King - ARM Linux admin
2020-09-28 15:08         ` Russell King - ARM Linux admin
2020-09-07 15:36 ` [PATCH 5/9] ARM: oabi-compat: rework epoll_wait/epoll_pwait emulation Arnd Bergmann
2020-09-07 15:36   ` Arnd Bergmann
2020-09-08  6:20   ` Christoph Hellwig
2020-09-08  6:20     ` Christoph Hellwig
2020-09-08 20:56     ` Arnd Bergmann
2020-09-08 20:56       ` Arnd Bergmann
2020-09-07 15:36 ` [PATCH 6/9] ARM: oabi-compat: rework sys_semtimedop emulation Arnd Bergmann
2020-09-07 15:36   ` Arnd Bergmann
2020-09-07 15:36 ` [PATCH 7/9] ARM: oabi-compat: rework fcntl64() emulation Arnd Bergmann
2020-09-07 15:36   ` Arnd Bergmann
2020-09-07 15:36 ` [PATCH 8/9] ARM: uaccess: add __{get,put}_kernel_nofault Arnd Bergmann
2020-09-07 15:36   ` Arnd Bergmann
2020-09-07 15:36 ` [PATCH 9/9] ARM: uaccess: remove set_fs() implementation Arnd Bergmann
2020-09-07 15:36   ` Arnd Bergmann
  -- strict thread matches above, loose matches on Subject: below --
2020-10-30 15:45 [PATCH v4 0/9] ARM: remove set_fs callers and implementation Arnd Bergmann
2020-10-30 15:49 ` [PATCH 1/9] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Arnd Bergmann
2020-10-30 15:49   ` [PATCH 2/9] ARM: traps: use get_kernel_nofault instead of set_fs() Arnd Bergmann
2020-10-30 15:49     ` Arnd Bergmann
2020-11-06  9:02     ` Linus Walleij
2020-11-06  9:02       ` Linus Walleij

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=20200908061528.GB13930@lst.de \
    --to=hch@lst.de \
    --cc=0x7f454c46@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=kernel@vger.kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=rmk@arm.linux.org.uk \
    --cc=viro@zeniv.linux.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 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.