From patchwork Wed Sep 13 11:38:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 138808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp1109726vqx; Wed, 13 Sep 2023 07:06:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4G+6HdGTuM8BDZoQMX79mAieq8WsjOhQJcgYmM6T2SBbnGVGqQ9ltgmMMaTnJcCIvR3fW X-Received: by 2002:a05:6808:1494:b0:3a4:35bb:edae with SMTP id e20-20020a056808149400b003a435bbedaemr3043653oiw.29.1694613963687; Wed, 13 Sep 2023 07:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694613963; cv=none; d=google.com; s=arc-20160816; b=V4zVk6ido0wsh9OyC8lrTZ3wBFKNiqQQQsd8v3bPgmz4GF0s13erLE3ER5om2H/HL/ Rj2ZstefmeK2Sj2BAq+eMT0yj/p0TiClZaT4Bz2Wa0O8zexptU6F5aQYw5/Ri8awMfCY ZE+jQnV3wSDRv/BBdox/ShHgj0e0+4qNoKAGVLXyFP/7jMtM1rzbYpZYD3ZoNujY9kRQ ipq3OOuR4WM9BEPNkqwu4iuWqkzphf8/YDJ0j+GAeoprLqaCYsU0yJowlfRlGqO/KnY+ 8ko47F2PSICsmYTfEOTeMGXpevLu7RfmKhs/P7kKxJh5BI32hp7GPswpF2thZ2p2n9Ah EoWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=++Gf4nZevYukLnMCd8J7gk+s802IZpzJx/5E73wtImY=; fh=xP7rPEwwmYjRFdY4LvohNByAc3I2TDa74iPJEEVDE0E=; b=V5uV3O4+dsVLZcVDbDn4FtZfsTsJsnk/y3/cvYE1SE2WuwP/u9yE8J9Ma56PWwD+sn kH6jIAfiqajV+lc6NDI/iIrCe2+58Y6OmuhaQ3OEhfXiAFAXgWcWNxnR82j8XlPPoULo 5theMsi0jInDyWgXNgLC4LY/Zj0rjvKfEY+rBsj9jyB56owoxgijxkcHoFUgXp7NGn6s G0CUPpH0QcGySsC9gNQX5f5a5nVRaARldxF0kUKqq54WegcA7ZRoXR5ImcfFzILCXco4 n+/vJe7PPtppWDQ6K8rgm5WUUM19bxf82QNTLaYGUbWfVzfVuPIDm7LkdsNWfVVXkfvY hgeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=SHILpcKU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id v10-20020a63f20a000000b005774aba519asi7250324pgh.118.2023.09.13.07.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 07:06:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=SHILpcKU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 98EDD8256BFB; Wed, 13 Sep 2023 04:39:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240472AbjIMLi4 (ORCPT + 36 others); Wed, 13 Sep 2023 07:38:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240381AbjIMLix (ORCPT ); Wed, 13 Sep 2023 07:38:53 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 251FF19AD for ; Wed, 13 Sep 2023 04:38:49 -0700 (PDT) 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) 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= 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 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 13 Sep 2023 04:39:12 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776931531371886222 X-GMAIL-MSGID: 1776931531371886222 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/xen/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 { }; DECLARE_PER_CPU(enum xen_lazy_mode, xen_lazy_mode); +DECLARE_PER_CPU(unsigned int, xen_lazy_nesting); static inline void enter_lazy(enum xen_lazy_mode mode) { - BUG_ON(this_cpu_read(xen_lazy_mode) != XEN_LAZY_NONE); + enum xen_lazy_mode old_mode = this_cpu_read(xen_lazy_mode); + + if (mode == old_mode) { + this_cpu_inc(xen_lazy_nesting); + return; + } + + BUG_ON(old_mode != XEN_LAZY_NONE); 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) != mode); - this_cpu_write(xen_lazy_mode, XEN_LAZY_NONE); + if (this_cpu_read(xen_lazy_nesting) == 0) + this_cpu_write(xen_lazy_mode, XEN_LAZY_NONE); + else + this_cpu_dec(xen_lazy_nesting); } 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 { }; DEFINE_PER_CPU(enum xen_lazy_mode, xen_lazy_mode) = XEN_LAZY_NONE; +DEFINE_PER_CPU(unsigned int, xen_lazy_nesting); enum xen_lazy_mode xen_get_lazy_mode(void) {