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 4E346C43334 for ; Wed, 20 Jul 2022 16:21:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231622AbiGTQVs (ORCPT ); Wed, 20 Jul 2022 12:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234245AbiGTQVo (ORCPT ); Wed, 20 Jul 2022 12:21:44 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 770DF6171B for ; Wed, 20 Jul 2022 09:21:42 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id g4so16858799pgc.1 for ; Wed, 20 Jul 2022 09:21:42 -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=f0adogo0zxbyENycGDyitWJjrMgz2USumvEVtMapSaM=; b=spGLDNQ08YQPqH7UmhIpiHe2RaM2zw7ODEii6vmP7whH0yk8NhoS7QYoLrpacwnfbW S3VkQABUgvOUZAhV+aAm4mnqaDYIZ6zOWmQpK2Ozj1qZ4yEP8IO8Ogxh+e38++9rhFjG Gncn3BStXeB7j7O3s/y/CX20mihB4UWNCG15aOuY2njFY086JqM16L+H4BlY/AN8pWe8 s9ex7tY8xz16AMATUg5JkSGjI8FqtQ1JH/Ckd2eXT2/cGJ188i8q7NwsSTtTXSvKMUHc Y4He+Vu/AgyMtaInE+pTo4N4Wc2xqCJOuE/medBD2cHSdxBx52LLtQTesVoUiLmIcCvV AYCw== 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=f0adogo0zxbyENycGDyitWJjrMgz2USumvEVtMapSaM=; b=x/fEPx9/GES8CQuf6xy/9QiVKs/3FLrs3VHStibVknNW4jC6MuOyedjfwiBeRDg5Sx 3dfvpKsbW5BDHz/UknS/zQrPX27sxx9zonfQueOqww4U9kGpHMG4JrFO+Qbc4X6jtcNn WqKRQm2IZWxo4gSXVEGNLzTETNyIa/ft/M0sKNYbH1Tl/GVkFrxdSdRlABN7ppnvRuo9 C4OMyu5658JoD/l6bnY+xGnlF8hw8E6npQTl1RHlHAVHoG6YwR5UFMdN6sqkVseG/Q4o VaoXjmaDakKgAkahNRTao+MvIewnSIfdUgROgarhMtD4d7d19AgJmvQYsUt84nUQqMQa Yu+g== X-Gm-Message-State: AJIora/ypZWB5xYlzCBKSztcbnVPa/kBAf2wwcmaKMHBzayQRub/+ufa Ei2+fsm/483asAbNiHF2X+RhUg== X-Google-Smtp-Source: AGRyM1vSVUjKLbGc4Kd7xVml29j/pMq086Pfs5AgzFCjeBxpV+cVQy9BGtwT6tQB+IRvWirFlwJ5Og== X-Received: by 2002:a65:6bcc:0:b0:3f6:1815:f541 with SMTP id e12-20020a656bcc000000b003f61815f541mr33324434pgw.183.1658334101831; Wed, 20 Jul 2022 09:21:41 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id g5-20020a63dd45000000b0041a4d5e7e5fsm3266314pgj.47.2022.07.20.09.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 09:21:41 -0700 (PDT) Date: Wed, 20 Jul 2022 16:21:37 +0000 From: Sean Christopherson To: "Gupta, Pankaj" Cc: Chao Peng , 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: 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> 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-kernel@vger.kernel.org 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 > > > > > > +#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. Maybe this? static int kvm_vm_ioctl_set_or_clear_mem_private(struct kvm *kvm, gpa_t gpa, gpa_t size, bool set_private) 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...