Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1624450rwb; Fri, 13 Jan 2023 15:14:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXv3VLezSs9Jn4mSMpFH1Gmh6+MuWk/eTTE87jf0Bw3H/+K9Msw0hraQ+nAC0gB9QM8h8JR0 X-Received: by 2002:a17:906:d96b:b0:862:c1d5:ea1b with SMTP id rp11-20020a170906d96b00b00862c1d5ea1bmr8616411ejb.8.1673651648721; Fri, 13 Jan 2023 15:14:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673651648; cv=none; d=google.com; s=arc-20160816; b=CtvTtsN4FRY83GH0RgFafeJPUhF94XynCbEGqePQws6og0NpbkgWaR9IMIJGc5poa+ 5Gm6um/uR1SVikNeGT7Qouu2Q/eJUhQlrL8VqnAovYQFWtjAZ7ZfYQXx82mU746g0Qd1 g4MXVRWNZvWwiHSRpB7QA/6GQhStz4iQTB11iaH6riy4F9Sz0si4i9g6joVAlUQaNZdL CvKQdNJOSpCNE8TmtxkjSHePjDH2JjZg05EsUGRUwmLlHZcmMBqlI3Xykahv/bVXYjj7 h4mH2RGhyNIXmJcQOr2s/ScdRUEhHBa82E0tWZ/fPM5tteYoWUDkBK1MYqWXrLssuJTq AliQ== 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=oYGGpY3c8wYSsolPP7oPQ187xmYhIxXfoDRmESiHutM=; b=MuL7jDyNaRPo1iI5cNbLmCouA6FIgZ7Eaqc8GV+Ik+0qZAqUUV+y28D25iUAZXCKnB BAMelBnyrxBLHk/XypOhfCH7D82zMG8zMju0ovi8aCOrwweISL5SZZ5N16XoaO4X4jRV Bd0Ag9vEacV9SkQQlA8uSjzUQKFAMz3gep+j+l/bxc4+12TDNDWmUqJUKgw17hf/dEUh 3/fPjAGWKNpPQ/1rwau/3wY0rW22fhNTwn1SOocd0twrFhGtCz3NKzzei1EDhMDAGhBZ sNHv+GOQt+E1wQoPd0Lux5m4PHyjiW6xuhk2mwVth34kx53q8pyDbVihEp3leylU71eT 9fng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tgwARpR6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg10-20020a170907a40a00b0086ae94c7927si2871487ejc.345.2023.01.13.15.13.56; Fri, 13 Jan 2023 15:14:08 -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=@google.com header.s=20210112 header.b=tgwARpR6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbjAMWht (ORCPT + 52 others); Fri, 13 Jan 2023 17:37:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbjAMWhq (ORCPT ); Fri, 13 Jan 2023 17:37:46 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DDFA77D21 for ; Fri, 13 Jan 2023 14:37:45 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id v23so19941127plo.1 for ; Fri, 13 Jan 2023 14:37:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=oYGGpY3c8wYSsolPP7oPQ187xmYhIxXfoDRmESiHutM=; b=tgwARpR6oX7pIqiIfedVsEF9/fVdX7R++KsquyR9ziZ7UzwRxscaS5kujj2zHNYPAs HesOuR7Sx5qOtSVwO3krm9uRXR5UTvzOqDPwLsoUS2mCaA5ph+KP9eBNBsRpd0A9L435 C78pBQlFmakDJoSXEeoufowua/fVMOTGqx3NtP2NIvaMzedd/pr1PLOYbQsS6dFkx5/5 kwCkXGYgxwKfF8lpKdpuKcjcpYVGyJ9gllu5qeMUhB05/Ix+APK3DiMQF2xJm40Kxo/a rgTKeVYwqHKt8DoSnIFSclpMZ4e19SkFrGNJvf/OTxDBdTMTbfjsPlmc3hwEOi/a1hX7 bWaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=oYGGpY3c8wYSsolPP7oPQ187xmYhIxXfoDRmESiHutM=; b=b6bHafyMn9Xx1qI/MZBoNpC5/W1CB5sgdPa/BEeAXKsjnb0+ITcMFs6kdOgvtuFENq UwtXiJ9aYnIiEi465/e3U82nLb1uSgxUKVvvfFzL4LM6jDD+/OuEtMmqKLiHgireMFr8 pe3gRjjP1YRVeEhsOHHFFZzUOti0jhSMgWADaJ5vT2E3v4XT8kgYab5qN/McK77KlqK8 IWM07MHOSt2Kwk9hruAF3ZqD5vGe7wQyfCwkSJBbdFaIDblQ+1biOIlnFaRX0pSZznGt g5eWZGAFvoJa0HX+e6504MnVu/ltWtuqC081GEiQkVAvn1W4BELpBbgBPKjQGSn7Jesw L7dg== X-Gm-Message-State: AFqh2kpwoXbpB9uBAAYzp1EPns8K9sc1AFI/7EVwafBPxe8/LxFs3XeY PV3a6xhLeUypiN03KzFDXLg84w== X-Received: by 2002:a17:90a:d148:b0:229:1e87:365f with SMTP id t8-20020a17090ad14800b002291e87365fmr580615pjw.2.1673649464636; Fri, 13 Jan 2023 14:37:44 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id z7-20020a17090ad78700b002270155254csm10626708pju.24.2023.01.13.14.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 14:37:43 -0800 (PST) Date: Fri, 13 Jan 2023 22:37:39 +0000 From: Sean Christopherson To: Chao Peng 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: 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> <20230110091432.GA2441264@chaop.bj.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230110091432.GA2441264@chaop.bj.intel.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Tue, Jan 10, 2023, Chao Peng wrote: > 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. The ioctl() magic embeds the size of the payload (struct kvm_userspace_memory_region in this case) in the ioctl() number, and that information is visible to userspace via _IOCTL_SIZE(). Attempting to take a larger size can mess up sanity checks, e.g. KVM selftests get tripped up on this assert if KVM_SET_USER_MEMORY_REGION is passed an "extended" struct. #define kvm_do_ioctl(fd, cmd, arg) \ ({ \ kvm_static_assert(!_IOC_SIZE(cmd) || sizeof(*arg) == _IOC_SIZE(cmd)); \ ioctl(fd, cmd, arg); \ }) > Then we will use kvm_userspace_memory_region2 as the KVM internal alias, > right? Yep. > 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? Yes? So long as its not used by KVM, it's safe. AFAICT, it's unused.