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; }