From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11F15C432C0 for ; Mon, 25 Nov 2019 17:03:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B9BBB207FD for ; Mon, 25 Nov 2019 17:03:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YWFgW2Mg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B9BBB207FD Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4F48F6B059D; Mon, 25 Nov 2019 12:03:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 47D1A6B05A0; Mon, 25 Nov 2019 12:03:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31F236B05DD; Mon, 25 Nov 2019 12:03:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id 14E4F6B059D for ; Mon, 25 Nov 2019 12:03:38 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 8DCFE9436 for ; Mon, 25 Nov 2019 17:03:37 +0000 (UTC) X-FDA: 76195421274.11.walk04_3c8c657193c19 X-HE-Tag: walk04_3c8c657193c19 X-Filterd-Recvd-Size: 7773 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Mon, 25 Nov 2019 17:03:35 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id b11so57224wmj.4 for ; Mon, 25 Nov 2019 09:03:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=zgs24zlATOZjxvqFre/5dpE8dgJQKO4B4cLBiPFQtVw=; b=YWFgW2MgDOgDuNHND+T2C4yo5D7GxPkQase+tvLKrqf2wmTyMmYGGBda/zHG9t9s6v ZNKY/abhDQSC8AdBJBvxg0UzcYV31SNCrLnQZ/5s3szCGRdRXdQRcGqvIQZva9E8Q4uC MGfN8mv/mmQTm/LdDkHr0zNU4mxk2YH2X9yidUi/KBVFBbJh8VmeEmgYBxHlxOTZT9EV pVAFIMHfd8UIKuDcRosY3eMXhgUm2pbKD7pPlWCbOVmbGXyOP1cgRN5GRyGLgzoJO57h sCU0wYcscz41FgobDFNtwJl0RH2Tg3Nbe6PCd3T6l9mCx9CQRfeQv+jGMXYwN9nyWO/C PKIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=zgs24zlATOZjxvqFre/5dpE8dgJQKO4B4cLBiPFQtVw=; b=nVgtsKgfEf6eJkbC7BCV09w47EBWTe6JCRvO/ZDxyeddaC7Y1n0SGBakebKPQvOg7S jlW+/ijt4u7QNGQTka/s+nRBZuP7lyrBqyUJwmDr5wxeIdwakySugCBXT41SDqsLqXjc znpJZwPJoWnteYSCNM6863HcxatWbovY0C0IZSE+ccF9rQGTB71BuM2jIG1hWz6avhVv st97nl+KXwpgiuSO6L3b/ihaN9C7PsHIr66mXOY79hywZh7Ki1CmP1juzsc3RGfDgwzN GHk0aTWMQ9Mj9zyhupz88v6IrVU0MpKxpxvtAjlPelGBQagR0QbQHly0j53h8BDwjH16 UOXg== X-Gm-Message-State: APjAAAWhTgCCQZbdQHHsGgn0vaHmazy0VklG/X7BKZrf3irSQQkfpz/w X96XYI1HmoF3y2ZXAyMmWH0cjZSc1yNF393F4knR/g== X-Google-Smtp-Source: APXvYqytpba6D1+i/WZOnW2oRRQhjYjDaIWWKLX8GGlRzZdFNumQlCKwRYmqmH/AWMdgg4KCTVDuGAEFb8gpTq4a1u0= X-Received: by 2002:a05:600c:1:: with SMTP id g1mr22982704wmc.131.1574701414293; Mon, 25 Nov 2019 09:03:34 -0800 (PST) MIME-Version: 1.0 References: <20191122112621.204798-1-glider@google.com> <20191122112621.204798-36-glider@google.com> <3265ac30-4df5-70a9-5634-ea00253d0946@arm.com> In-Reply-To: <3265ac30-4df5-70a9-5634-ea00253d0946@arm.com> From: Alexander Potapenko Date: Mon, 25 Nov 2019 18:03:05 +0100 Message-ID: Subject: Re: [PATCH RFC v3 35/36] kmsan: ext4: skip block merging logic in ext4_mpage_readpages for KMSAN To: Robin Murphy Cc: "Theodore Ts'o" , Andreas Dilger , Vegard Nossum , Dmitry Vyukov , Linux Memory Management List , Al Viro , Andrew Morton , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , hch@infradead.org, Christoph Hellwig , darrick.wong@oracle.com, David Miller , Dmitry Torokhov , Eric Biggers , Eric Dumazet , Eric Van Hensbergen , Greg Kroah-Hartman , Harry Wentland , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , jasowang@redhat.com, Jens Axboe , Marek Szyprowski , Marco Elver , Mark Rutland , "Martin K . Petersen" , Martin Schwidefsky , Matthew Wilcox , "Michael S. Tsirkin" , Michal Simek , Petr Mladek , Qian Cai , Randy Dunlap , Sergey Senozhatsky , Steven Rostedt , Takashi Iwai , Thomas Gleixner , Vasily Gorbik , Wolfram Sang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Nov 25, 2019 at 5:05 PM Robin Murphy wrote: > > On 22/11/2019 11:26 am, glider@google.com wrote: > > KMSAN doesn't allow treating adjacent memory pages as such, if they wer= e > > allocated by different alloc_pages() calls. > > ext4_mpage_readpages() however does so: adjacent pages end up being pas= sed > > together to dma_direct_map_sg(). > > Urgh, there are definitely more places where physically-contiguous pages > are coalesced into single scatterlist entries - see > sg_alloc_table_from_pages() for instance. I wouldn't be surprised if > there are further open-coded versions hiding out in various other > drivers/subsystems too. Unless I've misunderstood, this seems like quite > an invasive limitation :( You're right. Other places haven't fired off so far, so I was just unaware of them, but I'm anticipating more. There are two possible solutions to that problem: 1. Allocate shadow and origin pages at fixed offset from the kernel page. This is what we already do for vmalloc, but not for page_alloc(), as it turned out to be quite hard. Ideas on how to implement this approach are still welcome, because it'll simplify the rest of the KMSAN runtime a lot. 2. Make all accesses touching non-contiguous pages access dummy shadow pages instead, so that such accesses don't produce any uninitialized values. This is quite controversial, as it may prevent true positives from being reported. > Robin. > > > To prevent this, jump directly to the buffer_head-based read function i= n > > KMSAN builds. > > > > Signed-off-by: Alexander Potapenko > > Cc: "Theodore Ts'o" > > Cc: Andreas Dilger > > Cc: Vegard Nossum > > Cc: Dmitry Vyukov > > Cc: linux-mm@kvack.org > > --- > > > > Change-Id: I54ae8af536626a988e6398ff18a06c179b0ce034 > > --- > > fs/ext4/readpage.c | 11 +++++++++++ > > 1 file changed, 11 insertions(+) > > > > diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c > > index a30b203fa461..a3bb9e3ce5de 100644 > > --- a/fs/ext4/readpage.c > > +++ b/fs/ext4/readpage.c > > @@ -252,6 +252,17 @@ int ext4_mpage_readpages(struct address_space *map= ping, > > if (page_has_buffers(page)) > > goto confused; > > > > +#if defined(CONFIG_KMSAN) > > + /* > > + * The following code may treat adjacent pages allocated > > + * separately as a bigger contiguous allocation. > > + * KMSAN doesn't allow this, as the corresponding metadat= a > > + * pages may be separated. > > + * Skip this complex logic for KMSAN builds. > > + */ > > + goto confused; > > +#endif > > + > > block_in_file =3D (sector_t)page->index << (PAGE_SHIFT - = blkbits); > > last_block =3D block_in_file + nr_pages * blocks_per_page= ; > > last_block_in_file =3D (ext4_readpage_limit(inode) + > > --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg