Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp342357lqb; Tue, 28 May 2024 18:24:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVgoHkCN/0p32j7/vjHbtL1FN0ky06UN6Sv9x+aWAMmZ3GXt0kbzClisoB/jrmN4ySjyngY3YIcAFNSoRyxjlPkQ9r/kNkHJljIr5PtWQ== X-Google-Smtp-Source: AGHT+IFDop5VMAAisdip1udM/3m+btI8Owl0SUowbz6wOPL4AWkzDyAesZFRNfs0MZX3C5pDoByO X-Received: by 2002:a05:6808:ddf:b0:3c9:94ab:e8e8 with SMTP id 5614622812f47-3d1a5c33869mr14669892b6e.33.1716945895672; Tue, 28 May 2024 18:24:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716945895; cv=pass; d=google.com; s=arc-20160816; b=qgk9CfF5uINTFjwY750bEB0RSgspChgF4lRvRBmci+pSru664hr+f6wP/xJbcKXP8y jTuz2FnYFso3EWYhMSsCijRjR0tZgzv5QOj8G6diwCTVNmHlJBxHg+u0jeV7dsXkYg3q st+c1amE7IrM9W2Grpos/ypUGbLcJ2rTdr5qzezN+fPHhvVV4+SbH6+t7CMzKKZyKcXj DFZo3cL8Wb0bPWpA9OsRZPNXaKFz3FTg2x0Gb5pnKixPMn9F7Cd18FfYFDR7KhANb1yM +kvtSKtnL5X50pPga4AM0+2IGF49rGnJY4HHww1/oAO20VMXKeX8bYVyQbtbabgVp+Oh /EiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=HfmqnU1KxOCs9aYwbP7dcIbEHxbZlH3pIHoC5GmW1x8=; fh=6hHsum75P/D2htWF+n0A+L+SaLLIJPrfMQhRqxXGeso=; b=wxoXVDfi68YiP79VDCQqYk+z5bwNGKmWQSJYhDub5orUFfUIaU2UfBiZIof0nKKyTx 4/EEs2W6CxaG7Fj5CKjpwgZeDs01NXSsT/lf47I8mhDzOM0AJhtugjSYTVfSXNdBFS0U c2hiAgvoRl3L6st22RZlQj9ZaobqMD99teU5cjnjyqJmqKQOvaH490UF1t+Vr7gY2Jn7 AKFrHn6Pw0M3DLI+ToaVJvxOsOqQFH2u6KgpPmvMz26AeZjcWJdHvIWe6rgRbHRIw7Bq sV24UVqe8oHONWQdB9X/zOw6Kd6IbBMhv9zaMMH+E0AqxNE0KnB5YcyXnf1BpK/YsJ7h ZyLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jMKXZqRJ; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-193291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43fb5bafc9esi116265251cf.176.2024.05.28.18.24.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:24:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jMKXZqRJ; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-193291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 659521C22B85 for ; Wed, 29 May 2024 01:24:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27CC815A87D; Wed, 29 May 2024 01:24:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jMKXZqRJ" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B737A632; Wed, 29 May 2024 01:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945886; cv=none; b=BQC9oah/SlDedKTYyERjH9f4uP3TmCiCK6VQ6ba5iV/rJBX1opmfUzHd026ZmSQPdBwSyL7hB2shgAkTHxTpelywBHhvNeXnnkXzygMwDIkqACUnFLF5DLTzVTr4t+hTA5QGxHuDfqJAEzXlkEM05lUI6CFz0QmMDc6alef9D4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945886; c=relaxed/simple; bh=h17TCwO7J8oz04t/BLJj158cBfXMx//CHvgnp7zRR30=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lCv6f7DffjK/BJXFojdlZc6nkhrDfchbW91ZvuedSR2gY5ny7rjsjq+DDKtV79im9Y5vChA0RQJOI1iHCN95H+dJJto3tEG0vfu4lhDPOLDWflBCne6+z9nM33tVucIqeAOQQoe3LFrROk4IqSxkhrjO/QtNCz+jDTp84BDaa6U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jMKXZqRJ; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716945885; x=1748481885; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=h17TCwO7J8oz04t/BLJj158cBfXMx//CHvgnp7zRR30=; b=jMKXZqRJ8HeQA9n4VsViTxuwlbrJP+kilXXqbjbfa7sTNqPOAUiQvlMe j7SQV5TprMu8dkGP9gIRYobHjB+kwj/nZc3+xh9x5dZp4tmr4CLJKKx4V TkeF04imbEqSjBvHkJd45I50sosnQgjI7PE/NRb/S5RbGM37Y77YAyTg/ 7zFdhKuotvv5lLVEv4Bh/yrV88N9bv//ZA/bRvte3y6wxDdkkppvrLZyn KMYCFMrN6r8T8Cb+uqPTvzGsfgzoYLXaC1IOMTXwB13/8+62MfWGzHb0c 2/UdJq69k3iETLDP1R5vbm4wAS0O9C/5r1alKJEsiJMS2P/uSUyRzenBU g==; X-CSE-ConnectionGUID: Lz32YKi7QZC0e7lC5wesCA== X-CSE-MsgGUID: Z1QQJdRvRz+iofBfBjs1tA== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13509623" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13509623" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 18:24:44 -0700 X-CSE-ConnectionGUID: FxV3x9RcT+GXTtPwt8Htrw== X-CSE-MsgGUID: ClJDGNrWQZORNSK9Wv888A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35727802" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.54]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 18:24:44 -0700 Date: Tue, 28 May 2024 18:24:43 -0700 From: Isaku Yamahata To: "Edgecombe, Rick P" Cc: "kvm@vger.kernel.org" , "pbonzini@redhat.com" , "seanjc@google.com" , "sagis@google.com" , "dmatlack@google.com" , "linux-kernel@vger.kernel.org" , "isaku.yamahata@gmail.com" , "Zhao, Yan Y" , "Aktas, Erdem" Subject: Re: [PATCH 10/16] KVM: x86/tdp_mmu: Support TDX private mapping for TDP MMU Message-ID: <20240529012443.GE386318@ls.amr.corp.intel.com> References: <20240515005952.3410568-1-rick.p.edgecombe@intel.com> <20240515005952.3410568-11-rick.p.edgecombe@intel.com> <36a1b5d239bdbca588625a75660406c1b5ea952a.camel@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <36a1b5d239bdbca588625a75660406c1b5ea952a.camel@intel.com> On Tue, May 28, 2024 at 08:54:31PM +0000, "Edgecombe, Rick P" wrote: > On Tue, 2024-05-14 at 17:59 -0700, Rick Edgecombe wrote: > > +static inline int __tdp_mmu_set_spte_atomic(struct kvm *kvm, struct tdp_iter > > *iter, u64 new_spte) > >  { > >         u64 *sptep = rcu_dereference(iter->sptep); > >   > > @@ -542,15 +671,42 @@ static inline int __tdp_mmu_set_spte_atomic(struct > > tdp_iter *iter, u64 new_spte) > >          */ > >         WARN_ON_ONCE(iter->yielded || is_removed_spte(iter->old_spte)); > >   > > -       /* > > -        * Note, fast_pf_fix_direct_spte() can also modify TDP MMU SPTEs and > > -        * does not hold the mmu_lock.  On failure, i.e. if a different > > logical > > -        * CPU modified the SPTE, try_cmpxchg64() updates iter->old_spte with > > -        * the current value, so the caller operates on fresh data, e.g. if it > > -        * retries tdp_mmu_set_spte_atomic() > > -        */ > > -       if (!try_cmpxchg64(sptep, &iter->old_spte, new_spte)) > > -               return -EBUSY; > > +       if (is_private_sptep(iter->sptep) && !is_removed_spte(new_spte)) { > > +               int ret; > > + > > +               if (is_shadow_present_pte(new_spte)) { > > +                       /* > > +                        * Populating case. > > +                        * - set_private_spte_present() implements > > +                        *   1) Freeze SPTE > > +                        *   2) call hooks to update private page table, > > +                        *   3) update SPTE to new_spte > > +                        * - handle_changed_spte() only updates stats. > > +                        */ > > +                       ret = set_private_spte_present(kvm, iter->sptep, iter- > > >gfn, > > +                                                      iter->old_spte, > > new_spte, iter->level); > > +                       if (ret) > > +                               return ret; > > +               } else { > > +                       /* > > +                        * Zapping case. > > +                        * Zap is only allowed when write lock is held > > +                        */ > > +                       if (WARN_ON_ONCE(!is_shadow_present_pte(new_spte))) > > This inside an else block for (is_shadow_present_pte(new_spte)), so it will > always be true if it gets here. But it can't because TDX doesn't do any atomic > zapping. > > We can remove the conditional, but in regards to the WARN, any recollection of > what was might have been going on here originally? We had an optimization so that there are other state in addition to present, non-present. When I dropped it, I should've dropped else-sentence. -- Isaku Yamahata