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 63B27C433FE for ; Fri, 7 Oct 2022 11:14:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2F386B0072; Fri, 7 Oct 2022 07:14:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDE236B0073; Fri, 7 Oct 2022 07:14:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7F476B0074; Fri, 7 Oct 2022 07:14:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9576F6B0072 for ; Fri, 7 Oct 2022 07:14:12 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4CF1180F70 for ; Fri, 7 Oct 2022 11:14:12 +0000 (UTC) X-FDA: 79993894344.17.9E37D52 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id A3D3D20027 for ; Fri, 7 Oct 2022 11:14:10 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7290861CBB; Fri, 7 Oct 2022 11:14:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FF19C433C1; Fri, 7 Oct 2022 11:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665141248; bh=iGUUEynvCAjegBrsy6JU4OD39853Ax+NThhfisNR9Vo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fmKEzZfv+NcFm5KZPC8vC7ZMGO+4smagpqxidG4f8sTZ/z8q2aoMCJSNtysPorB+u kk9P97XlyfQbbtnFo8LHPNJFX9dz+rglzxIJfihqhOEfRZ95SMPj67dZ/fvnuNbSqC jqfHkAdl/kZOqmVgzI+rs0S1M/uPV1KhYkYw7RvKkChyMhuiR2/2wEETdeyyy8vdL+ xSn8DoYpH/zTYYkmMvP9NOyVC0t2HvDfp9uL80OcPykiAatvUGYg8ebg5q6VkchIVf DXvK7t9XwhCTk3XnR5NXjkt3/qkelWVMPuwnPC3EPAwGRYke53ktd+UBomw4T2mbx6 O0+yu62YgKnxg== Date: Fri, 7 Oct 2022 14:14:03 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: Chao Peng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@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 , 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 , Michael Roth , mhocko@suse.com, Muchun Song , wei.w.wang@intel.com Subject: Re: [PATCH v8 2/8] KVM: Extend the memslot to support fd-based private memory Message-ID: References: <20220915142913.2213336-1-chao.p.peng@linux.intel.com> <20220915142913.2213336-3-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=fmKEzZfv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of jarkko@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jarkko@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665141250; a=rsa-sha256; cv=none; b=sSqVfCHkHavJJ+17SNBseD9ntiuFtDRMHlLSbZ0uT/bUF5TM0Nko6Jqh7odeCOZ7LkG/p+ hVaG7/LcWq17CPVYRo1jiX6v9/4kPzYpIG0e+oOR8aahYQxJiM6Yw5UutzKkXU8BX4Yf5e nMaH8hThU4q5cQ3Be1+1EjByVPjR7Tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665141250; 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=ylMaT+d6tmjinoUS+YA33dc3XWHNX1i4tTYbatTBtk8=; b=o01ZwjrM1jICoOXDyQP5anAHUM4GZ9KAf6MbQqj1+8kpWuc8307yccC9GSJK02mSaOYAwI 3Y0ufb+KCxZ0712wT1Yc9XreMILpK1le1ngTI9Yb1dKEJob3m/1oshSn6sWsIXDbYUdtoq IWyB6cfcgnwK6DtwE3LP2WA8D3dN0sc= Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=fmKEzZfv; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of jarkko@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jarkko@kernel.org X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: ujoh9g58nja8r6c197uc48bqu9yc5wmg X-Rspamd-Queue-Id: A3D3D20027 X-HE-Tag: 1665141250-669356 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 Thu, Oct 06, 2022 at 03:34:58PM +0000, Sean Christopherson wrote: > On Thu, Oct 06, 2022, Jarkko Sakkinen wrote: > > On Thu, Oct 06, 2022 at 05:58:03PM +0300, Jarkko Sakkinen wrote: > > > On Thu, Sep 15, 2022 at 10:29:07PM +0800, Chao Peng wrote: > > > > This new extension, indicated by the new flag KVM_MEM_PRIVATE, adds two > > > > additional KVM memslot fields private_fd/private_offset to allow > > > > userspace to specify that guest private memory provided from the > > > > private_fd and guest_phys_addr mapped at the private_offset of the > > > > private_fd, spanning a range of memory_size. > > > > > > > > The extended memslot can still have the userspace_addr(hva). When use, a > > > > single memslot can maintain both private memory through private > > > > fd(private_fd/private_offset) and shared memory through > > > > hva(userspace_addr). Whether the private or shared part is visible to > > > > guest is maintained by other KVM code. > > > > > > What is anyway the appeal of private_offset field, instead of having just > > > 1:1 association between regions and files, i.e. one memfd per region? > > Modifying memslots is slow, both in KVM and in QEMU (not sure about Google's VMM). > E.g. if a vCPU converts a single page, it will be forced to wait until all other > vCPUs drop SRCU, which can have severe latency spikes, e.g. if KVM is faulting in > memory. KVM's memslot updates also hold a mutex for the entire duration of the > update, i.e. conversions on different vCPUs would be fully serialized, exacerbating > the SRCU problem. > > KVM also has historical baggage where it "needs" to zap _all_ SPTEs when any > memslot is deleted. > > Taking both a private_fd and a shared userspace address allows userspace to convert > between private and shared without having to manipulate memslots. Right, this was really good explanation, thank you. Still wondering could this possibly work (or not): 1. Union userspace_addr and private_fd. 2. Instead of introducing private_offset, use guest_phys_addr as the offset. BR, Jarkko