Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp846886rwb; Sat, 13 Aug 2022 10:01:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR49kCXFgNy4LUzCiSCUvHOaJR8ePT0ORG+RxyhLY1H7dL26YH/GN6sMbXNpuqE4EMjHdfnt X-Received: by 2002:a17:90b:350a:b0:1f5:6a5e:5d12 with SMTP id ls10-20020a17090b350a00b001f56a5e5d12mr19781144pjb.46.1660410110512; Sat, 13 Aug 2022 10:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660410110; cv=none; d=google.com; s=arc-20160816; b=CtIFegDXAHrK9gpKceXKEqfAK+tnItoMAlVzUGHE+pE7Cfg+sTCrmn1l6peGnGDA9D 8vuhyRg5WnZ0LWdUnVacTiZm4FZAoVEFRT7uiWCVId8d9ptb0fk8ksCO5ORy8So7/+qA xYH0xUxfhgHg52YyCQ+J2aUyCG/8spgTJLfg2zeF6hCR0bLwotiNbWk/ajDofWVBVQVd uRQrqJ5S1Yjsqo3ZIkDfklHgCPohfb2pywIP2EP/gisARMvfkCs6ee2wXiskcRL86w1l j8OPx0rRekDt1RGjrYD8QlKlyrKl644HVNQSff1jD72m+rigVUVOE51UoREF6nVt1z3e +0mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:cc:to:from :date:references:in-reply-to:message-id:mime-version:user-agent :feedback-id:dkim-signature; bh=QkjISwrhI0K6AqWr0s0984uyVFFnPkGFa50oEfAuhdM=; b=GFv65QOPJOoF9CB+9lQV8sagnSG3zlXXJeZ0IsAubzXDE4+C7gLQKIxCTlywjQVquT DX1M+yaIe9tXq2WrCvr88mYyOQLQF7eS1ckls/XtaACnvA2i1kPJz7mh3tqF8LB+L9iG tiFYgC2RQmALxQXIJ5yN2twjI6GL8H3R6ypCtKzzL/1c2y1ihcOp4x7Kq2sVybhofNS0 GUoG9ThgbLqUoNNG2UoXzFDffk61rQLCwQog/ITGpK5YIHJGXnVFm8t8cUmwSzLaYyes LWICtjWd277lbn6+4JYkIFy2gZzxL5RhWmsy33uuame8vy9gJqxzvIY63I4Vhobv6UwQ Cl0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PhTckigv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r24-20020a6560d8000000b0041cfc9ef388si5985712pgv.159.2022.08.13.10.01.33; Sat, 13 Aug 2022 10:01:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PhTckigv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239795AbiHMQDn (ORCPT + 99 others); Sat, 13 Aug 2022 12:03:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235696AbiHMQDm (ORCPT ); Sat, 13 Aug 2022 12:03:42 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 556F2BE27 for ; Sat, 13 Aug 2022 09:03:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 8FECACE0989 for ; Sat, 13 Aug 2022 16:03:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F0E7C433B5; Sat, 13 Aug 2022 16:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660406617; bh=8AKntuXc65i1saqB877W3R6RYDsPiOzfHdOG82gubqU=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=PhTckigvrk6wORM1yefMuhw4OzzCT5g0MqPXfKBkB8Ikh82SWyxGormHL2RVr4qaa 5RaurmRXRFFSNRxF4WZl0vecbOzuu815Ii4L3Bvj5VRZN4Padu85IFiJaSZXzV/uTj bkAC3PraOdUJ3Rn3lWl+DmWbtt/fAEPmj9x3xH7d31AtXJtDZVyoZ4C0UWM/ti7blF TQ+CDO8qaPlwRFWZqW7TEIkNT01056UTuWfVNyCayV1STzUhrHZQLNS71p3Bjx7s8E 9q/siV67O39uPnKXtapHZ4pyNVn6akegu/zvDkxPnOshvvzsDsIMA0bws64+k+llO5 jijaAWyfZbLmw== Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 6EC2127C0054; Sat, 13 Aug 2022 12:03:35 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute2.internal (MEProxy); Sat, 13 Aug 2022 12:03:35 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdegkedgleekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtgfesthhqredtreerjeenucfhrhhomhepfdet nhguhicunfhuthhomhhirhhskhhifdcuoehluhhtoheskhgvrhhnvghlrdhorhhgqeenuc ggtffrrghtthgvrhhnpeduveffvdegvdefhfegjeejlefgtdffueekudfgkeduvdetvddu ieeluefgjeeggfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegrnhguhidomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqudduiedu keehieefvddqvdeifeduieeitdekqdhluhhtoheppehkvghrnhgvlhdrohhrgheslhhinh hugidrlhhuthhordhush X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id BB8CF31A0062; Sat, 13 Aug 2022 12:03:33 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-841-g7899e99a45-fm-20220811.002-g7899e99a Mime-Version: 1.0 Message-Id: <453fb432-ac13-4819-8395-95561bca948b@www.fastmail.com> In-Reply-To: <20220809113827.fchtnyzy44z5fuis@box.shutemov.name> References: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> <20220614120231.48165-11-kirill.shutemov@linux.intel.com> <7cec93c5-3db4-409b-8c1e-bc1f10dd68fc@www.fastmail.com> <20220809113827.fchtnyzy44z5fuis@box.shutemov.name> Date: Sat, 13 Aug 2022 09:03:13 -0700 From: "Andy Lutomirski" To: "Kirill A. Shutemov" Cc: "Borislav Petkov" , "Sean Christopherson" , "Andrew Morton" , "Joerg Roedel" , "Ard Biesheuvel" , "Andi Kleen" , "Sathyanarayanan Kuppuswamy" , "David Rientjes" , "Vlastimil Babka" , "Tom Lendacky" , "Thomas Gleixner" , "Peter Zijlstra (Intel)" , "Paolo Bonzini" , "Ingo Molnar" , "Varad Gautam" , "Dario Faggioli" , "Dave Hansen" , "Mike Rapoport" , "David Hildenbrand" , "Marcelo Henrique Cerri" , tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, "the arch/x86 maintainers" , linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, "Linux Kernel Mailing List" Subject: Re: [PATCHv7 10/14] x86/mm: Avoid load_unaligned_zeropad() stepping into unaccepted memory Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 9, 2022, at 4:38 AM, Kirill A. Shutemov wrote: > On Tue, Jul 26, 2022 at 01:17:13PM -0700, Andy Lutomirski wrote: >>=20 >>=20 >> On Tue, Jun 14, 2022, at 5:02 AM, Kirill A. Shutemov wrote: >> > load_unaligned_zeropad() can lead to unwanted loads across page bou= ndaries. >> > The unwanted loads are typically harmless. But, they might be made = to >> > totally unrelated or even unmapped memory. load_unaligned_zeropad() >> > relies on exception fixup (#PF, #GP and now #VE) to recover from th= ese >> > unwanted loads. >> > >> > But, this approach does not work for unaccepted memory. For TDX, a = load >> > from unaccepted memory will not lead to a recoverable exception wit= hin >> > the guest. The guest will exit to the VMM where the only recourse i= s to >> > terminate the guest. >>=20 >> Why is unaccepted memory marked present in the direct map in the firs= t place? >>=20 >> Having kernel code assume that every valid address is followed by >> several bytes of memory that may be read without side effects other t= han >> #PF also seems like a mistake, but I probably won=E2=80=99t win that = fight. But >> sticking guard pages in front of definitely-not-logically present pag= es >> seems silly to me. Let=E2=80=99s just not map it. > > It would mean no 1G pages in direct mapping for TDX as we accept 2M a > time. > >> (What if MMIO memory is mapped next to regular memory? Doing random >> unaligned reads that cross into MMIO seems unwise.) > > MMIO is shared, not unaccpted private. We already handle the situation. > See 1e7769653b06 ("x86/tdx: Handle load_unaligned_zeropad() page-cross= to > a shared page"). > I don=E2=80=99t mean in a confidential guest =E2=80=94 I mean generally.= This whole model of =E2=80=9Coverrun the buffer =E2=80=94 no big deal=E2= =80=9D is just fragile. > --=20 > Kiryl Shutsemau / Kirill A. Shutemov