From patchwork Fri Aug 2 15:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13751751 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 B3DBDC52D6F for ; Fri, 2 Aug 2024 15:56:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D9D96B009D; Fri, 2 Aug 2024 11:56:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 488EA6B009E; Fri, 2 Aug 2024 11:56:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 350936B009F; Fri, 2 Aug 2024 11:56:37 -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 12BB96B009D for ; Fri, 2 Aug 2024 11:56:37 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B2B46C1419 for ; Fri, 2 Aug 2024 15:56:36 +0000 (UTC) X-FDA: 82407757992.06.F80B696 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 0D376180003 for ; Fri, 2 Aug 2024 15:56:34 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VMyO9V5j; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1722614152; a=rsa-sha256; cv=none; b=NguPuJmmIzH7RL6HTg1qFo9GnSRkNwNF1kR8Lgwppn/NR+4pZkVK31/o7KbbjUJeED0bRx uKSPEy2X51ZzT1/q2GPIPKnucMeDk+zVVavXXQ0BCf1svtZbi1rHrsb7U6Xdc3OGDYQzHk JyLDZHY7GHp/0PmBScA0jFsiz2qwCpU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VMyO9V5j; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1722614152; 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=pjcECCTgCmWZTwab+g/RP394PBHLh37fGlT1XvTATXs=; b=seOj44JWxybfCn6aXubzP+bYisiBNHmC592Z38+CZkc9duok98svUBnqnN56WB8yNgZ19c XOGQA1BzgsTlNPiE/DcM+h/UVPjLdfqDPF4LBU4QoNp7jUaD3sCnTyvfAlGU2FswMrlCLH Ja+r5HFA5ITGGnmuL4w6YTqe6cReuVw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722614194; 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=pjcECCTgCmWZTwab+g/RP394PBHLh37fGlT1XvTATXs=; b=VMyO9V5jw5PBC7zQEqKVIsbk2jI0a1m2Gg/Wds7dtOoDh1R9rj2QYr2r8+7QeRzYpnN9Md 7O2qCW1wOJBlgbJbsYHirQEpBE0oWYrvJnCx8ekJ46z8wYroYyXN+l4JsFGB2fsp2u9zkw 5oSEJCf8dguEb20+c7zAk2S3ShXDkqg= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-74-WFy2ItSoPW6bK_LvEE1k_Q-1; Fri, 02 Aug 2024 11:56:29 -0400 X-MC-Unique: WFy2ItSoPW6bK_LvEE1k_Q-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 95BE31910417; Fri, 2 Aug 2024 15:56:26 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 11D163000198; Fri, 2 Aug 2024 15:56:19 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Jonathan Corbet , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Gerald Schaefer Subject: [PATCH v1 08/11] s390/uv: convert gmap_destroy_page() from follow_page() to folio_walk Date: Fri, 2 Aug 2024 17:55:21 +0200 Message-ID: <20240802155524.517137-9-david@redhat.com> In-Reply-To: <20240802155524.517137-1-david@redhat.com> References: <20240802155524.517137-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Queue-Id: 0D376180003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: sc9jbq71mgtpsxxkgbur383mbtbzw8pr X-HE-Tag: 1722614194-938805 X-HE-Meta: U2FsdGVkX19cXBDtt57pNgPDZfjeph7zefLxKwevZ3B4v8w09wN+woQDBvT8bGSCbnoKen2RZtH6UObF4nHbKQcDAfSYkr5ztzr6kM6s6Co+wAeJz4b8BVsAl6y2LpxNHrHa182dTfQU1eumjq4ReLQ++9sOvmNWG8G/MFBA5iEy7OW+Ngmt1aAHS7dZeQYYV6EECsu+imVbEWRV8v6YpGz/o8xbLOyUsCeBwZdLAPMrO/fgN4pfo+f4Z4la8ViuMk0XProvaJUZvz7pJuscBUubotqnsfUObtCFyAMQQDGSl4dxy13pxQ83aTZoHI2yZI8hGjUOoCuYe4hpVSAyUuMHiQNHcSz/p5uQj6TzMmVICdwh3LnPWTs3w1kOzHAD6GtpmBWMUQgNwjASfni5kfaaZQsZE8BHyW9vd9KZ3kqEl8RLNm/NSl81XR1xeMSDgMOBL3g3+d6SWitdNOgGg+7wARrYr1aM4/sn+3jJPyHUVuzlhMRnTsBEDrL/yLw8oY6gGa+4pm6/EUMLfBbUAhdIHgOvF2lmXI09hs1SIa8DywU4AEfHxFPArixnDnWjafVGmqaFXrjhJe9hzdfPmwq8Zh2oC+ZmoZh2QEI418dr/FbqIYyAH70nJ9dTrqxuMMxxbNX6joSaHrO7ifr2eXpXcalm2uBQ95bGBXzZfhaGXJHH3oDcMkjp68OCu78QaAVKPGITyR/ectwK4SkZ3qDTLtHyzpfIs0OESjMzHzX5nxbP34pYms5KOFqCKBViQYj0XJhHQzC5yuufDK8EiMJQE+ySQRpzub20oACWast7oYP9cfKjw4AedJa9o61DK970SxdReXM63mLSalc/ZeRrDAkuiSzW5YUBS8b+e7Up9jE5Kmek1DsGyCr09u7nuALZMyOcyLq9c35Ads7MKYVxL9jRW4o8pt+Cbyfl/PskkUAfsRjSvcIxPep+gxDFTq0CX8vt8JDFqWtpoaP pz2SiqHl znsjFriL1ZxaAs4FE+wFjeWlne16rqS98txduJYK8G248oQsAU7PMM8+KcW3yip1ffdRwWZ8GuKpBEVlJ1AKSpo62c4ggimFNFQnUilUs8R//q3eVfBe4/4IrZgK5X41JbPEM2jWgn52isdaCRpF42NcR7Mr+RYSjpUccjvFtHlcOdNrPxcDrCIQX+aVHXK//YNoJgdXMbXnd75gm9a7Y1PN7OtEvbXTrF9DrMlA58cJX9j5ztEgwh3RRaUu2Jj8/b5EUYxwBiCHwkOhbalGCC7LNP6Z5FWMVa9+YH6doobaxWGWqZNBn/ZISZjzrjiD5PoNy6fTdBxdEetthTCr0yL0wLim4VE4PZ+cSaJIYHaib5h724f5q/wvJCsBM3qIQQlQ+ 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 get rid of another follow_page() user and perform the UV calls under PTL -- which likely should be fine. No need for an additional reference while holding the PTL: uv_destroy_folio() and uv_convert_from_secure_folio() raise the refcount, so any concurrent make_folio_secure() would see an unexpted reference and cannot set PG_arch_1 concurrently. Do we really need a writable PTE? Likely yes, because the "destroy" part is, in comparison to the export, a destructive operation. So we'll keep the writability check for now. We'll lose the secretmem check from follow_page(). Likely we don't care about that here. Signed-off-by: David Hildenbrand --- arch/s390/kernel/uv.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index 35ed2aea8891..9646f773208a 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -462,9 +463,9 @@ EXPORT_SYMBOL_GPL(gmap_convert_to_secure); int gmap_destroy_page(struct gmap *gmap, unsigned long gaddr) { struct vm_area_struct *vma; + struct folio_walk fw; unsigned long uaddr; struct folio *folio; - struct page *page; int rc; rc = -EFAULT; @@ -483,11 +484,15 @@ int gmap_destroy_page(struct gmap *gmap, unsigned long gaddr) goto out; rc = 0; - /* we take an extra reference here */ - page = follow_page(vma, uaddr, FOLL_WRITE | FOLL_GET); - if (IS_ERR_OR_NULL(page)) + folio = folio_walk_start(&fw, vma, uaddr, 0); + if (!folio) goto out; - folio = page_folio(page); + /* + * See gmap_make_secure(): large folios cannot be secure. Small + * folio implies FW_LEVEL_PTE. + */ + if (folio_test_large(folio) || !pte_write(fw.pte)) + goto out_walk_end; rc = uv_destroy_folio(folio); /* * Fault handlers can race; it is possible that two CPUs will fault @@ -500,7 +505,8 @@ int gmap_destroy_page(struct gmap *gmap, unsigned long gaddr) */ if (rc) rc = uv_convert_from_secure_folio(folio); - folio_put(folio); +out_walk_end: + folio_walk_end(&fw, vma); out: mmap_read_unlock(gmap->mm); return rc;