All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
To: Neal Liu <neal.liu@mediatek.com>
Cc: Rob Herring <robh+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	devicetree@vger.kernel.org,
	wsd_upstream <wsd_upstream@mediatek.com>,
	lkml <linux-kernel@vger.kernel.org>,
	"moderated list:ARM/Mediatek SoC support" 
	<linux-mediatek@lists.infradead.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v3 2/2] soc: mediatek: add mtk-devapc driver
Date: Wed, 22 Jul 2020 07:21:35 +0800	[thread overview]
Message-ID: <CAAOTY_8T=DCntU8x5YEo+Pcs2J0Y4YvDaHUBdGiqEFRxghOd_Q@mail.gmail.com> (raw)
In-Reply-To: <1595303971-8793-3-git-send-email-neal.liu@mediatek.com>

Hi, Neal:

Neal Liu <neal.liu@mediatek.com> 於 2020年7月21日 週二 下午12:00寫道:
>
> MediaTek bus fabric provides TrustZone security support and data
> protection to prevent slaves from being accessed by unexpected
> masters.
> The security violation is logged and sent to the processor for
> further analysis or countermeasures.
>
> Any occurrence of security violation would raise an interrupt, and
> it will be handled by mtk-devapc driver. The violation
> information is printed in order to find the murderer.
>
> Signed-off-by: Neal Liu <neal.liu@mediatek.com>
> ---

[snip]

> +
> +static u32 get_shift_group(struct mtk_devapc_context *ctx, u32 vio_idx)

vio_idx is useless, so remove it.

> +{
> +       u32 vio_shift_sta;
> +       void __iomem *reg;
> +
> +       reg = ctx->devapc_pd_base + ctx->offset->vio_shift_sta;
> +       vio_shift_sta = readl(reg);
> +
> +       if (vio_shift_sta)
> +               return __ffs(vio_shift_sta);
> +
> +       return 31;
> +}
> +

[snip]

> +
> +/*
> + * mtk_devapc_dump_vio_dbg - get the violation index and dump the full violation
> + *                           debug information.
> + */
> +static bool mtk_devapc_dump_vio_dbg(struct mtk_devapc_context *ctx, u32 vio_idx)
> +{
> +       u32 shift_bit;
> +
> +       if (check_vio_mask(ctx, vio_idx))
> +               return false;
> +
> +       if (!check_vio_status(ctx, vio_idx))
> +               return false;
> +
> +       shift_bit = get_shift_group(ctx, vio_idx);
> +
> +       if (sync_vio_dbg(ctx, shift_bit))
> +               return false;
> +
> +       devapc_extract_vio_dbg(ctx);

I think get_shift_group(), sync_vio_dbg(), and
devapc_extract_vio_dbg() should be moved out of vio_idx for-loop (the
loop in devapc_violation_irq()) because these three function is not
related to vio_idx.
Another question: when multiple vio_idx violation occur, vio_addr is
related to which one vio_idx? The latest happened one?

> +
> +       return true;
> +}
> +
> +/*
> + * devapc_violation_irq - the devapc Interrupt Service Routine (ISR) will dump
> + *                        violation information including which master violates
> + *                        access slave.
> + */
> +static irqreturn_t devapc_violation_irq(int irq_number,
> +                                       struct mtk_devapc_context *ctx)
> +{
> +       u32 vio_idx;
> +
> +       for (vio_idx = 0; vio_idx < ctx->vio_idx_num; vio_idx++) {
> +               if (!mtk_devapc_dump_vio_dbg(ctx, vio_idx))
> +                       continue;
> +
> +               /* Ensure that violation info are written before
> +                * further operations
> +                */
> +               smp_mb();
> +
> +               /*
> +                * Mask slave's irq before clearing vio status.
> +                * Must do it to avoid nested interrupt and prevent
> +                * unexpected behavior.
> +                */
> +               mask_module_irq(ctx, vio_idx, true);
> +
> +               clear_vio_status(ctx, vio_idx);
> +
> +               mask_module_irq(ctx, vio_idx, false);
> +       }
> +
> +       return IRQ_HANDLED;
> +}
> +
> +/*
> + * start_devapc - initialize devapc status and start receiving interrupt
> + *                while devapc violation is triggered.
> + */
> +static int start_devapc(struct mtk_devapc_context *ctx)
> +{
> +       void __iomem *pd_vio_shift_sta_reg;
> +       void __iomem *pd_apc_con_reg;
> +       u32 vio_shift_sta;
> +       u32 vio_idx;
> +
> +       pd_apc_con_reg = ctx->devapc_pd_base + ctx->offset->apc_con;
> +       pd_vio_shift_sta_reg = ctx->devapc_pd_base + ctx->offset->vio_shift_sta;
> +       if (!pd_apc_con_reg || !pd_vio_shift_sta_reg)
> +               return -EINVAL;
> +
> +       /* Clear devapc violation status */
> +       writel(BIT(31), pd_apc_con_reg);
> +
> +       /* Clear violation shift status */
> +       vio_shift_sta = readl(pd_vio_shift_sta_reg);
> +       if (vio_shift_sta)
> +               writel(vio_shift_sta, pd_vio_shift_sta_reg);
> +
> +       /* Clear slave violation status */
> +       for (vio_idx = 0; vio_idx < ctx->vio_idx_num; vio_idx++) {
> +               clear_vio_status(ctx, vio_idx);
> +               mask_module_irq(ctx, vio_idx, false);
> +       }
> +

Why do you clear these? After power on hardware, I think these
register status are correct. If the default value of these register
are not correct, add a comment for this.

Regards,
Chun-Kuang.

> +       return 0;
> +}
> +

WARNING: multiple messages have this Message-ID (diff)
From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
To: Neal Liu <neal.liu@mediatek.com>
Cc: devicetree@vger.kernel.org,
	wsd_upstream <wsd_upstream@mediatek.com>,
	lkml <linux-kernel@vger.kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	"moderated list:ARM/Mediatek SoC support"
	<linux-mediatek@lists.infradead.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v3 2/2] soc: mediatek: add mtk-devapc driver
Date: Wed, 22 Jul 2020 07:21:35 +0800	[thread overview]
Message-ID: <CAAOTY_8T=DCntU8x5YEo+Pcs2J0Y4YvDaHUBdGiqEFRxghOd_Q@mail.gmail.com> (raw)
In-Reply-To: <1595303971-8793-3-git-send-email-neal.liu@mediatek.com>

Hi, Neal:

Neal Liu <neal.liu@mediatek.com> 於 2020年7月21日 週二 下午12:00寫道:
>
> MediaTek bus fabric provides TrustZone security support and data
> protection to prevent slaves from being accessed by unexpected
> masters.
> The security violation is logged and sent to the processor for
> further analysis or countermeasures.
>
> Any occurrence of security violation would raise an interrupt, and
> it will be handled by mtk-devapc driver. The violation
> information is printed in order to find the murderer.
>
> Signed-off-by: Neal Liu <neal.liu@mediatek.com>
> ---

[snip]

> +
> +static u32 get_shift_group(struct mtk_devapc_context *ctx, u32 vio_idx)

vio_idx is useless, so remove it.

> +{
> +       u32 vio_shift_sta;
> +       void __iomem *reg;
> +
> +       reg = ctx->devapc_pd_base + ctx->offset->vio_shift_sta;
> +       vio_shift_sta = readl(reg);
> +
> +       if (vio_shift_sta)
> +               return __ffs(vio_shift_sta);
> +
> +       return 31;
> +}
> +

[snip]

> +
> +/*
> + * mtk_devapc_dump_vio_dbg - get the violation index and dump the full violation
> + *                           debug information.
> + */
> +static bool mtk_devapc_dump_vio_dbg(struct mtk_devapc_context *ctx, u32 vio_idx)
> +{
> +       u32 shift_bit;
> +
> +       if (check_vio_mask(ctx, vio_idx))
> +               return false;
> +
> +       if (!check_vio_status(ctx, vio_idx))
> +               return false;
> +
> +       shift_bit = get_shift_group(ctx, vio_idx);
> +
> +       if (sync_vio_dbg(ctx, shift_bit))
> +               return false;
> +
> +       devapc_extract_vio_dbg(ctx);

I think get_shift_group(), sync_vio_dbg(), and
devapc_extract_vio_dbg() should be moved out of vio_idx for-loop (the
loop in devapc_violation_irq()) because these three function is not
related to vio_idx.
Another question: when multiple vio_idx violation occur, vio_addr is
related to which one vio_idx? The latest happened one?

> +
> +       return true;
> +}
> +
> +/*
> + * devapc_violation_irq - the devapc Interrupt Service Routine (ISR) will dump
> + *                        violation information including which master violates
> + *                        access slave.
> + */
> +static irqreturn_t devapc_violation_irq(int irq_number,
> +                                       struct mtk_devapc_context *ctx)
> +{
> +       u32 vio_idx;
> +
> +       for (vio_idx = 0; vio_idx < ctx->vio_idx_num; vio_idx++) {
> +               if (!mtk_devapc_dump_vio_dbg(ctx, vio_idx))
> +                       continue;
> +
> +               /* Ensure that violation info are written before
> +                * further operations
> +                */
> +               smp_mb();
> +
> +               /*
> +                * Mask slave's irq before clearing vio status.
> +                * Must do it to avoid nested interrupt and prevent
> +                * unexpected behavior.
> +                */
> +               mask_module_irq(ctx, vio_idx, true);
> +
> +               clear_vio_status(ctx, vio_idx);
> +
> +               mask_module_irq(ctx, vio_idx, false);
> +       }
> +
> +       return IRQ_HANDLED;
> +}
> +
> +/*
> + * start_devapc - initialize devapc status and start receiving interrupt
> + *                while devapc violation is triggered.
> + */
> +static int start_devapc(struct mtk_devapc_context *ctx)
> +{
> +       void __iomem *pd_vio_shift_sta_reg;
> +       void __iomem *pd_apc_con_reg;
> +       u32 vio_shift_sta;
> +       u32 vio_idx;
> +
> +       pd_apc_con_reg = ctx->devapc_pd_base + ctx->offset->apc_con;
> +       pd_vio_shift_sta_reg = ctx->devapc_pd_base + ctx->offset->vio_shift_sta;
> +       if (!pd_apc_con_reg || !pd_vio_shift_sta_reg)
> +               return -EINVAL;
> +
> +       /* Clear devapc violation status */
> +       writel(BIT(31), pd_apc_con_reg);
> +
> +       /* Clear violation shift status */
> +       vio_shift_sta = readl(pd_vio_shift_sta_reg);
> +       if (vio_shift_sta)
> +               writel(vio_shift_sta, pd_vio_shift_sta_reg);
> +
> +       /* Clear slave violation status */
> +       for (vio_idx = 0; vio_idx < ctx->vio_idx_num; vio_idx++) {
> +               clear_vio_status(ctx, vio_idx);
> +               mask_module_irq(ctx, vio_idx, false);
> +       }
> +

Why do you clear these? After power on hardware, I think these
register status are correct. If the default value of these register
are not correct, add a comment for this.

Regards,
Chun-Kuang.

> +       return 0;
> +}
> +

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

WARNING: multiple messages have this Message-ID (diff)
From: Chun-Kuang Hu <chunkuang.hu@kernel.org>
To: Neal Liu <neal.liu@mediatek.com>
Cc: devicetree@vger.kernel.org,
	wsd_upstream <wsd_upstream@mediatek.com>,
	lkml <linux-kernel@vger.kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	"moderated list:ARM/Mediatek SoC support"
	<linux-mediatek@lists.infradead.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v3 2/2] soc: mediatek: add mtk-devapc driver
Date: Wed, 22 Jul 2020 07:21:35 +0800	[thread overview]
Message-ID: <CAAOTY_8T=DCntU8x5YEo+Pcs2J0Y4YvDaHUBdGiqEFRxghOd_Q@mail.gmail.com> (raw)
In-Reply-To: <1595303971-8793-3-git-send-email-neal.liu@mediatek.com>

Hi, Neal:

Neal Liu <neal.liu@mediatek.com> 於 2020年7月21日 週二 下午12:00寫道:
>
> MediaTek bus fabric provides TrustZone security support and data
> protection to prevent slaves from being accessed by unexpected
> masters.
> The security violation is logged and sent to the processor for
> further analysis or countermeasures.
>
> Any occurrence of security violation would raise an interrupt, and
> it will be handled by mtk-devapc driver. The violation
> information is printed in order to find the murderer.
>
> Signed-off-by: Neal Liu <neal.liu@mediatek.com>
> ---

[snip]

> +
> +static u32 get_shift_group(struct mtk_devapc_context *ctx, u32 vio_idx)

vio_idx is useless, so remove it.

> +{
> +       u32 vio_shift_sta;
> +       void __iomem *reg;
> +
> +       reg = ctx->devapc_pd_base + ctx->offset->vio_shift_sta;
> +       vio_shift_sta = readl(reg);
> +
> +       if (vio_shift_sta)
> +               return __ffs(vio_shift_sta);
> +
> +       return 31;
> +}
> +

[snip]

> +
> +/*
> + * mtk_devapc_dump_vio_dbg - get the violation index and dump the full violation
> + *                           debug information.
> + */
> +static bool mtk_devapc_dump_vio_dbg(struct mtk_devapc_context *ctx, u32 vio_idx)
> +{
> +       u32 shift_bit;
> +
> +       if (check_vio_mask(ctx, vio_idx))
> +               return false;
> +
> +       if (!check_vio_status(ctx, vio_idx))
> +               return false;
> +
> +       shift_bit = get_shift_group(ctx, vio_idx);
> +
> +       if (sync_vio_dbg(ctx, shift_bit))
> +               return false;
> +
> +       devapc_extract_vio_dbg(ctx);

I think get_shift_group(), sync_vio_dbg(), and
devapc_extract_vio_dbg() should be moved out of vio_idx for-loop (the
loop in devapc_violation_irq()) because these three function is not
related to vio_idx.
Another question: when multiple vio_idx violation occur, vio_addr is
related to which one vio_idx? The latest happened one?

> +
> +       return true;
> +}
> +
> +/*
> + * devapc_violation_irq - the devapc Interrupt Service Routine (ISR) will dump
> + *                        violation information including which master violates
> + *                        access slave.
> + */
> +static irqreturn_t devapc_violation_irq(int irq_number,
> +                                       struct mtk_devapc_context *ctx)
> +{
> +       u32 vio_idx;
> +
> +       for (vio_idx = 0; vio_idx < ctx->vio_idx_num; vio_idx++) {
> +               if (!mtk_devapc_dump_vio_dbg(ctx, vio_idx))
> +                       continue;
> +
> +               /* Ensure that violation info are written before
> +                * further operations
> +                */
> +               smp_mb();
> +
> +               /*
> +                * Mask slave's irq before clearing vio status.
> +                * Must do it to avoid nested interrupt and prevent
> +                * unexpected behavior.
> +                */
> +               mask_module_irq(ctx, vio_idx, true);
> +
> +               clear_vio_status(ctx, vio_idx);
> +
> +               mask_module_irq(ctx, vio_idx, false);
> +       }
> +
> +       return IRQ_HANDLED;
> +}
> +
> +/*
> + * start_devapc - initialize devapc status and start receiving interrupt
> + *                while devapc violation is triggered.
> + */
> +static int start_devapc(struct mtk_devapc_context *ctx)
> +{
> +       void __iomem *pd_vio_shift_sta_reg;
> +       void __iomem *pd_apc_con_reg;
> +       u32 vio_shift_sta;
> +       u32 vio_idx;
> +
> +       pd_apc_con_reg = ctx->devapc_pd_base + ctx->offset->apc_con;
> +       pd_vio_shift_sta_reg = ctx->devapc_pd_base + ctx->offset->vio_shift_sta;
> +       if (!pd_apc_con_reg || !pd_vio_shift_sta_reg)
> +               return -EINVAL;
> +
> +       /* Clear devapc violation status */
> +       writel(BIT(31), pd_apc_con_reg);
> +
> +       /* Clear violation shift status */
> +       vio_shift_sta = readl(pd_vio_shift_sta_reg);
> +       if (vio_shift_sta)
> +               writel(vio_shift_sta, pd_vio_shift_sta_reg);
> +
> +       /* Clear slave violation status */
> +       for (vio_idx = 0; vio_idx < ctx->vio_idx_num; vio_idx++) {
> +               clear_vio_status(ctx, vio_idx);
> +               mask_module_irq(ctx, vio_idx, false);
> +       }
> +

Why do you clear these? After power on hardware, I think these
register status are correct. If the default value of these register
are not correct, add a comment for this.

Regards,
Chun-Kuang.

> +       return 0;
> +}
> +

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-07-21 23:21 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21  3:59 [PATCH v3] Add MediaTek MT6779 devapc driver Neal Liu
2020-07-21  3:59 ` Neal Liu
2020-07-21  3:59 ` Neal Liu
2020-07-21  3:59 ` [PATCH v3 1/2] dt-bindings: devapc: add bindings for mtk-devapc Neal Liu
2020-07-21  3:59   ` Neal Liu
2020-07-21  3:59   ` Neal Liu
2020-07-21  3:59 ` [PATCH v3 2/2] soc: mediatek: add mtk-devapc driver Neal Liu
2020-07-21  3:59   ` Neal Liu
2020-07-21  3:59   ` Neal Liu
2020-07-21 23:21   ` Chun-Kuang Hu [this message]
2020-07-21 23:21     ` Chun-Kuang Hu
2020-07-21 23:21     ` Chun-Kuang Hu
2020-07-22  3:49     ` Neal Liu
2020-07-22  3:49       ` Neal Liu
2020-07-22  3:49       ` Neal Liu
2020-07-22 14:25       ` Chun-Kuang Hu
2020-07-22 14:25         ` Chun-Kuang Hu
2020-07-22 14:25         ` Chun-Kuang Hu
2020-07-23  6:11         ` Neal Liu
2020-07-23  6:11           ` Neal Liu
2020-07-23  6:11           ` Neal Liu
2020-07-23 16:32           ` Chun-Kuang Hu
2020-07-23 16:32             ` Chun-Kuang Hu
2020-07-23 16:32             ` Chun-Kuang Hu
2020-07-24  6:55             ` Neal Liu
2020-07-24  6:55               ` Neal Liu
2020-07-24  6:55               ` Neal Liu
2020-07-24 15:55               ` Chun-Kuang Hu
2020-07-24 15:55                 ` Chun-Kuang Hu
2020-07-24 15:55                 ` Chun-Kuang Hu
2020-07-27  3:05                 ` Neal Liu
2020-07-27  3:05                   ` Neal Liu
2020-07-27  3:05                   ` Neal Liu
2020-07-27 14:47                   ` Chun-Kuang Hu
2020-07-27 14:47                     ` Chun-Kuang Hu
2020-07-27 14:47                     ` Chun-Kuang Hu
2020-07-28  3:52                     ` Neal Liu
2020-07-28  3:52                       ` Neal Liu
2020-07-28  3:52                       ` Neal Liu
2020-07-28 15:35                       ` Chun-Kuang Hu
2020-07-28 15:35                         ` Chun-Kuang Hu
2020-07-28 15:35                         ` Chun-Kuang Hu
2020-07-29  2:10                         ` Neal Liu
2020-07-29  2:10                           ` Neal Liu
2020-07-29  2:10                           ` Neal Liu
2020-07-29  2:22                           ` Chun-Kuang Hu
2020-07-29  2:22                             ` Chun-Kuang Hu
2020-07-29  2:22                             ` Chun-Kuang Hu
2020-07-29  3:15                             ` Neal Liu
2020-07-29  3:15                               ` Neal Liu
2020-07-29  3:15                               ` Neal Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAOTY_8T=DCntU8x5YEo+Pcs2J0Y4YvDaHUBdGiqEFRxghOd_Q@mail.gmail.com' \
    --to=chunkuang.hu@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=neal.liu@mediatek.com \
    --cc=robh+dt@kernel.org \
    --cc=wsd_upstream@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.