Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp920195rdb; Wed, 1 Nov 2023 06:42:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRBzOHahPyyEXh/nLjHZY2wPGFDvUnRXGrw37bXAxCcoRmxA1Nsy/8EJrWNvGMwUVuIeg8 X-Received: by 2002:a17:90a:357:b0:280:1729:b3e6 with SMTP id 23-20020a17090a035700b002801729b3e6mr11945268pjf.10.1698846122877; Wed, 01 Nov 2023 06:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698846122; cv=none; d=google.com; s=arc-20160816; b=l/ohmAoFd5LG9cfsSMDvn1f7d8sXMLhlZflJ2K5X04KSHgKTqDUrMOYKCC7oPRuDGp iDgbr7fqIwDiD32mP2elZ9n3Hsoj+uwveLWDUx3FB/m6Ea6NtWkCMVvJ62c6mmdaUMJk jTbB958RA859rEQWGk/Z2tNBc7cH8APzSIAPN+BMXTjMY4160C/3DUSIejL/bgl07EP2 a0PxxN3J1lXLQaGyJbtdcxFkOS+h1oWuqnLyDNTh4EkqfUBsctcyIxcEfOhkNTP0B1OH K/U2ppLnCtop2IZb2JtjiNS+POliYkuGraVijb359Rnpjp6iYtVqvE32BntFo3HTcbUa NpEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=nFf6aEaGwk5ej5JezQy0IgMN87WPAcTCXufwbiE3fug=; fh=1N3tQc5hMawYHUzIVFjUTPHHuyyOH103pPs30XYrSwQ=; b=Y1m9ktuZ8pWxPHoVK4bcVQSjfFtsyxB25yO6+2xvQjUZ2LHfJhos8UlQrjXNnsU6N0 nn9TBuPhkXQawwfhDIY4kSLcWPDyZJWNSW75m2fmS/5l3JwexhXy3/c9wlXmb1JYm+9P rSj4iNDob039on2JONzzdHHwkTcicG1Oj+kYrMlx/5sCNOq4oek0Cl+3GQqv1HtcilV8 cp/+EyT83jlRBcpCrhVRavLkjO3FuDhF32St79Kcf+MMAa9GXni3zlSnI6OxRFLxSPlZ +fbwe8MhaXg2dHHeLX3fDE2D3w3QHWYn8aFor7MgrwiP2hWQB3m+ucTHySGVq5mQ0rvR lzFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=R2O+hzqr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id y15-20020a17090a784f00b00280464bcd94si850815pjl.130.2023.11.01.06.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 06:42:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=R2O+hzqr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id EAAB5805A798; Wed, 1 Nov 2023 06:41:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229437AbjKANlw (ORCPT + 99 others); Wed, 1 Nov 2023 09:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229854AbjKANlu (ORCPT ); Wed, 1 Nov 2023 09:41:50 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82267F7 for ; Wed, 1 Nov 2023 06:41:47 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5b02ed0f886so61967927b3.0 for ; Wed, 01 Nov 2023 06:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698846106; x=1699450906; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nFf6aEaGwk5ej5JezQy0IgMN87WPAcTCXufwbiE3fug=; b=R2O+hzqrfXKjpVkCK7WWKNStZqPyF2cdxKhoLb11/ctjZo5ZPSp0q11vTaRIMqKh+G rTGHEntcK74whLXVzkwTEfg4kXFGvDFoyHYkdR0w4NkG++ha3FYomi7HyzXNxjoxUIK2 kcKweF9pJ+NEs74UZBMULXVN7G7SWL8wASy0+pNCqSNNPT1zkqvQfLHK78Y20NUzPNkc zAZ09oqc5lZHgiYL4DmQPGFbydmLOB6LzfwncWQjpui3CcXu6Wc1sVfHimGhI82PhfIb /7xN434TnAp+9QvKT0AHhWkz3sCvRmyo2aHZIig6PpsFsT18SvRKUf81x8cwxHJJ0j8r nrVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698846106; x=1699450906; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nFf6aEaGwk5ej5JezQy0IgMN87WPAcTCXufwbiE3fug=; b=XQpGq+WESPYhqiiCQyjLetE0/zokhdT9tZuTtDb14WsDcnB8h3wbiwNT4KiHU0bl49 kVQ9ahZdPnVvYtPO9UmRf1hFA3UHwJp0VTU3ljgfPjZJtdEN2zUIE4gcvd56cvuNBPgN 8IP0jxx0IeTJHSD2BXHVzr/m1XCPiRvBHzHgrMVprTGjEm2fnISWHpg3O1p5IKjBHEUr EoNjRxnJRfaBovHpHEvPqI1ZxaApyXUJ8CTUOLEiOMntRBpzXh6ZzSiEMgDCG/u2608u 9qwnNaY9xFUSMO/krIAhfynO+YQudNoDv9qTsiwLgRiuCTdFf/uMkL+JUD5zNRows+Zk d22A== X-Gm-Message-State: AOJu0YyMOiPWveUqbTKIhxlDgF0MIdk7SGZz0AWxVRD+P4NkEOALVN80 bi2ap7KVZjYhZiIgh7SzpUjRa8kAoKk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:e689:0:b0:5a7:bfcf:2cb8 with SMTP id p131-20020a0de689000000b005a7bfcf2cb8mr314827ywe.1.1698846106686; Wed, 01 Nov 2023 06:41:46 -0700 (PDT) Date: Wed, 1 Nov 2023 06:41:45 -0700 In-Reply-To: <92ba7ddd-2bc8-4a8d-bd67-d6614b21914f@intel.com> Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-18-seanjc@google.com> <7c0844d8-6f97-4904-a140-abeabeb552c1@intel.com> <92ba7ddd-2bc8-4a8d-bd67-d6614b21914f@intel.com> Message-ID: Subject: Re: [PATCH v13 17/35] KVM: Add transparent hugepage support for dedicated guest memory From: Sean Christopherson To: Xiaoyao Li Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , "=?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?=" , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 01 Nov 2023 06:42:00 -0700 (PDT) On Wed, Nov 01, 2023, Xiaoyao Li wrote: > On 10/31/2023 10:16 PM, Sean Christopherson wrote: > > On Tue, Oct 31, 2023, Xiaoyao Li wrote: > > > On 10/28/2023 2:21 AM, Sean Christopherson wrote: > > > > Extended guest_memfd to allow backing guest memory with transparent > > > > hugepages. Require userspace to opt-in via a flag even though there's no > > > > known/anticipated use case for forcing small pages as THP is optional, > > > > i.e. to avoid ending up in a situation where userspace is unaware that > > > > KVM can't provide hugepages. > > > > > > Personally, it seems not so "transparent" if requiring userspace to opt-in. > > > > > > People need to 1) check if the kernel built with TRANSPARENT_HUGEPAGE > > > support, or check is the sysfs of transparent hugepage exists; 2)get the > > > maximum support hugepage size 3) ensure the size satisfies the alignment; > > > before opt-in it. > > > > > > Even simpler, userspace can blindly try to create guest memfd with > > > transparent hugapage flag. If getting error, fallback to create without the > > > transparent hugepage flag. > > > > > > However, it doesn't look transparent to me. > > > > The "transparent" part is referring to the underlying kernel mechanism, it's not > > saying anything about the API. The "transparent" part of THP is that the kernel > > doesn't guarantee hugepages, i.e. whether or not hugepages are actually used is > > (mostly) transparent to userspace. > > > > Paolo also isn't the biggest fan[*], but there are also downsides to always > > allowing hugepages, e.g. silent failure due to lack of THP or unaligned size, > > and there's precedent in the form of MADV_HUGEPAGE. > > > > [*] https://lore.kernel.org/all/84a908ae-04c7-51c7-c9a8-119e1933a189@redhat.com > > But it's different than MADV_HUGEPAGE, in a way. Per my understanding, the > failure of MADV_HUGEPAGE is not fatal, user space can ignore it and > continue. > > However, the failure of KVM_GUEST_MEMFD_ALLOW_HUGEPAGE is fatal, which leads > to failure of guest memfd creation. Failing KVM_CREATE_GUEST_MEMFD isn't truly fatal, it just requires different action from userspace, i.e. instead of ignoring the error, userspace could redo KVM_CREATE_GUEST_MEMFD with KVM_GUEST_MEMFD_ALLOW_HUGEPAGE=0. We could make the behavior more like MADV_HUGEPAGE, e.g. theoretically we could extend fadvise() with FADV_HUGEPAGE, or add a guest_memfd knob/ioctl() to let userspace provide advice/hints after creating a guest_memfd. But I suspect that guest_memfd would be the only user of FADV_HUGEPAGE, and IMO a post-creation hint is actually less desirable. KVM_GUEST_MEMFD_ALLOW_HUGEPAGE will fail only if userspace didn't provide a compatible size or the kernel doesn't support THP. An incompatible size is likely a userspace bug, and for most setups that want to utilize guest_memfd, lack of THP support is likely a configuration bug. I.e. many/most uses *want* failures due to KVM_GUEST_MEMFD_ALLOW_HUGEPAGE to be fatal. > For current implementation, I think maybe KVM_GUEST_MEMFD_DESIRE_HUGEPAGE > fits better than KVM_GUEST_MEMFD_ALLOW_HUGEPAGE? or maybe *PREFER*? Why? Verbs like "prefer" and "desire" aren't a good fit IMO because they suggest the flag is a hint, and hints are usually best effort only, i.e. are ignored if there is a fundamental incompatibility. "Allow" isn't perfect, e.g. I would much prefer a straight KVM_GUEST_MEMFD_USE_HUGEPAGES or KVM_GUEST_MEMFD_HUGEPAGES flag, but I wanted the name to convey that KVM doesn't (yet) guarantee hugepages. I.e. KVM_GUEST_MEMFD_ALLOW_HUGEPAGE is stronger than a hint, but weaker than a requirement. And if/when KVM supports a dedicated memory pool of some kind, then we can add KVM_GUEST_MEMFD_REQUIRE_HUGEPAGE.