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 1AED9C433EF for ; Fri, 24 Jun 2022 08:47:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1A978E01F6; Fri, 24 Jun 2022 04:47:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C9126B0170; Fri, 24 Jun 2022 04:47:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 869BE8E01F6; Fri, 24 Jun 2022 04:47:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 75B596B016F for ; Fri, 24 Jun 2022 04:47:17 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 42C6E120B2D for ; Fri, 24 Jun 2022 08:47:17 +0000 (UTC) X-FDA: 79612500114.15.EF1B06A Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf14.hostedemail.com (Postfix) with ESMTP id 5AA8510001D for ; Fri, 24 Jun 2022 08:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656060434; x=1687596434; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=Jc8yORiINhpFzMTo8QL55TU28YhiMcNQ45ukyK/l2T4=; b=VzmD2dh9O4PT4K5ctZjJPc+mrSbn1X8ZJGdnDwYqG30MSLfO+/O3jKR+ TGAJUB2ZqjIKfAZgiwm6Tmt0imlKpfcuapDmeRMMohPIPDY7lZTU6JSFH H3AY3famWQ4b0xD/dYlOH1JctUFgHTupuVgcrxDsDF82MsUMb8vpwSwdD oWi/gONk2gzqibAxnxJlOqHp0CfmDqBFxjK+C7IOdH6dqYcJ0RY0aWR2W /Mijaaww2VQx4Pf3kCFtVqVyRy16tH9VjZoaDrXUQiKZY3micV/xwmNDN pjOqI8YA36ZocskqlkhIbjDfgUEteD9UshX4crlaZ4I9V4L4RdbROUYcG g==; X-IronPort-AV: E=McAfee;i="6400,9594,10387"; a="344951727" X-IronPort-AV: E=Sophos;i="5.92,218,1650956400"; d="scan'208";a="344951727" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2022 01:47:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,218,1650956400"; d="scan'208";a="586508201" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga007.jf.intel.com with ESMTP; 24 Jun 2022 01:47:01 -0700 Date: Fri, 24 Jun 2022 16:43:41 +0800 From: Chao Peng To: Michael Roth Cc: 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 , Sean Christopherson , 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 , 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 , mhocko@suse.com Subject: Re: [PATCH v6 7/8] KVM: Enable and expose KVM_MEM_PRIVATE Message-ID: <20220624084341.GA2178308@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220519153713.819591-1-chao.p.peng@linux.intel.com> <20220519153713.819591-8-chao.p.peng@linux.intel.com> <20220623220751.emt3iqq77faxfzzy@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220623220751.emt3iqq77faxfzzy@amd.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656060436; a=rsa-sha256; cv=none; b=NTlV13RwA1u4Tvix9GtasPWhdXh7pHywzVSwh4pmb/Z393V8JShfkFf+uBukbtIdD463M9 VL6VhUOQTU3ZvT5X70VVkGtwYCReCkfLzITaehXSDEGQ+B7joOuNlWVgmS+1AwUoYgQMuc ZnHeabjcbAJ3fICcoaH0i/xxZoWoq+s= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=VzmD2dh9; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf14.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 134.134.136.100) 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=1656060436; 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=9pqjyL1JINBbBoThUufP5dRYQpxoLXUS5UgLaOX/ZMg=; b=BC18Y6/Jd6aSjBdSORa0c+ScDhEgOMz1H7UvCNpVi5LpYhIl3qsFaswEy69LR6cEJdflq0 T4amS8/RilbP3hgxq+VL/AJTRmDMXAGzyhOvyaYMCcKp4PlIzCFydSa2EtUMbRjr9xhRh7 uBcB02D7v7nSR6QqB+v51BrDDRX9l4Y= X-Stat-Signature: 4p3e76zgbo19kt6y93dryaqibimfaimt X-Rspamd-Queue-Id: 5AA8510001D Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=VzmD2dh9; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf14.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 134.134.136.100) smtp.mailfrom=chao.p.peng@linux.intel.com X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1656060434-406034 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, Jun 23, 2022 at 05:07:51PM -0500, Michael Roth wrote: ... > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > > index db9d39a2d3a6..f93ac7cdfb53 100644 > > --- a/virt/kvm/kvm_main.c > > +++ b/virt/kvm/kvm_main.c > > @@ -843,6 +843,73 @@ static int kvm_init_mmu_notifier(struct kvm *kvm) > > > > #endif /* CONFIG_MMU_NOTIFIER && KVM_ARCH_WANT_MMU_NOTIFIER */ > > > > +#ifdef CONFIG_HAVE_KVM_PRIVATE_MEM > > +static void kvm_private_mem_notifier_handler(struct memfile_notifier *notifier, > > + pgoff_t start, pgoff_t end) > > +{ > > + int idx; > > + struct kvm_memory_slot *slot = container_of(notifier, > > + struct kvm_memory_slot, > > + notifier); > > + struct kvm_gfn_range gfn_range = { > > + .slot = slot, > > + .start = start - (slot->private_offset >> PAGE_SHIFT), > > + .end = end - (slot->private_offset >> PAGE_SHIFT), > > This code assumes that 'end' is greater than slot->private_offset, but > even if slot->private_offset is non-zero, nothing stops userspace from > allocating pages in the range of 0 through slot->private_offset, which > will still end up triggering this notifier. In that case gfn_range.end > will end up going negative, and the below code will limit that to > slot->npages and do a populate/invalidate for the entire range. > > Not sure if this covers all the cases, but this fixes the issue for me: Right, already noticed this issue, will fix in next version. Thanks. > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 903ffdb5f01c..4c744d8f7527 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -872,6 +872,19 @@ static void kvm_private_mem_notifier_handler(struct memfile_notifier *notifier, > .may_block = true, > }; > > struct kvm *kvm = slot->kvm; > + > + if (slot->private_offset > end) > + return; > + >