Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1901941ybz; Sat, 2 May 2020 10:22:13 -0700 (PDT) X-Google-Smtp-Source: APiQypKjJh4Xa+SNHof25Y+yLiYusJVntw70bYo5tWbjFtidAcT+W42941Mf8WeN5BNmza4VBJOO X-Received: by 2002:aa7:d1cc:: with SMTP id g12mr8469958edp.84.1588440133176; Sat, 02 May 2020 10:22:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588440133; cv=none; d=google.com; s=arc-20160816; b=QX7QWkMsOqNtIFJTw43tCb+xsSEPo7+AzbRFWwiEV/cyBrXc6In9wSZRrlgilqNhZh HnnvjGk5qk2AVEoxGFQlIwfx+PcQp983I/pMgnqUZTLUcIzhVx/xHOptRlgkLfbF8/cr NeFla4iTPXZmW09HxxIC5Qc5IPXrCTYiKp7fmK0SpNGcFixyqU9iDpt6ywsJ6K5CIaMw 3BAwTeSmkPHfR1c+1ezJ88Z2K7Lc+9zgpLSndVGsruMBWkCzNVd1HQ1z88c2J6pjfMvk UbW8XbHybRcqD0pA2O777SNDpi9sxm4ZCrBQ/w5XUhRx2eIDFwxS39fgPEp19FPT94gI jU9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=3GUmho2FLAfT35PNKqGTCcuOkwHoviG0UIXTuAz4erg=; b=gULJzw8RMWDXzVS9YcaKCZdh7UEdLJOOauzZ7AYuYmDGjtbCj9lvGrfO7241g1grLh uZ1MQiBYtUoHlGI4/OPJszPTv7lWYipCnb3+bzzi6cfJZbUGTOs3OfIcaWGSbf9l6kOr 32F9G+6FJ3TdnSDoAlTnDJbCSmjpV/hWfEVonzH0c0BB2hUxele5bHI5TlXfGAw0Bu4s MRHP4Fiw2xloNLDwCCWuLOGqQrIV/AgFVi57sVN5tIIJXCKRKCu4xCR2V0tznGXT3zYB 61AE0e/xYZsbY3P1oGxDTb4x++P+icoaj4+oTuWKSQr2Uj+zVpndhdNJxs6dDRYoo+fA FoBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iTEahbx6; 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 a11si2032913edq.562.2020.05.02.10.21.49; Sat, 02 May 2020 10:22:13 -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=iTEahbx6; 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 S1728447AbgEBRUJ (ORCPT + 99 others); Sat, 2 May 2020 13:20:09 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:42294 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728382AbgEBRUJ (ORCPT ); Sat, 2 May 2020 13:20:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588440007; 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=3GUmho2FLAfT35PNKqGTCcuOkwHoviG0UIXTuAz4erg=; b=iTEahbx6dISbiWaj2P0SrIne2OQ9YYu3L8VUfcPHMXl7ZgbrAwBQ5xvb0sOAkDjfgEDIHB mNwvzK31oXkzXwTbsy6SAzdDb2C6S4zRReWKY0YuXPDigR5Auk53l7r/X3dq8w1GucrWeS as1LuKv7VNH5XK3eZIVleJUXTlQbcYc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-331-3lkw48_uN0yaMh3w4L_gFg-1; Sat, 02 May 2020 13:20:05 -0400 X-MC-Unique: 3lkw48_uN0yaMh3w4L_gFg-1 Received: by mail-wr1-f69.google.com with SMTP id z8so481897wrp.7 for ; Sat, 02 May 2020 10:20:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3GUmho2FLAfT35PNKqGTCcuOkwHoviG0UIXTuAz4erg=; b=Dtz5dojg//8WB5QwQ8IU9u3KwgO4lm9j+0apDBCfG1CJJyHPvL+NLN87t5fUvaX5c3 dUHP9XTFpNi/YcSk4p+wNbadDL7Y0AFP4+JMDMIjRMSycYbRF0MreCw9nwtwj1UmZzFh rRkMJjWP8ER3EqqG5YFfLcStfxEsjn/3FKSbPVxHqdKrzRlFG+53N8DfBLTnAV45yopz 52SdCw/uocNvejp8MVBNoqK7OpwrpQb7Z3EPVKCQDhcDtRfGtxasAHFy2a1c9KOJ/9V/ gealOIX8BLK3gACiqA1uQflN91mtFBBLcYQAwD8Y0GN7uxUMI60AN9CkgXaKv0AHvJD4 MlsA== X-Gm-Message-State: AGi0Pubgy8vyCqhWUzpEa2Pv1/Co6Am8ROLQ1yejfpgoZyAgYMQFKlyk jSpw59XsNO3jm3jSm7pnfdO81sFuOc8mxrb+kPUrqtbD9sA66h4gsU7p72ABVGgXppT7KWZ+wmp +rcygkSMnmTe4vB+Aa6Q1stVh X-Received: by 2002:adf:ab1b:: with SMTP id q27mr10914203wrc.220.1588440004541; Sat, 02 May 2020 10:20:04 -0700 (PDT) X-Received: by 2002:adf:ab1b:: with SMTP id q27mr10912510wrc.220.1588439974357; Sat, 02 May 2020 10:19:34 -0700 (PDT) Received: from [192.168.10.150] ([93.56.170.5]) by smtp.gmail.com with ESMTPSA id c83sm5680943wmd.23.2020.05.02.10.19.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 May 2020 10:19:33 -0700 (PDT) Subject: Re: [PATCH v2] kvm: ioapic: Introduce arch-specific check for lazy update EOI mechanism To: Suravee Suthikulpanit , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: rkrcmar@redhat.com, joro@8bytes.org, jon.grimm@amd.com, borisvk@bstnet.org References: <1588411495-202521-1-git-send-email-suravee.suthikulpanit@amd.com> From: Paolo Bonzini Message-ID: Date: Sat, 2 May 2020 19:19:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <1588411495-202521-1-git-send-email-suravee.suthikulpanit@amd.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/05/20 11:24, Suravee Suthikulpanit wrote: > This is due to re-entrancy of the lazy update EOI logic > when enable APICv with VFIO pass-through device, which > sets up kvm_irqfd() w/ KVM_IRQFD_FLAG_RESAMPLE. > > Fixes by adding re-entrancy check logic. This does not explain why this is the right fix. The questions to answer are: what is causing the re-entrancy? and why is dropping the second EOI update safe? The answer to the latter could well be "because we've already processed it", but the answer to the former is more important. The re-entrancy happens because the irq state is the OR of the interrupt state and the resamplefd state. That is, we don't want to show the state as 0 until we've had a chance to set the resamplefd. But if the interrupt has _not_ gone low then we get an infinite loop. So the actual root cause is that this is a level-triggered interrupt, otherwise irqfd_inject would immediately set the KVM_USERSPACE_IRQ_SOURCE_ID high and then low and you wouldn't have the infinite loop. But in the case of level-triggered interrupts the VMEXIT already happens because TMR is set; only edge-triggered interrupts need the lazy invocation of the ack notifier. So this should be the fix: diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c index 7668fed1ce65..ca2d73cd00a3 100644 --- a/arch/x86/kvm/ioapic.c +++ b/arch/x86/kvm/ioapic.c @@ -225,12 +225,12 @@ static int ioapic_set_irq(struct kvm_ioapic *ioapic, unsigned int irq, } /* - * AMD SVM AVIC accelerate EOI write and do not trap, - * in-kernel IOAPIC will not be able to receive the EOI. + * AMD SVM AVIC accelerate EOI write iff the interrupt is level + * triggered, in-kernel IOAPIC will not be able to receive the EOI. * In this case, we do lazy update of the pending EOI when * trying to set IOAPIC irq. */ - if (kvm_apicv_activated(ioapic->kvm)) + if (edge && kvm_apicv_activated(ioapic->kvm)) ioapic_lazy_update_eoi(ioapic, irq); /* Did I miss anything in the above analysis with respect to AVIC? Paolo