Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp265586lqp; Fri, 12 Apr 2024 18:01:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU//IPZEqyhvHI4xgBTIxwo73wgDlwiSzsDmVZflBqgCf+pACz41+1vKYcOqjA6Tz3glRaMsrNbGdI3OSrtuqLbg0Lm5v1GOM2L3yZNLg== X-Google-Smtp-Source: AGHT+IH3oiaUH2atS4+4CjwbZ4jADZ4pQhQh3xpX2d8zkzHSAmgaX/achf5y6mAarc0wpjox/oAC X-Received: by 2002:a05:6358:170f:b0:183:ef80:1e7 with SMTP id d15-20020a056358170f00b00183ef8001e7mr4233190rwj.14.1712970116945; Fri, 12 Apr 2024 18:01:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712970116; cv=pass; d=google.com; s=arc-20160816; b=niIQOcg8w0fz5OHwyll/OaMxiESCamdiElAlEStFaxaTBFVNR5JdhFdCxwcCYC70Wv VSpD+y239KLir8K3sqPoBmjbHceH+U/AZ8lmbYVdv3HfqfKwrIu7hR332FbHy2vNbQRQ lIpjM+oNBNGx6EEozNAc3etQbNbqdHxHCOd7MWzG6Ku/6qYZcCnCldzxHR3FVHDFeJRY 2aU1j0za4erC9CRFakndlYF2CuPvEucZlJnS05rI6DLKBwlzjIRTbNAUERYsCRkbOHkz p7oD8WxPqRVUbQ2cavZ9nQ5v4X6o9pKfEBSf0vVCyoeB0qU8ATj2rYV1JcxaZPNCnG1u FWeQ== 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=tMgjI8AVGHkW4P79rp6TuAtMZyh9p6jX8VdU/137IaQ=; fh=SBKhUukjKiZTPuyQF+oT/1cIpwbeKgifZDkSzBdpjJs=; b=D2zwfETNQDxl8WGpaAepMciurNPZIhGfVxaGZleomB3Oq+3rCNdfvm5y05Jt2P7ZE5 rivBN4jpVrAS9VkibhNiz1gUq4vN87/WhL3sBGXG28fbKgP2Hk8XzQjugcg3Ql1WbOom YS+jizoxkOLjHIj5aX8Wj0Bv0NwRrUbx0uPemFOV5r8mSCsm2M0JXWLuV3EqnRm8Rp4d mNzsiGOe30lHuUKS6s0ZF09bUiZ67HhkT4xRe22vKAxdTZXaRQccVns8z8FfXg/rr+gf Ca6M8wBrnoea9+/tsT2cukT348Zosjvg8sU5ZRj2XZ77baO6DCkyGfeJDbXjHS8Qksno WzmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qe6zm3fd; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-143378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143378-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m25-20020a635819000000b005dc47b71821si4247547pgb.572.2024.04.12.18.01.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 18:01:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qe6zm3fd; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-143378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143378-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 C80BB2875E2 for ; Fri, 12 Apr 2024 21:23:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35DD1152171; Fri, 12 Apr 2024 21:23:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Qe6zm3fd" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 A3A43152160 for ; Fri, 12 Apr 2024 21:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712957020; cv=none; b=oMtgS4p57MddTqPWcHnRRb7ZfvWVVlsRkaIAZHgd6ZT1WAA9d5oT5prvrb9Vq3GYNkV8yCwjt5sbMSEWNpo4NimKBXUsoEavFEsgyv/RtvJUUr97OpBVXZE8j4tuG9p2HVhTDKpAocitLXDlu0J+rUSihykMhjn++Od/Zj4Ga4Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712957020; c=relaxed/simple; bh=Bq3H/RyDbl490yZ4MG8+fNB+9hwAPtOP5y4q+oQYBho=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=srcoQUSm6wUNp6vpeRYOXb4gFJ9TdszPaBrCKw5T4KGmgl6dh8HLhAssRQaE3IN1WWuX/TpePRALRFn1eX/arChGn3EyHLBpkcxgnxqKxUxtk+FIOCub10E25Sf8cWCL67RtT7L96jJ8li4iI8chKZBoVPq9L6lqYlKQZMMXKJY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Qe6zm3fd; arc=none smtp.client-ip=198.175.65.21 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=1712957018; x=1744493018; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Bq3H/RyDbl490yZ4MG8+fNB+9hwAPtOP5y4q+oQYBho=; b=Qe6zm3fdJJW8Dsl98JfJC7y3bYsK6aZUgCIqRMmWoUnOQwoiuN/WKUNe OGac4UTPcIAImUYivHKgGjnA9VFUSknw06UPxIks0SFwEhCoQp9Et5Sz8 f2TOl4Bx8Vzy/wEc2+Tsva7lEuCuZyv+5RmJrcoq6w3q1c5c0oBpu6I6h KO0f2N8fzClWL0jL1wjFMuPRPZ1iJLGFkl34+L6JGLrd1yIs4i//dZ9rq KnM2SkhX5uIhDFwdlpz8Uwy5HOvA1K+eUdJ7X4OnJQ3+xgQyK08+C6b5y Eo48oFlzQLk0jqPSODRsRNEi7LAbWyhoYAk/2vGHYnfLL5ZbIVmcG5EzS w==; X-CSE-ConnectionGUID: MZ1lGiYRTaWeG2dpUu9eTw== X-CSE-MsgGUID: wM+UlvEyTdufYAIhhjWS3Q== X-IronPort-AV: E=McAfee;i="6600,9927,11042"; a="8346708" X-IronPort-AV: E=Sophos;i="6.07,197,1708416000"; d="scan'208";a="8346708" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2024 14:23:38 -0700 X-CSE-ConnectionGUID: vPs/dnBQSC6BvKbTYFciEg== X-CSE-MsgGUID: OoOkRVn1TCSCTa+GcWkhyA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,197,1708416000"; d="scan'208";a="25770875" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa005.fm.intel.com with ESMTP; 12 Apr 2024 14:23:35 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 73F98FF; Sat, 13 Apr 2024 00:23:33 +0300 (EEST) Date: Sat, 13 Apr 2024 00:23:33 +0300 From: "kirill.shutemov@linux.intel.com" To: "Edgecombe, Rick P" Cc: "tglx@linutronix.de" , "mingo@redhat.com" , "Hansen, Dave" , "bp@alien8.de" , "Cui, Dexuan" , "Reshetova, Elena" , "x86@kernel.org" , "seanjc@google.com" , "hpa@zytor.com" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "thomas.lendacky@amd.com" , "cho@microsoft.com" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] x86/tdx: Preserve shared bit on mprotect() Message-ID: References: <20240412191247.369841-1-kirill.shutemov@linux.intel.com> <40abc379ba6c690fd5a768070b7906c694a1b49d.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=us-ascii Content-Disposition: inline In-Reply-To: <40abc379ba6c690fd5a768070b7906c694a1b49d.camel@intel.com> On Fri, Apr 12, 2024 at 08:48:56PM +0000, Edgecombe, Rick P wrote: > On Fri, 2024-04-12 at 22:12 +0300, Kirill A. Shutemov wrote: > > The TDX guest platform takes one bit from the physical address to > > indicate if the page is shared (accessible by VMM). This bit is not part > > of the physical_mask and is not preserved during mprotect(). As a > > result, the 'shared' bit is lost during mprotect() on shared mappings. > > > > _COMMON_PAGE_CHG_MASK specifies which PTE bits need to be preserved > > during modification. AMD includes 'sme_me_mask' in the define to > > preserve the 'encrypt' bit. > > > > To cover both Intel and AMD cases, include 'cc_mask' in > > _COMMON_PAGE_CHG_MASK instead of 'sme_me_mask'. > > > > Signed-off-by: Kirill A. Shutemov > > Fixes: 41394e33f3a0 ("x86/tdx: Extend the confidential computing API to > > support TDX guests") > > Cc: Tom Lendacky > > Cc: Chris Oo > > Cc: Dexuan Cui > > Reviewed-by: Rick Edgecombe > > So does this mean there is shared memory mapped to userspace? Or is this a > theoretical correctness thing? Drivers can do this. Things like VFIO, I guess. I think I should have credited Chris for reporting and testing the problem: Reported-and-tested-by: Chris Oo -- Kiryl Shutsemau / Kirill A. Shutemov