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 F0D43C433EF for ; Tue, 14 Jun 2022 06:49:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52A726B00A1; Tue, 14 Jun 2022 02:49:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B3748D020F; Tue, 14 Jun 2022 02:49:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 305ED6B00A8; Tue, 14 Jun 2022 02:49:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 199406B00A1 for ; Tue, 14 Jun 2022 02:49:00 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D802D34865 for ; Tue, 14 Jun 2022 06:48:59 +0000 (UTC) X-FDA: 79575913998.23.E744B8C Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf01.hostedemail.com (Postfix) with ESMTP id 0DEDF400AB for ; Tue, 14 Jun 2022 06:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655189339; x=1686725339; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=wuX5JnFrxSq386a6TH37odo/ge8jsmW2qkPxXWwsMwk=; b=VDCEAeYzDnPJbN3/k6B4DHJglkIgebz892KpTOtb0fOjLGJS+/HYBwI9 zdgaxse+klhXz6V5nk2y7oGlOLO/4R13YsZLjDF4VqGW0VVeP6FD3OQlx RXD855EtVvMf1aS2nVVaAphdSCju3E0oHq5LNHiUVm2Mw9ZJe9GOKvgCf mRRpmPGDcub+mstm5AHhZ+ujpWBMrm2bffh4wtVon5lFPPm2c6VYSFNzY QpCPB0s8gwqtwffVFn1kDzAQnsL8jFiIUx5rE1Wv6j6h4eGErQnNmXiMl 19f8Rz7/hlxODq/fp7HOGQimxO39UaT2IIzVj3Kfvlir3D+YSc+AKHI6u w==; X-IronPort-AV: E=McAfee;i="6400,9594,10377"; a="364861495" X-IronPort-AV: E=Sophos;i="5.91,299,1647327600"; d="scan'208";a="364861495" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.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: ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=VDCEAeYz; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf01.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.43) 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=1655189339; 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=8G94nKig9OcoKAYiTGZ6yEdojCDiJ7PLroC/oAPUK4k=; b=uNSBnalZB+yrxA/Pz2bsCKvdYjIzoHTighhDwqMu5DiqTxNuv8SLO+ishuvcRRNrqwAw3d wcM5mY0JJTTW84pNXEA2nNFv7eCvQnGiBbLs6CySxMuZkx9ERVUKdkZKjMhluk7QdoLKVN LvWMbZqPh0A5FRHJFUS4vF92dQG4QYQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655189339; a=rsa-sha256; cv=none; b=VJtLcfL6StqtoUcdXxrmrhNHaDh2rG2TTe+ME9WCJTxx01gi2jkzR7fhy2GhOPLT7H5vWh Ky4gHcZ7GYhPNfuGZAnBSXrI7skP0y+1+YDNOzDK34yhj7Qw5G2WwrBsd/1auDrbGmCTNo thUIxaXUvfjx0I6bx7iB1RbBcBUljRU= X-Stat-Signature: 8at174q5oxz5bmgoso43grh631zbgizr X-Rspamd-Queue-Id: 0DEDF400AB X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=VDCEAeYz; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf01.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.43) smtp.mailfrom=chao.p.peng@linux.intel.com X-Rspamd-Server: rspam10 X-HE-Tag: 1655189338-456085 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 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.