From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83499C00140 for ; Tue, 2 Aug 2022 23:07:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234661AbiHBXHf (ORCPT ); Tue, 2 Aug 2022 19:07:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234193AbiHBXH2 (ORCPT ); Tue, 2 Aug 2022 19:07:28 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1D6539BB6 for ; Tue, 2 Aug 2022 16:07:26 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id r6-20020a17090a2e8600b001f0768a1af1so98297pjd.8 for ; Tue, 02 Aug 2022 16:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:reply-to:from:to:cc; bh=+GFkeGjcI/kh+1Shtb4fxwNaREiAkX51PnmuuTAQK8A=; b=pOA9GnOT+nlyPEzAnIBAEih/PaG2I2w7V5WKhUFU6eQ5B8Fat2GYPJqmqhXHVNcxD6 p5gHVxB9cHa4DgK6uwW1wU7YMKq96dAGSpshNoelsEaVP8QTaC9nbRgsIuedG5zlB7tG FVzSMiSEhcVzUllG6do3/SuOGAgIAjcZtEyV2p0GSZ6K9IEn8eC9Zg7oKYOy14SYdaxE 5rcFsnxepDGJs6twRR4oVInr447mpWXw7X07CRek7XK3CuZBdqxq7nFH6EACkRWmDGiA GfX+aIHWEONmpu/l653qLK1m6bIr3LKBn7nj6H+cyd8EQdIA/Q6pJcXe16m84E59370q XvRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc; bh=+GFkeGjcI/kh+1Shtb4fxwNaREiAkX51PnmuuTAQK8A=; b=FKU1xPtUWrez0n14DHuJPdxG7TUIfkOyqqPXdHDkI2Q+V1K2Cyu1c5f9Py9A/3j6Su 3VP9smov+RIklpdsJOXiyg9aWSgiSQdNTCWZ9AAJT0HG8v/bN3bR/CyG8IaXbowdOBrT IC9/6RGf1lZguHG/e7T/z1iZvwKpD9VSoLdCvEwwH+TYV9iNXP5fNSGZYuqEhedHvdxe igWT1X+u40s3ZXhFrvB5V4BGln/LrjKxSYJhZZA06c97ENggc96Dane4x0gJe+4Anfzu WvQnRQXHWg5wSPkdLshwBM5Uotxf+L+ax2HwOZuH86JUBT91Vp6akifWOi9UG/7kD+/t MjSg== X-Gm-Message-State: ACgBeo2lqyW0XLK7oywI72Id7WkowZ/7cN5osUUWgpjySMIExPLdewul qlTrYJMnZk/+2+lF816DBED6IHdsX/ri X-Google-Smtp-Source: AA6agR7baxuoDiumlwxT8og4KDOAqwSDO43YIdTmYpk4I7uSGbhlRnMu5fP0gocL3tClU2CNLVv8GL0cxZwz X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a17:90b:3e84:b0:1f0:3f92:8c91 with SMTP id rj4-20020a17090b3e8400b001f03f928c91mr1904559pjb.112.1659481646348; Tue, 02 Aug 2022 16:07:26 -0700 (PDT) Reply-To: Mingwei Zhang Date: Tue, 2 Aug 2022 23:07:16 +0000 In-Reply-To: <20220802230718.1891356-1-mizhang@google.com> Message-Id: <20220802230718.1891356-4-mizhang@google.com> Mime-Version: 1.0 References: <20220802230718.1891356-1-mizhang@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH 3/5] selftests: KVM: Introduce vcpu_run_interruptable() From: Mingwei Zhang To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Oliver Upton , Mingwei Zhang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce vcpu_run_interruptable() to allow selftests execute their own code when a vcpu is kicked out of KVM_RUN on receiving a POSIX signal. This function gives selftests the flexibility to execute their own logic especially when a vCPU is halted. Note that vcpu_run_complete_io() almost achieves the same effect. However, it explicitly disallows the case of returning to caller when errno is EINTR. Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/include/kvm_util_base.h | 2 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index ac883b8eab57..cfb91c63d8c3 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -398,6 +398,8 @@ static inline int __vcpu_run(struct kvm_vcpu *vcpu) return __vcpu_ioctl(vcpu, KVM_RUN, NULL); } +int vcpu_run_interruptable(struct kvm_vcpu *vcpu); + void vcpu_run_complete_io(struct kvm_vcpu *vcpu); struct kvm_reg_list *vcpu_get_reg_list(struct kvm_vcpu *vcpu); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 9889fe0d8919..aca418ce4e8c 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1406,6 +1406,17 @@ void vm_create_irqchip(struct kvm_vm *vm) vm->has_irqchip = true; } +int vcpu_run_interruptable(struct kvm_vcpu *vcpu) +{ + int rc; + + rc = __vcpu_run(vcpu); + + vcpu->run->immediate_exit = 0; + + return rc; +} + int _vcpu_run(struct kvm_vcpu *vcpu) { int rc; -- 2.37.1.455.g008518b4e5-goog