Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1312871rwd; Tue, 16 May 2023 15:24:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5tqEZONqD9qJqQmteOj5UrbWF73i75CKHTI1qf9fE9hlacnb/3P2nxehl8MfrIcYVyIheg X-Received: by 2002:a05:6a20:3caa:b0:105:f8e4:7227 with SMTP id b42-20020a056a203caa00b00105f8e47227mr12052247pzj.33.1684275894526; Tue, 16 May 2023 15:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684275894; cv=none; d=google.com; s=arc-20160816; b=NUndlSTXq3vb/ZuQ5nwl0Uub7/4IcvUs/rH6YTz+Og+d25dtmYs3tOD4wLHZ7lE4iO MY1LBnX3f6eibkQibxtWhkUwuaM7GzbJnguw4EVevVy2C7PEkLuqKafIrDnOBLzQGbVR Gf/rdbz+VC/IlwXJDYETS6/kteoucA8fFN4FWGa0VGpDSXBxFMlw63Ailga/3onHJ+BH nUGGifQxv+RQyKRR8MTnm00sRz9KsxNqjUqRhJIhq2L0t6ZDWxLisEtX+5iDM+x0cwDT Ho+m7Nesk2UvF29YAXmhdUAFUmodugYl3Nn+aMF4u+aWAT5FE/nssCcdhsZs/1TXE3PR EALA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Pb/qFhxBLgovJmQJ0/96J8qVL7adD4F5qjbc56++jyQ=; b=Xz1ZcpCDlGomsQlU6mkO+QpEto3HJKsTROxfz2JTslPHMZ7cga3avaPej+M+rk34GW QWRzLZucq09l8kOvHljL8ZZr/lysF5y/8TwJ07q+sZqg6ACv8vngrPt5vpin6VNgaNj7 DfQORr28pOHAiFLaGjWniKWGetnAabbp7F4kSxuBFhvGzOsgGPWrEcrCDbJb3Fs0CRFP vsBwakkpfkkqI23azUaM3Dv0lXDqT+vM5jWAoAOveazMteBFebhhBmoZ5G5j3oN8G/ZI 9UApC6EwysjHxMNZ+9+ikzu0ahNew5kje3wN64ZndPVbn1JTEHz/G1o9/Ze+Lr+xTJzV 0uoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G+BtFuRt; 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 s21-20020a63af55000000b005285958c85bsi15482274pgo.807.2023.05.16.15.24.40; Tue, 16 May 2023 15:24:54 -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=G+BtFuRt; 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 S229555AbjEPWPs (ORCPT + 99 others); Tue, 16 May 2023 18:15:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjEPWPr (ORCPT ); Tue, 16 May 2023 18:15:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F7864231; Tue, 16 May 2023 15:15:46 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1F7C363CF5; Tue, 16 May 2023 22:15:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A8E5C433AC; Tue, 16 May 2023 22:15:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684275345; bh=1CVkm2h1qch1auKHIlF0XC2larxx6NtF2jvkbfM3xkE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=G+BtFuRtmO43VpHUyXzzLrGRiKKiGKFzaJ1G/xmVPtKgURUm2bRbh7ubHUJ8D0d+3 W/LOKo/w1wOQozubpTzz1KvUk2ZAUhzOHIUxuNavpfJojgyYnMt9AW43CCV4d6vTCp a8zC53EjQerVUtIpToCHqUFWSjlhqQ4Yt+H02t5L44VdcOY8eppFQ1zoDZf6XVyyid 6GNrGrulqtB6stMf+Sz56LomEbpd+NNlUETl308W7lS7/zEwSgNEtbv051wM/eGYK+ +LJTtsZA3ObVScGmI25LRKPJahNG4iIN70fuQ5Lfd0mgACBkUXqaarrFEqe0XYOjxD E+9QCs9rGZNrQ== Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-4f37b860173so101101e87.2; Tue, 16 May 2023 15:15:45 -0700 (PDT) X-Gm-Message-State: AC+VfDxiIuXE0NRwDsFPc/hKnY7lywcNXYILQfogCAx+X/xj5TpkeFIG Co2ar3H7Ds+PYKKmhdsCa25L6oUgjuoUCXSFJN4= X-Received: by 2002:ac2:5285:0:b0:4f2:6857:1d98 with SMTP id q5-20020ac25285000000b004f268571d98mr5554640lfm.48.1684275343279; Tue, 16 May 2023 15:15:43 -0700 (PDT) MIME-Version: 1.0 References: <20230513220418.19357-1-kirill.shutemov@linux.intel.com> <20230513220418.19357-7-kirill.shutemov@linux.intel.com> <6fe42f66-819c-f2c8-176b-759c1c5a9cf5@intel.com> <20230516215210.pviqojbr5o4hd6bb@box.shutemov.name> In-Reply-To: From: Ard Biesheuvel Date: Wed, 17 May 2023 00:15:32 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCHv11 6/9] efi/unaccepted: Avoid load_unaligned_zeropad() stepping into unaccepted memory To: Dave Hansen Cc: "Kirill A. Shutemov" , "Kirill A. Shutemov" , Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Dario Faggioli , Mike Rapoport , David Hildenbrand , Mel Gorman , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, aarcange@redhat.com, peterx@redhat.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Hansen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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 Wed, 17 May 2023 at 00:00, Dave Hansen wrote: > > On 5/16/23 14:52, Kirill A. Shutemov wrote: > > On Tue, May 16, 2023 at 01:03:32PM -0700, Dave Hansen wrote: > >> On 5/16/23 11:35, Ard Biesheuvel wrote: > >>>>> Does this mean that the kernel maps memory before accepting it? As > >>>>> otherwise, I would assume that such an access would page fault insi= de > >>>>> the guest before triggering an exception related to the unaccepted > >>>>> state. > >>>> Yes, the kernel maps memory before accepting it (modulo things like > >>>> DEBUG_PAGEALLOC). > >>>> > >>> OK, and so the architecture stipulates that prefetching or other > >>> speculative accesses must never deliver exceptions to the host > >>> regarding such ranges? > >> I don't know of anywhere that this is explicitly written. It's probab= ly > >> implicit _somewhere_ in the reams of VMX/TDX and base SDM docs, but he= ck > >> if I know where it is. =F0=9F=98=84 > > It is not specific to TDX: on x86 (and all architectures with precise > > exceptions) exception handling is delayed until instruction retirement = and > > will not happen if speculation turned out to be wrong. And prefetching > > never generates exceptions. > > Not to be Debbie Downer too much here, but it's *totally* possible for > speculative execution to go read memory that causes you to machine > check. We've had such bugs in Linux. > > We just happen to be lucky in this case that the unaccepted memory > exceptions don't generate machine checks *AND* TDX hardware does not > machine check on speculative accesses that would _just_ violate TDX > security properties. > > You're right for normal, sane exceptions, though. Same thing on ARM, although I'd have to check their RME stuff in more detail to see how it behaves in this particular case. But Kyrill is right that it doesn't really matter for the logic in this patch - it just accepts some additional pages. The relevant difference between implementations will likely be whether unaccepted memory gets mapped beforehand in the first place, but we'll deal with that once we have to. As long as we only accept memory that appears in the bitmap as 'unaccepted', this kind of rounding seems safe and reasonable to me. Reviewed-by: Ard Biesheuvel