Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3978588pxu; Mon, 12 Oct 2020 06:31:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6lBY13JT7t98+bLwGHVDEoAsCZwc/565Im0YCIukjrBqIhg0owVSH81RJECxE5T5jmsvY X-Received: by 2002:aa7:c1da:: with SMTP id d26mr13818499edp.135.1602509461857; Mon, 12 Oct 2020 06:31:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602509461; cv=none; d=google.com; s=arc-20160816; b=zHpkYzeUL2ycDYQdVjZ3P9FOagVqBNvRBAuSpka7Yuzjkugx6eytfBhsZ6tqaCyEf4 UgtZyWKxsKTAxzzGDBHzQUZB8e/0L6k3DwX3axHwnbv5CGM7w+3S+F7dMKGsxHRY7w2a svk9XVtizmha9SvGyWXtNx3GFYoMxzHnVQTTayDpfnduIeZ44l0Ng9BiG9OhofiyBdJp EueZ2+4h8r5NHM86QJxnr/ti2XcOtcRcWKtRJA4+hwsfjJ4SUZI7Wd3sc2t9J3bSHw4z Gvkhn+7JBgJEx92GeVNnkTPXxbDj4cfrbdzO63VRO5jGzc7XW59EJ4OzvM2Y+q+5Vh5V RtEA== 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=7uNq+DgFx1awbtxRCO5i53i4OzQ+SF2JZ2u66Xi43bM=; b=oK2Mi6V0GI22rMYYxD1aRaJL31BxE/Fl0ACIu+4ow3isctHv0Nj2B2Tmh0+Ti9JrOy sgmf79VmTTtyF63g4LVgiXLUdImX4LYQo7dejwJW1Nc1wtfTix0aKIeHtBHvQ5mFKlyr 4jdWy0ArvunyGIwgKw5K+tC2oNX5cHU9zwEV74OGJ/7wqS9Yfc7wb2eoNjLOplP5i3ne Q4tDlHVKDIc5N0p/tCG9izDAVxuIazQJFM57BP6cxVSveDMjJrzi4QxxYKm1pcW4460a K6haQ8XDQ4Q0IbdfSwWhg19CwocjfwyX3OKCDdG/tMko5O61WPFtDH7zU++Vu1AlELz9 dZNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W7wrFnxG; 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 hh2si13458602ejb.601.2020.10.12.06.30.38; Mon, 12 Oct 2020 06:31:01 -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=W7wrFnxG; 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 S1730157AbgJLMzZ (ORCPT + 99 others); Mon, 12 Oct 2020 08:55:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54073 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729953AbgJLMzU (ORCPT ); Mon, 12 Oct 2020 08:55:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602507318; 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=7uNq+DgFx1awbtxRCO5i53i4OzQ+SF2JZ2u66Xi43bM=; b=W7wrFnxGwOPW3xs8QkEz+UN4TH0ziImZhtT9QGigPZxGZrBUKxWXcYo2Up4+r7x3PAfhPh EU3HXbytCbaslXadJZpdYWpYvsf+82H+nPjHPHON53yx1HQIW1pzPeCkOylUVd7ikvVF41 RgT9FBdyE6c7OsgDVdTLU7wyOA6cVnE= 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-398-qnEyoJ0YOFmFIFcl_UGbGQ-1; Mon, 12 Oct 2020 08:55:15 -0400 X-MC-Unique: qnEyoJ0YOFmFIFcl_UGbGQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6722164144; Mon, 12 Oct 2020 12:55:14 +0000 (UTC) Received: from t480s.redhat.com (ovpn-113-251.ams2.redhat.com [10.36.113.251]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1C6460C07; Mon, 12 Oct 2020 12:55:09 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, Andrew Morton , "Michael S . Tsirkin" , David Hildenbrand , Jason Wang , Pankaj Gupta Subject: [PATCH v1 13/29] virtio-mem: factor out handling of fake-offline pages in memory notifier Date: Mon, 12 Oct 2020 14:53:07 +0200 Message-Id: <20201012125323.17509-14-david@redhat.com> In-Reply-To: <20201012125323.17509-1-david@redhat.com> References: <20201012125323.17509-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's factor out the core pieces and place the implementation next to virtio_mem_fake_offline(). We'll reuse this functionality soon. Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 73 +++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index d132bc54ef57..a2124892e510 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -168,6 +168,10 @@ static LIST_HEAD(virtio_mem_devices); static void virtio_mem_online_page_cb(struct page *page, unsigned int order); static void virtio_mem_retry(struct virtio_mem *vm); +static void virtio_mem_fake_offline_going_offline(unsigned long pfn, + unsigned long nr_pages); +static void virtio_mem_fake_offline_cancel_offline(unsigned long pfn, + unsigned long nr_pages); /* * Register a virtio-mem device so it will be considered for the online_page @@ -604,27 +608,15 @@ static void virtio_mem_notify_going_offline(struct virtio_mem *vm, unsigned long mb_id) { const unsigned long nr_pages = PFN_DOWN(vm->subblock_size); - struct page *page; unsigned long pfn; - int sb_id, i; + int sb_id; for (sb_id = 0; sb_id < vm->nb_sb_per_mb; sb_id++) { if (virtio_mem_mb_test_sb_plugged(vm, mb_id, sb_id, 1)) continue; - /* - * Drop our reference to the pages so the memory can get - * offlined and add the unplugged pages to the managed - * page counters (so offlining code can correctly subtract - * them again). - */ pfn = PFN_DOWN(virtio_mem_mb_id_to_phys(mb_id) + sb_id * vm->subblock_size); - adjust_managed_page_count(pfn_to_page(pfn), nr_pages); - for (i = 0; i < nr_pages; i++) { - page = pfn_to_page(pfn + i); - if (WARN_ON(!page_ref_dec_and_test(page))) - dump_page(page, "unplugged page referenced"); - } + virtio_mem_fake_offline_going_offline(pfn, nr_pages); } } @@ -633,21 +625,14 @@ static void virtio_mem_notify_cancel_offline(struct virtio_mem *vm, { const unsigned long nr_pages = PFN_DOWN(vm->subblock_size); unsigned long pfn; - int sb_id, i; + int sb_id; for (sb_id = 0; sb_id < vm->nb_sb_per_mb; sb_id++) { if (virtio_mem_mb_test_sb_plugged(vm, mb_id, sb_id, 1)) continue; - /* - * Get the reference we dropped when going offline and - * subtract the unplugged pages from the managed page - * counters. - */ pfn = PFN_DOWN(virtio_mem_mb_id_to_phys(mb_id) + sb_id * vm->subblock_size); - adjust_managed_page_count(pfn_to_page(pfn), -nr_pages); - for (i = 0; i < nr_pages; i++) - page_ref_inc(pfn_to_page(pfn + i)); + virtio_mem_fake_offline_cancel_offline(pfn, nr_pages); } } @@ -853,6 +838,48 @@ static int virtio_mem_fake_offline(unsigned long pfn, unsigned long nr_pages) return 0; } +/* + * Handle fake-offline pages when memory is going offline - such that the + * pages can be skipped by mm-core when offlining. + */ +static void virtio_mem_fake_offline_going_offline(unsigned long pfn, + unsigned long nr_pages) +{ + struct page *page; + unsigned long i; + + /* + * Drop our reference to the pages so the memory can get offlined + * and add the unplugged pages to the managed page counters (so + * offlining code can correctly subtract them again). + */ + adjust_managed_page_count(pfn_to_page(pfn), nr_pages); + /* Drop our reference to the pages so the memory can get offlined. */ + for (i = 0; i < nr_pages; i++) { + page = pfn_to_page(pfn + i); + if (WARN_ON(!page_ref_dec_and_test(page))) + dump_page(page, "fake-offline page referenced"); + } +} + +/* + * Handle fake-offline pages when memory offlining is canceled - to undo + * what we did in virtio_mem_fake_offline_going_offline(). + */ +static void virtio_mem_fake_offline_cancel_offline(unsigned long pfn, + unsigned long nr_pages) +{ + unsigned long i; + + /* + * Get the reference we dropped when going offline and subtract the + * unplugged pages from the managed page counters. + */ + adjust_managed_page_count(pfn_to_page(pfn), -nr_pages); + for (i = 0; i < nr_pages; i++) + page_ref_inc(pfn_to_page(pfn + i)); +} + static void virtio_mem_online_page_cb(struct page *page, unsigned int order) { const unsigned long addr = page_to_phys(page); -- 2.26.2