Re: [Xen-devel] [PATCH 2/2 v2] xen: Fix 16550 UART console for HP Moonshot (Aarch64) platform

2017-11-21 Thread Bhupinder Thakur

Hi,


On Thursday 16 November 2017 03:26 PM, George Dunlap wrote:

On Nov 15, 2017, at 9:20 PM, Konrad Rzeszutek Wilk  
wrote:

On Thu, Nov 09, 2017 at 03:49:24PM +0530, Bhupinder Thakur wrote:

The console was not working on HP Moonshot (HPE Proliant Aarch64) because
the UART registers were accessed as 8-bit aligned addresses. However,
registers are 32-bit aligned for HP Moonshot.

Since ACPI/SPCR table does not specify the register shift to be applied to 
the
register offset, this patch implements an erratum to correctly set the 
register
shift for HP Moonshot.

Similar erratum was implemented in linux:

commit 79a648328d2a604524a30523ca763fbeca0f70e3
Author: Loc Ho 
Date:   Mon Jul 3 14:33:09 2017 -0700

ACPI: SPCR: Workaround for APM X-Gene 8250 UART 32-alignment errata

APM X-Gene verion 1 and 2 have an 8250 UART with its register
aligned to 32-bit. In addition, the latest released BIOS
encodes the access field as 8-bit access instead 32-bit access.
This causes no console with ACPI boot as the console
will not match X-Gene UART port due to the lack of mmio32
option.

Signed-off-by: Loc Ho 
Acked-by: Greg Kroah-Hartman 
Signed-off-by: Rafael J. Wysocki 

Any particular reason you offset this whole commit description by four spaces?

I get this effect when I use “git show” to look at a changeset for some reason. 
 Bhupinder, did you perhaps export a changeset as a patch using “git show” and 
then re-import it?

In any case, this needs to be fixed.

Yes I copied the commit message from git show. I will align the text.

  -George


Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 1/2 v2] xen: Add support for initializing 16550 UART using ACPI

2017-11-15 Thread Bhupinder Thakur

Hi,


On Thursday 09 November 2017 05:01 PM, Roger Pau Monné wrote:

On Thu, Nov 09, 2017 at 03:49:23PM +0530, Bhupinder Thakur wrote:

Currently, Xen supports only DT based initialization of 16550 UART.
This patch adds support for initializing 16550 UART using ACPI SPCR table.

This patch also makes the uart initialization code common between DT and
ACPI based initialization.

Signed-off-by: Bhupinder Thakur 
---
TBD:
There was one review comment from Julien about how the uart->io_size is being
calculated. Currently, I am calulating the io_size based on address of the last
UART register.

pci_uart_config also calcualates the uart->io_size like this:

uart->io_size = max(8U << param->reg_shift,
  param->uart_offset);

I am not sure whether we can use similar logic for calculating uart->io_size.

Changes since v1:
- Reused common code between DT and ACPI based initializations

CC: Andrew Cooper 
CC: George Dunlap 
CC: Ian Jackson 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Wei Liu 
CC: Julien Grall 

  xen/drivers/char/ns16550.c  | 132 
  xen/include/xen/8250-uart.h |   1 +
  2 files changed, 121 insertions(+), 12 deletions(-)

diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index e0f8199..cf42fce 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -1463,18 +1463,13 @@ void __init ns16550_init(int index, struct 
ns16550_defaults *defaults)
  }
  
  #ifdef CONFIG_HAS_DEVICE_TREE

-static int __init ns16550_uart_dt_init(struct dt_device_node *dev,
-   const void *data)
+static int ns16550_init_dt(struct ns16550 *uart,
+   const struct dt_device_node *dev)

Why are you dropping the __init attribute?
This is a helper I defined for initializing the uart and called from the 
main __init function.



  {
-struct ns16550 *uart;
-int res;
+int res = 0;
  u32 reg_shift, reg_width;
  u64 io_size;
  
-uart = &ns16550_com[0];

-
-ns16550_init_common(uart);
-
  uart->baud  = BAUD_AUTO;
  uart->data_bits = 8;
  uart->parity= UART_PARITY_NONE;
@@ -1510,18 +1505,103 @@ static int __init ns16550_uart_dt_init(struct 
dt_device_node *dev,
  
  uart->dw_usr_bsy = dt_device_is_compatible(dev, "snps,dw-apb-uart");
  
+return res;

+}
+#else
+static int ns16550_init_dt(struct ns16550 *uart,
+   const struct dt_device_node *dev)
+{
+return -EINVAL;
+}
+#endif
+
+#ifdef CONFIG_ACPI
+#include 

Please place the include at the top of the file, together with the
other ones.

ok.



+static int ns16550_init_acpi(struct ns16550 *uart,
+ const void *data)
+{
+struct acpi_table_spcr *spcr = NULL;
+int status = 0;

I don't think you need to initialize any of those two variables. Or
do:

int status = acpi_get_table(ACPI_SIG_SPCR, 0,
 (struct acpi_table_header **)&spcr);

if ( ... )


ok.

+status = acpi_get_table(ACPI_SIG_SPCR, 0,
+(struct acpi_table_header **)&spcr);
+
+if ( ACPI_FAILURE(status) )
+{
+printk("ns16550: Failed to get SPCR table\n");
+return -EINVAL;
+}
+
+uart->baud  = BAUD_AUTO;
+uart->data_bits = 8;
+uart->parity= spcr->parity;
+uart->stop_bits = spcr->stop_bits;
+uart->io_base = spcr->serial_port.address;
+uart->irq = spcr->interrupt;
+uart->reg_width = spcr->serial_port.bit_width / 8;
+uart->reg_shift = 0;
+uart->io_size = UART_MAX_REG << uart->reg_shift;

You seem to align some of the '=' above but not all, please do either
one, but consistently.

I will align the assignments.

+
+irq_set_type(spcr->interrupt, spcr->interrupt_type);
+
+return 0;
+}
+#else
+static int ns16550_init_acpi(struct ns16550 *uart,
+ const void *data)
+{
+return -EINVAL;
+}
+#endif
+
+static int ns16550_uart_init(struct ns16550 **puart,
+ const void *data, bool acpi)
+{
+struct ns16550 *uart = &ns16550_com[0];
+
+*puart = uart;
+
+ns16550_init_common(uart);
+
+return ( acpi ) ? ns16550_init_acpi(uart, data)

   ^ unneeded parentheses.

+: ns16550_init_dt(uart, data);
+}
+
+static void ns16550_vuart_init(struct ns16550 *uart)
+{
+#ifdef CONFIG_ARM
  uart->vuart.base_addr = uart->io_base;
  uart->vuart.size = uart->io_size;
-uart->vuart.data_off = UART_THR <reg_shift;
-uart->vuart.status_off = UART_LSR<reg_shift;
-uart->vuart.status = UART_LSR_THRE|UART_LSR_TEMT;
+uart->vuart.data_off = UART_THR << uart->reg_shift;
+uart->vuart.status_off = UART_LSR &l

Re: [Xen-devel] [PATCH 1/2 v2] xen: Add support for initializing 16550 UART using ACPI

2017-11-15 Thread Bhupinder Thakur

Hi Julien,


On Tuesday 14 November 2017 12:21 AM, Julien Grall wrote:

Hi Bhupinder,

On 11/09/2017 10:19 AM, Bhupinder Thakur wrote:

Currently, Xen supports only DT based initialization of 16550 UART.
This patch adds support for initializing 16550 UART using ACPI SPCR 
table.


This patch also makes the uart initialization code common between DT and
ACPI based initialization.


Can you please have one patch to refactor the code and one to add ACPI 
support? This will be easier to review.



ok.


Signed-off-by: Bhupinder Thakur 
---
TBD:
There was one review comment from Julien about how the uart->io_size 
is being
calculated. Currently, I am calulating the io_size based on address 
of the last

UART register.

pci_uart_config also calcualates the uart->io_size like this:

uart->io_size = max(8U << param->reg_shift,
  param->uart_offset);

I am not sure whether we can use similar logic for calculating 
uart->io_size.


Changes since v1:
- Reused common code between DT and ACPI based initializations

CC: Andrew Cooper 
CC: George Dunlap 
CC: Ian Jackson 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Wei Liu 
CC: Julien Grall 

  xen/drivers/char/ns16550.c  | 132 


  xen/include/xen/8250-uart.h |   1 +
  2 files changed, 121 insertions(+), 12 deletions(-)

diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index e0f8199..cf42fce 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -1463,18 +1463,13 @@ void __init ns16550_init(int index, struct 
ns16550_defaults *defaults)

  }
    #ifdef CONFIG_HAS_DEVICE_TREE
-static int __init ns16550_uart_dt_init(struct dt_device_node *dev,
-   const void *data)
+static int ns16550_init_dt(struct ns16550 *uart,
+   const struct dt_device_node *dev)
  {
-    struct ns16550 *uart;
-    int res;
+    int res = 0;
  u32 reg_shift, reg_width;
  u64 io_size;
  -    uart = &ns16550_com[0];
-
-    ns16550_init_common(uart);
-
  uart->baud  = BAUD_AUTO;
  uart->data_bits = 8;
  uart->parity    = UART_PARITY_NONE;
@@ -1510,18 +1505,103 @@ static int __init 
ns16550_uart_dt_init(struct dt_device_node *dev,
    uart->dw_usr_bsy = dt_device_is_compatible(dev, 
"snps,dw-apb-uart");

  +    return res;
+}
+#else
+static int ns16550_init_dt(struct ns16550 *uart,
+   const struct dt_device_node *dev)
+{
+    return -EINVAL;
+}
+#endif
+
+#ifdef CONFIG_ACPI
+#include 
+static int ns16550_init_acpi(struct ns16550 *uart,
+ const void *data)
+{
+    struct acpi_table_spcr *spcr = NULL;
+    int status = 0;
+
+    status = acpi_get_table(ACPI_SIG_SPCR, 0,
+    (struct acpi_table_header **)&spcr);
+
+    if ( ACPI_FAILURE(status) )
+    {
+    printk("ns16550: Failed to get SPCR table\n");
+    return -EINVAL;
+    }
+
+    uart->baud  = BAUD_AUTO;
+    uart->data_bits = 8;
+    uart->parity    = spcr->parity;
+    uart->stop_bits = spcr->stop_bits;
+    uart->io_base = spcr->serial_port.address;
+    uart->irq = spcr->interrupt;
+    uart->reg_width = spcr->serial_port.bit_width / 8;
+    uart->reg_shift = 0;
+    uart->io_size = UART_MAX_REG << uart->reg_shift;
+
+    irq_set_type(spcr->interrupt, spcr->interrupt_type);
+
+    return 0;
+}
+#else
+static int ns16550_init_acpi(struct ns16550 *uart,
+ const void *data)
+{
+    return -EINVAL;
+}
+#endif
+
+static int ns16550_uart_init(struct ns16550 **puart,
+ const void *data, bool acpi)
+{
+    struct ns16550 *uart = &ns16550_com[0];
+
+    *puart = uart;
+
+    ns16550_init_common(uart);
+
+    return ( acpi ) ? ns16550_init_acpi(uart, data)
+    : ns16550_init_dt(uart, data);
+}


This function does not look very useful but getting &ns16550_com[0].
I do agree that we need it is nice to have common code, but I think 
you went too far here.


There are no need for 3 separate functions and 2 functions for each 
firmware.


I think duplicating the code of ns16550_uart_init for ACPI and DT is 
fine. You could then create a function that is a merge vuart_init and 
register_init.


We can retain the ns16550_init_acpi() and ns16550_init_dt() and call 
them directly from the main __init functions.



This would also limit the number of #ifdef within this code.


+
+static void ns16550_vuart_init(struct ns16550 *uart)
+{
+#ifdef CONFIG_ARM
  uart->vuart.base_addr = uart->io_base;
  uart->vuart.size = uart->io_size;
-    uart->vuart.data_off = UART_THR <reg_shift;
-    uart->vuart.status_off = UART_LSR<reg_shift;
-    uart->vuart.status = UART_LSR_THRE|UART_LSR_TEMT;
+    uart->v

Re: [Xen-devel] [PATCH 1/4 v3 for-4.10] libxl: Fix the bug introduced in commit "libxl: use correct type modifier for vuart_gfn"

2017-11-14 Thread Bhupinder Thakur
Hi,

On 14 Nov 2017 3:35 pm, "Wei Liu"  wrote:

> On Mon, Nov 13, 2017 at 03:56:23PM +, Julien Grall wrote:
> > Hi Wei,
> >
> > Sorry I missed that e-mail.
> >
> > On 10/31/2017 10:07 AM, Wei Liu wrote:
> > > Change the tag to for-4.10.
> > >
> > > Julien, this is needed to fix vuart emulation.
> >
> > To confirm, only patch #1 is candidate for Xen 4.10, right? The rest
> will be
> > queued for Xen 4.11?
> >
>
> I think so.
>
> Bhupinder, can you confirm that?
>

Yes. Only first patch is required for fixing the compilation issue.

Regards,
Bhupinder
___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] Bringing up OSS test framework on moonshot(aarch64) systems

2017-11-13 Thread Bhupinder Thakur

Hi Ian,


On Wednesday 08 November 2017 05:09 PM, Ian Jackson wrote:

Bhupinder Thakur writes ("Bringing up OSS test framework on moonshot(aarch64) 
systems"):

While going through [1], I have some queries/doubts on the configuration.
H
NetNameservers 10.80.248.2 10.80.16.28 10.80.16.67
HostProp_DhcpWatchMethod leases dhcp3 dhcp.uk.xensource.com:5556
TftpPath /usr/groups/netboot/

DebianNonfreeFirmware firmware-bnx2
DebianSuite squeeze
DebianMirrorHost debian.uk.xensource.com
DebianPreseed= < <‘END’
d-i clock-setup/ntp-server string ntp.uk.xensource.com
END

1. In this configuration, where would the DNS server be running? Does
it expect that a DNS server is already configured in the network and
it has mapping of name <--> IP address for all test hosts? Or do we
need to setup it up on the OSS controller?

The information about the nameservers, the tftp server, and the ntp
server, is supposed to refer to infrastructure that already exists.
I think your test hosts should be in the DNS, yes.  It may be possible
to get it to work without doing that but I wouldn't recommend it.

osstest does not need a dedicated network.  Specifically, it can
share its broadcast domain, and its dhcp and tftp servers (and web
proxies, Debian mirrors, ntp servers, and so on), with other uses.

When running osstest in production ("Executive") mode the individual
test boxes must be configured to be available to osstest only if they
are not being used for something else, of course.

See INSTALL.production.


2. What is the DhcpWatchMethod option used for?

See under DHCP in INSTALL.production, and please let me know if that's
not clear.
What I could understand is that this option is used to listen to any 
changes in the
dhcp lease file. But I am not clear why osstest needs to listen to any 
changes to
the lease file. Is it because it needs to know the IP address allocated 
to the guest
VMs? So whenever the guest VM is allocated an ip address, the osstest 
would come

to know.


3. How are the debian related options mentioned above used? Does OSS
fetches the installers/preseed files from DEbianMirrorHost and place
them in the required tftp folders?

mg-debian-installer-update downloads d-i installation information and
puts it in the tftp area.

But the tftp area is also updated at runtime, obviously, in order to
control the booting of each host.  And the mirror host is accessed
separately, too.


I may have more doubts as I try to set things up.

I'm happy to answer more questions, of course :-).


[1] https://blog.xenproject.org/2013/09/30/osstest-standalone-mode-step-by-step/

That blog post may be rather out of date, I'm afraid.  But the in-tree
documentation is somewhat better since then.


I am trying to bring up OSS test framework on a couple of moonshot
systems which are accessible to me remotely.

I'm not familiar with the referent of "moonshot" in this context.  IME
"moonshot" is a project name chosen multiple times, for different
projects, by people who want to give an impression that the project is
ambitious.

Regards,
Ian.


Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 2/2 v2] xen: Fix 16550 UART console for HP Moonshot (Aarch64) platform

2017-11-09 Thread Bhupinder Thakur
The console was not working on HP Moonshot (HPE Proliant Aarch64) because
the UART registers were accessed as 8-bit aligned addresses. However,
registers are 32-bit aligned for HP Moonshot.

Since ACPI/SPCR table does not specify the register shift to be applied to 
the
register offset, this patch implements an erratum to correctly set the 
register
shift for HP Moonshot.

Similar erratum was implemented in linux:

commit 79a648328d2a604524a30523ca763fbeca0f70e3
Author: Loc Ho 
Date:   Mon Jul 3 14:33:09 2017 -0700

ACPI: SPCR: Workaround for APM X-Gene 8250 UART 32-alignment errata

APM X-Gene verion 1 and 2 have an 8250 UART with its register
aligned to 32-bit. In addition, the latest released BIOS
encodes the access field as 8-bit access instead 32-bit access.
This causes no console with ACPI boot as the console
will not match X-Gene UART port due to the lack of mmio32
option.

Signed-off-by: Loc Ho 
Acked-by: Greg Kroah-Hartman 
Signed-off-by: Rafael J. Wysocki 

Signed-off-by: Bhupinder Thakur 
---
CC: Andrew Cooper 
CC: George Dunlap 
CC: Ian Jackson 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Wei Liu 
CC: Julien Grall 

 xen/drivers/char/ns16550.c | 42 --
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index cf42fce..bb01c46 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -1517,6 +1517,33 @@ static int ns16550_init_dt(struct ns16550 *uart,
 
 #ifdef CONFIG_ACPI
 #include 
+/*
+ * APM X-Gene v1 and v2 UART hardware is an 16550 like device but has its
+ * register aligned to 32-bit. In addition, the BIOS also encoded the
+ * access width to be 8 bits. This function detects this errata condition.
+ */
+static bool xgene_8250_erratum_present(struct acpi_table_spcr *tb)
+{
+bool xgene_8250 = false;
+
+if ( tb->interface_type != ACPI_DBG2_16550_COMPATIBLE )
+return false;
+
+if ( memcmp(tb->header.oem_id, "APMC0D", ACPI_OEM_ID_SIZE) &&
+ memcmp(tb->header.oem_id, "HPE   ", ACPI_OEM_ID_SIZE) )
+return false;
+
+if ( !memcmp(tb->header.oem_table_id, "XGENESPC",
+ ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 0 )
+xgene_8250 = true;
+
+if ( !memcmp(tb->header.oem_table_id, "ProLiant",
+ ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 1 )
+xgene_8250 = true;
+
+return xgene_8250;
+}
+
 static int ns16550_init_acpi(struct ns16550 *uart,
  const void *data)
 {
@@ -1539,9 +1566,20 @@ static int ns16550_init_acpi(struct ns16550 *uart,
 uart->io_base = spcr->serial_port.address;
 uart->irq = spcr->interrupt;
 uart->reg_width = spcr->serial_port.bit_width / 8;
-uart->reg_shift = 0;
-uart->io_size = UART_MAX_REG << uart->reg_shift;
 
+if ( xgene_8250_erratum_present(spcr) )
+{
+/*
+ * for xgene v1 and v2 the registers are 32-bit and so a
+ * register shift of 2 has to be applied to get the
+ * correct register offset.
+ */
+uart->reg_shift = 2;
+}
+else
+uart->reg_shift = 0;
+
+uart->io_size = UART_MAX_REG << uart->reg_shift;
 irq_set_type(spcr->interrupt, spcr->interrupt_type);
 
 return 0;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 1/2 v2] xen: Add support for initializing 16550 UART using ACPI

2017-11-09 Thread Bhupinder Thakur
Currently, Xen supports only DT based initialization of 16550 UART.
This patch adds support for initializing 16550 UART using ACPI SPCR table.

This patch also makes the uart initialization code common between DT and
ACPI based initialization.

Signed-off-by: Bhupinder Thakur 
---
TBD:
There was one review comment from Julien about how the uart->io_size is being 
calculated. Currently, I am calulating the io_size based on address of the last
UART register. 

pci_uart_config also calcualates the uart->io_size like this:

uart->io_size = max(8U << param->reg_shift,
 param->uart_offset);

I am not sure whether we can use similar logic for calculating uart->io_size.

Changes since v1:
- Reused common code between DT and ACPI based initializations

CC: Andrew Cooper 
CC: George Dunlap 
CC: Ian Jackson 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Wei Liu 
CC: Julien Grall 

 xen/drivers/char/ns16550.c  | 132 
 xen/include/xen/8250-uart.h |   1 +
 2 files changed, 121 insertions(+), 12 deletions(-)

diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index e0f8199..cf42fce 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -1463,18 +1463,13 @@ void __init ns16550_init(int index, struct 
ns16550_defaults *defaults)
 }
 
 #ifdef CONFIG_HAS_DEVICE_TREE
-static int __init ns16550_uart_dt_init(struct dt_device_node *dev,
-   const void *data)
+static int ns16550_init_dt(struct ns16550 *uart,
+   const struct dt_device_node *dev)
 {
-struct ns16550 *uart;
-int res;
+int res = 0;
 u32 reg_shift, reg_width;
 u64 io_size;
 
-uart = &ns16550_com[0];
-
-ns16550_init_common(uart);
-
 uart->baud  = BAUD_AUTO;
 uart->data_bits = 8;
 uart->parity= UART_PARITY_NONE;
@@ -1510,18 +1505,103 @@ static int __init ns16550_uart_dt_init(struct 
dt_device_node *dev,
 
 uart->dw_usr_bsy = dt_device_is_compatible(dev, "snps,dw-apb-uart");
 
+return res;
+}
+#else
+static int ns16550_init_dt(struct ns16550 *uart,
+   const struct dt_device_node *dev)
+{
+return -EINVAL;
+}
+#endif
+
+#ifdef CONFIG_ACPI
+#include 
+static int ns16550_init_acpi(struct ns16550 *uart,
+ const void *data)
+{
+struct acpi_table_spcr *spcr = NULL;
+int status = 0;
+
+status = acpi_get_table(ACPI_SIG_SPCR, 0,
+(struct acpi_table_header **)&spcr);
+
+if ( ACPI_FAILURE(status) )
+{
+printk("ns16550: Failed to get SPCR table\n");
+return -EINVAL;
+}
+
+uart->baud  = BAUD_AUTO;
+uart->data_bits = 8;
+uart->parity= spcr->parity;
+uart->stop_bits = spcr->stop_bits;
+uart->io_base = spcr->serial_port.address;
+uart->irq = spcr->interrupt;
+uart->reg_width = spcr->serial_port.bit_width / 8;
+uart->reg_shift = 0;
+uart->io_size = UART_MAX_REG << uart->reg_shift;
+
+irq_set_type(spcr->interrupt, spcr->interrupt_type);
+
+return 0;
+}
+#else
+static int ns16550_init_acpi(struct ns16550 *uart,
+ const void *data)
+{
+return -EINVAL;
+}
+#endif
+
+static int ns16550_uart_init(struct ns16550 **puart,
+ const void *data, bool acpi)
+{
+struct ns16550 *uart = &ns16550_com[0];
+
+*puart = uart;
+
+ns16550_init_common(uart);
+
+return ( acpi ) ? ns16550_init_acpi(uart, data)
+: ns16550_init_dt(uart, data);
+}
+
+static void ns16550_vuart_init(struct ns16550 *uart)
+{
+#ifdef CONFIG_ARM
 uart->vuart.base_addr = uart->io_base;
 uart->vuart.size = uart->io_size;
-uart->vuart.data_off = UART_THR <reg_shift;
-uart->vuart.status_off = UART_LSR<reg_shift;
-uart->vuart.status = UART_LSR_THRE|UART_LSR_TEMT;
+uart->vuart.data_off = UART_THR << uart->reg_shift;
+uart->vuart.status_off = UART_LSR << uart->reg_shift;
+uart->vuart.status = UART_LSR_THRE | UART_LSR_TEMT;
+#endif
+}
 
+static void ns16550_register_uart(struct ns16550 *uart)
+{
 /* Register with generic serial driver. */
 serial_register_uart(uart - ns16550_com, &ns16550_driver, uart);
+}
+
+#ifdef CONFIG_HAS_DEVICE_TREE
+static int __init ns16550_uart_dt_init(struct dt_device_node *dev,
+   const void *data)
+{
+struct ns16550 *uart;
+int ret = 0;
+
+ret = ns16550_uart_init(&uart, dev, false);
+if ( ret )
+return ret;
+
+ns16550_vuart_init(uart);
+
+ns16550_register_uart(uart);
 
 dt_device_set_used_by(dev, DOMID_XEN);
 
-return 0;
+return ret;
 }
 
 static const struct dt_device_match n

[Xen-devel] [PATCH 0/2 v2] xen: ACPI/SPCR based initialization of 8250 UART

2017-11-09 Thread Bhupinder Thakur
Currently, Xen supports only DT based initialization of 16550 UART.
This patch set adds support for initializing 16550 UART using ACPI
SPCR table.

It also fixes one issue in HP Moonshot (HPE Proliant Aarch64)
platform, which uses 16550 UART as a console. There is an erratum
required to be implemented to make the UART console work.

CC: Andrew Cooper 
CC: George Dunlap 
CC: Ian Jackson 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Wei Liu 
CC: Julien Grall 

Bhupinder Thakur (2):
  xen: Add support for initializing 16550 UART using ACPI
  xen: Fix 16550 UART console for HP Moonshot (Aarch64) platform

 xen/drivers/char/ns16550.c  | 170 
 xen/include/xen/8250-uart.h |   1 +
 2 files changed, 159 insertions(+), 12 deletions(-)

-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 1/2] xen: Add support for initializing 16550 UART using ACPI

2017-11-07 Thread Bhupinder Thakur
Hi Julien,

On 2 November 2017 at 17:45, Julien Grall  wrote:
> Hi Bhupinder,
>
> Please write a cover letter even if it is small when your send a series with
> multiple patches.
>
>
> On 02/11/17 10:13, Bhupinder Thakur wrote:
>>
>> Currently, Xen supports only DT based initialization of 16550 UART.
>> This patch adds support for initializing 16550 UART using ACPI SPCR table.
>>
>> Signed-off-by: Bhupinder Thakur 
>> ---
>> CC: Andrew Cooper 
>> CC: George Dunlap 
>> CC: Ian Jackson 
>> CC: Jan Beulich 
>> CC: Konrad Rzeszutek Wilk 
>> CC: Stefano Stabellini 
>> CC: Tim Deegan 
>> CC: Wei Liu 
>> CC: Julien Grall 
>>
>>   xen/drivers/char/ns16550.c  | 57
>> +
>>   xen/include/xen/8250-uart.h |  1 +
>>   2 files changed, 58 insertions(+)
>>
>> diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
>> index e0f8199..b3f6d85 100644
>> --- a/xen/drivers/char/ns16550.c
>> +++ b/xen/drivers/char/ns16550.c
>> @@ -1538,6 +1538,63 @@ DT_DEVICE_START(ns16550, "NS16550 UART",
>> DEVICE_SERIAL)
>>   DT_DEVICE_END
>> #endif /* HAS_DEVICE_TREE */
>> +
>> +#ifdef CONFIG_ACPI
>
>
> The code below is going to break x86 build. You need to do #if
> defined(CONFIG_ACPI) && defined(CONFIG_ARM)
>
>
>> +#include 
>> +
>> +static int __init ns16550_acpi_uart_init(const void *data)
>> +{
>> +struct ns16550 *uart;
>> +acpi_status status;
>> +struct acpi_table_spcr *spcr = NULL;
>> +
>> +status = acpi_get_table(ACPI_SIG_SPCR, 0,
>> +(struct acpi_table_header **)&spcr);
>> +
>> +if ( ACPI_FAILURE(status) )
>> +{
>> +printk("ns16550: Failed to get SPCR table\n");
>> +return -EINVAL;
>> +}
>> +
>> +uart = &ns16550_com[0];
>> +
>> +ns16550_init_common(uart);
>> +
>> +uart->baud  = BAUD_AUTO;
>> +uart->data_bits = 8;
>> +uart->parity= spcr->parity;
>> +uart->stop_bits = spcr->stop_bits;
>> +uart->io_base = spcr->serial_port.address;
>> +uart->irq = spcr->interrupt;
>> +uart->reg_width = spcr->serial_port.bit_width/8;
>
>
> width / 8;
>
>> +uart->reg_shift = 0;
>> +uart->io_size = UART_MAX_REG<reg_shift;
>
>
> space before and after <<.
>
> Also, io_size seems to be computed differently in pci_uart_config. I am not
> sure why the difference here?

In pci_uart_config:

uart->io_size = max(8U << param->reg_shift,
 param->uart_offset);

I was not sure which param to consider to get the uart_offset. Since
the max register that ns16550 uses is UART_USR, I
calculated the io_size based on that.
>
>> +
>> +irq_set_type(spcr->interrupt, spcr->interrupt_type);
>> +
>> +uart->vuart.base_addr = uart->io_base;
>> +uart->vuart.size = uart->io_size;
>> +uart->vuart.data_off = UART_THR <reg_shift;
>
>
> Ditto for the space.
>
>> +uart->vuart.status_off = UART_LSR<reg_shift;
>
>
> Ditto.
>
>> +uart->vuart.status = UART_LSR_THRE|UART_LSR_TEMT;
>
>
> Ditto.
>
> Also, the code looks very similar to the DT version. Is there any way to
> share it?
>
>
>> +
>> +/* Register with generic serial driver. */
>> +serial_register_uart(uart - ns16550_com, &ns16550_driver, uart);
>> +
>> +return 0;
>> +}
>> +
>> +ACPI_DEVICE_START(ns16550c, "16550 COMPAT UART", DEVICE_SERIAL)
>> +.class_type = ACPI_DBG2_16550_COMPATIBLE,
>> +.init = ns16550_acpi_uart_init,
>> +ACPI_DEVICE_END
>> +ACPI_DEVICE_START(ns16550s, "16550 SUBSET UART", DEVICE_SERIAL)
>> +.class_type = ACPI_DBG2_16550_SUBSET,
>> +.init = ns16550_acpi_uart_init,
>> +ACPI_DEVICE_END
>> +
>> +#endif
>>   /*
>>* Local variables:
>>* mode: C
>> diff --git a/xen/include/xen/8250-uart.h b/xen/include/xen/8250-uart.h
>> index 5c3bac3..1b3e137 100644
>> --- a/xen/include/xen/8250-uart.h
>> +++ b/xen/include/xen/8250-uart.h
>> @@ -35,6 +35,7 @@
>>   #define UART_USR  0x1f/* Status register (DW) */
>>   #define UART_DLL  0x00/* divisor latch (ls) (DLAB=1) */
>>   #define UART_DLM  0x01/* divisor latch (ms) (DLAB=1) */
>> +#define UART_MAX_REG  (UART_USR+1)
>> /* Interrupt Enable Register */
>>   #define UART_IER_ERDAI0x01/* rx data recv'd   */
>>
>
> Cheers,
>
> --
> Julien Grall

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] Bringing up OSS test framework on moonshot(aarch64) systems

2017-11-06 Thread Bhupinder Thakur
Hi,

I am trying to bring up OSS test framework on a couple of moonshot
systems which are accessible to me remotely.

While going through [1], I have some queries/doubts on the configuration.

1. The following configuration:

DnsDomain uk.xensource.com
NetNameservers 10.80.248.2 10.80.16.28 10.80.16.67
HostProp_DhcpWatchMethod leases dhcp3 dhcp.uk.xensource.com:5556
TftpPath /usr/groups/netboot/

DebianNonfreeFirmware firmware-bnx2
DebianSuite squeeze
DebianMirrorHost debian.uk.xensource.com
DebianPreseed= < <‘END’
d-i clock-setup/ntp-server string ntp.uk.xensource.com
END

1. In this configuration, where would the DNS server be running? Does
it expect that a DNS server is already configured in the network and
it has mapping of name <--> IP address for all test hosts? Or do we
need to setup it up on the OSS controller?

2. What is the DhcpWatchMethod option used for?

3. How are the debian related options mentioned above used? Does OSS
fetches the installers/preseed files from DEbianMirrorHost and place
them in the required tftp folders?

I may have more doubts as I try to set things up.

[1] https://blog.xenproject.org/2013/09/30/osstest-standalone-mode-step-by-step/

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 2/2] xen: Fix 16550 UART console for HP Moonshot (Aarch64) platform

2017-11-02 Thread Bhupinder Thakur
The console was not working on HP Moonshot (HPE Proliant Aarch64) because
the UART registers were accessed as 8-bit aligned addresses. However,
registers are 32-bit aligned for HP Moonshot.

Since ACPI/SPCR table does not specify the register shift to be applied to 
the
register offset, this patch implements an erratum to correctly set the 
register
shift for HP Moonshot.

Similar erratum was implemented in linux:

commit 79a648328d2a604524a30523ca763fbeca0f70e3
Author: Loc Ho 
Date:   Mon Jul 3 14:33:09 2017 -0700

ACPI: SPCR: Workaround for APM X-Gene 8250 UART 32-alignment errata

APM X-Gene verion 1 and 2 have an 8250 UART with its register
aligned to 32-bit. In addition, the latest released BIOS
encodes the access field as 8-bit access instead 32-bit access.
This causes no console with ACPI boot as the console
will not match X-Gene UART port due to the lack of mmio32
option.

Signed-off-by: Loc Ho 
Acked-by: Greg Kroah-Hartman 
Signed-off-by: Rafael J. Wysocki 

Signed-off-by: Bhupinder Thakur 
---
CC: Andrew Cooper 
CC: George Dunlap 
CC: Ian Jackson 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Wei Liu 
CC: Julien Grall 

 xen/drivers/char/ns16550.c | 42 --
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index b3f6d85..e716aba 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -1542,6 +1542,33 @@ DT_DEVICE_END
 #ifdef CONFIG_ACPI
 #include 
 
+/*
+ * APM X-Gene v1 and v2 UART hardware is an 16550 like device but has its
+ * register aligned to 32-bit. In addition, the BIOS also encoded the
+ * access width to be 8 bits. This function detects this errata condition.
+ */
+static bool xgene_8250_erratum_present(struct acpi_table_spcr *tb)
+{
+bool xgene_8250 = false;
+
+if ( tb->interface_type != ACPI_DBG2_16550_COMPATIBLE )
+return false;
+
+if ( memcmp(tb->header.oem_id, "APMC0D", ACPI_OEM_ID_SIZE) &&
+ memcmp(tb->header.oem_id, "HPE   ", ACPI_OEM_ID_SIZE) )
+return false;
+
+if ( !memcmp(tb->header.oem_table_id, "XGENESPC",
+ ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 0 )
+xgene_8250 = true;
+
+if ( !memcmp(tb->header.oem_table_id, "ProLiant",
+ ACPI_OEM_TABLE_ID_SIZE) && tb->header.oem_revision == 1 )
+xgene_8250 = true;
+
+return xgene_8250;
+}
+
 static int __init ns16550_acpi_uart_init(const void *data)
 {
 struct ns16550 *uart;
@@ -1568,9 +1595,20 @@ static int __init ns16550_acpi_uart_init(const void 
*data)
 uart->io_base = spcr->serial_port.address;
 uart->irq = spcr->interrupt;
 uart->reg_width = spcr->serial_port.bit_width/8;
-uart->reg_shift = 0;
-uart->io_size = UART_MAX_REG<reg_shift;
 
+if ( xgene_8250_erratum_present(spcr) )
+{
+/*
+ * for xgene v1 and v2 the registers are 32-bit and so a
+ * register shift of 2 has to be applied to get the
+ * correct register offset.
+ */
+uart->reg_shift = 2;
+}
+else
+uart->reg_shift = 0;
+
+uart->io_size = UART_MAX_REG<reg_shift;
 irq_set_type(spcr->interrupt, spcr->interrupt_type);
 
 uart->vuart.base_addr = uart->io_base;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 1/2] xen: Add support for initializing 16550 UART using ACPI

2017-11-02 Thread Bhupinder Thakur
Currently, Xen supports only DT based initialization of 16550 UART.
This patch adds support for initializing 16550 UART using ACPI SPCR table.

Signed-off-by: Bhupinder Thakur 
---
CC: Andrew Cooper 
CC: George Dunlap 
CC: Ian Jackson 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Wei Liu 
CC: Julien Grall 

 xen/drivers/char/ns16550.c  | 57 +
 xen/include/xen/8250-uart.h |  1 +
 2 files changed, 58 insertions(+)

diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index e0f8199..b3f6d85 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -1538,6 +1538,63 @@ DT_DEVICE_START(ns16550, "NS16550 UART", DEVICE_SERIAL)
 DT_DEVICE_END
 
 #endif /* HAS_DEVICE_TREE */
+
+#ifdef CONFIG_ACPI
+#include 
+
+static int __init ns16550_acpi_uart_init(const void *data)
+{
+struct ns16550 *uart;
+acpi_status status;
+struct acpi_table_spcr *spcr = NULL;
+
+status = acpi_get_table(ACPI_SIG_SPCR, 0,
+(struct acpi_table_header **)&spcr);
+
+if ( ACPI_FAILURE(status) )
+{
+printk("ns16550: Failed to get SPCR table\n");
+return -EINVAL;
+}
+
+uart = &ns16550_com[0];
+
+ns16550_init_common(uart);
+
+uart->baud  = BAUD_AUTO;
+uart->data_bits = 8;
+uart->parity= spcr->parity;
+uart->stop_bits = spcr->stop_bits;
+uart->io_base = spcr->serial_port.address;
+uart->irq = spcr->interrupt;
+uart->reg_width = spcr->serial_port.bit_width/8;
+uart->reg_shift = 0;
+uart->io_size = UART_MAX_REG<reg_shift;
+
+irq_set_type(spcr->interrupt, spcr->interrupt_type);
+
+uart->vuart.base_addr = uart->io_base;
+uart->vuart.size = uart->io_size;
+uart->vuart.data_off = UART_THR <reg_shift;
+uart->vuart.status_off = UART_LSR<reg_shift;
+uart->vuart.status = UART_LSR_THRE|UART_LSR_TEMT;
+
+/* Register with generic serial driver. */
+serial_register_uart(uart - ns16550_com, &ns16550_driver, uart);
+
+return 0;
+}
+
+ACPI_DEVICE_START(ns16550c, "16550 COMPAT UART", DEVICE_SERIAL)
+.class_type = ACPI_DBG2_16550_COMPATIBLE,
+.init = ns16550_acpi_uart_init,
+ACPI_DEVICE_END
+ACPI_DEVICE_START(ns16550s, "16550 SUBSET UART", DEVICE_SERIAL)
+.class_type = ACPI_DBG2_16550_SUBSET,
+.init = ns16550_acpi_uart_init,
+ACPI_DEVICE_END
+
+#endif
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/xen/8250-uart.h b/xen/include/xen/8250-uart.h
index 5c3bac3..1b3e137 100644
--- a/xen/include/xen/8250-uart.h
+++ b/xen/include/xen/8250-uart.h
@@ -35,6 +35,7 @@
 #define UART_USR  0x1f/* Status register (DW) */
 #define UART_DLL  0x00/* divisor latch (ls) (DLAB=1) */
 #define UART_DLM  0x01/* divisor latch (ms) (DLAB=1) */
+#define UART_MAX_REG  (UART_USR+1)
 
 /* Interrupt Enable Register */
 #define UART_IER_ERDAI0x01/* rx data recv'd   */
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 1/4 v3] libxl: Fix the bug introduced in commit "libxl: use correct type modifier for vuart_gfn"

2017-10-30 Thread Bhupinder Thakur
In libxl__device_vuart_add vuart_gfn is getting stored as a hex value:

> flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));

However, xenstore reads this value as a decimal value and tries to map the
wrong address and fails.

This patch introduces a new format specifier "PRIu_xen_pfn" which formats the 
value as a
decimal value.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 
CC: Jan Beulich 
CC: Andrew Cooper 

 tools/libxl/libxl_console.c   | 2 +-
 xen/include/public/arch-arm.h | 1 +
 xen/include/public/arch-x86/xen.h | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index c05dc28..6bfc0e5 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -376,7 +376,7 @@ int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
 flexarray_append(ro_front, "port");
 flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
 flexarray_append(ro_front, "ring-ref");
-flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));
+flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, state->vuart_gfn));
 flexarray_append(ro_front, "limit");
 flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT));
 flexarray_append(ro_front, "type");
diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h
index 5708cd2..05fd11c 100644
--- a/xen/include/public/arch-arm.h
+++ b/xen/include/public/arch-arm.h
@@ -274,6 +274,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t);
 
 typedef uint64_t xen_pfn_t;
 #define PRI_xen_pfn PRIx64
+#define PRIu_xen_pfn PRIu64
 
 /* Maximum number of virtual CPUs in legacy multi-processor guests. */
 /* Only one. All other VCPUS must use VCPUOP_register_vcpu_info */
diff --git a/xen/include/public/arch-x86/xen.h 
b/xen/include/public/arch-x86/xen.h
index ff91831..3b0b1d6 100644
--- a/xen/include/public/arch-x86/xen.h
+++ b/xen/include/public/arch-x86/xen.h
@@ -75,6 +75,7 @@ __DeFiNe__ __DECL_REG_LO16(name) e ## name
 #ifndef __ASSEMBLY__
 typedef unsigned long xen_pfn_t;
 #define PRI_xen_pfn "lx"
+#define PRIu_xen_pfn "lu"
 #endif
 
 #define XEN_HAVE_PV_GUEST_ENTRY 1
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 2/4 v3] libxl: Change the type of console_mfn to xen_pfn_t

2017-10-30 Thread Bhupinder Thakur
Currently the type of console mfn is unsigned long in libxl. This may be
an issue for 32-bit toolstack running on 64-bit Xen, where the pfn are
64 bit. To ensure that console_mfn can hold any valid 64-bit pfn, the
type of console_mfn is changed to xen_pfn_t.

Also the name console_mfn is misleading as it is actually a gfn. This
patch also modifies the name to console_gfn.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

This patch is as per the review of commit fa1f157
libxl: Fix the bug introduced in commit "libxl: use correct type

 tools/libxc/include/xenctrl_compat.h |  2 +-
 tools/libxc/xc_foreign_memory.c  |  4 ++--
 tools/libxl/libxl_console.c  |  2 +-
 tools/libxl/libxl_create.c   | 10 +-
 tools/libxl/libxl_dom.c  | 12 ++--
 tools/libxl/libxl_internal.h |  2 +-
 tools/libxl/libxl_save_helper.c  |  6 +++---
 7 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/tools/libxc/include/xenctrl_compat.h 
b/tools/libxc/include/xenctrl_compat.h
index a655e47..5ee72bf 100644
--- a/tools/libxc/include/xenctrl_compat.h
+++ b/tools/libxc/include/xenctrl_compat.h
@@ -26,7 +26,7 @@
  */
 void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
 int size, int prot,
-unsigned long mfn );
+xen_pfn_t pfn);
 
 void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
const xen_pfn_t *arr, int num );
diff --git a/tools/libxc/xc_foreign_memory.c b/tools/libxc/xc_foreign_memory.c
index 4053d26..c1f114a 100644
--- a/tools/libxc/xc_foreign_memory.c
+++ b/tools/libxc/xc_foreign_memory.c
@@ -33,7 +33,7 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, 
int prot,
 
 void *xc_map_foreign_range(xc_interface *xch,
uint32_t dom, int size, int prot,
-   unsigned long mfn)
+   xen_pfn_t pfn)
 {
 xen_pfn_t *arr;
 int num;
@@ -46,7 +46,7 @@ void *xc_map_foreign_range(xc_interface *xch,
 return NULL;
 
 for ( i = 0; i < num; i++ )
-arr[i] = mfn + i;
+arr[i] = pfn + i;
 
 ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
 free(arr);
diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index 6bfc0e5..f2ca689 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -329,7 +329,7 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t domid,
 flexarray_append(ro_front, "port");
 flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->console_port));
 flexarray_append(ro_front, "ring-ref");
-flexarray_append(ro_front, GCSPRINTF("%lu", state->console_mfn));
+flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, 
state->console_mfn));
 } else {
 flexarray_append(front, "state");
 flexarray_append(front, GCSPRINTF("%d", XenbusStateInitialising));
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index f15fb21..26870ca 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1134,7 +1134,7 @@ static void domcreate_bootloader_done(libxl__egc *egc,
 }
 
 void libxl__srm_callout_callback_restore_results(xen_pfn_t store_mfn,
-  xen_pfn_t console_mfn, void *user)
+  xen_pfn_t console_gfn, void *user)
 {
 libxl__save_helper_state *shs = user;
 libxl__domain_create_state *dcs = shs->caller_state;
@@ -1142,7 +1142,7 @@ void 
libxl__srm_callout_callback_restore_results(xen_pfn_t store_mfn,
 libxl__domain_build_state *const state = &dcs->build_state;
 
 state->store_mfn =store_mfn;
-state->console_mfn =  console_mfn;
+state->console_gfn =  console_gfn;
 shs->need_results =   0;
 }
 
@@ -1740,7 +1740,7 @@ static int do_domain_soft_reset(libxl_ctx *ctx,
 libxl__domain_create_state *dcs;
 libxl__domain_build_state *state;
 libxl__domain_save_state *dss;
-const char *console_tty, *xs_store_mfn, *xs_console_mfn;
+const char *console_tty, *xs_store_mfn, *xs_console_gfn;
 char *dom_path;
 uint32_t domid_out;
 int rc;
@@ -1781,12 +1781,12 @@ static int do_domain_soft_reset(libxl_ctx *ctx,
 
 rc = libxl__xs_read_checked(gc, XBT_NULL,
 GCSPRINTF("%s/console/ring-ref", dom_path),
-&xs_console_mfn);
+&xs_console_gfn);
 if (rc) {
 LOGD(ERROR, domid_soft_reset, "failed to read console/ring-ref.");
 goto out;
 }
-state->console_mfn = xs_console_mfn ? atol(xs_console_mfn): 0;
+state->console_gfn = xs_console_gfn ? atol(xs_console_gfn): 0;
 
 rc = libxl__x

[Xen-devel] [PATCH 3/4 v3] xenconsole: Change the type of ring_ref to xen_pfn_t in console_create_ring

2017-10-30 Thread Bhupinder Thakur
Currently, ring_ref is read as an integer in console_create_ring which could 
lead to
truncation of the value as it is reading a 64-bit value.

The fix is to modify the type of ring_ref to xen_pfn_t and use the correct 
format
specifier to read the value correctly for all architectures.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

This patch is as per the review of commit fa1f157
libxl: Fix the bug introduced in commit "libxl: use correct type

 tools/console/daemon/io.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index e22009a..1839973 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -19,6 +19,7 @@
 
 #define _GNU_SOURCE
 
+#include 
 #include "utils.h"
 #include "io.h"
 #include 
@@ -81,6 +82,12 @@ static unsigned int nr_fds;
 
 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 
+#if defined(CONFIG_ARM)
+# define SCNi_xen_pfn SCNi64
+#else
+# define SCNi_xen_pfn "li"
+#endif
+
 struct buffer {
char *data;
size_t consumed;
@@ -98,7 +105,7 @@ struct console {
struct buffer buffer;
char *xspath;
char *log_suffix;
-   int ring_ref;
+   xen_pfn_t ring_ref;
xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
int event_count;
@@ -661,12 +668,13 @@ static void console_unmap_interface(struct console *con)
  
 static int console_create_ring(struct console *con)
 {
-   int err, remote_port, ring_ref, rc;
+   int err, remote_port, rc;
+   xen_pfn_t ring_ref;
char *type, path[PATH_MAX];
struct domain *dom = con->d;
 
err = xs_gather(xs, con->xspath,
-   "ring-ref", "%u", &ring_ref,
+   "ring-ref", "%"SCNi_xen_pfn, &ring_ref,
"port", "%i", &remote_port,
NULL);
 
@@ -705,7 +713,7 @@ static int console_create_ring(struct console *con)
con->interface = xc_map_foreign_range(
xc, dom->domid, XC_PAGE_SIZE,
PROT_READ|PROT_WRITE,
-   (unsigned long)ring_ref);
+   ring_ref);
if (con->interface == NULL) {
err = EINVAL;
goto out;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 4/4 v3] xenconsole: Define and use a macro XEN_INVALID_PFN instead of -1

2017-10-30 Thread Bhupinder Thakur
xenconsole will use a new macro XEN_INVALID_PFN instead of -1 for initializing 
ring-ref.
Since the type of ring_ref is changed to xen_pfn_t (which is an unsigned value) 
assigning -1
appeared to be confusing. For clarity, XEN_INVALID_PFN is introduced.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

This patch is as per the review of commit fa1f157
libxl: Fix the bug introduced in commit "libxl: use correct type

 tools/console/daemon/io.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 1839973..aa291db 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -62,6 +62,8 @@
 /* Duration of each time period in ms */
 #define RATE_LIMIT_PERIOD 200
 
+#define XEN_INVALID_PFN (~(xen_pfn_t)0)
+
 extern int log_reload;
 extern int log_guest;
 extern int log_hv;
@@ -658,12 +660,12 @@ static void console_unmap_interface(struct console *con)
 {
if (con->interface == NULL)
return;
-   if (xgt_handle && con->ring_ref == -1)
+   if (xgt_handle && con->ring_ref == XEN_INVALID_PFN)
xengnttab_unmap(xgt_handle, con->interface, 1);
else
munmap(con->interface, XC_PAGE_SIZE);
con->interface = NULL;
-   con->ring_ref = -1;
+   con->ring_ref = XEN_INVALID_PFN;
 }
  
 static int console_create_ring(struct console *con)
@@ -698,7 +700,7 @@ static int console_create_ring(struct console *con)
free(type);
 
/* If using ring_ref and it has changed, remap */
-   if (ring_ref != con->ring_ref && con->ring_ref != -1)
+   if (ring_ref != con->ring_ref && con->ring_ref != XEN_INVALID_PFN)
console_unmap_interface(con);
 
if (!con->interface && xgt_handle && con->use_gnttab) {
@@ -706,7 +708,7 @@ static int console_create_ring(struct console *con)
con->interface = xengnttab_map_grant_ref(xgt_handle,
dom->domid, GNTTAB_RESERVED_CONSOLE,
PROT_READ|PROT_WRITE);
-   con->ring_ref = -1;
+   con->ring_ref = XEN_INVALID_PFN;
}
if (!con->interface) {
/* Fall back to xc_map_foreign_range */
@@ -812,7 +814,7 @@ static int console_init(struct console *con, struct domain 
*dom, void **data)
con->master_pollfd_idx = -1;
con->slave_fd = -1;
con->log_fd = -1;
-   con->ring_ref = -1;
+   con->ring_ref = XEN_INVALID_PFN;
con->local_port = -1;
con->remote_port = -1;
con->xce_pollfd_idx = -1;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 2/5 v2] libxl: Change the type of console_mfn to xen_pfn_t

2017-10-30 Thread Bhupinder Thakur
Hi,

On 26 October 2017 at 16:47, Andrew Cooper  wrote:
> On 26/10/17 12:13, Wei Liu wrote:
>> On Wed, Oct 25, 2017 at 02:57:05PM +0530, Bhupinder Thakur wrote:
>>> Currently the type of console mfn is unsigned long in libxl. This may be
>>> an issue for 32-bit toolstack running on 64-bit Xen, where the pfn are
>>> 64 bit. To ensure that console_mfn can hold any valid 64-bit pfn, the
>>> type of console_mfn is changed to xen_pfn_t.
>>>
>>> Signed-off-by: Bhupinder Thakur 
>>> ---
>>> CC: Ian Jackson 
>>> CC: Wei Liu 
>>> CC: Stefano Stabellini 
>>> CC: Julien Grall 
>>>
>>> This patch is as per the review of commit fa1f157
>>> libxl: Fix the bug introduced in commit "libxl: use correct type
>>>
>>>  tools/libxl/libxl_console.c  | 2 +-
>>>  tools/libxl/libxl_dom.c  | 2 +-
>>>  tools/libxl/libxl_internal.h | 2 +-
>>>  3 files changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
>>> index 6bfc0e5..f2ca689 100644
>>> --- a/tools/libxl/libxl_console.c
>>> +++ b/tools/libxl/libxl_console.c
>>> @@ -329,7 +329,7 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t 
>>> domid,
>>>  flexarray_append(ro_front, "port");
>>>  flexarray_append(ro_front, GCSPRINTF("%"PRIu32, 
>>> state->console_port));
>>>  flexarray_append(ro_front, "ring-ref");
>>> -flexarray_append(ro_front, GCSPRINTF("%lu", state->console_mfn));
>>> +flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, 
>>> state->console_mfn));
>> Actually, please consider changing console_mfn to console_pfn.
>
> If you are going to make this change, then it is a gfn, not a pfn.
> (console_pfn would be as equally wrong for PV guests as console_mfn is
> currently wrong for HVM guest.)

Changing console_mfn to console_gfn will require changes in many
files. Should I go ahead and change all the files?

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 5/5 v2] xenconsole: Define and use a macro XEN_INVALID_PFN instead of -1

2017-10-27 Thread Bhupinder Thakur
On 27 October 2017 at 12:34, Bhupinder Thakur
 wrote:
> Hi Wei,
>
> On 26 October 2017 at 16:56, Wei Liu  wrote:
>> On Wed, Oct 25, 2017 at 02:57:08PM +0530, Bhupinder Thakur wrote:
>>> xenconsole will use a new macro XEN_INVALID_PFN instead of -1 for 
>>> initializing ring-ref.
>>
>> Can you please paste in the error if the compilation fails with -1?
>>
>> The way this series is arranged make me wonder if the compilation is
>> broken half way. We should avoid that.
> It is not breaking the compilation. Since the type of ring_ref is
> changed to xen_pfn_t (which is an unsigned value) assigning -1
> appeared to be confusing. For better clarity, XEN_INVALID_PFN is
> introduced.

I will update the commit message accordingly.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 5/5 v2] xenconsole: Define and use a macro XEN_INVALID_PFN instead of -1

2017-10-27 Thread Bhupinder Thakur
Hi Wei,

On 26 October 2017 at 16:56, Wei Liu  wrote:
> On Wed, Oct 25, 2017 at 02:57:08PM +0530, Bhupinder Thakur wrote:
>> xenconsole will use a new macro XEN_INVALID_PFN instead of -1 for 
>> initializing ring-ref.
>
> Can you please paste in the error if the compilation fails with -1?
>
> The way this series is arranged make me wonder if the compilation is
> broken half way. We should avoid that.
It is not breaking the compilation. Since the type of ring_ref is
changed to xen_pfn_t (which is an unsigned value) assigning -1
appeared to be confusing. For better clarity, XEN_INVALID_PFN is
introduced.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 2/5 v2] libxl: Change the type of console_mfn to xen_pfn_t

2017-10-25 Thread Bhupinder Thakur
Currently the type of console mfn is unsigned long in libxl. This may be
an issue for 32-bit toolstack running on 64-bit Xen, where the pfn are
64 bit. To ensure that console_mfn can hold any valid 64-bit pfn, the
type of console_mfn is changed to xen_pfn_t.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

This patch is as per the review of commit fa1f157
libxl: Fix the bug introduced in commit "libxl: use correct type

 tools/libxl/libxl_console.c  | 2 +-
 tools/libxl/libxl_dom.c  | 2 +-
 tools/libxl/libxl_internal.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index 6bfc0e5..f2ca689 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -329,7 +329,7 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t domid,
 flexarray_append(ro_front, "port");
 flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->console_port));
 flexarray_append(ro_front, "ring-ref");
-flexarray_append(ro_front, GCSPRINTF("%lu", state->console_mfn));
+flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, 
state->console_mfn));
 } else {
 flexarray_append(front, "state");
 flexarray_append(front, GCSPRINTF("%d", XenbusStateInitialising));
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index ef834e6..a58e74f 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -869,7 +869,7 @@ out:
 static int hvm_build_set_params(xc_interface *handle, uint32_t domid,
 libxl_domain_build_info *info,
 int store_evtchn, unsigned long *store_mfn,
-int console_evtchn, unsigned long *console_mfn,
+int console_evtchn, xen_pfn_t *console_mfn,
 domid_t store_domid, domid_t console_domid)
 {
 struct hvm_info_table *va_hvm;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 45e6df6..f52aeb3 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1128,7 +1128,7 @@ typedef struct {
 
 uint32_t console_port;
 uint32_t console_domid;
-unsigned long console_mfn;
+xen_pfn_t console_mfn;
 char *console_tty;
 
 char *saved_state;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 3/5 v2] libxc: Fix the data type of mfn parameter passed to xc_map_foreign_range()

2017-10-25 Thread Bhupinder Thakur
Currently the data type of mfn parameter passed to xc_map_foreign_range() is 
unsigned
long. This could be problem for 32-bit arm architectures where the lengh of 
long is
32 bits while mfn happens to be a 64-bit value.

To avoid truncating a 64-bit value, the type of mfn is changed from "unsigned 
long" to
xen_pfn_t. Also the parameter name "mfn" is changed to "pfn" which is a more 
accurate
indication of what this parameter represents.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

This patch is as per the review of commit fa1f157
libxl: Fix the bug introduced in commit "libxl: use correct type

 tools/libxc/include/xenctrl_compat.h | 2 +-
 tools/libxc/xc_foreign_memory.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libxc/include/xenctrl_compat.h 
b/tools/libxc/include/xenctrl_compat.h
index a655e47..5ee72bf 100644
--- a/tools/libxc/include/xenctrl_compat.h
+++ b/tools/libxc/include/xenctrl_compat.h
@@ -26,7 +26,7 @@
  */
 void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
 int size, int prot,
-unsigned long mfn );
+xen_pfn_t pfn);
 
 void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
const xen_pfn_t *arr, int num );
diff --git a/tools/libxc/xc_foreign_memory.c b/tools/libxc/xc_foreign_memory.c
index 4053d26..c1f114a 100644
--- a/tools/libxc/xc_foreign_memory.c
+++ b/tools/libxc/xc_foreign_memory.c
@@ -33,7 +33,7 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, 
int prot,
 
 void *xc_map_foreign_range(xc_interface *xch,
uint32_t dom, int size, int prot,
-   unsigned long mfn)
+   xen_pfn_t pfn)
 {
 xen_pfn_t *arr;
 int num;
@@ -46,7 +46,7 @@ void *xc_map_foreign_range(xc_interface *xch,
 return NULL;
 
 for ( i = 0; i < num; i++ )
-arr[i] = mfn + i;
+arr[i] = pfn + i;
 
 ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
 free(arr);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 5/5 v2] xenconsole: Define and use a macro XEN_INVALID_PFN instead of -1

2017-10-25 Thread Bhupinder Thakur
xenconsole will use a new macro XEN_INVALID_PFN instead of -1 for initializing 
ring-ref.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

This patch is as per the review of commit fa1f157
libxl: Fix the bug introduced in commit "libxl: use correct type

 tools/console/daemon/io.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 1839973..aa291db 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -62,6 +62,8 @@
 /* Duration of each time period in ms */
 #define RATE_LIMIT_PERIOD 200
 
+#define XEN_INVALID_PFN (~(xen_pfn_t)0)
+
 extern int log_reload;
 extern int log_guest;
 extern int log_hv;
@@ -658,12 +660,12 @@ static void console_unmap_interface(struct console *con)
 {
if (con->interface == NULL)
return;
-   if (xgt_handle && con->ring_ref == -1)
+   if (xgt_handle && con->ring_ref == XEN_INVALID_PFN)
xengnttab_unmap(xgt_handle, con->interface, 1);
else
munmap(con->interface, XC_PAGE_SIZE);
con->interface = NULL;
-   con->ring_ref = -1;
+   con->ring_ref = XEN_INVALID_PFN;
 }
  
 static int console_create_ring(struct console *con)
@@ -698,7 +700,7 @@ static int console_create_ring(struct console *con)
free(type);
 
/* If using ring_ref and it has changed, remap */
-   if (ring_ref != con->ring_ref && con->ring_ref != -1)
+   if (ring_ref != con->ring_ref && con->ring_ref != XEN_INVALID_PFN)
console_unmap_interface(con);
 
if (!con->interface && xgt_handle && con->use_gnttab) {
@@ -706,7 +708,7 @@ static int console_create_ring(struct console *con)
con->interface = xengnttab_map_grant_ref(xgt_handle,
dom->domid, GNTTAB_RESERVED_CONSOLE,
PROT_READ|PROT_WRITE);
-   con->ring_ref = -1;
+   con->ring_ref = XEN_INVALID_PFN;
}
if (!con->interface) {
/* Fall back to xc_map_foreign_range */
@@ -812,7 +814,7 @@ static int console_init(struct console *con, struct domain 
*dom, void **data)
con->master_pollfd_idx = -1;
con->slave_fd = -1;
con->log_fd = -1;
-   con->ring_ref = -1;
+   con->ring_ref = XEN_INVALID_PFN;
con->local_port = -1;
con->remote_port = -1;
con->xce_pollfd_idx = -1;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 1/5 v2] libxl: Fix the bug introduced in commit "libxl: use correct type modifier for vuart_gfn"

2017-10-25 Thread Bhupinder Thakur
In libxl__device_vuart_add vuart_gfn is getting stored as a hex value:

> flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));

However, xenstore reads this value as a decimal value and tries to map the
wrong address and fails.

This patch introduces a new format specifier "PRIu_xen_pfn" which formats the 
value as a
decimal value.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 
CC: Jan Beulich 
CC: Andrew Cooper 

 tools/libxl/libxl_console.c   | 2 +-
 xen/include/public/arch-arm.h | 1 +
 xen/include/public/arch-x86/xen.h | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index c05dc28..6bfc0e5 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -376,7 +376,7 @@ int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
 flexarray_append(ro_front, "port");
 flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
 flexarray_append(ro_front, "ring-ref");
-flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));
+flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, state->vuart_gfn));
 flexarray_append(ro_front, "limit");
 flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT));
 flexarray_append(ro_front, "type");
diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h
index 5708cd2..05fd11c 100644
--- a/xen/include/public/arch-arm.h
+++ b/xen/include/public/arch-arm.h
@@ -274,6 +274,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t);
 
 typedef uint64_t xen_pfn_t;
 #define PRI_xen_pfn PRIx64
+#define PRIu_xen_pfn PRIu64
 
 /* Maximum number of virtual CPUs in legacy multi-processor guests. */
 /* Only one. All other VCPUS must use VCPUOP_register_vcpu_info */
diff --git a/xen/include/public/arch-x86/xen.h 
b/xen/include/public/arch-x86/xen.h
index ff91831..3b0b1d6 100644
--- a/xen/include/public/arch-x86/xen.h
+++ b/xen/include/public/arch-x86/xen.h
@@ -75,6 +75,7 @@ __DeFiNe__ __DECL_REG_LO16(name) e ## name
 #ifndef __ASSEMBLY__
 typedef unsigned long xen_pfn_t;
 #define PRI_xen_pfn "lx"
+#define PRIu_xen_pfn "lu"
 #endif
 
 #define XEN_HAVE_PV_GUEST_ENTRY 1
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 4/5 v2] xenconsole: Change the type of ring_ref to xen_pfn_t in console_create_ring

2017-10-25 Thread Bhupinder Thakur
Currently, ring_ref is read as an integer in console_create_ring which could 
lead to
truncation of the value as it is reading a 64-bit value.

The fix is to modify the type of ring_ref to xen_pfn_t and use the correct 
format
specifier to read the value correctly for all architectures.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

This patch is as per the review of commit fa1f157
libxl: Fix the bug introduced in commit "libxl: use correct type

 tools/console/daemon/io.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index e22009a..1839973 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -19,6 +19,7 @@
 
 #define _GNU_SOURCE
 
+#include 
 #include "utils.h"
 #include "io.h"
 #include 
@@ -81,6 +82,12 @@ static unsigned int nr_fds;
 
 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 
+#if defined(CONFIG_ARM)
+# define SCNi_xen_pfn SCNi64
+#else
+# define SCNi_xen_pfn "li"
+#endif
+
 struct buffer {
char *data;
size_t consumed;
@@ -98,7 +105,7 @@ struct console {
struct buffer buffer;
char *xspath;
char *log_suffix;
-   int ring_ref;
+   xen_pfn_t ring_ref;
xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
int event_count;
@@ -661,12 +668,13 @@ static void console_unmap_interface(struct console *con)
  
 static int console_create_ring(struct console *con)
 {
-   int err, remote_port, ring_ref, rc;
+   int err, remote_port, rc;
+   xen_pfn_t ring_ref;
char *type, path[PATH_MAX];
struct domain *dom = con->d;
 
err = xs_gather(xs, con->xspath,
-   "ring-ref", "%u", &ring_ref,
+   "ring-ref", "%"SCNi_xen_pfn, &ring_ref,
"port", "%i", &remote_port,
NULL);
 
@@ -705,7 +713,7 @@ static int console_create_ring(struct console *con)
con->interface = xc_map_foreign_range(
xc, dom->domid, XC_PAGE_SIZE,
PROT_READ|PROT_WRITE,
-   (unsigned long)ring_ref);
+   ring_ref);
if (con->interface == NULL) {
err = EINVAL;
goto out;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH RFC] ARM: vPL011: use receive timeout interrupt

2017-10-24 Thread Bhupinder Thakur
Hi,

On 23 October 2017 at 21:31, Andre Przywara  wrote:
> Hi,
>
> On 18/10/17 17:32, Bhupinder Thakur wrote:
>> Hi Andre,
>>
>> I verified this patch on qualcomm platform. It is working fine.
>>
>> On 18 October 2017 at 19:11, Andre Przywara  wrote:
>>> Instead of asserting the receive interrupt (RXI) on the first character
>>> in the FIFO, lets (ab)use the receive timeout interrupt (RTI) for that
>>> purpose. That seems to be closer to the spec and what hardware does.
>>> Improve the readability of vpl011_data_avail() on the way.
>>>
>>> Signed-off-by: Andre Przywara 
>>> ---
>>> Hi,
>>>
>>> this one is the approach I mentioned in the email earlier today.
>>> It goes on top of Bhupinders v12 27/27, but should eventually be merged
>>> into this one once we agreed on the subject. I just carved it out here
>>> for clarity to make it clearer what has been changed.
>>> Would be good if someone could test it.
>>>
>>> Cheers,
>>> Andre.
>>>  xen/arch/arm/vpl011.c | 61 
>>> ---
>>>  1 file changed, 29 insertions(+), 32 deletions(-)
>>>
>>> diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
>>> index adf1711571..ae18bddd81 100644
>>> --- a/xen/arch/arm/vpl011.c
>>> +++ b/xen/arch/arm/vpl011.c
>>> @@ -105,9 +105,13 @@ static uint8_t vpl011_read_data(struct domain *d)
>>>  if ( fifo_level == 0 )
>>>  {
>>>  vpl011->uartfr |= RXFE;
>>> -vpl011->uartris &= ~RXI;
>>> -vpl011_update_interrupt_status(d);
>>> +vpl011->uartris &= ~RTI;
>>>  }
>>> +
>>> +if ( fifo_level < sizeof(intf->in) - SBSA_UART_FIFO_SIZE / 2 )
>>> +vpl011->uartris &= ~RXI;
>>> +
>>> +vpl011_update_interrupt_status(d);
>> I think we check if ( fifo_level < SBSA_UART_FIFO_SIZE / 2 ) which
>> should be a valid condition to clear the RX interrupt.
>
> Are you sure? My understanding is that the semantics of the return value
> of xencons_queued() differs between intf and outf:
> - For intf, Xen fills that buffer with incoming characters. The
> watermark is assumed to be (FIFO / 2), which translates into 16
> characters. Now for the SBSA vUART RX side that means: "Assert the RX
> interrupt if there is only room for 16 (or less) characters in the FIFO
> (read: intf buffer in our case). Since we (ab)use the Xen buffer for the
> FIFO, this means we warn if the number of queued characters exceeds
> (buffersize - 16).
> - For outf, the UART emulation fills the buffer. The SBSA vUART TX side
> demands that the TX interrupt is asserted if the fill level of the
> transmit FIFO is less than or equal to the 16 characters, which means:
> number of queued characters is less than 16.
>
> I think the key point is that our trigger level isn't symmetrical here,
> since we have to emulate the architected 32-byte FIFO semantics for the
> driver, but have a (secretly) much larger "FIFO" internally.
>
> Do you agree with this reasoning and do I have a thinko here? Could well
> be I am seriously misguided here.
>
ok. I agree with the description as it will expose the same behavior
to the driver as it would be there for a real UART where only FIFO/2
space is left.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH RFC] ARM: vPL011: use receive timeout interrupt

2017-10-24 Thread Bhupinder Thakur
Hi Andre,


On 24 October 2017 at 16:57, Andre Przywara  wrote:
> Hi,
>
> On 24/10/17 12:00, Julien Grall wrote:
>> Hi,
>>
>> On 23/10/2017 17:01, Andre Przywara wrote:
>>> Hi,
>>>
>>> On 18/10/17 17:32, Bhupinder Thakur wrote:
>>>> Hi Andre,
>>>>
>>>> I verified this patch on qualcomm platform. It is working fine.
>>>>
>>>> On 18 October 2017 at 19:11, Andre Przywara 
>>>> wrote:
>>>>> Instead of asserting the receive interrupt (RXI) on the first character
>>>>> in the FIFO, lets (ab)use the receive timeout interrupt (RTI) for that
>>>>> purpose. That seems to be closer to the spec and what hardware does.
>>>>> Improve the readability of vpl011_data_avail() on the way.
>>>>>
>>>>> Signed-off-by: Andre Przywara 
>>>>> ---
>>>>> Hi,
>>>>>
>>>>> this one is the approach I mentioned in the email earlier today.
>>>>> It goes on top of Bhupinders v12 27/27, but should eventually be merged
>>>>> into this one once we agreed on the subject. I just carved it out here
>>>>> for clarity to make it clearer what has been changed.
>>>>> Would be good if someone could test it.
>>>>>
>>>>> Cheers,
>>>>> Andre.
>>>>>  xen/arch/arm/vpl011.c | 61
>>>>> ---
>>>>>  1 file changed, 29 insertions(+), 32 deletions(-)
>>>>>
>>>>> diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
>>>>> index adf1711571..ae18bddd81 100644
>>>>> --- a/xen/arch/arm/vpl011.c
>>>>> +++ b/xen/arch/arm/vpl011.c
>>>>> @@ -105,9 +105,13 @@ static uint8_t vpl011_read_data(struct domain *d)
>>>>>  if ( fifo_level == 0 )
>>>>>  {
>>>>>  vpl011->uartfr |= RXFE;
>>>>> -vpl011->uartris &= ~RXI;
>>>>> -vpl011_update_interrupt_status(d);
>>>>> +vpl011->uartris &= ~RTI;
>>>>>  }
>>>>> +
>>>>> +if ( fifo_level < sizeof(intf->in) - SBSA_UART_FIFO_SIZE / 2 )
>>>>> +vpl011->uartris &= ~RXI;
>>>>> +
>>>>> +vpl011_update_interrupt_status(d);
>>>> I think we check if ( fifo_level < SBSA_UART_FIFO_SIZE / 2 ) which
>>>> should be a valid condition to clear the RX interrupt.
>>>
>>> Are you sure? My understanding is that the semantics of the return value
>>> of xencons_queued() differs between intf and outf:
>>> - For intf, Xen fills that buffer with incoming characters. The
>>> watermark is assumed to be (FIFO / 2), which translates into 16
>>> characters. Now for the SBSA vUART RX side that means: "Assert the RX
>>> interrupt if there is only room for 16 (or less) characters in the FIFO
>>> (read: intf buffer in our case). Since we (ab)use the Xen buffer for the
>>> FIFO, this means we warn if the number of queued characters exceeds
>>> (buffersize - 16).
>>> - For outf, the UART emulation fills the buffer. The SBSA vUART TX side
>>> demands that the TX interrupt is asserted if the fill level of the
>>> transmit FIFO is less than or equal to the 16 characters, which means:
>>> number of queued characters is less than 16.
>>>
>>> I think the key point is that our trigger level isn't symmetrical here,
>>> since we have to emulate the architected 32-byte FIFO semantics for the
>>> driver, but have a (secretly) much larger "FIFO" internally.
>>>
>>> Do you agree with this reasoning and do I have a thinko here? Could well
>>> be I am seriously misguided here.
>>
>> xencons_queued calculates how many bytes are currently on the ring. So I
>> think your description makes sense.
>>
>> With (fifo_level < (SBSA_UART_FIFO_SIZE / 2)), you would only clear it
>> when the ring has less than 16 bytes queued.
>>
>> I have a few requests on those patches for the resender:
>> - Please introduce a define for SBSA_UART_FIFO_SIZE / 2 and use it
>> everywhere.
>> - Please add a bit more documentation on top of the checks in
>> vpl011_read_data function. The checks in vpl011_write_data looks
>> well-documented.
>
> I am just at rewording the commit message and was planning on re-sending
> the (merged) patches later today (keeping Bhupinder's authorship, of
> course).
>
> I hope that Bhupinder doesn't mind or this doesn't clash with any of his
> plans.
It is fine with me. Thanks.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH RFC] ARM: vPL011: use receive timeout interrupt

2017-10-18 Thread Bhupinder Thakur
Hi Andre,

I verified this patch on qualcomm platform. It is working fine.

On 18 October 2017 at 19:11, Andre Przywara  wrote:
> Instead of asserting the receive interrupt (RXI) on the first character
> in the FIFO, lets (ab)use the receive timeout interrupt (RTI) for that
> purpose. That seems to be closer to the spec and what hardware does.
> Improve the readability of vpl011_data_avail() on the way.
>
> Signed-off-by: Andre Przywara 
> ---
> Hi,
>
> this one is the approach I mentioned in the email earlier today.
> It goes on top of Bhupinders v12 27/27, but should eventually be merged
> into this one once we agreed on the subject. I just carved it out here
> for clarity to make it clearer what has been changed.
> Would be good if someone could test it.
>
> Cheers,
> Andre.
>  xen/arch/arm/vpl011.c | 61 
> ---
>  1 file changed, 29 insertions(+), 32 deletions(-)
>
> diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
> index adf1711571..ae18bddd81 100644
> --- a/xen/arch/arm/vpl011.c
> +++ b/xen/arch/arm/vpl011.c
> @@ -105,9 +105,13 @@ static uint8_t vpl011_read_data(struct domain *d)
>  if ( fifo_level == 0 )
>  {
>  vpl011->uartfr |= RXFE;
> -vpl011->uartris &= ~RXI;
> -vpl011_update_interrupt_status(d);
> +vpl011->uartris &= ~RTI;
>  }
> +
> +if ( fifo_level < sizeof(intf->in) - SBSA_UART_FIFO_SIZE / 2 )
> +vpl011->uartris &= ~RXI;
> +
> +vpl011_update_interrupt_status(d);
I think we check if ( fifo_level < SBSA_UART_FIFO_SIZE / 2 ) which
should be a valid condition to clear the RX interrupt.

>  }
>  else
>  gprintk(XENLOG_ERR, "vpl011: Unexpected IN ring buffer empty\n");
> @@ -129,7 +133,7 @@ static void vpl011_update_tx_fifo_status(struct vpl011 
> *vpl011,
>   unsigned int fifo_level)
>  {
>  struct xencons_interface *intf = vpl011->ring_buf;
> -unsigned int fifo_threshold;
> +unsigned int fifo_threshold = sizeof(intf->out) - SBSA_UART_FIFO_SIZE/2;
>
>  BUILD_BUG_ON(sizeof (intf->out) < SBSA_UART_FIFO_SIZE);
>
> @@ -137,8 +141,6 @@ static void vpl011_update_tx_fifo_status(struct vpl011 
> *vpl011,
>   * Set the TXI bit only when there is space for fifo_size/2 bytes which
>   * is the trigger level for asserting/de-assterting the TX interrupt.
>   */
> -fifo_threshold = sizeof(intf->out) - SBSA_UART_FIFO_SIZE/2;
> -
>  if ( fifo_level <= fifo_threshold )
>  vpl011->uartris |= TXI;
>  else
> @@ -390,35 +392,30 @@ static void vpl011_data_avail(struct domain *d)
>  out_cons,
>  sizeof(intf->out));
>
> -/* Update the uart rx state if the buffer is not empty. */
> -if ( in_fifo_level != 0 )
> -{
> +/ Update the UART RX state /
> +
> +/* Clear the FIFO_EMPTY bit if the FIFO holds at least one character. */
> +if ( in_fifo_level > 0 )
>  vpl011->uartfr &= ~RXFE;
>
> -if ( in_fifo_level == sizeof(intf->in) )
> -vpl011->uartfr |= RXFF;
> +/* Set the FIFO_FULL bit if the ring buffer is full. */
> +if ( in_fifo_level == sizeof(intf->in) )
> +vpl011->uartfr |= RXFF;
>
> -/*
> - * Currently, the RXI bit is getting set even if there is a single
> - * byte of data in the rx fifo. Ideally, the RXI bit should be set
> - * only if the rx fifo level reaches the threshold.
> - *
> - * However, since currently RX timeout interrupt is not
> - * implemented as there is not enough clarity in the SBSA spec,
> - * the guest may keep waiting for an interrupt to read more
> - * data. To ensure that guest reads all the data without
> - * any delay, the RXI interrupt is raised if there is RX data
> - * available without checking whether fifo level has reached
> - * the threshold.
> - *
> - * TBD: Once there is more clarity in the SBSA spec on whether RX
> - * timeout interrupt needs to be implemented, the RXI interrupt
> - * will be raised only when rx fifo level reaches the threshold.
> - */
> +/* The FIFO trigger level is fixed to half of the FIFO. */
> +if ( in_fifo_level >= sizeof(intf->in) - SBSA_UART_FIFO_SIZE / 2 )
>  vpl011->uartris |= RXI;
Here also should not we check if ( in_fifo_level >=
SBSA_UART_FIFO_SIZE / 2 ) since it is a valid condition to raise the
RX interrupt?

> -}
>
> -/* Update the uart tx state if the buffer is not full. */
> +/*
> + * If the input queue is not empty, we assert the receive timeout 
> interrupt.
> + * As we don't emulate any timing here, we ignore the actual timeout
> + * of 32 bit periods.
> + */
> +if ( in_fifo_level > 0 )
> +vpl011->uartris |= RTI;
> +
> +/ Update the UART TX state 

Re: [Xen-devel] [PATCH 27/27 v12] arm/xen: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt

2017-10-18 Thread Bhupinder Thakur
On 18 October 2017 at 15:56, Andre Przywara  wrote:
> Hi,
>
> On 13/10/17 11:40, Bhupinder Thakur wrote:
>> This patch fixes the issue observed when pl011 patches were tested on
>> the junos hardware by Andre/Julien. It was observed that when large
>> output is generated such as on running 'find /', output was getting
>> truncated intermittently due to OUT ring buffer getting full.
>>
>> This issue was due to the fact that the SBSA UART driver expects that
>> when a TX interrupt is asserted then the FIFO queue should be atleast
>> half empty and that it can write N bytes in the FIFO, where N is half
>> the FIFO queue size, without the bytes getting dropped due to FIFO
>> getting full.
>>
>> The SBSA UART emulation logic was asserting the TX interrupt as soon
>> as any space became available in the FIFO and the SBSA UART driver
>> tried to write more data (upto 16 bytes) in the FIFO expecting that
>> there is enough space available leading to dropped bytes.
>>
>> The SBSA spec [1] does not specify when the TX interrupt should be
>> asserted or de-asserted. Due to lack of clarity on the expected
>> behavior, it is assumed for now that TX interrupt should be asserted
>> only when the FIFO goes half empty.
>>
>> TBD: Once the SBSA spec is updated with the expected behavior, the
>> implementation will be modified to align with the spec requirement.
>
> So similar to the other patch:
>
> - I can confirm that this patch fixes the dropped characters issue we
> see with current staging HEAD. And, differently from the first patch,
> this one fixes a correctness issue (we are loosing characters at the
> moment) rather than just a performance problem. So I think we definitely
> need something along those lines.
>
> However ... ;-)
> Asserting the receive interrupt at the first character, while it is
> architected to be only triggered at half the FIFO level, is not right.
> Instead what we probably want it to use the timeout interrupt instead. I
> quickly hacked something up like that:
> - In vpl011_data_avail() we assert the timeout interrupt (RTI) if the
> in-FIFO is not empty. This is following the idea that when this function
> is called, Xen says: this is all the data I have at the moment. The
> guest should be able to see the data, because Xen has no idea when and
> if more data will come in.
> - If we drain the in-FIFO in vpl011_mmio_read() (fifo_level becomes 0),
> we clear RTI.
> - We handle RXI like described in the spec: assert it in data_avail() if
> the FIFO has 16 or less characters left, clear it in mmio_read() if the
> FIFO has space for more than 16 characters.
I think you meant - RXI should be asserted when FIFO has 16 or more
characters left.
>
> This basically moves the trick of asserting RXI to asserting RTI
> instead, which sounds architecturally cleaner.
>
> Let me try to clean up my approach and post it.
>
> Cheers,
> Andre.
>
>
>
>>
>> [1] http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf
>>
>> Signed-off-by: Bhupinder Thakur 
>> ---
>> CC: Julien Grall 
>> CC: Andre Przywara 
>> CC: Stefano Stabellini 
>> CC: Dave Martin 
>>
>> Changes since v11:
>> - Add a build assert to check that ring buffer size is more than minimum rx 
>> fif size of 32
>> - Added a comment to explain why threshold based logic is not implemented 
>> for rx fifo
>> - Moved calls to vpl011_update_interrupt_status() near where TXI/RXI status 
>> bit is set
>>
>> Changes since v8:
>> - Used variables fifo_level/fifo_threshold for more clarity
>> - Added a new macro SBSA_UART_FIFO_SIZE instead of using a magic number
>> - Renamed ring_qsize variables to fifo_level for consistency
>>
>>  xen/arch/arm/vpl011.c| 113 
>> ++-
>>  xen/include/asm-arm/vpl011.h |   2 +
>>  2 files changed, 82 insertions(+), 33 deletions(-)
>>
>> diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
>> index 0b07436..adf1711 100644
>> --- a/xen/arch/arm/vpl011.c
>> +++ b/xen/arch/arm/vpl011.c
>> @@ -93,24 +93,27 @@ static uint8_t vpl011_read_data(struct domain *d)
>>   */
>>  if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) > 0 )
>>  {
>> +unsigned int fifo_level;
>> +
>>  data = intf->in[xencons_mask(in_cons, sizeof(intf->in))];
>>  in_cons += 1;
>>  smp_mb();
>>  intf->in_cons = in_cons;
>> +
>> +fifo_level = xencons_queued(in_prod, in_cons, sizeof(intf->in));
>&

Re: [Xen-devel] [PATCH 26/27 v12] arm/xen: vpl011: Fix the slow early console SBSA UART output

2017-10-18 Thread Bhupinder Thakur
Hi Andre,

On 17 October 2017 at 15:21, Andre Przywara  wrote:
> Hi Bhupinder,
>
> first thing: As the bulk of the series has been merged now, please
> restart your patch and version numbering, so a (potential) next post
> should be prefixed [PATCH v3 1/2]. And please have a cover letter giving
> a brief overview what this series fixes.
>
Should I resend the patch series with a cover letter? I will also add
a reported-by tag.

> On 13/10/17 11:40, Bhupinder Thakur wrote:
>> The early console output uses pl011_early_write() to write data. This
>> function waits for BUSY bit to get cleared before writing the next byte.
>
> ... which is questionable given the actual definition of the BUSY bit in
> the PL011 TRM:
>
> 
>  The BUSY signal goes HIGH as soon as data is written to the
> transmit FIFO (that is, the FIFO is non-empty) and remains asserted
> HIGH while data is being transmitted. BUSY is negated only when the
> transmit FIFO is empty, and the last character has been transmitted from
> the shift register, 
> 
>
> (I take it you are talking about the Linux driver in a guest here).
> I think the early_write routine tries to (deliberately?) ignore the
> FIFO, possibly to make sure characters really get pushed out before a
> system crashes, maybe.
>
>>
>> In the SBSA UART emulation logic, the BUSY bit was set as soon one
>> byte was written in the FIFO and it remained set until the FIFO was
>> emptied.
>
> Which is correct behaviour, as this matches the PL011 TRM as quoted above.
>
>> This meant that the output was delayed as each character needed
>> the BUSY to get cleared.
>
> But this is true as well!
>
>> Since the SBSA UART is getting emulated in Xen using ring buffers, it
>> ensures that once the data is enqueued in the FIFO, it will be received
>> by xenconsole so it is safe to set the BUSY bit only when FIFO becomes
>> full. This will ensure that pl011_early_write() is not delayed unduly
>> to write the data.
>
> So I can confirm that this patch fixes the very slow earlycon output
> observed with the current staging HEAD.
>
> So while this is somewhat deviating from the spec, I can see the benefit
> for an emulation scenario. I believe that emulations in general might
> choose implementing things a bit differently, to cope with the
> fundamental differences in their environment, like the virtually endless
> "FIFO" and the lack of any timing restrictions on the emulated "wire".
>
> So unless someone comes up with a better solution, I would support
> taking this patch, as this fixes a real problem.
>
> Cheers,
> Andre
>
>> Signed-off-by: Bhupinder Thakur 
>> ---
>> CC: Julien Grall 
>> CC: Andre Przywara 
>> CC: Stefano Stabellini 
>>
>>  xen/arch/arm/vpl011.c | 21 -
>>  1 file changed, 16 insertions(+), 5 deletions(-)
>>
>> diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
>> index f7ddccb..0b07436 100644
>> --- a/xen/arch/arm/vpl011.c
>> +++ b/xen/arch/arm/vpl011.c
>> @@ -159,9 +159,15 @@ static void vpl011_write_data(struct domain *d, uint8_t 
>> data)
>>  {
>>  vpl011->uartfr |= TXFF;
>>  vpl011->uartris &= ~TXI;
>> -}
>>
>> -vpl011->uartfr |= BUSY;
>> +/*
>> + * This bit is set only when FIFO becomes full. This ensures that
>> + * the SBSA UART driver can write the early console data as fast as
>> + * possible, without waiting for the BUSY bit to get cleared before
>> + * writing each byte.
>> + */
>> +vpl011->uartfr |= BUSY;
>> +}
>>
>>  vpl011->uartfr &= ~TXFE;
>>
>> @@ -371,11 +377,16 @@ static void vpl011_data_avail(struct domain *d)
>>  {
>>  vpl011->uartfr &= ~TXFF;
>>  vpl011->uartris |= TXI;
>> +
>> +/*
>> + * Clear the BUSY bit as soon as space becomes available
>> + * so that the SBSA UART driver can start writing more data
>> + * without any further delay.
>> + */
>> +vpl011->uartfr &= ~BUSY;
>> +
>>  if ( out_ring_qsize == 0 )
>> -{
>> -vpl011->uartfr &= ~BUSY;
>>  vpl011->uartfr |= TXFE;
>> -}
>>  }
>>
>>  vpl011_update_interrupt_status(d);
>>

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] xenconsole: Define and use a macro INVALID_XEN_PFN instead of -1

2017-10-17 Thread Bhupinder Thakur
xenconsole will use a new macro INVALID_XEN_PFN instead of -1 for initializing 
ring-ref.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Andrew Cooper 
CC: George Dunlap 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Julien Grall 

 tools/console/daemon/io.c | 10 +-
 xen/include/public/xen.h  |  2 ++
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 1839973..9129f5a 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -658,12 +658,12 @@ static void console_unmap_interface(struct console *con)
 {
if (con->interface == NULL)
return;
-   if (xgt_handle && con->ring_ref == -1)
+   if (xgt_handle && con->ring_ref == INVALID_XEN_PFN)
xengnttab_unmap(xgt_handle, con->interface, 1);
else
munmap(con->interface, XC_PAGE_SIZE);
con->interface = NULL;
-   con->ring_ref = -1;
+   con->ring_ref = INVALID_XEN_PFN;
 }
  
 static int console_create_ring(struct console *con)
@@ -698,7 +698,7 @@ static int console_create_ring(struct console *con)
free(type);
 
/* If using ring_ref and it has changed, remap */
-   if (ring_ref != con->ring_ref && con->ring_ref != -1)
+   if (ring_ref != con->ring_ref && con->ring_ref != INVALID_XEN_PFN)
console_unmap_interface(con);
 
if (!con->interface && xgt_handle && con->use_gnttab) {
@@ -706,7 +706,7 @@ static int console_create_ring(struct console *con)
con->interface = xengnttab_map_grant_ref(xgt_handle,
dom->domid, GNTTAB_RESERVED_CONSOLE,
PROT_READ|PROT_WRITE);
-   con->ring_ref = -1;
+   con->ring_ref = INVALID_XEN_PFN;
}
if (!con->interface) {
/* Fall back to xc_map_foreign_range */
@@ -812,7 +812,7 @@ static int console_init(struct console *con, struct domain 
*dom, void **data)
con->master_pollfd_idx = -1;
con->slave_fd = -1;
con->log_fd = -1;
-   con->ring_ref = -1;
+   con->ring_ref = INVALID_XEN_PFN;
con->local_port = -1;
con->remote_port = -1;
con->xce_pollfd_idx = -1;
diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h
index 308109f..fc383ca 100644
--- a/xen/include/public/xen.h
+++ b/xen/include/public/xen.h
@@ -37,6 +37,8 @@
 #error "Unsupported architecture"
 #endif
 
+#define INVALID_XEN_PFN (~(xen_pfn_t)0)
+
 #ifndef __ASSEMBLY__
 /* Guest handles for primitive C types. */
 DEFINE_XEN_GUEST_HANDLE(char);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] libxl: Change the type of console_mfn to xen_pfn_t

2017-10-17 Thread Bhupinder Thakur
Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

 tools/libxl/libxl_console.c  | 2 +-
 tools/libxl/libxl_dom.c  | 2 +-
 tools/libxl/libxl_internal.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index 6bfc0e5..f2ca689 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -329,7 +329,7 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t domid,
 flexarray_append(ro_front, "port");
 flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->console_port));
 flexarray_append(ro_front, "ring-ref");
-flexarray_append(ro_front, GCSPRINTF("%lu", state->console_mfn));
+flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, 
state->console_mfn));
 } else {
 flexarray_append(front, "state");
 flexarray_append(front, GCSPRINTF("%d", XenbusStateInitialising));
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index ef834e6..a58e74f 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -869,7 +869,7 @@ out:
 static int hvm_build_set_params(xc_interface *handle, uint32_t domid,
 libxl_domain_build_info *info,
 int store_evtchn, unsigned long *store_mfn,
-int console_evtchn, unsigned long *console_mfn,
+int console_evtchn, xen_pfn_t *console_mfn,
 domid_t store_domid, domid_t console_domid)
 {
 struct hvm_info_table *va_hvm;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 45e6df6..f52aeb3 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1128,7 +1128,7 @@ typedef struct {
 
 uint32_t console_port;
 uint32_t console_domid;
-unsigned long console_mfn;
+xen_pfn_t console_mfn;
 char *console_tty;
 
 char *saved_state;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] libxl: Fix the bug introduced in commit "libxl: use correct type modifier for vuart_gfn"

2017-10-17 Thread Bhupinder Thakur
In libxl__device_vuart_add vuart_gfn is getting stored as a hex value:

> flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));

However, xenstore reads this value as a decimal value and tries to map the
wrong address and fails.

This patch introduces a new format specifier "PRIu_xen_pfn" which formats the 
value as a
decimal value.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 
CC: Jan Beulich 
CC: Andrew Cooper 

 tools/libxl/libxl_console.c   | 2 +-
 xen/include/public/arch-arm.h | 1 +
 xen/include/public/arch-x86/xen.h | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index c05dc28..6bfc0e5 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -376,7 +376,7 @@ int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
 flexarray_append(ro_front, "port");
 flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
 flexarray_append(ro_front, "ring-ref");
-flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));
+flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, state->vuart_gfn));
 flexarray_append(ro_front, "limit");
 flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT));
 flexarray_append(ro_front, "type");
diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h
index 5708cd2..05fd11c 100644
--- a/xen/include/public/arch-arm.h
+++ b/xen/include/public/arch-arm.h
@@ -274,6 +274,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t);
 
 typedef uint64_t xen_pfn_t;
 #define PRI_xen_pfn PRIx64
+#define PRIu_xen_pfn PRIu64
 
 /* Maximum number of virtual CPUs in legacy multi-processor guests. */
 /* Only one. All other VCPUS must use VCPUOP_register_vcpu_info */
diff --git a/xen/include/public/arch-x86/xen.h 
b/xen/include/public/arch-x86/xen.h
index ff91831..3b0b1d6 100644
--- a/xen/include/public/arch-x86/xen.h
+++ b/xen/include/public/arch-x86/xen.h
@@ -75,6 +75,7 @@ __DeFiNe__ __DECL_REG_LO16(name) e ## name
 #ifndef __ASSEMBLY__
 typedef unsigned long xen_pfn_t;
 #define PRI_xen_pfn "lx"
+#define PRIu_xen_pfn "lu"
 #endif
 
 #define XEN_HAVE_PV_GUEST_ENTRY 1
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] xenconsole: Change the type of ring_ref to xen_pfn_t in console_create_ring

2017-10-17 Thread Bhupinder Thakur
Currently, ring_ref is read as an integer in console_create_ring which could 
lead to
truncation of the value as it is reading a 64-bit value.

The fix is to modify the type of ring_ref to xen_pfn_t and use the correct 
format
specifier to read the value correctly for all architectures.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

 tools/console/daemon/io.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index e22009a..1839973 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -19,6 +19,7 @@
 
 #define _GNU_SOURCE
 
+#include 
 #include "utils.h"
 #include "io.h"
 #include 
@@ -81,6 +82,12 @@ static unsigned int nr_fds;
 
 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 
+#if defined(CONFIG_ARM)
+# define SCNi_xen_pfn SCNi64
+#else
+# define SCNi_xen_pfn "li"
+#endif
+
 struct buffer {
char *data;
size_t consumed;
@@ -98,7 +105,7 @@ struct console {
struct buffer buffer;
char *xspath;
char *log_suffix;
-   int ring_ref;
+   xen_pfn_t ring_ref;
xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
int event_count;
@@ -661,12 +668,13 @@ static void console_unmap_interface(struct console *con)
  
 static int console_create_ring(struct console *con)
 {
-   int err, remote_port, ring_ref, rc;
+   int err, remote_port, rc;
+   xen_pfn_t ring_ref;
char *type, path[PATH_MAX];
struct domain *dom = con->d;
 
err = xs_gather(xs, con->xspath,
-   "ring-ref", "%u", &ring_ref,
+   "ring-ref", "%"SCNi_xen_pfn, &ring_ref,
"port", "%i", &remote_port,
NULL);
 
@@ -705,7 +713,7 @@ static int console_create_ring(struct console *con)
con->interface = xc_map_foreign_range(
xc, dom->domid, XC_PAGE_SIZE,
PROT_READ|PROT_WRITE,
-   (unsigned long)ring_ref);
+   ring_ref);
if (con->interface == NULL) {
err = EINVAL;
goto out;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] libxc: Fix the data type of mfn parameter passed to xc_map_foreign_range()

2017-10-17 Thread Bhupinder Thakur
Currently the data type of mfn paramter passed to xc_map_foreign_range() is 
unsigned
long. This could be problem for 32-bit arm architectures where the lengh of 
long is
32 bits while mfn happens to be a 64-bit value.

To avoid truncating a 64-bit value, the type of mfn is changed from "unsigned 
long" to
xen_pfn_t. Also the parameter name "mfn" is changed to "pfn" which is a more 
accurate
indication of what this parameter represents.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

 tools/libxc/include/xenctrl_compat.h | 2 +-
 tools/libxc/xc_foreign_memory.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libxc/include/xenctrl_compat.h 
b/tools/libxc/include/xenctrl_compat.h
index a655e47..5ee72bf 100644
--- a/tools/libxc/include/xenctrl_compat.h
+++ b/tools/libxc/include/xenctrl_compat.h
@@ -26,7 +26,7 @@
  */
 void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
 int size, int prot,
-unsigned long mfn );
+xen_pfn_t pfn);
 
 void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
const xen_pfn_t *arr, int num );
diff --git a/tools/libxc/xc_foreign_memory.c b/tools/libxc/xc_foreign_memory.c
index 4053d26..c1f114a 100644
--- a/tools/libxc/xc_foreign_memory.c
+++ b/tools/libxc/xc_foreign_memory.c
@@ -33,7 +33,7 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, 
int prot,
 
 void *xc_map_foreign_range(xc_interface *xch,
uint32_t dom, int size, int prot,
-   unsigned long mfn)
+   xen_pfn_t pfn)
 {
 xen_pfn_t *arr;
 int num;
@@ -46,7 +46,7 @@ void *xc_map_foreign_range(xc_interface *xch,
 return NULL;
 
 for ( i = 0; i < num; i++ )
-arr[i] = mfn + i;
+arr[i] = pfn + i;
 
 ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
 free(arr);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] libxl/xenconsole: vpl011: Fix hex to dec conversion of vuart_gfn in libxl__device_vuart_add

2017-10-16 Thread Bhupinder Thakur
On 16 October 2017 at 15:53, Jan Beulich  wrote:
 On 16.10.17 at 11:02,  wrote:
>>  static int console_create_ring(struct console *con)
>>  {
>> - int err, remote_port, ring_ref, rc;
>> + int err, remote_port, rc;
>> + xen_pfn_t ring_ref;
>>   char *type, path[PATH_MAX];
>>   struct domain *dom = con->d;
>>
>>   err = xs_gather(xs, con->xspath,
>> - "ring-ref", "%u", &ring_ref,
>> + "ring-ref", "%i", &ring_ref,
>
> How would you gather a 64-bit value using %i without any length
> modifier? With just %i you're even going to use partially initialized
> data, so unless somewhere else the upper 32 bits got clipped off
> again the console wouldn't work anymore.
>
I should use "%lli" here to read it as a 64-bit value for all
architectures. Correct?

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] libxl: vpl011: Fix hex to dec conversion of vuart_gfn in libxl__device_vuart_add

2017-10-16 Thread Bhupinder Thakur
On 13 October 2017 at 20:36, Jan Beulich  wrote:
 On 13.10.17 at 16:35,  wrote:
>> Hi Jan,
>>
>> On 13/10/17 15:03, Jan Beulich wrote:
>> On 13.10.17 at 15:03,  wrote:
 On 13/10/17 13:32, Jan Beulich wrote:
 On 13.10.17 at 14:19,  wrote:
>> On 13/10/17 13:08, Jan Beulich wrote:
>> On 13.10.17 at 12:44,  wrote:
 In libxl__device_vuart_add vuart_gfn is getting stored as a hex value:

> flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, 
> state->vuart_gfn));
 However, xenstore reads this value as a decimal value and tries to map 
 the
 wrong address and fails.
>>> Is this generic or vuart specific code in xenstore that does so?
>>> Could you perhaps simply point me at the consuming side?
>>>
 Introduced a new format string "PRIu_xen_pfn" which formats the value 
 as a
 decimal value.
>>> I ask because I'm not really happy about this addition, i.e. I'd
>>> prefer the read side to change.
>>
>> Can the read side realistically change?
>
> Well, that's why I had asked whether this is generic or specific
> code. I would have hoped/assumed that xenstore doesn't
> generically try to translate strings into numbers - how would it
> know a string is to represent a number in the first place? Hence
> I was hoping for this to be specific (and hence) new code.
>
>> Its been decimal for a decade now, and there definitely is 3rd party
>> code which uses these values in xenstore (sadly).
>
> Are you trying to tell me there's been a vuart frontend before
> the device type introduction in libxl, or is the new device type
> compatible with an existing one?
>
>> Then again, the ring-ref key is listed as deprecated in our
>> documentation, without any reference describing which key should be used
>> instead.  It is also typically a grant reference, not a gfn, so
>> something wonky is definitely going on here.
>
> Which put under question how an existing frontend could work
> with this new device type.

 Well, vuart is replicating the behavior of console (see
 libxl__device_console_add). The console is passing a frame number in
 decimal in "ring-ref". Confusingly it is an MFN and would even break on
 32-bit toolstack using 64-bit Xen...

 So this patch is just following the console behavior by passing a
 decimal value rather than an hexadecimal value.
>>>
>>> Well, that other code path should then also use PRIu_xen_pfn, at
>>> the very least.
>>
>> By other code path, you mean the console code right? In that case, mfn
>> should also be moved from unsigned long to xen_pfn_t.
>
> Yes.
>
ok.

>>> It's of course interesting that the apparent consumer
>>> of this (tools/console/daemon/io.c:domain_create_ring()) uses
>>>
>>>  err = xs_gather(xs, dom->conspath,
>>>  "ring-ref", "%u", &ring_ref,
>>>  "port", "%i", &remote_port,
>>>  NULL);
>>>
>>> in order to then cast(!) the result to unsigned long in the
>>> invocation of xc_map_foreign_range(). Suggests to me that
>>> the console can't work reliably on a system with memory
>>> extending past the 1Tb boundary.
>>
>> It likely a latent bug. Probably a silly question, would there any
>> compatibility issue to switch the format to the correct one?
>
> I don't think so.
>
>>> It of course escapes me why %i (or really %lli) wasn't used here
>>> from the beginning, eliminating all radix concerns and matching
>>> what is being done for the port.
>>
>> Why %i? Should not the GFN be unsigned?
>
> Signedness is secondary here - the important thing is that %i is
> the only one allowing all of decimal, hex, and octal formatting of
> the string (the latter two of course with the usual 0 / 0x prefixes).
> Port numbers are unsigned too, yet %i is being used there.
>
>> Although, I can see the field
>> ring_reg is int and will store -1 as not mapped. This is quite confusing
>> and likely we want to turned into xen_pfn_t + use ~(xen_pfn_t)0.
>
> Indeed.
>
ok. I will modify the ring-ref type to xen_pfn_t.

>> But then, xc_map_foreign_range is using unsigned long instead of
>> xen_pfn_t. So I guess we should also switch the parameter to xen_pfn_t.
>
> Yes.
>
ok.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] libxl/xenconsole: vpl011: Fix hex to dec conversion of vuart_gfn in libxl__device_vuart_add

2017-10-16 Thread Bhupinder Thakur
In libxl__device_vuart_add vuart_gfn is getting stored as a hex value:

> flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));

However, xenstore reads this value as a decimal value and tries to map the
wrong address and fails.

Introduced a new format string "PRIu_xen_pfn" which formats the value as a
decimal value.  Also corrected the type of ring_ref to xen_pfn_t in xenconsole.

Signed-off-by: Bhupinder Thakur 
---

This patch was verified for arm64 and arm32 toolstack compilation.

CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 
CC: Jan Beulich 
CC: Andrew Cooper 

 tools/console/daemon/io.c| 20 +++-
 tools/libxc/include/xenctrl_compat.h |  2 +-
 tools/libxc/xc_foreign_memory.c  |  2 +-
 tools/libxl/libxl_console.c  |  4 ++--
 tools/libxl/libxl_dom.c  |  2 +-
 tools/libxl/libxl_internal.h |  2 +-
 xen/include/public/arch-arm.h|  1 +
 xen/include/public/arch-x86/xen.h|  1 +
 8 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index e22009a..6369bf4 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -80,6 +80,7 @@ static unsigned int current_array_size;
 static unsigned int nr_fds;
 
 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
+#define INVALID_RING_REF(~(xen_pfn_t)0)
 
 struct buffer {
char *data;
@@ -98,7 +99,7 @@ struct console {
struct buffer buffer;
char *xspath;
char *log_suffix;
-   int ring_ref;
+   xen_pfn_t ring_ref;
xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
int event_count;
@@ -651,22 +652,23 @@ static void console_unmap_interface(struct console *con)
 {
if (con->interface == NULL)
return;
-   if (xgt_handle && con->ring_ref == -1)
+   if (xgt_handle && con->ring_ref == INVALID_RING_REF)
xengnttab_unmap(xgt_handle, con->interface, 1);
else
munmap(con->interface, XC_PAGE_SIZE);
con->interface = NULL;
-   con->ring_ref = -1;
+   con->ring_ref = INVALID_RING_REF;
 }
  
 static int console_create_ring(struct console *con)
 {
-   int err, remote_port, ring_ref, rc;
+   int err, remote_port, rc;
+   xen_pfn_t ring_ref;
char *type, path[PATH_MAX];
struct domain *dom = con->d;
 
err = xs_gather(xs, con->xspath,
-   "ring-ref", "%u", &ring_ref,
+   "ring-ref", "%i", &ring_ref,
"port", "%i", &remote_port,
NULL);
 
@@ -690,7 +692,7 @@ static int console_create_ring(struct console *con)
free(type);
 
/* If using ring_ref and it has changed, remap */
-   if (ring_ref != con->ring_ref && con->ring_ref != -1)
+   if (ring_ref != con->ring_ref && con->ring_ref != INVALID_RING_REF)
console_unmap_interface(con);
 
if (!con->interface && xgt_handle && con->use_gnttab) {
@@ -698,14 +700,14 @@ static int console_create_ring(struct console *con)
con->interface = xengnttab_map_grant_ref(xgt_handle,
dom->domid, GNTTAB_RESERVED_CONSOLE,
PROT_READ|PROT_WRITE);
-   con->ring_ref = -1;
+   con->ring_ref = INVALID_RING_REF;
}
if (!con->interface) {
/* Fall back to xc_map_foreign_range */
con->interface = xc_map_foreign_range(
xc, dom->domid, XC_PAGE_SIZE,
PROT_READ|PROT_WRITE,
-   (unsigned long)ring_ref);
+   ring_ref);
if (con->interface == NULL) {
err = EINVAL;
goto out;
@@ -804,7 +806,7 @@ static int console_init(struct console *con, struct domain 
*dom, void **data)
con->master_pollfd_idx = -1;
con->slave_fd = -1;
con->log_fd = -1;
-   con->ring_ref = -1;
+   con->ring_ref = INVALID_RING_REF;
con->local_port = -1;
con->remote_port = -1;
con->xce_pollfd_idx = -1;
diff --git a/tools/libxc/include/xenctrl_compat.h 
b/tools/libxc/include/xenctrl_compat.h
index a655e47..2d930d8 100644
--- a/tools/libxc/include/xenctrl_compat.h
+++ b/tools/libxc/include/xenctrl_compat.h
@@ -26,7 +26,7 @@
  */
 void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
 int size, int prot,
-unsigned long mfn );
+xen_pfn_t mfn );
 
 void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int pr

[Xen-devel] libxl: vpl011: Fix hex to dec conversion of vuart_gfn in libxl__device_vuart_add

2017-10-13 Thread Bhupinder Thakur
In libxl__device_vuart_add vuart_gfn is getting stored as a hex value:

> flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));

However, xenstore reads this value as a decimal value and tries to map the
wrong address and fails.

Introduced a new format string "PRIu_xen_pfn" which formats the value as a
decimal value.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 
CC: Jan Beulich 
CC: Andrew Cooper 

 tools/libxl/libxl_console.c   | 2 +-
 xen/include/public/arch-arm.h | 1 +
 xen/include/public/arch-x86/xen.h | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index c05dc28..6bfc0e5 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -376,7 +376,7 @@ int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
 flexarray_append(ro_front, "port");
 flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
 flexarray_append(ro_front, "ring-ref");
-flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));
+flexarray_append(ro_front, GCSPRINTF("%"PRIu_xen_pfn, state->vuart_gfn));
 flexarray_append(ro_front, "limit");
 flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT));
 flexarray_append(ro_front, "type");
diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h
index 5708cd2..05fd11c 100644
--- a/xen/include/public/arch-arm.h
+++ b/xen/include/public/arch-arm.h
@@ -274,6 +274,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t);
 
 typedef uint64_t xen_pfn_t;
 #define PRI_xen_pfn PRIx64
+#define PRIu_xen_pfn PRIu64
 
 /* Maximum number of virtual CPUs in legacy multi-processor guests. */
 /* Only one. All other VCPUS must use VCPUOP_register_vcpu_info */
diff --git a/xen/include/public/arch-x86/xen.h 
b/xen/include/public/arch-x86/xen.h
index ff91831..3b0b1d6 100644
--- a/xen/include/public/arch-x86/xen.h
+++ b/xen/include/public/arch-x86/xen.h
@@ -75,6 +75,7 @@ __DeFiNe__ __DECL_REG_LO16(name) e ## name
 #ifndef __ASSEMBLY__
 typedef unsigned long xen_pfn_t;
 #define PRI_xen_pfn "lx"
+#define PRIu_xen_pfn "lu"
 #endif
 
 #define XEN_HAVE_PV_GUEST_ENTRY 1
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 27/27 v12] arm/xen: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt

2017-10-13 Thread Bhupinder Thakur
This patch fixes the issue observed when pl011 patches were tested on
the junos hardware by Andre/Julien. It was observed that when large
output is generated such as on running 'find /', output was getting
truncated intermittently due to OUT ring buffer getting full.

This issue was due to the fact that the SBSA UART driver expects that
when a TX interrupt is asserted then the FIFO queue should be atleast
half empty and that it can write N bytes in the FIFO, where N is half
the FIFO queue size, without the bytes getting dropped due to FIFO
getting full.

The SBSA UART emulation logic was asserting the TX interrupt as soon
as any space became available in the FIFO and the SBSA UART driver
tried to write more data (upto 16 bytes) in the FIFO expecting that
there is enough space available leading to dropped bytes.

The SBSA spec [1] does not specify when the TX interrupt should be
asserted or de-asserted. Due to lack of clarity on the expected
behavior, it is assumed for now that TX interrupt should be asserted
only when the FIFO goes half empty.

TBD: Once the SBSA spec is updated with the expected behavior, the
implementation will be modified to align with the spec requirement.

[1] http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf

Signed-off-by: Bhupinder Thakur 
---
CC: Julien Grall 
CC: Andre Przywara 
CC: Stefano Stabellini 
CC: Dave Martin 

Changes since v11:
- Add a build assert to check that ring buffer size is more than minimum rx fif 
size of 32
- Added a comment to explain why threshold based logic is not implemented for 
rx fifo
- Moved calls to vpl011_update_interrupt_status() near where TXI/RXI status bit 
is set
 
Changes since v8:
- Used variables fifo_level/fifo_threshold for more clarity
- Added a new macro SBSA_UART_FIFO_SIZE instead of using a magic number
- Renamed ring_qsize variables to fifo_level for consistency 

 xen/arch/arm/vpl011.c| 113 ++-
 xen/include/asm-arm/vpl011.h |   2 +
 2 files changed, 82 insertions(+), 33 deletions(-)

diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
index 0b07436..adf1711 100644
--- a/xen/arch/arm/vpl011.c
+++ b/xen/arch/arm/vpl011.c
@@ -93,24 +93,27 @@ static uint8_t vpl011_read_data(struct domain *d)
  */
 if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) > 0 )
 {
+unsigned int fifo_level;
+
 data = intf->in[xencons_mask(in_cons, sizeof(intf->in))];
 in_cons += 1;
 smp_mb();
 intf->in_cons = in_cons;
+
+fifo_level = xencons_queued(in_prod, in_cons, sizeof(intf->in));
+
+if ( fifo_level == 0 )
+{
+vpl011->uartfr |= RXFE;
+vpl011->uartris &= ~RXI;
+vpl011_update_interrupt_status(d);
+}
 }
 else
 gprintk(XENLOG_ERR, "vpl011: Unexpected IN ring buffer empty\n");
 
-if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) == 0 )
-{
-vpl011->uartfr |= RXFE;
-vpl011->uartris &= ~RXI;
-}
-
 vpl011->uartfr &= ~RXFF;
 
-vpl011_update_interrupt_status(d);
-
 VPL011_UNLOCK(d, flags);
 
 /*
@@ -122,6 +125,26 @@ static uint8_t vpl011_read_data(struct domain *d)
 return data;
 }
 
+static void vpl011_update_tx_fifo_status(struct vpl011 *vpl011,
+ unsigned int fifo_level)
+{
+struct xencons_interface *intf = vpl011->ring_buf;
+unsigned int fifo_threshold;
+
+BUILD_BUG_ON(sizeof (intf->out) < SBSA_UART_FIFO_SIZE);
+
+/*
+ * Set the TXI bit only when there is space for fifo_size/2 bytes which
+ * is the trigger level for asserting/de-assterting the TX interrupt.
+ */
+fifo_threshold = sizeof(intf->out) - SBSA_UART_FIFO_SIZE/2;
+
+if ( fifo_level <= fifo_threshold )
+vpl011->uartris |= TXI;
+else
+vpl011->uartris &= ~TXI;
+}
+
 static void vpl011_write_data(struct domain *d, uint8_t data)
 {
 unsigned long flags;
@@ -146,33 +169,37 @@ static void vpl011_write_data(struct domain *d, uint8_t 
data)
 if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) !=
  sizeof (intf->out) )
 {
+unsigned int fifo_level;
+
 intf->out[xencons_mask(out_prod, sizeof(intf->out))] = data;
 out_prod += 1;
 smp_wmb();
 intf->out_prod = out_prod;
-}
-else
-gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n");
 
-if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) ==
- sizeof (intf->out) )
-{
-vpl011->uartfr |= TXFF;
-vpl011->uartris &= ~TXI;
+fifo_level = xencons_queued(out_prod, out_cons, sizeof(intf->out));
 
-/*
- * This bit is set only when FIFO becomes full. This ensures that
- * the SBSA UART driver can write the

[Xen-devel] [PATCH 26/27 v12] arm/xen: vpl011: Fix the slow early console SBSA UART output

2017-10-13 Thread Bhupinder Thakur
The early console output uses pl011_early_write() to write data. This
function waits for BUSY bit to get cleared before writing the next byte.

In the SBSA UART emulation logic, the BUSY bit was set as soon one
byte was written in the FIFO and it remained set until the FIFO was
emptied. This meant that the output was delayed as each character needed
the BUSY to get cleared.

Since the SBSA UART is getting emulated in Xen using ring buffers, it
ensures that once the data is enqueued in the FIFO, it will be received
by xenconsole so it is safe to set the BUSY bit only when FIFO becomes
full. This will ensure that pl011_early_write() is not delayed unduly
to write the data.

Signed-off-by: Bhupinder Thakur 
---
CC: Julien Grall 
CC: Andre Przywara 
CC: Stefano Stabellini 

 xen/arch/arm/vpl011.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
index f7ddccb..0b07436 100644
--- a/xen/arch/arm/vpl011.c
+++ b/xen/arch/arm/vpl011.c
@@ -159,9 +159,15 @@ static void vpl011_write_data(struct domain *d, uint8_t 
data)
 {
 vpl011->uartfr |= TXFF;
 vpl011->uartris &= ~TXI;
-}
 
-vpl011->uartfr |= BUSY;
+/*
+ * This bit is set only when FIFO becomes full. This ensures that
+ * the SBSA UART driver can write the early console data as fast as
+ * possible, without waiting for the BUSY bit to get cleared before
+ * writing each byte.
+ */
+vpl011->uartfr |= BUSY;
+}
 
 vpl011->uartfr &= ~TXFE;
 
@@ -371,11 +377,16 @@ static void vpl011_data_avail(struct domain *d)
 {
 vpl011->uartfr &= ~TXFF;
 vpl011->uartris |= TXI;
+
+/*
+ * Clear the BUSY bit as soon as space becomes available
+ * so that the SBSA UART driver can start writing more data
+ * without any further delay.
+ */
+vpl011->uartfr &= ~BUSY;
+
 if ( out_ring_qsize == 0 )
-{
-vpl011->uartfr &= ~BUSY;
 vpl011->uartfr |= TXFE;
-}
 }
 
 vpl011_update_interrupt_status(d);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] ARM32 - build-issues with xen/arm: vpl011: Add a new vuart node in the xenstore

2017-10-13 Thread Bhupinder Thakur
On 13 October 2017 at 00:34, Andrew Cooper  wrote:
> On 12/10/17 19:54, Bhupinder Thakur wrote:
>> On 5 October 2017 at 15:07, Wei Liu  wrote:
>>> On Wed, Oct 04, 2017 at 09:58:32PM -0400, Konrad Rzeszutek Wilk wrote:
>>>> I get this when compiling under ARM32 (Ubuntu 15.04,
>>>> gcc (Ubuntu/Linaro 4.9.2-10ubuntu13) 4.9.2):
>>>>
>>>> libxl_console.c: In function ‘libxl__device_vuart_add’:
>>>> libxl_console.c:379:5: error: format ‘%lu’ expects argument of type ‘long 
>>>> unsigned int’, but argument 3 has type ‘xen_pfn_t’ [-Werror=format=]
>>>>  flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
>>>>  ^
>>>> ;
>>> My Wheezy 32bit chroot didn't catch this, sigh.
>>>
>>> Does the following patch work?
>>>
>>> From ae531197382bf0bc003606a9712075bdd22cfc24 Mon Sep 17 00:00:00 2001
>>> From: Wei Liu 
>>> Date: Thu, 5 Oct 2017 10:35:28 +0100
>>> Subject: [PATCH] libxl: use correct type modifier for vuart_gfn
>>> MIME-Version: 1.0
>>> Content-Type: text/plain; charset=UTF-8
>>> Content-Transfer-Encoding: 8bit
>>>
>>> Fixes compilation error like:
>>>
>>> libxl_console.c: In function ‘libxl__device_vuart_add’:
>>> libxl_console.c:379:5: error: format ‘%lu’ expects argument of type ‘long 
>>> unsigned int’, but argument 3 has type ‘xen_pfn_t’ [-Werror=format=]
>>>   flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
>>>
>>> Reported-by: Konrad Rzeszutek Wilk 
>>> Signed-off-by: Wei Liu 
>>> ---
>>>  tools/libxl/libxl_console.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
>>> index 13ecf128e2..c05dc28b99 100644
>>> --- a/tools/libxl/libxl_console.c
>>> +++ b/tools/libxl/libxl_console.c
>>> @@ -376,7 +376,7 @@ int libxl__device_vuart_add(libxl__gc *gc, uint32_t 
>>> domid,
>>>  flexarray_append(ro_front, "port");
>>>  flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
>>>  flexarray_append(ro_front, "ring-ref");
>>> -flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
>>> +flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, 
>>> state->vuart_gfn));
>> Unfortunately, this is causing an issue as PRI_xen_pfn formats the
>> value as a hexadecimal value but xenconsole later reads it as a
>> decimal value and tries to map it, which fails and therefore vuart
>> console initialization fails.
>>
>> Earlier, I verified only 32-bit compilation but did not test the
>> change. It was a miss from my side. I have tested now with the format
>> string changed to PRIu64 and the vuart console is working fine.
>
> That however, would break x86.
>
> andrewcoop@andrewcoop:/local/xen.git/xen$ git grep 'define PRI_xen_pfn' -- :/
> include/public/arch-arm.h:276:#define PRI_xen_pfn PRIx64
> include/public/arch-x86/xen.h:77:#define PRI_xen_pfn "lx"
>
> The best way to fix this is to introduce a new define for both
> architectures which is PRIu64 and "lu" as appropriate.
>
> Suggestions:
>
> PRI_xen_pfn_dec
> PRIu_xen_pfn
>
> Neither are great, but the latter does follow the PRI nomenclature.
Thanks. I will introduce this new format specifier.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] ARM32 - build-issues with xen/arm: vpl011: Add a new vuart node in the xenstore

2017-10-12 Thread Bhupinder Thakur
On 5 October 2017 at 15:07, Wei Liu  wrote:
> On Wed, Oct 04, 2017 at 09:58:32PM -0400, Konrad Rzeszutek Wilk wrote:
>> I get this when compiling under ARM32 (Ubuntu 15.04,
>> gcc (Ubuntu/Linaro 4.9.2-10ubuntu13) 4.9.2):
>>
>> libxl_console.c: In function ‘libxl__device_vuart_add’:
>> libxl_console.c:379:5: error: format ‘%lu’ expects argument of type ‘long 
>> unsigned int’, but argument 3 has type ‘xen_pfn_t’ [-Werror=format=]
>>  flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
>>  ^
>> ;
>
> My Wheezy 32bit chroot didn't catch this, sigh.
>
> Does the following patch work?
>
> From ae531197382bf0bc003606a9712075bdd22cfc24 Mon Sep 17 00:00:00 2001
> From: Wei Liu 
> Date: Thu, 5 Oct 2017 10:35:28 +0100
> Subject: [PATCH] libxl: use correct type modifier for vuart_gfn
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> Fixes compilation error like:
>
> libxl_console.c: In function ‘libxl__device_vuart_add’:
> libxl_console.c:379:5: error: format ‘%lu’ expects argument of type ‘long 
> unsigned int’, but argument 3 has type ‘xen_pfn_t’ [-Werror=format=]
>   flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
>
> Reported-by: Konrad Rzeszutek Wilk 
> Signed-off-by: Wei Liu 
> ---
>  tools/libxl/libxl_console.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
> index 13ecf128e2..c05dc28b99 100644
> --- a/tools/libxl/libxl_console.c
> +++ b/tools/libxl/libxl_console.c
> @@ -376,7 +376,7 @@ int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
>  flexarray_append(ro_front, "port");
>  flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
>  flexarray_append(ro_front, "ring-ref");
> -flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
> +flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));

Unfortunately, this is causing an issue as PRI_xen_pfn formats the
value as a hexadecimal value but xenconsole later reads it as a
decimal value and tries to map it, which fails and therefore vuart
console initialization fails.

Earlier, I verified only 32-bit compilation but did not test the
change. It was a miss from my side. I have tested now with the format
string changed to PRIu64 and the vuart console is working fine.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 27/27 v11] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt

2017-10-12 Thread Bhupinder Thakur
On 9 October 2017 at 22:48, Andre Przywara  wrote:
> Hi,
>
> can you please re-break the commit message to fit into 72 characters?
> git show looks rather ugly as it is now.
ok.
>
> On 27/09/17 07:13, Bhupinder Thakur wrote:
>> This patch fixes the issue observed when pl011 patches were tested on
>> the junos hardware by Andre/Julien. It was observed that when large output is
>> generated such as on running 'find /', output was getting truncated 
>> intermittently
>> due to OUT ring buffer getting full.
>>
>> This issue was due to the fact that the SBSA UART driver expects that when
>> a TX interrupt is asserted then the FIFO queue should be atleast half empty 
>> and
>> that it can write N bytes in the FIFO, where N is half the FIFO queue size, 
>> without
>> the bytes getting dropped due to FIFO getting full.
>>
>> The SBSA UART emulation logic was asserting the TX interrupt as soon as
>> any space became available in the FIFO and the SBSA UART driver tried to 
>> write
>> more data (upto 16 bytes) in the FIFO expecting that there is enough space
>> available leading to dropped bytes.
>>
>> The SBSA spec [1] does not specify when the TX interrupt should be asserted
>> or de-asserted. Due to lack of clarity on the expected behavior, it is
>> assumed for now that TX interrupt should be asserted only when the FIFO goes
>> half empty.
>>
>> TBD: Once the SBSA spec is updated with the expected behavior, the 
>> implementation
>> will be modified to align with the spec requirement.
>>
>> [1] http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf
>>
>> Signed-off-by: Bhupinder Thakur 
>
> Only some minor things left below, but in general this looks much better
> to me now.
>
>> ---
>> CC: Julien Grall 
>> CC: Andre Przywara 
>> CC: Stefano Stabellini 
>>
>> Changes since v8:
>> - Used variables fifo_level/fifo_threshold for more clarity
>> - Added a new macro SBSA_UART_FIFO_SIZE instead of using a magic number
>> - Renamed ring_qsize variables to fifo_level for consistency
>>
>>  xen/arch/arm/vpl011.c| 87 
>> ++--
>>  xen/include/asm-arm/vpl011.h |  2 +
>>  2 files changed, 61 insertions(+), 28 deletions(-)
>>
>> diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
>> index 36794d8..1f97261 100644
>> --- a/xen/arch/arm/vpl011.c
>> +++ b/xen/arch/arm/vpl011.c
>> @@ -91,20 +91,24 @@ static uint8_t vpl011_read_data(struct domain *d)
>>   */
>>  if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) > 0 )
>>  {
>> +unsigned int fifo_level;
>> +
>>  data = intf->in[xencons_mask(in_cons, sizeof(intf->in))];
>>  in_cons += 1;
>>  smp_mb();
>>  intf->in_cons = in_cons;
>> +
>> +fifo_level = xencons_queued(in_prod, in_cons, sizeof(intf->in));
>> +
>> +if ( fifo_level == 0 )
>> +{
>> +vpl011->uartfr |= RXFE;
>> +vpl011->uartris &= ~RXI;
>> +}
>>  }
>>  else
>>  gprintk(XENLOG_ERR, "vpl011: Unexpected IN ring buffer empty\n");
>>
>> -if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) == 0 )
>> -{
>> -vpl011->uartfr |= RXFE;
>> -vpl011->uartris &= ~RXI;
>> -}
>> -
>>  vpl011->uartfr &= ~RXFF;
>>
>>  vpl011_update_interrupt_status(d);
>> @@ -144,28 +148,41 @@ static void vpl011_write_data(struct domain *d, 
>> uint8_t data)
>>  if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) !=
>>   sizeof (intf->out) )
>>  {
>> +unsigned int fifo_level, fifo_threshold;
>> +
>>  intf->out[xencons_mask(out_prod, sizeof(intf->out))] = data;
>>  out_prod += 1;
>>  smp_wmb();
>>  intf->out_prod = out_prod;
>> -}
>> -else
>> -gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n");
>>
>> -if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) ==
>> - sizeof (intf->out) )
>> -{
>> -vpl011->uartfr |= TXFF;
>> -vpl011->uartris &= ~TXI;
>> +fifo_level = xencons_queued(out_prod, out_cons, sizeof(intf->out));
>> +
>> +if ( fifo_level == sizeof (intf->out) )
>> +{
>> +vpl011->uartf

Re: [Xen-devel] [PATCH 27/27 v10] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt

2017-10-11 Thread Bhupinder Thakur
On 11 October 2017 at 15:38, Dave Martin  wrote:
> On Wed, Oct 11, 2017 at 01:28:44PM +0530, Bhupinder Thakur wrote:
>> Hi Dave,
>>
>> On 26 September 2017 at 20:08, Dave Martin  wrote:
>> > On Fri, Sep 22, 2017 at 01:53:26PM +0530, Bhupinder Thakur wrote:
>> >> This patch fixes the issue observed when pl011 patches were tested on
>> >> the junos hardware by Andre/Julien. It was observed that when large 
>> >> output is
>> >> generated such as on running 'find /', output was getting truncated 
>> >> intermittently
>> >> due to OUT ring buffer getting full.
>> >>
>> >> This issue was due to the fact that the SBSA UART driver expects that when
>> >> a TX interrupt is asserted then the FIFO queue should be atleast half 
>> >> empty and
>> >> that it can write N bytes in the FIFO, where N is half the FIFO queue 
>> >> size, without
>> >> the bytes getting dropped due to FIFO getting full.
>> >>
>> >> The SBSA UART emulation logic was asserting the TX interrupt as soon as
>> >> any space became available in the FIFO and the SBSA UART driver tried to 
>> >> write
>> >> more data (upto 16 bytes) in the FIFO expecting that there is enough space
>> >> available leading to dropped bytes.
>> >>
>> >> The SBSA spec [1] does not specify when the TX interrupt should be 
>> >> asserted
>> >> or de-asserted. Due to lack of clarity on the expected behavior, it is
>> >> assumed for now that TX interrupt should be asserted only when the FIFO 
>> >> goes
>> >> half empty.
>> >>
>> >> TBD: Once the SBSA spec is updated with the expected behavior, the 
>> >> implementation
>> >> will be modified to align with the spec requirement.
>> >>
>> >> [1] http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf
>> >>
>> >> Signed-off-by: Bhupinder Thakur 
>> >> ---
>> >> CC: Julien Grall 
>> >> CC: Andre Przywara 
>> >> CC: Stefano Stabellini 
>> >
>> > (Taking a quick look at this because I remember fighthing with FIFO
>> > behaviour issues when hacking the Linux driver -- but beware, I'm not a
>> > Xen guy...)
>> >
>> >
>> > Should this patch be flattened into the patches is fixes?  Keeping
>> > known-wrong code in the series does not help reviewers (but maybe it's
>> > the Xen way).
>> >
>> >> Changes since v8:
>> >> - Used variables fifo_level/fifo_threshold for more clarity
>> >> - Added a new macro SBSA_UART_FIFO_SIZE instead of using a magic number
>> >
>> > What's sizeof(intf->in), sizeof(intf->out)?
>> >
>> > For correct operation, you assume that the total ring buffer size is >=
>> > SBSA_UART_FIFO_SIZE, but nothing enforces this.  If the xencons ring
>> > buffer size is set elsewhere and can't be chosen by a driver, you may at
>> > least add a build-time assert to check that it's big enough.
>> >
>> I will add an assert to check this condition.
>>
>> > [...]
>> >
>> >> @@ -144,28 +148,41 @@ static void vpl011_write_data(struct domain *d, 
>> >> uint8_t data)
>> >
>> > [...]
>> >
>> >> + * Clear the TXI bit if the fifo level exceeds fifo_size/2 mark 
>> >> which
>> >> + * is the trigger level for asserting/de-assterting the TX 
>> >> interrupt.
>> >>   */
>> >> -vpl011->uartfr |= BUSY;
>> >> +fifo_threshold = sizeof (intf->out) - SBSA_UART_FIFO_SIZE/2;
>> >> +
>> >> +if ( fifo_level <= fifo_threshold )
>> >> +vpl011->uartris |= TXI;
>> >> +else
>> >> +vpl011->uartris &= ~TXI;
>> >>  }
>> >> +else
>> >> +gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n");
>> >>
>> >>  vpl011->uartfr &= ~TXFE;
>> >>
>> >
>> > [...]
>> >
>> >> @@ -353,37 +370,51 @@ static void vpl011_data_avail(struct domain *d)
>> >>
>> >>  smp_rmb();
>> >>
>> >> -in_ring_qsize = xencons_queued(in_prod,
>> >> +in_fifo_level = xencons_queued(in_prod,
>> >>   

Re: [Xen-devel] [PATCH 27/27 v10] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt

2017-10-11 Thread Bhupinder Thakur
Hi Dave,

On 26 September 2017 at 20:08, Dave Martin  wrote:
> On Fri, Sep 22, 2017 at 01:53:26PM +0530, Bhupinder Thakur wrote:
>> This patch fixes the issue observed when pl011 patches were tested on
>> the junos hardware by Andre/Julien. It was observed that when large output is
>> generated such as on running 'find /', output was getting truncated 
>> intermittently
>> due to OUT ring buffer getting full.
>>
>> This issue was due to the fact that the SBSA UART driver expects that when
>> a TX interrupt is asserted then the FIFO queue should be atleast half empty 
>> and
>> that it can write N bytes in the FIFO, where N is half the FIFO queue size, 
>> without
>> the bytes getting dropped due to FIFO getting full.
>>
>> The SBSA UART emulation logic was asserting the TX interrupt as soon as
>> any space became available in the FIFO and the SBSA UART driver tried to 
>> write
>> more data (upto 16 bytes) in the FIFO expecting that there is enough space
>> available leading to dropped bytes.
>>
>> The SBSA spec [1] does not specify when the TX interrupt should be asserted
>> or de-asserted. Due to lack of clarity on the expected behavior, it is
>> assumed for now that TX interrupt should be asserted only when the FIFO goes
>> half empty.
>>
>> TBD: Once the SBSA spec is updated with the expected behavior, the 
>> implementation
>> will be modified to align with the spec requirement.
>>
>> [1] http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf
>>
>> Signed-off-by: Bhupinder Thakur 
>> ---
>> CC: Julien Grall 
>> CC: Andre Przywara 
>> CC: Stefano Stabellini 
>
> (Taking a quick look at this because I remember fighthing with FIFO
> behaviour issues when hacking the Linux driver -- but beware, I'm not a
> Xen guy...)
>
>
> Should this patch be flattened into the patches is fixes?  Keeping
> known-wrong code in the series does not help reviewers (but maybe it's
> the Xen way).
>
>> Changes since v8:
>> - Used variables fifo_level/fifo_threshold for more clarity
>> - Added a new macro SBSA_UART_FIFO_SIZE instead of using a magic number
>
> What's sizeof(intf->in), sizeof(intf->out)?
>
> For correct operation, you assume that the total ring buffer size is >=
> SBSA_UART_FIFO_SIZE, but nothing enforces this.  If the xencons ring
> buffer size is set elsewhere and can't be chosen by a driver, you may at
> least add a build-time assert to check that it's big enough.
>
I will add an assert to check this condition.

> [...]
>
>> @@ -144,28 +148,41 @@ static void vpl011_write_data(struct domain *d, 
>> uint8_t data)
>
> [...]
>
>> + * Clear the TXI bit if the fifo level exceeds fifo_size/2 mark 
>> which
>> + * is the trigger level for asserting/de-assterting the TX 
>> interrupt.
>>   */
>> -vpl011->uartfr |= BUSY;
>> +fifo_threshold = sizeof (intf->out) - SBSA_UART_FIFO_SIZE/2;
>> +
>> +if ( fifo_level <= fifo_threshold )
>> +vpl011->uartris |= TXI;
>> +else
>> +vpl011->uartris &= ~TXI;
>>  }
>> +else
>> +gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n");
>>
>>  vpl011->uartfr &= ~TXFE;
>>
>
> [...]
>
>> @@ -353,37 +370,51 @@ static void vpl011_data_avail(struct domain *d)
>>
>>  smp_rmb();
>>
>> -in_ring_qsize = xencons_queued(in_prod,
>> +in_fifo_level = xencons_queued(in_prod,
>> in_cons,
>> sizeof(intf->in));
>>
>> -out_ring_qsize = xencons_queued(out_prod,
>> +out_fifo_level = xencons_queued(out_prod,
>>  out_cons,
>>  sizeof(intf->out));
>>
>>  /* Update the uart rx state if the buffer is not empty. */
>> -if ( in_ring_qsize != 0 )
>> +if ( in_fifo_level != 0 )
>>  {
>>  vpl011->uartfr &= ~RXFE;
>> -if ( in_ring_qsize == sizeof(intf->in) )
>> +
>> +if ( in_fifo_level == sizeof(intf->in) )
>>  vpl011->uartfr |= RXFF;
>> +
>>  vpl011->uartris |= RXI;
>>  }
>>
>>  /* Update the uart tx state if the buffer is not full. */
>> -if ( out_ring_qsize != sizeof(intf->out) )
>> +if ( out_fifo_level != sizeof(intf->out) )
>>  {
>&g

Re: [Xen-devel] [PATCH v2] xen, tools: console.h shouldn't require string.h by default

2017-10-08 Thread Bhupinder Thakur
Hi,

On 6 October 2017 at 23:11, Wei Liu  wrote:
> Unilaterally making string.h a prerequisite for console.h is going to
> break build for a lot of consumers of console.h.
>
> Define a macro for the new flex ring. Consumers which want to use it
> should define the macro.
>
> Partially revert af8d9356417cb617b635c5ace782388ebfe86e3a.
>
> Signed-off-by: Wei Liu 
> ---
> Cc: Julien Grall 
> Cc: Bhupinder Thakur 
> Cc: Andrew Cooper 
> Cc: George Dunlap 
> Cc: Ian Jackson 
> Cc: Jan Beulich 
> Cc: Konrad Rzeszutek Wilk 
> Cc: Stefano Stabellini 
> Cc: Tim Deegan 
> Cc: Wei Liu 
> ---
>  tools/console/daemon/io.c   | 2 +-
>  xen/arch/arm/vpl011.c   | 2 ++
>  xen/include/Makefile| 1 -
>  xen/include/public/io/console.h | 5 ++---
>  4 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
> index afe162e9c2..e22009aa39 100644
> --- a/tools/console/daemon/io.c
> +++ b/tools/console/daemon/io.c
> @@ -21,7 +21,6 @@
>
>  #include "utils.h"
>  #include "io.h"
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -30,6 +29,7 @@
>
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
> index 56d9cbe09e..f7ddccb42a 100644
> --- a/xen/arch/arm/vpl011.c
> +++ b/xen/arch/arm/vpl011.c
> @@ -16,6 +16,8 @@
>   * this program; If not, see <http://www.gnu.org/licenses/>.
>   */
>
> +#define XEN_WANT_FLEX_CONSOLE_RING 1
> +
>  #include 
>  #include 
>  #include 
> diff --git a/xen/include/Makefile b/xen/include/Makefile
> index c90fdeee75..1299b1962f 100644
> --- a/xen/include/Makefile
> +++ b/xen/include/Makefile
> @@ -98,7 +98,6 @@ PUBLIC_C99_HEADERS := public/io/9pfs.h public/io/pvcalls.h
>  PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/% 
> public/%hvm/save.h $(PUBLIC_C99_HEADERS), $(PUBLIC_HEADERS))
>
>  public/io/9pfs.h-prereq := string
> -public/io/console.h-prereq := string
>  public/io/pvcalls.h-prereq := string
>
>  headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile
> diff --git a/xen/include/public/io/console.h b/xen/include/public/io/console.h
> index 0f0711fbdb..4c32f51903 100644
> --- a/xen/include/public/io/console.h
> +++ b/xen/include/public/io/console.h
> @@ -27,8 +27,6 @@
>  #ifndef __XEN_PUBLIC_IO_CONSOLE_H__
>  #define __XEN_PUBLIC_IO_CONSOLE_H__
>
> -#include "ring.h"
> -
>  typedef uint32_t XENCONS_RING_IDX;
>
>  #define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring)-1))
> @@ -40,7 +38,8 @@ struct xencons_interface {
>  XENCONS_RING_IDX out_cons, out_prod;
>  };
>
> -#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
> +#if defined(XEN_WANT_FLEX_CONSOLE_RING)
> +#include "ring.h"
>  DEFINE_XEN_FLEX_RING(xencons);
>  #endif

I verified that with this patch the compilation goes fine.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] ARM32 - build-issues with xen/arm: vpl011: Add a new vuart node in the xenstore

2017-10-05 Thread Bhupinder Thakur
Hi Wei,

On 5 October 2017 at 15:07, Wei Liu  wrote:
> On Wed, Oct 04, 2017 at 09:58:32PM -0400, Konrad Rzeszutek Wilk wrote:
>> I get this when compiling under ARM32 (Ubuntu 15.04,
>> gcc (Ubuntu/Linaro 4.9.2-10ubuntu13) 4.9.2):
>>
>> libxl_console.c: In function ‘libxl__device_vuart_add’:
>> libxl_console.c:379:5: error: format ‘%lu’ expects argument of type ‘long 
>> unsigned int’, but argument 3 has type ‘xen_pfn_t’ [-Werror=format=]
>>  flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
>>  ^
>> ;
>
> My Wheezy 32bit chroot didn't catch this, sigh.
>
> Does the following patch work?
>

I verified that with this fix, the arm32 toolstack compiles fine.

> From ae531197382bf0bc003606a9712075bdd22cfc24 Mon Sep 17 00:00:00 2001
> From: Wei Liu 
> Date: Thu, 5 Oct 2017 10:35:28 +0100
> Subject: [PATCH] libxl: use correct type modifier for vuart_gfn
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> Fixes compilation error like:
>
> libxl_console.c: In function ‘libxl__device_vuart_add’:
> libxl_console.c:379:5: error: format ‘%lu’ expects argument of type ‘long 
> unsigned int’, but argument 3 has type ‘xen_pfn_t’ [-Werror=format=]
>   flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
>
> Reported-by: Konrad Rzeszutek Wilk 
> Signed-off-by: Wei Liu 
> ---
>  tools/libxl/libxl_console.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
> index 13ecf128e2..c05dc28b99 100644
> --- a/tools/libxl/libxl_console.c
> +++ b/tools/libxl/libxl_console.c
> @@ -376,7 +376,7 @@ int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
>  flexarray_append(ro_front, "port");
>  flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
>  flexarray_append(ro_front, "ring-ref");
> -flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
> +flexarray_append(ro_front, GCSPRINTF("%"PRI_xen_pfn, state->vuart_gfn));
>  flexarray_append(ro_front, "limit");
>  flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT));
>  flexarray_append(ro_front, "type");
> --
> 2.11.0
>

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [xen-unstable-smoke test] 114005: regressions - trouble: blocked/fail

2017-10-04 Thread Bhupinder Thakur
Hi,

On 4 October 2017 at 17:56, Julien Grall  wrote:
>
>
> On 04/10/17 12:47, osstest service owner wrote:
>> flight 114005 xen-unstable-smoke real [real]
>> http://logs.test-lab.xenproject.org/osstest/logs/114005/
>>
>> Regressions :-(
>>
>> Tests which did not succeed and are blocking,
>> including tests which could not be run:
>>   build-amd64   6 xen-buildfail REGR. vs. 
>> 113972
>
> I think this was the error discussed on IRC:
>
> /home/osstest/build.114005.build-amd64/xen/stubdom/cross-root-x86_64/x86_64-xen-elf/include/string.h:24:8:
>  error: conflicting types for 'memcpy'
>  _PTR   _EXFUN(memcpy,(_PTR, const _PTR, size_t));
> ^
> In file included from 
> /home/osstest/build.114005.build-amd64/xen/extras/mini-os-remote/include/console.h:44:0,
>  from main.c:11:
> /home/osstest/build.114005.build-amd64/xen/stubdom/include/xen/io/console.h:44:485:
>  note: previous implicit declaration of 'memcpy' was here
>  DEFINE_XEN_FLEX_RING(xencons);
>
> I am not sure how to fix that one.
>
It seems that grub/main.c does not include string.h before including
console.h which could be causing this implicit declaration. Ideally,
ring.h should include string.h explicitly as it depends on string.h.

>
>>   build-armhf   6 xen-buildfail REGR. vs. 
>> 113972
>
> daemon/io.c: In function 'console_evtchn_unmask':
> daemon/io.c:1050:18: error: cast from pointer to integer of different size 
> [-Werror=pointer-to-int-cast]
>   long long now = (long long)data;
>   ^
> daemon/io.c: In function 'handle_io':
> daemon/io.c:1346:53: error: cast to pointer from integer of different size 
> [-Werror=int-to-pointer-cast]
> console_iter_void_arg2(d, console_evtchn_unmask, (void *)now);
>
>  ^
>
> It seems that 32-bit build has been built test it. I will send a patch for it.
>
Instead of using a generic void *, I can use the long long type
itself. I think there was a review comment regarding that.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v3] xen/arm: Fix the issue in cmp_mmio_handler used in find_mmio_handler

2017-09-28 Thread Bhupinder Thakur
This patch fixes the wrong range check done in cmp_mmio_handler().

This function returns -1 , 0 or 1  based on whether the key value
is below the range, in the range or above the range where the range is
(start, start+size). However, it should check against (start, start+size-1)
because start+size falls outside the range.

This resulted in returning a wrong mmio_handler for a given mmio address which
happened to be start+size.

This bug was introduced when the mmio region search switched from
linear search to binary search in the following commit:

8047e09 "xen/arm: io: Use binary search for mmio handler lookup".

Signed-off-by: Bhupinder Thakur 
---
CC: Stefano Stabellini 
CC: Julien Grall 

This patch may have to be back ported to 4.8 also.

 xen/arch/arm/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c
index e216128..c748d8f 100644
--- a/xen/arch/arm/io.c
+++ b/xen/arch/arm/io.c
@@ -79,7 +79,7 @@ static int cmp_mmio_handler(const void *key, const void *elem)
 if ( handler0->addr < handler1->addr )
 return -1;
 
-if ( handler0->addr > (handler1->addr + handler1->size) )
+if ( handler0->addr >= (handler1->addr + handler1->size) )
 return 1;
 
 return 0;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v2] xen/arm: Fix the issue in cmp_mmio_handler used in find_mmio_handler

2017-09-28 Thread Bhupinder Thakur
This function returns true/false based on whether the key value
is in the range (start, start+size). However, it should check against
(start, start+size-1) because start+size falls outside the range.

This resulted in returning a wrong mmio_handler for a given mmio address which
happened to be start+size.

This bug was introduced when the mmio region search was switched from
linear search to binary search in the following commit:

8047e09 "xen/arm: io: Use binary search for mmio handler lookup".

This change may have to be back-ported to 4.8 also.

Signed-off-by: Bhupinder Thakur 
---
CC: Stefano Stabellini 
CC: Julien Grall 

 xen/arch/arm/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c
index e216128..c748d8f 100644
--- a/xen/arch/arm/io.c
+++ b/xen/arch/arm/io.c
@@ -79,7 +79,7 @@ static int cmp_mmio_handler(const void *key, const void *elem)
 if ( handler0->addr < handler1->addr )
 return -1;
 
-if ( handler0->addr > (handler1->addr + handler1->size) )
+if ( handler0->addr >= (handler1->addr + handler1->size) )
 return 1;
 
 return 0;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 26/27 v11] xen/arm: vpl011: Fix the slow early console SBSA UART output

2017-09-26 Thread Bhupinder Thakur
The early console output uses pl011_early_write() to write data. This
function waits for BUSY bit to get cleared before writing the next byte.

In the SBSA UART emulation logic, the BUSY bit was set as soon one
byte was written in the FIFO and it remained set until the FIFO was
emptied. This meant that the output was delayed as each character needed
the BUSY to get cleared.

Since the SBSA UART is getting emulated in Xen using ring buffers, it
ensures that once the data is enqueued in the FIFO, it will be received
by xenconsole so it is safe to set the BUSY bit only when FIFO becomes
full. This will ensure that pl011_early_write() is not delayed unduly
to write the data.

Signed-off-by: Bhupinder Thakur 
---
CC: Julien Grall 
CC: Andre Przywara 
CC: Stefano Stabellini 

 xen/arch/arm/vpl011.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
index 56d9cbe..36794d8 100644
--- a/xen/arch/arm/vpl011.c
+++ b/xen/arch/arm/vpl011.c
@@ -157,9 +157,15 @@ static void vpl011_write_data(struct domain *d, uint8_t 
data)
 {
 vpl011->uartfr |= TXFF;
 vpl011->uartris &= ~TXI;
-}
 
-vpl011->uartfr |= BUSY;
+/*
+ * This bit is set only when FIFO becomes full. This ensures that
+ * the SBSA UART driver can write the early console data as fast as
+ * possible, without waiting for the BUSY bit to get cleared before
+ * writing each byte.
+ */
+vpl011->uartfr |= BUSY;
+}
 
 vpl011->uartfr &= ~TXFE;
 
@@ -369,11 +375,16 @@ static void vpl011_data_avail(struct domain *d)
 {
 vpl011->uartfr &= ~TXFF;
 vpl011->uartris |= TXI;
+
+/*
+ * Clear the BUSY bit as soon as space becomes available
+ * so that the SBSA UART driver can start writing more data
+ * without any further delay.
+ */
+vpl011->uartfr &= ~BUSY;
+
 if ( out_ring_qsize == 0 )
-{
-vpl011->uartfr &= ~BUSY;
 vpl011->uartfr |= TXFE;
-}
 }
 
 vpl011_update_interrupt_status(d);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 21/27 v11] xen/arm: vpl011: Add support for multiple consoles in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch adds the support for multiple consoles and introduces the
iterator functions to operate on multiple consoles.

The functions called by the iterators check that they are operating
on valid I/O parameters. This ensures that if a particular console is
not initialized then the functions will not do anything for that
console type.

This patch is in preparation to support a new vuart console.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this patch in multiple smaller patches.

Changes since v4:
- Changes to make event channel handling per console rather than per domain.

Changes since v3:
- The changes in xenconsole have been split into four patches. This is the 
third patch.

 tools/console/daemon/io.c | 160 --
 1 file changed, 126 insertions(+), 34 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 71465a0..a198dbb 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -90,12 +90,14 @@ struct buffer {
 };
 
 struct console {
+   char *ttyname;
int master_fd;
int master_pollfd_idx;
int slave_fd;
int log_fd;
struct buffer buffer;
char *xspath;
+   char *log_suffix;
int ring_ref;
xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
@@ -107,21 +109,109 @@ struct console {
struct domain *d;
 };
 
+struct console_type {
+   char *xsname;
+   char *ttyname;
+   char *log_suffix;
+};
+
+static struct console_type console_type[] = {
+   {
+   .xsname = "/console",
+   .ttyname = "tty",
+   .log_suffix = "",
+   },
+};
+
+#define NUM_CONSOLE_TYPE (sizeof(console_type)/sizeof(struct console_type))
+
 struct domain {
int domid;
bool is_dead;
unsigned last_seen;
struct domain *next;
-   struct console console;
+   struct console console[NUM_CONSOLE_TYPE];
 };
 
 static struct domain *dom_head;
 
+typedef void (*VOID_ITER_FUNC_ARG1)(struct console *);
+typedef int (*INT_ITER_FUNC_ARG1)(struct console *);
+typedef void (*VOID_ITER_FUNC_ARG2)(struct console *,  void *);
+typedef int (*INT_ITER_FUNC_ARG3)(struct console *,
+ struct domain *dom, void **);
+
 static inline bool console_enabled(struct console *con)
 {
return con->local_port != -1;
 }
 
+static inline void console_iter_void_arg1(struct domain *d,
+ VOID_ITER_FUNC_ARG1 iter_func)
+{
+   unsigned int i;
+   struct console *con = &d->console[0];
+
+   for (i = 0; i < NUM_CONSOLE_TYPE; i++, con++) {
+   iter_func(con);
+   }
+}
+
+static inline void console_iter_void_arg2(struct domain *d,
+ VOID_ITER_FUNC_ARG2 iter_func,
+ void *iter_data)
+{
+   unsigned int i;
+   struct console *con = &d->console[0];
+
+   for (i = 0; i < NUM_CONSOLE_TYPE; i++, con++) {
+   iter_func(con, iter_data);
+   }
+}
+
+static inline int console_iter_int_arg1(struct domain *d,
+   INT_ITER_FUNC_ARG1 iter_func)
+{
+   unsigned int i;
+   int ret;
+   struct console *con = &d->console[0];
+
+   for (i = 0; i < NUM_CONSOLE_TYPE; i++, con++) {
+   /*
+* Zero return values means success.
+*
+* Non-zero return value indicates an error in which
+* case terminate the loop.
+*/
+   ret = iter_func(con);
+   if (ret)
+   break;
+   }
+   return ret;
+}
+
+static inline int console_iter_int_arg3(struct domain *d,
+   INT_ITER_FUNC_ARG3 iter_func,
+   void **iter_data)
+{
+   unsigned int i;
+   int ret;
+   struct console *con = &d->console[0];
+
+   for (i = 0; i < NUM_CONSOLE_TYPE; i++, con++) {
+   /*
+* Zero return values means success.
+*
+* Non-zero return value indicates an error in which
+* case terminate the loop.
+*/
+   ret = iter_func(con, d, iter_data);
+   if (ret)
+   break;
+   }
+   return ret;
+}
+
 static int write_all(int fd, const char* buf, size_t len)
 {
while (len) {
@@ -336,7 +426,9 @@ static int create_console_log(struct console *con)
return -1;
}
 
-   snprintf(logfile, PATH_MAX-1, "%s/guest-%s.log", log_dir, data);
+   snprintf(logfile, PATH_MAX-1, "%s/guest-%s%s.log",
+log_dir, data, con->log

[Xen-devel] [PATCH 24/27 v11] xen/arm: vpl011: Add a pl011 uart DT node in the guest device tree

2017-09-26 Thread Bhupinder Thakur
The SBSA UART node format is as specified in
Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt and given below:

ARM SBSA defined generic UART
--
This UART uses a subset of the PL011 registers and consequently lives
in the PL011 driver. It's baudrate and other communication parameters
cannot be adjusted at runtime, so it lacks a clock specifier here.

Required properties:
- compatible: must be "arm,sbsa-uart"
- reg: exactly one register range
- interrupts: exactly one interrupt specifier
- current-speed: the (fixed) baud rate set by the firmware

Currently the baud rate of 115200 has been selected as a default value,
which is one of the valid baud rate settings. Higher baud rate was
selected since an emulated pl011 can support any valid baud rate without
any limitation of the hardware.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v7:
- Added a TODO to avoid conflict between vpl011 irq and user specified irqs.
- Used a new bool vuart_enabled to explicitly set whether pl011 UART is 
enabled/disabled.

Changes since v6:
- Added a comment explaining why user specified IRQ should not conflict with 
vpl011
  SPI.
- Checking the vuart type explicitly against vpl011 enum type.
- Removed uart-compat string and using "arm,sbsa-uart" string directly.
- I have retained the reviewed-by/acked-by tags as these are minor changes.

 tools/libxl/libxl_arm.c | 62 +
 1 file changed, 62 insertions(+)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 2e9f780..bfb7d08 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -43,11 +43,38 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
 {
 uint32_t nr_spis = 0;
 unsigned int i;
+uint32_t vuart_irq;
+bool vuart_enabled = false;
+
+/*
+ * If pl011 vuart is enabled then increment the nr_spis to allow allocation
+ * of SPI VIRQ for pl011.
+ */
+if (d_config->b_info.arch_arm.vuart == LIBXL_VUART_TYPE_SBSA_UART) {
+nr_spis += (GUEST_VPL011_SPI - 32) + 1;
+vuart_irq = GUEST_VPL011_SPI;
+vuart_enabled = true;
+}
 
 for (i = 0; i < d_config->b_info.num_irqs; i++) {
 uint32_t irq = d_config->b_info.irqs[i];
 uint32_t spi;
 
+/*
+ * This check ensures the if user has requested pass-through of a 
certain irq
+ * which conflicts with vpl011 irq then it flags an error to indicate 
to the
+ * user that the specific HW irq cannot be used as it is dedicated for 
vpl011.
+ * 
+ * TODO:
+ * The vpl011 irq should be assigned such that it never conflicts with 
user
+ * specified irqs thereby preventing its pass-through. This TODO is for
+ * implementing that logic in future.
+ */
+if (vuart_enabled && irq == vuart_irq) {
+LOG(ERROR, "Physical IRQ %u conflicting with pl011 SPI\n", irq);
+return ERROR_FAIL;
+}
+
 if (irq < 32)
 continue;
 
@@ -590,6 +617,38 @@ static int make_hypervisor_node(libxl__gc *gc, void *fdt,
 return 0;
 }
 
+static int make_vpl011_uart_node(libxl__gc *gc, void *fdt,
+ const struct arch_info *ainfo,
+ struct xc_dom_image *dom)
+{
+int res;
+gic_interrupt intr;
+
+res = fdt_begin_node(fdt, "sbsa-pl011");
+if (res) return res;
+
+res = fdt_property_compat(gc, fdt, 1, "arm,sbsa-uart");
+if (res) return res;
+
+res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+1,
+GUEST_PL011_BASE, GUEST_PL011_SIZE);
+if (res) return res;
+
+set_interrupt(intr, GUEST_VPL011_SPI, 0xf, DT_IRQ_TYPE_LEVEL_HIGH);
+
+res = fdt_property_interrupts(gc, fdt, &intr, 1);
+if (res) return res;
+
+/* Use a default baud rate of 115200. */
+fdt_property_u32(fdt, "current-speed", 115200);
+
+res = fdt_end_node(fdt);
+if (res) return res;
+
+return 0;
+}
+
 static const struct arch_info *get_arch_info(libxl__gc *gc,
  const struct xc_dom_image *dom)
 {
@@ -889,6 +948,9 @@ next_resize:
 FDT( make_timer_node(gc, fdt, ainfo, xc_config->clock_frequency) );
 FDT( make_hypervisor_node(gc, fdt, vers) );
 
+if (info->arch_arm.vuart == LIBXL_VUART_TYPE_SBSA_UART)
+FDT( make_vpl011_uart_node(gc, fdt, ainfo, dom) );
+
 if (pfdt)
 FDT( copy_partial_fdt(gc, fdt, pfdt) );
 
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 11/27 v11] xen/arm: vpl011: Add a new console_init function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a new console_init function. This function
initializes the console structure.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 65 ---
 1 file changed, 39 insertions(+), 26 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index a2a3496..1da08d7 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -655,20 +655,51 @@ static bool watch_domain(struct domain *dom, bool watch)
return success;
 }
 
-
-static struct domain *create_domain(int domid)
+static int console_init(struct console *con, struct domain *dom)
 {
-   struct domain *dom;
char *s;
+   int err = -1;
struct timespec ts;
-   struct console *con;
 
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
dolog(LOG_ERR, "Cannot get time of day %s:%s:L%d",
  __FILE__, __FUNCTION__, __LINE__);
-   return NULL;
+   return err;
}
 
+   con->master_fd = -1;
+   con->master_pollfd_idx = -1;
+   con->slave_fd = -1;
+   con->log_fd = -1;
+   con->ring_ref = -1;
+   con->local_port = -1;
+   con->remote_port = -1;
+   con->xce_pollfd_idx = -1;
+   con->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 
100) + RATE_LIMIT_PERIOD;
+   con->d = dom;
+   con->xspath = xs_get_domain_path(xs, dom->domid);
+   s = realloc(con->xspath, strlen(con->xspath) +
+   strlen("/console") + 1);
+   if (s) {
+   con->xspath = s;
+   strcat(con->xspath, "/console");
+   err = 0;
+   }
+
+   return err;
+}
+
+static void console_free(struct console *con)
+{
+   if (con->xspath)
+   free(con->xspath);
+}
+
+static struct domain *create_domain(int domid)
+{
+   struct domain *dom;
+   struct console *con;
+
dom = calloc(1, sizeof *dom);
if (dom == NULL) {
dolog(LOG_ERR, "Out of memory %s:%s():L%d",
@@ -677,28 +708,10 @@ static struct domain *create_domain(int domid)
}
 
dom->domid = domid;
-
con = &dom->console;
-   con->xspath = xs_get_domain_path(xs, dom->domid);
-   s = realloc(con->xspath, strlen(con->xspath) +
-   strlen("/console") + 1);
-   if (s == NULL)
-   goto out;
-   con->xspath = s;
-   strcat(con->xspath, "/console");
-
-   con->master_fd = -1;
-   con->master_pollfd_idx = -1;
-   con->slave_fd = -1;
-   con->log_fd = -1;
-   con->xce_pollfd_idx = -1;
-   con->d = dom;
-
-   con->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 
100) + RATE_LIMIT_PERIOD;
 
-   con->ring_ref = -1;
-   con->local_port = -1;
-   con->remote_port = -1;
+   if (console_init(con, dom))
+   goto out;
 
if (!watch_domain(dom, true))
goto out;
@@ -710,7 +723,7 @@ static struct domain *create_domain(int domid)
 
return dom;
  out:
-   free(con->xspath);
+   console_free(con);
free(dom);
return NULL;
 }
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 25/27 v11] xen/arm: vpl011: Update documentation for vuart console support

2017-09-26 Thread Bhupinder Thakur
1. Update documentation for a new vuart option added.
2. Update documentation about SPI irq reserved for vuart.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Andrew Cooper 
CC: George Dunlap 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Julien Grall 

Changes since v6:
- Added a new section for vuart usage.
- I have retained the reviewed-by/acked-by tags as this is a limited change. 
Kindly
  review.

Changes since v4:
- Minor change to rename "pl011" to "sbsa_uart". Since it is a minor change I 
have
  retained the reviewed-by and acked-by tags.

 docs/man/xl.cfg.pod.5.in | 12 
 docs/misc/console.txt| 44 +---
 2 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in
index 247ae99..f1d2a7a 100644
--- a/docs/man/xl.cfg.pod.5.in
+++ b/docs/man/xl.cfg.pod.5.in
@@ -1105,6 +1105,9 @@ Allow a guest to access specific physical IRQs.
 It is recommended to only use this option for trusted VMs under
 administrator's control.
 
+If vuart console is enabled then irq 32 is reserved for it. See
+L to know how to enable vuart console.
+
 =item B
 
 Limit the guest to using at most N event channels (PV interrupts).
@@ -2220,6 +2223,15 @@ the domain was created.
 This requires hardware compatibility with the requested version, either
 natively or via hardware backwards compatibility support.
 
+=item B
+
+To enable vuart console, user must specify the following option in the
+VM config file:
+
+vuart = "sbsa_uart"
+
+Currently, only the "sbsa_uart" model is supported for ARM.
+
 =back
 
 =head3 x86
diff --git a/docs/misc/console.txt b/docs/misc/console.txt
index 16da805..4e180f8 100644
--- a/docs/misc/console.txt
+++ b/docs/misc/console.txt
@@ -19,7 +19,20 @@ The first PV console path in xenstore remains:
 
 /local/domain/$DOMID/console
 
-the other PV consoles follow the conventional xenstore device path and
+The virtual UART console path in xenstore is defined as:
+
+/local/domain/$DOMID/vuart/0
+
+The vuart console provides access to a virtual SBSA UART on ARM systems.
+To enable vuart the following line has to be added to the guest configuration
+file:
+
+vuart = "sbsa_uart"
+
+In Linux you can select the virtual SBSA UART by using the "ttyAMA0"
+console instead of "hvc0".
+
+The other PV consoles follow the conventional xenstore device path and
 live in:
 
 /local/domain/$DOMID/device/console/$DEVID.
@@ -61,6 +74,14 @@ output = pty
 The backend will write the pty device name to the "tty" node in the
 console frontend.
 
+For the PV console the tty node is added at
+
+/local/domain/$DOMID/console/tty
+
+For the virtual UART console the tty node is added at
+
+/local/domain/$DOMID/vuart/0/tty
+
 If the toolstack wants a listening Unix domain socket to be created at path
 , a connection accepted and data proxied to the console, it will write:
 
@@ -79,8 +100,8 @@ For example:
 ioemu
 
 The supported values are only xenconsoled or ioemu; xenconsoled has
-several limitations: it can only be used for the first PV console and it
-can only connect to a pty.
+several limitations: it can only be used for the first PV or virtual UART
+console and it can only connect to a pty.
 
 Emulated serials are provided by qemu-dm only to hvm guests; the number
 of emulated serials depends on how many "-serial" command line options
@@ -90,14 +111,15 @@ xenstore in the following path:
 
 /local/domain/$DOMID/serial/$SERIAL_NUM/tty
 
-xenconsole is the tool to connect to a PV console or an emulated serial
-that has a pty as output. Xenconsole takes a domid as parameter plus an
-optional console type (pv for PV consoles or serial for emulated
-serials) and console number. Depending on the type and console
-number, xenconsole will look for the tty node in different xenstore
-paths, as described above.  If the user doesn't specify the console type
-xenconsole will try to guess: if the guest is a pv guest it defaults to
-PV console, if the guest is an hvm guest it defaults to emulated serial.
+xenconsole is the tool to connect to a PV or virtual UART console or an
+emulated serial that has a pty as output. Xenconsole takes a domid as
+parameter plus an optional console type (pv for PV consoles, vuart for
+virtual UART or serial for emulated serials) and console number.
+Depending on the type and console number, xenconsole will look for the tty
+node in different xenstore paths, as described above.  If the user doesn't
+specify the console type xenconsole will try to guess: if the guest is a pv
+guest it defaults to PV console, if the guest is an hvm guest it defaults to
+emulated serial.
 
 By default xl creates a pv console for hvm guests, plus an emulated
 serial if the user specified 'serial = "

[Xen-devel] [PATCH 23/27 v11] xen/arm: vpl011: Add a new vuart console type to xenconsole client

2017-09-26 Thread Bhupinder Thakur
Add a new console type VUART to connect to guest's emualated vuart
console.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v4:
- Removed the vuart compile time flag so that vuart code is compiled always.

Changes since v3:
- The vuart console support is under CONFIG_VUART_CONSOLE option.
- Since there is a change from last review, I have not included
  reviewed-by tag from Stefano and acked-by tag from Wei.

 tools/console/client/main.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/console/client/main.c b/tools/console/client/main.c
index c340cb7..f92ad3d 100644
--- a/tools/console/client/main.c
+++ b/tools/console/client/main.c
@@ -76,7 +76,7 @@ static void usage(const char *program) {
   "\n"
   "  -h, --help   display this help and exit\n"
   "  -n, --num N  use console number N\n"
-  "  --type TYPE  console type. must be 'pv' or 'serial'\n"
+  "  --type TYPE  console type. must be 'pv', 'serial' or 
'vuart'\n"
   "  --start-notify-fd N file descriptor used to notify parent\n"
   , program);
 }
@@ -264,6 +264,7 @@ typedef enum {
CONSOLE_INVAL,
CONSOLE_PV,
CONSOLE_SERIAL,
+   CONSOLE_VUART,
 } console_type;
 
 static struct termios stdin_old_attr;
@@ -344,6 +345,7 @@ int main(int argc, char **argv)
char *end;
console_type type = CONSOLE_INVAL;
bool interactive = 0;
+   char *console_names = "serial, pv, vuart";
 
while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
switch(ch) {
@@ -359,9 +361,12 @@ int main(int argc, char **argv)
type = CONSOLE_SERIAL;
else if (!strcmp(optarg, "pv"))
type = CONSOLE_PV;
+   else if (!strcmp(optarg, "vuart"))
+   type = CONSOLE_VUART;
else {
fprintf(stderr, "Invalid type argument\n");
-   fprintf(stderr, "Console types supported are: 
serial, pv\n");
+   fprintf(stderr, "Console types supported are: 
%s\n",
+   console_names);
exit(EINVAL);
}
break;
@@ -437,6 +442,10 @@ int main(int argc, char **argv)
else
snprintf(path, strlen(dom_path) + 
strlen("/device/console/%d/tty") + 5, "%s/device/console/%d/tty", dom_path, 
num);
}
+   if (type == CONSOLE_VUART) {
+   snprintf(path, strlen(dom_path) + strlen("/vuart/0/tty") + 1,
+"%s/vuart/0/tty", dom_path);
+   }
 
/* FIXME consoled currently does not assume domain-0 doesn't have a
   console which is good when we break domain-0 up.  To keep us
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 27/27 v11] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt

2017-09-26 Thread Bhupinder Thakur
This patch fixes the issue observed when pl011 patches were tested on
the junos hardware by Andre/Julien. It was observed that when large output is
generated such as on running 'find /', output was getting truncated 
intermittently
due to OUT ring buffer getting full.

This issue was due to the fact that the SBSA UART driver expects that when
a TX interrupt is asserted then the FIFO queue should be atleast half empty and
that it can write N bytes in the FIFO, where N is half the FIFO queue size, 
without
the bytes getting dropped due to FIFO getting full.

The SBSA UART emulation logic was asserting the TX interrupt as soon as
any space became available in the FIFO and the SBSA UART driver tried to write
more data (upto 16 bytes) in the FIFO expecting that there is enough space
available leading to dropped bytes.

The SBSA spec [1] does not specify when the TX interrupt should be asserted
or de-asserted. Due to lack of clarity on the expected behavior, it is
assumed for now that TX interrupt should be asserted only when the FIFO goes
half empty.

TBD: Once the SBSA spec is updated with the expected behavior, the 
implementation
will be modified to align with the spec requirement.

[1] http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf

Signed-off-by: Bhupinder Thakur 
---
CC: Julien Grall 
CC: Andre Przywara 
CC: Stefano Stabellini 

Changes since v8:
- Used variables fifo_level/fifo_threshold for more clarity
- Added a new macro SBSA_UART_FIFO_SIZE instead of using a magic number
- Renamed ring_qsize variables to fifo_level for consistency 

 xen/arch/arm/vpl011.c| 87 ++--
 xen/include/asm-arm/vpl011.h |  2 +
 2 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
index 36794d8..1f97261 100644
--- a/xen/arch/arm/vpl011.c
+++ b/xen/arch/arm/vpl011.c
@@ -91,20 +91,24 @@ static uint8_t vpl011_read_data(struct domain *d)
  */
 if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) > 0 )
 {
+unsigned int fifo_level;
+
 data = intf->in[xencons_mask(in_cons, sizeof(intf->in))];
 in_cons += 1;
 smp_mb();
 intf->in_cons = in_cons;
+
+fifo_level = xencons_queued(in_prod, in_cons, sizeof(intf->in));
+
+if ( fifo_level == 0 )
+{
+vpl011->uartfr |= RXFE;
+vpl011->uartris &= ~RXI;
+}
 }
 else
 gprintk(XENLOG_ERR, "vpl011: Unexpected IN ring buffer empty\n");
 
-if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) == 0 )
-{
-vpl011->uartfr |= RXFE;
-vpl011->uartris &= ~RXI;
-}
-
 vpl011->uartfr &= ~RXFF;
 
 vpl011_update_interrupt_status(d);
@@ -144,28 +148,41 @@ static void vpl011_write_data(struct domain *d, uint8_t 
data)
 if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) !=
  sizeof (intf->out) )
 {
+unsigned int fifo_level, fifo_threshold;
+
 intf->out[xencons_mask(out_prod, sizeof(intf->out))] = data;
 out_prod += 1;
 smp_wmb();
 intf->out_prod = out_prod;
-}
-else
-gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n");
 
-if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) ==
- sizeof (intf->out) )
-{
-vpl011->uartfr |= TXFF;
-vpl011->uartris &= ~TXI;
+fifo_level = xencons_queued(out_prod, out_cons, sizeof(intf->out));
+
+if ( fifo_level == sizeof (intf->out) )
+{
+vpl011->uartfr |= TXFF;
+
+/*
+ * This bit is set only when FIFO becomes full. This ensures that
+ * the SBSA UART driver can write the early console data as fast as
+ * possible, without waiting for the BUSY bit to get cleared before
+ * writing each byte.
+ */
+vpl011->uartfr |= BUSY;
+}
 
 /*
- * This bit is set only when FIFO becomes full. This ensures that
- * the SBSA UART driver can write the early console data as fast as
- * possible, without waiting for the BUSY bit to get cleared before
- * writing each byte.
+ * Clear the TXI bit if the fifo level exceeds fifo_size/2 mark which
+ * is the trigger level for asserting/de-assterting the TX interrupt.
  */
-vpl011->uartfr |= BUSY;
+fifo_threshold = sizeof (intf->out) - SBSA_UART_FIFO_SIZE/2;
+
+if ( fifo_level <= fifo_threshold )
+vpl011->uartris |= TXI;
+else
+vpl011->uartris &= ~TXI;
 }
+else
+gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n");
 
 vpl011->uartfr &= ~TXFE;
 
@@ -342,7 +359,7 @@ static void vpl011_data_avail(struct domain *d)
   

[Xen-devel] [PATCH 12/27 v11] xen/arm: vpl011: Add a new buffer_available function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a new buffer_available function to check if
more data is allowed to be buffered.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 1da08d7..0009bbe 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -163,6 +163,16 @@ static int write_with_timestamp(int fd, const char *data, 
size_t sz,
return 0;
 }
 
+static inline bool buffer_available(struct console *con)
+{
+   if (discard_overflowed_data ||
+   !con->buffer.max_capacity ||
+   con->buffer.size < con->buffer.max_capacity)
+   return true;
+   else
+   return false;
+}
+
 static void buffer_append(struct console *con)
 {
struct buffer *buffer = &con->buffer;
@@ -1120,9 +1130,7 @@ void handle_io(void)
con->next_period < next_timeout)
next_timeout = con->next_period;
} else if (con->xce_handle != NULL) {
-   if (discard_overflowed_data ||
-   !con->buffer.max_capacity ||
-   con->buffer.size < 
con->buffer.max_capacity) {
+   if (buffer_available(con)) {
int evtchn_fd = 
xenevtchn_fd(con->xce_handle);
con->xce_pollfd_idx = set_fds(evtchn_fd,

POLLIN|POLLPRI);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 05/27 v11] xen/arm: vpl011: Rearrange xen header includes in alphabetical order in domctl.c

2017-09-26 Thread Bhupinder Thakur
Rearrange xen header includes in alphabetical order in domctl.c.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Reviewed-by: Julien Grall 
---
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Corrected include of  in alphabetical order.

 xen/arch/arm/domctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c
index 24bcb55..8232f44 100644
--- a/xen/arch/arm/domctl.c
+++ b/xen/arch/arm/domctl.c
@@ -4,12 +4,12 @@
  * Copyright (c) 2012, Citrix Systems
  */
 
-#include 
-#include 
 #include 
-#include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 15/27 v11] xen/arm: vpl011: Add a new console_evtchn_unmask function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a new console_evtchn_unmask function. This function
unmasks the console event channel if it is masked for some timeout
period.

One optimization that has been done is to merge the two for loops.

One for loop was used to iterate through all domains and
unmask the domain event channels which had been rate limited for a
specified duration.

The other for loop was run to add the event channel fd and the tty fd to
the poll list.

These two for loops were merged so that the these operations can be done
in one iteration instead of two iterations.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 44 +++-
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index a0b35da..2dcaee6 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -117,6 +117,11 @@ struct domain {
 
 static struct domain *dom_head;
 
+static inline bool console_enabled(struct console *con)
+{
+   return con->local_port != -1;
+}
+
 static int write_all(int fd, const char* buf, size_t len)
 {
while (len) {
@@ -908,6 +913,27 @@ static void handle_tty_write(struct console *con)
}
 }
 
+static void console_evtchn_unmask(struct console *con, void *data)
+{
+   long long now = (long long)data;
+
+   if (!console_enabled(con))
+   return;
+
+   /* CS 16257:955ee4fa1345 introduces a 5ms fuzz
+* for select(), it is not clear poll() has
+* similar behavior (returning a couple of ms
+* sooner than requested) as well. Just leave
+* the fuzz here. Remove it with a separate
+* patch if necessary */
+   if ((now+5) > con->next_period) {
+   con->next_period = now + RATE_LIMIT_PERIOD;
+   if (con->event_count >= RATE_LIMIT_ALLOWANCE)
+   (void)xenevtchn_unmask(con->xce_handle, 
con->local_port);
+   con->event_count = 0;
+   }
+}
+
 static void handle_ring_read(struct domain *dom)
 {
xenevtchn_port_or_error_t port;
@@ -1142,23 +1168,7 @@ void handle_io(void)
for (d = dom_head; d; d = d->next) {
struct console *con = &d->console;
 
-   /* CS 16257:955ee4fa1345 introduces a 5ms fuzz
-* for select(), it is not clear poll() has
-* similar behavior (returning a couple of ms
-* sooner than requested) as well. Just leave
-* the fuzz here. Remove it with a separate
-* patch if necessary */
-   if ((now+5) > con->next_period) {
-   con->next_period = now + RATE_LIMIT_PERIOD;
-   if (con->event_count >= RATE_LIMIT_ALLOWANCE) {
-   (void)xenevtchn_unmask(con->xce_handle, 
con->local_port);
-   }
-   con->event_count = 0;
-   }
-   }
-
-   for (d = dom_head; d; d = d->next) {
-   struct console *con = &d->console;
+   console_evtchn_unmask(con, (void *)now);
 
maybe_add_console_evtchn_fd(con, (void *)&next_timeout);
 
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 22/27 v11] xen/arm: vpl011: Add support for vuart console in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch finally adds the support for vuart console. It adds
two new fields in the console initialization:

- optional
- use_gnttab

optional flag tells whether the console is optional.

use_gnttab tells whether the ring buffer should be allocated using
grant table.

The VUART console is enabled ony for ARM.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Julien Grall 
CC: Stefano Stabellini 

Changes since v8:
- Removed CONFIG_VUART_CONSOLE config option
- Renamed CFLAGS_vuart-$(CONFIG_VUART_CONSOLE) to CONSOLE_CFLAGS-$(CONFIG_ARM)
- I hav retained the acked-by tag as it is a minor change

Changes since v6:
- Renames prefer_gnttab to use_gnttab

Changes since v4:
- Renamed VUART_CFLAGS- to CFLAGS_vuart- in the Makefile as per the convention.

 tools/console/Makefile|  3 ++-
 tools/console/daemon/io.c | 30 --
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/tools/console/Makefile b/tools/console/Makefile
index c5f3f5c..84796ea 100644
--- a/tools/console/Makefile
+++ b/tools/console/Makefile
@@ -11,6 +11,7 @@ LDLIBS += $(SOCKET_LIBS)
 
 LDLIBS_xenconsoled += $(UTIL_LIBS)
 LDLIBS_xenconsoled += -lrt
+CONSOLE_CFLAGS-$(CONFIG_ARM) = -DCONFIG_ARM
 
 BIN  = xenconsoled xenconsole
 
@@ -28,7 +29,7 @@ clean:
 distclean: clean
 
 daemon/main.o: daemon/_paths.h
-daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab)
+daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab) 
$(CONSOLE_CFLAGS-y)
 xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c))
$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_libxenevtchn) 
$(LDLIBS_libxengnttab) $(LDLIBS_xenconsoled) $(APPEND_LDFLAGS)
 
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index a198dbb..2615b50 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -107,12 +107,16 @@ struct console {
xenevtchn_port_or_error_t remote_port;
struct xencons_interface *interface;
struct domain *d;
+   bool optional;
+   bool use_gnttab;
 };
 
 struct console_type {
char *xsname;
char *ttyname;
char *log_suffix;
+   bool optional;
+   bool use_gnttab;
 };
 
 static struct console_type console_type[] = {
@@ -120,7 +124,18 @@ static struct console_type console_type[] = {
.xsname = "/console",
.ttyname = "tty",
.log_suffix = "",
+   .optional = false,
+   .use_gnttab = true,
},
+#if defined(CONFIG_ARM)
+   {
+   .xsname = "/vuart/0",
+   .ttyname = "tty",
+   .log_suffix = "-vuart0",
+   .optional = true,
+   .use_gnttab = false,
+   },
+#endif
 };
 
 #define NUM_CONSOLE_TYPE (sizeof(console_type)/sizeof(struct console_type))
@@ -654,8 +669,17 @@ static int console_create_ring(struct console *con)
"ring-ref", "%u", &ring_ref,
"port", "%i", &remote_port,
NULL);
-   if (err)
+
+   if (err) {
+   /*
+* This is a normal condition for optional consoles: they might 
not be
+* present on xenstore at all. In that case, just return 
without error.
+   */
+   if (con->optional)
+   err = 0;
+
goto out;
+   }
 
snprintf(path, sizeof(path), "%s/type", con->xspath);
type = xs_read(xs, XBT_NULL, path, NULL);
@@ -669,7 +693,7 @@ static int console_create_ring(struct console *con)
if (ring_ref != con->ring_ref && con->ring_ref != -1)
console_unmap_interface(con);
 
-   if (!con->interface && xgt_handle) {
+   if (!con->interface && xgt_handle && con->use_gnttab) {
/* Prefer using grant table */
con->interface = xengnttab_map_grant_ref(xgt_handle,
dom->domid, GNTTAB_RESERVED_CONSOLE,
@@ -788,6 +812,8 @@ static int console_init(struct console *con, struct domain 
*dom, void **data)
con->d = dom;
con->ttyname = (*con_type)->ttyname;
con->log_suffix = (*con_type)->log_suffix;
+   con->optional = (*con_type)->optional;
+   con->use_gnttab = (*con_type)->use_gnttab;
xsname = (char *)(*con_type)->xsname;
xspath = xs_get_domain_path(xs, dom->domid);
s = realloc(xspath, strlen(xspath) +
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 01/27 v11] xen/arm: vpl011: Define common ring buffer helper functions in console.h

2017-09-26 Thread Bhupinder Thakur
DEFINE_XEN_FLEX_RING(xencons) defines common helper functions such as
xencons_queued() to tell the current size of the ring buffer,
xencons_mask() to mask off the index, which are useful helper functions.
pl011 emulation code will use these helper functions.

io/console.h includes io/ring.h which defines DEFINE_XEN_FLEX_RING.

In console/daemon/io.c, string.h had to be included before io/console.h
because ring.h uses string functions.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
Acked-by: Konrad Rzeszutek Wilk 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v10:
- Fix for the headers.chk/headers++.chk compilation failures when code is 
compiled natively.
1)  Inclusion of DEFINE_XEN_FLEX_RING in console.h had to be put under
!defined(__STRICT_ANSI__) check as console.h is __STRICT_ANSI__
currently since it is part of headers.chk.
2)  Also string header file had to be added as a pre-req for headers++.chk 
to pass
the compilation because c++ does not define __STRICT_ANSI__ and thus
expands DEFINE_XEN_FLEX_RING, which looks for memcpy(), size_t 
declarations.
To satify that requirement string header file had to be added a pre-req
for header++.chk.
 
Changes since v4:
- Split this change in a separate patch.

 tools/console/daemon/io.c   | 2 +-
 xen/include/public/io/console.h | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)

 tools/console/daemon/io.c   | 2 +-
 xen/include/Makefile| 1 +
 xen/include/public/io/console.h | 6 ++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 7e474bb..e8033d2 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -21,6 +21,7 @@
 
 #include "utils.h"
 #include "io.h"
+#include 
 #include 
 #include 
 #include 
@@ -29,7 +30,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/xen/include/Makefile b/xen/include/Makefile
index 1299b19..c90fdee 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -98,6 +98,7 @@ PUBLIC_C99_HEADERS := public/io/9pfs.h public/io/pvcalls.h
 PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/% 
public/%hvm/save.h $(PUBLIC_C99_HEADERS), $(PUBLIC_HEADERS))
 
 public/io/9pfs.h-prereq := string
+public/io/console.h-prereq := string
 public/io/pvcalls.h-prereq := string
 
 headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile
diff --git a/xen/include/public/io/console.h b/xen/include/public/io/console.h
index e2cd97f..0f0711f 100644
--- a/xen/include/public/io/console.h
+++ b/xen/include/public/io/console.h
@@ -27,6 +27,8 @@
 #ifndef __XEN_PUBLIC_IO_CONSOLE_H__
 #define __XEN_PUBLIC_IO_CONSOLE_H__
 
+#include "ring.h"
+
 typedef uint32_t XENCONS_RING_IDX;
 
 #define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring)-1))
@@ -38,6 +40,10 @@ struct xencons_interface {
 XENCONS_RING_IDX out_cons, out_prod;
 };
 
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+DEFINE_XEN_FLEX_RING(xencons);
+#endif
+
 #endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */
 
 /*
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 10/27 v11] xen/arm: vpl011: Modify xenconsole functions to take console structure as input

2017-09-26 Thread Bhupinder Thakur
Xenconsole functions take domain structure as input. These functions shall be
modified to take console structure as input since these functions typically 
perform
console specific operations.

Also the console specific functions starting with prefix "domain_" shall be 
modified
to "console_" to indicate that these are console specific functions.

This patch is in preparation to support multiple consoles to support vuart 
console.

Signed-off-by: Bhupinder Thakur 
Acked-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v3:
- The changes in xenconsole have been split into multiple patches. This is the 
second patch.

 tools/console/daemon/io.c | 79 +++
 1 file changed, 38 insertions(+), 41 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 6f5c69c..a2a3496 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -163,10 +163,10 @@ static int write_with_timestamp(int fd, const char *data, 
size_t sz,
return 0;
 }
 
-static void buffer_append(struct domain *dom)
+static void buffer_append(struct console *con)
 {
-   struct console *con = &dom->console;
struct buffer *buffer = &con->buffer;
+   struct domain *dom = con->d;
XENCONS_RING_IDX cons, prod, size;
struct xencons_interface *intf = con->interface;
 
@@ -296,12 +296,13 @@ static int create_hv_log(void)
return fd;
 }
 
-static int create_domain_log(struct domain *dom)
+static int create_console_log(struct console *con)
 {
char logfile[PATH_MAX];
char *namepath, *data, *s;
int fd;
unsigned int len;
+   struct domain *dom = con->d;
 
namepath = xs_get_domain_path(xs, dom->domid);
s = realloc(namepath, strlen(namepath) + 6);
@@ -342,10 +343,8 @@ static int create_domain_log(struct domain *dom)
return fd;
 }
 
-static void domain_close_tty(struct domain *dom)
+static void console_close_tty(struct console *con)
 {
-   struct console *con = &dom->console;
-
if (con->master_fd != -1) {
close(con->master_fd);
con->master_fd = -1;
@@ -417,7 +416,7 @@ void cfmakeraw(struct termios *termios_p)
 }
 #endif /* __sun__ */
 
-static int domain_create_tty(struct domain *dom)
+static int console_create_tty(struct console *con)
 {
const char *slave;
char *path;
@@ -426,7 +425,7 @@ static int domain_create_tty(struct domain *dom)
char *data;
unsigned int len;
struct termios term;
-   struct console *con = &dom->console;
+   struct domain *dom = con->d;
 
assert(con->slave_fd == -1);
assert(con->master_fd == -1);
@@ -487,7 +486,7 @@ static int domain_create_tty(struct domain *dom)
 
return 1;
 out:
-   domain_close_tty(dom);
+   console_close_tty(con);
return 0;
 }
  
@@ -526,10 +525,8 @@ static int xs_gather(struct xs_handle *xs, const char 
*dir, ...)
return ret;
 }
 
-static void domain_unmap_interface(struct domain *dom)
+static void console_unmap_interface(struct console *con)
 {
-   struct console *con = &dom->console;
-
if (con->interface == NULL)
return;
if (xgt_handle && con->ring_ref == -1)
@@ -540,11 +537,11 @@ static void domain_unmap_interface(struct domain *dom)
con->ring_ref = -1;
 }
  
-static int domain_create_ring(struct domain *dom)
+static int console_create_ring(struct console *con)
 {
int err, remote_port, ring_ref, rc;
char *type, path[PATH_MAX];
-   struct console *con = &dom->console;
+   struct domain *dom = con->d;
 
err = xs_gather(xs, con->xspath,
"ring-ref", "%u", &ring_ref,
@@ -563,7 +560,7 @@ static int domain_create_ring(struct domain *dom)
 
/* If using ring_ref and it has changed, remap */
if (ring_ref != con->ring_ref && con->ring_ref != -1)
-   domain_unmap_interface(dom);
+   console_unmap_interface(con);
 
if (!con->interface && xgt_handle) {
/* Prefer using grant table */
@@ -621,7 +618,7 @@ static int domain_create_ring(struct domain *dom)
con->remote_port = remote_port;
 
if (con->master_fd == -1) {
-   if (!domain_create_tty(dom)) {
+   if (!console_create_tty(con)) {
err = errno;
xenevtchn_close(con->xce_handle);
con->xce_handle = NULL;
@@ -632,7 +629,7 @@ static int domain_create_ring(struct domain *dom)
}
 
if (log_guest && (con->log_fd == -1))
-   con->log_fd = create_domain_log(dom);
+   con->log_fd = c

[Xen-devel] [PATCH 08/27 v11] xen/arm: vpl011: Modify xenconsole to define and use a new console structure

2017-09-26 Thread Bhupinder Thakur
Xenconsole uses a domain structure which contains console specific fields. This
patch defines a new console structure, which would be used by the xenconsole
functions to perform console specific operations like reading/writing data 
from/to
the console ring buffer or reading/writing data from/to console tty.

This patch is in preparation to support multiple consoles to support vuart 
console.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v4:
- Moved the following fields from the struct domain to struct console:
  ->xenevtchn_handle *xce_handle;
  ->int xce_pollfd_idx;
  ->int event_count;
  ->long long next_period;

Changes since v3:
- The changes in xenconsole have been split into four patches. This is the 
first patch
  which modifies the xenconsole to use a new console structure.

Changes since v2:
- Defined a new function console_create_ring() which sets up the ring buffer 
and 
  event channel a new console. domain_create_ring() uses this function to setup
  a console.
- This patch does not contain vuart specific changes, which would be introduced 
in
  the next patch.
- Changes for keeping the PV log file name unchanged.

Changes since v1:
- Split the domain struture to a separate console structure
- Modified the functions to operate on the console struture
- Replaced repetitive per console code with generic code

 tools/console/daemon/io.c | 299 +-
 1 file changed, 165 insertions(+), 134 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index e8033d2..30cd167 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -89,25 +89,30 @@ struct buffer {
size_t max_capacity;
 };
 
-struct domain {
-   int domid;
+struct console {
int master_fd;
int master_pollfd_idx;
int slave_fd;
int log_fd;
-   bool is_dead;
-   unsigned last_seen;
struct buffer buffer;
-   struct domain *next;
char *conspath;
int ring_ref;
-   xenevtchn_port_or_error_t local_port;
-   xenevtchn_port_or_error_t remote_port;
xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
-   struct xencons_interface *interface;
int event_count;
long long next_period;
+   xenevtchn_port_or_error_t local_port;
+   xenevtchn_port_or_error_t remote_port;
+   struct xencons_interface *interface;
+   struct domain *d;
+};
+
+struct domain {
+   int domid;
+   bool is_dead;
+   unsigned last_seen;
+   struct domain *next;
+   struct console console;
 };
 
 static struct domain *dom_head;
@@ -160,9 +165,10 @@ static int write_with_timestamp(int fd, const char *data, 
size_t sz,
 
 static void buffer_append(struct domain *dom)
 {
-   struct buffer *buffer = &dom->buffer;
+   struct console *con = &dom->console;
+   struct buffer *buffer = &con->buffer;
XENCONS_RING_IDX cons, prod, size;
-   struct xencons_interface *intf = dom->interface;
+   struct xencons_interface *intf = con->interface;
 
cons = intf->out_cons;
prod = intf->out_prod;
@@ -187,22 +193,22 @@ static void buffer_append(struct domain *dom)
 
xen_mb();
intf->out_cons = cons;
-   xenevtchn_notify(dom->xce_handle, dom->local_port);
+   xenevtchn_notify(con->xce_handle, con->local_port);
 
/* Get the data to the logfile as early as possible because if
 * no one is listening on the console pty then it will fill up
 * and handle_tty_write will stop being called.
 */
-   if (dom->log_fd != -1) {
+   if (con->log_fd != -1) {
int logret;
if (log_time_guest) {
logret = write_with_timestamp(
-   dom->log_fd,
+   con->log_fd,
buffer->data + buffer->size - size,
size, &log_time_guest_needts);
} else {
logret = write_all(
-   dom->log_fd,
+   con->log_fd,
buffer->data + buffer->size - size,
size);
}
@@ -338,14 +344,16 @@ static int create_domain_log(struct domain *dom)
 
 static void domain_close_tty(struct domain *dom)
 {
-   if (dom->master_fd != -1) {
-   close(dom->master_fd);
-   dom->master_fd = -1;
+   struct console *con = &dom->console;
+
+   if (con->master_fd != -1) {
+   close(con->master_fd);
+   con->master_fd = -1;
}
 
-   if (dom->slave_fd != -1) {
-   close(

[Xen-devel] [PATCH 09/27 v11] xen/arm: vpl011: Rename the console structure field conspath to xspath

2017-09-26 Thread Bhupinder Thakur
The console->conspath name is changed to console->xspath as it is
clear from the name that it is referring to xenstore path.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v4:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 30cd167..6f5c69c 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -95,7 +95,7 @@ struct console {
int slave_fd;
int log_fd;
struct buffer buffer;
-   char *conspath;
+   char *xspath;
int ring_ref;
xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
@@ -463,7 +463,7 @@ static int domain_create_tty(struct domain *dom)
goto out;
}
 
-   success = asprintf(&path, "%s/limit", con->conspath) !=
+   success = asprintf(&path, "%s/limit", con->xspath) !=
-1;
if (!success)
goto out;
@@ -474,7 +474,7 @@ static int domain_create_tty(struct domain *dom)
}
free(path);
 
-   success = (asprintf(&path, "%s/tty", con->conspath) != -1);
+   success = (asprintf(&path, "%s/tty", con->xspath) != -1);
if (!success)
goto out;
success = xs_write(xs, XBT_NULL, path, slave, strlen(slave));
@@ -546,14 +546,14 @@ static int domain_create_ring(struct domain *dom)
char *type, path[PATH_MAX];
struct console *con = &dom->console;
 
-   err = xs_gather(xs, con->conspath,
+   err = xs_gather(xs, con->xspath,
"ring-ref", "%u", &ring_ref,
"port", "%i", &remote_port,
NULL);
if (err)
goto out;
 
-   snprintf(path, sizeof(path), "%s/type", con->conspath);
+   snprintf(path, sizeof(path), "%s/type", con->xspath);
type = xs_read(xs, XBT_NULL, path, NULL);
if (type && strcmp(type, "xenconsoled") != 0) {
free(type);
@@ -646,13 +646,13 @@ static bool watch_domain(struct domain *dom, bool watch)
 
snprintf(domid_str, sizeof(domid_str), "dom%u", dom->domid);
if (watch) {
-   success = xs_watch(xs, con->conspath, domid_str);
+   success = xs_watch(xs, con->xspath, domid_str);
if (success)
domain_create_ring(dom);
else
-   xs_unwatch(xs, con->conspath, domid_str);
+   xs_unwatch(xs, con->xspath, domid_str);
} else {
-   success = xs_unwatch(xs, con->conspath, domid_str);
+   success = xs_unwatch(xs, con->xspath, domid_str);
}
 
return success;
@@ -682,13 +682,13 @@ static struct domain *create_domain(int domid)
dom->domid = domid;
 
con = &dom->console;
-   con->conspath = xs_get_domain_path(xs, dom->domid);
-   s = realloc(con->conspath, strlen(con->conspath) +
+   con->xspath = xs_get_domain_path(xs, dom->domid);
+   s = realloc(con->xspath, strlen(con->xspath) +
strlen("/console") + 1);
if (s == NULL)
goto out;
-   con->conspath = s;
-   strcat(con->conspath, "/console");
+   con->xspath = s;
+   strcat(con->xspath, "/console");
 
con->master_fd = -1;
con->master_pollfd_idx = -1;
@@ -712,7 +712,7 @@ static struct domain *create_domain(int domid)
 
return dom;
  out:
-   free(con->conspath);
+   free(con->xspath);
free(dom);
return NULL;
 }
@@ -756,8 +756,8 @@ static void cleanup_domain(struct domain *d)
free(con->buffer.data);
con->buffer.data = NULL;
 
-   free(con->conspath);
-   con->conspath = NULL;
+   free(con->xspath);
+   con->xspath = NULL;
 
remove_domain(d);
 }
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 13/27 v11] xen/arm: vpl011: Add a new maybe_add_console_evtchn_fd function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a new maybe_add_console_evtchn_fd function. This
function adds the console event channel FD to list of polled FDs.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v6:
- Renamed add_console_evtchn_fd to maybe_add_console_evtchn_fd since it 
  adds the FD to the poll list conditionally.

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 33 +
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 0009bbe..3483252 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -1047,6 +1047,26 @@ static void reset_fds(void)
memset(fds, 0, sizeof(struct pollfd) * current_array_size);
 }
 
+static void maybe_add_console_evtchn_fd(struct console *con, void *data)
+{
+   long long next_timeout = *((long long *)data);
+
+   if (con->event_count >= RATE_LIMIT_ALLOWANCE) {
+   /* Determine if we're going to be the next time slice to expire 
*/
+   if (!next_timeout ||
+   con->next_period < next_timeout)
+   next_timeout = con->next_period;
+   } else if (con->xce_handle != NULL) {
+   if (buffer_available(con)) {
+   int evtchn_fd = xenevtchn_fd(con->xce_handle);
+   con->xce_pollfd_idx = set_fds(evtchn_fd,
+ POLLIN|POLLPRI);
+   }
+   }
+
+   *((long long *)data) = next_timeout;
+}
+
 void handle_io(void)
 {
int ret;
@@ -1124,18 +1144,7 @@ void handle_io(void)
for (d = dom_head; d; d = d->next) {
struct console *con = &d->console;
 
-   if (con->event_count >= RATE_LIMIT_ALLOWANCE) {
-   /* Determine if we're going to be the next time 
slice to expire */
-   if (!next_timeout ||
-   con->next_period < next_timeout)
-   next_timeout = con->next_period;
-   } else if (con->xce_handle != NULL) {
-   if (buffer_available(con)) {
-   int evtchn_fd = 
xenevtchn_fd(con->xce_handle);
-   con->xce_pollfd_idx = set_fds(evtchn_fd,
-   
POLLIN|POLLPRI);
-   }
-   }
+   maybe_add_console_evtchn_fd(con, (void *)&next_timeout);
 
if (con->master_fd != -1) {
short events = 0;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 16/27 v11] xen/arm: vpl011: Add a new handle_console_ring function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a new handle_console_ring function. This function
reads the data from the ring buffer on receiving an event.

The initialization of event channel poll fd to -1 is moved inside the
handle_console_ring function as they are related. There should be no
change in the behavior as there is no functional change.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 40 +++-
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 2dcaee6..c361b42 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -934,17 +934,23 @@ static void console_evtchn_unmask(struct console *con, 
void *data)
}
 }
 
-static void handle_ring_read(struct domain *dom)
+static void handle_ring_read(struct console *con)
 {
xenevtchn_port_or_error_t port;
-   struct console *con = &dom->console;
 
-   if (dom->is_dead)
+   if (con->d->is_dead)
return;
 
if ((port = xenevtchn_pending(con->xce_handle)) == -1)
return;
 
+   if (port != con->local_port) {
+   dolog(LOG_ERR,
+ "Event received for invalid port %d, Expected port is 
%d\n",
+ port, con->local_port);
+   return;
+   }
+
con->event_count++;
 
buffer_append(con);
@@ -953,6 +959,21 @@ static void handle_ring_read(struct domain *dom)
(void)xenevtchn_unmask(con->xce_handle, port);
 }
 
+static void handle_console_ring(struct console *con)
+{
+   if (con->event_count < RATE_LIMIT_ALLOWANCE) {
+   if (con->xce_handle != NULL &&
+   con->xce_pollfd_idx != -1 &&
+   !(fds[con->xce_pollfd_idx].revents &
+ ~(POLLIN|POLLOUT|POLLPRI)) &&
+   (fds[con->xce_pollfd_idx].revents &
+POLLIN))
+   handle_ring_read(con);
+   }
+
+   con->xce_pollfd_idx = -1;
+}
+
 static void handle_xs(void)
 {
char **vec;
@@ -1236,15 +1257,8 @@ void handle_io(void)
struct console *con = &d->console;
 
n = d->next;
-   if (con->event_count < RATE_LIMIT_ALLOWANCE) {
-   if (con->xce_handle != NULL &&
-   con->xce_pollfd_idx != -1 &&
-   !(fds[con->xce_pollfd_idx].revents &
- ~(POLLIN|POLLOUT|POLLPRI)) &&
- (fds[con->xce_pollfd_idx].revents &
-  POLLIN))
-   handle_ring_read(d);
-   }
+
+   handle_console_ring(con);
 
if (con->master_fd != -1 && con->master_pollfd_idx != 
-1) {
if (fds[con->master_pollfd_idx].revents &
@@ -1261,7 +1275,7 @@ void handle_io(void)
}
}
 
-   con->xce_pollfd_idx = con->master_pollfd_idx = -1;
+   con->master_pollfd_idx = -1;
 
if (d->last_seen != enum_pass)
shutdown_domain(d);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 20/27 v11] xen/arm: vpl011: Add a new console_close_evtchn function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a console_close_evtchn function. This function closes
the console event channel.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index cfd7273..71465a0 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -793,6 +793,14 @@ static void cleanup_domain(struct domain *d)
remove_domain(d);
 }
 
+static void console_close_evtchn(struct console *con)
+{
+   if (con->xce_handle != NULL)
+   xenevtchn_close(con->xce_handle);
+
+   con->xce_handle = NULL;
+}
+
 static void shutdown_domain(struct domain *d)
 {
struct console *con = &d->console;
@@ -800,9 +808,7 @@ static void shutdown_domain(struct domain *d)
d->is_dead = true;
watch_domain(d, false);
console_unmap_interface(con);
-   if (con->xce_handle != NULL)
-   xenevtchn_close(con->xce_handle);
-   con->xce_handle = NULL;
+   console_close_evtchn(con);
 }
 
 static unsigned enum_pass = 0;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 03/27 v11] xen/arm: vpl011: Allocate a new GFN in the toolstack for vuart

2017-09-26 Thread Bhupinder Thakur
Allocate a new gfn to be used as a ring buffer between xenconsole
and Xen for sending/receiving pl011 console data.

Signed-off-by: Bhupinder Thakur 
Acked-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v4:
- Removed xc_get_vuart_gfn() as it is not required since the vpl011 
initialization
  function which used this API has been moved to after gfn is allocated.
- I have included the reviewed-by and acked-by tags as there is no change in the
  logic.

Changes since v3:
- Added a new helper function xc_get_vuart_gfn() to return the GFN allocated for
  vpl011.
- Since a new function has been added in this patch, I have not included 
Stefano's
  reviewed-by and Wei's acked-by tags.

Changes since v2:
- Removed the DOMCTL call to set the GFN as now this information is passed
  in the DOMCTL call to initialize vpl011 emulation.

 tools/libxc/include/xc_dom.h | 2 ++
 tools/libxc/xc_dom_arm.c | 5 -
 tools/libxc/xc_dom_boot.c| 2 ++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/libxc/include/xc_dom.h b/tools/libxc/include/xc_dom.h
index ce47058..6e06ef1 100644
--- a/tools/libxc/include/xc_dom.h
+++ b/tools/libxc/include/xc_dom.h
@@ -216,6 +216,8 @@ struct xc_dom_image {
 
 /* Extra SMBIOS structures passed to HVMLOADER */
 struct xc_hvm_firmware_module smbios_module;
+
+xen_pfn_t vuart_gfn;
 };
 
 /* --- pluggable kernel loader - */
diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c
index e669fb0..98200ae 100644
--- a/tools/libxc/xc_dom_arm.c
+++ b/tools/libxc/xc_dom_arm.c
@@ -26,10 +26,11 @@
 #include "xg_private.h"
 #include "xc_dom.h"
 
-#define NR_MAGIC_PAGES 3
+#define NR_MAGIC_PAGES 4
 #define CONSOLE_PFN_OFFSET 0
 #define XENSTORE_PFN_OFFSET 1
 #define MEMACCESS_PFN_OFFSET 2
+#define VUART_PFN_OFFSET 3
 
 #define LPAE_SHIFT 9
 
@@ -85,10 +86,12 @@ static int alloc_magic_pages(struct xc_dom_image *dom)
 
 dom->console_pfn = base + CONSOLE_PFN_OFFSET;
 dom->xenstore_pfn = base + XENSTORE_PFN_OFFSET;
+dom->vuart_gfn = base + VUART_PFN_OFFSET;
 
 xc_clear_domain_page(dom->xch, dom->guest_domid, dom->console_pfn);
 xc_clear_domain_page(dom->xch, dom->guest_domid, dom->xenstore_pfn);
 xc_clear_domain_page(dom->xch, dom->guest_domid, base + 
MEMACCESS_PFN_OFFSET);
+xc_clear_domain_page(dom->xch, dom->guest_domid, base + VUART_PFN_OFFSET);
 xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_PFN,
 dom->console_pfn);
 xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_PFN,
diff --git a/tools/libxc/xc_dom_boot.c b/tools/libxc/xc_dom_boot.c
index c3b44dd..8a376d0 100644
--- a/tools/libxc/xc_dom_boot.c
+++ b/tools/libxc/xc_dom_boot.c
@@ -226,6 +226,8 @@ int xc_dom_boot_image(struct xc_dom_image *dom)
 return rc;
 if ( (rc = clear_page(dom, dom->xenstore_pfn)) != 0 )
 return rc;
+if ( (rc = clear_page(dom, dom->vuart_gfn)) != 0 )
+return rc;
 
 /* start info page */
 if ( dom->arch_hooks->start_info )
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 04/27 v11] xen/arm: vpl011: Add support for vuart in libxl

2017-09-26 Thread Bhupinder Thakur
An option is provided in libxl to enable/disable SBSA vuart while
creating a guest domain.

Libxl now supports a generic vuart console and SBSA uart is a specific type.
In future support can be added for multiple vuart of different types.

User can enable SBSA vuart by adding the following line in the guest
configuration file:

vuart = "sbsa_uart"

Signed-off-by: Bhupinder Thakur 
Acked-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v4:
- Renamed "pl011" to "sbsa_uart".

Changes since v3:
- Added a new config option CONFIG_VUART_CONSOLE to enable/disable vuart console
  support.
- Moved libxl_vuart_type to arch-arm part of libxl_domain_build_info
- Updated xl command help to mention new console type - vuart.

Changes since v2:
- Defined vuart option as an enum instead of a string.
- Removed the domain creation flag defined for vuart and the related code
  to pass on the information while domain creation. Now vpl011 is initialized
  independent of domain creation through new DOMCTL APIs.

 tools/libxl/libxl.h  | 7 +++
 tools/libxl/libxl_console.c  | 3 +++
 tools/libxl/libxl_dom.c  | 1 +
 tools/libxl/libxl_internal.h | 3 +++
 tools/libxl/libxl_types.idl  | 7 +++
 tools/xl/xl_cmdtable.c   | 2 +-
 tools/xl/xl_console.c| 5 -
 tools/xl/xl_parse.c  | 8 
 8 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 7d853ca..9dfd964 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -308,9 +308,16 @@
 /*
  * LIBXL_HAVE_P9S indicates that the p9 field in IDL has been changed to p9s
  */
+
 #define LIBXL_HAVE_P9S 1
 
 /*
+ * LIBXL_HAVE_BUILDINFO_ARM_VUART indicates that the toolstack supports 
virtual UART
+ * for ARM.
+ */
+#define LIBXL_HAVE_BUILDINFO_ARM_VUART 1
+
+/*
  * libxl ABI compatibility
  *
  * The only guarantee which libxl makes regarding ABI compatibility
diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index 68511d7..f4f64ad 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -67,6 +67,9 @@ int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int 
cons_num,
 case LIBXL_CONSOLE_TYPE_SERIAL:
 cons_type_s = "serial";
 break;
+case LIBXL_CONSOLE_TYPE_VUART:
+cons_type_s = "vuart";
+break;
 default:
 goto out;
 }
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index f54fd49..e0f0d78 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -803,6 +803,7 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
 if (xc_dom_translated(dom)) {
 state->console_mfn = dom->console_pfn;
 state->store_mfn = dom->xenstore_pfn;
+state->vuart_gfn = dom->vuart_gfn;
 } else {
 state->console_mfn = xc_dom_p2m(dom, dom->console_pfn);
 state->store_mfn = xc_dom_p2m(dom, dom->xenstore_pfn);
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 81e87ae..30a5cb2 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1139,6 +1139,9 @@ typedef struct {
 uint32_t num_vmemranges;
 
 xc_domain_configuration_t config;
+
+xen_pfn_t vuart_gfn;
+evtchn_port_t vuart_port;
 } libxl__domain_build_state;
 
 _hidden int libxl__build_pre(libxl__gc *gc, uint32_t domid,
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 756e120..37ac8ec 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -105,6 +105,7 @@ libxl_console_type = Enumeration("console_type", [
 (0, "UNKNOWN"),
 (1, "SERIAL"),
 (2, "PV"),
+(3, "VUART"),
 ])
 
 libxl_disk_format = Enumeration("disk_format", [
@@ -240,6 +241,11 @@ libxl_checkpointed_stream = 
Enumeration("checkpointed_stream", [
 (2, "COLO"),
 ])
 
+libxl_vuart_type = Enumeration("vuart_type", [
+(0, "unknown"),
+(1, "sbsa_uart"),
+])
+
 #
 # Complex libxl types
 #
@@ -581,6 +587,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
 
 
 ("arch_arm", Struct(None, [("gic_version", libxl_gic_version),
+   ("vuart", libxl_vuart_type),
   ])),
 # Alternate p2m is not bound to any architecture or guest type, as it is
 # supported by x86 HVM and ARM support is planned.
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 48f0324..2126e70 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -133,7 +133,7 @@ struct cmd_spec cmd_table[] = {
   &main_console, 0, 0,
   "Attach to domain's console",
   "[options] \n"
-  &

[Xen-devel] [PATCH 17/27 v11] xen/arm: vpl011: Add a new handle_console_tty function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a new handle_console_tty function. This function
performs read/write from/to console tty.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 35 +++
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index c361b42..5c6da31 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -1130,6 +1130,24 @@ static void maybe_add_console_tty_fd(struct console *con)
}
 }
 
+static void handle_console_tty(struct console *con)
+{
+   if (con->master_fd != -1 && con->master_pollfd_idx != -1) {
+   if (fds[con->master_pollfd_idx].revents &
+   ~(POLLIN|POLLOUT|POLLPRI))
+   console_handle_broken_tty(con, 
domain_is_valid(con->d->domid));
+   else {
+   if (fds[con->master_pollfd_idx].revents &
+   POLLIN)
+   handle_tty_read(con);
+   if (fds[con->master_pollfd_idx].revents &
+   POLLOUT)
+   handle_tty_write(con);
+   }
+   }
+   con->master_pollfd_idx = -1;
+}
+
 void handle_io(void)
 {
int ret;
@@ -1260,22 +1278,7 @@ void handle_io(void)
 
handle_console_ring(con);
 
-   if (con->master_fd != -1 && con->master_pollfd_idx != 
-1) {
-   if (fds[con->master_pollfd_idx].revents &
-   ~(POLLIN|POLLOUT|POLLPRI))
-   console_handle_broken_tty(con,
-  domain_is_valid(d->domid));
-   else {
-   if (fds[con->master_pollfd_idx].revents 
&
-   POLLIN)
-   handle_tty_read(con);
-   if (fds[con->master_pollfd_idx].revents 
&
-   POLLOUT)
-   handle_tty_write(con);
-   }
-   }
-
-   con->master_pollfd_idx = -1;
+   handle_console_tty(con);
 
if (d->last_seen != enum_pass)
shutdown_domain(d);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 06/27 v11] xen/arm: vpl011: Add a new domctl API to initialize vpl011

2017-09-26 Thread Bhupinder Thakur
Add a new domctl API to initialize vpl011. It takes the GFN and console
backend domid as input and returns an event channel to be used for
sending and receiving events from Xen.

Xen will communicate with xenconsole using GFN as the ring buffer and
the event channel to transmit and receive pl011 data on the guest domain's
behalf.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Andrew Cooper 
CC: George Dunlap 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Julien Grall 

Changes since v9:
- Initialized local variable in libxl__arch_build_dom_finish
- Replaced __copy_to_guest with copy_to_guest
- Added comment for console_domid field in vuart_op structure

Changes since v8:
- Added explicit padding in the vuart_op structure
- Moved vuart_op structure after the PSR structure definition
- The input fields moved before the output fields in vuart_op structure
- Checking explicitly that padding fields are initialized to 0

Changes since v6:
- Renamed the vuart initialization function to a generic name xc_dom_vuart_init 
- Used domid_t as a type instead of uint32_t for domid
- Checking the vuart type explicitly against vpl011 enum value

Changes since v5:
- xc_dom_vpl011_init() will be compiled for both x86/arm architectures as there
  is nothing architecture specific in this function. This function will return 
  error when called for x86.
- Fixed coding style issues in libxl.

Changes since v4:
- Removed libxl__arch_domain_create_finish().
- Added a new function libxl__arch_build_dom_finish(), which is called at the 
last
  in libxl__build_dom(). This function calls the vpl011 initialization function 
now.

Changes since v3:
- Added a new arch specific function libxl__arch_domain_create_finish(), which
  calls the vpl011 initialization function. For x86 this function does not do
  anything.
- domain_vpl011_init() takes a pointer to a structure which contains all the 
  required information such as console_domid, gfn instead of passing parameters
  separately.
- Dropped a DOMCTL API defined for de-initializing vpl011 as that should be
  taken care when the domain is destroyed (and not dependent on userspace 
  libraries/applications).

Changes since v2:
- Replaced the DOMCTL APIs defined for get/set of event channel and GFN with 
  a set of DOMCTL APIs for initializing and de-initializing vpl011 emulation.

 tools/libxc/include/xenctrl.h | 20 +
 tools/libxc/xc_domain.c   | 27 ++
 tools/libxl/libxl_arch.h  |  7 ++
 tools/libxl/libxl_arm.c   | 27 ++
 tools/libxl/libxl_dom.c   |  4 
 tools/libxl/libxl_x86.c   |  8 +++
 xen/arch/arm/domain.c |  6 +
 xen/arch/arm/domctl.c | 52 +++
 xen/include/public/domctl.h   | 24 
 9 files changed, 175 insertions(+)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 073fbc9..2086e71 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -886,6 +886,26 @@ int xc_vcpu_getcontext(xc_interface *xch,
vcpu_guest_context_any_t *ctxt);
 
 /**
+ * This function initializes the vuart emulation and returns
+ * the event to be used by the backend for communicating with
+ * the emulation code.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * #parm type type of vuart
+ * @parm domid the domain to get information from
+ * @parm console_domid the domid of the backend console
+ * @parm gfn the guest pfn to be used as the ring buffer
+ * @parm evtchn the event channel to be used for events
+ * @return 0 on success, negative error on failure
+ */
+int xc_dom_vuart_init(xc_interface *xch,
+  uint32_t type,
+  domid_t domid,
+  domid_t console_domid,
+  xen_pfn_t gfn,
+  evtchn_port_t *evtchn);
+
+/**
  * This function returns information about the XSAVE state of a particular
  * vcpu of a domain. If extstate->size and extstate->xfeature_mask are 0,
  * the call is considered a query to retrieve them and the buffer is not
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index f40dc4f..f2e9f0c 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -343,6 +343,33 @@ int xc_domain_get_guest_width(xc_interface *xch, uint32_t 
domid,
 return 0;
 }
 
+int xc_dom_vuart_init(xc_interface *xch,
+  uint32_t type,
+  domid_t domid,
+  domid_t console_domid,
+  xen_pfn_t gfn,
+  evtchn_port_t *evtchn)
+{
+DECLARE_DOMCTL;
+int rc = 0;
+
+memset(&domctl, 0, sizeof(domctl));
+
+domctl.cmd = XEN_DOMCTL_vuart_op;
+domctl.domain = domid;
+domctl.u.vuart_op.cmd = XEN_DOMCT

[Xen-devel] [PATCH 02/27 v11] xen/arm: vpl011: Add SBSA UART emulation in Xen

2017-09-26 Thread Bhupinder Thakur
Add emulation code to emulate read/write access to pl011 registers
and pl011 interrupts:

- Emulate DR read/write by reading and writing from/to the IN
  and OUT ring buffers and raising an event to the backend when
  there is data in the OUT ring buffer and injecting an interrupt
  to the guest when there is data in the IN ring buffer

- Other registers are related to interrupt management and
  essentially control when interrupts are delivered to the guest

This patch implements the SBSA Generic UART which is a subset of ARM
PL011 UART.

The SBSA Generic UART is covered in Appendix B of
https://static.docs.arm.com/den0029/a/Server_Base_System_Architecture_v3_1_ARM_DEN_0029A.pdf

Signed-off-by: Bhupinder Thakur 
Acked-by: Julien Grall 
Reviewed-by: Stefano Stabellini 
---
CC: Stefano Stabellini 
CC: Julien Grall 
CC: Andre Przywara 

Changes since v7:
- Set/clear the TX interrupt status bit based on whether space available for 16 
bytes in the ring buffer
- Clear the BUSY status bit as soon as space becomes available in the ring 
buffer

Changes since v6:
- Removed freeing of mmio_handlers in vpl011_deinit() as the handlers get freed 
when a domain is 
  destroyed. Since this is a minor change, I have included the reviewed-by and 
acked-by tags.

Changes since v5:
- use  instead of  for including arm specific header files.
- renamed shadow_uartris to shadow_uartmis to indicate that it is masked 
interrupt status.
- use smp_mb() instead of smp_rmb() in vpl011_write_data().

Changes since v4:
- Renamed vpl011_update() to vpl011_update_interrupt_status() and added logic 
to avoid
  raising spurious interrupts.
- Used barrier instructions correctly while reading/writing data to the ring 
buffer.
- Proper lock taken before reading ring buffer indices.

Changes since v3:
- Moved the call to DEFINE_XEN_FLEX_RING from vpl011.h to public/console.h. 
This macro defines
  standard functions to operate on the ring buffer.
- Lock taken while updating the interrupt mask and clear registers in 
mmio_write.
- Use gfn_t instead of xen_pfn_t.
- vgic_free_virq called if there is any error in vpl011 initialization.
- mmio handlers freed if there is any error in vpl011 initialization.
- Removed vpl011->initialized flag usage as the same check could be done 
  using vpl011->ring-ref.
- Used return instead of break in the switch handling of emulation of different 
pl011 registers.
- Renamed vpl011_update_spi() to vpl011_update().

Changes since v2:
- Use generic vreg_reg* for read/write of registers emulating pl011.
- Use generic ring buffer functions defined using DEFINE_XEN_FLEX_RING.
- Renamed the SPI injection function to vpl011_update_spi() to reflect level 
  triggered nature of pl011 interrupts.
- The pl011 register access address should always be the base address of the
  corresponding register as per section B of the SBSA document. For this reason,
  the register range address access is not allowed.

Changes since v1:
- Removed the optimiztion related to sendiing events to xenconsole 
- Use local variables as ring buffer indices while using the ring buffer

 xen/arch/arm/Kconfig |   7 +
 xen/arch/arm/Makefile|   1 +
 xen/arch/arm/vpl011.c| 454 +++
 xen/include/asm-arm/domain.h |   6 +
 xen/include/asm-arm/pl011-uart.h |   2 +
 xen/include/asm-arm/vpl011.h |  72 +++
 xen/include/public/arch-arm.h|   6 +
 7 files changed, 548 insertions(+)
 create mode 100644 xen/arch/arm/vpl011.c
 create mode 100644 xen/include/asm-arm/vpl011.h

diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index d46b98c..f58019d 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -50,6 +50,13 @@ config HAS_ITS
 prompt "GICv3 ITS MSI controller support" if EXPERT = "y"
 depends on HAS_GICV3
 
+config SBSA_VUART_CONSOLE
+   bool "Emulated SBSA UART console support"
+   default y
+   ---help---
+ Allows a guest to use SBSA Generic UART as a console. The
+ SBSA Generic UART implements a subset of ARM PL011 UART.
+
 endmenu
 
 menu "ARM errata workaround via the alternative framework"
diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 17bff98..424580b 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_HAS_GICV3) += vgic-v3.o
 obj-$(CONFIG_HAS_ITS) += vgic-v3-its.o
 obj-y += vm_event.o
 obj-y += vtimer.o
+obj-$(CONFIG_SBSA_VUART_CONSOLE) += vpl011.o
 obj-y += vpsci.o
 obj-y += vuart.o
 
diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
new file mode 100644
index 000..56d9cbe
--- /dev/null
+++ b/xen/arch/arm/vpl011.c
@@ -0,0 +1,454 @@
+/*
+ * arch/arm/vpl011.c
+ *
+ * Virtual PL011 UART
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the 

[Xen-devel] [PATCH 18/27 v11] xen/arm: vpl011: Add a new console_cleanup function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a new console_cleanup function. This function
frees up the console resources.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v6:
- Removed a null pointer check before calling free() as free() already checks 
that.

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 5c6da31..ff69e52 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -768,12 +768,8 @@ static void remove_domain(struct domain *dom)
}
 }
 
-static void cleanup_domain(struct domain *d)
+static void console_cleanup(struct console *con)
 {
-   struct console *con = &d->console;
-
-   console_close_tty(con);
-
if (con->log_fd != -1) {
close(con->log_fd);
con->log_fd = -1;
@@ -784,6 +780,15 @@ static void cleanup_domain(struct domain *d)
 
free(con->xspath);
con->xspath = NULL;
+}
+
+static void cleanup_domain(struct domain *d)
+{
+   struct console *con = &d->console;
+
+   console_close_tty(con);
+
+   console_cleanup(con);
 
remove_domain(d);
 }
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 00/27 v11] SBSA UART emulation support in Xen

2017-09-26 Thread Bhupinder Thakur
y the UEFI firmware so that all debug output
   is redirected to this port.

2. Linux seems to have hvc console as the default console i.e. if no
   console is specified then it uses hvc as the console. How can an 
   option be provided in Linux to select either hvc or pl011 as the 
   default console.

   It was suggeted to use the SPCR in ACPI and the stdout-path option in the
   device tree to specify the default console. However, currently hvc console
   is not describable in the ACPI/device tree. This support will have to be
   added to allow the user to specify the default console.

3. ACPI support for pl011 device.

CC: Andrew Cooper 
CC: George Dunlap 
CC: Ian Jackson 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Wei Liu 
CC: Julien Grall 
CC: Andre Przywara 

Bhupinder Thakur (27):
  xen/arm: vpl011: Define common ring buffer helper functions in
console.h
  xen/arm: vpl011: Add SBSA UART emulation in Xen
  xen/arm: vpl011: Allocate a new GFN in the toolstack for vuart
  xen/arm: vpl011: Add support for vuart in libxl
  xen/arm: vpl011: Rearrange xen header includes in alphabetical order
in domctl.c
  xen/arm: vpl011: Add a new domctl API to initialize vpl011
  xen/arm: vpl011: Add a new vuart node in the xenstore
  xen/arm: vpl011: Modify xenconsole to define and use a new console
structure
  xen/arm: vpl011: Rename the console structure field conspath to xspath
  xen/arm: vpl011: Modify xenconsole functions to take console structure
as input
  xen/arm: vpl011: Add a new console_init function in xenconsole
  xen/arm: vpl011: Add a new buffer_available function in xenconsole
  xen/arm: vpl011: Add a new maybe_add_console_evtchn_fd function in
xenconsole
  xen/arm: vpl011: Add a new maybe_add_console_tty_fd function in
xenconsole
  xen/arm: vpl011: Add a new console_evtchn_unmask function in
xenconsole
  xen/arm: vpl011: Add a new handle_console_ring function in xenconsole
  xen/arm: vpl011: Add a new handle_console_tty function in xenconsole
  xen/arm: vpl011: Add a new console_cleanup function in xenconsole
  xen/arm: vpl011: Add a new console_open_log function in xenconsole
  xen/arm: vpl011: Add a new console_close_evtchn function in xenconsole
  xen/arm: vpl011: Add support for multiple consoles in xenconsole
  xen/arm: vpl011: Add support for vuart console in xenconsole
  xen/arm: vpl011: Add a new vuart console type to xenconsole client
  xen/arm: vpl011: Add a pl011 uart DT node in the guest device tree
  xen/arm: vpl011: Update documentation for vuart console support
  xen/arm: vpl011: Fix the slow early console SBSA UART output
  xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA
UART TX interrupt

 docs/man/xl.cfg.pod.5.in |  12 +
 docs/misc/console.txt|  44 ++-
 tools/console/Makefile   |   3 +-
 tools/console/client/main.c  |  13 +-
 tools/console/daemon/io.c| 661 +++
 tools/libxc/include/xc_dom.h |   2 +
 tools/libxc/include/xenctrl.h|  20 ++
 tools/libxc/xc_dom_arm.c |   5 +-
 tools/libxc/xc_dom_boot.c|   2 +
 tools/libxc/xc_domain.c  |  27 ++
 tools/libxl/libxl.h  |   7 +
 tools/libxl/libxl_arch.h |   7 +
 tools/libxl/libxl_arm.c  |  89 +
 tools/libxl/libxl_console.c  |  47 +++
 tools/libxl/libxl_create.c   |   9 +-
 tools/libxl/libxl_device.c   |   9 +-
 tools/libxl/libxl_dom.c  |   5 +
 tools/libxl/libxl_internal.h |   6 +
 tools/libxl/libxl_types.idl  |   7 +
 tools/libxl/libxl_types_internal.idl |   1 +
 tools/libxl/libxl_x86.c  |   8 +
 tools/xl/xl_cmdtable.c   |   2 +-
 tools/xl/xl_console.c|   5 +-
 tools/xl/xl_parse.c  |   8 +
 xen/arch/arm/Kconfig |   7 +
 xen/arch/arm/Makefile|   1 +
 xen/arch/arm/domain.c|   6 +
 xen/arch/arm/domctl.c|  58 ++-
 xen/arch/arm/vpl011.c| 496 ++
 xen/include/Makefile |   1 +
 xen/include/asm-arm/domain.h |   6 +
 xen/include/asm-arm/pl011-uart.h |   2 +
 xen/include/asm-arm/vpl011.h |  74 
 xen/include/public/arch-arm.h|   6 +
 xen/include/public/domctl.h  |  24 ++
 xen/include/public/io/console.h  |   6 +
 36 files changed, 1445 insertions(+), 241 deletions(-)
 create mode 100644 xen/arch/arm/vpl011.c
 create mode 100644 xen/include/asm-arm/vpl011.h

-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 14/27 v11] xen/arm: vpl011: Add a new maybe_add_console_tty_fd function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a new maybe_add_console_tty_fd function. This function
adds the tty fd to the list of polled fds.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v6:
- Renamed add_console_tty_fd to maybe_add_console_tty_fd since it 
  adds the tty FD to the poll list conditionally.
- I have retained the reviewed-by tag as only the function name has been
  changed.

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 30 +-
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 3483252..a0b35da 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -1067,6 +1067,22 @@ static void maybe_add_console_evtchn_fd(struct console 
*con, void *data)
*((long long *)data) = next_timeout;
 }
 
+static void maybe_add_console_tty_fd(struct console *con)
+{
+   if (con->master_fd != -1) {
+   short events = 0;
+   if (!con->d->is_dead && ring_free_bytes(con))
+   events |= POLLIN;
+
+   if (!buffer_empty(&con->buffer))
+   events |= POLLOUT;
+
+   if (events)
+   con->master_pollfd_idx =
+   set_fds(con->master_fd, events|POLLPRI);
+   }
+}
+
 void handle_io(void)
 {
int ret;
@@ -1146,19 +1162,7 @@ void handle_io(void)
 
maybe_add_console_evtchn_fd(con, (void *)&next_timeout);
 
-   if (con->master_fd != -1) {
-   short events = 0;
-   if (!d->is_dead && ring_free_bytes(con))
-   events |= POLLIN;
-
-   if (!buffer_empty(&con->buffer))
-   events |= POLLOUT;
-
-   if (events)
-   con->master_pollfd_idx =
-   set_fds(con->master_fd,
-   events|POLLPRI);
-   }
+   maybe_add_console_tty_fd(con);
}
 
/* If any domain has been rate limited, we need to work
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 07/27 v11] xen/arm: vpl011: Add a new vuart node in the xenstore

2017-09-26 Thread Bhupinder Thakur
Add a new vuart console node to xenstore. This node is added at

/local/domain/$DOMID/vuart/0.

The node contains information such as the ring-ref, event channel,
buffer limit and type of console.

Xenconsole reads the node information to setup the ring buffer and
event channel for sending/receiving vuart data.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v4:
-  vuart_device moved inside libxl__device_vuart_add() as a local variable.

Changes since v3:
- Added a backend node for vpl011.
- Removed libxl__device_vuart_add() for HVM guest. It is called only for PV 
guest.

 tools/libxl/libxl_console.c  | 44 
 tools/libxl/libxl_create.c   |  9 +++-
 tools/libxl/libxl_device.c   |  9 ++--
 tools/libxl/libxl_internal.h |  3 +++
 tools/libxl/libxl_types_internal.idl |  1 +
 5 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index f4f64ad..0db9cd0 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -344,6 +344,50 @@ out:
 return rc;
 }
 
+int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
+libxl__device_console *console,
+libxl__domain_build_state *state)
+{
+libxl__device device;
+flexarray_t *ro_front;
+flexarray_t *back;
+int rc;
+
+ro_front = flexarray_make(gc, 16, 1);
+back = flexarray_make(gc, 16, 1);
+
+device.backend_devid = console->devid;
+device.backend_domid = console->backend_domid;
+device.backend_kind = LIBXL__DEVICE_KIND_VUART;
+device.devid = console->devid;
+device.domid = domid;
+device.kind = LIBXL__DEVICE_KIND_VUART;
+
+flexarray_append(back, "frontend-id");
+flexarray_append(back, GCSPRINTF("%d", domid));
+flexarray_append(back, "online");
+flexarray_append(back, "1");
+flexarray_append(back, "state");
+flexarray_append(back, GCSPRINTF("%d", XenbusStateInitialising));
+flexarray_append(back, "protocol");
+flexarray_append(back, LIBXL_XENCONSOLE_PROTOCOL);
+
+flexarray_append(ro_front, "port");
+flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
+flexarray_append(ro_front, "ring-ref");
+flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
+flexarray_append(ro_front, "limit");
+flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT));
+flexarray_append(ro_front, "type");
+flexarray_append(ro_front, "xenconsoled");
+
+rc = libxl__device_generic_add(gc, XBT_NULL, &device,
+   libxl__xs_kvs_of_flexarray(gc, back),
+   NULL,
+   libxl__xs_kvs_of_flexarray(gc, ro_front));
+return rc;
+}
+
 int libxl__init_console_from_channel(libxl__gc *gc,
  libxl__device_console *console,
  int dev_num,
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 0ef54d2..9dcbe48 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1370,7 +1370,7 @@ static void domcreate_launch_dm(libxl__egc *egc, 
libxl__multidev *multidev,
 }
 case LIBXL_DOMAIN_TYPE_PV:
 {
-libxl__device_console console;
+libxl__device_console console, vuart;
 libxl__device device;
 
 for (i = 0; i < d_config->num_vfbs; i++) {
@@ -1380,6 +1380,13 @@ static void domcreate_launch_dm(libxl__egc *egc, 
libxl__multidev *multidev,
   &d_config->vkbs[i]);
 }
 
+if (d_config->b_info.arch_arm.vuart == LIBXL_VUART_TYPE_SBSA_UART) {
+init_console_info(gc, &vuart, 0);
+vuart.backend_domid = state->console_domid;
+libxl__device_vuart_add(gc, domid, &vuart, state);
+libxl__device_console_dispose(&vuart);
+}
+
 init_console_info(gc, &console, 0);
 console.backend_domid = state->console_domid;
 libxl__device_console_add(gc, domid, &console, state, &device);
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 67b7afb..3473687 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -26,6 +26,9 @@ static char *libxl__device_frontend_path(libxl__gc *gc, 
libxl__device *device)
 if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
 return GCSPRINTF("%s/console", dom_path);
 
+if (device->kind == LIBXL__DEVICE_KIND_VUART)
+return GCS

[Xen-devel] [PATCH 19/27 v11] xen/arm: vpl011: Add a new console_open_log function in xenconsole

2017-09-26 Thread Bhupinder Thakur
This patch introduces a console_open_log console_cleanup function. This function
opens the console log file.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index ff69e52..cfd7273 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -1038,6 +1038,15 @@ static void handle_hv_logs(xenevtchn_handle *xce_handle, 
bool force)
(void)xenevtchn_unmask(xce_handle, port);
 }
 
+static void console_open_log(struct console *con)
+{
+   if (console_enabled(con)) {
+   if (con->log_fd != -1)
+   close(con->log_fd);
+   con->log_fd = create_console_log(con);
+   }
+}
+
 static void handle_log_reload(void)
 {
if (log_guest) {
@@ -1045,9 +1054,7 @@ static void handle_log_reload(void)
for (d = dom_head; d; d = d->next) {
struct console *con = &d->console;
 
-   if (con->log_fd != -1)
-   close(con->log_fd);
-   con->log_fd = create_console_log(con);
+   console_open_log(con);
}
}
 
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH] xen/arm: Fix the issue in cmp_mmio_handler used in find_mmio_handler

2017-09-26 Thread Bhupinder Thakur
This function returns true/false based on whether the key value
is in the range (start, start+size). However, it should check against
(start, start+size-1) because start+size falls outside the range.

This resulted in returning a wrong mmio_handler for a given mmio address which
happened to be start+size.

Signed-off-by: Bhupinder Thakur 
---
CC: Stefano Stabellini 
CC: Julien Grall 

 xen/arch/arm/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/arm/io.c b/xen/arch/arm/io.c
index e216128..c748d8f 100644
--- a/xen/arch/arm/io.c
+++ b/xen/arch/arm/io.c
@@ -79,7 +79,7 @@ static int cmp_mmio_handler(const void *key, const void *elem)
 if ( handler0->addr < handler1->addr )
 return -1;
 
-if ( handler0->addr > (handler1->addr + handler1->size) )
+if ( handler0->addr >= (handler1->addr + handler1->size) )
 return 1;
 
 return 0;
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 01/27 v10] xen/arm: vpl011: Define common ring buffer helper functions in console.h

2017-09-26 Thread Bhupinder Thakur
Hi Jan,

On 26 September 2017 at 12:45, Jan Beulich  wrote:
 On 26.09.17 at 01:08,  wrote:
>> Yes, after including the __STRICT_ANSI__ check the headers.chk check
>> passes. But I had to include string header file (after suggestion from
>> Stefano) for fixing the headers++.chk.
>
> I'd like to have a more detailed explanation here - since the header
> passed the check without this prereq before, I'd prefer if the
> dependency was not added unconditionally.

The C header passed the check without the prereq addition. However,
for C++ headers since
__STRICT_ANSI__ is not defined, it tries to expand the
DEFINE_XEN_FLEX_RING macro
and looks for declarations for size_t, memcpy() etc. To satisfy that
requirement, string header
file had to included similar to what was done for pvcalls.

>
>> --- a/xen/include/public/io/console.h
>> +++ b/xen/include/public/io/console.h
>> @@ -40,7 +40,9 @@ struct xencons_interface {
>>  XENCONS_RING_IDX out_cons, out_prod;
>>  };
>>
>> +#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
>>  DEFINE_XEN_FLEX_RING(xencons);
>> +#endif
>
> At the first glance it also looks as if the scope of this conditional
> was too narrow.

Do you mean that xencons_interface should also be under ifdef?

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 01/27 v10] xen/arm: vpl011: Define common ring buffer helper functions in console.h

2017-09-25 Thread Bhupinder Thakur
Hi Jan,

Yes, after including the __STRICT_ANSI__ check the headers.chk check
passes. But I had to include string header file (after suggestion from Stefano)
for fixing the headers++.chk.

I have pasted the changes below:

diff --git a/xen/include/Makefile b/xen/include/Makefile
index 1299b19..c90fdee 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -98,6 +98,7 @@ PUBLIC_C99_HEADERS := public/io/9pfs.h public/io/pvcalls.h
 PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/%
public/%hvm/save.h $(PUBLIC_C99_HEADERS), $(PUBLIC_HEADERS))

 public/io/9pfs.h-prereq := string
+public/io/console.h-prereq := string
 public/io/pvcalls.h-prereq := string

 headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile
diff --git a/xen/include/public/io/console.h b/xen/include/public/io/console.h
index 5e45e1c..0f0711f 100644
--- a/xen/include/public/io/console.h
+++ b/xen/include/public/io/console.h
@@ -40,7 +40,9 @@ struct xencons_interface {
 XENCONS_RING_IDX out_cons, out_prod;
 };

+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
 DEFINE_XEN_FLEX_RING(xencons);
+#endif

 #endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */

Regards,
Bhupinder

On 25 September 2017 at 08:49, Jan Beulich  wrote:
>>>> On 23.09.17 at 00:44,  wrote:
>> On Fri, 22 Sep 2017, Bhupinder Thakur wrote:
>>> DEFINE_XEN_FLEX_RING(xencons) defines common helper functions such as
>>> xencons_queued() to tell the current size of the ring buffer,
>>> xencons_mask() to mask off the index, which are useful helper functions.
>>> pl011 emulation code will use these helper functions.
>>>
>>> io/console.h includes io/ring.h which defines DEFINE_XEN_FLEX_RING.
>>>
>>> In console/daemon/io.c, string.h had to be included before io/console.h
>>> because ring.h uses string functions.
>>>
>>> Signed-off-by: Bhupinder Thakur 
>>> Reviewed-by: Stefano Stabellini 
>>> Acked-by: Wei Liu 
>>> Acked-by: Konrad Rzeszutek Wilk 
>>
>> Unfortunately this patch breaks the build on x86. The reason is that
>> DEFINE_XEN_FLEX_RING requires C99, and the current header checks in
>> xen/include/Makefile use ANSI C.
>>
>> The only two headers to use DEFINE_XEN_FLEX_RING so far are pvcalls and
>> 9pfs that are both explicitly marked as c99 in xen/include/Makefile, see
>> PUBLIC_C99_HEADERS.
>>
>> One way to solve this problem would be to mark console.h as one of the
>> c99 headers, but I am guessing that Jan will want to keep it ANSI C.
>>
>> In that case, we could make DEFINE_XEN_FLEX_RING ANSI C, which is ugly
>> but possible. It requires turning the static inline functions in ring.h
>> into macros.
>>
>> Otherwise, we could take DEFINE_XEN_FLEX_RING(xencons) out of
>> io/console.h. We could move it to a new header file, and the new header
>> file could be C99.
>>
>> Jan, do you have other suggestions?
>
> Moving the C99 requiring parts to a separate header is certainly
> a reasonable option. Another might be to frame the additions by
> a __STRICT_ANSI__ and/or __GNUC__ and/or __STDC_VERSION__
> check (we have some examples elsewhere, but they may not be
> exact fits for the case here).
>
> Jan
>

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 01/27 v10] xen/arm: vpl011: Define common ring buffer helper functions in console.h

2017-09-23 Thread Bhupinder Thakur
Hi,

On 23 September 2017 at 18:55, Julien Grall  wrote:
> Hi,
>
> On 09/22/2017 11:44 PM, Stefano Stabellini wrote:
>>
>> Adding Jan
>>
>> On Fri, 22 Sep 2017, Bhupinder Thakur wrote:
>>>
>>> DEFINE_XEN_FLEX_RING(xencons) defines common helper functions such as
>>> xencons_queued() to tell the current size of the ring buffer,
>>> xencons_mask() to mask off the index, which are useful helper functions.
>>> pl011 emulation code will use these helper functions.
>>>
>>> io/console.h includes io/ring.h which defines DEFINE_XEN_FLEX_RING.
>>>
>>> In console/daemon/io.c, string.h had to be included before io/console.h
>>> because ring.h uses string functions.
>>>
>>> Signed-off-by: Bhupinder Thakur 
>>> Reviewed-by: Stefano Stabellini 
>>> Acked-by: Wei Liu 
>>> Acked-by: Konrad Rzeszutek Wilk 
>>
>>
>> Unfortunately this patch breaks the build on x86.
>
>
> I am a bit surprised that this breaks only build on x86. I was expecting the
> header checks to be done on all the architecture ... hmmm... looking at the
> Makefile, the checks is only done when building natively. I guess you are
> cross-compiling?

>
> It might be interesting to look at getting headers check in cross-compile
> environment given that this is the main way to build the hypervisor today.
>
Yes I am doing cross-compilation.

>> The reason is that
>> DEFINE_XEN_FLEX_RING requires C99, and the current header checks in
>> xen/include/Makefile use ANSI C.
>
>
> I was not able to spot why DEFINE_XEN_FLEX_RING would require C99. Can you
> detail it?
This macro expands to generate inline functions, which I believe
require C99 to compile.

Regards,
Bhupinder

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 27/27 v10] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt

2017-09-22 Thread Bhupinder Thakur
This patch fixes the issue observed when pl011 patches were tested on
the junos hardware by Andre/Julien. It was observed that when large output is
generated such as on running 'find /', output was getting truncated 
intermittently
due to OUT ring buffer getting full.

This issue was due to the fact that the SBSA UART driver expects that when
a TX interrupt is asserted then the FIFO queue should be atleast half empty and
that it can write N bytes in the FIFO, where N is half the FIFO queue size, 
without
the bytes getting dropped due to FIFO getting full.

The SBSA UART emulation logic was asserting the TX interrupt as soon as
any space became available in the FIFO and the SBSA UART driver tried to write
more data (upto 16 bytes) in the FIFO expecting that there is enough space
available leading to dropped bytes.

The SBSA spec [1] does not specify when the TX interrupt should be asserted
or de-asserted. Due to lack of clarity on the expected behavior, it is
assumed for now that TX interrupt should be asserted only when the FIFO goes
half empty.

TBD: Once the SBSA spec is updated with the expected behavior, the 
implementation
will be modified to align with the spec requirement.

[1] http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf

Signed-off-by: Bhupinder Thakur 
---
CC: Julien Grall 
CC: Andre Przywara 
CC: Stefano Stabellini 

Changes since v8:
- Used variables fifo_level/fifo_threshold for more clarity
- Added a new macro SBSA_UART_FIFO_SIZE instead of using a magic number
- Renamed ring_qsize variables to fifo_level for consistency 

 xen/arch/arm/vpl011.c| 87 ++--
 xen/include/asm-arm/vpl011.h |  2 +
 2 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
index 36794d8..1f97261 100644
--- a/xen/arch/arm/vpl011.c
+++ b/xen/arch/arm/vpl011.c
@@ -91,20 +91,24 @@ static uint8_t vpl011_read_data(struct domain *d)
  */
 if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) > 0 )
 {
+unsigned int fifo_level;
+
 data = intf->in[xencons_mask(in_cons, sizeof(intf->in))];
 in_cons += 1;
 smp_mb();
 intf->in_cons = in_cons;
+
+fifo_level = xencons_queued(in_prod, in_cons, sizeof(intf->in));
+
+if ( fifo_level == 0 )
+{
+vpl011->uartfr |= RXFE;
+vpl011->uartris &= ~RXI;
+}
 }
 else
 gprintk(XENLOG_ERR, "vpl011: Unexpected IN ring buffer empty\n");
 
-if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) == 0 )
-{
-vpl011->uartfr |= RXFE;
-vpl011->uartris &= ~RXI;
-}
-
 vpl011->uartfr &= ~RXFF;
 
 vpl011_update_interrupt_status(d);
@@ -144,28 +148,41 @@ static void vpl011_write_data(struct domain *d, uint8_t 
data)
 if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) !=
  sizeof (intf->out) )
 {
+unsigned int fifo_level, fifo_threshold;
+
 intf->out[xencons_mask(out_prod, sizeof(intf->out))] = data;
 out_prod += 1;
 smp_wmb();
 intf->out_prod = out_prod;
-}
-else
-gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n");
 
-if ( xencons_queued(out_prod, out_cons, sizeof(intf->out)) ==
- sizeof (intf->out) )
-{
-vpl011->uartfr |= TXFF;
-vpl011->uartris &= ~TXI;
+fifo_level = xencons_queued(out_prod, out_cons, sizeof(intf->out));
+
+if ( fifo_level == sizeof (intf->out) )
+{
+vpl011->uartfr |= TXFF;
+
+/*
+ * This bit is set only when FIFO becomes full. This ensures that
+ * the SBSA UART driver can write the early console data as fast as
+ * possible, without waiting for the BUSY bit to get cleared before
+ * writing each byte.
+ */
+vpl011->uartfr |= BUSY;
+}
 
 /*
- * This bit is set only when FIFO becomes full. This ensures that
- * the SBSA UART driver can write the early console data as fast as
- * possible, without waiting for the BUSY bit to get cleared before
- * writing each byte.
+ * Clear the TXI bit if the fifo level exceeds fifo_size/2 mark which
+ * is the trigger level for asserting/de-assterting the TX interrupt.
  */
-vpl011->uartfr |= BUSY;
+fifo_threshold = sizeof (intf->out) - SBSA_UART_FIFO_SIZE/2;
+
+if ( fifo_level <= fifo_threshold )
+vpl011->uartris |= TXI;
+else
+vpl011->uartris &= ~TXI;
 }
+else
+gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n");
 
 vpl011->uartfr &= ~TXFE;
 
@@ -342,7 +359,7 @@ static void vpl011_data_avail(struct domain *d)
   

[Xen-devel] [PATCH 25/27 v10] xen/arm: vpl011: Update documentation for vuart console support

2017-09-22 Thread Bhupinder Thakur
1. Update documentation for a new vuart option added.
2. Update documentation about SPI irq reserved for vuart.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Andrew Cooper 
CC: George Dunlap 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Julien Grall 

Changes since v6:
- Added a new section for vuart usage.
- I have retained the reviewed-by/acked-by tags as this is a limited change. 
Kindly
  review.

Changes since v4:
- Minor change to rename "pl011" to "sbsa_uart". Since it is a minor change I 
have
  retained the reviewed-by and acked-by tags.

 docs/man/xl.cfg.pod.5.in | 12 
 docs/misc/console.txt| 44 +---
 2 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in
index 247ae99..f1d2a7a 100644
--- a/docs/man/xl.cfg.pod.5.in
+++ b/docs/man/xl.cfg.pod.5.in
@@ -1105,6 +1105,9 @@ Allow a guest to access specific physical IRQs.
 It is recommended to only use this option for trusted VMs under
 administrator's control.
 
+If vuart console is enabled then irq 32 is reserved for it. See
+L to know how to enable vuart console.
+
 =item B
 
 Limit the guest to using at most N event channels (PV interrupts).
@@ -2220,6 +2223,15 @@ the domain was created.
 This requires hardware compatibility with the requested version, either
 natively or via hardware backwards compatibility support.
 
+=item B
+
+To enable vuart console, user must specify the following option in the
+VM config file:
+
+vuart = "sbsa_uart"
+
+Currently, only the "sbsa_uart" model is supported for ARM.
+
 =back
 
 =head3 x86
diff --git a/docs/misc/console.txt b/docs/misc/console.txt
index 16da805..4e180f8 100644
--- a/docs/misc/console.txt
+++ b/docs/misc/console.txt
@@ -19,7 +19,20 @@ The first PV console path in xenstore remains:
 
 /local/domain/$DOMID/console
 
-the other PV consoles follow the conventional xenstore device path and
+The virtual UART console path in xenstore is defined as:
+
+/local/domain/$DOMID/vuart/0
+
+The vuart console provides access to a virtual SBSA UART on ARM systems.
+To enable vuart the following line has to be added to the guest configuration
+file:
+
+vuart = "sbsa_uart"
+
+In Linux you can select the virtual SBSA UART by using the "ttyAMA0"
+console instead of "hvc0".
+
+The other PV consoles follow the conventional xenstore device path and
 live in:
 
 /local/domain/$DOMID/device/console/$DEVID.
@@ -61,6 +74,14 @@ output = pty
 The backend will write the pty device name to the "tty" node in the
 console frontend.
 
+For the PV console the tty node is added at
+
+/local/domain/$DOMID/console/tty
+
+For the virtual UART console the tty node is added at
+
+/local/domain/$DOMID/vuart/0/tty
+
 If the toolstack wants a listening Unix domain socket to be created at path
 , a connection accepted and data proxied to the console, it will write:
 
@@ -79,8 +100,8 @@ For example:
 ioemu
 
 The supported values are only xenconsoled or ioemu; xenconsoled has
-several limitations: it can only be used for the first PV console and it
-can only connect to a pty.
+several limitations: it can only be used for the first PV or virtual UART
+console and it can only connect to a pty.
 
 Emulated serials are provided by qemu-dm only to hvm guests; the number
 of emulated serials depends on how many "-serial" command line options
@@ -90,14 +111,15 @@ xenstore in the following path:
 
 /local/domain/$DOMID/serial/$SERIAL_NUM/tty
 
-xenconsole is the tool to connect to a PV console or an emulated serial
-that has a pty as output. Xenconsole takes a domid as parameter plus an
-optional console type (pv for PV consoles or serial for emulated
-serials) and console number. Depending on the type and console
-number, xenconsole will look for the tty node in different xenstore
-paths, as described above.  If the user doesn't specify the console type
-xenconsole will try to guess: if the guest is a pv guest it defaults to
-PV console, if the guest is an hvm guest it defaults to emulated serial.
+xenconsole is the tool to connect to a PV or virtual UART console or an
+emulated serial that has a pty as output. Xenconsole takes a domid as
+parameter plus an optional console type (pv for PV consoles, vuart for
+virtual UART or serial for emulated serials) and console number.
+Depending on the type and console number, xenconsole will look for the tty
+node in different xenstore paths, as described above.  If the user doesn't
+specify the console type xenconsole will try to guess: if the guest is a pv
+guest it defaults to PV console, if the guest is an hvm guest it defaults to
+emulated serial.
 
 By default xl creates a pv console for hvm guests, plus an emulated
 serial if the user specified 'serial = "

[Xen-devel] [PATCH 26/27 v10] xen/arm: vpl011: Fix the slow early console SBSA UART output

2017-09-22 Thread Bhupinder Thakur
The early console output uses pl011_early_write() to write data. This
function waits for BUSY bit to get cleared before writing the next byte.

In the SBSA UART emulation logic, the BUSY bit was set as soon one
byte was written in the FIFO and it remained set until the FIFO was
emptied. This meant that the output was delayed as each character needed
the BUSY to get cleared.

Since the SBSA UART is getting emulated in Xen using ring buffers, it
ensures that once the data is enqueued in the FIFO, it will be received
by xenconsole so it is safe to set the BUSY bit only when FIFO becomes
full. This will ensure that pl011_early_write() is not delayed unduly
to write the data.

Signed-off-by: Bhupinder Thakur 
---
CC: Julien Grall 
CC: Andre Przywara 
CC: Stefano Stabellini 

 xen/arch/arm/vpl011.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
index 56d9cbe..36794d8 100644
--- a/xen/arch/arm/vpl011.c
+++ b/xen/arch/arm/vpl011.c
@@ -157,9 +157,15 @@ static void vpl011_write_data(struct domain *d, uint8_t 
data)
 {
 vpl011->uartfr |= TXFF;
 vpl011->uartris &= ~TXI;
-}
 
-vpl011->uartfr |= BUSY;
+/*
+ * This bit is set only when FIFO becomes full. This ensures that
+ * the SBSA UART driver can write the early console data as fast as
+ * possible, without waiting for the BUSY bit to get cleared before
+ * writing each byte.
+ */
+vpl011->uartfr |= BUSY;
+}
 
 vpl011->uartfr &= ~TXFE;
 
@@ -369,11 +375,16 @@ static void vpl011_data_avail(struct domain *d)
 {
 vpl011->uartfr &= ~TXFF;
 vpl011->uartris |= TXI;
+
+/*
+ * Clear the BUSY bit as soon as space becomes available
+ * so that the SBSA UART driver can start writing more data
+ * without any further delay.
+ */
+vpl011->uartfr &= ~BUSY;
+
 if ( out_ring_qsize == 0 )
-{
-vpl011->uartfr &= ~BUSY;
 vpl011->uartfr |= TXFE;
-}
 }
 
 vpl011_update_interrupt_status(d);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 23/27 v10] xen/arm: vpl011: Add a new vuart console type to xenconsole client

2017-09-22 Thread Bhupinder Thakur
Add a new console type VUART to connect to guest's emualated vuart
console.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v4:
- Removed the vuart compile time flag so that vuart code is compiled always.

Changes since v3:
- The vuart console support is under CONFIG_VUART_CONSOLE option.
- Since there is a change from last review, I have not included
  reviewed-by tag from Stefano and acked-by tag from Wei.

 tools/console/client/main.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/console/client/main.c b/tools/console/client/main.c
index c340cb7..f92ad3d 100644
--- a/tools/console/client/main.c
+++ b/tools/console/client/main.c
@@ -76,7 +76,7 @@ static void usage(const char *program) {
   "\n"
   "  -h, --help   display this help and exit\n"
   "  -n, --num N  use console number N\n"
-  "  --type TYPE  console type. must be 'pv' or 'serial'\n"
+  "  --type TYPE  console type. must be 'pv', 'serial' or 
'vuart'\n"
   "  --start-notify-fd N file descriptor used to notify parent\n"
   , program);
 }
@@ -264,6 +264,7 @@ typedef enum {
CONSOLE_INVAL,
CONSOLE_PV,
CONSOLE_SERIAL,
+   CONSOLE_VUART,
 } console_type;
 
 static struct termios stdin_old_attr;
@@ -344,6 +345,7 @@ int main(int argc, char **argv)
char *end;
console_type type = CONSOLE_INVAL;
bool interactive = 0;
+   char *console_names = "serial, pv, vuart";
 
while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
switch(ch) {
@@ -359,9 +361,12 @@ int main(int argc, char **argv)
type = CONSOLE_SERIAL;
else if (!strcmp(optarg, "pv"))
type = CONSOLE_PV;
+   else if (!strcmp(optarg, "vuart"))
+   type = CONSOLE_VUART;
else {
fprintf(stderr, "Invalid type argument\n");
-   fprintf(stderr, "Console types supported are: 
serial, pv\n");
+   fprintf(stderr, "Console types supported are: 
%s\n",
+   console_names);
exit(EINVAL);
}
break;
@@ -437,6 +442,10 @@ int main(int argc, char **argv)
else
snprintf(path, strlen(dom_path) + 
strlen("/device/console/%d/tty") + 5, "%s/device/console/%d/tty", dom_path, 
num);
}
+   if (type == CONSOLE_VUART) {
+   snprintf(path, strlen(dom_path) + strlen("/vuart/0/tty") + 1,
+"%s/vuart/0/tty", dom_path);
+   }
 
/* FIXME consoled currently does not assume domain-0 doesn't have a
   console which is good when we break domain-0 up.  To keep us
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 12/27 v10] xen/arm: vpl011: Add a new buffer_available function in xenconsole

2017-09-22 Thread Bhupinder Thakur
This patch introduces a new buffer_available function to check if
more data is allowed to be buffered.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 1da08d7..0009bbe 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -163,6 +163,16 @@ static int write_with_timestamp(int fd, const char *data, 
size_t sz,
return 0;
 }
 
+static inline bool buffer_available(struct console *con)
+{
+   if (discard_overflowed_data ||
+   !con->buffer.max_capacity ||
+   con->buffer.size < con->buffer.max_capacity)
+   return true;
+   else
+   return false;
+}
+
 static void buffer_append(struct console *con)
 {
struct buffer *buffer = &con->buffer;
@@ -1120,9 +1130,7 @@ void handle_io(void)
con->next_period < next_timeout)
next_timeout = con->next_period;
} else if (con->xce_handle != NULL) {
-   if (discard_overflowed_data ||
-   !con->buffer.max_capacity ||
-   con->buffer.size < 
con->buffer.max_capacity) {
+   if (buffer_available(con)) {
int evtchn_fd = 
xenevtchn_fd(con->xce_handle);
con->xce_pollfd_idx = set_fds(evtchn_fd,

POLLIN|POLLPRI);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 17/27 v10] xen/arm: vpl011: Add a new handle_console_tty function in xenconsole

2017-09-22 Thread Bhupinder Thakur
This patch introduces a new handle_console_tty function. This function
performs read/write from/to console tty.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 35 +++
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index c361b42..5c6da31 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -1130,6 +1130,24 @@ static void maybe_add_console_tty_fd(struct console *con)
}
 }
 
+static void handle_console_tty(struct console *con)
+{
+   if (con->master_fd != -1 && con->master_pollfd_idx != -1) {
+   if (fds[con->master_pollfd_idx].revents &
+   ~(POLLIN|POLLOUT|POLLPRI))
+   console_handle_broken_tty(con, 
domain_is_valid(con->d->domid));
+   else {
+   if (fds[con->master_pollfd_idx].revents &
+   POLLIN)
+   handle_tty_read(con);
+   if (fds[con->master_pollfd_idx].revents &
+   POLLOUT)
+   handle_tty_write(con);
+   }
+   }
+   con->master_pollfd_idx = -1;
+}
+
 void handle_io(void)
 {
int ret;
@@ -1260,22 +1278,7 @@ void handle_io(void)
 
handle_console_ring(con);
 
-   if (con->master_fd != -1 && con->master_pollfd_idx != 
-1) {
-   if (fds[con->master_pollfd_idx].revents &
-   ~(POLLIN|POLLOUT|POLLPRI))
-   console_handle_broken_tty(con,
-  domain_is_valid(d->domid));
-   else {
-   if (fds[con->master_pollfd_idx].revents 
&
-   POLLIN)
-   handle_tty_read(con);
-   if (fds[con->master_pollfd_idx].revents 
&
-   POLLOUT)
-   handle_tty_write(con);
-   }
-   }
-
-   con->master_pollfd_idx = -1;
+   handle_console_tty(con);
 
if (d->last_seen != enum_pass)
shutdown_domain(d);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 24/27 v10] xen/arm: vpl011: Add a pl011 uart DT node in the guest device tree

2017-09-22 Thread Bhupinder Thakur
The SBSA UART node format is as specified in
Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt and given below:

ARM SBSA defined generic UART
--
This UART uses a subset of the PL011 registers and consequently lives
in the PL011 driver. It's baudrate and other communication parameters
cannot be adjusted at runtime, so it lacks a clock specifier here.

Required properties:
- compatible: must be "arm,sbsa-uart"
- reg: exactly one register range
- interrupts: exactly one interrupt specifier
- current-speed: the (fixed) baud rate set by the firmware

Currently the baud rate of 115200 has been selected as a default value,
which is one of the valid baud rate settings. Higher baud rate was
selected since an emulated pl011 can support any valid baud rate without
any limitation of the hardware.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v7:
- Added a TODO to avoid conflict between vpl011 irq and user specified irqs.
- Used a new bool vuart_enabled to explicitly set whether pl011 UART is 
enabled/disabled.

Changes since v6:
- Added a comment explaining why user specified IRQ should not conflict with 
vpl011
  SPI.
- Checking the vuart type explicitly against vpl011 enum type.
- Removed uart-compat string and using "arm,sbsa-uart" string directly.
- I have retained the reviewed-by/acked-by tags as these are minor changes.

 tools/libxl/libxl_arm.c | 62 +
 1 file changed, 62 insertions(+)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 2e9f780..bfb7d08 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -43,11 +43,38 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
 {
 uint32_t nr_spis = 0;
 unsigned int i;
+uint32_t vuart_irq;
+bool vuart_enabled = false;
+
+/*
+ * If pl011 vuart is enabled then increment the nr_spis to allow allocation
+ * of SPI VIRQ for pl011.
+ */
+if (d_config->b_info.arch_arm.vuart == LIBXL_VUART_TYPE_SBSA_UART) {
+nr_spis += (GUEST_VPL011_SPI - 32) + 1;
+vuart_irq = GUEST_VPL011_SPI;
+vuart_enabled = true;
+}
 
 for (i = 0; i < d_config->b_info.num_irqs; i++) {
 uint32_t irq = d_config->b_info.irqs[i];
 uint32_t spi;
 
+/*
+ * This check ensures the if user has requested pass-through of a 
certain irq
+ * which conflicts with vpl011 irq then it flags an error to indicate 
to the
+ * user that the specific HW irq cannot be used as it is dedicated for 
vpl011.
+ * 
+ * TODO:
+ * The vpl011 irq should be assigned such that it never conflicts with 
user
+ * specified irqs thereby preventing its pass-through. This TODO is for
+ * implementing that logic in future.
+ */
+if (vuart_enabled && irq == vuart_irq) {
+LOG(ERROR, "Physical IRQ %u conflicting with pl011 SPI\n", irq);
+return ERROR_FAIL;
+}
+
 if (irq < 32)
 continue;
 
@@ -590,6 +617,38 @@ static int make_hypervisor_node(libxl__gc *gc, void *fdt,
 return 0;
 }
 
+static int make_vpl011_uart_node(libxl__gc *gc, void *fdt,
+ const struct arch_info *ainfo,
+ struct xc_dom_image *dom)
+{
+int res;
+gic_interrupt intr;
+
+res = fdt_begin_node(fdt, "sbsa-pl011");
+if (res) return res;
+
+res = fdt_property_compat(gc, fdt, 1, "arm,sbsa-uart");
+if (res) return res;
+
+res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+1,
+GUEST_PL011_BASE, GUEST_PL011_SIZE);
+if (res) return res;
+
+set_interrupt(intr, GUEST_VPL011_SPI, 0xf, DT_IRQ_TYPE_LEVEL_HIGH);
+
+res = fdt_property_interrupts(gc, fdt, &intr, 1);
+if (res) return res;
+
+/* Use a default baud rate of 115200. */
+fdt_property_u32(fdt, "current-speed", 115200);
+
+res = fdt_end_node(fdt);
+if (res) return res;
+
+return 0;
+}
+
 static const struct arch_info *get_arch_info(libxl__gc *gc,
  const struct xc_dom_image *dom)
 {
@@ -889,6 +948,9 @@ next_resize:
 FDT( make_timer_node(gc, fdt, ainfo, xc_config->clock_frequency) );
 FDT( make_hypervisor_node(gc, fdt, vers) );
 
+if (info->arch_arm.vuart == LIBXL_VUART_TYPE_SBSA_UART)
+FDT( make_vpl011_uart_node(gc, fdt, ainfo, dom) );
+
 if (pfdt)
 FDT( copy_partial_fdt(gc, fdt, pfdt) );
 
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 07/27 v10] xen/arm: vpl011: Add a new vuart node in the xenstore

2017-09-22 Thread Bhupinder Thakur
Add a new vuart console node to xenstore. This node is added at

/local/domain/$DOMID/vuart/0.

The node contains information such as the ring-ref, event channel,
buffer limit and type of console.

Xenconsole reads the node information to setup the ring buffer and
event channel for sending/receiving vuart data.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v4:
-  vuart_device moved inside libxl__device_vuart_add() as a local variable.

Changes since v3:
- Added a backend node for vpl011.
- Removed libxl__device_vuart_add() for HVM guest. It is called only for PV 
guest.

 tools/libxl/libxl_console.c  | 44 
 tools/libxl/libxl_create.c   |  9 +++-
 tools/libxl/libxl_device.c   |  9 ++--
 tools/libxl/libxl_internal.h |  3 +++
 tools/libxl/libxl_types_internal.idl |  1 +
 5 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index f4f64ad..0db9cd0 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -344,6 +344,50 @@ out:
 return rc;
 }
 
+int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid,
+libxl__device_console *console,
+libxl__domain_build_state *state)
+{
+libxl__device device;
+flexarray_t *ro_front;
+flexarray_t *back;
+int rc;
+
+ro_front = flexarray_make(gc, 16, 1);
+back = flexarray_make(gc, 16, 1);
+
+device.backend_devid = console->devid;
+device.backend_domid = console->backend_domid;
+device.backend_kind = LIBXL__DEVICE_KIND_VUART;
+device.devid = console->devid;
+device.domid = domid;
+device.kind = LIBXL__DEVICE_KIND_VUART;
+
+flexarray_append(back, "frontend-id");
+flexarray_append(back, GCSPRINTF("%d", domid));
+flexarray_append(back, "online");
+flexarray_append(back, "1");
+flexarray_append(back, "state");
+flexarray_append(back, GCSPRINTF("%d", XenbusStateInitialising));
+flexarray_append(back, "protocol");
+flexarray_append(back, LIBXL_XENCONSOLE_PROTOCOL);
+
+flexarray_append(ro_front, "port");
+flexarray_append(ro_front, GCSPRINTF("%"PRIu32, state->vuart_port));
+flexarray_append(ro_front, "ring-ref");
+flexarray_append(ro_front, GCSPRINTF("%lu", state->vuart_gfn));
+flexarray_append(ro_front, "limit");
+flexarray_append(ro_front, GCSPRINTF("%d", LIBXL_XENCONSOLE_LIMIT));
+flexarray_append(ro_front, "type");
+flexarray_append(ro_front, "xenconsoled");
+
+rc = libxl__device_generic_add(gc, XBT_NULL, &device,
+   libxl__xs_kvs_of_flexarray(gc, back),
+   NULL,
+   libxl__xs_kvs_of_flexarray(gc, ro_front));
+return rc;
+}
+
 int libxl__init_console_from_channel(libxl__gc *gc,
  libxl__device_console *console,
  int dev_num,
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 0ef54d2..9dcbe48 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1370,7 +1370,7 @@ static void domcreate_launch_dm(libxl__egc *egc, 
libxl__multidev *multidev,
 }
 case LIBXL_DOMAIN_TYPE_PV:
 {
-libxl__device_console console;
+libxl__device_console console, vuart;
 libxl__device device;
 
 for (i = 0; i < d_config->num_vfbs; i++) {
@@ -1380,6 +1380,13 @@ static void domcreate_launch_dm(libxl__egc *egc, 
libxl__multidev *multidev,
   &d_config->vkbs[i]);
 }
 
+if (d_config->b_info.arch_arm.vuart == LIBXL_VUART_TYPE_SBSA_UART) {
+init_console_info(gc, &vuart, 0);
+vuart.backend_domid = state->console_domid;
+libxl__device_vuart_add(gc, domid, &vuart, state);
+libxl__device_console_dispose(&vuart);
+}
+
 init_console_info(gc, &console, 0);
 console.backend_domid = state->console_domid;
 libxl__device_console_add(gc, domid, &console, state, &device);
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 67b7afb..3473687 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -26,6 +26,9 @@ static char *libxl__device_frontend_path(libxl__gc *gc, 
libxl__device *device)
 if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
 return GCSPRINTF("%s/console", dom_path);
 
+if (device->kind == LIBXL__DEVICE_KIND_VUART)
+return GCS

[Xen-devel] [PATCH 21/27 v10] xen/arm: vpl011: Add support for multiple consoles in xenconsole

2017-09-22 Thread Bhupinder Thakur
This patch adds the support for multiple consoles and introduces the
iterator functions to operate on multiple consoles.

The functions called by the iterators check that they are operating
on valid I/O parameters. This ensures that if a particular console is
not initialized then the functions will not do anything for that
console type.

This patch is in preparation to support a new vuart console.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this patch in multiple smaller patches.

Changes since v4:
- Changes to make event channel handling per console rather than per domain.

Changes since v3:
- The changes in xenconsole have been split into four patches. This is the 
third patch.

 tools/console/daemon/io.c | 160 --
 1 file changed, 126 insertions(+), 34 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 71465a0..a198dbb 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -90,12 +90,14 @@ struct buffer {
 };
 
 struct console {
+   char *ttyname;
int master_fd;
int master_pollfd_idx;
int slave_fd;
int log_fd;
struct buffer buffer;
char *xspath;
+   char *log_suffix;
int ring_ref;
xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
@@ -107,21 +109,109 @@ struct console {
struct domain *d;
 };
 
+struct console_type {
+   char *xsname;
+   char *ttyname;
+   char *log_suffix;
+};
+
+static struct console_type console_type[] = {
+   {
+   .xsname = "/console",
+   .ttyname = "tty",
+   .log_suffix = "",
+   },
+};
+
+#define NUM_CONSOLE_TYPE (sizeof(console_type)/sizeof(struct console_type))
+
 struct domain {
int domid;
bool is_dead;
unsigned last_seen;
struct domain *next;
-   struct console console;
+   struct console console[NUM_CONSOLE_TYPE];
 };
 
 static struct domain *dom_head;
 
+typedef void (*VOID_ITER_FUNC_ARG1)(struct console *);
+typedef int (*INT_ITER_FUNC_ARG1)(struct console *);
+typedef void (*VOID_ITER_FUNC_ARG2)(struct console *,  void *);
+typedef int (*INT_ITER_FUNC_ARG3)(struct console *,
+ struct domain *dom, void **);
+
 static inline bool console_enabled(struct console *con)
 {
return con->local_port != -1;
 }
 
+static inline void console_iter_void_arg1(struct domain *d,
+ VOID_ITER_FUNC_ARG1 iter_func)
+{
+   unsigned int i;
+   struct console *con = &d->console[0];
+
+   for (i = 0; i < NUM_CONSOLE_TYPE; i++, con++) {
+   iter_func(con);
+   }
+}
+
+static inline void console_iter_void_arg2(struct domain *d,
+ VOID_ITER_FUNC_ARG2 iter_func,
+ void *iter_data)
+{
+   unsigned int i;
+   struct console *con = &d->console[0];
+
+   for (i = 0; i < NUM_CONSOLE_TYPE; i++, con++) {
+   iter_func(con, iter_data);
+   }
+}
+
+static inline int console_iter_int_arg1(struct domain *d,
+   INT_ITER_FUNC_ARG1 iter_func)
+{
+   unsigned int i;
+   int ret;
+   struct console *con = &d->console[0];
+
+   for (i = 0; i < NUM_CONSOLE_TYPE; i++, con++) {
+   /*
+* Zero return values means success.
+*
+* Non-zero return value indicates an error in which
+* case terminate the loop.
+*/
+   ret = iter_func(con);
+   if (ret)
+   break;
+   }
+   return ret;
+}
+
+static inline int console_iter_int_arg3(struct domain *d,
+   INT_ITER_FUNC_ARG3 iter_func,
+   void **iter_data)
+{
+   unsigned int i;
+   int ret;
+   struct console *con = &d->console[0];
+
+   for (i = 0; i < NUM_CONSOLE_TYPE; i++, con++) {
+   /*
+* Zero return values means success.
+*
+* Non-zero return value indicates an error in which
+* case terminate the loop.
+*/
+   ret = iter_func(con, d, iter_data);
+   if (ret)
+   break;
+   }
+   return ret;
+}
+
 static int write_all(int fd, const char* buf, size_t len)
 {
while (len) {
@@ -336,7 +426,9 @@ static int create_console_log(struct console *con)
return -1;
}
 
-   snprintf(logfile, PATH_MAX-1, "%s/guest-%s.log", log_dir, data);
+   snprintf(logfile, PATH_MAX-1, "%s/guest-%s%s.log",
+log_dir, data, con->log

[Xen-devel] [PATCH 14/27 v10] xen/arm: vpl011: Add a new maybe_add_console_tty_fd function in xenconsole

2017-09-22 Thread Bhupinder Thakur
This patch introduces a new maybe_add_console_tty_fd function. This function
adds the tty fd to the list of polled fds.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v6:
- Renamed add_console_tty_fd to maybe_add_console_tty_fd since it 
  adds the tty FD to the poll list conditionally.
- I have retained the reviewed-by tag as only the function name has been
  changed.

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 30 +-
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 3483252..a0b35da 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -1067,6 +1067,22 @@ static void maybe_add_console_evtchn_fd(struct console 
*con, void *data)
*((long long *)data) = next_timeout;
 }
 
+static void maybe_add_console_tty_fd(struct console *con)
+{
+   if (con->master_fd != -1) {
+   short events = 0;
+   if (!con->d->is_dead && ring_free_bytes(con))
+   events |= POLLIN;
+
+   if (!buffer_empty(&con->buffer))
+   events |= POLLOUT;
+
+   if (events)
+   con->master_pollfd_idx =
+   set_fds(con->master_fd, events|POLLPRI);
+   }
+}
+
 void handle_io(void)
 {
int ret;
@@ -1146,19 +1162,7 @@ void handle_io(void)
 
maybe_add_console_evtchn_fd(con, (void *)&next_timeout);
 
-   if (con->master_fd != -1) {
-   short events = 0;
-   if (!d->is_dead && ring_free_bytes(con))
-   events |= POLLIN;
-
-   if (!buffer_empty(&con->buffer))
-   events |= POLLOUT;
-
-   if (events)
-   con->master_pollfd_idx =
-   set_fds(con->master_fd,
-   events|POLLPRI);
-   }
+   maybe_add_console_tty_fd(con);
}
 
/* If any domain has been rate limited, we need to work
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 16/27 v10] xen/arm: vpl011: Add a new handle_console_ring function in xenconsole

2017-09-22 Thread Bhupinder Thakur
This patch introduces a new handle_console_ring function. This function
reads the data from the ring buffer on receiving an event.

The initialization of event channel poll fd to -1 is moved inside the
handle_console_ring function as they are related. There should be no
change in the behavior as there is no functional change.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 40 +++-
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 2dcaee6..c361b42 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -934,17 +934,23 @@ static void console_evtchn_unmask(struct console *con, 
void *data)
}
 }
 
-static void handle_ring_read(struct domain *dom)
+static void handle_ring_read(struct console *con)
 {
xenevtchn_port_or_error_t port;
-   struct console *con = &dom->console;
 
-   if (dom->is_dead)
+   if (con->d->is_dead)
return;
 
if ((port = xenevtchn_pending(con->xce_handle)) == -1)
return;
 
+   if (port != con->local_port) {
+   dolog(LOG_ERR,
+ "Event received for invalid port %d, Expected port is 
%d\n",
+ port, con->local_port);
+   return;
+   }
+
con->event_count++;
 
buffer_append(con);
@@ -953,6 +959,21 @@ static void handle_ring_read(struct domain *dom)
(void)xenevtchn_unmask(con->xce_handle, port);
 }
 
+static void handle_console_ring(struct console *con)
+{
+   if (con->event_count < RATE_LIMIT_ALLOWANCE) {
+   if (con->xce_handle != NULL &&
+   con->xce_pollfd_idx != -1 &&
+   !(fds[con->xce_pollfd_idx].revents &
+ ~(POLLIN|POLLOUT|POLLPRI)) &&
+   (fds[con->xce_pollfd_idx].revents &
+POLLIN))
+   handle_ring_read(con);
+   }
+
+   con->xce_pollfd_idx = -1;
+}
+
 static void handle_xs(void)
 {
char **vec;
@@ -1236,15 +1257,8 @@ void handle_io(void)
struct console *con = &d->console;
 
n = d->next;
-   if (con->event_count < RATE_LIMIT_ALLOWANCE) {
-   if (con->xce_handle != NULL &&
-   con->xce_pollfd_idx != -1 &&
-   !(fds[con->xce_pollfd_idx].revents &
- ~(POLLIN|POLLOUT|POLLPRI)) &&
- (fds[con->xce_pollfd_idx].revents &
-  POLLIN))
-   handle_ring_read(d);
-   }
+
+   handle_console_ring(con);
 
if (con->master_fd != -1 && con->master_pollfd_idx != 
-1) {
if (fds[con->master_pollfd_idx].revents &
@@ -1261,7 +1275,7 @@ void handle_io(void)
}
}
 
-   con->xce_pollfd_idx = con->master_pollfd_idx = -1;
+   con->master_pollfd_idx = -1;
 
if (d->last_seen != enum_pass)
shutdown_domain(d);
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 05/27 v10] xen/arm: vpl011: Rearrange xen header includes in alphabetical order in domctl.c

2017-09-22 Thread Bhupinder Thakur
Rearrange xen header includes in alphabetical order in domctl.c.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Reviewed-by: Julien Grall 
---
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Corrected include of  in alphabetical order.

 xen/arch/arm/domctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c
index 24bcb55..8232f44 100644
--- a/xen/arch/arm/domctl.c
+++ b/xen/arch/arm/domctl.c
@@ -4,12 +4,12 @@
  * Copyright (c) 2012, Citrix Systems
  */
 
-#include 
-#include 
 #include 
-#include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 22/27 v10] xen/arm: vpl011: Add support for vuart console in xenconsole

2017-09-22 Thread Bhupinder Thakur
This patch finally adds the support for vuart console. It adds
two new fields in the console initialization:

- optional
- use_gnttab

optional flag tells whether the console is optional.

use_gnttab tells whether the ring buffer should be allocated using
grant table.

The VUART console is enabled ony for ARM.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Julien Grall 
CC: Stefano Stabellini 

Changes since v8:
- Removed CONFIG_VUART_CONSOLE config option
- Renamed CFLAGS_vuart-$(CONFIG_VUART_CONSOLE) to CONSOLE_CFLAGS-$(CONFIG_ARM)
- I hav retained the acked-by tag as it is a minor change

Changes since v6:
- Renames prefer_gnttab to use_gnttab

Changes since v4:
- Renamed VUART_CFLAGS- to CFLAGS_vuart- in the Makefile as per the convention.

 tools/console/Makefile|  3 ++-
 tools/console/daemon/io.c | 30 --
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/tools/console/Makefile b/tools/console/Makefile
index c5f3f5c..84796ea 100644
--- a/tools/console/Makefile
+++ b/tools/console/Makefile
@@ -11,6 +11,7 @@ LDLIBS += $(SOCKET_LIBS)
 
 LDLIBS_xenconsoled += $(UTIL_LIBS)
 LDLIBS_xenconsoled += -lrt
+CONSOLE_CFLAGS-$(CONFIG_ARM) = -DCONFIG_ARM
 
 BIN  = xenconsoled xenconsole
 
@@ -28,7 +29,7 @@ clean:
 distclean: clean
 
 daemon/main.o: daemon/_paths.h
-daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab)
+daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab) 
$(CONSOLE_CFLAGS-y)
 xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c))
$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_libxenevtchn) 
$(LDLIBS_libxengnttab) $(LDLIBS_xenconsoled) $(APPEND_LDFLAGS)
 
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index a198dbb..2615b50 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -107,12 +107,16 @@ struct console {
xenevtchn_port_or_error_t remote_port;
struct xencons_interface *interface;
struct domain *d;
+   bool optional;
+   bool use_gnttab;
 };
 
 struct console_type {
char *xsname;
char *ttyname;
char *log_suffix;
+   bool optional;
+   bool use_gnttab;
 };
 
 static struct console_type console_type[] = {
@@ -120,7 +124,18 @@ static struct console_type console_type[] = {
.xsname = "/console",
.ttyname = "tty",
.log_suffix = "",
+   .optional = false,
+   .use_gnttab = true,
},
+#if defined(CONFIG_ARM)
+   {
+   .xsname = "/vuart/0",
+   .ttyname = "tty",
+   .log_suffix = "-vuart0",
+   .optional = true,
+   .use_gnttab = false,
+   },
+#endif
 };
 
 #define NUM_CONSOLE_TYPE (sizeof(console_type)/sizeof(struct console_type))
@@ -654,8 +669,17 @@ static int console_create_ring(struct console *con)
"ring-ref", "%u", &ring_ref,
"port", "%i", &remote_port,
NULL);
-   if (err)
+
+   if (err) {
+   /*
+* This is a normal condition for optional consoles: they might 
not be
+* present on xenstore at all. In that case, just return 
without error.
+   */
+   if (con->optional)
+   err = 0;
+
goto out;
+   }
 
snprintf(path, sizeof(path), "%s/type", con->xspath);
type = xs_read(xs, XBT_NULL, path, NULL);
@@ -669,7 +693,7 @@ static int console_create_ring(struct console *con)
if (ring_ref != con->ring_ref && con->ring_ref != -1)
console_unmap_interface(con);
 
-   if (!con->interface && xgt_handle) {
+   if (!con->interface && xgt_handle && con->use_gnttab) {
/* Prefer using grant table */
con->interface = xengnttab_map_grant_ref(xgt_handle,
dom->domid, GNTTAB_RESERVED_CONSOLE,
@@ -788,6 +812,8 @@ static int console_init(struct console *con, struct domain 
*dom, void **data)
con->d = dom;
con->ttyname = (*con_type)->ttyname;
con->log_suffix = (*con_type)->log_suffix;
+   con->optional = (*con_type)->optional;
+   con->use_gnttab = (*con_type)->use_gnttab;
xsname = (char *)(*con_type)->xsname;
xspath = xs_get_domain_path(xs, dom->domid);
s = realloc(xspath, strlen(xspath) +
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 11/27 v10] xen/arm: vpl011: Add a new console_init function in xenconsole

2017-09-22 Thread Bhupinder Thakur
This patch introduces a new console_init function. This function
initializes the console structure.

Signed-off-by: Bhupinder Thakur 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 65 ---
 1 file changed, 39 insertions(+), 26 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index a2a3496..1da08d7 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -655,20 +655,51 @@ static bool watch_domain(struct domain *dom, bool watch)
return success;
 }
 
-
-static struct domain *create_domain(int domid)
+static int console_init(struct console *con, struct domain *dom)
 {
-   struct domain *dom;
char *s;
+   int err = -1;
struct timespec ts;
-   struct console *con;
 
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
dolog(LOG_ERR, "Cannot get time of day %s:%s:L%d",
  __FILE__, __FUNCTION__, __LINE__);
-   return NULL;
+   return err;
}
 
+   con->master_fd = -1;
+   con->master_pollfd_idx = -1;
+   con->slave_fd = -1;
+   con->log_fd = -1;
+   con->ring_ref = -1;
+   con->local_port = -1;
+   con->remote_port = -1;
+   con->xce_pollfd_idx = -1;
+   con->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 
100) + RATE_LIMIT_PERIOD;
+   con->d = dom;
+   con->xspath = xs_get_domain_path(xs, dom->domid);
+   s = realloc(con->xspath, strlen(con->xspath) +
+   strlen("/console") + 1);
+   if (s) {
+   con->xspath = s;
+   strcat(con->xspath, "/console");
+   err = 0;
+   }
+
+   return err;
+}
+
+static void console_free(struct console *con)
+{
+   if (con->xspath)
+   free(con->xspath);
+}
+
+static struct domain *create_domain(int domid)
+{
+   struct domain *dom;
+   struct console *con;
+
dom = calloc(1, sizeof *dom);
if (dom == NULL) {
dolog(LOG_ERR, "Out of memory %s:%s():L%d",
@@ -677,28 +708,10 @@ static struct domain *create_domain(int domid)
}
 
dom->domid = domid;
-
con = &dom->console;
-   con->xspath = xs_get_domain_path(xs, dom->domid);
-   s = realloc(con->xspath, strlen(con->xspath) +
-   strlen("/console") + 1);
-   if (s == NULL)
-   goto out;
-   con->xspath = s;
-   strcat(con->xspath, "/console");
-
-   con->master_fd = -1;
-   con->master_pollfd_idx = -1;
-   con->slave_fd = -1;
-   con->log_fd = -1;
-   con->xce_pollfd_idx = -1;
-   con->d = dom;
-
-   con->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 
100) + RATE_LIMIT_PERIOD;
 
-   con->ring_ref = -1;
-   con->local_port = -1;
-   con->remote_port = -1;
+   if (console_init(con, dom))
+   goto out;
 
if (!watch_domain(dom, true))
goto out;
@@ -710,7 +723,7 @@ static struct domain *create_domain(int domid)
 
return dom;
  out:
-   free(con->xspath);
+   console_free(con);
free(dom);
return NULL;
 }
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 18/27 v10] xen/arm: vpl011: Add a new console_cleanup function in xenconsole

2017-09-22 Thread Bhupinder Thakur
This patch introduces a new console_cleanup function. This function
frees up the console resources.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v6:
- Removed a null pointer check before calling free() as free() already checks 
that.

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 5c6da31..ff69e52 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -768,12 +768,8 @@ static void remove_domain(struct domain *dom)
}
 }
 
-static void cleanup_domain(struct domain *d)
+static void console_cleanup(struct console *con)
 {
-   struct console *con = &d->console;
-
-   console_close_tty(con);
-
if (con->log_fd != -1) {
close(con->log_fd);
con->log_fd = -1;
@@ -784,6 +780,15 @@ static void cleanup_domain(struct domain *d)
 
free(con->xspath);
con->xspath = NULL;
+}
+
+static void cleanup_domain(struct domain *d)
+{
+   struct console *con = &d->console;
+
+   console_close_tty(con);
+
+   console_cleanup(con);
 
remove_domain(d);
 }
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 19/27 v10] xen/arm: vpl011: Add a new console_open_log function in xenconsole

2017-09-22 Thread Bhupinder Thakur
This patch introduces a console_open_log console_cleanup function. This function
opens the console log file.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v5:
- Split this change in a separate patch.

 tools/console/daemon/io.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index ff69e52..cfd7273 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -1038,6 +1038,15 @@ static void handle_hv_logs(xenevtchn_handle *xce_handle, 
bool force)
(void)xenevtchn_unmask(xce_handle, port);
 }
 
+static void console_open_log(struct console *con)
+{
+   if (console_enabled(con)) {
+   if (con->log_fd != -1)
+   close(con->log_fd);
+   con->log_fd = create_console_log(con);
+   }
+}
+
 static void handle_log_reload(void)
 {
if (log_guest) {
@@ -1045,9 +1054,7 @@ static void handle_log_reload(void)
for (d = dom_head; d; d = d->next) {
struct console *con = &d->console;
 
-   if (con->log_fd != -1)
-   close(con->log_fd);
-   con->log_fd = create_console_log(con);
+   console_open_log(con);
}
}
 
-- 
2.7.4


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 06/27 v10] xen/arm: vpl011: Add a new domctl API to initialize vpl011

2017-09-22 Thread Bhupinder Thakur
Add a new domctl API to initialize vpl011. It takes the GFN and console
backend domid as input and returns an event channel to be used for
sending and receiving events from Xen.

Xen will communicate with xenconsole using GFN as the ring buffer and
the event channel to transmit and receive pl011 data on the guest domain's
behalf.

Signed-off-by: Bhupinder Thakur 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Andrew Cooper 
CC: George Dunlap 
CC: Jan Beulich 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Julien Grall 

Changes since v9:
- Initialized local variable in libxl__arch_build_dom_finish
- Replaced __copy_to_guest with copy_to_guest
- Added comment for console_domid field in vuart_op structure

Changes since v8:
- Added explicit padding in the vuart_op structure
- Moved vuart_op structure after the PSR structure definition
- The input fields moved before the output fields in vuart_op structure
- Checking explicitly that padding fields are initialized to 0

Changes since v6:
- Renamed the vuart initialization function to a generic name xc_dom_vuart_init 
- Used domid_t as a type instead of uint32_t for domid
- Checking the vuart type explicitly against vpl011 enum value

Changes since v5:
- xc_dom_vpl011_init() will be compiled for both x86/arm architectures as there
  is nothing architecture specific in this function. This function will return 
  error when called for x86.
- Fixed coding style issues in libxl.

Changes since v4:
- Removed libxl__arch_domain_create_finish().
- Added a new function libxl__arch_build_dom_finish(), which is called at the 
last
  in libxl__build_dom(). This function calls the vpl011 initialization function 
now.

Changes since v3:
- Added a new arch specific function libxl__arch_domain_create_finish(), which
  calls the vpl011 initialization function. For x86 this function does not do
  anything.
- domain_vpl011_init() takes a pointer to a structure which contains all the 
  required information such as console_domid, gfn instead of passing parameters
  separately.
- Dropped a DOMCTL API defined for de-initializing vpl011 as that should be
  taken care when the domain is destroyed (and not dependent on userspace 
  libraries/applications).

Changes since v2:
- Replaced the DOMCTL APIs defined for get/set of event channel and GFN with 
  a set of DOMCTL APIs for initializing and de-initializing vpl011 emulation.

 tools/libxc/include/xenctrl.h | 20 +
 tools/libxc/xc_domain.c   | 27 ++
 tools/libxl/libxl_arch.h  |  7 ++
 tools/libxl/libxl_arm.c   | 27 ++
 tools/libxl/libxl_dom.c   |  4 
 tools/libxl/libxl_x86.c   |  8 +++
 xen/arch/arm/domain.c |  6 +
 xen/arch/arm/domctl.c | 52 +++
 xen/include/public/domctl.h   | 24 
 9 files changed, 175 insertions(+)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 073fbc9..2086e71 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -886,6 +886,26 @@ int xc_vcpu_getcontext(xc_interface *xch,
vcpu_guest_context_any_t *ctxt);
 
 /**
+ * This function initializes the vuart emulation and returns
+ * the event to be used by the backend for communicating with
+ * the emulation code.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * #parm type type of vuart
+ * @parm domid the domain to get information from
+ * @parm console_domid the domid of the backend console
+ * @parm gfn the guest pfn to be used as the ring buffer
+ * @parm evtchn the event channel to be used for events
+ * @return 0 on success, negative error on failure
+ */
+int xc_dom_vuart_init(xc_interface *xch,
+  uint32_t type,
+  domid_t domid,
+  domid_t console_domid,
+  xen_pfn_t gfn,
+  evtchn_port_t *evtchn);
+
+/**
  * This function returns information about the XSAVE state of a particular
  * vcpu of a domain. If extstate->size and extstate->xfeature_mask are 0,
  * the call is considered a query to retrieve them and the buffer is not
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index f40dc4f..f2e9f0c 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -343,6 +343,33 @@ int xc_domain_get_guest_width(xc_interface *xch, uint32_t 
domid,
 return 0;
 }
 
+int xc_dom_vuart_init(xc_interface *xch,
+  uint32_t type,
+  domid_t domid,
+  domid_t console_domid,
+  xen_pfn_t gfn,
+  evtchn_port_t *evtchn)
+{
+DECLARE_DOMCTL;
+int rc = 0;
+
+memset(&domctl, 0, sizeof(domctl));
+
+domctl.cmd = XEN_DOMCTL_vuart_op;
+domctl.domain = domid;
+domctl.u.vuart_op.cmd = XEN_DOMCTL_VUART_OP_INIT;
+domctl.u.vuart

[Xen-devel] [PATCH 08/27 v10] xen/arm: vpl011: Modify xenconsole to define and use a new console structure

2017-09-22 Thread Bhupinder Thakur
Xenconsole uses a domain structure which contains console specific fields. This
patch defines a new console structure, which would be used by the xenconsole
functions to perform console specific operations like reading/writing data 
from/to
the console ring buffer or reading/writing data from/to console tty.

This patch is in preparation to support multiple consoles to support vuart 
console.

Signed-off-by: Bhupinder Thakur 
Reviewed-by: Stefano Stabellini 
Acked-by: Wei Liu 
---
CC: Ian Jackson 
CC: Wei Liu 
CC: Stefano Stabellini 
CC: Julien Grall 

Changes since v4:
- Moved the following fields from the struct domain to struct console:
  ->xenevtchn_handle *xce_handle;
  ->int xce_pollfd_idx;
  ->int event_count;
  ->long long next_period;

Changes since v3:
- The changes in xenconsole have been split into four patches. This is the 
first patch
  which modifies the xenconsole to use a new console structure.

Changes since v2:
- Defined a new function console_create_ring() which sets up the ring buffer 
and 
  event channel a new console. domain_create_ring() uses this function to setup
  a console.
- This patch does not contain vuart specific changes, which would be introduced 
in
  the next patch.
- Changes for keeping the PV log file name unchanged.

Changes since v1:
- Split the domain struture to a separate console structure
- Modified the functions to operate on the console struture
- Replaced repetitive per console code with generic code

 tools/console/daemon/io.c | 299 +-
 1 file changed, 165 insertions(+), 134 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index e8033d2..30cd167 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -89,25 +89,30 @@ struct buffer {
size_t max_capacity;
 };
 
-struct domain {
-   int domid;
+struct console {
int master_fd;
int master_pollfd_idx;
int slave_fd;
int log_fd;
-   bool is_dead;
-   unsigned last_seen;
struct buffer buffer;
-   struct domain *next;
char *conspath;
int ring_ref;
-   xenevtchn_port_or_error_t local_port;
-   xenevtchn_port_or_error_t remote_port;
xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
-   struct xencons_interface *interface;
int event_count;
long long next_period;
+   xenevtchn_port_or_error_t local_port;
+   xenevtchn_port_or_error_t remote_port;
+   struct xencons_interface *interface;
+   struct domain *d;
+};
+
+struct domain {
+   int domid;
+   bool is_dead;
+   unsigned last_seen;
+   struct domain *next;
+   struct console console;
 };
 
 static struct domain *dom_head;
@@ -160,9 +165,10 @@ static int write_with_timestamp(int fd, const char *data, 
size_t sz,
 
 static void buffer_append(struct domain *dom)
 {
-   struct buffer *buffer = &dom->buffer;
+   struct console *con = &dom->console;
+   struct buffer *buffer = &con->buffer;
XENCONS_RING_IDX cons, prod, size;
-   struct xencons_interface *intf = dom->interface;
+   struct xencons_interface *intf = con->interface;
 
cons = intf->out_cons;
prod = intf->out_prod;
@@ -187,22 +193,22 @@ static void buffer_append(struct domain *dom)
 
xen_mb();
intf->out_cons = cons;
-   xenevtchn_notify(dom->xce_handle, dom->local_port);
+   xenevtchn_notify(con->xce_handle, con->local_port);
 
/* Get the data to the logfile as early as possible because if
 * no one is listening on the console pty then it will fill up
 * and handle_tty_write will stop being called.
 */
-   if (dom->log_fd != -1) {
+   if (con->log_fd != -1) {
int logret;
if (log_time_guest) {
logret = write_with_timestamp(
-   dom->log_fd,
+   con->log_fd,
buffer->data + buffer->size - size,
size, &log_time_guest_needts);
} else {
logret = write_all(
-   dom->log_fd,
+   con->log_fd,
buffer->data + buffer->size - size,
size);
}
@@ -338,14 +344,16 @@ static int create_domain_log(struct domain *dom)
 
 static void domain_close_tty(struct domain *dom)
 {
-   if (dom->master_fd != -1) {
-   close(dom->master_fd);
-   dom->master_fd = -1;
+   struct console *con = &dom->console;
+
+   if (con->master_fd != -1) {
+   close(con->master_fd);
+   con->master_fd = -1;
}
 
-   if (dom->slave_fd != -1) {
-   close(

  1   2   3   4   5   >