-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RISCV] Add support for Smepmp 1.0 #78489
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-risc-v Author: Min-Yih Hsu (mshockwave) ChangesSmepmp is a supervisor extension that prevents privileged processes from accessing unprivileged program and data. https://github.com/riscv/riscv-tee/blob/main/Smepmp/Smepmp.pdf Full diff: https://github.com/llvm/llvm-project/pull/78489.diff 5 Files Affected:
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp
index 390d950486a7956..f67bbd1969e1b37 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -55,6 +55,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
{"m", {2, 0}},
{"smaia", {1, 0}},
+ {"smepmp", {1, 0}},
{"ssaia", {1, 0}},
{"svinval", {1, 0}},
{"svnapot", {1, 0}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 279509575bb52a9..00b5c710daac322 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -716,6 +716,13 @@ def FeatureStdExtSmaia
"AIA specifies for a hart, over all privilege levels.)",
[]>;
+def FeatureStdExtSmepmp
+ : SubtargetFeature<"smepmp", "HasStdExtSmepmp", "true",
+ "'Smepmp' (Smepmp prevents privileged processes from "
+ "executing or accessing unprivileged programs and"
+ "data.)",
+ []>;
+
def FeatureStdExtSsaia
: SubtargetFeature<"ssaia", "HasStdExtSsaia", "true",
"'Ssaia' (Ssaia is essentially the same as Smaia except "
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll
index 9a6e78c09ad8c3f..ad6f205692fe30e 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -88,6 +88,7 @@
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zimop %s -o - | FileCheck --check-prefix=RV32ZIMOP %s
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcmop %s -o - | FileCheck --check-prefix=RV32ZCMOP %s
; RUN: llc -mtriple=riscv32 -mattr=+smaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SMAIA %s
+; RUN: llc -mtriple=riscv32 -mattr=+smepmp %s -o - | FileCheck --check-prefixes=CHECK,RV32SMEPMP %s
; RUN: llc -mtriple=riscv32 -mattr=+ssaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SSAIA %s
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZFBFMIN %s
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFMIN %s
@@ -182,6 +183,7 @@
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zimop %s -o - | FileCheck --check-prefix=RV64ZIMOP %s
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcmop %s -o - | FileCheck --check-prefix=RV64ZCMOP %s
; RUN: llc -mtriple=riscv64 -mattr=+smaia %s -o - | FileCheck --check-prefixes=CHECK,RV64SMAIA %s
+; RUN: llc -mtriple=riscv64 -mattr=+smepmp %s -o - | FileCheck --check-prefixes=CHECK,RV64SMEPMP %s
; RUN: llc -mtriple=riscv64 -mattr=+ssaia %s -o - | FileCheck --check-prefixes=CHECK,RV64SSAIA %s
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZFBFMIN %s
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVFBFMIN %s
@@ -278,6 +280,7 @@
; RV32ZIMOP: .attribute 5, "rv32i2p1_zimop0p1"
; RV32ZCMOP: .attribute 5, "rv32i2p1_zca1p0_zcmop0p2"
; RV32SMAIA: .attribute 5, "rv32i2p1_smaia1p0"
+; RV32SMEPMP: .attribute 5, "rv32i2p1_smepmp1p0"
; RV32SSAIA: .attribute 5, "rv32i2p1_ssaia1p0"
; RV32ZFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p8"
; RV32ZVFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvl32b1p0"
@@ -371,6 +374,7 @@
; RV64ZIMOP: .attribute 5, "rv64i2p1_zimop0p1"
; RV64ZCMOP: .attribute 5, "rv64i2p1_zca1p0_zcmop0p2"
; RV64SMAIA: .attribute 5, "rv64i2p1_smaia1p0"
+; RV64SMEPMP: .attribute 5, "rv64i2p1_smepmp1p0"
; RV64SSAIA: .attribute 5, "rv64i2p1_ssaia1p0"
; RV64ZFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin0p8"
; RV64ZVFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvl32b1p0"
diff --git a/llvm/test/MC/RISCV/attribute-arch.s b/llvm/test/MC/RISCV/attribute-arch.s
index 4f8a8dfdbcec903..bab104c5809008f 100644
--- a/llvm/test/MC/RISCV/attribute-arch.s
+++ b/llvm/test/MC/RISCV/attribute-arch.s
@@ -270,6 +270,9 @@
.attribute arch, "rv32i_smaia1p0"
# CHECK: attribute 5, "rv32i2p1_smaia1p0"
+.attribute arch, "rv32i_smepmp1p0"
+# CHECK: attribute 5, "rv32i2p1_smepmp1p0"
+
.attribute arch, "rv32i_ssaia1p0"
# CHECK: attribute 5, "rv32i2p1_ssaia1p0"
diff --git a/llvm/unittests/Support/RISCVISAInfoTest.cpp b/llvm/unittests/Support/RISCVISAInfoTest.cpp
index 997551e5c44c092..fc96ea5ff3669ae 100644
--- a/llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -753,6 +753,7 @@ R"(All available -march extensions for RISC-V
zhinx 1.0
zhinxmin 1.0
smaia 1.0
+ smepmp 1.0
ssaia 1.0
svinval 1.0
svnapot 1.0
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be added to RISCVUsage.rst, and probably a note in the release docs as well.
@@ -716,6 +716,13 @@ def FeatureStdExtSmaia | |||
"AIA specifies for a hart, over all privilege levels.)", | |||
[]>; | |||
|
|||
def FeatureStdExtSmepmp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep smaia and ssaia together since they come from the same specification? I assume you were alphabetizing, but I don't think there's any order in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep smaia and ssaia together since they come from the same specification? I assume you were alphabetizing, but I don't think there's any order in this file.
I've reordered it here and other places for consistency.
It's done now. |
@@ -92,6 +92,7 @@ on support follow. | |||
``M`` Supported | |||
``Smaia`` Supported | |||
``Ssaia`` Supported | |||
``Smepmp`` Supported |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this list is aphabetized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -56,6 +56,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = { | |||
|
|||
{"smaia", {1, 0}}, | |||
{"ssaia", {1, 0}}, | |||
{"smepmp", {1, 0}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required to be alphabetized. It won't pass lit tests if it isn't. Might even fail when tablegen runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
def71b1
to
bb2e208
Compare
@@ -722,6 +722,11 @@ def FeatureStdExtSsaia | |||
"'Ssaia' (Advanced Interrupt Architecture Supervisor " | |||
"Level)", []>; | |||
|
|||
def FeatureStdExtSmepmp | |||
: SubtargetFeature<"smepmp", "HasStdExtSmepmp", "true", | |||
"'Smepmp' (PMP Enhancements for memory access and " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems pretty clunky, what's wrong with just "Enhanced PMP" / "Enhanced Physical Memory Protection"? That's what it stands for after all...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fixed now.
df49f8c
to
a05871b
Compare
// RUN: %clang --target=riscv32 -menable-experimental-extensions \ | ||
// RUN: -march=rv32ismepmp1p0 -x c -E -dM %s \ | ||
// RUN: -o - | FileCheck --check-prefix=CHECK-SMEPMP-EXT %s | ||
// RUN: %clang --target=riscv64 -menable-experimental-extensions \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This extension shouldn't require -menable-experimental-extensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fixed now.
@@ -116,6 +116,7 @@ | |||
|
|||
// CHECK-NOT: __riscv_smaia {{.*$}} | |||
// CHECK-NOT: __riscv_ssaia {{.*$}} | |||
// CHECK-NOT: __riscv_smepmp {{.*$}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the experimental extension section according to the comment on 115. I guess we're bad at moving things out of this section when they go non-experimental
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fixed now.
Smepmp is a supervisor extension that prevents privileged processes from accessing unprivileged program and data.
a05871b
to
fd3ee24
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Smepmp is a supervisor extension that prevents privileged processes from accessing unprivileged program and data.
https://github.com/riscv/riscv-tee/blob/main/Smepmp/Smepmp.pdf