Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1516051pxb; Wed, 20 Oct 2021 06:42:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwI1s4jjbKeDgoBXdZNC3WwJnlKS+rqpBbo2Q14h+wqMXKzbgFuObBI23CVgivyIte7j7ZI X-Received: by 2002:aa7:c6d4:: with SMTP id b20mr111702eds.270.1634737339186; Wed, 20 Oct 2021 06:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634737339; cv=none; d=google.com; s=arc-20160816; b=nM+JQXyD+SkLyZpB/aK7KLumjrJkmIoIrhMca/p+bZLIYwaTpxQ1sm+N/L34ivuBao Hqrmf+72+FPhAo9ceImOTYO0lfMgJOsYbQqU56BTneOgX1+Jm8WS6zRby3I/7/C0vCzD c5DiEvu1oldUq4RqMxPq55hjjCilbSwDn0HERh8FZ66BN+sJ/WCD+kA1FCt0HK4qwTs2 G023h94Hw8Nz7F3Q2zkraIqLKKB8WakNty+0o55REGb8z1zsRYYWwVKFHJaPeAT8BSIR mBr5eaI4iTW6dzvPShb3SQn3GmTrSfNqkbOxuqink+7ehTm2ri9b1E26I+Z3HsOF8V9i SN8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=u6CGs01obc8jKPitQtYRdGE87x9sved8yOI/KYoYUvM=; b=svwjG8Po8y855k8XFgHOhCzkDEdV+lRAWso8Tt1QrR5RdDpsMkwOuKbftOEHDgGWnX DhigQac6akO3TPTzibxd0G1evi7l42ZwxNSuRNC1SWAQq2cuennP7dSGprmeCzm2HQwn ThJ4VK/VkongJXNCZ7FR2LtB+qXFUvtwi3plTtF74Ko5sTPbxivmI5REhmcOsWvHJgP4 Cmu9g+Wko+pZ/OABh5Iuk6lH3uJGCpm9EtIHOxulmaZRYbAFaF9lLSd6bR+RZqkNdE0P w1uqVN+cDkiCOfu9bzgL7YmM07Do0DXfB7n/gNh6P3VEPRinNnvvZcACHXTqDvkltiw9 IqaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=JOKjVeuL; 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=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s1si2524249ejs.162.2021.10.20.06.41.43; Wed, 20 Oct 2021 06:42:19 -0700 (PDT) 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; dkim=pass header.i=@alien8.de header.s=dkim header.b=JOKjVeuL; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230072AbhJTNl5 (ORCPT + 99 others); Wed, 20 Oct 2021 09:41:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229639AbhJTNl5 (ORCPT ); Wed, 20 Oct 2021 09:41:57 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D75FFC06161C; Wed, 20 Oct 2021 06:39:42 -0700 (PDT) Received: from zn.tnic (p200300ec2f0db30070b4efa7ef8aef1e.dip0.t-ipconnect.de [IPv6:2003:ec:2f0d:b300:70b4:efa7:ef8a:ef1e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 7316B1EC0570; Wed, 20 Oct 2021 15:39:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1634737180; 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: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=u6CGs01obc8jKPitQtYRdGE87x9sved8yOI/KYoYUvM=; b=JOKjVeuLwqZCuvZ6qwDs2kFiAENVgsfWrC1duhZjVCLqxPZEjspIKzy2GG5wfa9FghK6FD 6BUAIx7wFBudqOs3rEenI/nv4Kfz3muGrf+OpOpJ0AAImqmKIH4NDzPQ/GxHnWgAHMLVXD XyFXHXj5LiYFLCSO/Hl2eW5mrHiQ/d4= Date: Wed, 20 Oct 2021 15:39:38 +0200 From: Borislav Petkov To: Tianyu Lan Cc: Tianyu Lan , kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, kuba@kernel.org, gregkh@linuxfoundation.org, arnd@arndb.de, jroedel@suse.de, brijesh.singh@amd.com, thomas.lendacky@amd.com, pgonda@google.com, akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, rppt@kernel.org, tj@kernel.org, aneesh.kumar@linux.ibm.com, saravanand@fb.com, hannes@cmpxchg.org, rientjes@google.com, michael.h.kelley@microsoft.com, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, vkuznets@redhat.com, konrad.wilk@oracle.com, hch@lst.de, robin.murphy@arm.com, joro@8bytes.org, parri.andrea@gmail.com, dave.hansen@intel.com Subject: Re: [PATCH] x86/sev-es: Expose __sev_es_ghcb_hv_call() to call ghcb hv call out of sev code Message-ID: References: <2772390d-09c1-80c1-082f-225f32eae4aa@gmail.com> <20211020062321.3581158-1-ltykernel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 20, 2021 at 08:39:59PM +0800, Tianyu Lan wrote: > Hyper-V runs paravisor in guest VMPL0 which emulates some functions > (e.g, timer, tsc, serial console and so on) via handling VC exception. > GHCB pages are allocated and set up by the paravisor and report to Linux > guest via MSR register.Hyper-V SEV implementation is unenlightened guest > case which doesn't Linux doesn't handle VC and paravisor in the VMPL0 > handle it. Aha, unenlightened. So why don't you export the original function by doing this (only partial diff to show intent only): --- diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index f1d513897baf..bfe82f58508f 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -125,7 +125,7 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt return ES_VMM_ERROR; } -static enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, +static enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, bool set_ghcb_msr, struct es_em_ctxt *ctxt, u64 exit_code, u64 exit_info_1, u64 exit_info_2) @@ -138,7 +138,14 @@ static enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, ghcb_set_sw_exit_info_1(ghcb, exit_info_1); ghcb_set_sw_exit_info_2(ghcb, exit_info_2); - sev_es_wr_ghcb_msr(__pa(ghcb)); + /* + * Hyper-V unenlightened guests use a paravisor for communicating and + * GHCB pages are being allocated by that paravisor which uses a + * different MSR and protocol. + */ + if (set_ghcb_msr) + sev_es_wr_ghcb_msr(__pa(ghcb)); + VMGEXIT(); return verify_exception_info(ghcb, ctxt); -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette