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 A32A6C63797 for ; Tue, 17 Jan 2023 12:50:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E7E56B0071; Tue, 17 Jan 2023 07:50:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2712A6B0073; Tue, 17 Jan 2023 07:50:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 111DB6B0074; Tue, 17 Jan 2023 07:50:19 -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 ED7596B0071 for ; Tue, 17 Jan 2023 07:50:18 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 98A61C0B44 for ; Tue, 17 Jan 2023 12:50:18 +0000 (UTC) X-FDA: 80364274116.15.27CE09D Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf06.hostedemail.com (Postfix) with ESMTP id 9BC8F18000C for ; Tue, 17 Jan 2023 12:50:16 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="W/tBpyO1"; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf06.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.93) smtp.mailfrom=chao.p.peng@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673959816; h=from:from:sender:reply-to: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=Gmhx5Ziq1GEsTU03LLG5cYiduw/9oe2bHYKB7jTYwrk=; b=fvCCfJgG9yPhta7Fo71EqMJXRxN71gXwbyo9h60HDRseGh5zWjhV8oWXrOPJ6shcKUkXpF WVS921KMZ31SVFnvbetFc6Tww80HuomSFBaB6SBlGYHKbNeWEHo9sukOWm3bJ7bdh1Cdf0 NfMD5riAGA0MWokmtWWQsFmeOukAihI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="W/tBpyO1"; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf06.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.93) smtp.mailfrom=chao.p.peng@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673959816; a=rsa-sha256; cv=none; b=g1g03LM869+24avop4AM4s5ZL4iw8/Ul5BnaVSFrriNCHrG67anMrvAPoWdZfVIGgY9ZOE RTnds/FOeUGKO5y5UIn05soXfKqzHMpSweHESiLT3v90F64NfGaimjMQsO20nHTvId9RrD VjMdxEv9Q/V9xd8sbpsCMbMZaE+sPjg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673959816; x=1705495816; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=ymQ/JZoVFvqCeW/jz/ISyD5XcjWYygq7yVQJBCOqdNM=; b=W/tBpyO1xpu6S9S3QaQEjj1X4Yk7J6pWV59S9FeV67vUiVuuxIB9mqws xi9AH1Ppk4STw1tcErxtS/l6tZvH3yj0Aao979mWBmzfzCBFCfqlYzK3K vjs8us3agjhiySdFfDbuhnalh2wPMiYUMhO60n7UyMOy/CqsE+etkitzH cZAZJJ69AcnRpjbojwKmnoL7A7qCHtLO6uVT7MKPEGmf08FgicOF1+X1a S2yuG5QwuJGjXdscZxL7CvVNG4s4ttAPf3yNlNcVm65B9/iVuwy/LV5jo ImckcQ1i9TT/H/NVYD/vBLxSbIxVR+vQ18wmGhiU28TKgKFBrRXPkbZR/ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10592"; a="322374482" X-IronPort-AV: E=Sophos;i="5.97,222,1669104000"; d="scan'208";a="322374482" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2023 04:50:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10592"; a="691571557" X-IronPort-AV: E=Sophos;i="5.97,222,1669104000"; d="scan'208";a="691571557" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.105]) by orsmga001.jf.intel.com with ESMTP; 17 Jan 2023 04:50:02 -0800 Date: Tue, 17 Jan 2023 20:42:14 +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: <20230117124214.GB273037@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> <20230110091432.GA2441264@chaop.bj.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 9BC8F18000C X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: dmyhbbwofjjj8mmrcik3b7seaop9dhrg X-HE-Tag: 1673959816-545366 X-HE-Meta: U2FsdGVkX18PFfBuSi04EhJtosPjHLwUNx13JtKJnMitKvyAAfg5yo98vPmwObR/3BXrUyJQQ5zlwes8eiAx8vy28hwjkitezfP8Yhhr1+zJXDHw4w3SKKZFT0yC0CcqlvuS8rix5YdiO69wd0Z4T669R2dJgfNSmgh4cnCTteLOr2QwQQUbSvI7UYhG1AAgtv6R4H1XpRUWBhdqwPR4XP1ECCi7qycdwVXqGKYylvQRqsMnzZnWDFeq0aFO3l42t4T3BZBTIA7IVKvvdAMBzuZjWCihd1umy/fermPyGJCJZk0EAepYekqC1K70x57kF1uXPRHUfmH2Z11nVP2toiFsziSunkzK1iUFovVB3e1e8JEKE8TdKdvYfmU+Ean3jSyYYNO7Y18zlrazZoQimHa4FsOgbTk/Xx7w6AUsL3X0SqTutBI725OVQDByaAW/YAtMfShf53NXbCTpv3mnT9beqiZ2dUFm+BZVKxzM6Sj7JsRasRPT743im8cM48IcVvIYIoLhiTVfESwhzGwUFoBQDhNUYUhsevvwOtTWMlagXSPA57q8mxIgWRxjU4wkoFCiO3WWiRXF4Ic8ImhjaqD0CBYwtgIclKAml0AdiIPSOVh4kcby+xcaJDYcFte7Hesi+TWG5Fl6MogvH81le9nM3gNEra6OWYdEYZGl6DV9y3RLQTmR/DyLLPgczp+tKcOqg47FC7k6NZmcI/lKfsGQNaro5JbRL+UcmXvIsZgNPJSqR24J/FIOYMZZwVTejBF9rggTUUbJXzQ7q3JSDzCVXeSTxaIKYIizYKSvTfZWLoN6tGVPGKBeOVPH508Qy6tITX8xRLty1G6yF7W1yHD9VfO2g0cMVOdjp5wasjUCKQ8NaUA+ZEPPXBUc8jYmL9ZLUqmVL9B+2iTWGREx8IPw+zki8eyzY9yKqiZKSgeRobKlGIq0ptlmmtHnl65icOIRBUvauiI= 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 Fri, Jan 13, 2023 at 10:37:39PM +0000, Sean Christopherson wrote: > 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); \ > }) Got it. Thanks for the explanation. Chao