Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] accel/amd-ai-engine: unflushed pm_ops on error in
  aiemlv2_part_init()
- [Medium] accel/amd-ai-engine: unchecked 2-column NMU range in
  aiemlv2_part_init()
- [Low] accel/amd-ai-engine: open-coded polling in
  aie_part_maskpoll_register()
--

commit 7ceb805ff0b7740b5882eeff9e935665efc44bc8
Author: Gregory Williams <[email protected]>

accel/amd-ai-engine: Add reset operations

This commit adds partition initialization and teardown callbacks for AI
Engine partitions, configuring resets, memory zeroization, NMU routing,
ECC scrubbing, error reporting, and tile clocks.

> diff --git a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c 
> b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> index 26dd1d726bfad..910a9bda23055 100644
> --- a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> +++ b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c

[ ... ]

> @@ -173,10 +177,250 @@ static int aiemlv2_set_part_clocks(struct 
> aie_partition *apart)

[ ... ]

> +static int aiemlv2_part_init(struct aie_partition *apart,
> +                          struct aie_partition_init_args *args)
> +{
> +     u32 opts;
> +     int ret;

[ ... ]

> +     if (args->init_opts & AIE_PART_INIT_OPT_NMU_CONFIG) {
> +             struct aie_range range = {0};
> +
> +             opts |= AIE_PART_INIT_OPT_NMU_CONFIG;
> +             if (apart->range.start.col == 0) {
> +                     range.size.col = 2;
> +                     ret = aie_part_pm_ops(apart, NULL, 
> AIE_PART_INIT_OPT_NMU_CONFIG,
> +                                           range, 0);
> +                     if (ret)
> +                             goto out;
> +             }
> +     }

[Severity: Medium]
Can this configure column 1 outside the partition's allocated columns?
If a 1-column partition is requested at column 0 (apart->range.start.col
== 0, apart->range.size.col == 1), setting range.size.col = 2 without
checking apart->range.size.col >= 2 programs NMU routing on column 1 as
well, which may belong to another partition.

> +
> +     if (args->init_opts & AIE_PART_INIT_OPT_HW_ERR_INT) {
> +             u16 data = 0;
> +
> +             opts |= AIE_PART_INIT_OPT_HW_ERR_INT;
> +             ret = aie_part_pm_ops(apart, &data, 
> AIE_PART_INIT_OPT_HW_ERR_INT,
> +                                   apart->range, 0);
> +             if (ret)
> +                     goto out;
> +     }
> +
> +     if (args->init_opts & AIE_PART_INIT_OPT_HW_ERR_MASK) {
> +             u16 data = 0x2;
> +
> +             opts |= AIE_PART_INIT_OPT_HW_ERR_MASK;
> +             ret = aie_part_pm_ops(apart, &data, 
> AIE_PART_INIT_OPT_HW_ERR_MASK,
> +                                   apart->range, 0);
> +             if (ret)
> +                     goto out;
> +     }
> +
> +     if (args->init_opts & AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD) {
> +             u16 data;
> +
> +             if (args->ecc_scrub > U16_MAX) {
> +                     ret = -EINVAL;
> +                     goto out;
> +             }
> +
> +             data = args->ecc_scrub;
> +             opts |= AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD;
> +             ret = aie_part_pm_ops(apart, &data,
> +                                   AIE_PART_INIT_OPT_SET_ECC_SCRUB_PERIOD,
> +                                   apart->range, 0);
> +             if (ret)
> +                     goto out;
> +     }
> +
> +     if (args->init_opts & AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV) {
> +             opts |= AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV;
> +
> +             ret = aie_part_pm_ops(apart, NULL, 
> AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV,
> +                                   apart->range, 0);
> +             if (ret)
> +                     goto out;
> +     }
> +
> +     /* Request tile locations */
> +     ret = aie_part_request_tiles(apart, args->num_tiles, args->locs);
> +     if (ret)
> +             goto out;
> +
> +     if (args->init_opts & AIE_PART_INIT_OPT_DIS_TLAST_ERROR) {
> +             u16 data = 0;
> +
> +             opts |= AIE_PART_INIT_OPT_DIS_TLAST_ERROR;
> +             ret = aie_part_pm_ops(apart, &data,
> +                                   AIE_PART_INIT_OPT_DIS_TLAST_ERROR,
> +                                   apart->range, 1);
> +             if (ret)
> +                     goto out;
> +     }
> +
> +     if (opts != args->init_opts)
> +             dev_warn(&apart->dev, "Invalid init_opts: 0x%x\n", opts ^ 
> args->init_opts);
> +
> +out:
> +     mutex_unlock(&apart->mlock);
> +     return ret;
> +}

[Severity: Medium]
Does the error path leave unflushed commands queued in apart->pm_ops?

The operations from AIE_PART_INIT_OPT_NMU_CONFIG through
AIE_PART_INIT_OPT_UC_ENB_MEM_PRIV are queued with flush = 0 and rely on
aie_part_request_tiles() -> aiemlv2_set_part_clocks() ->
aie_part_pm_ops_flush() to flush and reset the buffer.  If args->ecc_scrub
> U16_MAX or aie_part_request_tiles() fails (for example, when
args->num_tiles > 0 and args->locs is NULL), jumping to out leaves those
descriptors in apart->pm_ops.pkt_va, so they will be sent to firmware
ahead of the DMA pause operations on the next initialize or teardown call.

Validating args before modifying hardware state and resetting
apart->pm_ops on failure would avoid both the stale command buffer and
leaving the partition partially reset on -EINVAL.

> diff --git a/drivers/accel/amd-ai-engine/ai-engine-part.c 
> b/drivers/accel/amd-ai-engine/ai-engine-part.c
> index 35451d1ed88a4..2cd93c02246e5 100644
> --- a/drivers/accel/amd-ai-engine/ai-engine-part.c
> +++ b/drivers/accel/amd-ai-engine/ai-engine-part.c

[ ... ]

> @@ -106,3 +107,34 @@ struct aie_partition *aie_part_create(struct aie_device 
> *adev,
>       device_unregister(&apart->dev);
>       return ERR_PTR(ret);
>  }
> +
> +/**
> + * aie_part_maskpoll_register() - Mask polls an address for a data in a 
> partition.
> + * @apart: AI engine partition.
> + * @offset: AI engine register offset.
> + * @data: data to poll.
> + * @mask: if it is non 0, it is mask read.
> + * @timeout: Timeout in microseconds.
> + *
> + * Return: zero for success, or -EBUSY for failure
> + */
> +int aie_part_maskpoll_register(struct aie_partition *apart, u32 offset, u32 
> data,
> +                            u32 mask, u32 timeout)
> +{
> +     u32 usleep_time = 10;
> +     u32 value;
> +     u32 i;
> +
> +     for (i = 0; i < timeout; i += usleep_time) {
> +             value = readl(apart->adev->base + offset);
> +             if ((value & mask) == data)
> +                     return 0;
> +             usleep_range(usleep_time, usleep_time + 10);
> +     }
> +
> +     value = readl(apart->adev->base + offset);
> +     if ((value & mask) == data)
> +             return 0;
> +
> +     return -EBUSY;
> +}

[Severity: Low]
Can this use readl_poll_timeout() from linux/iopoll.h instead of an
open-coded loop?  Advancing i by 10 us per iteration while calling
usleep_range(10, 20) does not account for sleeps up to 20 us or scheduler
wakeup overhead, so a 2000000 us timeout can block for much longer than 2
seconds per column while holding apart->mlock.

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

Reply via email to