Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp246911pxb; Mon, 25 Oct 2021 07:33:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdIXE2nUCkKpBgcRdo1KY7Om2hj7vfNwZKjXRoUHJiz6Ka6pGmIj4qYEGGvCtZyXeKV5Sr X-Received: by 2002:a17:90b:4f46:: with SMTP id pj6mr21117486pjb.63.1635172383933; Mon, 25 Oct 2021 07:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635172383; cv=none; d=google.com; s=arc-20160816; b=sIaLCzV2C/pf1GlcFA85XHK9UTgNSff0rTs4t135RoGiC5DydVHuUsxnzyum4j/I8a UkeIX3DbO6zKyfZAPk3ASzUPLObMM1HlyrZKngln/9QX7oyC+IslaukHGE3ANpp8ClPz uGZB1SaH2+NhnLrN0zTf+DMljNxQnhWmo/Yv+jH+hLZHOB9R06j9BGswfZrDKRq9vTcW rnNh2sQNmOOkkBphpqM24etYBwgtKCBeO/hUqEUpMNK+K2OFM84Lp2lQ9BgPwqXbxxCX YDQJ53A8l8Kyvr5BLeQtdS7ANSNpVN/rM+5EAAsj7D3qOvwL+PrYEqhOjRYuSztYk6mp /z3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=5GxuWusEjMHZ4JQn5qLWUyg1MyGQPS66ltUGy4HnHFU=; b=kmfLHAYxfXbQk1GTY7SnvmoZtO7FQCuMNl8hERkNl+9EnNGfg39mL2HBtwyzN3PFDl W3mh2c36bE9B8QbLJ6JI/d8QKMKEfVfS1Q1l3LE6MwCI8dbLwzQCFicXePvfhI9MIt0Q hDqni6meHLK8yHc37tISkTNHad+ncUYfa+XxVdFYv+6q1AkqxvMXk+a4Wv21kRG7mtIB 3gk/OnylI/CghpNPKl8kHHZWb9u/PnLyiERCHV6t+lbP54P/7Xdzr6X9/Xwb5u4z7doy d9AyoczeC3qC1doXqNSaBb66hqOQXnNXUaMOqoEL0ZXVz+6uQqtb5OOyYGB94BeUbOkY u8Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LTAJJXA6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si23681540plt.111.2021.10.25.07.32.49; Mon, 25 Oct 2021 07:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LTAJJXA6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233152AbhJYOEL (ORCPT + 99 others); Mon, 25 Oct 2021 10:04:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46000 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233083AbhJYOEK (ORCPT ); Mon, 25 Oct 2021 10:04:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635170508; 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=5GxuWusEjMHZ4JQn5qLWUyg1MyGQPS66ltUGy4HnHFU=; b=LTAJJXA6gfcvH8FfYagOIEjcLjtfU1pf6A1jqzc9+E74Nzq4xvgT/emRiNrwGpl7EeuaZG rxMUo8rjBjFRlw1ujqmRYrN8yaly/emG/PCs4jUIsivvieTF3mvRkJFgXU3CWw2VIHMg+V IBTgj3rYwZXMbdSyiBwwtz/OPhEVtfA= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-YAQ6iQXcOQmu_4oCsl9cEQ-1; Mon, 25 Oct 2021 10:01:46 -0400 X-MC-Unique: YAQ6iQXcOQmu_4oCsl9cEQ-1 Received: by mail-wm1-f69.google.com with SMTP id 128-20020a1c0486000000b0030dcd45476aso3731604wme.0 for ; Mon, 25 Oct 2021 07:01:46 -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=5GxuWusEjMHZ4JQn5qLWUyg1MyGQPS66ltUGy4HnHFU=; b=hnEYZwIbcMv0B+pA+8vp4HZN82ZKIOaKdWNjMh4LXGOqFuoD0Ov/K6J5+/Oay6pGgQ zB0akNPIjlsN6UrCTdEaBbSwaY+m2PKOtbdgangmDne9tYoryXQVaHrVU8y4oq2Ljm2q ExZN25Yg9zsEsS7hyz+ySuVYAtqtPF788GO9NhZUPGU6VFoc80flZKq2acmT/nLrqJ+A fyPNYzo6/+jrTdjKvkivjTZesHmh6S04aWK77l5GUhDT2kq48LXXA7Z5hnHMjMjk1ebe 3uQ5zl3TFrfAN0kbxVaK+btMmj7JCKRjCC0bOAJZT1qxazpU420LNGa/6WB69OXwve/M Hilg== X-Gm-Message-State: AOAM533bR3DpJznHgnaNwe9ZR/pIOPZjbG7GguvyuJSl3FgoF1NWD02p 0+6X29Npy1OPchqLn7RnF2y1amgxmTr3oR42jGtZrU7P+Ka2koOLgMLdk4y5uWBok3PlZSzlKOY McZIa2sAgUmZWCVpsz7sua1Hn X-Received: by 2002:a5d:59ae:: with SMTP id p14mr23589898wrr.76.1635170505455; Mon, 25 Oct 2021 07:01:45 -0700 (PDT) X-Received: by 2002:a5d:59ae:: with SMTP id p14mr23589820wrr.76.1635170505123; Mon, 25 Oct 2021 07:01:45 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id x2sm5765371wmj.3.2021.10.25.07.01.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Oct 2021 07:01:44 -0700 (PDT) Message-ID: <18e6a656-f583-0ad4-6770-9678be3f5cf4@redhat.com> Date: Mon, 25 Oct 2021 16:01:42 +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 24/43] KVM: VMX: Drop pointless PI.NDST update when blocking Content-Language: en-US To: Sean Christopherson , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank Cc: 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-25-seanjc@google.com> From: Paolo Bonzini In-Reply-To: <20211009021236.4122790-25-seanjc@google.com> 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 09/10/21 04:12, Sean Christopherson wrote: > Don't update Posted Interrupt's NDST, a.k.a. the target pCPU, in the > pre-block path, as NDST is guaranteed to be up-to-date. The comment > about the vCPU being preempted during the update is simply wrong, as the > update path runs with IRQs disabled (from before snapshotting vcpu->cpu, > until after the update completes). Right, it didn't as of commit bf9f6ac8d74969690df1485b33b7c238ca9f2269 (when VT-d posted interrupts were introduced). The interrupt disable/enable pair was added in the same commit that motivated the introduction of the sanity checks: commit 8b306e2f3c41939ea528e6174c88cfbfff893ce1 Author: Paolo Bonzini Date: Tue Jun 6 12:57:05 2017 +0200 KVM: VMX: avoid double list add with VT-d posted interrupts In some cases, for example involving hot-unplug of assigned devices, pi_post_block can forget to remove the vCPU from the blocked_vcpu_list. When this happens, the next call to pi_pre_block corrupts the list. Fix this in two ways. First, check vcpu->pre_pcpu in pi_pre_block and WARN instead of adding the element twice in the list. Second, always do the list removal in pi_post_block if vcpu->pre_pcpu is set (not -1). The new code keeps interrupts disabled for the whole duration of pi_pre_block/pi_post_block. This is not strictly necessary, but easier to follow. For the same reason, PI.ON is checked only after the cmpxchg, and to handle it we just call the post-block code. This removes duplication of the list removal code. At the time, I didn't notice the now useless NDST update. Paolo > The vCPU can get preempted_before_ the update starts, but not during. > And if the vCPU is preempted before, vmx_vcpu_pi_load() is responsible > for updating NDST when the vCPU is scheduled back in. In that case, the > check against the wakeup vector in vmx_vcpu_pi_load() cannot be true as > that would require the notification vector to have been set to the wakeup > vector_before_ blocking. > > Opportunistically switch to using vcpu->cpu for the list/lock lookups, > which presumably used pre_pcpu only for some phantom preemption logic.