Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2111973rwl; Fri, 6 Jan 2023 01:59:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXvfg3zSzuhs/wzWs73gAjJBkLbBsSkLa9FuyrpWsed/xSau+oqq+YZu6QKpDC4t0RoUx+XY X-Received: by 2002:a17:90a:acf:b0:226:ddf6:b7da with SMTP id r15-20020a17090a0acf00b00226ddf6b7damr2415123pje.41.1672999156351; Fri, 06 Jan 2023 01:59:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672999156; cv=none; d=google.com; s=arc-20160816; b=hs5nbTlXT4zhq+dOihHp+sENwXVMmFQrMsJxmnpGwVSPTcwvXa+S6NBcxxEQi7sgig TYNTAMQA0cD0R3cM5mQmLlVkEIZFIdI2O5GWmVVqnIJFEYM4CrqI6TrxiUfVXm8jlwht rz5LYTDD07AmcGA07zygjz6KQTLrlgaYbHuTiRY6QNzN66pfCyZjJtSYDBigS7vfA+AC ngKkbDDsrrX3h3JuxeGF+izkHxz1EXEtCAHbMkqWhDp4JPZC02s6FPV/XQyO136sr7+o ib8dxhw2G2K2H1d8yaa8/pkvOK18OaeHPP9NIAVmbcSi2Yw2yk1Q/VPrHmZknnO7x48F veag== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=eXVsVcFB5IcwowdBS01rBrglplhr+nGiuEnrWvUqrFQ=; b=ED2T9eQ05XephPRT1EJN8VXoWBclKh7CrqCNYDNz57KmwAUQhE3aIYxuowJZeY+4bv 0Gd0OYeWVcFdzME1C5LAXzVkSmw21YgwSra/Og83wa9CyRWMIX3+AvsTjzA/Bk3JND45 PN2o4Ze93clvBPXGo59/IrxTBs2XQdddorvb/XxqdIkhVrMHqpMk2eYwGp6FxCaD9r8r kqk7HbnA2TtQ2BxsJ8hWJNWrc7+H7UO1V6nZA6EvphcKk8RfFDKOm0bIhsTNyB6CNakb YkZBa9FZvruRnPp3HhbbGZJiQwKgT9SF1fs2w/rUdofX4/IkXqc1ww7HW4Ie+PdtHqQe l2Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="LCw2qM+/"; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a17090aad8400b002182cd7d958si4372739pjq.46.2023.01.06.01.59.08; Fri, 06 Jan 2023 01:59:16 -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=@intel.com header.s=Intel header.b="LCw2qM+/"; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232520AbjAFJqh (ORCPT + 54 others); Fri, 6 Jan 2023 04:46:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232986AbjAFJqO (ORCPT ); Fri, 6 Jan 2023 04:46:14 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6C3A625DC; Fri, 6 Jan 2023 01:44:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672998265; x=1704534265; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=fhXY6C/6U5im9JnhiBqmPE5GvqslI6HKlZc88plC8HU=; b=LCw2qM+/WlOf86kBXpCK6162AEhGv7KRqM1qPg0uofFdNn20fjPQJwKO V6aYMzKzdtlnEh1Z5C7X54efd3WfmAW37qDCUDsspLCXBGZoloyjJU2U4 9bgMJjXrdcNUx9ilcP9N7LnBZ20ANVWcuwB/Kl9uqJYF7TjF9XkoPsJRU UyqlpEaJ03UIT2QJ0sBOxSljSyyZpNnzkoxZ0cH7KfjzdXvdk/0/32H39 vY7hM2ZeyHuwy3FNmJxfjbQL6ssl62qAnLO8bLgZKGA6I7iKkP8VWdqpk YnM5LjRrXip4R0EhqPG+fBxHenJu/jdm3l/O7q6RMr2D3o7yWqefhmMw0 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="320148916" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="320148916" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2023 01:44:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="901237278" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="901237278" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.193.75]) by fmsmga006.fm.intel.com with ESMTP; 06 Jan 2023 01:44:12 -0800 Date: Fri, 6 Jan 2023 17:40:00 +0800 From: Chao Peng To: Jarkko Sakkinen 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: <20230106094000.GA2297836@chaop.bj.intel.com> Reply-To: Chao Peng 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: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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, Jan 05, 2023 at 11:23:01AM +0000, Jarkko Sakkinen wrote: > 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. Yes, people can always choose to add a new ioctl for this kind of change and the balance point here is we want to also avoid 'too many ioctls' if the functionalities are similar. The '_ext' variant reuses all the existing fields in the 'normal' variant and most importantly KVM internally can reuse most of the code. I certainly can add some words in the commit message to explain this design choice. Thanks, Chao > > BR, Jarkko