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 5F7DAC43334 for ; Thu, 21 Jul 2022 12:02:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 868CA6B0072; Thu, 21 Jul 2022 08:02:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F20F8E0003; Thu, 21 Jul 2022 08:02:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66CE08E0002; Thu, 21 Jul 2022 08:02:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 541C96B0072 for ; Thu, 21 Jul 2022 08:02:33 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AF104408DD for ; Thu, 21 Jul 2022 09:34:13 +0000 (UTC) X-FDA: 79710595986.09.7DA4199 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf25.hostedemail.com (Postfix) with ESMTP id 770AFA009A for ; Thu, 21 Jul 2022 09:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658396052; x=1689932052; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=wCb9PX4Sp0/BeSAl8rvIo3FQtV/S7LHLo0bGkTMYvrA=; b=TzkAWP+Pv3CskzZy/vJG0CkVSACKYXsYWaYW5QhOO4phG5R0jz+f2REW kuIn8dfuq4/BO3CuY7k17L3EpU/vMk8DYI0GzZTWjWPKHxPxceHZCamX8 Bfe0UigxHwe5HV7P1w4dLNd4bRzngonFJNentFTg/wx9EwDHgSbdQKVCC qupXC4wWR/LYBSc0e6tvRgo3T0bqv8qgFQPNPgC24JEVXcUmTmdL82gbV kzhNX0UfAwHtVD1lPyIWTVWB33KxSFzO+sKQX3bLX1JDvDKLq3ImS+MH4 nl7UMDNfWG6wwTgKBfTb0V19R1lK0tdvugQc0GdJ76aLbSbYCvVWQJ/Im Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10414"; a="287749094" X-IronPort-AV: E=Sophos;i="5.92,289,1650956400"; d="scan'208";a="287749094" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2022 02:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,289,1650956400"; d="scan'208";a="656666919" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.193.75]) by fmsmga008.fm.intel.com with ESMTP; 21 Jul 2022 02:33:56 -0700 Date: Thu, 21 Jul 2022 17:29:06 +0800 From: Chao Peng To: Wei Wang Cc: Sean Christopherson , "Gupta, Pankaj" , 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, linux-kselftest@vger.kernel.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 , Shuah Khan , 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, Muchun Song Subject: Re: [PATCH v7 11/14] KVM: Register/unregister the guest private memory regions Message-ID: <20220721092906.GA153288@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220706082016.2603916-1-chao.p.peng@linux.intel.com> <20220706082016.2603916-12-chao.p.peng@linux.intel.com> <20220719140843.GA84779@chaop.bj.intel.com> <36e671d2-6b95-8e4f-c2ac-fee4b2670c6e@amd.com> <20220720150706.GB124133@chaop.bj.intel.com> <45ae9f57-d595-f202-abb5-26a03a2ca131@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <45ae9f57-d595-f202-abb5-26a03a2ca131@linux.intel.com> ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TzkAWP+P; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf25.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 134.134.136.24) smtp.mailfrom=chao.p.peng@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658396053; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Qcz7OtGIEOUa2H2V9xa0DCimLJxIsRWVh36DrfqSijg=; b=4s4MxJbkUmhuX9ZVIddkrf3MxoZfhtI8Vf/iPrlOCSeYEeBr+fTZgWBLCtFWsDenf0xhYs o/nBw/Np9c9eKRGxI5nTEZsVFs/OjJ+r6ZgpbwsyAOt6Eh3b+Dy6UrvKMwtzggFlwDPZGl uAaVPI41dcED9Q+FtvA0RGKrGL/op90= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658396053; a=rsa-sha256; cv=none; b=FL9E9UocJnrE7wEaUBkpheDg4/7kwvsBbh2nrZnv3ZvDTyJbGCe+4RBnu2NMc/kMuBK70A j5ws7h/rB3rVI6gFD3g82vihSw7Z1RvMVx/fxhpMGjgAwQuPqdcqrcoI5mhx7s+WuWmiB2 Gt8tZKZRi8Jh+4gXQ6SdaLRZGSswaEM= X-Rspamd-Queue-Id: 770AFA009A Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TzkAWP+P; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf25.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 134.134.136.24) smtp.mailfrom=chao.p.peng@linux.intel.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: xdjm4xcekaysuzqmke7t6wk5amnz9uqi X-HE-Tag: 1658396052-77523 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 Thu, Jul 21, 2022 at 03:34:59PM +0800, Wei Wang wrote: > > > On 7/21/22 00:21, Sean Christopherson wrote: > > On Wed, Jul 20, 2022, Gupta, Pankaj wrote: > > > > > > > > +bool __weak kvm_arch_private_mem_supported(struct kvm *kvm) > > Use kvm_arch_has_private_mem(), both because "has" makes it obvious this is checking > > a flag of sorts, and to align with other helpers of this nature (and with > > CONFIG_HAVE_KVM_PRIVATE_MEM). > > > > $ git grep kvm_arch | grep supported | wc -l > > 0 > > $ git grep kvm_arch | grep has | wc -l > > 26 Make sense. kvm_arch_has_private_mem it actually better. > > > > > > > > > > +#ifdef CONFIG_HAVE_KVM_PRIVATE_MEM > > > > > > > > + case KVM_MEMORY_ENCRYPT_REG_REGION: > > > > > > > > + case KVM_MEMORY_ENCRYPT_UNREG_REGION: { > > > > > > > > + struct kvm_enc_region region; > > > > > > > > + > > > > > > > > + if (!kvm_arch_private_mem_supported(kvm)) > > > > > > > > + goto arch_vm_ioctl; > > > > > > > > + > > > > > > > > + r = -EFAULT; > > > > > > > > + if (copy_from_user(®ion, argp, sizeof(region))) > > > > > > > > + goto out; > > > > > > > > + > > > > > > > > + r = kvm_vm_ioctl_set_encrypted_region(kvm, ioctl, ®ion); > > > > > > > this is to store private region metadata not only the encrypted region? > > > > > > Correct. > > > > > Sorry for not being clear, was suggesting name change of this function from: > > > > > "kvm_vm_ioctl_set_encrypted_region" to "kvm_vm_ioctl_set_private_region" > > > > Though I don't have strong reason to change it, I'm fine with this and > > > Yes, no strong reason, just thought "kvm_vm_ioctl_set_private_region" would > > > depict the actual functionality :) > > > > > > > this name matches the above kvm_arch_private_mem_supported perfectly. > > > BTW could not understand this, how "kvm_vm_ioctl_set_encrypted_region" > > > matches "kvm_arch_private_mem_supported"? > > Chao is saying that kvm_vm_ioctl_set_private_region() pairs nicely with > > kvm_arch_private_mem_supported(), not that the "encrypted" variant pairs nicely. > > > > I also like using "private" instead of "encrypted", though we should probably > > find a different verb than "set", because calling "set_private" when making the > > region shared is confusing. I'm struggling to come up with a good alternative > > though. > > > > kvm_vm_ioctl_set_memory_region() is already taken by KVM_SET_USER_MEMORY_REGION, > > and that also means that anything with "memory_region" in the name is bound to be > > confusing. > > > > Hmm, and if we move away from "encrypted", it probably makes sense to pass in > > addr+size instead of a kvm_enc_region. This makes sense. > > > > Maybe this? > > > > static int kvm_vm_ioctl_set_or_clear_mem_private(struct kvm *kvm, gpa_t gpa, > > gpa_t size, bool set_private) Currently this should work. > > > > and then: > > > > #ifdef CONFIG_HAVE_KVM_PRIVATE_MEM > > case KVM_MEMORY_ENCRYPT_REG_REGION: > > case KVM_MEMORY_ENCRYPT_UNREG_REGION: { > > bool set = ioctl == KVM_MEMORY_ENCRYPT_REG_REGION; > > struct kvm_enc_region region; > > > > if (!kvm_arch_private_mem_supported(kvm)) > > goto arch_vm_ioctl; > > > > r = -EFAULT; > > if (copy_from_user(®ion, argp, sizeof(region))) > > goto out; > > > > r = kvm_vm_ioctl_set_or_clear_mem_private(kvm, region.addr, > > region.size, set); > > break; > > } > > #endif > > > > I don't love it, so if someone has a better idea... > > > Maybe you could tag it with cgs for all the confidential guest support > related stuff: > e.g. kvm_vm_ioctl_set_cgs_mem() > > bool is_private = ioctl == KVM_MEMORY_ENCRYPT_REG_REGION; > ... > kvm_vm_ioctl_set_cgs_mem(, is_private) If we plan to widely use such abbr. through KVM (e.g. it's well known), I'm fine. I actually use mem_attr in patch: https://lkml.org/lkml/2022/7/20/610 But I also don't quite like it, it's so generic and sounds say nothing. But I do want a name can cover future usages other than just private/shared (pKVM for example may have a third state). Thanks, Chao