Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2832791pxk; Tue, 15 Sep 2020 03:38:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDiK9ou4d7P1+4FzmuqXtVW2u/Y0Hj8AuTEn4ciOmdNEzKv+h8HEsTFwlpwQWSoN74mHVk X-Received: by 2002:a17:906:b04a:: with SMTP id bj10mr19219307ejb.303.1600166313731; Tue, 15 Sep 2020 03:38:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600166313; cv=none; d=google.com; s=arc-20160816; b=UhUBBmvvLMU0gm1imwWOYzTo6PwQJ7miYcPxFKYiOMKcAY8RCIyZwMRXlkdo7goLgk MUOJR8jQofNe3vqG1g4bWfz5eIgJINSdRINZHtXR5tXOv4hIpQq3+Hw4ePkPhnDY6x5v pwAabXB3xf58bs+U1YM5QDvJP9hO2SQVkezeQw8mYUojgnUah8+3OkHj1qz5BX12Qq9u 8LKglcjN+DnsykCBH1hhnID1mMJhqeEln/ebvokCEA3RoOsYaoZG5SSygl/XvT+TjfCy 3kOwN8T67l7eRnDKwHlsfPDkjullTzL3axFYjegBlHZ3GqXsIvYU9PmvOBdh3xXNTBc1 3dkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=h0FEvhe81Rt7AJ2NQ20nZUIPRKHUuLpPLW8xH6sCpcw=; b=Du1zDePojx1Qy8t4iFM4KHsKxy2PdHctd68dUPBRL2CIlpQI7vcZ4/Z5F2RkURvzZL UZfQFXZaM9npNFfHsOSeTvplJuWHtadkKTZmsYmFwR8UV1q7EzezpYybejRAuJaoilf+ UWSms5zYdTia4jPosVZq5+8k+k9pKKjKbqWfhLODzT+pEY+Ucg69atba40wv2xYiq70g /QxAdCN2iGd3SIVwUlwPCM4PC74zlcW0KuGcIJXmif2TDv6JKCLbSWCvsMGACUkhcNF9 BMOv7kD3LcrjRJENq/vYOMMNz2+XLg5b4cGZ8z1XKsZYBV5ecmUZiVKUSsI2rWvo3ca6 qdLA== 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 mj21si8964010ejb.271.2020.09.15.03.38.11; Tue, 15 Sep 2020 03:38:33 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726304AbgIOKh0 (ORCPT + 99 others); Tue, 15 Sep 2020 06:37:26 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54885 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726095AbgIOKhO (ORCPT ); Tue, 15 Sep 2020 06:37:14 -0400 Received: by mail-wm1-f68.google.com with SMTP id s13so2841294wmh.4; Tue, 15 Sep 2020 03:37:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=h0FEvhe81Rt7AJ2NQ20nZUIPRKHUuLpPLW8xH6sCpcw=; b=hfRgbSGlk9jJV5G7YD2Dh6pfhkj5DAM5FZabKqOxqI1gYlYKvO3db9c1pNh98SvaQf nwQY9pq1rQ8uFDJFML4upMSBP0FDGrYutOx2NYB2xUsthgXNsb+HONA+H94iRbuQBVIq HBKp2YnZf9yiFO1zhYcJhIabpISYX4DKdjfSlxyvDpBp2wTh4j+Cz3mNDY8a99yII1xX TDJuWfZV2sOA6B+PK980+AGD/oKHsJZ6xl/Bg/Fs1P7xIYnU4S20gwr6dIbM1+9P0Sbg HVyCov59JTijbxfzRyPWIZMqHceIApWanUfyxgRJK2gGfXyTg+hJFVCRAkDx5rHq2dBd DHGA== X-Gm-Message-State: AOAM532fEeNGYxj1Tkj1zk9lbRYISwSb9N71xKRsUQzqktx6TJIb05Dy XZvZH+8J/lyjllpSHdCzjRg= X-Received: by 2002:a1c:2b43:: with SMTP id r64mr3863166wmr.164.1600166231873; Tue, 15 Sep 2020 03:37:11 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id g12sm25361404wro.89.2020.09.15.03.37.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 03:37:11 -0700 (PDT) Date: Tue, 15 Sep 2020 10:37:10 +0000 From: Wei Liu To: Vitaly Kuznetsov Cc: Wei Liu , Linux on Hyper-V List , virtualization@lists.linux-foundation.org, Linux Kernel List , Michael Kelley , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , Lillian Grassin-Drake , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" Subject: Re: [PATCH RFC v1 08/18] x86/hyperv: handling hypercall page setup for root Message-ID: <20200915103710.cqmdvzh5lys4wsqo@liuwe-devbox-debian-v2> References: <20200914112802.80611-1-wei.liu@kernel.org> <20200914112802.80611-9-wei.liu@kernel.org> <87v9gfjpoi.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87v9gfjpoi.fsf@vitty.brq.redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 15, 2020 at 12:32:29PM +0200, Vitaly Kuznetsov wrote: > Wei Liu writes: > > > When Linux is running as the root partition, the hypercall page will > > have already been setup by Hyper-V. Copy the content over to the > > allocated page. > > And we can't setup a new hypercall page by writing something different > to HV_X64_MSR_HYPERCALL, right? > My understanding is that we can't, but Sunil can maybe correct me. > > > > The suspend, resume and cleanup paths remain untouched because they are > > not supported in this setup yet. > > > > Signed-off-by: Lillian Grassin-Drake > > Signed-off-by: Sunil Muthuswamy > > Signed-off-by: Nuno Das Neves > > Co-Developed-by: Lillian Grassin-Drake > > Co-Developed-by: Sunil Muthuswamy > > Co-Developed-by: Nuno Das Neves > > Signed-off-by: Wei Liu > > --- > > arch/x86/hyperv/hv_init.c | 26 ++++++++++++++++++++++++-- > > 1 file changed, 24 insertions(+), 2 deletions(-) > > > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > > index 0eec1ed32023..26233aebc86c 100644 > > --- a/arch/x86/hyperv/hv_init.c > > +++ b/arch/x86/hyperv/hv_init.c > > @@ -25,6 +25,7 @@ > > #include > > #include > > #include > > +#include > > > > /* Is Linux running as the root partition? */ > > bool hv_root_partition; > > @@ -448,8 +449,29 @@ void __init hyperv_init(void) > > > > rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > > hypercall_msr.enable = 1; > > - hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg); > > - wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > > + > > + if (hv_root_partition) { > > + struct page *pg; > > + void *src, *dst; > > + > > + /* > > + * Order is important here. We must enable the hypercall page > > + * so it is populated with code, then copy the code to an > > + * executable page. > > + */ > > + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > > + > > + pg = vmalloc_to_page(hv_hypercall_pg); > > + dst = kmap(pg); > > + src = memremap(hypercall_msr.guest_physical_address << PAGE_SHIFT, PAGE_SIZE, > > + MEMREMAP_WB); > > memremap() can fail... And we don't care here, if it fails, we would rather it panic or oops. I was relying on the fact that copying from / to a NULL pointer will cause the kernel to crash. But of course it wouldn't hurt to explicitly panic here. > > > + memcpy(dst, src, PAGE_SIZE); > > + memunmap(src); > > + kunmap(pg); > > + } else { > > + hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg); > > + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > > + } > > Why can't we do wrmsrl() for both cases here? > Because the hypercall page has already been set up when Linux is the root. I could've tried writing to the MSR again, but because the behaviour here is not documented and subject to change so I didn't bother trying. Wei. > > > > /* > > * Ignore any errors in setting up stimer clockevents > > -- > Vitaly >