From patchwork Wed Feb 17 15:48:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 62117 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp75509lbl; Wed, 17 Feb 2016 07:48:55 -0800 (PST) X-Received: by 10.55.80.9 with SMTP id e9mr2708322qkb.94.1455724135700; Wed, 17 Feb 2016 07:48:55 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e13si1779417qka.120.2016.02.17.07.48.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 17 Feb 2016 07:48:55 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from localhost ([::1]:58935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW4LX-0000rQ-5w for patch@linaro.org; Wed, 17 Feb 2016 10:48:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW4LA-0000mw-DO for grub-devel@gnu.org; Wed, 17 Feb 2016 10:48:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aW4L9-0005EC-8i for grub-devel@gnu.org; Wed, 17 Feb 2016 10:48:32 -0500 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:38428) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW4L8-0005Dz-RT for grub-devel@gnu.org; Wed, 17 Feb 2016 10:48:31 -0500 Received: by mail-wm0-x232.google.com with SMTP id a4so34221557wme.1 for ; Wed, 17 Feb 2016 07:48:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=Q7cg1xbiyIaJQSfwkuVHDjzJ/irVzwiNaqZswybGb88=; b=FnwEifctCsu6L4PGUlMYCNIJNlf6KEmRV3JdBEkne0MpZjzy2EpqaQngiLdoUf5HmT jGjcbzu8EF1enG0ICUWyLFKmhUnlvRipiB+ZjTvotJCMtDRMKlezaSgXp5XL9F+YKg/t jOVXZcQ7wQYfUGloae3wdt2bbkdauh3xzZrzs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=Q7cg1xbiyIaJQSfwkuVHDjzJ/irVzwiNaqZswybGb88=; b=MxBfsYXy8qwJLbAaEnRxbj4o+SrYOHsy55B/fytZ18berZNwcHXeZaoybFtzAbl1Er aYhINYEtoChzFzT84zTeRuiIdABpHGTqlzCzMbTbl5FfYFLhtCkYPVHMKlPVl6ro5hTt 60nvyUmP8++DSV1ISDKEhPlLBJoXzO5A5d9hhGHs+Z46pTmmRytuwdc9fn0GG+w+ST8w FW08uYLv3R7QPbnmuArYnzHkIZ/Nv3TvKgNdC8PthUaSH80VDzjlcth0OgZrxECFRlrE Yglf/s9qkkLwwvSPy/6nfy4Ewt+DdAca2NVIVlrftmNfvtBDTDXCXF9ghGS+HsKPbhvh qQlw== X-Gm-Message-State: AG10YOSRrWuEtoN0eN43aw43bhz0zGiFGlFEom4YGRY7fgC3HvI6IFU3m55Qh5AjOqsOr+uP X-Received: by 10.28.150.69 with SMTP id y66mr4292563wmd.35.1455724109836; Wed, 17 Feb 2016 07:48:29 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id jo6sm2060207wjb.48.2016.02.17.07.48.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Feb 2016 07:48:28 -0800 (PST) Date: Wed, 17 Feb 2016 15:48:25 +0000 From: Leif Lindholm To: grub-devel@gnu.org Subject: Respect EFI block-io buffer alignment Message-ID: <20160217154825.GD1159@bivouac.eciton.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::232 Cc: Jeremy Linton X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: grub-devel-bounces+patch=linaro.org@gnu.org This resolves a complete failure to access devices connected to the SATA port on the ARM ltd. Juno platform (apart from a violation of the UEFI block io protocol). The below is a bit of a hack, but I'd like some feedback on preferred solution before over(or under)engineering something. As far as I can tell, a struct_disk is only ever allocated in kern/disk.c, using grub_zalloc(). So the only reason for the horrid ifdefs is that there is no grub_memalign for EMU. Do I: - Keep the ifdefs? - Implement grub_memalign() for EMU? - Something else? / Leif >From 2d8b7ae2dd4c639252517e9a1df783ed0564c112 Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Wed, 17 Feb 2016 15:33:47 +0000 Subject: [PATCH] efidisk: Respect block_io_protocol buffer alignment Returned from the OpenProtocol operation, the grub_efi_block_io_media structure contains the io_align field, specifying the minimum alignment required for buffers used in any data transfers with the device. Add an io_align field to struct grub_disk, and use it in kern/disk.c when GRUB_MACHINE_EFI is defined. Reported-by: Jeremy Linton --- grub-core/disk/efi/efidisk.c | 1 + grub-core/kern/disk.c | 9 +++++++++ include/grub/disk.h | 3 +++ 3 files changed, 13 insertions(+) -- 2.1.4 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 1c00e3e..424ff92 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -495,6 +495,7 @@ grub_efidisk_open (const char *name, struct grub_disk *disk) and total sectors should be replaced with total blocks. */ grub_dprintf ("efidisk", "m = %p, last block = %llx, block size = %x\n", m, (unsigned long long) m->last_block, m->block_size); + disk->io_align = m->io_align; disk->total_sectors = m->last_block + 1; /* Don't increase this value due to bug in some EFI. */ disk->max_agglomerate = 0xa0000 >> (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS); diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 789f8c0..27bef10 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -331,7 +331,12 @@ grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector, } /* Allocate a temporary buffer. */ +#ifdef GRUB_MACHINE_EFI + tmp_buf = grub_memalign (disk->io_align, + GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS); +#else tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS); +#endif if (! tmp_buf) return grub_errno; @@ -373,7 +378,11 @@ grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector, num = ((size + offset + (1ULL << (disk->log_sector_size)) - 1) >> (disk->log_sector_size)); +#ifdef GRUB_MACHINE_EFI + tmp_buf = grub_memalign (disk->io_align, num << disk->log_sector_size); +#else tmp_buf = grub_malloc (num << disk->log_sector_size); +#endif if (!tmp_buf) return grub_errno; diff --git a/include/grub/disk.h b/include/grub/disk.h index b385af8..b063bf6 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -126,6 +126,9 @@ struct grub_disk /* Logarithm of sector size. */ unsigned int log_sector_size; + /* Minimum read/write buffer alignment */ + unsigned int io_align; + /* Maximum number of sectors read divided by GRUB_DISK_CACHE_SIZE. */ unsigned int max_agglomerate;