Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1775194ybb; Thu, 26 Mar 2020 07:09:08 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsGFj+LbQA44p9h93v/6bGQPb5E0Q39XoaLSTIWs6hG8P4/SPdYyb8RPtmleU5o+OpCHgkG X-Received: by 2002:a4a:940e:: with SMTP id h14mr5307354ooi.26.1585231748765; Thu, 26 Mar 2020 07:09:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585231748; cv=none; d=google.com; s=arc-20160816; b=vg5C2CJ2iQwzfxWdMarL1kNClNdC6E931oRtUDQ3w1rFAWl99DGCaCbTGKMxXUgQiT /ik8PiHZDp0Y0MaZRDARBcDpYv6334+IUJkCH5AEWUdoB8QaBINfsCYd2CR1L6FRRdtF 9IYv5U6nsNoqe9PwGH/1gZoLLY4YEWuQOuz49G4RDQpk8Png4wC62LBEkTFt+5B5lgmu CZqLdR3Al/APcA35DtwQ/V1X7anQL4ygmJpiDCBPKCc1jpjPTx0BLSYK4RNDoX8WgG2N GPrItbiRJoGCz8S76x+E95lWgA923iXDTsUBPBNWzSodyI4cYIhjavq1+IuPLKjCKKnv BdVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=iu8pP+Jj7yxXz+kaoKj+StMGIPihDf+lmC4twg0Tx8I=; b=IoJ0hZSwDiwY8az5emWvnU7+TlzzCiMNBfo/LhfohnYho6owYaoGCk8FlxLj7nT4bN 1NQBlHhS9mEgqjnpQVnd5Pur2f062uodfubvHPG2w3Ygo7GhowS+Ihw3f+StE2T6AZDB 2Zw43U1x7FsU4Pr/ZxL5QjEKyW+ycRClnI790n3e25ulwzpTQ5kxGR4Fq+NxMpQFkVWV LDg+KcSOp1qqkupLcM+8NQBpzNI4r7Y8SjIwi19uInl7Ga9/DN3YdpwB+l3pO4icqPLG l4Ot1iVITbmBM1XghAIfn5B0wvkOqHbeih16OX7KPey/0LjTylmmPIR2wSvF0t4V8kFU D/Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WSWb+AKS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i4si1016067oii.211.2020.03.26.07.08.46; Thu, 26 Mar 2020 07:09:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WSWb+AKS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727905AbgCZOF1 (ORCPT + 99 others); Thu, 26 Mar 2020 10:05:27 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:58354 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727829AbgCZOF1 (ORCPT ); Thu, 26 Mar 2020 10:05:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585231525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iu8pP+Jj7yxXz+kaoKj+StMGIPihDf+lmC4twg0Tx8I=; b=WSWb+AKSjFkVDJ+4UqgQ1b676RSAwOVsRNKIZNKp7Je1VD6QnR1DwgFaMxz1LdGnt81jaa fMRtZtFEoQELpuUwW9iCXKvZig/tTtQf9fdA5ZVkE1A7kZioEtqjOp9NadnUloe9Fem0Ai YJ0YHWQ2c0Pp8VZxVXVZGpuTGOUI3JQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-237-0u_75s20Ol2V_hn2y9Qfqw-1; Thu, 26 Mar 2020 10:05:24 -0400 X-MC-Unique: 0u_75s20Ol2V_hn2y9Qfqw-1 Received: by mail-wr1-f70.google.com with SMTP id b2so2649372wrq.8 for ; Thu, 26 Mar 2020 07:05:24 -0700 (PDT) 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:in-reply-to:references:date :message-id:mime-version; bh=iu8pP+Jj7yxXz+kaoKj+StMGIPihDf+lmC4twg0Tx8I=; b=SA5MJBU3xtLvNwYo1j0OfrzDWJdT3146GyIApUfR6punU6TaAzFMjs6IvZBK8I/iix L8ifjXNS0XVoe6w66SLY8n1NEClvJT71ALbjBZZ4IgWfPaD6N4/tmDfBgqO8gyeFi1YG YisMgS2rFuMtJTozZvqLCEjfZA2kygNqyW5rtHmNbEypfOMk5pJAlH9v07FIPgsx7IAY qIyJbCZmJFSJ603Csj02gClzFZ2HERK3W7wWfxy0FdFOaqwJQ4VUi9j98g/stL+AXPjZ n5UnGOQgSiwXPgLPe9Is7E0h/juCibDUBEKZlptyoHJb7LU7FMeMejmAaNDru5todc5S 3mOQ== X-Gm-Message-State: ANhLgQ3DahjdwozQuWt8itoXvMymn99Cg3MrmFYXf1YROsjUAp8oRqCQ e1ChCYhOcD92AQeFI93l9TDYUByK0PELP8lcB8qvQ1jRB/GPIxCb5W6Ugd2Ggrkb+jyl1oqLs/6 iKtE1f2dU8izlwoZqojNBnqx8 X-Received: by 2002:a5d:4611:: with SMTP id t17mr392178wrq.16.1585231520389; Thu, 26 Mar 2020 07:05:20 -0700 (PDT) X-Received: by 2002:a5d:4611:: with SMTP id t17mr392144wrq.16.1585231520041; Thu, 26 Mar 2020 07:05:20 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id r3sm3775853wrm.35.2020.03.26.07.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 07:05:19 -0700 (PDT) From: Vitaly Kuznetsov To: "Andrea Parri \(Microsoft\)" , Dexuan Cui Cc: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , linux-hyperv@vger.kernel.org, Michael Kelley , Boqun Feng , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 01/11] Drivers: hv: vmbus: Always handle the VMBus messages on CPU0 In-Reply-To: <20200325225505.23998-2-parri.andrea@gmail.com> References: <20200325225505.23998-1-parri.andrea@gmail.com> <20200325225505.23998-2-parri.andrea@gmail.com> Date: Thu, 26 Mar 2020 15:05:17 +0100 Message-ID: <874kub5i02.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Andrea Parri (Microsoft)" writes: > A Linux guest have to pick a "connect CPU" to communicate with the > Hyper-V host. This CPU can not be taken offline because Hyper-V does > not provide a way to change that CPU assignment. > > Current code sets the connect CPU to whatever CPU ends up running the > function vmbus_negotiate_version(), and this will generate problems if > that CPU is taken offine. > > Establish CPU0 as the connect CPU, and add logics to prevents the > connect CPU from being taken offline. We could pick some other CPU, > and we could pick that "other CPU" dynamically if there was a reason to > do so at some point in the future. But for now, #defining the connect > CPU to 0 is the most straightforward and least complex solution. > > While on this, add inline comments explaining "why" offer and rescind > messages should not be handled by a same serialized work queue. > > Suggested-by: Dexuan Cui > Signed-off-by: Andrea Parri (Microsoft) > --- > drivers/hv/connection.c | 20 +------------------- > drivers/hv/hv.c | 7 +++++++ > drivers/hv/hyperv_vmbus.h | 11 ++++++----- > drivers/hv/vmbus_drv.c | 20 +++++++++++++++++--- > 4 files changed, 31 insertions(+), 27 deletions(-) > > diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c > index 74e77de89b4f3..f4bd306d2cef9 100644 > --- a/drivers/hv/connection.c > +++ b/drivers/hv/connection.c > @@ -69,7 +69,6 @@ MODULE_PARM_DESC(max_version, > int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) > { > int ret = 0; > - unsigned int cur_cpu; > struct vmbus_channel_initiate_contact *msg; > unsigned long flags; > > @@ -102,24 +101,7 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) > > msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]); > msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]); > - /* > - * We want all channel messages to be delivered on CPU 0. > - * This has been the behavior pre-win8. This is not > - * perf issue and having all channel messages delivered on CPU 0 > - * would be ok. > - * For post win8 hosts, we support receiving channel messagges on > - * all the CPUs. This is needed for kexec to work correctly where > - * the CPU attempting to connect may not be CPU 0. > - */ > - if (version >= VERSION_WIN8_1) { > - cur_cpu = get_cpu(); > - msg->target_vcpu = hv_cpu_number_to_vp_number(cur_cpu); > - vmbus_connection.connect_cpu = cur_cpu; > - put_cpu(); > - } else { > - msg->target_vcpu = 0; > - vmbus_connection.connect_cpu = 0; > - } > + msg->target_vcpu = hv_cpu_number_to_vp_number(VMBUS_CONNECT_CPU); > > /* > * Add to list before we send the request since we may > diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c > index 6098e0cbdb4b0..e2b3310454640 100644 > --- a/drivers/hv/hv.c > +++ b/drivers/hv/hv.c > @@ -249,6 +249,13 @@ int hv_synic_cleanup(unsigned int cpu) > bool channel_found = false; > unsigned long flags; > > + /* > + * Hyper-V does not provide a way to change the connect CPU once > + * it is set; we must prevent the connect CPU from going offline. > + */ > + if (cpu == VMBUS_CONNECT_CPU) > + return -EBUSY; > + > /* > * Search for channels which are bound to the CPU we're about to > * cleanup. In case we find one and vmbus is still connected we need to > diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h > index 70b30e223a578..67fb1edcbf527 100644 > --- a/drivers/hv/hyperv_vmbus.h > +++ b/drivers/hv/hyperv_vmbus.h > @@ -212,12 +212,13 @@ enum vmbus_connect_state { > > #define MAX_SIZE_CHANNEL_MESSAGE HV_MESSAGE_PAYLOAD_BYTE_COUNT > > -struct vmbus_connection { > - /* > - * CPU on which the initial host contact was made. > - */ > - int connect_cpu; > +/* > + * The CPU that Hyper-V will interrupt for VMBUS messages, such as > + * CHANNELMSG_OFFERCHANNEL and CHANNELMSG_RESCIND_CHANNELOFFER. > + */ > +#define VMBUS_CONNECT_CPU 0 > > +struct vmbus_connection { > u32 msg_conn_id; > > atomic_t offer_in_progress; > diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c > index 029378c27421d..7600615e13754 100644 > --- a/drivers/hv/vmbus_drv.c > +++ b/drivers/hv/vmbus_drv.c > @@ -1056,14 +1056,28 @@ void vmbus_on_msg_dpc(unsigned long data) > /* > * If we are handling the rescind message; > * schedule the work on the global work queue. > + * > + * The OFFER message and the RESCIND message should > + * not be handled by the same serialized work queue, > + * because the OFFER handler may call vmbus_open(), > + * which tries to open the channel by sending an > + * OPEN_CHANNEL message to the host and waits for > + * the host's response; however, if the host has > + * rescinded the channel before it receives the > + * OPEN_CHANNEL message, the host just silently > + * ignores the OPEN_CHANNEL message; as a result, > + * the guest's OFFER handler hangs for ever, if we > + * handle the RESCIND message in the same serialized > + * work queue: the RESCIND handler can not start to > + * run before the OFFER handler finishes. > */ > - schedule_work_on(vmbus_connection.connect_cpu, > + schedule_work_on(VMBUS_CONNECT_CPU, > &ctx->work); > break; > > case CHANNELMSG_OFFERCHANNEL: > atomic_inc(&vmbus_connection.offer_in_progress); > - queue_work_on(vmbus_connection.connect_cpu, > + queue_work_on(VMBUS_CONNECT_CPU, > vmbus_connection.work_queue, > &ctx->work); > break; > @@ -1110,7 +1124,7 @@ static void vmbus_force_channel_rescinded(struct vmbus_channel *channel) > > INIT_WORK(&ctx->work, vmbus_onmessage_work); > > - queue_work_on(vmbus_connection.connect_cpu, > + queue_work_on(VMBUS_CONNECT_CPU, > vmbus_connection.work_queue, > &ctx->work); > } I tried to refresh my memory on why 'connect_cpu' was introduced and it all comes down to the following commit: commit 7268644734f6a300353a4c4ff8bf3e013ba80f89 Author: Alex Ng Date: Fri Feb 26 15:13:22 2016 -0800 Drivers: hv: vmbus: Support kexec on ws2012 r2 and above which for some unknown reason kept hardcoding '0' for pre-win2012-r2 ( hv_context.vp_index[smp_processor_id()] in all cases would do exactly the same I guess ). Later, 'connect_cpu' appeared just to remember our choice, I can't see why we didn't go with CPU0 for simplicity. Reviewed-by: Vitaly Kuznetsov -- Vitaly