Skip to content

Commit 25702de

Browse files
committed
Fix zer Global table init to be optional and zero init DDI tables
- Fix the zer Global Init to be treated like an experimental init that cannot affect the ability to use a driver. - Zero initialize the zer DDI tables to avoid uninitialized memory reads when a driver does not implement all DDI functions. Signed-off-by: Neil R. Spruit <[email protected]>
1 parent e6f47c3 commit 25702de

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

scripts/templates/ldrddi.cpp.mako

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ ${tbl['export']['name']}(
532532

533533
${x}_result_t result = ${X}_RESULT_SUCCESS;
534534

535-
%if tbl['experimental'] is False: #//Experimental Tables may not be implemented in driver
535+
%if tbl['experimental'] is False and namespace != "zer": #//Experimental Tables may not be implemented in driver
536536
bool atLeastOneDriverValid = false;
537537
%endif
538538
// Load the device-driver DDI tables
@@ -547,7 +547,7 @@ ${tbl['export']['name']}(
547547
auto getTable = reinterpret_cast<${tbl['pfn']}>(
548548
GET_FUNCTION_PTR( drv.handle, "${tbl['export']['name']}") );
549549
if(!getTable)
550-
%if th.isNewProcTable(tbl['export']['name']) is True:
550+
%if th.isNewProcTable(tbl['export']['name']) is True and namespace != "zer":
551551
{
552552
atLeastOneDriverValid = true;
553553
//It is valid to not have this proc addr table
@@ -556,15 +556,15 @@ ${tbl['export']['name']}(
556556
%else:
557557
continue;
558558
%endif
559-
%if tbl['experimental'] is False: #//Experimental Tables may not be implemented in driver
559+
%if tbl['experimental'] is False and namespace != "zer": #//Experimental Tables may not be implemented in driver
560560
auto getTableResult = getTable( version, &drv.dditable.${n}.${tbl['name']});
561561
if(getTableResult == ZE_RESULT_SUCCESS) {
562562
atLeastOneDriverValid = true;
563563
loader::context->configured_version = version;
564564
} else
565565
drv.initStatus = getTableResult;
566566
%if namespace != "zes":
567-
%if tbl['name'] == "Global":
567+
%if tbl['name'] == "Global" and namespace != "zer":
568568
if (drv.dditable.ze.Global.pfnInitDrivers) {
569569
loader::context->initDriversSupport = true;
570570
}
@@ -575,7 +575,7 @@ ${tbl['export']['name']}(
575575
%endif
576576
}
577577

578-
%if tbl['experimental'] is False: #//Experimental Tables may not be implemented in driver
578+
%if tbl['experimental'] is False and namespace != "zer": #//Experimental Tables may not be implemented in driver
579579
if(!atLeastOneDriverValid)
580580
result = ${X}_RESULT_ERROR_UNINITIALIZED;
581581
else

source/lib/ze_lib.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ namespace ze_lib
206206

207207
if ( ZE_RESULT_SUCCESS == result )
208208
{
209+
memset(&initialzeDdiTable, 0, sizeof(ze_dditable_t));
210+
memset(&initialzetDdiTable, 0, sizeof(zet_dditable_t));
211+
memset(&initialzesDdiTable, 0, sizeof(zes_dditable_t));
212+
memset(&initialzerDdiTable, 0, sizeof(zer_dditable_t));
209213
ze_lib::context->zeDdiTable.exchange(&ze_lib::context->initialzeDdiTable);
210214
ze_lib::context->zetDdiTable.exchange(&ze_lib::context->initialzetDdiTable);
211215
ze_lib::context->zesDdiTable.exchange(&ze_lib::context->initialzesDdiTable);

source/loader/zer_ldrddi.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ zerGetGlobalProcAddrTable(
141141

142142
ze_result_t result = ZE_RESULT_SUCCESS;
143143

144-
bool atLeastOneDriverValid = false;
145144
// Load the device-driver DDI tables
146145
for( auto& drv : loader::context->zeDrivers )
147146
{
@@ -151,21 +150,9 @@ zerGetGlobalProcAddrTable(
151150
GET_FUNCTION_PTR( drv.handle, "zerGetGlobalProcAddrTable") );
152151
if(!getTable)
153152
continue;
154-
auto getTableResult = getTable( version, &drv.dditable.zer.Global);
155-
if(getTableResult == ZE_RESULT_SUCCESS) {
156-
atLeastOneDriverValid = true;
157-
loader::context->configured_version = version;
158-
} else
159-
drv.initStatus = getTableResult;
160-
if (drv.dditable.ze.Global.pfnInitDrivers) {
161-
loader::context->initDriversSupport = true;
162-
}
153+
result = getTable( version, &drv.dditable.zer.Global);
163154
}
164155

165-
if(!atLeastOneDriverValid)
166-
result = ZE_RESULT_ERROR_UNINITIALIZED;
167-
else
168-
result = ZE_RESULT_SUCCESS;
169156

170157
if( ZE_RESULT_SUCCESS == result )
171158
{

0 commit comments

Comments
 (0)