Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1353867pxy; Thu, 29 Apr 2021 05:29:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0e7vbf5kUBlcuQHSFrhZk9MTuKhaAoQfkMLThr/0yJEY8C4Ov+cbOZUG8CahO4qW4mN9l X-Received: by 2002:a17:90b:3852:: with SMTP id nl18mr9127184pjb.119.1619699377471; Thu, 29 Apr 2021 05:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619699377; cv=none; d=google.com; s=arc-20160816; b=bJQjfczz0TgSJcfZHgciqqHsczBMYDslHxj0l2vg37aape2E+wFs+FmMtnNc93bTy9 aq+Az+dWvehxiwqAdDESSlPUzRyHEzwYCYZJfMgs3rGSroVX7F8abbF2bsXVJypprlAF S1bdPjJM8FCyCOgI7Fzk6olhffP/Iu22AqrHHmSeb14s+VTM31u6wn2te9cUprXCqzOK C9/3eesegF4nsRZXsLE+KtY0h5fhQ9ZkhTcDXghoGojUEbpqeNIFM1cxd8GQWf37bZqe ZIVkrxmnrPZDlpbxp1ozh6grPjhEzvrqXB/AgdRKWOgKqBgHFFstFfv5PF14n86qndMo 4dkQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8j9mBor07Cs8M7oV014u0wi5MvoFT2r3E+Kj0uohzbw=; b=z7OZx33KfXBfT2a5McEOHyuGLsNNJr15VGtx9YH3OADRmgVfojBpXtKiGcue2jJlAJ yhaDkFfAsOdridLe5KA+HUKLWfkcAjwbFaX9kVyk2y4P6nOl+c3UPdeA83O/dOxa/j7F P2rFa/NlegWI9iQFQSf0ET+5ZwE4SaRbnAoyfcXfN7g6oWjxtRW7bKgX4KvE187CCvRB 3pYYMhexLqWrWy8hqDE70uFbCS8Uuc9A1VPN/F4HfMyFN8F0qgZFnEQE9+hPOJnPv/p1 XUxdGbBsTo6prB8MJpq+jbrnDhd9RLxJs8lyd2CKga+5SfeCzzBdaAVj1IHBCJvaef2h /R+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Q2ueY/bf"; 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 p27si3363309pgc.27.2021.04.29.05.29.24; Thu, 29 Apr 2021 05:29:37 -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="Q2ueY/bf"; 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 S231708AbhD2M2S (ORCPT + 99 others); Thu, 29 Apr 2021 08:28:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32124 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231921AbhD2M2R (ORCPT ); Thu, 29 Apr 2021 08:28:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619699250; 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: in-reply-to:in-reply-to:references:references; bh=8j9mBor07Cs8M7oV014u0wi5MvoFT2r3E+Kj0uohzbw=; b=Q2ueY/bfihQWmJVU0cBapVR4RsBG7nHK9D0GbgdWNkPFnsWVzglmQpyvCIqsg8RPj9pC3B jFmoYxNjRIZG73BktbxPRvks+JVYeWGW0wHZ+tpFSIHo6UuamcCnL92t/6R9rRx5z0o44U YY/bgFDkagGsocpfcnnprkgHWeiar7g= 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-412-mextiE51O4S-F0gnYD4sAg-1; Thu, 29 Apr 2021 08:27:26 -0400 X-MC-Unique: mextiE51O4S-F0gnYD4sAg-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 097B8108BD0C; Thu, 29 Apr 2021 12:27:22 +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 C62B318811; Thu, 29 Apr 2021 12:26:43 +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 7/7] fs/proc/kcore: use page_offline_(freeze|unfreeze) Date: Thu, 29 Apr 2021 14:25:19 +0200 Message-Id: <20210429122519.15183-8-david@redhat.com> In-Reply-To: <20210429122519.15183-1-david@redhat.com> References: <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 Let's properly synchronize with drivers that set PageOffline(). Unfreeze every now and then, so drivers that want to set PageOffline() can make progress. Signed-off-by: David Hildenbrand --- fs/proc/kcore.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index 92ff1e4436cb..3d7531f47389 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -311,6 +311,7 @@ static void append_kcore_note(char *notes, size_t *i, const char *name, static ssize_t read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) { + size_t page_offline_frozen = 0; char *buf = file->private_data; size_t phdrs_offset, notes_offset, data_offset; size_t phdrs_len, notes_len; @@ -509,6 +510,18 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) pfn = __pa(start) >> PAGE_SHIFT; page = pfn_to_online_page(pfn); + /* + * Don't race against drivers that set PageOffline() + * and expect no further page access. + */ + if (page_offline_frozen == MAX_ORDER_NR_PAGES) { + page_offline_unfreeze(); + page_offline_frozen = 0; + cond_resched(); + } + if (!page_offline_frozen++) + page_offline_freeze(); + /* * Don't read offline sections, logically offline pages * (e.g., inflated in a balloon), hwpoisoned pages, @@ -565,6 +578,8 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) } out: + if (page_offline_frozen) + page_offline_unfreeze(); up_read(&kclist_lock); if (ret) return ret; -- 2.30.2