Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1351770pxy; Thu, 29 Apr 2021 05:26:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfeWYWdRok/sZszjL7mKzE++4r5tCz3qFiEOo3QhvE9ovbnavEYG3Dy6dDl1fFd57sk3hZ X-Received: by 2002:a17:90a:885:: with SMTP id v5mr1437559pjc.67.1619699198125; Thu, 29 Apr 2021 05:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619699198; cv=none; d=google.com; s=arc-20160816; b=N96ULLLJW2Ak6UzJQ6WzAyhs7Ro5bca8+gITnT0LMBOsmsWaGk6kJuufwIoiLB3zUj kg6+od/MRgTyHVW5rR8g0tkUZ96jq6zhR3mx24J8mjpxB2C7OXffFIMvNXSHF+Rch7by S/SP13ICM3ljCq4DuNkxQeq4meOlby7n0MKMSI8sMRxgs5Z7WbG3PZykgkMUa12QAqSv Ty1B3/06rcyvN9SEVvkyH8YaaNaj02y1ZuGb7rhupoQ1BgTo0xUWbVqm6tUXstBH0WcJ 5u1dIuPZEigssMlWq30CsrxWXcc78+JqjbFHxtaD5ERwA9euu8QWVmS4W0uQt6axquJj GJHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/OdSxwojrLS5sAnanUpiMcEtuJGNRcvvNrKB0SCQWUs=; b=DALv1pdwsk8pCsacNxh1EIuKO1OF9Hbdc36t25qJPuC2o5t5kex1EiQWqyhUsvFKfb IxfbLmyVRAoLhb3JTnqkS31xeaEOcd0fUZs1HGW6UJE8Zl0nTb1DkfhPPg5r+qQNyyKd WPqiiRKthNUXVuDulv2Jp731E0BDW7M0J5dMWDSv1tO9g/ld+7fc1ShhjznlmaLM0ZsK rnwhBwEikceirVCEM5sqt3ZhsnQwKShQfq1isVYr7XKqgFCQNmUqJe1sp6OPWiYmVxQ8 x+G0EJsB0brqNU8Tc/MN0JjL8MswU3UAhdFoAr9HqwufMumhk1Od3TJpu7RWH4u5U9Zs O4PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X+nevQWr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si2677077pgp.482.2021.04.29.05.26.25; Thu, 29 Apr 2021 05:26:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X+nevQWr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233731AbhD2M0U (ORCPT + 99 others); Thu, 29 Apr 2021 08:26:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47228 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230148AbhD2M0T (ORCPT ); Thu, 29 Apr 2021 08:26:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619699132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/OdSxwojrLS5sAnanUpiMcEtuJGNRcvvNrKB0SCQWUs=; b=X+nevQWrFZ4xyT6tADC43QWeA+hB9osIuJay3BciFL39koUVkiwCh3Z4AYaGa4UwNnFwg/ Hsa999ecwtuZpID/i0ee4SOkjdl9NHWgWTdyL4l5ZYLYRhNzrUD4OGqAVqJTZcICg1Lf1O y274RpLhHhqy/btzOJh5uqX+KstV/4U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-572-1idR3NXgNvivsbYndrR7Yg-1; Thu, 29 Apr 2021 08:25:29 -0400 X-MC-Unique: 1idR3NXgNvivsbYndrR7Yg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75AD4107ACF3; Thu, 29 Apr 2021 12:25:26 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-50.ams2.redhat.com [10.36.114.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 330B45C1BB; Thu, 29 Apr 2021 12:25:20 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , "Michael S. Tsirkin" , Jason Wang , Alexey Dobriyan , Mike Rapoport , "Matthew Wilcox (Oracle)" , Oscar Salvador , Michal Hocko , Roman Gushchin , Alex Shi , Steven Price , Mike Kravetz , Aili Yao , Jiri Bohac , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Naoya Horiguchi , linux-hyperv@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1 0/7] fs/proc/kcore: don't read offline sections, logically offline pages and hwpoisoned pages Date: Thu, 29 Apr 2021 14:25:12 +0200 Message-Id: <20210429122519.15183-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is (obviously) for v5.13++; no need to rush with review, but I decided to send it around right away. Looking for places where the kernel might unconditionally read PageOffline() pages, I stumbled over /proc/kcore; turns out /proc/kcore needs some more love to not touch some other pages we really don't want to read -- i.e., hwpoisoned. Examples for PageOffline() pages are pages inflated in a balloon, memory unplugged via virtio-mem, and partially-present sections in memory added by the Hyper-V balloon. When reading pages inflated in a balloon, we essentially produce unnecessary load in the hypervisor; holes in partially present sections in case of Hyper-V are not accessible and already were a problem for /proc/vmcore, fixed in makedumpfile by detecting PageOffline() pages. In the future, virtio-mem might disallow reading unplugged memory -- marked as PageOffline() -- in some environments, resulting in undefined behavior when accessed; therefore, I'm trying to identify and rework all these (corner) cases. With this series, there is really only access via /dev/mem, /proc/vmcore and kdb left after I ripped out /dev/kmem. kdb is an advanced corner-case use case -- we won't care for now if someone explicitly tries to do nasty things by reading from/writing to physical addresses we better not touch. /dev/mem is a use case we won't support for virtio-mem, at least for now, so we'll simply disallow mapping any virtio-mem memory via /dev/mem next. /proc/vmcore is really only a problem when dumping the old kernel via something that's not makedumpfile (read: basically never), however, we'll try sanitizing that as well in the second kernel in the future. Tested via kcore_dump: https://github.com/schlafwandler/kcore_dump Cc: Andrew Morton Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Alexey Dobriyan Cc: Mike Rapoport Cc: "Matthew Wilcox (Oracle)" Cc: Oscar Salvador Cc: Michal Hocko Cc: Roman Gushchin Cc: Alex Shi Cc: Steven Price Cc: Mike Kravetz Cc: Aili Yao Cc: Jiri Bohac Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Cc: Wei Liu Cc: Naoya Horiguchi Cc: linux-hyperv@vger.kernel.org Cc: virtualization@lists.linux-foundation.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org David Hildenbrand (7): fs/proc/kcore: drop KCORE_REMAP and KCORE_OTHER fs/proc/kcore: pfn_is_ram check only applies to KCORE_RAM mm: rename and move page_is_poisoned() fs/proc/kcore: don't read offline sections, logically offline pages and hwpoisoned pages mm: introduce page_offline_(begin|end|freeze|unfreeze) to synchronize setting PageOffline() virtio-mem: use page_offline_(start|end) when setting PageOffline() fs/proc/kcore: use page_offline_(freeze|unfreeze) drivers/virtio/virtio_mem.c | 2 ++ fs/proc/kcore.c | 69 ++++++++++++++++++++++++++++++------- include/linux/kcore.h | 3 -- include/linux/page-flags.h | 12 +++++++ mm/gup.c | 6 +++- mm/internal.h | 20 ----------- mm/util.c | 40 +++++++++++++++++++++ 7 files changed, 115 insertions(+), 37 deletions(-) base-commit: 9f4ad9e425a1d3b6a34617b8ea226d56a119a717 -- 2.30.2