Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp366333rdb; Tue, 16 Jan 2024 02:53:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFS73nifbQpKVJxIoYisccKb+h+vvpr2jxrhbSfaMOJ5BcQaX+H/gDDUuPvSJNCBLiaipdE X-Received: by 2002:a17:906:79a:b0:a2b:2de2:8dd4 with SMTP id l26-20020a170906079a00b00a2b2de28dd4mr6592200ejc.15.1705402425067; Tue, 16 Jan 2024 02:53:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705402425; cv=none; d=google.com; s=arc-20160816; b=d2PhPX1rpBwXwOIrAl7E6cPVTOIy7DeGfXi+Hxb5n1ve3DwMTBS9omT1JTAiBNTqMC YFR4QGcUfBSF7jzl8hsMi57xrgDzQn+8ioM5qBnae7MNjyfdHA5OT+dR9lMkq5gQjpFM p3m3L40zNJcBVso3eVl3gC+TO70hMSMkmaAcv7dO2efKS0EZAjKT7KyHE48mZgTL+VT6 gTIKmGovSjZS5xFToRi/rVwAMNvVuQ8k6DndXn2/Gi2X4rWdZOdVoMYT+/uXDGq24v4U FD4KjvDTwsEMK3ZGZwr/tk/EcspQEC2SKAJqhD/bCpdiO+K7fD8Z8r4sAOCMdnUY7YQQ tleQ== ARC-Message-Signature: i=1; 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=bwVzhNwZEH2blgCWyOYY+yaARHRYAk3EeX+UjHqhh7Q=; fh=dcRslSjZTlGgDHJ9/mCy7T4peJ7te6GzM1eJdKDJ8HQ=; b=fMKfvAAyAINkPftDrlngu6X+Wz5q50tWESI2zN0YTTrZPC1/HD2o7eAgmtiyw4HVL4 HqU3yCZbLIK7wUneNTv7DmD+a73lWyCtC+FVB3XtKSAcpCVcYW5pvzZPV6T9p6KX2sgq 6ByoFBUZULkas71LZx1xNIY3FF5ITbHspGvlPKtFs6fWlP2xUcKYKt5n1kPNdHzMAicl k+LwJNt5dGN4/kuq5q7JuMrZJ/75tVFIhiuGpc302NgcoD2IOKe9tehCbKIz361zH7Eh uu4xgflpRaLngWiJSFVGe94siZ+JA/T8B0mI34uLZAZPi2rXfwWfFMEgpHD4wVMdJwGP 5cqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KbEWUu1G; spf=pass (google.com: domain of linux-kernel+bounces-27276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27276-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id jw19-20020a17090776b300b00a2846a56c43si4618818ejc.242.2024.01.16.02.53.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 02:53:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KbEWUu1G; spf=pass (google.com: domain of linux-kernel+bounces-27276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27276-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 am.mirrors.kernel.org (Postfix) with ESMTPS id BCC2B1F23382 for ; Tue, 16 Jan 2024 10:53:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6370199AE; Tue, 16 Jan 2024 10:53:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KbEWUu1G" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) (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 8C68319445 for ; Tue, 16 Jan 2024 10:53:33 +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=1705402413; x=1736938413; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=kwLew776p5vzcGbpOZt4QJk08QQAHvX8ubIV3cyIJIw=; b=KbEWUu1Ge8ZpC9QZ67NOETkzeOOGaG3IBJPCpG05thxetqI5xUEf8L2n 1aWfXn7RsfgPVKYc8hEiNSIVIdyKXgFogJgYtWB7SkCX7xMQlgIKMSxqs 7Udf97MCChaqGtZzTb9LPQIMkgun23HoZZGZdt4Q94EbStc3TAgQZlV0V XxR+efB8VF3x3SjDsl/2yEJd0Rlk8Ogpv4M280/MYN3aex54cd75SFeDv 3k1BlUYy1URBelVtrputZRf83xEnKzH9i5ubGvvhvvfdeeIZYeFmEPUzQ NGr17oMO4nRUfl/ipD5whBZTI/fhAfm1wDJJHbar8BXLgbvHFleD8bqUU Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="396983666" X-IronPort-AV: E=Sophos;i="6.04,198,1695711600"; d="scan'208";a="396983666" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 02:53:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="818134005" X-IronPort-AV: E=Sophos;i="6.04,198,1695711600"; d="scan'208";a="818134005" Received: from uschumac-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.213.254]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 02:53:27 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id BBABD10A17B; Tue, 16 Jan 2024 13:53:24 +0300 (+03) Date: Tue, 16 Jan 2024 13:53:24 +0300 From: "Kirill A. Shutemov" To: Nikolay Borisov Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCHv5 10/16] x86/tdx: Convert shared memory back to private on kexec Message-ID: <20240116105324.5kz6b2b6cbv6g4xn@box.shutemov.name> References: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> <20231222235209.32143-11-kirill.shutemov@linux.intel.com> <89e8722b-661b-4319-8018-06705b366c62@suse.com> <20240116072822.pvzseyqry56eqa4j@box.shutemov.name> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240116072822.pvzseyqry56eqa4j@box.shutemov.name> On Tue, Jan 16, 2024 at 10:28:22AM +0300, Kirill A. Shutemov wrote: > > > @@ -809,12 +823,25 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) > > > static int tdx_enc_status_change_prepare(unsigned long vaddr, int numpages, > > > bool enc) > > > { > > > + atomic_inc(&conversions_in_progress); > > > + > > > + /* > > > + * Check after bumping conversions_in_progress to serialize > > > + * against tdx_shutdown(). s/tdx_shutdown/tdx_kexec_stop_conversion/ > > > + */ > > > + if (!conversion_allowed) { > > > + atomic_dec(&conversions_in_progress); > > > + return -EBUSY; > > > + } > > > > nit: Can you make the inc of conversions_in_progress be done here, this > > eliminated the atomic_dec in case they aren't. Somewhat simplifies the > > logic. > > Okay, fair enough. Will change. Actually, no, it will breaks serialization. Consider following scenario (includes change you proposed): CPU0 CPU1 tdx_enc_status_change_prepare() if (!conversion_allowed) // false tdx_kexec_stop_conversion() conversion_allowed = false; <...> Incrementing conversion_in_progress before checking conversion_allowed will make tdx_kexec_stop_conversion() to spin until CPU0 is done with conversion. -- Kiryl Shutsemau / Kirill A. Shutemov