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 3005EC5479D for ; Thu, 12 Jan 2023 03:06:45 +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:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ob8o4wMWpTCF4OPJL736rFt3EDCJj0+zjtmghGqIC2g=; b=hC2jn7k7LVOfpp vIrAPnB7zRnq7WjnZ+kr+fka/ZUV3Bb6AT2C8EcXWADyZHOKWiqbCMzXRXamq63b0GVKgIn3oGaqn 1lf+7uTEKl9Fo+Kx8yQ1QfUsu9o5fPMS4ey8mk6PUuoJxxqul+CGOXvJgx7IQrE7dLDRaGicqWyqJ kqgHqrQcVl9o5AQNrPsge1R2a6foPTxd2DCdIEVbe5hyFmv8KM4ecV1COJKz/d/YOrwN0NkRRPw8l oyRT5GBnKzc3fthYk78Jl+3/Ng65csorHxRdtUMWjcSTv9hRK6ZEtrJEU2bZQXMjlNdTshXwALcL6 0hDmnbz8hpykEX0dXxnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFnuT-00DXam-S2; Thu, 12 Jan 2023 03:05:45 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFnuP-00DXZl-NN for linux-arm-kernel@lists.infradead.org; Thu, 12 Jan 2023 03:05:43 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 890D1FEC; Wed, 11 Jan 2023 19:06:21 -0800 (PST) Received: from [10.162.41.9] (unknown [10.162.41.9]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CA3563F67D; Wed, 11 Jan 2023 19:05:37 -0800 (PST) Message-ID: Date: Thu, 12 Jan 2023 08:35:34 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v2] arm64: Avoid repeated AA64MMFR1_EL1 register read on pagefault path Content-Language: en-US To: Gabriel Krisman Bertazi , catalin.marinas@arm.com, will@kernel.org Cc: linux-arm-kernel@lists.infradead.org, broonie@kernel.org References: <20230109151955.8292-1-krisman@suse.de> From: Anshuman Khandual In-Reply-To: <20230109151955.8292-1-krisman@suse.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230111_190541_882993_F0973BB3 X-CRM114-Status: GOOD ( 23.40 ) 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 On 1/9/23 20:49, Gabriel Krisman Bertazi wrote: > 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 using the sanitized cached value. > It should be safe to do so, since this register mustn't change for a > given cpu. > > [1] https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Learn%20the%20Architecture/Armv8-A%20virtualization.pdf?revision=a765a7df-1a00-434d-b241-357bfda2dd31 A small nit. This URL length causes a checkpatch.pl warning. WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per line) Just wondering, if this URL can be replaced with a document identification number or something similar for a more cleaner commit message, not sure if such a thing is even feasible. > > Signed-off-by: Gabriel Krisman Bertazi > > --- > Changes since v1: > - Rely on read_sanitised_ftr_reg instead of static var (will) > --- > arch/arm64/include/asm/cpufeature.h | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index 03d1c9d7af82..3d1a5677321e 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -864,7 +864,11 @@ static inline bool cpu_has_hw_af(void) > if (!IS_ENABLED(CONFIG_ARM64_HW_AFDBM)) > return false; > > - mmfr1 = read_cpuid(ID_AA64MMFR1_EL1); > + /* > + * Use cached version to avoid emulated msr operation on KVM > + * guests. > + */ > + mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1); > return cpuid_feature_extract_unsigned_field(mmfr1, > ID_AA64MMFR1_EL1_HAFDBS_SHIFT); > } FWIW Reviewed-by: Anshuman Khandual _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel