From patchwork Mon Aug 21 12:30:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13359371 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 6BFC9EE49AC for ; Mon, 21 Aug 2023 12:31:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8165E8D000D; Mon, 21 Aug 2023 08:31:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 752558D0002; Mon, 21 Aug 2023 08:31:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61A018D000D; Mon, 21 Aug 2023 08:31:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 50D798D0002 for ; Mon, 21 Aug 2023 08:31:24 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 35E04B2191 for ; Mon, 21 Aug 2023 12:31:24 +0000 (UTC) X-FDA: 81148047288.06.ED258C6 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf05.hostedemail.com (Postfix) with ESMTP id 7B3DA10001D for ; Mon, 21 Aug 2023 12:31:21 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692621082; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GZ/DbYffByNIesxQY+KWY4PvD/yumirnKdLUTYRNp3o=; b=WqGrgnfSIM5lE293AgW3vcSt9Al5nYlTc3ToK0tw7cJkjEQA4ipZxKlJrsApwmF2AHAR6+ woYmGwGXEYee4g/4bmYl5MAGCYtH8vyct/npXfuiZE17U9EaOGmBFP3AwOhOvB6spSb4BI ze4LMLmyNFdzkxFHe0LrUc/PBsgtbp8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692621082; a=rsa-sha256; cv=none; b=FqzoovVw2bcwSxMbOD4HAeETQ4h/K8l6dV+wd8jMwXC1RqpOzNXW3jwEvpzdKNmN8q980y Z1Acbmh3KDqiQ0RjUoVhfPkjr8LoxSwrcOEYTEcIlMkqXC5flATDuKCdAVxjHHwCx8YBm/ UTzbDjBsGwwIeTJq3xpNIVSzoVpg854= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RTsHg0Sf6z1L9Pp; Mon, 21 Aug 2023 20:29:51 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 21 Aug 2023 20:31:16 +0800 From: Kefeng Wang To: Andrew Morton , CC: , , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , , "H . Peter Anvin" , , , , , , , Kefeng Wang Subject: [PATCH rfc v2 04/10] s390: mm: use try_vma_locked_page_fault() Date: Mon, 21 Aug 2023 20:30:50 +0800 Message-ID: <20230821123056.2109942-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230821123056.2109942-1-wangkefeng.wang@huawei.com> References: <20230821123056.2109942-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: 3drear839ejdsyc11mwkboscyfjcmng8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7B3DA10001D X-HE-Tag: 1692621081-781940 X-HE-Meta: U2FsdGVkX1+g+R8zySs174/BfnTcsoWlZwFH6OuXpBeLGmAuYDXY6YWjT4CwtM73fdw1T/2yYMC9yccCCedq3tP9pOdj/coSQmM3D0p2P+ftVvujnKCdSkaHK4t7LUc2MTtzeHCzpaPV25IxTqmNMfqt34n+Kg4GQ+0NsHwtXQZdCu4u/UAnzNHSFcYGsCBaqCqQGkZomHL47aupzwWfYmyvTPHvlNYH23jmZnS7t3rJylcgDELRV7yDCpxBFtDPt9yg1nmLaka//AZLWwwgrbDJ8Cj05gHYcMU3t7ULcmMG3NQu6J/nuRuQSvlmjP2Gimz6GaIq2ka9qvbR/R5CE7Vh0RcdtLUr9Z7hAS8JGEI2DdlpmAOBd9mJ8+6felQ/vAkgqjUXlCVz1lP0DJPAr8TTahBb3oJ8jN4Wkg1PNbOFuTct2HDy5ViIbpc16i9Wo2yLDdVfNibqi0tHw2SYpi6nkuXK9vpLH6br9Zy7LN33s0X3sJ20izStg4NBzjZp47e0Kzb8uAqh4R/Oac8+tta4TB9s/ne8A9ZzBAqbOPKji06+syaphJq7HdNVc/A5+1fo8g+kiYr/2OzleBf0LV2U/BZUy23Jerbql404JPPAWDGECVUH8ATJkXGwvW4z2CA/WXLfydSp3nNRLDWSnshPvt1L0DumivzujfX8LX8EkdXpIXbeZnSigzBRVaDZa2jCxLKSiypHHhjdp3m/NKz7Bc0vJSA6yfDRob4qJoHm908HU71HwlOCd6u63blfDak1Pt/bMNxFXTzGZY9l45vopsEk5r5MFIdS+7BQtDbuMUHb5qPPG7gQGiCL+emRJE6npk1j6terTXEpg6FpWSzfmXluhl0Qyc9iXkzecXrfublLKlewz4+yJnA5UdCu2p/ICxq5kn5dNgythvP2ekYDgdR5/aVJ7EuYzEKm2GkQDGP2nSI2b67DimCxruUM9frYPX13HoCsHGyIo97 NDXnNgmR qGKHYKXFydPLogCZuPkyMhFDwPvcHSp8dL57gD8aI1gIPngc6GdkClSaua+mEUxCgG7IAFv4cyiZft2ieALlceS78/bHIaNZpvw5WstEef04F2eHuiH1FdgtB4SP+VETGznzZb3SHfLBCR8KJAQaDWa+u3L9lMFxLsJpTg+YIlXCZYROZp/IoFiQYeLRPkc55OLdG 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: Use new try_vma_locked_page_fault() helper to simplify code. No functional change intended. Signed-off-by: Kefeng Wang --- arch/s390/mm/fault.c | 66 ++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c index 099c4824dd8a..fbbdebde6ea7 100644 --- a/arch/s390/mm/fault.c +++ b/arch/s390/mm/fault.c @@ -357,16 +357,18 @@ static noinline void do_fault_error(struct pt_regs *regs, vm_fault_t fault) static inline vm_fault_t do_exception(struct pt_regs *regs, int access) { struct gmap *gmap; - struct task_struct *tsk; - struct mm_struct *mm; struct vm_area_struct *vma; enum fault_type type; - unsigned long address; - unsigned int flags; + struct mm_struct *mm = current->mm; + unsigned long address = get_fault_address(regs); vm_fault_t fault; bool is_write; + struct vm_fault vmf = { + .real_address = address, + .flags = FAULT_FLAG_DEFAULT, + .vm_flags = access, + }; - tsk = current; /* * The instruction that caused the program check has * been nullified. Don't signal single step via SIGTRAP. @@ -376,8 +378,6 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) if (kprobe_page_fault(regs, 14)) return 0; - mm = tsk->mm; - address = get_fault_address(regs); is_write = fault_is_write(regs); /* @@ -398,45 +398,33 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) } perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); - flags = FAULT_FLAG_DEFAULT; if (user_mode(regs)) - flags |= FAULT_FLAG_USER; + vmf.flags |= FAULT_FLAG_USER; if (is_write) - access = VM_WRITE; - if (access == VM_WRITE) - flags |= FAULT_FLAG_WRITE; - if (!(flags & FAULT_FLAG_USER)) - goto lock_mmap; - vma = lock_vma_under_rcu(mm, address); - if (!vma) - goto lock_mmap; - if (!(vma->vm_flags & access)) { - vma_end_read(vma); - goto lock_mmap; - } - fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) - vma_end_read(vma); - if (!(fault & VM_FAULT_RETRY)) { - count_vm_vma_lock_event(VMA_LOCK_SUCCESS); - if (likely(!(fault & VM_FAULT_ERROR))) - fault = 0; + vmf.vm_flags = VM_WRITE; + if (vmf.vm_flags == VM_WRITE) + vmf.flags |= FAULT_FLAG_WRITE; + + fault = try_vma_locked_page_fault(&vmf); + if (fault == VM_FAULT_NONE) + goto lock_mm; + if (!(fault & VM_FAULT_RETRY)) goto out; - } - count_vm_vma_lock_event(VMA_LOCK_RETRY); + /* Quick path to respond to signals */ if (fault_signal_pending(fault, regs)) { fault = VM_FAULT_SIGNAL; goto out; } -lock_mmap: + +lock_mm: mmap_read_lock(mm); gmap = NULL; if (IS_ENABLED(CONFIG_PGSTE) && type == GMAP_FAULT) { gmap = (struct gmap *) S390_lowcore.gmap; current->thread.gmap_addr = address; - current->thread.gmap_write_flag = !!(flags & FAULT_FLAG_WRITE); + current->thread.gmap_write_flag = !!(vmf.flags & FAULT_FLAG_WRITE); current->thread.gmap_int_code = regs->int_code & 0xffff; address = __gmap_translate(gmap, address); if (address == -EFAULT) { @@ -444,7 +432,7 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) goto out_up; } if (gmap->pfault_enabled) - flags |= FAULT_FLAG_RETRY_NOWAIT; + vmf.flags |= FAULT_FLAG_RETRY_NOWAIT; } retry: @@ -466,7 +454,7 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) * we can handle it.. */ fault = VM_FAULT_BADACCESS; - if (unlikely(!(vma->vm_flags & access))) + if (unlikely(!(vma->vm_flags & vmf.vm_flags))) goto out_up; /* @@ -474,10 +462,10 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) * make sure we exit gracefully rather than endlessly redo * the fault. */ - fault = handle_mm_fault(vma, address, flags, regs); + fault = handle_mm_fault(vma, address, vmf.flags, regs); if (fault_signal_pending(fault, regs)) { fault = VM_FAULT_SIGNAL; - if (flags & FAULT_FLAG_RETRY_NOWAIT) + if (vmf.flags & FAULT_FLAG_RETRY_NOWAIT) goto out_up; goto out; } @@ -497,7 +485,7 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) if (fault & VM_FAULT_RETRY) { if (IS_ENABLED(CONFIG_PGSTE) && gmap && - (flags & FAULT_FLAG_RETRY_NOWAIT)) { + (vmf.flags & FAULT_FLAG_RETRY_NOWAIT)) { /* * FAULT_FLAG_RETRY_NOWAIT has been set, mmap_lock has * not been released @@ -506,8 +494,8 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) fault = VM_FAULT_PFAULT; goto out_up; } - flags &= ~FAULT_FLAG_RETRY_NOWAIT; - flags |= FAULT_FLAG_TRIED; + vmf.flags &= ~FAULT_FLAG_RETRY_NOWAIT; + vmf.flags |= FAULT_FLAG_TRIED; mmap_read_lock(mm); goto retry; }