From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA56FC3F2CE for ; Tue, 17 Mar 2020 10:50:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 81B082073C for ; Tue, 17 Mar 2020 10:50:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Jnp1a/LW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726605AbgCQKu1 (ORCPT ); Tue, 17 Mar 2020 06:50:27 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:51095 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbgCQKuY (ORCPT ); Tue, 17 Mar 2020 06:50:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584442223; 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=V59E7vNQ/J1sWCSrCuIGfyF/JUs0k+zR/JYAQnnzPbY=; b=Jnp1a/LWfhx7gT6hFxPxJ0+MvfNMbAZYlKlKUUpu7WDzkOqBnXkgZAUbkaW4aiOWBwtuKN 89hjzEgPRNxMHXBWesHxC4NbU3WxP+xXV1fCjj9SnRSgep7h5paMEPumPOC0g8PCJW1OaH DMM1845RWhnpxWEMRaFoBc6C4V3QOVM= 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-2-_1sloA26MUOHIPosJgaWyQ-1; Tue, 17 Mar 2020 06:50:19 -0400 X-MC-Unique: _1sloA26MUOHIPosJgaWyQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2801100550E; Tue, 17 Mar 2020 10:50:17 +0000 (UTC) Received: from t480s.redhat.com (ovpn-112-136.ams2.redhat.com [10.36.112.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF30373865; Tue, 17 Mar 2020 10:50:14 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-hyperv@vger.kernel.org, David Hildenbrand , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Andrew Morton , Michal Hocko , Oscar Salvador , "Rafael J. Wysocki" , Baoquan He , Wei Yang , Vitaly Kuznetsov Subject: [PATCH v2 5/8] hv_balloon: don't check for memhp_auto_online manually Date: Tue, 17 Mar 2020 11:49:39 +0100 Message-Id: <20200317104942.11178-6-david@redhat.com> In-Reply-To: <20200317104942.11178-1-david@redhat.com> References: <20200317104942.11178-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Content-Transfer-Encoding: quoted-printable Sender: linux-hyperv-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hyperv@vger.kernel.org We get the MEM_ONLINE notifier call if memory is added right from the kernel via add_memory() or later from user space. Let's get rid of the "ha_waiting" flag - the wait event has an inbuilt mechanism (->done) for that. Initialize the wait event only once and reinitialize before adding memory. Unconditionally call complete() and wait_for_completion_timeout(). If there are no waiters, complete() will only increment ->done - which will be reset by reinit_completion(). If complete() has already been called, wait_for_completion_timeout() will not wait. There is still the chance for a small race between concurrent reinit_completion() and complete(). If complete() wins, we would not wait - which is tolerable (and the race exists in current code as well). Note: We only wait for "some" memory to get onlined, which seems to be good enough for now. Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Cc: Wei Liu Cc: Andrew Morton Cc: Michal Hocko Cc: Oscar Salvador Cc: "Rafael J. Wysocki" Cc: Baoquan He Cc: Wei Yang Cc: Vitaly Kuznetsov Cc: linux-hyperv@vger.kernel.org Signed-off-by: David Hildenbrand --- drivers/hv/hv_balloon.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index a02ce43d778d..af5e09f08130 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -533,7 +533,6 @@ struct hv_dynmem_device { * State to synchronize hot-add. */ struct completion ol_waitevent; - bool ha_waiting; /* * This thread handles hot-add * requests from the host as well as notifying @@ -634,10 +633,7 @@ static int hv_memory_notifier(struct notifier_block = *nb, unsigned long val, switch (val) { case MEM_ONLINE: case MEM_CANCEL_ONLINE: - if (dm_device.ha_waiting) { - dm_device.ha_waiting =3D false; - complete(&dm_device.ol_waitevent); - } + complete(&dm_device.ol_waitevent); break; =20 case MEM_OFFLINE: @@ -726,8 +722,7 @@ static void hv_mem_hot_add(unsigned long start, unsig= ned long size, has->covered_end_pfn +=3D processed_pfn; spin_unlock_irqrestore(&dm_device.ha_lock, flags); =20 - init_completion(&dm_device.ol_waitevent); - dm_device.ha_waiting =3D !memhp_auto_online; + reinit_completion(&dm_device.ol_waitevent); =20 nid =3D memory_add_physaddr_to_nid(PFN_PHYS(start_pfn)); ret =3D add_memory(nid, PFN_PHYS((start_pfn)), @@ -753,15 +748,14 @@ static void hv_mem_hot_add(unsigned long start, uns= igned long size, } =20 /* - * Wait for the memory block to be onlined when memory onlining - * is done outside of kernel (memhp_auto_online). Since the hot - * add has succeeded, it is ok to proceed even if the pages in - * the hot added region have not been "onlined" within the - * allowed time. + * Wait for memory to get onlined. If the kernel onlined the + * memory when adding it, this will return directly. Otherwise, + * it will wait for user space to online the memory. This helps + * to avoid adding memory faster than it is getting onlined. As + * adding succeeded, it is ok to proceed even if the memory was + * not onlined in time. */ - if (dm_device.ha_waiting) - wait_for_completion_timeout(&dm_device.ol_waitevent, - 5*HZ); + wait_for_completion_timeout(&dm_device.ol_waitevent, 5 * HZ); post_status(&dm_device); } } @@ -1707,6 +1701,7 @@ static int balloon_probe(struct hv_device *dev, #ifdef CONFIG_MEMORY_HOTPLUG set_online_page_callback(&hv_online_page); register_memory_notifier(&hv_memory_nb); + init_completion(&dm_device.ol_waitevent); #endif =20 hv_set_drvdata(dev, &dm_device); --=20 2.24.1