Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12478335rwl; Tue, 3 Jan 2023 15:19:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXs+tQzMeoe8mBQF2OJ9+QPKBvbMqBsI2Onk4NzAkCI7VRDJmUQVzeaNysxREWHbtQqtksED X-Received: by 2002:a05:6a20:2a9f:b0:a4:ac45:8a68 with SMTP id v31-20020a056a202a9f00b000a4ac458a68mr71291509pzh.11.1672787956449; Tue, 03 Jan 2023 15:19:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672787956; cv=none; d=google.com; s=arc-20160816; b=R4Pb0OLZ+ToWkhmQj4USRnN20FIHmIqUVROBjIbY1Xhu6Q7cw+1f45TZI0YgmAsjPY gA59L/KcwNPqkD3uplreX3GFptp+rNsP6S72RJ6QzZp/U1R+jVP0Jv3aHHXSpmO4qthS Ur0rfv/XFhooydZhPJazxpJdbe4UJBl42WDqmPxjVDSQBKepqHq03pciM/WqmyPXxGQC fVs++49hq218ecn5xbAWXI+4Voew88GwvbQFbJXr6IPJe91LYoaa7A3BZ/ABRwBW1Ln5 07yI5H1lt890kuuGI78EaHACbwGdD59Bacprcx1azuBWWTtmlXsnE6t0pWbYXYJgIhKq 0SMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wms9vJRG39Hnpaj8L9AdTUEiKoOujl8Zc1PlfJpuAvc=; b=m0J7rij3XWtFrTVdLJ48kHN3Jr7SXA2f9Hl8cMAAg9QJexuyGnD0c/XOPpDLrcwNlc h+nXpp4pkScCnsPNUnOpYxfRO8chrw3WS+r+9NHt644dIN9C09nLbh+3WLc092NojUVh AFMi4aejHForgtu+px00s77jq7NHyLAueij75m3b88vOGwQecqq/HONlkHAyk5PpC4Tu NEsw2HM8dJ2tCXfQ0xUCTeeto3wTsI7wgSiSRUpCFnYfcHA/qnIPc0Tir3b1WeOaWmnt Ie9wM7MQuYbNVLvvFaMTpw0CahpYFexjYhBsVFNUbR3wORfHBXpzg1aA1O+idhHqlIXm i0Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=h9725tfa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j71-20020a63804a000000b0049694f10986si30331775pgd.697.2023.01.03.15.19.08; Tue, 03 Jan 2023 15:19:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=h9725tfa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233936AbjACXGo (ORCPT + 59 others); Tue, 3 Jan 2023 18:06:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233577AbjACXGm (ORCPT ); Tue, 3 Jan 2023 18:06:42 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3D9E13F3C for ; Tue, 3 Jan 2023 15:06:41 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id n65-20020a17090a2cc700b0021bc5ef7a14so32684982pjd.0 for ; Tue, 03 Jan 2023 15:06:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=wms9vJRG39Hnpaj8L9AdTUEiKoOujl8Zc1PlfJpuAvc=; b=h9725tfa5hdVaq1HRKMg38pT3bnSdsZu1gYJxnR5d5+gbg52PuYQIv5wBFlDJhO9bS mI84Q+hhI20dHQcSkgxSkQf4wP4qmQP1LNIFkAq/VomPx4jdE8OPYacqy/eeBE+fylf/ swL/aH5bYQ07AmejSAYJHcZh07QDgP5xrRt6bm8Q1etUwfrKAFos+bdLOE5+JE6PBi3U sFDQ9Dps9Lxs/yyXs3jQijpfnjXJqK66rKL3UJSPZwrJDKJketPNn4qX/18FtXZzHbno RPLBoKWopziiN34rcQN0qmYINuJwWj5jMTrSB3yTnXpqqbcBJ6htLtlQbhw4piMR+QeH MFPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=wms9vJRG39Hnpaj8L9AdTUEiKoOujl8Zc1PlfJpuAvc=; b=l/mmY/sBgDIjkdSNrnOrDEAJF1AmJUAHKqKOYUZHb2YfOjbI+aa+bhhs6Yu4qlJpCW u/AuohcpPamZ7t2zs12qCyiWRYn9G14DBID7jZJxX9vG2tVBOkJjaiWwG98Ra8i1mVRW 3P0L5iKo0SsFjFcIIBQZFBiJCX9T4oKzTmuWHzN7ONUuF7f6MaueBEXx2wxRNssX+e+p 61zjAZ6w8U6w/f6Gwrw1uNWOvRIqEZObyqsSsFvYSTvEHJbol31M9VGhFsBDAaD87R5q wPKGkwsEY2zJmGxXgKpcMXtbI6RdsEyVu+a7pFkC5VyqPR93vSpfmTsxVlz/f1GiC1f+ RPXg== X-Gm-Message-State: AFqh2krlxO3wIttebh7iQmGkJgIzjshSQQgm2B8O23seJjQS9NPUX7M+ rrh9bi1ugF4Uw5rMlA7ItpOI2EPRamO5sWfO X-Received: by 2002:a05:6a20:2a9f:b0:a4:efde:2ed8 with SMTP id v31-20020a056a202a9f00b000a4efde2ed8mr5044243pzh.0.1672787201272; Tue, 03 Jan 2023 15:06:41 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id b27-20020aa7951b000000b00580c8a15d13sm19479380pfp.11.2023.01.03.15.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 15:06:40 -0800 (PST) Date: Tue, 3 Jan 2023 23:06:37 +0000 From: Sean Christopherson To: "Wang, Wei W" Cc: Chao Peng , "Qiang, Chenyi" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-fsdevel@vger.kernel.org" , "linux-arch@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 , Arnd Bergmann , Naoya Horiguchi , Miaohe Lin , "x86@kernel.org" , "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , "Lutomirski, Andy" , "Nakajima, Jun" , "Hansen, Dave" , "ak@linux.intel.com" , "david@redhat.com" , "aarcange@redhat.com" , "ddutile@redhat.com" , "dhildenb@redhat.com" , Quentin Perret , "tabba@google.com" , Michael Roth , "Hocko, Michal" Subject: Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes Message-ID: References: <20221202061347.1070246-1-chao.p.peng@linux.intel.com> <20221202061347.1070246-3-chao.p.peng@linux.intel.com> <1c9bbaa5-eea3-351e-d6a0-cfbc32115c82@intel.com> <20230103013948.GA2178318@chaop.bj.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 03, 2023, Wang, Wei W wrote: > On Tuesday, January 3, 2023 9:40 AM, Chao Peng wrote: > > > Because guest memory defaults to private, and now this patch stores > > > the attributes with KVM_MEMORY_ATTRIBUTE_PRIVATE instead of > > _SHARED, > > > it would bring more KVM_EXIT_MEMORY_FAULT exits at the beginning of > > > boot time. Maybe it can be optimized somehow in other places? e.g. set > > > mem attr in advance. > > > > KVM defaults to 'shared' because this ioctl can also be potentially used by > > normal VMs and 'shared' sounds a value meaningful for both normal VMs and > > confidential VMs. > > Do you mean a normal VM could have pages marked private? What's the usage? > (If all the pages are just marked shared for normal VMs, then why do we need it) No, there are potential use cases for per-page attribute/permissions, e.g. to make select pages read-only, exec-only, no-exec, etc... > > As for more KVM_EXIT_MEMORY_FAULT exits during the > > booting time, yes, setting all memory to 'private' for confidential VMs through > > this ioctl in userspace before guest launch is an approach for KVM userspace to > > 'override' the KVM default and reduce the number of implicit conversions. > > Most pages of a confidential VM are likely to be private pages. It seems more efficient > (and not difficult to check vm_type) to have KVM defaults to "private" for confidential VMs > and defaults to "shared" for normal VMs. If done right, the default shouldn't matter all that much for efficiency. KVM needs to be able to effeciently track large ranges regardless of the default, otherwise the memory overhead and the presumably cost of lookups will be painful. E.g. converting a 1GiB chunk to shared should ideally require one entry, not 256k entries. Looks like that behavior was changed in v8 in response to feedback[*] that doing xa_store_range() on a subset of an existing range (entry) would overwrite the entire existing range (entry), not just the smaller subset. xa_store_range() does appear to be too simplistic for this use case, but looking at __filemap_add_folio(), splitting an existing entry isn't super complex. Using xa_store() for the very initial implementation is ok, and probably a good idea since it's more obviously correct and will give us a bisection point. But we definitely want a more performant implementation sooner than later. The hardest part will likely be merging existing entries, but that can be done separately too, and is probably lower priority. E.g. (1) use xa_store() and always track at 4KiB granularity, (2) support storing metadata in multi-index entries, and finally (3) support merging adjacent entries with identical values. [*] https://lore.kernel.org/all/CAGtprH9xyw6bt4=RBWF6-v2CSpabOCpKq5rPz+e-9co7EisoVQ@mail.gmail.com