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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48DF6C7EE2A for ; Wed, 17 May 2023 13:49:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC492900004; Wed, 17 May 2023 09:49:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7556900003; Wed, 17 May 2023 09:49:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93E28900004; Wed, 17 May 2023 09:49:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 82768900003 for ; Wed, 17 May 2023 09:49:37 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 51639A05FF for ; Wed, 17 May 2023 13:49:37 +0000 (UTC) X-FDA: 80799879594.07.087514D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id C919D14000C for ; Wed, 17 May 2023 13:49:33 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Qh6HOzrO; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684331374; a=rsa-sha256; cv=none; b=X87g5QZZmCDC2/brkOkDCDPYstoDvzi/5QlSFZIBHT6pBcTMBNpYwdVrOOGXQ1bJztyHUb 7ECZYrl3IxP1oYhF4OMBrkj6pN6MZFQrN+ywpfuJvV+6NxToF9mh9e7zYZW5yXp13+X2yx nTmPn/kd8kKdqGmV9RzeZElKc9nLJIQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Qh6HOzrO; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684331374; h=from:from:sender: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:dkim-signature; bh=0e/SUf5A48wwb3JWMFE3HoGFxkqjXULKhzRKlOy/0Pk=; b=hrU4P1bG3CazrhQrHxkuoG3ZLssGkA41pple7NtTlz11F14AJd/1r5K8VeKOQkbNgH0Kzb 0zfG0tLu4KqWANFYtMQ1PN8nK1MNlxkxNlbRFFUBYNiThyZVD0OuXmVvttohZ+hFv5/ht3 GzcPCxs/H94NBmbxQ2ESdvzTawZFb10= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684331372; 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=0e/SUf5A48wwb3JWMFE3HoGFxkqjXULKhzRKlOy/0Pk=; b=Qh6HOzrOhPln/N7ZVH0IH8qjvB/SJVURpZY7ajdmbu9YSFnnN+jdX8mcFVnvwH9UnRv9/l oEOFt4Fu8ycvKInfO0+XvnGAECbD5AqdFA5swlmmageUB0Ekly5g8dZyjegLCWOl8xSDlH weSeWlcb4D6eaDCXHjBa31gxL/Wel7s= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156-tlHhEmfzPVmU11Zdc4c-Cw-1; Wed, 17 May 2023 09:49:31 -0400 X-MC-Unique: tlHhEmfzPVmU11Zdc4c-Cw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f433a2308bso46812125e9.0 for ; Wed, 17 May 2023 06:49:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684331369; x=1686923369; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0e/SUf5A48wwb3JWMFE3HoGFxkqjXULKhzRKlOy/0Pk=; b=cMe1QxzydrZKzkYSe5ZsZOEL9Bppm72bWwutbTvTFpUmicO9M+52hdjpG9xm/IDk4j R0WO7p7s3TMVYIFdQHTGgRzRFuQwZ6etFTL0S6p4aiekaU3LNP30mdp0LGPbBq8QkbEI LMkb/M2s50PVgBQmCtUekW9sy5Xv52sHUWApszpBAC0JvNKje0xd9u6K6FxlHQlODovm 5kJFB4V6zo8bOandJdEHj28JslVHPdjnS05S6JW3k2uVju331tpMpEXjAr70Xa4NYO88 SF431U5nUt8sbBkLak0sIHuVwI/An51TTqYpb3wBBvG5SNn77zsm8ZSVuz/Nj3k8j58T /Cpg== X-Gm-Message-State: AC+VfDypb/f8Daud/vZkpr8Yly8DvSva4g8wK5NybTGwdGrMnSy7O2TO TbF11Jejc4P5xpfAq72RmiYKIREKvZXNqLFqpPeOwwqB0md3l+oqiemiwCoUhPhBBtLpX9yCPvj INM8SfOF8UA8= X-Received: by 2002:adf:e74f:0:b0:2f7:cfe2:6507 with SMTP id c15-20020adfe74f000000b002f7cfe26507mr675507wrn.20.1684331369591; Wed, 17 May 2023 06:49:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5a5arMtnNTOv8xW4922VW8BZeZ7wJoPt5cnWb7Q96XDpQAvRopJCLeAn9BjbsFKP1k1Lhf+w== X-Received: by 2002:adf:e74f:0:b0:2f7:cfe2:6507 with SMTP id c15-20020adfe74f000000b002f7cfe26507mr675476wrn.20.1684331369155; Wed, 17 May 2023 06:49:29 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:3900:757e:83f8:a99d:41ae? (p200300cbc7073900757e83f8a99d41ae.dip0.t-ipconnect.de. [2003:cb:c707:3900:757e:83f8:a99d:41ae]) by smtp.gmail.com with ESMTPSA id a3-20020a05600c224300b003f17848673fsm2323496wmm.27.2023.05.17.06.49.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 May 2023 06:49:28 -0700 (PDT) Message-ID: <9aa7d030-19b5-01df-70c0-86d8d6ab86a6@redhat.com> Date: Wed, 17 May 2023 15:49:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH 0/7] riscv: Memory Hot(Un)Plug support To: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Cc: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador , virtualization@lists.linux-foundation.org, linux@rivosinc.com, Alexandre Ghiti References: <20230512145737.985671-1-bjorn@kernel.org> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20230512145737.985671-1-bjorn@kernel.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: 4cd1jt5co7ix3mwmuunem8ffz95x5er7 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: C919D14000C X-HE-Tag: 1684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sugnxzDRjRITC652lQADQ8Mq37H2vjS34eXgvzdTC97TYhHQuvSwRABcjok3rxnjvzzlTe5mqCr2HLMns4Z4vtGb4MOfWT7Cg17umz/Fe0PpA5UAaN3pIrOZOwzKIbIlfFZ333iBF8tPluWWC0ApJ4vyKFtAZiUKPLjWvRYVm27fv5Rc9vBUjkwp8amfjaZKO+QrYZ2p6ilpRkQdWLoxzvGX8q/kzA2fDKXCV2utC7g58JgA3+YewNqyoHcrfghUxk1yymPvH6Sj4GzFWV6BzElUddE8hrMV3LZenn9RqBgi3zc1ShDfyM9FhL6VUu+8B9NdCMIxKJzFW84EO380r4QYeOnw73ywh4cc5w+ETHL1BBUqsuV8zqvC6JIO0cdpuvbaLXuXGr+Khwqu3Cvzw/ue7RPn7Hb+QLJ4/Kjf02VNbcGa9T11dXbzHHoVANFbSwCo6JcODA54CzTF8j7BKj4Dc0QNFuNtiywRsBjUjwvU8IqbTEz+Cz3ISKbVE3/r0FNOelNxX+Z1tvVN8tmCmQgyw5EtTtYPEmoPg+flQJhdNcE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 12.05.23 16:57, Björn Töpel wrote: > From: Björn Töpel > > Memory Hot(Un)Plug support for the RISC-V port > ============================================== > > Introduction > ------------ > > To quote "Documentation/admin-guide/mm/memory-hotplug.rst": "Memory > hot(un)plug allows for increasing and decreasing the size of physical > memory available to a machine at runtime." > > This series attempts to add memory hot(un)plug support for the RISC-V > Linux port. > > I'm sending the series as a v1, but it's borderline RFC. It definitely > needs more testing time, but it would be nice with some early input. > > Implementation > -------------- > > From an arch perspective, a couple of callbacks needs to be > implemented to support hot plugging: > > arch_add_memory() > This callback is responsible for updating the linear/direct map, and > call into the memory hot plugging generic code via __add_pages(). > > arch_remove_memory() > In this callback the linear/direct map is tore down. > > vmemmap_free() > The function tears down the vmemmap mappings (if > CONFIG_SPARSEMEM_VMEMMAP is in-use), and also deallocates the backing > vmemmap pages. Note that for persistent memory, an alternative > allocator for the backing pages can be used -- the vmem_altmap. This > means that when the backing pages are cleared, extra care is needed so > that the correct deallocation method is used. Note that RISC-V > populates the vmemmap using vmemmap_populate_basepages(), so currently > no hugepages are used for the backing store. > > The page table unmap/teardown functions are heavily based (copied!) > from the x86 tree. The same remove_pgd_mapping() is used in both > vmemmap_free() and arch_remove_memory(), but in the latter function > the backing pages are not removed. > > On RISC-V, the PGD level kernel mappings needs to synchronized with > all page-tables (e.g. via sync_kernel_mappings()). Synchronization > involves special care, like locking. Instead, this patch series takes > a different approach (introduced by Jörg Rödel in the x86-tree); > Pre-allocate the PGD-leaves (P4D, PUD, or PMD depending on the paging > setup) at mem_init(), for vmemmap and the direct map. > > Pre-allocating the PGD-leaves waste some memory, but is only enabled > for CONFIG_MEMORY_HOTPLUG. The number pages, potentially unused, are > ~128 * 4K. > > Patch 1: Preparation for hotplugging support, by pre-allocating the > PGD leaves. > > Patch 2: Changes the __init attribute to __meminit, to avoid that the > functions are removed after init. __meminit keeps the > functions after init, if memory hotplugging is enabled for > the build. > > Patch 3: Refactor the direct map setup, so it can be used for hot add. > > Patch 4: The actual add/remove code. Mostly a page-table-walk > exercise. > > Patch 5: Turn on the arch support in Kconfig > > Patch 6: Now that memory hotplugging is enabled, make virtio-mem > usable for RISC-V > > Patch 7: Pre-allocate vmalloc PGD-leaves as well, which removes the > need for vmalloc faulting. > > RFC > --- > > * TLB flushes. The current series uses Big Hammer flush-it-all. > * Pre-allocation vs explicit syncs > > Testing > ------- > > ACPI support is still in the making for RISC-V, so tests that involve > CXL and similar fanciness is currently not possible. Virtio-mem, > however, works without proper ACPI support. In order to try this out > in Qemu, some additional patches for Qemu are needed: > > * Enable virtio-mem for RISC-V > * Add proper hotplug support for virtio-mem > > The patch for Qemu can be found is commit 5d90a7ef1bc0 > ("hw/riscv/virt: Support for virtio-mem-pci"), and can be found here > > https://github.com/bjoto/qemu/tree/riscv-virtio-mem > > I will try to upstream that work in parallel with this. > > Thanks to David Hildenbrand for valuable input for the Qemu side of > things. > > The series is based on the RISC-V fixes tree > https://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git/log/?h=fixes > Cool stuff! I'm fairly busy right now, so some high-level questions upfront: What is the memory section size (which implies the memory block size and)? This implies the minimum DIMM granularity and the high-level granularity in which virtio-mem adds memory. What is the pageblock size, implying the minimum granularity that virtio-mem can operate on? On x86-64 and arm64 we currently use the ACPI SRAT to expose the maximum physical address where we can see memory getting hotplugged. [1] From that, we can derive the "max_possible_pfn" and prepare the kernel virtual memory layourt (especially, direct map). Is something similar required on RISC-V? On s390x, I'm planning on adding a paravirtualized mechanism to detect where memory devices might be located. (I had a running RFC, but was distracted by all other kinds of stuff) [1] https://virtio-mem.gitlab.io/developer-guide.html -- Thanks, David / dhildenb