diff mbox

[GIT,PULL] Btrfs

Message ID 20131115113216.GA7777@osiris (mailing list archive)
State New, archived
Headers show

Commit Message

Heiko Carstens Nov. 15, 2013, 11:32 a.m. UTC
On Thu, Nov 14, 2013 at 12:19:52PM -0500, Chris Mason wrote:
> Hi Linus,
> 
> Please pull my for-linus branch:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git for-linus
> 
> This is our usual merge window set of bug fixes, performance
> improvements and cleanups.  Miao Xie has some really nice optimizations
> for writeback.
> 
> Josef also expanded our sanity checks quite a bit; these make up a big
> chunk of the new lines.

Hmm..  b19e68439375  "btrfs: Remove redundant local zero structure" seems to
use the empty_zero_page incorrectly and causes this compile warning on s390:

  CC      fs/btrfs/ioctl.o
fs/btrfs/ioctl.c: In function 'btrfs_is_empty_uuid':
fs/btrfs/ioctl.c:372:2: warning: passing argument 2 of 'memcmp' makes pointer from
                        integer without a cast [enabled by default]
  return !memcmp(uuid, empty_zero_page, BTRFS_UUID_SIZE);
  ^

In fact there seem to be two more incorrect usages in the kernel. The patch
below is not really tested.


From c2a9d3a453629466f0528aacbc6cbecc4247cff5 Mon Sep 17 00:00:00 2001
From: Heiko Carstens <heiko.carstens@de.ibm.com>
Date: Fri, 15 Nov 2013 12:14:55 +0100
Subject: [PATCH] fix empty_zero_page misusage

The definition of empty_zero_page is architecture specific.
It is (currently) either a character array, an unsigned long containing
the address of the empty_zero_page, or even worse only the address
of the struct page belonging to the empty_zero_page.

So using empty_zero_page as source address to e.g. clear something may
give random results.
ZERO_PAGE() however returns across all architectures the pointer to
the struct page belonging to the empty_zero_page.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
---
 drivers/spi/spi-fsl-cpm.c | 3 ++-
 fs/btrfs/ioctl.c          | 4 +++-
 virt/kvm/kvm_main.c       | 5 +++--
 3 files changed, 8 insertions(+), 4 deletions(-)

Comments

Chris Mason Nov. 15, 2013, 12:21 p.m. UTC | #1
Quoting Heiko Carstens (2013-11-15 06:32:16)
> On Thu, Nov 14, 2013 at 12:19:52PM -0500, Chris Mason wrote:
> > Hi Linus,
> > 
> > Please pull my for-linus branch:
> > 
> > git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git for-linus
> > 
> > This is our usual merge window set of bug fixes, performance
> > improvements and cleanups.  Miao Xie has some really nice optimizations
> > for writeback.
> > 
> > Josef also expanded our sanity checks quite a bit; these make up a big
> > chunk of the new lines.
> 
> Hmm..  b19e68439375  "btrfs: Remove redundant local zero structure" seems to
> use the empty_zero_page incorrectly and causes this compile warning on s390:
> 
>   CC      fs/btrfs/ioctl.o
> fs/btrfs/ioctl.c: In function 'btrfs_is_empty_uuid':
> fs/btrfs/ioctl.c:372:2: warning: passing argument 2 of 'memcmp' makes pointer from
>                         integer without a cast [enabled by default]
>   return !memcmp(uuid, empty_zero_page, BTRFS_UUID_SIZE);
>   ^
> 
> In fact there seem to be two more incorrect usages in the kernel. The patch
> below is not really tested.

Thanks Heiko,

I'll make a new pull with the btrfs part of this.

-chris
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chris Mason Nov. 15, 2013, 1:40 p.m. UTC | #2
Quoting Chris Mason (2013-11-15 07:21:31)
> Quoting Heiko Carstens (2013-11-15 06:32:16)
> > On Thu, Nov 14, 2013 at 12:19:52PM -0500, Chris Mason wrote:
> > > Hi Linus,
> > > 
> > > Please pull my for-linus branch:
> > > 
> > > git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git for-linus
> > > 
> > > This is our usual merge window set of bug fixes, performance
> > > improvements and cleanups.  Miao Xie has some really nice optimizations
> > > for writeback.
> > > 
> > > Josef also expanded our sanity checks quite a bit; these make up a big
> > > chunk of the new lines.
> > 
> > Hmm..  b19e68439375  "btrfs: Remove redundant local zero structure" seems to
> > use the empty_zero_page incorrectly and causes this compile warning on s390:
> > 
> >   CC      fs/btrfs/ioctl.o
> > fs/btrfs/ioctl.c: In function 'btrfs_is_empty_uuid':
> > fs/btrfs/ioctl.c:372:2: warning: passing argument 2 of 'memcmp' makes pointer from
> >                         integer without a cast [enabled by default]
> >   return !memcmp(uuid, empty_zero_page, BTRFS_UUID_SIZE);
> >   ^
> > 
> > In fact there seem to be two more incorrect usages in the kernel. The patch
> > below is not really tested.
> 
> Thanks Heiko,
> 
> I'll make a new pull with the btrfs part of this.

Or something slightly different ;)

BUG: unable to handle kernel paging request at 0000000001ba6000
IP: [<ffffffff812b3656>] memcmp+0xf/0x22

-chris

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Geert Uytterhoeven Nov. 15, 2013, 1:42 p.m. UTC | #3
On Fri, Nov 15, 2013 at 2:40 PM, Chris Mason <chris.mason@fusionio.com> wrote:
> Quoting Chris Mason (2013-11-15 07:21:31)
>> Quoting Heiko Carstens (2013-11-15 06:32:16)
>> > On Thu, Nov 14, 2013 at 12:19:52PM -0500, Chris Mason wrote:
>> > > Hi Linus,
>> > >
>> > > Please pull my for-linus branch:
>> > >
>> > > git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git for-linus
>> > >
>> > > This is our usual merge window set of bug fixes, performance
>> > > improvements and cleanups.  Miao Xie has some really nice optimizations
>> > > for writeback.
>> > >
>> > > Josef also expanded our sanity checks quite a bit; these make up a big
>> > > chunk of the new lines.
>> >
>> > Hmm..  b19e68439375  "btrfs: Remove redundant local zero structure" seems to
>> > use the empty_zero_page incorrectly and causes this compile warning on s390:
>> >
>> >   CC      fs/btrfs/ioctl.o
>> > fs/btrfs/ioctl.c: In function 'btrfs_is_empty_uuid':
>> > fs/btrfs/ioctl.c:372:2: warning: passing argument 2 of 'memcmp' makes pointer from
>> >                         integer without a cast [enabled by default]
>> >   return !memcmp(uuid, empty_zero_page, BTRFS_UUID_SIZE);
>> >   ^
>> >
>> > In fact there seem to be two more incorrect usages in the kernel. The patch
>> > below is not really tested.
>>
>> Thanks Heiko,
>>
>> I'll make a new pull with the btrfs part of this.
>
> Or something slightly different ;)
>
> BUG: unable to handle kernel paging request at 0000000001ba6000
> IP: [<ffffffff812b3656>] memcmp+0xf/0x22

I was just going to comment that

+       const void *zero_page = (const void *) page_to_phys(ZERO_PAGE(0));

won't fly. You can't just cast a physical address to "void *".

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Heiko Carstens Nov. 15, 2013, 2:57 p.m. UTC | #4
On Fri, Nov 15, 2013 at 02:42:08PM +0100, Geert Uytterhoeven wrote:
> On Fri, Nov 15, 2013 at 2:40 PM, Chris Mason <chris.mason@fusionio.com> wrote:
> > Quoting Chris Mason (2013-11-15 07:21:31)
> >> Quoting Heiko Carstens (2013-11-15 06:32:16)
> >> > On Thu, Nov 14, 2013 at 12:19:52PM -0500, Chris Mason wrote:
> >> > > Hi Linus,
> >> > >
> >> > > Please pull my for-linus branch:
> >> > >
> >> > > git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git for-linus
> >> > >
> >> > > This is our usual merge window set of bug fixes, performance
> >> > > improvements and cleanups.  Miao Xie has some really nice optimizations
> >> > > for writeback.
> >> > >
> >> > > Josef also expanded our sanity checks quite a bit; these make up a big
> >> > > chunk of the new lines.
> >> >
> >> > Hmm..  b19e68439375  "btrfs: Remove redundant local zero structure" seems to
> >> > use the empty_zero_page incorrectly and causes this compile warning on s390:
> >> >
> >> >   CC      fs/btrfs/ioctl.o
> >> > fs/btrfs/ioctl.c: In function 'btrfs_is_empty_uuid':
> >> > fs/btrfs/ioctl.c:372:2: warning: passing argument 2 of 'memcmp' makes pointer from
> >> >                         integer without a cast [enabled by default]
> >> >   return !memcmp(uuid, empty_zero_page, BTRFS_UUID_SIZE);
> >> >   ^
> >> >
> >> > In fact there seem to be two more incorrect usages in the kernel. The patch
> >> > below is not really tested.
> >>
> >> Thanks Heiko,
> >>
> >> I'll make a new pull with the btrfs part of this.
> >
> > Or something slightly different ;)
> >
> > BUG: unable to handle kernel paging request at 0000000001ba6000
> > IP: [<ffffffff812b3656>] memcmp+0xf/0x22
> 
> I was just going to comment that
> 
> +       const void *zero_page = (const void *) page_to_phys(ZERO_PAGE(0));
> 
> won't fly. You can't just cast a physical address to "void *".

Ouch.. I think that only works on s390 because we have a 1:1 mapping for
physical to virtual addresses in kernel space due to our split address spaces.

So for btrfs and kvm it should be page_to_virt(), and for the dma_map_single()
case I have no idea. :)

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Gleb Natapov Nov. 17, 2013, 9:36 a.m. UTC | #5
On Fri, Nov 15, 2013 at 03:57:23PM +0100, Heiko Carstens wrote:
> On Fri, Nov 15, 2013 at 02:42:08PM +0100, Geert Uytterhoeven wrote:
> > On Fri, Nov 15, 2013 at 2:40 PM, Chris Mason <chris.mason@fusionio.com> wrote:
> > > Quoting Chris Mason (2013-11-15 07:21:31)
> > >> Quoting Heiko Carstens (2013-11-15 06:32:16)
> > >> > On Thu, Nov 14, 2013 at 12:19:52PM -0500, Chris Mason wrote:
> > >> > > Hi Linus,
> > >> > >
> > >> > > Please pull my for-linus branch:
> > >> > >
> > >> > > git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git for-linus
> > >> > >
> > >> > > This is our usual merge window set of bug fixes, performance
> > >> > > improvements and cleanups.  Miao Xie has some really nice optimizations
> > >> > > for writeback.
> > >> > >
> > >> > > Josef also expanded our sanity checks quite a bit; these make up a big
> > >> > > chunk of the new lines.
> > >> >
> > >> > Hmm..  b19e68439375  "btrfs: Remove redundant local zero structure" seems to
> > >> > use the empty_zero_page incorrectly and causes this compile warning on s390:
> > >> >
> > >> >   CC      fs/btrfs/ioctl.o
> > >> > fs/btrfs/ioctl.c: In function 'btrfs_is_empty_uuid':
> > >> > fs/btrfs/ioctl.c:372:2: warning: passing argument 2 of 'memcmp' makes pointer from
> > >> >                         integer without a cast [enabled by default]
> > >> >   return !memcmp(uuid, empty_zero_page, BTRFS_UUID_SIZE);
> > >> >   ^
> > >> >
> > >> > In fact there seem to be two more incorrect usages in the kernel. The patch
> > >> > below is not really tested.
> > >>
> > >> Thanks Heiko,
> > >>
> > >> I'll make a new pull with the btrfs part of this.
> > >
> > > Or something slightly different ;)
> > >
> > > BUG: unable to handle kernel paging request at 0000000001ba6000
> > > IP: [<ffffffff812b3656>] memcmp+0xf/0x22
> > 
> > I was just going to comment that
> > 
> > +       const void *zero_page = (const void *) page_to_phys(ZERO_PAGE(0));
> > 
> > won't fly. You can't just cast a physical address to "void *".
> 
> Ouch.. I think that only works on s390 because we have a 1:1 mapping for
> physical to virtual addresses in kernel space due to our split address spaces.
> 
> So for btrfs and kvm it should be page_to_virt(), and for the dma_map_single()
> case I have no idea. :)
Can you send updated patch for kvm please?

--
			Gleb.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c
index 54b06376f03c..3807bbf8a48f 100644
--- a/drivers/spi/spi-fsl-cpm.c
+++ b/drivers/spi/spi-fsl-cpm.c
@@ -280,6 +280,7 @@  static unsigned long fsl_spi_cpm_get_pram(struct mpc8xxx_spi *mspi)
 
 int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
 {
+	const void *zero_page = (const void *) page_to_phys(ZERO_PAGE(0));
 	struct device *dev = mspi->dev;
 	struct device_node *np = dev->of_node;
 	const u32 *iprop;
@@ -324,7 +325,7 @@  int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
 		goto err_bds;
 	}
 
-	mspi->dma_dummy_tx = dma_map_single(dev, empty_zero_page, PAGE_SIZE,
+	mspi->dma_dummy_tx = dma_map_single(dev, zero_page, PAGE_SIZE,
 					    DMA_TO_DEVICE);
 	if (dma_mapping_error(dev, mspi->dma_dummy_tx)) {
 		dev_err(dev, "unable to map dummy tx buffer\n");
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 1d04b5559e61..83f2b3e4fbf0 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -368,8 +368,10 @@  static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
 
 int btrfs_is_empty_uuid(u8 *uuid)
 {
+	const void *zero_page = (const void *) page_to_phys(ZERO_PAGE(0));
+
 	BUILD_BUG_ON(BTRFS_UUID_SIZE > PAGE_SIZE);
-	return !memcmp(uuid, empty_zero_page, BTRFS_UUID_SIZE);
+	return !memcmp(uuid, zero_page, BTRFS_UUID_SIZE);
 }
 
 static noinline int create_subvol(struct inode *dir,
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 662f34c3287e..01edf1c19332 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1615,8 +1615,9 @@  EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
 
 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
 {
-	return kvm_write_guest_page(kvm, gfn, (const void *) empty_zero_page,
-				    offset, len);
+	const void *zero_page = (const void *) page_to_phys(ZERO_PAGE(0));
+
+	return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
 }
 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);