From patchwork Wed Sep 13 16:56:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13383571 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 8035DEE01E9 for ; Wed, 13 Sep 2023 16:57:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D4136B01FE; Wed, 13 Sep 2023 12:57:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1832D6B01FF; Wed, 13 Sep 2023 12:57:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 024336B0200; Wed, 13 Sep 2023 12:57:20 -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 E043B6B01FE for ; Wed, 13 Sep 2023 12:57:20 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B523180482 for ; Wed, 13 Sep 2023 16:57:20 +0000 (UTC) X-FDA: 81232179840.10.438B25A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 0300040021 for ; Wed, 13 Sep 2023 16:57:18 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HfOn669x; spf=pass (imf17.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694624239; 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=xJaTbGB+togQTw9SIdIdixTkcz5/QJ2b3c5fZ9o3sSg=; b=raTY/HTUlabuURJoSTYrm8aE+2c0HFM/aGEBcK6JJpDB2Fpr2vwnc/qhz7cUfxAKlioZrz ErxaLMzYCpo3yPwIkUrAks67N3kTEYYTjTOdbHffgLKsutd/ABY4c3OzrdTgIq2pL5X4xe uPVM8twJ90ZCwQUZhitDsA79w0iKEf8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HfOn669x; spf=pass (imf17.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694624239; a=rsa-sha256; cv=none; b=l1AllzG/p0WDvtAdMHghh5ZgUQXH+CJo760uZmXL9FSFiNR9Xqi6x/p2cNSTo2Uey8ddlC jruGBcovvPdYJ7kIgz6IoUOBH7yJvoA5RsuY+6CNUG4DgKQpHPVxaSHHdObnJf110T4vW0 AhiDNpncLADDostU2GUI3Oc2fc5tRcA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694624238; 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=xJaTbGB+togQTw9SIdIdixTkcz5/QJ2b3c5fZ9o3sSg=; b=HfOn669xlwTfoWZq0V70ffw3GETThHlu+aO8dBRezYafMfssbN+RwDifn0aO005+JaE4nr FmYeWfvJOugIKOCdfyp4GFa5qgJtJI+mIEXb5UsjS+McOIYfdjXYAXgeJw3XD+6dcpzNns oWtsQhDP7lM8xhzh+UhYkBpSGbKURsA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-694-6buX1QvqNt-weeixz82rJw-1; Wed, 13 Sep 2023 12:57:12 -0400 X-MC-Unique: 6buX1QvqNt-weeixz82rJw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 222FF18312C9; Wed, 13 Sep 2023 16:57:10 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B42840C6EBF; Wed, 13 Sep 2023 16:57:08 +0000 (UTC) From: David Howells To: Al Viro , Linus Torvalds Cc: David Howells , Jens Axboe , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 07/13] iov_iter: Make copy_from_iter() always handle MCE Date: Wed, 13 Sep 2023 17:56:42 +0100 Message-ID: <20230913165648.2570623-8-dhowells@redhat.com> In-Reply-To: <20230913165648.2570623-1-dhowells@redhat.com> References: <20230913165648.2570623-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: 0300040021 X-Rspam-User: X-Stat-Signature: s519ebb4sq3tpjq7i66ambd9epsx3pt8 X-Rspamd-Server: rspam01 X-HE-Tag: 1694624238-213512 X-HE-Meta: U2FsdGVkX19B/EeYkyK7gw1NNYhdl2BAb5We0CFyrncM+u8K9oORdI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SdDgM1KFHTI0CWZwpfyETaNUvyEkVkiOeQDJU+2r9FvC27+JmshGxs6zOeYK4kJ+yV50RxSc6sD2/aXqbbT3DSWLcVnvVOKXa5UKaUqtg3Q41WGV1oJoMjC8dccOJfc1v9QQ/apXxXv7DZVxHthMoh7z0HV0taXyvquFSvEdj06Bziyi7drfjHT1IdULFlEWVIqKObL4JItB8QqcGTmkBwu/czfH0zsWNXS/i9Up43evjpfr69mgcC3yr7AdQjYTut+ERumIcZciUCKc60rt7Zydn6cyS6vG/xvnJ5HSvR7bC7gFdiu6JnEnynRya0YncliBkG8kWVev9ycisHLJft8/HdkZTVUwcQvyVmo+gpsr8m49ghSkebG27BNjjXkgIy9mjbgobpCUbP2apsNRtboSZq9c7LxKpUfY0g4lBhetKG/hnFcUnF0E0= 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: Make copy_from_iter() always catch an MCE and return a short copy and make the coredump code rely on that. This requires arch support in the form of a memcpy_mc() function that returns the length copied. [?] Is it better to kill the thread in the event of an MCE occurring? Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- arch/x86/include/asm/mce.h | 23 +++++++++++++++++++++++ fs/coredump.c | 1 - lib/iov_iter.c | 12 +++++------- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h index 180b1cbfcc4e..77ce2044536c 100644 --- a/arch/x86/include/asm/mce.h +++ b/arch/x86/include/asm/mce.h @@ -353,4 +353,27 @@ static inline void mce_hygon_feature_init(struct cpuinfo_x86 *c) { return mce_am unsigned long copy_mc_fragile_handle_tail(char *to, char *from, unsigned len); +static __always_inline __must_check +size_t memcpy_mc(void *to, const void *from, size_t len) +{ +#ifdef CONFIG_ARCH_HAS_COPY_MC + /* + * If CPU has FSRM feature, use 'rep movs'. + * Otherwise, use rep_movs_alternative. + */ + asm volatile( + "1:\n\t" + ALTERNATIVE("rep movsb", + "call rep_movs_alternative", ALT_NOT(X86_FEATURE_FSRM)) + "2:\n" + _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_DEFAULT_MCE_SAFE) + :"+c" (len), "+D" (to), "+S" (from), ASM_CALL_CONSTRAINT + : : "memory", "rax", "r8", "r9", "r10", "r11"); +#else + memcpy(to, from, len); + return 0; +#endif + return len; +} + #endif /* _ASM_X86_MCE_H */ diff --git a/fs/coredump.c b/fs/coredump.c index 9d235fa14ab9..ad54102a5e14 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -884,7 +884,6 @@ static int dump_emit_page(struct coredump_params *cprm, struct page *page) pos = file->f_pos; bvec_set_page(&bvec, page, PAGE_SIZE, 0); iov_iter_bvec(&iter, ITER_SOURCE, &bvec, 1, PAGE_SIZE); - iov_iter_set_copy_mc(&iter); n = __kernel_write_iter(cprm->file, &iter, &pos); if (n != PAGE_SIZE) return 0; diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 65374ee91ecd..b574601783bc 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -14,6 +14,7 @@ #include #include #include +#include static __always_inline size_t copy_to_user_iter(void __user *iter_to, size_t progress, @@ -253,14 +254,11 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i) EXPORT_SYMBOL_GPL(_copy_mc_to_iter); #endif /* CONFIG_ARCH_HAS_COPY_MC */ -static size_t memcpy_from_iter_mc(void *iter_from, size_t progress, - size_t len, void *to, void *priv2) +static __always_inline +size_t memcpy_from_iter_mc(void *iter_from, size_t progress, + size_t len, void *to, void *priv2) { - struct iov_iter *iter = priv2; - - if (iov_iter_is_copy_mc(iter)) - return copy_mc_to_kernel(to + progress, iter_from, len); - return memcpy_from_iter(iter_from, progress, len, to, priv2); + return memcpy_mc(to + progress, iter_from, len); } size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i)