x86/pv-shim: shadow PV console's page for L2 DomU

Signed-off-by: Sergey Dyasli <sergey.dyasli@citrix.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
[remove notify_guest helper and directly use pv_shim_inject_evtchn]
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
Sergey Dyasli authored and Wei Liu committed 2018-01-16 18:34:05 +00:00
1 parent 49f79fe03d
commit 5ef49f185c
5 files changed
+209 -4

No files matched your search

+27 -4
View File
@@ -25,6 +25,8 @@
#include <xen/iocap.h>
#include <xen/shutdown.h>
#include <xen/types.h>
#include <xen/consoled.h>
#include <xen/pv_console.h>
#include <asm/apic.h>
#include <asm/dom0_build.h>
@@ -127,13 +129,28 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,
})
SET_AND_MAP_PARAM(HVM_PARAM_STORE_PFN, si->store_mfn, store_va);
SET_AND_MAP_PARAM(HVM_PARAM_STORE_EVTCHN, si->store_evtchn, 0);
SET_AND_MAP_PARAM(HVM_PARAM_CONSOLE_EVTCHN, si->console.domU.evtchn, 0);
if ( !pv_console )
{
SET_AND_MAP_PARAM(HVM_PARAM_CONSOLE_PFN, si->console.domU.mfn,
console_va);
SET_AND_MAP_PARAM(HVM_PARAM_CONSOLE_EVTCHN, si->console.domU.evtchn, 0);
}
#undef SET_AND_MAP_PARAM
else
{
/* Allocate a new page for DomU's PV console */
void *page = alloc_xenheap_pages(0, MEMF_bits(32));
uint64_t console_mfn;
ASSERT(page);
clear_page(page);
console_mfn = virt_to_mfn(page);
si->console.domU.mfn = console_mfn;
share_xen_page_with_guest(mfn_to_page(console_mfn), d,
XENSHARE_writable);
replace_va_mapping(d, l4start, console_va, console_mfn);
dom0_update_physmap(d, (console_va - va_start) >> PAGE_SHIFT,
console_mfn, vphysmap);
consoled_set_ring_addr(page);
}
pv_hypercall_table_replace(__HYPERVISOR_event_channel_op,
(hypercall_fn_t *)pv_shim_event_channel_op,
(hypercall_fn_t *)pv_shim_event_channel_op);
@@ -341,7 +358,13 @@ static long pv_shim_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
if ( copy_from_guest(&send, arg, 1) != 0 )
return -EFAULT;
rc = xen_hypercall_event_channel_op(EVTCHNOP_send, &send);
if ( pv_console && send.port == pv_console_evtchn() )
{
consoled_guest_rx();
rc = 0;
}
else
rc = xen_hypercall_event_channel_op(EVTCHNOP_send, &send);
break;
}
+1
View File
@@ -9,3 +9,4 @@ obj-$(CONFIG_HAS_EHCI) += ehci-dbgp.o
obj-$(CONFIG_ARM) += arm-uart.o
obj-y += serial.o
obj-$(CONFIG_XEN_GUEST) += xen_pv_console.o
obj-$(CONFIG_PV_SHIM) += consoled.o
+6
View File
@@ -32,6 +32,7 @@
#include <xen/warning.h>
#ifdef CONFIG_X86
#include <xen/consoled.h>
#include <xen/pv_console.h>
#include <asm/guest.h>
#endif
@@ -415,6 +416,11 @@ static void __serial_rx(char c, struct cpu_user_regs *regs)
serial_rx_ring[SERIAL_RX_MASK(serial_rx_prod++)] = c;
/* Always notify the guest: prevents receive path from getting stuck. */
send_global_virq(VIRQ_CONSOLE);
#ifdef CONFIG_X86
if ( pv_shim && pv_console )
consoled_guest_tx(c);
#endif
}
static void serial_rx(char c, struct cpu_user_regs *regs)
+148
View File
@@ -0,0 +1,148 @@
/******************************************************************************
* drivers/char/consoled.c
*
* A backend driver for Xen's PV console.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (c) 2017 Citrix Systems Ltd.
*/
#include <xen/lib.h>
#include <xen/event.h>
#include <xen/pv_console.h>
#include <xen/consoled.h>
#include <asm/guest.h>
static struct xencons_interface *cons_ring;
static DEFINE_SPINLOCK(rx_lock);
void consoled_set_ring_addr(struct xencons_interface *ring)
{
cons_ring = ring;
}
struct xencons_interface *consoled_get_ring_addr(void)
{
return cons_ring;
}
#define BUF_SZ 255
static char buf[BUF_SZ + 1];
/* Receives characters from a domain's PV console */
size_t consoled_guest_rx(void)
{
size_t recv = 0, idx = 0;
XENCONS_RING_IDX cons, prod;
if ( !cons_ring )
return 0;
spin_lock(&rx_lock);
cons = cons_ring->out_cons;
prod = ACCESS_ONCE(cons_ring->out_prod);
/*
* Latch pointers before accessing the ring. Included compiler barrier also
* ensures that pointers are really read only once into local variables.
*/
smp_rmb();
ASSERT((prod - cons) <= sizeof(cons_ring->out));
/* Is the ring empty? */
if ( cons == prod )
goto out;
while ( cons != prod )
{
char c = cons_ring->out[MASK_XENCONS_IDX(cons++, cons_ring->out)];
buf[idx++] = c;
recv++;
if ( idx >= BUF_SZ )
{
pv_console_puts(buf);
idx = 0;
}
}
if ( idx )
{
buf[idx] = '\0';
pv_console_puts(buf);
}
/* No need for a mem barrier because every character was already consumed */
barrier();
ACCESS_ONCE(cons_ring->out_cons) = cons;
pv_shim_inject_evtchn(pv_console_evtchn());
out:
spin_unlock(&rx_lock);
return recv;
}
/* Sends a character into a domain's PV console */
size_t consoled_guest_tx(char c)
{
size_t sent = 0;
XENCONS_RING_IDX cons, prod;
if ( !cons_ring )
return 0;
cons = ACCESS_ONCE(cons_ring->in_cons);
prod = cons_ring->in_prod;
/*
* Latch pointers before accessing the ring. Included compiler barrier also
* ensures that pointers are really read only once into local variables.
*/
smp_rmb();
ASSERT((prod - cons) <= sizeof(cons_ring->in));
/* Is the ring out of space? */
if ( sizeof(cons_ring->in) - (prod - cons) == 0 )
goto notify;
cons_ring->in[MASK_XENCONS_IDX(prod++, cons_ring->in)] = c;
sent++;
/* Write to the ring before updating the pointer */
smp_wmb();
ACCESS_ONCE(cons_ring->in_prod) = prod;
notify:
/* Always notify the guest: prevents receive path from getting stuck. */
pv_shim_inject_evtchn(pv_console_evtchn());
return sent;
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
+27
View File
@@ -0,0 +1,27 @@
#ifndef __XEN_CONSOLED_H__
#define __XEN_CONSOLED_H__
#include <public/io/console.h>
#ifdef CONFIG_PV_SHIM
void consoled_set_ring_addr(struct xencons_interface *ring);
struct xencons_interface *consoled_get_ring_addr(void);
size_t consoled_guest_rx(void);
size_t consoled_guest_tx(char c);
#else
size_t consoled_guest_tx(char c) { return 0; }
#endif /* !CONFIG_PV_SHIM */
#endif /* __XEN_CONSOLED_H__ */
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.