Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1003066rwb; Sat, 13 Aug 2022 14:01:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR6CFKg5whTHnl8TS1F365mGLMBtsVbcjsHM3YFTBT00ZELn3OmKDro/J8zJ4q7KS9VHK9BJ X-Received: by 2002:a63:6c42:0:b0:3fe:465:7a71 with SMTP id h63-20020a636c42000000b003fe04657a71mr7942553pgc.101.1660424483859; Sat, 13 Aug 2022 14:01:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660424483; cv=none; d=google.com; s=arc-20160816; b=nUAytUQdxc5bUytTcljXZt454TBahzDqv1eaK/eJeG24mMJF3a2/vDhYPoqqJEkWct IjXwlleV3c55lZW8KEggfwRJ7KiXUwXcOfMxcTTDUDFHrFsxtv/kvi3qXOlfCISu1KCZ CSf49+3rv95FT8Qwhst5AWji2/zCpXTsMVDvbZX3jHyhPhPfGEit5bB19HA3UzWKURmg 2l3a976nNIY+0PwCo9Maunp8rbQhAAV7UzG6brDF0yuqmhYfU4xQPYXHOJYNzkJ0L7Sh k4mq8oOX8S28e8Rlzfy8riugjjIfcq4MBBwZW7OV85sFv3wYOqIWs8Gfdx8c8AWFRfAI t0bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature:dkim-signature; bh=8ehvrQN0pYNFeadixhtX5cZ4eBy7Bgjn0JWqP+l7wXQ=; b=JrQoBhvKMIFtzOjiIGVhdF1/yQj+YDPpYPZRlZssI0RVBrLnfQiFHkDFoZpJnvmvli 2ADK0CdQtr46eUSgzqeXEzfjA5mvM7F1w8MUqlyT2ccQoAl1y37zwimARtP4B/yN7PrN Z7StV6vfD5fPE3Pw7SIpXxrSwFcHr4Y3OBXsgugAEiUc9c8DL57106h8TQRTq8p8K6Ru hN9uOALWjGUzxRd+i6myO2yzJfyT1m7YwBIK7Ugt8BC9fIv/jWImxf9fV+z+pHa49B7l C+m7K5jayKkM9j6lrhPkrzQchsCA/RW7mAPI+8FW/FdZ07+WNmsF3xXMBlbWj6Wn3KH2 OU5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm2 header.b="gFDwk5/6"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="k/y/rtfU"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r75-20020a632b4e000000b0041b089cacfcsi6206938pgr.721.2022.08.13.14.01.12; Sat, 13 Aug 2022 14:01:23 -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=@shutemov.name header.s=fm2 header.b="gFDwk5/6"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="k/y/rtfU"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240287AbiHMU7R (ORCPT + 99 others); Sat, 13 Aug 2022 16:59:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240280AbiHMU7P (ORCPT ); Sat, 13 Aug 2022 16:59:15 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE8E110FDE; Sat, 13 Aug 2022 13:59:13 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 2B8695C0107; Sat, 13 Aug 2022 16:59:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 13 Aug 2022 16:59:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1660424353; x= 1660510753; bh=8ehvrQN0pYNFeadixhtX5cZ4eBy7Bgjn0JWqP+l7wXQ=; b=g FDwk5/6lXnt8IgUJBQ5h3ul+WnJaUqC6rkxWEvv2tFpia49i71CkydK1KyQRQDD7 tFdrCBX0nFbwO2ac4cjfh58oN2SyUIGUMGewk4oGA6t/spNXjma8R8AeTilZ/FHM fIgHoqm4Gt4ACoZNrK99W/TOU2JbDMMyEABj3iMQpk7j3PqAWbzpv0eMpauS9Wyq GCMy+rz4NDG4A/Oc+xvm16J1c/v1AfGcc072nSHEtXA3byTtikqFjdymuQ2hsbQ5 jqtzU0gweDS4Qtxkm0L//zUvrve55VVROdC/j1E4W68G30B8k3OXFu5+Pt+qEdsZ Q3z7tOhGVFvkcIbpcR93A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1660424353; x= 1660510753; bh=8ehvrQN0pYNFeadixhtX5cZ4eBy7Bgjn0JWqP+l7wXQ=; b=k /y/rtfU1c0w9XkXRQQ2h9nUAvJe3+XoGwPui0wznHuh3MWeSsxNaVmbxLt2g0gxV qn3QGn7HklA3lTPFu8x3xaYDrikQa0uRzhUeLf7s5hIQzoIIz1vGgDEImDzla7mY 6atxbGqUfzrAygK5+7BV3wRE3WAYToZQOKhu/ELdLOImaD7n+8ENYA+jAJhH93RI S5p6R5s6r2281WnD4UBdQifTLvMWmZ/foovmWYg2ozAljvmjCPtaKlmObWsbINsK v2jq9v6zXlOA7ScMETizfN/1Pa932O56p+yYYZFLFXIOnRzxz8RSh/bzRKgEA0cR Hx0SAxmFUKXMUK+swjv2g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdegkedgudehkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtugfgjgesthektddttddtjeenucfhrhhomhepfdfm ihhrihhllhcutedrucfuhhhuthgvmhhovhdfuceokhhirhhilhhlsehshhhuthgvmhhovh drnhgrmhgvqeenucggtffrrghtthgvrhhnpefgjeeikefffeefvedugfdtkedvhfdttdei feevtdehgefgjeffleelgffggfdvkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehkihhrihhllhesshhhuhhtvghmohhvrdhnrghmvg X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 13 Aug 2022 16:59:12 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id 57259104A08; Sun, 14 Aug 2022 00:02:15 +0300 (+03) Date: Sun, 14 Aug 2022 00:02:15 +0300 From: "Kirill A. Shutemov" To: Andy Lutomirski Cc: "Kirill A. Shutemov" , 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 Message-ID: <20220813210215.ti7f2vqdg6olthjv@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> <453fb432-ac13-4819-8395-95561bca948b@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <453fb432-ac13-4819-8395-95561bca948b@www.fastmail.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Sat, Aug 13, 2022 at 09:03:13AM -0700, Andy Lutomirski wrote: > > > 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: > >> > >> > >> On Tue, Jun 14, 2022, at 5:02 AM, Kirill A. Shutemov wrote: > >> > load_unaligned_zeropad() can lead to unwanted loads across page boundaries. > >> > 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 these > >> > 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 within > >> > the guest. The guest will exit to the VMM where the only recourse is to > >> > terminate the guest. > >> > >> Why is unaccepted memory marked present in the direct map in the first place? > >> > >> Having kernel code assume that every valid address is followed by > >> several bytes of memory that may be read without side effects other than > >> #PF also seems like a mistake, but I probably won’t win that fight. But > >> sticking guard pages in front of definitely-not-logically present pages > >> seems silly to me. Let’s just not map it. > > > > It would mean no 1G pages in direct mapping for TDX as we accept 2M a > > time. As of now, we don't have a way to recover direct mapping from fragmentation. So once we split 1G to 2M it stays this way. > >> (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’t mean in a confidential guest — I mean generally. This whole > model of “overrun the buffer — no big deal” is just fragile. If you want to remove load_unaligned_zeropad(), I would not object. It can make life easier. I presumed that optimization it brings has measuarable benefit (otherwise, why bother). -- Kiryl Shutsemau / Kirill A. Shutemov