Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp839465imn; Tue, 26 Jul 2022 10:40:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tlDvtBDNfnAsoPp8IrpZRcFUZ8THGLOKWS0zKYjhRbLaXbhNSHDArTbzYMKQiK/QweG1CY X-Received: by 2002:a17:907:6d1d:b0:72b:6d8a:ca64 with SMTP id sa29-20020a1709076d1d00b0072b6d8aca64mr14959153ejc.371.1658857202640; Tue, 26 Jul 2022 10:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658857202; cv=none; d=google.com; s=arc-20160816; b=Ppa3rVkki8dTlVEeixJgGpHgvgmoMmmFR1UehZy0lt5FD5ZIlSu/1YDcmw86QTGnSt /XQs/plpRW+Gn7mgwIufCZE2AXiK7d1K1846X1+sHklHuzf68gJIE02lFdJkgJgXBsl0 EnQ6eW9/EdZinNLrjwKtJ25fUdvmUe00wyrVwyANojT5NH9u0RJrAssBLVy3DGJ82+N3 fK5L3Axykl2Blb2ZlWOc9K+6Akx9E4DmNm6XNA7M6zOnkF0UX02woquk4c09GnbvRL+V W71mS9dqWLCAd4C/M4/msYMCD4NiqO6gexAi2e93pUNZ9+9LJy5BTzSLVyxwOP1B9wEG 35yw== 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:dkim-signature; bh=Zc808cWbuiJ1LaEmAlRr5AvsxdqrezqcJtLhbo5Uy7g=; b=XTUnNZwUm5hiA1sjsFTZZd/zDwj/1rZXn7U+ZG0K3IsARFOauyjDr6OfG/CgUwLgSe ROIay4h+njNuSJwwn87slGpo7kAs3Lfx+9eAQXeFVbo0gXCQEUeW3UgumkKKSRASVkDV NEZ+3bngfmkWRwctlQZqUfrvuozRHyeVlqXQ45//ExuTy/EQLq8EVJ6Nf0/cx3qALirC khxpVLbBh6d/EG4gnV1W2ANLaIY10Sb4ykE+Blg1XfEb0QrR0Ovequull/kNK9qR8WEP iu9VadKoCGo9w6Qai30dBwg1MriZd9+uhL48XeI05NOzS2U6athpMCoO8mRTaEHojYL/ IOFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="ql/OkaR/"; 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=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a05640242d100b0043a72c8b750si20392550edc.114.2022.07.26.10.39.37; Tue, 26 Jul 2022 10:40:02 -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=@alien8.de header.s=dkim header.b="ql/OkaR/"; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233910AbiGZRZW (ORCPT + 99 others); Tue, 26 Jul 2022 13:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbiGZRZU (ORCPT ); Tue, 26 Jul 2022 13:25:20 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6697B642C; Tue, 26 Jul 2022 10:25:19 -0700 (PDT) Received: from zn.tnic (p200300ea970f4ff2329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:970f:4ff2:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 7E2BA1EC0373; Tue, 26 Jul 2022 19:25:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1658856313; h=from:from: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; bh=Zc808cWbuiJ1LaEmAlRr5AvsxdqrezqcJtLhbo5Uy7g=; b=ql/OkaR/2POULdFAydeXv9SQYYLAW2Oguhc/zysyKU429tW8xTTiXOcCVj73rfKKSdqrp9 S2n5W66hmjC11W1t+j5O+pllUu0utmqWbzKTSg7rCsEUxTCKefdk+G0CusKKEjYT9YMGhP 1I2mP9ZoAv/WhylmeLh+Gcmv8J0BS9Q= Date: Tue, 26 Jul 2022 19:25:09 +0200 From: Borislav Petkov To: "Kirill A. Shutemov" Cc: Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , Dave Hansen , Mike Rapoport , David Hildenbrand , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv7 10/14] x86/mm: Avoid load_unaligned_zeropad() stepping into unaccepted memory Message-ID: References: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> <20220614120231.48165-11-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220614120231.48165-11-kirill.shutemov@linux.intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 Tue, Jun 14, 2022 at 03:02:27PM +0300, Kirill A. Shutemov wrote: > diff --git a/arch/x86/mm/unaccepted_memory.c b/arch/x86/mm/unaccepted_memory.c > index 1df918b21469..bcd56fe82b9e 100644 > --- a/arch/x86/mm/unaccepted_memory.c > +++ b/arch/x86/mm/unaccepted_memory.c > @@ -23,6 +23,38 @@ void accept_memory(phys_addr_t start, phys_addr_t end) > bitmap = __va(boot_params.unaccepted_memory); > range_start = start / PMD_SIZE; > > + /* > + * 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. > + * > + * There are three parts to fix this issue and comprehensively avoid > + * access to unaccepted memory. Together these ensure that an extra > + * “guard” page is accepted in addition to the memory that needs to be > + * used: > + * > + * 1. Implicitly extend the range_contains_unaccepted_memory(start, end) > + * checks up to end+2M if ‘end’ is aligned on a 2M boundary. > + * > + * 2. Implicitly extend accept_memory(start, end) to end+2M if ‘end’ is > + * aligned on a 2M boundary. Why do we need those unicode quotes and backticks in there? verify_diff: Warning: Unicode char [“] (0x8220 in line: + * “guard” page is accepted in addition to the memory that needs to be verify_diff: Warning: Unicode char [‘] (0x8216 in line: + * checks up to end+2M if ‘end’ is aligned on a 2M boundary. verify_diff: Warning: Unicode char [‘] (0x8216 in line: + * 2. Implicitly extend accept_memory(start, end) to end+2M if ‘end’ is verify_diff: Warning: Unicode char [‘] (0x8216 in line: + * needs to be done to make ‘page’ usable. That work might include verify_diff: Warning: Unicode char [‘] (0x8216 in line: + * accepting pages in addition to ‘page’ itself. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette