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

Re: [XEN PATCH] x86/guest_walk: address violations of MISRA C:2012 Rule 8.3


  • To: Federico Serafini <federico.serafini@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 28 Nov 2023 14:00:04 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=rfapMZGC0ldvaZD2FsFFwfN4SpGFQQ6bhBNwcbppQ7g=; b=dS3snC4CNMJOXQtkbrlIn7GcwkS0kLu4sJOZ3Fmf9zsMn+OieG5p2Go/MorJ8iuZNEksBJjGamYb91MzWGJ6aijlPbu1fKs/vWmagfwRhAUDFOnmPTCpIm/bG/LQ5JD3y4L8D5SzGPvzSY6LlI5PpBveZWOvY2VM4biYBDnMpyBdvvG5M3IK0UGUYx5Gabmxeb2u/7wFcmojGVi9WwvNNBw2PjV1CsGbbZRMlznFIpbQ+gdkWrJJ6fsKsBkAE04lDWr9qBcGQevh+5lIskvw2We92TCOmZgyOEkaluPa4Xrqlz32osAktkRNyO0d8RbbRZaw6SKbPnN09dWjNcr/jQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=amLVEtOOZR8pVVgZ643e2KajQhDsOGGqx+iausJARnHgThXhZNyTAWKEdHNqK2oYIdFIK7+dyPgRIztcU9n1GVtk/kHKScCuoViTKJiatc3Vzyx8pNkKwL52ygaula2lvQf5i7zhH9qFApOe/n2N6aO2zI9g9c01yX6xJlygZMTDQz+MRXOerMy/4luK0TloVAO4nzvPfvZb3cMO/65nRbNe/vrImkagVSwLPXDhPt7CPb0Dgb6j7nCIpitwmkS7G6ucm4EN2oIGo8YTm/1fF1+6D6PZ32tBnRWqJ/0brGpglPMWOCxeY4asQvOxhK34znOsr3Z2DZcPIm3M+9z1IA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • 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: consulting@xxxxxxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 28 Nov 2023 13:00:18 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 28.11.2023 10:46, Federico Serafini wrote:
> Uniform declaration and definition of guest_walk_tables() using
> parameter name "pfec_walk":
> this name highlights the connection with PFEC_* constants and it is
> consistent with the use of the parameter within function body.
> No functional change.
> 
> Signed-off-by: Federico Serafini <federico.serafini@xxxxxxxxxxx>

I'm curious what other x86 maintainers think. I for one don't like this,
but not enough to object if others are happy. That said, there was earlier
discussion (and perhaps even a patch), yet without a reference I don't
think I can locate this among all the Misra bits and pieces.

Jan

> --- a/xen/arch/x86/include/asm/guest_pt.h
> +++ b/xen/arch/x86/include/asm/guest_pt.h
> @@ -422,7 +422,7 @@ static inline unsigned int guest_walk_to_page_order(const 
> walk_t *gw)
>  
>  bool
>  guest_walk_tables(const struct vcpu *v, struct p2m_domain *p2m,
> -                  unsigned long va, walk_t *gw, uint32_t pfec,
> +                  unsigned long va, walk_t *gw, uint32_t pfec_walk,
>                    gfn_t top_gfn, mfn_t top_mfn, void *top_map);
>  
>  /* Pretty-print the contents of a guest-walk */
> --- a/xen/arch/x86/mm/guest_walk.c
> +++ b/xen/arch/x86/mm/guest_walk.c
> @@ -69,7 +69,7 @@ static bool set_ad_bits(guest_intpte_t *guest_p, 
> guest_intpte_t *walk_p,
>   */
>  bool
>  guest_walk_tables(const struct vcpu *v, struct p2m_domain *p2m,
> -                  unsigned long va, walk_t *gw, uint32_t walk,
> +                  unsigned long va, walk_t *gw, uint32_t pfec_walk,
>                    gfn_t top_gfn, mfn_t top_mfn, void *top_map)
>  {
>      struct domain *d = v->domain;
> @@ -100,16 +100,17 @@ guest_walk_tables(const struct vcpu *v, struct 
> p2m_domain *p2m,
>       * inputs to a guest walk, but a whole load of code currently passes in
>       * other PFEC_ constants.
>       */
> -    walk &= (PFEC_implicit | PFEC_insn_fetch | PFEC_user_mode | 
> PFEC_write_access);
> +    pfec_walk &= (PFEC_implicit | PFEC_insn_fetch | PFEC_user_mode |
> +                  PFEC_write_access);
>  
>      /* Only implicit supervisor data accesses exist. */
> -    ASSERT(!(walk & PFEC_implicit) ||
> -           !(walk & (PFEC_insn_fetch | PFEC_user_mode)));
> +    ASSERT(!(pfec_walk & PFEC_implicit) ||
> +           !(pfec_walk & (PFEC_insn_fetch | PFEC_user_mode)));
>  
>      perfc_incr(guest_walk);
>      memset(gw, 0, sizeof(*gw));
>      gw->va = va;
> -    gw->pfec = walk & (PFEC_user_mode | PFEC_write_access);
> +    gw->pfec = pfec_walk & (PFEC_user_mode | PFEC_write_access);
>  
>      /*
>       * PFEC_insn_fetch is only reported if NX or SMEP are enabled.  Hardware
> @@ -117,7 +118,7 @@ guest_walk_tables(const struct vcpu *v, struct p2m_domain 
> *p2m,
>       * rights.
>       */
>      if ( guest_nx_enabled(v) || guest_smep_enabled(v) )
> -        gw->pfec |= (walk & PFEC_insn_fetch);
> +        gw->pfec |= (pfec_walk & PFEC_insn_fetch);
>  
>  #if GUEST_PAGING_LEVELS >= 3 /* PAE or 64... */
>  #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */
> @@ -399,7 +400,7 @@ guest_walk_tables(const struct vcpu *v, struct p2m_domain 
> *p2m,
>       * N.B. In the case that the walk ended with a superpage, the fabricated
>       * gw->l1e contains the appropriate leaf pkey.
>       */
> -    if ( !(walk & PFEC_insn_fetch) &&
> +    if ( !(pfec_walk & PFEC_insn_fetch) &&
>           ((ar & _PAGE_USER) ? guest_pku_enabled(v)
>                              : guest_pks_enabled(v)) )
>      {
> @@ -408,8 +409,8 @@ guest_walk_tables(const struct vcpu *v, struct p2m_domain 
> *p2m,
>          unsigned int pk_ar = (pkr >> (pkey * PKEY_WIDTH)) & (PKEY_AD | 
> PKEY_WD);
>  
>          if ( (pk_ar & PKEY_AD) ||
> -             ((walk & PFEC_write_access) && (pk_ar & PKEY_WD) &&
> -              ((walk & PFEC_user_mode) || guest_wp_enabled(v))) )
> +             ((pfec_walk & PFEC_write_access) && (pk_ar & PKEY_WD) &&
> +              ((pfec_walk & PFEC_user_mode) || guest_wp_enabled(v))) )
>          {
>              gw->pfec |= PFEC_prot_key;
>              goto out;
> @@ -417,17 +418,17 @@ guest_walk_tables(const struct vcpu *v, struct 
> p2m_domain *p2m,
>      }
>  #endif
>  
> -    if ( (walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )
> +    if ( (pfec_walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )
>          /* Requested an instruction fetch and found NX? Fail. */
>          goto out;
>  
> -    if ( walk & PFEC_user_mode ) /* Requested a user acess. */
> +    if ( pfec_walk & PFEC_user_mode ) /* Requested a user acess. */
>      {
>          if ( !(ar & _PAGE_USER) )
>              /* Got a supervisor walk?  Unconditional fail. */
>              goto out;
>  
> -        if ( (walk & PFEC_write_access) && !(ar & _PAGE_RW) )
> +        if ( (pfec_walk & PFEC_write_access) && !(ar & _PAGE_RW) )
>              /* Requested a write and only got a read? Fail. */
>              goto out;
>      }
> @@ -435,18 +436,18 @@ guest_walk_tables(const struct vcpu *v, struct 
> p2m_domain *p2m,
>      {
>          if ( ar & _PAGE_USER ) /* Got a user walk. */
>          {
> -            if ( (walk & PFEC_insn_fetch) && guest_smep_enabled(v) )
> +            if ( (pfec_walk & PFEC_insn_fetch) && guest_smep_enabled(v) )
>                  /* User insn fetch and smep? Fail. */
>                  goto out;
>  
> -            if ( !(walk & PFEC_insn_fetch) && guest_smap_enabled(v) &&
> -                 ((walk & PFEC_implicit) ||
> +            if ( !(pfec_walk & PFEC_insn_fetch) && guest_smap_enabled(v) &&
> +                 ((pfec_walk & PFEC_implicit) ||
>                    !(guest_cpu_user_regs()->eflags & X86_EFLAGS_AC)) )
>                  /* User data access and smap? Fail. */
>                  goto out;
>          }
>  
> -        if ( (walk & PFEC_write_access) && !(ar & _PAGE_RW) &&
> +        if ( (pfec_walk & PFEC_write_access) && !(ar & _PAGE_RW) &&
>               guest_wp_enabled(v) )
>              /* Requested a write, got a read, and CR0.WP is set? Fail. */
>              goto out;
> @@ -468,7 +469,7 @@ guest_walk_tables(const struct vcpu *v, struct p2m_domain 
> *p2m,
>  
>      case 1:
>          if ( set_ad_bits(&l1p[guest_l1_table_offset(va)].l1, &gw->l1e.l1,
> -                         (walk & PFEC_write_access)) )
> +                         (pfec_walk & PFEC_write_access)) )
>          {
>              paging_mark_dirty(d, gw->l1mfn);
>              hvmemul_write_cache(v, l1gpa, &gw->l1e, sizeof(gw->l1e));
> @@ -476,7 +477,7 @@ guest_walk_tables(const struct vcpu *v, struct p2m_domain 
> *p2m,
>          /* Fallthrough */
>      case 2:
>          if ( set_ad_bits(&l2p[guest_l2_table_offset(va)].l2, &gw->l2e.l2,
> -                         (walk & PFEC_write_access) && leaf_level == 2) )
> +                         (pfec_walk & PFEC_write_access) && leaf_level == 2) 
> )
>          {
>              paging_mark_dirty(d, gw->l2mfn);
>              hvmemul_write_cache(v, l2gpa, &gw->l2e, sizeof(gw->l2e));
> @@ -485,7 +486,7 @@ guest_walk_tables(const struct vcpu *v, struct p2m_domain 
> *p2m,
>  #if GUEST_PAGING_LEVELS == 4 /* 64-bit only... */
>      case 3:
>          if ( set_ad_bits(&l3p[guest_l3_table_offset(va)].l3, &gw->l3e.l3,
> -                         (walk & PFEC_write_access) && leaf_level == 3) )
> +                         (pfec_walk & PFEC_write_access) && leaf_level == 3) 
> )
>          {
>              paging_mark_dirty(d, gw->l3mfn);
>              hvmemul_write_cache(v, l3gpa, &gw->l3e, sizeof(gw->l3e));




 


Rackspace

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