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 AA04BC3DA7A for ; Fri, 6 Jan 2023 16:47:31 +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=+beoI3PxBLleROO+6iHnB6gsFnbkEE/7eNPHGU/Q2LE=; b=iC7RQPeUSShMcF byZ02RDUpz5wy5UrUawxM7r+UORd4PWOpB+V74i2qQgmTMTnbQt0x6sCrAIdU2z+rnMbxpMpJPFnb 7dKykt7MnoAdYL3KH+JJ4MZEsrV5muILxLjvAMb8g75YE9EQYkRmX0K6h50j8BqW2a881wuLkk476 tc+2eDDIdET2a3SUCUgLh7n5stNJpJF5dUECfahM6aeWgiNIeY+tLoUQmYWtwf8VsbKsphOLD+4xc uBjlDs4sbYna05Z6NIFPH9G2ArJLUPGlqaleLORUmPS7fwY1H/wJuORX0Ns1+DHV4fShn6i8qb7d7 zYPPb3RcSIsyBaVmZxEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDprB-00APeX-Mm; Fri, 06 Jan 2023 16:46:14 +0000 Received: from smtp-out2.suse.de ([195.135.220.29]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDpjx-00AIYW-6y for linux-arm-kernel@lists.infradead.org; Fri, 06 Jan 2023 16:38:47 +0000 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C7B3226E48; Fri, 6 Jan 2023 16:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1673023117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Jc09aqlLfTrWqFF/hWlS9hS5VsdNuWjb8hwJ4tyxrI0=; b=s5mshQc8MAF4t3cr0rShYqb6o9GVi55Q+abtWnL7mJ1jNJ9UCf+TOVemqu6hXAh5vBSLeE lC4lQuxr/qpasgkUtxFejivAqUJYUs6MMSOTjoKTk4FKaHnVX/t3IkP9qmGhzyUGLrxcKZ YFWUhA46KkdVinlfTSRUTUyfoSKGWeE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1673023117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Jc09aqlLfTrWqFF/hWlS9hS5VsdNuWjb8hwJ4tyxrI0=; b=v7HySvwsNNOSDEvMZd333jFXKSwEzV7QGSZea6jlb4E1aA3ZX500xp8irTyk2GSu8p9fNc FqLwGjfDajT9hDBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2DB39139D5; Fri, 6 Jan 2023 16:38:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wOTlMoxOuGP2OAAAMHmgww (envelope-from ); Fri, 06 Jan 2023 16:38:36 +0000 From: Gabriel Krisman Bertazi To: catalin.marinas@arm.com, will@kernel.org Cc: linux-arm-kernel@lists.infradead.org, broonie@kernel.org, Gabriel Krisman Bertazi Subject: [RFC PATCH] arm64: Cache HW update of Access Flag support Date: Fri, 6 Jan 2023 13:38:25 -0300 Message-Id: <20230106163825.4812-1-krisman@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_083845_468938_EA38792C X-CRM114-Status: GOOD ( 20.64 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Accessing AA64MMFR1_EL1 is expensive in KVM guests, since it is emulated in the hypervisor. In fact, ARM documentation mentions some feature registers are not supposed to be accessed frequently by the OS, and therefore should be emulated for guests [1]. Commit 0388f9c74330 ("arm64: mm: Implement arch_wants_old_prefaulted_pte()") introduced a read of this register in the page fault path. But, even when the feature of setting faultaround pages with the old flag is disabled for a given cpu, we are still paying the cost of checking the register on every pagefault. This results in an explosion of vmexit events in KVM guests, which directly impacts the performance of virtualized workloads. For instance, running kernbench yields a 15% increase in system time solely due to the increased vmexit cycles. This patch avoids the extra cost by caching the register value after the first read. It should be safe to do so, since this register mustn't change for a specific processor. As a side note, we can't rely on the usual cpucap for this bit, because for some reason that I'm missing, it is always enabled for aarch64, even if the functionality is not supported by the processor. [1] https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/Armv8-A%20virtualization.pdf?revision=a765a7df-1a00-434d-b241-357bfda2dd31 Signed-off-by: Gabriel Krisman Bertazi --- arch/arm64/include/asm/cpufeature.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 03d1c9d7af82..599c7a22155b 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -859,14 +859,24 @@ static inline u32 id_aa64mmfr0_parange_to_phys_shift(int parange) /* Check whether hardware update of the Access flag is supported */ static inline bool cpu_has_hw_af(void) { - u64 mmfr1; + static unsigned int has_af = -1U; if (!IS_ENABLED(CONFIG_ARM64_HW_AFDBM)) return false; - mmfr1 = read_cpuid(ID_AA64MMFR1_EL1); - return cpuid_feature_extract_unsigned_field(mmfr1, + /* + * Cache the register to avoid repeatedly reading it, + * which is an emulated operation on KVM guests. + * + * Also do not rely on cpucap, since this bit is always set + * there, regardless of actual status. See has_hw_dbm() for + * details. + */ + if (unlikely(has_af == -1U)) + has_af = cpuid_feature_extract_unsigned_field( + read_cpuid(ID_AA64MMFR1_EL1), ID_AA64MMFR1_EL1_HAFDBS_SHIFT); + return has_af; } static inline bool cpu_has_pan(void) -- 2.35.3 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel