diff mbox series

[RFC,v3,34/36] kmsan: disable physical page merging in biovec

Message ID 20191122112621.204798-35-glider@google.com (mailing list archive)
State New, archived
Headers show
Series Add KernelMemorySanitizer infrastructure | expand

Commit Message

Alexander Potapenko Nov. 22, 2019, 11:26 a.m. UTC
KMSAN metadata for consequent physical pages may be inconsequent,
therefore accessing such pages together may lead to metadata
corruption.
We disable merging pages in biovec to prevent such corruptions.

Signed-off-by: Alexander Potapenko <glider@google.com>
To: Alexander Potapenko <glider@google.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Vegard Nossum <vegard.nossum@oracle.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: linux-mm@kvack.org
---

Change-Id: Id2f2babaf662ac44675c4f2790f4a80ddc328fa7
---
 block/blk.h | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Marco Elver Dec. 3, 2019, 12:54 p.m. UTC | #1
On Fri, 22 Nov 2019 at 12:28, <glider@google.com> wrote:
>
> KMSAN metadata for consequent physical pages may be inconsequent,
> therefore accessing such pages together may lead to metadata
> corruption.
> We disable merging pages in biovec to prevent such corruptions.
>
> Signed-off-by: Alexander Potapenko <glider@google.com>
> To: Alexander Potapenko <glider@google.com>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Vegard Nossum <vegard.nossum@oracle.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: linux-mm@kvack.org
> ---
>
> Change-Id: Id2f2babaf662ac44675c4f2790f4a80ddc328fa7
> ---
>  block/blk.h | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/block/blk.h b/block/blk.h
> index 47fba9362e60..9ee271a22423 100644
> --- a/block/blk.h
> +++ b/block/blk.h
> @@ -78,6 +78,13 @@ static inline bool biovec_phys_mergeable(struct request_queue *q,
>         phys_addr_t addr1 = page_to_phys(vec1->bv_page) + vec1->bv_offset;
>         phys_addr_t addr2 = page_to_phys(vec2->bv_page) + vec2->bv_offset;
>
> +#ifdef CONFIG_KMSAN

Prefer 'if (IS_ENABLED(CONFIG_KMSAN))'.

Thanks,
-- Marco
Alexander Potapenko Dec. 3, 2019, 1:38 p.m. UTC | #2
On Tue, Dec 3, 2019 at 1:54 PM Marco Elver <elver@google.com> wrote:
>
> On Fri, 22 Nov 2019 at 12:28, <glider@google.com> wrote:
> >
> > KMSAN metadata for consequent physical pages may be inconsequent,
> > therefore accessing such pages together may lead to metadata
> > corruption.
> > We disable merging pages in biovec to prevent such corruptions.
> >
> > Signed-off-by: Alexander Potapenko <glider@google.com>
> > To: Alexander Potapenko <glider@google.com>
> > Cc: Jens Axboe <axboe@kernel.dk>
> > Cc: Andy Lutomirski <luto@kernel.org>
> > Cc: Vegard Nossum <vegard.nossum@oracle.com>
> > Cc: Dmitry Vyukov <dvyukov@google.com>
> > Cc: Christoph Hellwig <hch@lst.de>
> > Cc: linux-mm@kvack.org
> > ---
> >
> > Change-Id: Id2f2babaf662ac44675c4f2790f4a80ddc328fa7
> > ---
> >  block/blk.h | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/block/blk.h b/block/blk.h
> > index 47fba9362e60..9ee271a22423 100644
> > --- a/block/blk.h
> > +++ b/block/blk.h
> > @@ -78,6 +78,13 @@ static inline bool biovec_phys_mergeable(struct request_queue *q,
> >         phys_addr_t addr1 = page_to_phys(vec1->bv_page) + vec1->bv_offset;
> >         phys_addr_t addr2 = page_to_phys(vec2->bv_page) + vec2->bv_offset;
> >
> > +#ifdef CONFIG_KMSAN
>
> Prefer 'if (IS_ENABLED(CONFIG_KMSAN))'.
WBD in v4.
> Thanks,
> -- Marco
diff mbox series

Patch

diff --git a/block/blk.h b/block/blk.h
index 47fba9362e60..9ee271a22423 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -78,6 +78,13 @@  static inline bool biovec_phys_mergeable(struct request_queue *q,
 	phys_addr_t addr1 = page_to_phys(vec1->bv_page) + vec1->bv_offset;
 	phys_addr_t addr2 = page_to_phys(vec2->bv_page) + vec2->bv_offset;
 
+#ifdef CONFIG_KMSAN
+	/*
+	 * Merging consequent physical pages may not work correctly under KMSAN
+	 * if their metadata pages aren't consequent. Just disable merging.
+	 */
+	return false;
+#endif
 	if (addr1 + vec1->bv_len != addr2)
 		return false;
 	if (xen_domain() && !xen_biovec_phys_mergeable(vec1, vec2->bv_page))