Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1703467pxy; Sat, 1 May 2021 23:36:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuY67kla+X+/3SRi34OPejsY2YLI3hGtoWxYCJFmmuU9nXCTx7Iuyhf48An7MBO/sL1NBz X-Received: by 2002:a50:82e2:: with SMTP id 89mr14119652edg.0.1619937399803; Sat, 01 May 2021 23:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619937399; cv=none; d=google.com; s=arc-20160816; b=G06D3+sxu4I0cLyj17npWj8chuCx5a5O6cSobhHiuiecTYasRJt39vWeUshiXpz8Z8 laCpL11SZd4aO5hgRxLqUcJA0brlv5QHqGrafjPCMYuM5wqlYJeG47wq5mfRF2faodg+ GV3b+fZnxcsq+ozJ6gbRKynO4q//cPPwbis8LNaP8oYfu/TbQchfH1sf3dcVkMassBis rrl3YRx8Ecvod6rOuw0QycEudGt/AkqprtE/OUdf7Pihx5v4O8yR6YeHQZYdXl5e8LL+ iiR1hp+pSMK1EW/P8+sCIZZ3ruioX7xeuaN/MYjtskZckoYmUJ+r6VpoazJGajRK61/j hf/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bVP/hF2e+zShVNnL3bBCfCyBe1KpJuKuF9HM/AQskc0=; b=pg1DoXFzm5P+SrQaFLce0kt70RT/RY7HhaCM/s+LIO7LwzLgLnZyqvIWG91b9Q1Lwl 7CSky6v8mWWYj4KM5Mpth41xFOEv63LKo3Pgva6HBqM4pEGPzRWVSWcaIx/dHpxJqqIi 6XNI+7fnuoyvH59Wy8Ht9ju848IsyoddvucU7HiBYQp3J/3DnJ865z9ZmOwtC5DzL4v2 hUajYBauCgucC7OodCpa8XIZEUNu0/odiuj1Hq8eVYbNS3rjkyWvNikZYcnW8wEBAdE4 a+bQVSv6R4gDnw9vYrNf+fTlH6/oor7/q67lLKdGyz1TnQ6Hgk1bHq1xcU6iXXAFaZvd sOtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s8Xy8pvy; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h15si6236402ejt.69.2021.05.01.23.36.16; Sat, 01 May 2021 23:36:39 -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=@kernel.org header.s=k20201202 header.b=s8Xy8pvy; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbhEBGfO (ORCPT + 99 others); Sun, 2 May 2021 02:35:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:32784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbhEBGfO (ORCPT ); Sun, 2 May 2021 02:35:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6D49E61408; Sun, 2 May 2021 06:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619937263; bh=cByN/RcKM8xbB6KsfcBCkuoO/9VHkzKGkqsC7qrvyPM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s8Xy8pvyPi42yMVDvXg8Iv0BIywloo7o7xzc9wKr/4UrRbkY0CKZvRozbvzXENCa4 UUZaptLpgkRVVl3eR/YC8PbVKT6jw+SaSxYKecOHesP02+UCu+CWqXDCDmDfeK5Epg TfWYkhVsqTcmoiSZqgqK4mCwfSmt5qEU0zNYzSrjKqR4WPmb2Uek8LX8JDwShqSbgd Nhc5IGoeN86yH1RMJLQJtCfYHjdLHre9EZDOJ4QxJqjrVDKP400NkwXCMi9Q6Pvf4k 75xNE+1dK5Z9hV3/Yl+I8kGsk724zbVqOKaVmkB0ixJBwLZhxQFMsdk1UI8ZsRmifT tlR+6/+IGZspg== Date: Sun, 2 May 2021 09:34:11 +0300 From: Mike Rapoport To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, Andrew Morton , "Michael S. Tsirkin" , Jason Wang , Alexey Dobriyan , "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: Re: [PATCH v1 7/7] fs/proc/kcore: use page_offline_(freeze|unfreeze) Message-ID: References: <20210429122519.15183-1-david@redhat.com> <20210429122519.15183-8-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210429122519.15183-8-david@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 29, 2021 at 02:25:19PM +0200, David Hildenbrand wrote: > 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); Can't this race with page offlining for the first time we get here? > + /* > + * 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 we need to freeze before doing pfn_to_online_page()? > /* > * 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 > -- Sincerely yours, Mike.