Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp196640pxb; Wed, 20 Jan 2021 04:59:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBrHPddBb1A/w5JrwXWw5e3f8haGRQBJ5/p8A5az23bNwxHJ5Uhsa6KZKXexop1dkvgcju X-Received: by 2002:a17:906:6846:: with SMTP id a6mr6023558ejs.470.1611147595580; Wed, 20 Jan 2021 04:59:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611147595; cv=none; d=google.com; s=arc-20160816; b=HJ5LXkiCHj03T5WbV7qPS6t0UJn0Tacu4lnczcq0BYZo/vqg5ezMFBeHKdaRrViZha 3q0s1/M+c5Z9bkZLdmzAcHiH/7Hv0YaUfgS3x4NsU3WiDamE2CpM1J1l0o8IPNPsJeO9 FwAqoF7WxZAZ0wc0OV0i8jD2N6nGG3q7vuc37xmXWwdyE6sajP+GFXwtSZaBcC1kPDPZ jzYEW/1IKrKoIn5LR7QLhmyevo9N7qaT4995JHcx3AGbM+nyGPKkcEoWjiWW1pvg4HS4 CPyU5DLy3POTViM4B/z4FotVM+q5ZNkIIZ5hC2xsRIkE8OIvbDpb9ihL+HSdHRP3WF7i adXA== 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; bh=1AnwUhpK3uc/E6NKbzj7KMKk+WsZG+5G79p8q0Z4Cfs=; b=J8D2hsDfs8VI9r0ttLERgZfEbCFA55+I0M4htwRPQU/ID0rcfvirFi4liZsVppe+Cc sWlsPKm+Z8NlLIbhCVIh31DX9fQw8fBAXL/irKqcy/f0zQyqVODF+ulCgDttVu8g5fyG xkBteEdZGTdRyCpkzaVKko6pTUZdg/9f/zjCTiS1TK5vmyTWHErlT8ty1g0cPqHzGEjX 7BPkmaHLDIkhUlAYMLhp1Xckv3h4kV9gea3K2ztV/XdAkazKS7OAQuNwVViOErx547qx JcT0uxSaP5LRXyuHEvip7p/uDu6JYd4/3NGgEpoJqQra/iF/BuE+nbTedZD3HeBlc3yb kM0Q== 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 n12si803026edo.512.2021.01.20.04.59.30; Wed, 20 Jan 2021 04:59:55 -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 S2388772AbhATM6n (ORCPT + 99 others); Wed, 20 Jan 2021 07:58:43 -0500 Received: from mail-wm1-f47.google.com ([209.85.128.47]:34193 "EHLO mail-wm1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389196AbhATMKn (ORCPT ); Wed, 20 Jan 2021 07:10:43 -0500 Received: by mail-wm1-f47.google.com with SMTP id o10so3174139wmc.1; Wed, 20 Jan 2021 04:10:25 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=1AnwUhpK3uc/E6NKbzj7KMKk+WsZG+5G79p8q0Z4Cfs=; b=RipKft3tWjqWpVrLkSfnDVSuZlrz02O5rSNgWf0xN+l06zrAwwg/O7APjc3nLmllwV 4zNDIwpnNwA08eDl9jF8Iw0Df4ai5IOnVuWgTRWz+H3P5sqxquJ8gyLzw7uVDEkpg+lq +jD9KeJUwPMGEAZnS+jB36yA2/XmEwiB4/uNSxtRs863avaI7N/V+x2zd+I/jvBrQKaM /j0jPU48jdubsdacpKXeygTX6v9GGr7L9+0BSb3I6pA0VYsp+cHA+7Jlmvvd+IUiaVOO y6Hm5QQhstoFsvFFEsyCK9s2cpH+PC0bJ+st6VzzVd7NcyDiy4E9sAPhndqjuOQKDLeF rViw== X-Gm-Message-State: AOAM531GC0t9suabA/5dgV0+d1bMeYMHECA56kXtynRKa29hDBGrsbR3 PZjn1ivEAspG06ncejNBVOMFvQo2oeE= X-Received: by 2002:a1c:99d1:: with SMTP id b200mr4020424wme.37.1611144067464; Wed, 20 Jan 2021 04:01:07 -0800 (PST) Received: from liuwe-devbox-debian-v2.j3c5onc20sse1dnehy4noqpfcg.zx.internal.cloudapp.net ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id x17sm3747671wro.40.2021.01.20.04.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 04:01:07 -0800 (PST) From: Wei Liu To: Linux on Hyper-V List Cc: virtualization@lists.linux-foundation.org, Linux Kernel List , Michael Kelley , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , pasha.tatashin@soleen.com, Wei Liu , Lillian Grassin-Drake , "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" Subject: [PATCH v5 06/16] x86/hyperv: allocate output arg pages if required Date: Wed, 20 Jan 2021 12:00:48 +0000 Message-Id: <20210120120058.29138-7-wei.liu@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210120120058.29138-1-wei.liu@kernel.org> References: <20210120120058.29138-1-wei.liu@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When Linux runs as the root partition, it will need to make hypercalls which return data from the hypervisor. Allocate pages for storing results when Linux runs as the root partition. Signed-off-by: Lillian Grassin-Drake Co-Developed-by: Lillian Grassin-Drake Signed-off-by: Wei Liu --- v3: Fix hv_cpu_die to use free_pages. v2: Address Vitaly's comments --- arch/x86/hyperv/hv_init.c | 35 ++++++++++++++++++++++++++++----- arch/x86/include/asm/mshyperv.h | 1 + 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index e04d90af4c27..6f4cb40e53fe 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -41,6 +41,9 @@ EXPORT_SYMBOL_GPL(hv_vp_assist_page); void __percpu **hyperv_pcpu_input_arg; EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); +void __percpu **hyperv_pcpu_output_arg; +EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg); + u32 hv_max_vp_index; EXPORT_SYMBOL_GPL(hv_max_vp_index); @@ -73,12 +76,19 @@ static int hv_cpu_init(unsigned int cpu) void **input_arg; struct page *pg; - input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ - pg = alloc_page(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL); + pg = alloc_pages(irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL, hv_root_partition ? 1 : 0); if (unlikely(!pg)) return -ENOMEM; + + input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); *input_arg = page_address(pg); + if (hv_root_partition) { + void **output_arg; + + output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); + *output_arg = page_address(pg + 1); + } hv_get_vp_index(msr_vp_index); @@ -205,14 +215,23 @@ static int hv_cpu_die(unsigned int cpu) unsigned int new_cpu; unsigned long flags; void **input_arg; - void *input_pg = NULL; + void *pg; local_irq_save(flags); input_arg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); - input_pg = *input_arg; + pg = *input_arg; *input_arg = NULL; + + if (hv_root_partition) { + void **output_arg; + + output_arg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); + *output_arg = NULL; + } + local_irq_restore(flags); - free_page((unsigned long)input_pg); + + free_pages((unsigned long)pg, hv_root_partition ? 1 : 0); if (hv_vp_assist_page && hv_vp_assist_page[cpu]) wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0); @@ -346,6 +365,12 @@ void __init hyperv_init(void) BUG_ON(hyperv_pcpu_input_arg == NULL); + /* Allocate the per-CPU state for output arg for root */ + if (hv_root_partition) { + hyperv_pcpu_output_arg = alloc_percpu(void *); + BUG_ON(hyperv_pcpu_output_arg == NULL); + } + /* Allocate percpu VP index */ hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index), GFP_KERNEL); diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index ac2b0d110f03..62d9390f1ddf 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -76,6 +76,7 @@ static inline void hv_disable_stimer0_percpu_irq(int irq) {} #if IS_ENABLED(CONFIG_HYPERV) extern void *hv_hypercall_pg; extern void __percpu **hyperv_pcpu_input_arg; +extern void __percpu **hyperv_pcpu_output_arg; static inline u64 hv_do_hypercall(u64 control, void *input, void *output) { -- 2.20.1