Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1442017lqp; Mon, 15 Apr 2024 06:49:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVBW1Lo0e3vOs9PnozctflGZ8ZMCdKQ2GQ4j7vBS9WOu5nQt9Gjq1vxyG565Yj2sBV+aqM9k0Xqx1G1ylQaw854PvzY00iOWB9Bj0veGg== X-Google-Smtp-Source: AGHT+IHCDLsU2+Ze2GbzAhBJQbGY7wQR6V9HzrEeLty562Ifsnm2sWiJ/wHQ+nQXIj6iF+qrxItB X-Received: by 2002:a05:6a20:3cab:b0:1a7:8828:bca0 with SMTP id b43-20020a056a203cab00b001a78828bca0mr14246475pzj.3.1713188988535; Mon, 15 Apr 2024 06:49:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713188988; cv=pass; d=google.com; s=arc-20160816; b=T4uN3nw5IphLYXafNES6W2Zu+IVIXGQ7JtV2EzBoHyrs/sxuZwhvFk1anoXVz8UE8X CB87aRPBO+RpN6OhbjdhjWd/F7pEGvU76ar+sk1gGguUknrSB6AmHMI2sdf6QYSAieUF Ph9QZFjnSM4jWo1Q4Xqb8u26j2X5Kca5lZevaqOSS2dHDUZp4vG02fHmotZ7CfDYzTAU bbQvsvduBEQpsyjvW4cPYQAncJr8cU85dNxEkhl6N5YB3F2antF5+s0xKuvvWKHHhR49 DcXsqdjrw18wPD+QdON6gI9wIvuyf5WWEkyNwtiCRGk/6kdBY7sG0JhutInk3Tu1WIAs zaAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=xyd56S0l2Vyx+AmnHkLVn8KVbV/FkDbyRlJsdS3u6MA=; fh=ImO9xZDYLNKTCNsDeuXg61faiiNxyHOG9f+pQreqogI=; b=s2edr8fA5R+6N92AS0rSaS5Rm+dn+fmHCc4O/wgpVTVXpfeav2Btc5wccW21VwPHdY lKEo2BOaEFQDY1w5j0wmdhnLMIoYO4fdEcC1JS3IiIGnZ4e3Ql7+2DgVVym1fUt6+8/G sS7suCKIzGOXffsvZg30y2uhTulAkRvvBEh9BCHppnM/CsWvMh7Td+UFaqyfXcN1A6wv xbdBggxYM+xnZ+n/iitnSwwsvm/+4+pFBoRcBbKOVQ5+AHa51ckIuV/kjkssjXHKV0GP JjqaBWBJgmsz3/DH7kri1MHMXeMc2MrZVhcy79XwlTNrh6m5FT3+IczVL//tZ1BoJzCJ 8BiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vhetVyjK; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-145290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145290-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u24-20020a63b558000000b005d8b8f81dd2si8070213pgo.700.2024.04.15.06.49.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 06:49:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vhetVyjK; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-145290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145290-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 38C75280FE1 for ; Mon, 15 Apr 2024 13:49:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0299473191; Mon, 15 Apr 2024 13:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vhetVyjK" Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F08B471B5B for ; Mon, 15 Apr 2024 13:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713188979; cv=none; b=lrsjN6S5bym6cYZmSdmCCVb6SjuWQ1jQm0VJut2QL3Elr0KK8xDc5cmEh/WDitvfFqHoO7urtIme0qtq4B2YLOdrakBDYRAqo/Wu6bphvseBDcrGe3HMPpJEyDB8Fc7wR240RTEZaPs7HCejsctxeANHAr2WZxQWQJqcmSn3UGk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713188979; c=relaxed/simple; bh=TvUNx+79vaopmzaM3PSKeNfcMIwNczVLZHrejGQKVD0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XLdh0B2IE4rzrfQUJTR1Wmh6mAp6sEMelCeq5xiFO3SQaUgmJQt39XTSJzOi/k0VNLAMTKanr5UWpgdShz4L1TGQF3newwhNTWlJHyf+wAGUlwKduvvK4GQG7eYg/ke2Pt7dQcuiD5i8YfLoAiWEjWKKlWj77FiSyQV47Di1Qo0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vhetVyjK; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1e417e43c13so38589035ad.2 for ; Mon, 15 Apr 2024 06:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713188977; x=1713793777; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xyd56S0l2Vyx+AmnHkLVn8KVbV/FkDbyRlJsdS3u6MA=; b=vhetVyjKbC+U/ym5VynQzCHTXf8oCDev7vs++We7Vz8rBWldoPz4iNAk2n5mv4K/z2 ykSgIEjVu2NwQAfgcg1gZI3I8oVuIWO2CJgDenDRx6PDZ1xQeCAqhqHd+VZ3YldrPYqi Q0TAAwlUYA80lVfO0g/DUR3Rdkpkdo0gZZlioUt/YFDgrDyHv3LsPh5sgDKCq7IZXZWb DzFDqrmbclmrkMD3Rwd1qHNrgQXKbNwsX3HXhc+TjyRBHU0axUl1J5BsjQzOcBFncyVO LKETZ1BiLfwoxLadxnpP4wqn5ebiwaoctSU2GHtq8B+73jMAHKnFEBd7dqsc7XoZZIVj O0pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713188977; x=1713793777; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xyd56S0l2Vyx+AmnHkLVn8KVbV/FkDbyRlJsdS3u6MA=; b=PLJKkmfML9J7TPHwXFmup8B+b+r+X+2HM7tP1wgD0ThVxnvDfQiCnGj2xPJSDh00Th 0gGNfg6SU3I8X5DutT/yJ2pyFV2pfrUkbFCi8w0nBF+4EJdldSlcJPuDy2YEjN/K0F05 i+TUHt+dxCJ6Vy/HFZCfrQswXkO57uWESB3J/nRl7NZzqhCF0ZWLbOHudXs0LhwXggUz Jj0hB/2sVdU7QjmV5OyEG03YXPmbNDIVNrAGHoj9tWZ7f+2yYNKQPI3OjuajXGiC4/50 RRLhmbWov4G7Am+YF7qMgkX4zaAloWnnxodZgk36WlX1m9GN9nxfZmMEX1ZF11hNGo2E fGcQ== X-Forwarded-Encrypted: i=1; AJvYcCX0Vnsz7yfccM6hS+FeHC6EICjo2eaYS7yLgUkFW0Ja03KAxedajixA7scDBgqMlITKUpkrNJaw2F+7sb4DsmCew++OTpMo9ZqqSJ3K X-Gm-Message-State: AOJu0Yw3pOM4nc1eRpm/SyfoaPlph/MDL2TaiEoUcy8UAev3qAko51QH B/QeGVRG0HAqCU2riuPALGTqgXD3h44rcmANRxJIXLp1vHxy4ee5Z3B1YbqU3Q4rfaFi0X2nztd 8VA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:da8c:b0:1e5:e651:6099 with SMTP id j12-20020a170902da8c00b001e5e6516099mr727874plx.9.1713188977177; Mon, 15 Apr 2024 06:49:37 -0700 (PDT) Date: Mon, 15 Apr 2024 06:49:35 -0700 In-Reply-To: <20240413004031.GQ3039520@ls.amr.corp.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <0c3efffa-8dd5-4231-8e90-e0241f058a20@intel.com> <20240412214201.GO3039520@ls.amr.corp.intel.com> <20240413004031.GQ3039520@ls.amr.corp.intel.com> Message-ID: Subject: Re: [PATCH v19 087/130] KVM: TDX: handle vcpu migration over logical processor From: Sean Christopherson To: Isaku Yamahata Cc: Reinette Chatre , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, isaku.yamahata@linux.intel.com Content-Type: text/plain; charset="us-ascii" On Fri, Apr 12, 2024, Isaku Yamahata wrote: > On Fri, Apr 12, 2024 at 03:46:05PM -0700, > Sean Christopherson wrote: > > > On Fri, Apr 12, 2024, Isaku Yamahata wrote: > > > On Fri, Apr 12, 2024 at 09:15:29AM -0700, Reinette Chatre wrote: > > > > > +void tdx_mmu_release_hkid(struct kvm *kvm) > > > > > +{ > > > > > + while (__tdx_mmu_release_hkid(kvm) == -EBUSY) > > > > > + ; > > > > > } > > > > > > > > As I understand, __tdx_mmu_release_hkid() returns -EBUSY > > > > after TDH.VP.FLUSH has been sent for every vCPU followed by > > > > TDH.MNG.VPFLUSHDONE, which returns TDX_FLUSHVP_NOT_DONE. > > > > > > > > Considering earlier comment that a retry of TDH.VP.FLUSH is not > > > > needed, why is this while() loop here that sends the > > > > TDH.VP.FLUSH again to all vCPUs instead of just a loop within > > > > __tdx_mmu_release_hkid() to _just_ resend TDH.MNG.VPFLUSHDONE? > > > > > > > > Could it be possible for a vCPU to appear during this time, thus > > > > be missed in one TDH.VP.FLUSH cycle, to require a new cycle of > > > > TDH.VP.FLUSH? > > > > > > Yes. There is a race between closing KVM vCPU fd and MMU notifier release hook. > > > When KVM vCPU fd is closed, vCPU context can be loaded again. > > > > But why is _loading_ a vCPU context problematic? > > It's nothing problematic. It becomes a bit harder to understand why > tdx_mmu_release_hkid() issues IPI on each loop. I think it's reasonable > to make the normal path easy and to complicate/penalize the destruction path. > Probably I should've added comment on the function. By "problematic", I meant, why can that result in a "missed in one TDH.VP.FLUSH cycle"? AFAICT, loading a vCPU shouldn't cause that vCPU to be associated from the TDX module's perspective, and thus shouldn't trigger TDX_FLUSHVP_NOT_DONE. I.e. looping should be unnecessary, no?