From patchwork Thu Apr 29 12:25:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 12231161 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=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 DED3BC43461 for ; Thu, 29 Apr 2021 12:27:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8F596141E for ; Thu, 29 Apr 2021 12:27:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234317AbhD2M2R (ORCPT ); Thu, 29 Apr 2021 08:28:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57318 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230148AbhD2M2R (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 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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;