Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp467371rdb; Fri, 5 Jan 2024 16:59:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCiX5Z4CGc4UuSY5J8y6ZWfAvMVZ93g5kFLEGlqSnutZRC97alsltlglpmiHRksju7UFrQ X-Received: by 2002:a05:620a:40d2:b0:781:5bfd:5a1b with SMTP id g18-20020a05620a40d200b007815bfd5a1bmr310257qko.49.1704502758732; Fri, 05 Jan 2024 16:59:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704502758; cv=none; d=google.com; s=arc-20160816; b=L6DACzYzIemFralJrdjkOLXll/qKMX77OiwPsEp0mw8v8zfERRaHGohMtlP2glvSV6 9vfufOg2t3STQmOrYwkBjfFIFAunX07Ato+ssl56hesEMlJQT+ydwiZdv6wycUsQXvzs Foa7ZU5Ty82fIVCmj7fP6f7i6G2KoDVGtSlaeqA3UCl22+omUzZhhmLgK7a92iuCDpj0 GrF688qhsuYjWZxftNt3EYBUa8hXeB8jsrYd9XrJSAnd2DRRD7CmFPoMnM0mWgVLkckC GW/w23mvGDTRoBebYZHjYfpeEONUGf56AChW/cBdskFmhv65HX80VLBMzSBdV0mpjdtO /IqQ== ARC-Message-Signature: i=1; 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=bK3XE6VfLfL64vFWL6bybjy1lHYkCbrMj2zpB1deeWw=; fh=wUtAS8bu7u+SUsoOpnLKHGbhKmUynxyqc31PmvfG918=; b=iAw7+ualWsC+PLk4ikgRWBiLfM966YIb1FM1IgTbAVQ4iihkUzg+isV9TkbtIdbck5 W9kBStiB69uJjXQTUyhMF2/slj1/K1vggFA6P2L9GxswPyUPd8DOSyCIdsjLo/Z2p1O+ k5NHZ6r2dO/Qr6T1jq0fk09yiwJ0534sq2lpsgiMXhw5q4nmAUs8TQCoJmEysU6e4NEU ZI+pcDXkf8Dts+3tuOit8FaPsRGLa65dKH0zNnEAyzEmsI+Cixvub4EWRfmeXH3XEilj /bBE0Mx5Xe+9kVx4X5uOAZbw3wW/JZt7WLXk/2ZQfhFDpIr03VPOakApE7UTy67Asf/o YXAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BRLQ4bSz; spf=pass (google.com: domain of linux-kernel+bounces-18438-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18438-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 y19-20020a37e313000000b00781b518af18si2808600qki.709.2024.01.05.16.59.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 16:59:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18438-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=BRLQ4bSz; spf=pass (google.com: domain of linux-kernel+bounces-18438-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18438-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 7B6731C23ACA for ; Sat, 6 Jan 2024 00:59:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F297015CE; Sat, 6 Jan 2024 00:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BRLQ4bSz" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) (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 A70AB15A0 for ; Sat, 6 Jan 2024 00:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704502749; x=1736038749; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=bSsYNHPqPBPvIfJLFuPRmb0GQmnn1/patfbIJCmnLTQ=; b=BRLQ4bSz0qsthctPXjsE714BffJdhaitUaTo1HBmQqSev3BEL8TcgIGr SPCvUwG81S8NtPQdvE0KD2y+ol8M2s92hypDG04jrmusTH0GGyqS9Q/iY p22eRRg0R+Gz2EsEFly1ZnwSFYS2SQEcS7TGix4JjzXFnCkOtnR8MZVzf ZXrxjptYzNzAaQSQkiDr9x9T3HXvsnDwczDmReYAxjBF3HeF7Htln1Xw4 9cwfaYhhZNhxDcbN7qaCktyqvxBv+1Z1M5rIffLOpRGmCNcIKDTY2Xn1A ooM1x3lh75z1utonYTR9k/wrkpWvzURECnskenf6/wgbsiERv2rxZzO/G g==; X-IronPort-AV: E=McAfee;i="6600,9927,10944"; a="461918823" X-IronPort-AV: E=Sophos;i="6.04,335,1695711600"; d="scan'208";a="461918823" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 16:59:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10944"; a="871366157" X-IronPort-AV: E=Sophos;i="6.04,335,1695711600"; d="scan'208";a="871366157" Received: from mflierl-xps15.amr.corp.intel.com (HELO box.shutemov.name) ([10.252.36.84]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 16:59:03 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 49F5C10A57B; Sat, 6 Jan 2024 03:59:01 +0300 (+03) Date: Sat, 6 Jan 2024 03:59:01 +0300 From: "kirill.shutemov@linux.intel.com" To: "Edgecombe, Rick P" Cc: "tglx@linutronix.de" , "mingo@redhat.com" , "x86@kernel.org" , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "kexec@lists.infradead.org" , "Reshetova, Elena" , "Nakajima, Jun" , "rafael@kernel.org" , "peterz@infradead.org" , "Huang, Kai" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Hunter, Adrian" , "thomas.lendacky@amd.com" , "ashish.kalra@amd.com" , "linux-coco@lists.linux.dev" , "seanjc@google.com" , "bhe@redhat.com" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCHv5 10/16] x86/tdx: Convert shared memory back to private on kexec Message-ID: <20240106005901.jpdxd544ddih6nw7@box.shutemov.name> References: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> <20231222235209.32143-11-kirill.shutemov@linux.intel.com> <063a42bfe538710931fca183a8d28c8a3d011608.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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <063a42bfe538710931fca183a8d28c8a3d011608.camel@intel.com> On Fri, Jan 05, 2024 at 07:38:48PM +0000, Edgecombe, Rick P wrote: > The break apart looks good. > > On Sat, 2023-12-23 at 02:52 +0300, Kirill A. Shutemov wrote: > > +???????while (addr < end) { > > +???????????????unsigned long size; > > +???????????????unsigned int level; > > +???????????????pte_t *pte; > > + > > +???????????????pte = lookup_address(addr, &level); > > +???????????????size = page_level_size(level); > > + > > +???????????????if (pte && pte_decrypted(*pte)) { > > +???????????????????????int pages = size / PAGE_SIZE; > > + > > +???????????????????????/* > > +??????????????????????? * Touching memory with shared bit set > > triggers implicit > > +??????????????????????? * conversion to shared. > > +??????????????????????? * > > +??????????????????????? * Make sure nobody touches the shared range > > from > > +??????????????????????? * now on. > > +??????????????????????? */ > > +???????????????????????set_pte(pte, __pte(0)); > > Does this need a full shootdown at this point, at least in the crash > case? A local flush for the non-crash case might be nice too. See __flush_tlb_all() after the loop. > Also, probably a barrier() between set_pte() and > tdx_enc_status_changed(). But why? There's no concurrency at this point. Interrupts are disabled and only one CPU is active. Nobody can touch the memory relevant for the PTE. -- Kiryl Shutsemau / Kirill A. Shutemov