From patchwork Mon Sep 18 14:41:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2857952vqi; Mon, 18 Sep 2023 11:15:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsxJb7gjdfLUZktdQC90xgubYNgSKdMhh0awWUEEZXF50Xa1JUdJVJKPnDCPj3OFyuUBYq X-Received: by 2002:a05:6a21:3297:b0:133:e3e3:dc07 with SMTP id yt23-20020a056a21329700b00133e3e3dc07mr10917114pzb.49.1695060915241; Mon, 18 Sep 2023 11:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695060915; cv=none; d=google.com; s=arc-20160816; b=h+XujV7X3u0a6mqfdPC0L7tNoNdKVTdj8LyqauW8CoAJpIS8mBwkrX/OSOseVYWz5b Ba76u60cNHWOgzeieGZRRG4vmSdqzzO8uouy2FkiIwTQw6YhA10sKYiSFxB9E5hL1+IH /MisFqeWnPdDWiTqA6cTn5cjRcIf9kSgssr7p3YFjHFS57qrDF9uY0eKzmHq6FEllS3L lhL0rqfAnuKFSTHcbMprKgSzb0rem6qesGI1nHR4gD1G3YgntAyYnKTxu4RQd7nKDP70 qyctee+5acJo3YQtDSgzksnzhtaJyg/qxw4WHefg0k0s085zre2PHHBmJsU6wU+HR5v7 PSVg== 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=5dx9h7SGIgzZx3McRPLzAIAziBr0OX4wLMeK0R+Vbo4=; fh=F/y/rQAitAoVhyEvV7npxQC+pmk+LQOxsxEGW4WYgok=; b=gr33XsrkYdHU6hTajDADPCAdZgdFHteo7LGCEOGQOr7REWHHP40Yo3a2W5bagNgIyB UkXSRts0BFzV8KoEji1L7WevgQi1l61Wy1/nKDv4Cx4p5CdnLmIgecFe5Nz8TevZfSOJ GSiCL5pvYN5xHrPmCkhkUU2fq4IIUMolQ5ggoazjmaVv+5jwUrO+EhxsYBoMndq8DsPY Tzfk7WbudRDG7UUEa5GbtcZ9IEdV9GnymaRan9NMAPjaroQWomHSCwCO4vaKrrTT4Bxv NzJ944EZumLMWRQr4ZJccuZbt789dxfO1drb7234BUY5cJayxtWwvhGFDQUw2I37Znab yreg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="Gnf/zoQr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id n3-20020a6546c3000000b00563a0bacbb4si209378pgr.694.2023.09.18.11.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 11:15:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="Gnf/zoQr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id B5B1E8040900; Mon, 18 Sep 2023 09:09:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbjIRQJQ (ORCPT + 25 others); Mon, 18 Sep 2023 12:09:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbjIRQJB (ORCPT ); Mon, 18 Sep 2023 12:09:01 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD42A4490; Mon, 18 Sep 2023 09:07:21 -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=5dx9h7SGIgzZx3McRPLzAIAziBr0OX4wLMeK0R+Vbo4=; b=Gnf/zoQr0L3d+R9LPNsUGbq9bn HzG3qkJHEhds8QKj4zCEfDn9lyoFzW4/0jEq/L93y57iXD3UO6VvyudUojAEt+NWCqbmkqFrQNtR1 WVAXGfWxzW/NRzKTCxp++ExLwZpbUFO66gw8qeGAwZfdq4DWdPDAKytgz9W7wqkxkyHY=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFRG-0003RQ-Lf; Mon, 18 Sep 2023 14:41: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 1qiFRG-0006IJ-E8; Mon, 18 Sep 2023 14:41:26 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH v3 08/13] KVM: xen: prevent vcpu_id from changing whilst shared_info is valid Date: Mon, 18 Sep 2023 14:41:06 +0000 Message-Id: <20230918144111.641369-9-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:09:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777396452284052686 X-GMAIL-MSGID: 1777400194611676631 From: Paul Durrant To further prepare for automatically using the vcpu_info structures embedded in the shared_info page, we need to ensure that the Xen vcpu_id cannot change under our feet. We can do this by simply returning -EBUSY to any attempt to modify the attribute while the shinfo_cache is active. Signed-off-by: Paul Durrant --- Cc: 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: x86@kernel.org v3: - New in this version. --- arch/x86/kvm/xen.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 7fc4fc2e54d8..459f3ca4710e 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -752,6 +752,18 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) return r; } +static int kvm_xen_set_vcpu_id(struct kvm_vcpu *vcpu, unsigned int vcpu_id) +{ + struct kvm *kvm = vcpu->kvm; + struct gfn_to_pfn_cache *gpc = &kvm->arch.xen.shinfo_cache; + + if (gpc->active) + return -EBUSY; + + vcpu->arch.xen.vcpu_id = vcpu_id; + return 0; +} + int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) { int idx, r = -ENOENT; @@ -941,10 +953,8 @@ int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) case KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID: if (data->u.vcpu_id >= KVM_MAX_VCPUS) r = -EINVAL; - else { - vcpu->arch.xen.vcpu_id = data->u.vcpu_id; - r = 0; - } + else + r = kvm_xen_set_vcpu_id(vcpu, data->u.vcpu_id); break; case KVM_XEN_VCPU_ATTR_TYPE_TIMER: