Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp559075rdb; Thu, 15 Feb 2024 08:14:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZ5kVPxu9lSH8R93q48NJy9MEQjrgIdooUVoReKTbsYKLKiZvuyYGropM3+XpVkJpAOgUpwc40Q+dNZ859Vzfdw+Dv4+CV8DFKOTZCiw== X-Google-Smtp-Source: AGHT+IFiQaQpC6s3a9eqXUhsQIjPgx5MmCTou2QGW4mKffeeyQmIzAKC0xXC/qIbJuUc9+suojLc X-Received: by 2002:a05:6a21:3116:b0:19e:378a:124c with SMTP id yz22-20020a056a21311600b0019e378a124cmr2643945pzb.12.1708013667309; Thu, 15 Feb 2024 08:14:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708013667; cv=pass; d=google.com; s=arc-20160816; b=kkHBcKIJGo24ocBR61o5B98RSX+kC7CG/iZa+5vm/YD3FsIxQy/+Gf4nUsy1gwCZuR JuDUsIFFlkhiLRprA/5HRmjJCkA9o6f01oFagULTKnaGcV9+akBgu+S61ENaC1npoEcZ w4Fll3sVET3MsSa/Mg2Ng4zsXQ8+Pbq9IpRD50D46QOGvcD3j/MVMojKRY+O+8iDc712 qOKPiF5Yrv9B7ve8JRUwr1nikNzbzgfWwa0m1Afs/QmcOx5qIAQTZYr/G5OA3698/rll ecYGFHh4fVim0oTdWQGoX6pYaUPb9QjyDByVmPixSest5efmp3PKT/m2wgTx3kvmRvnU FPaQ== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67225-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l62-20020a638841000000b005d64d951c89si1337102pgd.143.2024.02.15.08.14.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 08:14:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67225-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 383C0B2CC5E for ; Thu, 15 Feb 2024 15:45:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F95F1350CC; Thu, 15 Feb 2024 15:44:36 +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 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 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 -- 2.39.2