From patchwork Tue Jul 11 23:01:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 118745 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp796723vqm; Tue, 11 Jul 2023 16:16:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlGd16EhK5K2kMYZMzaGvvzwkT3Se/xLF5akuKvIh8edbuYd0FbQ7zrQelodEy96qNmRL/I5 X-Received: by 2002:a05:6512:2005:b0:4f4:d83e:4141 with SMTP id a5-20020a056512200500b004f4d83e4141mr12728696lfb.50.1689117361138; Tue, 11 Jul 2023 16:16:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689117361; cv=none; d=google.com; s=arc-20160816; b=bhy9juMUkmMeatu6/rk3DBreX347cmu4vr1ECC8zdzKMV62Abff/jABQ/n/uRnVYZE dua+e9epvKjGX4viFnottjUQxgHvfzz7VRmZQnZHmy72VTDEkKEsjDOhsKJkR7Yd7gp3 1QrPYjMxEgjuVMfGCq8DQ4CyGk+XrpRTmoNrBo0LY8IPdt88eSY5giy9wfl+eqd3h+DY uR3a653DKTlgqscXi5OcyhMhug7F6+F50otkffpLDzHR6ROUi+ClYjC/gsnXshpenopy g27eLb4ZDFKcV4cY58riaqT8J/JIl0FtVreAZANYTLmSyN+ySA5mVgAfMl9n5nH3HBer txuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=qyvtqeRPq/MlF0ZTdDehI+RMIDCPhIW4IOYWhk2FAaM=; fh=WlkBVuaco6NrS/z+1f/wCzwszSt/RBqjyVC/qitxnws=; b=mTIkxNw//nZiZSl5EEQh8WbN/RQWToFEHrW93unnv4okdadsIrICtFg5V5hLGku8TN MLGthEN8ved1ycNeionxCk+w0iPTZTw9Zik1E4WgYt/PImSkl3Fcya5Fwgxg7xra9XLA UdTI5ZMbyE/x34Xlf4Zv3W1Gg8/MuRlbAJRSS604CVimi7JUh2hA7GVPhVzf9IQuyXCH pix0kTjFlRGOutRFa9jn0w9r4DsBZQLs7mIyVbcczoGrSOTrmzkUR3HhT0w6mtDpYyqi OO12q5Wy6k34W9tzpJvDlr4GSqaNuNiX2qmR2+DCBkHpe576ejjt4WzdvPyZGJ6oF/J1 cfDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=QEG302Aq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ba4-20020a0564021ac400b0051e26b9696dsi3366371edb.518.2023.07.11.16.15.38; Tue, 11 Jul 2023 16:16:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=QEG302Aq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232118AbjGKXCF (ORCPT + 99 others); Tue, 11 Jul 2023 19:02:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232116AbjGKXB6 (ORCPT ); Tue, 11 Jul 2023 19:01:58 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72AC7199E for ; Tue, 11 Jul 2023 16:01:47 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2631fc29e8aso6932728a91.3 for ; Tue, 11 Jul 2023 16:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689116507; x=1691708507; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=qyvtqeRPq/MlF0ZTdDehI+RMIDCPhIW4IOYWhk2FAaM=; b=QEG302AqsBou4e85I0bF1Fz1XHfj0kuK+s+Tyb/kkQXroB3QCJtAhiMap8KwBAPra/ 6dcmyFBYaZJ8RT7RQa7OY1Sv8Bq/HZxHa/hQ/i0T48PfCJX4o82eWzWooZWWpf9I/9hI BmJU4cP7FdnXukTED5kPtBE1V7fVEVH3jgT7bjT7vwZcpSYJXmNuAefLnVlGTauwTbFN J2hChuMEbuHZ4Lg75AxBrMxefqcIHUIiyVrsJFOykmBCruaMa6gD+2f0zzjDugYF/Nby c66Uj630xv5E9wJ2kPs2CBKz123BxpbrZJ38lJWWHiYCINz+XSK+zr8bzynn2LI3K0tL ynqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689116507; x=1691708507; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qyvtqeRPq/MlF0ZTdDehI+RMIDCPhIW4IOYWhk2FAaM=; b=T1Q0SyVL+uByS9olfs11gdeL0V9OG6pF59jGD3acb6zNDIXA+wUF+kOmbbhJYpEx9T qvdI4XQhXVAaHkzZQXI1xBwFj0Y96ERCrl+QURJo3gCPQI2vhXu/I3k0mYv8981VKpDk QHWnT0xMkND4UnTtvAIqfYdidfQUocydjXq5kZH3YANKURGrbJHZJm0WykVqKjM3eef8 4FWOHaZX7GdzKV8pQLM08t8BywNiAKM2pv8M/f2D0OiEY0neiwZRQzfqrxPNQPwJ7SiK qfexKdR/dp10CPG60MeofWq7Rbr4fAahkadmia52jOx5zW/J5JH1lKbAXF5BLwQPOF7p sx8Q== X-Gm-Message-State: ABy/qLboIQp4w5dy6a1slXOAqcy0z5pKJVaqE1IJBLCYkRYFViEyXrCw 5f91T2xPGRnXAZw/CeADYe1Mf2MEV/k= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:ead1:b0:1b9:e8e5:b0a4 with SMTP id p17-20020a170902ead100b001b9e8e5b0a4mr2142642pld.8.1689116506840; Tue, 11 Jul 2023 16:01:46 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 11 Jul 2023 16:01:30 -0700 In-Reply-To: <20230711230131.648752-1-seanjc@google.com> Mime-Version: 1.0 References: <20230711230131.648752-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230711230131.648752-7-seanjc@google.com> Subject: [PATCH 6/7] KVM: selftests: Verify stats fd can be dup()'d and read From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zheng Zhang , Kees Cook , Sean Christopherson X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771167925551047229 X-GMAIL-MSGID: 1771167925551047229 Expand the binary stats test to verify that a stats fd can be dup()'d and read, to (very) roughly simulate userspace passing around the file. Adding the dup() test is primarily an intermediate step towards verifying that userspace can read VM/vCPU stats before _and_ after userspace closes its copy of the VM fd; the dup() test itself is only mildly interesting. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/kvm_binary_stats_test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c index 653f10d8fb7c..5317e27b77d0 100644 --- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c +++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c @@ -232,17 +232,23 @@ int main(int argc, char *argv[]) } /* - * Check stats read for every VM and vCPU, with a variety of testcases. + * Check stats read for every VM and vCPU, with a variety of flavors. * Note, stats_test() closes the passed in stats fd. */ for (i = 0; i < max_vm; ++i) { + /* + * Verify that creating multiple userspace references to a + * single stats file works and doesn't cause explosions. + */ vm_stats_fds = vm_get_stats_fd(vms[i]); + stats_test(dup(vm_stats_fds)); /* Verify userspace can instantiate multiple stats files. */ stats_test(vm_get_stats_fd(vms[i])); for (j = 0; j < max_vcpu; ++j) { vcpu_stats_fds[j] = vcpu_get_stats_fd(vcpus[i * max_vcpu + j]); + stats_test(dup(vcpu_stats_fds[j])); stats_test(vcpu_get_stats_fd(vcpus[i * max_vcpu + j])); }