Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1205895rwd; Thu, 8 Jun 2023 14:02:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5M6tSO8okgzx95Z09WEBLXaOLzOJLOf+33R0nwFo8DP7rIOuJq+CUu3wxIcgDDKBdGkysw X-Received: by 2002:a05:6a20:9388:b0:104:f534:6c8d with SMTP id x8-20020a056a20938800b00104f5346c8dmr5287999pzh.33.1686258177556; Thu, 08 Jun 2023 14:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686258177; cv=none; d=google.com; s=arc-20160816; b=Ydb48IpvLA6Qyh7k9DPVV2WhtsNMg/pf/qqHLJpQRei+n18WlTMlHHcpz6xGHy182c BVVMaGcva30Ue6ytq9GwGEDVGu/pfYsohdFRtEM/pOKu1Xb3ePjpZ05Ig/pK7CBNN9np NKkf7r15r0PWxDym8z0k9GBPPbkgdRHRQeB8x/Od0BLRDrOMXe2IJ3ONtaXoW2zrSfdS CUR25QS/LuprQjyTbqBrofmvXcS3/vWCFjMP4toX7An9PmPocbTvrRp1XwFAj2EF8a2R FthG0jNP+7+FOOgNyg0dZqU/RQfZLBNU0Ycxn7cwo241edWickDK63ecCQrZZq5ZZ4EE 5v9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=6oWrHsl4d9N87fafwcjt6WPe/4TeEPsaBiFgd+6930M=; b=MmukIMvuNYSu26PXlCWGy3XOmfHa9bqeSvue/zs8CWyHEfdAxLZb09eOWxk6igRwkd hJOMkASBkI5bi8CEfm1vNHCvXXnQyGwQDPgXrfo3UCGdMg2kkTW+1uqcHU27xh+pmQyQ 8ejpNUVRzDQzwqu6FeL0JOyxd2MFDFOjdQITr2/NKFcwN7nO74D1nkVmrnEz0UhxhV7a A/kr9yinJ4Rv/xG32EIcV2ZDGABTC1Y/wzhsaAmc64vgI9xmW+POyj9VTZksmNJK5dLN QAw4ke5qUPsRQ53GO09SEL7r9JPCcsjt0vhEK8cDnkdUzJOBJg2l7S/pyzSdg9eWNPXQ n0Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=nq8AaAsG; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 185-20020a6306c2000000b005301151503esi1486885pgg.186.2023.06.08.14.02.44; Thu, 08 Jun 2023 14:02:57 -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=@gmail.com header.s=20221208 header.b=nq8AaAsG; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236068AbjFHUzJ (ORCPT + 99 others); Thu, 8 Jun 2023 16:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbjFHUzI (ORCPT ); Thu, 8 Jun 2023 16:55:08 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36C5A133; Thu, 8 Jun 2023 13:55:07 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-53fa455cd94so110174a12.2; Thu, 08 Jun 2023 13:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686257706; x=1688849706; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=6oWrHsl4d9N87fafwcjt6WPe/4TeEPsaBiFgd+6930M=; b=nq8AaAsGA71zvWXKV0bCclZE1ncs4V6jl3FXcw0S1vk/1waURyQRsDA4Zbc1QyAnQD YkTIr9cyAzhKoMq4fRi9cJ+gzlvIO7UH6djIYVw+8KIiM/I4OcI+lGb1yengwlt9lACH eSUuUQtwboeBwqYMdDmOV5q9PwF43isu+hwPBUh1EpjglEpVFz3Zz5bclUsyOWxd/bfb es3rKeHSdz7ZzNbTvODd2nbn0uuE9xHVp/j4kxOXStMOXr+rwNH5ZOQhzmTRCa8oaplm X8iVzZmnjolukj+Ydp59sSnM/zRQB1+QNpTud+BLoxgojKMcavcKFFGVZKOWgtMSO3wC HymQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686257706; x=1688849706; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6oWrHsl4d9N87fafwcjt6WPe/4TeEPsaBiFgd+6930M=; b=DMajDgMDmOtxCJ9ztzd9GsyzY5u68c4I99jQZbsinMH+ZZpNRSHjn6KyVKp8bCGvQl kzyiMRe5aV16qg+StlKAdS6xZn+TES/Q6MD/JxSVX3Z02RtBx7Vo1n/Sr8rwKyx1mb9c 1fJA6yo9aE5HE0zwOlqmBiSPVu6PJN57SGq69lXP5UHU6hy+s8J75R6L9r/Z3BSzzCAl 0ekPJKCCAmwmu8XakexdXOCGqt89xlzuBtTWObE3LtSU5oDEVCG58h35em+LM1+CI14O rgyiIKm5DRgoOS+JUvTjejKunkyc8O670AJKRYN37uFXFu7ra/c2P4uFoTew8IpIg87b BPYw== X-Gm-Message-State: AC+VfDxInQH/G72lHubFoLz4N8AaotCGuCJ0FLALOUSM3OLGLrKDAzvC DTscIdbEXGvekP5xRymyFQI= X-Received: by 2002:a17:90a:6348:b0:253:727e:4b41 with SMTP id v8-20020a17090a634800b00253727e4b41mr4683052pjs.34.1686257706282; Thu, 08 Jun 2023 13:55:06 -0700 (PDT) Received: from localhost ([192.55.54.50]) by smtp.gmail.com with ESMTPSA id nn4-20020a17090b38c400b002562cfb81dfsm3430923pjb.28.2023.06.08.13.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 13:55:05 -0700 (PDT) Date: Thu, 8 Jun 2023 13:55:03 -0700 From: Isaku Yamahata To: Erdem Aktas Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, Vishal Annapurve Subject: Re: [PATCH v14 055/113] KVM: TDX: TDP MMU TDX support Message-ID: <20230608205503.GL2244082@ls.amr.corp.intel.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 Thu, Jun 08, 2023 at 04:29:35AM -0700, Erdem Aktas wrote: > On Sun, May 28, 2023 at 9:21 PM wrote: > > > > From: Isaku Yamahata > > > > +static int tdx_sept_drop_private_spte(struct kvm *kvm, gfn_t gfn, > > + enum pg_level level, kvm_pfn_t pfn) > > +{ > > + int tdx_level = pg_level_to_tdx_sept_level(level); > > + struct kvm_tdx *kvm_tdx = to_kvm_tdx(kvm); > > + struct tdx_module_output out; > > + gpa_t gpa = gfn_to_gpa(gfn); > > + hpa_t hpa = pfn_to_hpa(pfn); > > + hpa_t hpa_with_hkid; > > + u64 err; > > + > > + /* TODO: handle large pages. */ > > + if (KVM_BUG_ON(level != PG_LEVEL_4K, kvm)) > > + return -EINVAL; > > + > > + if (unlikely(!is_hkid_assigned(kvm_tdx))) { > > + /* > > + * The HKID assigned to this TD was already freed and cache > > + * was already flushed. We don't have to flush again. > > + */ > > + err = tdx_reclaim_page(hpa, false, 0); > > + if (KVM_BUG_ON(err, kvm)) > > + return -EIO; > > + tdx_unpin(kvm, pfn); > > + return 0; > > + } > > + > > + do { > > + /* > > + * When zapping private page, write lock is held. So no race > > + * condition with other vcpu sept operation. Race only with > > + * TDH.VP.ENTER. > > + */ > > + err = tdh_mem_page_remove(kvm_tdx->tdr_pa, gpa, tdx_level, &out); > > + } while (unlikely(err == TDX_ERROR_SEPT_BUSY)); > > + if (KVM_BUG_ON(err, kvm)) { > > + pr_tdx_error(TDH_MEM_PAGE_REMOVE, err, &out); > > + return -EIO; > > + } > > + > > + hpa_with_hkid = set_hkid_to_hpa(hpa, (u16)kvm_tdx->hkid); > > + do { > > + /* > > + * TDX_OPERAND_BUSY can happen on locking PAMT entry. Because > > + * this page was removed above, other thread shouldn't be > > + * repeatedly operating on this page. Just retry loop. > > + */ > > + err = tdh_phymem_page_wbinvd(hpa_with_hkid); > > + } while (unlikely(err == (TDX_OPERAND_BUSY | TDX_OPERAND_ID_RCX))); > > + if (KVM_BUG_ON(err, kvm)) { > > + pr_tdx_error(TDH_PHYMEM_PAGE_WBINVD, err, NULL); > > + return -EIO; > > + } > > > It seems like when the TD is destroyed, all the TD private pages are > removed with tdx_reclaim_page which also clears the page with > movdir64b instruction. But when the page is removed while the TD is > alive (in this case), the page content is never cleared with movdir64b > which causes any poisoned cache line to be consumed by the host > resulting in #MC exceptions in the host context. > > We should clear the page before returning it back to the free pool by > calling tdx_clear_page((unsigned long)__va(hpa)) here. Thank you for catching it up. I'll fix tdx_sept_drop_private_spte(), tdx_sept_free_private_spt() (and tdx_sept_merge_private_spt() for large page support). We should clear the page for Not only guest memory, but also secure-ept. -- Isaku Yamahata