Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp681031pxj; Fri, 14 May 2021 12:58:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjr7s2zsvq2DhXnOPiqnaF0EuAeUmrq5pEGTSCDQ3bcE8MR0N27e0ji2GAmpg3PTuIkcPx X-Received: by 2002:a92:c60e:: with SMTP id p14mr40361330ilm.205.1621022302171; Fri, 14 May 2021 12:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621022302; cv=none; d=google.com; s=arc-20160816; b=cgikk03TR2S/XxKFme0j21nSnhRJq9M8vAWKPoh9U+kelj5XWg8tw4k359tUpewVd0 QY3k3jbB9GGwCk8tUnit8si18nlOlXguQcrBFmZ7pwLl4aIP1k8qlWZq0QHuW0KugMMH 7SWgUYFsGDQMhaX5EZx8cOzbLkB5qcqAEIcNW0nJz2dxN3lVOHhjndAt+f7dnZuPZZRu RoSKEilKICMctTZFxT3dzBeAH3bRo3Eqv0EQ6gw0J8Ll08U0/va9ya/o+XVaN5VWrWG1 jXfSXWIbLoEwuv5sAkVje7GOl+AMFLWBlLhddfm2/Dobv4xmcD6bCF0revtxpIjflXYm /IvA== 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=5uvq7/HzHxoBsPRM6oyLa2n9DVz25WrcnXOXa28LPqo=; b=FMB8RHBvBGa8KZJt9Fh01ELlzpZTgB39pRndD9ADMZxY/Zn8yhafLteQ6A+aJDRY5M B8c/pW4KiqdC2ZqidnGrX9LQAT7mCYAxgNdd4iZwrvxiOyPI5JbCwtodJU9DsknmJg2d 5elRT0LGzK8aKbyr7wuwubHAUa3SOOaGpSywIxqhRX7PUY/SKrGLJZqzq1y+yP4xHcUy Hho737zWQf1maoBhObsPUJ+rKNx4hKFN2sWIf1a22uO66DndzcGrbNflWQO0HoI+HPmW kwU8EeaikpPTnM1RKQlcXy4tbX6T5hEfXGVgC5t4rULOsQ9emKUboYAiq91NUAnbGAm6 SMQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d2wn75e0; 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 j11si8326694ila.145.2021.05.14.12.58.09; Fri, 14 May 2021 12:58:22 -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=d2wn75e0; 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 S235149AbhENRZM (ORCPT + 99 others); Fri, 14 May 2021 13:25:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51471 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235137AbhENRZL (ORCPT ); Fri, 14 May 2021 13:25:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621013039; 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=5uvq7/HzHxoBsPRM6oyLa2n9DVz25WrcnXOXa28LPqo=; b=d2wn75e0uIB41RuXqcELSbqUA1nE5kM4bLeal7+8jvd2p4pqQ5kH032sVv08bApBD62Kzk dEgU52RAtz5LcY/yXeybnyQ37rfA295wFyBoxolmzNfgq4VKi32tDuuP1J9ly6s4YtTyGe R0XerX9wDEHLBUTWtKikqfEjy7B2jQA= 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-189-bmhtkxP6O3aGBDbCC145OQ-1; Fri, 14 May 2021 13:23:57 -0400 X-MC-Unique: bmhtkxP6O3aGBDbCC145OQ-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 A7731107ACE3; Fri, 14 May 2021 17:23:54 +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 2B3F61F4; Fri, 14 May 2021 17:23:48 +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 5/6] virtio-mem: use page_offline_(start|end) when setting PageOffline() Date: Fri, 14 May 2021 19:22:46 +0200 Message-Id: <20210514172247.176750-6-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 use page_offline_(start|end) to synchronize setting PageOffline(), so we won't have valid page access to unplugged memory regions from /proc/kcore. Existing balloon implementations usually allow reading inflated memory; doing so might result in unnecessary overhead in the hypervisor, which is currently the case with virtio-mem. For future virtio-mem use cases, it will be different when using shmem, huge pages, !anonymous private mappings, ... as backing storage for a VM. virtio-mem unplugged memory must no longer be accessed and access might result in undefined behavior. There will be a virtio spec extension to document this change, including a new feature flag indicating the changed behavior. We really don't want to race against PFN walkers reading random page content. Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 10ec60d81e84..dc2a2e2b2ff8 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -1065,6 +1065,7 @@ static int virtio_mem_memory_notifier_cb(struct notifier_block *nb, static void virtio_mem_set_fake_offline(unsigned long pfn, unsigned long nr_pages, bool onlined) { + page_offline_begin(); for (; nr_pages--; pfn++) { struct page *page = pfn_to_page(pfn); @@ -1075,6 +1076,7 @@ static void virtio_mem_set_fake_offline(unsigned long pfn, ClearPageReserved(page); } } + page_offline_end(); } /* -- 2.31.1