From patchwork Wed Mar 29 15:11:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13192689 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 6CC5EC77B61 for ; Wed, 29 Mar 2023 15:11:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01901900005; Wed, 29 Mar 2023 11:11:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBD6F900002; Wed, 29 Mar 2023 11:11:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0FC2900005; Wed, 29 Mar 2023 11:11:31 -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 BE015900002 for ; Wed, 29 Mar 2023 11:11:31 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 88C131C6264 for ; Wed, 29 Mar 2023 15:11:31 +0000 (UTC) X-FDA: 80622274782.30.01572D6 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf27.hostedemail.com (Postfix) with ESMTP id BE74C40007 for ; Wed, 29 Mar 2023 15:11:29 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=H4q+TwD9; spf=pass (imf27.hostedemail.com: domain of 3IFUkZAgKCIMqphxp5hunvvnsl.jvtspu14-ttr2hjr.vyn@flex--jiaqiyan.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3IFUkZAgKCIMqphxp5hunvvnsl.jvtspu14-ttr2hjr.vyn@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680102689; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4YhYo6B188EjYYv/dO1DqyMOiNYtHUIng4cDGkzB8Lk=; b=Z1DUx5s7C33TZtfAODGSF/Ny3qGMAMtl1/YFlCXuy/AKH9qJy7zGYseqL0NL1WfQPRWR33 I33VP0BXkBWZVpkSB91WoWtFk2LGhqDKb0P9H3jZw8O757dYkEWBf5yyOjTPpYUfKRtLQB Ihj6zWNI/PPNXpTMLbZIYAtyumdvAxc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=H4q+TwD9; spf=pass (imf27.hostedemail.com: domain of 3IFUkZAgKCIMqphxp5hunvvnsl.jvtspu14-ttr2hjr.vyn@flex--jiaqiyan.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3IFUkZAgKCIMqphxp5hunvvnsl.jvtspu14-ttr2hjr.vyn@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680102689; a=rsa-sha256; cv=none; b=vrkcE+6V8BpsU2e6i8jMPI85o+2LwrcHKZIh8X2Q6nHySFP9pqYAHmUhuNYeBHQdAE/KWd LmXoPofCokyvGHjX/zhiXEqFjOXqV+MInAWgjuObP2Q7IJmMekd1MUc87bvgz6RbuDYDsq wh/T0dDx+3HZ56XfxKrCFQ1Q4vsBrLI= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-54629ed836aso18475627b3.10 for ; Wed, 29 Mar 2023 08:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680102689; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4YhYo6B188EjYYv/dO1DqyMOiNYtHUIng4cDGkzB8Lk=; b=H4q+TwD9UVpgB5nFgnHUeSTy5tD0C0o/7KXWk/aX4kOJfKGqztfLfegB7y6oFPt10l zT/qiuo3l6IfZBy8o+vMHOurFOfvLa/VLAO1yXBXfYtwP9GISZDxPZelRRJmUeAN49hr jFwM+F7C3+hbhDBEDUzazCLLQo+CFAyVebNDt0d9nPWNt+WKgN1ALhbksLuhohjo71DR ZfXwoAjwArUaEQTX43NeNulPfo5XZKGT6NnlBe/xx6dh0haZg/iJN0NOXxt1pWgeutBN DRQnuFLe3uV1Tglvuy8jYPJ1yNcuOOYcaklRBzt1wwC5oVRJb7V7A/TWgq+WfoOnckbJ 1p4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680102689; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4YhYo6B188EjYYv/dO1DqyMOiNYtHUIng4cDGkzB8Lk=; b=vFjltVoybRXY6ZRmDR6txULBS3n7GZK1+hMSWaH5N0QYqYowesdOERnt2F+fmVrCNk ukA5tnXeFqSy0BWm8c3hwaJPjD1W62tPHOjCVA/7bzcmE8RsF2O5gNR/b9fm0nj0u0QK 0wCvLmdU1ceN1XGHSaA7vvgdz399R570LXNdLGcVbFsZp0cYYKZ8RIB62COOojjbp+IJ acIbNICznKAOopOmWIb2LKbtjmiitiphKtN9tC6IeaC82sJqrbPNroHTiPSM7zMqVEb1 RKn+mfFNm5HD0cv8p/qWB3wwWtRCaT3B2HWWasb1IJq//ESwNwHKv3UH272MtOwqXjMz KpcQ== X-Gm-Message-State: AAQBX9f5h3YWTMQAvjRLv0ME/mwf+ce5uucJ6L+Vy3/nE79l5M5j005D SNbMbLKc+O1FEQ0nisAOJ5NS7PjGpp0YQw== X-Google-Smtp-Source: AKy350a6vnNmt0apkVinDUk9B3nDoGqNiJBFJu9rC2M/NhUgqqaqBkIa19qq+cveyhDdOd5rJA+y2DJGs3jtKg== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a81:d007:0:b0:546:81f:a89e with SMTP id v7-20020a81d007000000b00546081fa89emr3865593ywi.9.1680102688868; Wed, 29 Mar 2023 08:11:28 -0700 (PDT) Date: Wed, 29 Mar 2023 08:11:20 -0700 In-Reply-To: <20230329151121.949896-1-jiaqiyan@google.com> Mime-Version: 1.0 References: <20230329151121.949896-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230329151121.949896-3-jiaqiyan@google.com> Subject: [PATCH v12 2/3] mm/hwpoison: introduce copy_mc_highpage From: Jiaqi Yan To: kirill.shutemov@linux.intel.com, kirill@shutemov.name, shy828301@gmail.com, tongtiangen@huawei.com, tony.luck@intel.com Cc: naoya.horiguchi@nec.com, linmiaohe@huawei.com, jiaqiyan@google.com, linux-mm@kvack.org, akpm@linux-foundation.org, osalvador@suse.de, wangkefeng.wang@huawei.com, stevensd@chromium.org, hughd@google.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: s3jmtadj1meahhdah3fyfcju7n8y6c8k X-Rspamd-Queue-Id: BE74C40007 X-HE-Tag: 1680102689-437718 X-HE-Meta: U2FsdGVkX1/2utgERDyk509a7mz094ArvCoG/uvKA0BhGq34BJV3gC1Tb2sLc0jBFdwAmUlFOEU4SUW2nCsntG7q5SCwY5fFVq4gQsj5jP4FuKkwhLxqbpxU8hhqY6/SYh+iRGGd9lZ7XoWiOtc4V3P6picSFNce5RGgvbitA6z95r4BNstS1tRx55FP+0ldxf0fxMNSxzDkEHd/i8ae1OiS/qn59NyuS0Gz2zG812vkdWTVPJlDgkd/jzaiNd0TQfCOYVoaZr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fWQyuOlkcp7NNfdvR0EchyGrBjj2SIVEu8C7muhHofemOVKp71siuTFrJqnzY/pmOjfWeSzaqW8gD02m7jiBFVY530pyFGgSombSpW9PDzUFzkWoox5Sz2CBVQhSi0svLTilLXzqMZy8DHUXp3t+CTWWWrw7izy4nzHBqE9QD5fkezat7QfKWu+gYhM06kMhNtEYHlsFvWoHKOwO/EsN5D7h7oPgoKtCrOLoVwChU2r8LzQ80QX+E4ECZ1AuHo65n4dk2muefDkqZiX8iCGwO2kulZNFb7ND+avhfskjnh0H1ol8X+9ftk1A8Cqpr2V2fXRqN8kxfaeq87n4/vyoeeexdmXcuG57F5U0DkHq+QFFYl/VBPAw== 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: Similar to how copy_mc_user_highpage is implemented for copy_user_highpage on #MC supported architecture, introduce the #MC handled version of copy_highpage. This helper has immediate usage when khugepaged wants to copy file-backed memory pages and tolerate #MC. Signed-off-by: Jiaqi Yan Reviewed-by: Yang Shi --- include/linux/highmem.h | 54 +++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 9c7cdaa3de8cd..4de1dbcd3ef64 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -315,7 +315,29 @@ static inline void copy_user_highpage(struct page *to, struct page *from, #endif +#ifndef __HAVE_ARCH_COPY_HIGHPAGE + +static inline void copy_highpage(struct page *to, struct page *from) +{ + char *vfrom, *vto; + + vfrom = kmap_local_page(from); + vto = kmap_local_page(to); + copy_page(vto, vfrom); + kmsan_copy_page_meta(to, from); + kunmap_local(vto); + kunmap_local(vfrom); +} + +#endif + #ifdef copy_mc_to_kernel +/* + * If architecture supports machine check exception handling, define the + * #MC versions of copy_user_highpage and copy_highpage. They copy a memory + * page with #MC in source page (@from) handled, and return the number + * of bytes not copied if there was a #MC, otherwise 0 for success. + */ static inline int copy_mc_user_highpage(struct page *to, struct page *from, unsigned long vaddr, struct vm_area_struct *vma) { @@ -332,29 +354,35 @@ static inline int copy_mc_user_highpage(struct page *to, struct page *from, return ret; } -#else -static inline int copy_mc_user_highpage(struct page *to, struct page *from, - unsigned long vaddr, struct vm_area_struct *vma) -{ - copy_user_highpage(to, from, vaddr, vma); - return 0; -} -#endif -#ifndef __HAVE_ARCH_COPY_HIGHPAGE - -static inline void copy_highpage(struct page *to, struct page *from) +static inline int copy_mc_highpage(struct page *to, struct page *from) { + unsigned long ret; char *vfrom, *vto; vfrom = kmap_local_page(from); vto = kmap_local_page(to); - copy_page(vto, vfrom); - kmsan_copy_page_meta(to, from); + ret = copy_mc_to_kernel(vto, vfrom, PAGE_SIZE); + if (!ret) + kmsan_copy_page_meta(to, from); kunmap_local(vto); kunmap_local(vfrom); + + return ret; +} +#else +static inline int copy_mc_user_highpage(struct page *to, struct page *from, + unsigned long vaddr, struct vm_area_struct *vma) +{ + copy_user_highpage(to, from, vaddr, vma); + return 0; } +static inline int copy_mc_highpage(struct page *to, struct page *from) +{ + copy_highpage(to, from); + return 0; +} #endif static inline void memcpy_page(struct page *dst_page, size_t dst_off,