Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp252022pxu; Tue, 5 Jan 2021 09:54:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPefgT21mFSTUtFwAsNCfiVaVHuMlbnLvKPjB+mKGTro2/h5LfbGwKuvl7gXlU/KHO/kA8 X-Received: by 2002:a50:fc96:: with SMTP id f22mr985247edq.162.1609869269745; Tue, 05 Jan 2021 09:54:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609869269; cv=none; d=google.com; s=arc-20160816; b=ni/McoDG8VxywRe4+JMqKdJdv6G3BW8KqL3BP4pyrs0rWOzQgQILhWjBbXjfl1wiXR dh+sAZt7wvW6f3DzKU02HS5kh4/a9sv2OGCrekbRLpE8jrDtYShJDJgBz1Rbq1f9HRvc O5NlnT/dQG85/QZwtaDgxZoOAlDsMypwPRX6Xea6CN9v9Di8v0wl0cXRumDgmjPCl6nA 0uOZfsp0FuQtAAyIL+6GxMuSyy9SuV/lfAycuak8G3PGSwN2gOxnu96kXoWIXciJmXKc v1SSDeMvdRfD3PLwVeVfxWe/6DRtNkHiiMZT+ucyS5ihlsQhVu2D0hMdcSw9RYyk7S2Z 4zmQ== 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 :message-id:date:subject:cc:to:from; bh=JIQuW/4RpxsmZTrmBPjCy0e3BYyOVCHG2XSMv9AGbhM=; b=EII5NXeR8s6/3Jkj4uFNW1cnqV+spyCNvYqvwRbP7KOUTXcgDKNshFwMWxUAwJu+3v h2yBfp77YejJgyJHRWGbMGSYGWXo84S5M6QXbg/mhUEjB1qLPTff7jXKoJLACYkLtoJF 8LsE2cEJA4mT3MPR/rGfi61OD7Hv4xcvXLMrZe1wt1iEpKIg13N7au6gHNXX96AUyRtP SV0ewvE28Qbh06EOJ4UUZVL9NKipHSjLhUk6KW60OpcyAUGyotFtNC2nPFcy8RVesiGt +K6VKHIRO+y1M6cQiM3NCOqUBQB6uywHO9xaTc2Z4bQBRscxHdYzUwJzxeupNlTlX41D NpLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u26si158113edo.164.2021.01.05.09.54.05; Tue, 05 Jan 2021 09:54:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729919AbhAERv3 (ORCPT + 99 others); Tue, 5 Jan 2021 12:51:29 -0500 Received: from mail-wr1-f43.google.com ([209.85.221.43]:44195 "EHLO mail-wr1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725838AbhAERv3 (ORCPT ); Tue, 5 Jan 2021 12:51:29 -0500 Received: by mail-wr1-f43.google.com with SMTP id w5so20440wrm.11; Tue, 05 Jan 2021 09:51:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JIQuW/4RpxsmZTrmBPjCy0e3BYyOVCHG2XSMv9AGbhM=; b=NxIo9zIxrafnEJ1eOpBYYdpu5RdiQffsDQuPEK1GwJ6zZH+4lnVjts415nXLuoWC8l bJnWLaVzVkNXygwA180gXTw+znEEwmC2oB4LR9Rqki9Bnu04AMSmuSOsPFMx0HwPa1sl CjuNHmg1r+keoZ8CIcFPXeXkfTanGo0xovhY0aLoM/6E5OccEODnSpJCwiok17kk1mk2 5ZDax1rg1b1RRJ/XrZrbgTE9K68CNMQSfwv8iryMx1RcXyJh4yyR+bkzwXjvLC4MXdkw syCFya+CRbMZ/LUg+yj2ImzJJt/7GViDcjKrbdUqoAtCJWUFO/Df9P//SgWtD3BJRw6k +I1Q== X-Gm-Message-State: AOAM5334TmzYu4q6b1Q0Km7YFBjkoQx2br6pPfbDjbhgU62OUrFWBLuK uBa6ZDDgy2Z0X8t/SvHrcKFaHGoR4BI= X-Received: by 2002:adf:8290:: with SMTP id 16mr670660wrc.27.1609869047148; Tue, 05 Jan 2021 09:50:47 -0800 (PST) Received: from liuwe-devbox-debian-v2.j3c5onc20sse1dnehy4noqpfcg.zx.internal.cloudapp.net ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id r20sm285596wmh.15.2021.01.05.09.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 09:50:46 -0800 (PST) From: Wei Liu To: Linux on Hyper-V List Cc: Michael Kelley , Wei Liu , stable@kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH] x86/hyperv: check cpu mask after interrupt has been disabled Date: Tue, 5 Jan 2021 17:50:43 +0000 Message-Id: <20210105175043.28325-1-wei.liu@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We've observed crashes due to an empty cpu mask in hyperv_flush_tlb_others. Obviously the cpu mask in question is changed between the cpumask_empty call at the beginning of the function and when it is actually used later. One theory is that an interrupt comes in between and a code path ends up changing the mask. Move the check after interrupt has been disabled to see if it fixes the issue. Signed-off-by: Wei Liu Cc: stable@kernel.org --- arch/x86/hyperv/mmu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c index 5208ba49c89a..2c87350c1fb0 100644 --- a/arch/x86/hyperv/mmu.c +++ b/arch/x86/hyperv/mmu.c @@ -66,11 +66,17 @@ static void hyperv_flush_tlb_others(const struct cpumask *cpus, if (!hv_hypercall_pg) goto do_native; - if (cpumask_empty(cpus)) - return; - local_irq_save(flags); + /* + * Only check the mask _after_ interrupt has been disabled to avoid the + * mask changing under our feet. + */ + if (cpumask_empty(cpus)) { + local_irq_restore(flags); + return; + } + flush_pcpu = (struct hv_tlb_flush **) this_cpu_ptr(hyperv_pcpu_input_arg); -- 2.20.1