Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aWFO4-0003Kb-M0 for mharc-grub-devel@gnu.org; Wed, 17 Feb 2016 22:36:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWFO1-0003KL-AQ for grub-devel@gnu.org; Wed, 17 Feb 2016 22:36:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWFNy-0008PG-36 for grub-devel@gnu.org; Wed, 17 Feb 2016 22:36:13 -0500 Received: from mail-lb0-x22a.google.com ([2a00:1450:4010:c04::22a]:33115) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWFNx-0008PA-Qv for grub-devel@gnu.org; Wed, 17 Feb 2016 22:36:10 -0500 Received: by mail-lb0-x22a.google.com with SMTP id x4so21248152lbm.0 for ; Wed, 17 Feb 2016 19:36:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=CriCMgC/ly24mQg09PBK1OaCEtG1FFos966IM7KccFg=; b=hE0l4EjonkIhUuSMn7b/c55G3DuDOJt3DrKmMZjgrhUpVX6l2MAJrRrtZJAL44g0qv ZIuu2Dlenzfx3aG1Qz+iXcgx9KEH2MzmQugNuVJ5OosxcKyVG2d0r5iKQ/IgB1BPQST3 UW8Ki4y6zhxavSzcv3uDlgF+5Ztk8GyHcHh5x7wo/quXsdpdkDQTXmaLFHJsaXcisluY AFW0c5LU8/sumET/tcPxy8n5D4JwpjBJFKA/8MgoKxb4TffmpCMSyCq0kXhKohwY6xEY o5Pjw8J93U+vCy2Bt82l2yfCZRjN2dbrciq+vOutAdwUyjYrBNtjPKHyncquUyCCLFdi d4DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=CriCMgC/ly24mQg09PBK1OaCEtG1FFos966IM7KccFg=; b=Ed793HO2bSFpHjaZG18oaGbU9xK3huAMn+6sCsQFeEBYWKnGQPUoILHBehIHt9i8wx uoNoZ3RSEfLQHBl+zvV2eBajodlkcS2q4AS7EyJ6cCegmsNyRUmibpevkhudYi3FaG0s D0uxzv0t895rBoEUq7Eq+5PQLEIHjCUaCDXuq79ZORjT5BrZLTJE/yIdJtT1kj8otghT nbnPTCqPYec0H5y7SM0pdhs8Z+8V5G3Mayp8c9ySfQi2jS3gPWKE8EyKUeGVWTEq9C8B ceZChwKnIkyvm3ifNxw7crMBWbTSWxmRW3S5V//Wu7v//17pv1EK/0dtKcw4tKrumyc2 WqWg== X-Gm-Message-State: AG10YOT60Olrtm6YLcw9C56NYLKm8rtir2Yxxwc0PGDLdlUnNoQ6J5AS1t0s61zzG5oNaA== X-Received: by 10.112.13.193 with SMTP id j1mr2246849lbc.24.1455766569047; Wed, 17 Feb 2016 19:36:09 -0800 (PST) Received: from [192.168.1.41] (ppp109-252-76-159.pppoe.spdop.ru. [109.252.76.159]) by smtp.gmail.com with ESMTPSA id g74sm659339lfi.1.2016.02.17.19.36.07 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 17 Feb 2016 19:36:07 -0800 (PST) Subject: Re: [PATCH] efidisk: Respect block_io_protocol buffer alignment To: The development of GNU GRUB References: <56C49E90.3070307@gmail.com> <1455738274-20469-1-git-send-email-leif.lindholm@linaro.org> From: Andrei Borzenkov X-Enigmail-Draft-Status: N1110 Message-ID: <56C53C26.5000406@gmail.com> Date: Thu, 18 Feb 2016 06:36:06 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <1455738274-20469-1-git-send-email-leif.lindholm@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::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: , X-List-Received-Date: Thu, 18 Feb 2016 03:36:15 -0000 17.02.2016 22:44, Leif Lindholm пишет: > 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(-) > > 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; We probably should sanity check that it is power of two in grub_efidisk_open. > + num_bytes = size << disk->log_sector_size; > + > + if ((unsigned long) buf & (io_align - 1)) grub_addr_t? > + { > + 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 >