Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1481052imm; Fri, 29 Jun 2018 20:21:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI8md4Qn9cJAwi8CQQlDZQaPJlbg5/5KUDNS9KAyPkYjKSIPGsPyrVwAMWo7jRwM01v+fSm X-Received: by 2002:a17:902:925:: with SMTP id 34-v6mr17540006plm.103.1530328904813; Fri, 29 Jun 2018 20:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530328904; cv=none; d=google.com; s=arc-20160816; b=spLVg3IAC2SHDvKkkRiouwG8NRjpaBSaRFUPwJ6Zu/KKapKqlNZLRHq9pe/LRNCcJo aBPRP2PCR+KIA49ZnLeCD2XJ+JqBQe4e1T3BF0JkGRjjoKZwjf4Q0lxzzKFs5zGgmed/ Fqkc607bDOtM62wCqFgmsyoJcZn9di/yqZ4V26JdvOtW6KcaoCj2JeQKIye1RzVRE7S3 exfqvisbjJ2e+BIc+MIR4yc/sSKWVSEoSBzkP41blMGF1PbOkMZln88YhTwEtzEijFG/ r+pDYhOKy8VBFjpUBKH6bVkcHQ7pQX+jkADyFf7mkDo7WfGUDQPUW23ydNRxB3wndLrC bVpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=21VYb3A17E0UHzSWXuxJrJ5W/2DJqMdGwuMllqSk5sU=; b=Q4jAlQJLcnzrLRqKx+puDIbM9UXzDV4HpzjnphMu23mO+cDkulhEhEg/1uUZuvJFk1 N0BPbZ4GwrjUXtnQppg1gdGfdzDrgLSN9oYDhc9E8li6HKBS9RSK5OFwcn1lbJ0VW4yF OCqSB6WCZYxdz4OyxZl3guLenh/v6zDkSPlLwFdXeuUL4MWmrG5FufMF5ubSttbCwyDK dJnqTxVjJN/iXQxmEAUckkNepyZwX+BNcpxjqDmHADdjfgt6h42/rECoIgKg4achdjks izH0hiGLeUQivQAxALEwa9tLFoxAP54bt4GaNW6cr0u9MmqX7tv/uPP872TFh12BfLC5 yjBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=07TY8jpE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12-v6si10878668pfa.113.2018.06.29.20.21.29; Fri, 29 Jun 2018 20:21:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=07TY8jpE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936045AbeF3DTJ (ORCPT + 99 others); Fri, 29 Jun 2018 23:19:09 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:39896 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932822AbeF3DTI (ORCPT ); Fri, 29 Jun 2018 23:19:08 -0400 Received: by mail-oi0-f66.google.com with SMTP id d189-v6so1452055oib.6 for ; Fri, 29 Jun 2018 20:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=21VYb3A17E0UHzSWXuxJrJ5W/2DJqMdGwuMllqSk5sU=; b=07TY8jpEjmjUibfWADoFyI1voRzGwNICH3o+trj1WlKPMW8IDpQvH3rPlo6I4evj2b OioDtVmFZ9gxBmQLen+nQQsjkywWbPTumNfNkGpDp//a7vqtDVEaxAEYzYmjXVMlzo8G cdPBhaDhe3xQpo0Uar1xUS9IsH00lKHOT6A3vfcw67LBWMfu+jcL1dlN0qpA0gyzgtrD 0/Ih48z3BFrOmiFgnVecagjvefwdlPv+3Jw3vpoG0sUqyabvyFqW8E4jcjeaUF/70Bqf FXCEwr20Rt5hwLTvdwTQHdgwATqISv83jPmfLjivZr6iOo4P8avkGWUw/wvF669ggTby rjUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=21VYb3A17E0UHzSWXuxJrJ5W/2DJqMdGwuMllqSk5sU=; b=cZNXRDzh/4N++hlFrzqkEhLXrXkb2e+71jySQ/ikdDZfxHYdcPOTjbZpuN3EQNkDB1 dSQoYaxRy1UPAuRmf1VI5IvhH2UXKvjuaAVmhd+oJXyO/s/4T9J3NfLh4eO/wJ/AdGtW tgWO0/fo5vrXVSRGtgoGTBuHSHQ5PZXv+sr5HsO0p5m/G3wvQnhVsmw4hU5rJ4nWHPRq E70B6aF5WpmbAcw4VR0n+3ihTZbLlWrD9/dVmvMkVY+xHDo3I798awAfOgm4FZ10W8Fc VOtmQA1jGUWLyb7OUxRxACSqow3hkyg12np8oYVoksNCl3KUsTaN22g2jg5XXAtM15PK Zlnw== X-Gm-Message-State: APt69E1dU/Qaw6lq5ZAG6ZFUL9rAdg9GtDxdPo8TQqcyiOxVNDE//AA5 uID2WqsZlQDg2w6bZNBr3gZqbHzRldzBaZQEdAMn/w== X-Received: by 2002:aca:745:: with SMTP id 66-v6mr9161348oih.295.1530328747981; Fri, 29 Jun 2018 20:19:07 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:3495:0:0:0:0:0 with HTTP; Fri, 29 Jun 2018 20:19:07 -0700 (PDT) In-Reply-To: <20180629193300.0ae0f25880a800bd27952b15@linux-foundation.org> References: <20180625170259.30393-1-aryabinin@virtuozzo.com> <20180629164932.740-1-aryabinin@virtuozzo.com> <20180629193300.0ae0f25880a800bd27952b15@linux-foundation.org> From: Dan Williams Date: Fri, 29 Jun 2018 20:19:07 -0700 Message-ID: Subject: Re: [PATCH v2] kernel/memremap, kasan: Make ZONE_DEVICE with work with KASAN To: Andrew Morton Cc: Andrey Ryabinin , david , kasan-dev@googlegroups.com, Linux Kernel Mailing List , Linux MM , Dmitry Vyukov , Alexander Potapenko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 29, 2018 at 7:33 PM, Andrew Morton wrote: > On Fri, 29 Jun 2018 19:49:32 +0300 Andrey Ryabinin wrote: > >> KASAN learns about hot added memory via the memory hotplug notifier. >> The devm_memremap_pages() intentionally skips calling memory hotplug >> notifiers. > > Why does it do that? devm_memremap_pages() deliberately does only half of memory hotplug. Namely it only adds to the linear map and allocates / initializes 'struct page', but it never onlines the pages, so devm_memremap_pages() generates none of the events that the hotplug notifiers would publish. >> So KASAN doesn't know anything about new memory added >> by devm_memremap_pages(). This causes to crash when KASAN tries to >> access non-existent shadow memory: >> >> BUG: unable to handle kernel paging request at ffffed0078000000 >> RIP: 0010:check_memory_region+0x82/0x1e0 >> Call Trace: >> memcpy+0x1f/0x50 >> pmem_do_bvec+0x163/0x720 >> pmem_make_request+0x305/0xac0 >> generic_make_request+0x54f/0xcf0 >> submit_bio+0x9c/0x370 >> submit_bh_wbc+0x4c7/0x700 >> block_read_full_page+0x5ef/0x870 >> do_read_cache_page+0x2b8/0xb30 >> read_dev_sector+0xbd/0x3f0 >> read_lba.isra.0+0x277/0x670 >> efi_partition+0x41a/0x18f0 >> check_partition+0x30d/0x5e9 >> rescan_partitions+0x18c/0x840 >> __blkdev_get+0x859/0x1060 >> blkdev_get+0x23f/0x810 >> __device_add_disk+0x9c8/0xde0 >> pmem_attach_disk+0x9a8/0xf50 >> nvdimm_bus_probe+0xf3/0x3c0 >> driver_probe_device+0x493/0xbd0 >> bus_for_each_drv+0x118/0x1b0 >> __device_attach+0x1cd/0x2b0 >> bus_probe_device+0x1ac/0x260 >> device_add+0x90d/0x1380 >> nd_async_device_register+0xe/0x50 >> async_run_entry_fn+0xc3/0x5d0 >> process_one_work+0xa0a/0x1810 >> worker_thread+0x87/0xe80 >> kthread+0x2d7/0x390 >> ret_from_fork+0x3a/0x50 >> >> Add kasan_add_zero_shadow()/kasan_remove_zero_shadow() - post mm_init() >> interface to map/unmap kasan_zero_page at requested virtual addresses. >> And use it to add/remove the shadow memory for hotpluged/unpluged >> device memory. >> >> Reported-by: Dave Chinner >> Signed-off-by: Andrey Ryabinin >> Cc: Dan Williams >> Cc: Dmitry Vyukov >> Cc: Alexander Potapenko > > No cc:stable? Which kernel version(s) do you believe need the fix? I think devm_memremap_pages() was incompatible with KASAN from the outset, so I would say: Fixes: 41e94a851304 ("add devm_memremap_pages") > >> include/linux/kasan.h | 13 ++- >> kernel/memremap.c | 10 ++ >> mm/kasan/kasan_init.c | 316 +++++++++++++++++++++++++++++++++++++++++++++++--- > > It's a surprisingly large amount of ode to do something which KASAN > already does for hotplugged memory. How come?