Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1703757pxy; Sat, 1 May 2021 23:37:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJUtCp/ffa6e20dP7Z84FKGDGtkH7FoBCp2u8QsBt8QeYDHV4bsUnWQfytHhHKjbOGASMZ X-Received: by 2002:a17:906:32cb:: with SMTP id k11mr11829314ejk.158.1619937438170; Sat, 01 May 2021 23:37:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619937438; cv=none; d=google.com; s=arc-20160816; b=UheDKUWcNlyq4UESV37QkLBTgdPziyXH+JhkHWLGJdovgbZNwpFy3IdzfTYUe4aTfx iMbwROz/Gzhy94u7IU9Hr0I5lqIOX2ze6nTmLJMAzQEHCL8jDef2H/9oekfoNFEpUYhE O3xSFHbyYNJSovINAfOFJxC0xA8i/MZZozleke/iJya3FFANszhP7++E2YMOgK6W7jYa n8tSPGAOmrZ+mLjO4hzBYnbFeeXOoxq9wORXQgRxHoOqPYxbu6b/Fy6OUyMYfDgYOjOr U7i9tLRrOZGUFhmi2NjwSTF5Ia0Rgh0d++/LQHnNeJksM7lrhpco6/c7xdtCqlxQefAd elwg== 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=Ll/QWRil7MqNQ0gL/uS6xmirbVtJQrsYlU6jonArqsM=; b=eYjt+6yafxnGSj5y5/6LjHLx+yWVru11JFpCyI6ifskpskezLH3ooLktsRJ5nAstJz KZ4pGNRL5mXGLCEez6ST5LWMdAtIb/nYQWLS9f0psg+VIKaN1zMauHGiEYan+bLTK7jw Jtpb3pUqJ21OyDn8f2DRZKSqK2nA+8W7k3c40XmoRlfCvcNONncINEn3Cs0AdG8TbvKt d+5pdssch5nGuLo5VBjOARiqSLW442UPg58IRbDdC+I6jXQPcbM3prv29azjDqYghOBi Douq+hkmWbq7LeyOIz4CvlKL7I09jIyeZlziJduIxNSS5BDwqQ5YEWI21gUuEJr1E9Ln dvyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AL85wToj; 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 b1si8111282ejb.714.2021.05.01.23.36.55; Sat, 01 May 2021 23:37:18 -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=AL85wToj; 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 S231793AbhEBGeO (ORCPT + 99 others); Sun, 2 May 2021 02:34:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:60482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbhEBGeO (ORCPT ); Sun, 2 May 2021 02:34:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 25C6A61408; Sun, 2 May 2021 06:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619937203; bh=xCHXh8bLinDeqYhXWURePtlkQbRyXAxtzpNH6qseAsY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AL85wToj2jGrctsZ0HQQHbsSMt44YWw4Z8REWyA6PNEHF0KvUISqbJC4d3+nPxC9y jbsunE8U4QW5sBdGsAfnnNB6HI2lC5CBXdk6PtPcEEb+G2B8cOK9ukA1ZNKBsqeIjw eEIy5SKRaRFyKkxHLNUykNIPS3XVrQuXbQzlI9tmKyb7Y0XQtB77sog4tikowZqPMF J1J7ZD2hnQNzQgaMVgdc92cya3uwzf/fQmZN0OKRxtylB3n8MXy9wfvAbda08PjxUr 7KnYRKaGqcdN9kHIoBfexZXHidgYuGisApHdpqiHk/NRiPqHIInsENYcU9KgBC/a+q xYb+XUXyasQPw== Date: Sun, 2 May 2021 09:33: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 5/7] mm: introduce page_offline_(begin|end|freeze|unfreeze) to synchronize setting PageOffline() Message-ID: References: <20210429122519.15183-1-david@redhat.com> <20210429122519.15183-6-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210429122519.15183-6-david@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 29, 2021 at 02:25:17PM +0200, David Hildenbrand wrote: > A driver might set a page logically offline -- PageOffline() -- and > turn the page inaccessible in the hypervisor; after that, access to page > content can be fatal. One example is virtio-mem; while unplugged memory > -- marked as PageOffline() can currently be read in the hypervisor, this > will no longer be the case in the future; for example, when having > a virtio-mem device backed by huge pages in the hypervisor. > > Some special PFN walkers -- i.e., /proc/kcore -- read content of random > pages after checking PageOffline(); however, these PFN walkers can race > with drivers that set PageOffline(). > > Let's introduce page_offline_(begin|end|freeze|unfreeze) for Bikeshed: freeze|thaw? > synchronizing. > > page_offline_freeze()/page_offline_unfreeze() allows for a subsystem to > synchronize with such drivers, achieving that a page cannot be set > PageOffline() while frozen. > > page_offline_begin()/page_offline_end() is used by drivers that care about > such races when setting a page PageOffline(). > > For simplicity, use a rwsem for now; neither drivers nor users are > performance sensitive. > > Signed-off-by: David Hildenbrand > --- > include/linux/page-flags.h | 5 +++++ > mm/util.c | 38 ++++++++++++++++++++++++++++++++++++++ > 2 files changed, 43 insertions(+) > > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > index b8c56672a588..e3d00c72f459 100644 > --- a/include/linux/page-flags.h > +++ b/include/linux/page-flags.h > @@ -767,6 +767,11 @@ PAGE_TYPE_OPS(Buddy, buddy) > */ > PAGE_TYPE_OPS(Offline, offline) > > +extern void page_offline_freeze(void); > +extern void page_offline_unfreeze(void); > +extern void page_offline_begin(void); > +extern void page_offline_end(void); > + > /* > * Marks pages in use as page tables. > */ > diff --git a/mm/util.c b/mm/util.c > index 54870226cea6..95395d4e4209 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -1013,3 +1013,41 @@ void mem_dump_obj(void *object) > } > pr_cont(" non-slab/vmalloc memory.\n"); > } > + > +/* > + * A driver might set a page logically offline -- PageOffline() -- and > + * turn the page inaccessible in the hypervisor; after that, access to page > + * content can be fatal. > + * > + * Some special PFN walkers -- i.e., /proc/kcore -- read content of random > + * pages after checking PageOffline(); however, these PFN walkers can race > + * with drivers that set PageOffline(). > + * > + * page_offline_freeze()/page_offline_unfreeze() allows for a subsystem to > + * synchronize with such drivers, achieving that a page cannot be set > + * PageOffline() while frozen. > + * > + * page_offline_begin()/page_offline_end() is used by drivers that care about > + * such races when setting a page PageOffline(). > + */ > +static DECLARE_RWSEM(page_offline_rwsem); > + > +void page_offline_freeze(void) > +{ > + down_read(&page_offline_rwsem); > +} > + > +void page_offline_unfreeze(void) > +{ > + up_read(&page_offline_rwsem); > +} > + > +void page_offline_begin(void) > +{ > + down_write(&page_offline_rwsem); > +} > + > +void page_offline_end(void) > +{ > + up_write(&page_offline_rwsem); > +} > -- > 2.30.2 > -- Sincerely yours, Mike.