From patchwork Mon Sep 18 11:21: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: 141423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2683753vqi; Mon, 18 Sep 2023 07:05:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUQepDO8lUING8zq9dRCjRqHR3ela5bb0eC5FpgpjbBGXZee1/PG5Dypm3yCAFHTrKGXwd X-Received: by 2002:a05:6e02:13d3:b0:345:d58d:9ae5 with SMTP id v19-20020a056e0213d300b00345d58d9ae5mr11845983ilj.7.1695045956036; Mon, 18 Sep 2023 07:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695045956; cv=none; d=google.com; s=arc-20160816; b=affoInNHsciOk2zhk4KM6LkInHACaTfltPQrLO/7WttHeAOOsk+GmoaW3ZOzdThg2h ZyRKH2h6ABWnhz9TexXSbBgIdeP5m0mdouK+yrwnR5ze4WJZeljakpls6ohExCfHYqWg f8JyWrjevB12JKZJOe5vfKR37RLoXNwkFWB8+BnJwWi1iF9mXWMCPuA/IEUSqJDS/vfT WTHpbjVfGNQlnTWtVtaAECSAX6mpPLl3tTpXOtisbYuvYE0mvuP0eOHNqFpQYRw5O+2/ TizHJubktb+DMiR5IutfYMOU5czBTnmQW7ROYgiCIh8qONW9CF+r7OZjrVOmAqew2sjY UFRQ== 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=F2tt1vng5GeCrD0vCTbIE4sW0FPuoGj/KLthbnkHO/8=; fh=NVKswJvclYk1MEC7AfFzo67YIylApYMwZ7eFzXKDgdk=; b=AKUKelY8rNYQtByPCOi6cTtUKwIfQ+PGUAOvAmn64Y/VYG0zrXGd0PHIqqT8UZ/THZ umLgdr+kb2J01GiJ1FaHkKpfh0D0JmZqPtuyU4QCAUGaPs+AprGI/nsQZPyRjGujhYLN tctImC3GiBAP3dRUocnZZ5Hpqwj7FfVv8OA4YghtmTGV8QcsxN+JlJVkH+yurzXbIBet 061Cybu3P/qti6LBjuMWqpxIuZaI1ZcamQUampOBWtH5jB69YlmPO6G3jtlRVitBGxh2 C8MQjrp1lttBikHcfKLzLBbgjWVaqVDggjDz2fYRxbl4dowPnwkdOu4t6x2uCkbNCgg5 ss5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=ZDN0LQkR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z4-20020a656104000000b0056c297d163csi7418484pgu.530.2023.09.18.07.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 07:05:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=ZDN0LQkR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id B3CE4803202D; Mon, 18 Sep 2023 04:44:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241756AbjIRLnc (ORCPT + 27 others); Mon, 18 Sep 2023 07:43:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241716AbjIRLnD (ORCPT ); Mon, 18 Sep 2023 07:43:03 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71BAEFD; Mon, 18 Sep 2023 04:42:56 -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=F2tt1vng5GeCrD0vCTbIE4sW0FPuoGj/KLthbnkHO/8=; b=ZDN0LQkR52OCZ+dcXyY461a9r+ 7l1WiuKByZk0SU3yaOe1HlaKKcjw4lCY3mH/Nc2Ap4bfDVsT+bLVNvqsEFkv0G5gGLaz1ej+GeXJ7 zv9NTLNyfY3fd0YgA/dPANIaEkjaPeLswMcFmmScxoY17etAkI8dGJNYrO8Be03Dh23k=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiCeV-0007d9-Ek; Mon, 18 Sep 2023 11:42:55 +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 1qiCKY-0005f3-J9; Mon, 18 Sep 2023 11:22:18 +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 10/12] KVM: selftests / xen: map shared_info using HVA rather than GFN Date: Mon, 18 Sep 2023 11:21:46 +0000 Message-Id: <20230918112148.28855-11-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 04:44:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777384508370416552 X-GMAIL-MSGID: 1777384508370416552 From: Paul Durrant Using the HVA of the shared_info page is more efficient, so if the capability (KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA) is present use that method to do the mapping. 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 | 50 ++++++++++++++++--- 1 file changed, 43 insertions(+), 7 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 49d0c91ee078..fa829d6e0848 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c @@ -395,6 +395,7 @@ static int cmp_timespec(struct timespec *a, struct timespec *b) return 0; } +static struct shared_info *shinfo; static struct vcpu_info *vinfo; static struct kvm_vcpu *vcpu; @@ -406,7 +407,7 @@ static void handle_alrm(int sig) TEST_FAIL("IRQ delivery timed out"); } -static void *juggle_shinfo_state(void *arg) +static void *juggle_shinfo_state_gfn(void *arg) { struct kvm_vm *vm = (struct kvm_vm *)arg; @@ -429,6 +430,29 @@ static void *juggle_shinfo_state(void *arg) return NULL; } +static void *juggle_shinfo_state_hva(void *arg) +{ + struct kvm_vm *vm = (struct kvm_vm *)arg; + + struct kvm_xen_hvm_attr cache_activate = { + .type = KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA, + .u.shared_info.hva = (unsigned long)shinfo + }; + + struct kvm_xen_hvm_attr cache_deactivate = { + .type = KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA, + .u.shared_info.hva = 0 + }; + + for (;;) { + __vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_activate); + __vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_deactivate); + pthread_testcancel(); + } + + return NULL; +} + int main(int argc, char *argv[]) { struct timespec min_ts, max_ts, vm_ts; @@ -449,6 +473,7 @@ int main(int argc, char *argv[]) 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); + bool has_shinfo_hva = !!(xen_caps & KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA); clock_gettime(CLOCK_REALTIME, &min_ts); @@ -459,7 +484,7 @@ int main(int argc, char *argv[]) SHINFO_REGION_GPA, SHINFO_REGION_SLOT, 3, 0); virt_map(vm, SHINFO_REGION_GVA, SHINFO_REGION_GPA, 3); - struct shared_info *shinfo = addr_gpa2hva(vm, SHINFO_VADDR); + shinfo = addr_gpa2hva(vm, SHINFO_VADDR); int zero_fd = open("/dev/zero", O_RDONLY); TEST_ASSERT(zero_fd != -1, "Failed to open /dev/zero"); @@ -495,10 +520,16 @@ int main(int argc, char *argv[]) "Failed to read back RUNSTATE_UPDATE_FLAG attr"); } - struct kvm_xen_hvm_attr ha = { - .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, - .u.shared_info.gfn = SHINFO_ADDR / PAGE_SIZE, - }; + struct kvm_xen_hvm_attr ha = {}; + + if (has_shinfo_hva) { + ha.type = KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA; + ha.u.shared_info.hva = (unsigned long)shinfo; + } else { + ha.type = KVM_XEN_ATTR_TYPE_SHARED_INFO; + ha.u.shared_info.gfn = SHINFO_ADDR / PAGE_SIZE; + } + vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &ha); /* @@ -902,7 +933,12 @@ int main(int argc, char *argv[]) if (verbose) printf("Testing shinfo lock corruption (KVM_XEN_HVM_EVTCHN_SEND)\n"); - ret = pthread_create(&thread, NULL, &juggle_shinfo_state, (void *)vm); + if (has_shinfo_hva) + ret = pthread_create(&thread, NULL, + &juggle_shinfo_state_hva, (void *)vm); + else + ret = pthread_create(&thread, NULL, + &juggle_shinfo_state_gfn, (void *)vm); TEST_ASSERT(ret == 0, "pthread_create() failed: %s", strerror(ret)); struct kvm_irq_routing_xen_evtchn uxe = {