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.8 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,URIBL_BLOCKED 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 23253C4724C for ; Thu, 7 May 2020 10:46:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02D7624962 for ; Thu, 7 May 2020 10:46:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="D0pXP0IU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726538AbgEGKq4 (ORCPT ); Thu, 7 May 2020 06:46:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60011 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726393AbgEGKq4 (ORCPT ); Thu, 7 May 2020 06:46:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588848414; 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: in-reply-to:in-reply-to:references:references; bh=jwFSP1qKPzAiDWVK6ecZi/lZRSGtCCdB3pW0dxf0VHw=; b=D0pXP0IUIMyXohYPb51/MwOqKX3cwc8P3CtBT1BmWOlAcovCp183l3rbTn1Px4Btyw5R// gNbfNHE5PRtqKcHOKz3qDV2dfoh6wXYpAbT2gtuddFNAXOUazg5TNJzXN041miT2NcPORQ dtQTNv7YqmwPF3o9p+o4GAb5jQ97E2Y= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-52-NbxiJMuVNJKQVEfv9nsKaQ-1; Thu, 07 May 2020 06:46:53 -0400 X-MC-Unique: NbxiJMuVNJKQVEfv9nsKaQ-1 Received: by mail-wr1-f70.google.com with SMTP id 30so3176583wrq.15 for ; Thu, 07 May 2020 03:46:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jwFSP1qKPzAiDWVK6ecZi/lZRSGtCCdB3pW0dxf0VHw=; b=oHFtQ1J1+29vv/d6gAlhqK7/a6fspfhlIr6XGyj97ZExryBlUBh98BpzqO/mv+9Iex LWAp1IHB7z0MnYPXzlwqmKTWmN/B+t56V67VaLqU4XNYrlevbj+5yoM2Nny14v2f00K3 aXvtMcCUv4EUGLjgxKU+2KKLq4/Y6QTJAX1pYHzoXjpZTMKq77Fzl8VAPnmuOPYqh0j2 KQsnk0sGE63StJhL+vKwNcTvZpbvxztlY7/9o7pVTGPzlYtTOsW/tuEp8pA5kAZizNge YYCHl5tnEXfnm1UrkhqdMH2hJWJVrCcQe5UDSviM0Xon7Se/wmH91lufCqY0msGONQZh jV4w== X-Gm-Message-State: AGi0PuYrHC2d5sB9pO/8Xf2Brj7bR4hHLFvsTTU0/yVUEZM3k0rXFovj oi951C/NnZWCnVsYgrAPa/QTQgrhZ6/HG5pLe7mDznXPqGLNzZsF0Nadr4QAcTRr6AHMw41OwjK AnVkH+bU4swgyUWJ2GC7A+wPN X-Received: by 2002:a1c:4b16:: with SMTP id y22mr9704516wma.170.1588848411507; Thu, 07 May 2020 03:46:51 -0700 (PDT) X-Google-Smtp-Source: APiQypJwkpcsvMDTihRmO/58UI/oBdWetzX3zNTW+RN5tQqtGOSRJ/Ox4DqJrFYHImjL7fq9CHlvYA== X-Received: by 2002:a1c:4b16:: with SMTP id y22mr9704494wma.170.1588848411214; Thu, 07 May 2020 03:46:51 -0700 (PDT) Received: from redhat.com (bzq-109-66-7-121.red.bezeqint.net. [109.66.7.121]) by smtp.gmail.com with ESMTPSA id v11sm7638062wrv.53.2020.05.07.03.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 03:46:50 -0700 (PDT) Date: Thu, 7 May 2020 06:46:46 -0400 From: "Michael S. Tsirkin" To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , Michal Hocko , Pankaj Gupta , Oscar Salvador , Pavel Tatashin , Wei Yang , Dan Williams , Qian Cai Subject: Re: [PATCH v3 07/15] mm/memory_hotplug: Introduce offline_and_remove_memory() Message-ID: <20200507064558-mutt-send-email-mst@kernel.org> References: <20200507103119.11219-1-david@redhat.com> <20200507103119.11219-8-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200507103119.11219-8-david@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 12:31:11PM +0200, David Hildenbrand wrote: > virtio-mem wants to offline and remove a memory block once it unplugged > all subblocks (e.g., using alloc_contig_range()). Let's provide > an interface to do that from a driver. virtio-mem already supports to > offline partially unplugged memory blocks. Offlining a fully unplugged > memory block will not require to migrate any pages. All unplugged > subblocks are PageOffline() and have a reference count of 0 - so > offlining code will simply skip them. > > All we need is an interface to offline and remove the memory from kernel > module context, where we don't have access to the memory block devices > (esp. find_memory_block() and device_offline()) and the device hotplug > lock. > > To keep things simple, allow to only work on a single memory block. > > Acked-by: Michal Hocko > Tested-by: Pankaj Gupta > Cc: Andrew Morton > Cc: David Hildenbrand > Cc: Oscar Salvador > Cc: Michal Hocko > Cc: Pavel Tatashin > Cc: Wei Yang > Cc: Dan Williams > Cc: Qian Cai > Signed-off-by: David Hildenbrand didn't you lose Andrew Morton's ack here? > --- > include/linux/memory_hotplug.h | 1 + > mm/memory_hotplug.c | 37 ++++++++++++++++++++++++++++++++++ > 2 files changed, 38 insertions(+) I get: error: sha1 information is lacking or useless (mm/memory_hotplug.c). error: could not build fake ancestor which version is this against? Pls post patches on top of some tag in Linus' tree if possible. > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 7dca9cd6076b..d641828e5596 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -318,6 +318,7 @@ extern void try_offline_node(int nid); > extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); > extern int remove_memory(int nid, u64 start, u64 size); > extern void __remove_memory(int nid, u64 start, u64 size); > +extern int offline_and_remove_memory(int nid, u64 start, u64 size); > > #else > static inline void try_offline_node(int nid) {} > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 936bfe208a6e..bf1941f02a60 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1748,4 +1748,41 @@ int remove_memory(int nid, u64 start, u64 size) > return rc; > } > EXPORT_SYMBOL_GPL(remove_memory); > + > +/* > + * Try to offline and remove a memory block. Might take a long time to > + * finish in case memory is still in use. Primarily useful for memory devices > + * that logically unplugged all memory (so it's no longer in use) and want to > + * offline + remove the memory block. > + */ > +int offline_and_remove_memory(int nid, u64 start, u64 size) > +{ > + struct memory_block *mem; > + int rc = -EINVAL; > + > + if (!IS_ALIGNED(start, memory_block_size_bytes()) || > + size != memory_block_size_bytes()) > + return rc; > + > + lock_device_hotplug(); > + mem = find_memory_block(__pfn_to_section(PFN_DOWN(start))); > + if (mem) > + rc = device_offline(&mem->dev); > + /* Ignore if the device is already offline. */ > + if (rc > 0) > + rc = 0; > + > + /* > + * In case we succeeded to offline the memory block, remove it. > + * This cannot fail as it cannot get onlined in the meantime. > + */ > + if (!rc) { > + rc = try_remove_memory(nid, start, size); > + WARN_ON_ONCE(rc); > + } > + unlock_device_hotplug(); > + > + return rc; > +} > +EXPORT_SYMBOL_GPL(offline_and_remove_memory); > #endif /* CONFIG_MEMORY_HOTREMOVE */ > -- > 2.25.3