Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] irqchip/gic-v3-its: sleepable alloc_cc_shared_node() called in
  atomic context
--

commit 7bc078950f204b97107cefaed10cb60658f98e21
Author: Aneesh Kumar K.V (Arm) <[email protected]>

irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator

This commit converts GICv3 ITS table and command queue allocations from
alloc_pages_node() and set_memory_decrypted() to alloc_cc_shared_node() and
free_cc_shared().

> diff --git a/drivers/irqchip/irq-gic-v3-its.c 
> b/drivers/irqchip/irq-gic-v3-its.c
> index ada5c30af41ea..cc64384109def 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c

[ ... ]

> @@ -213,47 +212,18 @@ static DEFINE_IDA(its_vpeid_ida);
>  
>  static gfp_t gfp_flags_quirk;
>  
> -static struct page *its_alloc_pages_node(int node, gfp_t gfp,
> -                                      unsigned int order)
> +static void *its_alloc_node(int node, gfp_t gfp, unsigned int order)
>  {
> -     struct page *page;
> -     int ret = 0;
> -
>       if (node == NUMA_NO_NODE)
>               node = numa_mem_id();
>  
> -     page = alloc_pages_node(node, gfp | gfp_flags_quirk, order);
> -
> -     if (!page)
> -             return NULL;
> -
> -     ret = set_memory_decrypted((unsigned long)page_address(page),
> -                                1 << order);
> -     /*
> -      * If set_memory_decrypted() fails then we don't know what state the
> -      * page is in, so we can't free it. Instead we leak it.
> -      * set_memory_decrypted() will already have WARNed.
> -      */
> -     if (ret)
> -             return NULL;
> -
> -     return page;
> -}
> -
> -static struct page *its_alloc_pages(gfp_t gfp, unsigned int order)
> -{
> -     return its_alloc_pages_node(NUMA_NO_NODE, gfp, order);
> +     return alloc_cc_shared_node(node, gfp | gfp_flags_quirk,
> +                                 PAGE_SIZE << order);
>  }
>  
> -static void its_free_pages(void *addr, unsigned int order)
> +static void *its_alloc(gfp_t gfp, unsigned int order)
>  {
> -     /*
> -      * If the memory cannot be encrypted again then we must leak the pages.
> -      * set_memory_encrypted() will already have WARNed.
> -      */
> -     if (set_memory_encrypted((unsigned long)addr, 1 << order))
> -             return;
> -     free_pages((unsigned long)addr, order);
> +     return its_alloc_node(NUMA_NO_NODE, gfp, order);
>  }

[ ... ]

> @@ -3000,12 +2970,12 @@ static int allocate_vpe_l1_table(void)
>  
>       pr_debug("np = %d, npg = %lld, psz = %d, epp = %d, esz = %d\n",
>                np, npg, psz, epp, esz);
> -     page = its_alloc_pages(GFP_ATOMIC | __GFP_ZERO, get_order(np * 
> PAGE_SIZE));
> -     if (!page)
> +     table_base = its_alloc(GFP_ATOMIC | __GFP_ZERO, get_order(np * 
> PAGE_SIZE));
> +     if (!table_base)
>               return -ENOMEM;

[Severity: High]
Does routing its_alloc(GFP_ATOMIC | __GFP_ZERO, ...) through
alloc_cc_shared_node() call might_sleep() in atomic context?

allocate_vpe_l1_table() is called from the CPUHP_AP_IRQ_GIC_STARTING
hotplug callback (gic_starting_cpu() -> its_cpu_init() ->
its_cpu_init_lpis()) with interrupts and preemption disabled, as noted in
d1bd7e0ba533 ("irqchip/gic-v4.1: Use GFP_ATOMIC flag in
allocate_vpe_l1_table()").  Unlike set_memory_decrypted(), which returned
early without calling might_sleep() when memory encryption was inactive,
alloc_cc_shared_node() unconditionally calls might_sleep() at entry before
checking gfp flags or CC_ATTR_MEM_ENCRYPT.  On GICv4.1 systems with
multiple CommonLPIAff groups where a secondary CPU allocates a new VPE L1
table, this triggers a sleep-in-atomic-context splat even on non-CoCo
systems (and sleeps in atomic context if CC_ATTR_MEM_ENCRYPT is active).

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=14

Reply via email to