diff --git a/debian/changelog b/debian/changelog index 4813cef21..73c261977 100644 --- a/debian/changelog +++ b/debian/changelog @@ -30,6 +30,38 @@ linux-2.6 (3.3~rc6-1~experimental.1) experimental; urgency=low -- Ben Hutchings Sun, 04 Mar 2012 20:27:42 +0000 +linux-2.6 (3.2.16-1) unstable; urgency=low + + * New upstream stable update: + http://www.kernel.org/pub/linux/kernel/v3.x/ChangeLog-3.2.16 + - drm/i915: properly compute dp dithering for user-created modes + (Closes: #666360) + - md/bitmap: prevent bitmap_daemon_work running while initialising bitmap + - [ia64] Fix futex_atomic_cmpxchg_inatomic() (Closes: #659485) + - USB: serial: fix race between probe and open + - fcaps: clear the same personality flags as suid when fcaps are used + (CVE-2012-2123) + - ACPICA: Fix to allow region arguments to reference other scopes + (Closes: #661581) + - futex: Do not leak robust list to unprivileged process + - drm/radeon/kms: fix the regression of DVI connector check + (Closes: #670047) + + [ Ben Hutchings ] + * rt2x00: Identify rt2800usb chipsets. (Closes: #658067) + * [x86] Add EFI boot stub support (Closes: #669033) + * brcmsmac: "INTERMEDIATE but not AMPDU" only when tracing + * NFSv4: Fix error handling and improve error reporting for file locking + (Closes: #669270) + - Rate limit the state manager for lock reclaim warning messages + - Ensure that the LOCK code sets exception->inode + - Ensure that we check lock exclusive/shared type against open modes + * [x86] i915: Fix integer overflows in i915_gem_{do_execbuffer,execbuffer2} + * Revert "autofs: work around unhappy compat problem on x86-64". + Reopens #633423. + + -- Ben Hutchings Sun, 29 Apr 2012 08:00:53 +0100 + linux-2.6 (3.2.15-1) unstable; urgency=high * New upstream stable update: diff --git a/debian/config/kernelarch-x86/config b/debian/config/kernelarch-x86/config index 26ba66bd3..49ff1f736 100644 --- a/debian/config/kernelarch-x86/config +++ b/debian/config/kernelarch-x86/config @@ -44,6 +44,7 @@ CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT=0 CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT=1 CONFIG_X86_PAT=y CONFIG_EFI=y +CONFIG_EFI_STUB=y CONFIG_SECCOMP=y CONFIG_CC_STACKPROTECTOR=y CONFIG_KEXEC=y diff --git a/debian/lib/python/debian_linux/firmware.py b/debian/lib/python/debian_linux/firmware.py index cc91ae7e0..ece3743d3 100644 --- a/debian/lib/python/debian_linux/firmware.py +++ b/debian/lib/python/debian_linux/firmware.py @@ -25,7 +25,7 @@ class FirmwareWhence(list): driver = None files = {} licence = None - binary = None + binary = [] desc = None source = [] version = None @@ -48,9 +48,13 @@ class FirmwareWhence(list): if line == '\n': # End of field; end of file fields - if binary: - files[binary] = FirmwareFile(binary, desc, source, version) - binary = None + for b in binary: + # XXX The WHENCE file isn't yet consistent in its + # association of binaries and their sources and + # metadata. This associates all sources and + # metadata in a group with each binary. + files[b] = FirmwareFile(b, desc, source, version) + binary = [] desc = None source = [] version = None @@ -66,7 +70,7 @@ class FirmwareWhence(list): driver = value.split(' ')[0].lower() elif keyword == 'File': match = re.match(r'(\S+)(?:\s+--\s+(.*))?', value) - binary = match.group(1) + binary.append(match.group(1)) desc = match.group(2) elif keyword in ['Info', 'Version']: version = value @@ -79,7 +83,7 @@ class FirmwareWhence(list): re.sub(r'^(?:[/ ]\*| \*/)?\s*(.*?)\s*$', r'\1', line)) # Finish last section if non-empty - if binary: - files[binary] = FirmwareFile(binary, desc, source, version) + for b in binary: + files[b] = FirmwareFile(b, desc, source, version) if driver: self.append(FirmwareSection(driver, files, licence)) diff --git a/debian/patches/bugfix/all/NFSv4-Ensure-that-the-LOCK-code-sets-exception-inode.patch b/debian/patches/bugfix/all/NFSv4-Ensure-that-the-LOCK-code-sets-exception-inode.patch new file mode 100644 index 000000000..6a9e5b9d5 --- /dev/null +++ b/debian/patches/bugfix/all/NFSv4-Ensure-that-the-LOCK-code-sets-exception-inode.patch @@ -0,0 +1,52 @@ +From: Trond Myklebust +Date: Wed, 18 Apr 2012 12:20:10 -0400 +Subject: [PATCH 1/2] NFSv4: Ensure that the LOCK code sets exception->inode + +commit 05ffe24f5290dc095f98fbaf84afe51ef404ccc5 upstream. + +All callers of nfs4_handle_exception() that need to handle +NFS4ERR_OPENMODE correctly should set exception->inode + +Signed-off-by: Trond Myklebust +Cc: stable@vger.kernel.org +--- + fs/nfs/nfs4proc.c | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c +index f82bde0..3c787d0 100644 +--- a/fs/nfs/nfs4proc.c ++++ b/fs/nfs/nfs4proc.c +@@ -4558,7 +4558,9 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f + static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) + { + struct nfs_server *server = NFS_SERVER(state->inode); +- struct nfs4_exception exception = { }; ++ struct nfs4_exception exception = { ++ .inode = state->inode, ++ }; + int err; + + do { +@@ -4576,7 +4578,9 @@ static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request + static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) + { + struct nfs_server *server = NFS_SERVER(state->inode); +- struct nfs4_exception exception = { }; ++ struct nfs4_exception exception = { ++ .inode = state->inode, ++ }; + int err; + + err = nfs4_set_lock_state(state, request); +@@ -4676,6 +4680,7 @@ static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock * + { + struct nfs4_exception exception = { + .state = state, ++ .inode = state->inode, + }; + int err; + +-- +1.7.10 + diff --git a/debian/patches/bugfix/all/NFSv4-Ensure-that-we-check-lock-exclusive-shared-typ.patch b/debian/patches/bugfix/all/NFSv4-Ensure-that-we-check-lock-exclusive-shared-typ.patch new file mode 100644 index 000000000..8eda0d139 --- /dev/null +++ b/debian/patches/bugfix/all/NFSv4-Ensure-that-we-check-lock-exclusive-shared-typ.patch @@ -0,0 +1,44 @@ +From: Trond Myklebust +Date: Wed, 18 Apr 2012 12:48:35 -0400 +Subject: [PATCH 2/2] NFSv4: Ensure that we check lock exclusive/shared type + against open modes + +commit 55725513b5ef9d462aa3e18527658a0362aaae83 upstream. + +Since we may be simulating flock() locks using NFS byte range locks, +we can't rely on the VFS having checked the file open mode for us. + +Signed-off-by: Trond Myklebust +Cc: stable@vger.kernel.org +--- + fs/nfs/nfs4proc.c | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c +index 3c787d0..ba837d9 100644 +--- a/fs/nfs/nfs4proc.c ++++ b/fs/nfs/nfs4proc.c +@@ -4726,6 +4726,20 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) + + if (state == NULL) + return -ENOLCK; ++ /* ++ * Don't rely on the VFS having checked the file open mode, ++ * since it won't do this for flock() locks. ++ */ ++ switch (request->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) { ++ case F_RDLCK: ++ if (!(filp->f_mode & FMODE_READ)) ++ return -EBADF; ++ break; ++ case F_WRLCK: ++ if (!(filp->f_mode & FMODE_WRITE)) ++ return -EBADF; ++ } ++ + do { + status = nfs4_proc_setlk(state, cmd, request); + if ((status != -EAGAIN) || IS_SETLK(cmd)) +-- +1.7.10 + diff --git a/debian/patches/bugfix/all/NFSv4-Rate-limit-the-state-manager-for-lock-reclaim-.patch b/debian/patches/bugfix/all/NFSv4-Rate-limit-the-state-manager-for-lock-reclaim-.patch new file mode 100644 index 000000000..972e21eb0 --- /dev/null +++ b/debian/patches/bugfix/all/NFSv4-Rate-limit-the-state-manager-for-lock-reclaim-.patch @@ -0,0 +1,28 @@ +From: William Dauchy +Date: Wed, 14 Mar 2012 12:32:04 +0100 +Subject: [PATCH] NFSv4: Rate limit the state manager for lock reclaim warning + messages + +commit 96dcadc2fdd111dca90d559f189a30c65394451a upstream. + +Adding rate limit on `Lock reclaim failed` messages since it could fill +up system logs +Signed-off-by: William Dauchy +Signed-off-by: Trond Myklebust +[bwh: Backported to 3.2: add the 'NFS:' prefix at the same time] +Signed-off-by: Ben Hutchings +--- +--- a/fs/nfs/nfs4state.c ++++ b/fs/nfs/nfs4state.c +@@ -1261,8 +1261,9 @@ restart: + spin_lock(&state->state_lock); + list_for_each_entry(lock, &state->lock_states, ls_locks) { + if (!(lock->ls_flags & NFS_LOCK_INITIALIZED)) +- printk("%s: Lock reclaim failed!\n", +- __func__); ++ pr_warn_ratelimited("NFS: " ++ "%s: Lock reclaim " ++ "failed!\n", __func__); + } + spin_unlock(&state->state_lock); + nfs4_put_open_state(state); diff --git a/debian/patches/bugfix/all/brcmsmac-INTERMEDIATE-but-not-AMPDU-only-when-tracin.patch b/debian/patches/bugfix/all/brcmsmac-INTERMEDIATE-but-not-AMPDU-only-when-tracin.patch new file mode 100644 index 000000000..3d36af9fc --- /dev/null +++ b/debian/patches/bugfix/all/brcmsmac-INTERMEDIATE-but-not-AMPDU-only-when-tracin.patch @@ -0,0 +1,42 @@ +From: Eldad Zack +Date: Sun, 22 Apr 2012 00:48:04 +0200 +Subject: [PATCH] brcmsmac: "INTERMEDIATE but not AMPDU" only when tracing + +commit 6ead629b27269c553c9092c47cd8f5ab0309ee3b upstream. + +I keep getting the following messages on the log buffer: +[ 2167.097507] ieee80211 phy0: brcms_c_dotxstatus: INTERMEDIATE but not AMPDU +[ 2281.331305] ieee80211 phy0: brcms_c_dotxstatus: INTERMEDIATE but not AMPDU +[ 2281.332539] ieee80211 phy0: brcms_c_dotxstatus: INTERMEDIATE but not AMPDU +[ 2329.876605] ieee80211 phy0: brcms_c_dotxstatus: INTERMEDIATE but not AMPDU +[ 2329.877354] ieee80211 phy0: brcms_c_dotxstatus: INTERMEDIATE but not AMPDU +[ 2462.280756] ieee80211 phy0: brcms_c_dotxstatus: INTERMEDIATE but not AMPDU +[ 2615.651689] ieee80211 phy0: brcms_c_dotxstatus: INTERMEDIATE but not AMPDU + +From the code comment I understand that this something that can - +and does, quite frequently - happen. + +Signed-off-by: Eldad Zack +Acked-by: Franky Lin +Signed-off-by: John W. Linville +--- + drivers/net/wireless/brcm80211/brcmsmac/main.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/drivers/net/wireless/brcm80211/brcmsmac/main.c b/drivers/net/wireless/brcm80211/brcmsmac/main.c +index 7083db7..b4d9279 100644 +--- a/drivers/net/wireless/brcm80211/brcmsmac/main.c ++++ b/drivers/net/wireless/brcm80211/brcmsmac/main.c +@@ -847,8 +847,7 @@ brcms_c_dotxstatus(struct brcms_c_info *wlc, struct tx_status *txs) + */ + if (!(txs->status & TX_STATUS_AMPDU) + && (txs->status & TX_STATUS_INTERMEDIATE)) { +- wiphy_err(wlc->wiphy, "%s: INTERMEDIATE but not AMPDU\n", +- __func__); ++ BCMMSG(wlc->wiphy, "INTERMEDIATE but not AMPDU\n"); + return false; + } + +-- +1.7.10 + diff --git a/debian/patches/bugfix/all/revert-autofs-work-around-unhappy-compat-problem-on-.patch b/debian/patches/bugfix/all/revert-autofs-work-around-unhappy-compat-problem-on-.patch new file mode 100644 index 000000000..1516e8712 --- /dev/null +++ b/debian/patches/bugfix/all/revert-autofs-work-around-unhappy-compat-problem-on-.patch @@ -0,0 +1,133 @@ +From: Linus Torvalds +Date: Sat, 28 Apr 2012 08:29:56 -0700 +Subject: [PATCH] Revert "autofs: work around unhappy compat problem on + x86-64" + +commit fcbf94b9dedd2ce08e798a99aafc94fec8668161 upstream. + +This reverts commit a32744d4abae24572eff7269bc17895c41bd0085. + +While that commit was technically the right thing to do, and made the +x86-64 compat mode work identically to native 32-bit mode (and thus +fixing the problem with a 32-bit systemd install on a 64-bit kernel), it +turns out that the automount binaries had workarounds for this compat +problem. + +Now, the workarounds are disgusting: doing an "uname()" to find out the +architecture of the kernel, and then comparing it for the 64-bit cases +and fixing up the size of the read() in automount for those. And they +were confused: it's not actually a generic 64-bit issue at all, it's +very much tied to just x86-64, which has different alignment for an +'u64' in 64-bit mode than in 32-bit mode. + +But the end result is that fixing the compat layer actually breaks the +case of a 32-bit automount on a x86-64 kernel. + +There are various approaches to fix this (including just doing a +"strcmp()" on current->comm and comparing it to "automount"), but I +think that I will do the one that teaches pipes about a special "packet +mode", which will allow user space to not have to care too deeply about +the padding at the end of the autofs packet. + +That change will make the compat workaround unnecessary, so let's revert +it first, and get automount working again in compat mode. The +packetized pipes will then fix autofs for systemd. + +Reported-and-requested-by: Michael Tokarev +Cc: Ian Kent +Cc: stable@kernel.org # for 3.3 +Signed-off-by: Linus Torvalds +--- + fs/autofs4/autofs_i.h | 1 - + fs/autofs4/dev-ioctl.c | 1 - + fs/autofs4/inode.c | 2 -- + fs/autofs4/waitq.c | 22 +++------------------- + 4 files changed, 3 insertions(+), 23 deletions(-) + +diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h +index eb1cc92..d8d8e7b 100644 +--- a/fs/autofs4/autofs_i.h ++++ b/fs/autofs4/autofs_i.h +@@ -110,7 +110,6 @@ struct autofs_sb_info { + int sub_version; + int min_proto; + int max_proto; +- int compat_daemon; + unsigned long exp_timeout; + unsigned int type; + int reghost_enabled; +diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c +index 9dacb85..3dfd615 100644 +--- a/fs/autofs4/dev-ioctl.c ++++ b/fs/autofs4/dev-ioctl.c +@@ -385,7 +385,6 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp, + sbi->pipefd = pipefd; + sbi->pipe = pipe; + sbi->catatonic = 0; +- sbi->compat_daemon = is_compat_task(); + } + out: + mutex_unlock(&sbi->wq_mutex); +diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c +index d8dc002..14c7bc0 100644 +--- a/fs/autofs4/inode.c ++++ b/fs/autofs4/inode.c +@@ -19,7 +19,6 @@ + #include + #include + #include +-#include + #include "autofs_i.h" + #include + +@@ -225,7 +224,6 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent) + set_autofs_type_indirect(&sbi->type); + sbi->min_proto = 0; + sbi->max_proto = 0; +- sbi->compat_daemon = is_compat_task(); + mutex_init(&sbi->wq_mutex); + mutex_init(&sbi->pipe_mutex); + spin_lock_init(&sbi->fs_lock); +diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c +index 9c098db..da8876d 100644 +--- a/fs/autofs4/waitq.c ++++ b/fs/autofs4/waitq.c +@@ -91,24 +91,7 @@ static int autofs4_write(struct autofs_sb_info *sbi, + + return (bytes > 0); + } +- +-/* +- * The autofs_v5 packet was misdesigned. +- * +- * The packets are identical on x86-32 and x86-64, but have different +- * alignment. Which means that 'sizeof()' will give different results. +- * Fix it up for the case of running 32-bit user mode on a 64-bit kernel. +- */ +-static noinline size_t autofs_v5_packet_size(struct autofs_sb_info *sbi) +-{ +- size_t pktsz = sizeof(struct autofs_v5_packet); +-#if defined(CONFIG_X86_64) && defined(CONFIG_COMPAT) +- if (sbi->compat_daemon > 0) +- pktsz -= 4; +-#endif +- return pktsz; +-} +- ++ + static void autofs4_notify_daemon(struct autofs_sb_info *sbi, + struct autofs_wait_queue *wq, + int type) +@@ -172,7 +155,8 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi, + { + struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet; + +- pktsz = autofs_v5_packet_size(sbi); ++ pktsz = sizeof(*packet); ++ + packet->wait_queue_token = wq->wait_queue_token; + packet->len = wq->name.len; + memcpy(packet->name, wq->name.name, wq->name.len); +-- +1.7.10 + diff --git a/debian/patches/bugfix/x86/drm-i915-fix-integer-overflow-in-i915_gem_do_execbuffer.patch b/debian/patches/bugfix/x86/drm-i915-fix-integer-overflow-in-i915_gem_do_execbuffer.patch new file mode 100644 index 000000000..032ac89ac --- /dev/null +++ b/debian/patches/bugfix/x86/drm-i915-fix-integer-overflow-in-i915_gem_do_execbuffer.patch @@ -0,0 +1,38 @@ +From: Xi Wang +Date: Mon, 23 Apr 2012 04:06:42 -0400 +Message-Id: <1335168402-25174-2-git-send-email-xi.wang@gmail.com> +Subject: [PATCH v2 2/2] drm/i915: fix integer overflow in + i915_gem_do_execbuffer() + +On 32-bit systems, a large args->num_cliprects from userspace via ioctl +may overflow the allocation size, leading to out-of-bounds access. + +This vulnerability was introduced in commit 432e58ed ("drm/i915: Avoid +allocation for execbuffer object list"). + +Signed-off-by: Xi Wang +Cc: Chris Wilson +Cc: stable@vger.kernel.org +--- + drivers/gpu/drm/i915/i915_gem_execbuffer.c | 5 +++++ + 1 files changed, 5 insertions(+), 0 deletions(-) + +diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c +index 7c50e58..de43194 100644 +--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c ++++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c +@@ -1133,6 +1133,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, + return -EINVAL; + } + ++ if (args->num_cliprects > UINT_MAX / sizeof(*cliprects)) { ++ DRM_DEBUG("execbuf with %u cliprects\n", ++ args->num_cliprects); ++ return -EINVAL; ++ } + cliprects = kmalloc(args->num_cliprects * sizeof(*cliprects), + GFP_KERNEL); + if (cliprects == NULL) { +-- +1.7.5.4 + diff --git a/debian/patches/bugfix/x86/drm-i915-fix-integer-overflow-in-i915_gem_execbuffer2.patch b/debian/patches/bugfix/x86/drm-i915-fix-integer-overflow-in-i915_gem_execbuffer2.patch new file mode 100644 index 000000000..bb39a6254 --- /dev/null +++ b/debian/patches/bugfix/x86/drm-i915-fix-integer-overflow-in-i915_gem_execbuffer2.patch @@ -0,0 +1,37 @@ +From: Xi Wang +Date: Mon, 23 Apr 2012 04:06:41 -0400 +Message-Id: <1335168402-25174-1-git-send-email-xi.wang@gmail.com> +Subject: [PATCH v2 1/2] drm/i915: fix integer overflow in + i915_gem_execbuffer2() + +On 32-bit systems, a large args->buffer_count from userspace via ioctl +may overflow the allocation size, leading to out-of-bounds access. + +This vulnerability was introduced in commit 8408c282 ("drm/i915: +First try a normal large kmalloc for the temporary exec buffers"). + +Signed-off-by: Xi Wang +Cc: Chris Wilson +Cc: stable@vger.kernel.org +[bwh: Backported to 3.2: adjust context] +--- + drivers/gpu/drm/i915/i915_gem_execbuffer.c | 3 ++- + 1 files changed, 2 insertions(+), 1 deletions(-) + +diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c +index f51a696..7c50e58 100644 +--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c ++++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c +@@ -1404,7 +1404,8 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data, + struct drm_i915_gem_exec_object2 *exec2_list = NULL; + int ret; + +- if (args->buffer_count < 1) { ++ if (args->buffer_count < 1 || ++ args->buffer_count > UINT_MAX / sizeof(*exec2_list)) { + DRM_ERROR("execbuf2 with %d buffers\n", args->buffer_count); + return -EINVAL; + } +-- +1.7.5.4 + diff --git a/debian/patches/features/x86/efi-stub/0001-x86-Add-missing-bzImage-fields-to-struct-setup_heade.patch b/debian/patches/features/x86/efi-stub/0001-x86-Add-missing-bzImage-fields-to-struct-setup_heade.patch new file mode 100644 index 000000000..e3c1853a9 --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0001-x86-Add-missing-bzImage-fields-to-struct-setup_heade.patch @@ -0,0 +1,34 @@ +From: Matt Fleming +Date: Sat, 27 Aug 2011 09:35:45 +0100 +Subject: [PATCH 01/11] x86: Add missing bzImage fields to struct setup_header + +commit 8af21e7e71d1ac56d9b66fb787a14fd66af7f5f7 upstream. + +commit 37ba7ab5e33c ("x86, boot: make kernel_alignment adjustable; new +bzImage fields") introduced some new fields into the bzImage header +but struct setup_header was not updated accordingly. Add the missing +'pref_address' and 'init_size' fields. + +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1318848017-12301-1-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + arch/x86/include/asm/bootparam.h | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/arch/x86/include/asm/bootparam.h b/arch/x86/include/asm/bootparam.h +index e020d88..2f90c51 100644 +--- a/arch/x86/include/asm/bootparam.h ++++ b/arch/x86/include/asm/bootparam.h +@@ -64,6 +64,8 @@ struct setup_header { + __u32 payload_offset; + __u32 payload_length; + __u64 setup_data; ++ __u64 pref_address; ++ __u32 init_size; + } __attribute__((packed)); + + struct sys_desc_table { +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0002-x86-Don-t-use-magic-strings-for-EFI-loader-signature.patch b/debian/patches/features/x86/efi-stub/0002-x86-Don-t-use-magic-strings-for-EFI-loader-signature.patch new file mode 100644 index 000000000..c65676874 --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0002-x86-Don-t-use-magic-strings-for-EFI-loader-signature.patch @@ -0,0 +1,61 @@ +From: Matt Fleming +Date: Tue, 15 Nov 2011 12:56:14 +0000 +Subject: [PATCH 02/11] x86: Don't use magic strings for EFI loader signature + +commit f7d7d01be53cb47e0ae212c4e968aa28b82d2138 upstream. + +Introduce a symbol, EFI_LOADER_SIGNATURE instead of using the magic +strings, which also helps to reduce the amount of ifdeffery. + +Cc: Matthew Garrett +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1318848017-12301-1-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + arch/x86/include/asm/efi.h | 4 ++++ + arch/x86/kernel/setup.c | 7 +------ + 2 files changed, 5 insertions(+), 6 deletions(-) + +diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h +index b8d8bfc..26d8c18 100644 +--- a/arch/x86/include/asm/efi.h ++++ b/arch/x86/include/asm/efi.h +@@ -3,6 +3,8 @@ + + #ifdef CONFIG_X86_32 + ++#define EFI_LOADER_SIGNATURE "EL32" ++ + extern unsigned long asmlinkage efi_call_phys(void *, ...); + + #define efi_call_phys0(f) efi_call_phys(f) +@@ -35,6 +37,8 @@ extern unsigned long asmlinkage efi_call_phys(void *, ...); + + #else /* !CONFIG_X86_32 */ + ++#define EFI_LOADER_SIGNATURE "EL64" ++ + extern u64 efi_call0(void *fp); + extern u64 efi_call1(void *fp, u64 arg1); + extern u64 efi_call2(void *fp, u64 arg1, u64 arg2); +diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c +index 9a9e40f..4d5243c 100644 +--- a/arch/x86/kernel/setup.c ++++ b/arch/x86/kernel/setup.c +@@ -752,12 +752,7 @@ void __init setup_arch(char **cmdline_p) + #endif + #ifdef CONFIG_EFI + if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature, +-#ifdef CONFIG_X86_32 +- "EL32", +-#else +- "EL64", +-#endif +- 4)) { ++ EFI_LOADER_SIGNATURE, 4)) { + efi_enabled = 1; + efi_memblock_x86_reserve_range(); + } +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0003-efi.h-Add-struct-definition-for-boot-time-services.patch b/debian/patches/features/x86/efi-stub/0003-efi.h-Add-struct-definition-for-boot-time-services.patch new file mode 100644 index 000000000..f8ea6b08f --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0003-efi.h-Add-struct-definition-for-boot-time-services.patch @@ -0,0 +1,91 @@ +From: Matt Fleming +Date: Tue, 15 Nov 2011 12:56:32 +0000 +Subject: [PATCH 03/11] efi.h: Add struct definition for boot time services + +commit f30ca6ba0bb2b7d050f24682bb8639c939c79859 upstream. + +With the forthcoming efi stub code we're gonna need to access boot +time services so let's define a struct so we can access the functions. + +Cc: Matthew Garrett +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1318848017-12301-1-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + include/linux/efi.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 52 insertions(+), 1 deletion(-) + +diff --git a/include/linux/efi.h b/include/linux/efi.h +index 2362a0b..9547597 100644 +--- a/include/linux/efi.h ++++ b/include/linux/efi.h +@@ -139,6 +139,57 @@ typedef struct { + } efi_time_cap_t; + + /* ++ * EFI Boot Services table ++ */ ++typedef struct { ++ efi_table_hdr_t hdr; ++ void *raise_tpl; ++ void *restore_tpl; ++ void *allocate_pages; ++ void *free_pages; ++ void *get_memory_map; ++ void *allocate_pool; ++ void *free_pool; ++ void *create_event; ++ void *set_timer; ++ void *wait_for_event; ++ void *signal_event; ++ void *close_event; ++ void *check_event; ++ void *install_protocol_interface; ++ void *reinstall_protocol_interface; ++ void *uninstall_protocol_interface; ++ void *handle_protocol; ++ void *__reserved; ++ void *register_protocol_notify; ++ void *locate_handle; ++ void *locate_device_path; ++ void *install_configuration_table; ++ void *load_image; ++ void *start_image; ++ void *exit; ++ void *unload_image; ++ void *exit_boot_services; ++ void *get_next_monotonic_count; ++ void *stall; ++ void *set_watchdog_timer; ++ void *connect_controller; ++ void *disconnect_controller; ++ void *open_protocol; ++ void *close_protocol; ++ void *open_protocol_information; ++ void *protocols_per_handle; ++ void *locate_handle_buffer; ++ void *locate_protocol; ++ void *install_multiple_protocol_interfaces; ++ void *uninstall_multiple_protocol_interfaces; ++ void *calculate_crc32; ++ void *copy_mem; ++ void *set_mem; ++ void *create_event_ex; ++} efi_boot_services_t; ++ ++/* + * Types and defines for EFI ResetSystem + */ + #define EFI_RESET_COLD 0 +@@ -261,7 +312,7 @@ typedef struct { + unsigned long stderr_handle; + unsigned long stderr; + efi_runtime_services_t *runtime; +- unsigned long boottime; ++ efi_boot_services_t *boottime; + unsigned long nr_tables; + unsigned long tables; + } efi_system_table_t; +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0004-efi.h-Add-efi_image_loaded_t.patch b/debian/patches/features/x86/efi-stub/0004-efi.h-Add-efi_image_loaded_t.patch new file mode 100644 index 000000000..80773e32e --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0004-efi.h-Add-efi_image_loaded_t.patch @@ -0,0 +1,59 @@ +From: Matt Fleming +Date: Tue, 15 Nov 2011 12:56:50 +0000 +Subject: [PATCH 04/11] efi.h: Add efi_image_loaded_t + +commit 8e84f345e2f2189a37492c77c566c7494b7b6b23 upstream. + +Add the EFI loaded image structure and protocol guid which are +required by the x86 EFI boot stub. The EFI boot stub uses the +structure to figure out where it was loaded in memory and to pass +command line arguments to the kernel. + +Cc: Matthew Garrett +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1318848017-12301-1-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + include/linux/efi.h | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +diff --git a/include/linux/efi.h b/include/linux/efi.h +index 9547597..e35005f 100644 +--- a/include/linux/efi.h ++++ b/include/linux/efi.h +@@ -287,6 +287,9 @@ typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules, + #define LINUX_EFI_CRASH_GUID \ + EFI_GUID( 0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0 ) + ++#define LOADED_IMAGE_PROTOCOL_GUID \ ++ EFI_GUID( 0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b ) ++ + typedef struct { + efi_guid_t guid; + unsigned long table; +@@ -326,6 +329,22 @@ struct efi_memory_map { + unsigned long desc_size; + }; + ++typedef struct { ++ u32 revision; ++ void *parent_handle; ++ efi_system_table_t *system_table; ++ void *device_handle; ++ void *file_path; ++ void *reserved; ++ u32 load_options_size; ++ void *load_options; ++ void *image_base; ++ __aligned_u64 image_size; ++ unsigned int image_code_type; ++ unsigned int image_data_type; ++ unsigned long unload; ++} efi_loaded_image_t; ++ + #define EFI_INVALID_TABLE_ADDR (~0UL) + + /* +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0005-efi.h-Add-allocation-types-for-boottime-allocate_pag.patch b/debian/patches/features/x86/efi-stub/0005-efi.h-Add-allocation-types-for-boottime-allocate_pag.patch new file mode 100644 index 000000000..ddecd43dd --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0005-efi.h-Add-allocation-types-for-boottime-allocate_pag.patch @@ -0,0 +1,41 @@ +From: Matt Fleming +Date: Tue, 15 Nov 2011 12:57:03 +0000 +Subject: [PATCH 05/11] efi.h: Add allocation types for + boottime->allocate_pages() + +commit bb05e4ba452ada7966fbced4e829aa029f546445 upstream. + +Add the allocation types detailed in section 6.2 - "AllocatePages()" +of the UEFI 2.3 specification. These definitions will be used by the +x86 EFI boot stub which needs to allocate memory during boot. + +Cc: Matthew Garrett +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1318848017-12301-1-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + include/linux/efi.h | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/include/linux/efi.h b/include/linux/efi.h +index e35005f..378f2cd 100644 +--- a/include/linux/efi.h ++++ b/include/linux/efi.h +@@ -109,6 +109,14 @@ typedef struct { + u32 imagesize; + } efi_capsule_header_t; + ++/* ++ * Allocation types for calls to boottime->allocate_pages. ++ */ ++#define EFI_ALLOCATE_ANY_PAGES 0 ++#define EFI_ALLOCATE_MAX_ADDRESS 1 ++#define EFI_ALLOCATE_ADDRESS 2 ++#define EFI_MAX_ALLOCATE_TYPE 3 ++ + typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg); + + /* +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0006-efi.h-Add-graphics-protocol-guids.patch b/debian/patches/features/x86/efi-stub/0006-efi.h-Add-graphics-protocol-guids.patch new file mode 100644 index 000000000..ceb9fae62 --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0006-efi.h-Add-graphics-protocol-guids.patch @@ -0,0 +1,41 @@ +From: Matt Fleming +Date: Tue, 15 Nov 2011 12:57:16 +0000 +Subject: [PATCH 06/11] efi.h: Add graphics protocol guids + +commit 0f7c5d477f2ce552997831d80e2c872cca1b9054 upstream. + +The x86 EFI boot stub uses the Graphics Output Protocol and Universal +Graphics Adapter (UGA) protocol guids when initialising graphics +during boot. + +Cc: Matthew Garrett +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1318848017-12301-1-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + include/linux/efi.h | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/include/linux/efi.h b/include/linux/efi.h +index 378f2cd..e46d771 100644 +--- a/include/linux/efi.h ++++ b/include/linux/efi.h +@@ -298,6 +298,15 @@ typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules, + #define LOADED_IMAGE_PROTOCOL_GUID \ + EFI_GUID( 0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b ) + ++#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ ++ EFI_GUID( 0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a ) ++ ++#define EFI_UGA_PROTOCOL_GUID \ ++ EFI_GUID( 0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 ) ++ ++#define EFI_PCI_IO_PROTOCOL_GUID \ ++ EFI_GUID( 0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x2, 0x9a ) ++ + typedef struct { + efi_guid_t guid; + unsigned long table; +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0007-efi.h-Add-boottime-locate_handle-search-types.patch b/debian/patches/features/x86/efi-stub/0007-efi.h-Add-boottime-locate_handle-search-types.patch new file mode 100644 index 000000000..81dfa2a5e --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0007-efi.h-Add-boottime-locate_handle-search-types.patch @@ -0,0 +1,37 @@ +From: Matt Fleming +Date: Tue, 15 Nov 2011 12:57:26 +0000 +Subject: [PATCH 07/11] efi.h: Add boottime->locate_handle search types + +commit e2527a7cbec073b69a251193f200a88efbced7ad upstream. + +The x86 EFI boot stub needs to locate handles for various protocols. + +Cc: Matthew Garrett +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1318848017-12301-1-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + include/linux/efi.h | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/include/linux/efi.h b/include/linux/efi.h +index e46d771..d407c88 100644 +--- a/include/linux/efi.h ++++ b/include/linux/efi.h +@@ -472,6 +472,13 @@ extern int __init efi_setup_pcdp_console(char *); + #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004 + + /* ++ * The type of search to perform when calling boottime->locate_handle ++ */ ++#define EFI_LOCATE_ALL_HANDLES 0 ++#define EFI_LOCATE_BY_REGISTER_NOTIFY 1 ++#define EFI_LOCATE_BY_PROTOCOL 2 ++ ++/* + * EFI Device Path information + */ + #define EFI_DEV_HW 0x01 +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0008-efi-Add-EFI-file-I-O-data-types.patch b/debian/patches/features/x86/efi-stub/0008-efi-Add-EFI-file-I-O-data-types.patch new file mode 100644 index 000000000..9f1a5bc45 --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0008-efi-Add-EFI-file-I-O-data-types.patch @@ -0,0 +1,78 @@ +From: Matt Fleming +Date: Thu, 11 Aug 2011 10:28:06 +0100 +Subject: [PATCH 08/11] efi: Add EFI file I/O data types + +commit 55839d515495e766605d7aaabd9c2758370a8d27 upstream. + +The x86 EFI stub needs to access files, for example when loading +initrd's. Add the required data types. + +Cc: Matthew Garrett +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1318848017-12301-1-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + include/linux/efi.h | 40 ++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 40 insertions(+) + +diff --git a/include/linux/efi.h b/include/linux/efi.h +index d407c88..37c3007 100644 +--- a/include/linux/efi.h ++++ b/include/linux/efi.h +@@ -307,6 +307,12 @@ typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules, + #define EFI_PCI_IO_PROTOCOL_GUID \ + EFI_GUID( 0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x2, 0x9a ) + ++#define EFI_FILE_INFO_ID \ ++ EFI_GUID( 0x9576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b ) ++ ++#define EFI_FILE_SYSTEM_GUID \ ++ EFI_GUID( 0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b ) ++ + typedef struct { + efi_guid_t guid; + unsigned long table; +@@ -362,6 +368,40 @@ typedef struct { + unsigned long unload; + } efi_loaded_image_t; + ++typedef struct { ++ u64 revision; ++ void *open_volume; ++} efi_file_io_interface_t; ++ ++typedef struct { ++ u64 size; ++ u64 file_size; ++ u64 phys_size; ++ efi_time_t create_time; ++ efi_time_t last_access_time; ++ efi_time_t modification_time; ++ __aligned_u64 attribute; ++ efi_char16_t filename[1]; ++} efi_file_info_t; ++ ++typedef struct { ++ u64 revision; ++ void *open; ++ void *close; ++ void *delete; ++ void *read; ++ void *write; ++ void *get_position; ++ void *set_position; ++ void *get_info; ++ void *set_info; ++ void *flush; ++} efi_file_handle_t; ++ ++#define EFI_FILE_MODE_READ 0x0000000000000001 ++#define EFI_FILE_MODE_WRITE 0x0000000000000002 ++#define EFI_FILE_MODE_CREATE 0x8000000000000000 ++ + #define EFI_INVALID_TABLE_ADDR (~0UL) + + /* +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0009-x86-efi-EFI-boot-stub-support.patch b/debian/patches/features/x86/efi-stub/0009-x86-efi-EFI-boot-stub-support.patch new file mode 100644 index 000000000..dd1663bac --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0009-x86-efi-EFI-boot-stub-support.patch @@ -0,0 +1,1720 @@ +From: Matt Fleming +Date: Mon, 12 Dec 2011 21:27:52 +0000 +Subject: [PATCH 09/11] x86, efi: EFI boot stub support +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +commit 291f36325f9f252bd76ef5f603995f37e453fc60 upstream. + +There is currently a large divide between kernel development and the +development of EFI boot loaders. The idea behind this patch is to give +the kernel developers full control over the EFI boot process. As +H. Peter Anvin put it, + +"The 'kernel carries its own stub' approach been very successful in +dealing with BIOS, and would make a lot of sense to me for EFI as +well." + +This patch introduces an EFI boot stub that allows an x86 bzImage to +be loaded and executed by EFI firmware. The bzImage appears to the +firmware as an EFI application. Luckily there are enough free bits +within the bzImage header so that it can masquerade as an EFI +application, thereby coercing the EFI firmware into loading it and +jumping to its entry point. The beauty of this masquerading approach +is that both BIOS and EFI boot loaders can still load and run the same +bzImage, thereby allowing a single kernel image to work in any boot +environment. + +The EFI boot stub supports multiple initrds, but they must exist on +the same partition as the bzImage. Command-line arguments for the +kernel can be appended after the bzImage name when run from the EFI +shell, e.g. + +Shell> bzImage console=ttyS0 root=/dev/sdb initrd=initrd.img + +v7: + - Fix checkpatch warnings. + +v6: + + - Try to allocate initrd memory just below hdr->inird_addr_max. + +v5: + + - load_options_size is UTF-16, which needs dividing by 2 to convert + to the corresponding ASCII size. + +v4: + + - Don't read more than image->load_options_size + +v3: + + - Fix following warnings when compiling CONFIG_EFI_STUB=n + + arch/x86/boot/tools/build.c: In function ‘main’: + arch/x86/boot/tools/build.c:138:24: warning: unused variable ‘pe_header’ + arch/x86/boot/tools/build.c:138:15: warning: unused variable ‘file_sz’ + + - As reported by Matthew Garrett, some Apple machines have GOPs that + don't have hardware attached. We need to weed these out by + searching for ones that handle the PCIIO protocol. + + - Don't allocate memory if no initrds are on cmdline + - Don't trust image->load_options_size + +Maarten Lankhorst noted: + - Don't strip first argument when booted from efibootmgr + - Don't allocate too much memory for cmdline + - Don't update cmdline_size, the kernel considers it read-only + - Don't accept '\n' for initrd names + +v2: + + - File alignment was too large, was 8192 should be 512. Reported by + Maarten Lankhorst on LKML. + - Added UGA support for graphics + - Use VIDEO_TYPE_EFI instead of hard-coded number. + - Move linelength assignment until after we've assigned depth + - Dynamically fill out AddressOfEntryPoint in tools/build.c + - Don't use magic number for GDT/TSS stuff. Requested by Andi Kleen + - The bzImage may need to be relocated as it may have been loaded at + a high address address by the firmware. This was required to get my + macbook booting because the firmware loaded it at 0x7cxxxxxx, which + triggers this error in decompress_kernel(), + + if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff)) + error("Destination address too large"); + +Cc: Mike Waychison +Cc: Matthew Garrett +Tested-by: Henrik Rydberg +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1321383097.2657.9.camel@mfleming-mobl1.ger.corp.intel.com +Signed-off-by: H. Peter Anvin +--- + arch/x86/Kconfig | 7 + + arch/x86/boot/compressed/Makefile | 10 +- + arch/x86/boot/compressed/eboot.c | 1014 ++++++++++++++++++++++++++++++++ + arch/x86/boot/compressed/eboot.h | 60 ++ + arch/x86/boot/compressed/efi_stub_32.S | 86 +++ + arch/x86/boot/compressed/efi_stub_64.S | 1 + + arch/x86/boot/compressed/head_32.S | 22 + + arch/x86/boot/compressed/head_64.S | 20 + + arch/x86/boot/compressed/string.c | 9 + + arch/x86/boot/header.S | 158 +++++ + arch/x86/boot/string.c | 35 ++ + arch/x86/boot/tools/build.c | 39 ++ + arch/x86/kernel/asm-offsets.c | 2 + + 13 files changed, 1462 insertions(+), 1 deletion(-) + create mode 100644 arch/x86/boot/compressed/eboot.c + create mode 100644 arch/x86/boot/compressed/eboot.h + create mode 100644 arch/x86/boot/compressed/efi_stub_32.S + create mode 100644 arch/x86/boot/compressed/efi_stub_64.S + +diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig +index efb4294..d71b656 100644 +--- a/arch/x86/Kconfig ++++ b/arch/x86/Kconfig +@@ -1478,6 +1478,13 @@ config EFI + resultant kernel should continue to boot on existing non-EFI + platforms. + ++config EFI_STUB ++ bool "EFI stub support" ++ depends on EFI ++ ---help--- ++ This kernel feature allows a bzImage to be loaded directly ++ by EFI firmware without the use of a bootloader. ++ + config SECCOMP + def_bool y + prompt "Enable seccomp to safely compute untrusted bytecode" +diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile +index 09664ef..b123b9a 100644 +--- a/arch/x86/boot/compressed/Makefile ++++ b/arch/x86/boot/compressed/Makefile +@@ -23,7 +23,15 @@ LDFLAGS_vmlinux := -T + + hostprogs-y := mkpiggy + +-$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o $(obj)/piggy.o FORCE ++VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ ++ $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \ ++ $(obj)/piggy.o ++ ++ifeq ($(CONFIG_EFI_STUB), y) ++ VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o ++endif ++ ++$(obj)/vmlinux: $(VMLINUX_OBJS) FORCE + $(call if_changed,ld) + @: + +diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c +new file mode 100644 +index 0000000..4055e63 +--- /dev/null ++++ b/arch/x86/boot/compressed/eboot.c +@@ -0,0 +1,1014 @@ ++/* ----------------------------------------------------------------------- ++ * ++ * Copyright 2011 Intel Corporation; author Matt Fleming ++ * ++ * This file is part of the Linux kernel, and is made available under ++ * the terms of the GNU General Public License version 2. ++ * ++ * ----------------------------------------------------------------------- */ ++ ++#include ++#include ++#include ++#include ++ ++#include "eboot.h" ++ ++static efi_system_table_t *sys_table; ++ ++static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size, ++ unsigned long *desc_size) ++{ ++ efi_memory_desc_t *m = NULL; ++ efi_status_t status; ++ unsigned long key; ++ u32 desc_version; ++ ++ *map_size = sizeof(*m) * 32; ++again: ++ /* ++ * Add an additional efi_memory_desc_t because we're doing an ++ * allocation which may be in a new descriptor region. ++ */ ++ *map_size += sizeof(*m); ++ status = efi_call_phys3(sys_table->boottime->allocate_pool, ++ EFI_LOADER_DATA, *map_size, (void **)&m); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ status = efi_call_phys5(sys_table->boottime->get_memory_map, map_size, ++ m, &key, desc_size, &desc_version); ++ if (status == EFI_BUFFER_TOO_SMALL) { ++ efi_call_phys1(sys_table->boottime->free_pool, m); ++ goto again; ++ } ++ ++ if (status != EFI_SUCCESS) ++ efi_call_phys1(sys_table->boottime->free_pool, m); ++ ++fail: ++ *map = m; ++ return status; ++} ++ ++/* ++ * Allocate at the highest possible address that is not above 'max'. ++ */ ++static efi_status_t high_alloc(unsigned long size, unsigned long align, ++ unsigned long *addr, unsigned long max) ++{ ++ unsigned long map_size, desc_size; ++ efi_memory_desc_t *map; ++ efi_status_t status; ++ unsigned long nr_pages; ++ u64 max_addr = 0; ++ int i; ++ ++ status = __get_map(&map, &map_size, &desc_size); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; ++again: ++ for (i = 0; i < map_size / desc_size; i++) { ++ efi_memory_desc_t *desc; ++ unsigned long m = (unsigned long)map; ++ u64 start, end; ++ ++ desc = (efi_memory_desc_t *)(m + (i * desc_size)); ++ if (desc->type != EFI_CONVENTIONAL_MEMORY) ++ continue; ++ ++ if (desc->num_pages < nr_pages) ++ continue; ++ ++ start = desc->phys_addr; ++ end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT); ++ ++ if ((start + size) > end || (start + size) > max) ++ continue; ++ ++ if (end - size > max) ++ end = max; ++ ++ if (round_down(end - size, align) < start) ++ continue; ++ ++ start = round_down(end - size, align); ++ ++ /* ++ * Don't allocate at 0x0. It will confuse code that ++ * checks pointers against NULL. ++ */ ++ if (start == 0x0) ++ continue; ++ ++ if (start > max_addr) ++ max_addr = start; ++ } ++ ++ if (!max_addr) ++ status = EFI_NOT_FOUND; ++ else { ++ status = efi_call_phys4(sys_table->boottime->allocate_pages, ++ EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, ++ nr_pages, &max_addr); ++ if (status != EFI_SUCCESS) { ++ max = max_addr; ++ max_addr = 0; ++ goto again; ++ } ++ ++ *addr = max_addr; ++ } ++ ++free_pool: ++ efi_call_phys1(sys_table->boottime->free_pool, map); ++ ++fail: ++ return status; ++} ++ ++/* ++ * Allocate at the lowest possible address. ++ */ ++static efi_status_t low_alloc(unsigned long size, unsigned long align, ++ unsigned long *addr) ++{ ++ unsigned long map_size, desc_size; ++ efi_memory_desc_t *map; ++ efi_status_t status; ++ unsigned long nr_pages; ++ int i; ++ ++ status = __get_map(&map, &map_size, &desc_size); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; ++ for (i = 0; i < map_size / desc_size; i++) { ++ efi_memory_desc_t *desc; ++ unsigned long m = (unsigned long)map; ++ u64 start, end; ++ ++ desc = (efi_memory_desc_t *)(m + (i * desc_size)); ++ ++ if (desc->type != EFI_CONVENTIONAL_MEMORY) ++ continue; ++ ++ if (desc->num_pages < nr_pages) ++ continue; ++ ++ start = desc->phys_addr; ++ end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT); ++ ++ /* ++ * Don't allocate at 0x0. It will confuse code that ++ * checks pointers against NULL. Skip the first 8 ++ * bytes so we start at a nice even number. ++ */ ++ if (start == 0x0) ++ start += 8; ++ ++ start = round_up(start, align); ++ if ((start + size) > end) ++ continue; ++ ++ status = efi_call_phys4(sys_table->boottime->allocate_pages, ++ EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, ++ nr_pages, &start); ++ if (status == EFI_SUCCESS) { ++ *addr = start; ++ break; ++ } ++ } ++ ++ if (i == map_size / desc_size) ++ status = EFI_NOT_FOUND; ++ ++free_pool: ++ efi_call_phys1(sys_table->boottime->free_pool, map); ++fail: ++ return status; ++} ++ ++static void low_free(unsigned long size, unsigned long addr) ++{ ++ unsigned long nr_pages; ++ ++ nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; ++ efi_call_phys2(sys_table->boottime->free_pages, addr, size); ++} ++ ++static void find_bits(unsigned long mask, u8 *pos, u8 *size) ++{ ++ u8 first, len; ++ ++ first = 0; ++ len = 0; ++ ++ if (mask) { ++ while (!(mask & 0x1)) { ++ mask = mask >> 1; ++ first++; ++ } ++ ++ while (mask & 0x1) { ++ mask = mask >> 1; ++ len++; ++ } ++ } ++ ++ *pos = first; ++ *size = len; ++} ++ ++/* ++ * See if we have Graphics Output Protocol ++ */ ++static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, ++ unsigned long size) ++{ ++ struct efi_graphics_output_protocol *gop, *first_gop; ++ struct efi_pixel_bitmask pixel_info; ++ unsigned long nr_gops; ++ efi_status_t status; ++ void **gop_handle; ++ u16 width, height; ++ u32 fb_base, fb_size; ++ u32 pixels_per_scan_line; ++ int pixel_format; ++ int i; ++ ++ status = efi_call_phys3(sys_table->boottime->allocate_pool, ++ EFI_LOADER_DATA, size, &gop_handle); ++ if (status != EFI_SUCCESS) ++ return status; ++ ++ status = efi_call_phys5(sys_table->boottime->locate_handle, ++ EFI_LOCATE_BY_PROTOCOL, proto, ++ NULL, &size, gop_handle); ++ if (status != EFI_SUCCESS) ++ goto free_handle; ++ ++ first_gop = NULL; ++ ++ nr_gops = size / sizeof(void *); ++ for (i = 0; i < nr_gops; i++) { ++ struct efi_graphics_output_mode_info *info; ++ efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; ++ void *pciio; ++ void *h = gop_handle[i]; ++ ++ status = efi_call_phys3(sys_table->boottime->handle_protocol, ++ h, proto, &gop); ++ if (status != EFI_SUCCESS) ++ continue; ++ ++ efi_call_phys3(sys_table->boottime->handle_protocol, ++ h, &pciio_proto, &pciio); ++ ++ status = efi_call_phys4(gop->query_mode, gop, ++ gop->mode->mode, &size, &info); ++ if (status == EFI_SUCCESS && (!first_gop || pciio)) { ++ /* ++ * Apple provide GOPs that are not backed by ++ * real hardware (they're used to handle ++ * multiple displays). The workaround is to ++ * search for a GOP implementing the PCIIO ++ * protocol, and if one isn't found, to just ++ * fallback to the first GOP. ++ */ ++ width = info->horizontal_resolution; ++ height = info->vertical_resolution; ++ fb_base = gop->mode->frame_buffer_base; ++ fb_size = gop->mode->frame_buffer_size; ++ pixel_format = info->pixel_format; ++ pixel_info = info->pixel_information; ++ pixels_per_scan_line = info->pixels_per_scan_line; ++ ++ /* ++ * Once we've found a GOP supporting PCIIO, ++ * don't bother looking any further. ++ */ ++ if (pciio) ++ break; ++ ++ first_gop = gop; ++ } ++ } ++ ++ /* Did we find any GOPs? */ ++ if (!first_gop) ++ goto free_handle; ++ ++ /* EFI framebuffer */ ++ si->orig_video_isVGA = VIDEO_TYPE_EFI; ++ ++ si->lfb_width = width; ++ si->lfb_height = height; ++ si->lfb_base = fb_base; ++ si->lfb_size = fb_size; ++ si->pages = 1; ++ ++ if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) { ++ si->lfb_depth = 32; ++ si->lfb_linelength = pixels_per_scan_line * 4; ++ si->red_size = 8; ++ si->red_pos = 0; ++ si->green_size = 8; ++ si->green_pos = 8; ++ si->blue_size = 8; ++ si->blue_pos = 16; ++ si->rsvd_size = 8; ++ si->rsvd_pos = 24; ++ } else if (pixel_format == PIXEL_BGR_RESERVED_8BIT_PER_COLOR) { ++ si->lfb_depth = 32; ++ si->lfb_linelength = pixels_per_scan_line * 4; ++ si->red_size = 8; ++ si->red_pos = 16; ++ si->green_size = 8; ++ si->green_pos = 8; ++ si->blue_size = 8; ++ si->blue_pos = 0; ++ si->rsvd_size = 8; ++ si->rsvd_pos = 24; ++ } else if (pixel_format == PIXEL_BIT_MASK) { ++ find_bits(pixel_info.red_mask, &si->red_pos, &si->red_size); ++ find_bits(pixel_info.green_mask, &si->green_pos, ++ &si->green_size); ++ find_bits(pixel_info.blue_mask, &si->blue_pos, &si->blue_size); ++ find_bits(pixel_info.reserved_mask, &si->rsvd_pos, ++ &si->rsvd_size); ++ si->lfb_depth = si->red_size + si->green_size + ++ si->blue_size + si->rsvd_size; ++ si->lfb_linelength = (pixels_per_scan_line * si->lfb_depth) / 8; ++ } else { ++ si->lfb_depth = 4; ++ si->lfb_linelength = si->lfb_width / 2; ++ si->red_size = 0; ++ si->red_pos = 0; ++ si->green_size = 0; ++ si->green_pos = 0; ++ si->blue_size = 0; ++ si->blue_pos = 0; ++ si->rsvd_size = 0; ++ si->rsvd_pos = 0; ++ } ++ ++free_handle: ++ efi_call_phys1(sys_table->boottime->free_pool, gop_handle); ++ return status; ++} ++ ++/* ++ * See if we have Universal Graphics Adapter (UGA) protocol ++ */ ++static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, ++ unsigned long size) ++{ ++ struct efi_uga_draw_protocol *uga, *first_uga; ++ unsigned long nr_ugas; ++ efi_status_t status; ++ u32 width, height; ++ void **uga_handle = NULL; ++ int i; ++ ++ status = efi_call_phys3(sys_table->boottime->allocate_pool, ++ EFI_LOADER_DATA, size, &uga_handle); ++ if (status != EFI_SUCCESS) ++ return status; ++ ++ status = efi_call_phys5(sys_table->boottime->locate_handle, ++ EFI_LOCATE_BY_PROTOCOL, uga_proto, ++ NULL, &size, uga_handle); ++ if (status != EFI_SUCCESS) ++ goto free_handle; ++ ++ first_uga = NULL; ++ ++ nr_ugas = size / sizeof(void *); ++ for (i = 0; i < nr_ugas; i++) { ++ efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; ++ void *handle = uga_handle[i]; ++ u32 w, h, depth, refresh; ++ void *pciio; ++ ++ status = efi_call_phys3(sys_table->boottime->handle_protocol, ++ handle, uga_proto, &uga); ++ if (status != EFI_SUCCESS) ++ continue; ++ ++ efi_call_phys3(sys_table->boottime->handle_protocol, ++ handle, &pciio_proto, &pciio); ++ ++ status = efi_call_phys5(uga->get_mode, uga, &w, &h, ++ &depth, &refresh); ++ if (status == EFI_SUCCESS && (!first_uga || pciio)) { ++ width = w; ++ height = h; ++ ++ /* ++ * Once we've found a UGA supporting PCIIO, ++ * don't bother looking any further. ++ */ ++ if (pciio) ++ break; ++ ++ first_uga = uga; ++ } ++ } ++ ++ if (!first_uga) ++ goto free_handle; ++ ++ /* EFI framebuffer */ ++ si->orig_video_isVGA = VIDEO_TYPE_EFI; ++ ++ si->lfb_depth = 32; ++ si->lfb_width = width; ++ si->lfb_height = height; ++ ++ si->red_size = 8; ++ si->red_pos = 16; ++ si->green_size = 8; ++ si->green_pos = 8; ++ si->blue_size = 8; ++ si->blue_pos = 0; ++ si->rsvd_size = 8; ++ si->rsvd_pos = 24; ++ ++ ++free_handle: ++ efi_call_phys1(sys_table->boottime->free_pool, uga_handle); ++ return status; ++} ++ ++void setup_graphics(struct boot_params *boot_params) ++{ ++ efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; ++ struct screen_info *si; ++ efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; ++ efi_status_t status; ++ unsigned long size; ++ void **gop_handle = NULL; ++ void **uga_handle = NULL; ++ ++ si = &boot_params->screen_info; ++ memset(si, 0, sizeof(*si)); ++ ++ size = 0; ++ status = efi_call_phys5(sys_table->boottime->locate_handle, ++ EFI_LOCATE_BY_PROTOCOL, &graphics_proto, ++ NULL, &size, gop_handle); ++ if (status == EFI_BUFFER_TOO_SMALL) ++ status = setup_gop(si, &graphics_proto, size); ++ ++ if (status != EFI_SUCCESS) { ++ size = 0; ++ status = efi_call_phys5(sys_table->boottime->locate_handle, ++ EFI_LOCATE_BY_PROTOCOL, &uga_proto, ++ NULL, &size, uga_handle); ++ if (status == EFI_BUFFER_TOO_SMALL) ++ setup_uga(si, &uga_proto, size); ++ } ++} ++ ++struct initrd { ++ efi_file_handle_t *handle; ++ u64 size; ++}; ++ ++/* ++ * Check the cmdline for a LILO-style initrd= arguments. ++ * ++ * We only support loading an initrd from the same filesystem as the ++ * kernel image. ++ */ ++static efi_status_t handle_ramdisks(efi_loaded_image_t *image, ++ struct setup_header *hdr) ++{ ++ struct initrd *initrds; ++ unsigned long initrd_addr; ++ efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; ++ u64 initrd_total; ++ efi_file_io_interface_t *io; ++ efi_file_handle_t *fh; ++ efi_status_t status; ++ int nr_initrds; ++ char *str; ++ int i, j, k; ++ ++ initrd_addr = 0; ++ initrd_total = 0; ++ ++ str = (char *)(unsigned long)hdr->cmd_line_ptr; ++ ++ j = 0; /* See close_handles */ ++ ++ if (!str || !*str) ++ return EFI_SUCCESS; ++ ++ for (nr_initrds = 0; *str; nr_initrds++) { ++ str = strstr(str, "initrd="); ++ if (!str) ++ break; ++ ++ str += 7; ++ ++ /* Skip any leading slashes */ ++ while (*str == '/' || *str == '\\') ++ str++; ++ ++ while (*str && *str != ' ' && *str != '\n') ++ str++; ++ } ++ ++ if (!nr_initrds) ++ return EFI_SUCCESS; ++ ++ status = efi_call_phys3(sys_table->boottime->allocate_pool, ++ EFI_LOADER_DATA, ++ nr_initrds * sizeof(*initrds), ++ &initrds); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ str = (char *)(unsigned long)hdr->cmd_line_ptr; ++ for (i = 0; i < nr_initrds; i++) { ++ struct initrd *initrd; ++ efi_file_handle_t *h; ++ efi_file_info_t *info; ++ efi_char16_t filename[256]; ++ unsigned long info_sz; ++ efi_guid_t info_guid = EFI_FILE_INFO_ID; ++ efi_char16_t *p; ++ u64 file_sz; ++ ++ str = strstr(str, "initrd="); ++ if (!str) ++ break; ++ ++ str += 7; ++ ++ initrd = &initrds[i]; ++ p = filename; ++ ++ /* Skip any leading slashes */ ++ while (*str == '/' || *str == '\\') ++ str++; ++ ++ while (*str && *str != ' ' && *str != '\n') { ++ if (p >= filename + sizeof(filename)) ++ break; ++ ++ *p++ = *str++; ++ } ++ ++ *p = '\0'; ++ ++ /* Only open the volume once. */ ++ if (!i) { ++ efi_boot_services_t *boottime; ++ ++ boottime = sys_table->boottime; ++ ++ status = efi_call_phys3(boottime->handle_protocol, ++ image->device_handle, &fs_proto, &io); ++ if (status != EFI_SUCCESS) ++ goto free_initrds; ++ ++ status = efi_call_phys2(io->open_volume, io, &fh); ++ if (status != EFI_SUCCESS) ++ goto free_initrds; ++ } ++ ++ status = efi_call_phys5(fh->open, fh, &h, filename, ++ EFI_FILE_MODE_READ, (u64)0); ++ if (status != EFI_SUCCESS) ++ goto close_handles; ++ ++ initrd->handle = h; ++ ++ info_sz = 0; ++ status = efi_call_phys4(h->get_info, h, &info_guid, ++ &info_sz, NULL); ++ if (status != EFI_BUFFER_TOO_SMALL) ++ goto close_handles; ++ ++grow: ++ status = efi_call_phys3(sys_table->boottime->allocate_pool, ++ EFI_LOADER_DATA, info_sz, &info); ++ if (status != EFI_SUCCESS) ++ goto close_handles; ++ ++ status = efi_call_phys4(h->get_info, h, &info_guid, ++ &info_sz, info); ++ if (status == EFI_BUFFER_TOO_SMALL) { ++ efi_call_phys1(sys_table->boottime->free_pool, info); ++ goto grow; ++ } ++ ++ file_sz = info->file_size; ++ efi_call_phys1(sys_table->boottime->free_pool, info); ++ ++ if (status != EFI_SUCCESS) ++ goto close_handles; ++ ++ initrd->size = file_sz; ++ initrd_total += file_sz; ++ } ++ ++ if (initrd_total) { ++ unsigned long addr; ++ ++ /* ++ * Multiple initrd's need to be at consecutive ++ * addresses in memory, so allocate enough memory for ++ * all the initrd's. ++ */ ++ status = high_alloc(initrd_total, 0x1000, ++ &initrd_addr, hdr->initrd_addr_max); ++ if (status != EFI_SUCCESS) ++ goto close_handles; ++ ++ /* We've run out of free low memory. */ ++ if (initrd_addr > hdr->initrd_addr_max) { ++ status = EFI_INVALID_PARAMETER; ++ goto free_initrd_total; ++ } ++ ++ addr = initrd_addr; ++ for (j = 0; j < nr_initrds; j++) { ++ u64 size; ++ ++ size = initrds[j].size; ++ status = efi_call_phys3(fh->read, initrds[j].handle, ++ &size, addr); ++ if (status != EFI_SUCCESS) ++ goto free_initrd_total; ++ ++ efi_call_phys1(fh->close, initrds[j].handle); ++ ++ addr += size; ++ } ++ ++ } ++ ++ efi_call_phys1(sys_table->boottime->free_pool, initrds); ++ ++ hdr->ramdisk_image = initrd_addr; ++ hdr->ramdisk_size = initrd_total; ++ ++ return status; ++ ++free_initrd_total: ++ low_free(initrd_total, initrd_addr); ++ ++close_handles: ++ for (k = j; k < nr_initrds; k++) ++ efi_call_phys1(fh->close, initrds[k].handle); ++free_initrds: ++ efi_call_phys1(sys_table->boottime->free_pool, initrds); ++fail: ++ hdr->ramdisk_image = 0; ++ hdr->ramdisk_size = 0; ++ ++ return status; ++} ++ ++/* ++ * Because the x86 boot code expects to be passed a boot_params we ++ * need to create one ourselves (usually the bootloader would create ++ * one for us). ++ */ ++static efi_status_t make_boot_params(struct boot_params *boot_params, ++ efi_loaded_image_t *image, ++ void *handle) ++{ ++ struct efi_info *efi = &boot_params->efi_info; ++ struct apm_bios_info *bi = &boot_params->apm_bios_info; ++ struct sys_desc_table *sdt = &boot_params->sys_desc_table; ++ struct e820entry *e820_map = &boot_params->e820_map[0]; ++ struct e820entry *prev = NULL; ++ struct setup_header *hdr = &boot_params->hdr; ++ unsigned long size, key, desc_size, _size; ++ efi_memory_desc_t *mem_map; ++ void *options = image->load_options; ++ u32 load_options_size = image->load_options_size / 2; /* ASCII */ ++ int options_size = 0; ++ efi_status_t status; ++ __u32 desc_version; ++ unsigned long cmdline; ++ u8 nr_entries; ++ u16 *s2; ++ u8 *s1; ++ int i; ++ ++ hdr->type_of_loader = 0x21; ++ ++ /* Convert unicode cmdline to ascii */ ++ cmdline = 0; ++ s2 = (u16 *)options; ++ ++ if (s2) { ++ while (*s2 && *s2 != '\n' && options_size < load_options_size) { ++ s2++; ++ options_size++; ++ } ++ ++ if (options_size) { ++ if (options_size > hdr->cmdline_size) ++ options_size = hdr->cmdline_size; ++ ++ options_size++; /* NUL termination */ ++ ++ status = low_alloc(options_size, 1, &cmdline); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ s1 = (u8 *)(unsigned long)cmdline; ++ s2 = (u16 *)options; ++ ++ for (i = 0; i < options_size - 1; i++) ++ *s1++ = *s2++; ++ ++ *s1 = '\0'; ++ } ++ } ++ ++ hdr->cmd_line_ptr = cmdline; ++ ++ hdr->ramdisk_image = 0; ++ hdr->ramdisk_size = 0; ++ ++ status = handle_ramdisks(image, hdr); ++ if (status != EFI_SUCCESS) ++ goto free_cmdline; ++ ++ setup_graphics(boot_params); ++ ++ /* Clear APM BIOS info */ ++ memset(bi, 0, sizeof(*bi)); ++ ++ memset(sdt, 0, sizeof(*sdt)); ++ ++ memcpy(&efi->efi_loader_signature, EFI_LOADER_SIGNATURE, sizeof(__u32)); ++ ++ size = sizeof(*mem_map) * 32; ++ ++again: ++ size += sizeof(*mem_map); ++ _size = size; ++ status = low_alloc(size, 1, (unsigned long *)&mem_map); ++ if (status != EFI_SUCCESS) ++ goto free_cmdline; ++ ++ status = efi_call_phys5(sys_table->boottime->get_memory_map, &size, ++ mem_map, &key, &desc_size, &desc_version); ++ if (status == EFI_BUFFER_TOO_SMALL) { ++ low_free(_size, (unsigned long)mem_map); ++ goto again; ++ } ++ ++ if (status != EFI_SUCCESS) ++ goto free_mem_map; ++ ++ efi->efi_systab = (unsigned long)sys_table; ++ efi->efi_memdesc_size = desc_size; ++ efi->efi_memdesc_version = desc_version; ++ efi->efi_memmap = (unsigned long)mem_map; ++ efi->efi_memmap_size = size; ++ ++#ifdef CONFIG_X86_64 ++ efi->efi_systab_hi = (unsigned long)sys_table >> 32; ++ efi->efi_memmap_hi = (unsigned long)mem_map >> 32; ++#endif ++ ++ /* Might as well exit boot services now */ ++ status = efi_call_phys2(sys_table->boottime->exit_boot_services, ++ handle, key); ++ if (status != EFI_SUCCESS) ++ goto free_mem_map; ++ ++ /* Historic? */ ++ boot_params->alt_mem_k = 32 * 1024; ++ ++ /* ++ * Convert the EFI memory map to E820. ++ */ ++ nr_entries = 0; ++ for (i = 0; i < size / desc_size; i++) { ++ efi_memory_desc_t *d; ++ unsigned int e820_type = 0; ++ unsigned long m = (unsigned long)mem_map; ++ ++ d = (efi_memory_desc_t *)(m + (i * desc_size)); ++ switch (d->type) { ++ case EFI_RESERVED_TYPE: ++ case EFI_RUNTIME_SERVICES_CODE: ++ case EFI_RUNTIME_SERVICES_DATA: ++ case EFI_MEMORY_MAPPED_IO: ++ case EFI_MEMORY_MAPPED_IO_PORT_SPACE: ++ case EFI_PAL_CODE: ++ e820_type = E820_RESERVED; ++ break; ++ ++ case EFI_UNUSABLE_MEMORY: ++ e820_type = E820_UNUSABLE; ++ break; ++ ++ case EFI_ACPI_RECLAIM_MEMORY: ++ e820_type = E820_ACPI; ++ break; ++ ++ case EFI_LOADER_CODE: ++ case EFI_LOADER_DATA: ++ case EFI_BOOT_SERVICES_CODE: ++ case EFI_BOOT_SERVICES_DATA: ++ case EFI_CONVENTIONAL_MEMORY: ++ e820_type = E820_RAM; ++ break; ++ ++ case EFI_ACPI_MEMORY_NVS: ++ e820_type = E820_NVS; ++ break; ++ ++ default: ++ continue; ++ } ++ ++ /* Merge adjacent mappings */ ++ if (prev && prev->type == e820_type && ++ (prev->addr + prev->size) == d->phys_addr) ++ prev->size += d->num_pages << 12; ++ else { ++ e820_map->addr = d->phys_addr; ++ e820_map->size = d->num_pages << 12; ++ e820_map->type = e820_type; ++ prev = e820_map++; ++ nr_entries++; ++ } ++ } ++ ++ boot_params->e820_entries = nr_entries; ++ ++ return EFI_SUCCESS; ++ ++free_mem_map: ++ low_free(_size, (unsigned long)mem_map); ++free_cmdline: ++ if (options_size) ++ low_free(options_size, hdr->cmd_line_ptr); ++fail: ++ return status; ++} ++ ++/* ++ * On success we return a pointer to a boot_params structure, and NULL ++ * on failure. ++ */ ++struct boot_params *efi_main(void *handle, efi_system_table_t *_table) ++{ ++ struct boot_params *boot_params; ++ unsigned long start, nr_pages; ++ struct desc_ptr *gdt, *idt; ++ efi_loaded_image_t *image; ++ struct setup_header *hdr; ++ efi_status_t status; ++ efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; ++ struct desc_struct *desc; ++ ++ sys_table = _table; ++ ++ /* Check if we were booted by the EFI firmware */ ++ if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) ++ goto fail; ++ ++ status = efi_call_phys3(sys_table->boottime->handle_protocol, ++ handle, &proto, (void *)&image); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ status = low_alloc(0x4000, 1, (unsigned long *)&boot_params); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ memset(boot_params, 0x0, 0x4000); ++ ++ /* Copy first two sectors to boot_params */ ++ memcpy(boot_params, image->image_base, 1024); ++ ++ hdr = &boot_params->hdr; ++ ++ /* ++ * The EFI firmware loader could have placed the kernel image ++ * anywhere in memory, but the kernel has various restrictions ++ * on the max physical address it can run at. Attempt to move ++ * the kernel to boot_params.pref_address, or as low as ++ * possible. ++ */ ++ start = hdr->pref_address; ++ nr_pages = round_up(hdr->init_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; ++ ++ status = efi_call_phys4(sys_table->boottime->allocate_pages, ++ EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, ++ nr_pages, &start); ++ if (status != EFI_SUCCESS) { ++ status = low_alloc(hdr->init_size, hdr->kernel_alignment, ++ &start); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ } ++ ++ hdr->code32_start = (__u32)start; ++ hdr->pref_address = (__u64)(unsigned long)image->image_base; ++ ++ memcpy((void *)start, image->image_base, image->image_size); ++ ++ status = efi_call_phys3(sys_table->boottime->allocate_pool, ++ EFI_LOADER_DATA, sizeof(*gdt), ++ (void **)&gdt); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ gdt->size = 0x800; ++ status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ status = efi_call_phys3(sys_table->boottime->allocate_pool, ++ EFI_LOADER_DATA, sizeof(*idt), ++ (void **)&idt); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ idt->size = 0; ++ idt->address = 0; ++ ++ status = make_boot_params(boot_params, image, handle); ++ if (status != EFI_SUCCESS) ++ goto fail; ++ ++ memset((char *)gdt->address, 0x0, gdt->size); ++ desc = (struct desc_struct *)gdt->address; ++ ++ /* The first GDT is a dummy and the second is unused. */ ++ desc += 2; ++ ++ desc->limit0 = 0xffff; ++ desc->base0 = 0x0000; ++ desc->base1 = 0x0000; ++ desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; ++ desc->s = DESC_TYPE_CODE_DATA; ++ desc->dpl = 0; ++ desc->p = 1; ++ desc->limit = 0xf; ++ desc->avl = 0; ++ desc->l = 0; ++ desc->d = SEG_OP_SIZE_32BIT; ++ desc->g = SEG_GRANULARITY_4KB; ++ desc->base2 = 0x00; ++ ++ desc++; ++ desc->limit0 = 0xffff; ++ desc->base0 = 0x0000; ++ desc->base1 = 0x0000; ++ desc->type = SEG_TYPE_DATA | SEG_TYPE_READ_WRITE; ++ desc->s = DESC_TYPE_CODE_DATA; ++ desc->dpl = 0; ++ desc->p = 1; ++ desc->limit = 0xf; ++ desc->avl = 0; ++ desc->l = 0; ++ desc->d = SEG_OP_SIZE_32BIT; ++ desc->g = SEG_GRANULARITY_4KB; ++ desc->base2 = 0x00; ++ ++#ifdef CONFIG_X86_64 ++ /* Task segment value */ ++ desc++; ++ desc->limit0 = 0x0000; ++ desc->base0 = 0x0000; ++ desc->base1 = 0x0000; ++ desc->type = SEG_TYPE_TSS; ++ desc->s = 0; ++ desc->dpl = 0; ++ desc->p = 1; ++ desc->limit = 0x0; ++ desc->avl = 0; ++ desc->l = 0; ++ desc->d = 0; ++ desc->g = SEG_GRANULARITY_4KB; ++ desc->base2 = 0x00; ++#endif /* CONFIG_X86_64 */ ++ ++ asm volatile ("lidt %0" : : "m" (*idt)); ++ asm volatile ("lgdt %0" : : "m" (*gdt)); ++ ++ asm volatile("cli"); ++ ++ return boot_params; ++fail: ++ return NULL; ++} +diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h +new file mode 100644 +index 0000000..f66d023 +--- /dev/null ++++ b/arch/x86/boot/compressed/eboot.h +@@ -0,0 +1,60 @@ ++#ifndef BOOT_COMPRESSED_EBOOT_H ++#define BOOT_COMPRESSED_EBOOT_H ++ ++#define SEG_TYPE_DATA (0 << 3) ++#define SEG_TYPE_READ_WRITE (1 << 1) ++#define SEG_TYPE_CODE (1 << 3) ++#define SEG_TYPE_EXEC_READ (1 << 1) ++#define SEG_TYPE_TSS ((1 << 3) | (1 << 0)) ++#define SEG_OP_SIZE_32BIT (1 << 0) ++#define SEG_GRANULARITY_4KB (1 << 0) ++ ++#define DESC_TYPE_CODE_DATA (1 << 0) ++ ++#define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT) ++ ++#define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0 ++#define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1 ++#define PIXEL_BIT_MASK 2 ++#define PIXEL_BLT_ONLY 3 ++#define PIXEL_FORMAT_MAX 4 ++ ++struct efi_pixel_bitmask { ++ u32 red_mask; ++ u32 green_mask; ++ u32 blue_mask; ++ u32 reserved_mask; ++}; ++ ++struct efi_graphics_output_mode_info { ++ u32 version; ++ u32 horizontal_resolution; ++ u32 vertical_resolution; ++ int pixel_format; ++ struct efi_pixel_bitmask pixel_information; ++ u32 pixels_per_scan_line; ++} __packed; ++ ++struct efi_graphics_output_protocol_mode { ++ u32 max_mode; ++ u32 mode; ++ unsigned long info; ++ unsigned long size_of_info; ++ u64 frame_buffer_base; ++ unsigned long frame_buffer_size; ++} __packed; ++ ++struct efi_graphics_output_protocol { ++ void *query_mode; ++ unsigned long set_mode; ++ unsigned long blt; ++ struct efi_graphics_output_protocol_mode *mode; ++}; ++ ++struct efi_uga_draw_protocol { ++ void *get_mode; ++ void *set_mode; ++ void *blt; ++}; ++ ++#endif /* BOOT_COMPRESSED_EBOOT_H */ +diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S +new file mode 100644 +index 0000000..a53440e +--- /dev/null ++++ b/arch/x86/boot/compressed/efi_stub_32.S +@@ -0,0 +1,86 @@ ++/* ++ * EFI call stub for IA32. ++ * ++ * This stub allows us to make EFI calls in physical mode with interrupts ++ * turned off. Note that this implementation is different from the one in ++ * arch/x86/platform/efi/efi_stub_32.S because we're _already_ in physical ++ * mode at this point. ++ */ ++ ++#include ++#include ++ ++/* ++ * efi_call_phys(void *, ...) is a function with variable parameters. ++ * All the callers of this function assure that all the parameters are 4-bytes. ++ */ ++ ++/* ++ * In gcc calling convention, EBX, ESP, EBP, ESI and EDI are all callee save. ++ * So we'd better save all of them at the beginning of this function and restore ++ * at the end no matter how many we use, because we can not assure EFI runtime ++ * service functions will comply with gcc calling convention, too. ++ */ ++ ++.text ++ENTRY(efi_call_phys) ++ /* ++ * 0. The function can only be called in Linux kernel. So CS has been ++ * set to 0x0010, DS and SS have been set to 0x0018. In EFI, I found ++ * the values of these registers are the same. And, the corresponding ++ * GDT entries are identical. So I will do nothing about segment reg ++ * and GDT, but change GDT base register in prelog and epilog. ++ */ ++ ++ /* ++ * 1. Because we haven't been relocated by this point we need to ++ * use relative addressing. ++ */ ++ call 1f ++1: popl %edx ++ subl $1b, %edx ++ ++ /* ++ * 2. Now on the top of stack is the return ++ * address in the caller of efi_call_phys(), then parameter 1, ++ * parameter 2, ..., param n. To make things easy, we save the return ++ * address of efi_call_phys in a global variable. ++ */ ++ popl %ecx ++ movl %ecx, saved_return_addr(%edx) ++ /* get the function pointer into ECX*/ ++ popl %ecx ++ movl %ecx, efi_rt_function_ptr(%edx) ++ ++ /* ++ * 3. Call the physical function. ++ */ ++ call *%ecx ++ ++ /* ++ * 4. Balance the stack. And because EAX contain the return value, ++ * we'd better not clobber it. We need to calculate our address ++ * again because %ecx and %edx are not preserved across EFI function ++ * calls. ++ */ ++ call 1f ++1: popl %edx ++ subl $1b, %edx ++ ++ movl efi_rt_function_ptr(%edx), %ecx ++ pushl %ecx ++ ++ /* ++ * 10. Push the saved return address onto the stack and return. ++ */ ++ movl saved_return_addr(%edx), %ecx ++ pushl %ecx ++ ret ++ENDPROC(efi_call_phys) ++.previous ++ ++.data ++saved_return_addr: ++ .long 0 ++efi_rt_function_ptr: ++ .long 0 +diff --git a/arch/x86/boot/compressed/efi_stub_64.S b/arch/x86/boot/compressed/efi_stub_64.S +new file mode 100644 +index 0000000..cedc60d +--- /dev/null ++++ b/arch/x86/boot/compressed/efi_stub_64.S +@@ -0,0 +1 @@ ++#include "../../platform/efi/efi_stub_64.S" +diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S +index 67a655a..a055993 100644 +--- a/arch/x86/boot/compressed/head_32.S ++++ b/arch/x86/boot/compressed/head_32.S +@@ -32,6 +32,28 @@ + + __HEAD + ENTRY(startup_32) ++#ifdef CONFIG_EFI_STUB ++ /* ++ * We don't need the return address, so set up the stack so ++ * efi_main() can find its arugments. ++ */ ++ add $0x4, %esp ++ ++ call efi_main ++ cmpl $0, %eax ++ je preferred_addr ++ movl %eax, %esi ++ call 1f ++1: ++ popl %eax ++ subl $1b, %eax ++ subl BP_pref_address(%esi), %eax ++ add BP_code32_start(%esi), %eax ++ leal preferred_addr(%eax), %eax ++ jmp *%eax ++ ++preferred_addr: ++#endif + cld + /* + * Test KEEP_SEGMENTS flag to see if the bootloader is asking +diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S +index 35af09d..558d76c 100644 +--- a/arch/x86/boot/compressed/head_64.S ++++ b/arch/x86/boot/compressed/head_64.S +@@ -199,6 +199,26 @@ ENTRY(startup_64) + * an identity mapped page table being provied that maps our + * entire text+data+bss and hopefully all of memory. + */ ++#ifdef CONFIG_EFI_STUB ++ pushq %rsi ++ mov %rcx, %rdi ++ mov %rdx, %rsi ++ call efi_main ++ popq %rsi ++ cmpq $0,%rax ++ je preferred_addr ++ movq %rax,%rsi ++ call 1f ++1: ++ popq %rax ++ subq $1b, %rax ++ subq BP_pref_address(%rsi), %rax ++ add BP_code32_start(%esi), %eax ++ leaq preferred_addr(%rax), %rax ++ jmp *%rax ++ ++preferred_addr: ++#endif + + /* Setup data segments. */ + xorl %eax, %eax +diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/string.c +index 19b3e69..ffb9c5c 100644 +--- a/arch/x86/boot/compressed/string.c ++++ b/arch/x86/boot/compressed/string.c +@@ -1,2 +1,11 @@ + #include "misc.h" ++ ++int memcmp(const void *s1, const void *s2, size_t len) ++{ ++ u8 diff; ++ asm("repe; cmpsb; setnz %0" ++ : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len)); ++ return diff; ++} ++ + #include "../string.c" +diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S +index bdb4d45..f1bbeeb 100644 +--- a/arch/x86/boot/header.S ++++ b/arch/x86/boot/header.S +@@ -45,6 +45,11 @@ SYSSEG = 0x1000 /* historical load address >> 4 */ + + .global bootsect_start + bootsect_start: ++#ifdef CONFIG_EFI_STUB ++ # "MZ", MS-DOS header ++ .byte 0x4d ++ .byte 0x5a ++#endif + + # Normalize the start address + ljmp $BOOTSEG, $start2 +@@ -79,6 +84,14 @@ bs_die: + # invoke the BIOS reset code... + ljmp $0xf000,$0xfff0 + ++#ifdef CONFIG_EFI_STUB ++ .org 0x3c ++ # ++ # Offset to the PE header. ++ # ++ .long pe_header ++#endif /* CONFIG_EFI_STUB */ ++ + .section ".bsdata", "a" + bugger_off_msg: + .ascii "Direct booting from floppy is no longer supported.\r\n" +@@ -87,6 +100,141 @@ bugger_off_msg: + .ascii "Remove disk and press any key to reboot . . .\r\n" + .byte 0 + ++#ifdef CONFIG_EFI_STUB ++pe_header: ++ .ascii "PE" ++ .word 0 ++ ++coff_header: ++#ifdef CONFIG_X86_32 ++ .word 0x14c # i386 ++#else ++ .word 0x8664 # x86-64 ++#endif ++ .word 2 # nr_sections ++ .long 0 # TimeDateStamp ++ .long 0 # PointerToSymbolTable ++ .long 1 # NumberOfSymbols ++ .word section_table - optional_header # SizeOfOptionalHeader ++#ifdef CONFIG_X86_32 ++ .word 0x306 # Characteristics. ++ # IMAGE_FILE_32BIT_MACHINE | ++ # IMAGE_FILE_DEBUG_STRIPPED | ++ # IMAGE_FILE_EXECUTABLE_IMAGE | ++ # IMAGE_FILE_LINE_NUMS_STRIPPED ++#else ++ .word 0x206 # Characteristics ++ # IMAGE_FILE_DEBUG_STRIPPED | ++ # IMAGE_FILE_EXECUTABLE_IMAGE | ++ # IMAGE_FILE_LINE_NUMS_STRIPPED ++#endif ++ ++optional_header: ++#ifdef CONFIG_X86_32 ++ .word 0x10b # PE32 format ++#else ++ .word 0x20b # PE32+ format ++#endif ++ .byte 0x02 # MajorLinkerVersion ++ .byte 0x14 # MinorLinkerVersion ++ ++ # Filled in by build.c ++ .long 0 # SizeOfCode ++ ++ .long 0 # SizeOfInitializedData ++ .long 0 # SizeOfUninitializedData ++ ++ # Filled in by build.c ++ .long 0x0000 # AddressOfEntryPoint ++ ++ .long 0x0000 # BaseOfCode ++#ifdef CONFIG_X86_32 ++ .long 0 # data ++#endif ++ ++extra_header_fields: ++#ifdef CONFIG_X86_32 ++ .long 0 # ImageBase ++#else ++ .quad 0 # ImageBase ++#endif ++ .long 0x1000 # SectionAlignment ++ .long 0x200 # FileAlignment ++ .word 0 # MajorOperatingSystemVersion ++ .word 0 # MinorOperatingSystemVersion ++ .word 0 # MajorImageVersion ++ .word 0 # MinorImageVersion ++ .word 0 # MajorSubsystemVersion ++ .word 0 # MinorSubsystemVersion ++ .long 0 # Win32VersionValue ++ ++ # ++ # The size of the bzImage is written in tools/build.c ++ # ++ .long 0 # SizeOfImage ++ ++ .long 0x200 # SizeOfHeaders ++ .long 0 # CheckSum ++ .word 0xa # Subsystem (EFI application) ++ .word 0 # DllCharacteristics ++#ifdef CONFIG_X86_32 ++ .long 0 # SizeOfStackReserve ++ .long 0 # SizeOfStackCommit ++ .long 0 # SizeOfHeapReserve ++ .long 0 # SizeOfHeapCommit ++#else ++ .quad 0 # SizeOfStackReserve ++ .quad 0 # SizeOfStackCommit ++ .quad 0 # SizeOfHeapReserve ++ .quad 0 # SizeOfHeapCommit ++#endif ++ .long 0 # LoaderFlags ++ .long 0x1 # NumberOfRvaAndSizes ++ ++ .quad 0 # ExportTable ++ .quad 0 # ImportTable ++ .quad 0 # ResourceTable ++ .quad 0 # ExceptionTable ++ .quad 0 # CertificationTable ++ .quad 0 # BaseRelocationTable ++ ++ # Section table ++section_table: ++ .ascii ".text" ++ .byte 0 ++ .byte 0 ++ .byte 0 ++ .long 0 ++ .long 0x0 # startup_{32,64} ++ .long 0 # Size of initialized data ++ # on disk ++ .long 0x0 # startup_{32,64} ++ .long 0 # PointerToRelocations ++ .long 0 # PointerToLineNumbers ++ .word 0 # NumberOfRelocations ++ .word 0 # NumberOfLineNumbers ++ .long 0x60500020 # Characteristics (section flags) ++ ++ # ++ # The EFI application loader requires a relocation section ++ # because EFI applications are relocatable and not having ++ # this section seems to confuse it. But since we don't need ++ # the loader to fixup any relocs for us just fill it with a ++ # single dummy reloc. ++ # ++ .ascii ".reloc" ++ .byte 0 ++ .byte 0 ++ .long reloc_end - reloc_start ++ .long reloc_start ++ .long reloc_end - reloc_start # SizeOfRawData ++ .long reloc_start # PointerToRawData ++ .long 0 # PointerToRelocations ++ .long 0 # PointerToLineNumbers ++ .word 0 # NumberOfRelocations ++ .word 0 # NumberOfLineNumbers ++ .long 0x42100040 # Characteristics (section flags) ++#endif /* CONFIG_EFI_STUB */ + + # Kernel attributes; used by setup. This is part 1 of the + # header, from the old boot sector. +@@ -318,3 +466,13 @@ die: + setup_corrupt: + .byte 7 + .string "No setup signature found...\n" ++ ++ .data ++dummy: .long 0 ++ ++ .section .reloc ++reloc_start: ++ .long dummy - reloc_start ++ .long 10 ++ .word 0 ++reloc_end: +diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c +index 3cbc405..574dedf 100644 +--- a/arch/x86/boot/string.c ++++ b/arch/x86/boot/string.c +@@ -111,3 +111,38 @@ unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int bas + + return result; + } ++ ++/** ++ * strlen - Find the length of a string ++ * @s: The string to be sized ++ */ ++size_t strlen(const char *s) ++{ ++ const char *sc; ++ ++ for (sc = s; *sc != '\0'; ++sc) ++ /* nothing */; ++ return sc - s; ++} ++ ++/** ++ * strstr - Find the first substring in a %NUL terminated string ++ * @s1: The string to be searched ++ * @s2: The string to search for ++ */ ++char *strstr(const char *s1, const char *s2) ++{ ++ size_t l1, l2; ++ ++ l2 = strlen(s2); ++ if (!l2) ++ return (char *)s1; ++ l1 = strlen(s1); ++ while (l1 >= l2) { ++ l1--; ++ if (!memcmp(s1, s2, l2)) ++ return (char *)s1; ++ s1++; ++ } ++ return NULL; ++} +diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c +index fdc60a0..4e9bd6b 100644 +--- a/arch/x86/boot/tools/build.c ++++ b/arch/x86/boot/tools/build.c +@@ -135,6 +135,9 @@ static void usage(void) + + int main(int argc, char ** argv) + { ++#ifdef CONFIG_EFI_STUB ++ unsigned int file_sz, pe_header; ++#endif + unsigned int i, sz, setup_sectors; + int c; + u32 sys_size; +@@ -194,6 +197,42 @@ int main(int argc, char ** argv) + buf[0x1f6] = sys_size >> 16; + buf[0x1f7] = sys_size >> 24; + ++#ifdef CONFIG_EFI_STUB ++ file_sz = sz + i + ((sys_size * 16) - sz); ++ ++ pe_header = *(unsigned int *)&buf[0x3c]; ++ ++ /* Size of code */ ++ *(unsigned int *)&buf[pe_header + 0x1c] = file_sz; ++ ++ /* Size of image */ ++ *(unsigned int *)&buf[pe_header + 0x50] = file_sz; ++ ++#ifdef CONFIG_X86_32 ++ /* Address of entry point */ ++ *(unsigned int *)&buf[pe_header + 0x28] = i; ++ ++ /* .text size */ ++ *(unsigned int *)&buf[pe_header + 0xb0] = file_sz; ++ ++ /* .text size of initialised data */ ++ *(unsigned int *)&buf[pe_header + 0xb8] = file_sz; ++#else ++ /* ++ * Address of entry point. startup_32 is at the beginning and ++ * the 64-bit entry point (startup_64) is always 512 bytes ++ * after. ++ */ ++ *(unsigned int *)&buf[pe_header + 0x28] = i + 512; ++ ++ /* .text size */ ++ *(unsigned int *)&buf[pe_header + 0xc0] = file_sz; ++ ++ /* .text size of initialised data */ ++ *(unsigned int *)&buf[pe_header + 0xc8] = file_sz; ++#endif /* CONFIG_X86_32 */ ++#endif /* CONFIG_EFI_STUB */ ++ + crc = partial_crc32(buf, i, crc); + if (fwrite(buf, 1, i, stdout) != i) + die("Writing setup failed"); +diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c +index 4f13faf..68de2dc 100644 +--- a/arch/x86/kernel/asm-offsets.c ++++ b/arch/x86/kernel/asm-offsets.c +@@ -67,4 +67,6 @@ void common(void) { + OFFSET(BP_hardware_subarch, boot_params, hdr.hardware_subarch); + OFFSET(BP_version, boot_params, hdr.version); + OFFSET(BP_kernel_alignment, boot_params, hdr.kernel_alignment); ++ OFFSET(BP_pref_address, boot_params, hdr.pref_address); ++ OFFSET(BP_code32_start, boot_params, hdr.code32_start); + } +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0010-x86-efi-Break-up-large-initrd-reads.patch b/debian/patches/features/x86/efi-stub/0010-x86-efi-Break-up-large-initrd-reads.patch new file mode 100644 index 000000000..2d7e6cbc6 --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0010-x86-efi-Break-up-large-initrd-reads.patch @@ -0,0 +1,72 @@ +From: Maarten Lankhorst +Date: Fri, 16 Dec 2011 13:30:58 +0100 +Subject: [PATCH 10/11] x86, efi: Break up large initrd reads + +commit 2d2da60fb40a80cc59383121ccf763e0e0e8a42a upstream. + +The efi boot stub tries to read the entire initrd in 1 go, however +some efi implementations hang if too much if asked to read too much +data at the same time. After some experimentation I found out that my +asrock p67 board will hang if asked to read chunks of 4MiB, so use a +safe value. + +elilo reads in chunks of 16KiB, but since that requires many read +calls I use a value of 1 MiB. hpa suggested adding individual +blacklists for when systems are found where this value causes a crash. + +Signed-off-by: Maarten Lankhorst +Link: http://lkml.kernel.org/r/4EEB3A02.3090201@gmail.com +Signed-off-by: H. Peter Anvin +--- + arch/x86/boot/compressed/eboot.c | 20 ++++++++++++++------ + arch/x86/boot/compressed/eboot.h | 1 + + 2 files changed, 15 insertions(+), 6 deletions(-) + +diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c +index 4055e63..fec216f 100644 +--- a/arch/x86/boot/compressed/eboot.c ++++ b/arch/x86/boot/compressed/eboot.c +@@ -643,14 +643,22 @@ grow: + u64 size; + + size = initrds[j].size; +- status = efi_call_phys3(fh->read, initrds[j].handle, +- &size, addr); +- if (status != EFI_SUCCESS) +- goto free_initrd_total; ++ while (size) { ++ u64 chunksize; ++ if (size > EFI_READ_CHUNK_SIZE) ++ chunksize = EFI_READ_CHUNK_SIZE; ++ else ++ chunksize = size; ++ status = efi_call_phys3(fh->read, ++ initrds[j].handle, ++ &chunksize, addr); ++ if (status != EFI_SUCCESS) ++ goto free_initrd_total; ++ addr += chunksize; ++ size -= chunksize; ++ } + + efi_call_phys1(fh->close, initrds[j].handle); +- +- addr += size; + } + + } +diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h +index f66d023..3925166 100644 +--- a/arch/x86/boot/compressed/eboot.h ++++ b/arch/x86/boot/compressed/eboot.h +@@ -12,6 +12,7 @@ + #define DESC_TYPE_CODE_DATA (1 << 0) + + #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT) ++#define EFI_READ_CHUNK_SIZE (1024 * 1024) + + #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0 + #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1 +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0011-x86-efi-Fix-pointer-math-issue-in-handle_ramdisks.patch b/debian/patches/features/x86/efi-stub/0011-x86-efi-Fix-pointer-math-issue-in-handle_ramdisks.patch new file mode 100644 index 000000000..daecd5e56 --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0011-x86-efi-Fix-pointer-math-issue-in-handle_ramdisks.patch @@ -0,0 +1,63 @@ +From: Dan Carpenter +Date: Mon, 5 Mar 2012 21:06:14 +0300 +Subject: [PATCH 11/11] x86, efi: Fix pointer math issue in handle_ramdisks() + +commit c7b738351ba92f48b943ac59aff6b5b0f17f37c9 upstream. + +"filename" is a efi_char16_t string so this check for reaching the end +of the array doesn't work. We need to cast the pointer to (u8 *) before +doing the math. + +This patch changes the "filename" to "filename_16" to avoid confusion in +the future. + +Signed-off-by: Dan Carpenter +Link: http://lkml.kernel.org/r/20120305180614.GA26880@elgon.mountain +Acked-by: Matt Fleming +Signed-off-by: H. Peter Anvin +--- + arch/x86/boot/compressed/eboot.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c +index fec216f..0cdfc0d 100644 +--- a/arch/x86/boot/compressed/eboot.c ++++ b/arch/x86/boot/compressed/eboot.c +@@ -539,7 +539,7 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image, + struct initrd *initrd; + efi_file_handle_t *h; + efi_file_info_t *info; +- efi_char16_t filename[256]; ++ efi_char16_t filename_16[256]; + unsigned long info_sz; + efi_guid_t info_guid = EFI_FILE_INFO_ID; + efi_char16_t *p; +@@ -552,14 +552,14 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image, + str += 7; + + initrd = &initrds[i]; +- p = filename; ++ p = filename_16; + + /* Skip any leading slashes */ + while (*str == '/' || *str == '\\') + str++; + + while (*str && *str != ' ' && *str != '\n') { +- if (p >= filename + sizeof(filename)) ++ if ((u8 *)p >= (u8 *)filename_16 + sizeof(filename_16)) + break; + + *p++ = *str++; +@@ -583,7 +583,7 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image, + goto free_initrds; + } + +- status = efi_call_phys5(fh->open, fh, &h, filename, ++ status = efi_call_phys5(fh->open, fh, &h, filename_16, + EFI_FILE_MODE_READ, (u64)0); + if (status != EFI_SUCCESS) + goto close_handles; +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0012-tools-include-Add-byteshift-headers-for-endian-acces.patch b/debian/patches/features/x86/efi-stub/0012-tools-include-Add-byteshift-headers-for-endian-acces.patch new file mode 100644 index 000000000..2342a42ab --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0012-tools-include-Add-byteshift-headers-for-endian-acces.patch @@ -0,0 +1,179 @@ +From: Matt Fleming +Date: Tue, 28 Feb 2012 13:37:20 +0000 +Subject: [PATCH 12/17] tools/include: Add byteshift headers for endian access + +commit a07f7672d7cf0ff0d6e548a9feb6e0bd016d9c6c upstream. + +There are various hostprogs in the kernel that are rolling their own +implementations of {get,put}_unaligned_le*(). Copy the byteshift +headers from include/linux/unaligned so that they can all use a single +implementation. + +This requires changing some of the data types to the userspace +exported ones (u32 -> __u32, etc). + +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1330436245-24875-2-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + tools/include/tools/be_byteshift.h | 70 ++++++++++++++++++++++++++++++++++++ + tools/include/tools/le_byteshift.h | 70 ++++++++++++++++++++++++++++++++++++ + 2 files changed, 140 insertions(+) + create mode 100644 tools/include/tools/be_byteshift.h + create mode 100644 tools/include/tools/le_byteshift.h + +diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h +new file mode 100644 +index 0000000..f4912e2 +--- /dev/null ++++ b/tools/include/tools/be_byteshift.h +@@ -0,0 +1,70 @@ ++#ifndef _TOOLS_BE_BYTESHIFT_H ++#define _TOOLS_BE_BYTESHIFT_H ++ ++#include ++ ++static inline __u16 __get_unaligned_be16(const __u8 *p) ++{ ++ return p[0] << 8 | p[1]; ++} ++ ++static inline __u32 __get_unaligned_be32(const __u8 *p) ++{ ++ return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; ++} ++ ++static inline __u64 __get_unaligned_be64(const __u8 *p) ++{ ++ return (__u64)__get_unaligned_be32(p) << 32 | ++ __get_unaligned_be32(p + 4); ++} ++ ++static inline void __put_unaligned_be16(__u16 val, __u8 *p) ++{ ++ *p++ = val >> 8; ++ *p++ = val; ++} ++ ++static inline void __put_unaligned_be32(__u32 val, __u8 *p) ++{ ++ __put_unaligned_be16(val >> 16, p); ++ __put_unaligned_be16(val, p + 2); ++} ++ ++static inline void __put_unaligned_be64(__u64 val, __u8 *p) ++{ ++ __put_unaligned_be32(val >> 32, p); ++ __put_unaligned_be32(val, p + 4); ++} ++ ++static inline __u16 get_unaligned_be16(const void *p) ++{ ++ return __get_unaligned_be16((const __u8 *)p); ++} ++ ++static inline __u32 get_unaligned_be32(const void *p) ++{ ++ return __get_unaligned_be32((const __u8 *)p); ++} ++ ++static inline __u64 get_unaligned_be64(const void *p) ++{ ++ return __get_unaligned_be64((const __u8 *)p); ++} ++ ++static inline void put_unaligned_be16(__u16 val, void *p) ++{ ++ __put_unaligned_be16(val, p); ++} ++ ++static inline void put_unaligned_be32(__u32 val, void *p) ++{ ++ __put_unaligned_be32(val, p); ++} ++ ++static inline void put_unaligned_be64(__u64 val, void *p) ++{ ++ __put_unaligned_be64(val, p); ++} ++ ++#endif /* _TOOLS_BE_BYTESHIFT_H */ +diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h +new file mode 100644 +index 0000000..c99d45a +--- /dev/null ++++ b/tools/include/tools/le_byteshift.h +@@ -0,0 +1,70 @@ ++#ifndef _TOOLS_LE_BYTESHIFT_H ++#define _TOOLS_LE_BYTESHIFT_H ++ ++#include ++ ++static inline __u16 __get_unaligned_le16(const __u8 *p) ++{ ++ return p[0] | p[1] << 8; ++} ++ ++static inline __u32 __get_unaligned_le32(const __u8 *p) ++{ ++ return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; ++} ++ ++static inline __u64 __get_unaligned_le64(const __u8 *p) ++{ ++ return (__u64)__get_unaligned_le32(p + 4) << 32 | ++ __get_unaligned_le32(p); ++} ++ ++static inline void __put_unaligned_le16(__u16 val, __u8 *p) ++{ ++ *p++ = val; ++ *p++ = val >> 8; ++} ++ ++static inline void __put_unaligned_le32(__u32 val, __u8 *p) ++{ ++ __put_unaligned_le16(val >> 16, p + 2); ++ __put_unaligned_le16(val, p); ++} ++ ++static inline void __put_unaligned_le64(__u64 val, __u8 *p) ++{ ++ __put_unaligned_le32(val >> 32, p + 4); ++ __put_unaligned_le32(val, p); ++} ++ ++static inline __u16 get_unaligned_le16(const void *p) ++{ ++ return __get_unaligned_le16((const __u8 *)p); ++} ++ ++static inline __u32 get_unaligned_le32(const void *p) ++{ ++ return __get_unaligned_le32((const __u8 *)p); ++} ++ ++static inline __u64 get_unaligned_le64(const void *p) ++{ ++ return __get_unaligned_le64((const __u8 *)p); ++} ++ ++static inline void put_unaligned_le16(__u16 val, void *p) ++{ ++ __put_unaligned_le16(val, p); ++} ++ ++static inline void put_unaligned_le32(__u32 val, void *p) ++{ ++ __put_unaligned_le32(val, p); ++} ++ ++static inline void put_unaligned_le64(__u64 val, void *p) ++{ ++ __put_unaligned_le64(val, p); ++} ++ ++#endif /* _TOOLS_LE_BYTESHIFT_H */ +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0013-x86-mkpiggy-Don-t-open-code-put_unaligned_le32.patch b/debian/patches/features/x86/efi-stub/0013-x86-mkpiggy-Don-t-open-code-put_unaligned_le32.patch new file mode 100644 index 000000000..5a7a481c4 --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0013-x86-mkpiggy-Don-t-open-code-put_unaligned_le32.patch @@ -0,0 +1,62 @@ +From: Matt Fleming +Date: Tue, 28 Feb 2012 13:37:22 +0000 +Subject: [PATCH 13/17] x86, mkpiggy: Don't open code put_unaligned_le32() + +commit 12871c568305a0b20f116315479a18cd46882e9b upstream. + +Use the new headers in tools/include instead of rolling our own +put_unaligned_le32() implementation. + +Cc: H. Peter Anvin +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1330436245-24875-4-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + arch/x86/boot/compressed/Makefile | 1 + + arch/x86/boot/compressed/mkpiggy.c | 11 ++--------- + 2 files changed, 3 insertions(+), 9 deletions(-) + +diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile +index b123b9a..fd55a2f 100644 +--- a/arch/x86/boot/compressed/Makefile ++++ b/arch/x86/boot/compressed/Makefile +@@ -22,6 +22,7 @@ LDFLAGS := -m elf_$(UTS_MACHINE) + LDFLAGS_vmlinux := -T + + hostprogs-y := mkpiggy ++HOST_EXTRACFLAGS += -I$(srctree)/tools/include + + VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ + $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \ +diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c +index 46a8238..958a641 100644 +--- a/arch/x86/boot/compressed/mkpiggy.c ++++ b/arch/x86/boot/compressed/mkpiggy.c +@@ -29,14 +29,7 @@ + #include + #include + #include +- +-static uint32_t getle32(const void *p) +-{ +- const uint8_t *cp = p; +- +- return (uint32_t)cp[0] + ((uint32_t)cp[1] << 8) + +- ((uint32_t)cp[2] << 16) + ((uint32_t)cp[3] << 24); +-} ++#include + + int main(int argc, char *argv[]) + { +@@ -69,7 +62,7 @@ int main(int argc, char *argv[]) + } + + ilen = ftell(f); +- olen = getle32(&olen); ++ olen = get_unaligned_le32(&olen); + fclose(f); + + /* +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0014-x86-boot-Restrict-CFLAGS-for-hostprogs.patch b/debian/patches/features/x86/efi-stub/0014-x86-boot-Restrict-CFLAGS-for-hostprogs.patch new file mode 100644 index 000000000..6a07540af --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0014-x86-boot-Restrict-CFLAGS-for-hostprogs.patch @@ -0,0 +1,41 @@ +From: Matt Fleming +Date: Tue, 28 Feb 2012 13:37:23 +0000 +Subject: [PATCH 14/17] x86, boot: Restrict CFLAGS for hostprogs + +commit d40f833630a1299fd377408dc8d8fac370d621b0 upstream. + +Currently tools/build has access to all the kernel headers in +$(srctree). This is unnecessary and could potentially allow +tools/build to erroneously include kernel headers when it should only +be including userspace-exported headers. + +Unfortunately, mkcpustr still needs access to some of the asm kernel +headers, so explicitly special case that hostprog. + +Cc: H. Peter Anvin +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1330436245-24875-5-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + arch/x86/boot/Makefile | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile +index 95365a8..3e02148 100644 +--- a/arch/x86/boot/Makefile ++++ b/arch/x86/boot/Makefile +@@ -37,8 +37,9 @@ setup-y += video-bios.o + targets += $(setup-y) + hostprogs-y := mkcpustr tools/build + +-HOST_EXTRACFLAGS += $(LINUXINCLUDE) +- ++HOSTCFLAGS_mkcpustr.o := -I$(srctree)/arch/$(SRCARCH)/include ++HOST_EXTRACFLAGS += -I$(objtree)/include -I$(srctree)/tools/include \ ++ -include $(srctree)/include/linux/kconfig.h + $(obj)/cpu.o: $(obj)/cpustr.h + + quiet_cmd_cpustr = CPUSTR $@ +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0015-x86-efi-Fix-endian-issues-and-unaligned-accesses.patch b/debian/patches/features/x86/efi-stub/0015-x86-efi-Fix-endian-issues-and-unaligned-accesses.patch new file mode 100644 index 000000000..39d1b2123 --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0015-x86-efi-Fix-endian-issues-and-unaligned-accesses.patch @@ -0,0 +1,125 @@ +From: Matt Fleming +Date: Tue, 28 Feb 2012 13:37:24 +0000 +Subject: [PATCH 15/17] x86, efi: Fix endian issues and unaligned accesses + +commit 92f42c50f227ad228f815a8f4eec872524dae3a5 upstream. + +We may need to convert the endianness of the data we read from/write +to 'buf', so let's use {get,put}_unaligned_le32() to do that. Failure +to do so can result in accessing invalid memory, leading to a +segfault. Stephen Rothwell noticed this bug while cross-building an +x86_64 allmodconfig kernel on PowerPC. + +We need to read from and write to 'buf' a byte at a time otherwise +it's possible we'll perform an unaligned access, which can lead to bus +errors when cross-building an x86 kernel on risc architectures. + +Cc: H. Peter Anvin +Cc: Nick Bowler +Tested-by: Stephen Rothwell +Reported-by: Stephen Rothwell +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1330436245-24875-6-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + arch/x86/boot/tools/build.c | 31 +++++++++++++++---------------- + 1 file changed, 15 insertions(+), 16 deletions(-) + +diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c +index 4e9bd6b..f2ac95e 100644 +--- a/arch/x86/boot/tools/build.c ++++ b/arch/x86/boot/tools/build.c +@@ -34,6 +34,7 @@ + #include + #include + #include ++#include + + typedef unsigned char u8; + typedef unsigned short u16; +@@ -41,6 +42,7 @@ typedef unsigned long u32; + + #define DEFAULT_MAJOR_ROOT 0 + #define DEFAULT_MINOR_ROOT 0 ++#define DEFAULT_ROOT_DEV (DEFAULT_MAJOR_ROOT << 8 | DEFAULT_MINOR_ROOT) + + /* Minimal number of setup sectors */ + #define SETUP_SECT_MIN 5 +@@ -159,7 +161,7 @@ int main(int argc, char ** argv) + die("read-error on `setup'"); + if (c < 1024) + die("The setup must be at least 1024 bytes"); +- if (buf[510] != 0x55 || buf[511] != 0xaa) ++ if (get_unaligned_le16(&buf[510]) != 0xAA55) + die("Boot block hasn't got boot flag (0xAA55)"); + fclose(file); + +@@ -171,8 +173,7 @@ int main(int argc, char ** argv) + memset(buf+c, 0, i-c); + + /* Set the default root device */ +- buf[508] = DEFAULT_MINOR_ROOT; +- buf[509] = DEFAULT_MAJOR_ROOT; ++ put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); + + fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i); + +@@ -192,44 +193,42 @@ int main(int argc, char ** argv) + + /* Patch the setup code with the appropriate size parameters */ + buf[0x1f1] = setup_sectors-1; +- buf[0x1f4] = sys_size; +- buf[0x1f5] = sys_size >> 8; +- buf[0x1f6] = sys_size >> 16; +- buf[0x1f7] = sys_size >> 24; ++ put_unaligned_le32(sys_size, &buf[0x1f4]); + + #ifdef CONFIG_EFI_STUB + file_sz = sz + i + ((sys_size * 16) - sz); + +- pe_header = *(unsigned int *)&buf[0x3c]; ++ pe_header = get_unaligned_le32(&buf[0x3c]); + + /* Size of code */ +- *(unsigned int *)&buf[pe_header + 0x1c] = file_sz; ++ put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]); + + /* Size of image */ +- *(unsigned int *)&buf[pe_header + 0x50] = file_sz; ++ put_unaligned_le32(file_sz, &buf[pe_header + 0x50]); + + #ifdef CONFIG_X86_32 + /* Address of entry point */ +- *(unsigned int *)&buf[pe_header + 0x28] = i; ++ put_unaligned_le32(i, &buf[pe_header + 0x28]); + + /* .text size */ +- *(unsigned int *)&buf[pe_header + 0xb0] = file_sz; ++ put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]); + + /* .text size of initialised data */ +- *(unsigned int *)&buf[pe_header + 0xb8] = file_sz; ++ put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]); + #else + /* + * Address of entry point. startup_32 is at the beginning and + * the 64-bit entry point (startup_64) is always 512 bytes + * after. + */ +- *(unsigned int *)&buf[pe_header + 0x28] = i + 512; ++ put_unaligned_le32(i + 512, &buf[pe_header + 0x28]); + + /* .text size */ +- *(unsigned int *)&buf[pe_header + 0xc0] = file_sz; ++ put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]); + + /* .text size of initialised data */ +- *(unsigned int *)&buf[pe_header + 0xc8] = file_sz; ++ put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]); ++ + #endif /* CONFIG_X86_32 */ + #endif /* CONFIG_EFI_STUB */ + +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0016-x86-boot-Correct-CFLAGS-for-hostprogs.patch b/debian/patches/features/x86/efi-stub/0016-x86-boot-Correct-CFLAGS-for-hostprogs.patch new file mode 100644 index 000000000..b00469eca --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0016-x86-boot-Correct-CFLAGS-for-hostprogs.patch @@ -0,0 +1,50 @@ +From: "H. Peter Anvin" +Date: Thu, 22 Mar 2012 11:08:18 -0700 +Subject: [PATCH 16/17] x86, boot: Correct CFLAGS for hostprogs + +commit 446e1c86d51d0823e003a43a2b85c430efce2733 upstream. + +This is a partial revert of commit: + d40f833 "Restrict CFLAGS for hostprogs" + +The endian-manipulation macros in tools/include need , +but the hostprogs in arch/x86/boot need several headers from the +kernel build tree, which means we have to add the kernel headers to +the include path. This picks up from the kernel tree, +which gives a warning. + +Since this use of is intentional, add +-D__EXPORTED_HEADERS__ to the command line to silence the warning. + +A better way to fix this would be to always install the exported +kernel headers into $(objtree)/usr/include as a standard part of the +kernel build, but that is a lot more involved. + +Reported-by: Linus Torvalds +Acked-by: Matt Fleming +Link: http://lkml.kernel.org/r/1330436245-24875-5-git-send-email-matt@console-pimps.org +Signed-off-by: H. Peter Anvin +--- + arch/x86/boot/Makefile | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile +index 3e02148..5a747dd 100644 +--- a/arch/x86/boot/Makefile ++++ b/arch/x86/boot/Makefile +@@ -37,9 +37,9 @@ setup-y += video-bios.o + targets += $(setup-y) + hostprogs-y := mkcpustr tools/build + +-HOSTCFLAGS_mkcpustr.o := -I$(srctree)/arch/$(SRCARCH)/include +-HOST_EXTRACFLAGS += -I$(objtree)/include -I$(srctree)/tools/include \ +- -include $(srctree)/include/linux/kconfig.h ++HOST_EXTRACFLAGS += -I$(srctree)/tools/include $(LINUXINCLUDE) \ ++ -D__EXPORTED_HEADERS__ ++ + $(obj)/cpu.o: $(obj)/cpustr.h + + quiet_cmd_cpustr = CPUSTR $@ +-- +1.7.10 + diff --git a/debian/patches/features/x86/efi-stub/0017-x86-efi-Add-dedicated-EFI-stub-entry-point.patch b/debian/patches/features/x86/efi-stub/0017-x86-efi-Add-dedicated-EFI-stub-entry-point.patch new file mode 100644 index 000000000..da5b1ef23 --- /dev/null +++ b/debian/patches/features/x86/efi-stub/0017-x86-efi-Add-dedicated-EFI-stub-entry-point.patch @@ -0,0 +1,143 @@ +From: Matt Fleming +Date: Sun, 15 Apr 2012 16:06:04 +0100 +Subject: [PATCH 17/17] x86, efi: Add dedicated EFI stub entry point + +commit b1994304fc399f5d3a5368c81111d713490c4799 upstream. + +The method used to work out whether we were booted by EFI firmware or +via a boot loader is broken. Because efi_main() is always executed +when booting from a boot loader we will dereference invalid pointers +either on the stack (CONFIG_X86_32) or contained in %rdx +(CONFIG_X86_64) when searching for an EFI System Table signature. + +Instead of dereferencing these invalid system table pointers, add a +new entry point that is only used when booting from EFI firmware, when +we know the pointer arguments will be valid. With this change legacy +boot loaders will no longer execute efi_main(), but will instead skip +EFI stub initialisation completely. + +[ hpa: Marking this for urgent/stable since it is a regression when + the option is enabled; without the option the patch has no effect ] + +Signed-off-by: Matt Fleming +Link: http://lkml.kernel.org/r/1334584744.26997.14.camel@mfleming-mobl1.ger.corp.intel.com +Reported-by: Jordan Justen +Signed-off-by: H. Peter Anvin +Cc: v3.3 +--- + arch/x86/boot/compressed/head_32.S | 14 +++++++++++--- + arch/x86/boot/compressed/head_64.S | 22 ++++++++++++++++------ + arch/x86/boot/tools/build.c | 15 +++++++++++---- + 3 files changed, 38 insertions(+), 13 deletions(-) + +diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S +index a055993..c85e3ac 100644 +--- a/arch/x86/boot/compressed/head_32.S ++++ b/arch/x86/boot/compressed/head_32.S +@@ -33,6 +33,9 @@ + __HEAD + ENTRY(startup_32) + #ifdef CONFIG_EFI_STUB ++ jmp preferred_addr ++ ++ .balign 0x10 + /* + * We don't need the return address, so set up the stack so + * efi_main() can find its arugments. +@@ -41,12 +44,17 @@ ENTRY(startup_32) + + call efi_main + cmpl $0, %eax +- je preferred_addr + movl %eax, %esi +- call 1f ++ jne 2f + 1: ++ /* EFI init failed, so hang. */ ++ hlt ++ jmp 1b ++2: ++ call 3f ++3: + popl %eax +- subl $1b, %eax ++ subl $3b, %eax + subl BP_pref_address(%esi), %eax + add BP_code32_start(%esi), %eax + leal preferred_addr(%eax), %eax +diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S +index 558d76c..87e03a1 100644 +--- a/arch/x86/boot/compressed/head_64.S ++++ b/arch/x86/boot/compressed/head_64.S +@@ -200,18 +200,28 @@ ENTRY(startup_64) + * entire text+data+bss and hopefully all of memory. + */ + #ifdef CONFIG_EFI_STUB +- pushq %rsi ++ /* ++ * The entry point for the PE/COFF executable is 0x210, so only ++ * legacy boot loaders will execute this jmp. ++ */ ++ jmp preferred_addr ++ ++ .org 0x210 + mov %rcx, %rdi + mov %rdx, %rsi + call efi_main +- popq %rsi +- cmpq $0,%rax +- je preferred_addr + movq %rax,%rsi +- call 1f ++ cmpq $0,%rax ++ jne 2f + 1: ++ /* EFI init failed, so hang. */ ++ hlt ++ jmp 1b ++2: ++ call 3f ++3: + popq %rax +- subq $1b, %rax ++ subq $3b, %rax + subq BP_pref_address(%rsi), %rax + add BP_code32_start(%esi), %eax + leaq preferred_addr(%rax), %rax +diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c +index ed54976..24443a3 100644 +--- a/arch/x86/boot/tools/build.c ++++ b/arch/x86/boot/tools/build.c +@@ -205,8 +205,13 @@ int main(int argc, char ** argv) + put_unaligned_le32(file_sz, &buf[pe_header + 0x50]); + + #ifdef CONFIG_X86_32 +- /* Address of entry point */ +- put_unaligned_le32(i, &buf[pe_header + 0x28]); ++ /* ++ * Address of entry point. ++ * ++ * The EFI stub entry point is +16 bytes from the start of ++ * the .text section. ++ */ ++ put_unaligned_le32(i + 16, &buf[pe_header + 0x28]); + + /* .text size */ + put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]); +@@ -217,9 +222,11 @@ int main(int argc, char ** argv) + /* + * Address of entry point. startup_32 is at the beginning and + * the 64-bit entry point (startup_64) is always 512 bytes +- * after. ++ * after. The EFI stub entry point is 16 bytes after that, as ++ * the first instruction allows legacy loaders to jump over ++ * the EFI stub initialisation + */ +- put_unaligned_le32(i + 512, &buf[pe_header + 0x28]); ++ put_unaligned_le32(i + 528, &buf[pe_header + 0x28]); + + /* .text size */ + put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]); +-- +1.7.10 + diff --git a/debian/patches/series/base b/debian/patches/series/base index 6e4fa7762..3495857e5 100644 --- a/debian/patches/series/base +++ b/debian/patches/series/base @@ -97,3 +97,19 @@ + features/x86/hyperv/0077-hv-remove-the-second-argument-of-k-un-map_atomic.patch + bugfix/all/hugetlb-fix-race-condition-in-hugetlb_fault.patch + ++ features/x86/efi-stub/0011-x86-efi-Fix-pointer-math-issue-in-handle_ramdisks.patch ++ features/x86/efi-stub/0012-tools-include-Add-byteshift-headers-for-endian-acces.patch ++ features/x86/efi-stub/0013-x86-mkpiggy-Don-t-open-code-put_unaligned_le32.patch ++ features/x86/efi-stub/0014-x86-boot-Restrict-CFLAGS-for-hostprogs.patch ++ features/x86/efi-stub/0015-x86-efi-Fix-endian-issues-and-unaligned-accesses.patch ++ features/x86/efi-stub/0016-x86-boot-Correct-CFLAGS-for-hostprogs.patch ++ features/x86/efi-stub/0017-x86-efi-Add-dedicated-EFI-stub-entry-point.patch + ++ bugfix/all/brcmsmac-INTERMEDIATE-but-not-AMPDU-only-when-tracin.patch ++ bugfix/all/NFSv4-Rate-limit-the-state-manager-for-lock-reclaim-.patch ++ bugfix/all/NFSv4-Ensure-that-the-LOCK-code-sets-exception-inode.patch ++ bugfix/all/NFSv4-Ensure-that-we-check-lock-exclusive-shared-typ.patch ++ bugfix/x86/drm-i915-fix-integer-overflow-in-i915_gem_execbuffer2.patch ++ bugfix/x86/drm-i915-fix-integer-overflow-in-i915_gem_do_execbuffer.patch ++ bugfix/all/revert-autofs-work-around-unhappy-compat-problem-on-.patch