Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp55137lqo; Wed, 15 May 2024 07:36:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUUzJc+ZdnvrrNhPqbSqmLNPop6ePkHPXCfwUP5Cjm6mx1jDi9FpcmP3y2P419dk7GxJ8paw9RQPz/jUv7exItBhwNxRQVPaEvRusbUmg== X-Google-Smtp-Source: AGHT+IHZ4QKvXqabEMdAUxQybFGPu6HNhgfDveOapQ/DIpwm/L8vSBeyEYEYaZM3QU+zKqBvn4rn X-Received: by 2002:a05:6a20:5b22:b0:1af:ac8a:19b1 with SMTP id adf61e73a8af0-1afde1b6ff3mr14144343637.50.1715783775588; Wed, 15 May 2024 07:36:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715783775; cv=pass; d=google.com; s=arc-20160816; b=Kl8s2npqNHL3H2eEbm5NhYZfRJTVtpfKMvytFjbhKVZjsNNzkXGmyu8XFVILeva9SO oOg4JMKaVN/YC+dvOi5SfvqZe+BIkqgaICYKrnjH7v3qD8a4bE34ydR4wSYgZ31CkwU9 l1v578NJwkHKgIZAKgGmmJRxhSvBaJzqMMxRLfFvUnqdFaZOXZMrH77GG86+cVOZUJh6 o1crGSSM5fLmjeMOQRcceVxNKyWBdtu92UDS1SbA4wumD42gNWuTZncaB8p00yNoIp7E +kBRLpEBULoJJwxTyW1rUwWV/nqgyy8bNcesHKKaM77IBsqZ/Oo+N8Aq8tKgWEiHcGJt CzDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=jdxIByov0RVf+aN153pBKSl5TPquAFNeaI2ECMgg+cY=; fh=VsKorQT1VBhIq6vJPjJE/Ju3H8+9lpebmyF2FFviA0o=; b=YoZEaAtml1pdts47gEiIFs/YTzQ6TXqFU96D5E/5oB6JDIJOUaPPw+9vcdD3VDT1Wq qD3M4o6kFnhs/WMmS0wgjTnD+X54/iSwr8sC+uoSnyI24P8vSLvyCwQ3Vwm7QP9H6jmT 0lmTxCpp7oVJ+fDxlUP92RBnCpEYI42p3W7lHEVewLWIRd/PY3lHwW4dZsZt9tNrZsop dtedZH+CvPRotBq5Ji4X35hCEQ/+MNyo5tdebICupXgQbtmZW1dqBO/8ZU7Wbv+ZPnOo fnMtDZAYYRgxFH83o7Wm/RwRhRwCFmBKJ90m+ZWc6oDj4WV8ri7czfwjqO93EUF9Fxw2 nHog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O424Jpx4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-179997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63413d72925si13154572a12.835.2024.05.15.07.36.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 07:36:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O424Jpx4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-179997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 175C5B23000 for ; Wed, 15 May 2024 14:28:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC2ED13FD74; Wed, 15 May 2024 14:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O424Jpx4" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 18C7E13F450; Wed, 15 May 2024 14:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715783328; cv=none; b=cvewRM59S++Ti2/fh6joG2zlCYT1CMDbB4tV/7xwIsCgueim7zLBF9wWam6Rln9ENHxidVXsaVmkKRy4fw76XF0q+66Q+9PiQzPc+IPaI6r1p9bp5Eyet3bYytgj8UcwySLPHQHJUNt/zTg2gs+DWSQK/KFSSNkgp6MqJuJG8cc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715783328; c=relaxed/simple; bh=wVxlxaCe3WCmkKrErEY5yiOlxIbpPpGgac7nwZVst50=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=B0YkHbeGNALn5YqgWB6zGiqRsJUkZOZfo2F9LJ+qFz6+3dSOtceXtDIRnW9/72Y+yXAvY8rXoqhKh0rXvePWuS6DwBAQ+cIN7vaG3dVlswVkd6gbRZocIRRJ34hP2bVQ4BXhEnagT23TM1w86qxfPBLqLoKrDj0rYqXp6XSH/HA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O424Jpx4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37208C116B1; Wed, 15 May 2024 14:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715783327; bh=wVxlxaCe3WCmkKrErEY5yiOlxIbpPpGgac7nwZVst50=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=O424Jpx4eTABQG70Ji1zLKnoiOWWaNqrxpvSW/DvCqHfLa05vyyCBVX5GH3VZUKk6 O3QL9RMabQQX0nzu2PbVvkF+PLP9hoM0duU9K4dUWrZm9ce7bm2TAMrnCBnvmoAnkM Uf/plchz0n3Wza7jtk7w2/VylD6+Nt9xyHSY2fL5Fl0NWF3O0mszwYHIjuupEKUfZ9 DNivSAZrPw007Mz/InHOP2cmS6pYndphnHeEq50htflhtBE6lAwF8rLbKMD6nsQKP6 NZWDX3u8RAruvHx15PLE4miI7Rf2bEmLl6x1X6DbgXKwNCw+YkYC7oPqXUk4MZuCx1 Zns8dy2xQAL4g== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 15 May 2024 17:28:43 +0300 Message-Id: Cc: , , , =?utf-8?q?Marcelina_Ko=C5=9Bcielnicka?= Subject: Re: [PATCH v2 1/2] x86/sgx: Resolve EAUG race where losing thread returns SIGBUS From: "Jarkko Sakkinen" To: "Dave Hansen" , "Dmitrii Kuvaiskii" , , , , , , X-Mailer: aerc 0.17.0 References: <20240515131240.1304824-1-dmitrii.kuvaiskii@intel.com> <20240515131240.1304824-2-dmitrii.kuvaiskii@intel.com> <58e9d453-7909-4157-86fd-a2d5561e728e@intel.com> In-Reply-To: <58e9d453-7909-4157-86fd-a2d5561e728e@intel.com> On Wed May 15, 2024 at 5:15 PM EEST, Dave Hansen wrote: > On 5/15/24 06:54, Jarkko Sakkinen wrote: > > I'd cut out 90% of the description out and just make the argument of > > the wrong error code, and done. The sequence is great for showing > > how this could happen. The prose makes my head hurt tbh. > > The changelog is too long, but not fatally so. I'd much rather have a > super verbose description than something super sparse. > > Would something like this make more sense to folks? > > Imagine an mmap()'d file. Two threads touch the same address at > the same time and fault. Both allocate a physical page and race > to install a PTE for that page. Only one will win the race. The > loser frees its page, but still continues handling the fault as > a success and returns VM_FAULT_NOPAGE from the fault handler. > > The same race can happen with SGX. But there's a bug: the loser > in the SGX steers into a failure path. The loser EREMOVE's the > winner's EPC page, then returns SIGBUS, likely killing the app. > > Fix the SGX loser's behavior. Change the return code to > VM_FAULT_NOPAGE to avoid SIGBUS and call sgx_free_epc_page() > which avoids EREMOVE'ing the winner's page and only frees the > page that the loser allocated. Yes! I did read the whole thing. My comment was only related to the chain of maintainers who also have to deal with this patch eventually. BR, Jarkko