On 12.01.2026 11:19, Oleksii Kurochko wrote:
> On 1/6/26 4:56 PM, Jan Beulich wrote:
>> (some or even all of the comments may also apply to present Arm code)
>>
>> On 24.12.2025 18:03, Oleksii Kurochko wrote:
>>> + v->arch.cpu_info = (struct cpu_info *)(v->arch.stack
>>> + + STACK_SIZE
>>> + - sizeof(struct cpu_info));
>> Why the cast?
>
> Just for readability, from compiler point of view it could be just dropped.
Sorry, for me readability suffers from the cast and the then necessary
parentheses. Plus I've been keeping to tell you that casts can be dangerous,
and hence they would better only ever be used when really unavoidable.
>>> --- a/xen/arch/riscv/include/asm/current.h
>>> +++ b/xen/arch/riscv/include/asm/current.h
>>> @@ -21,6 +21,12 @@ struct pcpu_info {
>>> /* tp points to one of these */
>>> extern struct pcpu_info pcpu_info[NR_CPUS];
>>>
>>> +/* Per-VCPU state that lives at the top of the stack */
>>> +struct cpu_info {
>>> + /* This should be the first member. */
>>> + struct cpu_user_regs guest_cpu_user_regs;
>>> +};
>> You may want to enforce what the comment says by way of a BUILD_BUG_ON().
>
> Makes sense, I will add:
> BUILD_BUG_ON(offsetof(struct cpu_info, guest_cpu_user_regs) != 0);
> in|arch_vcpu_create()|, somewhere around the initialization
> of|v->arch.cpu_info = ... . |I noticed that there is no|BUILD_BUG_ON()|
> variant that can be used outside
> of a function, or does such a variant exist and I’m just missing it? Or there
> is no such sense at all for such variant?
There's none, correct. hence why in a few places we have build_assertions()
functions.
Jan