From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9610421F11 for ; Fri, 8 May 2026 20:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778273711; cv=none; b=BxX4TNqZJrrj5ySRVIPOgVLJ2UmUYtkfHrpoKtsSXI213Yc68/3pi5x6vxnuvImBlIwIzFz4NXy0Q8FyAtkDd1Pc9VQ1QVw8xYgqKcyljsJfiErEbZ6em3UOvtR6AKVfCbD9D+JEKVWrDOoD2VQJJ29JFhGa5aSJYm9LlwuBWtc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778273711; c=relaxed/simple; bh=EYkONMkW0IatpZ5QawspWJ7T/VJZH158OZO7NH03taE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qZNsi8B8q+Q4c4GghO/T9th3mA+abpAJUulhF2rEbz3TEPkrNleczgcMQLaYZMs3RSbEmtOiQz2sKwXbTSt4TNOm6HZgBqvNaV3nyI6Wvw+HwK6dZwKKa6MGcO9Yf4EIkBKGblt4El25fO1WAH3lEi0A4kU19GTnD8RIGNUQaXM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=oT/QNC9y; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="oT/QNC9y" 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 4A79F1C25; Fri, 8 May 2026 13:55:02 -0700 (PDT) Received: from [10.57.35.132] (unknown [10.57.35.132]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B76E33F836; Fri, 8 May 2026 13:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778273707; bh=EYkONMkW0IatpZ5QawspWJ7T/VJZH158OZO7NH03taE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=oT/QNC9yXHo4z1ugT7/FLiBNGDpaiDMdHzLuLsLDP/RfnuNDn7+RkOx6fUHYck5WY 4JiTtgOh/rHTuurIlP+VjgGp6OdeXiP8hc2bG238RdglsrJ4AC+VD81LgCQr74gaL9 avbGNpzxwH5AeadHWfiYrYy0idGktRIUI2usTaMk= Message-ID: <362bc938-18ea-4f6a-938a-893dfb1c956d@arm.com> Date: Fri, 8 May 2026 22:54:59 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/xen: Tolerate nested XEN_LAZY_MMU entering/leaving To: Juergen Gross , linux-kernel@vger.kernel.org, x86@kernel.org Cc: marmarek@invisiblethingslab.com, Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , xen-devel@lists.xenproject.org References: <20260508143933.493013-1-jgross@suse.com> From: Kevin Brodsky Content-Language: en-GB In-Reply-To: <20260508143933.493013-1-jgross@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 08/05/2026 16:39, Juergen Gross wrote: > With the support of nested lazy mmu sections it can happen that > arch_enter_lazy_mmu_mode() is being called twice without a call of > arch_leave_lazy_mmu_mode() in between, as the lazy_mmu_*() helpers > are not disabling preemption when checking for nested lazy mmu > sections. I think this is a correct description of the issue, i.e. potentially we have arch_enter_lazy_mmu_mode() called twice *sequentially*. Therefore I don't think that disabling preemption inside arch_enter_lazy_mmu_mode() is enough - we have a problem with preemption occurring inside lazy_mmu_mode_enable() generally, not necessarily inside arch_enter_lazy_mmu_mode(). Preemption shouldn't matter if commit 291b3abed657 is reverted. AFAICT this is the only easy fix. - Kevin > This is a problem when running as a Xen PV guest, as > xen_enter_lazy_mmu() and xen_leave_lazy_mmu() don't tolerate this > case. > > Fix that in xen_enter_lazy_mmu() and xen_leave_lazy_mmu() in order > not to hurt all other lazy mmu mode users. > > Fixes: 291b3abed657 ("x86/xen: use lazy_mmu_state when context-switching") > Signed-off-by: Juergen Gross > --- > arch/x86/xen/mmu_pv.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c > index c80d0058efd1..3eee5f84f8a7 100644 > --- a/arch/x86/xen/mmu_pv.c > +++ b/arch/x86/xen/mmu_pv.c > @@ -2145,7 +2145,10 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot) > > static void xen_enter_lazy_mmu(void) > { > - enter_lazy(XEN_LAZY_MMU); > + preempt_disable(); > + if (xen_get_lazy_mode() != XEN_LAZY_MMU) > + enter_lazy(XEN_LAZY_MMU); > + preempt_enable(); > } > > static void xen_flush_lazy_mmu(void) > @@ -2182,7 +2185,8 @@ static void xen_leave_lazy_mmu(void) > { > preempt_disable(); > xen_mc_flush(); > - leave_lazy(XEN_LAZY_MMU); > + if (xen_get_lazy_mode() != XEN_LAZY_NONE) > + leave_lazy(XEN_LAZY_MMU); > preempt_enable(); > } >