Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1870117rwb; Wed, 5 Oct 2022 06:07:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM60l+lSV+eoMhQZZEAJXVTUYAM09z8J+NXKtL21ljf5y6y1Nc7pJTfqe4q6Ql7aLaZQXxKS X-Received: by 2002:a17:907:7f11:b0:78d:2872:538e with SMTP id qf17-20020a1709077f1100b0078d2872538emr3010454ejc.583.1664975262940; Wed, 05 Oct 2022 06:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664975262; cv=none; d=google.com; s=arc-20160816; b=ekGUdSXf6GyHqVlfmkhy5yNTUNoPKCEcMTdlyVgIUjN53ULPiuYYjILh9EzonT1kTp A3xKE0Te8H2B5gBjeHQoctQ2ky3gwxKAe2SC7VOobAim0wyo865VtafCjxpC1gDroz0D YnBb1UEEHybCy+A93T0+oHxcSIf4im6GMlQFfZFdfwqB315STQH9brtgSMHNS33nUtXf TH+nqTx8RbQaSK/ViNs9VY5ty1jPi7HG2OWAqEvbIkPC7bnGRUQdi0WsJWEz9sZEELYy NcLQMNORG/UHffXfleGR97G8Anfy7Dy7jgW9RB/+suvvGIJYVZ/ybJ9IUAqhWjHClmbG gxKA== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=PultTMGQKCqnjYqkbiZduj5MhR5JjwBemy9q9jDeNqg=; b=p8H+/8wiPfWZyb1leXBM1cULokFMEUfT2gdafAATDETD/WntW9pkwXH6IzxWPDLRVI NtENcCeM1+HidiNUXR5L1UHGyU8JCV+7bZNEGXkqIAmJFyYi0+QCxZdj9zq4f3C856sP BmeFVNkYnndAdGkk9PZDNznLDdRsQDjfDCC61wBLtuYCj4LIj1Rq5xZXHEsTPzMad6or bIuU8W8hR3mWSbngBuJN07IG6d9SiGuH6kg5ISkkexP8IP5ENEm+OkJ2FMrE4PWYlLaV 6TcLOXyMtuhSbv7vMQ3E2L4qdk/arDo7tA96YT/KoQdtoSlcRW2POISKdSnm/qHNqgLE yuiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GAEi5XwU; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd10-20020a1709069b8a00b007313312730esi14994958ejc.85.2022.10.05.06.07.13; Wed, 05 Oct 2022 06:07:42 -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=@kernel.org header.s=k20201202 header.b=GAEi5XwU; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229737AbiJENEJ (ORCPT + 99 others); Wed, 5 Oct 2022 09:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbiJENEH (ORCPT ); Wed, 5 Oct 2022 09:04:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCA2E786DC; Wed, 5 Oct 2022 06:04:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 767F9616E1; Wed, 5 Oct 2022 13:04:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47B63C433C1; Wed, 5 Oct 2022 13:04:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664975045; bh=bvM+jB0eDJn00RJ2w02HJMno7C/rvhAvA9ixbzV8D8Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GAEi5XwUyJTM6kXENY8THipzyzcW4UsR+iOIk9OE2N30SkWjZyUPCqvnu0kkZ1ytt snObPlm0BJoTwCEnjxDVpJ6mWYSfhMHSwaSpp8ek+ecR3X5LLvHH+iHrYhCjpRRcNa qszvnxuGnI8lo1cfby+Kf5XTEN1X6g0nXwdnPSukqdX2bl8Ex7kt1TrI/vZHLsGCtf ywSeQaYlUbXsuTfpixP++EedrfHPpeYh1PKBjBiHrlIGMIirU1Pl4KtxDFLBCKcHyd wtdJL7rpVbf6gmChh9Z09Zz1zjtxX5sdKWbN/8kyQGTKMjQBBGQEXAArUH27/8ANgY suMQ/DnCvYCAA== Date: Wed, 5 Oct 2022 16:04:01 +0300 From: Jarkko Sakkinen To: Chao Peng Cc: 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 , Sean Christopherson , 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 , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, 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, Muchun Song , wei.w.wang@intel.com Subject: Re: [PATCH v8 2/8] KVM: Extend the memslot to support fd-based private memory Message-ID: References: <20220915142913.2213336-1-chao.p.peng@linux.intel.com> <20220915142913.2213336-3-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220915142913.2213336-3-chao.p.peng@linux.intel.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Thu, Sep 15, 2022 at 10:29:07PM +0800, Chao Peng wrote: > In memory encryption usage, guest memory may be encrypted with special > key and can be accessed only by the VM itself. We call such memory > private memory. It's valueless and sometimes can cause problem to allow > userspace to access guest private memory. This patch extends the KVM > memslot definition so that guest private memory can be provided though > an inaccessible_notifier enlightened file descriptor (fd), without being > mmaped into userspace. > > This new extension, indicated by the new flag KVM_MEM_PRIVATE, adds two > additional KVM memslot fields private_fd/private_offset to allow > userspace to specify that guest private memory provided from the > private_fd and guest_phys_addr mapped at the private_offset of the > private_fd, spanning a range of memory_size. > > The extended memslot can still have the userspace_addr(hva). When use, a > single memslot can maintain both private memory through private > fd(private_fd/private_offset) and shared memory through > hva(userspace_addr). Whether the private or shared part is visible to > guest is maintained by other KVM code. > > Since there is no userspace mapping for private fd so we cannot > get_user_pages() to get the pfn in KVM, instead we add a new > inaccessible_notifier in the internal memslot structure and rely on it > to get pfn by interacting with the memory file systems. > > Together with the change, a new config HAVE_KVM_PRIVATE_MEM is added and > right now it is selected on X86_64 for Intel TDX usage. > > To make code maintenance easy, internally we use a binary compatible > alias struct kvm_user_mem_region to handle both the normal and the > '_ext' variants. > > Co-developed-by: Yu Zhang > Signed-off-by: Yu Zhang > Signed-off-by: Chao Peng What if userspace_addr would contain address of an extension structure, if the flag is set, instead of shared address? I.e. interpret that field differently (could be turned into union too ofc). That idea could be at least re-used, if there's ever any new KVM_MEM_* flags that would need an extension. E.g. have struct kvm_userspace_memory_private, which contains shared address, fd and the offset. BR, Jarkko