From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BF1AC677F1 for ; Fri, 13 Jan 2023 22:37:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F9E38E0002; Fri, 13 Jan 2023 17:37:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A9858E0001; Fri, 13 Jan 2023 17:37:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E650F8E0002; Fri, 13 Jan 2023 17:37:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D1EFD8E0001 for ; Fri, 13 Jan 2023 17:37:47 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9F6E5C0646 for ; Fri, 13 Jan 2023 22:37:47 +0000 (UTC) X-FDA: 80351239374.17.9667E17 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf03.hostedemail.com (Postfix) with ESMTP id E7E0120002 for ; Fri, 13 Jan 2023 22:37:45 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tgwARpR6; spf=pass (imf03.hostedemail.com: domain of seanjc@google.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673649466; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oYGGpY3c8wYSsolPP7oPQ187xmYhIxXfoDRmESiHutM=; b=NyZthgyrEadDz7iEpAyJ+8eaHkha5yLyJfIZ3PR+SXBhupZv23JOf6FNlxpvU/Epdhi96t 9/P72yw9jH4yU2Xty2mBoeWEu935T2wf5qbghGz3d0QgurTxT0froetcsNwbpeAcKoBudF sA47QEkTExvNxY8iATFNUGD1vPp/jPE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tgwARpR6; spf=pass (imf03.hostedemail.com: domain of seanjc@google.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673649466; a=rsa-sha256; cv=none; b=zWaT63BqExR/lbEMk9CHLqFHUb8X+rMSvb31FPwJ7jQCfHJi/PrYIo5e2ljuvJrp2F6Gsc XrxxsNuDXEKxf6djqkwZLPccqgTuBJxOM2Pk8COiVQ3K2hK8q2td2ifb4xGLZdm17/dN8G bPhPtPez6KJSxLBvv3dsDlsN11YgyFI= Received: by mail-pl1-f169.google.com with SMTP id jl4so24838552plb.8 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=S/eKVBHk/esE2CN2ksE5n9pGCABaaeUj3XhLRTaSpPWNvxawH2wl7JLglSMx7WeZz1 8nsyXl4O+7ysAi8jz/Ls01+hfxqyk7C8MXEuie4GhOl9K2KSTK4lesGt4S++ds6/aI6D ZGSVotFZAOFnc2vcHXkTTs7LPH2qmxpE8qV17O0fHQnsYJzYtfCF/wXjQUQMOiTNNVqw ApGWAQpLG8aeXWLGZhDyavUR2fp64DznEtOKit/BbQfnOsgOLu7405mF19XS3tlUoH9t bCokqC5CO1dTK3TQOyC521o9lL2Np8V8JdCenzqbUs+7xex80dQ20LKoJFJ4jYApmG8q P5Sg== X-Gm-Message-State: AFqh2ko9dfp7AvHjTyVGooKzVKrIqYXeBeSzr42bYzxQXFzWBBg25NL3 fTAdPcI2LzWnH6MnSFrDN9sLlQ== X-Google-Smtp-Source: AMrXdXt5stBpwIEJwVXkUT6AxYk7gqWiLYnlxJx1z/r5PInmsD3i+NPQ2hSxNQ6Dxd7BftBMBypz9g== 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E7E0120002 X-Stat-Signature: tgw5cm3i1za1u43iiyozmihb1y5xa1pd X-Rspam-User: X-HE-Tag: 1673649465-58236 X-HE-Meta: U2FsdGVkX18+q9EOy+dSMrxhzbTbBb3KFd/+Bz8prB7fshaTmsaSOBvJixS/Maelz8wvIaTveFKdtgxwWk1BuELbZXi60xFEqK09+it898epx/z+8FeseCIfBMVMdXoV9OCoZPnZkZyb0XoMJYgpIJx0OLw3KADrL4X1eCCwYKmYJ31fnP5C4B70VfTjBfhsMM8kv2TsqflFIfWC9MFb9UdQ/lQPMsXrKEO4A3GvusmvULvXAOTcKAqSf0qG7iikwV0WTLfemUBoGabkQCFBXZNgjttbU/pDQXHRqo35FrrfP7IjhYYy6mDZT+nWmzFIYDMYTqLxhuSgMEmf07N5xlSi3uy7vw1NXkkSqK0RUT82ekzUIe/PMLTWAlj2jnhSUd4nrETYAf58VH3SGFsGR4iJY0VwnHcCizM4T4X3dVev1uw9n+/NhYRowv29vAt4FuA6PISI6xAE2RsbmTd0l+SD2UU0+e7WuywbXSkUxyAqfo/4bP9d7Uf/hQqIW4xPFO5nV2RWgRWuAlpZRe0SViOxU4dCbOTj6kphL7WmXmqa4ivOpX9LQoGbchzb50Hr7oaq4uYU9wp/QljFMSxLP7X2QOPApjc/C8taD3W+WDxqL7jXpeEWT3z+G2dAF/TR7egSUcN+e1+B6Gwftpaiv/v4awHpIO8lbcZ8gxIFvdscRdfdmBcU04KkqcwZhA7bswLOakrksewSHa+N+o8iSai+jXIAh9efrkqR8IQ3MCA6mXWjlH13Vmlm9GWCBpBNebIf0KG0f0L+1HZTO64JsKdHQHhdU5W+KwzYxwLMZgoRtveVoU/F6Rfqm5KDgH2iBSLrauoIvjPPLE5NAwRCIifL2btLWNaz/J+FZref/VLYEBgdeB2CyE2MmPNm1SxMRQyFiS0gxuWRrirzDMc4TzP66MJfQRlypSLxSyjde6jsEBxGYpkJmDuQNop+Tpvd4gTHdr61WjzaxFNqilM uctryHEr W/xnL8QDEVF3vsHziYJL6ADZIWUh6YRrF5dnI9qYpShIheSxMphPAAYJN+KA3lYj+fWaGgQO9ggffS6LopYhnDzlKBUMuaj18ygLw X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.