Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp522134rdb; Mon, 15 Jan 2024 05:11:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBXTVy1HcIu6QnGm0tEV5iQhmwjT8zyN3X+qeaCKULdF5g/1DukbHkgKMOZNF9QkdFWS9K X-Received: by 2002:a05:6512:2316:b0:50e:ab15:724f with SMTP id o22-20020a056512231600b0050eab15724fmr2124971lfu.98.1705324309906; Mon, 15 Jan 2024 05:11:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705324309; cv=none; d=google.com; s=arc-20160816; b=x+MX1pE4A3J32YX5I7VtA29w1mAnXwAd5GQ8LUBwjXFPCaBSDTuPFw15U83/PJYG/L 6Xz2FY3Wsn8JewgDW6kCc6TxEUaPvXkbRoZQEBfr0AH6dqS3hz7upTAi6IjxdMoGeEZJ +Z41Qt0zdrZ61B6L/GWGhgF0lxscMM7eEVYyvXQfAVtCGGmbaYhL1aTt/ch4vLzjC4Il XRToMfCYctnQH/sQj2Vbu0BWDUYhPg/H8eN8WpWdzMEJ5eTl1CHda7x0xYs/TBtAQiLS huzdpM4nI/je1FzEOzkcTPMbW3wZO0mWSONwYiLgrnbpG2uZVOs/du6VY0cAI2LUDSCm xIQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=TGoYbz9rXouSd9WFL4ciI9FwoKQtj7ZUq9cOLPJ0RRg=; fh=aAPqvXm40pY9772UiBOljEePwtz/3Q0zIOpw238tj3M=; b=MNswJVLf2/xltfZAiBZ4MVW53X9qc8YCa8zOL/yZox8egz3za732J2TlaQbp2vAuk4 51uk8kRDkslrtRlLrN64XNimVJXkLD7tSsbhWKyWTof7em42t7K95hr3nV1+lrhZVE/j EqJoWE5E3fwy9i3dvgvQcvXeoG55I06FckX7CsXMlx2NJtyUuSMPvuU0vnVC0tptjfuh 7Ka8Gw3dYu/mr0yJby1rUhyhRWfF5drDcePXDp/hvyaFKSnXe/QmZkPX4qxKdjtOgYBx LEEMHGfsD9pzct2DfWjS0QNUi0Tc9D8/UTx860hlmkX7PXLQnF0X9iY01qr4U5cxB2Wy RZ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=MHrFpF5I; spf=pass (google.com: domain of linux-kernel+bounces-26003-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26003-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ov12-20020a170906fc0c00b00a27d992a6d6si3686005ejb.610.2024.01.15.05.11.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 05:11:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26003-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=MHrFpF5I; spf=pass (google.com: domain of linux-kernel+bounces-26003-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26003-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A48B41F22038 for ; Mon, 15 Jan 2024 13:11:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1613917BC2; Mon, 15 Jan 2024 13:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="MHrFpF5I" Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2CD7175A5; Mon, 15 Jan 2024 13:09:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen.org 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=TGoYbz9rXouSd9WFL4ciI9FwoKQtj7ZUq9cOLPJ0RRg=; b=MHrFpF5IJ+PfFQlCE294QZkLS7 j1/pDVM5hSybbNPSM6bz27B/hEc8rQyVvvivfowOtblwXmtVBmpjhVNlW+rsILZE79dR237K3WYe4 sWL/GJ3zw5LqApPZ60YVEe5o0HHNWZ/i5HLLuN8wc99AFrvl6Mtrl/xbbb4PtGW9BywY=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPMiY-00035c-L6; Mon, 15 Jan 2024 13:09:30 +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 1rPMXN-0002kM-4Y; Mon, 15 Jan 2024 12:57:57 +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 v12 10/20] KVM: xen: re-initialize shared_info if guest (32/64-bit) mode is set Date: Mon, 15 Jan 2024 12:56:57 +0000 Message-Id: <20240115125707.1183-11-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240115125707.1183-1-paul@xen.org> References: <20240115125707.1183-1-paul@xen.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 v12: - Fix missing update of return value if mode is not actually changed. v11: - Drop the hunk removing the call to kvm_xen_shared_info_init() when KVM_XEN_ATTR_TYPE_SHARED_INFO is set; it was a mistake and causes self- test failures. v10: - New in this version. --- arch/x86/kvm/xen.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index df53fea73747..d595d476a5b3 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -625,8 +625,16 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) } else { mutex_lock(&kvm->arch.xen.xen_lock); kvm->arch.xen.long_mode = !!data->u.long_mode; + + /* + * Re-initialize shared_info to put the wallclock in the + * correct place. Whilst it's not necessary to do this + * unless the mode is actually changed, it does no harm + * to make the call anyway. + */ + r = kvm->arch.xen.shinfo_cache.active ? + kvm_xen_shared_info_init(kvm) : 0; mutex_unlock(&kvm->arch.xen.xen_lock); - r = 0; } break; @@ -1101,9 +1109,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 -- 2.39.2