All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@citrix.com>
To: Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.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: Wed, 4 Nov 2015 11:40:38 +0000	[thread overview]
Message-ID: <5639EEB6.6040908@citrix.com> (raw)
In-Reply-To: <1446636465.6461.70.camel@citrix.com>

On 04/11/15 11:27, Ian Campbell wrote:
> On Wed, 2015-11-04 at 11:17 +0000, Julien Grall wrote:
>>>
>>> we could:
>>> #ifdef(__XEN__)
>>> #define XEN_BUILD_BUG_ON(x) BUILD_BUG_ON(x)
>>> #elif !defined(XEN_BUILD_BUG_ON)
>>> #define XEN_BUILD_BUG_ON(x)
>>> #endif
>>> and using XEN_BUILD_BUG_ON in the macro
>>>
>>> So, __XEN__ builds get the check and users can opt in by providing
>>> XEN_BUILD_BUG_ON if they want. If they don't then they don't get the
>>> check.
>>
>> I wouldn't let the user the choice to disable build-time check.
> 
> Up to you. Note that "the user" here would potentially include
> xen.git/tools, and I would expect them to want to define it.
> 
> Also...
> 
>>  There is
>> no harm to open-code them as I did today and avoid possible issue in the
>> code later.
> 
> ... there is always a downside to open coding. If you don't want to expose
> the ability to define a BUG_ON to the application then just drop that #elif
> from the chain.

Good point. I will give a look.

> 
>>> Or maybe we could just omit this from the public API by one or both of
>>> a)
>>> adding an explicit 8 byte type to the union purely to force the size
>>> and/or
>>
>> This is already done in the current version:
>>
>>     typedef union { type *p; uint64_aligned_t q; }              \
>>         __guest_handle_64_ ## name;
>>
>> However I don't see how this ensure that the caller of
>> set_xen_raw_guest_handle will effectively hnd as a pointer to an 8-byte
>> placeholder.
> 
> Not sure I follow. If hnd isn't a suitable struct xen guest handle then
> other things will fail. If a user is passing a non struct xen_guest_handle
> to this which happens to contain the same fields then more fool them, and
> if it happens to be 8 bytes anyway your check won't catch that.

With the 2 checks in set_xen_raw_guest_handle we catch most of the
problem. They both ensure that the handle is 8-byte and the pointer is
valid. However we don't check that the padding is at the beginning of
the structure.

It's better than what we have today as we don't even check that the
handle is 8-byte.

[...]

>>> This looses out on the arm32 hypervisor sanity checking that the padding
>>> bytes are 0 (as required by the ABI) but TBH I haven't checked that the
>>> current version has that property either.
>>
>> It's done during the assignation by the compiler:
>>
>> (hnd).q = (uint64_t)(uintptr_t)(val);
> 
> I meant on the reading side.

It's the responsibility of the caller to zero the padding. There is
nothing to do on the reading side, the hypervisor will use "p" which
will be the size of the natural pointer.

Regards,

-- 
Julien Grall

  reply	other threads:[~2015-11-04 11:42 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
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 [this message]
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=5639EEB6.6040908@citrix.com \
    --to=julien.grall@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.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.