From patchwork Wed Jan 11 00:02:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 13095776 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD13DC46467 for ; Wed, 11 Jan 2023 00:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ZjXY1Q9wMlnJ5l4ZrPLZOtT9un9IhAU/SuK+9hq/QZE=; b=lGEdKyPBJ9vuva zUgfnlw0XvEfLhf1tgKuZYFsXNf2EVWzWJj8PSqbbW7A8kc6mxnlTeGVQCz+KZqPa+5rmFWUIconB OSPHzAowjB20HMWKGbyJWctF1iJbq1RJyydr/fHzYMIv4gT8hz2+aLPUcXjYntpk90TDkSfqlLTVR YoxQysBE9f17iWlQQB6CSE+Q3VMQzGLPIK6RE4ykfnRLQ7cTpRN5wLnNwOzZ07VR5WeSnSwCM3emX k1m8tF+w3vkHKwxHxcxdg/yRCOIGphHxjKDigfYsvwDDjPS2RZsrofOF4Di4CvmsYQYIEChXUo9ZR +Sf30KzHj0ulTiZOEKMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFOai-008y8Y-B4; Wed, 11 Jan 2023 00:03:40 +0000 Received: from out-173.mta0.migadu.com ([2001:41d0:1004:224b::ad]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFOae-008y6z-3x for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2023 00:03:37 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1673395412; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/eZZc/neLJzaT5SbsrQS+XXWG1igFh8UZKu9r852wV4=; b=kjbG7c9LKCmdNB6lZAS8aeSKBdkPzIz9MmWwa9qUOXnoPDiY2a3/vQyF6rO8+1o1ny4axV pDPHdlQY7kMikhL0r7jdTXFOr1g95+0iIzMp/MD2+GHTyQqGcAYREugtR7Pa5HIQPlr3ci unVSsHaacTs0ITiUYNGZk0gqozaM9dI= From: Oliver Upton To: Marc Zyngier , James Morse Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Quentin Perret , Will Deacon , Reiji Watanabe , Oliver Upton Subject: [PATCH 0/5] KVM: arm64: Handle unaligned memslots in kvm_(test_)_age_gfn() Date: Wed, 11 Jan 2023 00:02:55 +0000 Message-Id: <20230111000300.2034799-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_160336_593104_59A5B6F7 X-CRM114-Status: GOOD ( 11.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There is no requirement for userspace to align KVM memslots to an appropriate boundary for the backing memory source. For example, userspace could choose to use 2M THP and place the memslot at a 4K offset within the hugepage. Under these conditions, KVM can only map at the 4K level, effectively shattering the hugepage into a table of PTEs. kvm_(test_)_age_gfn() operate on the assumption that the GFN range is of a single page or hugepage size. Furthermore, this assumption bleeds into the table walkers, which walk until reaching the first leaf PTE. This completely falls apart in the aforementioned example where the memslot is unalgined, as there could be many leaf PTEs that need to be visited for a single hugepage. Furthermore, this configuration can lead to the WARN in kvm_age_gfn() firing as well. This series addresses the issue by rejigging the related page table walkers to traverse a specified range of memory. I also roped in some cleanups that I did along the way (i.e. patches 1 and 5), but can easily respin w/o them if desired. Tested on Ampere Altra w/ kvmtool and KVM selftests. I was going to implement a reproducer for the issue in KVM selftests, but there is a significant amount of idiot-proofing around the memslots helpers that prevent an unaligned memslot. Might get back to that when I have more patience for it. Applies to 6.2-rc3. Oliver Upton (5): KVM: arm64: Hoist S2 PTE definitions into kvm_pgtable.h KVM: arm64: Add a mask for all leaf PTE attributes KVM: arm64: Only return attributes from stage2_update_leaf_attrs() KVM: arm64: Correctly handle page aging notifiers for unaligned memlsot KVM: arm64: Consistently use KVM's types/helpers in kvm_age_gfn() arch/arm64/include/asm/kvm_pgtable.h | 66 +++++++++++++++++++---- arch/arm64/kvm/hyp/pgtable.c | 79 ++++++++-------------------- arch/arm64/kvm/mmu.c | 18 +++---- 3 files changed, 88 insertions(+), 75 deletions(-) base-commit: b7bfaa761d760e72a969d116517eaa12e404c262