From patchwork Sun Nov 29 00:45:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 11938889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69500C63777 for ; Sun, 29 Nov 2020 00:50:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB82F20731 for ; Sun, 29 Nov 2020 00:50:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JXkc1J0m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB82F20731 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1516E6B0071; Sat, 28 Nov 2020 19:50:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B1336B0072; Sat, 28 Nov 2020 19:50:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD4396B0073; Sat, 28 Nov 2020 19:50:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id B6E1B6B0071 for ; Sat, 28 Nov 2020 19:50:04 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7EAC1181AEF3F for ; Sun, 29 Nov 2020 00:50:04 +0000 (UTC) X-FDA: 77535623928.01.tree23_2316e9627395 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 6224F10051D0B for ; Sun, 29 Nov 2020 00:50:04 +0000 (UTC) X-HE-Tag: tree23_2316e9627395 X-Filterd-Recvd-Size: 6985 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Sun, 29 Nov 2020 00:50:03 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id 34so7361563pgp.10 for ; Sat, 28 Nov 2020 16:50:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Outm6gEC+5HjahTktjjf3Gr4SlDabvLvwFKs6X9GaDo=; b=JXkc1J0m8q1ntIjEb8P0oB7txqBuFASeZRfk+omNYk7PSIF9Lb17UYXJw0JZ44Gvpu vyhiqCx0fLhJxtWz3BHww882rkN3VXTSCye4KO03ADZCppgAWMFaAD0YnJT5b/5O6paR dUvmyrw1IZ8lY1XsFTTaA68OALCpBgBHx4qfU7F3wjQ0GyEWepLcJ1JzQMwaWUVlUxKf UTbFHlb8xVyN2aoazAVCVQzhdJmgZ5e9051KiaGjAM7aUu/VmRaReDB+JVMH1qZjVrk9 P2PAA86vJxpTRJRyw+R+AJyq6lCuWHsizPj3XM9Kj3MgyjYSTTjf3F/9kbLLIBIbmyPo cVgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Outm6gEC+5HjahTktjjf3Gr4SlDabvLvwFKs6X9GaDo=; b=OPqu08+IPVioLliKwiMx96C4nCjTWEcZjvOOxNNxVG+3lnTWp3HAXtU9nS/sft4CRH aXkvERDn/C1dnUvjYOU3tBLqEUOxfBVvKlbhbNzROUGbM4CxmtW2J4wl61UiUSzyIGGq NAElNq8hgZi7jFJlZ36hUq1Ck0hZ//yCHOnJCF1V+K/o35f+rnhylueojd53lNZUxNS6 7QVZC/XuxIG2EXahDjYDBsIh6fysIy4TdFrMxDwO0FIE4hD3iSlVC2i3DSRxKx8DQUZn L8qVEGROUqAwX9KNmLwj3nfbM7kVxgD4Obuls3hJ0vfsiBJ0hW7/h3oYMk+0BLKQZlHE cCDw== X-Gm-Message-State: AOAM531VcbAH+PitP8BnT3i2pdUQv3Cj2wGF57yFjP8HgbKxbVEm237i K0tTlZg2fLzr1kVTemgrjmBhE5A1/ReB+Q== X-Google-Smtp-Source: ABdhPJz2e8ontBvjHCkwTIZD/Q/8yELGY7l4hU7c2tROHTtsG+mu9LU/UdHzbTu+WsuKZa2yKMHsQw== X-Received: by 2002:a63:531b:: with SMTP id h27mr11647606pgb.371.1606611003080; Sat, 28 Nov 2020 16:50:03 -0800 (PST) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id gg19sm16444871pjb.21.2020.11.28.16.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2020 16:50:02 -0800 (PST) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-fsdevel@vger.kernel.org Cc: Nadav Amit , Jens Axboe , Andrea Arcangeli , Peter Xu , Alexander Viro , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 06/13] iov_iter: support atomic copy_page_from_iter_iovec() Date: Sat, 28 Nov 2020 16:45:41 -0800 Message-Id: <20201129004548.1619714-7-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201129004548.1619714-1-namit@vmware.com> References: <20201129004548.1619714-1-namit@vmware.com> MIME-Version: 1.0 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: From: Nadav Amit copy_page_from_iter_iovec() cannot be used when preemption is enabled. Change copy_page_from_iter_iovec() into __copy_page_from_iter_iovec() with an additional parameter that says whether the caller runs in atomic context. When __copy_page_from_iter_iovec() is used in an atomic context it will gracefully fail but would not lead to a deadlock. The caller is expected to recover from such failure gracefully. Cc: Jens Axboe Cc: Andrea Arcangeli Cc: Peter Xu Cc: Alexander Viro Cc: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Nadav Amit --- include/linux/uio.h | 3 +++ lib/iov_iter.c | 23 +++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 72d88566694e..7c90f7371a6f 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -121,6 +121,9 @@ size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, struct iov_iter *i); size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, struct iov_iter *i); +size_t __copy_page_from_iter(struct page *page, size_t offset, size_t bytes, + struct iov_iter *i, bool atomic); + size_t _copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i); size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i); diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 1635111c5bd2..e597df6a46a7 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -246,7 +246,7 @@ static size_t copy_page_to_iter_iovec(struct page *page, size_t offset, size_t b } static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t bytes, - struct iov_iter *i) + struct iov_iter *i, bool atomic) { size_t skip, copy, left, wanted; const struct iovec *iov; @@ -259,14 +259,15 @@ static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t if (unlikely(!bytes)) return 0; - might_fault(); + if (!atomic) + might_fault(); wanted = bytes; iov = i->iov; skip = i->iov_offset; buf = iov->iov_base + skip; copy = min(bytes, iov->iov_len - skip); - if (IS_ENABLED(CONFIG_HIGHMEM) && !fault_in_pages_readable(buf, copy)) { + if (atomic || (IS_ENABLED(CONFIG_HIGHMEM) && !fault_in_pages_readable(buf, copy))) { kaddr = kmap_atomic(page); to = kaddr + offset; @@ -295,6 +296,9 @@ static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t buf += copy; kunmap_atomic(kaddr); copy = min(bytes, iov->iov_len - skip); + if (atomic) + goto done; + } /* Too bad - revert to non-atomic kmap */ @@ -929,8 +933,8 @@ size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, } EXPORT_SYMBOL(copy_page_to_iter); -size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, - struct iov_iter *i) +size_t __copy_page_from_iter(struct page *page, size_t offset, size_t bytes, + struct iov_iter *i, bool atomic) { if (unlikely(!page_copy_sane(page, offset, bytes))) return 0; @@ -944,7 +948,14 @@ size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, kunmap_atomic(kaddr); return wanted; } else - return copy_page_from_iter_iovec(page, offset, bytes, i); + return copy_page_from_iter_iovec(page, offset, bytes, i, atomic); +} +EXPORT_SYMBOL(__copy_page_from_iter); + +size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, + struct iov_iter *i) +{ + return __copy_page_from_iter(page, offset, bytes, i, false); } EXPORT_SYMBOL(copy_page_from_iter);