From patchwork Fri Aug 2 15:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13751752 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 9D6FFC52D6F for ; Fri, 2 Aug 2024 15:56:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A3D06B009F; Fri, 2 Aug 2024 11:56:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 154BB6B00A0; Fri, 2 Aug 2024 11:56:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F37736B00A1; Fri, 2 Aug 2024 11:56:46 -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 D263A6B009F for ; Fri, 2 Aug 2024 11:56:46 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8CB0C1C4B5F for ; Fri, 2 Aug 2024 15:56:46 +0000 (UTC) X-FDA: 82407758412.16.31CA52A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id C62311C001A for ; Fri, 2 Aug 2024 15:56:44 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f0TtLs3b; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.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=1722614157; a=rsa-sha256; cv=none; b=jRF9a7aUU2Gq4xZCV9ZO1CmVhdlGECuhiJBF9S+RnBgFSwdwEKJEq+jPtjMh2T+YfpeKfE 9BcpRAJVSOuA9ZOOuG93xK0eW47OOV991sml1XsX2fnJY20RTR83GePm1YiMLGMnublm0v GJYnqAu5YDwNfba46AODFKgWBJcsSag= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f0TtLs3b; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.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=1722614157; 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=Y8hDUFeX9csW/JE1owVpjHxLVtzwb2VhQ3RSyvg6DEc=; b=E4b+0t0PBUhE7+mpd5emtaxNAbPiPNqvISbGtcnEKH1lHWMkQT1zfeP742bW1FZKC+BdOj zmdMV49apNS6zevdC6avI0sNbqqYQEfih4RrO5vTyhnFX4Y1iWiQqpwXGoeUhRPjqw1p+9 /84Q3TAKnrzdjMng9/JPgF5RQtseYXY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722614203; 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=Y8hDUFeX9csW/JE1owVpjHxLVtzwb2VhQ3RSyvg6DEc=; b=f0TtLs3bjsEhCvNLIivKYozUU5WnT2Pqj0C+4rbhCMIul/xABTHy1PHyRcTF8PpLBaWjD6 ew++LhdWIjzOju/JkkkCkIlU+wIfyP5aOFlJrYYN1uS88uQ95vHI57VYA4e+KKpZ5sfK6Q q1gj3VP1uQ5ks7NCNupmcLorSrutPb0= Received: from mx-prod-mc-02.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-314-xQRxca8hNvOMbFAn_7Ci0g-1; Fri, 02 Aug 2024 11:56:36 -0400 X-MC-Unique: xQRxca8hNvOMbFAn_7Ci0g-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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9C68619776D7; Fri, 2 Aug 2024 15:56:32 +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 CD843300018D; Fri, 2 Aug 2024 15:56:26 +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 09/11] s390/mm/fault: convert do_secure_storage_access() from follow_page() to folio_walk Date: Fri, 2 Aug 2024 17:55:22 +0200 Message-ID: <20240802155524.517137-10-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-Server: rspam12 X-Rspamd-Queue-Id: C62311C001A X-Stat-Signature: pxfhi6ruej8981inrdojre1uoqbu5xbx X-Rspam-User: X-HE-Tag: 1722614204-707854 X-HE-Meta: U2FsdGVkX1/2DGmc3JohczeA997AZQ01m3c6/+oPXjAy7Ndfz/JrQW0M71/eyR+AdP8qdangvTfDP0zC+A5sgNpfyyaa50XeK5MwmBQTRxOdf72f8soDq7leOn+rj91N3Aj+OKI9K9gDRvz+WWXyZnlAJKpX1OPSXLxb0gIqT681Hh/0ko/91YFM7nCgeTr6oE07m2yTbjr1Ywncwf+6pUYj6LYimlzHLSAWO5HRmY++Ejl00FxRKWFrZNSEz2ZEiklt5M2SiTYhwCeLP1MiXPH3baFDPJzO2NvH1yo+CfMRl91LzPojz1Ko/cMVP9t/gWL5M//zOiLfJfyqhR5wubz/4fuFnwSwOKDEuUnycdkRREWyUToQCsStX8ciGse163yd8FicOwptLswVLRKNdKkdKXNIrVNHyU8GM0p35plzmQl0tGDXfgrkunJHTldxYLMBlSxg1FY2STv4+l37IDoG7rMC98HbEZRyID35Nc7EB21xXw+94WNj5XPLtao80g/VTY2j4Q0RqxaHKAtbtxdrEMx3s3cvYdS3xoNebFoNxmhUTY9cnBVzkwdJOMTrUV7LTlMAxHfueoLfufwakSBDCLb4D0gTih0GoMRZpgMKiTK2QQl5St1e80U4Q0q+tRRTJoOVdPuPGYtDab54oI+qzYjoqGfnXgzvJTQV5pIP0X6yTXXX1RCD/giptLtT275Vbd1Yq+l8W77yJ1wrPuKB5pLoGalf3vJnH5KIsTAygW3TscWVwu1n1OojmvGYcwyY4ec1I+hMSGgBwgl0jyFcV4tAMMt2m6LT5AlDKczCUBLExqIbidwd5AT9d6iOC+u2Yds2WSCzhp4irEbs7V1FdvDcsx7Ioh5twGsDRbfVcrO8tHWqrrATJQaA35M6CTs/ahDnCRWLicnOWN/XOwDZUR5rFuV0SPZYIiyA0ruSJdAqhF9TBrNqNzc7UTNldQltVAB3xPjvouPMM5h jwc6w64I Xehakea9lfRzxbcvLHVWHnfHfx1e89zJSMjEERbxjxAQ8W4uOpk13pYZSrNZIhw5du/C4mKddRGdRRZZMLO8O4sl/YTytHBqaQXnZgthzKmh6HsLeW9yxrrvNRN6oS45Se+zu1N92DnC+WhxqFpYfW02zWeU5qDzwVyDaO87jMeSGfW3LtKJLTJ56K/lpChZnLJUdD10FcXQ5nRbmT1t/JMI7nBmPzmzRjzZL/NgN2EnleP8AP5kYxQPBHY0YX66VgrQpOcyzmW1/JiRHNx5ZvMpXRNoV5E9AANcBnme+PoGERoH8fxVkM1fdxXtPUeBme6hXAbIBlz9HkB2nakcF+1Z+O58d4ND7DlY25wJMXno5or+d+Y03DHhgp1rHI3yPfsQu 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 conversion under PTL: Note that this is also what follow_page_pte() ends up doing. Unfortunately we cannot currently optimize out the additional reference, because arch_make_folio_accessible() must be called with a raised refcount to protect against concurrent conversion to secure. We can just move the arch_make_folio_accessible() under the PTL, like follow_page_pte() would. We'll effectively drop the "writable" check implied by FOLL_WRITE: follow_page_pte() would also not check that when calling arch_make_folio_accessible(), so there is no good reason for doing that here. We'll lose the secretmem check from follow_page() as well, about which we shouldn't really care about. Signed-off-by: David Hildenbrand --- arch/s390/mm/fault.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c index 8e149ef5e89b..ad8b0d6b77ea 100644 --- a/arch/s390/mm/fault.c +++ b/arch/s390/mm/fault.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -492,9 +493,9 @@ void do_secure_storage_access(struct pt_regs *regs) union teid teid = { .val = regs->int_parm_long }; unsigned long addr = get_fault_address(regs); struct vm_area_struct *vma; + struct folio_walk fw; struct mm_struct *mm; struct folio *folio; - struct page *page; struct gmap *gmap; int rc; @@ -536,15 +537,18 @@ void do_secure_storage_access(struct pt_regs *regs) vma = find_vma(mm, addr); if (!vma) return handle_fault_error(regs, SEGV_MAPERR); - page = follow_page(vma, addr, FOLL_WRITE | FOLL_GET); - if (IS_ERR_OR_NULL(page)) { + folio = folio_walk_start(&fw, vma, addr, 0); + if (!folio) { mmap_read_unlock(mm); break; } - folio = page_folio(page); - if (arch_make_folio_accessible(folio)) - send_sig(SIGSEGV, current, 0); + /* arch_make_folio_accessible() needs a raised refcount. */ + folio_get(folio); + rc = arch_make_folio_accessible(folio); folio_put(folio); + folio_walk_end(&fw, vma); + if (rc) + send_sig(SIGSEGV, current, 0); mmap_read_unlock(mm); break; case KERNEL_FAULT: