* [Xen-devel] [PATCH 0/2] xen/x86: hap: Small clean-up/hardening in hap_enable()
@ 2020-02-04 9:34 Julien Grall
2020-02-04 9:34 ` [Xen-devel] [PATCH 1/2] xen/x86: hap: Fix coding style " Julien Grall
2020-02-04 9:34 ` [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable() Julien Grall
0 siblings, 2 replies; 11+ messages in thread
From: Julien Grall @ 2020-02-04 9:34 UTC (permalink / raw)
To: xen-devel
Cc: Wei Liu, George Dunlap, Andrew Cooper, Julien Grall, Jan Beulich,
Roger Pau Monné
From: Julien Grall <jgrall@amazon.com>
Hi all,
This series contain a couple of clean-up/hardening for the function
hap_enable().
Cheers,
Julien Grall (2):
xen/x86: hap: Fix coding style in hap_enable()
xen/x86: hap: Clean-up and harden hap_enable()
xen/arch/x86/mm/hap/hap.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
--
2.17.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Xen-devel] [PATCH 1/2] xen/x86: hap: Fix coding style in hap_enable()
2020-02-04 9:34 [Xen-devel] [PATCH 0/2] xen/x86: hap: Small clean-up/hardening in hap_enable() Julien Grall
@ 2020-02-04 9:34 ` Julien Grall
2020-02-04 10:07 ` Roger Pau Monné
2020-02-04 9:34 ` [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable() Julien Grall
1 sibling, 1 reply; 11+ messages in thread
From: Julien Grall @ 2020-02-04 9:34 UTC (permalink / raw)
To: xen-devel
Cc: Wei Liu, George Dunlap, Andrew Cooper, Julien Grall, Jan Beulich,
Roger Pau Monné
From: Julien Grall <jgrall@amazon.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
---
xen/arch/x86/mm/hap/hap.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
index 3d93f3451c..31362a31b6 100644
--- a/xen/arch/x86/mm/hap/hap.c
+++ b/xen/arch/x86/mm/hap/hap.c
@@ -473,7 +473,8 @@ int hap_enable(struct domain *d, u32 mode)
goto out;
}
- for (i = 0; i < MAX_NESTEDP2M; i++) {
+ for ( i = 0; i < MAX_NESTEDP2M; i++ )
+ {
rv = p2m_alloc_table(d->arch.nested_p2m[i]);
if ( rv != 0 )
goto out;
--
2.17.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable()
2020-02-04 9:34 [Xen-devel] [PATCH 0/2] xen/x86: hap: Small clean-up/hardening in hap_enable() Julien Grall
2020-02-04 9:34 ` [Xen-devel] [PATCH 1/2] xen/x86: hap: Fix coding style " Julien Grall
@ 2020-02-04 9:34 ` Julien Grall
2020-02-04 10:51 ` Roger Pau Monné
1 sibling, 1 reply; 11+ messages in thread
From: Julien Grall @ 2020-02-04 9:34 UTC (permalink / raw)
To: xen-devel
Cc: Wei Liu, George Dunlap, Andrew Cooper, Julien Grall, Jan Beulich,
Roger Pau Monné
From: Julien Grall <jgrall@amazon.com>
Unlike shadow_enable(), hap_enable() can only be called once during
domain creation and with the mode equal to mode equal to
PG_external | PG_translate | PG_refcounts.
If it were called twice, then we might have something interesting
problem as the p2m tables would be re-allocated (and therefore all the
mappings would be lost).
Add code to sanity check the mode and that the function is only called
once. Take the opportunity to an if checking that PG_translate is set.
Signed-off-by: Julien Grall <jgrall@amazon.com>
---
It is not entirely clear when PG_translate was enforced.
---
xen/arch/x86/mm/hap/hap.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
index 31362a31b6..b734e2e6d3 100644
--- a/xen/arch/x86/mm/hap/hap.c
+++ b/xen/arch/x86/mm/hap/hap.c
@@ -445,6 +445,13 @@ int hap_enable(struct domain *d, u32 mode)
unsigned int i;
int rv = 0;
+ if ( mode != (PG_external | PG_translate | PG_refcounts) )
+ return -EINVAL;
+
+ /* The function can only be called once */
+ if ( d->arch.paging.mode != 0 )
+ return -EINVAL;
+
domain_pause(d);
old_pages = d->arch.paging.hap.total_pages;
@@ -465,13 +472,10 @@ int hap_enable(struct domain *d, u32 mode)
d->arch.paging.alloc_page = hap_alloc_p2m_page;
d->arch.paging.free_page = hap_free_p2m_page;
- /* allocate P2m table */
- if ( mode & PG_translate )
- {
- rv = p2m_alloc_table(p2m_get_hostp2m(d));
- if ( rv != 0 )
- goto out;
- }
+ /* allocate P2M table */
+ rv = p2m_alloc_table(p2m_get_hostp2m(d));
+ if ( rv != 0 )
+ goto out;
for ( i = 0; i < MAX_NESTEDP2M; i++ )
{
--
2.17.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [Xen-devel] [PATCH 1/2] xen/x86: hap: Fix coding style in hap_enable()
2020-02-04 9:34 ` [Xen-devel] [PATCH 1/2] xen/x86: hap: Fix coding style " Julien Grall
@ 2020-02-04 10:07 ` Roger Pau Monné
0 siblings, 0 replies; 11+ messages in thread
From: Roger Pau Monné @ 2020-02-04 10:07 UTC (permalink / raw)
To: Julien Grall
Cc: Wei Liu, George Dunlap, Andrew Cooper, Julien Grall, Jan Beulich,
xen-devel
On Tue, Feb 04, 2020 at 09:34:10AM +0000, Julien Grall wrote:
> From: Julien Grall <jgrall@amazon.com>
>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable()
2020-02-04 9:34 ` [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable() Julien Grall
@ 2020-02-04 10:51 ` Roger Pau Monné
2020-02-04 11:11 ` Julien Grall
0 siblings, 1 reply; 11+ messages in thread
From: Roger Pau Monné @ 2020-02-04 10:51 UTC (permalink / raw)
To: Julien Grall
Cc: Wei Liu, George Dunlap, Andrew Cooper, Julien Grall, Jan Beulich,
xen-devel
On Tue, Feb 04, 2020 at 09:34:11AM +0000, Julien Grall wrote:
> From: Julien Grall <jgrall@amazon.com>
>
> Unlike shadow_enable(), hap_enable() can only be called once during
> domain creation and with the mode equal to mode equal to
^ equals to
> PG_external | PG_translate | PG_refcounts.
>
> If it were called twice, then we might have something interesting
^ a problem
> problem as the p2m tables would be re-allocated (and therefore all the
> mappings would be lost).
>
> Add code to sanity check the mode and that the function is only called
> once. Take the opportunity to an if checking that PG_translate is set.
^ add an if
>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
>
> ---
>
> It is not entirely clear when PG_translate was enforced.
> ---
> xen/arch/x86/mm/hap/hap.c | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
> index 31362a31b6..b734e2e6d3 100644
> --- a/xen/arch/x86/mm/hap/hap.c
> +++ b/xen/arch/x86/mm/hap/hap.c
> @@ -445,6 +445,13 @@ int hap_enable(struct domain *d, u32 mode)
> unsigned int i;
> int rv = 0;
>
> + if ( mode != (PG_external | PG_translate | PG_refcounts) )
> + return -EINVAL;
> +
> + /* The function can only be called once */
> + if ( d->arch.paging.mode != 0 )
> + return -EINVAL;
If you want to return EINVAL for both they can be merged into a single
if. Also note that this would usually be written as
if ( d->arch.paging.mode ) to keep it shorter.
Albeit I think you might want to return EEXIST instead of EINVAL if
mode is already set.
> +
> domain_pause(d);
>
> old_pages = d->arch.paging.hap.total_pages;
> @@ -465,13 +472,10 @@ int hap_enable(struct domain *d, u32 mode)
> d->arch.paging.alloc_page = hap_alloc_p2m_page;
> d->arch.paging.free_page = hap_free_p2m_page;
>
> - /* allocate P2m table */
> - if ( mode & PG_translate )
> - {
> - rv = p2m_alloc_table(p2m_get_hostp2m(d));
> - if ( rv != 0 )
> - goto out;
> - }
> + /* allocate P2M table */
> + rv = p2m_alloc_table(p2m_get_hostp2m(d));
> + if ( rv != 0 )
I would also avoid comparing against 0 here.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable()
2020-02-04 10:51 ` Roger Pau Monné
@ 2020-02-04 11:11 ` Julien Grall
2020-02-04 11:28 ` Roger Pau Monné
0 siblings, 1 reply; 11+ messages in thread
From: Julien Grall @ 2020-02-04 11:11 UTC (permalink / raw)
To: Roger Pau Monné
Cc: Wei Liu, George Dunlap, Andrew Cooper, Julien Grall, Jan Beulich,
xen-devel
On 04/02/2020 10:51, Roger Pau Monné wrote:
> On Tue, Feb 04, 2020 at 09:34:11AM +0000, Julien Grall wrote:
>> From: Julien Grall <jgrall@amazon.com>
>>
>> Unlike shadow_enable(), hap_enable() can only be called once during
>> domain creation and with the mode equal to mode equal to
> ^ equals to
Will fix it.
>> PG_external | PG_translate | PG_refcounts.
>>
>> If it were called twice, then we might have something interesting
> ^ a problem
>> problem as the p2m tables would be re-allocated (and therefore all the
>> mappings would be lost).
>>
>> Add code to sanity check the mode and that the function is only called
>> once. Take the opportunity to an if checking that PG_translate is set.
> ^ add an if
Will fix it.
>>
>> Signed-off-by: Julien Grall <jgrall@amazon.com>
>>
>> ---
>>
>> It is not entirely clear when PG_translate was enforced.
>> ---
>> xen/arch/x86/mm/hap/hap.c | 18 +++++++++++-------
>> 1 file changed, 11 insertions(+), 7 deletions(-)
>>
>> diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
>> index 31362a31b6..b734e2e6d3 100644
>> --- a/xen/arch/x86/mm/hap/hap.c
>> +++ b/xen/arch/x86/mm/hap/hap.c
>> @@ -445,6 +445,13 @@ int hap_enable(struct domain *d, u32 mode)
>> unsigned int i;
>> int rv = 0;
>>
>> + if ( mode != (PG_external | PG_translate | PG_refcounts) )
>> + return -EINVAL;
>> +
>> + /* The function can only be called once */
>> + if ( d->arch.paging.mode != 0 )
>> + return -EINVAL;
>
> If you want to return EINVAL for both they can be merged into a single
> if. Also note that this would usually be written as
> if ( d->arch.paging.mode ) to keep it shorter.
To be honest, this is a matter of taste. There is also an argument that
for MISRA, your suggestion is not compliant (see Rule 14.4).
>
> Albeit I think you might want to return EEXIST instead of EINVAL if
> mode is already set.
I am happy with that.
>
>> +
>> domain_pause(d);
>>
>> old_pages = d->arch.paging.hap.total_pages;
>> @@ -465,13 +472,10 @@ int hap_enable(struct domain *d, u32 mode)
>> d->arch.paging.alloc_page = hap_alloc_p2m_page;
>> d->arch.paging.free_page = hap_free_p2m_page;
>>
>> - /* allocate P2m table */
>> - if ( mode & PG_translate )
>> - {
>> - rv = p2m_alloc_table(p2m_get_hostp2m(d));
>> - if ( rv != 0 )
>> - goto out;
>> - }
>> + /* allocate P2M table */
>> + rv = p2m_alloc_table(p2m_get_hostp2m(d));
>> + if ( rv != 0 )
>
> I would also avoid comparing against 0 here.
See above.
Cheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable()
2020-02-04 11:11 ` Julien Grall
@ 2020-02-04 11:28 ` Roger Pau Monné
2020-02-04 11:33 ` George Dunlap
2020-02-04 11:44 ` Julien Grall
0 siblings, 2 replies; 11+ messages in thread
From: Roger Pau Monné @ 2020-02-04 11:28 UTC (permalink / raw)
To: Julien Grall
Cc: Wei Liu, George Dunlap, Andrew Cooper, Julien Grall, Jan Beulich,
xen-devel
On Tue, Feb 04, 2020 at 11:11:11AM +0000, Julien Grall wrote:
>
>
> On 04/02/2020 10:51, Roger Pau Monné wrote:
> > On Tue, Feb 04, 2020 at 09:34:11AM +0000, Julien Grall wrote:
> > > From: Julien Grall <jgrall@amazon.com>
> > >
> > > Unlike shadow_enable(), hap_enable() can only be called once during
> > > domain creation and with the mode equal to mode equal to
> > ^ equals to
>
> Will fix it.
>
> > > PG_external | PG_translate | PG_refcounts.
> > >
> > > If it were called twice, then we might have something interesting
> > ^ a problem
> > > problem as the p2m tables would be re-allocated (and therefore all the
> > > mappings would be lost).
> > >
> > > Add code to sanity check the mode and that the function is only called
> > > once. Take the opportunity to an if checking that PG_translate is set.
> > ^ add an if
>
> Will fix it.
>
> > >
> > > Signed-off-by: Julien Grall <jgrall@amazon.com>
> > >
> > > ---
> > >
> > > It is not entirely clear when PG_translate was enforced.
> > > ---
> > > xen/arch/x86/mm/hap/hap.c | 18 +++++++++++-------
> > > 1 file changed, 11 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
> > > index 31362a31b6..b734e2e6d3 100644
> > > --- a/xen/arch/x86/mm/hap/hap.c
> > > +++ b/xen/arch/x86/mm/hap/hap.c
> > > @@ -445,6 +445,13 @@ int hap_enable(struct domain *d, u32 mode)
> > > unsigned int i;
> > > int rv = 0;
> > > + if ( mode != (PG_external | PG_translate | PG_refcounts) )
> > > + return -EINVAL;
> > > +
> > > + /* The function can only be called once */
> > > + if ( d->arch.paging.mode != 0 )
> > > + return -EINVAL;
> >
> > If you want to return EINVAL for both they can be merged into a single
> > if. Also note that this would usually be written as
> > if ( d->arch.paging.mode ) to keep it shorter.
>
> To be honest, this is a matter of taste. There is also an argument that for
> MISRA, your suggestion is not compliant (see Rule 14.4).
Oh, then we should add those rules to CODING_STYLE if they are to be
enforced.
So far the style of most of the hypervisor code is to omit the value
when comparing against 0 or NULL AFAIK.
I don't have an issue with requiring explicit comparisons, but it
needs to be documented so we can aim to have an homogeneous style,
because so far I've been recommending the other way around.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable()
2020-02-04 11:28 ` Roger Pau Monné
@ 2020-02-04 11:33 ` George Dunlap
2020-02-04 11:44 ` Julien Grall
1 sibling, 0 replies; 11+ messages in thread
From: George Dunlap @ 2020-02-04 11:33 UTC (permalink / raw)
To: Roger Pau Monné, Julien Grall
Cc: Wei Liu, George Dunlap, Andrew Cooper, Julien Grall, Jan Beulich,
xen-devel
On 2/4/20 11:28 AM, Roger Pau Monné wrote:
> On Tue, Feb 04, 2020 at 11:11:11AM +0000, Julien Grall wrote:
>>
>>
>> On 04/02/2020 10:51, Roger Pau Monné wrote:
>>> On Tue, Feb 04, 2020 at 09:34:11AM +0000, Julien Grall wrote:
>>>> From: Julien Grall <jgrall@amazon.com>
>>>>
>>>> Unlike shadow_enable(), hap_enable() can only be called once during
>>>> domain creation and with the mode equal to mode equal to
>>> ^ equals to
>>
>> Will fix it.
>>
>>>> PG_external | PG_translate | PG_refcounts.
>>>>
>>>> If it were called twice, then we might have something interesting
>>> ^ a problem
>>>> problem as the p2m tables would be re-allocated (and therefore all the
>>>> mappings would be lost).
>>>>
>>>> Add code to sanity check the mode and that the function is only called
>>>> once. Take the opportunity to an if checking that PG_translate is set.
>>> ^ add an if
>>
>> Will fix it.
>>
>>>>
>>>> Signed-off-by: Julien Grall <jgrall@amazon.com>
>>>>
>>>> ---
>>>>
>>>> It is not entirely clear when PG_translate was enforced.
>>>> ---
>>>> xen/arch/x86/mm/hap/hap.c | 18 +++++++++++-------
>>>> 1 file changed, 11 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
>>>> index 31362a31b6..b734e2e6d3 100644
>>>> --- a/xen/arch/x86/mm/hap/hap.c
>>>> +++ b/xen/arch/x86/mm/hap/hap.c
>>>> @@ -445,6 +445,13 @@ int hap_enable(struct domain *d, u32 mode)
>>>> unsigned int i;
>>>> int rv = 0;
>>>> + if ( mode != (PG_external | PG_translate | PG_refcounts) )
>>>> + return -EINVAL;
>>>> +
>>>> + /* The function can only be called once */
>>>> + if ( d->arch.paging.mode != 0 )
>>>> + return -EINVAL;
>>>
>>> If you want to return EINVAL for both they can be merged into a single
>>> if. Also note that this would usually be written as
>>> if ( d->arch.paging.mode ) to keep it shorter.
>>
>> To be honest, this is a matter of taste. There is also an argument that for
>> MISRA, your suggestion is not compliant (see Rule 14.4).
>
> Oh, then we should add those rules to CODING_STYLE if they are to be
> enforced.
>
> So far the style of most of the hypervisor code is to omit the value
> when comparing against 0 or NULL AFAIK.
>
> I don't have an issue with requiring explicit comparisons, but it
> needs to be documented so we can aim to have an homogeneous style,
> because so far I've been recommending the other way around.
Indeed, the general preference of the codebase as a whole is to favor
conciseness in this case; there's value in being consistent.
I don't want to be annoying about this. I don't agree with the MISRA
rule here; but I do think that MISRA is important. OTOH this is in x86
code, which I don't think anyone has suggested become MISRA compliant.
And if we're going to start making these sorts of changes, I agree that
we should have a discussion about it, rather than implicitly do things
sometimes one way and sometimes another.
-George
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable()
2020-02-04 11:28 ` Roger Pau Monné
2020-02-04 11:33 ` George Dunlap
@ 2020-02-04 11:44 ` Julien Grall
2020-02-04 12:36 ` Jan Beulich
1 sibling, 1 reply; 11+ messages in thread
From: Julien Grall @ 2020-02-04 11:44 UTC (permalink / raw)
To: Roger Pau Monné, Julien Grall
Cc: George Dunlap, xen-devel, Wei Liu, Jan Beulich, Andrew Cooper
On 04/02/2020 11:28, Roger Pau Monné wrote:
> On Tue, Feb 04, 2020 at 11:11:11AM +0000, Julien Grall wrote:
>>
>>
>> On 04/02/2020 10:51, Roger Pau Monné wrote:
>>> On Tue, Feb 04, 2020 at 09:34:11AM +0000, Julien Grall wrote:
>>>> From: Julien Grall <jgrall@amazon.com>
>>>>
>>>> Unlike shadow_enable(), hap_enable() can only be called once during
>>>> domain creation and with the mode equal to mode equal to
>>> ^ equals to
>>
>> Will fix it.
>>
>>>> PG_external | PG_translate | PG_refcounts.
>>>>
>>>> If it were called twice, then we might have something interesting
>>> ^ a problem
>>>> problem as the p2m tables would be re-allocated (and therefore all the
>>>> mappings would be lost).
>>>>
>>>> Add code to sanity check the mode and that the function is only called
>>>> once. Take the opportunity to an if checking that PG_translate is set.
>>> ^ add an if
>>
>> Will fix it.
>>
>>>>
>>>> Signed-off-by: Julien Grall <jgrall@amazon.com>
>>>>
>>>> ---
>>>>
>>>> It is not entirely clear when PG_translate was enforced.
>>>> ---
>>>> xen/arch/x86/mm/hap/hap.c | 18 +++++++++++-------
>>>> 1 file changed, 11 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
>>>> index 31362a31b6..b734e2e6d3 100644
>>>> --- a/xen/arch/x86/mm/hap/hap.c
>>>> +++ b/xen/arch/x86/mm/hap/hap.c
>>>> @@ -445,6 +445,13 @@ int hap_enable(struct domain *d, u32 mode)
>>>> unsigned int i;
>>>> int rv = 0;
>>>> + if ( mode != (PG_external | PG_translate | PG_refcounts) )
>>>> + return -EINVAL;
>>>> +
>>>> + /* The function can only be called once */
>>>> + if ( d->arch.paging.mode != 0 )
>>>> + return -EINVAL;
>>>
>>> If you want to return EINVAL for both they can be merged into a single
>>> if. Also note that this would usually be written as
>>> if ( d->arch.paging.mode ) to keep it shorter.
>>
>> To be honest, this is a matter of taste. There is also an argument that for
>> MISRA, your suggestion is not compliant (see Rule 14.4).
>
> Oh, then we should add those rules to CODING_STYLE if they are to be
> enforced.
I am not looking to enforce anything at the moment. My main point here
is this is pretty much as matter of taste. But there might be concern
with your suggestion if go forward with MISRA (this is not the only one
though ;)).
>
> So far the style of most of the hypervisor code is to omit the value
> when comparing against 0 or NULL AFAIK.
>
> I don't have an issue with requiring explicit comparisons, but it
> needs to be documented so we can aim to have an homogeneous style,
> because so far I've been recommending the other way around.
Aside the MISRA, there are some cases where I feel the explicit
comparisons make sense. But I don't have any rational for them and view
this as a matter of taste. So I would leave it to the author of the
patch the choice.
Cheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable()
2020-02-04 11:44 ` Julien Grall
@ 2020-02-04 12:36 ` Jan Beulich
2020-02-04 12:51 ` Julien Grall
0 siblings, 1 reply; 11+ messages in thread
From: Jan Beulich @ 2020-02-04 12:36 UTC (permalink / raw)
To: Julien Grall
Cc: Julien Grall, Wei Liu, George Dunlap, Andrew Cooper, xen-devel,
Roger Pau Monné
On 04.02.2020 12:44, Julien Grall wrote:
> Aside the MISRA, there are some cases where I feel the explicit
> comparisons make sense. But I don't have any rational for them and view
> this as a matter of taste. So I would leave it to the author of the
> patch the choice.
FWIW, I disagree on this aspect. Consistency of the code base
is, I think, more important an aspect. Yes, we likely never
won't reach a fully consistent state, as goals shift, but
anyway.
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable()
2020-02-04 12:36 ` Jan Beulich
@ 2020-02-04 12:51 ` Julien Grall
0 siblings, 0 replies; 11+ messages in thread
From: Julien Grall @ 2020-02-04 12:51 UTC (permalink / raw)
To: Jan Beulich
Cc: Julien Grall, Wei Liu, George Dunlap, Andrew Cooper, xen-devel,
Roger Pau Monné
On 04/02/2020 12:36, Jan Beulich wrote:
> On 04.02.2020 12:44, Julien Grall wrote:
>> Aside the MISRA, there are some cases where I feel the explicit
>> comparisons make sense. But I don't have any rational for them and view
>> this as a matter of taste. So I would leave it to the author of the
>> patch the choice.
>
> FWIW, I disagree on this aspect. Consistency of the code base
> is, I think, more important an aspect. Yes, we likely never
> won't reach a fully consistent state, as goals shift, but
> anyway.
The meaning of consistency is quite broad. What you view as consistent
may not be for me (and vice versa). So we are down to the "matter of
taste" territory.
We could suggest to be consistent with the code surrounding, but I think
you will not be happy with it as some code does not suit the coding
style (see the recent discussion about using __).
Cheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2020-02-04 12:51 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-04 9:34 [Xen-devel] [PATCH 0/2] xen/x86: hap: Small clean-up/hardening in hap_enable() Julien Grall
2020-02-04 9:34 ` [Xen-devel] [PATCH 1/2] xen/x86: hap: Fix coding style " Julien Grall
2020-02-04 10:07 ` Roger Pau Monné
2020-02-04 9:34 ` [Xen-devel] [PATCH 2/2] xen/x86: hap: Clean-up and harden hap_enable() Julien Grall
2020-02-04 10:51 ` Roger Pau Monné
2020-02-04 11:11 ` Julien Grall
2020-02-04 11:28 ` Roger Pau Monné
2020-02-04 11:33 ` George Dunlap
2020-02-04 11:44 ` Julien Grall
2020-02-04 12:36 ` Jan Beulich
2020-02-04 12:51 ` Julien Grall
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.