Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5021325imm; Tue, 31 Jul 2018 04:21:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe1zLPtpk/RHO/Ey5ofj7wTxxfx4lx3Wy7RO0qsgaFbeRo7wVMY7loFJ2QfNHHvtf6c0dj5 X-Received: by 2002:a17:902:59da:: with SMTP id d26-v6mr20033908plj.42.1533036064350; Tue, 31 Jul 2018 04:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533036064; cv=none; d=google.com; s=arc-20160816; b=TLw7Hs9j6UvD4QkNIUcTFjOLIkC2Q9g+XoFx+hvNSKP9ngrS8C9gLPtQGtJDBZUOmk V+j85rK0cQR6JxNq1nakNPc7kipwsy2qZdFJG3gHktkQRkPc9FvMcojFg2t2nzNmM6Qf EtQZoYwFIw1+7Ab8JP8k1Q/VwUIRbEadulzYu6KSk3A3Lw1yMnZHsagbWAmr4Ls88hbq ylo62b7HDEk2vXC5RZJH90orvS/NgTo+9oSuVRJfoFteumu47qIN6BoLkKFFPSXOmnat +ofPpLotilYj8GHgvy26kTS4JjaikWopyk0U2X+1xQgzcfTq2v5nGhVDsOpfV7uHev8k VZkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from :arc-authentication-results; bh=aVEYSwcM9YwyKV9A4YNa1ur0wjzTizwx5sYV7yMUvTw=; b=m2GCHZQx77YUQxO4IV8qpsLFIJJrwibUQ2jzBa4nmR+aGoqQy+cnUaOG7AHtDCDtEH po+1PqYowZ1a4XP6q9h2nGCk/wR+SfPcqFIe4Ppi6raMLE/sdiKSBq1CbRrZjZb78nPp uu6CyLxWGKHMmQJYNXkfLhhmzcmEE6Qj5CgWOI7cGaaKd+TWSj00pHMMTewlbl4FZCKs TdXfBF3aj6+JRsbJJ1p7m7HLhhUs1kJ9PRtfn6SoxoAbvKX67gcTb9z5LaMmJtS9m11I zq6d10dGXP88K3exodgF7ny97la8zWbBGS7U+NG14nm56f/wKZZTMt24n61v1ccgwBZo kuow== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 e188-v6si5868420pfe.231.2018.07.31.04.20.49; Tue, 31 Jul 2018 04:21:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732073AbeGaM7n (ORCPT + 99 others); Tue, 31 Jul 2018 08:59:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54588 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731639AbeGaM7m (ORCPT ); Tue, 31 Jul 2018 08:59:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F29C40241C0; Tue, 31 Jul 2018 11:19:51 +0000 (UTC) Received: from vitty.brq.redhat.com.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38F0D178BC; Tue, 31 Jul 2018 11:19:49 +0000 (UTC) From: Vitaly Kuznetsov To: mhkelley58@gmail.com Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, jasowang@redhat.com, marcelo.cerri@canonical.com, sthemmin@microsoft.com, kys@microsoft.com, mikelley@microsoft.com Subject: Re: [PATCH char-misc 1/1] Drivers: hv: vmbus: Make synic_initialized flag per-cpu References: <1533004484-3937-1-git-send-email-mikelley@microsoft.com> Date: Tue, 31 Jul 2018 13:19:48 +0200 In-Reply-To: <1533004484-3937-1-git-send-email-mikelley@microsoft.com> (mhkelley's message of "Mon, 30 Jul 2018 19:34:44 -0700") Message-ID: <87ftzzodnv.fsf@vitty.brq.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 31 Jul 2018 11:19:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 31 Jul 2018 11:19:51 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkuznets@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org mhkelley58@gmail.com writes: > From: Michael Kelley > > The synic_initialized flag is part of the global hv_context > structure. But the Hyper-V synthetic interrupt controller is > fundamentally a per-cpu device, and other synic related > fields are in hv_per_cpu_context. In a multi-CPU system, > synic_initialized gets set multiple times, making the test in > hv_synic_cleanup() invalid. Fix this by moving the flag to > hv_per_cpu_context and adjusting the references. > > Signed-off-by: Michael Kelley > --- > drivers/hv/hv.c | 16 +++++++--------- > drivers/hv/hyperv_vmbus.h | 4 ++-- > 2 files changed, 9 insertions(+), 11 deletions(-) > > diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c > index 312fe5e..8d4fe0e 100644 > --- a/drivers/hv/hv.c > +++ b/drivers/hv/hv.c > @@ -33,9 +33,7 @@ > #include "hyperv_vmbus.h" > > /* The one and only */ > -struct hv_context hv_context = { > - .synic_initialized = false, > -}; > +struct hv_context hv_context; > > /* > * If false, we're using the old mechanism for stimer0 interrupts > @@ -315,7 +313,7 @@ int hv_synic_init(unsigned int cpu) > > hv_set_synic_state(sctrl.as_uint64); > > - hv_context.synic_initialized = true; > + hv_cpu->synic_initialized = true; > > /* > * Register the per-cpu clockevent source. > @@ -354,6 +352,8 @@ void hv_synic_clockevents_cleanup(void) > */ > int hv_synic_cleanup(unsigned int cpu) > { > + struct hv_per_cpu_context *hv_cpu > + = per_cpu_ptr(hv_context.cpu_context, cpu); > union hv_synic_sint shared_sint; > union hv_synic_simp simp; > union hv_synic_siefp siefp; > @@ -362,7 +362,7 @@ int hv_synic_cleanup(unsigned int cpu) > bool channel_found = false; > unsigned long flags; > > - if (!hv_context.synic_initialized) > + if (!hv_cpu->synic_initialized) > return -EFAULT; > > /* > @@ -395,12 +395,8 @@ int hv_synic_cleanup(unsigned int cpu) > > /* Turn off clockevent device */ > if (ms_hyperv.features & HV_MSR_SYNTIMER_AVAILABLE) { > - struct hv_per_cpu_context *hv_cpu > - = this_cpu_ptr(hv_context.cpu_context); > - > clockevents_unbind_device(hv_cpu->clk_evt, cpu); > hv_ce_shutdown(hv_cpu->clk_evt); > - put_cpu_ptr(hv_cpu); > } > > hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64); > @@ -428,5 +424,7 @@ int hv_synic_cleanup(unsigned int cpu) > sctrl.enable = 0; > hv_set_synic_state(sctrl.as_uint64); > > + hv_cpu->synic_initialized = false; > + > return 0; > } > diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h > index 72eaba3..eadd3df 100644 > --- a/drivers/hv/hyperv_vmbus.h > +++ b/drivers/hv/hyperv_vmbus.h > @@ -202,6 +202,8 @@ enum { > struct hv_per_cpu_context { > void *synic_message_page; > void *synic_event_page; > + bool synic_initialized; > + > /* > * buffer to post messages to the host. > */ > @@ -230,8 +232,6 @@ struct hv_context { > > void *tsc_page; > > - bool synic_initialized; > - > struct hv_per_cpu_context __percpu *cpu_context; > > /* Reviewed-by: Vitaly Kuznetsov Alternatively, we can get rid of synic_initialized flag altogether: hv_synic_init() never fails in the first place but we can always implement something like: int hv_synic_is_initialized(void) { union hv_synic_scontrol sctrl; hv_get_synic_state(sctrl.as_uint64); return sctrl.enable; } as it doesn't seem that we need to check synic state on _other_ CPUs. -- Vitaly