Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

powerpc/powernv: implement opal_put_chars_atomic

The RAW console does not need writes to be atomic, so relax
opal_put_chars to be able to do partial writes, and implement an
_atomic variant which does not take a spinlock. This API is used
in xmon, so the less locking that is used, the better chance there
is that a crash can be debugged.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Nicholas Piggin and committed by
Michael Ellerman
17cc1dd4 ac4ac788

+41 -15
+1
arch/powerpc/include/asm/opal.h
··· 305 305 306 306 extern int opal_get_chars(uint32_t vtermno, char *buf, int count); 307 307 extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len); 308 + extern int opal_put_chars_atomic(uint32_t vtermno, const char *buf, int total_len); 308 309 extern int opal_flush_console(uint32_t vtermno); 309 310 310 311 extern void hvc_opal_init_early(void);
+27 -10
arch/powerpc/platforms/powernv/opal.c
··· 344 344 return 0; 345 345 } 346 346 347 - int opal_put_chars(uint32_t vtermno, const char *data, int total_len) 347 + static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, bool atomic) 348 348 { 349 - unsigned long flags; 349 + unsigned long flags = 0 /* shut up gcc */; 350 350 int written; 351 351 __be64 olen; 352 352 s64 rc; ··· 354 354 if (!opal.entry) 355 355 return -ENODEV; 356 356 357 - /* We want put_chars to be atomic to avoid mangling of hvsi 358 - * packets. To do that, we first test for room and return 359 - * -EAGAIN if there isn't enough. 360 - */ 361 - spin_lock_irqsave(&opal_write_lock, flags); 357 + if (atomic) 358 + spin_lock_irqsave(&opal_write_lock, flags); 362 359 rc = opal_console_write_buffer_space(vtermno, &olen); 363 360 if (rc || be64_to_cpu(olen) < total_len) { 364 361 /* Closed -> drop characters */ ··· 388 391 389 392 written = be64_to_cpu(olen); 390 393 if (written < total_len) { 391 - /* Should not happen */ 392 - pr_warn("atomic console write returned partial len=%d written=%d\n", total_len, written); 394 + if (atomic) { 395 + /* Should not happen */ 396 + pr_warn("atomic console write returned partial " 397 + "len=%d written=%d\n", total_len, written); 398 + } 393 399 if (!written) 394 400 written = -EAGAIN; 395 401 } 396 402 397 403 out: 398 - spin_unlock_irqrestore(&opal_write_lock, flags); 404 + if (atomic) 405 + spin_unlock_irqrestore(&opal_write_lock, flags); 399 406 400 407 /* In the -EAGAIN case, callers loop, so we have to flush the console 401 408 * here in case they have interrupts off (and we don't want to wait ··· 411 410 opal_flush_console(vtermno); 412 411 413 412 return written; 413 + } 414 + 415 + int opal_put_chars(uint32_t vtermno, const char *data, int total_len) 416 + { 417 + return __opal_put_chars(vtermno, data, total_len, false); 418 + } 419 + 420 + /* 421 + * opal_put_chars_atomic will not perform partial-writes. Data will be 422 + * atomically written to the terminal or not at all. This is not strictly 423 + * true at the moment because console space can race with OPAL's console 424 + * writes. 425 + */ 426 + int opal_put_chars_atomic(uint32_t vtermno, const char *data, int total_len) 427 + { 428 + return __opal_put_chars(vtermno, data, total_len, true); 414 429 } 415 430 416 431 int opal_flush_console(uint32_t vtermno)
+13 -5
drivers/tty/hvc/hvc_opal.c
··· 183 183 return -ENOMEM; 184 184 pv->proto = proto; 185 185 hvc_opal_privs[termno] = pv; 186 - if (proto == HV_PROTOCOL_HVSI) 187 - hvsilib_init(&pv->hvsi, opal_get_chars, opal_put_chars, 186 + if (proto == HV_PROTOCOL_HVSI) { 187 + /* 188 + * We want put_chars to be atomic to avoid mangling of 189 + * hvsi packets. 190 + */ 191 + hvsilib_init(&pv->hvsi, 192 + opal_get_chars, opal_put_chars_atomic, 188 193 termno, 0); 194 + } 189 195 190 196 /* Instanciate now to establish a mapping index==vtermno */ 191 197 hvc_instantiate(termno, termno, ops); ··· 381 375 else if (of_device_is_compatible(stdout_node,"ibm,opal-console-hvsi")) { 382 376 hvc_opal_boot_priv.proto = HV_PROTOCOL_HVSI; 383 377 ops = &hvc_opal_hvsi_ops; 384 - hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars, 385 - opal_put_chars, index, 1); 378 + hvsilib_init(&hvc_opal_boot_priv.hvsi, 379 + opal_get_chars, opal_put_chars_atomic, 380 + index, 1); 386 381 /* HVSI, perform the handshake now */ 387 382 hvsilib_establish(&hvc_opal_boot_priv.hvsi); 388 383 pr_devel("hvc_opal: Found HVSI console\n"); ··· 415 408 hvc_opal_privs[index] = &hvc_opal_boot_priv; 416 409 hvc_opal_boot_termno = index; 417 410 udbg_init_opal_common(); 418 - hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars, opal_put_chars, 411 + hvsilib_init(&hvc_opal_boot_priv.hvsi, 412 + opal_get_chars, opal_put_chars_atomic, 419 413 index, 1); 420 414 hvsilib_establish(&hvc_opal_boot_priv.hvsi); 421 415 }