Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3652263rdh; Mon, 27 Nov 2023 23:02:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfFvnzRW887w02+3AVEMaE1iZ5XrimGQSUCdq7csZdpqDYoUe67N1dSpjuYlgFk3Jy3Y+L X-Received: by 2002:a17:902:bb8c:b0:1cf:a8ef:df8f with SMTP id m12-20020a170902bb8c00b001cfa8efdf8fmr12075986pls.68.1701154935661; Mon, 27 Nov 2023 23:02:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701154935; cv=none; d=google.com; s=arc-20160816; b=yUfI5OvghalQOwraYhjC9EoEmna2kzxdT8ZkqQalonaQT3LNfVGwlrR7YAmPdOAHf1 g6RKY8ilBC4g6ZmXoqdZj6lifhKzJeR6qtlCZnhn3q3fZHX1TRavKLzgRYHRWvUo3fqB PTTZuwC18iEZD0YPcw1NlhY5SirzTnMPetDqOJkChJf6zdEhp9ssau0tVcvTxlh8UouY UHwdwCbTRhUqIdtqoUu9PVV+RLEdzTuREyjueH8tnnUXPRGHWNxwEGgVPkiPUCsv52dF C5Wm3p8pTCAkRX4TyUylOotUb80/BKTwhe+5VAFpqcCy+OijH+KuPT1LGV7JIvNX29KX zYcw== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=TFm09BdRgr9hMTLD1yLTzer1bL4YuNmrnI5hvmqZVZ4=; fh=0JE/s9melwQrHIwHj7I58Itp5rDesgOPWrDm6iWtl/s=; b=gc2d4uvwZFoYEQ35Dpc3oBzhClbzHwU3bFx20XY+km4BCf+fDd2PBHOTeX5OvHTrh8 b0FNgthLGAzDsrR/baLNWkwcpXBxdFhmj71V9QmJjkwinKNrx6CJwe0BRws7M5+RYw6M Gu5ZS0tSEKlznekg8ohhUlxhHY10ZUS3RucYj2GrjUJC7fT9QxjXn2o6/eaEMfpxnIka m6gQorznHdXQJollG87vY3sJDAoc5mg1CI1oa2YkKolwe+40RWCI5bnxiO3EbIUnQag3 Dlmpp6wHjUE7Z3j3Mi7Wvu3sRAlkHZR8B9CBCJVP2CHcfSnswYFzx8fcnpjgFoOS/v83 3RWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TaYW9onr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q102-20020a17090a17ef00b0028547ba201csi11262250pja.78.2023.11.27.23.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 23:02:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TaYW9onr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id DCDB98060CB6; Mon, 27 Nov 2023 23:02:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343688AbjK1HBq (ORCPT + 99 others); Tue, 28 Nov 2023 02:01:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231540AbjK1HBn (ORCPT ); Tue, 28 Nov 2023 02:01:43 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BC8C1AE for ; Mon, 27 Nov 2023 23:01:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701154908; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TFm09BdRgr9hMTLD1yLTzer1bL4YuNmrnI5hvmqZVZ4=; b=TaYW9onre+X4u+pU5istavdZSFc0Lx+VQQgLB8ddfTuiXzJltFNIDsQw5Xc1DHvL/7Ph8T UFshCl2dWN/WUvSUCVCVz3R2CtiE8vlgm8Y9ZMBLX9tDdUd9izEgZfQ9wTfvEF5xA9B668 Q9/smGaj3IDYACVqcXTtisgQlBc4+q8= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-345-hteZO2bRPYGgsdfOreHL5w-1; Tue, 28 Nov 2023 02:01:46 -0500 X-MC-Unique: hteZO2bRPYGgsdfOreHL5w-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-40b3487fa9eso35488065e9.2 for ; Mon, 27 Nov 2023 23:01:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701154905; x=1701759705; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TFm09BdRgr9hMTLD1yLTzer1bL4YuNmrnI5hvmqZVZ4=; b=hkG5pMVPkfftR+TiO0toGpozn1NNqGQdSMywKdLB/ykpGXfCjrPtHk95/f71PIfGVN JKD/ORVMZTSvV5dnyGQatoJkTSZUABdw3mEt7KB5K10Kr23jPd/nwJuPzmFmXKlyM5lM qcQimZVw/PUuHpWGTXi0oZouynh2gFymswqhSmjAEQtCu9T9N4feMy54X5aWnPD/N1fC 7lP3bC2j2sVL74wbMT7+2LpYUjXh6N0Cb9oQ3RA0RJ7ZrHdV19JJj7BBgXlShp+Wqn/i ZZq2xGMMBdxS94/JK5VIRJQWqK0taTUFB5idoVSZ21q7fat0iMbeVi2TUyBg5RPtmCPx 9+lQ== X-Gm-Message-State: AOJu0YzNH9Et3g010Gaggk1gSKHKEPiEVo7bJy91ItQToA99d5BElp7b 89095PNq7/RNyhVuf7w9+cFyAO7Z44sEwFiGmvAVIInNzw5M153trBotUy1mRhkwFCwxnPMHAHf C/+VJtpjpX7oQGb2LYQzwnkHB X-Received: by 2002:a5d:5551:0:b0:332:eaa7:56b1 with SMTP id g17-20020a5d5551000000b00332eaa756b1mr10473120wrw.37.1701154905454; Mon, 27 Nov 2023 23:01:45 -0800 (PST) X-Received: by 2002:a5d:5551:0:b0:332:eaa7:56b1 with SMTP id g17-20020a5d5551000000b00332eaa756b1mr10473106wrw.37.1701154905161; Mon, 27 Nov 2023 23:01:45 -0800 (PST) Received: from starship ([77.137.131.4]) by smtp.gmail.com with ESMTPSA id l12-20020a5d4bcc000000b00332fbc183ebsm6535150wrt.76.2023.11.27.23.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 23:01:44 -0800 (PST) Message-ID: <04a6495330967c74cb6e6e122a634992bb3efa0e.camel@redhat.com> Subject: Re: [RFC 04/33] KVM: x86: hyper-v: Move hypercall page handling into separate function From: Maxim Levitsky To: Nicolas Saenz Julienne , kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, anelkz@amazon.com, graf@amazon.com, dwmw@amazon.co.uk, jgowans@amazon.com, corbert@lwn.net, kys@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com, x86@kernel.org, linux-doc@vger.kernel.org Date: Tue, 28 Nov 2023 09:01:42 +0200 In-Reply-To: <20231108111806.92604-5-nsaenz@amazon.com> References: <20231108111806.92604-1-nsaenz@amazon.com> <20231108111806.92604-5-nsaenz@amazon.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 27 Nov 2023 23:02:08 -0800 (PST) On Wed, 2023-11-08 at 11:17 +0000, Nicolas Saenz Julienne wrote: > The hypercall page patching is about to grow considerably, move it into > its own function. > > No functional change intended. > > Signed-off-by: Nicolas Saenz Julienne > --- > arch/x86/kvm/hyperv.c | 69 ++++++++++++++++++++++++------------------- > 1 file changed, 39 insertions(+), 30 deletions(-) > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > index e1bc861ab3b0..78d053042667 100644 > --- a/arch/x86/kvm/hyperv.c > +++ b/arch/x86/kvm/hyperv.c > @@ -256,6 +256,42 @@ static void synic_exit(struct kvm_vcpu_hv_synic *synic, u32 msr) > kvm_make_request(KVM_REQ_HV_EXIT, vcpu); > } > > +static int patch_hypercall_page(struct kvm_vcpu *vcpu, u64 data) > +{ > + struct kvm *kvm = vcpu->kvm; > + u8 instructions[9]; > + int i = 0; > + u64 addr; > + > + /* > + * If Xen and Hyper-V hypercalls are both enabled, disambiguate > + * the same way Xen itself does, by setting the bit 31 of EAX > + * which is RsvdZ in the 32-bit Hyper-V hypercall ABI and just > + * going to be clobbered on 64-bit. > + */ > + if (kvm_xen_hypercall_enabled(kvm)) { > + /* orl $0x80000000, %eax */ > + instructions[i++] = 0x0d; > + instructions[i++] = 0x00; > + instructions[i++] = 0x00; > + instructions[i++] = 0x00; > + instructions[i++] = 0x80; > + } > + > + /* vmcall/vmmcall */ > + static_call(kvm_x86_patch_hypercall)(vcpu, instructions + i); > + i += 3; > + > + /* ret */ > + ((unsigned char *)instructions)[i++] = 0xc3; > + > + addr = data & HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK; > + if (kvm_vcpu_write_guest(vcpu, addr, instructions, i)) > + return 1; > + > + return 0; > +} > + > static int synic_set_msr(struct kvm_vcpu_hv_synic *synic, > u32 msr, u64 data, bool host) > { > @@ -1338,11 +1374,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data, > if (!hv->hv_guest_os_id) > hv->hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE; > break; > - case HV_X64_MSR_HYPERCALL: { > - u8 instructions[9]; > - int i = 0; > - u64 addr; > - > + case HV_X64_MSR_HYPERCALL: > /* if guest os id is not set hypercall should remain disabled */ > if (!hv->hv_guest_os_id) > break; > @@ -1351,34 +1383,11 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data, > break; > } > > - /* > - * If Xen and Hyper-V hypercalls are both enabled, disambiguate > - * the same way Xen itself does, by setting the bit 31 of EAX > - * which is RsvdZ in the 32-bit Hyper-V hypercall ABI and just > - * going to be clobbered on 64-bit. > - */ > - if (kvm_xen_hypercall_enabled(kvm)) { > - /* orl $0x80000000, %eax */ > - instructions[i++] = 0x0d; > - instructions[i++] = 0x00; > - instructions[i++] = 0x00; > - instructions[i++] = 0x00; > - instructions[i++] = 0x80; > - } > - > - /* vmcall/vmmcall */ > - static_call(kvm_x86_patch_hypercall)(vcpu, instructions + i); > - i += 3; > - > - /* ret */ > - ((unsigned char *)instructions)[i++] = 0xc3; > - > - addr = data & HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK; > - if (kvm_vcpu_write_guest(vcpu, addr, instructions, i)) > + if (patch_hypercall_page(vcpu, data)) > return 1; > + > hv->hv_hypercall = data; > break; > - } > case HV_X64_MSR_REFERENCE_TSC: > hv->hv_tsc_page = data; > if (hv->hv_tsc_page & HV_X64_MSR_TSC_REFERENCE_ENABLE) { This looks like another nice cleanup that can be accepted to the kvm, before the main VTL patch series. Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky