From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0C66C47DDB for ; Mon, 29 Jan 2024 15:26:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E7ED6B00A6; Mon, 29 Jan 2024 10:26:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5990A6B00AA; Mon, 29 Jan 2024 10:26:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 438B86B00B0; Mon, 29 Jan 2024 10:26:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 338466B00A6 for ; Mon, 29 Jan 2024 10:26:08 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 08C7C1205A5 for ; Mon, 29 Jan 2024 15:26:08 +0000 (UTC) X-FDA: 81732724416.29.97EDC7A Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf30.hostedemail.com (Postfix) with ESMTP id 6DFF680025 for ; Mon, 29 Jan 2024 15:26:05 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IqJ9FeBb; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=buBCJSoE; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=wra20jGo; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=QGF3yu+y; dmarc=none; spf=pass (imf30.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706541966; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jh9pQCHiNrOIgT4Qx0ZOIp8ky/ddjw+KrmlzKD3GTFA=; b=5KUphtF/md6PpX3FdJpUfOoDvViqEpRGwQsMlA8n6aWAHU2yF8JePmqkn/Wk+aNfpg30Ui mI9BcVOpEzxxjxNGIC4NCl+BUkdoWFZN+Li9wn5iv51OgGX3jzhPbCyiG7xwKAfpQZtCY5 y1gripuLlaxRqXDz6eQ9LTVt1z4j/+s= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IqJ9FeBb; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=buBCJSoE; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=wra20jGo; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=QGF3yu+y; dmarc=none; spf=pass (imf30.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706541966; a=rsa-sha256; cv=none; b=ehu5BP3g2VoPsPa6JoQWvaK4M5zrtb3z4P0ckJtOGjjdOjFNaA2W/NmV59rS7R5WQgDe+l qEy4lRjTJhXXeWKF8n2hVSR+3uYmvEvBCANI9aldJjwGgGsVzEtNkmxaBXm8L3Uu/K/ouT PfAiTYTV+TmjsOOYzLu9Dm8m6aZxu74= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B26A01F7EF; Mon, 29 Jan 2024 15:26:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1706541963; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jh9pQCHiNrOIgT4Qx0ZOIp8ky/ddjw+KrmlzKD3GTFA=; b=IqJ9FeBbPT86udoxla6bPHyxwjxJzWqX7LKUgjJK80R5KnYwWbAAOHeWSivRHKTim9jS4C AGd8isc43iGspBrV087KRzqkHx8cDtcjOGfxumSF+UmpfzhTsaGPVyd4WF8uG3cjFqYFIq LvI6iAgggiWgMe7TcwdX8ZurFxm3emA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1706541963; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jh9pQCHiNrOIgT4Qx0ZOIp8ky/ddjw+KrmlzKD3GTFA=; b=buBCJSoENZMrlJF3gAtTCcP9YbSkzSTmYZPOMOHmNSfSKzKJyT1yHabOIKQWMQHSFjiKmM VXdS65hxh/BSTgDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1706541961; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jh9pQCHiNrOIgT4Qx0ZOIp8ky/ddjw+KrmlzKD3GTFA=; b=wra20jGo4/gxClPMQNEDxg3qKNEOScanFSiG/ETsrUypOo2JjVxnSwInEkTN/6LLJK8vVk lr0dEOzA4BY/h9s6rmQy5uO24sZFxM4CfUUU/8H/5uZXweZKJ7QtHpxtCVrjufuWVnL4al 7ChaBUZLjJahSiWbJ1BTuv9XGk79JKw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1706541961; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jh9pQCHiNrOIgT4Qx0ZOIp8ky/ddjw+KrmlzKD3GTFA=; b=QGF3yu+yO4l0N6y9I54yuTV433cHTbnUtte7rHsiobjlibNuPusNpVGfX31J18kGHt/OrC c9YEFnT6c3ldgqDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6548013647; Mon, 29 Jan 2024 15:26:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id dcSQF4nDt2U4RAAAD6G6ig (envelope-from ); Mon, 29 Jan 2024 15:26:01 +0000 Message-ID: <2068cfca-b99b-4cf0-addc-43376c2681cb@suse.cz> Date: Mon, 29 Jan 2024 16:26:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 11/25] x86/sev: Adjust directmap to avoid inadvertant RMP faults Content-Language: en-US To: Borislav Petkov , Michael Roth Cc: x86@kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, tobin@ibm.com, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, jarkko@kernel.org, ashish.kalra@amd.com, nikunj.dadhania@amd.com, pankaj.gupta@amd.com, liam.merwick@oracle.com References: <20240126041126.1927228-1-michael.roth@amd.com> <20240126041126.1927228-12-michael.roth@amd.com> <20240126153451.GDZbPRG3KxaQik-0aY@fat_crate.local> <20240126170415.f7r4nvsrzgpzcrzv@amd.com> <20240126184340.GEZbP9XA13X91-eybA@fat_crate.local> <20240126235420.mu644waj2eyoxqx6@amd.com> <20240127114207.GBZbTsDyC3hFq8pQ3D@fat_crate.local> <20240127154506.v3wdio25zs6i2lc3@amd.com> <20240127160249.GDZbUpKW_cqRzdYn7Z@fat_crate.local> <20240129115928.GBZbeTIJUYivEMSonh@fat_crate.local> From: Vlastimil Babka In-Reply-To: <20240129115928.GBZbeTIJUYivEMSonh@fat_crate.local> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 6DFF680025 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: eooz8ks5q8br3k6em1b86699uksns4rx X-HE-Tag: 1706541965-601144 X-HE-Meta: U2FsdGVkX19NXVSvdsYLDXiezbHeUSn8JYpzUYawAe95KzBB1IptzzJNZ/ktBESsdbnwEY/8q20Ar/mD6D6498nzDcWE+WqvkBBqfGfJjoyplevetpV+QRuohaUwB0XvzdO759JaGZGUQpZ6Q1JJa1msJD8mYSRWLCpSbLDAX754HxKg1m4Mbugub4P65lT0CwUr0gUPE0nCRk8SIcM1XQhG63QJ1knQDc1QQdBsnQD/cT2tQX5dyCWO1Ty4afFZu2XRPIfaFwoNDqh36ppCmw1l5YcYSwaqQsRl1TVD8P8b7OjIbfZHUjE2WbBWPAzYDTcarAFYf5t5iynYgI40PiNAfHrZlsdwfU4SIPN652bXOhPd3KTxESaebRR8cdI41cgrWUm0tSr+NQZzTOIVaeI7O3bfCGjNb6UF5AIS5DtBrEILGqLn3MrxArEZo5HK+wrblAUWZIZ6kOJpfABkP34QttDjrVW8J6NQvCAhUGP5fUYK1MN+5cNyrNCPPodAdXEvMowExAmkx8RjCMxCRF3tYTzbVFKDEw7RVJcmenyRyhVlp9ydcI2UuQPs9uTpwfoZ7yDBaCE2QT6LX5gCW7wyqLIlubv+HMpwL8xEee4kJzzH5Tz9co1Ie90VfxkJ3kV4PYQafgzMHBr8AIRC+JegOzl2Qg3o9lqmux3D9edxwE3rH+suHFwKfSSrUQO+wmk+7QmTb+VOhRZNUUHCmGTjvi+srcn4FSVsDJ5Fu5TA1VMGXd3yhOqtLXFu4xVOIMzm4lvWtXYJcOjef1hYnOQx2SgFJlxl/Z4+lYLQ2UA8zzLu5FUVxmWgS8sATu2IYmgmcxm0n422HcRyGfHuqVH4HHQ+7Yo5U0k897CVny6dzzqhzGfTVhhvC2CVD/qZj07svinolK0liJ73Cxtvi/lld1W2M2tkctI4gShbfWv0+w8opiZGLelB4f/Ek3YN X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 1/29/24 12:59, Borislav Petkov wrote: > On Sat, Jan 27, 2024 at 05:02:49PM +0100, Borislav Petkov wrote: >> This function takes any PFN it gets passed in as it is. I don't care >> who its users are now or in the future and whether they pay attention >> what they pass into - it needs to be properly defined. > > Ok, we solved it offlist, here's the final version I have. It has > a comment explaining what I was asking. > > --- > From: Michael Roth > Date: Thu, 25 Jan 2024 22:11:11 -0600 > Subject: [PATCH] x86/sev: Adjust the directmap to avoid inadvertent RMP faults > > If the kernel uses a 2MB or larger directmap mapping to write to an > address, and that mapping contains any 4KB pages that are set to private > in the RMP table, an RMP #PF will trigger and cause a host crash. > > SNP-aware code that owns the private PFNs will never attempt such > a write, but other kernel tasks writing to other PFNs in the range may > trigger these checks inadvertently due to writing to those other PFNs > via a large directmap mapping that happens to also map a private PFN. > > Prevent this by splitting any 2MB+ mappings that might end up containing > a mix of private/shared PFNs as a result of a subsequent RMPUPDATE for > the PFN/rmp_level passed in. > > Another way to handle this would be to limit the directmap to 4K > mappings in the case of hosts that support SNP, but there is potential > risk for performance regressions of certain host workloads. > > Handling it as-needed results in the directmap being slowly split over > time, which lessens the risk of a performance regression since the more > the directmap gets split as a result of running SNP guests, the more > likely the host is being used primarily to run SNP guests, where > a mostly-split directmap is actually beneficial since there is less > chance of TLB flushing and cpa_lock contention being needed to perform > these splits. > > Cases where a host knows in advance it wants to primarily run SNP guests > and wishes to pre-split the directmap can be handled by adding > a tuneable in the future, but preliminary testing has shown this to not > provide a signficant benefit in the common case of guests that are > backed primarily by 2MB THPs, so it does not seem to be warranted > currently and can be added later if a need arises in the future. > > Signed-off-by: Michael Roth > Signed-off-by: Borislav Petkov (AMD) > Link: https://lore.kernel.org/r/20240126041126.1927228-12-michael.roth@amd.com Acked-by: Vlastimil Babka Thanks!