From: "Jan Beulich" Subject: Re: [PATCH v2 5/5] xen: replace XEN_GUEST_HANDLE with XEN_GUEST_HANDLE_PARAM when appropriate Date: Tue, 14 Aug 2012 17:14:04 +0100 Message-ID: <502A956C0200007800094DFE@nat28.tlf.novell.com> References: <1344600612-10815-5-git-send-email-stefano.stabellini@eu.citrix.com> <5025276B02000078000942BE@nat28.tlf.novell.com> <5029098A020000780009471C@nat28.tlf.novell.com> <502A58CF0200007800094BE4@nat28.tlf.novell.com> <502A71370200007800094C5F@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Stefano Stabellini Cc: "xen-devel@lists.xensource.com" , Ian Campbell , "Tim Deegan (3P)" List-Id: xen-devel@lists.xenproject.org >>> On 14.08.12 at 17:42, Stefano Stabellini wrote: > On Tue, 14 Aug 2012, Jan Beulich wrote: >> >>> On 14.08.12 at 14:56, Stefano Stabellini > wrote: >> > On Tue, 14 Aug 2012, Jan Beulich wrote: >> >> Perhaps we have a different understanding of embedded fields: >> >> I'm thinking of structure field having XEN_GUEST_HANDLE() type. >> >> An example would be struct mmuext_op's vcpumask field, which >> >> is being passed to vcpumask_to_pcpumask(). This must remain to >> >> be possible (and not just in x86-specific code, where it's mere luck >> >> that both are really identical). >> > >> > Thanks for the concrete example; glancing through the common code I >> > didn't find any examples like this. >> > As I wrote in the follow up email, guest_handle_cast is just what we >> > need: >> > >> > diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c >> > index 4d72700..70ffa58 100644 >> > --- a/xen/arch/x86/mm.c >> > +++ b/xen/arch/x86/mm.c >> > @@ -3198,7 +3198,9 @@ int do_mmuext_op( >> > { >> > cpumask_t pmask; >> > >> > - if ( unlikely(vcpumask_to_pcpumask(d, op.arg2.vcpumask, &pmask)) > ) >> > + if ( unlikely(vcpumask_to_pcpumask(d, >> > + guest_handle_cast(op.arg2.vcpumask, > const_void), >> >> No, the conversion should explicitly _not_ require specification >> of the type, i.e. this should not be a true cast. Type safety >> (checked by the compiler) can only be achieved if no intermediate >> cast is involved. > > guest_handle_cast is implemented as: > > #define guest_handle_cast(hnd, type) ({ \ > type *_x = (hnd).p; \ > (XEN_GUEST_HANDLE_PARAM(type)) { _x }; \ > }) > > as you can see there is actually no explicit cast involved. > If you specify the wrong type the compiler would fail at: > > type *_x = (hnd).p; Except if, as in your example, "type" is (a qualified version of) "void"... > I think that having to specify the type as parameter is acceptable if it > makes up for simpler code over all. > > The alternative would be something like the following: > > diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c > index 4d72700..e6685c7 100644 > --- a/xen/arch/x86/mm.c > +++ b/xen/arch/x86/mm.c > @@ -3197,8 +3197,11 @@ int do_mmuext_op( > case MMUEXT_INVLPG_MULTI: > { > cpumask_t pmask; > + XEN_GUEST_HANDLE_PARAM(const_void) param; > > - if ( unlikely(vcpumask_to_pcpumask(d, op.arg2.vcpumask, &pmask)) ) > + set_xen_guest_handle(param, op.arg2.vcpumask.p); > + > + if ( unlikely(vcpumask_to_pcpumask(d, param, &pmask)) ) No, I would expect this to be possible without an intermediate variable (i.e. similar to the guest_handle_cast() approach, just without specifying the type). And in no case should there be an open coded access to the "p" member. > { > okay = 0; > break; > > but I think it makes the code worse. Agreed, this variant definitely looked worse. Jan