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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6B9BCCA479 for ; Fri, 17 Jun 2022 21:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235147AbiFQV1c (ORCPT ); Fri, 17 Jun 2022 17:27:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232538AbiFQV1b (ORCPT ); Fri, 17 Jun 2022 17:27:31 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2F193A18B for ; Fri, 17 Jun 2022 14:27:30 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id a17so2911641pls.6 for ; Fri, 17 Jun 2022 14:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=4Nh/ioaLxS4TiMuv6mrO3BuuJxs5edtEcbJCJ0DlzHg=; b=kqV10ZowD4mEAwkhnGeH7Vi46uyd6cVb+D27K/8D7q4ZgbepI0UMc7Xg/GhUj7mWCn sUXIO1GdA6DWiQTudDzJU8yc0x7fO1CRRIYu+qGUSrN9fwrVOrLdD1rfHGdBXyFAfxoY HUeLpXo40NmxK6NMGADGQ7EfuqeHEdheydvWwcQvIfZxA5YfRVWSMGNAX2325hWiHuHY 7FXv22PI/DmPa7E2x1nANjza+zy8ei0HlKM5niFMLK6Y/yuw6Rd/UBQlspC2hX9x3Qb4 bTlUA9qVQpHAf6cfcS9FKqlK43DFOWeREbCmJaIPzqYk2+TsXXbIzRcnGQoReMxVEUKW K2kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4Nh/ioaLxS4TiMuv6mrO3BuuJxs5edtEcbJCJ0DlzHg=; b=d+7SfzRppTj0SBW/EPWDfuC4AcZ+R49mQzqHTvnCxKQQW8oX25aiAqS4ij4+TexFHi pRZdtjn3mTk0NSXscvcmdaAcyT1F3QTj2rG9cBIFI1HlUVGlqYd30mrpVr9VBUAWDm/4 y85SGRC575jGkYOF8CNQzg7sBENaeV4jkNAzAbqNrhhSfpYax04H/3GiFF/AnlcPyOBt q4faIA9hNwXmU3+yL4eg406+Mz8E3DdDHBQ55bCQ6Sr8fZvavEZh6yS//j4wlHnjeBz3 R4ZwZz69Xzer8KdkvpYO4dAZNuSNUiVmd/nKnpKSIRBbSAJYXK3LCI445G7aFiXJ9prj W20Q== X-Gm-Message-State: AJIora8lPklxNrtEfEVdtBcy9EU5c8a/EMmhOGZx4QC91rRsCGbnFwMi r6gFqKE9vYviq+sMucA63XKz7g== X-Google-Smtp-Source: AGRyM1uRS2fAbjyxhFU2PYlmkBtwm8UeO62IZrWZixGAXkVAe6FeSFCI9nOgPKmO0Bfh0yLM2ya5lQ== X-Received: by 2002:a17:90a:4503:b0:1ea:4718:829f with SMTP id u3-20020a17090a450300b001ea4718829fmr12496982pjg.103.1655501249895; Fri, 17 Jun 2022 14:27:29 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id f2-20020a62db02000000b0051868677e6dsm4218356pfg.51.2022.06.17.14.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 14:27:29 -0700 (PDT) Date: Fri, 17 Jun 2022 21:27:25 +0000 From: Sean Christopherson To: Chao Peng Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com Subject: Re: [PATCH v6 4/8] KVM: Extend the memslot to support fd-based private memory Message-ID: References: <20220519153713.819591-1-chao.p.peng@linux.intel.com> <20220519153713.819591-5-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Fri, Jun 17, 2022, Sean Christopherson wrote: > > @@ -110,6 +133,7 @@ struct kvm_userspace_memory_region { > > */ > > #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0) > > #define KVM_MEM_READONLY (1UL << 1) > > +#define KVM_MEM_PRIVATE (1UL << 2) > > Hmm, KVM_MEM_PRIVATE is technically wrong now that a "private" memslot maps private > and/or shared memory. Strictly speaking, we don't actually need a new flag. Valid > file descriptors must be >=0, so the logic for specifying a memslot that can be > converted between private and shared could be that "(int)private_fd < 0" means > "not convertible", i.e. derive the flag from private_fd. > > And looking at the two KVM consumers of the flag, via kvm_slot_is_private(), they're > both wrong. Both kvm_faultin_pfn() and kvm_mmu_max_mapping_level() should operate > on the _fault_, not the slot. So it would actually be a positive to not have an easy > way to query if a slot supports conversion. I take that back, the usage in kvm_faultin_pfn() is correct, but the names ends up being confusing because it suggests that it always faults in a private pfn. diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index b6d75016e48c..e1008f00609d 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4045,7 +4045,7 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) return RET_PF_EMULATE; } - if (fault->is_private) { + if (kvm_slot_can_be_private(slot)) { r = kvm_faultin_pfn_private(vcpu, fault); if (r != RET_PF_CONTINUE) return r == RET_PF_FIXED ? RET_PF_CONTINUE : r; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 31f704c83099..c5126190fb71 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -583,9 +583,9 @@ struct kvm_memory_slot { struct kvm *kvm; }; -static inline bool kvm_slot_is_private(const struct kvm_memory_slot *slot) +static inline bool kvm_slot_can_be_private(const struct kvm_memory_slot *slot) { - return slot && (slot->flags & KVM_MEM_PRIVATE); + return slot && !!slot->private_file; } static inline bool kvm_slot_dirty_track_enabled(const struct kvm_memory_slot *slot)