All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/4] xen/arm: guest_walk: refuse a block descriptor where the granule has none
       [not found] <cover.1794962603.git.stefano.stabellini@amd.com>
@ 2026-11-18  0:59 ` Stefano Stabellini
  2026-11-18  2:04   ` Volodymyr Babchuk
  2026-11-18  0:59 ` [PATCH v2 2/4] xen/arm: guest_walk: refuse an address outside both halves of the range Stefano Stabellini
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Stefano Stabellini @ 2026-11-18  0:59 UTC (permalink / raw)
  To: xen-devel
  Cc: stefano.stabellini, Julien Grall, Bertrand Marquis, Michal Orzel,
	Volodymyr Babchuk

guest_walk_ld() accepted a block descriptor at any level. No granule has
level 0 blocks, and the 16KB and 64KB granules have no level 1 blocks
(ARM DDI 0487 M.d D8.3.1.2): the translation table walk makes such an
entry a Translation fault (AArch64.BlockDescSupported()). Refuse it.

The check is only valid without 52-bit support (FEAT_LPA, FEAT_LPA2).
Note in get_ipa_output_size() that 52-bit support requires updating it.

Fixes: 7d623b358a45 ("arm/mem_access: Add long-descriptor based gpt")
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
Cc: Julien Grall <julien@xen.org>
Cc: Bertrand Marquis <bertrand.marquis@arm.com>
Cc: Michal Orzel <michal.orzel@amd.com>
Cc: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>

Changes in v2:
- Cite ARM DDI 0487 M.d instead of A.k.
- Say in the commit message and the comment that the check is only
  valid without 52-bit support (FEAT_LPA, FEAT_LPA2), and note in
  get_ipa_output_size() that 52-bit support requires updating it.
- Move the Cc list after ---.
---
 xen/arch/arm/guest_walk.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c
index 09fe486598..151b837541 100644
--- a/xen/arch/arm/guest_walk.c
+++ b/xen/arch/arm/guest_walk.c
@@ -201,7 +201,8 @@ static int get_ipa_output_size(struct domain *d, register_t tcr,
          * Return an error on reserved IPA output-sizes and if the IPA
          * output-size is 52bit.
          *
-         * XXX: 52 bit output-size is not supported yet.
+         * XXX: 52 bit output-size is not supported yet. Supporting it also
+         * requires updating the block descriptor check in guest_walk_ld().
          */
         if ( ips > TCR_EL1_IPS_48_BIT )
             return -EFAULT;
@@ -533,6 +534,17 @@ static bool guest_walk_ld(const struct vcpu *v,
     if ( !lpae_is_valid(pte) || !lpae_is_mapping(pte, level) )
         return false;
 
+    /*
+     * A block descriptor is only supported at level 1 and level 2 with the
+     * 4KB granule, and only at level 2 with the 16KB and 64KB granules (ARM
+     * DDI 0487 M.d D8.3.1.2). The block encoding at any other level generates
+     * a Translation fault (AArch64.BlockDescSupported()).
+     *
+     * This is only valid without 52-bit support (FEAT_LPA, FEAT_LPA2).
+     */
+    if ( level == 0 || (level == 1 && gran != GRANULE_SIZE_INDEX_4K) )
+        return false;
+
     /* Make sure that the lower bits of the PTE's base address are zero. */
     mask = GENMASK_ULL(47, grainsizes[gran]);
     *ipa = (pfn_to_paddr(pte.walk.base) & mask) |
-- 
2.47.3



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

* [PATCH v2 2/4] xen/arm: guest_walk: refuse an address outside both halves of the range
       [not found] <cover.1794962603.git.stefano.stabellini@amd.com>
  2026-11-18  0:59 ` [PATCH v2 1/4] xen/arm: guest_walk: refuse a block descriptor where the granule has none Stefano Stabellini
@ 2026-11-18  0:59 ` Stefano Stabellini
  2026-11-18  2:10   ` Volodymyr Babchuk
  2026-11-18  0:59 ` [PATCH v2 3/4] xen/arm: traps: enter the SP_EL0 vector group for an exception at EL1t Stefano Stabellini
  2026-11-18  0:59 ` [PATCH v2 4/4] vpci/header: empty the BAR range sets when modify_bars() fails Stefano Stabellini
  3 siblings, 1 reply; 6+ messages in thread
From: Stefano Stabellini @ 2026-11-18  0:59 UTC (permalink / raw)
  To: xen-devel
  Cc: stefano.stabellini, Julien Grall, Bertrand Marquis, Michal Orzel,
	Volodymyr Babchuk

The bits of an input address from its top bit (bit 63, or bit 55 with
the top byte ignored) down to the input address size must be all 0 for
TTBR0 and all 1 for TTBR1, else the walk faults (ARM DDI 0487 M.d
D8.2.4, AArch64.VAIsOutOfRange()). guest_walk_ld() chose the base from
the top bit alone and translated such an address. Refuse it before
reading any table.

Fixes: 7d623b358a45 ("arm/mem_access: Add long-descriptor based gpt")
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
Cc: Julien Grall <julien@xen.org>
Cc: Bertrand Marquis <bertrand.marquis@arm.com>
Cc: Michal Orzel <michal.orzel@amd.com>
Cc: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>

Changes in v2:
- Cite ARM DDI 0487 M.d (D8.2.4, AArch64.VAIsOutOfRange()) instead of
  A.k, in the commit message and the comment.
- Move the Cc list after ---.
---
 xen/arch/arm/guest_walk.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c
index 151b837541..8c73ceb04d 100644
--- a/xen/arch/arm/guest_walk.c
+++ b/xen/arch/arm/guest_walk.c
@@ -408,6 +408,15 @@ static bool guest_walk_ld(const struct vcpu *v,
         if ( (input_size > TCR_EL1_IPS_48_BIT_VAL) ||
              (input_size < TCR_EL1_IPS_MIN_VAL) )
             return false;
+
+        /*
+         * The bits of the GVA from the top bit down to the input size must
+         * all be 0 for TTBR0 and all 1 for TTBR1, or the translation faults
+         * (ARM DDI 0487 M.d D8.2.4, AArch64.VAIsOutOfRange()).
+         */
+        mask = GENMASK_ULL(topbit, input_size);
+        if ( (gva & mask) != ((gva & BIT(topbit, ULL)) ? mask : 0) )
+            return false;
     }
     else
     {
-- 
2.47.3



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

* [PATCH v2 3/4] xen/arm: traps: enter the SP_EL0 vector group for an exception at EL1t
       [not found] <cover.1794962603.git.stefano.stabellini@amd.com>
  2026-11-18  0:59 ` [PATCH v2 1/4] xen/arm: guest_walk: refuse a block descriptor where the granule has none Stefano Stabellini
  2026-11-18  0:59 ` [PATCH v2 2/4] xen/arm: guest_walk: refuse an address outside both halves of the range Stefano Stabellini
@ 2026-11-18  0:59 ` Stefano Stabellini
  2026-11-18  0:59 ` [PATCH v2 4/4] vpci/header: empty the BAR range sets when modify_bars() fails Stefano Stabellini
  3 siblings, 0 replies; 6+ messages in thread
From: Stefano Stabellini @ 2026-11-18  0:59 UTC (permalink / raw)
  To: xen-devel
  Cc: stefano.stabellini, Michal Orzel, Julien Grall, Bertrand Marquis,
	Volodymyr Babchuk

An exception taken from the current level is delivered to the SP_EL0
vector group (offset 0x000) when the guest was at EL1t, and to the
SP_ELx group (0x200) only at EL1h (ARM DDI 0487 M.d D1.4.1).
exception_handler64() used 0x200 for both.

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
---
Cc: Julien Grall <julien@xen.org>
Cc: Bertrand Marquis <bertrand.marquis@arm.com>
Cc: Michal Orzel <michal.orzel@amd.com>
Cc: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>

Changes in v2:
- Cite ARM DDI 0487 M.d D1.4.1 instead of A.k, in the commit message
  and the comment.
- Move the Cc list after ---.
- Add Michal's Reviewed-by.
---
 xen/arch/arm/traps.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
index 47a5c6bdd4..b4ca812233 100644
--- a/xen/arch/arm/traps.c
+++ b/xen/arch/arm/traps.c
@@ -532,7 +532,13 @@ static vaddr_t exception_handler64(struct cpu_user_regs *regs, vaddr_t offset)
         base += VECTOR64_LOWER32_BASE;
     else if ( psr_mode(regs->cpsr,PSR_MODE_EL0t) )
         base += VECTOR64_LOWER64_BASE;
-    else /* Otherwise must be from kernel mode */
+    /*
+     * Otherwise must be from kernel mode. The current EL group is chosen by
+     * the stack pointer in use (ARM DDI 0487 M.d D1.4.1).
+     */
+    else if ( psr_mode(regs->cpsr,PSR_MODE_EL1t) )
+        base += VECTOR64_CURRENT_SP0_BASE;
+    else
         base += VECTOR64_CURRENT_SPx_BASE;
 
     return base + offset;
-- 
2.47.3



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

* [PATCH v2 4/4] vpci/header: empty the BAR range sets when modify_bars() fails
       [not found] <cover.1794962603.git.stefano.stabellini@amd.com>
                   ` (2 preceding siblings ...)
  2026-11-18  0:59 ` [PATCH v2 3/4] xen/arm: traps: enter the SP_EL0 vector group for an exception at EL1t Stefano Stabellini
@ 2026-11-18  0:59 ` Stefano Stabellini
  3 siblings, 0 replies; 6+ messages in thread
From: Stefano Stabellini @ 2026-11-18  0:59 UTC (permalink / raw)
  To: xen-devel
  Cc: stefano.stabellini, Jan Beulich, Roger Pau Monné,
	Stewart Hildebrand

On error modify_bars() returned with the ranges already collected still
in the per-BAR sets. The next request on the device then trips the
ASSERT(rangeset_is_empty()) at the start of modify_bars() in a debug
build, and in a release build maps or unmaps the stale ranges along
with its own. Purge every set when collecting the ranges fails.

Fixes: 622bdd962822 ("vpci/header: handle p2m range sets per BAR")
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
Cc: "Roger Pau Monné" <roger@xenproject.org>
Cc: Stewart Hildebrand <stewart.hildebrand@amd.com>
Cc: Jan Beulich <jbeulich@suse.com>

Changes in v2:
- Mention the ASSERT(rangeset_is_empty()) in the commit message.
- Move the Cc list after ---.
- Add Jan's Reviewed-by.
---
 xen/drivers/vpci/header.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
index 7e5f4b8a00..0bdc4d6a46 100644
--- a/xen/drivers/vpci/header.c
+++ b/xen/drivers/vpci/header.c
@@ -366,7 +366,8 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only)
             gprintk(XENLOG_G_WARNING,
                     "%pp: can't map BAR%u - offset mismatch: %#lx vs %#lx\n",
                     &pdev->sbdf, i, bar->guest_addr, bar->addr);
-            return -EINVAL;
+            rc = -EINVAL;
+            goto fail;
         }
 
         rc = rangeset_add_range(bar->mem, start_guest, end_guest);
@@ -374,7 +375,7 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only)
         {
             printk(XENLOG_G_WARNING "Failed to add [%lx, %lx]: %d\n",
                    start_guest, end_guest, rc);
-            return rc;
+            goto fail;
         }
 
         /* Check for overlap with the already setup BAR ranges. */
@@ -391,7 +392,7 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only)
                 gprintk(XENLOG_WARNING,
                        "%pp: failed to remove overlapping range [%lx, %lx]: %d\n",
                         &pdev->sbdf, start_guest, end_guest, rc);
-                return rc;
+                goto fail;
             }
         }
 
@@ -401,7 +402,7 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only)
             gprintk(XENLOG_WARNING,
                     "%pp: failed to sanitize BAR#%u memory: %d\n",
                     &pdev->sbdf, i, rc);
-            return rc;
+            goto fail;
         }
     }
 
@@ -425,7 +426,7 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only)
                 gprintk(XENLOG_WARNING,
                        "%pp: failed to remove MSIX table [%lx, %lx]: %d\n",
                         &pdev->sbdf, start, end, rc);
-                return rc;
+                goto fail;
             }
         }
     }
@@ -487,7 +488,7 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only)
                         gprintk(XENLOG_WARNING,
                                 "%pp: failed to remove [%lx, %lx]: %d\n",
                                 &pdev->sbdf, start, end, rc);
-                        return rc;
+                        goto fail;
                     }
                 }
             }
@@ -516,6 +517,18 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only)
     defer_map(pdev, cmd, rom_only);
 
     return 0;
+
+ fail:
+    /*
+     * Leave no range collected for the request that failed: the next request
+     * expects every BAR's set to start empty, and a range left behind would
+     * be mapped or unmapped with it.
+     */
+    for ( i = 0; i < ARRAY_SIZE(header->bars); i++ )
+        if ( header->bars[i].mem )
+            rangeset_purge(header->bars[i].mem);
+
+    return rc;
 }
 
 static void cf_check cmd_write(
-- 
2.47.3



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

* Re: [PATCH v2 1/4] xen/arm: guest_walk: refuse a block descriptor where the granule has none
  2026-11-18  0:59 ` [PATCH v2 1/4] xen/arm: guest_walk: refuse a block descriptor where the granule has none Stefano Stabellini
@ 2026-11-18  2:04   ` Volodymyr Babchuk
  0 siblings, 0 replies; 6+ messages in thread
From: Volodymyr Babchuk @ 2026-11-18  2:04 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: xen-devel@lists.xenproject.org, Julien Grall, Bertrand Marquis,
	Michal Orzel

Hello Stefano,

Stefano Stabellini <stefano.stabellini@amd.com> writes:

> guest_walk_ld() accepted a block descriptor at any level. No granule has
> level 0 blocks, and the 16KB and 64KB granules have no level 1 blocks
> (ARM DDI 0487 M.d D8.3.1.2): the translation table walk makes such an
> entry a Translation fault (AArch64.BlockDescSupported()). Refuse it.
>
> The check is only valid without 52-bit support (FEAT_LPA, FEAT_LPA2).
> Note in get_ipa_output_size() that 52-bit support requires updating it.
>
> Fixes: 7d623b358a45 ("arm/mem_access: Add long-descriptor based gpt")
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>

Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>

> ---
> Cc: Julien Grall <julien@xen.org>
> Cc: Bertrand Marquis <bertrand.marquis@arm.com>
> Cc: Michal Orzel <michal.orzel@amd.com>
> Cc: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
>
> Changes in v2:
> - Cite ARM DDI 0487 M.d instead of A.k.
> - Say in the commit message and the comment that the check is only
>   valid without 52-bit support (FEAT_LPA, FEAT_LPA2), and note in
>   get_ipa_output_size() that 52-bit support requires updating it.
> - Move the Cc list after ---.
> ---
>  xen/arch/arm/guest_walk.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c
> index 09fe486598..151b837541 100644
> --- a/xen/arch/arm/guest_walk.c
> +++ b/xen/arch/arm/guest_walk.c
> @@ -201,7 +201,8 @@ static int get_ipa_output_size(struct domain *d, register_t tcr,
>           * Return an error on reserved IPA output-sizes and if the IPA
>           * output-size is 52bit.
>           *
> -         * XXX: 52 bit output-size is not supported yet.
> +         * XXX: 52 bit output-size is not supported yet. Supporting it also
> +         * requires updating the block descriptor check in guest_walk_ld().
>           */
>          if ( ips > TCR_EL1_IPS_48_BIT )
>              return -EFAULT;
> @@ -533,6 +534,17 @@ static bool guest_walk_ld(const struct vcpu *v,
>      if ( !lpae_is_valid(pte) || !lpae_is_mapping(pte, level) )
>          return false;
>  
> +    /*
> +     * A block descriptor is only supported at level 1 and level 2 with the
> +     * 4KB granule, and only at level 2 with the 16KB and 64KB granules (ARM
> +     * DDI 0487 M.d D8.3.1.2). The block encoding at any other level generates
> +     * a Translation fault (AArch64.BlockDescSupported()).
> +     *
> +     * This is only valid without 52-bit support (FEAT_LPA, FEAT_LPA2).
> +     */
> +    if ( level == 0 || (level == 1 && gran != GRANULE_SIZE_INDEX_4K) )
> +        return false;
> +
>      /* Make sure that the lower bits of the PTE's base address are zero. */
>      mask = GENMASK_ULL(47, grainsizes[gran]);
>      *ipa = (pfn_to_paddr(pte.walk.base) & mask) |

-- 
WBR, Volodymyr

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

* Re: [PATCH v2 2/4] xen/arm: guest_walk: refuse an address outside both halves of the range
  2026-11-18  0:59 ` [PATCH v2 2/4] xen/arm: guest_walk: refuse an address outside both halves of the range Stefano Stabellini
@ 2026-11-18  2:10   ` Volodymyr Babchuk
  0 siblings, 0 replies; 6+ messages in thread
From: Volodymyr Babchuk @ 2026-11-18  2:10 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: xen-devel@lists.xenproject.org, Julien Grall, Bertrand Marquis,
	Michal Orzel

Hi,

Stefano Stabellini <stefano.stabellini@amd.com> writes:

> The bits of an input address from its top bit (bit 63, or bit 55 with
> the top byte ignored) down to the input address size must be all 0 for
> TTBR0 and all 1 for TTBR1, else the walk faults (ARM DDI 0487 M.d
> D8.2.4, AArch64.VAIsOutOfRange()). guest_walk_ld() chose the base from
> the top bit alone and translated such an address. Refuse it before
> reading any table.
>
> Fixes: 7d623b358a45 ("arm/mem_access: Add long-descriptor based gpt")
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>

Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>

> ---
> Cc: Julien Grall <julien@xen.org>
> Cc: Bertrand Marquis <bertrand.marquis@arm.com>
> Cc: Michal Orzel <michal.orzel@amd.com>
> Cc: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
>
> Changes in v2:
> - Cite ARM DDI 0487 M.d (D8.2.4, AArch64.VAIsOutOfRange()) instead of
>   A.k, in the commit message and the comment.
> - Move the Cc list after ---.
> ---
>  xen/arch/arm/guest_walk.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c
> index 151b837541..8c73ceb04d 100644
> --- a/xen/arch/arm/guest_walk.c
> +++ b/xen/arch/arm/guest_walk.c
> @@ -408,6 +408,15 @@ static bool guest_walk_ld(const struct vcpu *v,
>          if ( (input_size > TCR_EL1_IPS_48_BIT_VAL) ||
>               (input_size < TCR_EL1_IPS_MIN_VAL) )
>              return false;
> +
> +        /*
> +         * The bits of the GVA from the top bit down to the input size must
> +         * all be 0 for TTBR0 and all 1 for TTBR1, or the translation faults
> +         * (ARM DDI 0487 M.d D8.2.4, AArch64.VAIsOutOfRange()).
> +         */
> +        mask = GENMASK_ULL(topbit, input_size);
> +        if ( (gva & mask) != ((gva & BIT(topbit, ULL)) ? mask : 0) )
> +            return false;
>      }
>      else
>      {

-- 
WBR, Volodymyr

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

end of thread, other threads:[~2026-11-18  2:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1794962603.git.stefano.stabellini@amd.com>
2026-11-18  0:59 ` [PATCH v2 1/4] xen/arm: guest_walk: refuse a block descriptor where the granule has none Stefano Stabellini
2026-11-18  2:04   ` Volodymyr Babchuk
2026-11-18  0:59 ` [PATCH v2 2/4] xen/arm: guest_walk: refuse an address outside both halves of the range Stefano Stabellini
2026-11-18  2:10   ` Volodymyr Babchuk
2026-11-18  0:59 ` [PATCH v2 3/4] xen/arm: traps: enter the SP_EL0 vector group for an exception at EL1t Stefano Stabellini
2026-11-18  0:59 ` [PATCH v2 4/4] vpci/header: empty the BAR range sets when modify_bars() fails Stefano Stabellini

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.