From patchwork Mon Sep 18 11:21:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2855206vqi; Mon, 18 Sep 2023 11:11:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgKs+jZXS8t4FCGFvpJqRRqp+N6KNSeahCvljCCginASW/vh4Wds5Srg5DChlJ0Nru6aB8 X-Received: by 2002:a17:902:db03:b0:1c4:2ca5:8b7c with SMTP id m3-20020a170902db0300b001c42ca58b7cmr9238896plx.61.1695060678178; Mon, 18 Sep 2023 11:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695060678; cv=none; d=google.com; s=arc-20160816; b=RTsMEmy6Wcv0NxAVnWC5jIiIy+r3RvwQwvLcCaj3eyaF/NRz9yY6Ruj563QS11QmUy 9jZWikA3aakIAgdCFeBTsrBjnIaoESHPnztv7DJrgOxdR/0QGccZt0phHYLa22J6h1G+ cBOShBroTNzdwMn74YnCoz+csDX/V8Sz8FexntbNEiXzDQ1SboDJIirdDpMqnmrgd/j2 zt2IOqQ+9i2WA1Gm1vwqvEhycORit3nXW/IFNdc/kJTSj0bcbo2Q259B2ZaY18HifyDB ufgp19EOBJuoxTarLMRtMLogICwTjGOUEhifGPEqlU0KoGgxgK9qavS+BbO60y2WBCEo MDGg== 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=ED0l6T0DdIBVNn8czLldNPS0uF0oubT1etNCdRtl7Qw=; fh=NVKswJvclYk1MEC7AfFzo67YIylApYMwZ7eFzXKDgdk=; b=VV/wI0PI5naZAitEDZTEPqNcY1sD99Upyg4WC8LFHyzyU+PqJdbFqM6vsUjsRiVEtT Rx9MxJHnUZKjpDA5nV0nCwob366BRg2CGKqil9XYYvPPTTn1cD0hSuOzDkE6j/9zEavz zKErz5ty/aVbjWpbTXlhV+JC+5mv7D13/s1C7p42bsROdsCHsDD5rUlNr9boJV8s102H ox6uJHpqkSG0KViTkKjllH8xz4p3XRxf5J2LwzhZ7gxrJU/n5yP3e0XYkr1r6gjN2+rr VjAhu2WsNcmnZpWie4vTjG9Np4QBxrJzYElHk1dbsvL9e63QbOLHklkzZ06WguM0JLqm aUjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=QHG7DRpC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ks6-20020a170903084600b001bf0cc53d1fsi1900515plb.343.2023.09.18.11.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 11:11:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=QHG7DRpC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id BC10C8243086; Mon, 18 Sep 2023 04:23:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241702AbjIRLXD (ORCPT + 27 others); Mon, 18 Sep 2023 07:23:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241292AbjIRLWY (ORCPT ); Mon, 18 Sep 2023 07:22:24 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D02A0B3; Mon, 18 Sep 2023 04:22:18 -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=ED0l6T0DdIBVNn8czLldNPS0uF0oubT1etNCdRtl7Qw=; b=QHG7DRpC84gyDdVc8cAcwIFQOr nGA81HVkPAJdJdy7t4vTi/xC2FTFAxW+e7uAGNbihxdvrDaSbmmBTb6niIU04lRzAz26F6TqMiErv SN7CRY7OxmfVONirdegQzk+lPQtLhaQVsxKCa5nA7EyxLT6C/z5mbu2877x+9QTetkpE=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiCKX-000732-Rp; Mon, 18 Sep 2023 11:22:17 +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 1qiCKX-0005f3-Kd; Mon, 18 Sep 2023 11:22:17 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , Sean Christopherson , Paolo Bonzini , David Woodhouse Subject: [PATCH v2 09/12] KVM: selftests / xen: set KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID Date: Mon, 18 Sep 2023 11:21:45 +0000 Message-Id: <20230918112148.28855-10-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918112148.28855-1-paul@xen.org> References: <20230918112148.28855-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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 18 Sep 2023 04:23:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777376890658106022 X-GMAIL-MSGID: 1777399946166968055 From: Paul Durrant If the capability (KVM_XEN_HVM_CONFIG_EVTCHN_SEND) is present then set the guest's vCPU id to match the chosen vcpu_info offset. Also make some cosmetic fixes to the code for clarity. Signed-off-by: Paul Durrant --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: David Woodhouse v2: - New in this version. --- .../selftests/kvm/x86_64/xen_shinfo_test.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c index 05898ad9f4d9..49d0c91ee078 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c @@ -38,6 +38,8 @@ #define VCPU_INFO_VADDR (SHINFO_REGION_GVA + 0x40) #define RUNSTATE_VADDR (SHINFO_REGION_GVA + PAGE_SIZE + PAGE_SIZE - 15) +#define VCPU_ID 1 /* Must correspond to offset of VCPU_INFO_[V]ADDR */ + #define EVTCHN_VECTOR 0x10 #define EVTCHN_TEST1 15 @@ -410,7 +412,7 @@ static void *juggle_shinfo_state(void *arg) struct kvm_xen_hvm_attr cache_activate = { .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, - .u.shared_info.gfn = SHINFO_REGION_GPA / PAGE_SIZE + .u.shared_info.gfn = SHINFO_ADDR / PAGE_SIZE }; struct kvm_xen_hvm_attr cache_deactivate = { @@ -446,6 +448,7 @@ int main(int argc, char *argv[]) bool do_runstate_flag = !!(xen_caps & KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG); bool do_eventfd_tests = !!(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL); bool do_evtchn_tests = do_eventfd_tests && !!(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_SEND); + bool has_vcpu_id = !!(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_SEND); clock_gettime(CLOCK_REALTIME, &min_ts); @@ -494,7 +497,7 @@ int main(int argc, char *argv[]) struct kvm_xen_hvm_attr ha = { .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, - .u.shared_info.gfn = SHINFO_REGION_GPA / PAGE_SIZE, + .u.shared_info.gfn = SHINFO_ADDR / PAGE_SIZE, }; vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &ha); @@ -508,6 +511,14 @@ int main(int argc, char *argv[]) TEST_ASSERT(m == shinfo, "Failed to map /dev/zero over shared info"); shinfo->wc = wc_copy; + if (has_vcpu_id) { + struct kvm_xen_vcpu_attr vid = { + .type = KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID, + .u.vcpu_id = VCPU_ID, + }; + vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &vid); + } + struct kvm_xen_vcpu_attr vi = { .type = KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO, .u.gpa = VCPU_INFO_ADDR, @@ -983,8 +994,8 @@ int main(int argc, char *argv[]) struct pvclock_wall_clock *wc; struct pvclock_vcpu_time_info *ti, *ti2; - wc = addr_gpa2hva(vm, SHINFO_REGION_GPA + 0xc00); - ti = addr_gpa2hva(vm, SHINFO_REGION_GPA + 0x40 + 0x20); + wc = addr_gpa2hva(vm, SHINFO_ADDR + 0xc00); + ti = addr_gpa2hva(vm, VCPU_INFO_ADDR + 0x20); ti2 = addr_gpa2hva(vm, PVTIME_ADDR); if (verbose) {