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 5956EC43334 for ; Fri, 10 Jun 2022 16:14:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 924F88D00C3; Fri, 10 Jun 2022 12:14:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D4588D00C1; Fri, 10 Jun 2022 12:14:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7754A8D00C3; Fri, 10 Jun 2022 12:14:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 648388D00C1 for ; Fri, 10 Jun 2022 12:14:28 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2D0C9614DD for ; Fri, 10 Jun 2022 16:14:28 +0000 (UTC) X-FDA: 79562823816.30.F8A108B Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf26.hostedemail.com (Postfix) with ESMTP id 8D6A314006E for ; Fri, 10 Jun 2022 16:14:27 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id s135so9567815pgs.10 for ; Fri, 10 Jun 2022 09:14:27 -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=sqYpRJpV7hTVkJzWeySC/55ywPreerEYyAHVK7rq9LA=; b=ZehwwLYuij7pbQaghWD2GrdTIOfQ1XgasEUmVI+nhvd82X4ZEWGF79XBvheRliFM+8 LQlrxByJVokCQ/gINBsFhOZhZjHXcpmAir492TXOaXI7iC/F7Bwi4ptRQtYUbYGyY5SQ TxK5qW/wV8CCV8YqQLV5jWM8YEEm92a1WCcQVxigUczBkLKzhwgrSGPjDy4yzeckQMEl k23GcmLFp8s0aWbczjuNfnjBEB9gzzj7nGZZJi5rfah1FRb/8MQ3Cd99incf77459IOk fmV8msfIleb4V2r4FMWvWw0fr1RX3bQCUO2JP23SfG2qby97FTF15ddfD8Y7n8su8tG3 h2BA== 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=sqYpRJpV7hTVkJzWeySC/55ywPreerEYyAHVK7rq9LA=; b=10JfOqQZXvpLw7U5HC/iioSvPcTozCYZhyN1TFrIeo3y+MbDrkrNzG6x0hty5KQ/1t zaDdgU0NdJmtAlIW8ZrtNLhSmvozC+fui6UO/SU91NIgSI3LJ1OGwMaY++NEpcsEuWM2 CfC+vw6vdIBPMaiT/zVE2jM1cicW2cAxQRli+8i9iEtPvMYdVjR15/JuvjBk7tyZ3/Vl 6R8QlXyS0YberGDtMCACwJ/c28xZKuW3oBzUKcDT444fQWhcp4nSvIcI4tv32kIWXXYx FxVpyoaMEqhZ+GWw2/o30rJ/GrwrBRPds3AY6Tu4WTZTzrKcBF90d4Qd5g68Yvjtc5h9 6Qhw== X-Gm-Message-State: AOAM530IGGfr4i6R+sFVUg/qCnpr5aospd/q8NRXJ4ZIZ+t6+8InhmRk hdLS9nItejmkFlTwtkRTSXG1tQ== X-Google-Smtp-Source: ABdhPJzxrryZznx/9GnvIIDqh+c23V5/Xt5ZsJHD0N8PohIbtiXWvM06mGWU66DmH3LeRvNyTftAHA== X-Received: by 2002:a63:5:0:b0:3fe:2558:677 with SMTP id 5-20020a630005000000b003fe25580677mr14572323pga.113.1654877666234; Fri, 10 Jun 2022 09:14:26 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id r11-20020a170902e3cb00b0015e8d4eb28csm18669442ple.214.2022.06.10.09.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 09:14:25 -0700 (PDT) Date: Fri, 10 Jun 2022 16:14:21 +0000 From: Sean Christopherson To: Chao Peng 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: 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: <20220530132613.GA1200843@chaop.bj.intel.com> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654877667; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sqYpRJpV7hTVkJzWeySC/55ywPreerEYyAHVK7rq9LA=; b=ObpBZ962BUwVZdr5MGsdHAMmavH0+d5Fg4v1fVHvRujZOTPsLDeyRr26QUMRAuJiB4IcYB ofnv+Ybcx3TGK8UELZeS2hD2efmCkMIqnabDR09hQ45TZTaNb9kmOOjzPeRwP9NFnAfxzB dnc3TUKQy0CSmd6uBAEA4ByRv9Oy0SE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ZehwwLYu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of seanjc@google.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=seanjc@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654877667; a=rsa-sha256; cv=none; b=V9K/QlegkPRTIxWoy2MXN0kovBWO/zKVKu6TXD3qqg8HhZCeJI+G1eRXfnRnVcYsLOvvXs n2wkf//2sx4lvwS7fghYoT687XZrgex/lRaZ3rukzyl7V6k4nGIXozvgUh6dspm+vZZ4BT dxpCOk06pkZqQQaAGvtJ3ifOWKNL6pk= X-Stat-Signature: mag11bdbn116mhi5zqpmmxjswe3p9ta4 X-Rspamd-Queue-Id: 8D6A314006E Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ZehwwLYu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of seanjc@google.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=seanjc@google.com X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1654877667-137233 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 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. 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. 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; } 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.