From patchwork Fri Sep 15 17:28:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13387298 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 82249EED619 for ; Fri, 15 Sep 2023 17:28:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DED16B027C; Fri, 15 Sep 2023 13:28:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98FCD6B034F; Fri, 15 Sep 2023 13:28:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8581C6B035D; Fri, 15 Sep 2023 13:28:35 -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 771A36B027C for ; Fri, 15 Sep 2023 13:28:35 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 531851A0417 for ; Fri, 15 Sep 2023 17:28:35 +0000 (UTC) X-FDA: 81239516190.25.01AEEAF Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id 2F0981C0003 for ; Fri, 15 Sep 2023 17:28:32 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HX7V942n; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798913; 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=yD9ktfId0rEPTuzY1QWVmcz2oEdRPlEREsQSBWfYTjA=; b=lHziuK4KHE0x4WSB/p5oco/chLDE8L1Txf27C+F83wQ2DvGb9qhf5BD5Lgj3Dyv00cOD41 BwXeVM6BAhLrjkFhnxdqKod24BnJ+VdmjDJ49LU40NMgv5Rxpu1VZpTH9CRYDHV6lTetEg etksTs1F7fSG4vpSyQ3hh8GfNRk973g= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HX7V942n; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798913; a=rsa-sha256; cv=none; b=RpXvyjRPDXGmszjrHh91sCylxr22gnPYnO63I2nfmkiBNd3YJPdnv+uJEakOKu0A8QP3V4 /fPNJ6pEmGR1plzPVI2OqLCKHRawUaWwbxjnMe/XCWVOV7UkZvDGEPcOSbnJZlGbU+WkVb US/L3z1Y7QQzL7CsJV8RGuKgpTuSb1I= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=yD9ktfId0rEPTuzY1QWVmcz2oEdRPlEREsQSBWfYTjA=; b=HX7V942nk7CHODHYQIA5tKfGxK cqfI5oqlGmQtDriP6IOkzJVbb4aQ9RVu+dirfylSh9gv/23r1hv78HpgIe6qdGAv9305ibm/CcUiP Cy7+3Mb8ROXAJWT218q0vG0yenqlmVqwmpfUAiqkSYIU1i8d6Kllw2K8786NlWuL+qk9sic5Q84av vz6Tnnu+8qAIDYA6k0PurN9+jHhz8oS1Zz1yC7jBuK7KTc9AMNsD0E2OnAnjGA97omR5Dc2FrvaBt NHsa8YRE+hRQ5/zTc7ddCWQ201F0sGDveVYd+7PeKe+MhfDy0+FawWBchRl7RY8NXygzu1sr3awRc EYMtiwEg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qhCcI-00B2xv-MV; Fri, 15 Sep 2023 17:28:30 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Claudio Imbrenda , linux-s390@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 3/3] s390: Convert arch_make_page_accessible() to arch_make_folio_accessible() Date: Fri, 15 Sep 2023 18:28:28 +0100 Message-Id: <20230915172829.2632994-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230915172829.2632994-1-willy@infradead.org> References: <20230915172829.2632994-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2F0981C0003 X-Rspam-User: X-Stat-Signature: 8uixf6qsypfoyned8fgfs1hwc7o57don X-Rspamd-Server: rspam01 X-HE-Tag: 1694798912-922096 X-HE-Meta: U2FsdGVkX18hL8WISOZBFY3fpZxtlsiwXX5HUUNgTwilwHF09osVa/TDKOv2L3LaL/+EsAvB/ke6YbpzgIC4a5SqIoDz9aqg6pP9sWmnlDGJAwsCqwaJcgVTm4gDLCzMAAWAOwuLw2IioYC7AICVAB0+g7Ehz/4No+IVGrZ7cJFtE8wmu7gDoy5uq5Mw/Yd7sRLlr1sYF2kUieEnOxmIvoCIVGoQYc8w147H8pRTk0XwZz1jsa/b/L9WIHIL7Lg0FB+keT4xvMBQeqEIdFGMnR6OoTGNqyfSJMHcEDUxOof+BXLzMwphcdulhvYFFlbmHC58DQrB3hqCy4eXbxWnxEMzhn5z8juFKSOcXjDcnYKhGJV2skmUebryCw+AtsTYFAjEpUAtkm1YMcceHJH7NVPnw1hFLWJKVQYNZJT2V7Mtoyx8WwCm4vKKSeA9PdvZOcuNNh4JY7nsAZCIgmcr3I7aEKLIkEI9XUXr98L3AcD7DXlJbyAJ37iocdBkCXtww5qBwy3doGsgMWMaI/M1mdQMneKxNGRA6MWShYm5XXIgrN9VmLnupng7fSv4Ja7oJ/mhps92tpULAVqQYXl63Dh59hlfKm1vHPIj+UgfdL+VoUwdFpB2j9yDA3faBU6BX/NgUCWEYYk/S2t45SZY23fFdkBg9g1ZkB8I8d0XTauOSRZrnxst3b/5Ik2Ha1HqTnPdLG0q4/jcajImt6rARykBEznVQGfIzPQGasqdqFIaNyM1fDKxWLc83l8K2ZZnZKNN1gX7Y88mxWMKEc+OLwwqBg/1mjPgJoKuAnLKDbUyNhstOAAI+soRH1E4TA/VTbcNQDXUylkjfiw3Y55qseI1pk0qK+UJtenLsdlcVhkB4+nsQMsxchgJu0P4yVl+IUCEnVtJc5AfB1VjzT8qgBbVJ01urGZ//Gs3UA/Cmfxge2AzY3UbUqnATwFXvz16yFefjG6opVxkxHIxCCD 2LMjsyaR iyGNUFscgL4qtqbEJXcUfItPgxdT4qKZIKbKRAYUwbu9Mi5PAL+fvoihN+oUZJdb0cXlLFmwI8OCbkYcnWL4VI59UgGOpA2DXd1y+5JahHi4YSBlWBaIC+Fg7tpU8z+e+45DXCuLyPXASvGsMRqUXMo7df31trUpF5kAUIOR6sYbpPpipF5aOPmLaGYZm92GdsPG2h/vZRoFHlyD5L91WZVPznKoQ3O2OVT/I 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: With all users now using arch_make_folio_accessible(), move the loop over each page from common code into the only implementation. Signed-off-by: Matthew Wilcox (Oracle) --- arch/s390/include/asm/page.h | 5 ++-- arch/s390/kernel/uv.c | 46 +++++++++++++++++++++++------------- arch/s390/mm/fault.c | 15 ++++++------ include/linux/mm.h | 20 ++-------------- 4 files changed, 42 insertions(+), 44 deletions(-) diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h index cfec0743314e..4f1b7107f0d9 100644 --- a/arch/s390/include/asm/page.h +++ b/arch/s390/include/asm/page.h @@ -162,6 +162,7 @@ static inline int page_reset_referenced(unsigned long addr) #define _PAGE_ACC_BITS 0xf0 /* HW access control bits */ struct page; +struct folio; void arch_free_page(struct page *page, int order); void arch_alloc_page(struct page *page, int order); void arch_set_page_dat(struct page *page, int order); @@ -175,8 +176,8 @@ static inline int devmem_is_allowed(unsigned long pfn) #define HAVE_ARCH_ALLOC_PAGE #if IS_ENABLED(CONFIG_PGSTE) -int arch_make_page_accessible(struct page *page); -#define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE +int arch_make_folio_accessible(struct folio *folio); +#define arch_make_folio_accessible arch_make_folio_accessible #endif #define __PAGE_OFFSET 0x0UL diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index fc07bc39e698..dadf29469b46 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -426,46 +426,58 @@ int gmap_destroy_page(struct gmap *gmap, unsigned long gaddr) EXPORT_SYMBOL_GPL(gmap_destroy_page); /* - * To be called with the page locked or with an extra reference! This will - * prevent gmap_make_secure from touching the page concurrently. Having 2 - * parallel make_page_accessible is fine, as the UV calls will become a - * no-op if the page is already exported. + * To be called with the folio locked or with an extra reference! This will + * prevent gmap_make_secure from touching the folio concurrently. Having 2 + * parallel make_folio_accessible is fine, as the UV calls will become a + * no-op if the folio is already exported. + * + * Returns 0 on success or negative errno. */ -int arch_make_page_accessible(struct page *page) +int arch_make_folio_accessible(struct folio *folio) { - int rc = 0; + unsigned long i, nr = folio_nr_pages(folio); + unsigned long pfn = folio_pfn(folio); + int err = 0; /* Hugepage cannot be protected, so nothing to do */ - if (PageHuge(page)) + if (folio_test_hugetlb(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 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)); - if (!rc) { - clear_bit(PG_arch_1, &page->flags); + for (i = 0; i < nr; i++) { + err = uv_pin_shared((pfn + i) * PAGE_SIZE); + if (err) + break; + } + if (!err) { + clear_bit(PG_arch_1, &folio->flags); return 0; } - rc = uv_convert_from_secure(page_to_phys(page)); - if (!rc) { - clear_bit(PG_arch_1, &page->flags); + for (i = 0; i < nr; i++) { + err = uv_convert_from_secure((pfn + i) * PAGE_SIZE); + if (err) + break; + } + if (!err) { + clear_bit(PG_arch_1, &folio->flags); return 0; } - return rc; + return err; } -EXPORT_SYMBOL_GPL(arch_make_page_accessible); +EXPORT_SYMBOL_GPL(arch_make_folio_accessible); #endif diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c index b678295931c3..ac707e5d58ab 100644 --- a/arch/s390/mm/fault.c +++ b/arch/s390/mm/fault.c @@ -588,6 +588,7 @@ void do_secure_storage_access(struct pt_regs *regs) struct vm_area_struct *vma; struct mm_struct *mm; struct page *page; + struct folio *folio; struct gmap *gmap; int rc; @@ -643,17 +644,17 @@ void do_secure_storage_access(struct pt_regs *regs) mmap_read_unlock(mm); break; } - if (arch_make_page_accessible(page)) + folio = page_folio(page); + if (arch_make_folio_accessible(folio)) send_sig(SIGSEGV, current, 0); - put_page(page); + folio_put(folio); mmap_read_unlock(mm); break; case KERNEL_FAULT: - page = phys_to_page(addr); - if (unlikely(!try_get_page(page))) - break; - rc = arch_make_page_accessible(page); - put_page(page); + folio = page_folio(phys_to_page(addr)); + folio_get(folio); + rc = arch_make_folio_accessible(folio); + folio_put(folio); if (rc) BUG(); break; diff --git a/include/linux/mm.h b/include/linux/mm.h index bf5d0b1b16f4..55d3e466d3cb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2139,26 +2139,10 @@ static inline int folio_estimated_sharers(struct folio *folio) return page_mapcount(folio_page(folio, 0)); } -#ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE -static inline int arch_make_page_accessible(struct page *page) -{ - return 0; -} -#endif - -#ifndef HAVE_ARCH_MAKE_FOLIO_ACCESSIBLE +#ifndef arch_make_folio_accessible static inline int arch_make_folio_accessible(struct folio *folio) { - int ret; - long i, nr = folio_nr_pages(folio); - - for (i = 0; i < nr; i++) { - ret = arch_make_page_accessible(folio_page(folio, i)); - if (ret) - break; - } - - return ret; + return 0; } #endif