Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2504779pxy; Mon, 3 May 2021 01:17:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWuuGag1QoNhoh3BRZJy/6M7CIWxsdAXtZ8SXZ1l8uzzy5hnBEC3Syl5z4/lOeiwuxqwvD X-Received: by 2002:a05:6402:4314:: with SMTP id m20mr2180550edc.387.1620029860240; Mon, 03 May 2021 01:17:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620029860; cv=none; d=google.com; s=arc-20160816; b=UGyqs4cjTHjk++ix4YRDfzlZy/MGLE2HTZfCarlKCPv/egaz5EdurxrEL+UuPCUCgb /+9ce9nGAy/BiYyBRRlm6IEYoso0W19mVKGgLF9hCn20jjs0Gu7l4Cuumw4nus+e8AGR g6IigTCw0znNMGVmBJJiFd14kNlRTnlAwqN2yPSCFsFDp1fs2a8iZryTp1XfbGi5PMAK uL5WGnKlGcJ4/qPEuUnPbfE5UGuFRNfVJKA/3ckGPNurPUWScf/mzQRXFlT0aqsvcO0i 2ucYKx/CAdpBLqFiepxXUvifwXIystywSmTykMmaKn5gPd6e+wnvBALYuyv62w6JE2Oh +rOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=3uB/EYYvRDIWzIKd9NUtpds132sJrn5ZaXZy/6UA0sM=; b=KHXUj0hF9I+81GEdRgOd/D4njBQQ+JlwHQw2ssc+DnHKysXcTX8Xq/voUNXhKWfagC onpO7ZAgWMrjpkluR3QjPzNH0BAn+4qvy1pW67EIkosN8rpf4hCe7XEB2uwFy2zuCTTp mdYcK8yBk4oA1loIaP8zKmyA2ymST9Afe2miXOaYhEB/Zh5neKMpE0WeWwjbyeeUYWub UYYF/CbDuM4GFDsjtX/ozRf/NccYSEl0yauRMbbwROoMN3CKJz5sXDUzKO/pt1GQY1y2 CQvRX+8Uv8dwRoJCXBAxA+1Rw4+Chc6ISmnqXLw5omzKfMmHJ+Q1aIfD2KE6oxY7lfGr Vnpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=agNuSzL4; 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 c16si9151013edw.227.2021.05.03.01.17.16; Mon, 03 May 2021 01:17:40 -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=agNuSzL4; 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 S232906AbhECIRE (ORCPT + 99 others); Mon, 3 May 2021 04:17:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20747 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232831AbhECIRC (ORCPT ); Mon, 3 May 2021 04:17:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620029769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3uB/EYYvRDIWzIKd9NUtpds132sJrn5ZaXZy/6UA0sM=; b=agNuSzL4sB4nJM4a3ImhqRPGf9dsq2uqox2rNh5P5drlhWCmH6CUsJFghV9LtZzg8p0cWD caMOtNW6dnCs5s/fF1f9y9yCsh/+DTo8XbP8psjPgtHzq3GkY6ilJ/68nNSfd3gxAKGXsj W2/xoGK9LsmNfoen7UyuhUj7L2C2XV8= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-50-6wZj9jtVNx-6AhASptlVWg-1; Mon, 03 May 2021 04:16:06 -0400 X-MC-Unique: 6wZj9jtVNx-6AhASptlVWg-1 Received: by mail-ed1-f71.google.com with SMTP id s20-20020a0564025214b029038752a2d8f3so4105533edd.2 for ; Mon, 03 May 2021 01:16:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=3uB/EYYvRDIWzIKd9NUtpds132sJrn5ZaXZy/6UA0sM=; b=Md4yJMhhuaWerBR/loIrt+HmjRwg/jAp4MbFJwglPjA1kVDwGYJ8x7EizkyBkuInMP GUIbJ5oXPW/eRwaFQLtGH7TvYR5t7VlTTPR9Mdk1xs1cRqKGwop1mXuxKZd3qppN6hDN oLIdAsxuvmqpXOTsDehAuIeXUCQlazoex1ueE01oo15aQWbAIv5WsuyhrBZaym3uyatE Nalft9me1OD74v2BhaeYNKZv4QmtWUMmE1q+uVffXeygx8kBQQUMyAlfAOOKhMbdFfWf dT4/249o94805XDcM3ya+xBPUV9he/OksZyyIEzz9n98KsGs0raP5ZTPS4V3Scom//iN 3Osg== X-Gm-Message-State: AOAM530odgnSCG0zRljg+AGAHUH+p45jlciAJGWkgcVTdK6x/V9IpXcg /6mK6x4OEKUgx3SNQ4XeX2zfwgruOWhfO+OozfVKPMPUja7LtikUTdEjEsomeSijPrnazxv6tzr IIegUeVU12nUV2YolH0qjBajy X-Received: by 2002:a17:906:8147:: with SMTP id z7mr11677881ejw.496.1620029764846; Mon, 03 May 2021 01:16:04 -0700 (PDT) X-Received: by 2002:a17:906:8147:: with SMTP id z7mr11677854ejw.496.1620029764611; Mon, 03 May 2021 01:16:04 -0700 (PDT) Received: from [192.168.3.132] (p5b0c649f.dip0.t-ipconnect.de. [91.12.100.159]) by smtp.gmail.com with ESMTPSA id lr15sm4554094ejb.107.2021.05.03.01.16.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 May 2021 01:16:04 -0700 (PDT) Subject: Re: [PATCH v1 6/7] virtio-mem: use page_offline_(start|end) when setting PageOffline() To: Mike Rapoport 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 References: <20210429122519.15183-1-david@redhat.com> <20210429122519.15183-7-david@redhat.com> From: David Hildenbrand Organization: Red Hat Message-ID: <98f22a46-da8b-2891-fade-09937c0ccf69@redhat.com> Date: Mon, 3 May 2021 10:16:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02.05.21 08:33, Mike Rapoport wrote: > On Thu, Apr 29, 2021 at 02:25:18PM +0200, David Hildenbrand wrote: >> 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. >> >> Signed-off-by: David Hildenbrand >> --- >> drivers/virtio/virtio_mem.c | 2 ++ >> mm/util.c | 2 ++ >> 2 files changed, 4 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(); > > I'm not really familiar with ballooning and memory hotplug, but is it the > only place that needs page_offline_{begin,end} ? Existing balloon implementations that I am aware of (Hyper-V, XEN, virtio-balloon, vmware-balloon) usually allow reading inflated memory; doing so might result in unnecessary overhead in the hypervisor, so we really want to avoid it -- but it's strictly not forbidden and has been working forever. So we barely care about races: if there would be a rare race, we'd still be able to read that memory. For virtio-mem, it'll be different in the future when using shmem, huge pages, !anonymous private mappings, ... as backing storage for a VM; there will be a virtio spec extension to document that virtio-mem changes that indicate the new behavior won't allow reading unplugged memory and doing so will result in undefined behavior. -- Thanks, David / dhildenb