From patchwork Wed Oct 30 13:49:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Roy X-Patchwork-Id: 13856551 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 53439D5CCB0 for ; Wed, 30 Oct 2024 13:50:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D705D6B00BB; Wed, 30 Oct 2024 09:50:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D20196B00BD; Wed, 30 Oct 2024 09:50:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9B2B6B00BF; Wed, 30 Oct 2024 09:50:30 -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 9280A6B00BB for ; Wed, 30 Oct 2024 09:50:30 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4636680C7C for ; Wed, 30 Oct 2024 13:50:30 +0000 (UTC) X-FDA: 82730402328.27.81F4CC1 Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) by imf15.hostedemail.com (Postfix) with ESMTP id D7C4DA0029 for ; Wed, 30 Oct 2024 13:50:01 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amazon.co.uk header.s=amazon201209 header.b=rmbuwUw8; dmarc=pass (policy=quarantine) header.from=amazon.co.uk; spf=pass (imf15.hostedemail.com: domain of "prvs=02621381b=roypat@amazon.co.uk" designates 99.78.197.220 as permitted sender) smtp.mailfrom="prvs=02621381b=roypat@amazon.co.uk" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730296110; a=rsa-sha256; cv=none; b=cLH4EV66Or6db9tb5j8ge4hvIphjCTXIaxJ3aMtIGx54Jj0CupxVNiFuEJ+JZZxeKHq3x0 O81OHCBK8BSbBpA39QkneGr5g14q72VoDatUQDJON2yn6y9rfK2mL6o2bC9ahQ9FqipQ7J JFlYglMmhTtQiLyBv9pOgn5zVfSQ0wg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=amazon.co.uk header.s=amazon201209 header.b=rmbuwUw8; dmarc=pass (policy=quarantine) header.from=amazon.co.uk; spf=pass (imf15.hostedemail.com: domain of "prvs=02621381b=roypat@amazon.co.uk" designates 99.78.197.220 as permitted sender) smtp.mailfrom="prvs=02621381b=roypat@amazon.co.uk" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730296110; 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=k/QSX0mI8qQz8W316WTJxbTS4bB3Lyue/iJHbqNfB18=; b=pJ8wA6WglSv44ATKR0zL+X3F9TKTL4XjK82qDxJbZkvfwZLlyjwv688EsSs3hy41lPs1Ku nWyDS4yHPCuWwP3TudKUb9MGAe91Ttrk9ih+3429Mjo5QCyCpZqPFtPcV9yquiv+hDKszS FJkDWPCIwmStDuF/S5ASSjUW1oPKTX0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazon201209; t=1730296228; x=1761832228; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k/QSX0mI8qQz8W316WTJxbTS4bB3Lyue/iJHbqNfB18=; b=rmbuwUw82tQVMx1tP9SL+XLdoCW7LITdBVr6bGCC6D3x6WOwfR1GG8XH BUitWi6b93Ncwn5j9PHOiDteY1I78t9d9FnpweaURY+XMIwPZXwCfnkEz RxsuAO3wUVWHDcvMvN/fepMjWPBWxiLcBA9xID+arSkBh7BEtGWsYfSAJ o=; X-IronPort-AV: E=Sophos;i="6.11,245,1725321600"; d="scan'208";a="142980689" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2024 13:50:27 +0000 Received: from EX19MTAEUB001.ant.amazon.com [10.0.43.254:32764] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.20.52:2525] with esmtp (Farcaster) id cb6221e8-e82a-4b95-aff9-f29080c6cf67; Wed, 30 Oct 2024 13:50:26 +0000 (UTC) X-Farcaster-Flow-ID: cb6221e8-e82a-4b95-aff9-f29080c6cf67 Received: from EX19D014EUA004.ant.amazon.com (10.252.50.41) by EX19MTAEUB001.ant.amazon.com (10.252.51.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 30 Oct 2024 13:50:23 +0000 Received: from EX19MTAUEA002.ant.amazon.com (10.252.134.9) by EX19D014EUA004.ant.amazon.com (10.252.50.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 30 Oct 2024 13:50:23 +0000 Received: from email-imr-corp-prod-pdx-all-2c-8a67eb17.us-west-2.amazon.com (10.43.8.2) by mail-relay.amazon.com (10.252.134.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Wed, 30 Oct 2024 13:50:22 +0000 Received: from ua2d7e1a6107c5b.home (dev-dsk-roypat-1c-dbe2a224.eu-west-1.amazon.com [172.19.88.180]) by email-imr-corp-prod-pdx-all-2c-8a67eb17.us-west-2.amazon.com (Postfix) with ESMTPS id 93E2B41303; Wed, 30 Oct 2024 13:50:13 +0000 (UTC) From: Patrick Roy To: , , , , , , , , CC: Patrick Roy , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v3 4/6] kvm: gmem: add trace point for direct map state changes Date: Wed, 30 Oct 2024 13:49:08 +0000 Message-ID: <20241030134912.515725-5-roypat@amazon.co.uk> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241030134912.515725-1-roypat@amazon.co.uk> References: <20241030134912.515725-1-roypat@amazon.co.uk> MIME-Version: 1.0 X-Rspamd-Queue-Id: D7C4DA0029 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gepd5iehxjyoft3rqrrpqonzdkwmybum X-HE-Tag: 1730296201-449342 X-HE-Meta: U2FsdGVkX18zTCCSwt7sTJREK637v3lNcTQOIAvNfBn+FUWt7mL7TozUHc59rcB2wdrepwxsshCyf+O77xWFq+G3NAQmCeEPBbe9hJucqcOWS9RjMXz9M+PTPG/uepOsbm1nAkXMJRux+bI56YMUArSb/2j4MeqAce5+/FrULvdl+iaOlhk4DfO7TjOgiUvuvK/XGanlD8DS4ullIXvI0vtHJ1l8VidNSkLDcldDjDLP2lY2C+NxELD1INH1xX1t1o6qsdqLtDom3XyS+5cgtVzZ5wxzVUjVEf4aIVU2ZPOQt209f1sW138VWaW8u6uRu5dZALeCc/eUD+mVUkS9JR7exGbikWJD03tR9HemVKd5V07ZjvhcT9Sqwsxw3Y5+YO/hQPO+So6lqWSruLdm1B9RE0EkpYbvJCvaU5o3gYqFp3GSxe9JwbXufrn/MiaIG3Lu8CC4qko8CqzGXwlV+QI0hlD940vgsx3wBx582sWYbnQhaaLmdo33kgIH7EQcCsLdmOm5KmrnNEl0JdVHvadc6soENfeejpCs0PQs/X96IMCt0Vuu9/7sMPOOYm5+0ts0U2mRCRn/FS0q0HDRxGnl95lm6ptiPDTE+2RSDSw4TMbcKnZSDbag8y9cCrI5WysZNW99xRr/waKzZrFldHiZ76HCujVdy6ygqC3z6mBqKvE8eMpi/lAvJucVZqMIlE4wK6o8fffrcjtTvtpTLYtK2iFBEnj4NWmxUnxUdsAIiDBAXd8hOV3yaSXtEAXlUgrjO09MHZO+2cUOjaKNWpf9QwfVe9raAJbVTK4Fgbi29Lzj0VMoJQfBxPBU7dZgdXUsBkhY3BwThZrmHizt5Jdy96nZJSQKcn3N+9rqiqqn7WQQ+KCJFrzrWlZZyxjKvOeYKssTMzxGBVjUoFdzUkPbuy3igONIqjn0g2ERWQxviWQ7cSx43bhPs6JKkM3J4/5sKHXnbUoaJmPg3rq iXPmsnEK hafx2oN39iR7vXJ6lOBXqruQl6T9qMMhYg95kAQBVYkS/ja0wYUIHsrsJzHIVamY9gUl6Tgn44Tjfu0Khj06Izv1xKcSsn1bSYK6ehHs+rlMmsWY5UHQp3/dV8IkQ3G7xudL97X56MLzuoTuI0jZURtbi36At4cRWHkz4Y/issU8ZOaapgu/+81xRR7bDsilVAbewSlUAPBssILtDU/Tj2H0KsRTbbFhYlgbosROLwaUunGvkj2yTeP09E5J6PEEer+fEJ4+R2HwOCqW98Nbqd0cQ8heGYg7y710hjnQQwVvmQ+yA9+UAsACBBxZbYMLxgBrJyzYoJNnRDsf7jLjecgdJPkbOTgRkzFzhLMeFvZjupMLemxcRCvUoHVC0l7uYR8tGn6i9r51gF6o= 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: List-Subscribe: List-Unsubscribe: Add tracepoints to kvm_gmem_set_direct_map and kvm_gmem_folio_set_direct_map. The above operations can cause folios to be insert/removed into/from the direct map. We want to be able to make sure that only those gmem folios that we expect KVM to access are ever reinserted into the direct map, and that all folios that are temporarily reinserted are also removed again at a later point. Processing ftrace output is one way to verify this. Signed-off-by: Patrick Roy --- include/trace/events/kvm.h | 22 ++++++++++++++++++++++ virt/kvm/guest_memfd.c | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/include/trace/events/kvm.h b/include/trace/events/kvm.h index 74e40d5d4af42..f3d852c18fa08 100644 --- a/include/trace/events/kvm.h +++ b/include/trace/events/kvm.h @@ -489,6 +489,28 @@ TRACE_EVENT(kvm_test_age_hva, TP_printk("mmu notifier test age hva: %#016lx", __entry->hva) ); +#ifdef CONFIG_KVM_PRIVATE_MEM +TRACE_EVENT(kvm_gmem_direct_map_state_change, + TP_PROTO(pgoff_t start, pgoff_t end, bool state), + TP_ARGS(start, end, state), + + TP_STRUCT__entry( + __field(pgoff_t, start) + __field(pgoff_t, end) + __field(bool, state) + ), + + TP_fast_assign( + __entry->start = start; + __entry->end = end; + __entry->state = state; + ), + + TP_printk("changed direct map state of guest_memfd range %lu to %lu to %s", + __entry->start, __entry->end, __entry->state ? "present" : "not present") +); +#endif + #endif /* _TRACE_KVM_MAIN_H */ /* This part must be outside protection */ diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 54387828dcc6a..a0b3b9cacd361 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -7,6 +7,7 @@ #include #include "kvm_mm.h" +#include "trace/events/kvm.h" struct kvm_gmem { struct kvm *kvm; @@ -169,6 +170,8 @@ static __always_unused int kvm_gmem_folio_set_direct_map(struct folio *folio, pg r = __kvm_gmem_folio_set_direct_map(folio, start, end, state); folio_unlock(folio); + trace_kvm_gmem_direct_map_state_change(start, end, state); + unlock_xa: xa_unlock(&gmem_priv->direct_map_state); out: @@ -216,6 +219,8 @@ static __always_unused int kvm_gmem_set_direct_map(struct inode *inode, pgoff_t folio_batch_release(&fbatch); } + trace_kvm_gmem_direct_map_state_change(start, end, state); + xa_unlock(&gmem_priv->direct_map_state); out: return r;