Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1162525iog; Mon, 13 Jun 2022 23:50:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaKr9G4M55nr0iB89cij+eDS+F2jb+uTq+P1XYhOvMXX4pme1KHn07uB5DiqMhtilhr+H7 X-Received: by 2002:a05:6402:2931:b0:42d:df54:c2e6 with SMTP id ee49-20020a056402293100b0042ddf54c2e6mr4024557edb.44.1655189430793; Mon, 13 Jun 2022 23:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655189430; cv=none; d=google.com; s=arc-20160816; b=xr/Emqum0JTLGCOaCVrqAWt3VdutO3Z3ziuNZ9JZbMa46eb6mFIBGsRpgMYjcfTfED st2ONXPvUnr1b9q7KkX0gPClAGhkKKQICuxTsQTv0esskrZ3gyw2PGIi/U0SoFZUqGJ6 JothQLyE0d6GvoZfwGp8DEhQlxXX8Zg4SANLF43bkOeryPnifwRFJsB59Yup+1++nEp7 QAeZwNr5xkdIL+Pr0/aWNdJhJfIZP7pWA48zjvwFpl6mOLCXXaREEfqN8kClYLYM5Lsk /MLRj/VWlXrNCx4Gr7EebWJUvMm6GutjVulr2WmxDtkEdCuu5KxBM00R+ikXlNlF7y6s vhuw== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=8G94nKig9OcoKAYiTGZ6yEdojCDiJ7PLroC/oAPUK4k=; b=jsFZJtnju2OWu9TNlJzNlBELuIcvBXxcvQHEpinJKgKpFd5WsZ7cD5R7H98am5iJBq 5XLqypAyETyhDwFP2x2U9IO1DJeXOQ+xH0n5zpYu1KGTYvrJUHXO5snEkdfhbnDO1gwT 22oYaNN4NZ0gjuL149sfcanx+9SZGRuKjw2UXbgf6fvhJ4AaPxDdBJqqKX7s0p12r/v3 bCyhu/4F2QFx8c/tDfMnMIEINlSRULWFYE8ZzSf+hRA5XJBgBkZ9J1CjIMIPjifOFD/I OjSf0+/PmMB0VmnTDefqLIk+u5zfqCicDJ9b5k6COKbGt5F5WnfK+GXebGcEESP6iqyF 54Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XqyBeM+S; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l10-20020a50c10a000000b0042df8161c98si9339320edf.244.2022.06.13.23.50.05; Mon, 13 Jun 2022 23:50:30 -0700 (PDT) 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=@intel.com header.s=Intel header.b=XqyBeM+S; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352419AbiFNGs5 (ORCPT + 99 others); Tue, 14 Jun 2022 02:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352348AbiFNGs4 (ORCPT ); Tue, 14 Jun 2022 02:48:56 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0B42393D0; Mon, 13 Jun 2022 23:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655189335; x=1686725335; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=wuX5JnFrxSq386a6TH37odo/ge8jsmW2qkPxXWwsMwk=; b=XqyBeM+SC0sn1m7v6sUkGKi3+OmUwaPu8oyiBwspM2lG1Iic58DIA9vw BsBnIj1O+Wjy1LFUBhFzfVmct8m2xyi9ZXj648n+QmmsfIwd9Y62S1vxg rIs9oFIPj4C7JjaL5z475EnQcUC3dP8Qzi6kJu36+Fm601u6gGVi4LDlA UQbsc1ZFe7GHxZ3E3ls4b4Ua8RwQMk1G71H3wU06W3yz763pklJWFcm7M UksybhVQ+ibZYou2JPRLTqdstS+yj2IofS4ch5SpC87yuCVVhuuuhYq1I x7Dd/G8pOLEfKVJnXbWGRupqhA2wEr8cdoO6ZRQYAjXy7n5Vrjkvptcxi w==; X-IronPort-AV: E=McAfee;i="6400,9594,10377"; a="303933443" X-IronPort-AV: E=Sophos;i="5.91,299,1647327600"; d="scan'208";a="303933443" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2022 23:48:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,299,1647327600"; d="scan'208";a="582566724" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga007.jf.intel.com with ESMTP; 13 Jun 2022 23:48:44 -0700 Date: Tue, 14 Jun 2022 14:45:22 +0800 From: Chao Peng To: Sean Christopherson Cc: Andy Lutomirski , 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" , 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: <20220614064522.GA1783435@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220519153713.819591-1-chao.p.peng@linux.intel.com> <20220519153713.819591-5-chao.p.peng@linux.intel.com> <8840b360-cdb2-244c-bfb6-9a0e7306c188@kernel.org> <20220523132154.GA947536@chaop.bj.intel.com> <20220530132613.GA1200843@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=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 Fri, Jun 10, 2022 at 04:14:21PM +0000, Sean Christopherson wrote: > On Mon, May 30, 2022, Chao Peng wrote: > > On Mon, May 23, 2022 at 03:22:32PM +0000, Sean Christopherson wrote: > > > Actually, if the semantics are that userspace declares memory as private, then we > > > can reuse KVM_MEMORY_ENCRYPT_REG_REGION and KVM_MEMORY_ENCRYPT_UNREG_REGION. It'd > > > be a little gross because we'd need to slightly redefine the semantics for TDX, SNP, > > > and software-protected VM types, e.g. the ioctls() currently require a pre-exisitng > > > memslot. But I think it'd work... > > > > These existing ioctls looks good for TDX and probably SNP as well. For > > softrware-protected VM types, it may not be enough. Maybe for the first > > step we can reuse this for all hardware based solutions and invent new > > interface when software-protected solution gets really supported. > > > > There is semantics difference for fd-based private memory. Current above > > two ioctls() use userspace addreess(hva) while for fd-based it should be > > fd+offset, and probably it's better to use gpa in this case. Then we > > will need change existing semantics and break backward-compatibility. > > My thought was to keep the existing semantics for VMs with type==0, i.e. SEV and > SEV-ES VMs. It's a bit gross, but the pinning behavior is a dead end for SNP and > TDX, so it effectively needs to be deprecated anyways. Yes agreed. > I'm definitely not opposed > to a new ioctl if Paolo or others think this is too awful, but burning an ioctl > for this seems wasteful. Yes, I also feel confortable if it's acceptable to reuse kvm_enc_region to pass _gpa_ range for this new type. > > Then generic KVM can do something like: > > case KVM_MEMORY_ENCRYPT_REG_REGION: > case KVM_MEMORY_ENCRYPT_UNREG_REGION: > struct kvm_enc_region region; > > if (!kvm_arch_vm_supports_private_memslots(kvm)) > goto arch_vm_ioctl; > > r = -EFAULT; > if (copy_from_user(®ion, argp, sizeof(region))) > goto out; > > r = kvm_set_encrypted_region(ioctl, ®ion); > break; > default: > arch_vm_ioctl: > r = kvm_arch_vm_ioctl(filp, ioctl, arg); > > > where common KVM provides > > __weak void kvm_arch_vm_supports_private_memslots(struct kvm *kvm) > { > return false; > } I already had kvm_arch_private_mem_supported() introduced in patch-07 so that can be reused. > > and x86 overrides that to > > bool kvm_arch_vm_supports_private_memslots(struct kvm *kvm) > { > /* I can't remember what we decided on calling type '0' VMs. */ > return !!kvm->vm_type; > } > > and if someone ever wants to enable private memslot for SEV/SEV-ES guests we can > always add a capability or even a new VM type. > > pKVM on arm can then obviously implement kvm_arch_vm_supports_private_memslots() > to grab whatever identifies a pKVM VM.