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 7D486C43334 for ; Fri, 10 Jun 2022 16:14:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238720AbiFJQOb (ORCPT ); Fri, 10 Jun 2022 12:14:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237375AbiFJQO2 (ORCPT ); Fri, 10 Jun 2022 12:14:28 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03E301BEB9 for ; Fri, 10 Jun 2022 09:14:27 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id e66so25183061pgc.8 for ; Fri, 10 Jun 2022 09:14:26 -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=26aUmJbBfeJ5oAzoN9m0myJZY1IQt9X18fsC7MTlf0gVkfZSmAlGCRNIANqqCFCrfU KPXPf7iD9UXcPnZlvhGhIqeEMuQSZM5D4OrXddLlifBpqC10f+wNNMlvlHeA6+KWpDc2 bgtNyjoBZ8Jvt03h/tAaAfPp3jmIvJC10Bi2+ojw4NnOekJkBiv6NADJ5DaZ4THTANhH GXgd02LdvEyEMO3xNV0tq/v/oMHYc+eCm387Km3U/C5abX3AbPlIPrwQCGQsHNEBVt+v lKXdiAPUQBRdcr93f+Pnr0ktMwtb1CMbhVwb28aeLXL2dKFtUhPSq4rmb2+NzGTOBARY QuVw== X-Gm-Message-State: AOAM533IgBS2r5Sz88RChYmmlIqqs8l3Wfj8CjP2suZYHwLyysNyHWOO llNEDzUO4QF+PeiCSkMh4bSx+A== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.