Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp403302rwd; Wed, 17 May 2023 21:08:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67F0IyV4Ga5PPcfq/xUVHz+nJA5qgASpP7IfNKtmZlt7M76BNBTiyc9GdEPOFrvnwMXxUC X-Received: by 2002:a05:6a20:7489:b0:104:f9d4:1423 with SMTP id p9-20020a056a20748900b00104f9d41423mr832442pzd.28.1684382915585; Wed, 17 May 2023 21:08:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684382915; cv=none; d=google.com; s=arc-20160816; b=n5glC+0iiWCywiyrdxBstuqaQuMw8MwhE2N84DmDMVaEmHtSzNFA2nWssZ4X5eaW9w iK9WCwJvMzM9G1emxmjCRXIDvCPHlBuz0oxf1Dy9PrJ9oyNxyCYRNpuRh5WFZJ/EuyH2 SCuts/OkS3OtV1LBm/qe3TjPMEd/S/kz6p6DaJbLc+6Xs1jM9EGSIvgadzCatA8c/9NT xDx1odGIuCfA4Uu5D0u+VKv/XFfWDrkwBsjQBboHJ7QCbvRylCu+HUrK5oIFzdgSzSSc xpBecAwkrWNXoOmoe9QhPDJXD8ag5/s4QyEG2mYDXMDdtzXV1N/V52hLLKNpETo3buHX QcOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MwR/MBLwVadvtqxIlhzjVFYQdhCDR7Ii81JaCJPJvZs=; b=I2WmR46zWYOSXgTdqKFIICBE08X35Lu3nphhlmhZcQ8naR2VZ80cjZ1CdNEcnt9XxP IhCP+BQtpYYXkP802gqkOE81mPZfBC8a/Tz3JvhF4+2mo8D73fdCCtwrpA7QzDSVwLxw BLR9jDsJqFIj8jXVRlGu0CCX5pEsgrItPsUAobb4AUhoPpXF/vIC6C2hJ+mFDGo6ezHN 1vLB6PqtB7iV6cxDjKz0OInHKkITGdgN8ltUQSPagdbM9nlLLLApr3nsHvCCU2t2oKDj aj5rtRWD4tIlycV7vo2A3gkYiKpyfmUMIIaN7dCbujrg/rjNdkLLvQ2jcMbwvgT9CIH5 LfTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=VrZI+Xa6; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a633c03000000b005210b2d0807si409012pga.678.2023.05.17.21.08.22; Wed, 17 May 2023 21:08:35 -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=@bytedance.com header.s=google header.b=VrZI+Xa6; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbjERD6d (ORCPT + 99 others); Wed, 17 May 2023 23:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbjERD6c (ORCPT ); Wed, 17 May 2023 23:58:32 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E67DA30E9 for ; Wed, 17 May 2023 20:58:10 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1ae4e49727eso16773935ad.1 for ; Wed, 17 May 2023 20:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684382290; x=1686974290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MwR/MBLwVadvtqxIlhzjVFYQdhCDR7Ii81JaCJPJvZs=; b=VrZI+Xa6/9MhLk/l3U2AToFKZEO4zZxd2Dl/8O31TlPKkWSfJxemmpYpXLU1cGPRlB oyTmKQZcNN9Q8ZVf3BpTO6ovTzg3t/IfRzrKMIVohUAMFJrb3cOQ0gpsE8T9QmETJlC1 E2gYpfH6OW5n3cUvvXjzqyIrhaWDOV3xFwHTENG2LSriCnR55HJky9ZLpgg71aFaFc5S L9I76yVUw2ZKg7j5gi96Qq6nv2bBdBG8jL7jmspxeWXqULRtju790lTI9t4T0OIY2eeT ySEtUAgL8mPhnouDarRYobCr6b9fnca+awWv5YYwVsDMKRZPN/dNF3Q3qSDGugLjpfAa pyFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684382290; x=1686974290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MwR/MBLwVadvtqxIlhzjVFYQdhCDR7Ii81JaCJPJvZs=; b=LIIFSavAhnnJFrOkuCPVZk/Srk5gNW7qQIN9XT3ek3kR3TyB6qxrxjANkKxWaC+Gu5 Y477+e/AlM+8M4Qa6l7kEqAaDJ0iAogaj2Nl8bWYIFrNxMOoj2cjBdugal2NQc3LrQVU SIU+WiaD0QspPtsCk3fz37qe/p6w0GltImbCnvhs3QsI9iYl3DXdNdLOAf0slunVM6SK t9hNvlln1+/mFy+wm5Xn9E4xVbAPinUseEwr7WeM4knPmHTspRiw5RdEHPcPXoncWUkR HcfhVqLrMe1xHsBVOwq51mMupgJ9gLWZpQsB8jRDOKAfelQuq7zaxqqTXmCUCnylxKd4 z3rQ== X-Gm-Message-State: AC+VfDxxw5Y/fmi/d1uuWo4q6BzHGiHcm9oxD31+ajDzW30zb4iYZT27 rKjPBhkuKWkXg+pMTjScxIvoew== X-Received: by 2002:a17:902:d382:b0:1aa:dd14:da98 with SMTP id e2-20020a170902d38200b001aadd14da98mr1219183pld.50.1684382290257; Wed, 17 May 2023 20:58:10 -0700 (PDT) Received: from n37-012-157.byted.org ([180.184.51.70]) by smtp.gmail.com with ESMTPSA id ch9-20020a17090af40900b0024e4aa37b90sm342311pjb.45.2023.05.17.20.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 20:58:09 -0700 (PDT) From: "dengqiao.joey" To: joao.m.martins@oracle.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, seanjc@google.com Subject: Re: [PATCH] KVM: SVM: Update destination when updating pi irte Date: Thu, 18 May 2023 11:58:06 +0800 Message-Id: <20230518035806.938517-1-dengqiao.joey@bytedance.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <3d05fcf1-dad3-826e-03e9-599ced7524b4@oracle.com> References: <3d05fcf1-dad3-826e-03e9-599ced7524b4@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Wed, May 17, 2023 at 11:32 PM Joao Martins wrote: > > On 17/05/2023 13:04, dengqiao.joey wrote: > > This seems to be a different issue. Joao's patch tries to fix the issue > > that IRTE is not changed. The problem I encountered is that IRTE does > > get changed, thus the destination field is also cleared by > > amd_iommu_activate_guest_mode(). > > Whether the amd_iommu_activate_guest_mode() clears the destination field or not > doesn't change the situation I think. So I don't think that is the problem > you're having. amd_iommu_activate_guest_mode() will always make IRTEs with > isRun=0. Which means your VF interrupts get injected via GALog events and the > DestID is meaningless there :/ Even if you leave the old affinity there with > isRun=1 bit it's still wrong as by the time you run the vcpu, the wrong affinity > will be used by the VF. More fundamentally I am not sure that on IRTE routing > updates in the VM that you can look on vcpu->cpu the way you are using it could > be potentially invalid when vcpus are blocked/preempted. You're changing IRTEs > in the whole VM in pi_update_irte() > > My changes essentially handle the fact where IRTEs will be always updated with > the right GATag set in the IRTE ... and then when the vCPU migrates, wakes or > block+unblocks it will change IRTE[DestID] with the new pcpu (which the vcpu is > running on) via amd_iommu_update_ga(). So there's a good chance my changes fixes > your affinity issue. > > Joao Sorry I forgot to mention before that in my application scenario, the vcpu runs on a dedicated isolated cpu and uses "mwait" instead of "halt". So it will not be migrated, blocked/wake and rarely get preempted by other threads. I think your patch can not fix my issue because the vcpu rarely gets the opportunity to execute amd_iommu_update_ga() from vcpu_load(). So each time the interrupt affinity is updated I can observe the loss of VF interrupt. After applying my patch, the problem is solved.