Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5611735rwb; Tue, 17 Jan 2023 16:29:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXvgxOdNCPh7DFDoz40D+rw6vEWcfxsaAxS5iwWUgTwGQtIqhnoGG6Fi8aHhr0Hrj8fPDBXB X-Received: by 2002:a05:6402:5208:b0:49e:4459:36a4 with SMTP id s8-20020a056402520800b0049e445936a4mr1491384edd.35.1674001762227; Tue, 17 Jan 2023 16:29:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674001762; cv=none; d=google.com; s=arc-20160816; b=aeKyhMv+qPXi86e9nq98G74NmFWj3TWnUNIMvXeX1yLNgEZgKTYkeotQN+j8r2EbbQ ttxP51++5S2onbW+c2TYBAvxmLPKK6pKJpNLn1ML99ve5Jr8sZKfzbT9BsYLN/Lo7sHz WMEbkA1QuQ8OQl81IZ2XUNZ1v+MCgRLwmtqD6Q+jmgEpbx2bBXY+8GLhruuyYr7gyQ14 FnW9AuptpLfm06F9zhxT4VyAncXM5BWmvOTRBcM74KXRvLgk6LwGFGHK4c0OtYy2uPly PYORhM+U/41z0xS7jVH8Igg+Ob0eO/2z5IH7UBiNL2fsHnnPRMi98gTsjFChYrmQhCnl sgrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4dz4YSfpv2T4m79ecLVLYg/MjvlF/TKDxbBLqvBzZUw=; b=TJQ7rBXRgz59X+dPBIgMRN6QeSflQ/ZbbXDyyJ2mQv7I/KpQBpw3jdPleLrzoPNcqM 8HTsOm/gNBZJ6dQMoHfadcOzfAr0lOAMukNoOQPEk6a14h1yjhopLsrQ7iG1q4HNLG5t aYiFNvdSsdySA0u1UdcXXzkYIyFjVKGwwJRW6O6ImZB8tNXUdNmG1aiiltjkalw8E+Ys x01oz3om28GMAA4o3E2SZDc07bcRJ+j6GLnh6+5bc6wleTqdPoBxfghn7blQXjS0xNl1 PKkq0fCcDXQ9jopHl+Rm7oqYIGJ3DWW7HJUKg1ZsihXG/PoAh7lSoAgeC285yvZltVpm pUgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sv78Dh2Q; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa40-20020a17090786a800b008688996dda7si10925884ejc.86.2023.01.17.16.29.10; Tue, 17 Jan 2023 16:29:22 -0800 (PST) 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=20210112 header.b=sv78Dh2Q; 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 S229507AbjAQXqF (ORCPT + 46 others); Tue, 17 Jan 2023 18:46:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbjAQXpj (ORCPT ); Tue, 17 Jan 2023 18:45:39 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D1884DE04 for ; Tue, 17 Jan 2023 14:51:47 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id w4-20020a17090ac98400b002186f5d7a4cso467046pjt.0 for ; Tue, 17 Jan 2023 14:51:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=4dz4YSfpv2T4m79ecLVLYg/MjvlF/TKDxbBLqvBzZUw=; b=sv78Dh2Q372NesG6fn9eLYR446uOhxqMw95J9Xmhrg1XZKK9E0pPqMndt5u6CFNZt+ wEx7TGifDWupQ1scvBA7o1nLOawl/DGYwQ/EpX3Vefiab0uJOUJG0SfBWAjtwQfs3Oym 9VvMWaizc8KXBH/FiUMj//KhicHS00IpGpo/4RCopkl9BMcYDeUnlsqv3wUtQA4yMTfT wNZSSV1OQs2TLn+dbNinHZ4ZSqgEbAuy5evzUe8XBMKF4hNltMJPeY/gN0UC0FHD254Q kF4s5VHwl6vpnWc2LRSEN9qEOrgZj2zH8YjY9UAxxNUdPIMuzjRJlkcQ1Sm03Mpvlryj fAmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4dz4YSfpv2T4m79ecLVLYg/MjvlF/TKDxbBLqvBzZUw=; b=LFtCinIslGrmOiyUf69IpP+eU0AuIWjFRKzUntKi/LgUz2BgZaS9Dkc4XiYG0dQgSF IMwSHtsLly56IZ/NWGSIeWJBvcXKBBh11H8696aO+FXca6Rkk9mUCdZ2FU2ucrz/pdv6 hUNZ/NQCq8xLgfLwBbE1tIvG2Sk27kwls51zTH+X5Ze9jJ6RA2IObZAuMK1tIp/YDIn9 zb8FQbk/7TktymOfA4c9bfaSy2436r1ecDUCpjQ08ndH7URF/OdlRxpiz9J4mSZBOjqD 0oTRjKr/jgakOrLI1xlcSumvkS66OevUFV8WVuM5GUZ/7J6imV09fcPsHWall8I/MNX3 JBqA== X-Gm-Message-State: AFqh2kou6zvQqGQ5BY6NVsY8pXvcH3aUPm8bqt8GEsXGY9tND1u8Lh02 V+HoTr0ip0/4YNES9BbRtK59Mg== X-Received: by 2002:a05:6a20:ce43:b0:b8:c3c0:e7f7 with SMTP id id3-20020a056a20ce4300b000b8c3c0e7f7mr395043pzb.1.1673995906357; Tue, 17 Jan 2023 14:51:46 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id z13-20020aa79e4d000000b0058bc1a13ffcsm7232252pfq.25.2023.01.17.14.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 14:51:45 -0800 (PST) Date: Tue, 17 Jan 2023 22:51:42 +0000 From: Sean Christopherson To: Vishal Annapurve Cc: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, shuah@kernel.org, yang.zhong@intel.com, ricarkol@google.com, aaronlewis@google.com, wei.w.wang@intel.com, kirill.shutemov@linux.intel.com, corbet@lwn.net, hughd@google.com, jlayton@kernel.org, bfields@fieldses.org, akpm@linux-foundation.org, chao.p.peng@linux.intel.com, yu.c.zhang@linux.intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, michael.roth@amd.com, qperret@google.com, steven.price@arm.com, ak@linux.intel.com, david@redhat.com, luto@kernel.org, vbabka@suse.cz, marcorr@google.com, erdemaktas@google.com, pgonda@google.com, nikunj@amd.com, diviness@google.com, maz@kernel.org, dmatlack@google.com, axelrasmussen@google.com, maciej.szmigiero@oracle.com, mizhang@google.com, bgardon@google.com, ackerleytng@google.com Subject: Re: [V2 PATCH 4/6] KVM: selftests: x86: Add helpers to execute VMs with private memory Message-ID: References: <20221205232341.4131240-1-vannapurve@google.com> <20221205232341.4131240-5-vannapurve@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221205232341.4131240-5-vannapurve@google.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Mon, Dec 05, 2022, Vishal Annapurve wrote: > +void vcpu_run_and_handle_mapgpa(struct kvm_vm *vm, struct kvm_vcpu *vcpu) > +{ > + /* > + * Loop until the guest exits with any reason other than > + * KVM_HC_MAP_GPA_RANGE hypercall. > + */ > + > + while (true) { > + vcpu_run(vcpu); > + > + if ((vcpu->run->exit_reason == KVM_EXIT_HYPERCALL) && > + (vcpu->run->hypercall.nr == KVM_HC_MAP_GPA_RANGE)) { I get what you're trying to do, and I completely agree that we need better helpers and/or macros to reduce this type of boilerplate, but adding a one-off helper like this is going to be a net negative overall. This helper services exactly one use case, and also obfuscates what a test does. In other words, this is yet another thing that needs broad, generic support (_vcpu_run() is a very special case). E.g. something like this to make it easy for tests to run a guest and handle ucalls plus specific exits (just a strawman, I think we can do better for handling ucalls). #define vcpu_run_loop(vcpu, handlers, ucalls) \ do { \ uint32_t __exit; \ int __r = 0; \ \ while (!r) { \ vcpu_run(vcpu); \ \ __exit = vcpu->run->exit_reason; \ \ if (__exit < ARRAY_SIZE(handlers) && handlers[__exit]) \ __r = handlers[__exit](vcpu); \ else if (__exit == KVM_EXIT_IO && ucalls) \ __r = handle_exit_ucall(vcpu, ucalls, \ ARRAY_SIZE(ucalls)); \ else \ TEST_FAIL(...) \ } \ } while (0) For this series, I think it makes sense to just open code yet another test. It really doesn't end up being much code, which is partly why we haven't added helpers :-/