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 51740C7EE2A for ; Mon, 22 May 2023 08:21:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC57D6B0074; Mon, 22 May 2023 04:21:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7515900002; Mon, 22 May 2023 04:21:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93D976B0078; Mon, 22 May 2023 04:21:21 -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 84D6B6B0074 for ; Mon, 22 May 2023 04:21:21 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4C502A0CC5 for ; Mon, 22 May 2023 08:21:21 +0000 (UTC) X-FDA: 80817196362.13.100F085 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 1710940014 for ; Mon, 22 May 2023 08:21:18 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V5PaRAqi; spf=pass (imf17.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=1684743679; 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=4Wu/XGI/Cw3LL7Rh46pg9C16OYUTDksjb0N1uf2C+4U=; b=m0ls9LzDmhxSGch12CCaMLTcIIAjJffQwfdvl6kDVQGAp7CAa9jpIqpR0gLH8mXV+pHwrR RYqrnaT86eH1mNDFSImQUvY9HcDpFaVLD9H+F2778x6/OsufkD/HkxgdFY4kLH9kvt8dbC pqThtsZGYtGW2NMuhg5Bo7uwVnIyV2w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684743679; a=rsa-sha256; cv=none; b=fyOV9gkgW+UTNzkwmLJVEDDEAp86OL7D0rTxwGkM4NLsulTSlouLGLyHPILe5eODjdAJgM 67V7j5tc+RmUFM7fYj8sK58rY3T3GW2tp2HusDvkiBN5pD+VoiTH9nsKolYPBMXe921XRd 8n0U9Lgz5e0AWUiF6PWxpbAMaSODNFc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V5PaRAqi; spf=pass (imf17.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684743678; 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=4Wu/XGI/Cw3LL7Rh46pg9C16OYUTDksjb0N1uf2C+4U=; b=V5PaRAqiDZ+xGE6sn7eQg2yOH7qAe6OAhq7XaeiDVb73bk/4CZHy9cqPg5sWUwNuBdR8bQ zwflFC8z9SyXvdydCmN4RVY4zlJenvofxis7q8NebxWijZyQ9Wj2xdEcUGsIpHIfYpOpTV k2P7ggCDfAKxOmzwWXNLni5WF0z+N8Y= 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-424-fIMuRdENMNOveyX-y4sHgA-1; Mon, 22 May 2023 04:21:16 -0400 X-MC-Unique: fIMuRdENMNOveyX-y4sHgA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f6045853c1so2375565e9.3 for ; Mon, 22 May 2023 01:21:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684743675; x=1687335675; h=content-transfer-encoding:in-reply-to:subject:organization:from :content-language:references:cc:to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4Wu/XGI/Cw3LL7Rh46pg9C16OYUTDksjb0N1uf2C+4U=; b=lamqeDGlG7xA1EF6bWcMcCgtrkTz4j0/qTj1iXYl0syqLqXGLvym/gtbSsx4YkDScL cfaWXt0e6Ahj6T2eYtUh43B6HaNDySZsf19KQxyqa2y9ctS8jOlKHxiOuzbtjWR6k3Wv WxmTu3EaiZv9q5WqWNjQ/RtUrhnIXJrwouc93GF4spfEKQU4m1H3cI6+FjUqREuYB5vN vegtT/zV074aDFgQ67vYeYzcaI1IvQltncE31UjqyDGo679+C+lXixHqqYw9gJU51KkZ 8SCL8AtdYACxX7kuXD6FNGS8b8I2hhdCcNrTFy5yqlyRYLHvEtv5Ww6Bok/Y3jby6GdM yM4g== X-Gm-Message-State: AC+VfDzUxpiogN87qmNo8m3j1d4wRK4AGqTRDn+aKvXaHcTdE28+fPwc xuQjftuVaHZ5WKvtMczhCCpEZScgKsghcC1rYAmZNbin9cT7q1ZR2SHUSErBHqM9LtiHfC3Nzfn okJeXrc3iq7E= X-Received: by 2002:a1c:f70e:0:b0:3f4:2b1a:553b with SMTP id v14-20020a1cf70e000000b003f42b1a553bmr6741832wmh.28.1684743675399; Mon, 22 May 2023 01:21:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6mG7l4xGGoGOdmClG/pwLidLadfZoXsxEEQrH052zzBQHncEp4Wz9Jql141DWAS4jQSBmoww== X-Received: by 2002:a1c:f70e:0:b0:3f4:2b1a:553b with SMTP id v14-20020a1cf70e000000b003f42b1a553bmr6741816wmh.28.1684743675017; Mon, 22 May 2023 01:21:15 -0700 (PDT) Received: from ?IPV6:2003:cb:c742:c800:d74f:aec6:f8ac:558? (p200300cbc742c800d74faec6f8ac0558.dip0.t-ipconnect.de. [2003:cb:c742:c800:d74f:aec6:f8ac:558]) by smtp.gmail.com with ESMTPSA id 16-20020a05600c021000b003f50d6ee334sm7400593wmi.47.2023.05.22.01.21.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 May 2023 01:21:14 -0700 (PDT) Message-ID: Date: Mon, 22 May 2023 10:21:13 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 To: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, Anshuman Khandual 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> <9aa7d030-19b5-01df-70c0-86d8d6ab86a6@redhat.com> <87zg62eqm4.fsf@all.your.base.are.belong.to.us> <87lehikpu6.fsf@all.your.base.are.belong.to.us> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 0/7] riscv: Memory Hot(Un)Plug support In-Reply-To: <87lehikpu6.fsf@all.your.base.are.belong.to.us> 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-Rspamd-Queue-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DNFPshT EwGyOZnU DyCfGt8bATVLShxsPx1ouufUkCuVkNSp5GKWGnNmVs68NK7JgYi8eMoqIqQvTfUVuiZAa1uQpCaNhsezO9Icy8ifY9Ps/eJPQF86mZ/02rUCpw/UWdl0hQ82DR5CXm/Vrb4S63ZiQY+iT8jryk3WHpw1g+CkKfyrPKTGbl3kEmj3OA5tbz05+KIcehuMGK0X71n5dnetvAm4gNWgfDGRmN8xkjGpXZnLVRJCa0cVNExgSoIe7rWJPgVtB6Mq2BY1oa+07clZ4cwrt6rQymXSmBNSqExK2Z5piLK5/xz4bZbnd8lY/GT1yCJoUBG8dvMC4UPpMYUCwj5RdJarISrmYb/5xoVBk2pD0gulIVWCtp8NB6o8lU7TDvzHyzSfFXpCwO7HgMKtbByFnwLnBPrpkiCRrCFiO7MjOnQfg3JRqACB3xGzA4nL/030YAGd3Jj8JiD1e2Zwh3nnwV0R8Pm0ux41o/bKkGP1tKqOJILWZgIEBMYGchXzh4sHn3byM8msDocBNtCOo3QV/RAcNoMIGs7yQ24CEIg5ddbljp8AwPJ4TF50= 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 21.05.23 11:15, Björn Töpel wrote: > Hi David and Anshuman! > > Björn Töpel writes: > >> David Hildenbrand writes: >> >>> 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 >>>> ============================================== >> >> [...] >> >>> >>> Cool stuff! I'm fairly busy right now, so some high-level questions upfront: >> >> No worries, and no rush! I'd say the v1 series was mainly for the RISC-V >> folks, and I've got tons of (offline) comments from Alex -- and with >> your comments below some more details to figure out. > > One of the major issues with my v1 patch is around init_mm page table > synchronization, and that'll be part of the v2. > > I've noticed there's a quite a difference between x86-64 and arm64 in > terms of locking, when updating (add/remove) the init_mm table. x86-64 > uses the usual page table locking mechanisms (used by the generic > kernel functions), whereas arm64 does not. > > How does arm64 manage to mix the "lock-less" updates (READ/WRITE_ONCE, > and fences in set_p?d+friends), with the generic kernel ones that uses > the regular page locking mechanism? > > I'm obviously missing something about the locking rules for memory hot > add/remove... I've been reading the arm64 memory hot add/remove > series, but none the wiser! ;-) In general, memory hot(un)plug is serialized on a high level using the mem_hotplug_lock. For example, in pagemap_range() or in add_memory_resource(), we grab that lock in write mode. So we'll never see memory getting added/removed concurrently from the direct map. From what I recall, the locking on the arch level is required for concurrent (direct mapping) page table modifications that target virtual address ranges adjacent to the ranges we hot(un)plug: CONFIG_ARCH_HAS_SET_DIRECT_MAP and vmalloc come to mind. For example, if a range would be mapped using a large PUD, but we have to unplug it partially (unplugging memory part of bootmem), we'd have to replace the large PUD by a PMD table first. That change (that could affect other concurrent page table walkers/operations) has to be synchronized. I guess to which degree this applies to riscv depends on the virtual memory layout, direct mapping granularity and features (e.g., CONFIG_ARCH_HAS_SET_DIRECT_MAP). One trick that arm64 implements is, that it only allows hotunplugging memory that was hotplugged (see prevent_bootmem_remove_notifier()). That might just rule out such problematic cases that require locking completely, and the high-level mem_hotplug_lock sufficient. -- Thanks, David / dhildenb