From patchwork Thu Jun 8 22:05:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Tse Shao X-Patchwork-Id: 13272950 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 3FF95C7EE29 for ; Thu, 8 Jun 2023 22:06:36 +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:Cc:To:From:Subject:Message-ID: Mime-Version:Date: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=MIBt5wwer7LFmIwNkxqIdJlGOiRYluZroPv3+LF/3vI=; b=23f iq7+LhtNpUWhnTJeybRLaC1pRMsTWHdcax3ERzJDcv/rboyQUeSHu/IB7qjoKvLTfFlCP4d9IseIE BWArJV+LucnBIwQ5NHFIMhH+cD95hZFwvKUIfCAC3H2whHO8fXHkLMoRcejHXqhBtkLZjRyxD0mt/ Xc2toZl18LjnzFeVFB8GfRX4y4rz8AD0m4L5uGbQL4b+5sH4gtKazI2xUZUdbgD3XJiDrLtlnyedD gEntkABSzFCLb+3PSwrR6d358GezSjsAJVrKJaKbGE0tTVbtWlLsgqsIAemzSoj8pDB3tLrUhVT22 i7DAYoPoGboIbF2z9yNw1AQcYiPo/EA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Nlo-00Akqt-1H; Thu, 08 Jun 2023 22:06:16 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7Nlm-00AkqB-1O for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2023 22:06:15 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1b0314f0aadso911105ad.0 for ; Thu, 08 Jun 2023 15:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686261972; x=1688853972; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=f9CaDc6GGBWuK7eCpoNYT6YueR8Zbl2jpIpeaKQVQvQ=; b=g6TUacceAYPEbfsv6EW0WtXBfm6IOz5S5d+OFFFjRuXIN+Gt6qw1Hxz/wxQRodLv6Q fZvF+Q31Rn/FCi8bHs7ONm0lzgg2+m7cQKkQ6aAmUBSZVRKELWdRRtCJE1LkgFGEy3zQ SxZE6ZO51wmiUifCL70ATkprYaVBcUZO8HlrsZfUqqxFI2uuJg2p5Hgbntzk6iKii5ZF qYY0amN96y9UZxoF6WKyTwgEpRR55ljoc844L4vL0UGsBIG0swmXQmOgRXIkO3EUuJIv vyKSVUkn1eQVVuBk8NZ6GWTUIYEHnAR4AAFKiV+taoOoCgyj5MdYG6SmNJrXxexjNXoH ZfQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686261972; x=1688853972; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=f9CaDc6GGBWuK7eCpoNYT6YueR8Zbl2jpIpeaKQVQvQ=; b=QuWLzSkRgy6dIz2Sv7VfSOvryGecoa35sEGKtHZc85XI3YMO3dWcLFtBY3xi9sl4Gs zUHNgT8h8Ws621u21MifG6B49TFFMhlBpT4kcYD40tdVnMDRetdyZO+e/wNF7gcTykMZ SlwkUbOHrZvf/5bjsbw2PAV+OHclu3ZVqcwtdy0wPVQCw9DY7v01quhVSAuHpYRHCPR+ YwSkF/wvRi8+UbvG1SEO7GTIcrse64ECEn7xJg7nPvxbtzp+ssaSwF2r0cXkI6+uTrC4 5Jv+8aLV+HIp8R4kwtaORy9EjBzJqqD0YryjmQyRulns1w7AUx4N0+OW8JVR61pAXfhm tTHg== X-Gm-Message-State: AC+VfDxD/QzrPvy8F5jjzdf1+qWTNhbTcYgGQ7kmP0D/IvmJczZxMag3 MLwLfE+/1oVjXOSKQE5vEZznH/w26fE= X-Google-Smtp-Source: ACHHUZ6MQlIY790bFakXPIY1+zDRu/UOVYFkss4KwDwJ93EXpywhfKozP0OWWxinQPg4v+c45aCEckKGtc8= X-Received: from colette.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:5cff]) (user=ctshao job=sendgmr) by 2002:a17:902:8c81:b0:1b0:46af:7edf with SMTP id t1-20020a1709028c8100b001b046af7edfmr626301plo.2.1686261971803; Thu, 08 Jun 2023 15:06:11 -0700 (PDT) Date: Thu, 8 Jun 2023 15:05:38 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230608220558.39094-1-ctshao@google.com> Subject: [PATCH v1 1/3] KVM: arm64: Consistently use free_removed_table() for stage-2 From: Chun-Tse Shao To: linux-kernel@vger.kernel.org, yuzhao@google.com, oliver.upton@linux.dev Cc: Chun-Tse Shao , Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Ben Gardon , Gavin Shan , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_150614_465601_9C3243DB X-CRM114-Status: GOOD ( 13.07 ) 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 From: Oliver Upton free_removed_table() is essential to the RCU-protected parallel walking scheme, as behind the scenes the cleanup is deferred until an RCU grace period. Nonetheless, the stage-2 unmap path calls put_page() directly, which leads to table memory being freed inline with the table walk. This is safe for the time being, as the stage-2 unmap walker is called while holding the write lock. A future change to KVM will further relax the locking mechanics around the stage-2 page tables to allow lock-free walkers protected only by RCU. As such, switch to the RCU-safe mechanism for freeing table memory. Signed-off-by: Oliver Upton Signed-off-by: Chun-Tse Shao Acked-by: Yu Zhao --- arch/arm64/kvm/hyp/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 5282cb9ca4cf..cc1af0286755 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1042,7 +1042,7 @@ static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx, kvm_granule_size(ctx->level)); if (childp) - mm_ops->put_page(childp); + mm_ops->free_removed_table(childp, ctx->level); return 0; } From patchwork Thu Jun 8 22:05:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Tse Shao X-Patchwork-Id: 13272951 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 EFB67C7EE25 for ; Thu, 8 Jun 2023 22:06:51 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ZuS7zuXAHDYgdKg7H/4Zq15GSOfyex5coAMJUdk1dUg=; b=V2TXPsr9Oq8z/0ob/oIEgsqfj8 7PROdEcs1yyucBENif3UUCqgDEmG0hxnrBXcI4AYi3Pq2OC1mjAudD3P+JZIF2C36/OcBfmyXNq33 xOQOI6BmKgnk2q2Hh39rF1+xYuCDr9ivJksn5fmj+TjmVznwODmzyHj2jvcn4i/sDxoWcrGvihXJg qjPWs9KNmNvbf0qWMMK6GmPjZyYuveDRg4JodJ8Nt7ytIsBXP6Or3mq6eM/o4xHQk956JOrsMgOBx GIiLMLmJW5M7OJlJTO3QaVGcvdQQ0JbeTNA/KvoUfFbyouyivp2EbKlezs9VMlsuNkFJXfzmXs0ga fY74FpGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Nm1-00Aktk-0w; Thu, 08 Jun 2023 22:06:29 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7Nlz-00AksJ-0X for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2023 22:06:28 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba87bd29e9dso1572060276.3 for ; Thu, 08 Jun 2023 15:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686261982; x=1688853982; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tdKizssFsMQJzj8/wSt0vRuPFuTT8IrX+6c5/ZqQtUU=; b=pYi5twzK16pe/u6UpDUsq5/gZ7VstFYaQpSoVInd6hIj+oSGhYPXPylVFxcNSuyTfw wCt/PuskPgVKlLP4RTlX1/zs0+7HkXHCX4XS7if1kU6ECFkPaPA6XhFNVqu9JjsX2WO/ 6WqFpH3dBOcrzKhywdtBIapeXoWXFx6aay6wJ/Qn7Ov7MwhcjCvIcth7YseBLy8rA6Ov 3DWI59xmNFppvf7woPF6SLT4FB7lfdwPzuUsRo9pwvg0hPnS8pOlnHx7+zVUdbb0FVld p5m22USbLg8gn8rqzTBnF1FE/reHbyRKFfM6g+eovhC7zK7inCcLfL8yF7dcAeB22C5F IZfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686261982; x=1688853982; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tdKizssFsMQJzj8/wSt0vRuPFuTT8IrX+6c5/ZqQtUU=; b=ZIdkcCMGezj1umJ1PQCp4YwBwBgPmpvqX7RAZywVjbRDCP+7qD+vVKxEcs4htLQehw 0HjLrfxDKJDR5gejdE6ik+Oh+X3qMU73Lu51mjGYW9lMbAG9M8DWkgRD3qkqMjxzKh+s fQRy4jf5XxkGDHMBPqEVIklERYfEaAsodLKapNW+9pTB7THq8P6XFRILIJkIw1wvBtR2 rScoAEFVs0kaDryRxDF0ddNpR9h4zpNl+91mzK7N7+BWcK6yxckhFkstnxUDZYnD5NZw lPJAETalwyncIvjoaTac7jZzNC89LHsDUIBWULnPWK22RjQzptu3Tp+mQPzTeZX61FWz usSA== X-Gm-Message-State: AC+VfDyjuqfYuDfM809KEi922Rj1dGEyBPMFcm+beFm+HQOkFLKwpWfD JJ+UKMkZGnb2URLT161eKWejfcxCF4k= X-Google-Smtp-Source: ACHHUZ4KfiB8l1+dUoVGrkHr93Y38MLg1AxejqBfztTpsuysMtbSy6a+JxAixUHY2sVHAQ46IvK3wvSRaY8= X-Received: from colette.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:5cff]) (user=ctshao job=sendgmr) by 2002:a05:6902:691:b0:ba8:1f20:ff4f with SMTP id i17-20020a056902069100b00ba81f20ff4fmr517992ybt.12.1686261982675; Thu, 08 Jun 2023 15:06:22 -0700 (PDT) Date: Thu, 8 Jun 2023 15:05:39 -0700 In-Reply-To: <20230608220558.39094-1-ctshao@google.com> Mime-Version: 1.0 References: <20230608220558.39094-1-ctshao@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230608220558.39094-2-ctshao@google.com> Subject: [PATCH v1 2/3] KVM: arm64: Only initiate walk if page_count() > 1 in free_removed_table() From: Chun-Tse Shao To: linux-kernel@vger.kernel.org, yuzhao@google.com, oliver.upton@linux.dev Cc: Chun-Tse Shao , Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Ben Gardon , Gavin Shan , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_150627_207789_E516E10B X-CRM114-Status: GOOD ( 11.85 ) 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 Page table walk is unnecessary in free_removed_table() being called from the stage-2 unmap path while PTEs on the table is empty. It can be fast-pathed by only initiating a walk if page_count() > 1 Original disussion can be found in: https://lore.kernel.org/kvmarm/ZHfWzX04GlcNngdU@linux.dev/ Suggested-by: Yu Zhao Suggested-by: Oliver Upton Signed-off-by: Chun-Tse Shao --- arch/arm64/kvm/hyp/pgtable.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index cc1af0286755..d8e570263388 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1319,5 +1319,6 @@ void kvm_pgtable_stage2_free_removed(struct kvm_pgtable_mm_ops *mm_ops, void *pg .end = kvm_granule_size(level), }; - WARN_ON(__kvm_pgtable_walk(&data, mm_ops, ptep, level + 1)); + if (mm_ops->page_count(pgtable) > 1) + WARN_ON(__kvm_pgtable_walk(&data, mm_ops, ptep, level + 1)); } From patchwork Thu Jun 8 22:05:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Tse Shao X-Patchwork-Id: 13272952 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 5A3D4C7EE29 for ; Thu, 8 Jun 2023 22:07:05 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=8QkU3P3KIZnF84bVZfN4bBteYxtAs8tm9DS5X9fciuk=; b=XmTexv71tFQlTimoJ4OOcRfx7x /zgoyk7WsJt2BB9KqXg5rlfUwyOkJRCIS7zmWHRp4i36aOhoprefx6ixVPH9unmBDH3a24UgenKNm cCRA0B6HPwl1y4k6A143YXorwQkcPlpHaiQsmWT/FvSiMyarQYcl4cXELmefKOfsxE83p5DXdVLMy ZdbHHUoJP/LkJSoRXRimILD1wOBrkeaRIKXyhD/s5IbTjNSr6nVRgAkGpdItyIVH4mePLjEfcZmbw RqsEF2drUCyrihif+S3NkKQPLJJVFDFrePUfCIoJgX6ZcWZs5GkTHe0Xw3irYbZH+03yUFK3jBwD2 FQprg88w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7NmF-00AkyM-2u; Thu, 08 Jun 2023 22:06:43 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7NmC-00Akwe-1P for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2023 22:06:41 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2566b668cc5so90243a91.0 for ; Thu, 08 Jun 2023 15:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686261998; x=1688853998; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RLQAgYf8iBGNcj/RlWRJvdUP+LxzH+dVMP3y494+MG8=; b=72g9XyvqNGl3FxCZJSPlIuUxU5j0nK1HOJfxv5zdttIag4OsGbA87NgmE6evU200aS 4DeqlItOIFsRMQ0edVVbXcJf6DzFv2YfutUisx2LuTPTVA7nkNWNd5uyttawNDTMrcGh wy65xqip1IhcVJ1CnkO3owJTaAfIhnrbD/WmfkrkSvNHld5eVlw3JgQjF0dtForqQaft bf5ROB4NASeWT8BrFaGbfxa5tS47+fie27CsKyFSPuMmPmwHfqEU/oAUA0hQT83Mec+T ojDgJK5GXHFV3Wjt7xLmT9aSemT69PEeoJdWthHnRlCut4YNMpKcxaM3Zu2FsJzZT0ix A6Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686261998; x=1688853998; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RLQAgYf8iBGNcj/RlWRJvdUP+LxzH+dVMP3y494+MG8=; b=PId7TSY0Nbo6uu61Ln1XpxsN712dfx5rf0rWM8kXbSABoj0TyLNLZy3zdOZC4wpE4Q yDPL1IIQCvVJcbqApLXWBzZjhKwePANqm7I4EC+Ezfw7nyQxn2PO5whSd5SoQMPBSVeX JPufcPNHQJYQN2/TQmiI6sf1hsymZohf0nSKXRpp8y+EIgav3pIyLlEGBA0jIOkI8yaR aBjY5ajKgZkxzKikD6jIc+Bvg282ZXEMDxpnfWzdVJSpVCeuYnUJYbTu1DwuT0cTLV1o N+6++rpHyl6KQjRcMnezbiPws1FAih4OnIc6gO3kOyVGIpSj02zaHkZ4M5DzURA+EeSQ 6KeA== X-Gm-Message-State: AC+VfDyhcLrLxjAMXKsKcUiw0hBVlC3HkXa4TaoToqqYQhNdewgTYWdi V0VHOvnlqqHe3WgWeZrhXKUhJKxygjU= X-Google-Smtp-Source: ACHHUZ4BB7wc/3PLgyJlfh6FiXwuAOEqUsspFVK4qOkYedUMSsY2SeUi7aLElhIVZxfm8OeC1VsqR/loduM= X-Received: from colette.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:5cff]) (user=ctshao job=sendgmr) by 2002:a17:90a:7886:b0:253:4800:438b with SMTP id x6-20020a17090a788600b002534800438bmr786194pjk.2.1686261997920; Thu, 08 Jun 2023 15:06:37 -0700 (PDT) Date: Thu, 8 Jun 2023 15:05:41 -0700 In-Reply-To: <20230608220558.39094-1-ctshao@google.com> Mime-Version: 1.0 References: <20230608220558.39094-1-ctshao@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230608220558.39094-4-ctshao@google.com> Subject: [PATCH v1 3/3] KVM: arm64: Using rcu_read_lock() for kvm_pgtable_stage2_mkyoung() From: Chun-Tse Shao To: linux-kernel@vger.kernel.org, yuzhao@google.com, oliver.upton@linux.dev Cc: Chun-Tse Shao , Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Ben Gardon , Gavin Shan , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_150640_495749_9485A891 X-CRM114-Status: GOOD ( 10.93 ) 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 Access bit is RCU safe and can be set without taking kvm->mmu_lock(). Replacing existing kvm->mmu_lock() with rcu_read_lock() for better performance. Original disussion can be found in: https://lore.kernel.org/kvmarm/CAOUHufZrfnfcbrqSzmHkejR5MA2gmGKZ3LMRhbLHV+1427z=Tw@mail.gmail.com/ Suggested-by: Yu Zhao Signed-off-by: Chun-Tse Shao --- arch/arm64/kvm/mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 3b9d4d24c361..0f7ea66fb894 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1437,10 +1437,10 @@ static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) trace_kvm_access_fault(fault_ipa); - read_lock(&vcpu->kvm->mmu_lock); + rcu_read_lock(); mmu = vcpu->arch.hw_mmu; pte = kvm_pgtable_stage2_mkyoung(mmu->pgt, fault_ipa); - read_unlock(&vcpu->kvm->mmu_lock); + rcu_read_unlock(); if (kvm_pte_valid(pte)) kvm_set_pfn_accessed(kvm_pte_to_pfn(pte));