From patchwork Wed Feb 17 19:44: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: 62130 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp190299lbl; Wed, 17 Feb 2016 11:45:04 -0800 (PST) X-Received: by 10.140.107.70 with SMTP id g64mr4129952qgf.75.1455738304163; Wed, 17 Feb 2016 11:45:04 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h5si47661242qgh.64.2016.02.17.11.45.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 17 Feb 2016 11:45:04 -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]:60991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW823-0006ar-N4 for patch@linaro.org; Wed, 17 Feb 2016 14:45:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW81j-0006aO-TM for grub-devel@gnu.org; Wed, 17 Feb 2016 14:44:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aW81g-0003i2-NE for grub-devel@gnu.org; Wed, 17 Feb 2016 14:44:43 -0500 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:36576) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW81g-0003hy-F6 for grub-devel@gnu.org; Wed, 17 Feb 2016 14:44:40 -0500 Received: by mail-wm0-x22a.google.com with SMTP id g62so177741006wme.1 for ; Wed, 17 Feb 2016 11:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BhroKE3WchIT6fENOpUxNTD04kn+7CJMq/UsFeUOvgs=; b=JoAMYluvnxxdPoqnzD7y+NWCnp3QGD0l9AfWPTC6xu2Ixnqm7l224ulFoqEYe+ndgV AUDbPktb8YRBD4eLge6P7S2oGZPtRw2FTN1STWfzhY3RYXqS/w6QDs7g4WlVdEJVQD/m 9K0WbrijIOHdD9+DKjTpBjNkQivtUVNYFtq9k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BhroKE3WchIT6fENOpUxNTD04kn+7CJMq/UsFeUOvgs=; b=Z4b0S1Cy52GXSsav6vH2QjwGL5zk8VNH2rp0DeRld7iL+MaM3KXBoE9M21xMIeKxDQ x/KYiKjJGuYso4TDSFGalPemJ57y637/SzlxRoQu4BB92d++0qexV7c24Tow21/SzCNE 1PpfcSykSARZ+E7gYxW0FWxHav9cxy96pSXP+UYdUHiNRqJBgmPfKg3JtXNFm8ZjYhP+ LY5XXqZwWwucgejPao7+Op1HCevJrg9er7G2rM8IXwHRmPYZefPNVM6vvbczjpwHsRGl vJPQwOpHGPLfuaU8nuhCfTpcbwSutmmi9L/OTcWau5PKqZWHyzvuQajmdSoUljCSUjQm dJYQ== X-Gm-Message-State: AG10YOQRi5W85G0IpCe94VJ+IyA93wvWv4GDtupbY2+Wg6PLwF4IG5cnR8EhvyU8sQOzkrDG X-Received: by 10.194.76.211 with SMTP id m19mr4314045wjw.113.1455738279601; Wed, 17 Feb 2016 11:44:39 -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 g1sm33174191wmc.0.2016.02.17.11.44.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Feb 2016 11:44:38 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH] efidisk: Respect block_io_protocol buffer alignment Date: Wed, 17 Feb 2016 19:44:34 +0000 Message-Id: <1455738274-20469-1-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <56C49E90.3070307@gmail.com> References: <56C49E90.3070307@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22a 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: , 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. Make grub_efidisk_readwrite() allocate a temporary buffer, aligned to this boundary, if the buffer passed to it does not already meet the requirements. Reported-by: Jeremy Linton --- This modified version is contained entirely within the efidisk driver. There is some excessive copying going on, but it removes the risk of the changes interfering with other disk drivers. grub-core/disk/efi/efidisk.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 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..901133f 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -524,15 +524,42 @@ grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector, { struct grub_efidisk_data *d; grub_efi_block_io_t *bio; + grub_efi_status_t status; + grub_size_t io_align, num_bytes; + char *aligned_buf; d = disk->data; bio = d->block_io; - return efi_call_5 ((wr ? bio->write_blocks : bio->read_blocks), bio, - bio->media->media_id, - (grub_efi_uint64_t) sector, - (grub_efi_uintn_t) size << disk->log_sector_size, - buf); + /* Set alignment to 1 if 0 specified */ + io_align = bio->media->io_align ? bio->media->io_align : 1; + num_bytes = size << disk->log_sector_size; + + if ((unsigned long) buf & (io_align - 1)) + { + aligned_buf = grub_memalign (io_align, num_bytes); + if (! aligned_buf) + return GRUB_EFI_OUT_OF_RESOURCES; + if (wr) + grub_memcpy (aligned_buf, buf, num_bytes); + } + else + { + aligned_buf = buf; + } + + status = efi_call_5 ((wr ? bio->write_blocks : bio->read_blocks), bio, + bio->media->media_id, (grub_efi_uint64_t) sector, + (grub_efi_uintn_t) num_bytes, aligned_buf); + + if ((unsigned long) buf & (io_align - 1)) + { + if (!wr) + grub_memcpy (buf, aligned_buf, num_bytes); + grub_free (aligned_buf); + } + + return status; } static grub_err_t