Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] accel/amd-ai-engine: spurious goto again after flush in
  aie_part_pm_ops()
- [Low] accel/amd-ai-engine: missing @loc kernel-doc in
  aie_op_handshake_data
- [Low] accel/amd-ai-engine: 32-bit shift overflow on dma_addr_t in
  aie_part_pm_ops()
--

commit d2e06ea50ba27d65c500c4af65cd1c3eb56d05cf
Author: Gregory Williams <[email protected]>

accel/amd-ai-engine: Add pm ops for firmware calls

This commit adds platform management operation structures and helpers to
pack and flush privileged AI Engine register operations to trusted
firmware via coherent DMA buffers.

> diff --git a/drivers/accel/amd-ai-engine/ai-engine-pm.c 
> b/drivers/accel/amd-ai-engine/ai-engine-pm.c
> new file mode 100644
> index 0000000000000..103879456f520
> --- /dev/null
> +++ b/drivers/accel/amd-ai-engine/ai-engine-pm.c
> @@ -0,0 +1,472 @@

[ ... ]

> +int aie_part_pm_ops(struct aie_partition *apart, void *data, u32 type,
> +                 struct aie_range range, bool flush)
> +{
> +     struct aie_pm_ops *pm_ops = &apart->pm_ops;
> +     struct aie_op_start_num_col *op_range;
> +     ssize_t end;
> +     int ret = 0;
> +
> +again:
> +     op_range = pm_ops->op_range;
> +     if (!op_range ||
> +         op_range->num_col != range.size.col ||
> +         op_range->start_col != range.start.col) {
> +             if (check_add_overflow(pm_ops->offset, sizeof(*op_range), &end) 
> ||
> +                 end >= pm_ops->size) {
> +                     ret = aie_part_pm_ops_flush(apart);
> +                     if (ret)
> +                             return ret;
> +             }
> +             pm_ops->op_range = pm_ops->pkt_va + pm_ops->offset;
> +             pm_ops->offset += sizeof(*pm_ops->op_range);
> +             op_range = pm_ops->op_range;
> +             op_range->type = XILINX_AIE_OPS_START_NUM_COL;
> +             op_range->start_col = range.start.col;
> +             op_range->num_col = range.size.col;
> +             op_range->len = sizeof(*op_range);
> +     }

[ ... ]

> +     if (type & AIE_PART_INIT_OPT_HW_ERR_STS) {
> +             struct aie_op_hw_err *op;
> +
> +             if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
> +                 end >= pm_ops->size) {
> +                     ret = aie_part_pm_ops_flush(apart);
> +                     if (ret)
> +                             return ret;
> +                     goto again;
> +             }
> +             type &= ~AIE_PART_INIT_OPT_HW_ERR_STS;
> +             op = pm_ops->pkt_va + pm_ops->offset;
> +             pm_ops->offset += sizeof(*op);
> +             op->type = XILINX_AIE_OPS_CLR_HW_ERR_STS;
> +             op->len = sizeof(*op);
> +             op->val = *((u16 *)data);
> +             ret = aie_part_pm_ops_flush(apart);
> +             if (ret)
> +                     return ret;
> +             goto again;
> +     }
> +     if (type & AIE_PART_INIT_OPT_DIS_TLAST_ERROR) {
> +             struct aie_op_tlast *op;
> +
> +             if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
> +                 end >= pm_ops->size) {
> +                     ret = aie_part_pm_ops_flush(apart);
> +                     if (ret)
> +                             return ret;
> +                     goto again;
> +             }
> +             type &= ~AIE_PART_INIT_OPT_DIS_TLAST_ERROR;
> +             op = pm_ops->pkt_va + pm_ops->offset;
> +             pm_ops->offset += sizeof(*op);
> +             op->type = XILINX_AIE_OPS_CTRL_PKT_TLAST_ERR;
> +             op->len = sizeof(*op);
> +             op->state = *((u16 *)data);
> +     }
> +     if (type & AIE_PART_INIT_OPT_HANDSHAKE) {
> +             struct aie_op_handshake *op;
> +             struct aie_op_handshake_addr *hs_addr = data;
> +
> +             if (check_add_overflow(pm_ops->offset, sizeof(*op), &end) ||
> +                 end >= pm_ops->size) {
> +                     ret = aie_part_pm_ops_flush(apart);
> +                     if (ret)
> +                             return ret;
> +                     goto again;
> +             }
> +
> +             type &= ~AIE_PART_INIT_OPT_HANDSHAKE;
> +             op = pm_ops->pkt_va + pm_ops->offset;
> +             pm_ops->offset += sizeof(*op);
> +             op->type = XILINX_AIE_OPS_HANDSHAKE;
> +             op->len = sizeof(*op) + hs_addr->size;
> +             op->offset = hs_addr->offset;
> +             op->low_addr = hs_addr->hs_dma & 0xFFFFFFFFULL;
> +             op->high_addr = hs_addr->hs_dma >> 32;

[Severity: Low]
Can shifting hs_addr->hs_dma by 32 bits trigger a -Wshift-count-overflow
warning on 32-bit COMPILE_TEST builds?

hs_dma has type dma_addr_t, which is 32 bits wide when
CONFIG_ARCH_DMA_ADDR_T_64BIT is disabled.  Using lower_32_bits() and
upper_32_bits() as in aie_part_pm_ops_flush() avoids the shift overflow.

> +             if (flush)
> +                     ret = aie_part_pm_ops_flush(apart);
> +
> +             if (ret)
> +                     return ret;
> +             goto again;
> +     }
> +
> +     if (type)
> +             dev_warn(&apart->dev, "Unknown ops type: 0x%x\n", type);
> +
> +     if (flush)
> +             ret = aie_part_pm_ops_flush(apart);
> +
> +     return ret;
> +}

[Severity: Medium]
Why do the AIE_PART_INIT_OPT_HW_ERR_STS and AIE_PART_INIT_OPT_HANDSHAKE
branches flush and jump back to again after queuing their operation?

Jumping to again after aie_part_pm_ops_flush() resets pm_ops->op_range to
NULL causes a new XILINX_AIE_OPS_START_NUM_COL range header to be written
into pm_ops->pkt_va even when no bits remain in type.  When flush is
true, the function then flushes a second time at the end; when flush is
false with AIE_PART_INIT_OPT_HW_ERR_STS (which also ignores the flush
parameter), an empty range header is left in pm_ops->pkt_va and will not
be stripped by aie_part_pm_ops_flush() if the next call uses a different
column range.

> diff --git a/include/linux/amd-ai-engine.h b/include/linux/amd-ai-engine.h
> index f5750d219e211..9df3463985afd 100644
> --- a/include/linux/amd-ai-engine.h
> +++ b/include/linux/amd-ai-engine.h

[ ... ]

> +/**
> + * struct aie_op_handshake_data - AI engine uc handshake region information
> + * @addr: handshake data address from where the data needs to be copied.
> + * @size: handshake data size.
> + * @offset: offset for handshake region update.
> + */
> +struct aie_op_handshake_data {
> +     void *addr;
> +     size_t size;
> +     size_t offset;
> +     struct aie_location loc;
> +};

[Severity: Low]
The kernel-doc comment for struct aie_op_handshake_data is missing an
entry for @loc, which will trigger a kernel-doc warning under W=1.

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

Reply via email to