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 5259EC433EF for ; Wed, 5 Jan 2022 20:52:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B2AB6B0074; Wed, 5 Jan 2022 15:52:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 960ED6B0075; Wed, 5 Jan 2022 15:52:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 801916B0078; Wed, 5 Jan 2022 15:52:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id 711056B0074 for ; Wed, 5 Jan 2022 15:52:45 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2596C9636C for ; Wed, 5 Jan 2022 20:52:45 +0000 (UTC) X-FDA: 78997432290.01.DF3FCE5 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf18.hostedemail.com (Postfix) with ESMTP id 908A11C000A for ; Wed, 5 Jan 2022 20:52:32 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id lr15-20020a17090b4b8f00b001b19671cbebso272205pjb.1 for ; Wed, 05 Jan 2022 12:52:44 -0800 (PST) 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=JbxoBomdcCqOqJFCBjDh/uGAgy3A+q4n81f2FmBqdOo=; b=lcHlW5fa9jFHIO/4BxpYp/Tmy5m91nF1IHDBqc7vkJc8rcl2mWmRRDknMp0CMLyVxf XG6AinG8ofa2FW/grJcmrznnxnQHMXttxllF9zF1ag/Jj8VLCCwLTO3HY4SCjlg2UOKE a+kMrofibgpexqlucg3jyspkX/e8zA6WbfAoOCzZ+l5q9hnkZ4u1+hn00u80p+ugmte0 FA+8o29Vyy3Jr5vKE3NEi0QEsEVR0MmdN6Ji77oqhe7fzz96jVnlyjBGeGVvEoGdMfXC VfzL8p3VVm36IH4JWgcFPStvAK81KBpBDqAZYWu4llyuPioega3WxWx8dVpGNUCvWcfd 19CA== 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=JbxoBomdcCqOqJFCBjDh/uGAgy3A+q4n81f2FmBqdOo=; b=WdQwz40tPnoHmrlAl/sgSdxixypG0AYCfELYgwtU1aG887nqW7syexBBCJHG5Lngbl M+3xVA5ot2AYh0QeYix3ZU03hsTN1ax12pVn6IfBRAm5TO9gRhvWWEwsvq3bUCBAxb6E 1YZc6l5CKSGJAd7fjGZf33uokyzUopJci5hvYcNVIUyJLDeHDqzKtyM9ODYfPb8qdc7y kuDPgjl7wy1QfhKC98fKKCcYlaiAtm42avI+AI0k+mLioBBNgYVobWs7XYrIyQMGWv6h 1854Wibk6UYQRvzpSuKK7TpyLvZez8PCh6e9xZvwACoHmyoP2FoBs0GhCOyeWn6ujWrb lngw== X-Gm-Message-State: AOAM533t/z9JKOeKkT4TNWsxEOXlF5y1vHqFOzyjvIV5OTu9EoQKh1iP xkmKGgZk/lTEwc/VMFLx4ZnELA== X-Google-Smtp-Source: ABdhPJyR0C1DrkXymrvkpk2S7sD/y26XNYIobEYJs+EPEbw+DMrYoag4fnJJYUy5LWVuQEwzegRnSA== X-Received: by 2002:a17:90a:ad07:: with SMTP id r7mr6153665pjq.67.1641415963380; Wed, 05 Jan 2022 12:52:43 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id h7sm28516pfv.35.2022.01.05.12.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jan 2022 12:52:42 -0800 (PST) Date: Wed, 5 Jan 2022 20:52:39 +0000 From: Sean Christopherson To: Yan Zhao Cc: Chao Peng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@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 , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, john.ji@intel.com, susie.li@intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com Subject: Re: [PATCH v3 kvm/queue 14/16] KVM: Handle page fault for private memory Message-ID: References: <20211223123011.41044-1-chao.p.peng@linux.intel.com> <20211223123011.41044-15-chao.p.peng@linux.intel.com> <20220104014629.GA2330@yzhao56-desk.sh.intel.com> <20220104091008.GA21806@chaop.bj.intel.com> <20220104100612.GA19947@yzhao56-desk.sh.intel.com> <20220105062810.GB25283@chaop.bj.intel.com> <20220105075356.GB19947@yzhao56-desk.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220105075356.GB19947@yzhao56-desk.sh.intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 908A11C000A X-Stat-Signature: g9pxkgj8y1gxfh6humq64y17543j7grz Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lcHlW5fa; spf=pass (imf18.hostedemail.com: domain of seanjc@google.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1641415952-134311 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 Wed, Jan 05, 2022, Yan Zhao wrote: > Sorry, maybe I didn't express it clearly. > > As in the kvm_faultin_pfn_private(), > static bool kvm_faultin_pfn_private(struct kvm_vcpu *vcpu, > struct kvm_page_fault *fault, > bool *is_private_pfn, int *r) > { > int order; > int mem_convert_type; > struct kvm_memory_slot *slot = fault->slot; > long pfn = kvm_memfd_get_pfn(slot, fault->gfn, &order); > ... > } > Currently, kvm_memfd_get_pfn() is called unconditionally. > However, if the backend of a private memslot is not memfd, and is device > fd for example, a different xxx_get_pfn() is required here. Ya, I've complained about this in a different thread[*]. This should really be something like kvm_private_fd_get_pfn(), where the underlying ops struct can point at any compatible backing store. https://lore.kernel.org/all/YcuMUemyBXFYyxCC@google.com/ > Further, though mapped to a private gfn, it might be ok for QEMU to > access the device fd in hva-based way (or call it MMU access way, e.g. > read/write/mmap), it's desired that it could use the traditional to get > pfn without convert the range to a shared one. No, this is expressly forbidden. The backing store for a private gfn must not be accessible by userspace. It's possible a backing store could support both, but not concurrently, and any conversion must be done without KVM being involved. In other words, resolving a private gfn must either succeed or fail (exit to userspace), KVM cannot initiate any conversions. > pfn = __gfn_to_pfn_memslot(slot, fault->gfn, ...) > |->addr = __gfn_to_hva_many (slot, gfn,...) > | pfn = hva_to_pfn (addr,...) > > > So, is it possible to recognize such kind of backends in KVM, and to get > the pfn in traditional way without converting them to shared? > e.g. > - specify KVM_MEM_PRIVATE_NONPROTECT to memory regions with such kind > of backends, or > - detect the fd type and check if get_pfn is provided. if no, go the > traditional way. No, because the whole point of this is to make guest private memory inaccessible to host userspace. Or did I misinterpret your questions?