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 3C54AC52D73 for ; Thu, 8 Aug 2024 21:47:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9AA6B6B0088; Thu, 8 Aug 2024 17:47:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9598E6B008A; Thu, 8 Aug 2024 17:47:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D3E46B008C; Thu, 8 Aug 2024 17:47:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5CDD36B0088 for ; Thu, 8 Aug 2024 17:47:54 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CDACD1201D6 for ; Thu, 8 Aug 2024 21:47:53 +0000 (UTC) X-FDA: 82430416026.15.5052F7B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id A84561A000E for ; Thu, 8 Aug 2024 21:47:51 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fMmTWglI; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723153662; a=rsa-sha256; cv=none; b=4iMrTG7c/261lbPTZ54Rn0HY0ucEycTXyIHJ9yqbTjZYx3U8XJ1EB2jZCXrubuCRKieItL tCsddYQIBT1pYOwySBSFVeVV6nKSnOti0OGJsKE9XzDAxMY3JlM48z0bJxMaYB6+ufiSTZ Wj0o7p4hJ+VuudH+JBtcAqoG4iVMWGk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fMmTWglI; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723153662; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y4cQ3dGvl+e98q+IJj301khv7EGPDrAUXWE89nsHh7w=; b=fdPhs1IzXD+IDFK72TIPof5ol/MPuAAe/mW9YshumNzHHAUYzX3OvhviM7o06eQ4axoYR4 9zSqdz4kqshmvwK2lapH5bdU/P+BEswuXJVabk8e1wZxoWgz+c3Mdw8LqpxiIURZztf4m5 K7CX/vGzd6yXxGEQzRhFVbm+5Qjg2RY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723153671; 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=y4cQ3dGvl+e98q+IJj301khv7EGPDrAUXWE89nsHh7w=; b=fMmTWglIu/fehKMmR18U820CqEY0EUkJ2/NAt0Rq3I1UUyCQX3DjC6NXz4jqCKjGxfn/BE BfkVzFAr51ei61I/Nsc7pd9FtUy5Kyop1D2vWkqYhSMXBU7xXNTgNzO9MkNJTII7Mxp6Mt 0PNYG1doRjTCQAfFf4BQuwp4nXmpwXA= Received: from mail-ua1-f71.google.com (mail-ua1-f71.google.com [209.85.222.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-4NcdtigVN9aXQFyLISwXfg-1; Thu, 08 Aug 2024 17:47:49 -0400 X-MC-Unique: 4NcdtigVN9aXQFyLISwXfg-1 Received: by mail-ua1-f71.google.com with SMTP id a1e0cc1a2514c-81fb65857e0so62734241.3 for ; Thu, 08 Aug 2024 14:47:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723153669; x=1723758469; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=y4cQ3dGvl+e98q+IJj301khv7EGPDrAUXWE89nsHh7w=; b=UvhKwKPgpS5EbuZ8TmJad/HMUErRqpJaprqKz+dXdZ6t4ChBYu2BAJuTfFFkW0Qb43 K7MxjDyQln++fbWEZK2BELD+MsRkrmwnNp7ZkByPNkM0AQKR2TjFxRrqcQcjyKTZB2dc 4oshSNcy1uS0F0mQjwLgk456e7Nenst4eAXEY+MZLTgkD+aKS+niaeFSh4iGI2JaZYu6 YNrQsA8TD3zOSMksPvP/kS4dmUi05XNHio4XAmlrasdZvxPJ3sCMvSaxFtljbX62nPi5 T2Cvz3A8RqWMv11SgXKccN9UZjFZLBTB4ffqH4oUv1mlEFf1t1kCORCM7AuQY62DxFHQ TXBA== X-Forwarded-Encrypted: i=1; AJvYcCX/LIMVncV3f44Rzk+6HtPmOYDfaAhHrF9D+rWAAnGcDPocwJ6N/OAHx7nYaJOfwjA1Z8Zqx9xvffEOEaon2D75OUs= X-Gm-Message-State: AOJu0YyOld/dt/KPCMBk437WM8StzToLfd0QXhXEKF5zBLECmVrJd8u3 Mke90gsST1JTD3maYk9ApkPdKeMAY0qW8bwgQtK6Ag0nHHHM7IHxfNn2uiY5j6d8LdWexYaBRe5 APPEiPxSuhudJ9GESiNhGowSnFxG1885WBBHm634dte5UUhXt X-Received: by 2002:a05:6122:1696:b0:4f4:959b:8342 with SMTP id 71dfb90a1353d-4f9028ededfmr2281585e0c.2.1723153669041; Thu, 08 Aug 2024 14:47:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBUCPV/3BJaIuZdMerz+8wpoNJAPGodVbwYONTfq25mwe5QVB/HX82z8YwrBUiUNO7Dj9CXg== X-Received: by 2002:a05:6122:1696:b0:4f4:959b:8342 with SMTP id 71dfb90a1353d-4f9028ededfmr2281559e0c.2.1723153668575; Thu, 08 Aug 2024 14:47:48 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a3785e13fdsm198784985a.34.2024.08.08.14.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 14:47:48 -0700 (PDT) Date: Thu, 8 Aug 2024 17:47:44 -0400 From: Peter Xu To: Sean Christopherson Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Aneesh Kumar K . V" , Michael Ellerman , Oscar Salvador , Dan Williams , James Houghton , Matthew Wilcox , Nicholas Piggin , Rik van Riel , Dave Jiang , Andrew Morton , x86@kernel.org, Ingo Molnar , Rick P Edgecombe , "Kirill A . Shutemov" , linuxppc-dev@lists.ozlabs.org, Mel Gorman , Hugh Dickins , Borislav Petkov , David Hildenbrand , Thomas Gleixner , Vlastimil Babka , Dave Hansen , Christophe Leroy , Huang Ying , kvm@vger.kernel.org, Paolo Bonzini , David Rientjes Subject: Re: [PATCH v4 2/7] mm/mprotect: Push mmu notifier to PUDs Message-ID: References: <20240807194812.819412-1-peterx@redhat.com> <20240807194812.819412-3-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspam-User: X-Rspamd-Queue-Id: A84561A000E X-Rsp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cvQnvAA2BGUduZUV/4jRTXEPN+klREgf8zOxwosqRDaGI8e8Fk93lCk2hXc75tcw5gzAGz+Ds73ylUgcQWaRB/JjQhnY/I2/zKIgFUKTRocrTbb4hAvmh7l+5ddmaduYyKGIwiG4ydFfKGBhR7ky5O4WyJY0Iw+uM8QFocUy317B9R1qCqwZov61wVqEvpTm1y7TI+qclWWLu/1HXxE9ooE6XP6BXuO1HZeFaKjwcG6SLu92Bsyis9rwSYwQ0yhWkHxG6qqmZej6MCMpJyl9eVqq4LWgH2/0yg7HpEyuQuixg== 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: List-Subscribe: List-Unsubscribe: On Thu, Aug 08, 2024 at 02:31:19PM -0700, Sean Christopherson wrote: > On Thu, Aug 08, 2024, Peter Xu wrote: > > Hi, Sean, > > > > On Thu, Aug 08, 2024 at 08:33:59AM -0700, Sean Christopherson wrote: > > > On Wed, Aug 07, 2024, Peter Xu wrote: > > > > mprotect() does mmu notifiers in PMD levels. It's there since 2014 of > > > > commit a5338093bfb4 ("mm: move mmu notifier call from change_protection to > > > > change_pmd_range"). > > > > > > > > At that time, the issue was that NUMA balancing can be applied on a huge > > > > range of VM memory, even if nothing was populated. The notification can be > > > > avoided in this case if no valid pmd detected, which includes either THP or > > > > a PTE pgtable page. > > > > > > > > Now to pave way for PUD handling, this isn't enough. We need to generate > > > > mmu notifications even on PUD entries properly. mprotect() is currently > > > > broken on PUD (e.g., one can easily trigger kernel error with dax 1G > > > > mappings already), this is the start to fix it. > > > > > > > > To fix that, this patch proposes to push such notifications to the PUD > > > > layers. > > > > > > > > There is risk on regressing the problem Rik wanted to resolve before, but I > > > > think it shouldn't really happen, and I still chose this solution because > > > > of a few reasons: > > > > > > > > 1) Consider a large VM that should definitely contain more than GBs of > > > > memory, it's highly likely that PUDs are also none. In this case there > > > > > > I don't follow this. Did you mean to say it's highly likely that PUDs are *NOT* > > > none? > > > > I did mean the original wordings. > > > > Note that in the previous case Rik worked on, it's about a mostly empty VM > > got NUMA hint applied. So I did mean "PUDs are also none" here, with the > > hope that when the numa hint applies on any part of the unpopulated guest > > memory, it'll find nothing in PUDs. Here it's mostly not about a huge PUD > > mapping as long as the guest memory is not backed by DAX (since only DAX > > supports 1G huge pud so far, while hugetlb has its own path here in > > mprotect, so it must be things like anon or shmem), but a PUD entry that > > contains pmd pgtables. For that part, I was trying to justify "no pmd > > pgtable installed" with the fact that "a large VM that should definitely > > contain more than GBs of memory", it means the PUD range should hopefully > > never been accessed, so even the pmd pgtable entry should be missing. > > Ah, now I get what you were saying. > > Problem is, walking the rmaps for the shadow MMU doesn't benefit (much) from > empty PUDs, because KVM needs to blindly walk the rmaps for every gfn covered by > the PUD to see if there are any SPTEs in any shadow MMUs mapping that gfn. And > that walk is done without ever yielding, which I suspect is the source of the > soft lockups of yore. > > And there's no way around that conundrum (walking rmaps), at least not without a > major rewrite in KVM. In a nested TDP scenario, KVM's stage-2 page tables (for > L2) key off of L2 gfns, not L1 gfns, and so the only way to find mappings is > through the rmaps. I think the hope here is when the whole PUDs being hinted are empty without pgtable installed, there'll be no mmu notifier to be kicked off at all. To be explicit, I meant after this patch applied, the pud loop for numa hints look like this: FOR_EACH_PUD() { ... if (pud_none(pud)) continue; if (!range.start) { mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_VMA, 0, vma->vm_mm, addr, end); mmu_notifier_invalidate_range_start(&range); } ... } So the hope is that pud_none() is always true for the hinted area (just like it used to be when pmd_none() can be hopefully true always), then we skip the mmu notifier as a whole (including KVM's)! Thanks, -- Peter Xu