Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2964065lqp; Mon, 25 Mar 2024 14:49:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9BbGfY/PMEl/77WXK9oqDK4pIyR7c9ua89bOtuS4qUj+yZHfxyZZPFeholKOS9L1W+73KiXx2UK2nY1VqplS2+d66EeEPXHjLhEnzVA== X-Google-Smtp-Source: AGHT+IHe7JKhE/KlYY9OhReVhIpgzGV2brZWLCd65LeCQsK7JEGpMXtliqoJn+OQt3AblscH+Tpt X-Received: by 2002:a17:902:784f:b0:1e0:e89f:fe20 with SMTP id e15-20020a170902784f00b001e0e89ffe20mr319804pln.16.1711403342908; Mon, 25 Mar 2024 14:49:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711403342; cv=pass; d=google.com; s=arc-20160816; b=I0Wctkm1z7Ay7QsQHcihfmF4Ls+X3N/wU4/vEXJooPhu5Mmm3cXD78DSuiR1e/Em+U B/A9/Omg1g4zYElJrrnCDmYNOgDXRvatYWkvYKr3lRhP1z9u/xJXI0RL69BUrJiO94BC 8H+/QNGP8dq0qAsmlZurw+molr5epKSCa/NBG2MZf4wiveuNDIa57hMuEYm0YjdXLIT3 3GYBYvPlq4LijtDs+WMKzqa0M6sAHiQcfo20u2+UynCpX41kwMT3BEX4kghXwf8h6EhW FbjfQljPUmfeGsFt02Kdsoo2v6Xuz31XTlwtlKbgnjDe26pWLy8dH+r81cr99tce2Jxd 5xtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=daJE5mNEsxp6AV7M+98NR2pkWoHnKQWRqfxbtaKqA4k=; fh=YYXmQolDZ545DIbHBGg3a8Ad9BfifqTm1mpLJOVQCbk=; b=hRvtTOaduKjoS300F7S4/bv6NmkHgvYMGj8YjUUDhg+3TSS6JdMQInHSN8oBbDcQqW 9rNy/tWqlH1pwDl5gDqmryq38X2pqD0UlP0RSpmoJJX/eQE6+9Uq7VuJwdn5kRfUuL4Y j0wAkm4jkC/JPG8S2/lWyL/HBgGBVuWDJhWbusfG0DLbgicdb3m+2EpJ1TFVDBs50tCP tpWcvPX1T60XvstSDE8rHuz1PPncJW970Y/Rf9oC/99AbSt3M+ivQnrWgGduHC1KD5/4 EfmM124mFG/crwQxKsCYI6ZfBKQ8Yi9pKnNlLtkIyZWsUYxvTZnF+jrv+lf0erq5WGdI 9peA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=e4Z+9Ajx; 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-118059-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118059-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z10-20020a170902d54a00b001e026392e6esi6063876plf.8.2024.03.25.14.49.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 14:49:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118059-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=e4Z+9Ajx; 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-118059-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118059-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 97A853042BF for ; Mon, 25 Mar 2024 21:49:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7A436FE09; Mon, 25 Mar 2024 21:48:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="e4Z+9Ajx" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 BE7195D8E0; Mon, 25 Mar 2024 21:48:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711403333; cv=none; b=rjBxv336riJTFnthZDP3ChVEEY3xG7v/uPcMCCJFe9u0OhLwB9obSavzGuRy1qSoi+lw74o3DpQIxgCiePEhIdhDg7N1c8fpfH/wE80YOqJIh5pJ9A4N9IJ5RHMyNJzkiSymIRDXAnLkGduOJl224D2GX+Akb+rITWBRIpy/9e8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711403333; c=relaxed/simple; bh=eIyEkdLme3YwP3nX80zt2BK9NvuG/TevdkijeZMdiO4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lUWGrRYQ4rvcvvjvqN3zHABthrG8oKnt9HQUm1Cz04CruoRqWS6pcmjZ5cA2KaqTdphP+7LSKjvikWEmw/8Ba6JDVhXFw/hDDkceQ2HomkOiM6HY++wI3JbEqp0dOfhjEcTDyjotb38Clq1HAhaySGQKPLu9Vi70qSzElEKtDNw= 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=e4Z+9Ajx; arc=none smtp.client-ip=192.198.163.19 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=1711403331; x=1742939331; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=eIyEkdLme3YwP3nX80zt2BK9NvuG/TevdkijeZMdiO4=; b=e4Z+9AjxlWXbZYeyyBTtPtdkZlnka0GADBY8ucu1BlSmP6sWkz2wVXvq Rj8HtvFMkONap0f/7di08dIkH25zcnmKUdGMIJaBSO9n0LHIXjzoLIvTo 2PlLge+8ujDn5Unr15NepujRW0mtwPnfX/H1cVhcfvRsmJVeWkdzZsiN9 XFWQHjicYLfQQ+kaC7dzy9dOs4qQzvDEzZOIv3rkHY98j/yNyUDa/5Olw tlLG5bY1tCqXrSHBA1uOEa9mMV1ztjtTPEnRDBgMP3VigBeC/sjF+2oOE viSvKYpx6Jt52lL09LYybFQQ/cq1euiSoOwTTPQNcXvZHAd/xREbMBCfA A==; X-IronPort-AV: E=McAfee;i="6600,9927,11024"; a="6294608" X-IronPort-AV: E=Sophos;i="6.07,154,1708416000"; d="scan'208";a="6294608" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 14:48:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,154,1708416000"; d="scan'208";a="38868640" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 14:48:51 -0700 Date: Mon, 25 Mar 2024 14:48:49 -0700 From: Isaku Yamahata To: Binbin Wu Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Sean Christopherson , isaku.yamahata@linux.intel.com Subject: Re: [PATCH v19 038/130] KVM: TDX: create/destroy VM structure Message-ID: <20240325214849.GM2357401@ls.amr.corp.intel.com> References: <7a508f88e8c8b5199da85b7a9959882ddf390796.1708933498.git.isaku.yamahata@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 In-Reply-To: On Mon, Mar 25, 2024 at 05:58:47PM +0800, Binbin Wu wrote: > > +static void tdx_clear_page(unsigned long page_pa) > > +{ > > + const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0))); > > + void *page = __va(page_pa); > > + unsigned long i; > > + > > + /* > > + * When re-assign one page from old keyid to a new keyid, MOVDIR64B is > > + * required to clear/write the page with new keyid to prevent integrity > > + * error when read on the page with new keyid. > > + * > > + * clflush doesn't flush cache with HKID set. The cache line could be > > + * poisoned (even without MKTME-i), clear the poison bit. > > + */ > > + for (i = 0; i < PAGE_SIZE; i += 64) > > + movdir64b(page + i, zero_page); > > + /* > > + * MOVDIR64B store uses WC buffer. Prevent following memory reads > > + * from seeing potentially poisoned cache. > > + */ > > + __mb(); > > Is __wmb() sufficient for this case? I don't think so because sfence is for other store. Here we care other load. > > + > > +static int tdx_do_tdh_mng_key_config(void *param) > > +{ > > + hpa_t *tdr_p = param; > > + u64 err; > > + > > + do { > > + err = tdh_mng_key_config(*tdr_p); > > + > > + /* > > + * If it failed to generate a random key, retry it because this > > + * is typically caused by an entropy error of the CPU's random > > Here you say "typically", is there other cause and is it safe to loop on > retry? No as long as I know. the TDX module returns KEY_GENERATION_FAILED only when rdrnd (or equivalent) failed. But I don't know the future. Let's delete "tyepically" because it seems confusing. -- Isaku Yamahata