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

Re: [PATCH v3 4/4] x86/shadow: re-work 4-level SHADOW_FOREACH_L2E()


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 10 Feb 2023 08:38:25 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Wse9i7PQQCT7mpq4yHOBI6RpsTexJCJeYMFvDaMso+Q=; b=c54yijjnmYpyKeyueiLmzjHb7UWIx69aqLsSmfAPnt3aq83sHcGBGicQjOqgisVIohQP+D+gOVlpgVG4/Fe9zxFg7fAOl+W+m7QT1V+dJoLRfU38xoosJltK+qNrdGbAaJC9k1qXxna/la9yLGY52yLPhlFSvkqsG37KXpV2cnpDsJ85tinsQ0vHpk0ZMAW8Uc3rwB78A4Xcm9AGclv6BJ2wvr0UlCVzhq35RKBIHDz3M2509MBAjk4sowzB9sTUjajHGI9HJbO0kp1OUO2BaV/t+f2HIQYL4J+XZVjtxM1uqocke79pIL59PdW8Qt/KJsshBC7Efk1ckc+A+POaow==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jqBRDU7/ngQVdusYVytnS9hLWDpGNgRo6m7OMEEdf2ZUx+BO3Ti6cXI2ExZ8Rz6Wm13b3VBTYqErljT5y5XzEfHBpP3RGX7LzVMDITEUTLX3+Oz3+vbZWFkzSSrfZy9mUULauEvj0OF4lBM9vVAUIl59Eft512uaAS01O0FNHvSgUoNbgh/+AI63R0UB8lI6ikAdo5PcquEJ73XPGhv/hn+y52bNAIrWDeQir5qCO5KzfXfJeUZW4lHyQvLQCnIfndLOMgyPFdOCsz9IC/gPaypQSkt39/KcQ+EKPYIBAWTgBZIKgifQDIAS+1PXtmJhvKraJZFbbGd2dLduYjlrgg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Tim Deegan <tim@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Fri, 10 Feb 2023 08:39:00 +0000
  • Ironport-data: A9a23:kRnl/K1oy3sHbYpiD/bD5eJwkn2cJEfYwER7XKvMYLTBsI5bpz0Ex 2AWWWjSOPyJa2ajfo90bt+1/ElV68ODmNA2TVNkpC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefTAOK6ULWeUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8tuTS93uDgNyo4GlD5gZnPagS1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfIzgQ6 ccCaxI0aivTpuyo8Li5TbF0r5F2RCXrFNt3VnBI6xj8VKxjbbWdBqLA6JlfwSs6gd1IEbDGf c0FZDFzbRPGJRpSJlMQD5F4l+Ct7pX9W2QA9BTJ+uxqsi6Kk1UZPLvFabI5fvSjQ8lPk1nej WXB52njWTkRNcCFyCrD+XWp7gPKtXKmCNJCROThnhJsqH+8zWc4Ej0ZbFX48NybuxGzZugDF WVBr0LCqoB3riRHVOLVXRe1vXqFtR40QMdLHqsx7wTl4rXQyxaUAC4DVDEpQMAnsecmSDps0 UWG9/v5CDoqvLCLRHa18raPsSj0KSUTNXUFZyIPUU0C+daLnW0ophfGT9ImHKvriNTwQGv02 2rT83F4gKgPh8kW0an95UrAnz+nupnOSEgy+xnTWWWmqAh+YeZJerCV1LQS1t4YRK7xc7VLl CFsdxS2hAzWMaywqQ==
  • Ironport-hdrordr: A9a23:MzYF0KxhE+MgrMgcGdD3KrPw3L1zdoMgy1knxilNoHxuH/Bw9v re+8jzsCWftN9/Yh4dcLy7VpVoBEmslqKdgrNhWYtKPjOHhILAFugLgbcKgQeQeREWntQ36U 4KSdkaNDSfNzlHZcaR2njFLz4jquP3j5xBU43lvglQpQIBUdAQ0+9gYDzrdHGf3GN9dOAE/J z33Ls/mxOQPU45Q+6cHXc/U+3Kt7Tw5e/biU5vPW9e1OGW5wnYk4LHLw==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 10/02/2023 7:07 am, Jan Beulich wrote:
> On 09.02.2023 18:26, Andrew Cooper wrote:
>> On 08/02/2023 2:38 pm, Jan Beulich wrote:
>>> First of all move the almost loop-invariant condition out of the loop;
>>> transform it into an altered loop boundary, noting that the updating of
>>> _gl2p is relevant only at one use site, and then also only inside the
>>> _code blob it provides. Then drop the shadow_mode_external() part of the
>>> condition as being redundant with the is_pv_32bit_domain() check.
>>> Further, since the new local variable wants to be "unsigned int",
>>> convert the loop induction variable accordingly. Finally also adjust
>>> formatting as most code needs touching anyway.
>>>
>>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>> Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Thanks.
>
>>> --- a/xen/arch/x86/mm/shadow/multi.c
>>> +++ b/xen/arch/x86/mm/shadow/multi.c
>>> @@ -861,23 +861,22 @@ do {
>>>  /* 64-bit l2: touch all entries except for PAE compat guests. */
>>>  #define SHADOW_FOREACH_L2E(_sl2mfn, _sl2e, _gl2p, _done, _dom, _code)      
>>>  \
>>>  do {                                                                       
>>>  \
>>> -    int _i;                                                                
>>>  \
>>> -    int _xen = !shadow_mode_external(_dom);                                
>>>  \
>>> +    unsigned int _i, _end = SHADOW_L2_PAGETABLE_ENTRIES;                   
>>>  \
>>>      shadow_l2e_t *_sp = map_domain_page((_sl2mfn));                        
>>>  \
>>>      ASSERT_VALID_L2(mfn_to_page(_sl2mfn)->u.sh.type);                      
>>>  \
>>> -    for ( _i = 0; _i < SHADOW_L2_PAGETABLE_ENTRIES; _i++ )                 
>>>  \
>>> +    if ( is_pv_32bit_domain(_dom) /* implies !shadow_mode_external(_dom) 
>>> */ && \
>> As this is a comment, I think can reasonably be
>>
>> /* implies !shadow_mode_external */
>>
>> which shortens it enough to maintain the RHS justification.
> I would certainly have done it without pushing out the escape, but both
> alternative variants look worse to me: In
>
>     /* Implies !shadow_mode_external(_dom) */                               \
>     if ( is_pv_32bit_domain(_dom) &&                                        \
>          mfn_to_page(_sl2mfn)->u.sh.type != SH_type_l2_64_shadow )          \
>         _end = COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(_dom);                    \
>
> it isn't clear that the comment applies to only the first part of the
> conditions, whereas
>     
>     if ( /* Implies !shadow_mode_external(_dom): */                         \
>          is_pv_32bit_domain(_dom) &&                                        \
>          mfn_to_page(_sl2mfn)->u.sh.type != SH_type_l2_64_shadow )          \
>         _end = COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(_dom);                    \
>
> looks more clumsy to me. I'm not very likely to accept a suggestion to
> for the former route; if you think the latter variant is strictly
> better than the original, I might make the change while committing.
>
> Hmm, or maybe
>
>     if ( mfn_to_page(_sl2mfn)->u.sh.type != SH_type_l2_64_shadow )          \
>          /* Implies !shadow_mode_external(_dom): */                         \
>          is_pv_32bit_domain(_dom) &&                                        \
>         _end = COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(_dom);                    \
>
> ?

I simply meant:

-    for ( _i = 0; _i < SHADOW_L2_PAGETABLE_ENTRIES; _i++
)                  \
+    if ( is_pv_32bit_domain(_dom) /* implies !shadow_mode_external */
&&   \

(If this renderers properly.)

It is not important for the comment to be syntactically valid C,
especially as you're saying one predicate implies the other.

~Andrew



 


Rackspace

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