All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	Julien Grall <julien.grall@citrix.com>
Cc: xen-devel@lists.xenproject.org, Keir Fraser <keir@xen.org>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Tim Deegan <tim@xen.org>
Subject: Re: [PATCH 4/4] xen/public: arm: rework the macro set_xen_guest_handle_raw
Date: Tue, 3 Nov 2015 12:35:24 +0000	[thread overview]
Message-ID: <1446554124.10390.19.camel@citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1511021520190.15801@kaball.uk.xensource.com>

On Mon, 2015-11-02 at 15:55 +0000, Stefano Stabellini wrote:
> 
> > +/*
> > + * Macro to set a guest pointer in the handle.
> > + *
> > + * Note that it's not possible to implement safely a macro to retrieve the
> > + * handle unless the guest is built with strict aliasing disabling.
> > + * Hence, we don't provide a such macro in the public headers.
> > + */
> > +#define set_xen_guest_handle_raw(hnd, val)                              \
> > +    do {                                                                \
> > +        /* Check if the handle is 64-bit (i.e 8-byte) */                \
> > +        (void) sizeof(struct { int : -!!(sizeof (hnd) != 8);
> > });        \
> > +        /* Check if the type of val is compatible with the handle
> > */    \
> > +        (void) sizeof((val) !=
> > (hnd).p);                                \
> > +        (hnd).q =
> > (uint64_t)(uintptr_t)(val);                           \
> >      } while ( 0 )
> 
> Honestly I would be OK with having a typeof in the public headers to
> avoid this code, which is much harder to follow.

I suppose your objection is to two things:

+        /* Check if the handle is 64-bit (i.e 8-byte) */                \
+        (void) sizeof(struct { int : -!!(sizeof (hnd) != 8); });        \

and

+        /* Check if the type of val is compatible with the handle */    \
+        (void) sizeof((val) != (hnd).p);                                \

The first is really just an open coding of BUILD_BUG_ON, I suppose for some
reason BUILD_BUG_ON cannot just be used here (I assume because this is
itself a macro).

Personally I think a comment referring back to BUILD_BUG_ON e.g.:
    /* BUILD_BUG_ON(sizeof(hnd) != 8); Cannot use real B_B_O in a macro */
would be sufficient.

For the second I think the comparison of two pointers in this as a macro
type safety check is a common enough idiom that it should be understood.
But I wouldn't object to a more explicit comment explaining this, or
explaining that sizeof is necessary to not evaluate hnd a second time in
the macro.

On the second though, Julien I think it needs to be (&val) since you need
to compare the pointers to the types to trigger the compiler's "comparing
distinct pointer types" warning/error. Also given this new usage I think it
would be worth renaming p and q to something less opaque, value and
type_check or something would be fine IMHO.

>  Why don't we do something like the following:

Apart from Jan's comment about __asm__ and a question I have about whether
it isn't even needed, how certain are you that this doesn't violate any of
the C aliasing rules etc?

BTW, Julien, I think it would be fine to also make this macro differ for
arm32 and arm64, since the arm64 variant would then surely be simpler and
the arm32 one might (or might not) be.

> diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-
> arm.h
> index 9a96401..e676ffb 100644
> --- a/xen/include/public/arch-arm.h
> +++ b/xen/include/public/arch-arm.h
> @@ -189,11 +189,12 @@
>  #define __XEN_GUEST_HANDLE(name)        __guest_handle_64_ ## name
>  #define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
>  #define XEN_GUEST_HANDLE_PARAM(name)    __guest_handle_ ## name
> +#define barrier()     __asm__ __volatile__("": : :"memory")
>  #define set_xen_guest_handle_raw(hnd, val)                  \
>      do {                                                    \
> -        typeof(&(hnd)) _sxghr_tmp = &(hnd);                 \
> -        _sxghr_tmp->q = 0;                                  \
> -        _sxghr_tmp->p = val;                                \
> +        *((uint64_aligned_t *)&(hnd)) = 0;                  \
> +        barrier();                                          \
> +        (hnd).p = val;                                      \
>      } while ( 0 )
>  #ifdef __XEN_TOOLS__
>  #define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  parent reply	other threads:[~2015-11-03 12:35 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-30 18:13 [PATCH 0/4] xen/public: arm: rework set_xen_guest_handle_raw Julien Grall
2015-10-30 18:13 ` [PATCH 1/4] xen/public: arm: Clarify the name of guest handle structures Julien Grall
2015-11-02 15:14   ` Stefano Stabellini
2015-10-30 18:13 ` [PATCH 2/4] xen/public: arm: Rework __guest_handle_param* Julien Grall
2015-11-02 15:19   ` Stefano Stabellini
2015-11-02 15:24     ` Julien Grall
2015-11-02 15:35       ` Ian Campbell
2015-11-02 15:39         ` Julien Grall
2015-11-02 15:49           ` Ian Campbell
2015-10-30 18:13 ` [PATCH 3/4] xen/public: Don't expose XEN_GUEST_HANDLE_PARAM outside of the hypervisor Julien Grall
2015-11-02 13:45   ` Jan Beulich
2015-11-02 13:52     ` Stefano Stabellini
2015-10-30 18:13 ` [PATCH 4/4] xen/public: arm: rework the macro set_xen_guest_handle_raw Julien Grall
2015-11-02 15:55   ` Stefano Stabellini
2015-11-02 16:15     ` Jan Beulich
2015-11-03 12:35     ` Ian Campbell [this message]
2015-11-03 14:01       ` Julien Grall
2015-11-03 14:34         ` Ian Campbell
2015-11-04 11:17           ` Julien Grall
2015-11-04 11:27             ` Ian Campbell
2015-11-04 11:40               ` Julien Grall
2015-11-04 14:29                 ` Ian Campbell
2015-11-04 14:42                   ` Julien Grall
2015-11-04 14:54                     ` Ian Campbell
2015-11-04 15:19                 ` Stefano Stabellini
2015-11-04 15:20                   ` Ian Jackson
2015-11-04 15:45                     ` Ian Jackson
2015-11-04 15:26                   ` Ian Campbell
2015-11-04 15:46                     ` Ian Jackson
2015-11-04 16:04                       ` Ian Campbell
2015-11-03 14:18   ` Stefano Stabellini
2015-11-03 15:25     ` Julien Grall
2015-11-04 16:22       ` Ian Jackson
2015-11-04 16:24         ` Ian Jackson
2015-11-04 16:39         ` Jan Beulich
2015-11-04 16:50           ` Ian Jackson
2015-11-04 16:59             ` Julien Grall
2015-11-04 17:05             ` Jan Beulich
2015-11-04 17:06               ` Ian Jackson
2015-11-05  8:37                 ` Jan Beulich
2015-11-06 12:10             ` Ian Campbell
2015-11-02 13:42 ` [PATCH 0/4] xen/public: arm: rework set_xen_guest_handle_raw Jan Beulich
2015-11-02 13:45   ` Julien Grall

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=1446554124.10390.19.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@citrix.com \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=tim@xen.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.