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

Re: [PATCH v2 1/2] x86/p2m: make p2m_get_page_from_gfn() handle grant case correctly


  • To: George Dunlap <dunlapg@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 8 Feb 2024 09:02:09 +0100
  • 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>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxx>
  • Delivery-date: Thu, 08 Feb 2024 08:02:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 08.02.2024 07:32, George Dunlap wrote:
> On Thu, Jun 23, 2022 at 7:54 PM Jan Beulich <jbeulich@xxxxxxxx> wrote:
> 
>> Grant P2M entries, which are covered by p2m_is_any_ram(), wouldn't pass
>> the get_page() unless the grant was a local one. These need to take the
>> same path as foreign entries. Just the assertion there is not valid for
>> local grants, and hence it triggering needs to be avoided.
>>
> 
> I think I'd say:
> 
> ---
> The 'fast' path of p2m_get_page_from_gfn handles three cases: normal ram,
> foreign p2m entries, and grant map entries.  For normal ram and grant table
> entries, get_page() is called, but for foreign entries,
> page_get_owner_and_reference() is called, since the current domain is
> expected not to be the owner.
> 
> Unfortunately, grant maps are *also* generally expected to be owned by
> foreign domains; so this function will fail for any p2m entry containing a
> grant map that doesn't happen to be local.
> 
> Have grant maps take the same path as foreign entries.  Since grants may
> actually be either foreign or local, adjust the assertion to allow for this.
> ---

Sure, thanks, I can use this, but then I'd perhaps ought to add your
S-o-b instead of ...

> One more comment...
> 
> 
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>> ---
>> Using | instead of || helps the compiler fold the two p2m_is_*().
>> ---
>> v2: The shared case was fine; limit to grant adjustment.
>>
>> --- a/xen/arch/x86/mm/p2m.c
>> +++ b/xen/arch/x86/mm/p2m.c
>> @@ -357,11 +357,11 @@ struct page_info *p2m_get_page_from_gfn(
>>               && !((q & P2M_UNSHARE) && p2m_is_shared(*t)) )
>>          {
>>              page = mfn_to_page(mfn);
>> -            if ( unlikely(p2m_is_foreign(*t)) )
>> +            if ( unlikely(p2m_is_foreign(*t) | p2m_is_grant(*t)) )
>>
> 
> I'm not a fan of this.  If you replace it with || you can have my R-b

... R-b, requiring yet someone else's ack?

> immediately; otherwise we'll have to wait until we can discuss our general
> policy on this sort of thing at the x86 maintainer's call.

I prefer to wait. Considering that even leaving aside the use of
p2m_is_...() "if ( a || b )" is equivalent to "if ( a | b )" (with a and
b of suitable types, of course), and typically requiring less branches
(on x86 at least; architectures with predicated insns of course are
different), personally I'd see us make more use of this in general.
(Hence also the post-commit-message remark.) But yes, Misra in principle
doesn't like such (we've already deviated the underlying pattern,
though).

Of course the compiler is generally in a position to do such a
transformation itself. Just that in at least this specific case I did
observe it not to. I didn't check simpler cases any time halfway
recently.

Jan



 


Rackspace

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