Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp682692pxj; Fri, 14 May 2021 13:01:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3QkeCtBAL2jUkXjTIKxp1HVRFpNbmfSwae8XFMhyB5AM5cTEsk4KSN+kjO+2QhmKyjKqy X-Received: by 2002:a05:6402:270b:: with SMTP id y11mr57647711edd.332.1621022464843; Fri, 14 May 2021 13:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621022464; cv=none; d=google.com; s=arc-20160816; b=Ve4+z7xLa2C99xUfzaJN++FB1AIbqy2WONOXjfT/S/X9xWpzQqmRL2zHpG1o0kNNuN RIJhj2z0zFHjc08QqvqVwMR0EtGWmhBR3d0iaIQn8A021V5MQvEQpLEUnYsxAFbpPOvm dYpC8/nt+BfyFru052yUsnvWeUntOFa9QnqSEG76/FUPqC8j423Rkz4KXLKM85VlCmMI 2e92kUzcK4dMUopGjsWNDsCPpRxv/mhbYTjhQhfUaMxPeyPXl9LtOUmxMNBiDH4GiRZY 2c23S/se/bqZye6u4XlQbtHTOfkHOrnWRUj/a2dZ0Xam4Mwl36aUp7uosilezJWLJJvL 1Dpw== 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=ulvwg2ZaPIw7oToA7TTsrb85Bhlj+6R6HqazJ1k8M40=; b=z5W/86/7sPxzBkdKrJxEODVM2bEgKdNOW5JV9to4c4ZsTr393+d2ulr4XQ6uOOY2VF 5jnPoO85yRukqJVhMcpGh6CrILDqJRuoLhk1UYwnKtqIC0ucxrc+AkrkR1f2z4hkdE9a SxNbLWaGEYL06fWgzo8J08tskZNlNHFQISRYsI7Xi8lqNPlsaS1PHhivApTpn9PMCVxy Kv4fp2hCLRnI4qrNBn4TaKdOcLyc001tubQo5TOwMW6MckBGpmbAtdWlBJK1AZtL/dWQ t62HbPvGXyEn8ZcPZl9XKv+11ik5+x3l3IXJZDWNtIRVOkiKouT8qoQtD1jTMi3d+uey LD+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iupD3UYX; 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 f6si7139421ejt.379.2021.05.14.13.00.41; Fri, 14 May 2021 13:01:04 -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=iupD3UYX; 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 S235150AbhENRZU (ORCPT + 99 others); Fri, 14 May 2021 13:25:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52730 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235157AbhENRZT (ORCPT ); Fri, 14 May 2021 13:25:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621013047; 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=ulvwg2ZaPIw7oToA7TTsrb85Bhlj+6R6HqazJ1k8M40=; b=iupD3UYXfvhVRHuMJ+xXQ0wfljY4JtsRCHz7Xf92Sh+eFFP03dfcoR9DKUbGDTh8lAR9pU 2+pWt3wmhtfpbMToDdubBR3GVmdqJK9jaFiDdga1EywU7Pmivm6lamcYmHDPsj/kI4Pvn1 lJtD3ow2x8UEAjxL2L5Eu9lckdRCLCc= 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-50-OcdPAodxOoS1AkW-8Jin5A-1; Fri, 14 May 2021 13:24:06 -0400 X-MC-Unique: OcdPAodxOoS1AkW-8Jin5A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D179B8015DB; Fri, 14 May 2021 17:24:03 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-113.ams2.redhat.com [10.36.114.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id F07801971B; Fri, 14 May 2021 17:23:54 +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 v2 6/6] fs/proc/kcore: use page_offline_(freeze|thaw) Date: Fri, 14 May 2021 19:22:47 +0200 Message-Id: <20210514172247.176750-7-david@redhat.com> In-Reply-To: <20210514172247.176750-1-david@redhat.com> References: <20210514172247.176750-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's properly synchronize with drivers that set PageOffline(). Unfreeze/thaw every now and then, so drivers that want to set PageOffline() can make progress. Signed-off-by: David Hildenbrand --- fs/proc/kcore.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index 92ff1e4436cb..982e694aae77 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -313,6 +313,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) { char *buf = file->private_data; size_t phdrs_offset, notes_offset, data_offset; + size_t page_offline_frozen = 1; size_t phdrs_len, notes_len; struct kcore_list *m; size_t tsz; @@ -322,6 +323,11 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) int ret = 0; down_read(&kclist_lock); + /* + * Don't race against drivers that set PageOffline() and expect no + * further page access. + */ + page_offline_freeze(); get_kcore_size(&nphdr, &phdrs_len, ¬es_len, &data_offset); phdrs_offset = sizeof(struct elfhdr); @@ -480,6 +486,12 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) } } + if (page_offline_frozen++ % MAX_ORDER_NR_PAGES == 0) { + page_offline_thaw(); + cond_resched(); + page_offline_freeze(); + } + if (&m->list == &kclist_head) { if (clear_user(buffer, tsz)) { ret = -EFAULT; @@ -565,6 +577,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) } out: + page_offline_thaw(); up_read(&kclist_lock); if (ret) return ret; -- 2.31.1