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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C88D0C4167D for ; Wed, 1 Nov 2023 13:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=wPogpYqDAXQX8HTgsmMEdNXOqDtslJJ+T/19tSicFMI=; b=0uM7q+8Oa+KzYIqeXrMFHHwrqN +Hq4vI5DJUhIxkKcFVFkTc1UGjrWV6dSba84qrIA0WXFiTOtZkgACtP+w7YviETcIvhgU+J7KU++Q jtUzgXR9QuMnRP23bGUhnDsjwO2dGwHUdLVp9winsyPfcz7B4sCjLxL1pdWVEAO4FBNg4Dod+lwoS U2CTApFXcRV0pCCp9d4yLg8NDP9/sV0ePTIcWxEZWGrRVkEf7AE1tSr9FjYdT2xmdoak9/yeTkoJD inVaksIvTyXKDfTp3rjOASlW2NcIq4H6EWZVbZS20IxYzvFF87G7kV/SyDgTk7wFzu+tAIyEYkPn3 oxvK0QrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qyBTm-007alA-0o; Wed, 01 Nov 2023 13:41:54 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qyBTi-007ais-2P for linux-arm-kernel@lists.infradead.org; Wed, 01 Nov 2023 13:41:52 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7aa161b2fso80286597b3.2 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=1698846107; x=1699450907; darn=lists.infradead.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=TxdC4ML5TuMh93VSDIBzefA8qXHE98Qp7DkzFy+i+0QcJgxEmBgxKmoMnY31GfO9Ts gDtoNMplscagESRttUr450U4+LUtViT8OE7gacG5SirW+Je8Jxobnh6HNWmst3ZDiPgG uour4Nxl6HgnqdaCxqzqyMhSSObKEf5sh71j2AtfIrV51wqqi8qXrYDV9ljHdB4x05jI MguS6b4M/dRvOLlkrbFJxPU1ei6wJ2Cxa5+mdwGLD8clMhJhMrY2LHUjsAYHAwx73ur9 1s4EPR6dpmavK9dahKPREYfcNgrCv0ISEmhCQgOF2Jmx2py+HHhJsBEL6SLIlemGekp9 KtAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698846107; x=1699450907; 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=p5s+0OEoH1sw1dJE8l2teMZKjS6CCzCCm9w6V5/959tfOgXRh2U4VNlyb1Zqdihq6D ucWAI6sRT6Nk27CeNcfOmcL993GfSdMpC8icLvA0axhXvga6tiOY0FZ5oJz2BNeARHuB ErtSB/XAVoV2z8jesH6eWZMQhjd10BlACcr7RLDX8RVq3pdNHbTOV+2Xhm7+/QFuy6Eq WNnJogndaE/gMjYpclihrrsVwD2vqTUFrON6dYAID0pg7LblzcfzH0GSyghcdoFwK1n3 zD49fnmyZHuI3ylC5acAII2QwZg3tv3nbodS8rBObxC3iLQOjJ0weJmtp3x8QPBH6CHB FBew== X-Gm-Message-State: AOJu0YxvWpqwmk7DmD0CKDLwKCL70EeeRyFdddSveoYwWgsmb3NpWDA/ hemZ/b5gY9KZoFInAUFFZxfWslEg4hs= X-Google-Smtp-Source: AGHT+IEsRM1yQnQClQeVqyoNLxT9cYgRny7PWezkHcY0wXTm/cdeLyJgnrb+5OZENHYJQKvQlFBt8yx8E+I= 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" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231101_064150_790856_A6C07250 X-CRM114-Status: GOOD ( 30.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel