Bug Summary

File:home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/PeSmiHandler.c
Warning:line 131, column 6
Value stored to 'RootState' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name PeSmiHandler.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-jump-tables -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/build/StmPkg/Core/Runtime -resource-dir /opt/xgcc/lib/clang/17 -include PcdData.h -D COREBOOT32 -D RELEASE -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/EDKII/BaseTools/Source/C/Include/X64 -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/EdkII/MdePkg/Include -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/EdkII/MdePkg/Include/X64 -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Include -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Include/x64 -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/../Init -I /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/. -internal-isystem /opt/xgcc/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -source-date-epoch 1714465709 -Os -fdebug-compilation-dir=/home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/build/StmPkg/Core/Runtime -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-max-loop 10 -analyzer-output=plist-html -faddrsig -o /cb-build/coreboot_scanbuild.0/PURISM_LIBREM15_V4_STM-scanbuildtmp/2024-05-02-081243-2232343-1/report-J0zqU2.plist -x c /home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/PeSmiHandler.c
1/** @file
2
3PE SMI handler - Used used for getting the other processor state and handling
4SMI's during VM/PE build and execution
5
6This program and the accompanying materials
7are licensed and made available under the terms and conditions of the BSD License
8which accompanies this distribution. The full text of the license may be found at
9http://opensource.org/licenses/bsd-license.php.
10
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14**/
15
16#include "StmRuntime.h"
17#include "PeStm.h"
18#include "PeLoadVm.h"
19
20PE_SMI_CONTROL PeSmiControl;
21
22extern void SignalPeVm(UINT32 CpuIndex);
23extern int CheckAndGetState(UINT32 CpuIndex);
24extern void CpuReadySync(UINT32 Index);
25extern PE_VM_DATA PeVmData[4]; // right now support a max of 3 PE VM (VM 0 is the SMI_HANDLER)
26extern int CheckTimerSTS(UINT32 Index);
27extern void StopSwTimer(void);
28extern void SetEndOfSmi(void);
29extern void PrintVmxState(UINT32 CpuIndex, ROOT_VMX_STATE * RootState);
30
31static UINT32 HandleTimer = 0;
32static UINT32 HandleSmi = 0;
33
34// additional VM/PE SMI handling
35
36static UINT32 retvalue = 0;
37
38UINT32 PeSmiHandler(UINT32 CpuIndex)
39{
40 ROOT_VMX_STATE * RootState;
41 UINT64 * NumProcessors;
42 UINT32 PeType = PE_PERM1;
43 UINT32 CpuNum;
44 UINT32 TimerSTS = 0;
45
46 InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMINULL0, PESMIHSMI2);
47 //DEBUG((EFI_D_INFO, "%ld PeSmiHandler - CurrPeSmiState %ld\n", CpuIndex, PeSmiControl.PeSmiState));
48
49 if(PeSmiControl.PeCpuIndex == (INT32)CpuIndex ) // when the pe/vm comes in...
50 {
51#if 0
52 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
53 "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
54 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
55 PeSmiControl.PeSmiState))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
;
56#endif
57 InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIPNMI25, PESMINULL0);
58 }
59
60 if(InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIPNMI3, PESMIPNMI25) == PESMIPNMI3)
61 {
62 // eventually the VM/PE will be started (or at least built) and this will cause one of the processors
63 // to send a NMI to the VM/PE processor causing it to drop out and process the SMI
64 // when it does, all processors will exit this loop and process the SMI as usual
65
66 SignalPeVm(CpuIndex); // make sure that the PE/VM processes this SMI as well
67 }
68
69 CpuReadySync(CpuIndex); // everyone waits until processor 0 figures out what to do
70
71 switch(PeSmiControl.PeSmiState)
72 {
73 case PESMIPSMI1:
74
75 // VM/PE sends a SMI to the other processors when it wants state information from other CPU's
76
77 NumProcessors = (UINT64 *) PeVmData[PeType].SharedPageStm;
78
79 //sizeof(*NumProcessors) + sizeof(*NumProcessors));
80 RootState = (ROOT_VMX_STATE *) ((char *)NumProcessors + 64);
81
82 // get the local processor state
83
84 GetRootVmxState(CpuIndex, &RootState[CpuIndex]);
85
86 CpuReadySync(CpuIndex); // wait for everyone to finish
87 if(CpuIndex == 0)
88 {
89 // Reset the state
90 InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIPSMI1, PESMINULL0);
91 }
92 return 1; // tell the SmiEventHandler that there is one less processor
93
94 break;
95
96 case PESMIHSMI2:
97
98 if(PeSmiControl.PeCpuIndex == (INT32)CpuIndex )
99 {
100 InterlockedCompareExchange32(&retvalue, 1, 0); // make sure that this is zero
101
102 if(InterlockedCompareExchange32(&PeSmiControl.PeWaitTimer, 1, 1) == 1)
103 {
104 TimerSTS = CheckTimerSTS(CpuIndex);
105
106 if (TimerSTS == 2)
107 {
108 // we have an additional SMI
109 InterlockedCompareExchange32 (&retvalue, 1, 0);
110
111 }
112 else
113 {
114
115 InterlockedCompareExchange32 (&retvalue, 0, 1);
116 }
117
118 if(TimerSTS != 0)
119 {
120#if 0
121 DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
122 "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
123 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
124 PeSmiControl.PeSmiState))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
;
125#endif
126 InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIHSMI2, PESMIHTMR4);
127
128 NumProcessors = (UINT64 *) PeVmData[PeType].SharedPageStm;
129
130 //sizeof(*NumProcessors) + sizeof(*NumProcessors));
131 RootState = (ROOT_VMX_STATE *) ((char *)NumProcessors + 64);
Value stored to 'RootState' is never read
132 }
133 }
134 }
135
136 CpuReadySync(CpuIndex);
137
138 if(InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIHTMR4, PESMIHTMR4) == PESMIHTMR4)
139 {
140 NumProcessors = (UINT64 *) PeVmData[PeType].SharedPageStm;
141
142 //sizeof(*NumProcessors) + sizeof(*NumProcessors));
143 RootState = (ROOT_VMX_STATE *) ((char *)NumProcessors + 64);
144
145 GetRootVmxState(CpuIndex, &RootState[CpuIndex]);
146 CpuReadySync(CpuIndex);
147
148 if (PeSmiControl.PeCpuIndex == (INT32)CpuIndex)
149 {
150 InterlockedCompareExchange32(&PeSmiControl.PeWaitTimer, 1, 0);
151 StopSwTimer();
152
153 // start the VM/PE
154 PeVmData[PeType].StartMode = PEVM_PRESTART_SMI3; // starting from SMI
155 SetEndOfSmi(); // make sure that the timer SMI has been cleared
156
157 InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIHTMR4, PESMINULL0);
158
159 for(CpuNum = 0; CpuNum < mHostContextCommon.CpuNum; CpuNum++)
160 {
161 PrintVmxState(CpuNum, &RootState[CpuNum]);
162 }
163
164 if( mHostContextCommon.StmShutdown == 1)
165 {
166 // time to quit
167 StmTeardown(CpuIndex);
168 }
169
170 if(TimerSTS == 2)
171 {
172 // SMI has happened at the same time, so process it
173 PeVmData[PeType].PeVmState = PE_VM_WAIT_START8;
174 return 0;
175 }
176
177 RunPermVM(CpuIndex);
178 }
179
180 // we do not reset the state here as the VM/PE will be processing
181 // when it competes it should end with a PeSmiState pf PESMIPNMI (waiting for NMI)
182 }
183 else
184 {
185 if(CpuIndex == 0)
186 {
187 // One of these will work
188 InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIHSMI2, PESMINULL0);
189 }
190 retvalue = 0;
191 }
192 return retvalue;
193
194 break;
195
196 case PESMINULL0:
197
198 return 0; // process normally
199 break;
200
201 case PESMIPNMI3:
202 case PESMIHTMR4:
203 // at this point, if this is set, the VM/PE is in the startup process and
204 // has set this so that at the next SMI, if it occurs while the VM/PE is active
205 // the pesmihandler can shoot down the VM/PE
206
207 // we have a one return because the VM/PE will stay in SMM
208
209 //SetEndOfSmi(); // make sure that the timer SMI has been cleared
210
211 return 1;
212 break;
213
214 default:
215
216 DEBUG((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
217 "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
218 CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
219 PeSmiControl.PeSmiState))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n"
, CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0
==1)))
;
220 PeSmiControl.PeSmiState = PESMINULL0;
221 return 0;
222 }
223
224}