From nobody Mon Sep 16 18:49:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1694605144; cv=none; d=zohomail.com; s=zohoarc; b=dBZI1s/DHRO+jsDIHYE/59qi+bdCbNdn/27LldlP3+HcaWR4hQ6DnAdHzSQAOzmMqNjMavP/30bIpFlYb3C2ApSno78aCKYPygZTCeWaEurvTGtAYFlIdyaFIHRDwB40Xk/nCG6hSa42sRkOJ566k/gOuvzA2fBQAeQ+AuHFV3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694605144; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=++Gf4nZevYukLnMCd8J7gk+s802IZpzJx/5E73wtImY=; b=HKBdVkrgbZsbtO7ppv6NtZWCCobT05dkL0eD92JNAaCqTw4V4MZdDmAnBdAaq6oet5ULwRH5wA5RS05++uV9zNwcIywoWB+NW3ormu67krfNU4IGNdkgiUvIsd21hJRItYkUuyIV4nldtnnFfZnljZ/BaU0/zKxC5HFO9P4dNsE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1694605144636357.8368863724937; Wed, 13 Sep 2023 04:39:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.601229.937214 (Exim 4.92) (envelope-from ) id 1qgOCp-0003rq-S7; Wed, 13 Sep 2023 11:38:51 +0000 Received: by outflank-mailman (output) from mailman id 601229.937214; Wed, 13 Sep 2023 11:38:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qgOCp-0003rO-P7; Wed, 13 Sep 2023 11:38:51 +0000 Received: by outflank-mailman (input) for mailman id 601229; Wed, 13 Sep 2023 11:38:50 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qgOCo-0003ob-H6 for xen-devel@lists.xenproject.org; Wed, 13 Sep 2023 11:38:50 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1a5c0bf3-522a-11ee-9b0d-b553b5be7939; Wed, 13 Sep 2023 13:38:48 +0200 (CEST) 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 DE4EF1F461; Wed, 13 Sep 2023 11:38:47 +0000 (UTC) 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 9401D13582; Wed, 13 Sep 2023 11:38:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id NCztIkefAWWVCwAAMHmgww (envelope-from ); Wed, 13 Sep 2023 11:38:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1a5c0bf3-522a-11ee-9b0d-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1694605127; 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: in-reply-to:in-reply-to:references:references; bh=++Gf4nZevYukLnMCd8J7gk+s802IZpzJx/5E73wtImY=; b=SHILpcKUB+qttiLi6k4sYhNzmXEFE767/y3kD9zbG2bluvZ7ghrloO9UGyNAhPubecIaKP NGNWWh5CDcoRq9haIK8xFSRVnZ0ag62gtllZXtXM6vGJ8WcYBytmyjAszMfOa3Kyr1S2Ur 7HXYBqGaBGWrqpTPsAL3X8ci5xu+xRw= From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , xen-devel@lists.xenproject.org Subject: [PATCH 3/3] x86/xen: allow nesting of same lazy mode Date: Wed, 13 Sep 2023 13:38:28 +0200 Message-Id: <20230913113828.18421-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230913113828.18421-1-jgross@suse.com> References: <20230913113828.18421-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1694605145283100003 Content-Type: text/plain; charset="utf-8" When running as a paravirtualized guest under Xen, Linux is using "lazy mode" for issuing hypercalls which don't need to take immediate effect in order to improve performance (examples are e.g. multiple PTE changes). There are two different lazy modes defined: MMU and CPU lazy mode. Today it is not possible to nest multiple lazy mode sections, even if they are of the same kind. A recent change in memory management added nesting of MMU lazy mode sections, resulting in a regression when running as Xen PV guest. Technically there is no reason why nesting of multiple sections of the same kind of lazy mode shouldn't be allowed. So add support for that for fixing the regression. Fixes: bcc6cc832573 ("mm: add default definition of set_ptes()") Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky --- arch/x86/include/asm/xen/hypervisor.h | 15 +++++++++++++-- arch/x86/xen/enlighten_pv.c | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/xen/hypervisor.h b/arch/x86/include/asm/x= en/hypervisor.h index ed05ce3df5c7..7048dfacc04b 100644 --- a/arch/x86/include/asm/xen/hypervisor.h +++ b/arch/x86/include/asm/xen/hypervisor.h @@ -72,10 +72,18 @@ enum xen_lazy_mode { }; =20 DECLARE_PER_CPU(enum xen_lazy_mode, xen_lazy_mode); +DECLARE_PER_CPU(unsigned int, xen_lazy_nesting); =20 static inline void enter_lazy(enum xen_lazy_mode mode) { - BUG_ON(this_cpu_read(xen_lazy_mode) !=3D XEN_LAZY_NONE); + enum xen_lazy_mode old_mode =3D this_cpu_read(xen_lazy_mode); + + if (mode =3D=3D old_mode) { + this_cpu_inc(xen_lazy_nesting); + return; + } + + BUG_ON(old_mode !=3D XEN_LAZY_NONE); =20 this_cpu_write(xen_lazy_mode, mode); } @@ -84,7 +92,10 @@ static inline void leave_lazy(enum xen_lazy_mode mode) { BUG_ON(this_cpu_read(xen_lazy_mode) !=3D mode); =20 - this_cpu_write(xen_lazy_mode, XEN_LAZY_NONE); + if (this_cpu_read(xen_lazy_nesting) =3D=3D 0) + this_cpu_write(xen_lazy_mode, XEN_LAZY_NONE); + else + this_cpu_dec(xen_lazy_nesting); } =20 enum xen_lazy_mode xen_get_lazy_mode(void); diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 54b83825c4b6..bbbfdd495ebd 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -102,6 +102,7 @@ struct tls_descs { }; =20 DEFINE_PER_CPU(enum xen_lazy_mode, xen_lazy_mode) =3D XEN_LAZY_NONE; +DEFINE_PER_CPU(unsigned int, xen_lazy_nesting); =20 enum xen_lazy_mode xen_get_lazy_mode(void) { --=20 2.35.3