From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36C08C10DC3 for ; Mon, 11 Dec 2023 13:08:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8A756B00E1; Mon, 11 Dec 2023 08:08:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C39CF6B00E2; Mon, 11 Dec 2023 08:08:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADA2B6B00E3; Mon, 11 Dec 2023 08:08:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9FB6D6B00E1 for ; Mon, 11 Dec 2023 08:08:44 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 79C8440672 for ; Mon, 11 Dec 2023 13:08:44 +0000 (UTC) X-FDA: 81554566968.03.F995EC4 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf24.hostedemail.com (Postfix) with ESMTP id C86CA180019 for ; Mon, 11 Dec 2023 13:08:41 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Ty3aJdb8; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=xrT8La9J; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Ty3aJdb8; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=xrT8La9J; dmarc=none; spf=pass (imf24.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702300122; h=from:from:sender: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:dkim-signature; bh=SmntiEclpJUrVX6mOseshDU2f41UdhrdCN/1UahG/nA=; b=GpUsSdZ9XqqBDgwdICF42elnmC8p5D0oqY7J2PVJGh5v+a5q+kYLPaZ6sumCiAuZuWo0Q0 Br2k6glaZb7XyzRkLCI7RhQSGae+nVq7TaY1RsVec6jB8uuH+2hm8K/hIy5PM4A8J4Np5a 8F3dQaDnpIx5dA56Q4EsZUl3D/VU24Q= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Ty3aJdb8; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=xrT8La9J; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Ty3aJdb8; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=xrT8La9J; dmarc=none; spf=pass (imf24.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702300122; a=rsa-sha256; cv=none; b=RijirCxqPwYuwqFfo6Ls76xQR+KOwa6PZbVVS1EIyBbqzCvy597CBPnWw5BWxbJnFDNCHR 9KLQTKDnOJBDhHLEhHiJsYDhd74y2L/q9IbzNHW0zMhfSO4E3N6isNoJOymXOnAvlmaTJv rT9YN02ZkaUAxt62Epn4KeEg5nIaFZo= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 10B761FB8C; Mon, 11 Dec 2023 13:08:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1702300119; h=from:from:reply-to: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=SmntiEclpJUrVX6mOseshDU2f41UdhrdCN/1UahG/nA=; b=Ty3aJdb89YN1/TyZTmB8friFjALhJaT7wRhSsvXG9LUl+mrKaL87QNQ3077mSbG9T69P5H ri9bAd29p7hsQ45pDClzY/hLBn92myJMIK1Hp3L+9FyC4H5C/Dhdbr8H/Xj4ED3MJRisa4 JX3sdjCD8Ob8PfIeo5Ar0DZintsCFOE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1702300119; h=from:from:reply-to: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=SmntiEclpJUrVX6mOseshDU2f41UdhrdCN/1UahG/nA=; b=xrT8La9JMjmb+L1xwUN6brQtsZmB1wfGVHmui83jV19zl80BucV2FEDjO5YHq9LItiU2a8 ZRd2rfQ8q1vDO6BA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1702300119; h=from:from:reply-to: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=SmntiEclpJUrVX6mOseshDU2f41UdhrdCN/1UahG/nA=; b=Ty3aJdb89YN1/TyZTmB8friFjALhJaT7wRhSsvXG9LUl+mrKaL87QNQ3077mSbG9T69P5H ri9bAd29p7hsQ45pDClzY/hLBn92myJMIK1Hp3L+9FyC4H5C/Dhdbr8H/Xj4ED3MJRisa4 JX3sdjCD8Ob8PfIeo5Ar0DZintsCFOE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1702300119; h=from:from:reply-to: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=SmntiEclpJUrVX6mOseshDU2f41UdhrdCN/1UahG/nA=; b=xrT8La9JMjmb+L1xwUN6brQtsZmB1wfGVHmui83jV19zl80BucV2FEDjO5YHq9LItiU2a8 ZRd2rfQ8q1vDO6BA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 138A1133DE; Mon, 11 Dec 2023 13:08:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id 5lRHA9YJd2U8BwAAD6G6ig (envelope-from ); Mon, 11 Dec 2023 13:08:38 +0000 Message-ID: Date: Mon, 11 Dec 2023 14:08:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v10 16/50] x86/sev: Introduce snp leaked pages list To: "Kalra, Ashish" , Michael Roth , kvm@vger.kernel.org Cc: linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, jarkko@kernel.org, nikunj.dadhania@amd.com, pankaj.gupta@amd.com, liam.merwick@oracle.com, zhi.a.wang@intel.com References: <20231016132819.1002933-1-michael.roth@amd.com> <20231016132819.1002933-17-michael.roth@amd.com> <0e84720f-bb52-c77f-e496-40d91e94a4f6@suse.cz> Content-Language: en-US From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C86CA180019 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: zd8dgpggdwzaq63purzqrtrpiwaiu344 X-HE-Tag: 1702300121-395196 X-HE-Meta: U2FsdGVkX1812VBx+Huje1Dev4RmwJw2B+V7qoy8vgwCkuAvKuu5r4fGRuyecIlP7IOKq1MVWibvIyzt72LxHC7xwADAvGaqOMz7Ttlvm3rMPsKb7Ajg54MbEEYcV4yK+X/5qJRnnVUb78jY/DjxEcgB57Nzoc1zaiEsSHoCSoNXeE6SASuh3g5f2FjPjaJEC/U4dV+kaXioxoIEwIZHSDQDH0Qw/TFWYg1GfPKhLf1lWd9myOT3ZmgW8uwhS7Id4yDl/u32kOPdI/+5mHWypg9QSAowNVIoNCY6LeDYpRZHE0Q8A7tEQP+l5KoNAAE/b85Kq0e/7GVaBe1m4iaj05088mLJigSpp4PMyr0noXMeIJaIDQvhzU7VRt4DubGO9m5/iALdWfwcBC/mcmqOu6VohsJ13Tsf3RuO9r5hr24lYBC1Dgrk4wTOWsdrWi02S0fsAg8xgQuFz/ZwxAlAAsBMbvhBYmglJaNpDu5I4cinE00riM5afnzRHnMCnjwDhczUA+4REDFX9P3uVLFXMzkDX1bVwWrVdHrfKrmMlkblv7+NPnwnRSOKp7Rs6nDkQ0j0MXP7kGTKJQuNrioqKCGK8EuHxoSy+dcb+YQ/iRyc+sUyijN65vlCp5wqw0h70x4Z4kUjBl7ukHHyTafnDenbYACCALxPrfvXQINfllXw0R5KMsJiG1oFvBAOe8dxPcC/YqiChqFWwtgbQpdcVVQq8LjkGzqYLwoFP3sGjiLQeoeM1dXZgjzcrTKqTPgwnGwwkVqXWJMwCqmkvEGhgNnuUh+2V2Vr23C4BJyj3RQmXjYmFX8aAR5yPHi1mel6d8dm5LXu8hIb1meWQBKOSQ8HC5n7sExiVzABWL7Aon/l+7X+w/rFouEZU5MDnvftH/X+qpqGSdrYzGfiXw/MjRDuZkuLbgZoGtGqpRaO3CEPmYotpx8g4vxa5PJzTxu//yhO/zhWJVfMUundonu fTKhSb60 +QR/uWOIOn/9bP5PP+2rPbN7oyQmrgCNWYX2+6FTpUUkU0jpYruJfncpUQBsZTa994kmmwNpbFpB4xlScvCG6a3AcTjhARXPllz0d/ktlSoOq6scK7SdPZvHf2nOl1I+4kND+9Rc8CeO8k6mqUsQGZdYWFfYu20E4vU0DVDR/Q1GjMkaaedsyUqs1KUeDQ4TI66ZLkNddYE/7pM0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 12/8/23 23:10, Kalra, Ashish wrote: > Hello Vlastimil, > > On 12/7/2023 10:20 AM, Vlastimil Babka wrote: > >>> + >>> +void snp_leak_pages(u64 pfn, unsigned int npages) >>> +{ >>> +    struct page *page = pfn_to_page(pfn); >>> + >>> +    pr_debug("%s: leaking PFN range 0x%llx-0x%llx\n", __func__, pfn, >>> pfn + npages); >>> + >>> +    spin_lock(&snp_leaked_pages_list_lock); >>> +    while (npages--) { >>> +        /* >>> +         * Reuse the page's buddy list for chaining into the leaked >>> +         * pages list. This page should not be on a free list currently >>> +         * and is also unsafe to be added to a free list. >>> +         */ >>> +        list_add_tail(&page->buddy_list, &snp_leaked_pages_list); >>> +        sev_dump_rmpentry(pfn); >>> +        pfn++; >> >> You increment pfn, but not page, which is always pointing to the page >> of the >> initial pfn, so need to do page++ too. > > Yes, that is a bug and needs to be fixed. > >> But that assumes it's all order-0 pages (hard to tell for me whether >> that's >> true as we start with a pfn), if there can be compound pages, it would be >> best to only add the head page and skip the tail pages - it's not >> expected >> to use page->buddy_list of tail pages. > > Can't we use PageCompound() to check if the page is a compound page and > then use page->compound_head to get and add the head page to leaked > pages list. I understand the tail pages for compound pages are really > limited for usage. Yeah that should work. Need to be careful though, should probably only process head pages and check if the whole compound_order() is within the range we are to leak, and then leak the head page and advance the loop by compound_order(). And if we encounter a tail page, it should probably be just skipped. I'm looking at snp_reclaim_pages() which seems to process a number of pages with SEV_CMD_SNP_PAGE_RECLAIM and once any fails, call snp_leak_pages() on the rest. Could that invoke snp_leak_pages with the first pfn being a tail page? > Thanks, > Ashish