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

Re: [PATCH v2 4/4] x86/vRTC: support century field


  • To: Roger Pau Monné <roger@xxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 2 Sep 2026 11:20:15 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • 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>, Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Wed, 02 Sep 2026 09:20:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 02.09.2026 10:07, Roger Pau Monné wrote:
> On Thu, Jul 02, 2026 at 11:31:14AM +0200, Jan Beulich wrote:
>> Both ROMBIOS and SeaBIOS (with CONFIG_QEMU=y, as we build it) blindly
>> assume availability of this field (at its conventional index 0x32); OVMF
>> at least has code to inspect FADT. Hence we ought to have supported it
>> virtually forever.
>>
>> As the index is beyond RTC_CMOS_SIZE, leverage the padding field in
>> struct hvm_hw_rtc to hold its value. Update the field only when involved
>> values are valid BCD century specifiers. Otherwise (for VMs migrated in
>> from an older hypervisor) leave handling to the DM.
>>
>> This makes the Linux rtc-cmos driver report y3k compatibility.
>>
>> In the new rtc_check(), besides checking the new fields also check the
>> pre-existing pad0 field.
>>
>> While extending xen-hvmctx.c:dump_rtc() also add RTC offset there.
>>
>> Fixes: 4ca161214355 ("[HVM] Move RTC emulation into the hypervisor")
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> 
> Acked-by: Roger Pau Monné <roger@xxxxxxxxxxxxxx>

Thanks.

>> Now that we extend struct hvm_hw_rtc, should we perhaps save not only the
>> century, but also its index?
> 
> Hm, possibly for correctness, albeit I think this is unlikely to cause
> issues.  Likely better done in a separate patch?

Possibly. Just that then we need to deal with two different cases of
backwards compatibility. (Not that I think that doing so would be overly
difficult, but still.)

>> Likely more sanity checking could be added to rtc_check(), but that's for
>> a separate patch imo.
>>
>> Isn't day-of-week handling flawed? If the field is brought out of sync
>> with the other values, shouldn't it stay respectively out-of-sync?
> 
> I don't know that much about the RTC TBH.
> 
>> And
>> isn't it excessive overhead to go through rtc_set_time() when the field
>> is updated while SET is clear?
> 
> I think this is done because we don't call rtc_set_time() when RTC_SET
> is activated in RTC_REG_B?  We would need to change the logic a bit.

I think you may have overlooked that my question was just for the day-of-
week field. When that field is changed, rtc_set_time() will call mktime(),
update_domain_wallclock_time(), and send_timeoffset_req() despite the
change not having any effect on the values used/calculated there. The only
actual change in that case is to s->current_tm.tm_wday.

> Is there a reason to propagate the changes to the DM even when SET is
> not active?

How does a DM come into play here? It's only accesses to non-time fields
of the CMOS which we forward to the DM.

>> @@ -760,6 +795,32 @@ static int cf_check rtc_save(struct vcpu
>>      return rc;
>>  }
>>  
>> +static int cf_check rtc_check(const struct domain *d, hvm_domain_context_t 
>> *h)
>> +{
>> +    const struct hvm_save_descriptor *desc =
>> +        (const struct hvm_save_descriptor *)&h->data[h->cur];
>> +    struct hvm_hw_rtc s;
>> +
>> +    if ( !has_vrtc(d) )
>> +        return -ENODEV;
>> +
>> +    if ( hvm_load_entry_zeroextend(RTC, h, &s) != 0 )
>> +        return -ENODATA;
>> +
>> +    if ( s.pad0 )
>> +        return -EINVAL;
>> +
>> +    for ( unsigned int i = 0; i < ARRAY_SIZE(s.pad1); ++i )
>> +        if ( s.pad1[i] )
>> +            return -EINVAL;
>> +
>> +    if ( desc->length >= endof_field(struct hvm_hw_rtc, century) &&
>> +         ((s.century & 0xf) >= 10 || (s.century >> 4) >= 10) )
>> +        return -EINVAL;
> 
> It would be nice to also set ->has_century here, but the s struct is
> a temporary stack allocation.

And deliberately so, as .check() hooks shouldn't alter state. (Hence
also why const struct domain * is passed in.)

>> @@ -793,12 +854,18 @@ static int cf_check rtc_load(struct doma
>>      check_update_timer(s);
>>      alarm_timer_update(s);
>>  
>> +    if ( !s->hw.century )
>> +    {
>> +        s->has_century = false;
>> +        s->hw.century = 0;
> 
> Isn't this last line pointless?  The if condition is !s->hw.century,
> and hence s->hw.century must be 0 here?

Oh, yes - insufficient pruning after the v2 adjustments.

Jan



 


Rackspace

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