Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1719813ybz; Thu, 23 Apr 2020 04:34:55 -0700 (PDT) X-Google-Smtp-Source: APiQypLL++jttnd+aeZU+prnnyOVwH2lxfUQ3k47nE9tbbOstrqtJPJOQyqzG5NLfbCJe2LO6Ze5 X-Received: by 2002:a17:906:2d4a:: with SMTP id e10mr2304287eji.222.1587641695385; Thu, 23 Apr 2020 04:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587641695; cv=none; d=google.com; s=arc-20160816; b=a5nTHEooi7DsjY3GXfUrXQvXauhMgp6ayZlZH/xSXVD8K+EQlRmSs9jsqKd2x62h+R b+F60Gi32Rk7bVTrTayO33w2uI9N4UE63JPAxrKFgzFP7or4d9uGbKw0uUJsj2zDo40n OO7QbxDCPm3hOpJeUQU2ab+iS3IBnyu9sTEooipG051VZ8Yu7300By/TqNarQnHFxByu t9gr9iFhiuG3cvfDwwKsz2gTlGxxLiusGP3OY+jRtLgkA7PTvZtJvzFQuIhejgt4KsWv Ob1SqN53hZt3xhL03ZOgyuEIo98BOeHUMfzDzGiZEq2BE/znzBaCAlLncnMA3BMtOQaU tXfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ajyqSpoIhxF3w3nqCNBKwEcVsf7jzh/tWKTQLfLA+vc=; b=SPviIvVgjgWlLM+s3lTk4KRF2jk04q06MOsCUEXI1ZV3SWG0OUjKU9Hf6yztIA34e2 arnpLmTypDH/57OcI3WiVljtp6JgTOqF6rPR1vBENN48ya/1Rvpf13qli3P8F4G1iUk2 7yqeEJxWDlPpEJ2MhPNGpYXz3cnBvYGm2qfqB9XhVbrFKUnky5HzOOh4peUrQJktacNa 2Jg7QeZrpwmdfoy0omoCeq9nBb/wm4DH4xVZ7MDVL7uc3SVThIK29Wgc6VDqfTgZxUOZ Eg9RXxVY2L+Y3QR8HSZ0Ip+zWitJ8QQHzIHJsJ828jAcGsC3m4b5pKdUhCunqMLaBATa ELtg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si1025772edp.0.2020.04.23.04.34.32; Thu, 23 Apr 2020 04:34:55 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728178AbgDWLad (ORCPT + 99 others); Thu, 23 Apr 2020 07:30:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:60130 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727928AbgDWLac (ORCPT ); Thu, 23 Apr 2020 07:30:32 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8C767B120; Thu, 23 Apr 2020 11:30:29 +0000 (UTC) Date: Thu, 23 Apr 2020 13:30:27 +0200 From: Joerg Roedel To: Bo Gan Cc: Mike Stunes , Joerg Roedel , "x86@kernel.org" , "hpa@zytor.com" , Andy Lutomirski , Dave Hansen , Peter Zijlstra , Thomas Hellstrom , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "virtualization@lists.linux-foundation.org" Subject: Re: Re: [PATCH 40/70] x86/sev-es: Setup per-cpu GHCBs for the runtime handler Message-ID: <20200423113027.GL30814@suse.de> References: <20200319091407.1481-1-joro@8bytes.org> <20200319091407.1481-41-joro@8bytes.org> <20200415155302.GD21899@suse.de> <1a164e55-19dd-a20b-6837-9f425cfac100@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1a164e55-19dd-a20b-6837-9f425cfac100@vmware.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 22, 2020 at 06:33:13PM -0700, Bo Gan wrote: > On 4/15/20 8:53 AM, Joerg Roedel wrote: > > Hi Mike, > > > > On Tue, Apr 14, 2020 at 07:03:44PM +0000, Mike Stunes wrote: > > > set_memory_decrypted needs to check the return value. I see it > > > consistently return ENOMEM. I've traced that back to split_large_page > > > in arch/x86/mm/pat/set_memory.c. > > > > I agree that the return code needs to be checked. But I wonder why this > > happens. The split_large_page() function returns -ENOMEM when > > alloc_pages() fails. Do you boot the guest with minal RAM assigned? > > > > Regards, > > > > Joerg > > > > I just want to add some context around this. The call path that lead to the > failure is like the following: > > __alloc_pages_slowpath > __alloc_pages_nodemask > alloc_pages_current > alloc_pages > split_large_page > __change_page_attr > __change_page_attr_set_clr > __set_memory_enc_dec > set_memory_decrypted > sev_es_init_ghcbs > trap_init -> before mm_init (in init/main.c) > start_kernel > x86_64_start_reservations > x86_64_start_kernel > secondary_startup_64 > > At this time, mem_init hasn't been called yet (which would be called by > mm_init). Thus, the free pages are still owned by memblock. It's in mem_init > (x86/mm/init_64.c) that memblock_free_all gets called and free pages are > released. > > During testing, I've also noticed that debug_pagealloc=1 will make the issue > disappear. That's because with debug_pagealloc=1, probe_page_size_mask in > x86/mm/init.c will not allow large pages (2M/1G). Therefore, no > split_large_page would happen. Similarly, if CPU doesn't have > X86_FEATURE_PSE, there won't be large pages either. > > Any thoughts? Maybe split_large_page should get pages from memblock at early > boot? Thanks for you analysis. I fixed it (verified by Mike) by using early_set_memory_decrypted() instead of set_memory_decrypted(). I still wonder why I didn't see that issue on my kernel. It has DEBUG_PAGEALLOC=y set, but it is not enabled by default and I also didn't pass the command-line parameter. Regards, Joerg