Bug 216964 - boot1.efi: can't boot from ZFS on 4kn HDD
Summary: boot1.efi: can't boot from ZFS on 4kn HDD
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 11.0-RELEASE
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-fs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-10 13:14 UTC by Serhii (Sergey) Kozlov
Modified: 2017-05-22 15:40 UTC (History)
3 users (show)

See Also:


Attachments
Screenshot of boot1 failure w/EFI_DEBUG enabled (34.72 KB, image/png)
2017-02-10 13:14 UTC, Serhii (Sergey) Kozlov
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Serhii (Sergey) Kozlov freebsd_committer freebsd_triage 2017-02-10 13:14:01 UTC
Created attachment 179826 [details]
Screenshot of boot1 failure w/EFI_DEBUG enabled

boot1.efi can't find /boot/loader.efi on ZFS root installed onto 4kn drive

Details:
- The OS was installed by using standard bsdinstall approach with the following options:
  - Drive schema: ada0 stripe
  - Swap size: 2g
  - Encrypt swap: YES
  - Boot schema: GPT (UEFI)
- The screenshot of failure is attached. boot1.efifat was built with -DEFI_DEBUG flag
- Able to boot from UFS root on the same HW w/o a problem
- Able to get the same behavior emulated in bhyve using file-backed memory disk with 4096 sector size. Might be useful for debugging

- Additional information about the drive:
# camcontrol identify ada0
pass1: <ST2000NM0105-1YY104 NN02> ACS-3 ATA SATA 3.x device
pass1: 600.000MB/s transfers (SATA 3.x, UDMA6, PIO 8192bytes)

protocol              ATA/ATAPI-10 SATA 3.x
device model          ST2000NM0105-1YY104
firmware revision     NN02
serial number         ZC200L2G
WWN                   5000c500915c633f
cylinders             16383
heads                 16
sectors/track         63
sector size           logical 4096, physical 4096, offset 0
LBA supported         268435455 sectors
LBA48 supported       488378646 sectors
PIO supported         PIO4
DMA supported         WDMA2 UDMA6 
media RPM             7200

Feature                      Support  Enabled   Value           Vendor
read ahead                     yes      yes
write cache                    yes      yes
flush cache                    yes      yes
overlap                        no
Tagged Command Queuing (TCQ)   no       no
Native Command Queuing (NCQ)   yes              32 tags
NCQ Queue Management           no
NCQ Streaming                  no
Receive & Send FPDMA Queued    yes
SMART                          yes      yes
microcode download             yes      yes
security                       yes      no
power management               yes      yes
advanced power management      no       no
automatic acoustic management  no       no
media status notification      no       no
power-up in Standby            yes      no
write-read-verify              yes      no      0/0x0
unload                         yes      yes
general purpose logging        yes      yes
free-fall                      no       no
Data Set Management (DSM/TRIM) no
Host Protected Area (HPA)      no
# gpart show ada0
=>        6  488378635  ada0  GPT  (1.8T)
          6        200     1  efi  (800K)
        206         50        - free -  (200K)
        256     524288     2  freebsd-swap  (2.0G)
     524544  487854080     3  freebsd-zfs  (1.8T)
  488378624         17        - free -  (68K)
Comment 1 Serhii (Sergey) Kozlov freebsd_committer freebsd_triage 2017-02-10 13:14:57 UTC
Sponsored by: Intel Corporation
Comment 2 Serhii (Sergey) Kozlov freebsd_committer freebsd_triage 2017-02-10 13:45:21 UTC
Tried to use boot1.efi built from latest 12.0-CURRENT sources - result is exactly the same.
Comment 3 Steven Hartland freebsd_committer freebsd_triage 2017-02-10 13:57:38 UTC
Might be related to:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=144234

Might be worth testing Allan's patch on there.
Comment 4 Serhii (Sergey) Kozlov freebsd_committer freebsd_triage 2017-02-27 17:01:04 UTC
(In reply to Steven Hartland from comment #3)
Tried Allan's patch on head, had to do some minor adjustments so the patch applies cleanly. The result is exactly the same.
Comment 5 Toomas Soome freebsd_committer freebsd_triage 2017-03-02 18:39:12 UTC
(In reply to Sergey Kozlov from comment #4)

The hint is on the screenshot; error 4 is EFI_BAD_BUFFER_SIZE; and indeed, the read size is 2048, thats half the sector. So the solution is that we need boot1 to use buffer if the sector size is >512B.

The similar problem most likely will hit us in loader.efi.

The UFS is working because the ufs is using 4k data blocks - that is, all reads are at least 4k.

Hm, I think... probably the best solution is to make sure zfs code does provide at least sector size buffer for reads. It is quite easy to do with 12-current, for 11, we would need to backport some updates.
Comment 6 Toomas Soome freebsd_committer freebsd_triage 2017-03-02 19:46:45 UTC
Please check if the patch from https://reviews.freebsd.org/D9870 will help.
Comment 7 Serhii (Sergey) Kozlov freebsd_committer freebsd_triage 2017-03-03 14:48:56 UTC
(In reply to Toomas Soome from comment #6)

The patch worked, details are added to the review comments. Thank you!
Comment 8 Toomas Soome freebsd_committer freebsd_triage 2017-03-03 15:49:55 UTC
(In reply to Sergey Kozlov from comment #7)

After I did check on efipart.c (used by loader), I found that it already does address the large sector issue on its own, so that part is also covered; it really does make the life a lot simpler. Thanks for feedback and I'll seek to have the patch commited.
Comment 9 commit-hook freebsd_committer freebsd_triage 2017-03-15 19:48:33 UTC
A commit references this bug:

Author: tsoome
Date: Wed Mar 15 19:48:22 UTC 2017
New revision: 315326
URL: https://svnweb.freebsd.org/changeset/base/315326

Log:
  boot1.efi: can't boot from ZFS on 4kn HDD

  The boot1.efi immediate issue from PR216964 is that we are reading into
  too small buffer, from UEFI spec 2.6:

  The size of the Buffer in bytes. This must be a multiple of the intrinsic block size of the device.

  The secondary issue is that LBA calculation does not check reminder from
  division.

  This fix does check the provided buffer size and if we read less than
  media sector size or the read offset is not aligned to sector boundary,
  we allocate bounce buffer and perform the read by single sector.

  PR:		216964
  Reported by:	Sergey Kozlov
  Reviewed by:	allanjude, Sergey Kozlov
  Approved by:	allanjude (mentor)
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D9870

Changes:
  head/sys/boot/efi/boot1/zfs_module.c
Comment 10 commit-hook freebsd_committer freebsd_triage 2017-03-30 17:27:11 UTC
A commit references this bug:

Author: tsoome
Date: Thu Mar 30 17:23:41 UTC 2017
New revision: 316282
URL: https://svnweb.freebsd.org/changeset/base/316282

Log:
  boot1.efi: can't boot from ZFS on 4kn HDD

  The boot1.efi immediate issue from PR216964 is that we are reading into
  too small buffer, from UEFI spec 2.6:

  The size of the Buffer in bytes. This must be a multiple of the intrinsic block size of the device.

  The secondary issue is that LBA calculation does not check reminder from
  division.

  This fix does check the provided buffer size and if we read less than
  media sector size or the read offset is not aligned to sector boundary,
  we allocate bounce buffer and perform the read by single sector.

  PR:		216964
  Reported by:	Sergey Kozlov
  Reviewed by:	allanjude, Sergey Kozlov
  Approved by:	allanjude (mentor)
  Differential Revision:	https://reviews.freebsd.org/D9870

Changes:
_U  stable/11/
  stable/11/sys/boot/efi/boot1/zfs_module.c