From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: xen-devel@lists.xenproject.org,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Teddy Astie" <teddy.astie@vates.tech>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: Re: [PATCH 4/5] x86/shadow: split a nested max() invocation
Date: Thu, 14 May 2026 07:08:17 +0200 [thread overview]
Message-ID: <337dd83065dae7555dfecb2163241ead@bugseng.com> (raw)
In-Reply-To: <146d214c-e766-4b3f-bc50-0b9beee50473@suse.com>
On 2026-05-13 13:46, Jan Beulich wrote:
> Such nesting causes the inner instance to shadow the outer instance's
> macro-local variables, thus violating Misra C:2012 rule 5.3 ("An
> identifier declared in an inner scope shall not hide an identifier
> declared in an outer scope"). Use an intermediate variable for the
> inner invocation. No difference in generated code.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> Supposedly this case is deviated (rules.rst). Does that deviation not
> work
> quite right? Actually, am I mis-reading deviations.ecl or is the
> respective setting only covering the combination of min() and max(),
> but
> not multiple use of the same macro? Furthermore, why would e.g.
> min(max_t(), ...) need a deviation? Even more generally, aren't those
> expressions too permissive?
Yeah, it does cover only mixing max(_t)?/min(_t)? because that was the
only pattern that emerged in the safety scope originally. the _t is not
there for mixing e.g. min(max_t(...), ...) but rather for
min_t(max_t(...), ...) and viceversa; could be split if you think it's
worth it. These expressions are a tad broad, because it's way more
complicated to express the condition: "ignore overlapping only beetween
identifiers defined in the expansion of max/min when used together".
Perhaps it could be done, but then if you are already implicitly using
shadowing in those instances maybe that's not as serious a concern?
In any case, the patch looks ok to me, so
Reviewed-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>
> --- a/xen/arch/x86/mm/shadow/common.c
> +++ b/xen/arch/x86/mm/shadow/common.c
> @@ -767,11 +767,12 @@ static unsigned int sh_min_allocation(co
> * megabyte of RAM (for the p2m table, minimally enough for HVM's
> setting
> * up of slot zero and an LAPIC page), plus one for HVM's 1-to-1
> pagetable.
> */
> + unsigned int extra = max(domain_tot_pages(d) / 256,
> + is_hvm_domain(d) ? CONFIG_PAGING_LEVELS +
> 2 : 0U) +
> + is_hvm_domain(d);
> +
> return shadow_min_acceptable_pages(d) +
> - max(max(domain_tot_pages(d) / 256,
> - is_hvm_domain(d) ? CONFIG_PAGING_LEVELS + 2 : 0U) +
> - is_hvm_domain(d),
> - d->arch.paging.p2m_pages);
> + max(extra, d->arch.paging.p2m_pages);
> }
>
> int shadow_set_allocation(struct domain *d, unsigned int pages, bool
> *preempted)
--
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
next prev parent reply other threads:[~2026-05-14 5:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 11:43 [PATCH 0/5] x86: Misra rule 5.3 Jan Beulich
2026-05-13 11:44 ` [PATCH 1/5] x86/guest: rename a local variable Jan Beulich
2026-05-13 21:17 ` Nicola Vetrini
2026-05-15 11:00 ` Andrew Cooper
2026-05-13 11:44 ` [PATCH 2/5] x86/PV: rename a local variable in pv_emulate_gate_op() Jan Beulich
2026-05-13 11:45 ` [PATCH 3/5] x86/shadow: conditionalize / rename local variables Jan Beulich
2026-05-13 11:46 ` [PATCH 4/5] x86/shadow: split a nested max() invocation Jan Beulich
2026-05-14 5:08 ` Nicola Vetrini [this message]
2026-05-15 6:15 ` Jan Beulich
2026-05-13 11:46 ` [PATCH 5/5] x86/shadow: rename a parameter of shadow_l<N>_index() Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=337dd83065dae7555dfecb2163241ead@bugseng.com \
--to=nicola.vetrini@bugseng.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=teddy.astie@vates.tech \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.