Message ID | 20240709132041.3625501-3-roypat@amazon.co.uk (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 19F88C3DA41 for <linux-mm@archiver.kernel.org>; Tue, 9 Jul 2024 13:21:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CD8B6B00A8; Tue, 9 Jul 2024 09:21:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 954DE6B00AA; Tue, 9 Jul 2024 09:21:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A7976B00AB; Tue, 9 Jul 2024 09:21:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 52D5E6B00A8 for <linux-mm@kvack.org>; Tue, 9 Jul 2024 09:21:05 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D09251A18DA for <linux-mm@kvack.org>; Tue, 9 Jul 2024 13:21:04 +0000 (UTC) X-FDA: 82320274848.06.73A3293 Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) by imf14.hostedemail.com (Postfix) with ESMTP id DD2E910001A for <linux-mm@kvack.org>; Tue, 9 Jul 2024 13:21:02 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=amazon.co.uk header.s=amazon201209 header.b=TRYTELdB; spf=pass (imf14.hostedemail.com: domain of "prvs=913fd7204=roypat@amazon.co.uk" designates 52.119.213.150 as permitted sender) smtp.mailfrom="prvs=913fd7204=roypat@amazon.co.uk"; dmarc=pass (policy=quarantine) header.from=amazon.co.uk ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720531232; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/DNQp/z0GUBgLTV7ZRmRKhZQi2WgjcFO0AlHckf358s=; b=lDkCPF1mfZFXl8l+ea8I5uQRujQ6RBWrpvLJm7iGXGtFl/tzzBBrD/eRGpyXlel21iHKvc gXIKvTDecBrNQFc/eKxucBi1eBqA8ZLMUwAfCcJcuCcG7WCdgXMQxPQfAD/HnorKuHPhhu WNk0RrLsn8KzGvktwJg4+Nx+fuC07sA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720531232; a=rsa-sha256; cv=none; b=Y/bzvv2t/m93rLIwIeYX5Xcoremk4z19J2tc7alvTNpdyBdDfuzwJEnA4JLqdT8zXI9Taw qOKBDc8c+NmhB2r4rn4YIOswsIpz8qvcOtDDXhEz7ePEtF1MV8V7vgf/Il8HK2UKRNwPOb yrnQdcGK0MKQynVsQYwq1Y+StMCZ5l0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=amazon.co.uk header.s=amazon201209 header.b=TRYTELdB; spf=pass (imf14.hostedemail.com: domain of "prvs=913fd7204=roypat@amazon.co.uk" designates 52.119.213.150 as permitted sender) smtp.mailfrom="prvs=913fd7204=roypat@amazon.co.uk"; dmarc=pass (policy=quarantine) header.from=amazon.co.uk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazon201209; t=1720531262; x=1752067262; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/DNQp/z0GUBgLTV7ZRmRKhZQi2WgjcFO0AlHckf358s=; b=TRYTELdBQH+qRpT5u2tcoKSXuWhZRosBu9ZITcrOF2+38mj1AX4heVYP hV3VJPUCYqTfjuGvqr0XKNLamXhVLyvAR6bQ6987mkWFlE6JxfEj1cBPW 3qfseaMrEk1iTh1gkY179Kd2KTgoEF8vyKazOzTrs0TbggXBfDWp8zBts 8=; X-IronPort-AV: E=Sophos;i="6.09,195,1716249600"; d="scan'208";a="644664049" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jul 2024 13:21:01 +0000 Received: from EX19MTAUEA002.ant.amazon.com [10.0.0.204:55215] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.17.85:2525] with esmtp (Farcaster) id cb50a819-87b3-4fab-a17a-29e4e0b8d5a4; Tue, 9 Jul 2024 13:21:00 +0000 (UTC) X-Farcaster-Flow-ID: cb50a819-87b3-4fab-a17a-29e4e0b8d5a4 Received: from EX19D008UEC001.ant.amazon.com (10.252.135.232) by EX19MTAUEA002.ant.amazon.com (10.252.134.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 9 Jul 2024 13:21:00 +0000 Received: from EX19MTAUEC001.ant.amazon.com (10.252.135.222) by EX19D008UEC001.ant.amazon.com (10.252.135.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 9 Jul 2024 13:21:00 +0000 Received: from ua2d7e1a6107c5b.ant.amazon.com (172.19.88.180) by mail-relay.amazon.com (10.252.135.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Tue, 9 Jul 2024 13:20:57 +0000 From: Patrick Roy <roypat@amazon.co.uk> To: <seanjc@google.com>, <pbonzini@redhat.com>, <akpm@linux-foundation.org>, <dwmw@amazon.co.uk>, <rppt@kernel.org>, <david@redhat.com> CC: Patrick Roy <roypat@amazon.co.uk>, <tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>, <dave.hansen@linux.intel.com>, <x86@kernel.org>, <hpa@zytor.com>, <willy@infradead.org>, <graf@amazon.com>, <derekmn@amazon.com>, <kalyazin@amazon.com>, <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>, <dmatlack@google.com>, <tabba@google.com>, <chao.p.peng@linux.intel.com>, <xmarcalx@amazon.co.uk> Subject: [RFC PATCH 2/8] kvm: use slowpath in gfn_to_hva_cache if memory is private Date: Tue, 9 Jul 2024 14:20:30 +0100 Message-ID: <20240709132041.3625501-3-roypat@amazon.co.uk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240709132041.3625501-1-roypat@amazon.co.uk> References: <20240709132041.3625501-1-roypat@amazon.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Stat-Signature: w1ehet1h5h3fkzh16im3gtnxqom9pcwc X-Rspamd-Queue-Id: DD2E910001A X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1720531262-351064 X-HE-Meta: U2FsdGVkX1/8oC29ARNtNO549rqknBzbVvRa2jUTKPSytTF9LsfJoX+XSd7X2dJGYAMs4jOS0h0qVgessklK2OyriPX/lCVsQsPn7MJOr1A90j1Z68HefTGDTVMzPu8SHtYu5iuXXWjnZ+M9yr19Ix4xWO3Yh7brPYmCJZrPD4dRyAMSqly3VwWdiZRboNZbyeI0ItlTt2TDykpMu3XD4MyDagdSNQ8A39L/WSziUGg9Apl+6iJ/OvudGRWZo28F4yzoNBR2den40RRW4vTfbiaat4D3bf0kh35+oNupISYrSZ2s+NKd6BWE+iE+/gLGRWGiAy98XO+eodVNxdhNp83Z+s243+FNExyERXn7y1nUVIdURX9KPG4b6b6+Xb83yEjGFP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amicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
Unmapping guest_memfd from Direct Map
|
expand
|
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index b3b3de70a4df..4357f7cdf040 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3603,7 +3603,7 @@ int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, if (kvm_is_error_hva(ghc->hva)) return -EFAULT; - if (unlikely(!ghc->memslot)) + if (unlikely(!ghc->memslot || kvm_mem_is_private(kvm, gpa_to_gfn(gpa)))) return kvm_write_guest(kvm, gpa, data, len); r = __copy_to_user((void __user *)ghc->hva + offset, data, len); @@ -3641,7 +3641,7 @@ int kvm_read_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, if (kvm_is_error_hva(ghc->hva)) return -EFAULT; - if (unlikely(!ghc->memslot)) + if (unlikely(!ghc->memslot || kvm_mem_is_private(kvm, gpa_to_gfn(gpa)))) return kvm_read_guest(kvm, gpa, data, len); r = __copy_from_user(data, (void __user *)ghc->hva + offset, len);
Currently, KVM uses gfn_to_hva_caches to cache gfn->memslot->userspace host virtual address (uhva) translations. If a gfn is backed by guest_memfd however, there is no uhva-equivalent item we could possible cache, since accesses go through a file descriptor instead of a VMA. Thus, we effectively disable gfn_to_hva_caches in the case where gfns are gmem-backed, and instead do a gfn->pfn translation on the fly by calling `kvm_{read,write}_guest` inside `kvm_{read,write}_guest_cached`. Signed-off-by: Patrick Roy <roypat@amazon.co.uk> --- virt/kvm/kvm_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)