From patchwork Thu Sep 14 08:49:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 139451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp215398vqi; Thu, 14 Sep 2023 02:14:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHf+qH3J0sGDa00JDHA4FQ25i58L+SMVXiZZ/0lz3Fk7Gi02tLLZzZ5C8thvHmrq5vI/kQ1 X-Received: by 2002:a05:6871:1d2:b0:1b0:189c:87a0 with SMTP id q18-20020a05687101d200b001b0189c87a0mr5540205oad.41.1694682896144; Thu, 14 Sep 2023 02:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694682896; cv=none; d=google.com; s=arc-20160816; b=kFzFj52aRUsWSIGYqbZMP2NNA+sjezv4wVE9tLEaYf/yQS/sVPWSYYRpvp753yin/w +oSNwXLjB0385WblRJHwTnbFnt0kZJDHITq7TcOOm9DubLwaJiASCHPVTyC3n1pV5YWV kSAPsgGoYRKhYHpSYPB2umPtx7cBX9euMU8BWfmhmFRUZjS/9P8Relp/a41jDv9kmGk6 O08Sm6AY1BEjjdZar3JlU5UyzlLJjCmOgQUiKFpQkTz1LeXlOEH6oGuBBunw5Nfy5N// fZxnyTkVd3VZg1sTGuKrOA7mzXrPIwfpseOGq2sAAripx6zcfP8vD3phzQ9RTmmt/xZM 2rfQ== 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:cc:to:from :dkim-signature; bh=b1ozqveOAFRuO/wOLzb/wpotEM9GW9TMSEMYXUlq+eo=; fh=Pw8ME2ioat+0rO24kCOjPSzdtMZ7IXXfoe/kHVOMV8g=; b=qA+8LMX0dNtShYaT32T9WkKnT4vSizXFiFj58Y62Ty10csEPdJl0cnTTkXmI5VwOVV 74SNK1J6ZGkB7SqoYc5qFLx99AAvP5KHp2AXiVMpyq9lJ/9ZEI2xCvVQjHWo9W0s0w9G OYFs/YkRCeTEmYVvd5Q5cTZnUZUJQw5ConD9Uo2jVYuuc5hfQ4jjZXj4SmRHAoSTCk6E L/yciPWWg0Cnei59PzocWLrW4uLcthgaQmVAj4rLWTt67+/uRk8WDGlYaxTmRWSQvN8o BWJSKnLaiYc4Z83ifVESOKJst9eRCEU9+m8RZt+qyhwyCEGLJLfqUF4WvoReDfS90hnw orgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=seWWyEIT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bv127-20020a632e85000000b00574024ad981si1056027pgb.660.2023.09.14.02.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 02:14:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=seWWyEIT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 8ECB581DDD35; Thu, 14 Sep 2023 02:08:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237027AbjINJH0 (ORCPT + 35 others); Thu, 14 Sep 2023 05:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237134AbjINJHQ (ORCPT ); Thu, 14 Sep 2023 05:07:16 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DFF11BF9; Thu, 14 Sep 2023 02:07:12 -0700 (PDT) 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:Cc:To:From; bh=b1ozqveOAFRuO/wOLzb/wpotEM9GW9TMSEMYXUlq+eo=; b=seWWyEITPDYjae4Nj30M50y4M3 HgTVvcdf04i37rSRTFWMkg+p4yMK7DRpKb4KtFf9Rn+ngHcUlgmr2q7D7K6DcHk2poBFQ5LmL/5eX hBBLHHZBCV+EQ/Hfu4hn0bVQYXXl/tGGqcQQi17tMebimnVGwgqnAXFMzPf1E7p/QWqg=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qgi3O-0001kl-Rt; Thu, 14 Sep 2023 08:50:26 +0000 Received: from ec2-63-33-11-17.eu-west-1.compute.amazonaws.com ([63.33.11.17] 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 1qgi3O-0002T9-Ij; Thu, 14 Sep 2023 08:50:26 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , David Woodhouse , x86@kernel.org Subject: [PATCH 8/8] KVM: xen: automatically use the vcpu_info embedded in shared_info Date: Thu, 14 Sep 2023 08:49:46 +0000 Message-Id: <20230914084946.200043-9-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230914084946.200043-1-paul@xen.org> References: <20230914084946.200043-1-paul@xen.org> MIME-Version: 1.0 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 (lipwig.vger.email [0.0.0.0]); Thu, 14 Sep 2023 02:08:04 -0700 (PDT) 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777003812561301745 X-GMAIL-MSGID: 1777003812561301745 From: Paul Durrant Add a KVM_XEN_HVM_CONFIG_DEFAULT_VCPU_INFO flag so that the VMM knows it need only set the KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO attribute in response to a VCPUOP_register_vcpu_info hypercall, and modify get_vcpu_info_cache() to pass back a pointer to the shared info pfn cache (and appropriate offset) for any of the first 32 vCPUs if the attribute has not been set. Signed-off-by: Paul Durrant --- 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 --- arch/x86/kvm/x86.c | 3 ++- arch/x86/kvm/xen.c | 15 +++++++++++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4cd577d01bc4..cdce8c463a1b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4528,7 +4528,8 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) KVM_XEN_HVM_CONFIG_SHARED_INFO | KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL | KVM_XEN_HVM_CONFIG_EVTCHN_SEND | - KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA; + KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA | + KVM_XEN_HVM_CONFIG_DEFAULT_VCPU_INFO; if (sched_info_on()) r |= KVM_XEN_HVM_CONFIG_RUNSTATE | KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG; diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 892563fea40f..66050a96ba25 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -491,6 +491,21 @@ static void kvm_xen_inject_vcpu_vector(struct kvm_vcpu *v) struct gfn_to_pfn_cache *get_vcpu_info_cache(struct kvm_vcpu *v, unsigned long *offset) { + if (!v->arch.xen.vcpu_info_cache.active && v->arch.xen.vcpu_id < MAX_VIRT_CPUS) { + struct kvm *kvm = v->kvm; + + if (offset) { + if (IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode) + *offset = offsetof(struct shared_info, + vcpu_info[v->arch.xen.vcpu_id]); + else + *offset = offsetof(struct compat_shared_info, + vcpu_info[v->arch.xen.vcpu_id]); + } + + return &kvm->arch.xen.shinfo_cache; + } + if (offset) *offset = 0; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index d3f371bafad8..480612f73fc2 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1283,6 +1283,7 @@ struct kvm_x86_mce { #define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5) #define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6) #define KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA (1 << 7) +#define KVM_XEN_HVM_CONFIG_DEFAULT_VCPU_INFO (1 << 8) struct kvm_xen_hvm_config { __u32 flags;