From patchwork Mon Dec 4 14:43:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 173429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2819268vqy; Mon, 4 Dec 2023 07:01:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7yJofEHJUNIK5xjjX0zSlnxagy6j4OkFomhHhQ5FCWtltaZTN2vtPmlVUb3dEua5+EDsL X-Received: by 2002:a05:6808:1708:b0:3b8:b063:5d75 with SMTP id bc8-20020a056808170800b003b8b0635d75mr4923326oib.92.1701702078941; Mon, 04 Dec 2023 07:01:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701702078; cv=none; d=google.com; s=arc-20160816; b=sdtV2FSbSBDhLCtLl0cNQ+RB/g3+vp5rXKYez1ze9fqO/R47IzCiQa/mXayB75FSAV MVGX+BRXXHzIQKT9c9AsT9FWEXKx4VTVfUQ96/EKunis2nL+UZbopQjVA9QNfW+44Awg 2qr+GppCv8L2KPeMoV1QhTpJqYvF5pJhbd/F4bXNG69N7TQtN9j8uuA2LdGgK0DTMhXK UfdRSaVhYxsjLzWHIpLB4/8SNHDSmZ+68wYvygSMl5+hI4qzqCDa/KF6ZoQRDziRmR1P d0faQ2U0WnxjIdi8OLWSsU5RsyHZcwvL5vldKNO8Q+IATztBqhI2iguEYDACcalyU4fa Il7w== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Xrs5wM6gBETIHeYh3Xm5diocfhQBioljk8lQV33tdj0=; fh=aAPqvXm40pY9772UiBOljEePwtz/3Q0zIOpw238tj3M=; b=E4TnDnma3sUXNnFKXdgbdPSh2nvrg03tQFV2oZ0bTuBX/lH1LuJioEutY7mnjSqzzo TKB0i1rA21vCSvBS/KQi8ga64D8Idl4W5LZqurNnaYjNmRDBAN/0F8blyXSLjKrSHnWF knj+RzkXCR6KAk09OX9NCSc1G6InPmN59+XcV+CAZISnAAnxxoUeYLx7nRiaHoNvJClN Ksazc8kHceg79yCCU+UcDJ+4DiuEtYAZm+BC7bgjbJ/9zBLX3TYyBw4TqDOzHWN002s/ S9iNM1ImSFeFxO7a5Cs9Igzm1aX/mC8sErn8S8dVsrQSIX5iTjA5j8FtHBSTk/M1VAIs ogjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=aAdU8jXl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id z17-20020a544591000000b003ae50bac8c4si3066982oib.246.2023.12.04.07.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 07:01:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=aAdU8jXl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1E0C68078301; Mon, 4 Dec 2023 07:01:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233869AbjLDPBA (ORCPT + 99 others); Mon, 4 Dec 2023 10:01:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233705AbjLDPA0 (ORCPT ); Mon, 4 Dec 2023 10:00:26 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86FAFB9; Mon, 4 Dec 2023 07:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:To:From; bh=Xrs5wM6gBETIHeYh3Xm5diocfhQBioljk8lQV33tdj0=; b=aAdU8jXlc+qOGuZ35FRaNzkHxt 8NOpVXOoEM5QqGRzNfJwfz4qdyYvqM3hWnG3IT51xhRREY0h2EZPgc2Ncn1ziUlWV+yNHbJmG2qmc 8OQ1u4lMWQmFMGUYjFu0q4FRtsjByD8QUZt3BOHxor7O0hUgDIhUCyb0aGhXrWSktFto=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rAAQk-00043f-PF; Mon, 04 Dec 2023 15:00:18 +0000 Received: from 54-240-197-231.amazon.com ([54.240.197.231] helo=REM-PW02S00X.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rAABG-00088g-2j; Mon, 04 Dec 2023 14:44:18 +0000 From: Paul Durrant To: Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , David Woodhouse , Paul Durrant , Shuah Khan , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v10 10/19] KVM: xen: (re-)initialize shared_info if guest (32/64-bit) mode is set Date: Mon, 4 Dec 2023 14:43:25 +0000 Message-Id: <20231204144334.910-11-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231204144334.910-1-paul@xen.org> References: <20231204144334.910-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 04 Dec 2023 07:01:11 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784363958866505883 X-GMAIL-MSGID: 1784363958866505883 From: Paul Durrant If the shared_info PFN cache has already been initialized then the content of the shared_info page needs to be (re-)initialized whenever the guest mode is (re)set. Setting the guest mode is either done explicitly by the VMM via the KVM_XEN_ATTR_TYPE_LONG_MODE attribute, or implicitly when the guest writes the MSR to set up the hypercall page. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: David Woodhouse Cc: x86@kernel.org v10: - New in this version. --- arch/x86/kvm/xen.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 9351b32cfcba..3aa452a71890 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -623,10 +623,20 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) if (!IS_ENABLED(CONFIG_64BIT) && data->u.long_mode) { r = -EINVAL; } else { + bool lm = !!data->u.long_mode; + mutex_lock(&kvm->arch.xen.xen_lock); - kvm->arch.xen.long_mode = !!data->u.long_mode; + if (kvm->arch.xen.long_mode != lm) { + kvm->arch.xen.long_mode = lm; + + /* + * Re-initialize shared_info to put the wallclock in the + * correct place. + */ + r = kvm->arch.xen.shinfo_cache.active ? + kvm_xen_shared_info_init(kvm) : 0; + } mutex_unlock(&kvm->arch.xen.xen_lock); - r = 0; } break; @@ -648,9 +658,6 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) srcu_read_unlock(&kvm->srcu, idx); - if (!r && kvm->arch.xen.shinfo_cache.active) - r = kvm_xen_shared_info_init(kvm); - mutex_unlock(&kvm->arch.xen.xen_lock); break; } @@ -1101,9 +1108,24 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data) u32 page_num = data & ~PAGE_MASK; u64 page_addr = data & PAGE_MASK; bool lm = is_long_mode(vcpu); + int r = 0; + + mutex_lock(&kvm->arch.xen.xen_lock); + if (kvm->arch.xen.long_mode != lm) { + kvm->arch.xen.long_mode = lm; + + /* + * Re-initialize shared_info to put the wallclock in the + * correct place. + */ + if (kvm->arch.xen.shinfo_cache.active && + kvm_xen_shared_info_init(kvm)) + r = 1; + } + mutex_unlock(&kvm->arch.xen.xen_lock); - /* Latch long_mode for shared_info pages etc. */ - vcpu->kvm->arch.xen.long_mode = lm; + if (r) + return r; /* * If Xen hypercall intercept is enabled, fill the hypercall