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 209EACD1288 for ; Wed, 3 Apr 2024 12:52:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D4826B0089; Wed, 3 Apr 2024 08:52:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6853B6B008C; Wed, 3 Apr 2024 08:52:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54D416B0093; Wed, 3 Apr 2024 08:52:18 -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 37B216B0089 for ; Wed, 3 Apr 2024 08:52:18 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E0D1FC0B2A for ; Wed, 3 Apr 2024 12:52:17 +0000 (UTC) X-FDA: 81968208714.02.8BB7286 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 12E25C0015 for ; Wed, 3 Apr 2024 12:52:15 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=R1uATYUA; spf=pass (imf28.hostedemail.com: domain of pbonzini@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=pbonzini@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712148736; h=from:from:sender: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Lzo04337+pWNqFR9KY5np7872oqctqWVTvayomhrVIY=; b=YFhVZ38u0KDcugKGiq/6r77w+alKWKXNOUxG3GjsT7as/sy/U/S90v73zSmPPIATeApBKH EH2u4/ZuIgrwFZXKW+G7RRQcTBmkYPrLzthTqf9YGGttQ+4n/E0/l/d96k1OMFN3RdJtx1 KJaSztERz7jdPiZoQp79tHKgu399Jqw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712148736; a=rsa-sha256; cv=none; b=YmLhZfyNRKNGF8nDUoTcG3uNhldfvTy4agf232yMZc2wbJVwbKDXTag2uE2gOFM1o69T2y 9P+4o7bN5iiL0qVv8uirwc41Vv2OtyGGyDv0zZ0uPBbs65iGhhgnDaHw5X/6KYaTrcx7pD 4p/R7NetEYwN6tWDMXJ2ntn8lTq6bvQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=R1uATYUA; spf=pass (imf28.hostedemail.com: domain of pbonzini@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=pbonzini@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712148735; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lzo04337+pWNqFR9KY5np7872oqctqWVTvayomhrVIY=; b=R1uATYUA4ggZ7o57HmejgazGydMQqrOhLAogWxV9VLIPXHzT5jZ6huaOOhjOtULG4uYXi3 Hml9yLdtEpkBkDYxWuxBmef8sVhIkTEfeE8Pc3K0NeS+lF6Ef6XgCRc0ODDSSlDyioS4iC be2DDKCT6N9CTqkfqjCES5AZTDW5gTo= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-500-ABxhgTrYOBGGtAxxplpyOg-1; Wed, 03 Apr 2024 08:52:13 -0400 X-MC-Unique: ABxhgTrYOBGGtAxxplpyOg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3436714e286so1193189f8f.0 for ; Wed, 03 Apr 2024 05:52:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712148732; x=1712753532; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lzo04337+pWNqFR9KY5np7872oqctqWVTvayomhrVIY=; b=WJNY7hJEcBIX8XPvjmTftVrZ4Mk4x1P1gFG5DFZjWfumt9aQIuDppqcOKh5bNvaBk7 /BpeD3F9/hsIn7YvuNQoKiPOQl8ZEbGS3flZ5gYWAtPnfWYJv72vAOWP/54hVh06jRNB aOvE6YE01RjkuhmTQWFmf3wPQ55WG4ydtXOqre+Yza/19Q5fAe4W9u1pdgUYBPCq8ugZ FgcN7siNqzRdkI2UT8WKoZcKEFOP60nE4GfS2kxd0FYX7q7Ngz02O0+ZI+AO0XPZqmvN s4qQlPwOAwLUH0BX29NV+T1dCo3hrFSRutavlQb41zqwXAo+ha8zTFaH1xkp8jLz2tZ2 ufXw== X-Forwarded-Encrypted: i=1; AJvYcCVpfuNMtirCj039DhXfV0ejGXC/hKyg47+JgaEDI2tYJEOlnHbb6VgdsC2kcH+/GGxF9yJosR4t88GDaKRQNHV452c= X-Gm-Message-State: AOJu0YxhASZN5+L99IXIEr74W9Tpo8xpBThxmBff/DvKB6RKO1YTTepH KnWC87f1Y9U8JCEYt5/SRlYuXApZ5G8ZwKehaGSskMumO0nDj8+9LGG5aZNrj9VpU1+ygY6h19n gEw9TPRfup3lJ4msEkUNqlWuSe6jfRN4H7uKvUpMwCXD/FpcnQZ3IpHrf3yk9z9yNwD9TWVepZg ZTNeuOas0MhP0M3MrJanteMHg= X-Received: by 2002:a5d:48cc:0:b0:33e:ca29:5a3 with SMTP id p12-20020a5d48cc000000b0033eca2905a3mr10071611wrs.23.1712148731976; Wed, 03 Apr 2024 05:52:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2UoNabPuQYMXaCFPaD8DdCLeElDGS9RU+nviM9wFLu/qKDV0J6kv+wy2lYCLkobeqVDalIcJhUKiwuGQdPuY= X-Received: by 2002:a5d:48cc:0:b0:33e:ca29:5a3 with SMTP id p12-20020a5d48cc000000b0033eca2905a3mr10071597wrs.23.1712148731603; Wed, 03 Apr 2024 05:52:11 -0700 (PDT) MIME-Version: 1.0 References: <20240329225835.400662-1-michael.roth@amd.com> <20240329225835.400662-12-michael.roth@amd.com> <8c3685a6-833c-4b3c-83f4-c0bd78bba36e@redhat.com> <20240401222229.qpnpozdsr6b2sntk@amd.com> <20240402225840.GB2444378@ls.amr.corp.intel.com> In-Reply-To: <20240402225840.GB2444378@ls.amr.corp.intel.com> From: Paolo Bonzini Date: Wed, 3 Apr 2024 14:51:59 +0200 Message-ID: Subject: Re: [PATCH v12 11/29] KVM: SEV: Add KVM_SEV_SNP_LAUNCH_UPDATE command To: Isaku Yamahata Cc: Michael Roth , kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, seanjc@google.com, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, jarkko@kernel.org, ashish.kalra@amd.com, nikunj.dadhania@amd.com, pankaj.gupta@amd.com, liam.merwick@oracle.com, Brijesh Singh , Xu Yilun , Binbin Wu , Xiaoyao Li , isaku.yamahata@linux.intel.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: e7egd378b9icnajsccd7nuabhnt55oo5 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 12E25C0015 X-Rspam-User: X-HE-Tag: 1712148735-25975 X-HE-Meta: U2FsdGVkX19jkKaArSt8T94zGo26lb+qPZdptY8YazY9lcwSqEeH4RzufTIebsH7BA0PNV9x6OzijqxKYatY+1ypFl4yNqu6YIKD8zIGM0LnJdw1r8HtwFQjUdGLxClTcewJ+K5WA/9Hfwkil/guMVEWvaTxIxTeuKtM3Ny2TK2mydjzqTlqkEI2juk3uQMoiGARGZSTpTCRSi6t7oAV7qdX0Gl07esZqhk7z87vX3NIycTrli6TrXZPoUUwWVrVuEp30zz6zdiZiUQCGC4pAweyJGBKZDT3CDTU4SURzLlOle40KY7S0ivGNVc8vYGoUKlk4DZb9fUH1+9GtYxIXiCKllU14q86ThToc/T+hyloAXFXzdamtQ8/8L59gagMA1JwkSdZToIqIVM4Q05Cy6T2+mL99eW7NLVG8yn4AYx2KfcYjTw8czRSiEEM/eJUULS5cUsBZjg8LoZN7+542c2GUwERVeLA61TBU4DfLrW+aikA1S39PQY/aqkaeksi3DmqJgxrucrRPq3+z+fjycwUPrL7lnLPqX/uwxJ6yGFR+friLM+EOPRexHlUDySPb47gOptfXhNAzcvKZUsz4tv9oucQt7kCJHE0G1o4yGWnpgV5tJeTWBvidNIwtzCPQysmUB+ou2RT0egGGMhnSU9RjmUsp/slFI163QCHThug+9jk6BsGZQ4rol4xPBQr3oqFjRAmMDim3+x4Q9zmZftHcYMzqjDDk84MAiWnyubYZZeRiSbMJogfGMiOSyE2AitJ232mD92ssg2BUxVjEyo5HhDcP7Ih+echXEsfLGke1grxiCE5FkdUcXS0hbfwgAIl9VQrxAKUDmOp7c5teSrqbjWn+RuzhkWlIoYnliRjih2xqYnNgM/6gzpTan7CbGm9/arJ4id0SuXigOFWVHqH8PAjyrhf145poMrNjYrVDc6hteCyGJgmvLRTdhDLj04CcqAWlsbYSQmwjEl UtbA203u DPxtygrwWSb1vDSO362RARwZvyRtkOnrHVddzl7zHITCLXlR86wfUl/6TcQ== 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: List-Subscribe: List-Unsubscribe: On Wed, Apr 3, 2024 at 12:58=E2=80=AFAM Isaku Yamahata wrote: > I think TDX can use it with slight change. Pass vcpu instead of KVM, page= pin > down and mmu_lock. TDX requires non-leaf Secure page tables to be popula= ted > before adding a leaf. Maybe with the assumption that vcpu doesn't run, G= FN->PFN > relation is stable so that mmu_lock isn't needed? What about punch hole? > > The flow would be something like as follows. > > - lock slots_lock > > - kvm_gmem_populate(vcpu) > - pin down source page instead of do_memcopy. Both pinning the source page and the memcpy can be done in the callback. I think the right thing to do is: 1) eliminate do_memcpy, letting AMD code taking care of copy_from_user. 2) pass to the callback only gfn/pfn/src, where src is computed as args->src ? args->src + i * PAGE_SIZE : NULL If another architecture/vendor needs do_memcpy, they can add something like kvm_gmem_populate_copy. > - get pfn with __kvm_gmem_get_pfn() > - read lock mmu_lock > - in the post_populate callback > - lookup tdp mmu page table to check if the table is populated. > lookup only version of kvm_tdp_mmu_map(). > We need vcpu instead of kvm. Passing vcpu can be done using the opaque callback argument to kvm_gmem_populate. Likewise, the mmu_lock can be taken by the TDX post_populate callback. Paolo > - TDH_MEM_PAGE_ADD > - read unlock mmu_lock > > - unlock slots_lock > > Thanks, > > > With that model, the potential for using kvm_gmem_populate() seemed > > plausible to I was trying to make it immediately usable for that > > purpose. But maybe the TDX folks can confirm whether this would be > > usable for them or not. (kvm_gmem_populate was introduced here[2] for > > reference/background) > > > > -Mike > > > > [1] https://lore.kernel.org/kvm/20240319155349.GE1645738@ls.amr.corp.in= tel.com/T/#m8580d8e39476be565534d6ff5f5afa295fe8d4f7 > > [2] https://lore.kernel.org/kvm/20240329212444.395559-3-michael.roth@am= d.com/T/#m3aeba660fcc991602820d3703b1265722b871025)