From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 9136F1A8F6B for ; Fri, 17 Jan 2025 21:14:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737148446; cv=none; b=dGxh3G9CqLDM01wzB0hg6uNdzBAru4YZjLKwr5N5cCzAVfAFTuH+LB/LH2ixW0NVurpEzTG0UXzDhS1tQMomGTs3z9cWsYawUlsdSX4k6PWEmdake4+o9zuybQshn7djhXd+z32Azs/K4LT7AWc9uhyqH1aGYneKsCSdyXXa6Cw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737148446; c=relaxed/simple; bh=ikVN6on2dhX26t8BcZAfBvyHKN466ydU/FtaOIQK14E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GPFZGNmMnfRH4kmYaAI/m+kNnEr7y78Zr3kkJCeaxgfJWzJeapftKG4dGB0ZrzyPkfE316On5XLZqGGYwRIYfZW6NQNUfQOlq3WKNex2fT/YBBlLGS5ygLjdppeQMPhMy4LO7rdM1mmzHWRt57fKDBX9/rriNh3E3JcoXqKvYj0= 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=h+3r3hUD; arc=none smtp.client-ip=209.85.214.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="h+3r3hUD" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2163c2f32fdso72553335ad.2 for ; Fri, 17 Jan 2025 13:14:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737148444; x=1737753244; 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=lYNnIYqKlVaCW5yjh3/vk4Rk7LFokJ1iex20vKR2caw=; b=h+3r3hUDGCfDdoZMXyVm6Ayna6TGdMCuyp3RV8qncX4hvEt4TdrJ2V0taD/AmffSZk rhsqyjbwrSCmeKOrDj3N4++cDOyHZI/aeu6fPJCJkNiPRqfyY1ssp5cSa/+63BMAfMiA Mj3xjwhcCcGJ+dRRK7JBQZe0FPQ1xF4dpreBPEYWmQxdsjSvxUi5r8p58yrzBKJ4r9qe 162tpLjokPdBs9yd4M7nucz8dGXswmuTO7mKpvvltZT1OzBuK01rBxXhf1mgENI2eknX SnVoMG8PyYhGlRCOZt87jcDy4b4snnGWQsDRbVpk9r6zvky9bpWp300UlL+lIkupx+8c ZifA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737148444; x=1737753244; 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=lYNnIYqKlVaCW5yjh3/vk4Rk7LFokJ1iex20vKR2caw=; b=dZR1n1Katct5oQ+Wnie2cs7PmOBSn724p1FJhpxUQGp/6IU0QesLsDjQBB2jbKRTMS 1zTrk8lmYpjJJaGoZG5x40997+m1C/BXWnLmVoRqXM/oDu+RryMxlKGhiDrlBfue2NBT oOmRuI61WXJW0gKcaZWOfMyWq+cEIRy+U8YXzeBpJBB56OdMbvNTUsPtNptumniGULJM G8x5WT3e3I6pwdP2dyHVPVDb5CMGrVoNo1+v+vPQ7SAY7obVtcl1cYZP2Eb6bBe6He3/ dvxRzDsP0bFkjI+TH81p6haAmVIMoM2zSBpgpYxkgjoO4b4BAhkU9WLuZlDkrfYbRALx vV4Q== X-Forwarded-Encrypted: i=1; AJvYcCVLITIgjRiuxOisJB69Hp1oTlQoBeZc29PeEdqsRbqS5DvJWjnX0/RHsv7/i8Mu5kb94HXMXshbnh9twMU=@vger.kernel.org X-Gm-Message-State: AOJu0YwD9ZEvhtZAAakGHw55cLyQ+KxkzXJTJv1OSmLeMfBeeLzbSP/E BAtNQORb/pl1tkFhuy9mpfcKr8B4dNK89tvREShAJ1k1lwhvawbBth9S3whQkVXA0Sjut4opabz K2g== X-Google-Smtp-Source: AGHT+IEwPPyP1BehuVb+1cCPxwwZEOtdZtF8brXlcwf1F/RI+bUJs1pvun2GzQVInlKAr7ZQoK8oVPzrUQ4= X-Received: from pgf9.prod.google.com ([2002:a05:6a02:4d09:b0:7fd:5437:9912]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7f96:b0:1d9:c78f:4207 with SMTP id adf61e73a8af0-1eb2147d3f9mr5832183637.11.1737148443850; Fri, 17 Jan 2025 13:14:03 -0800 (PST) Date: Fri, 17 Jan 2025 13:14:02 -0800 In-Reply-To: <20250113021218.18922-1-yan.y.zhao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250113020925.18789-1-yan.y.zhao@intel.com> <20250113021218.18922-1-yan.y.zhao@intel.com> Message-ID: Subject: Re: [PATCH 3/7] KVM: TDX: Retry locally in TDX EPT violation handler on RET_PF_RETRY From: Sean Christopherson To: Yan Zhao Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, rick.p.edgecombe@intel.com, kai.huang@intel.com, adrian.hunter@intel.com, reinette.chatre@intel.com, xiaoyao.li@intel.com, tony.lindgren@intel.com, binbin.wu@linux.intel.com, dmatlack@google.com, isaku.yamahata@intel.com, isaku.yamahata@gmail.com Content-Type: text/plain; charset="us-ascii" On Mon, Jan 13, 2025, Yan Zhao wrote: > @@ -1884,7 +1904,24 @@ static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu) > } > > trace_kvm_page_fault(vcpu, tdexit_gpa(vcpu), exit_qual); > - return __vmx_handle_ept_violation(vcpu, tdexit_gpa(vcpu), exit_qual); > + > + while (1) { > + ret = __vmx_handle_ept_violation(vcpu, gpa, exit_qual); > + > + if (ret != RET_PF_RETRY || !local_retry) > + break; > + > + /* > + * Break and keep the orig return value. Wrap at 80. > + * Signal & irq handling will be done later in vcpu_run() Please don't use "&" as shorthand. It saves all of two characters. That said, I don't see any point in adding this comment, if the reader can't follow the logic of this code, these comments aren't going to help them. And the comment about vcpu_run() in particular is misleading, as posted interrupts aren't truly handled by vcpu_run(), rather they're handled by hardware (although KVM does send a self-IPI). > + */ > + if (signal_pending(current) || pi_has_pending_interrupt(vcpu) || > + kvm_test_request(KVM_REQ_NMI, vcpu) || vcpu->arch.nmi_pending) This needs to check that the IRQ/NMI is actually allowed. I guess it doesn't matter for IRQs, but it does matter for NMIs. Why not use kvm_vcpu_has_events()? Ah, it's a local function. At a glance, I don't see any harm in exposing that to TDX. > + break; > + > + cond_resched(); > + } Nit, IMO this reads better as: do { ret = __vmx_handle_ept_violation(vcpu, gpa, exit_qual); } while (ret == RET_PF_RETY && local_retry && !kvm_vcpu_has_events(vcpu) && !signal_pending(current)); > + return ret; > } > > int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath) > -- > 2.43.2 >