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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D8E5C433F5 for ; Wed, 27 Oct 2021 22:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23E5460240 for ; Wed, 27 Oct 2021 22:09:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbhJ0WMV (ORCPT ); Wed, 27 Oct 2021 18:12:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40236 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229792AbhJ0WMN (ORCPT ); Wed, 27 Oct 2021 18:12:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635372587; 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=vPTDsq9RY16fTCCoMhEcqKhkYxR/hT5AGgzHMhJ6ojY=; b=GW84Vw7pza+og6AlQkSStDCr+1P5nspQ7TtvSEueKXYKAkG62c75otaTSgTDcHmZeCWVfT uwTNQTOGQCU7TvhtCZdIIeGUW18IXf5YInxnS1/X/q/y1v6tUSxRouck3/RjgSajycTUij gK+XzfOD7Ppyo2nzL6zjKY+Izr8o0ZI= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-604-4klXvBO4NxeINm1YwrfHNA-1; Wed, 27 Oct 2021 18:09:45 -0400 X-MC-Unique: 4klXvBO4NxeINm1YwrfHNA-1 Received: by mail-ed1-f70.google.com with SMTP id d11-20020a50cd4b000000b003da63711a8aso3609657edj.20 for ; Wed, 27 Oct 2021 15:09:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=vPTDsq9RY16fTCCoMhEcqKhkYxR/hT5AGgzHMhJ6ojY=; b=DHcVY1YQzLtziC4hDuV9vnEuuTqtwxUKLvtgAq5rXJ1r5tgaBhU2heXVwQmrEgLm15 p4SihdYIYBUsJ3ImMuIgppJ4DZpNQoeWsPTjQCftkKT8mvR3PofG0Oi6rWsD9QjGwGL/ ZFUYTPCw/75b9WdrL+JS35YD66oPGO97zeg8Jv0T0fvuA56F8kOkgexgVC2AlM8Dh2E4 4f43CYm2IqIupYJmD+FUie37DMfxvAEpVGV0Qxu/1gbmrc2Z1VLVEYQ6JtaKa3R1+Bxn GCvg6Fh780vUi12KCcB21qOj61qHCX2H5Oh5TJ2ghZsrtzFkTQUixERbYC7YjL5r7UL5 /TbA== X-Gm-Message-State: AOAM533ItJYvde2gS1xoYmSX/K4LePKgGNwAOrU4BScsMjbjjHUwFcUE k/4NQIaiHg67p+lFvL2Sz/uPRl7umHkz3tEU8mmlJwVmX/EKOAFJal++Z6PHcJ1rJf7ELrClOnG +k+GCBzEaACdt2YPWux018/po X-Received: by 2002:a17:906:3f95:: with SMTP id b21mr341849ejj.368.1635372584297; Wed, 27 Oct 2021 15:09:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoBx4vKjR30o+Kgjfdb4KsDUE6yjTUINxxdU8F5+6sRGk01DyvRy4bEl13EnJPgWSCV29mNQ== X-Received: by 2002:a17:906:3f95:: with SMTP id b21mr341810ejj.368.1635372584078; Wed, 27 Oct 2021 15:09:44 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id a9sm675279edm.31.2021.10.27.15.09.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Oct 2021 15:09:43 -0700 (PDT) Message-ID: Date: Thu, 28 Oct 2021 00:09:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v2 39/43] KVM: VMX: Don't do full kick when triggering posted interrupt "fails" Content-Language: en-US To: Sean Christopherson Cc: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , Oliver Upton , Jing Zhang References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-40-seanjc@google.com> <335822ac-b98b-1eec-4911-34e4d0e99907@redhat.com> From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27/10/21 18:04, Sean Christopherson wrote: >>> + /* >>> + * The smp_wmb() in kvm_make_request() pairs with the smp_mb_*() >>> + * after setting vcpu->mode in vcpu_enter_guest(), thus the vCPU >>> + * is guaranteed to see the event request if triggering a posted >>> + * interrupt "fails" because vcpu->mode != IN_GUEST_MODE. >> >> What this smp_wmb() pair with, is the smp_mb__after_atomic in >> kvm_check_request(KVM_REQ_EVENT, vcpu). > > I don't think that's correct. There is no kvm_check_request() in the relevant path. > kvm_vcpu_exit_request() uses kvm_request_pending(), which is just a READ_ONCE() > without a barrier. Ok, we are talking about two different set of barriers. This is mine: - smp_wmb() in kvm_make_request() pairs with the smp_mb__after_atomic() in kvm_check_request(); it ensures that everything before the request (in this case, pi_pending = true) is seen by inject_pending_event. - pi_test_and_set_on() orders the write to ON after the write to PIR, pairing with vmx_sync_pir_to_irr and ensuring that the bit in the PIR is seen. And this is yours: - pi_test_and_set_on() _also_ orders the write to ON before the read of vcpu->mode, pairing with vcpu_enter_guest() - kvm_make_request() however does _not_ order the write to vcpu->requests before the read of vcpu->mode, even though it's needed. Usually that's handled by kvm_vcpu_exiting_guest_mode(), but in this case vcpu->mode is read in kvm_vcpu_trigger_posted_interrupt. So vmx_deliver_nested_posted_interrupt() is missing a smp_mb__after_atomic(). It's documentation only for x86, but still easily done in v3. Paolo 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E23FC433EF for ; Wed, 27 Oct 2021 22:10:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C5FE60E75 for ; Wed, 27 Oct 2021 22:10:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0C5FE60E75 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gmSkob7EcEGXD0/0vnTxDNFFs5QHhgbjwC4CJGNPrk8=; b=juP1wXX0hH7bKR WZ1bqLQ0IcoNHLtpF7yvR+iYO6uud/zZRX0hdXPGLiMWOYuKyDO57CAgBoAdhG34Z97gmLuYDU6Qs Kk/PDcHQ0U6fPil4o2DHL59d/gFjV7tOeBDj8AzqAfjn4OuY599IbpdR1FgOtBtSXW0zKi2oAC9RZ CFQHiAAq9tnBr2EA+xD1Z9itbSsZsdfD1S5Y5VWiOfQe3r9ynZHUAs4yKnBqklhEZVvrHohPkkIas T9ymgvjVKLx85iahL5jmHIk93bd5ZnPdpC+9mJI8wNYwECjiT6xfnXffZ9YMm0w37xRZU0cgG6WRW 8c9D01qXSeK9yqepFpvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfr7U-006NNN-60; Wed, 27 Oct 2021 22:10:04 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfr7E-006NKB-Eo for linux-riscv@lists.infradead.org; Wed, 27 Oct 2021 22:09:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635372586; 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=vPTDsq9RY16fTCCoMhEcqKhkYxR/hT5AGgzHMhJ6ojY=; b=IAMcVO2ZcNaowSZesQXSUgOlxjCPhD3/D2HXDPcFh1EopPVgQ9wn/KzZ5ozVodm9vqYUFk TLB0aam8jfFrNaskFFG31AK/zseq6GosXpGUChclsiesCnNx+uv9OssMo6XO+h+p4p+Dyi 8CR1nGCKg1wkY2PNBXQg3WXk38p5uNQ= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-604-U1HHjXwmPRScZwNrXBh2yA-1; Wed, 27 Oct 2021 18:09:45 -0400 X-MC-Unique: U1HHjXwmPRScZwNrXBh2yA-1 Received: by mail-ed1-f70.google.com with SMTP id g6-20020a056402424600b003dd2b85563bso3656251edb.7 for ; Wed, 27 Oct 2021 15:09:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=vPTDsq9RY16fTCCoMhEcqKhkYxR/hT5AGgzHMhJ6ojY=; b=VzH79m4/XBIGyudo/bcbuoA5LdcsiAKUQnQ/1xLoeOfvIeDv7Wms9Au9ZTiZ1uvMNM PgoG6TEmOnbwuwL0Rb+VtKFq4MnNAlzFm+jJQmeIxqO+M6SpVWRAEX0vMVxqfpINrw/Q gmHG715g7h8wyMPe7ohRxPESn92eGQDlZ5q6XfupAQ9QHXZK1iMHh5fzVjjWpDijJcEk Fk/ctV9t1qJDGTAys4ZN3NMlFLxOjlzD3uM9GIs1Nef7Dd4vjwJIAC+dgXQL3/L6OPcb Hqq6MfvtxP2WXPUjJIKcaIetTrgXjQZE4q4defj4cePdnhDFNnccQmQJg31/cnykQgDN LGJg== X-Gm-Message-State: AOAM533rNiPYK4NEU6qjs1KhV17m6hvBjS7exXyi+JQU+QXKRBGsEQRG XpFt3SrEvtMjxL83h5P+Kg+H+KNeRJpneM4+uXSgcezLCsK58zwugMB4o+mosiBah+biSt+MyBw q5UHzK6zqanupWWXhJKKyMWKPo3Mq X-Received: by 2002:a17:906:3f95:: with SMTP id b21mr341867ejj.368.1635372584308; Wed, 27 Oct 2021 15:09:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoBx4vKjR30o+Kgjfdb4KsDUE6yjTUINxxdU8F5+6sRGk01DyvRy4bEl13EnJPgWSCV29mNQ== X-Received: by 2002:a17:906:3f95:: with SMTP id b21mr341810ejj.368.1635372584078; Wed, 27 Oct 2021 15:09:44 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id a9sm675279edm.31.2021.10.27.15.09.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Oct 2021 15:09:43 -0700 (PDT) Message-ID: Date: Thu, 28 Oct 2021 00:09:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v2 39/43] KVM: VMX: Don't do full kick when triggering posted interrupt "fails" To: Sean Christopherson Cc: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , Oliver Upton , Jing Zhang References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-40-seanjc@google.com> <335822ac-b98b-1eec-4911-34e4d0e99907@redhat.com> From: Paolo Bonzini In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211027_150948_644651_71DFFC5A X-CRM114-Status: GOOD ( 10.38 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On 27/10/21 18:04, Sean Christopherson wrote: >>> + /* >>> + * The smp_wmb() in kvm_make_request() pairs with the smp_mb_*() >>> + * after setting vcpu->mode in vcpu_enter_guest(), thus the vCPU >>> + * is guaranteed to see the event request if triggering a posted >>> + * interrupt "fails" because vcpu->mode != IN_GUEST_MODE. >> >> What this smp_wmb() pair with, is the smp_mb__after_atomic in >> kvm_check_request(KVM_REQ_EVENT, vcpu). > > I don't think that's correct. There is no kvm_check_request() in the relevant path. > kvm_vcpu_exit_request() uses kvm_request_pending(), which is just a READ_ONCE() > without a barrier. Ok, we are talking about two different set of barriers. This is mine: - smp_wmb() in kvm_make_request() pairs with the smp_mb__after_atomic() in kvm_check_request(); it ensures that everything before the request (in this case, pi_pending = true) is seen by inject_pending_event. - pi_test_and_set_on() orders the write to ON after the write to PIR, pairing with vmx_sync_pir_to_irr and ensuring that the bit in the PIR is seen. And this is yours: - pi_test_and_set_on() _also_ orders the write to ON before the read of vcpu->mode, pairing with vcpu_enter_guest() - kvm_make_request() however does _not_ order the write to vcpu->requests before the read of vcpu->mode, even though it's needed. Usually that's handled by kvm_vcpu_exiting_guest_mode(), but in this case vcpu->mode is read in kvm_vcpu_trigger_posted_interrupt. So vmx_deliver_nested_posted_interrupt() is missing a smp_mb__after_atomic(). It's documentation only for x86, but still easily done in v3. Paolo _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4FD9C433EF for ; Wed, 27 Oct 2021 22:09:55 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 444AA60240 for ; Wed, 27 Oct 2021 22:09:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 444AA60240 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 9BDDB4B16F; Wed, 27 Oct 2021 18:09:54 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@redhat.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jDb7A+b3v-nw; Wed, 27 Oct 2021 18:09:53 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 6B8694B172; Wed, 27 Oct 2021 18:09:53 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id AE7C44B163 for ; Wed, 27 Oct 2021 18:09:51 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y9B3-xHZL-iz for ; Wed, 27 Oct 2021 18:09:49 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 18C8E4B150 for ; Wed, 27 Oct 2021 18:09:49 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635372588; 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=vPTDsq9RY16fTCCoMhEcqKhkYxR/hT5AGgzHMhJ6ojY=; b=QcVXeKEmQ69d40jmh2rSlNCMAvXOH8wEQoTteJ2ZCqaUPE4nawlaLMza2KM3ogSDNOdNQb oeaI2FD7I3OqFzJ4HzDzFD70xp76Q0GpA6eYqCtDeKeky1jkdGvhqa2AErGIdMdRegP/TC kn9G2knclNOUrf26owqjCl4DcZczWE0= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-223-DyDWeTxqOqKQ2yoavIaRYA-1; Wed, 27 Oct 2021 18:09:45 -0400 X-MC-Unique: DyDWeTxqOqKQ2yoavIaRYA-1 Received: by mail-ed1-f69.google.com with SMTP id g6-20020a056402424600b003dd2b85563bso3656252edb.7 for ; Wed, 27 Oct 2021 15:09:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=vPTDsq9RY16fTCCoMhEcqKhkYxR/hT5AGgzHMhJ6ojY=; b=aD6hdjHxPKuijGUOAd0HVKyFZ7iYnlZOprmMvygyCLoPKaUYDr3+ldRHvhCNWoBk/K DvXh0iMjq/Oq8CGy+E0HMJy9s9yrciKvrTrVjd5O7I/irGf5gHbhUZeF5fp4XLCOYlS7 dRZS1gNq0SD7kBFS0Bra3oV22I2f6bMeJfNvyrq2+V7BDj3EKQwKWikPzIoOrHQJN+eJ HGwukd66oWMCx5aJchre8VuN7YNrolNuLmdpcaV39uWbjPtZsNICcWSSpBVinU0eRR1d K+TJjspRBNRxDt20NcI7lNwRGplQG5xRDUtZ8ZeTfQiEgC0l+E/Tw63YELOOqtzdVCgO rKdw== X-Gm-Message-State: AOAM530VXoL0QLZSDARoyZN47T0U2rgW82pg/scb0w9mn/5LKCMdqmEZ jgbYkBtkuElA2SQiw0Cny3czTNyx606zuDOa1K7dJYesVsi8cBJlpSaG3RZyf097w7kVD9fYup7 mSdnlPP64oE2AinfxSYentbfR X-Received: by 2002:a17:906:3f95:: with SMTP id b21mr341853ejj.368.1635372584298; Wed, 27 Oct 2021 15:09:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoBx4vKjR30o+Kgjfdb4KsDUE6yjTUINxxdU8F5+6sRGk01DyvRy4bEl13EnJPgWSCV29mNQ== X-Received: by 2002:a17:906:3f95:: with SMTP id b21mr341810ejj.368.1635372584078; Wed, 27 Oct 2021 15:09:44 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id a9sm675279edm.31.2021.10.27.15.09.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Oct 2021 15:09:43 -0700 (PDT) Message-ID: Date: Thu, 28 Oct 2021 00:09:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v2 39/43] KVM: VMX: Don't do full kick when triggering posted interrupt "fails" To: Sean Christopherson References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-40-seanjc@google.com> <335822ac-b98b-1eec-4911-34e4d0e99907@redhat.com> From: Paolo Bonzini In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Cc: Cornelia Huck , Wanpeng Li , kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, Paul Mackerras , Atish Patra , linux-riscv@lists.infradead.org, Claudio Imbrenda , kvmarm@lists.cs.columbia.edu, Janosch Frank , Marc Zyngier , Joerg Roedel , Huacai Chen , Christian Borntraeger , Aleksandar Markovic , Albert Ou , kvm-ppc@vger.kernel.org, Paul Walmsley , David Matlack , linux-arm-kernel@lists.infradead.org, Jim Mattson , Anup Patel , linux-mips@vger.kernel.org, Palmer Dabbelt , kvm-riscv@lists.infradead.org, Vitaly Kuznetsov X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On 27/10/21 18:04, Sean Christopherson wrote: >>> + /* >>> + * The smp_wmb() in kvm_make_request() pairs with the smp_mb_*() >>> + * after setting vcpu->mode in vcpu_enter_guest(), thus the vCPU >>> + * is guaranteed to see the event request if triggering a posted >>> + * interrupt "fails" because vcpu->mode != IN_GUEST_MODE. >> >> What this smp_wmb() pair with, is the smp_mb__after_atomic in >> kvm_check_request(KVM_REQ_EVENT, vcpu). > > I don't think that's correct. There is no kvm_check_request() in the relevant path. > kvm_vcpu_exit_request() uses kvm_request_pending(), which is just a READ_ONCE() > without a barrier. Ok, we are talking about two different set of barriers. This is mine: - smp_wmb() in kvm_make_request() pairs with the smp_mb__after_atomic() in kvm_check_request(); it ensures that everything before the request (in this case, pi_pending = true) is seen by inject_pending_event. - pi_test_and_set_on() orders the write to ON after the write to PIR, pairing with vmx_sync_pir_to_irr and ensuring that the bit in the PIR is seen. And this is yours: - pi_test_and_set_on() _also_ orders the write to ON before the read of vcpu->mode, pairing with vcpu_enter_guest() - kvm_make_request() however does _not_ order the write to vcpu->requests before the read of vcpu->mode, even though it's needed. Usually that's handled by kvm_vcpu_exiting_guest_mode(), but in this case vcpu->mode is read in kvm_vcpu_trigger_posted_interrupt. So vmx_deliver_nested_posted_interrupt() is missing a smp_mb__after_atomic(). It's documentation only for x86, but still easily done in v3. Paolo _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C6B6C433EF for ; Wed, 27 Oct 2021 22:11:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 367D560240 for ; Wed, 27 Oct 2021 22:11:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 367D560240 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vYl9wAOsWj1zGK+YBW0y/A711zrUG2ZVPyUwRPcRggY=; b=3tgHihSEgRCY3j +w+nUoOU647oc5PMUJz2qKW8adbA6W8gEazLvdY3vBT46H+8lJ1hQ9W8lzIrx6ucQR3Lk+LBFrD+d /o9KSjVw7vzxFQq9b9uEwUQdSM0CgvHGJauFhxZvQFb9bQ4qGRupXHSyY939HBdP2wLraG73dmTM4 71uI+FZM+2xDcVBMf55H5pJnmSjTANSrkxH+WLQBULvEzbVSiQ+I2fq56Y7ohWCNsnYHyyPtL8Xod eZwQf3hQRi/zdgHd9B88hMCLW/wAwn0tEP1mPPB+Wpe6ZntRN8cSQgnWkPZBjfhp/zl7fvd+a0IaE 3RkUUg5p7luzxqbTaPdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfr7I-006NLO-Gu; Wed, 27 Oct 2021 22:09:52 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfr7E-006NKC-En for linux-arm-kernel@lists.infradead.org; Wed, 27 Oct 2021 22:09:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635372586; 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=vPTDsq9RY16fTCCoMhEcqKhkYxR/hT5AGgzHMhJ6ojY=; b=IAMcVO2ZcNaowSZesQXSUgOlxjCPhD3/D2HXDPcFh1EopPVgQ9wn/KzZ5ozVodm9vqYUFk TLB0aam8jfFrNaskFFG31AK/zseq6GosXpGUChclsiesCnNx+uv9OssMo6XO+h+p4p+Dyi 8CR1nGCKg1wkY2PNBXQg3WXk38p5uNQ= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-604-lCgxOz61NxO_lcjUgke5Kw-1; Wed, 27 Oct 2021 18:09:45 -0400 X-MC-Unique: lCgxOz61NxO_lcjUgke5Kw-1 Received: by mail-ed1-f72.google.com with SMTP id v21-20020a056402349500b003dfa41553f3so75807edc.11 for ; Wed, 27 Oct 2021 15:09:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=vPTDsq9RY16fTCCoMhEcqKhkYxR/hT5AGgzHMhJ6ojY=; b=g1ZU4Mi91ssbgvPNreKLiSxmm3p3fvdtkdCW4B3OfZzljTZo+VfETJglX814YfmrDD QqaJhcpyIMWn82AIwAQb5w6/hdQsnqWkJiVoNkt/Qs4VSagURMNQjeZyvA2LmOXySKFj 9EKHewnzRv46FrU2dEMz82dEMISRw7ReD9OEgxPq+lQ9qXyTYcVGD4fks6CxAbcvG9D4 FGyMTPJQKty3BKtKXYx9rTC7ydpGnkxCosIB3jFpKV5eRWnb+n+tExyujzFR6K2/qwyA WQSyViDgYQLjMs409hOJqT2aA3b/sfQssnwC4Ij70k5AhgOI5vCPOKy2cZRilc+3XdJ8 Z9tg== X-Gm-Message-State: AOAM530fjnJDfjdsd7aKZY67FLD9KDWkJyRMzS+724VTcRWWwpR9oNor jfaZHbCKF5RvDGaGvNb1oBhPEVgnoRjwYKOQYcbhoLMo2G41inVK72SvQ9eOhgVnBaTs9kzOPrL YVURZC0rqSBi/w6WVvNQvXhbaM27XVQp7NAg= X-Received: by 2002:a17:906:3f95:: with SMTP id b21mr341846ejj.368.1635372584296; Wed, 27 Oct 2021 15:09:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoBx4vKjR30o+Kgjfdb4KsDUE6yjTUINxxdU8F5+6sRGk01DyvRy4bEl13EnJPgWSCV29mNQ== X-Received: by 2002:a17:906:3f95:: with SMTP id b21mr341810ejj.368.1635372584078; Wed, 27 Oct 2021 15:09:44 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id a9sm675279edm.31.2021.10.27.15.09.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Oct 2021 15:09:43 -0700 (PDT) Message-ID: Date: Thu, 28 Oct 2021 00:09:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v2 39/43] KVM: VMX: Don't do full kick when triggering posted interrupt "fails" To: Sean Christopherson Cc: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , Oliver Upton , Jing Zhang References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-40-seanjc@google.com> <335822ac-b98b-1eec-4911-34e4d0e99907@redhat.com> From: Paolo Bonzini In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211027_150948_638353_656652F1 X-CRM114-Status: GOOD ( 11.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 27/10/21 18:04, Sean Christopherson wrote: >>> + /* >>> + * The smp_wmb() in kvm_make_request() pairs with the smp_mb_*() >>> + * after setting vcpu->mode in vcpu_enter_guest(), thus the vCPU >>> + * is guaranteed to see the event request if triggering a posted >>> + * interrupt "fails" because vcpu->mode != IN_GUEST_MODE. >> >> What this smp_wmb() pair with, is the smp_mb__after_atomic in >> kvm_check_request(KVM_REQ_EVENT, vcpu). > > I don't think that's correct. There is no kvm_check_request() in the relevant path. > kvm_vcpu_exit_request() uses kvm_request_pending(), which is just a READ_ONCE() > without a barrier. Ok, we are talking about two different set of barriers. This is mine: - smp_wmb() in kvm_make_request() pairs with the smp_mb__after_atomic() in kvm_check_request(); it ensures that everything before the request (in this case, pi_pending = true) is seen by inject_pending_event. - pi_test_and_set_on() orders the write to ON after the write to PIR, pairing with vmx_sync_pir_to_irr and ensuring that the bit in the PIR is seen. And this is yours: - pi_test_and_set_on() _also_ orders the write to ON before the read of vcpu->mode, pairing with vcpu_enter_guest() - kvm_make_request() however does _not_ order the write to vcpu->requests before the read of vcpu->mode, even though it's needed. Usually that's handled by kvm_vcpu_exiting_guest_mode(), but in this case vcpu->mode is read in kvm_vcpu_trigger_posted_interrupt. So vmx_deliver_nested_posted_interrupt() is missing a smp_mb__after_atomic(). It's documentation only for x86, but still easily done in v3. Paolo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Date: Wed, 27 Oct 2021 22:09:25 +0000 Subject: Re: [PATCH v2 39/43] KVM: VMX: Don't do full kick when triggering posted interrupt "fails" Message-Id: List-Id: References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-40-seanjc@google.com> <335822ac-b98b-1eec-4911-34e4d0e99907@redhat.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Sean Christopherson Cc: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , Oliver Upton , Jing Zhang On 27/10/21 18:04, Sean Christopherson wrote: >>> + /* >>> + * The smp_wmb() in kvm_make_request() pairs with the smp_mb_*() >>> + * after setting vcpu->mode in vcpu_enter_guest(), thus the vCPU >>> + * is guaranteed to see the event request if triggering a posted >>> + * interrupt "fails" because vcpu->mode != IN_GUEST_MODE. >> >> What this smp_wmb() pair with, is the smp_mb__after_atomic in >> kvm_check_request(KVM_REQ_EVENT, vcpu). > > I don't think that's correct. There is no kvm_check_request() in the relevant path. > kvm_vcpu_exit_request() uses kvm_request_pending(), which is just a READ_ONCE() > without a barrier. Ok, we are talking about two different set of barriers. This is mine: - smp_wmb() in kvm_make_request() pairs with the smp_mb__after_atomic() in kvm_check_request(); it ensures that everything before the request (in this case, pi_pending = true) is seen by inject_pending_event. - pi_test_and_set_on() orders the write to ON after the write to PIR, pairing with vmx_sync_pir_to_irr and ensuring that the bit in the PIR is seen. And this is yours: - pi_test_and_set_on() _also_ orders the write to ON before the read of vcpu->mode, pairing with vcpu_enter_guest() - kvm_make_request() however does _not_ order the write to vcpu->requests before the read of vcpu->mode, even though it's needed. Usually that's handled by kvm_vcpu_exiting_guest_mode(), but in this case vcpu->mode is read in kvm_vcpu_trigger_posted_interrupt. So vmx_deliver_nested_posted_interrupt() is missing a smp_mb__after_atomic(). It's documentation only for x86, but still easily done in v3. Paolo