From patchwork Thu Feb 15 15:29:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 201585 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp489263dyb; Thu, 15 Feb 2024 07:49:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUbFZJ5pFQaKoBauReI8l2Qwhqbq+RZbJ9QLkOGOXQDRbP1DGAyC4pnjA9WIX9PrhuVjvFVofg58FNdFFVt6bF43D2FLg== X-Google-Smtp-Source: AGHT+IE6IRpEzt2q19G/leXmFqNR4yWj9+JbAMZMyDET4MaQqCHNqrhWIELZQkIpzGocyQzNvWyN X-Received: by 2002:a17:906:4e93:b0:a3c:f8df:970c with SMTP id v19-20020a1709064e9300b00a3cf8df970cmr1558378eju.0.1708012149339; Thu, 15 Feb 2024 07:49:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708012149; cv=pass; d=google.com; s=arc-20160816; b=fYu1C2qkFkcHlVJhycvnYex4pL0w+QOaJftEBf5+M6Jav/a5rHEXImqHQf9RTotRHb 09H7/8pLTDs8Py/9TXDvlYzjrY8LeItoUfZc+7v3YjQ9tVLWFavnAydkY4WEuwuwdo66 5yTfuhUogvMwrz1cizgJ9w9nqzbR3yHJ/wqSsYLOJqYkfmi78UHsTD67oxQcnFrUpR09 2Gx4+7t3Q+t2+L0sIDPZ3N3kcHi7Gt1YTKvwHPBOu7Z+jjkaPaIzcqduyGxED8D+oMro gbPprR0gvIindiFZBaFKrHvb9qDM27m+egE7V7WhuOOXmRxAZ551tUkrg3j/q2QS4aIs WvJw== ARC-Message-Signature: i=2; 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=u1ta1r3MgQVT6Oph1GwmQKSncCtReBnCTMzpKGY3caE=; fh=NrOggL3VZvuSFh5W9Wj2+kLgS4v0nogfnAWvBJoouXQ=; b=kcU/zBFyZbHfjgaU+ekSCEhF7k83DY2jcO5kyHSmx+OiykEWsiLuGgrya4LIQpq7h7 ygCHA21X4hNUx6ZfxbTubqCmMe4PZAG2/CtmF4KCQOdXs3LYEuNB8tacMsSx6QnSZ5Dp vAoRhj4nJ1CjCm2/qMrlnl4dhmuHf9w/p3fB1Hcojke+6j/EU/wsjveZUybF3w10b8eX BesFyFrKfOdO5CrHKrrZNzKQD02Yg+a2jd0hPdK7RmG8C5NWuvD9trviZfu/FKxr2jq9 cv5HzFka9lh3hJMzAada2aBkAKwSf+3Q6S2SjytLbKu6nOV7OoGjgzvXaVYRn6Cgbjuy 4AeA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=Jc2hqxeY; arc=pass (i=1 spf=pass spfdomain=xen.org dkim=pass dkdomain=xen.org); spf=pass (google.com: domain of linux-kernel+bounces-67225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67225-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ks23-20020a170906f85700b00a3d18b8d389si736316ejb.316.2024.02.15.07.49.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 07:49:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67225-ouuuleilei=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=Jc2hqxeY; arc=pass (i=1 spf=pass spfdomain=xen.org dkim=pass dkdomain=xen.org); spf=pass (google.com: domain of linux-kernel+bounces-67225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67225-ouuuleilei=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 8B1281F26739 for ; Thu, 15 Feb 2024 15:47:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FB5113666F; Thu, 15 Feb 2024 15:44:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="Jc2hqxeY" 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 A5B8F1339A7; Thu, 15 Feb 2024 15:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.130.215.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708011875; cv=none; b=uMccoE3SZwGNdErtcneUGkP5ziqBrICkDHYDsthZTETBoQWcMiYovu/5PQ02VB2HVedJpzVNP59EOmgHWb/X9s/QBk5UBt/iQyzHNltIfm9PSmjfY290X4JkDorMcL9w9+uP8JETBaIg1kGyz1KN0jfr6Qs/Res7GEkVzzMEhxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708011875; c=relaxed/simple; bh=3nwQ4igr4UHRdd+mgY7ZbOjy+y4K9Nat1gWNqM16aB8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nca0ZDH8udxCz4QT9uxNLUgIShDVjD31CBCqpbOOMnKhNgPpYPVxza31r6QaOtdIeGSrg3axggLHYuNPSWY4Ii3izeW3zkzuwu/UokF++2TtDtJKTOSAiCA1Hk0tGpYtO0F4TgbfuWUl/ewP+EE7IgscvL5VdeWCJLoQdwweRqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org; spf=pass smtp.mailfrom=xen.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b=Jc2hqxeY; arc=none smtp.client-ip=104.130.215.37 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=u1ta1r3MgQVT6Oph1GwmQKSncCtReBnCTMzpKGY3caE=; b=Jc2hqxeYDCBWgsreGCBjXM/BIw j3AlGYlS8zaYcO9vrzgZcdhd4yFQyqqqKWDMgPfjAH2z/zUH4BDoBgSRfyeg6KT6/v3xhgyO4FR4J zB4Cd97gfEFp79HEsvtCEnyOjNyxzYi4BK+ndLvD/Y/xpRJv3eg5OcVL2TuWQ2aeXQLA=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raduM-0001WS-3G; Thu, 15 Feb 2024 15:44:18 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] 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 1radhA-00089r-9J; Thu, 15 Feb 2024 15:30:40 +0000 From: Paul Durrant To: Paolo Bonzini , Jonathan Corbet , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , 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-s390@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v13 11/21] KVM: x86/xen: re-initialize shared_info if guest (32/64-bit) mode is set Date: Thu, 15 Feb 2024 15:29:06 +0000 Message-Id: <20240215152916.1158-12-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215152916.1158-1-paul@xen.org> References: <20240215152916.1158-1-paul@xen.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790980547662788783 X-GMAIL-MSGID: 1790980547662788783 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 v13: - Patch title change. 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 031e98d88ba2..52edf676c471 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