From patchwork Wed Feb 19 11:44:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11391279 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84F5B92A for ; Wed, 19 Feb 2020 11:45:30 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6158F24654 for ; Wed, 19 Feb 2020 11:45:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c/aQAfyj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6158F24654 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4NmG-00047C-5D; Wed, 19 Feb 2020 11:44:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4NmE-00046h-BH for xen-devel@lists.xenproject.org; Wed, 19 Feb 2020 11:44:26 +0000 X-Inumbo-ID: 291939b0-530d-11ea-aa99-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 291939b0-530d-11ea-aa99-bc764e2007e4; Wed, 19 Feb 2020 11:44:18 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id w15so155182wru.4 for ; Wed, 19 Feb 2020 03:44:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BLEjnFrEzrCENnu1c3Vg1Kq9JDtXw7ou3x1Aj1K6Fbg=; b=c/aQAfyjBQh06fMreeSRYuV3koBfURhV2Rx4b4RgDE1cHPhllgaRXldXorhhOKLogp YTHJmwSIzjG7jkht+C4NxLe7dLSHXj+uWVBW174Kv7mtEi+DSngKSPLs+0onTrYdj52q NdRppHSEfMapoaTBYjCzczaLcDFE/9fbWSkpUIJfLCwWaFp7qKJaZ+vr18a0cnvmqEWt It1v3lqG26b2TCK3iZoxG1CUPatA/7QDlobARF1JCCo7ubOw0TrDPXpjm+8BYxBcAfT7 F0mfOVdYBiAsnYwYDqSqqPVPYmbBNLEUg+Ljo27cKWqSFJ85iZdzi8y4UN+yQ4iyYOu0 tjUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BLEjnFrEzrCENnu1c3Vg1Kq9JDtXw7ou3x1Aj1K6Fbg=; b=tTi7AJQ2uLMIYFz3ip45UEP2Yq7ldNdvYUAo73lo2jN5GjP1i4dzC6bDFUL//owkrv VJg5AxP2y/2wMHOK2+hoOj6oCzSQ/+TS0u1TL985dNIKzaJmvswApzh7B6pHFq7Wb1JB aju3JKy3+3mYq9/wHOwcCCbvS1G9870AsWCurKMAVDVvkmKqV90DBXIcnhuGW0ptsNUx JTEcf9TbXMblTi30EAaDxBZrTMA9tB3MLt+V5TrjWd1LTUITn5k/VN5291MTZX/Hhupo cYcjrMLXGx0xO+a5rs/5cvOyXb1a544HhkBeA9xx7S7WqSxn58GCWbEW3P23sBvZoE5o CQ5g== X-Gm-Message-State: APjAAAUo7q9HligvZ3bAbhAhhBYza26YpArOSqJr8oa9ko+R8/UHyeLx yDNOHiOXMKnCtEKihAFYch5GI0gObcA= X-Google-Smtp-Source: APXvYqw/beDYgXei5owC6K4OiLanUMvRfieJtaMzU9HZZ4QMljt4ALmJEZYmSbwB7Q7Ap8+LatZ/qQ== X-Received: by 2002:adf:f586:: with SMTP id f6mr34018472wro.46.1582112656550; Wed, 19 Feb 2020 03:44:16 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id q3sm2534657wmj.38.2020.02.19.03.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 03:44:16 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 19 Feb 2020 11:44:10 +0000 Message-Id: <20200219114411.26922-3-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200219114411.26922-1-liuwe@microsoft.com> References: <20200219114411.26922-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 2/3] x86/hyperv: skeleton for L0 assisted TLB flush X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Implement a basic hook for L0 assisted TLB flush. The hook needs to check if prerequisites are met. If they are not met, it returns an error number to fall back to native flushes. Introduce a new variable to indicate if hypercall page is ready. Signed-off-by: Wei Liu Reviewed-by: Roger Pau Monné Reviewed-by: Paul Durrant --- v3: 1. Change hv_hcall_page_ready to hcall_page_ready --- xen/arch/x86/guest/hyperv/Makefile | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 17 ++++++++++++ xen/arch/x86/guest/hyperv/private.h | 4 +++ xen/arch/x86/guest/hyperv/tlb.c | 41 +++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/tlb.c diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile index 68170109a9..18902c33e9 100644 --- a/xen/arch/x86/guest/hyperv/Makefile +++ b/xen/arch/x86/guest/hyperv/Makefile @@ -1 +1,2 @@ obj-y += hyperv.o +obj-y += tlb.o diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 70f4cd5ae0..f1b3073712 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -33,6 +33,8 @@ DEFINE_PER_CPU_READ_MOSTLY(void *, hv_input_page); DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); +static bool __read_mostly hcall_page_ready; + static uint64_t generate_guest_id(void) { union hv_guest_os_id id = {}; @@ -119,6 +121,8 @@ static void __init setup_hypercall_page(void) BUG_ON(!hypercall_msr.enable); set_fixmap_x(FIX_X_HYPERV_HCALL, mfn << PAGE_SHIFT); + + hcall_page_ready = true; } static int setup_hypercall_pcpu_arg(void) @@ -199,11 +203,24 @@ static void __init e820_fixup(struct e820map *e820) panic("Unable to reserve Hyper-V hypercall range\n"); } +static int flush_tlb(const cpumask_t *mask, const void *va, + unsigned int flags) +{ + if ( !(ms_hyperv.hints & HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED) ) + return -EOPNOTSUPP; + + if ( !hcall_page_ready || !this_cpu(hv_input_page) ) + return -ENXIO; + + return hyperv_flush_tlb(mask, va, flags); +} + static const struct hypervisor_ops __initdata ops = { .name = "Hyper-V", .setup = setup, .ap_setup = ap_setup, .e820_fixup = e820_fixup, + .flush_tlb = flush_tlb, }; /* diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h index 956eff831f..509bedaafa 100644 --- a/xen/arch/x86/guest/hyperv/private.h +++ b/xen/arch/x86/guest/hyperv/private.h @@ -22,10 +22,14 @@ #ifndef __XEN_HYPERV_PRIVIATE_H__ #define __XEN_HYPERV_PRIVIATE_H__ +#include #include DECLARE_PER_CPU(void *, hv_input_page); DECLARE_PER_CPU(void *, hv_vp_assist); DECLARE_PER_CPU(unsigned int, hv_vp_index); +int hyperv_flush_tlb(const cpumask_t *mask, const void *va, + unsigned int flags); + #endif /* __XEN_HYPERV_PRIVIATE_H__ */ diff --git a/xen/arch/x86/guest/hyperv/tlb.c b/xen/arch/x86/guest/hyperv/tlb.c new file mode 100644 index 0000000000..48f527229e --- /dev/null +++ b/xen/arch/x86/guest/hyperv/tlb.c @@ -0,0 +1,41 @@ +/****************************************************************************** + * arch/x86/guest/hyperv/tlb.c + * + * Support for TLB management using hypercalls + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + * + * Copyright (c) 2020 Microsoft. + */ + +#include +#include + +#include "private.h" + +int hyperv_flush_tlb(const cpumask_t *mask, const void *va, + unsigned int flags) +{ + return -EOPNOTSUPP; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */