Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7534367rwl; Tue, 10 Jan 2023 01:59:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXtlExK5FIVXzVBKMNRW70NDM0dq7a0WMQ5PXN5ucgoJaJ5hZMdCmGsYc5fExH5fdHGNi/qN X-Received: by 2002:a05:6a21:86a8:b0:ad:6305:a4 with SMTP id ox40-20020a056a2186a800b000ad630500a4mr67641534pzb.48.1673344796970; Tue, 10 Jan 2023 01:59:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673344796; cv=none; d=google.com; s=arc-20160816; b=v3X83UvoT67nzSpjqTuSQVOUDHQJrkSYUnqwk99tSDuQZ101yUqQk+azBkiL0zsDLE SefX+v2UspGxjUkXDDqj8kCC4uW7vQ3lGnEYx1K5B55GwtekxRFUtrFL9vDZuwlSD8mZ duowzP4RWdv4Dk+vDru3ZDWnjPHu4rleuRpQUaqPh9QZIl/DYSxYN7PZhXLEwN7IdtdA aEa2a8U5m0ZqU4pu+fxigznJYnRLtKeJ3SANlj/UPk7FE/5v9kmBuV3txsuOIFRLHFe0 zIojbFxcBcOXHElAK6TrtYiEDVNCTYaRLyZBdtebF2gwkybPvYT6CiBwOGaGYHfZL1bm tylQ== 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=6A8l9LeafzkhjCZMFPdER1tQKzd2tVfkXCVwvAIl6z4=; b=RfqxjXTwgMaVdg+IbRKRp5P1jtjN6EuB190y/NG9oL/T3a16PM/3/83rea5m4hyiJ5 i/SQS7N1I2GQWs8a0FH/yXuvi2DC+28BOv/kNCZn4XClVaUPK/4eLhh+r/Thg0uNJDLq qIyFBGxRbRM8rThGN2iXsA1raa0vG/vxfGuVv5CD6eZG6N83wqZl4ox3BQsMP2Ly9k9X F8JylpK1tB9SWtXzEFIxjh6ElWpRMWVz+xtP7IriqUfPaVM74jw3Kpe8j/GHFvar9jVh NM5oodEHfsysJ+IesSqgXQg1YAf13s8tuTpE7GD5E+ecqLVgSyAjnUiGLDursAA5BeoN Ak+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=i1iV5CDg; 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 a65-20020a639044000000b004b64146f242si216150pge.430.2023.01.10.01.59.50; Tue, 10 Jan 2023 01:59:56 -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=i1iV5CDg; 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 S238081AbjAJJTx (ORCPT + 53 others); Tue, 10 Jan 2023 04:19:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238114AbjAJJTJ (ORCPT ); Tue, 10 Jan 2023 04:19:09 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB1395688B; Tue, 10 Jan 2023 01:18:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673342339; x=1704878339; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=2L0+jVEogDEzAgz7y5b+vzXDvmX8Ax8MX0YUEFpP2YQ=; b=i1iV5CDg83LjF3oXOFgMu7MxouDaTknFlDZcsvhoOcexgH6rqKUC8e+a pn0d0RvhB0etjXsBtzZySCdLwMi4FBvNHQLpDdBYB4FXaCvZrZLFFFTas rAYr2cpa5vZNfVvDTpOMaMNbhyKv5m6fBes/LFzge51E8m03Zve9zkP4h RkH01JsKpRuIEjbowIvj4/sFvMyDcnivNbaVGscf5bp+TyI04P+HLCkCV Wj4AhMV/jxVrrrzYYn8Dql9XOepHY7FILLGX9Cb4IaTJpuKn9qQ6d0+xq MDvd0crNvm3gV3Qdknc6/T7pITnpTg1v9ybr2twTzYaJ1TrbIZ7LzAYRe Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="324343028" X-IronPort-AV: E=Sophos;i="5.96,314,1665471600"; d="scan'208";a="324343028" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 01:18:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="689352645" X-IronPort-AV: E=Sophos;i="5.96,314,1665471600"; d="scan'208";a="689352645" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.193.75]) by orsmga001.jf.intel.com with ESMTP; 10 Jan 2023 01:18:43 -0800 Date: Tue, 10 Jan 2023 17:14:32 +0800 From: Chao Peng To: Sean Christopherson Cc: Jarkko Sakkinen , 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 , 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: <20230110091432.GA2441264@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> <20230106094000.GA2297836@chaop.bj.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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 Mon, Jan 09, 2023 at 07:32:05PM +0000, Sean Christopherson wrote: > On Fri, Jan 06, 2023, Chao Peng wrote: > > 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: > > > > 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. > > After seeing the userspace side of this, I agree with Jarkko; overloading > KVM_SET_USER_MEMORY_REGION is a hack. E.g. the size validation ends up being > bogus, and userspace ends up abusing unions or implementing kvm_user_mem_region > itself. How is the size validation being bogus? I don't quite follow. Then we will use kvm_userspace_memory_region2 as the KVM internal alias, right? I see similar examples use different functions to handle different versions but it does look easier if we use alias for this function. > > It feels absolutely ridiculous, but I think the best option is to do: > > #define KVM_SET_USER_MEMORY_REGION2 _IOW(KVMIO, 0x49, \ > struct kvm_userspace_memory_region2) Just interesting, is 0x49 a safe number we can use? > > /* for KVM_SET_USER_MEMORY_REGION2 */ > struct kvm_user_mem_region2 { > __u32 slot; > __u32 flags; > __u64 guest_phys_addr; > __u64 memory_size; > __u64 userspace_addr; > __u64 restricted_offset; > __u32 restricted_fd; > __u32 pad1; > __u64 pad2[14]; > } > > And it's consistent with other KVM ioctls(), e.g. KVM_SET_CPUID2. Okay, agree from KVM userspace API perspective this is more consistent with similar existing examples. I see several of them. I think we will also need a CAP_KVM_SET_USER_MEMORY_REGION2 for this new ioctl. > > Regarding the userspace side of things, please include Vishal's selftests in v11, > it's impossible to properly review the uAPI changes without seeing the userspace > side of things. I'm in the process of reviewing Vishal's v2[*], I'll try to > massage it into a set of patches that you can incorporate into your series. Previously I included Vishal's selftests in the github repo, but not include them in this patch series. It's OK for me to incorporate them directly into this series and review together if Vishal is fine. Chao > > [*] https://lore.kernel.org/all/20221205232341.4131240-1-vannapurve@google.com