[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Xenvif non-zero byte assertion error during teardown


  • To: "Durrant, Paul" <pdurrant@xxxxxxxxxxxx>, win-pv-devel <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Date: Mon, 6 Jul 2026 16:09:12 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Delivery-date: Mon, 06 Jul 2026 14:09:21 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

On 06/07/2026 11:32, Durrant, Paul wrote:
>>>
>>> What's wrong with zeroing the struct on allocation (which is what is 
>>> supposed to happen)?
>>>
>>
>>
>> Struct padding bytes have unspecified values and compilers are free to
>> emit code that overwrite them even if we don't access them directly. So
>> even if a structure was zeroed on initialization, its padding can't be
>> guaranteed to remain zero on teardown.
> 
> Make the padding explicit then... that should avoid the issue without 
> removing the check (which *has* caught leaks in the past).
> 

Doing so is hard since padding is architecture-dependent, and gets 
complex fast once child structures are involved. Some structures like 
INTERFACE (part of DebugInterface/SuspendInterface/etc) have padding 
that we can't simply eliminate or make explicit.

I've tried to check for padding correctness this way:

     #if DBG
     #define CONCAT2(a, b)   a##b
     #define CONCAT(a, b)    CONCAT2(a, b)

     #define PAD(n)          CHAR    CONCAT(_Pad_, __LINE__)[n]

     #define PAD_CHECK(name, T) \
         struct name T; \
         __pragma(pack(push, 1)) \
         struct _PACKED_##name T \
         __pragma(pack(pop)); \
         _STATIC_ASSERT(sizeof(struct name) == \
             sizeof(struct _PACKED_##name))

     #else
     #define PAD(n)
     #define PAD_CHECK(name, T) \
         struct name T;
     #endif

     PAD_CHECK(_XENVIF_FRONTEND, {
         BOOLEAN                     Online;
         PAD(7);
         KSPIN_LOCK                  Lock;
         // ...
     });

It works for trivial cases, but it breaks as soon as we encounter struct 
INTERFACE.
In any case, the padding content of struct INTERFACE is not guaranteed 
and we may run into the same problem with this struct.


--
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.