Skip to contentSkip to conversation

sparc64: Add privileged ADI driver

PATCH Superseded Tom Hromatka 2 participants 5 messages Apr 20, 2018 – Apr 22, 2018

Subsystems (2)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover sparc64: Add privileged ADI driver

ADI is a feature supported on SPARC M7 and newer processors to allow hardware to catch rogue accesses to memory. ADI is supported for data fetches only and not instruction fetches. An app can enable ADI on its data pages, set version tags on them and use versioned addresses to access the data pages. Upper bits of the address contain the version tag. On M7 processors, upper four bits (bits 63-60) contain the version tag. If a rogue app attempts to access ADI enabled data pages, its access is blocked and processor generates an exception. Please see Documentation/sparc/adi.txt for further details.

This patchset implements a char driver to read/write ADI versions from privileged user space processes. Intended consumers are makedumpfile and crash.

v4:
* Fixed messed up subject lines.
v3:
* Really fixed the copyright headers to use SPDX GPL v2. Really.
v2:
* Simplified copyright headers
* Completely reworked sparc64 selftests Makefiles. Used the android selftests Makefiles as an example
* Added run.sh and drivers_test.sh to the sparc64 selftest directory. Used bpf/test_kmod.sh and the android selftests as examples
* Minor cleanups in the selftest adi-test.c
* Added calls to ksft_test_*() in the adi-test.c

Tom Hromatka (2):
char: sparc64: Add privileged ADI driver
selftests: sparc64: char: Selftest for privileged ADI driver

 drivers/char/Kconfig                               |  12 +
 drivers/char/Makefile                              |   1 +
 drivers/char/adi.c                                 | 240 +++++++
 tools/testing/selftests/Makefile                   |   1 +
 tools/testing/selftests/sparc64/Makefile           |  46 ++
 tools/testing/selftests/sparc64/drivers/.gitignore |   1 +
 tools/testing/selftests/sparc64/drivers/Makefile   |  15 +
 tools/testing/selftests/sparc64/drivers/adi-test.c | 721 +++++++++++++++++++++
 .../selftests/sparc64/drivers/drivers_test.sh      |  30 +
 tools/testing/selftests/sparc64/run.sh             |   3 +
 10 files changed, 1070 insertions(+)
 create mode 100644 drivers/char/adi.c
 create mode 100644 tools/testing/selftests/sparc64/Makefile
 create mode 100644 tools/testing/selftests/sparc64/drivers/.gitignore
 create mode 100644 tools/testing/selftests/sparc64/drivers/Makefile
 create mode 100644 tools/testing/selftests/sparc64/drivers/adi-test.c
 create mode 100755 tools/testing/selftests/sparc64/drivers/drivers_test.sh
 create mode 100755 tools/testing/selftests/sparc64/run.sh
Signature · 6 lines
2.15.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH v4 1/2 char: sparc64: Add privileged ADI driver

SPARC M7 and newer processors utilize ADI to version and protect memory. This driver is capable of reading/writing ADI/MCD versions from privileged user space processes. Addresses in the adi file are mapped linearly to physical memory at a ratio of 1:adi_blksz. Thus, a read (or write) of offset K in the file operates upon the ADI version at physical address K * adi_blksz. The version information is encoded as one version per byte. Intended consumers are makedumpfile and crash.

Signed-off-by Tom Hromatka <tom.hromatka at oracle.com>
Reviewed-by Khalid Aziz <khalid.aziz at oracle.com>
Reviewed-by Shannon Nelson <shannon.nelson at oracle.com>
Reviewed-by Anthony Yznaga <anthony.yznaga at oracle.com>
---
 drivers/char/Kconfig  |  12 +++
 drivers/char/Makefile |   1 +
 drivers/char/adi.c    | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 253 insertions(+)
 create mode 100644 drivers/char/adi.c
drivers/char/Kconfig +12 -0
index 40947a796666..5ecddc95a698 100644
@@ -540,5 +540,17 @@ source "drivers/s390/char/Kconfig"
 
 source "drivers/char/xillybus/Kconfig"
 
+config ADI
+	tristate "SPARC Privileged ADI driver"
+	depends on SPARC64
+	default m
+	help
+	  SPARC M7 and newer processors utilize ADI (Application Data
+	  Integrity) to version and protect memory.  This driver provides
+	  read/write access to the ADI versions for privileged processes.
+	  This feature is also known as MCD (Memory Corruption Detection)
+	  and SSM (Silicon Secured Memory).  Intended consumers of this
+	  driver include crash and makedumpfile.
+
 endmenu
 
drivers/char/Makefile +1 -0
index c97c768cd1dd..b8d42b4e979b 100644
@@ -57,3 +57,4 @@ js-rtc-y = rtc.o
 
 obj-$(CONFIG_XILLYBUS)		+= xillybus/
 obj-$(CONFIG_POWERNV_OP_PANEL)	+= powernv-op-panel.o
+obj-$(CONFIG_ADI)		+= adi.o
drivers/char/adi.c new file +240 -0

240 lines not on this page · raw message

Signature · 6 lines
2.15.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#2 lore raw

Re: [PATCH v4 1/2] char: sparc64: Add privileged ADI driver

drivers/char/adi.c line 1

Quoted 4 lines · Tom Hromatka
drivers/char/adi.c new file +1 -0
@@ -0,0 +1,240 @@
+// SPDX-License-Identifier: GPL-2.0

Good, but:

drivers/char/adi.c line 240

Quoted 1 line
drivers/char/adi.c new file +1 -0
+MODULE_LICENSE("GPL");

That's the wrong line :(

Read include/linux/module.h for the correct string to put here for a GPL version 2 only module.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [PATCH v4 1/2] char: sparc64: Add privileged ADI driver

Quoted 7 lines · Greg KH

drivers/char/adi.c line 1

Quoted 4 lines · Tom Hromatka
drivers/char/adi.c new file +1 -0
@@ -0,0 +1,240 @@
+// SPDX-License-Identifier: GPL-2.0

Good, but:

Quoted 6 lines

drivers/char/adi.c line 240

Quoted 1 line
drivers/char/adi.c new file +1 -0
+MODULE_LICENSE("GPL");

That's the wrong line :(

Read include/linux/module.h for the correct string to put here for a GPL version 2 only module.

<Tom hangs his head in shame>

My sincerest apologies, Greg.  I'll follow the guidance from the aforementioned file and re-re-submit the patch tomorrow :(.

Thanks so much for your patience.

Regards,

Tom
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

PATCH v4 2/2 selftests: sparc64: char: Selftest for privileged ADI driver

In reply to Tom Hromatka

Add a selftest for the sparc64 privileged ADI driver. These tests verify the read(), pread(), write(), pwrite(), and seek() functionality of the driver. The tests also report simple performance statistics:

        Syscall Call    AvgTime AvgSize
                Count   (ticks) (bytes)
        -------------------------------
        read          3  119638    8133
        pread         4  118164    6741
        write         3  339442    8133
        pwrite        4  280134    6741
        seek         10    2919       0
        Pass 8 Fail 0 Xfail 0 Xpass 0 Skip 0 Error 0
Signed-off-by Tom Hromatka <tom.hromatka at oracle.com>
Reviewed-by Allen Pais <allen.pais at oracle.com>
---
 tools/testing/selftests/Makefile                   |   1 +
 tools/testing/selftests/sparc64/Makefile           |  46 ++
 tools/testing/selftests/sparc64/drivers/.gitignore |   1 +
 tools/testing/selftests/sparc64/drivers/Makefile   |  15 +
 tools/testing/selftests/sparc64/drivers/adi-test.c | 721 +++++++++++++++++++++
 .../selftests/sparc64/drivers/drivers_test.sh      |  30 +
 tools/testing/selftests/sparc64/run.sh             |   3 +
 7 files changed, 817 insertions(+)
 create mode 100644 tools/testing/selftests/sparc64/Makefile
 create mode 100644 tools/testing/selftests/sparc64/drivers/.gitignore
 create mode 100644 tools/testing/selftests/sparc64/drivers/Makefile
 create mode 100644 tools/testing/selftests/sparc64/drivers/adi-test.c
 create mode 100755 tools/testing/selftests/sparc64/drivers/drivers_test.sh
 create mode 100755 tools/testing/selftests/sparc64/run.sh
tools/testing/selftests/Makefile +1 -0
index 7442dfb73b7f..94da632579e7 100644
@@ -28,6 +28,7 @@ TARGETS += ptrace
 TARGETS += seccomp
 TARGETS += sigaltstack
 TARGETS += size
+TARGETS += sparc64
 TARGETS += splice
 TARGETS += static_keys
 TARGETS += sync
tools/testing/selftests/sparc64/Makefile new file +46 -0

46 lines not on this page · raw message

tools/testing/selftests/sparc64/drivers/.gitignore new file +1 -0
new file mode 100644
index 000000000000..90e835ed74e6
@@ -0,0 +1 @@
+adi-test
tools/testing/selftests/sparc64/drivers/Makefile new file +15 -0
new file mode 100644
index 000000000000..6264f40bbdbc
@@ -0,0 +1,15 @@
+
+INCLUDEDIR := -I.
+CFLAGS := $(CFLAGS) $(INCLUDEDIR) -Wall -O2 -g
+
+TEST_GEN_FILES := adi-test
+
+all: $(TEST_GEN_FILES)
+
+$(TEST_GEN_FILES): adi-test.c
+
+TEST_PROGS := drivers_test.sh
+
+include ../../lib.mk
+
+$(OUTPUT)/adi-test: adi-test.c
tools/testing/selftests/sparc64/drivers/adi-test.c new file +721 -0

721 lines not on this page · raw message

tools/testing/selftests/sparc64/drivers/drivers_test.sh new file +30 -0
new file mode 100755
index 000000000000..6d08273b7532
@@ -0,0 +1,30 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+SRC_TREE=../../../../
+
+test_run()
+{
+	if [ -f ${SRC_TREE}/drivers/char/adi.ko ]; then
+		insmod ${SRC_TREE}/drivers/char/adi.ko 2> /dev/null
+		if [ $? -ne 0 ]; then
+			rc=1
+		fi
+	else
+		# Use modprobe dry run to check for missing adi module
+		if ! /sbin/modprobe -q -n adi; then
+			echo "adi: [SKIP]"
+		elif /sbin/modprobe -q adi; then
+			echo "adi: ok"
+		else
+			echo "adi: [FAIL]"
+			rc=1
+		fi
+	fi
+	./adi-test
+	rmmod adi 2> /dev/null
+}
+
+rc=0
+test_run
+exit $rc
tools/testing/selftests/sparc64/run.sh new file +3 -0
new file mode 100755
index 000000000000..38ad61f9328e
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+(cd drivers; ./drivers_test.sh)
Signature · 6 lines
2.15.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html