All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] gnttab: hypervisor side XSA-448 follow-up
@ 2024-02-05 11:02 Jan Beulich
  2024-02-05 11:03 ` [PATCH 1/2] gnttab: fully ignore zero-size copy requests Jan Beulich
  2024-02-05 11:03 ` [PATCH 2/2] almost fully ignore zero-size flush requests Jan Beulich
  0 siblings, 2 replies; 13+ messages in thread
From: Jan Beulich @ 2024-02-05 11:02 UTC (permalink / raw)
  To: xen-devel
  Cc: Andrew Cooper, George Dunlap, Julien Grall, Stefano Stabellini, Wei Liu

Let's try to better deal with effectively no-op requests.

1: fully ignore zero-size copy requests
2: almost fully ignore zero-size flush requests

Jan


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/2] gnttab: fully ignore zero-size copy requests
  2024-02-05 11:02 [PATCH 0/2] gnttab: hypervisor side XSA-448 follow-up Jan Beulich
@ 2024-02-05 11:03 ` Jan Beulich
  2024-02-19 21:50   ` Julien Grall
  2024-02-05 11:03 ` [PATCH 2/2] almost fully ignore zero-size flush requests Jan Beulich
  1 sibling, 1 reply; 13+ messages in thread
From: Jan Beulich @ 2024-02-05 11:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Andrew Cooper, George Dunlap, Julien Grall, Stefano Stabellini, Wei Liu

Along the line with observations in the context of XSA-448, no field in
struct gnttab_copy_ptr is relevant when no data is to be copied, much
like e.g. the pointers passed to memcpy() are irrelevant (and would
never be "validated") when the passed length is zero.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -3061,6 +3061,9 @@ static int gnttab_copy_one(const struct
 {
     int rc;
 
+    if ( unlikely(!op->len) )
+        return GNTST_okay;
+
     if ( !src->domain || op->source.domid != src->ptr.domid ||
          !dest->domain || op->dest.domid != dest->ptr.domid )
     {



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-05 11:02 [PATCH 0/2] gnttab: hypervisor side XSA-448 follow-up Jan Beulich
  2024-02-05 11:03 ` [PATCH 1/2] gnttab: fully ignore zero-size copy requests Jan Beulich
@ 2024-02-05 11:03 ` Jan Beulich
  2024-02-19 22:22   ` Julien Grall
  1 sibling, 1 reply; 13+ messages in thread
From: Jan Beulich @ 2024-02-05 11:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Andrew Cooper, George Dunlap, Julien Grall, Stefano Stabellini, Wei Liu

Along the line with observations in the context of XSA-448, besides
"op" no field is relevant when the range to be flushed is empty, much
like e.g. the pointers passed to memcpy() are irrelevant (and would
never be "validated") when the passed length is zero. Split the existing
condition validating "op", "offset", and "length", leaving only the "op"
part ahead of the check for length being zero (or no flushing to be
performed).

In the course of splitting also simplify the moved part of the condition
from 3 to 2 conditionals, potentially (depending on the architecture)
requiring one less (conditional) branch.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -3528,15 +3528,16 @@ static int _cache_flush(const gnttab_cac
     void *v;
     int ret;
 
-    if ( (cflush->offset >= PAGE_SIZE) ||
-         (cflush->length > PAGE_SIZE) ||
-         (cflush->offset + cflush->length > PAGE_SIZE) ||
-         (cflush->op & ~(GNTTAB_CACHE_INVAL | GNTTAB_CACHE_CLEAN)) )
+    if ( cflush->op & ~(GNTTAB_CACHE_INVAL | GNTTAB_CACHE_CLEAN) )
         return -EINVAL;
 
     if ( cflush->length == 0 || cflush->op == 0 )
         return !*cur_ref ? 0 : -EILSEQ;
 
+    if ( (cflush->offset | cflush->length) > PAGE_SIZE ||
+         cflush->offset + cflush->length > PAGE_SIZE )
+        return -EINVAL;
+
     /* currently unimplemented */
     if ( cflush->op & GNTTAB_CACHE_SOURCE_GREF )
         return -EOPNOTSUPP;



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] gnttab: fully ignore zero-size copy requests
  2024-02-05 11:03 ` [PATCH 1/2] gnttab: fully ignore zero-size copy requests Jan Beulich
@ 2024-02-19 21:50   ` Julien Grall
  0 siblings, 0 replies; 13+ messages in thread
From: Julien Grall @ 2024-02-19 21:50 UTC (permalink / raw)
  To: Jan Beulich, xen-devel
  Cc: Andrew Cooper, George Dunlap, Stefano Stabellini, Wei Liu

Hi Jan,

On 05/02/2024 11:03, Jan Beulich wrote:
> Along the line with observations in the context of XSA-448, no field in
> struct gnttab_copy_ptr is relevant when no data is to be copied, much
> like e.g. the pointers passed to memcpy() are irrelevant (and would
> never be "validated") when the passed length is zero.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Julien Grall <jgrall@amazon.com>

Cheers,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-05 11:03 ` [PATCH 2/2] almost fully ignore zero-size flush requests Jan Beulich
@ 2024-02-19 22:22   ` Julien Grall
  2024-02-20  8:26     ` Jan Beulich
  0 siblings, 1 reply; 13+ messages in thread
From: Julien Grall @ 2024-02-19 22:22 UTC (permalink / raw)
  To: Jan Beulich, xen-devel
  Cc: Andrew Cooper, George Dunlap, Stefano Stabellini, Wei Liu

Hi Jan,

Title: I would add 'gnttab:' to clarify which subsystem you are modifying.

On 05/02/2024 11:03, Jan Beulich wrote:
> Along the line with observations in the context of XSA-448, besides
> "op" no field is relevant when the range to be flushed is empty, much
> like e.g. the pointers passed to memcpy() are irrelevant (and would
> never be "validated") when the passed length is zero. Split the existing
> condition validating "op", "offset", and "length", leaving only the "op"
> part ahead of the check for length being zero (or no flushing to be
> performed).

I am probably missing something here. I understand the theory behind 
reducing the number of checks when len == 0. But an OS cannot rely on it:
   1) older hypervisor would still return an error if the check doesn't 
pass)
   2) it does feel odd to allow "invalid" offset when len == 0 (at least.

So to me, it is better to keep those checks early. That said, I agree 
this is a matter of opinion, so I will not Nack it but also I will not 
Ack it.

> 
> In the course of splitting also simplify the moved part of the condition
> from 3 to 2 conditionals, potentially (depending on the architecture)
> requiring one less (conditional) branch.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> --- a/xen/common/grant_table.c
> +++ b/xen/common/grant_table.c
> @@ -3528,15 +3528,16 @@ static int _cache_flush(const gnttab_cac
>       void *v;
>       int ret;
>   
> -    if ( (cflush->offset >= PAGE_SIZE) ||
> -         (cflush->length > PAGE_SIZE) ||
> -         (cflush->offset + cflush->length > PAGE_SIZE) ||
> -         (cflush->op & ~(GNTTAB_CACHE_INVAL | GNTTAB_CACHE_CLEAN)) )
> +    if ( cflush->op & ~(GNTTAB_CACHE_INVAL | GNTTAB_CACHE_CLEAN) )
>           return -EINVAL;
>   
>       if ( cflush->length == 0 || cflush->op == 0 )
>           return !*cur_ref ? 0 : -EILSEQ;
>   
> +    if ( (cflush->offset | cflush->length) > PAGE_SIZE ||

This is confusing. I understand you are trying to force the compiler to 
optimize. But is it really worth it? After all, the rest of operation 
will outweight this check (cache flush are quite expensive).

We probably should take a more generic decision (and encode in our 
policy) because you seem to like this pattern and I dislike it :). Not 
sure what the others think.

Cheers,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-19 22:22   ` Julien Grall
@ 2024-02-20  8:26     ` Jan Beulich
  2024-02-20 11:52       ` Julien Grall
  2024-02-21  2:32       ` George Dunlap
  0 siblings, 2 replies; 13+ messages in thread
From: Jan Beulich @ 2024-02-20  8:26 UTC (permalink / raw)
  To: Julien Grall
  Cc: Andrew Cooper, George Dunlap, Stefano Stabellini, Wei Liu, xen-devel

On 19.02.2024 23:22, Julien Grall wrote:
> Title: I would add 'gnttab:' to clarify which subsystem you are modifying.

That's how I actually have it here; it's not clear to me why I lost the
prefix when sending.

> On 05/02/2024 11:03, Jan Beulich wrote:
>> Along the line with observations in the context of XSA-448, besides
>> "op" no field is relevant when the range to be flushed is empty, much
>> like e.g. the pointers passed to memcpy() are irrelevant (and would
>> never be "validated") when the passed length is zero. Split the existing
>> condition validating "op", "offset", and "length", leaving only the "op"
>> part ahead of the check for length being zero (or no flushing to be
>> performed).
> 
> I am probably missing something here. I understand the theory behind 
> reducing the number of checks when len == 0. But an OS cannot rely on it:
>    1) older hypervisor would still return an error if the check doesn't 
> pass)

Right, but that's no reason to keep the bogus earlier behavior.

>    2) it does feel odd to allow "invalid" offset when len == 0 (at least.

I'm puzzled: You've given R-b for patch 1 (thanks), where exactly the
same reasoning is used, i.e. similarly referring to memcpy() to
justify the (new / supposed) behavior.

>> In the course of splitting also simplify the moved part of the condition
>> from 3 to 2 conditionals, potentially (depending on the architecture)
>> requiring one less (conditional) branch.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>
>> --- a/xen/common/grant_table.c
>> +++ b/xen/common/grant_table.c
>> @@ -3528,15 +3528,16 @@ static int _cache_flush(const gnttab_cac
>>       void *v;
>>       int ret;
>>   
>> -    if ( (cflush->offset >= PAGE_SIZE) ||
>> -         (cflush->length > PAGE_SIZE) ||
>> -         (cflush->offset + cflush->length > PAGE_SIZE) ||
>> -         (cflush->op & ~(GNTTAB_CACHE_INVAL | GNTTAB_CACHE_CLEAN)) )
>> +    if ( cflush->op & ~(GNTTAB_CACHE_INVAL | GNTTAB_CACHE_CLEAN) )
>>           return -EINVAL;
>>   
>>       if ( cflush->length == 0 || cflush->op == 0 )
>>           return !*cur_ref ? 0 : -EILSEQ;
>>   
>> +    if ( (cflush->offset | cflush->length) > PAGE_SIZE ||
> 
> This is confusing. I understand you are trying to force the compiler to 
> optimize. But is it really worth it? After all, the rest of operation 
> will outweight this check (cache flush are quite expensive).

From purely a performance point of view it may not be worth it. From
code size angle (taken globally) I already view this differently.
Plus I think that we ought to aim at avoiding undesirable patterns,
just because people tend to clone existing code when they can. Thing
is that (as per below) the two of us apparently disagree on what
"undesirable" is in cases like this one.

> We probably should take a more generic decision (and encode in our 
> policy) because you seem to like this pattern and I dislike it :). Not 
> sure what the others think.

Perhaps. If the folding alone was the problem, I'd accept to split (or
even undo) that part. But the earlier aspect you raised also needs
sorting before I can decide whether to adjust or whether to consider
the patch rejected.

Jan


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-20  8:26     ` Jan Beulich
@ 2024-02-20 11:52       ` Julien Grall
  2024-02-20 12:25         ` Jan Beulich
  2024-02-21  2:32       ` George Dunlap
  1 sibling, 1 reply; 13+ messages in thread
From: Julien Grall @ 2024-02-20 11:52 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Andrew Cooper, George Dunlap, Stefano Stabellini, Wei Liu, xen-devel

Hi Jan,

On 20/02/2024 08:26, Jan Beulich wrote:
> On 19.02.2024 23:22, Julien Grall wrote:
>> Title: I would add 'gnttab:' to clarify which subsystem you are modifying.
> 
> That's how I actually have it here; it's not clear to me why I lost the
> prefix when sending.
> 
>> On 05/02/2024 11:03, Jan Beulich wrote:
>>> Along the line with observations in the context of XSA-448, besides
>>> "op" no field is relevant when the range to be flushed is empty, much
>>> like e.g. the pointers passed to memcpy() are irrelevant (and would
>>> never be "validated") when the passed length is zero. Split the existing
>>> condition validating "op", "offset", and "length", leaving only the "op"
>>> part ahead of the check for length being zero (or no flushing to be
>>> performed).
>>
>> I am probably missing something here. I understand the theory behind
>> reducing the number of checks when len == 0. But an OS cannot rely on it:
>>     1) older hypervisor would still return an error if the check doesn't
>> pass)
> 
> Right, but that's no reason to keep the bogus earlier behavior.

Hmmm... I am not sure why you say the behavior is bogus. From the commit 
message, it seems this is just an optimization that have side effect 
(ignoring the other fields).

> 
>>     2) it does feel odd to allow "invalid" offset when len == 0 (at least.
> 
> I'm puzzled: You've given R-b for patch 1 (thanks), where exactly the
> same reasoning is used, i.e. similarly referring to memcpy() to
> justify the (new / supposed) behavior.

I realize it. But I viewed it slightly different as you are adding the 
check. I think it is a good idea to add the check and ideally it should 
be after.

Here you don't seem to add any check and only re-order it. Hence why I 
treated it differently.

Cheers,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-20 11:52       ` Julien Grall
@ 2024-02-20 12:25         ` Jan Beulich
  2024-02-21  9:34           ` Julien Grall
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Beulich @ 2024-02-20 12:25 UTC (permalink / raw)
  To: Julien Grall
  Cc: Andrew Cooper, George Dunlap, Stefano Stabellini, Wei Liu, xen-devel

On 20.02.2024 12:52, Julien Grall wrote:
> Hi Jan,
> 
> On 20/02/2024 08:26, Jan Beulich wrote:
>> On 19.02.2024 23:22, Julien Grall wrote:
>>> Title: I would add 'gnttab:' to clarify which subsystem you are modifying.
>>
>> That's how I actually have it here; it's not clear to me why I lost the
>> prefix when sending.
>>
>>> On 05/02/2024 11:03, Jan Beulich wrote:
>>>> Along the line with observations in the context of XSA-448, besides
>>>> "op" no field is relevant when the range to be flushed is empty, much
>>>> like e.g. the pointers passed to memcpy() are irrelevant (and would
>>>> never be "validated") when the passed length is zero. Split the existing
>>>> condition validating "op", "offset", and "length", leaving only the "op"
>>>> part ahead of the check for length being zero (or no flushing to be
>>>> performed).
>>>
>>> I am probably missing something here. I understand the theory behind
>>> reducing the number of checks when len == 0. But an OS cannot rely on it:
>>>     1) older hypervisor would still return an error if the check doesn't
>>> pass)
>>
>> Right, but that's no reason to keep the bogus earlier behavior.
> 
> Hmmm... I am not sure why you say the behavior is bogus. From the commit 
> message, it seems this is just an optimization that have side effect 
> (ignoring the other fields).

I don't view this as primarily an optimization; I'm in particular after
not raising errors for cases where there is no error to be raised.
Hence the comparison to memcpy(), which you can pass "bogus" pointers
so long as you pass zero size.

>>>     2) it does feel odd to allow "invalid" offset when len == 0 (at least.
>>
>> I'm puzzled: You've given R-b for patch 1 (thanks), where exactly the
>> same reasoning is used, i.e. similarly referring to memcpy() to
>> justify the (new / supposed) behavior.
> 
> I realize it. But I viewed it slightly different as you are adding the 
> check. I think it is a good idea to add the check and ideally it should 
> be after.
> 
> Here you don't seem to add any check and only re-order it. Hence why I 
> treated it differently.

Right, there already was a zero-length check here. Just that zero
length requests still could have an error returned for no reason. So
the "optimization" part that you're talking about above was already
there, but as said, that's secondary to me.

Jan


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-20  8:26     ` Jan Beulich
  2024-02-20 11:52       ` Julien Grall
@ 2024-02-21  2:32       ` George Dunlap
  2024-02-21  7:17         ` Jan Beulich
  1 sibling, 1 reply; 13+ messages in thread
From: George Dunlap @ 2024-02-21  2:32 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Julien Grall, Andrew Cooper, Stefano Stabellini, Wei Liu, xen-devel

On Tue, Feb 20, 2024 at 4:26 PM Jan Beulich <jbeulich@suse.com> wrote:
> >> +    if ( (cflush->offset | cflush->length) > PAGE_SIZE ||
> >
> > This is confusing. I understand you are trying to force the compiler to
> > optimize. But is it really worth it? After all, the rest of operation
> > will outweight this check (cache flush are quite expensive).
>
> From purely a performance point of view it may not be worth it. From
> code size angle (taken globally) I already view this differently.
> Plus I think that we ought to aim at avoiding undesirable patterns,
> just because people tend to clone existing code when they can. Thing
> is that (as per below) the two of us apparently disagree on what
> "undesirable" is in cases like this one.
>
> > We probably should take a more generic decision (and encode in our
> > policy) because you seem to like this pattern and I dislike it :). Not
> > sure what the others think.

This is similar to the policy question I raised among the x86
committers a few weeks ago: You're manually specifying a more specific
behavior than is required, rather than specifying what you want and
then letting the compiler optimize things.  The problem with this is
twofold:

1. It's harder for humans to read and understand the intent

2. It ties the compiler's hands.  If you write your intent, then the
compiler is free to apply the optimization or not, or apply a
different optimization.  If you specify this optimization, then the
compiler has fewer ways that it's allowed to compile the code.

#1 by itself is probably enough to counterindicate this kind of
behavior.  Add them together, and I'm inclined to say that we should
write a policy against such optimizations, without specific
justifications.

 -George


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-21  2:32       ` George Dunlap
@ 2024-02-21  7:17         ` Jan Beulich
  2024-02-21  9:17           ` George Dunlap
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Beulich @ 2024-02-21  7:17 UTC (permalink / raw)
  To: George Dunlap
  Cc: Julien Grall, Andrew Cooper, Stefano Stabellini, Wei Liu, xen-devel

On 21.02.2024 03:32, George Dunlap wrote:
> On Tue, Feb 20, 2024 at 4:26 PM Jan Beulich <jbeulich@suse.com> wrote:
>>>> +    if ( (cflush->offset | cflush->length) > PAGE_SIZE ||
>>>
>>> This is confusing. I understand you are trying to force the compiler to
>>> optimize. But is it really worth it? After all, the rest of operation
>>> will outweight this check (cache flush are quite expensive).
>>
>> From purely a performance point of view it may not be worth it. From
>> code size angle (taken globally) I already view this differently.
>> Plus I think that we ought to aim at avoiding undesirable patterns,
>> just because people tend to clone existing code when they can. Thing
>> is that (as per below) the two of us apparently disagree on what
>> "undesirable" is in cases like this one.
>>
>>> We probably should take a more generic decision (and encode in our
>>> policy) because you seem to like this pattern and I dislike it :). Not
>>> sure what the others think.
> 
> This is similar to the policy question I raised among the x86
> committers a few weeks ago: You're manually specifying a more specific
> behavior than is required, rather than specifying what you want and
> then letting the compiler optimize things.  The problem with this is
> twofold:
> 
> 1. It's harder for humans to read and understand the intent

Depends.

> 2. It ties the compiler's hands.  If you write your intent, then the
> compiler is free to apply the optimization or not, or apply a
> different optimization.  If you specify this optimization, then the
> compiler has fewer ways that it's allowed to compile the code.

I'm inclined to believe that no compiler will do this kind of
optimization, unless a specific request was raised against it. The
pattern may not seem overly complex, but to recognize it would
require effort that on the whole may simply not be justified by
the gains (from the compiler's perspective).

> #1 by itself is probably enough to counterindicate this kind of
> behavior.  Add them together, and I'm inclined to say that we should
> write a policy against such optimizations, without specific
> justifications.

It's not like I didn't give any justification. So I guess you mean
without better (whatever that means) justification.

But yes, I'll undo that part of the change then and submit a v2,
albeit with not overly much hope for it to then be accepted.

Jan


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-21  7:17         ` Jan Beulich
@ 2024-02-21  9:17           ` George Dunlap
  0 siblings, 0 replies; 13+ messages in thread
From: George Dunlap @ 2024-02-21  9:17 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Julien Grall, Andrew Cooper, Stefano Stabellini, Wei Liu, xen-devel

On Wed, Feb 21, 2024 at 3:17 PM Jan Beulich <jbeulich@suse.com> wrote:
> > #1 by itself is probably enough to counterindicate this kind of
> > behavior.  Add them together, and I'm inclined to say that we should
> > write a policy against such optimizations, without specific
> > justifications.
>
> It's not like I didn't give any justification. So I guess you mean
> without better (whatever that means) justification.

Sorry, what I meant was that the policy would have to include a sketch
for what sorts of justifications would be acceptable.

For instance, here's a justification I would consider for this sort of thing:

A. In use-case X, there is hard limit Y on the binary size.  For X's
configuration, with a reasonably small number of features enabled, we
are already close to 90% of the way there.  If we were to consistently
use this sort of manual code size optimization techniques across the
codebase, we could cut down the total size of the code base by 25%.

Here's a situation I would absolutely not consider worth it:

B. If we consistently use this sort of code size optimization
techniques across the codebase, we could cut down the entire size of
the codebase by 0.1%.  There are no hard limits, we're just trying to
generally keep things smaller.

Filling our codebase with these sorts of logic puzzles ("Why are we
binary or-ing the offset and the length?") makes it more difficult for
people to understand the code base and increases the risk of someone
making a mistake as they try to change it.  For instance, is this
change really equivalent, given that previously one of the comparisons
had >=?  It turns out yes, but only because we filter out situations
where the length is 0; what if we were to move things around again,
such that we actually can get here with length 0?

Making the binary 0.1% smaller is absolutely not worth the cost of
that.  I'm not sure even 5% would be worth that cost, given that we
don't really have any hard limits we're in danger of exceeding (at
least that I'm aware of).

But a minimum justification for allowing these sorts of things would
need to include a concrete prediction of the improvement we would get
by applying these sorts of things all over the place; not simply, "in
this instance it goes from three to two branches".

 -George


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-20 12:25         ` Jan Beulich
@ 2024-02-21  9:34           ` Julien Grall
  2024-02-21 10:32             ` Jan Beulich
  0 siblings, 1 reply; 13+ messages in thread
From: Julien Grall @ 2024-02-21  9:34 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Andrew Cooper, George Dunlap, Stefano Stabellini, Wei Liu, xen-devel

Hi,

On 20/02/2024 12:25, Jan Beulich wrote:
> On 20.02.2024 12:52, Julien Grall wrote:
>> Hi Jan,
>>
>> On 20/02/2024 08:26, Jan Beulich wrote:
>>> On 19.02.2024 23:22, Julien Grall wrote:
>>>> Title: I would add 'gnttab:' to clarify which subsystem you are modifying.
>>>
>>> That's how I actually have it here; it's not clear to me why I lost the
>>> prefix when sending.
>>>
>>>> On 05/02/2024 11:03, Jan Beulich wrote:
>>>>> Along the line with observations in the context of XSA-448, besides
>>>>> "op" no field is relevant when the range to be flushed is empty, much
>>>>> like e.g. the pointers passed to memcpy() are irrelevant (and would
>>>>> never be "validated") when the passed length is zero. Split the existing
>>>>> condition validating "op", "offset", and "length", leaving only the "op"
>>>>> part ahead of the check for length being zero (or no flushing to be
>>>>> performed).
>>>>
>>>> I am probably missing something here. I understand the theory behind
>>>> reducing the number of checks when len == 0. But an OS cannot rely on it:
>>>>      1) older hypervisor would still return an error if the check doesn't
>>>> pass)
>>>
>>> Right, but that's no reason to keep the bogus earlier behavior.
>>
>> Hmmm... I am not sure why you say the behavior is bogus. From the commit
>> message, it seems this is just an optimization that have side effect
>> (ignoring the other fields).
> 
> I don't view this as primarily an optimization; I'm in particular after
> not raising errors for cases where there is no error to be raised.
> Hence the comparison to memcpy(), which you can pass "bogus" pointers
> so long as you pass zero size.

The part I am missing is why this approach is better than what we have. 
So far what you described is just a matter of taste.

To give a concrete example, if tomorrow a contributor decides to send a 
patch undoing what you did (IOW enforcing the check for zero-length or 
replace | with two branches), then on what grounds I will be able to 
refuse their patch?

Cheers,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] almost fully ignore zero-size flush requests
  2024-02-21  9:34           ` Julien Grall
@ 2024-02-21 10:32             ` Jan Beulich
  0 siblings, 0 replies; 13+ messages in thread
From: Jan Beulich @ 2024-02-21 10:32 UTC (permalink / raw)
  To: Julien Grall
  Cc: Andrew Cooper, George Dunlap, Stefano Stabellini, Wei Liu, xen-devel

On 21.02.2024 10:34, Julien Grall wrote:
> Hi,
> 
> On 20/02/2024 12:25, Jan Beulich wrote:
>> On 20.02.2024 12:52, Julien Grall wrote:
>>> Hi Jan,
>>>
>>> On 20/02/2024 08:26, Jan Beulich wrote:
>>>> On 19.02.2024 23:22, Julien Grall wrote:
>>>>> Title: I would add 'gnttab:' to clarify which subsystem you are modifying.
>>>>
>>>> That's how I actually have it here; it's not clear to me why I lost the
>>>> prefix when sending.
>>>>
>>>>> On 05/02/2024 11:03, Jan Beulich wrote:
>>>>>> Along the line with observations in the context of XSA-448, besides
>>>>>> "op" no field is relevant when the range to be flushed is empty, much
>>>>>> like e.g. the pointers passed to memcpy() are irrelevant (and would
>>>>>> never be "validated") when the passed length is zero. Split the existing
>>>>>> condition validating "op", "offset", and "length", leaving only the "op"
>>>>>> part ahead of the check for length being zero (or no flushing to be
>>>>>> performed).
>>>>>
>>>>> I am probably missing something here. I understand the theory behind
>>>>> reducing the number of checks when len == 0. But an OS cannot rely on it:
>>>>>      1) older hypervisor would still return an error if the check doesn't
>>>>> pass)
>>>>
>>>> Right, but that's no reason to keep the bogus earlier behavior.
>>>
>>> Hmmm... I am not sure why you say the behavior is bogus. From the commit
>>> message, it seems this is just an optimization that have side effect
>>> (ignoring the other fields).
>>
>> I don't view this as primarily an optimization; I'm in particular after
>> not raising errors for cases where there is no error to be raised.
>> Hence the comparison to memcpy(), which you can pass "bogus" pointers
>> so long as you pass zero size.
> 
> The part I am missing is why this approach is better than what we have. 
> So far what you described is just a matter of taste.
> 
> To give a concrete example, if tomorrow a contributor decides to send a 
> patch undoing what you did (IOW enforcing the check for zero-length or 
> replace | with two branches), then on what grounds I will be able to 
> refuse their patch?

On the grounds of the argument I gave before: Consistency with other
more or less similar operations, where length 0 simply means "no-op",
up to and including "no errors from arguments specifying the address(es)
to operate on".

Jan


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-02-21 10:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-05 11:02 [PATCH 0/2] gnttab: hypervisor side XSA-448 follow-up Jan Beulich
2024-02-05 11:03 ` [PATCH 1/2] gnttab: fully ignore zero-size copy requests Jan Beulich
2024-02-19 21:50   ` Julien Grall
2024-02-05 11:03 ` [PATCH 2/2] almost fully ignore zero-size flush requests Jan Beulich
2024-02-19 22:22   ` Julien Grall
2024-02-20  8:26     ` Jan Beulich
2024-02-20 11:52       ` Julien Grall
2024-02-20 12:25         ` Jan Beulich
2024-02-21  9:34           ` Julien Grall
2024-02-21 10:32             ` Jan Beulich
2024-02-21  2:32       ` George Dunlap
2024-02-21  7:17         ` Jan Beulich
2024-02-21  9:17           ` George Dunlap

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.