Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp737026rwl; Thu, 5 Jan 2023 03:58:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXsNXqwVWhR3C5ggqjAxjq1buh4j0hywuOSRuszDfltzFyR6umd37/+xZvvk+b/LW887KYUT X-Received: by 2002:a05:6a20:1e50:b0:b0:57d4:c026 with SMTP id cy16-20020a056a201e5000b000b057d4c026mr57283633pzb.21.1672919920859; Thu, 05 Jan 2023 03:58:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672919920; cv=none; d=google.com; s=arc-20160816; b=gqp38TlR0KSEDUbT0caI88xSwQdhsWqEThM64pWxdUM2uJ+64XdsYWtyBIVKpv8OKX Wv9PZuo1ewdejnM1lnUGOAJKcWWAQuxER0aLSnqovoEfMU3mcuHQzf5NzkrknB/1PPUp /rtkwYBwdOO5qY7C/tMaMpWZaqhUndhfkVB+AWqDpMnYJU8ucN65hTDKCRUwr0gYWcls zsgS0JLhyYN7uN5wpyXk3RNpjdph0JwSN8UvZaYocZiKEajOs/msceW0zl5JCJoNlfwD VfbwCXDBB5IIyUghqfXGC8sQ6fitMiChtJ4bzAF0AOsMU0W1La3MuRaNZ0uPJu1/QFoF s1lQ== 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=y2VEZPLcDJKdKDXU9Y1A6e1XI0+7YYXREIfq5BCq6HE=; b=tWbHwobTilX2rxT6+hQ1Xa/o63zmqJ3g2MESwyPeGl1yOPvEgQDvDZl71ni9uknulB t8I/hkGoHE8Cz175Qd0NpHu0oXqCVamqIyD9oQOUs8ddourN5I5dq5X2noWKZNAX67fC O8Dtk0fnt1ZKjNfVvBU0XJW69N2GYNJqWIfS1wbfFkh4PbPAnrkQpnKG3MSHV9aBDTqW kTCeGCeJ0JBSXy4ZH95mMJaFJUWTES/GCz23oKGX5q4803+NkLbi/WmA9f2gZ5w0+1Pe Va7smMrdmd+H9QBMYKP3AxC9bHrPuDTvm9JdYb9cr8Mhqhp0P12x5aiBIBnKJQKXn9/j Dh2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="f/NyAx/u"; 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 v10-20020a63150a000000b0049fa3a102ecsi17464404pgl.444.2023.01.05.03.58.33; Thu, 05 Jan 2023 03:58:40 -0800 (PST) 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="f/NyAx/u"; 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 S232176AbjAELXM (ORCPT + 55 others); Thu, 5 Jan 2023 06:23:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231725AbjAELXH (ORCPT ); Thu, 5 Jan 2023 06:23:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AB0F4E424; Thu, 5 Jan 2023 03:23:06 -0800 (PST) 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 EEDC761997; Thu, 5 Jan 2023 11:23:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCFDCC433F0; Thu, 5 Jan 2023 11:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672917785; bh=MBba54j0/BydJyfXJmD3sqygtai2bpp7J4HBZnAheDI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=f/NyAx/uidnIXzxaIjlXTomDF3irlmzZ+PCY7P4/TbnJUSJRD8UQ7c36MWpV71/Tn SYhuTjsjWfdmPqSLK8QE0FamFzSLRaWdbDObhW80t4Yhafl1J5jJ3bezM77sFrqnWb 7d/hzJOkyMc1nznD1fbjGD1fMn5JHCEwQ/N74LIUmis17aSfr3aoYAViHr5UwZIwBZ vMhpJpECkrYJfV357eN/7+fWF/0BXMk6663rsy2BQ1Hqv+wpHrlCHOkVeWNUyq7jDe MlCQt3z62ym96XHYhLSz9H4UynTy+xVr4M24uMVE/AY6qAUqNbC4TlEczADxwM5pwj vjHmuNVYuOTeg== Date: Thu, 5 Jan 2023 11:23:01 +0000 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-arch@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 , Arnd Bergmann , Naoya Horiguchi , Miaohe Lin , 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 , tabba@google.com, Michael Roth , mhocko@suse.com, wei.w.wang@intel.com Subject: Re: [PATCH v10 3/9] KVM: Extend the memslot to support fd-based private memory Message-ID: References: <20221202061347.1070246-1-chao.p.peng@linux.intel.com> <20221202061347.1070246-4-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221202061347.1070246-4-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 Fri, Dec 02, 2022 at 02:13:41PM +0800, Chao Peng wrote: > In memory encryption usage, guest memory may be encrypted with special > key and can be accessed only by the guest itself. We call such memory > private memory. It's valueless and sometimes can cause problem to allow > userspace to access guest private memory. This new KVM memslot extension > allows guest private memory being provided through a restrictedmem > backed file descriptor(fd) and userspace is restricted to access the > bookmarked memory in the fd. > > This new extension, indicated by the new flag KVM_MEM_PRIVATE, adds two > additional KVM memslot fields restricted_fd/restricted_offset to allow > userspace to instruct KVM to provide guest memory through restricted_fd. > 'guest_phys_addr' is mapped at the restricted_offset of restricted_fd > and the size is 'memory_size'. > > The extended memslot can still have the userspace_addr(hva). When use, a > single memslot can maintain both private memory through restricted_fd > and shared memory through userspace_addr. Whether the private or shared > part is visible to guest is maintained by other KVM code. > > A restrictedmem_notifier field is also added to the memslot structure to > allow the restricted_fd's backing store to notify KVM the memory change, > KVM then can invalidate its page table entries or handle memory errors. > > Together with the change, a new config HAVE_KVM_RESTRICTED_MEM is added > and right now it is selected on X86_64 only. > > To make future maintenance easy, internally use a binary compatible > alias struct kvm_user_mem_region to handle both the normal and the > '_ext' variants. Feels bit hacky IMHO, and more like a completely new feature than an extension. Why not just add a new ioctl? The commit message does not address the most essential design here. BR, Jarkko