Update access control lists. (#3433)

This CL updates the access control lists used in SPIRV-Tools to the more
descriptive allow/deny naming.
This commit is contained in:
dan sinclair 2020-06-15 13:20:40 -04:00 committed by GitHub
parent 30bf46dbe0
commit 52a5f074e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 45 additions and 45 deletions

View File

@ -455,7 +455,7 @@ bool spvIsInIdType(spv_operand_type_t type) {
return false; return false;
} }
switch (type) { switch (type) {
// Blacklist non-input IDs. // Deny non-input IDs.
case SPV_OPERAND_TYPE_TYPE_ID: case SPV_OPERAND_TYPE_TYPE_ID:
case SPV_OPERAND_TYPE_RESULT_ID: case SPV_OPERAND_TYPE_RESULT_ID:
return false; return false;

View File

@ -131,11 +131,11 @@ void AggressiveDCEPass::AddStores(uint32_t ptrId) {
} }
bool AggressiveDCEPass::AllExtensionsSupported() const { bool AggressiveDCEPass::AllExtensionsSupported() const {
// If any extension not in whitelist, return false // If any extension not in allowlist, return false
for (auto& ei : get_module()->extensions()) { for (auto& ei : get_module()->extensions()) {
const char* extName = const char* extName =
reinterpret_cast<const char*>(&ei.GetInOperand(0).words[0]); reinterpret_cast<const char*>(&ei.GetInOperand(0).words[0]);
if (extensions_whitelist_.find(extName) == extensions_whitelist_.end()) if (extensions_allowlist_.find(extName) == extensions_allowlist_.end())
return false; return false;
} }
return true; return true;
@ -882,14 +882,14 @@ bool AggressiveDCEPass::ProcessGlobalValues() {
AggressiveDCEPass::AggressiveDCEPass() = default; AggressiveDCEPass::AggressiveDCEPass() = default;
Pass::Status AggressiveDCEPass::Process() { Pass::Status AggressiveDCEPass::Process() {
// Initialize extensions whitelist // Initialize extensions allowlist
InitExtensions(); InitExtensions();
return ProcessImpl(); return ProcessImpl();
} }
void AggressiveDCEPass::InitExtensions() { void AggressiveDCEPass::InitExtensions() {
extensions_whitelist_.clear(); extensions_allowlist_.clear();
extensions_whitelist_.insert({ extensions_allowlist_.insert({
"SPV_AMD_shader_explicit_vertex_parameter", "SPV_AMD_shader_explicit_vertex_parameter",
"SPV_AMD_shader_trinary_minmax", "SPV_AMD_shader_trinary_minmax",
"SPV_AMD_gcn_shader", "SPV_AMD_gcn_shader",

View File

@ -87,7 +87,7 @@ class AggressiveDCEPass : public MemPass {
// to the live instruction worklist. // to the live instruction worklist.
void AddStores(uint32_t ptrId); void AddStores(uint32_t ptrId);
// Initialize extensions whitelist // Initialize extensions allowlist
void InitExtensions(); void InitExtensions();
// Return true if all extensions in this module are supported by this pass. // Return true if all extensions in this module are supported by this pass.
@ -191,7 +191,7 @@ class AggressiveDCEPass : public MemPass {
std::vector<Instruction*> to_kill_; std::vector<Instruction*> to_kill_;
// Extensions supported by this pass. // Extensions supported by this pass.
std::unordered_set<std::string> extensions_whitelist_; std::unordered_set<std::string> extensions_allowlist_;
}; };
} // namespace opt } // namespace opt

View File

@ -281,7 +281,7 @@ void LocalAccessChainConvertPass::Initialize() {
// Initialize collections // Initialize collections
supported_ref_ptrs_.clear(); supported_ref_ptrs_.clear();
// Initialize extension whitelist // Initialize extension allowlist
InitExtensions(); InitExtensions();
} }
@ -292,11 +292,11 @@ bool LocalAccessChainConvertPass::AllExtensionsSupported() const {
if (context()->get_feature_mgr()->HasCapability( if (context()->get_feature_mgr()->HasCapability(
SpvCapabilityVariablePointers)) SpvCapabilityVariablePointers))
return false; return false;
// If any extension not in whitelist, return false // If any extension not in allowlist, return false
for (auto& ei : get_module()->extensions()) { for (auto& ei : get_module()->extensions()) {
const char* extName = const char* extName =
reinterpret_cast<const char*>(&ei.GetInOperand(0).words[0]); reinterpret_cast<const char*>(&ei.GetInOperand(0).words[0]);
if (extensions_whitelist_.find(extName) == extensions_whitelist_.end()) if (extensions_allowlist_.find(extName) == extensions_allowlist_.end())
return false; return false;
} }
return true; return true;
@ -336,8 +336,8 @@ Pass::Status LocalAccessChainConvertPass::Process() {
} }
void LocalAccessChainConvertPass::InitExtensions() { void LocalAccessChainConvertPass::InitExtensions() {
extensions_whitelist_.clear(); extensions_allowlist_.clear();
extensions_whitelist_.insert({ extensions_allowlist_.insert({
"SPV_AMD_shader_explicit_vertex_parameter", "SPV_AMD_shader_explicit_vertex_parameter",
"SPV_AMD_shader_trinary_minmax", "SPV_AMD_shader_trinary_minmax",
"SPV_AMD_gcn_shader", "SPV_AMD_gcn_shader",

View File

@ -110,7 +110,7 @@ class LocalAccessChainConvertPass : public MemPass {
// Returns a status to indicate success or failure, and change or no change. // Returns a status to indicate success or failure, and change or no change.
Status ConvertLocalAccessChains(Function* func); Status ConvertLocalAccessChains(Function* func);
// Initialize extensions whitelist // Initialize extensions allowlist
void InitExtensions(); void InitExtensions();
// Return true if all extensions in this module are allowed by this pass. // Return true if all extensions in this module are allowed by this pass.
@ -124,7 +124,7 @@ class LocalAccessChainConvertPass : public MemPass {
std::unordered_set<uint32_t> supported_ref_ptrs_; std::unordered_set<uint32_t> supported_ref_ptrs_;
// Extensions supported by this pass. // Extensions supported by this pass.
std::unordered_set<std::string> extensions_whitelist_; std::unordered_set<std::string> extensions_allowlist_;
}; };
} // namespace opt } // namespace opt

View File

@ -168,16 +168,16 @@ void LocalSingleBlockLoadStoreElimPass::Initialize() {
// Clear collections // Clear collections
supported_ref_ptrs_.clear(); supported_ref_ptrs_.clear();
// Initialize extensions whitelist // Initialize extensions allowlist
InitExtensions(); InitExtensions();
} }
bool LocalSingleBlockLoadStoreElimPass::AllExtensionsSupported() const { bool LocalSingleBlockLoadStoreElimPass::AllExtensionsSupported() const {
// If any extension not in whitelist, return false // If any extension not in allowlist, return false
for (auto& ei : get_module()->extensions()) { for (auto& ei : get_module()->extensions()) {
const char* extName = const char* extName =
reinterpret_cast<const char*>(&ei.GetInOperand(0).words[0]); reinterpret_cast<const char*>(&ei.GetInOperand(0).words[0]);
if (extensions_whitelist_.find(extName) == extensions_whitelist_.end()) if (extensions_allowlist_.find(extName) == extensions_allowlist_.end())
return false; return false;
} }
return true; return true;
@ -214,8 +214,8 @@ Pass::Status LocalSingleBlockLoadStoreElimPass::Process() {
} }
void LocalSingleBlockLoadStoreElimPass::InitExtensions() { void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
extensions_whitelist_.clear(); extensions_allowlist_.clear();
extensions_whitelist_.insert({ extensions_allowlist_.insert({
"SPV_AMD_shader_explicit_vertex_parameter", "SPV_AMD_shader_explicit_vertex_parameter",
"SPV_AMD_shader_trinary_minmax", "SPV_AMD_shader_trinary_minmax",
"SPV_AMD_gcn_shader", "SPV_AMD_gcn_shader",

View File

@ -63,7 +63,7 @@ class LocalSingleBlockLoadStoreElimPass : public MemPass {
// where possible. Assumes logical addressing. // where possible. Assumes logical addressing.
bool LocalSingleBlockLoadStoreElim(Function* func); bool LocalSingleBlockLoadStoreElim(Function* func);
// Initialize extensions whitelist // Initialize extensions allowlist
void InitExtensions(); void InitExtensions();
// Return true if all extensions in this module are supported by this pass. // Return true if all extensions in this module are supported by this pass.
@ -94,7 +94,7 @@ class LocalSingleBlockLoadStoreElimPass : public MemPass {
std::unordered_set<uint32_t> pinned_vars_; std::unordered_set<uint32_t> pinned_vars_;
// Extensions supported by this pass. // Extensions supported by this pass.
std::unordered_set<std::string> extensions_whitelist_; std::unordered_set<std::string> extensions_allowlist_;
// Variables that are only referenced by supported operations for this // Variables that are only referenced by supported operations for this
// pass ie. loads and stores. // pass ie. loads and stores.

View File

@ -46,11 +46,11 @@ bool LocalSingleStoreElimPass::LocalSingleStoreElim(Function* func) {
} }
bool LocalSingleStoreElimPass::AllExtensionsSupported() const { bool LocalSingleStoreElimPass::AllExtensionsSupported() const {
// If any extension not in whitelist, return false // If any extension not in allowlist, return false
for (auto& ei : get_module()->extensions()) { for (auto& ei : get_module()->extensions()) {
const char* extName = const char* extName =
reinterpret_cast<const char*>(&ei.GetInOperand(0).words[0]); reinterpret_cast<const char*>(&ei.GetInOperand(0).words[0]);
if (extensions_whitelist_.find(extName) == extensions_whitelist_.end()) if (extensions_allowlist_.find(extName) == extensions_allowlist_.end())
return false; return false;
} }
return true; return true;
@ -74,12 +74,12 @@ Pass::Status LocalSingleStoreElimPass::ProcessImpl() {
LocalSingleStoreElimPass::LocalSingleStoreElimPass() = default; LocalSingleStoreElimPass::LocalSingleStoreElimPass() = default;
Pass::Status LocalSingleStoreElimPass::Process() { Pass::Status LocalSingleStoreElimPass::Process() {
InitExtensionWhiteList(); InitExtensionAllowList();
return ProcessImpl(); return ProcessImpl();
} }
void LocalSingleStoreElimPass::InitExtensionWhiteList() { void LocalSingleStoreElimPass::InitExtensionAllowList() {
extensions_whitelist_.insert({ extensions_allowlist_.insert({
"SPV_AMD_shader_explicit_vertex_parameter", "SPV_AMD_shader_explicit_vertex_parameter",
"SPV_AMD_shader_trinary_minmax", "SPV_AMD_shader_trinary_minmax",
"SPV_AMD_gcn_shader", "SPV_AMD_gcn_shader",

View File

@ -57,8 +57,8 @@ class LocalSingleStoreElimPass : public Pass {
// any resulting dead code. // any resulting dead code.
bool LocalSingleStoreElim(Function* func); bool LocalSingleStoreElim(Function* func);
// Initialize extensions whitelist // Initialize extensions allowlist
void InitExtensionWhiteList(); void InitExtensionAllowList();
// Return true if all extensions in this module are allowed by this pass. // Return true if all extensions in this module are allowed by this pass.
bool AllExtensionsSupported() const; bool AllExtensionsSupported() const;
@ -94,7 +94,7 @@ class LocalSingleStoreElimPass : public Pass {
const std::vector<Instruction*>& uses); const std::vector<Instruction*>& uses);
// Extensions supported by this pass. // Extensions supported by this pass.
std::unordered_set<std::string> extensions_whitelist_; std::unordered_set<std::string> extensions_allowlist_;
}; };
} // namespace opt } // namespace opt

View File

@ -413,7 +413,7 @@ OpFunctionEnd
predefs1 + names_after + predefs2 + func_after, true, true); predefs1 + names_after + predefs2 + func_after, true, true);
} }
TEST_F(AggressiveDCETest, OptWhitelistExtension) { TEST_F(AggressiveDCETest, OptAllowListExtension) {
// #version 140 // #version 140
// //
// in vec4 BaseColor; // in vec4 BaseColor;
@ -498,7 +498,7 @@ OpFunctionEnd
predefs1 + names_after + predefs2 + func_after, true, true); predefs1 + names_after + predefs2 + func_after, true, true);
} }
TEST_F(AggressiveDCETest, NoOptBlacklistExtension) { TEST_F(AggressiveDCETest, NoOptDenyListExtension) {
// #version 140 // #version 140
// //
// in vec4 BaseColor; // in vec4 BaseColor;

View File

@ -1952,7 +1952,7 @@ INSTANTIATE_TEST_SUITE_P(
"needs to be a 32-bit int", "is not an int")))); "needs to be a 32-bit int", "is not an int"))));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
WhitelistRejection, AllowListRejection,
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult, ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
Combine(Values("PointSize", "ClipDistance", "CullDistance", "VertexId", Combine(Values("PointSize", "ClipDistance", "CullDistance", "VertexId",
"InstanceId", "PointCoord", "SampleMask", "HelperInvocation", "InstanceId", "PointCoord", "SampleMask", "HelperInvocation",
@ -2979,7 +2979,7 @@ OpMemberDecorate %input_type 0 BuiltIn InstanceId
TEST_F(ValidateBuiltIns, ValidBuiltinsForMeshShader) { TEST_F(ValidateBuiltIns, ValidBuiltinsForMeshShader) {
CodeGenerator generator = CodeGenerator::GetDefaultShaderCodeGenerator(); CodeGenerator generator = CodeGenerator::GetDefaultShaderCodeGenerator();
generator.capabilities_ += R"( generator.capabilities_ += R"(
OpCapability MeshShadingNV OpCapability MeshShadingNV
)"; )";
generator.extensions_ = R"( generator.extensions_ = R"(
@ -3017,7 +3017,7 @@ OpDecorate %gl_ViewportIndex PerPrimitiveNV
TEST_F(ValidateBuiltIns, InvalidBuiltinsForMeshShader) { TEST_F(ValidateBuiltIns, InvalidBuiltinsForMeshShader) {
CodeGenerator generator = CodeGenerator::GetDefaultShaderCodeGenerator(); CodeGenerator generator = CodeGenerator::GetDefaultShaderCodeGenerator();
generator.capabilities_ += R"( generator.capabilities_ += R"(
OpCapability MeshShadingNV OpCapability MeshShadingNV
)"; )";
generator.extensions_ = R"( generator.extensions_ = R"(

View File

@ -6353,7 +6353,7 @@ INSTANTIATE_TEST_SUITE_P(
"requires one of these capabilities")))); "requires one of these capabilities"))));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
DecorationWhitelistFailure, ValidateWebGPUCombineDecorationResult, DecorationAllowListFailure, ValidateWebGPUCombineDecorationResult,
Combine(Values("RelaxedPrecision", "BufferBlock", "GLSLShared", Combine(Values("RelaxedPrecision", "BufferBlock", "GLSLShared",
"GLSLPacked", "Invariant", "Volatile", "Coherent"), "GLSLPacked", "Invariant", "Volatile", "Coherent"),
Values(TestResult( Values(TestResult(

View File

@ -714,14 +714,14 @@ INSTANTIATE_TEST_SUITE_P(
"SubgroupsPerWorkgroup 1", "SubgroupsPerWorkgroupId %int1"), "SubgroupsPerWorkgroup 1", "SubgroupsPerWorkgroupId %int1"),
Values(SPV_ENV_UNIVERSAL_1_3))); Values(SPV_ENV_UNIVERSAL_1_3)));
INSTANTIATE_TEST_SUITE_P(ValidateModeGLComputeWebGPUWhitelistGood, INSTANTIATE_TEST_SUITE_P(ValidateModeGLComputeWebGPUAllowListGood,
ValidateModeExecution, ValidateModeExecution,
Combine(Values(SPV_SUCCESS), Values(""), Combine(Values(SPV_SUCCESS), Values(""),
Values("GLCompute"), Values("LocalSize 1 1 1"), Values("GLCompute"), Values("LocalSize 1 1 1"),
Values(SPV_ENV_WEBGPU_0))); Values(SPV_ENV_WEBGPU_0)));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
ValidateModeGLComputeWebGPUWhitelistBad, ValidateModeExecution, ValidateModeGLComputeWebGPUAllowListBad, ValidateModeExecution,
Combine(Values(SPV_ERROR_INVALID_DATA), Combine(Values(SPV_ERROR_INVALID_DATA),
Values("Execution mode must be one of OriginUpperLeft, " Values("Execution mode must be one of OriginUpperLeft, "
"DepthReplacing, DepthGreater, DepthLess, DepthUnchanged, " "DepthReplacing, DepthGreater, DepthLess, DepthUnchanged, "
@ -730,14 +730,14 @@ INSTANTIATE_TEST_SUITE_P(
Values(SPV_ENV_WEBGPU_0))); Values(SPV_ENV_WEBGPU_0)));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
ValidateModeFragmentWebGPUWhitelistGood, ValidateModeExecution, ValidateModeFragmentWebGPUAllowListGood, ValidateModeExecution,
Combine(Values(SPV_SUCCESS), Values(""), Values("Fragment"), Combine(Values(SPV_SUCCESS), Values(""), Values("Fragment"),
Values("OriginUpperLeft", "DepthReplacing", "DepthGreater", Values("OriginUpperLeft", "DepthReplacing", "DepthGreater",
"DepthLess", "DepthUnchanged"), "DepthLess", "DepthUnchanged"),
Values(SPV_ENV_WEBGPU_0))); Values(SPV_ENV_WEBGPU_0)));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
ValidateModeFragmentWebGPUWhitelistBad, ValidateModeExecution, ValidateModeFragmentWebGPUAllowListBad, ValidateModeExecution,
Combine(Values(SPV_ERROR_INVALID_DATA), Combine(Values(SPV_ERROR_INVALID_DATA),
Values("Execution mode must be one of OriginUpperLeft, " Values("Execution mode must be one of OriginUpperLeft, "
"DepthReplacing, DepthGreater, DepthLess, DepthUnchanged, " "DepthReplacing, DepthGreater, DepthLess, DepthUnchanged, "

View File

@ -254,7 +254,7 @@ TEST_F(ValidateWebGPU, NonVulkanKHRMemoryModelBad) {
"environment.\n OpMemoryModel Logical GLSL450\n")); "environment.\n OpMemoryModel Logical GLSL450\n"));
} }
TEST_F(ValidateWebGPU, WhitelistedExtendedInstructionsImportGood) { TEST_F(ValidateWebGPU, AllowListedExtendedInstructionsImportGood) {
std::string spirv = R"( std::string spirv = R"(
OpCapability Shader OpCapability Shader
OpCapability VulkanMemoryModelKHR OpCapability VulkanMemoryModelKHR
@ -275,7 +275,7 @@ TEST_F(ValidateWebGPU, WhitelistedExtendedInstructionsImportGood) {
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_WEBGPU_0)); EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_WEBGPU_0));
} }
TEST_F(ValidateWebGPU, NonWhitelistedExtendedInstructionsImportBad) { TEST_F(ValidateWebGPU, NonAllowListedExtendedInstructionsImportBad) {
std::string spirv = R"( std::string spirv = R"(
OpCapability Shader OpCapability Shader
OpCapability VulkanMemoryModelKHR OpCapability VulkanMemoryModelKHR

View File

@ -55,11 +55,11 @@ def check_library(library):
# _Z[0-9]+spv[A-Z_] : C++ symbol starting with spv[A-Z_] # _Z[0-9]+spv[A-Z_] : C++ symbol starting with spv[A-Z_]
symbol_ok_pattern = re.compile(r'^(spv[A-Z]|_ZN|_Z[0-9]+spv[A-Z_])') symbol_ok_pattern = re.compile(r'^(spv[A-Z]|_ZN|_Z[0-9]+spv[A-Z_])')
# In addition, the following pattern whitelists global functions that are added # In addition, the following pattern allowlists global functions that are added
# by the protobuf compiler: # by the protobuf compiler:
# - AddDescriptors_spvtoolsfuzz_2eproto() # - AddDescriptors_spvtoolsfuzz_2eproto()
# - InitDefaults_spvtoolsfuzz_2eproto() # - InitDefaults_spvtoolsfuzz_2eproto()
symbol_whitelist_pattern = re.compile(r'_Z[0-9]+(InitDefaults|AddDescriptors)_spvtoolsfuzz_2eprotov') symbol_allowlist_pattern = re.compile(r'_Z[0-9]+(InitDefaults|AddDescriptors)_spvtoolsfuzz_2eprotov')
seen = set() seen = set()
result = 0 result = 0
@ -70,7 +70,7 @@ def check_library(library):
if symbol not in seen: if symbol not in seen:
seen.add(symbol) seen.add(symbol)
#print("look at '{}'".format(symbol)) #print("look at '{}'".format(symbol))
if not (symbol_whitelist_pattern.match(symbol) or symbol_ok_pattern.match(symbol)): if not (symbol_allowlist_pattern.match(symbol) or symbol_ok_pattern.match(symbol)):
print('{}: error: Unescaped exported symbol: {}'.format(PROG, symbol)) print('{}: error: Unescaped exported symbol: {}'.format(PROG, symbol))
result = 1 result = 1
return result return result