Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1280064pxb; Tue, 17 Aug 2021 08:02:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzC08Q+daVPGXScKj/Q2/KmQOaNjlO9HbrVv2j9+JllYRN6IoNAxmB+hL3N5BhL4JgWVvab X-Received: by 2002:a05:6602:1503:: with SMTP id g3mr3255914iow.25.1629212558156; Tue, 17 Aug 2021 08:02:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629212558; cv=none; d=google.com; s=arc-20160816; b=NeEusKoPRAWklHshqRj9mTztRyeaTVMhqiLjhfM/QUOIpRruCq7VpTru3kEK+vrvdx 8PoXF77eLIg3TOWVKsKKr/tcCXLjbW1x+skjZUd7wPfaZEb4x9rYzKI4KNoFRZOkOgTE 6SVh30d2YTub2qRK+7jJSPgSHOH6XqjP/PZoXGwApXAagyyaJ2zFgUJ9t2+xGnI1RB2G lVm3sc5aXjv8Pz/3rltFMjcMi6GAVsIpfyjqLi5pg8cOfqCwY1ogugmBcbuInjCyrRsB xwBfO1zJULazect/pjDzWjadC5UYsmMPbVRPhUSm+GOG+HvEa0m8iOPl1bGWAoSG99/Q Ne8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject :organization:from:references:cc:to:dkim-signature; bh=yGg8Z4A5xf8oGJMYeSLD5P5QfCrx/EVCnSOaaJXq7EU=; b=jMZGv5zoqswP0PPo173S2OpCfK7hrjMflkTExJ26o6e9BByO37htWAPrSNbaosEa1R MRJtDHa3wOHHu9H+tFONW6QNb2vAd7B7HWE9HdQjfwtUugNADEVgI87JUIcOeQ7H3706 YS30DdIllYsYJb+Edl8hpb1D4t8dCJRBA5+vbx1IWouuC5w3YFuhihzIrvOk4OGpUJxK C2y3cIw13O45BiJ4Nn+R2eh2v/gVa25ByW1hG+FueWBMTbtMEgAnsUjO68RADxR1DTd/ ZvEgfB1VPqwYhzgfV3xZecg9qvcTUOEfE2Dm9fIbE8GYj0KIpDZShKbDbT8ocQWNjfUR pRDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B6XOq4Yu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si118790jat.94.2021.08.17.08.02.26; Tue, 17 Aug 2021 08:02:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B6XOq4Yu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238763AbhHQPBe (ORCPT + 99 others); Tue, 17 Aug 2021 11:01:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49434 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236978AbhHQPBe (ORCPT ); Tue, 17 Aug 2021 11:01:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629212460; 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=yGg8Z4A5xf8oGJMYeSLD5P5QfCrx/EVCnSOaaJXq7EU=; b=B6XOq4YuyvfhipDRykN/9sY6QnzZsK4vpJivkTx+5j1+vtJ000USgqryvCgQ3GX32QLVf7 9QSmMbfCej5Q+go9b5yWkp57bFPg1J7DnXy3kGuSjmfiTQFuolIu4aAybiQlTV8FoSknuI iY0IhJzFj4lm7bGgEyZZQUJMaFOasuM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-O6Y0Cc75NdusiSjJyoK1AQ-1; Tue, 17 Aug 2021 11:00:59 -0400 X-MC-Unique: O6Y0Cc75NdusiSjJyoK1AQ-1 Received: by mail-wr1-f71.google.com with SMTP id a9-20020a0560000509b029015485b95d0cso6713230wrf.5 for ; Tue, 17 Aug 2021 08:00:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=yGg8Z4A5xf8oGJMYeSLD5P5QfCrx/EVCnSOaaJXq7EU=; b=l5XhlTD+7jbDf4Mc7axwtDaG/xRA90dzijUKbl1Mtk9bWrkMDSFS1dQl+nzKjNUTgQ OGfdEhMVnyafJ103IktinCEZAW+jAqNNCariBDC1rbLjKTwVGBlrepTE6fYT22Q26In5 ojhZj1PSxjQrTVV09cprdrI2NQJsK+Esd4q19rpRZEA67EQm6FCVAdkCP2MSbwUzZ0kM pPd7ii8Wof2eJHdkcYrws6AwA3iVaMkdIavxXQDYm4d9XhxqENE4cilG7mYknhy0GMjy khol+9zreBrxmX4TEd+ELlpzGZNuA9/+/P+awAX3Y9EBymmQwHRQMQS82wzhgaQj0EAe Mwtw== X-Gm-Message-State: AOAM533rLDV/IVA3PVUTC8Ho6dNAhyvUG1tqnrrsf8IfBZ44lpAnI8JS ZcM8M8IuhgDrgrE3KdyxPmUMX5TqP1ajEWMEACTesT/kEPGyQHmidfA4Xo3BhbU3wftltzPtJ9V opkXL1IU2rTjM+NMMGpNTZafl X-Received: by 2002:a5d:5646:: with SMTP id j6mr4609611wrw.314.1629212457442; Tue, 17 Aug 2021 08:00:57 -0700 (PDT) X-Received: by 2002:a5d:5646:: with SMTP id j6mr4609574wrw.314.1629212457208; Tue, 17 Aug 2021 08:00:57 -0700 (PDT) Received: from [192.168.3.132] (p5b0c65c6.dip0.t-ipconnect.de. [91.12.101.198]) by smtp.gmail.com with ESMTPSA id w14sm2674088wrt.23.2021.08.17.08.00.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Aug 2021 08:00:56 -0700 (PDT) To: Joerg Roedel , Dave Hansen Cc: Andi Kleen , "Kirill A. Shutemov" , Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" References: <20210810062626.1012-1-kirill.shutemov@linux.intel.com> <20210810062626.1012-2-kirill.shutemov@linux.intel.com> <9748c07c-4e59-89d0-f425-c57f778d1b42@linux.intel.com> <17b6a3a3-bd7d-f57e-8762-96258b16247a@intel.com> <796a4b20-7fa3-3086-efa0-2f728f35ae06@linux.intel.com> <3caf5e73-c104-0057-680c-7851476e67ac@linux.intel.com> <25312492-5d67-e5b0-1a51-b6880f45a550@intel.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 1/5] mm: Add support for unaccepted memory Message-ID: Date: Tue, 17 Aug 2021 17:00:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13.08.21 16:49, Joerg Roedel wrote: > Hi Dave, > > On Thu, Aug 12, 2021 at 07:14:20AM -0700, Dave Hansen wrote: >> maybe_accept_page() >> { >> unsigned long huge_pfn = page_to_phys(page) / PMD_SIZE; >> >> /* Test the bit before taking any locks: */ >> if (test_bit(huge_pfn, &accepted_bitmap)) >> return; >> >> spin_lock_irq(); >> /* Retest inside the lock: */ >> if (test_bit(huge_pfn, &accepted_bitmap)) >> return; >> tdx_accept_page(page, PMD_SIZE); >> set_bit(huge_pfn, &accepted_bitmap)); >> spin_unlock_irq(); >> } > > Yeah, this could work, but the global lock is likely the show-stopper > here. For SNP we also not allowed to double-validate, so we need > something that basically indicates 'validation-is-ongoing' on a per 2MB > basis. > > I am not an mm expert, but a page flag probably doesn't work. The flag > would be on the head of the 2MB range and when that page is already used > somewhere else there is no guarantee that the flag will survive. But > correct me if I am wrong here :) > > The other options I can come up with are not great either: > > 1) using an AVL bit in the direct-mapping PMD of that page. The > page-table would only be walked if the bit in the > accept_bitmap is clear. But I am not sure that all memory > which needs to be validated is in the direct-map. > > 2) Use another page-sized bitmap. If the machine has more than > 64GB of memory the bit index is wrapped around. This > shouldn't be a performance problem at runtime, if this page > is only consulted when the valid bit is clear in the > accept_bitmap. > > MM experts could certainly come up with better ideas :) Not sure if already discussed, but what about making sure that free pages are not a mixture (partially unaccepted, partially accepted). You'd have to expose the pages in that granularity to the buddy (__free_pages_core), indicating the state. You'd have to reject merging pages of differing acceptance state. Accepting a page would then be handled outside of the zone lock, completely controlled by the state. So a page in the buddy would either be completely accepted or completely unaccepted, signaled e.g., by PageOffline(). Consequently, when allocating a 4KiB page, you'd split an unaccepted 2MiB page into separate unaccepted pages. You'd grab one of the unaccepted 4KiB pages and accept it before initializing it and handing it out. -- Thanks, David / dhildenb