Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp181851lql; Fri, 12 Apr 2024 07:24:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV3H1ArNSzr4KCTAwExIdnc49kTzeObMCN6zTDDOkf8MokbLPMcqeyCLWQxla47iPESo5AFJlIAadVPqTPrJCUopW6e1O9TTJGczw+DIA== X-Google-Smtp-Source: AGHT+IGErhgiec6lVtKsRxb1eB+/fj4RKlWELe1eAOV9rAixLJqkpbfPXLuw5PZ07F16gPwE70Mj X-Received: by 2002:a17:902:e542:b0:1e4:320b:4311 with SMTP id n2-20020a170902e54200b001e4320b4311mr7519466plf.34.1712931843924; Fri, 12 Apr 2024 07:24:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712931843; cv=pass; d=google.com; s=arc-20160816; b=yOQmSGLT8Go6D/FlT3UwgIdk6JOncjuhobU9O/ur+O//pYEtd/pvHmNL9lNqUGBe2T vZo0Fl30xVU2vm+cTWFCa87zRQqck1rBcp/UfilhnREATZ9zyQZUZPqmcxEc4IQ2DV0/ 6xPVjTZqh+r7YkFIMYTCoqMqwm0vJmVq8mdR6jpoyyagwgn7RJyLl70B9BEDfwWEV8Oa NHt/MYIJi51FUDupcCZgqztRWYCkuAUKPHbqcf4qNcKG9AV+3cdQsdXIadoSn2y6dQtL aqW6SE+H9DluM7u3GPmip2CZfWIKWnVwmdsLw1l94PfFOWfknOIEgC8m1msc2a+zG9BS EUQA== 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=6DKeQI6yMk4WrSKY3ISFL+eRa3o1/6tdDeS8ur8VVlk=; fh=A+QcyawwK6Yq8daxuWFm+g/417ivXyGCFoP00qnMPro=; b=NTJyR+Itrbs9UxJrtqEv0JXVMGke2krIL3L3u39j9+M5XGv5E8krIRFO+WFEpm30ix DnrGW+qt0DBsPRtoRTR0RBHw12mXUYsAGZJaJbqG8/l5ihAhvPhwArYXHq3gnvcqS8vf 2VEAFGOcCMQUe+UkuFwj+t5K2CSx+QouE3x1FztSOrE93uBNL/QhKYODpQo5iuFaIa6G ICjBwlVMNN1Z859DbJnaTmKh2zIPbElLPSHrV6804DuY1V4EV1XPKBxd+iJtn2cv9EK4 gIOp4lXg1CVC9oHdy8kgaWmoUXimKcG/G1+BQuBEf3+O8ihcj8e5xvy3fyz4FIMXyVre epHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dvh6dCTt; 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-142818-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142818-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i17-20020a170902c95100b001e2624072dfsi3464918pla.616.2024.04.12.07.24.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 07:24:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142818-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dvh6dCTt; 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-142818-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142818-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2EE1F28705A for ; Fri, 12 Apr 2024 14:23:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D248912C486; Fri, 12 Apr 2024 14:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Dvh6dCTt" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 510BD12C468 for ; Fri, 12 Apr 2024 14:22:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931729; cv=none; b=trZ1mIDJRH8fpjRCOUziKld2XkYe5wAbPHK6KSB/vV4SO3EgDjPWUXw4L7+layGnI+78fx9gQ+bQlE4m+0iB/gxYVA6o8A2c2UXfOjIp/8VASTO8T9PNm/79Vytpwwjh0GnLWQQPMIgH7uDw0w0rAJpvY4iOJ1tfcb0GefU5bNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931729; c=relaxed/simple; bh=NYIsyAKTyDfXL1OBDe7AcstW++1OcYH4oDp5YUoFpOI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d9RnCUb/n8HU/jCV/20202PtuiKif0UQ0wQqLmSN/8Wv9u8w1oOUMY7Tg5wvcQ8y8EAXmSrSfRgGytx0a6p+2Gh7FYSgB81yu3PvrDHVZ/j8K6gphCwDQc0sZrBIkdGTGKtPTlUpLT3iwaFa8rixkpDoaaqCtgz5763v0tzCyak= 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=Dvh6dCTt; arc=none smtp.client-ip=170.10.129.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=1712931726; 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=6DKeQI6yMk4WrSKY3ISFL+eRa3o1/6tdDeS8ur8VVlk=; b=Dvh6dCTt8anaCXmO6VBnFYEES3JTGEoLuH5YG3OiMdKufXAYwKkNN024Ko2ISGGy5SJlbO F7zvCfQXj+sd8fS0Sz5BdJp6Q9XtzR51NJZZDZmL2eAjS8gQ1uAEPhUzdS2U2xlrNN0CWn F9d6fuZZK008wpnHJzNApSPViNcHq8s= 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-637-BlVDikT7O-igiyZtvUI5pw-1; Fri, 12 Apr 2024 10:22:00 -0400 X-MC-Unique: BlVDikT7O-igiyZtvUI5pw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 391BF802E4D; Fri, 12 Apr 2024 14:21:59 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.193.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 867AB40C6CC0; Fri, 12 Apr 2024 14:21:56 +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 v2 04/10] s390/uv: convert PG_arch_1 users to only work on small folios Date: Fri, 12 Apr 2024 16:21:14 +0200 Message-ID: <20240412142120.220087-5-david@redhat.com> In-Reply-To: <20240412142120.220087-1-david@redhat.com> References: <20240412142120.220087-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.2 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. 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 9381879f7ecf..b64384872c0f 100644 --- a/arch/s390/include/asm/page.h +++ b/arch/s390/include/asm/page.h @@ -214,7 +214,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.44.0