Commit Graph

725 Commits

Author SHA1 Message Date
Nikunj A Dadhania ff9b0bd159 virtio: add virtio 1.0 related struct and defines
Traditionally, struct virtio_device is shared between SLOF and C code.
This still remains shared with the addition of virtio_cap structure as
well. Now both virtio_device and virtio_cap structures are shared.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:39 +11:00
Nikunj A Dadhania 5ed17500f0 virtio: get rid of type variable in virtio_device
virtio device structure carries a type variable indicating whether
virtio is over PCI or VIO. While VIO is not there and no plan to
introduce other transport, there is no purpose of having this variable
around and checking for PCI.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:39 +11:00
Nikunj A Dadhania aa9566d2ed virtio-net: move setup-mac to the open routine
MAC reading should be done after the initialization of the device after
the features negotiation.

Adjust the open routine accordingly. There is no point in sending the
mac address to the virtionet_open. Change the signature. Also read the
mac address directly from the config space to remove the dependency of
getting the mac address from the open routine.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:39 +11:00
Nikunj A Dadhania 31312dcf44 virtio-net: make net_hdr_size a variable
Size of the net_hdr_size is different in legacy and modern devices. This
helps in conversion of the driver to 1.0.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:39 +11:00
Nikunj A Dadhania d20eb434fe virtio-net: replace vq array with vq_{tx,rx}
Using an array here is not necassary, simplifies the code for
readability.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:39 +11:00
Nikunj A Dadhania edc7a480d8 virtio-net: use virtio_fill_desc
Simplifies the driver code and is helpful for migration to virtio 1.0
enablement.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania a936ccce6e virtio-{net,blk,scsi,9p}: use status variable
The virtio_set_status lines were getting too long because of OR'ing the
status on the same line of the call. Moreover, going forward we need to
add FEATURES_OK status as well. The state progress is quite straight
forward, so use status variable instead. Code looks cleaner and can easily
make out the change in the state.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania fdb62149dc virtio-blk: add helpers for filling descriptors
Enable virtio_fill_desc/fill_blk_hdr with legacy and modern mode for
further use

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania b5a692d3f7 virtio-{blk,9p}: enable resetting the device
With the lack of the virtio_queue_init_vq routine, driver like
virtio-blk and virtio-9p had disabled device reset in the
initialization code. This helper will fix that problem, as the
initialization can be done after the device reset.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania bcdf942b91 virtio: introduce helper for initializing virt queue
The routine takes care to allocate and set the queue address in the
device. Add these calls in virtio-net, virtio-blk and virtio-9p.

With the lack of this routine, devices like virtio-blk and virtio-9p did
not do a device reset in the driver initialization code. This helper
will fix that problem

Change the signature of virtio_set_qaddr, accepting queue address as
unsigned long argument.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania 805cc24afa virtio: fix code style/design issues.
The patch does not make any functional changes.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania cb8725edfb fix code style in byteorder.h
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania 8b23f3fd8a pci: add byte read/write helper routines
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania 4f26878f17 virtio-net: fix gcc warnings (-Wextra)
Change rx_size type which originally should have been uint32_t. This
also requires a change in the function prototype.

Also change the return type of virtio_9p_load() to silence another gcc
warning

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Nikunj A Dadhania c8d2f276e7 virtio-blk: fix gcc warnings (-Wextra)
Change the prototype of virtioblk_read as blocknum wont be negative

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-02-08 16:40:38 +11:00
Alexey Kardashevskiy 2bba017e12 readme: Add a note about coding style
This is an attempt to standartize the coding style in the project.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2016-02-08 16:40:27 +11:00
Alexey Kardashevskiy 896e31da2c dhcp: Remove duplicated strtoip()
There is another implementation in netapps/args.c which is used by
netboot.c and ping.c so switch to it.

Suggested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2016-01-29 17:11:38 +11:00
Alexey Kardashevskiy dc0ecd1477 ethernet: Fix gcc warnings
This fixes gcc warnings but unlike other places, this does not change
the type of bytes_received as recv() may return a negative value;
instead this adds:
1) casting to size_t when comparing the size;
2) an additional check for a negative value returned from recv().

The make command used to test:
make qemu WARNFLAGS=-Wextra

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2016-01-29 17:10:40 +11:00
Alexey Kardashevskiy f344ef9b22 net-snk: Fix gcc warnings
This replaces some local variable types and some function parameters from
signed to unsigned to fix gcc warnings.

Tested DHCP+TFTP on both IPv4 and IPv6.

The make command used to test:
make qemu WARNFLAGS=-Wextra

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2016-01-29 17:10:35 +11:00
Alexey Kardashevskiy 253298295e net-snk: Fix coding style
This restyles function prototypes:
- return types on the same line;
- opening brace is on the next line.

VIM configs used for this was:
set noexpandtab
set tabstop=8
set shiftwidth=4
set cino=:0,(0

This replaces [><]* with "*" as >< are also used to resolve merge
conflicts.

This removes trailing spaces.

This removes some redundant braces.

This should cause no behavioural change.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2016-01-29 17:09:58 +11:00
Thomas Huth 2e9f1f28d2 net-snk: Fix memory leak in dhcp6_process_options()
The dhcp6_process_options() function allocates a struct
dhcp6_received_options each time it is called - but that
struct never gets used - and especially is also never freed
again. Fix this memory leak by simply removing the unused code.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-18 11:58:20 +11:00
Thomas Huth c0fbf94bc5 net-snk: Fix memory leak in ip6_to_multicast_mac() / send_ipv6()
ip6_to_multicast_mac() uses a malloc to allocate a 6 bytes buffer
for the MAC address - which never gets freed again! That means
we're leaking memory for every multicast IPv6 packet that gets
send out. Fix it by simply using the "uint8_t mac[6]" array from
send_ipv6() instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-18 11:58:12 +11:00
Thomas Huth c74ddc9954 net-snk: Remove bad NEIGHBOUR_SOLICITATION code in send_ipv6()
The code that checks for NEIGHBOUR_SOLICITATION packets is bad
in two ways: First, it does not check that the packet is really
an ICMPv6 packet, so it could accidentially be triggered for UDP
or TCP packets, too. Second, the fill_ethhdr() is redundant (since
it is done at the end of the function again) and also wrong (it
uses the wrong buffer pointer to fill in the ethernet header).

All we really need here is to get the right MAC address via
ip6_to_multicast_mac() - and this is handled in the following
if-statement already (NEIGHBOUR_SOLICITATIONs are always sent
as multicast in the send_neighbour_solicitation() function), so
the bad code block can simply be removed to fix the two issues.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-18 11:58:03 +11:00
Thomas Huth fe7b047c0c Fix dma-alloc and dma-map-in functions on board-js2x
Since slof/fs/dma-function.fs has been introduced for board-qemu,
these function definitions shadow the original js2x functions from
slof/fs/pci-config-bridge.fs, because dma-functions.fs is included
after pci-config-bridge.fs in slof/fs/pci-bridge.fs.
To restore the original behavior, move the js2x functions into
a board-specific dma-function.fs file instead and include that
one into the ROM-fs instead of the version for board-qemu.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-14 14:52:32 +11:00
Thomas Huth 056ff5b32d net-snk: Allow stateless autoconfig IPv6 addresses with IP_INIT_IPV6_MANUAL
When manually specifying the TFTP server address and boot file name
in IPv6 mode, we can still get the client IPv6 address via link-local
or stateless IPv6 address autoconfiguration. So the netboot should
not abort if just the client IPv6 address has not been specified yet.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-14 11:26:23 +11:00
Thomas Huth 82660c5da4 net-snk: Simplify the ip6_is_multicast() function
Using a memcpy to just compare one byte looks very cumbersome.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-14 11:26:14 +11:00
Thomas Huth 9308463cfd net-snk: Move global variable definition out of the header file
The IPv6 code declares a bunch of global variables (without "extern"
keyword!) in the ipv6.h header file. This is bad style and does not
work when linking with "-fno-common" for example. So let's move
the variables to the files where they are used instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-14 11:26:07 +11:00
Thomas Huth a9aa48d28a net-snk: Prefer non-link-local unicast IPv6 addresses if possible
When the IPv6 code is told to create IPv6 addresses automatically
(by passing NULL as parameter to set_ipv6_address()), the netboot
code currently only uses link-local IPv6 addresses - which is bad
since they can not be routed, e.g. if the TFTP server is not on
the same link.
So set_ipv6_address(NULL) should set own_ip6 preferably to a non-local
unicast address if it has been generated successfully during ipv6_init().

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-14 11:25:59 +11:00
Thomas Huth 7dc047e600 net-snk: Fix the check for link-local addresses when receiving RAs
The code that checks whether the router advertisments contain only
a link-local address has a bug: It must check the full first 10 bits
of the address, not only the first 9 bits. Otherwise, site-local
addresses (which start with 0xFEC0...) are also recognized as
link-local, which is wrong, of course.
Fix it by also introducing a proper wrapper functions for link-local
addresses (which will be used in a later patch, too).

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-14 11:25:51 +11:00
Thomas Huth caf8309249 net-snk: Remove junk at the end of IPv6 TFTP ACK and error packets
While looking at the network traffic from SLOF with Wireshark, I
noticed that there are some junk bytes at the end of TFTP ACK
packets. The problem is that send_ack() adds sizeof(struct ethhdr)
to the length of the packet that it wants to transmit. But adding
the sizeof(struct ethhdr) to the length of the packet is done
within send_ipv6() already, so this value got added twice.
Removing it from send_ack() fixes this issue - the packets then
look fine in Wireshark again.
send_error() apparently suffers from the same issue, so let's
also remove the sizeof(struct ethhdr) from that function.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-14 11:25:44 +11:00
Thomas Huth 568fb49625 Fix format strings in usb-ohci.c
When compiling with OHCI_DEBUG enabled, gcc complains about a
lot of bad format strings. So let's use more appropriate format
modifiers to fix these warnings.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2016-01-11 12:00:05 +11:00
Thomas Huth 749c50b84b net-snk: Get rid of junk at the end of sent DHCPv6 packets
Wireshark reports bad FCS values and trailing zeros for SLOF's
DHCPv6 packets. This happens due to two bugs. First, the length
given to send_ipv6() contained sizeof(struct ethhdr) - but
adding that length is the responsibility of the send_ipv6()
function itself, the upper layers must not add this length yet.
Second, struct option_request was defined with 5 options, but
the code only uses 3 options instead. So when the code uses
sizeof(struct dhcp_message_header) (which contains the struct
option_request), there were additional unused bytes appended
to the message.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 13:01:41 +11:00
Thomas Huth 33c9899c77 net-snk: Use transaction IDs in DHCPv4, too
Generate a proper transaction ID before sending DHCPv4 packets
and check whether the DHCPv4 replies contain that correct XID, too.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 13:01:34 +11:00
Thomas Huth def4d3e197 net-snk: Make use of DHCPv6 transaction IDs
Generate a proper transaction ID before sending DHCPv6 packets
and check whether the DHCPv6 replies contain that correct XID, too.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 13:01:25 +11:00
Thomas Huth 2c49891b55 net-snk: Seed the pseudo-random number generator
Use the MAC address and the current timebase value to seed the
pseudo-random number generator - this will hopefully give use
enough pseudo-randomness so that two guests that are booting in
parallel won't use the same rand() numbers.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 13:01:19 +11:00
Thomas Huth 48ae29e4c0 libc: Add srand() call
Needed for seeding the state of the pseudo-random number generator.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 13:01:12 +11:00
Thomas Huth 1487399da6 libc: Fix the rand() function to return non-zero values
The rand() function in SLOF's libc has a bug which caused the
function to always return zero: The _rand value was shifted left
by 16, and then ANDed with 0x7fff. Obviously, the shift operation
should be ">>" instead of "<<".
And while we're at it, also increase the constant for the
multiplaction in there so that more upper bits are affected.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 13:01:04 +11:00
Thomas Huth 7e31382cca net-snk: Improve printed text when booting via network
The output of net-snk is bad in a couple of places:
1) The hard-coded "Bootloader 1.6" message is pretty useless
   for the users (we never changed the version number in the
   past five years) - so let's change that into printing
   "Initializing NIC" instead.
2) "Requesting IP address via DHCP" is wrong for DHCPv6 since
   in this case, the net-snk might only request the boot file
   name via DHCPv6. In the IPv6-only case, the net-snk was
   already printing "Requesting information..." instead, so
   let's unify these texts to always print "information" instead
   of "IP address"
3) The client IPv6 address is never printed out, so do that now,
   too.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 13:00:41 +11:00
Thomas Huth c02cf76042 Increase temporary buffer size of ibm,client-architecture-support call
The buffer size that we currently use for the client-architecture-
support call currently only works if there is not more than 1 TiB
of hot-pluggable RAM for the guest. This will likely not be enough
in the near future, so increase the buffer size from 128 kiB to 2 MiB
instead. That should be enough to accomodate for 16 TiB of hot-pluggable
memory.
While we're at it, also rename the "size" variable to something more
specific (since it is put into the namespace of the root node), and
add a proper error message in case the alloc-mem fails.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 12:42:36 +11:00
Thomas Huth 078947d54a Move archsupport.fs into board-qemu directory
The "hv-cas" hypercall is only available on board-qemu.
Including archsupport.fs on board-js2x breaks the boot
process there. Thus the archsupport.fs file should
reside in the board-qemu/slof directory instead and
only be included from there.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 12:36:00 +11:00
Nikunj A Dadhania c73bf77619 boot: stop booting when we encounter HALT
QEMU when started with "-boot strict=on", appends "HALT" at the end of
the bootlist. Handle this in the boot order.

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-23 12:05:31 +11:00
Thomas Huth 299642e372 fat-files: Fix bug with root-entries = 0 on certain FAT32 file systems
The maximum number of root directory entries can be zero on
certain FAT32 file systems. In this case, we've got to read
the cluster number of the root directory from the extended BPB
instead. See also the following URL for details:
https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system#BPB20_OFS_06h

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-09 15:52:37 +11:00
Nikunj A Dadhania b25d5796db usb: print unhandled descriptor in debug mode
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-09 15:52:15 +11:00
Thomas Huth 271fd45605 Improve stack usage with libnvram get_partition function
The Forth-to-C wrapper for get-named-nvram-partition also
uses the STRING_INIT macro. This causes heavy stack usage
in the engine() function due to the static array in that
macro. So let's rework the wrapper to do the string convertion
in a separate function instead.
Now that all users of the STRING_INIT and STRING_FROM_STACK
macros are gone, the macros can be removed, too.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-02 14:54:41 +11:00
Thomas Huth baa834884c Improve stack usage in libnvram environment variable code
The Forth-to-C wrapper code in libnvram.code uses a temporary
buffer of 255 bytes via the STRING_INIT macro for each Forth string
that has to be converted to a C string. However, using such big
arrays in the wrapper code is a bad idea: Each of the buffers
is put into the stack frame of the engine() function (from paflof.c)!
That means the 7 strings from libnvram.code increase the stack
usage of engine() by 7 * 255 = 1785 bytes! This can cause stack
overflows since engine() can be called recursively, e.g. via the
forth_eval() macro.

To fix this issue in the functions from envvar.c, we can simply
pass the Forth strings directly to the functions by adding the
string length as additional function parameter, since the functions
in envvar.c don't really depend on NUL-terminated strings.

And while we're at it (i.e. we touch the function prototypes here
anyway), also rename the functions to have a proper "nvram_" prefix,
so we clearly mark them as part of libnvram instead of cluttering
the global name space with rather trivial function names.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-02 14:54:30 +11:00
Alexey Kardashevskiy da3bd7a2c7 libc: Port vsnprintf back from skiboot
Since initial port from slof to skiboot, vsnprintf() has improved in
skiboot so let's port the improved version back.

Suggested-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-02 14:23:25 +11:00
Thomas Huth 2ef6d1e52d Move the code for rfill into a separate function
The code from the FAST_RFILL macro uses a local array as a
temporary buffer - which gets allocated in the stack frame
of the engine() function. Since engine() can be called
recursively, this can cause stack overflows. So let's
move the rfill code into a separate function to avoid
these problems.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-01 17:02:04 +11:00
Thomas Huth f0d251a077 Rework wrapper for new_nvram_partition() and fix possible bug in there
The wrapper for new_nvram_partition() is using a 12 bytes buffer to
create a zero-terminated string. However, if the string has exactly
12 characters, the final NUL-terminator is missing. new_nvram_partition()
then calls create_nvram_partition() internally which depends on proper
NUL-terminated strings. So fix this by making sure that the copied
string is always NUL-terminated - and while we're at it, also move
the copy code out of libnvram.code to save some precious bytes in the
stack space of the engine() function.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-01 17:02:04 +11:00
Thomas Huth edd582383f Stack optimization in libusb: split up setup_new_device()
When scanning hubs, the code in libusb can be called recursively, for
example usb_hub_init() calls setup_new_device(), which then calls
slof_usb_handle() to execute Forth code for the next device.
If that next device is a hub, we end up recursively in usb_hub_init()
again.
Since stack space is limited in SLOF, we can optimize here a little
bit by splitting up the setup_new_device() function into the part
that retrieves the descriptors (which takes most of the stack space
in this code path since the descriptors are placed on the stack),
and the part that populates the the device tree node of the new
device (which is responsible for the recursion).

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-01 17:02:04 +11:00
Thomas Huth 3d5e62eea2 Check for stack overflow in paflof engine
Since engine() can be called recursively, this function is
prone for causing stack overflows. Add a sanity check and
spill out an error message if we detect an overflow. It's
not a bullet-proof check, but still, it should catch at least
the larger overflows and thus hopefully help detecting and
debugging these overflow problems in the future.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2015-12-01 17:02:04 +11:00