Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2076218rdh; Tue, 26 Sep 2023 11:33:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXLVNYd+jEvN2X+NWuqF5Ghwv0d6CAzJUgk7Df7fe0dtT/a+xvKyYWX/gNSTOjh/mvkON4 X-Received: by 2002:a05:6358:2796:b0:140:f08b:4f35 with SMTP id l22-20020a056358279600b00140f08b4f35mr10650190rwb.21.1695753218342; Tue, 26 Sep 2023 11:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695753218; cv=none; d=google.com; s=arc-20160816; b=pViETPc4lXp324VNTv01FcXqCbgX5Kouudn4uCFvJu6X0VFN0v26D5PxyXA5YZSvfk TLzSevAu/thlEzbbK6z/9XQDZyvGLSTQ6o29eVzhLkDXXexPZ6/DYnAxO2gpyKUts0zL MdHJBwGr/gMLyUJVcAdg+gS0r9OBFu+nc4dh1dLu7U0pcKBEGLiYSSMMcZ5HDTJz/nSt DrsYwu6Cru7oLk6c5bsquQ68Jw6ay2TRj6waNAvRetlW0Y5mhNAJ6+/+akU50HI3A7ab tiUdna5NznWWVn7O12W8zY7ibnJZ8MVOU+5RRc4T6hz3YIDCWCohHvyKCZnL5UPKB5VT azeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Hl8P0PehXe7JNy/kAUbNrPxe3ImQTd0Amx2bvocE0Xk=; fh=t1xvhnkFx9bfBDmZernKVuTHx9fbHS24RsGf4w4Mgw8=; b=epQpfSbp4fxk00cFmpu8dkZabchhUhr8Is1MM5iMwvpYph5G6l7M4TrIqBmZj3lQYl EFc7BtRfPkRFlp/yg3mH0uXJD4s5F7Aj0TNReTROM0cK8TJBc1etmr2ebIGHFCppwFBH KLyjifoXviPcOFXXnr3HxHj16zA76jkx69hV/2O+3k8/iCoz12wEHq3EbGcsGIc+isEU ti5vkd42shQHiYEGSBPsebqLXRZS69NH+NRNpBB2kBge/o2aeIrW6PvawXm3WnSMGl62 /nr+eoMFZ4Nnva6QNPkqeYnTEkn8zpjLKHLfua+NNij2WrHx3A69Qx2stSB9zoriKh9K R8dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gb0m8jZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id cn1-20020a056a020a8100b0057776b67494si12744453pgb.887.2023.09.26.11.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 11:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gb0m8jZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D9D7B8052BD1; Tue, 26 Sep 2023 10:21:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232450AbjIZRVe (ORCPT + 99 others); Tue, 26 Sep 2023 13:21:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229570AbjIZRVd (ORCPT ); Tue, 26 Sep 2023 13:21:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9758DCE for ; Tue, 26 Sep 2023 10:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695748838; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hl8P0PehXe7JNy/kAUbNrPxe3ImQTd0Amx2bvocE0Xk=; b=gb0m8jZcRHvSDdvXSmNAfPRHH6ibgme5xawboY0+kT0wHaY9RAJTvs7sA8U5ritv8hhmJz QFL1ZGYoWjQzWMLCclZ3T+hVnSKDUdN5em/P5pFU47Myrk/BAC4LV7YRs531GTkdGhL0Tj puaOKlFohXnIdT3KBYTF/wR2C8tZI4k= Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-327-wJ9wqXIGOqKzK0G9d48-FA-1; Tue, 26 Sep 2023 13:20:37 -0400 X-MC-Unique: wJ9wqXIGOqKzK0G9d48-FA-1 Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-45289b05c67so5110583137.2 for ; Tue, 26 Sep 2023 10:20:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695748836; x=1696353636; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hl8P0PehXe7JNy/kAUbNrPxe3ImQTd0Amx2bvocE0Xk=; b=ELY8SPYD5oyvhispsx25B+PIevd6OHMvAzUET6oqzqLCK5nQTByXWdTZiKsJqs2tIA tOj3w3jSnlfn9bSqMzEqapITwFcLGKJGG82j1l+Ug618rg1N88MwPNPB+l+aaayXGor9 ZlQNpdn7wvRJFs1inSE6a+a8FfzplAaCf/IUNQSW2IHLn4gTUFm1bh0jRtxpWceE6WQL shZ81Uhy075h+hLTuEB2YdiQqi0tBom21svDipGdmOzRv0lLVK+DhV2XgvNhhImTY6no hYOd18u11NXl5eE3dcpyY8PyTLZI8Zn/V+N9D4Y4OWKsYbZI4mvjWiKpTmOI7p+GU+1V waNA== X-Gm-Message-State: AOJu0Yz3BBWM90el1eIt8sPWNQbpPQ6F0ii0wU3u7Z8aRaM6z61iVgpw 7J2iE1FiUM+ZtZbkcstG35fK+hd4V/iob5tOwP68UQdX2L9t2THBiGNoBAIdnJ+OkPTBe9sQS8z g9d61vtxb7XRIzyyL8qI08xR8nvxBwMv3JhavfVtN X-Received: by 2002:a67:b40c:0:b0:452:5df8:b951 with SMTP id x12-20020a67b40c000000b004525df8b951mr7866122vsl.25.1695748836514; Tue, 26 Sep 2023 10:20:36 -0700 (PDT) X-Received: by 2002:a67:b40c:0:b0:452:5df8:b951 with SMTP id x12-20020a67b40c000000b004525df8b951mr7866096vsl.25.1695748836240; Tue, 26 Sep 2023 10:20:36 -0700 (PDT) MIME-Version: 1.0 References: <1b52b557beb6606007f7ec5672eab0adf1606a34.camel@infradead.org> <3dc66987-49c7-abda-eb70-1898181ef3fe@redhat.com> In-Reply-To: From: Paolo Bonzini Date: Tue, 26 Sep 2023 19:20:24 +0200 Message-ID: Subject: Re: [RFC] KVM: x86: Allow userspace exit on HLT and MWAIT, else yield on MWAIT To: Alexander Graf Cc: David Woodhouse , kvm@vger.kernel.org, Peter Zijlstra , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Nicolas Saenz Julienne , "Griffoul, Fred" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Tue, 26 Sep 2023 10:21:33 -0700 (PDT) On Sat, Sep 23, 2023 at 6:44=E2=80=AFPM Alexander Graf wro= te: > On 23.09.23 11:24, Paolo Bonzini wrote: > > Why do you need it? You can just use KVM_RUN to go to sleep, and if yo= u > > get another job you kick out the vCPU with pthread_kill. (I also didn'= t > > get the VSM reference). > > With the original VSM patches, we used to make a vCPU aware of the fact > that it can morph into one of many VTLs. That approach turned out to be > insanely intrusive and fragile and so we're currently reimplementing > everything as VTLs as vCPUs. That allows us to move the majority of VSM > functionality to user space. Everything we've seen so far looks as if > there is no real performance loss with that approach. Yes, that was also what I remember, sharing the FPU somehow while having separate vCPU file descriptors. > One small problem with that is that now user space is responsible for > switching between VTLs: It determines which VTL is currently running and > leaves all others (read: all other vCPUs) as stopped. That means if you > are running happily in KVM_RUN in VTL0 and VTL1 gets an interrupt, user > space needs to stop VTL0 and unpause VTL1 until it triggers VTL_RETURN > at which point VTL1 stops execution and VTL0 runs again. That's with IPIs in VTL1, right? I understand now. My idea was, since we need a link from VTL1 to VTL0 for the FPU, to use the same link to trigger a vmexit to userspace if source VTL > destination VTL. I am not sure how you would handle the case where the destination vCPU is not running; probably by detecting the IPI when VTL0 restarts on the destination vCPU? In any case, making vCPUs poll()-able is sensible. Paolo > Nicolas built a patch that exposes "interrupt on vCPU is pending" as an > ioeventfd user space can request. That way, user space can know whenever > a currently paused vCPU has a pending interrupt and can act accordingly. > You could use the same mechanism if you wanted to implement HLT in user > space, but still use an in-kernel LAPIC.