From patchwork Thu Apr 4 16:36:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13618057 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 4D802CD1299 for ; Thu, 4 Apr 2024 16:37:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDE216B0099; Thu, 4 Apr 2024 12:37:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8D1F6B009B; Thu, 4 Apr 2024 12:37:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2DB86B009C; Thu, 4 Apr 2024 12:37:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 81D9D6B0099 for ; Thu, 4 Apr 2024 12:37:20 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 309C7C057C for ; Thu, 4 Apr 2024 16:37:20 +0000 (UTC) X-FDA: 81972404640.18.B614984 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 84EAA160008 for ; Thu, 4 Apr 2024 16:37:18 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Zy9nG69G; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712248638; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zaZWU0YkYnbWySa48R8KGwWh1EeftVOr0gzeEuzgbNQ=; b=gEOMZZbQ8Ws8cvSA8BAOfoPsJdgVRud4nXe2orKPsxUDt9aX0L1WbTI/Cb3CkhVMHp3270 j4aSGWNEILoajNUq9GW+/XvUlJvRIrTEOePgYl6QaM4RtBKbuGWIq3SyPGTWtXh87aLF9k 5h3Px3eahGs+TYjWOLIC4txdm37in/k= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Zy9nG69G; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712248638; a=rsa-sha256; cv=none; b=CNiFGX/L8NHc6+gwzguYMNQLpZVEuMnJIzfCnpCOdXcDXb596rGWwEtFf+9GoFW64Yfefy qr3oLCL+hgyuexPn9uV7bm1xzDkfrVS4UHRkedOCQlWRMuLd2Iqk3PlxEzn5Od4QHHCFVf HZFEoHrJc1YDmfOttAIOj2tUjElxc84= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712248637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zaZWU0YkYnbWySa48R8KGwWh1EeftVOr0gzeEuzgbNQ=; b=Zy9nG69GyflDis2XEVjZIVmhdv5f1LJtNOSkJAT1gjkU5jrIFwM2uxe1poXRHlSafvu4aA ATEugUWNr41OA8aqd5r5P654XIfsibXxpv3NqWmWpYU+XIBK+NtcFpaLIxZemqcG9DWllL IiYmdiTE8OAEJg9tZeAtSMpEl1RACzc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-telD-LxGMoCt6ciulojX3A-1; Thu, 04 Apr 2024 12:37:14 -0400 X-MC-Unique: telD-LxGMoCt6ciulojX3A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 41945282479F; Thu, 4 Apr 2024 16:37:13 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8064E3C24; Thu, 4 Apr 2024 16:37:08 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, David Hildenbrand , Matthew Wilcox , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Janosch Frank , Claudio Imbrenda , Gerald Schaefer , Thomas Huth Subject: [PATCH v1 1/5] s390/uv: don't call wait_on_page_writeback() without a reference Date: Thu, 4 Apr 2024 18:36:38 +0200 Message-ID: <20240404163642.1125529-2-david@redhat.com> In-Reply-To: <20240404163642.1125529-1-david@redhat.com> References: <20240404163642.1125529-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 84EAA160008 X-Stat-Signature: 8rguhkponji3q14rcn5picp7q8yu4ag1 X-HE-Tag: 1712248638-692513 X-HE-Meta: U2FsdGVkX195bbSE0I15yY6L9DknD7yH3qUhdoNARs6a3DjA4mq9X5o5Oeoqc4mYqV+vPFK5PiVub84m1ojG/UbfS3Gei+UWGvVgF6HU6OHZoBB7FtOaB0z8GNdb8nnuo5dWakVma6av5VD9zgFeNXIeKz6w4cH1Y64uKUoU91BtZHOlrkNRKLDC/csH671JC0BpRViPcXJHhh2ZfBtraFEGyRtLxyZCY82Wbuq0o1Rw5Xur8y0A2YlQwZDPJ6phd0Khp9MhGWP0y8AtntvwplAuz13mnH5yXHhzg4MOEE9Wo1lu0zUfdnpZ+lPfYZc9smFzPu7iRPh/EnZj5HOSHtaukmTU2yr5t84lYWsbWOsqEXEtcD19zT0rV19vb8yZgM7bcDMSt4TQDdq//hUiLiF/ZYriGrzo9QLFwjb3BzpUoHfx5ku9XbnJ3NLLMmeehbLTgE0UXKxC9GakyPrwOoAcH/fmRbEG3JdIv2dvcAPIimd/yInUwfnN7Vz8NJOonL76KPxn1vo4D9RDdB8WGFYMEN6/l3GIwWKebVooXdc3tSrc8Pul3EL/aODVkMReruJr2PMH3E6cJRM0AisRxCjzSvutBnRj/0yPHJJjuQ+jTSq282lyMSla9rLp1iT66N+CwVpWzHxal4onEbhgqPmy8fHQTrCd8t7LuIRtgFes0Al8bd3BCc6+QV1piWpQ34Olo5TCkKBgCGI90di92DPVbviEh8Las+QgynGMyOHOrd4AzT5T6gGTU2In0kJOy+E/DPwRB2jCQ/QHRQkThJSprdQmsNuT+SoIchCzE9t/+ARr2aj8bHO3mO1MpEE2Hvqv606Vxf0hQ7Uf4KRf1uUMq4bGctng7NgMpuOLfzwgHG/CsDdJxYv+IiqTFIhzKm7Va11sadwoZww9ltDv7Zw6px8v+HmnVCv/motOqW82Wzyy8ouKni2DBpvEkvYztsuu8LIOZft3d4B888l 3ayNCw+5 t+KqBNTOln396phwXd9xjh9rA4CWHLk29Jjxw67j1qE5l9i+kUNbTdqRmwys9z4oM2Dvjued5+MJFs0qfmmGzuKptzFbx5NosIF1RdxWywoROXQWRdwe2bmi9s+acVAFpuzowKNoIst/10GtUmADcZDbBSVqUAdxB0HTdbo1EnsVZX9bZRrrnYVo8xsDDRmw5wQuvMJMOfqbLYnSm7X+D1bfF1v14XipGbxhz 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: wait_on_page_writeback() requires that no spinlocks are held and that a page reference is held, as documented for folio_wait_writeback(). After we dropped the PTL, the page could get freed concurrently. So grab a temporary reference. Fixes: 214d9bbcd3a6 ("s390/mm: provide memory management functions for protected KVM guests") Signed-off-by: David Hildenbrand Reviewed-by: Claudio Imbrenda --- arch/s390/kernel/uv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index fc07bc39e698..7401838b960b 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -314,6 +314,13 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) rc = make_page_secure(page, uvcb); unlock_page(page); } + + /* + * Once we drop the PTL, the page may get unmapped and + * freed immediately. We need a temporary reference. + */ + if (rc == -EAGAIN) + get_page(page); } pte_unmap_unlock(ptep, ptelock); out: @@ -325,6 +332,7 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) * completion, this is just a useless check, but it is safe. */ wait_on_page_writeback(page); + put_page(page); } else if (rc == -EBUSY) { /* * If we have tried a local drain and the page refcount From patchwork Thu Apr 4 16:36:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13618058 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 A4174CD1292 for ; Thu, 4 Apr 2024 16:37:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 351E76B009C; Thu, 4 Apr 2024 12:37:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3019C6B009D; Thu, 4 Apr 2024 12:37:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A40A6B00A0; Thu, 4 Apr 2024 12:37:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id EA6486B009C for ; Thu, 4 Apr 2024 12:37:24 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A93941402B0 for ; Thu, 4 Apr 2024 16:37:24 +0000 (UTC) X-FDA: 81972404808.12.A86A356 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 194B22000E for ; Thu, 4 Apr 2024 16:37:22 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CnmRsrOd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712248643; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YqMhB+a0hiEG+4rkQzSAJvqocE9H8po4mJ+mzkWYDBs=; b=QNkIHHOgfnwtvxJAiAdlkqehDwxd/kLMXpsGGFZGAcMnWowC+z25BiP4xsNE5yw4BMvEfi lZNJjM+4UKzx/MmWqTmcfhuEhKJktKSVK0tXAFXpOWMKZ+K4movy2nRxubYSvjDGfWR+5f pgqzk41Tjv6OhP6Kt0sJoYVuTzJJgjQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CnmRsrOd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712248643; a=rsa-sha256; cv=none; b=ux+P6q9c3UtUjAsvutsSpEBpuQDdj5cyLkB9PozyXe5/y4dJT/RzeFb5F9FD8gGNKD3A+F fKld86SHxIhkcttsRLjbAhzIXJIooTsSwDZMYAZdCCEv/tKuOCJElPb1O3gwCVlPmdoLnI c/D5/NNekJa51oSrOMdZQSwkIn2VV7M= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712248642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YqMhB+a0hiEG+4rkQzSAJvqocE9H8po4mJ+mzkWYDBs=; b=CnmRsrOdUB8nXoGrApte72Yukj6PtTjyEDGptq90T2YG4X/FVkDykOFhYIQA5dpEimeJwx ed5+OTp1H/rHwTt5QCt2exioWh8y1T93qi7eTQm1j9M7Y/o1LCvyTnwivWGh4MqS7sg0V4 ZRnDRoUewnU0PZrQfHszqa6wudP7VeM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-41-eqwsHOp0NrySS1NYBlY5wA-1; Thu, 04 Apr 2024 12:37:18 -0400 X-MC-Unique: eqwsHOp0NrySS1NYBlY5wA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2581E28116C5; Thu, 4 Apr 2024 16:37:17 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E09A5827; Thu, 4 Apr 2024 16:37:13 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, David Hildenbrand , Matthew Wilcox , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Janosch Frank , Claudio Imbrenda , Gerald Schaefer , Thomas Huth Subject: [PATCH v1 2/5] s390/uv: convert gmap_make_secure() to work on folios Date: Thu, 4 Apr 2024 18:36:39 +0200 Message-ID: <20240404163642.1125529-3-david@redhat.com> In-Reply-To: <20240404163642.1125529-1-david@redhat.com> References: <20240404163642.1125529-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Rspamd-Queue-Id: 194B22000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gyaxms85c4rbiuxq7q9noqzwt67imed9 X-HE-Tag: 1712248642-285385 X-HE-Meta: U2FsdGVkX180lJ5WlGDB4l7ao+5371mNXkq1AePsUoiycK6bRftv4cY+6BhHgrKw5xnOmjXRPaVnRJvu+obVMO2/YAPmQmgjZK5bor4TENjBZbtZ3tI+qNtKiwBOjUZjptIigypqlC0Fta90iYb7M+9la5jiRrKm8F5nFCahrlkCMYN+lNfw1VvP4yW8lXOgAGNl83Bg9Snf/ceJZecN3e0XQwfCdE2kg6B/X77gxBJ6JA6p4NdmOOh5tlZxg0QVyI6UaRT7y1arPqdebNGHxBcpZt6WteWbX5x+MdnoApWD+DiQ8nqak5MX3+cKFC+urtsm6RiX6Q4cGt0/aYkpEDrmO07L/lH90Pyf8xqOypSUIvUxIsmc+1oCUt8W9YUY/sT6QnpTEipXFT2RqVhH0lQSEe0BVJbEh4atrneQQR9MYJUkgP6j2tfutKTW9VpsMx+1hosDqeKGCIUM1SrUFJML9Ot4KmOsoL3+qhazsmPzp0PAQQqAYbiJZlVWtlngqtlveu7pKR3Pso+esskNQ5LGBTFfG8KCD9hH7rBhZK/HzNqPYqVVGmO5J23imWfl6Tiejte9k+fHnKvEYzlppdApa59RQ9/01NTlfPj0HAKFZ7bZ+TawL/bpe7TUsPxN+jAnDAnBfAzazZlU6oNEGoB4hR4578+X6XtbAkXFGri7IslesRk5p9yalneZcHF68M0TI3zCCbzJI8h28oG1MJYaYISpNLiFlYWOFfYJXLr6RhTElNNca6kb+vN1ev9sl6g2gEdxuQRVLNtDsFxJCbxuumfJx5bYedzxZPwLMJem/IdzqiZZPoos/8oj1qEj6qmUwEx28/EO8q51y0Rj8TZQwAYm0fgN8pDbqKsPVEW/tn1hIY6t9bO5u54U3mA4JyLaUsyzidgIrXs2Lcggo+TSaotEAMOWOo76Q4qPmxBc0XWNuTrR4RD9m4nqK8AQ 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: We have various goals that require gmap_make_secure() to only work on folios. We want to limit the use of page_mapcount() to the places where it is absolutely necessary, we want to avoid using page flags of tail pages, and we want to remove page_has_private(). So, let's convert gmap_make_secure() to folios. While s390x makes sure to never have PMD-mapped THP in processes that use KVM -- by remapping them using PTEs in thp_split_walk_pmd_entry()->split_huge_pmd() -- we might still find PTE-mapped THPs and could end up working on tail pages of such large folios for now. To handle that cleanly, let's simply split any PTE-mapped large folio, so we can be sure that we are always working with small folios and never on tail pages. There is no real change: splitting will similarly fail on unexpected folio references, just like it would already when we try to freeze the folio refcount. Signed-off-by: David Hildenbrand --- arch/s390/include/asm/page.h | 1 + arch/s390/kernel/uv.c | 66 ++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h index 9381879f7ecf..54d015bcd8e3 100644 --- a/arch/s390/include/asm/page.h +++ b/arch/s390/include/asm/page.h @@ -215,6 +215,7 @@ static inline unsigned long __phys_addr(unsigned long x, bool is_31bit) #define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys)) #define page_to_phys(page) pfn_to_phys(page_to_pfn(page)) +#define folio_to_phys(page) pfn_to_phys(folio_pfn(folio)) static inline void *pfn_to_virt(unsigned long pfn) { diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index 7401838b960b..adcbd4b13035 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -181,36 +181,36 @@ int uv_convert_owned_from_secure(unsigned long paddr) } /* - * Calculate the expected ref_count for a page that would otherwise have no + * Calculate the expected ref_count for a folio that would otherwise have no * further pins. This was cribbed from similar functions in other places in * the kernel, but with some slight modifications. We know that a secure - * page can not be a huge page for example. + * folio can only be a small folio for example. */ -static int expected_page_refs(struct page *page) +static int expected_folio_refs(struct folio *folio) { int res; - res = page_mapcount(page); - if (PageSwapCache(page)) { + res = folio_mapcount(folio); + if (folio_test_swapcache(folio)) { res++; - } else if (page_mapping(page)) { + } else if (folio_mapping(folio)) { res++; - if (page_has_private(page)) + if (folio_has_private(folio)) res++; } return res; } -static int make_page_secure(struct page *page, struct uv_cb_header *uvcb) +static int make_folio_secure(struct folio *folio, struct uv_cb_header *uvcb) { int expected, cc = 0; - if (PageWriteback(page)) + if (folio_test_writeback(folio)) return -EAGAIN; - expected = expected_page_refs(page); - if (!page_ref_freeze(page, expected)) + expected = expected_folio_refs(folio); + if (!folio_ref_freeze(folio, expected)) return -EBUSY; - set_bit(PG_arch_1, &page->flags); + set_bit(PG_arch_1, &folio->flags); /* * If the UVC does not succeed or fail immediately, we don't want to * loop for long, or we might get stall notifications. @@ -220,9 +220,9 @@ static int make_page_secure(struct page *page, struct uv_cb_header *uvcb) * -EAGAIN and we let the callers deal with it. */ cc = __uv_call(0, (u64)uvcb); - page_ref_unfreeze(page, expected); + folio_ref_unfreeze(folio, expected); /* - * Return -ENXIO if the page was not mapped, -EINVAL for other errors. + * Return -ENXIO if the folio was not mapped, -EINVAL for other errors. * If busy or partially completed, return -EAGAIN. */ if (cc == UVC_CC_OK) @@ -277,7 +277,7 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) bool local_drain = false; spinlock_t *ptelock; unsigned long uaddr; - struct page *page; + struct folio *folio; pte_t *ptep; int rc; @@ -306,33 +306,49 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) if (!ptep) goto out; if (pte_present(*ptep) && !(pte_val(*ptep) & _PAGE_INVALID) && pte_write(*ptep)) { - page = pte_page(*ptep); + folio = page_folio(pte_page(*ptep)); rc = -EAGAIN; - if (trylock_page(page)) { + + /* We might get PTE-mapped large folios; split them first. */ + if (folio_test_large(folio)) { + rc = -E2BIG; + } else if (folio_trylock(folio)) { if (should_export_before_import(uvcb, gmap->mm)) - uv_convert_from_secure(page_to_phys(page)); - rc = make_page_secure(page, uvcb); - unlock_page(page); + uv_convert_from_secure(folio_to_phys(folio)); + rc = make_folio_secure(folio, uvcb); + folio_unlock(folio); } /* - * Once we drop the PTL, the page may get unmapped and + * Once we drop the PTL, the folio may get unmapped and * freed immediately. We need a temporary reference. */ - if (rc == -EAGAIN) - get_page(page); + if (rc == -EAGAIN || rc == -E2BIG) + folio_get(folio); } pte_unmap_unlock(ptep, ptelock); out: mmap_read_unlock(gmap->mm); + if (rc == -E2BIG) { + /* + * Splitting might fail with -EBUSY due to unexpected folio + * references, just like make_folio_secure(). So handle it + * ahead of time without the PTL being held. + */ + folio_lock(folio); + rc = split_folio(folio); + folio_unlock(folio); + folio_put(folio); + } + if (rc == -EAGAIN) { /* * If we are here because the UVC returned busy or partial * completion, this is just a useless check, but it is safe. */ - wait_on_page_writeback(page); - put_page(page); + folio_wait_writeback(folio); + folio_put(folio); } else if (rc == -EBUSY) { /* * If we have tried a local drain and the page refcount From patchwork Thu Apr 4 16:36:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13618059 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 3E735CD1292 for ; Thu, 4 Apr 2024 16:37:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C79F56B00A0; Thu, 4 Apr 2024 12:37:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2A2D6B00A1; Thu, 4 Apr 2024 12:37:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACAA76B00A2; Thu, 4 Apr 2024 12:37:29 -0400 (EDT) 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 8D4B16B00A0 for ; Thu, 4 Apr 2024 12:37:29 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5A9831601A0 for ; Thu, 4 Apr 2024 16:37:29 +0000 (UTC) X-FDA: 81972405018.15.CF5F91B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id B5FBB40003 for ; Thu, 4 Apr 2024 16:37:27 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dmHMxhro; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712248647; a=rsa-sha256; cv=none; b=X7rZ2v8sV0568YgtRrNKRsgCzBFq054RpU4ZAKdMjZ8yE0U/GZZAgxDIzWWYC5gp9prh/+ IlIDciawejyqmKOUwaCoeosMro6Dx5nfO4n1VTD1UBhS6MOjmw1YsAaRCG3lwhiW+VaSdh +7uU0NFnFBayQNiv9mUZOFax4j9DZtY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dmHMxhro; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712248647; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gj+Px0USJVRdve0zHf2NII4M17BtyxK6NDqebl44nSI=; b=r2cVMfp0Mxaffd2uE4ZpPnS9oQjHQLI+HDhNynMRCrfKKlKZIAOA26drTErFSdhtfHrMVc Qt/yDTaUtw2VOFbSu+riERHBlwvR1sJXenPt6099WpeMWcWDPHkAZuTR7mvPRUhe4xQnHf CYG2t14FFLa98WfhTRTBfw2RRQTbQWs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712248646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gj+Px0USJVRdve0zHf2NII4M17BtyxK6NDqebl44nSI=; b=dmHMxhroa3EfssSaAdICuuaJN0CY/mRan/uEV1gbkKoJQI3C55QxJFDZ/1rRVLal5qQN+i lB+8YiGeA48PLDfxqpVHTC9WnEyeIQD/h89iYWG/rXJlzL8MqcPdc2leKgIKHLZ+90j/OW XLO0wdt3nalRBvbrGugQR+rNKSLXhJw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-OWEUhaqDPT6N364ahGpEZQ-1; Thu, 04 Apr 2024 12:37:22 -0400 X-MC-Unique: OWEUhaqDPT6N364ahGpEZQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D7141101A531; Thu, 4 Apr 2024 16:37:21 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8272E3C21; Thu, 4 Apr 2024 16:37:17 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, David Hildenbrand , Matthew Wilcox , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Janosch Frank , Claudio Imbrenda , Gerald Schaefer , Thomas Huth Subject: [PATCH v1 3/5] s390/uv: convert PG_arch_1 users to only work on small folios Date: Thu, 4 Apr 2024 18:36:40 +0200 Message-ID: <20240404163642.1125529-4-david@redhat.com> In-Reply-To: <20240404163642.1125529-1-david@redhat.com> References: <20240404163642.1125529-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B5FBB40003 X-Stat-Signature: 6y8femy7ugobha41efw9yztpnqx3u1im X-HE-Tag: 1712248647-730827 X-HE-Meta: U2FsdGVkX197WB097TJTMq//lcCukwWZNhAAEZ5BWjU1R/Uo9GWDAU3WcwpoYqvU9RySpFAnBcNNzUU1RoYJ+jfzlfvQcCQVmP9gb7iMo7QgVRyCywQU9TDXpkS8aq+YDIjTQQVuhgvJOS3p7kvt2e0l32UIuaHGHI0kmbgrllv0xtp1x5h7FIPyrvo5Klh1TIIz0bDEDrwVLRvX1QEOA/CknQFxNd/fqX8jVMZIEqbfw9/C84NqnA45qbZSYzQk/R/UsYZ0JZp+ryNeXCGgHO3+7hLTyIT31/d5LkaTTHYfCimqtGmoDvjQ6jRviT/GCWvWuFY07mXwH36mIQvwCcUrLx+fRbd9hpjEdZXn1xLjRQR7/j60Tql08tMw9GRdYbFdV7w+0zlH6Z1hDndQMFDTSO/MuDbR9A0pIkBwhkssON2yEpjs8GBZQ0G6Hue4yPa/rJwDMOcgRt4MQPesZ5K3lokJuc83I0eocNw3lZwo5b/3mdbAZlvGpIEKprHni6zJQBAESUnw7rFgtdW2mUhXyMfxLjSF9EdePjNifheGC7JA9UTRNzzfQXCHDRaLUYEnLH8TGpvQB1CZLPQFomaG4tsEEq3shz789UjKkZ0i4rMiStApbyDWov49KCjIQ8UwDm7NJGGHlZ5AoVRja3qptp9pvhRkoYWREZBXGazelVdSwmc724v9K6yp2G3zSRR5na7RNiQFGDEeluH2X/J5p588vL8T5Wr2X3eYBRLs9hZKM0p03siIfaFA0i87b8L9tpqpLquIOtQck0yZx3LCI78wt2QUyYDP0yu16v8FJf7unRrrEMmscYLkrGsirSS3JRaxb2Jb17AEoITyYEM1iuwZ+SzEj/jFRvoVDBHOvS4PHA2FAuVg7ImtxarxgmUJQ4Mw1yNPKiPDfs94fYcogt820Nib7n5SOu6X6MlGfV5PfW4sEHFFVDOG3a2m 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: Now that make_folio_secure() may only set PG_arch_1 for small folios, let's convert relevant remaining UV code to only work on (small) folios and simply reject large folios early. This way, we'll never end up touching PG_arch_1 on tail pages of a large folio in UV code. The folio_get()/folio_put() for functions that are documented to already hold a folio reference look weird and it should probably be removed. Similarly, uv_destroy_owned_page() and uv_convert_owned_from_secure() should really consume a folio reference instead. But these are cleanups for another day. Signed-off-by: David Hildenbrand --- arch/s390/include/asm/page.h | 1 + arch/s390/kernel/uv.c | 39 +++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h index 54d015bcd8e3..b64384872c0f 100644 --- a/arch/s390/include/asm/page.h +++ b/arch/s390/include/asm/page.h @@ -214,6 +214,7 @@ static inline unsigned long __phys_addr(unsigned long x, bool is_31bit) #define pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT) #define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys)) +#define phys_to_folio(phys) page_folio(phys_to_page(phys)) #define page_to_phys(page) pfn_to_phys(page_to_pfn(page)) #define folio_to_phys(page) pfn_to_phys(folio_pfn(folio)) diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index adcbd4b13035..9c0113b26735 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -134,14 +134,17 @@ static int uv_destroy_page(unsigned long paddr) */ int uv_destroy_owned_page(unsigned long paddr) { - struct page *page = phys_to_page(paddr); + struct folio *folio = phys_to_folio(paddr); int rc; - get_page(page); + if (unlikely(folio_test_large(folio))) + return 0; + + folio_get(folio); rc = uv_destroy_page(paddr); if (!rc) - clear_bit(PG_arch_1, &page->flags); - put_page(page); + clear_bit(PG_arch_1, &folio->flags); + folio_put(folio); return rc; } @@ -169,14 +172,17 @@ int uv_convert_from_secure(unsigned long paddr) */ int uv_convert_owned_from_secure(unsigned long paddr) { - struct page *page = phys_to_page(paddr); + struct folio *folio = phys_to_folio(paddr); int rc; - get_page(page); + if (unlikely(folio_test_large(folio))) + return 0; + + folio_get(folio); rc = uv_convert_from_secure(paddr); if (!rc) - clear_bit(PG_arch_1, &page->flags); - put_page(page); + clear_bit(PG_arch_1, &folio->flags); + folio_put(folio); return rc; } @@ -457,33 +463,34 @@ EXPORT_SYMBOL_GPL(gmap_destroy_page); */ int arch_make_page_accessible(struct page *page) { + struct folio *folio = page_folio(page); int rc = 0; - /* Hugepage cannot be protected, so nothing to do */ - if (PageHuge(page)) + /* Large folios cannot be protected, so nothing to do */ + if (unlikely(folio_test_large(folio))) return 0; /* * PG_arch_1 is used in 3 places: * 1. for kernel page tables during early boot * 2. for storage keys of huge pages and KVM - * 3. As an indication that this page might be secure. This can + * 3. As an indication that this small folio might be secure. This can * overindicate, e.g. we set the bit before calling * convert_to_secure. * As secure pages are never huge, all 3 variants can co-exists. */ - if (!test_bit(PG_arch_1, &page->flags)) + if (!test_bit(PG_arch_1, &folio->flags)) return 0; - rc = uv_pin_shared(page_to_phys(page)); + rc = uv_pin_shared(folio_to_phys(folio)); if (!rc) { - clear_bit(PG_arch_1, &page->flags); + clear_bit(PG_arch_1, &folio->flags); return 0; } - rc = uv_convert_from_secure(page_to_phys(page)); + rc = uv_convert_from_secure(folio_to_phys(folio)); if (!rc) { - clear_bit(PG_arch_1, &page->flags); + clear_bit(PG_arch_1, &folio->flags); return 0; } From patchwork Thu Apr 4 16:36:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13618060 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 83EE6CD1292 for ; Thu, 4 Apr 2024 16:37:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17E446B00A2; Thu, 4 Apr 2024 12:37:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12EBA6B00A3; Thu, 4 Apr 2024 12:37:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEBCD6B00A4; Thu, 4 Apr 2024 12:37:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C9DCF6B00A2 for ; Thu, 4 Apr 2024 12:37:32 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9D2781402B0 for ; Thu, 4 Apr 2024 16:37:32 +0000 (UTC) X-FDA: 81972405144.02.3CE4D74 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id A8E6BA001B for ; Thu, 4 Apr 2024 16:37:30 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UGhd8cqG; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712248650; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wn9vbDVG4YtRegf5ZBlenhUihh95CLw8Qi8j4juWPxs=; b=TE73UelwLFNroF6qKM5V8GkTj1PxXfh5u+YjJkdICXcoLUgcEmIZnSP5jMldYJQsQ/ndsp zJhwFOqYlB8iClF9+5tW4kfJuBh4AcuGLs+q2nRhlBlJY3N7L1MtStHSjuIAIWu1ocbjnW J72bxQgW/jh1qkI7mTtzyhEyz0JRmrw= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UGhd8cqG; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712248650; a=rsa-sha256; cv=none; b=pMcctYyQITRdI6CIP0XNmbd3ZMot66AOVWnDfVhIyKRehsgd15p7KYw+QNV7o4VPjdn5iG xt/iqWw/KPRslRcvIntsmIB9/W002RZNxakUZ15uTaw2HBhwh5gPnxwjbDfI9ZNYrWQvWS swzxR+uL0Sy4OXK80Q1e9JUuzdgG818= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712248650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wn9vbDVG4YtRegf5ZBlenhUihh95CLw8Qi8j4juWPxs=; b=UGhd8cqGvYkjl+9cUHy/iDcIRMaf9+ly1C8qU8LH9Z05MUWB+HI92Frzks38xFjmQvT01j O3KIjnr9w8qV6G7Pae9ieGtlc1SWoBspPXxH+9Xx87h/LzYh5mu61wlCWZ/NrHuX6tH9au 9kDitPKIGgWdTZxNBA/MIqD/fEoUJFE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-546-ZB9ewTULNjmhHBCUXGQC7Q-1; Thu, 04 Apr 2024 12:37:26 -0400 X-MC-Unique: ZB9ewTULNjmhHBCUXGQC7Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D4C688D01A; Thu, 4 Apr 2024 16:37:25 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1ADD23C54; Thu, 4 Apr 2024 16:37:21 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, David Hildenbrand , Matthew Wilcox , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Janosch Frank , Claudio Imbrenda , Gerald Schaefer , Thomas Huth Subject: [PATCH v1 4/5] s390/uv: update PG_arch_1 comment Date: Thu, 4 Apr 2024 18:36:41 +0200 Message-ID: <20240404163642.1125529-5-david@redhat.com> In-Reply-To: <20240404163642.1125529-1-david@redhat.com> References: <20240404163642.1125529-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Rspamd-Queue-Id: A8E6BA001B X-Rspam-User: X-Stat-Signature: eyodwu4kpgabyxywdgm4tbk43cgq7h6w X-Rspamd-Server: rspam01 X-HE-Tag: 1712248650-646653 X-HE-Meta: U2FsdGVkX19v6Nzw6m7dn6VjSyrKsbweV1eZT29Po6eYR+VQ9A6A1T51hJMjrTJQ7lWqGJU8bvQZ3Qj1DruGRu1J2mbPVT6BNDZImJbzTltGyUMR1lnccrfhKE1wUxNC4tXepYXLDOOeCaTNLWbT9tmm/t7fNH9I5LtIR304wOI3n7BbNEgZmD7pt7MPR33BqmHnMmSf+QN0MT1akrOt5eZvR+4lG2X2DBw2H99hkcHE51eP6LrhJjbaHHfyLEQZYIOOVluh5WhbSho75cZdx1eD17uWVT5/pXat8Jdw5ltjoBKsRljoovN8tG+rwl9Ru4yW1e8e/ojG4DXgt0KYr/ITgVZ63XoGxtd4lusSkTZeBVooFzHyPy8cG9SS6XwgOVi+GhexLmBsHN33feDVjMQ7lnD6cmSoOcopvvCCXBNgaE2fqmOuAyzlC82rzdjKxoRpEhCiOz6SIVD7PfX1c3Oo1kQV0VRPW+Gz8cfdAMkJ0/ZwfrDlvuPZ+oEjqjYtgPFIfw4yOcLp+7VW6ucBXof0K0GCaReyMWaGe+jR7uA9uqQ0/IdXO7WdckgW1gwS2koTt5zOBX6U/dz2jiqoKG+kzQjPzU7yvB/hdNzfaRnoD/GVTG6c0c0e+akIT1cwYL/MY9tCCQCZpJSUNTU/fqapAJxw89Lkx0H9ZxXYU5OmJHABpQjlBV6XY+XkI7CUr0SdcUWRaJPl7BpiFuEPf17I3lrLTf6TeNQ1JnXkgGJhLIxe3mwTqjOCRyoeRyfRGYlOksxVOokYa2TI+OzenxKUfG4j6bHAL5uETYJbHFIZGJXUxtpx3SxmSbLPh2bqLdpqsffo84p3mgeSGJ7xVTymxVJTWnGGd6w+EemQuaZLTqAigPsw5WxixjSSEp+KKonTGemnlhqBzaL8DLdqXIjbWvHX4xbfK1KZovLsYFGc6Jq9UABP8gtluI6ejyJ7fF1PMVuVryWJvXHwhrJ 2Eka2FUM BeskNs7BZoSo4jJeF2WoIYq8IccOFPu9IwRRmSCM1Ae5xWD5PvvP9QtH6hcX2oYJEpTUK7UPcRoAJPpydNNYLdlxMlDOaOgw5/6+28pMPoMDbxwn+LudxPdnQ+t9U6IMtg8/EE2QZHqnQ/mFX4w1+9Od9xSdDoIoTFzQ5F4o/upDR9sGlO2c4ul67kQnNyhxSZHz/c3+9BUcBG+NCYb4JsLCtGCHsGgTroLLH 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: We removed the usage of PG_arch_1 for page tables in commit a51324c430db ("s390/cmma: rework no-dat handling"). Let's update the comment in UV to reflect that. Signed-off-by: David Hildenbrand Reviewed-by: Claudio Imbrenda --- arch/s390/kernel/uv.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index 9c0113b26735..76fc61333fae 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -471,13 +471,12 @@ int arch_make_page_accessible(struct page *page) return 0; /* - * PG_arch_1 is used in 3 places: - * 1. for kernel page tables during early boot - * 2. for storage keys of huge pages and KVM - * 3. As an indication that this small folio might be secure. This can + * PG_arch_1 is used in 2 places: + * 1. for storage keys of hugetlb folios and KVM + * 2. As an indication that this small folio might be secure. This can * overindicate, e.g. we set the bit before calling * convert_to_secure. - * As secure pages are never huge, all 3 variants can co-exists. + * As secure pages are never large folios, both variants can co-exists. */ if (!test_bit(PG_arch_1, &folio->flags)) return 0; From patchwork Thu Apr 4 16:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13618061 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 139A1CD1284 for ; Thu, 4 Apr 2024 16:37:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BADA6B00A4; Thu, 4 Apr 2024 12:37:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96B656B00A5; Thu, 4 Apr 2024 12:37:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80CAC6B00A6; Thu, 4 Apr 2024 12:37:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5EF4A6B00A4 for ; Thu, 4 Apr 2024 12:37:38 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2F636A145E for ; Thu, 4 Apr 2024 16:37:38 +0000 (UTC) X-FDA: 81972405396.01.A75DA80 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 55BE0A000D for ; Thu, 4 Apr 2024 16:37:36 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XjOIYAFp; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712248656; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Q3q+pZ5P34ghakudMZLyDnJaIa/cVUQD0kuqVhWGHj8=; b=f7iJKOPkrCTX5015C4RraEE12zMeApvKstNaY5vp87eqGESERNlDGAYoKyQygm+IafzjFy /1pRSBrMN4Rme+z7mJREf8xdRgpiynmdHvHnQOj9VevAMyMaZglct22eO40H2f7vd4nysz JweO6YQxD0WYC0KaESkAvxY+MvB7Iio= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712248656; a=rsa-sha256; cv=none; b=WBu+4GoluwAzkBQ9s956WH8M6YYIVC85Xfi8jmErVZch7ZPAwyq6dbViWB7zJE8i5yVcEV +Mb8rfcrRF1YwL77JtaoCeZ9PfwGLdqaWIFo8YekiSDuFrcY2ihUtA7DRS5xKTW/0LjfyZ XhV9sC0wEbwDhEbukUQeBvkO6zjlfrU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XjOIYAFp; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712248655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q3q+pZ5P34ghakudMZLyDnJaIa/cVUQD0kuqVhWGHj8=; b=XjOIYAFpxvj2lctppkjJdZ4GRCD7Q2wJrFxsh+c8SfrnuY67WJe8eNJbW+QJSfFOPx5TA+ OxD/TeT/qbjuYAKgM4nYSpwQL9BQTm8ZRf/Nu7x26/f77EZcYwpCodlgkl6BXkU//cmC// 5FWoh8muvxcEN76rEmD5wIra7C8EGkI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-iKIcEnTlP7OdF8dgEB13LQ-1; Thu, 04 Apr 2024 12:37:30 -0400 X-MC-Unique: iKIcEnTlP7OdF8dgEB13LQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9AC5E88D016; Thu, 4 Apr 2024 16:37:29 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0804E3C24; Thu, 4 Apr 2024 16:37:25 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, David Hildenbrand , Matthew Wilcox , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Janosch Frank , Claudio Imbrenda , Gerald Schaefer , Thomas Huth Subject: [PATCH v1 5/5] s390/hugetlb: convert PG_arch_1 code to work on folio->flags Date: Thu, 4 Apr 2024 18:36:42 +0200 Message-ID: <20240404163642.1125529-6-david@redhat.com> In-Reply-To: <20240404163642.1125529-1-david@redhat.com> References: <20240404163642.1125529-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Stat-Signature: shxbg7yupsgqeef7dacaaq9y7r1d8z9f X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 55BE0A000D X-Rspam-User: X-HE-Tag: 1712248656-147759 X-HE-Meta: U2FsdGVkX18cpyYgbkYrUZgBl33JSHJc5vZezNjogbKXDUP5Rn4hfnktL5FHU6FYuAPjJ8h+Z3i5goS+iB9YBmGY8nbSrxf2o6noq0VirulKlYmRL3hI1O1/y5R4mtz2RNDqpuJgOG96qXE38oZTVuAjuV7ISzN7rAAb5Fq2wZB3J5lXUD56NXQ/7Xq/WS6NkCFT7dxz8DG2XCBrpT5DV/Bz3DRqqrthJjoZloTqzJj5Hp3wxcFErf5/tiH27lKY5cZ9fCXJs4tQVnqYVtVO+yex3A+cNgN6e6/d7V59Fb4au5rZUZVbLrvRPw3qxZmSMxbFGNXIvwgJ2+gYDdEeZ6WE3AldI4FnmmKTbuYJ1rqiGhEeaJZT6+AXqTwnvgxZ5JU/N2PJh+dO/mqcU7GGGS/ao+CO44a2xrXPRHjehdCzGRuBXkAK7xOhyfCDISyd0F9DjeR2AE/ZvG8EIEaY95XojEo+o+8TwfxoepclfrqAbUFyGZo15N4gFRWv/uygNm9pe3PJ6rfp3mnUiAyK6WQKsGvyqZsPmj1/tlYw323P6Ga1I4h0Vlxk3eCy2JIk0jLFwmRWlyNp2UOb4KwWDMhwP+QDYJI+ns8Y6oS4KoAyaOawzGhrYLtpN+RECKkD64IBaACTNEu3FLKf/ensDfpRwI8nvn/FXP1T0+eLnpLnEogQT+kV6B2Uq0scz5WJAcpeSbA6z78CK5eCBelKOf5/GoXDiHAWMob/2r0IlDXcqduswxNpbwV//ev+LJs9emve/MtcyHeCCUc26gB+9czNq/w/Lw9uFAaJYLBq+yBpKu5o+j4IkpYRY36iNKiMsByNitbrNOoxwt0fZhjJVDlTJ440vyVjrnQ+qvBqMb6mlp7BfEKCkVhh4vlrm3UrTvviFxO23ZUXkI0wLVDCxGGAysV1riQHz7QPlXJHhe+GRrc2Y6oH8pkMZs+VwPYAigNAUVmrPXqe4HuE1Gd PfTNjn+O grWYzMx6iRH+/QFfmTF/PF/BphdmQFzttKOxdQeD4INlxsOIAp62GC8D2NqFV/CYdRLTNWjoRx4/F/qJFAY0C181iCdM35QWbe3S4TMYSomud3e8q0kqtMl5A7PpMVABKaDiRUJKrpBzLL8NLYiKDbto73vsey921cNJuKmBTr6oTJTEqkNJ+RrW92vK2bihmvwg6tW5lDP7IiSaoKq0dohndBbhbIJL/V8Kc 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: Let's make it clearer that we are always working on folio flags and never page flags of tail pages. Signed-off-by: David Hildenbrand --- arch/s390/mm/gmap.c | 4 ++-- arch/s390/mm/hugetlbpage.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c index 9233b0acac89..ca31f2143bc0 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -2731,7 +2731,7 @@ static int __s390_enable_skey_hugetlb(pte_t *pte, unsigned long addr, { pmd_t *pmd = (pmd_t *)pte; unsigned long start, end; - struct page *page = pmd_page(*pmd); + struct folio *folio = pmd_folio(*pmd); /* * The write check makes sure we do not set a key on shared @@ -2746,7 +2746,7 @@ static int __s390_enable_skey_hugetlb(pte_t *pte, unsigned long addr, start = pmd_val(*pmd) & HPAGE_MASK; end = start + HPAGE_SIZE - 1; __storage_key_init_range(start, end); - set_bit(PG_arch_1, &page->flags); + set_bit(PG_arch_1, &folio->flags); cond_resched(); return 0; } diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c index e1e63dc1b23d..21ed6ac5f1c5 100644 --- a/arch/s390/mm/hugetlbpage.c +++ b/arch/s390/mm/hugetlbpage.c @@ -121,7 +121,7 @@ static inline pte_t __rste_to_pte(unsigned long rste) static void clear_huge_pte_skeys(struct mm_struct *mm, unsigned long rste) { - struct page *page; + struct folio *folio; unsigned long size, paddr; if (!mm_uses_skeys(mm) || @@ -129,16 +129,16 @@ static void clear_huge_pte_skeys(struct mm_struct *mm, unsigned long rste) return; if ((rste & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) { - page = pud_page(__pud(rste)); + folio = page_folio(pud_page(__pud(rste))); size = PUD_SIZE; paddr = rste & PUD_MASK; } else { - page = pmd_page(__pmd(rste)); + folio = pmd_folio(__pmd(rste)); size = PMD_SIZE; paddr = rste & PMD_MASK; } - if (!test_and_set_bit(PG_arch_1, &page->flags)) + if (!test_and_set_bit(PG_arch_1, &folio->flags)) __storage_key_init_range(paddr, paddr + size - 1); }