Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1582474pxy; Mon, 2 Aug 2021 05:32:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybmt79rkBQ15qCLaU50G0ooLpFFYSF4E/0kjZLv50nU4oTIpj/5gwKBBoogb6EAS/k3Kw0 X-Received: by 2002:a17:906:af02:: with SMTP id lx2mr14896355ejb.133.1627907559376; Mon, 02 Aug 2021 05:32:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627907559; cv=none; d=google.com; s=arc-20160816; b=Pdm7TwfNC8kysy6+LX6z/NqLd696esUzddLcPxWXoL8Rt+45Wb1QZ6rOJqc+26Ak73 PGjdaCA1YzUiHaEW/sRbcgoCuZ9rZfTs4snRxxRknFouP+PAT6zyYEsRiCp0BRlDotTi 4Wumvs2hYK+6j1UdBO329XzoKK0inPbRSNaxO7UrxAxFyZiwap1evNPTMbEyH3ZeEAz0 P4g38eZqRYnQ8qeAqh2mfd459ktxgcaTAGMTnr+bQbPjauG4IjsSOiG2V6pauLUc7fQT JwVKhMMUE42mc3g/ZoyvV+cMpZuhKJkYn/IWwsZeLie16BfJ/RcKr7+RgHlBMB5E6hH0 l3wA== 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; bh=anMVoI6dzS8fhlpxRVMXFZxo4TWjnRltdha3PogXGBs=; b=gAiZmm9hyddd/fWpoFDd8j7lS6EPJyJgcpjq8eD5wT6/TdKCF3UrN/Cklupoqc+JSf iNiUbx9A4CqMI8KWVoOm+nba9MQdDt09t05tJXlFlNuHSVaIz03vnWxXfPo/QjMLQyNo uOvz/HEZjGDtH2jlpQnMhVlW6E4XRs4A0vaMEgzlnhYSwF1Rz42wK58X6pJ1C0kyy+AG ijy09Whz4PfjP1qW+cMdvmEjHgoq4Riam3i86vR6mcdQOycOBZ9KH3vugtFk/9Ib3Lzs Rw8+njulBewPC9jV6CaV9QDlcpxMl6Ybuc9gDO8KK7yxuz+i3GuOFNnWWi5s21hklREI HpOQ== 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n15si10196007ejd.124.2021.08.02.05.32.13; Mon, 02 Aug 2021 05:32:39 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233622AbhHBM2z (ORCPT + 99 others); Mon, 2 Aug 2021 08:28:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233498AbhHBM2z (ORCPT ); Mon, 2 Aug 2021 08:28:55 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB989C06175F; Mon, 2 Aug 2021 05:28:45 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id 3FDE620C; Mon, 2 Aug 2021 14:28:42 +0200 (CEST) Date: Mon, 2 Aug 2021 14:28:36 +0200 From: Joerg Roedel To: Tianyu Lan Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, will@kernel.org, davem@davemloft.net, kuba@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, ardb@kernel.org, Tianyu.Lan@microsoft.com, rientjes@google.com, martin.b.radev@gmail.com, akpm@linux-foundation.org, rppt@kernel.org, kirill.shutemov@linux.intel.com, aneesh.kumar@linux.ibm.com, krish.sadhukhan@oracle.com, saravanand@fb.com, xen-devel@lists.xenproject.org, pgonda@google.com, david@redhat.com, keescook@chromium.org, hannes@cmpxchg.org, sfr@canb.auug.org.au, michael.h.kelley@microsoft.com, iommu@lists.linux-foundation.org, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, netdev@vger.kernel.org, vkuznets@redhat.com, anparri@microsoft.com Subject: Re: [PATCH 05/13] HV: Add Write/Read MSR registers via ghcb page Message-ID: References: <20210728145232.285861-1-ltykernel@gmail.com> <20210728145232.285861-6-ltykernel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210728145232.285861-6-ltykernel@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 28, 2021 at 10:52:20AM -0400, Tianyu Lan wrote: > +void hv_ghcb_msr_write(u64 msr, u64 value) > +{ > + union hv_ghcb *hv_ghcb; > + void **ghcb_base; > + unsigned long flags; > + > + if (!ms_hyperv.ghcb_base) > + return; > + > + WARN_ON(in_nmi()); > + > + local_irq_save(flags); > + ghcb_base = (void **)this_cpu_ptr(ms_hyperv.ghcb_base); > + hv_ghcb = (union hv_ghcb *)*ghcb_base; > + if (!hv_ghcb) { > + local_irq_restore(flags); > + return; > + } > + > + memset(hv_ghcb, 0x00, HV_HYP_PAGE_SIZE); Do you really need to zero out the whole 4k? The validation bitmap should be enough, there are no secrets on the page anyway. Same in hv_ghcb_msr_read(). > +enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, > + struct es_em_ctxt *ctxt, > + u64 exit_code, u64 exit_info_1, > + u64 exit_info_2) > { > enum es_result ret; > > @@ -109,7 +109,16 @@ 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 runs paravisor with SEV. Ghcb page is allocated by > + * paravisor and not needs to be updated in the Linux guest. > + * Otherwise, the ghcb page's PA reported by paravisor is above > + * VTOM. Hyper-V use this function with NULL for ctxt point and > + * skip setting ghcb page in such case. > + */ > + if (ctxt) > + sev_es_wr_ghcb_msr(__pa(ghcb)); No, do not make this function work with ctxt==NULL. Instead, factor out a helper function which contains what Hyper-V needs and use that in sev_es_ghcb_hv_call() and Hyper-V code. > +union hv_ghcb { > + struct ghcb ghcb; > +} __packed __aligned(PAGE_SIZE); I am curious what this will end up being good for.