Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp351401pxb; Wed, 14 Apr 2021 17:32:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYR/SYj+xlpEZXHMaWOvqQPH3jWStW3bcVYgWCY1ACvVgxqkQL3MQYwhccreZbYu9j/Wdq X-Received: by 2002:a65:4382:: with SMTP id m2mr935646pgp.354.1618446741534; Wed, 14 Apr 2021 17:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618446741; cv=none; d=google.com; s=arc-20160816; b=QAvIKUzZLnPJVymrIOSKtjy03BC6NIFFsywyBjNrCIVEIYwOxyiPWl/P93tDX6ybXA gsg1Dyh3BhP9tyX0V7XyUJlWm5ksH7Sd1j13iUhEsY+m3sWTBvmhXbuTwQNHerO0Av7U U6GIu/bwfD4w4XFSroUorFAgQgOR6b6DjVHmxkTMLdOriZ/cyezU15I8GH1IfTYohK3x GeAR+UzG3rTDrG6u3BMc+xsVuAn/sJcOI7gaS7YtD9u6k/0jkKvS0HfiOTfSJzG+bysz iBdJftHnZqM1JXuQ4Xy1LL7hBZpjwcvDq/EWD0deQIXlxCWs/5x3Drc0VR+u7rLOf4Ar RbqA== 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=tT7uwoYzV1OZBhSy625V8SIzoldYD1Jtal4XKpjIk6E=; b=pBgaIAADxdz2fWh29V3Mf1wWH71IYlRGJ046Q6NbkAVie+QwG/8ppRAvdf49LPizIV qhA2X52gecsZWsdCCzUAh71uve/uPREFeMwkHDHjV3krM5XeCT9Q+g7kvE59Ry4YIcW3 w1mHlJ3wqTBmliYAQvoQ5/f6Bjl/jmlVG9K6PxNg439f3KBQmaHht0kVt72bQy1Lal8s Boj1JqG7BjqJVceTdF+OJoOA2t83B1vTQbDq4L//4QEPUM/QD4J8VVX2i3srW4X1rkoD tKUT95yEolS0Ei046GmAraT7j3U8bK2z8+FXVLS5c0e19jnZjoTIxjm1Pd9qpbORZxWq SA1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gmFJ28R8; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si1356617plg.355.2021.04.14.17.32.09; Wed, 14 Apr 2021 17:32:21 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gmFJ28R8; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238241AbhDNPCM (ORCPT + 99 others); Wed, 14 Apr 2021 11:02:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232979AbhDNPB7 (ORCPT ); Wed, 14 Apr 2021 11:01:59 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE012C061756; Wed, 14 Apr 2021 08:01:36 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id m3so24103667edv.5; Wed, 14 Apr 2021 08:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tT7uwoYzV1OZBhSy625V8SIzoldYD1Jtal4XKpjIk6E=; b=gmFJ28R8jAqVvsrufxOILvnC1EhALwJelyqUFa2bAc6yNejyqklzCDN4MNbDh7azi4 sBwUgn6B+AF30eoC1zW4TYvYvOGV2BDLOW2G5Uoob9pf3ZCTw3S48qS1UjBJUQDzMFGl zJJC9JrDNICNRA0LWE4A1tj2hafsaxMS6uPBr9ah0kuYocLCt70qlhvWSOl9FW4cpgSB rXsK80Pb0Nddd0bbK91htO5PVtw/oRVEoVOz/tWtHbYI+0CUhqYbowA976+KF0UretoP dmd2IyxTiqT0J/b2Hzo8zfnusAgtd8Vcqs35Yu3x3f8A9Cz2fU5VwixFRVYV0PIDU8IX bPlQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=tT7uwoYzV1OZBhSy625V8SIzoldYD1Jtal4XKpjIk6E=; b=q6cS3HVP3htCzmhlsKlJ+w3xOswByofhRNOOq772udZEtHxD2DwdxZm7M6rOYlM+iV C4GYOfX4a1yz4B7wg102Y36mVLVA3vBG2gLVRQXAzD4Z7UT6hGot3AiT23mxSX1rjVrI sRbAk6SWXcVkZM3Ir52UTrymTCx0BtyQQbIvQNBjhoTzQiNrZen6W8uS//z2aci8rz/S U/Af9f+NkutARichkTwvdbWD9EqSBJN/kHqewKipio5pqrDjWEsbOdFnIM5T+TKwoEIE 7WNLEXTzkmALdSsUe/cvZFybETaR/1AoLyIBgXBKFnrG7lgkj3xMUYW6t+ndmjpd44/p 4mWg== X-Gm-Message-State: AOAM533L2lwQbcwYoRwOWkYk5h9hvRiVPL4ssqfjGjRM25v86piodvec aIkzwyCbaC+FDfiRgG4mvvb3yZYbHeUKpg== X-Received: by 2002:a05:6402:51cd:: with SMTP id r13mr41713124edd.116.1618412495387; Wed, 14 Apr 2021 08:01:35 -0700 (PDT) Received: from anparri.mshome.net (host-95-232-15-7.retail.telecomitalia.it. [95.232.15.7]) by smtp.gmail.com with ESMTPSA id c12sm12683393edx.54.2021.04.14.08.01.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Apr 2021 08:01:35 -0700 (PDT) From: "Andrea Parri (Microsoft)" To: linux-kernel@vger.kernel.org Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, linux-hyperv@vger.kernel.org, mikelley@microsoft.com, "Andrea Parri (Microsoft)" Subject: [PATCH v2 3/3] Drivers: hv: vmbus: Check for pending channel interrupts before taking a CPU offline Date: Wed, 14 Apr 2021 17:01:18 +0200 Message-Id: <20210414150118.2843-4-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210414150118.2843-1-parri.andrea@gmail.com> References: <20210414150118.2843-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Check that enough time has passed such that the modify channel message has been processed before taking a CPU offline. Signed-off-by: Andrea Parri (Microsoft) --- drivers/hv/hv.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 3e6ff83adff42..dc9aa1130b22f 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -292,6 +293,41 @@ void hv_synic_disable_regs(unsigned int cpu) disable_percpu_irq(vmbus_irq); } +#define HV_MAX_TRIES 3 +/* + * Scan the event flags page of 'this' CPU looking for any bit that is set. If we find one + * bit set, then wait for a few milliseconds. Repeat these steps for a maximum of 3 times. + * Return 'true', if there is still any set bit after this operation; 'false', otherwise. + * + * If a bit is set, that means there is a pending channel interrupt. The expectation is + * that the normal interrupt handling mechanism will find and process the channel interrupt + * "very soon", and in the process clear the bit. + */ +static bool hv_synic_event_pending(void) +{ + struct hv_per_cpu_context *hv_cpu = this_cpu_ptr(hv_context.cpu_context); + union hv_synic_event_flags *event = + (union hv_synic_event_flags *)hv_cpu->synic_event_page + VMBUS_MESSAGE_SINT; + unsigned long *recv_int_page = event->flags; /* assumes VMBus version >= VERSION_WIN8 */ + bool pending; + u32 relid; + int tries = 0; + +retry: + pending = false; + for_each_set_bit(relid, recv_int_page, HV_EVENT_FLAGS_COUNT) { + /* Special case - VMBus channel protocol messages */ + if (relid == 0) + continue; + pending = true; + break; + } + if (pending && tries++ < HV_MAX_TRIES) { + usleep_range(10000, 20000); + goto retry; + } + return pending; +} int hv_synic_cleanup(unsigned int cpu) { @@ -336,6 +372,19 @@ int hv_synic_cleanup(unsigned int cpu) if (channel_found && vmbus_connection.conn_state == CONNECTED) return -EBUSY; + if (vmbus_proto_version >= VERSION_WIN10_V4_1) { + /* + * channel_found == false means that any channels that were previously + * assigned to the CPU have been reassigned elsewhere with a call of + * vmbus_send_modifychannel(). Scan the event flags page looking for + * bits that are set and waiting with a timeout for vmbus_chan_sched() + * to process such bits. If bits are still set after this operation + * and VMBus is connected, fail the CPU offlining operation. + */ + if (hv_synic_event_pending() && vmbus_connection.conn_state == CONNECTED) + return -EBUSY; + } + hv_stimer_legacy_cleanup(cpu); hv_synic_disable_regs(cpu); -- 2.25.1