Skip to content

Commit

Permalink
FSP/CONSOLE: Fix fsp_console_write_buffer_space() call
Browse files Browse the repository at this point in the history
Kernel calls fsp_console_write_buffer_space() to check console buffer space
availability. If there is enough buffer space to write data, then kernel will
call fsp_console_write() to write actual data.

In some extreme corner cases (like one explained in commit c8a7535)
console becomes full and this function returns 0 to kernel (or space available
in console buffer < next incoming data size). Kernel will continue retrying
until it gets enough space. So we will start seeing RCU stalls.

This patch keeps track of previous available space. If previous space is same
as current means not enough space in console buffer to write incoming data.
It may be due to very high console write operation and slow response from FSP
-OR- FSP has stopped processing data (ex: because of ipmi daemon died). At this
point we will start timer with timeout of SER_BUFFER_OUT_TIMEOUT (10 secs).
If situation is not improved within 10 seconds means something went bad. Lets
return OPAL_RESOURCE so that kernel can drop console write and continue.

CC: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
CC: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
[stewart: reset timeout in fsp_console_write() path]
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
Vasant Hegde authored and stewartsmith committed Oct 11, 2017
1 parent 9d17551 commit 6557a72
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion hw/fsp/fsp-console.c
Expand Up @@ -61,11 +61,15 @@ struct fsp_serial {
struct fsp_msg *poke_msg;
u8 waiting;
u64 irq;
u16 out_buf_prev_len;
u64 out_buf_timeout;
};

#define SER_BUFFER_SIZE 0x00040000UL
#define MAX_SERIAL 4

#define SER_BUFFER_OUT_TIMEOUT 10

static struct fsp_serial fsp_serials[MAX_SERIAL];
static bool got_intf_query;
static struct lock fsp_con_lock = LOCK_UNLOCKED;
Expand Down Expand Up @@ -315,6 +319,8 @@ static void fsp_open_vserial(struct fsp_msg *msg)
fs->in_buf->flags = fs->out_buf->flags = 0;
fs->in_buf->reserved = fs->out_buf->reserved = 0;
fs->in_buf->next_out = fs->out_buf->next_out = 0;
fs->out_buf_prev_len = 0;
fs->out_buf_timeout = 0;
unlock(&fsp_con_lock);

already_open:
Expand Down Expand Up @@ -606,6 +612,12 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length,
requested = 0x1000;
written = fsp_write_vserial(fs, buffer, requested);

if (written) {
/* If we wrote anything, reset timeout */
fs->out_buf_prev_len = 0;
fs->out_buf_timeout = 0;
}

#ifdef OPAL_DEBUG_CONSOLE_IO
prlog(PR_TRACE, "OPAL: console write req=%ld written=%ld"
" ni=%d no=%d\n",
Expand Down Expand Up @@ -655,7 +667,29 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number,
% SER_BUF_DATA_SIZE;
unlock(&fsp_con_lock);

return OPAL_SUCCESS;
/* Console buffer has enough space to write incoming data */
if (*length != fs->out_buf_prev_len) {
fs->out_buf_prev_len = *length;
fs->out_buf_timeout = 0;

return OPAL_SUCCESS;
}

/*
* Buffer is full, start internal timer. We will continue returning
* SUCCESS until timeout happens, hoping FSP will consume data within
* timeout period.
*/
if (fs->out_buf_timeout == 0) {
fs->out_buf_timeout = mftb() +
secs_to_tb(SER_BUFFER_OUT_TIMEOUT);
}

if (tb_compare(mftb(), fs->out_buf_timeout) != TB_AAFTERB)
return OPAL_SUCCESS;

/* Timeout happened. Lets drop incoming data */
return OPAL_RESOURCE;
}

static int64_t fsp_console_read(int64_t term_number, int64_t *length,
Expand Down

0 comments on commit 6557a72

Please sign in to comment.