Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2176334pxa; Mon, 3 Aug 2020 09:17:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXVs8+8Y/0zKEVk26FR/hDo8KXaVfYEiYtSkRevC0PLnlEAPcT/7PrLI2IURnC806YAYu+ X-Received: by 2002:a17:906:38d8:: with SMTP id r24mr16883294ejd.341.1596471422551; Mon, 03 Aug 2020 09:17:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596471422; cv=none; d=google.com; s=arc-20160816; b=RAfqVKXZvvRrgZyqbkILQtrFW1aKbeyMCiIAbwll4rLdF4yw/q8fuM2YxehHqNCPVv No2NkDMOu3lf/bHabS+msfL6mOBDLFoqfg5Q4WZN8jNWWoD+28IVeeOJsh/YotM5N2It Tzh5GfYGwl4yg4UXoJWU9xB7d7XowsM/mGgkZQTqcohgLSX/11DE+E15WcND3AEDjU+t aNVKnKbBFX8xcfiGVAH9JTAijVgd5zZ0Ks/gqe9svszBzteab7NsZrVeuIQKjGhQtyjd DA5Q+deJuN7F4tCUP9jiY46kI/Nce5hrIu/1B5DAbhEOHLv6mKSR1nSY1iVnKjLoDQC8 1XeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=imGyG0IdK959x72IqfBfY7c7+5z1xRzzlWzpKGlHsdo=; b=WPmKgYOqQDs5f8hY03BOdc63CkANRYNcL205/vHHwzP25ZMXr3ofm8H/WBBbINqrPf Fu7XJbgJ4+WkqMZxr3r0zboRbwy7Ob/SSj5iU4tSiI1MJjjLiEdjw+/fd6TngmBLVNpk Byt8aViw6+wXB7XmlUMGb9jOAsWnXkYgHDc7ZIomw80TjkI/EJg313CovWofrNj0UJxy oEmNG8zSl6zUoGRQmDAi5wJAYYIkqnPU54rfgtOirXtfbpMqhNTScV/2cl3ghJgrukq1 ib3DA1aNrn/UsnKfpH/vsJ2dfXpKjMX4vigYtO2Nz+8HntfEYQV/sPJXf4IPMmTTsS8L BztA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X5IxzLoG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si10664221edp.166.2020.08.03.09.16.39; Mon, 03 Aug 2020 09:17:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X5IxzLoG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728003AbgHCQNj (ORCPT + 99 others); Mon, 3 Aug 2020 12:13:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:49638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726489AbgHCQNj (ORCPT ); Mon, 3 Aug 2020 12:13:39 -0400 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2A9792177B; Mon, 3 Aug 2020 16:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596471217; bh=HiU07JR1A+F1+Z53kyhPMkQd/qW5e56jQ2jPVulC8+4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=X5IxzLoGXGhZ8Bs4qDZQdy04EZQYbwGYyq5pZ6j4Y154+ryCc3QMwHdQGC5v1tq34 4A2h7BH/2Cmd0xibFPwmhNDUoaeGWgtGGAg/l/XlMLE6LQt0g8m2WA7gn23Ll+ewgf tIcyXRtGkEbtd56lShh1UKfNr4Icfv8vx+v7EjRM= Received: by mail-ed1-f47.google.com with SMTP id c15so17971886edj.3; Mon, 03 Aug 2020 09:13:38 -0700 (PDT) X-Gm-Message-State: AOAM531C3bNxd0t4jnJ3tjFqY2g8Cuo5ojtyqNC/ONzD6BxnnEgAQdhp QcxVuh52zaOUAT3Xg18+xmrX/2M5UMQg2D+U6w== X-Received: by 2002:a50:d2c7:: with SMTP id q7mr11624009edg.61.1596471216633; Mon, 03 Aug 2020 09:13:36 -0700 (PDT) MIME-Version: 1.0 References: <1596010690-13178-1-git-send-email-neal.liu@mediatek.com> <1596010690-13178-3-git-send-email-neal.liu@mediatek.com> <1596163478.3932.17.camel@mtkswgap22> <1596425521.22971.13.camel@mtkswgap22> In-Reply-To: <1596425521.22971.13.camel@mtkswgap22> From: Chun-Kuang Hu Date: Tue, 4 Aug 2020 00:13:23 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 2/2] soc: mediatek: add mtk-devapc driver To: Neal Liu Cc: Chun-Kuang Hu , Rob Herring , Matthias Brugger , devicetree@vger.kernel.org, wsd_upstream , lkml , "moderated list:ARM/Mediatek SoC support" , Linux ARM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Neal: Neal Liu =E6=96=BC 2020=E5=B9=B48=E6=9C=883=E6=97= =A5 =E9=80=B1=E4=B8=80 =E4=B8=8A=E5=8D=8811:32=E5=AF=AB=E9=81=93=EF=BC=9A > > Hi Chun-Kuang, > > On Fri, 2020-07-31 at 23:03 +0800, Chun-Kuang Hu wrote: > > Hi, Neal: > > > > Neal Liu =E6=96=BC 2020=E5=B9=B47=E6=9C=8831=E6= =97=A5 =E9=80=B1=E4=BA=94 =E4=B8=8A=E5=8D=8810:44=E5=AF=AB=E9=81=93=EF=BC= =9A > > > > > > Hi Chun-Kuang, > > > > > > > > > On Thu, 2020-07-30 at 00:38 +0800, Chun-Kuang Hu wrote: > > > > Hi, Neal: > > > > > > > > Neal Liu =E6=96=BC 2020=E5=B9=B47=E6=9C=882= 9=E6=97=A5 =E9=80=B1=E4=B8=89 =E4=B8=8B=E5=8D=884:29=E5=AF=AB=E9=81=93=EF= =BC=9A > > > > > > > > > > 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, an= d > > > > > it will be handled by mtk-devapc driver. The violation > > > > > information is printed in order to find the murderer. > > > > > > > > > > Signed-off-by: Neal Liu > > > > > --- > > > > > > > > [snip] > > > > > > > > > + > > > > > +/* > > > > > + * devapc_extract_vio_dbg - extract full violation information a= fter doing > > > > > + * shift mechanism. > > > > > + */ > > > > > +static void devapc_extract_vio_dbg(struct mtk_devapc_context *ct= x) > > > > > +{ > > > > > + const struct mtk_devapc_vio_dbgs *vio_dbgs; > > > > > + struct mtk_devapc_vio_info *vio_info; > > > > > + void __iomem *vio_dbg0_reg; > > > > > + void __iomem *vio_dbg1_reg; > > > > > + u32 dbg0; > > > > > + > > > > > + vio_dbg0_reg =3D ctx->devapc_pd_base + ctx->offset->vio_d= bg0; > > > > > + vio_dbg1_reg =3D ctx->devapc_pd_base + ctx->offset->vio_d= bg1; > > > > > + > > > > > + vio_dbgs =3D ctx->vio_dbgs; > > > > > + vio_info =3D ctx->vio_info; > > > > > + > > > > > + /* Starts to extract violation information */ > > > > > + dbg0 =3D readl(vio_dbg0_reg); > > > > > + vio_info->vio_addr =3D readl(vio_dbg1_reg); > > > > > + > > > > > + vio_info->master_id =3D (dbg0 & vio_dbgs->mstid.mask) >> > > > > > + vio_dbgs->mstid.start; > > > > > > > > What is master_id? How could we use it to debug? For example, if we > > > > get a master_id =3D 1, what should we do for this? > > > > > > > > > + vio_info->domain_id =3D (dbg0 & vio_dbgs->dmnid.mask) >> > > > > > + vio_dbgs->dmnid.start; > > > > > > > > What is domain_id? How could we use it to debug? For example, if we > > > > get a domain_id =3D 2, what should we do for this? > > > > > > > > > > master_id and domain_id belongs our bus side-band signal info. It can > > > help us to find the violation master. > > > > Does 'violation master' means the hardware could access the protected > > register? (ex. CPU, GCE, ...) If so, I think it's better to add > > comment to explain how to map (master_id, domain_id) to a hardware > > (maybe the device in device tree) because every body does not know > > what the number means. Don't try to translate the number to a string > > because this would cost much time to do this. Just print a number and > > we could find out the master by the comment. > > 'violation master' means the master which violates the permission > control. For example, if we set permission 'Secure R/W only' as CPU to > spi register. When violation is triggered, it means CPU access spi > register through normal world instead of secure world, which is not > allowed. > > 'master_id' cannot use the simple comments to describe which master it > is. It depends on violation slaves. For example, if there are two > violations: > 1. CPU access spi reg > 2. CPU access timer reg > It might be different 'master_id' for CPU on these two cases. > I would prefer to remain the id number if translate to a string is a bad > idea. > Thanks ! It seams that master_id and domain_id does not help for debug. When we get master_id =3D 1 and domain_id =3D 2, we don't know what it mean. I think we just need violation address because we could find the driver that write this address and the bug would be inside this driver. So need not to process master_id and domain_id. Regards, Chun-Kuang. > > > > > > > > > > > + vio_info->write =3D ((dbg0 & vio_dbgs->vio_w.mask) >> > > > > > + vio_dbgs->vio_w.start) =3D=3D 1; > > > > > + vio_info->read =3D ((dbg0 & vio_dbgs->vio_r.mask) >> > > > > > + vio_dbgs->vio_r.start) =3D=3D 1; > > > > > + vio_info->vio_addr_high =3D (dbg0 & vio_dbgs->addr_h.mask= ) >> > > > > > + vio_dbgs->addr_h.start; > > > > > > > > What is vio_addr_high? As I know all register address are 32 bits, = is > > > > vio_addr_high the address above 32 bits? > > > > > > Yes, you are right. In MT6779, all register base are 32 bits. We can > > > ignore this info for current driver. I'll update on next patch. > > > Thanks ! > > > > Such a strange hardware, all register is 32 bits but it has a > > vio_addr_high in its register. OK, just drop this. > > > > > > > > > > > > > > + > > > > > + devapc_vio_info_print(ctx); > > > > > +} > > > > > + > > > >