Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp687055lqo; Wed, 8 May 2024 11:31:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU+rTsynID+w1n0u3ukGHbpAmf4xTmI2R6ADXCWoXWOUZxkJZcc29S5qYcuYoGZPN4dOIQ/xkljUaOb1hcS52LJ+XGEUd4oSBt4FfC/2A== X-Google-Smtp-Source: AGHT+IHBVY4SoQwBLPIOLH06dsm5C0pNME6uBNzlT5F6iGkBfhGv68769mlUjbsQz5Cg/jUNFYiE X-Received: by 2002:a05:6830:16d0:b0:6f0:cf72:5d7c with SMTP id 46e09a7af769-6f0cf81a59amr1681482a34.24.1715193090718; Wed, 08 May 2024 11:31:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715193090; cv=pass; d=google.com; s=arc-20160816; b=SM1cyeG+DzaD5TIUjKRh0T/tsx67fE9VUQW3cAZ9tHKqx+rNfLwDz79IB7UaIXDMss oFdArQ5lICr2tcyDygltckEGPGUqArX3NmtxeKfNHKy0QwaDxn4I6heYDdgWJM3Loou3 IZD/t6tHJmDaS6Coqfxq/qQw9N9ycm/+SAuAkipORHJQoy7TMJX43EDtkAK2WDNJO61l lHHB0nJqN0GCL8/RRaALg3NIFehxRplBXGJXKrnNhzSdtEOayRyOFHzQ4QgggA47dHdG dC/KegBmL80xdLT1mzPbVjvOB5lciCA+MHE4qj4ktky3Pi4juacUY35a3a3Yb+wUoQds AYYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=MYWABkGxV8MYRWHh8nd3DHUSmm6awTOHiljU31Nr1kM=; fh=A+QcyawwK6Yq8daxuWFm+g/417ivXyGCFoP00qnMPro=; b=ScccKx12sWi3lr2R0Gnm8verG0rIXlx28W0m37A0YPX47GyYjaOp+6ZKJvibt2qfXm KNSuZvAFfs43S+0mg7+HYSv2c8dDJ8/pdx/7ePWoJtWBtfJeumS42sgg/IT11Mzk5Dho 1ZDZBto8J64lnf1zmW1Ltg7fdl034qSmAgskIVI/xZc+8WCmITLcYqcfmDZhltEvvWiN nFTpfhEh+Uafm492aFa3N48z8jksjHT+oDN2S8wDv5dagTNMLgmOTd7BLU5ewDMclU8k heYD1c2VZKFulklmxsP1yZmp3tEYKlsKfPPBezspgpEquqfmdiabueF6HloqK0+8vEe1 UZKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aqolmFLy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-173705-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173705-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i9-20020a05620a404900b0079299819525si8208544qko.560.2024.05.08.11.31.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 11:31:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173705-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aqolmFLy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-173705-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173705-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5F23A1C2140A for ; Wed, 8 May 2024 18:31:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3AC3130AE0; Wed, 8 May 2024 18:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aqolmFLy" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAA4B130A5D for ; Wed, 8 May 2024 18:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715193021; cv=none; b=bZu7GPHN6AIH9ji2kq2wiUZsM2O9IVNQZQj8D3Ai03hhCZxl8OlJLjzHwDRm5rMBxH5AOI/kLcyIxrV404aETGHnSkXjfpu1Wo4Ua581ESUvhvfjWCCgI4hV+pEcY0ct/vXLNbCnLfwY0K3V7qjDSFACtjAWjeo9fkhV2TIpn94= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715193021; c=relaxed/simple; bh=9cMxw+0FUPFscli9SRIp15T5tvpY7n1JYHRqVPxhLQ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n1UG4oMC4QoQK2Ok81VkQb3lZSidxTEhMGt+RJ+JhxXPquClmEWDfj+9qEqHrqfGKgKRiaY3ybwlhrCdoTTWIpb1U3vSiMm7PALWDnmWVPPedLwWvRDXD94SwfClC3a/xpn1yW1kKStFK3rPku/5SjuJuxM6T7YZduMq5fw77eM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aqolmFLy; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715193018; 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=MYWABkGxV8MYRWHh8nd3DHUSmm6awTOHiljU31Nr1kM=; b=aqolmFLyiCKur/L8AxnNt7vvV6YIHoBrTVtSLIpEZqiLVpTbxnz4hICnBwvcbSBJexjrtt XKstOWPl0Shpieuq4lE6LuejB43JdxmOFPTp62p+fFRbPMd1C+8VNvPywqVQE4yAcuE/hK AHqMUQKh/afMPXJ3NCT4DNOl0Xz+5/Q= 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-628-C9cFn8fZOBah3jYfTssNEg-1; Wed, 08 May 2024 14:30:13 -0400 X-MC-Unique: C9cFn8fZOBah3jYfTssNEg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 CD905800262; Wed, 8 May 2024 18:30:12 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5545C1000DB4; Wed, 8 May 2024 18:30:09 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Janosch Frank , Claudio Imbrenda , Gerald Schaefer , Matthew Wilcox , Thomas Huth Subject: [PATCH v3 04/10] s390/uv: convert PG_arch_1 users to only work on small folios Date: Wed, 8 May 2024 20:29:49 +0200 Message-ID: <20240508182955.358628-5-david@redhat.com> In-Reply-To: <20240508182955.358628-1-david@redhat.com> References: <20240508182955.358628-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 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; likely they are required to make concurrent gmap_make_secure() back off because the caller might only hold an implicit reference due to the page mapping. So leave that alone for now. Reviewed-by: Claudio Imbrenda Signed-off-by: David Hildenbrand --- arch/s390/include/asm/page.h | 2 ++ arch/s390/kernel/uv.c | 41 ++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h index 224ff9d433ea..ecbf4b626f46 100644 --- a/arch/s390/include/asm/page.h +++ b/arch/s390/include/asm/page.h @@ -247,7 +247,9 @@ 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)) static inline void *pfn_to_virt(unsigned long pfn) { diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index 3c6d86e3e828..914dcec27329 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -135,14 +135,18 @@ 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); + /* See gmap_make_secure(): large folios cannot be secure */ + 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; } @@ -170,14 +174,18 @@ 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); + /* See gmap_make_secure(): large folios cannot be secure */ + 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; } @@ -479,33 +487,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)) + /* See gmap_make_secure(): large folios cannot be secure */ + 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; } -- 2.45.0