Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3048763rwb; Mon, 3 Oct 2022 09:01:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7bXzE9OLdOihKPAYmE34Df/IuccWVkga96f8pQyhUbFxyHvKmA40Ezq7D87V5DNQLSKgo0 X-Received: by 2002:a17:907:a47:b0:780:6883:2a37 with SMTP id be7-20020a1709070a4700b0078068832a37mr15251002ejc.219.1664812881914; Mon, 03 Oct 2022 09:01:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664812881; cv=none; d=google.com; s=arc-20160816; b=PtjAGcJ0+hU40yyDnvJIdxMx7q4OgVITVL+Q46S+w7wobYL/dB5veg8W9OKG2OulPt BSvyXHA2SfBa7jcBx7yAYPpyATwl1e7Pa+nExXR4vwsgsv9SMiyQTKFydd8apEku83Wu S4y9opQ4m+1Yx5YxotlXFu+p7Vn9qYc7Z+HYaykd4xtWYz4fIADXQBdtld4sCaabDZaz W1sNpYEqx1J+/yTT5n1aX7ugfLLFrWHDin2lfQ6VmkoRG//b5PyxMsDYEC9eIXpRPMVN nqdrEe8m+ucrc/0lYHzX1VwVt7/vk0JreYzk3HBuO/K3njOLGIhncBDuZ/uJLe460Oek Xdyg== 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=8DydcZk1u0xB1c+8RaosfYF4xcLu+b5YE36qeyQVzwg=; b=C2lSJyPBZA+yJXMFr49FZaKjk3lcb6psocPMfdYy5SBTH6pqeoRHEaXkSCYgfwK9Ku /DdPPDsQLXB4stpvUiARgG140rFfAb/Y1HP+7ws43ZtNL327fMlCa//bibiT8eYFBGPu jM95QBMPj9BJKb1XH4/gxa8NXe/HnerPkJGzNNzx/+DIO7X4KaaG9OL7pR/I+tvCS+cF ib5ww007DQ9Nqx0u7ZqL9qWu85e6HFT2u88+YU6rzgK+63KFgbzZ5FQULp7jIdFxxW8A T1UPkWPGglvJ858pDF9n5nqgcho3F5w+XpcgNgDkQzgxNap7kbeoGAJcrj0jfNVxbO75 dXtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MWeYoPc1; 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 cs19-20020a170906dc9300b00782fd14c6e3si8615840ejc.87.2022.10.03.09.00.37; Mon, 03 Oct 2022 09:01:21 -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=20210112 header.b=MWeYoPc1; 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 S229669AbiJCPrp (ORCPT + 99 others); Mon, 3 Oct 2022 11:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbiJCPre (ORCPT ); Mon, 3 Oct 2022 11:47:34 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B326B31EE6 for ; Mon, 3 Oct 2022 08:47:31 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 78so9978317pgb.13 for ; Mon, 03 Oct 2022 08:47:31 -0700 (PDT) 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; bh=8DydcZk1u0xB1c+8RaosfYF4xcLu+b5YE36qeyQVzwg=; b=MWeYoPc1MT+Zh6TDC++oipZLPGWaGX7sho1om+CA6if9CGeO4XhqtOOzoT+1qAIr1k 7h379rag4jGR5OOWqd9YNfGNS2IPSQpV0lwALCkQmTNOJBJCXpFbMChWirjlEhmp0kHC OYILiPeSHJxkvOmpg6rTY+oVqAFG0U69/WEEUOAvCKcJP9V8XmHoObiZ/3D8WKBC9Yd5 hyOtD80f2AzLqB3yzVNvfRZIJAk0BUwhSOH5jx1SHhZlQZrPsJjd8jFRghEU/2+Qkxew ufUO65Q5D/17rnA/h3wHD0yX7mlG/4Ocz+aOi5/+s/pBgD2SHXwZcI10PaFqtRlvO2uz fLzw== 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; bh=8DydcZk1u0xB1c+8RaosfYF4xcLu+b5YE36qeyQVzwg=; b=dR428Pvs28wuSjUGtn2GyPXPHnRC6tw8mSjlf+imDFIs+d7dLM9u0mOFstAGOWUWlV 3LQ3lpsdYEPm3VIPg0dj2vLoD/LH45uFt4ZB240E0ORHh5LDEUWI/IRMEQY6j3JEtNsd ShS+jR5mEIxkEBPz79cXt7+w8eouDHuxrYociR0UUQkV76gYxTfFJ3ArSYF7O9CTSVyR 0sNIhLlFJeNhihQ45gZ5Y8nrV0l4ziRGXwc+YXLf3Rlvh4ZgKBuNlgoNxd8v7J8QBBkZ yftppO0sN4nIUYo7/hA09Z1VmTxsgGElBii3TnesBrTgnGRy1tA6qAXyBQ4Wz/0YjmE9 NpcQ== X-Gm-Message-State: ACrzQf2RVOR/IfA8CWPD0rqnhiuCDEYoBjv+Iv4Updus2n9BzYtfUXhE +Mv+zwGd6y7nYOou3lICprv+sw== X-Received: by 2002:a63:4042:0:b0:43b:ddc8:235 with SMTP id n63-20020a634042000000b0043bddc80235mr19773380pga.498.1664812050292; Mon, 03 Oct 2022 08:47:30 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id f4-20020a170902ce8400b00178b77b7e71sm7444647plg.188.2022.10.03.08.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 08:47:29 -0700 (PDT) Date: Mon, 3 Oct 2022 15:47:26 +0000 From: Sean Christopherson To: Vitaly Kuznetsov Cc: kvm@vger.kernel.org, Paolo Bonzini , Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , Yuan Yao , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v10 30/39] KVM: selftests: Hyper-V PV TLB flush selftest Message-ID: References: <20220921152436.3673454-1-vkuznets@redhat.com> <20220921152436.3673454-31-vkuznets@redhat.com> <87wn9h9i3w.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wn9h9i3w.fsf@redhat.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=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 On Mon, Oct 03, 2022, Vitaly Kuznetsov wrote: > Sean Christopherson writes: > > Anyways, why not do e.g. usleep(1)? > > I was under the impression that all these 'sleep' functions result in a > syscall (and I do see TRIPLE_FAULT when I swap my rep_nop() with usleep()) > and here we need to wait in the guest (sender) ... Oh, duh, guest code. > > And if you really need a udelay() and not a > > usleep(), IMO it's worth adding exactly that instead of throwing NOPs at the CPU. > > E.g. aarch64 KVM selftests already implements udelay(), so adding an x86 variant > > would move us one step closer to being able to use it in common tests. > > ... so yes, I think we need a delay. The problem with implementing > udelay() is that TSC frequency is unknown. We can get it from kvmclock > but setting up kvmclock pages for all selftests looks like an > overkill. Hyper-V emulation gives us HV_X64_MSR_TSC_FREQUENCY but that's > not generic enough. Alternatively, we can use KVM_GET_TSC_KHZ when > creating a vCPU but we'll need to pass the value to guest code somehow. > AFAIR, we can use CPUID.0x15 and/or MSR_PLATFORM_INFO (0xce) or even > introduce a PV MSR for our purposes -- or am I missing an obvious "easy" > solution? I don't think you're missing anything. Getting the value into the guest is the biggest issue. Vishal is solving a similar problem where the guest needs to know the "native" hypercall. We can piggyback that hook to do KVM_GET_TSC_KHZ there during VM creation, and then simply define udelay()'s behavior to always operate on the "default" frequency. I.e. if a test wants to change the frequency _and_ use udelay() _and_ cares about the precision of udelay(), then that test can go write its own code. > I'm thinking about being lazy here and implemnting a Hyper-V specific > udelay through HV_X64_MSR_TSC_FREQUENCY (unless you object, of course) > to avoid bloating this series beyond 46 patches it already has. I'm totally fine being even lazier here and just using a loop of nops, but with a different function name and a TODO (I completely forgot this was guest code when making the usleep() suggestion). Then we can clean up the TODO via udelay() in a follow-up series.