Commit Graph

40 Commits

Author SHA1 Message Date
Toomas Soome
f6eef0f9a2 libefi: efipart_floppy() will should not pass acpi pointer if the HID test fails
The current efipart_floppy() implementation is leaking the acpi pointer.
2017-09-25 19:49:56 +00:00
Toomas Soome
c57460d994 libefi: define EISA PNP constants
Define EISA PNP constants and use them, also fix ID for 0x701
2017-09-22 07:44:36 +00:00
Toomas Soome
f43a98e6c2 libefi: efipart_hdinfo_add_filepath should check strtol result
Use errno for error checking.
2017-09-22 07:40:05 +00:00
Toomas Soome
abf054b4c6 libefi: efipart.c cstyle fix for efipart_print_common()
The else statement should have { }
2017-09-22 07:37:42 +00:00
Toomas Soome
5af584ffc1 libefi: efipart_strategy() should return ENXIO when there is no media
We should return ENXIO to indicate the situation with device present,
but no media.
2017-09-22 07:34:08 +00:00
Toomas Soome
cfe103a2ac libefi: efipart.c should use calloc()
The device specific *_add functions are using malloc() + memset,
should use calloc instead.
2017-09-21 23:22:18 +00:00
Toomas Soome
59fcc285f4 libefi: efi_devpath_match() should return bool
The current implementation of efi_devpath_match() is returning values 0 or 1,
so it should be updated to return bool.
2017-09-21 23:14:07 +00:00
Toomas Soome
0a0c72ff93 libefi: efipart_realstrategy rsize pointer may be NULL
Need to check rsize before dereferencing it.
2017-09-13 14:27:13 +00:00
Toomas Soome
c7847a364a libefi: efipart_open should check the status from disk_open
In case of error from disk_open(), we should clean up properly.

Reviewed by:	allanjude, imp
Differential Revision:	https://reviews.freebsd.org/D12340
2017-09-12 14:18:45 +00:00
Toomas Soome
44832ad99d loader.efi: chain loader should provide proper device handle
Since the efipart rewrite, the chain command was looking for device
handle using interface applicable only for net devices. Disk
partitions and zfs pools need their own approach to find the proper handle.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D12287
2017-09-10 13:53:42 +00:00
Allan Jude
e11bad9d2b Integer underflow in efipart_realstrategy when I/O starts after end of disk
This fixes an integer underflow in efipart_realstrategy, which causes
crashes when an I/O operation's start point is after the end of the disk.
This can happen when trying to detect filesystems on very small disks.
This can occur if a BIOS freebsd-boot partition exists on a system when the
EFI loader is being used.

PR:		219000
Submitted by:	Eric McCorkle <eric@metricspace.net>
Reviewed by:	cem (previous version), tsoome (previous version)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D10559
2017-07-01 20:25:22 +00:00
Toomas Soome
c9296b3227 loader: F_READ/F_WRITE should be checked against masked flag
The work to make it possible to avoid bcache via using F_NORA modifier did
miss the fact that not all loader platforms are using the bcache, and so
it is possible the modifier is not cleared, as bcache strategy function is
not used.

For fix, we make sure the checks are dont with masked flag.

This patch does fix boot for platforms which do not use bcache.

Reported by:	emaste
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D10422
2017-04-18 18:07:54 +00:00
Toomas Soome
4479aa540f loader: efipart should check disk size from partition table
While testing 32bit UEFI OVMF (which has bug about how the disk size
is presented), I did witness the errors from blkio->ReadBlocks().

It became apparent we can not entirely trust UEFI interfaces either,
so additional checks are needed.

So we use disk_ioctl(DIOCGMEDIASIZE) for disks, with fallback of
Media->LastBlock for other media.

In addition, we need to check if there is media present.

+ small fixes for error printout, and avoiding multiple blk * 512.

Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D10197
2017-03-30 16:23:31 +00:00
Toomas Soome
b91aad35da loader: remove open_disk cache
As we provide the disk size verification and correction via disk_ioctl
and disk state provided by disk_open(), we can not share the partition
state in disk_devdesc structure. Also the sharing does make a lot of sense
with ufs, as only one partition is open at any given time, but zfs pools
do keep the disk devices open.

To make sure we do get the correct information about the open device,
just remove the cache.

Reviewed by:	allanjude, smh
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9757
2017-03-16 12:04:43 +00:00
Toomas Soome
dcb8552acb loader: cstyle fixes and DIOCGMEDIASIZE should use uint64_t
Cleaned up some spaces where tabs should be.
efipart_ioctl() DIOCGMEDIASIZE needs to use uint64_t, not off_t

Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9562
2017-02-13 21:33:50 +00:00
Toomas Soome
c05d666747 loader: implement MEDIA_FILEPATH_DP support in efipart
The efipart rework did break the ARM systems as the new code is
using more exact filters to sort the devices and we need to
add support for MEDIA_FILEPATH_DP device paths.

PR:		216940
Reported by:	karl@denninger.net
Reviewed by:	allanjude, manu
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9520
2017-02-11 15:25:49 +00:00
Toomas Soome
c7bf8909b1 loader: possible NULL pointer dereference in efipart.c
Fix bugs found by Coverity in efipart.c.

The Issue is that efi_devpath_last_node() can return NULL pointer, and
therefore we should check for it. In real life we really do not
expect to see it to happen, so we will just error out from the test.

CID:		1371004
Reported by:	Coverity
Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9490
2017-02-08 15:52:09 +00:00
Toomas Soome
467c82cb84 loader: Replace EFI part devices.
Rewrite EFI part device interface to present disk devices in more
user friendly way.

We keep list of three types of devices: floppy, cd and disk, the
visible names: fdX: cdX: and diskX:

Use common/disk.c and common/part.c interfaces to manage the
partitioning.

The lsdev -l will additionally list the device path.

Reviewed by:	imp, allanjude
Approved by:	imp (mentor), allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D8581
2017-02-06 09:18:47 +00:00
Toomas Soome
9c1cd3f5c3 loader: efi devpath api usage should be more aware of NULL pointers
As the efi_devpath_last_node() and efi_devpath_trim() can return NULL
pointers, the consumers of this API should check the the NULL pointers.

Same for efinet_dev_init() using calloc().

Reported by:	Robert Mustacchi <rm@joyent.com>
Reviewed by:	jhb, allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9203
2017-01-18 08:18:07 +00:00
Toomas Soome
1ecc859193 dosfs support in libstand is broken since r298230
Apparently the libstand dosfs optimization is a bit too optimistic
and did introduce possible memory corruption.

This patch is backing out the bad part and since this results in
dosfs reading full blocks now, we can also remove extra offset argument
from dv_strategy callback.

The analysis of the issue and the backout patch is provided by Mikhail Kupchik.

PR:		214423
Submitted by:	Mikhail Kupchik
Reported by:	Mikhail Kupchik
Reviewed by:	bapt, allanjude
Approved by:	allanjude (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D8644
2016-12-30 19:06:29 +00:00
Toomas Soome
77d81a4dab lsdev device name section headers should be printed by dv_print callback.
lsdev command does walk over devsw list, prints list element name and
will use dv_print() callback to print the device list.
Unfortunately this approach will add unneeded noise when there are no
particular devices detected.

To remove "empty" device section headers, the dv_print() callback
should print the header instead.

In addition, fixed dv_print callback for md module.

Reviewed by:	imp
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D8551
2016-11-19 08:54:21 +00:00
Toomas Soome
cbd6713146 Loader paged/pageable data is not always paged.
This change does modify devsw dv_print() to return the int value,
enabling walkers to interrupt the walk on non zero value from dv_print().

This will allow the pager_print actually to stop displaying data on
user input, and additionally pager is used in various *dev_print callbacks,
where it was missing.

For test, lsdev [-v] command should display data by screenfuls and should
stop when the key 'q' is pressed on pager prompt.

Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D5461
2016-11-08 06:50:18 +00:00
Emmanuel Vadot
e40bf91460 Print a message when disks are found but no logical partition are
reported by EFI implementation. This address comment on r301714.

Approved by:	re (gjb), andrew (mentor)
Differential Revision:	https://reviews.freebsd.org/D6787
2016-06-17 17:09:22 +00:00
Emmanuel Vadot
e644b7c5a5 Print a message when the efi disk isn't a logical partition.
Approved by:	andrew (mentor)
Differential Revision:	https://reviews.freebsd.org/D6782
2016-06-09 02:02:50 +00:00
Doug Ambrisko
9c8f0619db If the I/O offset and length is multiple of the media size then
directly pass the request otherwise use a buffer that is a
multiple of the media size.  This speeds up I/O quite a bit
when using large transfer sizes on 4Kn disks etc.

MFC after:	1 week
2016-05-27 19:23:15 +00:00
John Baldwin
e06f8144fb Use routines from the recently added devpath.c.
These efipart layer did several devpath related operations inline.  This
just switches it over to using shared code for working with device paths.

Sponsored by:	Cisco Systems
2016-05-26 22:13:40 +00:00
Warner Losh
9a0b26ec6f Fix several instances where the boot loader ignored pager_output
return value when it could return 1 (indicating we should stop).
Fix a few instances of pager_open() / pager_close() not being called.
Actually use these routines for the environment variable printing code
I just committed.
2016-05-18 05:59:05 +00:00
Conrad Meyer
3d5b6ffbf8 efipart: Support an arbitrary number of partitions
Don't crash if the user has more than 31 of them.  A follow-up to
r298230.

Reviewed by:	allanjude
Relnotes:	maybe
Sponsored by:	EMC / Isilon Storage Division
Differential Revision:	https://reviews.freebsd.org/D6212
2016-05-05 00:07:08 +00:00
Allan Jude
ffd50bca7e bcache read ahead may attempt to read past end of disk
The new bcache code does not know the size of the disk, and therefore may attempt to read past the end of the disk while trying to fill its read-ahead cache.

This is usually not an issue, it fails gracefully on all of my machines, but some BIOSes seem to retry the reads for up to 30 seconds each, resulting in a long stall during boot

Submitted by:	Toomas Soome <tsoome@me.com>
Reviewed by:	jhb, np
Differential Revision:	https://reviews.freebsd.org/D6109
2016-05-01 21:06:59 +00:00
Allan Jude
87ed2b7f5a A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.

Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.

Submitted by:	Toomas Soome <tsoome@me.com>
Reviewed by:	delphij (previous version), emaste (previous version)
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
Steven Hartland
022e692a47 Enable warnings in EFI boot code
Set WARNS if not set for EFI boot code and fix the issues highlighted by
setting it.

Most components are set to WARNS level 6 with few being left at lower
levels due to the amount of changes needed to fix at higher levels.

Error types fixed:
* Missing / invalid casts
* Missing inner structs
* Unused vars
* Missing static for internal only funcs
* Missing prototypes
* Alignment changes
* Use of uninitialised vars
* Unknown pragma (intrinsic)
* Missing types etc due to missing includes
* printf formatting types

Reviewed by:	emaste (in part)
MFC after:	2 weeks
X-MFC-With:	r293268
Sponsored by:	Multiplay
Differential Revision:	https://reviews.freebsd.org/D4839
2016-01-12 02:17:39 +00:00
Ed Maste
7ebeabcf9b Revert accidental whitespace changes included with r292623 2015-12-22 20:40:34 +00:00
Ed Maste
6ee0db8b76 Support a.out format in nlist only on i386
i386 is the only current FreeBSD architecture that ever used a.out
format.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D4687
2015-12-22 20:36:14 +00:00
Ed Maste
906451276a Avoid creating invalid UEFI device path
The UEFI loader on the 10.1 release install disk (disc1) modifies an
existing EFI_DEVICE_PATH_PROTOCOL instance in an apparent attempt to
truncate the device path.  In doing so it creates an invalid device
path.

Perform the equivalent action without modification of structures
allocated by firmware.

PR:		197641
MFC After:	1 week
Submitted by:	Chris Ruffin <chris.ruffin@intel.com>
2015-07-07 18:44:27 +00:00
Ed Maste
b900a57189 Add explicit casts to quiet warnings in libefi
Sponsored by:	The FreeBSD Foundation
2014-04-08 18:21:38 +00:00
Ed Maste
ee83e77448 Merge efilib changes from projects/uefi
r247216:

  Add the ability for a device to have an "alias" handle.

r247379:

  Fix network device registration.

r247380:

  Adjust our load device when we boot from CD under UEFI.

  The process for booting from a CD under UEFI involves adding a FAT
  filesystem containing your loader code as an El Torito boot image.
  When UEFI detects this, it provides a block IO instance that points
  at the FAT filesystem as a child of the device that represents the CD
  itself. The problem being that the CD device is flagged as a "raw
  device" while the boot image is flagged as a "logical partition".
  The existing EFI partition code only looks for logical partitions and
  so the CD filesystem was rendered invisible.

  To fix this, check the type of each block IO device. If it's found to
  be a CD, and thus an El Torito boot image, look up its parent device
  and add that instead so that the loader will then load the kernel from
  the CD filesystem.  This is done by using the handle for the boot
  filesystem as an alias.

  Something similar to this will be required for booting from other media
  as well as the loader will live in the EFI system partition, not on the
  partition containing the kernel.

r247381:

  Remove a scatalogical debug printf that crept in.
2014-04-03 21:39:59 +00:00
Marcel Moolenaar
e681e3cd56 Revert previous commit: EFI_STATUS is a 64-bit integral on ia64. Fix the
compile warning on i386 (where EFI_STATUS is a 32-bit integral) by casting
the status argument to u_long instead.

Pointy hat: brucec
MFC after: 3 days
2011-03-16 00:08:10 +00:00
Rebecca Cran
ce52330412 Handle memory allocation failures in include().
PR:		i386/85652
Submitted by:	Ben Thomas <bthomas at virtualiron.com>
MFC after:	3 days
2011-02-23 17:17:05 +00:00
Marcel Moolenaar
1f60bb276b Help static analysis by initializing variables that we know cannot be
used uninitialized, but which cannot be inferred from the code itself.
2011-01-06 20:50:16 +00:00
Marcel Moolenaar
716f79c093 Remove file system support based on the simple file system protocol
as this only allows us to access file systems that EFI knows about.
With a loader that can only use EFI-supported file systems, we're
forced to put /boot on the EFI system partition. This is suboptimal
in the following ways:
1.  With /boot a symlink to /efi/boot, mergemaster complains about
    the mismatch and there's no quick solution.
2.  The EFI loader can only boot a single version of FreeBSD. There's
    no way to install multiple versions of FreeBSD and select one
    at the loader prompt.
3.  ZFS maintains /boot/zfs/zpool.cache and with /boot a symlink we
    end up with the file on a MSDOS file system. ZFS does not have
    proper handling of file systems that are under Giant.

Implement a disk device based on the block I/O protocol instead and
pull in file system code from libstand. The disk devices are really
the partitions that EFI knows about.

This change is backward compatible.

MFC after:	1 week
2010-01-09 22:54:29 +00:00