start filling in
[libreriscv.git] / isa_conflict_resolution.mdwn
1 # Resolving ISA conflicts and providing a pain-free RISC-V Standards Upgrade Path
2
3 In a lengthy thread that ironically was full of conflict indicative
4 of the future direction in which RISC-V will go if left unresolved,
5 multiple Custom Extensions were noted to be permitted free rein to
6 introduce global binary-encoding conflict with no means of resolution
7 described or endorsed by the RISC-V Standard: a practice that has known
8 disastrous and irreversible consequences for any architecture that
9 permits such practices (1).
10
11 Much later on in the discussion it was realised that there is also no way
12 within the current RISC-V Specification to transition to improved versions
13 of the standard, regardless of whether the fixes are absolutely critical
14 show-stoppers or whether they are just keeping the standard up-to-date (2).
15
16 With no transition path there is guaranteed to be tension and conflict
17 within the RISC-V Community over whether revisions should be made:
18 should existing legacy designs be prioritised, mutually-exclusively over
19 future designs (and what happens during the transition period is absolute
20 chaos, with the compiler toolchain, software ecosystem and ultimately
21 the end-users bearing the full brunt of the impact). If several
22 overlapping revisions are required that have not yet transitioned out
23 of use (which could take well over two decades to occur) the situation
24 becomes disastrous for the credibility of the entire RISC-V ecosystem.
25
26 It was also pointed out that Compliance is an extremely important factor
27 to take into consideration, and that Custom Extensions (as being optional)
28 effectively and quite reasonably fall entirely outside of the scope of
29 Compliance Testing. At this point in the discussion however it was not
30 yet noted the stark problem that the *mandatory* RISC-V Specification
31 also faces, by virtue of there being no transitional way to bring in
32 show-stopping critical alterations.
33
34 To put this into perspective, just taking into account hardware costs
35 alone: with production mask charges for 28nm being around USD $1.5m,
36 engineering development costs and licensing of RTLs for peripherals
37 being of a similar magnitude, no manufacturer is going to back away
38 from selling a "flawed" or "legacy" product (whether it complies with
39 the RISC-V Specification or not) without a bitter fight.
40
41 It was also pointed out that there will be significant software tool
42 maintenance costs for manufacturers, meaning that the probability will
43 be extremely high that they will refuse to shoulder such costs, and
44 will publish and continue to publish (and use) hopelessly out-of-date
45 unpatched tools. This practice is well-known to result in security
46 flaws going unpatched, with one of many immediate undesirable consequences
47 being that product in extremely large volume gets discarded into landfill.
48
49 **All and any of the issues that were discussed, and all of those that
50 were not, can be avoided by providing a hardware-level runtime-enabled
51 forwards and backwards compatible transition path between *all* parts
52 (mandatory or not) of current and future revisions of the RISC-V ISA
53 Standard.**
54
55 The rest of the discussion - indicative as it was of the stark mutually
56 exclusive gap being faced by the RISC-V ISA Standard given that it does
57 not cope with the problem - was an effort by two groups in two clear
58 camps: one that wanted things to remain as they are, and another that
59 made efforts to point out that the consequences of not taking action
60 are clearly extreme and irreversible (which, unfortunately, given the
61 severity, some of the first group were unable to believe, despite there
62 being clear historical precedent for the exact same mistake being made in
63 other architectures, and the consequences on the same being absolutely
64 clear).
65
66 However after a significant amount of time, certain clear requirements came
67 out of the discussion:
68
69 * Any proposal must be a minimal change with minimal (or zero) impact
70 * Any proposal should place no restriction on existing or future
71 ISA encoding space
72 * Any proposal should take into account that there are existing implementors
73 of the (yet to be finalised but still "partly frozen") Standard who may
74 resist, for financial investment reasons, efforts to make any change
75 (at all) that could cost them immediate short-term profits.
76
77 Several proposals were put forward (and some are still under discussion)
78
79 * "Do nothing": problem is not severe: no action needed.
80 * "Do nothing": problem is out-of-scope for RISC-V Foundation.
81 * "Do nothing": problem complicates Compliance Testing (and is out of scope)
82 * "MISA": the MISA CSR enables and disables extensions already: use that
83 * "MISA-like": a new CSR which switches in and out new encodings
84 (without destroying state)
85 * "mvendorid/marchid WARL": switching the entire "identity" of a machine
86 * "ioctl-like": a OO proposal based around the linux kernel "ioctl" system.
87
88 Each of these will be discussed below in their own sections.
89
90 # Do nothing (no problem exists)
91
92 TBD (basically not an option).
93
94 There were several solutions offered that fell into this category.
95 A few of them are listed in the introduction; more are listed below,
96 and it was exhaustively (and exhaustingly) established that none of
97 them are workable.
98
99 Initially it was pointed out that Fabless Semiconductor companies could
100 simply license multiple Custom Extensions and a suitable RISC-V core, and
101 modify them accordingly. The Fabless Semi Company would be responsible
102 for paying the NREs on re-developing the test vectors (as the extension
103 licensers would be extremely unlikely to do that without payment), and
104 given that said Companies have an "integration" job to do, it would
105 be reasonable to expect them to have such additional costs as well.
106
107 The costs of this approach were outlined and discussed as being
108 disproportionate and extreme compared to the actual likely cost of
109 licensing the Custom Extensions in the first place. Additionally it
110 was pointed out that not only hardware NREs would be involved but
111 custom software tools (compilers and more) would also be required
112 (and maintained separately, on the basis that upstream would not
113 accept them except under extreme pressure, and then only with
114 prejudice).
115
116 All similar schemes involving customisation of the custom extensions
117 were likewise rejected, but not before the customisation process was
118 mistakenly conflated with tne *normal* integration process of developing
119 a custom processor (Bus Architectures, Cache layouts, peripheral layouts).
120
121 The most compelling hardware-related reason (excluding the severe impact on
122 the software ecosystem) for rejecting the customisation-of-customisation
123 approach was the case where Extensions were using an instruction encoding
124 space (48-bit, 64-bit) *greater* than that which the chosen core could
125 cope with (32-bit, 48-bit).
126
127 Overall, none of the options presented were feasible, and, in addition,
128 with no clear leadership from the RISC-V Foundation on how to avoid
129 global world-wide encoding conflict, even if they were followed through,
130 still would result in the failure of the RISC-V ecosystem due to
131 irreversible global conflicting ISA binary-encoding meanings (POWERPC's
132 Altivec / SPE nightmare).
133
134 This in addition to the case where the RISC-V Foundation wishes to
135 fix a critical show-stopping update to the Standard, post-release,
136 where billions of dollars have been spent on deploying RISC-V in the
137 field.
138
139 # Do nothing (out of scope)
140
141 TBD (basically, may not be RV Foundation's "scope", still results in
142 problem, so not an option)
143
144 This was one of the first arguments presented: The RISC-V Foundation
145 considers Custom Extensions to be "out of scope"; that "it's not their
146 problem, therefore there isn't a problem".
147
148 The logical errors in this argument were quickly enumerated: namely that
149 the RISC-V Foundation is not in control of the uses to which RISC-V is
150 put, such that public global conflicts in binary-encoding are a hundred
151 percent guaranteed to occur, and a hundred percent guaranteed to occur in
152 *commodity* hardware where Debian, Fedora, SUSE and other distros will
153 be hardest hit by the resultant chaos, and that will just be the more
154 "visible" aspect of the underlying problem.
155
156 # Do nothing (Compliance too complex, therefore out of scope)
157
158 TBD (basically, may not be RV Foundation's "scope", still results in
159 problem, so not an option)
160
161 The summary here was that Compliance testing of Custom Extensions is
162 not just out-of-scope, but even if it was taken into account that
163 binary-encoding meanings could change, it would still be out-of-scope.
164
165 However at the time that this argument was made, it had not yet been
166 appreciated fully the impact that revisions to the Standard would have,
167 when billions of dollars worth of (older, legacy) RISC-V hardware had
168 already been deployed.
169
170 Two interestingly diametrically-opposed equally valid arguments exist here:
171
172 * Whilst Compliance testing of Custom Extensions is definitely legitimately
173 out of scope, Compliance testing of simultaneous legacy (old revisions of
174 ISA Standards) and current (new revisions of ISA Standard) definitely
175 is not. Efforts to reduce *Compliance Testing* complexity is therefore
176 "Compliance Tail Wagging Standard Dog".
177 * Beyond a certain threshold, complexity of Compliance Testing is so
178 burdensome that it risks outright rejection of the entire Standard.
179
180 Meeting these two diametrically-opposed perspectives requires that the
181 solution be very, very simple.
182
183 # MISA
184
185 TBD, basically MISA not suitable
186
187 MISA permits extensions to be disabled by masking out the relevant bit.
188 Hypothetically it could be used to disable one extension, then enable
189 another that happens to use the same binary encoding.
190
191 *However*:
192
193 * MISA Extension disabling is permitted (optionally) to **destroy**
194 the state information. Thus it is totally unsuitable for cases
195 where instructions from different Custom extensions are needed in
196 quick succession.
197 * MISA was only designed to cover Standard Extensions.
198 * There is nothing to prevent multiple Extensions being enabled
199 that wish to simultaneously interpret the same binary encoding.
200
201 Overall, whilst the MISA concept is a step in the right direction it's
202 a hundred percent unsuitable for solving the problem.
203
204 # MISA-like
205
206 TBD, basically same as mvend/march WARL except needs an extra CSR where
207 mv/ma doesn't.
208
209 Out of the MISA discussion came a "MISA-like" proposal, which would
210 take into account the flaws pointed out by trying to use "MISA":
211
212 * The MISA-like CSR's meaning would be identified by compilers using the
213 mvendor-id/march-id tuple as a compiler target
214 * Each custom-defined bit of the MISA-like CSR would (mutually-exclusively)
215 redirect binary encoding(s) to specific encodings
216 * No Extension would *actually* be disabled: its internal state would
217 be left on (permanently) so that switching could be done inside
218 inner loops.
219
220 Whilst it was the first "workable" solution it was also noted that the
221 scheme is quite invasive: it requires an entirely new CSR to be added
222 to the privileged spec. This does not completely fulfil the "minimum
223 impact" requirement.
224
225 Also interesting around the same time an additional discussion was
226 raised that covered the *compiler* side of the same equation. This
227 revolved around using mvendorid-marchid tuples at the compiler level,
228 to be put into assembly output (by gcc), preserving the required
229 *globally* unique identifying information for binutils to successfully
230 turn the custom instruction into an actual binary-encoding (plus
231 binary-encoding of the context-switching information). (**TBD, Jacob,
232 separate page? review this para?**)
233
234 # mvendorid/marchid WARL
235
236 TBD paraphrase and clarify
237
238 Coming out of the software-related proposal by Jacob, which hinged on
239 the idea of a global gcc / binutils database that kept and coordinated
240 architectural encodings, was to quite simply make the mvendorid and
241 marchid CSRs have WARL (writeable) characteristics. For instances
242 where mvendorid and marchid are readable, that would be taken to be
243 a Standards-mandatory "declaration" that the architecture has *no*
244 Custom Extensions.
245
246 This incredibly simple non-invasive idea has some unique and distinct
247 advantages over other proposals:
248
249 * Existing designs - even though the specification is not finalised
250 (but has "frozen" aspects) - would be completely unaffected: the
251 change is to the "wording" of the specification to "retrospectively"
252 fit reality.
253 * Unlike with the MISA idea this is *purely* at the "decode" phase:
254 no internal Extension state information is permitted to be disabled,
255 altered or destroyed as a direct result of writing to the
256 mvendor/march-id CSRs.
257 * Compliance Testing may be carried out with a different vendorid/marchid
258 tuple set prior to a test, allowing a vendor to claim *Certified*
259 compatibility with *both* one (or more) legacy variants of the RISC-V
260 Specification *and* with a present one.
261 * With sufficient care taken in the implementation an implementor
262 may have multiple interpretations of the same binary encoding within
263 an inner loop, with a single instruction (to the WARL register)
264 changing the meaning.
265
266 A couple of points were made:
267
268 * Compliance Testing may **fail** any system that has mvendorid/marchid
269 as WARL. This however is a clear case of "Compliance Tail Wagging Standard
270 Dog".
271 * The redirection of meaning of certain binary encodings to multiple
272 engines was considered extreme, eyebrow-raising, and also (importantly)
273 potentially expensive, introducing significant latency at the decode
274 phase.
275
276 On this latter point, it was observed that MISA already switches out entire
277 sets of instructions (interacts at the "decode" phase). The difference
278 between what MISA does and the mvendor/march-id WARL idea is that whilst
279 MISA only switches instruction decoding on (or off), the WARL idea
280 *redirects* encoding, to *different* engines, fortunately in a deliberately
281 mutually-exclusive fashion.
282
283 > that particular lead that:
284 >
285 > * MISA Extension disabling is permitted (optionally) to DESTROY the state
286 > information (which means that it *has* to be re-initialised just to be
287 > safe... mistake in the standard, there), and * MISA was only designed
288 > to cover Standard Extensions.
289 >
290 > So the practice of switching extensions in and out - and the resultant
291 > "disablement" and "enablement" at the *instruction decode phase* is
292 > *already* a hard requirement as part of conforming with the present
293 > RISC-V Specification.
294 >
295 > Around the same MISA discussion, someone else also kindly pointed out
296 > that one solution to the heavyweight nature of the switching would
297 > be to deliberately introduce a pipeline stall whilst the switching is
298 > occurring: I can see the sense in that approach, even if I don't know the
299 > full details of what each implementor might choose to do. They may even
300 > choose two, or three, or N pipeline stalls: it really doesn't matter,
301 > as it's an implementors' choice (and problem to solve).
302 >
303 > So yes it's pretty heavy-duty... and also already required.
304 >
305 > For the case where "legacy" variants of the RISC-V Standard are
306 > backwards-forwards-compatibly supported over a 10-20 year period
307 > in Industrial and Military/Goverment-procurement scenarios (so that
308 > the impossible-to-achieve pressure is off to get the spec ABSOLUTELY
309 > correct, RIGHT now), nobody would expect a seriously heavy-duty amount
310 > of instruction-by-instruction switching: it'd be used pretty much once
311 > and only once at boot-up (or once in a Hypervisor Virtual Machine client)
312 > and that's it.
313 >
314 > I can however foresee instances where implementors would actually
315 > genuinely want a bank of operations to be carried out using one extension,
316 > followed immediately by another bank from a (conflicting binary-encoding)
317 > extension, in an inner loop: Software-defined MPEG / MP4 decode to call
318 > DCT block decode Custom Extension followed immediately by Custom Video
319 > Processing Extension followed immediately by Custom DSP Processing
320 > Extension to do YUV-to-RGB conversion for example is something that
321 > is clearly desirable. Solving that one would be entiiirely their
322 > problem... and the RISC-V Specification really really should give them
323 > the space to do that in a clear-cut unambiguous way.
324
325 # ioctl-like
326
327 TBD - [[ioctl]] for full details, summary kept here
328
329 # Discussion and analysis
330
331 TBD
332
333 # Conclusion
334
335 TBD
336
337 # Conversation Exerpts
338
339 The following conversation exerpts are taken from the ISA-dev discussion
340
341 ## (1) Albert Calahan on SPE / Altiven conflict in POWERPC
342
343 > Yes. Well, it should be blocked via legal means. Incompatibility is
344 > a disaster for an architecture.
345 >
346 > The viability of PowerPC was badly damaged when SPE was
347 > introduced. This was a vector instruction set that was incompatible
348 > with the AltiVec instruction set. Software vendors had to choose,
349 > and typically the choice was "neither". Nobody wants to put in the
350 > effort when there is uncertainty and a market fragmented into
351 > small bits.
352 > Note how Intel did not screw up. When SSE was added, MMX remained.
353 > Software vendors could trust that instructions would be supported.
354 > Both MMX and SSE remain today, in all shipping processors. With very
355 > few exceptions, Intel does not ship chips with missing functionality.
356 > There is a unified software ecosystem.
357 >
358 > This goes beyond the instruction set. MMU functionality also matters.
359 > You can add stuff, but then it must be implemented in every future CPU.
360 > You can not take stuff away without harming the architecture.
361
362 ## (2) Luke Kenneth Casson Leighton on Standards backwards-compatibility
363
364 > For the case where "legacy" variants of the RISC-V Standard are
365 > backwards-forwards-compatibly supported over a 10-20 year period in
366 > Industrial and Military/Goverment-procurement scenarios (so that the
367 > impossible-to-achieve pressure is off to get the spec ABSOLUTELY
368 > correct, RIGHT now), nobody would expect a seriously heavy-duty amount
369 > of instruction-by-instruction switching: it'd be used pretty much once
370 > and only once at boot-up (or once in a Hypervisor Virtual Machine
371 > client) and that's it.
372
373 ## (3) Allen Baum on Standards Compliance
374
375 > Putting my compliance chair hat on: One point that was made quite
376 > clear to me is that compliance will only test that an implementation
377 > correctly implements the portions of the spec that are mandatory, and
378 > the portions of the spec that are optional and the implementor claims
379 > it is implementing. It will test nothing in the custom extension space,
380 > and doesn't monitor or care what is in that space.
381