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=-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 DF3E3C433B4 for ; Thu, 29 Apr 2021 12:27:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E277613F1 for ; Thu, 29 Apr 2021 12:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236053AbhD2M2V (ORCPT ); Thu, 29 Apr 2021 08:28:21 -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 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=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 5BB94C43462 for ; Thu, 29 Apr 2021 12:27:34 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDD2B61457 for ; Thu, 29 Apr 2021 12:27:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDD2B61457 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 53AE24199D; Thu, 29 Apr 2021 12:27:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C0K3Q9y9JDg4; Thu, 29 Apr 2021 12:27:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTP id 92C2141942; Thu, 29 Apr 2021 12:27:31 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7B17EC000D; Thu, 29 Apr 2021 12:27:31 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id BE489C0001 for ; Thu, 29 Apr 2021 12:27:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id ABB3F41942 for ; Thu, 29 Apr 2021 12:27:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id anBfhFcz6IQB for ; Thu, 29 Apr 2021 12:27:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id CF2AB4194C for ; Thu, 29 Apr 2021 12:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619699248; 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=atzWh2EhlbxeMnDtrXOZlAGyrrQp0IH2zOCnyg6vAviRtoeF8AhXyjN2Ru40OCmB7Top8F /SE2x8DyhmUUA50efYpeADr2kZ47mkXRbkt3SMAvkv9wNnrm8OIdedLnRspKGxmde92NwP uLeL2ofdOl0yFiortdI5b7bmMnCQukg= 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 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 Cc: Aili Yao , Michal Hocko , "Michael S. Tsirkin" , linux-hyperv@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, Wei Liu , Alex Shi , Stephen Hemminger , "Matthew Wilcox \(Oracle\)" , Steven Price , Alexey Dobriyan , Jiri Bohac , Haiyang Zhang , Oscar Salvador , Naoya Horiguchi , linux-fsdevel@vger.kernel.org, Andrew Morton , Roman Gushchin , Mike Rapoport , Mike Kravetz X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" 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 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization