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

Re: [PATCH] x86/mm: split struct sh_dirty_vram and make results private


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 3 Feb 2026 08:41:51 +0100
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>
  • Delivery-date: Tue, 03 Feb 2026 07:42:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 02.02.2026 18:35, Roger Pau Monné wrote:
> On Wed, Nov 12, 2025 at 04:47:31PM +0100, Jan Beulich wrote:
>> The types are local to the shadow and HAP subsystems respectively, and
>> HAP has no need for the shadow-specific fields (i.e. it can get away with
>> smaller allocations). In struct hvm_domain it therefore suffices to have
>> a union of two (generally opaque) pointers.
>>
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> 
> Acked-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

Thanks.

>> --- a/xen/arch/x86/include/asm/hvm/domain.h
>> +++ b/xen/arch/x86/include/asm/hvm/domain.h
>> @@ -95,7 +95,10 @@ struct hvm_domain {
>>      struct list_head       pinned_cacheattr_ranges;
>>  
>>      /* VRAM dirty support.  Protect with the domain paging lock. */
>> -    struct sh_dirty_vram *dirty_vram;
>> +    union {
>> +        struct sh_dirty_vram *sh;
>> +        struct hap_dirty_vram *hap;
>> +    }                      dirty_vram;
> 
> Other in-place declared structures don't use this aligning.  I have to
> admit it looks somewhat odd for structs like this one.

As I don't mind much, I've changed it. It's odd either way - either, as you say,
it looks odd, or it's not in line with the other field decls which all align
their names (except for the in-place struct decls).

>> --- a/xen/arch/x86/mm/shadow/hvm.c
>> +++ b/xen/arch/x86/mm/shadow/hvm.c
>> @@ -1033,7 +1033,7 @@ int shadow_track_dirty_vram(struct domai
>>      p2m_lock(p2m_get_hostp2m(d));
>>      paging_lock(d);
>>  
>> -    dirty_vram = d->arch.hvm.dirty_vram;
>> +    dirty_vram = d->arch.hvm.dirty_vram.sh;
>>  
>>      if ( dirty_vram && (!nr_frames ||
>>               ( begin_pfn != dirty_vram->begin_pfn
>> @@ -1043,8 +1043,8 @@ int shadow_track_dirty_vram(struct domai
>>          gdprintk(XENLOG_INFO, "stopping tracking VRAM %lx - %lx\n", 
>> dirty_vram->begin_pfn, dirty_vram->end_pfn);
>>          xfree(dirty_vram->sl1ma);
>>          xfree(dirty_vram->dirty_bitmap);
>> -        xfree(dirty_vram);
>> -        dirty_vram = d->arch.hvm.dirty_vram = NULL;
>> +        XFREE(dirty_vram);
>> +        d->arch.hvm.dirty_vram.sh = NULL;
> 
> It would be better if this was done the other way around, first set
> the reference to NULL, then free the memory?
> 
>         d->arch.hvm.dirty_vram.sh = NULL;
>         XFREE(dirty_vram);

Indeed, changed.

>> @@ -1075,7 +1075,7 @@ int shadow_track_dirty_vram(struct domai
>>              goto out;
>>          dirty_vram->begin_pfn = begin_pfn;
>>          dirty_vram->end_pfn = end_pfn;
>> -        d->arch.hvm.dirty_vram = dirty_vram;
>> +        d->arch.hvm.dirty_vram.sh = dirty_vram;
>>  
>>          if ( (dirty_vram->sl1ma = xmalloc_array(paddr_t, nr_frames)) == 
>> NULL )
>>              goto out_dirty_vram;
>> @@ -1202,8 +1202,8 @@ int shadow_track_dirty_vram(struct domai
>>   out_sl1ma:
>>      xfree(dirty_vram->sl1ma);
>>   out_dirty_vram:
>> -    xfree(dirty_vram);
>> -    dirty_vram = d->arch.hvm.dirty_vram = NULL;
>> +    XFREE(dirty_vram);
>> +    d->arch.hvm.dirty_vram.sh = NULL;
> 
> Similar here, I would change the order.

Changed as well. I can't tell why I didn't do it this way right away.

Jan



 


Rackspace

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