All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Juergen Gross <jgross@suse.com>,
	linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org,
	x86@kernel.org
Cc: sstabellini@kernel.org, mingo@redhat.com, bp@alien8.de,
	hpa@zytor.com, boris.ostrovsky@oracle.com, tglx@linutronix.de
Subject: Re: [PATCH] x86/xen: fix pv boot
Date: Wed, 7 Nov 2018 11:55:26 +0000	[thread overview]
Message-ID: <f95cf3fb-fb49-8211-0c54-f6c7382ac455__20625.5226432861$1541591668$gmane$org@citrix.com> (raw)
In-Reply-To: <20181107113017.30090-1-jgross@suse.com>

On 07/11/18 11:30, Juergen Gross wrote:
> Commit 9da3f2b7405440 ("x86/fault: BUG() when uaccess helpers fault on
> kernel addresses") introduced a regression for booting Xen PV guests.
>
> Xen PV guests are using __put_user() and __get_user() for accessing the
> p2m map (physical to machine frame number map) as accesses might fail
> in case of not populated areas of the map.
>
> With above commit using __put_user() and __get_user() for accessing
> kernel pages is no longer valid. So replace the Xen hack by adding
> appropriate p2m access functions using the default fixup handler.
>
> Fixes: 9da3f2b7405440 ("x86/fault: BUG() when uaccess helpers fault on kernel addresses")
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>  arch/x86/include/asm/xen/page.h | 39 ++++++++++++++++++++++++++++++++++++---
>  arch/x86/xen/p2m.c              |  3 +--
>  2 files changed, 37 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index 123e669bf363..a39015cb2f3f 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -9,7 +9,7 @@
>  #include <linux/mm.h>
>  #include <linux/device.h>
>  
> -#include <linux/uaccess.h>
> +#include <asm/extable.h>
>  #include <asm/page.h>
>  #include <asm/pgtable.h>
>  
> @@ -91,15 +91,48 @@ clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
>   * Helper functions to write or read unsigned long values to/from
>   * memory, when the access may fault.
>   */
> +#ifdef CONFIG_X86_32
> +#define __i "l"
> +#define __r "k"
> +#else
> +#define __i "q"
> +#define __r ""
> +#endif

You don't need any of these.  GCC and Clang can derive the correct
encoding from the type passed in, and will DTRT given unsigned long's.

Furthermore, it makes the asm easier to read.

>  static inline int xen_safe_write_ulong(unsigned long *addr, unsigned long val)
>  {
> -	return __put_user(val, (unsigned long __user *)addr);
> +	int ret = 0;
> +
> +	asm volatile("1: mov"__i" %"__r"1,%2\n"
> +		     "2:\n"
> +		     ".section .fixup,\"ax\"\n"
> +		     "3: mov %3,%0\n"
> +		     "   jmp 2b\n"
> +		     ".previous\n"
> +		     _ASM_EXTABLE(1b, 3b)
> +		     : "=r"(ret)
> +		     : "r" (val), "m" (*addr), "i" (-1), "0" (ret));

This constraint hides the write to addr.

> +	return ret;
>  }
>  
>  static inline int xen_safe_read_ulong(unsigned long *addr, unsigned long *val)
>  {
> -	return __get_user(*val, (unsigned long __user *)addr);
> +	int ret = 0;
> +	unsigned long rval;
> +
> +	asm volatile("1: mov"__i" %2,%"__r"1\n"
> +		     "2:\n"
> +		     ".section .fixup,\"ax\"\n"
> +		     "3: mov %3,%0\n"
> +		     "   jmp 2b\n"
> +		     ".previous\n"
> +		     _ASM_EXTABLE(1b, 3b)
> +		     : "=r" (ret), "=r" (rval)
> +		     : "m" (*addr), "i" (-1), "0" (ret));
> +	*val = rval;
> +	return ret;

This also uses rval uninitialised if a fault occurs.

Overall, how about:

static inline int xen_safe_write_ulong(unsigned long *addr, unsigned
long val)
{
    int ret = 0;

    asm volatile("1: mov %[val], %[ptr]\n"
                 "2:\n"
                 ".section .fixup, \"ax\"\n"
                 "3: mov %[err], %[ret]\n"
                 "   jmp 2b\n"
                 ".previous\n"
                 _ASM_EXTABLE(1b, 3b)
                 : [ret] "+r" (ret), [ptr] "=m" (*addr),
                 : [val] "r" (val), [err] "i" (-1));

    return ret;
}

static inline int xen_safe_read_ulong(const unsigned long *addr,
                                      unsigned long *val)
{
    int ret = 0;
    unsigned long rval = ~0ul;

    asm volatile("1: mov %[ptr], %[rval]\n"
                 "2:\n"
                 ".section .fixup, \"ax\"\n"
                 "3: mov %[err], %[ret]\n"
                 "   jmp 2b\n"
                 ".previous\n"
                 _ASM_EXTABLE(1b, 3b)
                 : [ret] "+r" (ret), [rval] "+r" (rval)
                 : [ptr] "=m" (*addr), [err] "i" (-1));
    *val = rval;

    return ret;
}

?

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-11-07 11:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-07 11:30 [PATCH] x86/xen: fix pv boot Juergen Gross
2018-11-07 11:55 ` Andrew Cooper [this message]
2018-11-07 11:55 ` [Xen-devel] " Andrew Cooper
2018-11-07 12:02   ` Andrew Cooper
2018-11-07 12:16     ` Juergen Gross
2018-11-07 12:16     ` [Xen-devel] " Juergen Gross
2018-11-07 12:02   ` Andrew Cooper
2018-11-07 11:30 Juergen Gross

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='f95cf3fb-fb49-8211-0c54-f6c7382ac455__20625.5226432861$1541591668$gmane$org@citrix.com' \
    --to=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sstabellini@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.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.