From patchwork Fri Feb 19 16:18:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 62356 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1255292lbl; Fri, 19 Feb 2016 08:20:02 -0800 (PST) X-Received: by 10.55.23.217 with SMTP id 86mr16595626qkx.64.1455898801972; Fri, 19 Feb 2016 08:20:01 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s2si14985027qki.76.2016.02.19.08.20.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Feb 2016 08:20:01 -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]:53490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWnmj-0007o7-DN for patch@linaro.org; Fri, 19 Feb 2016 11:20:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWnlX-00066C-6s for grub-devel@gnu.org; Fri, 19 Feb 2016 11:18:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWnlU-0005zG-Te for grub-devel@gnu.org; Fri, 19 Feb 2016 11:18:47 -0500 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:35263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWnlU-0005z8-NL for grub-devel@gnu.org; Fri, 19 Feb 2016 11:18:44 -0500 Received: by mail-wm0-x22e.google.com with SMTP id c200so83454932wme.0 for ; Fri, 19 Feb 2016 08:18:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=NqTUVtB+iomkrVLWjhPOF/0p+awkhCaYEidBA9iwOGk=; b=M8ShZWoPLttLGXhn4N/vwzb4bdEfePe6UbdpTqEOPqXDwZ4+0GPSThnmdqfEGAqut1 mtNpOvzvF6T9nb1NgQ9fEz7oKe+jo3xRouzJLpxOsMdNHSuS6dsB+9RPGZDoPpp/EBXy 9xXoUQT6SKcbqdnSszGqzHxZi65T9Jzv+X9+g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=NqTUVtB+iomkrVLWjhPOF/0p+awkhCaYEidBA9iwOGk=; b=O61cQxOzdfrucp7lU0ZMwCO1IaiPdqZQVvXA7qAWF2SHENpr5vJdUXpY+RxorGn7C4 aLIDqtmu/QLrXM/7QC+nf7P4ZoDuG3dSwrZWZ0sJpoNMwZ7PGHJjub7o0yBBDw9dB094 Na7QGElwzLrzuopbblzJGx0d23ws5oDmzhUM/W0UdJJb//Namzjzip/RfhDwUcVdqKMC VCsZX6X8cyGJ9epomKnrRmX7QdeKAqIc665rwjcwHimnA383abpMhU2A+tcPEUSim4qA 50KB+f14UYiMWp4MvTIcQWMETtgVMKX6PnGtBWh0fVVa1ALQ5AfBNldBQAH7EQ0C5qII D3SQ== X-Gm-Message-State: AG10YOQsW9/BMJm8Z2BUELfP9utgmQciM+Z9NbeP3G7nHPzNPoVONdE+b9Nh/7mh9yCn+8J+ X-Received: by 10.28.227.213 with SMTP id a204mr10602843wmh.2.1455898724228; Fri, 19 Feb 2016 08:18:44 -0800 (PST) Received: from mohikan.mushroom.smurfnet.nu (cpc92308-cmbg19-2-0-cust814.5-4.cable.virginm.net. [82.24.251.47]) by smtp.gmail.com with ESMTPSA id t205sm8304703wmt.23.2016.02.19.08.18.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Feb 2016 08:18:43 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 2/2] efidisk: respect block_io_protocol minimum buffer alignment Date: Fri, 19 Feb 2016 16:18:34 +0000 Message-Id: <1455898714-25127-3-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455898714-25127-1-git-send-email-leif.lindholm@linaro.org> References: <1455898714-25127-1-git-send-email-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22e 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: , MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: grub-devel-bounces+patch=linaro.org@gnu.org 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. Implement a driver-specific malloc function that allocates a buffer with the required alignment. Also verify on open that the alignment value is valid, or return failure. --- grub-core/disk/efi/efidisk.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) -- 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..9b42585 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -457,6 +457,13 @@ get_device (struct grub_efidisk_data *devices, int num) return 0; } +static void * +aligned_malloc (struct grub_disk *disk, grub_size_t size) +{ + struct grub_efidisk_data *d = disk->data; + return grub_memalign (d->block_io->media->io_align, size); +} + static grub_err_t grub_efidisk_open (const char *name, struct grub_disk *disk) { @@ -493,8 +500,15 @@ grub_efidisk_open (const char *name, struct grub_disk *disk) m = d->block_io->media; /* FIXME: Probably it is better to store the block size in the 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); + grub_dprintf ("efidisk", + "m = %p, last block = %llx, block size = %x, io align = %x\n", + m, (unsigned long long) m->last_block, m->block_size, + m->io_align); + + /* Ensure required buffer alignment is a power of two (or is zero). */ + if (m->io_align & (m->io_align - 1)) + return grub_error (GRUB_ERR_IO, "invalid buffer alignment %d", 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); @@ -505,6 +519,7 @@ grub_efidisk_open (const char *name, struct grub_disk *disk) (1U << disk->log_sector_size) < m->block_size; disk->log_sector_size++); disk->data = d; + disk->malloc = aligned_malloc; grub_dprintf ("efidisk", "opening %s succeeded\n", name);