Received: by 10.213.65.68 with SMTP id h4csp1557052imn; Thu, 15 Mar 2018 03:11:42 -0700 (PDT) X-Google-Smtp-Source: AG47ELtIr6+ezUgn11Y9SvtNLMcCKqzhg+Blfb9dwIFTL7NlQTtT6K5HSzVi/iy1dZ6ISa9IH8PY X-Received: by 10.101.66.76 with SMTP id d12mr6281530pgq.234.1521108702712; Thu, 15 Mar 2018 03:11:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521108702; cv=none; d=google.com; s=arc-20160816; b=OJDA4gkcA3a5EpupYSD/wXOhKbqXJ8JaVhcnN7oUqex6akmJTQBxPxOOjweMaehrYx U9/S9mHfG6OuM+EpEELhjqS1FJY46li0oiyRmo6GzEcXsW9Pl7Cqsx+ZOD0k4ZeICzpp +453sqsNdTKKpqcm4NlljbgQBxWsFlyVP2tR+Go9utV2uanmZgWslRRZovqnDZfK0lry vKtD3xF2kzDRe9q2/ezEP3HeE5G7gInh3Vsh+oF8XDfuMaVTMaLkNMBHDroUJE5zyp5h fyp7u0U3ni30zL3Sx9rdgBSuY+j+07rLwBGD3I5OmJGcp9HeKqJzPg5GCWptOI5gEaZN dQtg== 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=CvBTsssRn14bJIEue0LzUNdWavvlOSeoxPdUY3RGA0A=; b=kcubK7RCV4NZu7pyr+7WkNAr2m2dHLvA3gwS/TRXYTbTBkcReKkF2W6Lbh63hyIr8/ Kgxi5FbwqdfawbD82ISJi9JHcoLzrKMCboF2G9jZ5PW5QRiyjn+ta5LwCpGh5fKJARLt dR8cQdI5wUzPKvLDjmoCqb/cIn5sAZvLLdYcrkQhthMIWqnlAUlSupy6FC3Ig307q5X0 21j2n2shz4b8DlPdGd7pi+3OamdZjKRgDaqjcrkQrrpX2ii6zb/d+8H619OD3PJcQYkp HZzivgoHGR4kNWwnyDxmkVCZ/+yqY346L6XQAWgH9vbS6KhDGXaK/5pKphBYi9aYAcsn piCw== 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 c5-v6si3712652pll.90.2018.03.15.03.11.27; Thu, 15 Mar 2018 03:11:42 -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 S1751693AbeCOKKe (ORCPT + 99 others); Thu, 15 Mar 2018 06:10:34 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42438 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751405AbeCOKKc (ORCPT ); Thu, 15 Mar 2018 06:10:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 107474072CC1; Thu, 15 Mar 2018 10:10:32 +0000 (UTC) Received: from vitty.brq.redhat.com.redhat.com (unknown [10.40.205.96]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA69E2026DFD; Thu, 15 Mar 2018 10:10:28 +0000 (UTC) From: Vitaly Kuznetsov To: Thomas Gleixner Cc: kvm@vger.kernel.org, x86@kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley \(EOSG\)" , Mohammed Gamal , Cathy Avery , Bandan Das , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 4/7] x86/hyper-v: allocate and use Virtual Processor Assist Pages References: <20180309140249.2840-1-vkuznets@redhat.com> <20180309140249.2840-5-vkuznets@redhat.com> Date: Thu, 15 Mar 2018 11:10:27 +0100 In-Reply-To: (Thomas Gleixner's message of "Wed, 14 Mar 2018 16:15:58 +0100 (CET)") Message-ID: <87bmfpbqek.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.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 15 Mar 2018 10:10:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 15 Mar 2018 10:10:32 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 Thomas Gleixner writes: > On Fri, 9 Mar 2018, Vitaly Kuznetsov wrote: >> @@ -198,6 +218,12 @@ static int hv_cpu_die(unsigned int cpu) >> struct hv_reenlightenment_control re_ctrl; >> unsigned int new_cpu; >> >> + if (hv_vp_assist_page && hv_vp_assist_page[cpu]) { >> + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0); >> + vfree(hv_vp_assist_page[cpu]); >> + hv_vp_assist_page[cpu] = NULL; > > So this is freed before the CPU is actually dead. And this runs in > preemtible context. Is the wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0); enough to > prevent eventual users of the assist page on the outgoing CPU from > accessing it? > After we do wrmsrl() the page is no longer 'magic' so in case eventual users try using it they'll most likely misbehave -- so changing the shutdown order won't help. The only user of these pages is currently KVM. Can we still have vCPUs running on the outgoing CPU at this point? If case we can we're in trouble and we need to somehow kick them out first. >> if (hv_reenlightenment_cb == NULL) >> return 0; >> >> @@ -241,6 +267,13 @@ void hyperv_init(void) >> if (!hv_vp_index) >> return; >> >> + hv_vp_assist_page = kcalloc(num_possible_cpus(), >> + sizeof(*hv_vp_assist_page), GFP_KERNEL); >> + if (!hv_vp_assist_page) { >> + ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED; >> + return; >> + } >> + >> if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/hyperv_init:online", >> hv_cpu_init, hv_cpu_die) < 0) >> goto free_vp_index; > > Shouldn't you free hv_vp_assist_page in the error path? > Yep, will do. >> +extern struct hv_vp_assist_page **hv_vp_assist_page; >> + >> +static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu) >> +{ >> + return hv_vp_assist_page[cpu]; > > Shouldn't that check hv_vp_assist_page != NULL? > Not strictly required as we clean HV_X64_ENLIGHTENED_VMCS_RECOMMENDED above so KVM won't use it but I can add the check to make the API better. Thanks, -- Vitaly