When running under a secure monitor, some peripherals are setup as accessible
by secure world only. When those peripherals are system controllers, they might
need to be accessed by the normal world for some peripheral configuration.
In order to keep the existing code working for such devices (which usually uses
the regmap from a syscon), this series adds support for a regmap that uses SMCs
(Secure Monitor Call) to request access to registers. The secure monitor will
then catch these accesses and decide whether or not the normal world is allowed
to access the requested register.
As said, most drivers that needs access to registers that are shared in a system
controller often uses syscon. Currently, syscon uses a regmap_mmio which allows
to read and write registers using MMIO accesses. Support is added in this series
to also support "syscon-smc" compatible which will use a SMC regmap instead of a
MMIO one.
Clément Léger (3):
regmap: add regmap using ARM SMCCC
syscon: add support for "syscon-smc" compatible
dt-bindings: mfd: add "syscon-smc" YAML description
.../devicetree/bindings/mfd/syscon-smc.yaml | 57 ++++++
drivers/base/regmap/Kconfig | 7 +-
drivers/base/regmap/Makefile | 1 +
drivers/base/regmap/regmap-smccc.c | 131 ++++++++++++++
drivers/mfd/syscon.c | 170 +++++++++++++++---
include/linux/regmap.h | 38 ++++
6 files changed, 378 insertions(+), 26 deletions(-)
create mode 100644 Documentation/devicetree/bindings/mfd/syscon-smc.yaml
create mode 100644 drivers/base/regmap/regmap-smccc.c
--
2.32.0
When running under secure monitor control, some controllers can be placed in
secure world and their access is thus not possible from normal world. However,
these controllers frequently contain registers than are needed by the normal
world for a few specific operations.
This patch adds a regmap where registers are accessed using SMCs. The secure
monitor is then responsible to allow or deny access to the requested registers.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
drivers/base/regmap/Kconfig | 7 +-
drivers/base/regmap/Makefile | 1 +
drivers/base/regmap/regmap-smccc.c | 131 +++++++++++++++++++++++++++++
include/linux/regmap.h | 38 +++++++++
4 files changed, 176 insertions(+), 1 deletion(-)
create mode 100644 drivers/base/regmap/regmap-smccc.c
@@ -4,7 +4,7 @@# subsystems should select the appropriate symbols.configREGMAP-defaultyif(REGMAP_I2C||REGMAP_SPI||REGMAP_SPMI||REGMAP_W1||REGMAP_AC97||REGMAP_MMIO||REGMAP_IRQ||REGMAP_SOUNDWIRE||REGMAP_SOUNDWIRE_MBQ||REGMAP_SCCB||REGMAP_I3C||REGMAP_SPI_AVMM||REGMAP_MDIO)+defaultyif(REGMAP_I2C||REGMAP_SPI||REGMAP_SPMI||REGMAP_W1||REGMAP_AC97||REGMAP_MMIO||REGMAP_IRQ||REGMAP_SOUNDWIRE||REGMAP_SOUNDWIRE_MBQ||REGMAP_SCCB||REGMAP_I3C||REGMAP_SPI_AVMM||REGMAP_MDIO||REGMAP_SMCCC)selectIRQ_DOMAINifREGMAP_IRQselectMDIO_BUSifREGMAP_MDIObool
From: Mark Brown <broonie@kernel.org> Date: 2021-07-23 14:43:27
On Fri, Jul 23, 2021 at 03:52:37PM +0200, Clément Léger wrote:
When running under secure monitor control, some controllers can be placed in
secure world and their access is thus not possible from normal world. However,
these controllers frequently contain registers than are needed by the normal
world for a few specific operations.
This patch adds a regmap where registers are accessed using SMCs. The secure
monitor is then responsible to allow or deny access to the requested registers.
I can't see any SMC specification for this interface? Frankly I have
some very substantial concerns about the use case for this over exposing
the functionality of whatever device the SMC is gating access to through
SMC interfaces specific to that functionality. Exposing raw access to a
(presumed?) subset of whatever device functionality feels like the wrong
abstraction level to be working at and like an invitation to system
integrators to do things that are going to get them into trouble down
the line.
If the end user really is just twiddling a few bits here and there I'd
expect those functionality specific services to be pretty simple to do,
slightly more effort on the secure monitor side but a lot safer. If
there is a use case for passing through an entire device for some reason
(ran out of controllers or something?) then I think we probably want an
abstraction at the bus level so we don't need to add custom support to
every device that we want to pass through and it's clear what's going on.
Hi Mark,
Le Fri, 23 Jul 2021 15:43:18 +0100,
Mark Brown [off-list ref] a écrit :
On Fri, Jul 23, 2021 at 03:52:37PM +0200, Clément Léger wrote:
quoted
When running under secure monitor control, some controllers can be
placed in secure world and their access is thus not possible from
normal world. However, these controllers frequently contain
registers than are needed by the normal world for a few specific
operations.
quoted
This patch adds a regmap where registers are accessed using SMCs.
The secure monitor is then responsible to allow or deny access to
the requested registers.
I can't see any SMC specification for this interface? Frankly I have
some very substantial concerns about the use case for this over
exposing the functionality of whatever device the SMC is gating
access to through SMC interfaces specific to that functionality.
This would require to modify drivers to check if the access should be
done using SMCs, parse the device tree to find appropriate SMC ids for
each functionality, add dependencies in KConfig on
HAVE_ARM_SMCCC_DISCOVERY, and do SMC calls instead of regmap access.
I'm not saying this is not the way to go but this is clearly more
intrusive than keeping the existing syscon support.
Exposing raw access to a (presumed?) subset of whatever device
functionality feels like the wrong abstraction level to be working at
and like an invitation to system integrators to do things that are
going to get them into trouble down the line.
Indeed, access is reduced to a subset of registers offset which are
checked by the TEE.
If the end user really is just twiddling a few bits here and there I'd
expect those functionality specific services to be pretty simple to
do, slightly more effort on the secure monitor side but a lot safer.
The SMC id is supposed to be unique for a given device. The TEE check is
merely a register offset check and a value check. But I agree that the
attack surface is larger than with a SMC targeted for a single
functionality though.
If there is a use case for passing through an entire device for some
reason (ran out of controllers or something?) then I think we
probably want an abstraction at the bus level so we don't need to add
custom support to every device that we want to pass through and it's
clear what's going on.
In our use case, only a few registers located in a secure controller
is needed to be done. We don't have a use case for an entire device
access.
Clément
From: Mark Brown <broonie@kernel.org> Date: 2021-07-23 16:38:12
On Fri, Jul 23, 2021 at 05:53:15PM +0200, Clément Léger wrote:
Mark Brown [off-list ref] a écrit :
quoted
I can't see any SMC specification for this interface? Frankly I have
some very substantial concerns about the use case for this over
exposing the functionality of whatever device the SMC is gating
access to through SMC interfaces specific to that functionality.
This would require to modify drivers to check if the access should be
done using SMCs, parse the device tree to find appropriate SMC ids for
each functionality, add dependencies in KConfig on
HAVE_ARM_SMCCC_DISCOVERY, and do SMC calls instead of regmap access.
I'm not saying this is not the way to go but this is clearly more
intrusive than keeping the existing syscon support.
You're not doing this at the syscon level, you're doing this at the
regmap level. Any user of this code is going to have to be modified to
use the SMCCC regmap and discover the relevant SMCCC interfaces no
matter what, but by having it we're saying that that's a sensible and
reasonable thing to do and encouraging implementations as a result.
Device specific regmap interfaces do not require adding anything to the
core, there's the reg_read() and reg_write() callbacks for this, if
there is a sensible use case for this at the syscon level and only the
syscon level (but I really do strongly question if it's a good idea at
all) then you can use those without adding a generic interface for
defining SMCCC conduits as regmaps. TBH what's being added to the
regmap core is so trival that I don't see what we'd be gaining anyway
even if this was widely used, it's not helping with the SMCCC
enumeration side at all.
quoted
Exposing raw access to a (presumed?) subset of whatever device
functionality feels like the wrong abstraction level to be working at
and like an invitation to system integrators to do things that are
going to get them into trouble down the line.
Indeed, access is reduced to a subset of registers offset which are
checked by the TEE.
I really think it would be clearer and safer to have the TEE expose
specific operations that encode the intent of whatever it is trying to
accomplish rather than just expose the register map and then audit the
operations that are going on in the register map after the fact. It
seems like it's going to be more error prone to do things this way,
especially as this starts getting used as a generic pipe for exposing
things and things get built up - as well as auditing concerns if any
problems are identified it's going to be harder to track the intent of
what the non-secure world is doing.
System controllers can be placed under secure monitor control when running
under them. In order to keep existing code which accesses such system
controllers using a syscon, add support for "syscon-smc" compatible.
When enable, the syscon will handle this new compatible and look for an
"arm,smc-id" property to execute the appropriate SMC. A SMC regmap is then
created to forward register access to the secure monitor.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
drivers/mfd/syscon.c | 170 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 145 insertions(+), 25 deletions(-)
From: Lee Jones <hidden> Date: 2021-07-23 15:29:51
On Fri, 23 Jul 2021, Clément Léger wrote:
System controllers can be placed under secure monitor control when running
under them. In order to keep existing code which accesses such system
controllers using a syscon, add support for "syscon-smc" compatible.
When enable, the syscon will handle this new compatible and look for an
"arm,smc-id" property to execute the appropriate SMC. A SMC regmap is then
created to forward register access to the secure monitor.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
drivers/mfd/syscon.c | 170 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 145 insertions(+), 25 deletions(-)
I'm going to let Arnd have at this, but just a couple of points.
Le Fri, 23 Jul 2021 16:27:59 +0100,
Lee Jones [off-list ref] a écrit :
On Fri, 23 Jul 2021, Clément Léger wrote:
quoted
System controllers can be placed under secure monitor control when
running under them. In order to keep existing code which accesses
such system controllers using a syscon, add support for
"syscon-smc" compatible.
When enable, the syscon will handle this new compatible and look
for an "arm,smc-id" property to execute the appropriate SMC. A SMC
regmap is then created to forward register access to the secure
monitor.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
drivers/mfd/syscon.c | 170
++++++++++++++++++++++++++++++++++++------- 1 file changed, 145
insertions(+), 25 deletions(-)
I'm going to let Arnd have at this, but just a couple of points.
... and we certainly don't want to be doing so using #ifdefery.
Please find a better way to support this feature.
Agreed too, best solution would probably be to allow having multiple
syscon "backends" split in multiple files which would create the
correct regmap according to the devicetree.
Clément
quoted
+ else
+ syscon = of_syscon_register_mmio(np,
check_clk); +
+ if (!IS_ERR(syscon))
+ syscon_add(syscon);
+ }
if (IS_ERR(syscon))
return ERR_CAST(syscon);
On Fri, Jul 23, 2021 at 3:52 PM Clément Léger [off-list ref] wrote:
System controllers can be placed under secure monitor control when running
under them. In order to keep existing code which accesses such system
controllers using a syscon, add support for "syscon-smc" compatible.
When enable, the syscon will handle this new compatible and look for an
"arm,smc-id" property to execute the appropriate SMC. A SMC regmap is then
created to forward register access to the secure monitor.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
I don't see anything wrong with the implementation, but this worries
me conceptually, because of the ways this might get abused:
- this creates one more way to keep device drivers hidden away
behind firmware when they should be in the kernel. You can already
do that with separate SMC calls, but adding an indirection makes it
sneakier. If the 'registers' in here are purely
- This may be seen as an easy way out for firmware writers that just
expose a bare register-level interface when the correct solution would
be to create a high-level interface.
There is also a problem with locking: In the case that both firmware and
kernel have to access registers within a syscon area, you may need to
have a semaphore to protect an atomic sequence of accesses, but since
the interface only provides a single register load/store, there is no way for
a kernel driver to serialize against a firmware-internal driver.
Arnd
From: Mark Brown <broonie@kernel.org> Date: 2021-07-23 16:42:08
On Fri, Jul 23, 2021 at 06:07:44PM +0200, Arnd Bergmann wrote:
There is also a problem with locking: In the case that both firmware and
kernel have to access registers within a syscon area, you may need to
have a semaphore to protect an atomic sequence of accesses, but since
the interface only provides a single register load/store, there is no way for
a kernel driver to serialize against a firmware-internal driver.
The standard solution to this for the read/modify/write case would be to
expose an explicit update_bits() operation (some hardware does this for
concurrency and/or bus bandwidth/latency reasons), though that doesn't
help with larger or multi-register sequences (and to be clear as I've
been saying I don't think we should do this at all).
From: Peng Fan (OSS) <hidden> Date: 2021-07-24 12:36:38
Subject: Re: [PATCH 2/3] syscon: add support for "syscon-smc" compatible
On Fri, Jul 23, 2021 at 3:52 PM Clément Léger [off-list ref]
wrote:
quoted
System controllers can be placed under secure monitor control when
running under them. In order to keep existing code which accesses such
system controllers using a syscon, add support for "syscon-smc" compatible.
When enable, the syscon will handle this new compatible and look for
an "arm,smc-id" property to execute the appropriate SMC. A SMC regmap
is then created to forward register access to the secure monitor.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
I don't see anything wrong with the implementation,
I also vote for such an implementation. Such as we have a chip has a misc
register space, part as below:
44h USB Wake-up Control Register (DGO 10) (USB_WAKEUP)
48h PTD Pads Compensation Cell Configuration Register
4Ch Lower CA35 TS Timer First Compare Value (TSTMR_CMP0_VAL_L)
50h Upper CA35 TS Timer First Compare Value
54h Lower CA35 TS Timer Second Compare value
58h Upper CA35 TS Timer Second Compare Value
5Ch CA35 Core0 Reset Vector Base Address (DGO 8) (RVBARADDR0)
60h CA35 Core1 Reset Vector Base Address (DGO 9) (RVBARADDR1)
64h Medium Quality Sound Configuration Register (MQS1_CF) 32 RW 0100_0000h
It contains several functions, we need protect 5Ch, 60h to avoid
Non-secure world modify it. Others could be directly used by Linux kernel.
But we could only hide the whole register space in secure world to make
5C/60h register not touch by linux.
We not find a good way to provide high-level interface for such
a misc register space, provide register level interface would make
it easy for various drivers to use.
Thanks,
Peng.
but this worries me
conceptually, because of the ways this might get abused:
- this creates one more way to keep device drivers hidden away
behind firmware when they should be in the kernel. You can already
do that with separate SMC calls, but adding an indirection makes it
sneakier. If the 'registers' in here are purely
- This may be seen as an easy way out for firmware writers that just
expose a bare register-level interface when the correct solution would
be to create a high-level interface.
There is also a problem with locking: In the case that both firmware and
kernel have to access registers within a syscon area, you may need to have a
semaphore to protect an atomic sequence of accesses, but since the interface
only provides a single register load/store, there is no way for a kernel driver to
serialize against a firmware-internal driver.
Arnd
This patch adds documentation for the "syscon-smc" compatible which describes
a syscon using a SMC regmap instead of a MMIO one. This allows accessing system
controllers that are set as secure by using SMC handled by the secure monitor.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
.../devicetree/bindings/mfd/syscon-smc.yaml | 57 +++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mfd/syscon-smc.yaml
@@ -0,0 +1,57 @@+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)+%YAML1.2+---+$id:http://devicetree.org/schemas/mfd/syscon-smc.yaml#+$schema:http://devicetree.org/meta-schemas/core.yaml#++title:System Controller Registers R/W via SMC Device Tree Bindings++description:|+System controller SMC node represents a register region containing a set+of miscellaneous registers accessed through a secure monitor.+The typical use-case is the same as the syscon one but when running with a+secure monitor.++maintainers:+-Lee Jones <lee.jones@linaro.org>++properties:+compatible:+anyOf:+-items:+-enum:+-atmel,sama5d2-sfr++-const:syscon-smc++-contains:+const:syscon-smc+minItems:2+maxItems:4# Should be enough++arm,smc-id:+$ref:/schemas/types.yaml#/definitions/uint32+description:|+The ATF smc function id used by the firmware.++reg-io-width:+description:|+The size (in bytes) of the IO accesses that should be performed+on the device.+$ref:/schemas/types.yaml#/definitions/uint32+enum:[1,2,4,8]++required:+-compatible+-arm,smc-id++additionalProperties:false++examples:+-|+sfr {+compatible = "atmel,sama5d2-sfr", "syscon-smc";+arm,smc-id = <0x02000300>;+};++...
From: Rob Herring <robh@kernel.org> Date: 2021-07-29 21:19:26
On Fri, Jul 23, 2021 at 03:52:39PM +0200, Clément Léger wrote:
quoted hunk
This patch adds documentation for the "syscon-smc" compatible which describes
a syscon using a SMC regmap instead of a MMIO one. This allows accessing system
controllers that are set as secure by using SMC handled by the secure monitor.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
.../devicetree/bindings/mfd/syscon-smc.yaml | 57 +++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mfd/syscon-smc.yaml
@@ -0,0 +1,57 @@+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)+%YAML1.2+---+$id:http://devicetree.org/schemas/mfd/syscon-smc.yaml#+$schema:http://devicetree.org/meta-schemas/core.yaml#++title:System Controller Registers R/W via SMC Device Tree Bindings++description:|+System controller SMC node represents a register region containing a set+of miscellaneous registers accessed through a secure monitor.+The typical use-case is the same as the syscon one but when running with a+secure monitor.++maintainers:+-Lee Jones <lee.jones@linaro.org>++properties:+compatible:+anyOf:+-items:+-enum:+-atmel,sama5d2-sfr++-const:syscon-smc
I regret having 'syscon' as a compatible, so nak on a 2nd flavor of it.
It's only purpose is a hint to Linux to automagically create a regmap for
you.
All you need is the specific compatible, atmel,sama5d2-sfr, and you can
imply the rest of this from it. That's assuming the conclusion is a
register read/write interface on SMC is a good idea, but I don't think
it is.
Rob
Le Thu, 29 Jul 2021 15:19:19 -0600,
Rob Herring [off-list ref] a écrit :
On Fri, Jul 23, 2021 at 03:52:39PM +0200, Clément Léger wrote:
quoted
This patch adds documentation for the "syscon-smc" compatible which
describes a syscon using a SMC regmap instead of a MMIO one. This
allows accessing system controllers that are set as secure by using
SMC handled by the secure monitor.
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
.../devicetree/bindings/mfd/syscon-smc.yaml | 57
+++++++++++++++++++ 1 file changed, 57 insertions(+)
create mode 100644
Documentation/devicetree/bindings/mfd/syscon-smc.yaml
@@ -0,0 +1,57 @@+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)+%YAML1.2+---+$id:http://devicetree.org/schemas/mfd/syscon-smc.yaml#+$schema:http://devicetree.org/meta-schemas/core.yaml#++title:System Controller Registers R/W via SMC Device Tree Bindings++description:|+System controller SMC node represents a register region
containing a set
+ of miscellaneous registers accessed through a secure monitor.
+ The typical use-case is the same as the syscon one but when
running with a
+ secure monitor.
+
+maintainers:
+ - Lee Jones [off-list ref]
+
+properties:
+ compatible:
+ anyOf:
+ - items:
+ - enum:
+ - atmel,sama5d2-sfr
+
+ - const: syscon-smc
I regret having 'syscon' as a compatible, so nak on a 2nd flavor of
it. It's only purpose is a hint to Linux to automagically create a
regmap for you.
Indeed.
All you need is the specific compatible, atmel,sama5d2-sfr, and you
can imply the rest of this from it. That's assuming the conclusion is
a register read/write interface on SMC is a good idea, but I don't
think it is.
Ok noted, I'll try to find something else to implement that.
Clément