From patchwork Tue Sep 19 07:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 141912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3424930vqi; Tue, 19 Sep 2023 07:19:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8DJOo0E2hQVd2HC7Fs8DhFhds2Pek1uVLN1LFBghP7BP2g3bzXh0vTrBD+uqRH1Vmxvhx X-Received: by 2002:a05:6358:3413:b0:143:27e:d3cf with SMTP id h19-20020a056358341300b00143027ed3cfmr15198701rwd.4.1695133175967; Tue, 19 Sep 2023 07:19:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695133175; cv=none; d=google.com; s=arc-20160816; b=BDuiqkT6u2XdM4E1Qhnky7OetRhTlLco96wWQV/iVIYqEt7FpYVUd4RxGXYpA1mLM3 eqJ+G4/xg8YuHJgySI8xl2IH5E0M76QSR5zcVwLOj6FWNwjLOg59DsjTJD9VafD4Mthf oCKmwktFzdgoZXnpTMGUSC5nsusVipaOrX+zTsQt/cGeD2FM/6ZSErPxFIZOiCGiuMMx MJCqlt0fmXvZIgmanoDNHu2lKY836CaBhYaieLUQtuE/BOaWstWTOWrKI7ca7csheOVz qUc29zXDwr2xXfvC5ENNB5khDaA8c1uc3lrxnSlv3uYxGbmyl+ABV8FEBurRhdVDe14g jarg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=TYhAeXJ6n0p1NLvV6l5GcJ19JSLs3+6aIPIDGI6CfRk=; fh=koSzqVT9cbu9a0VeQ+VZmxtXb/DvsILKvDzYrpZ/jzA=; b=upnvJpylycwh1hbcXBcKwogrzFRUWvHjOBG1qYX4TtGhvFT6TTI/FdBsXNUVqL1hzv 4LbTfx2P8gu0ZJ9bCftVSuHMdT0pVL9p2dS5dL4CxNkAk8u5cI81bu0dG/jGNZsbrPOi PQzqW/Do4PszwNeMfGxePQRVHr50DpwYch5L2gsgeNYF0CwSsjyV8bP6QtSo4BiKYfm/ Ut6zEKNowO1cX7iwGsUfE62YcEt5r6FkhStRwwhoTGixxG5BTpa52XChJgNkKnt0uuTF DPyJWvZDnpdp3jt52p5s90mR9uy5Ui/wkDmlGi4F11wuIvj1NiNE9XUSJMhqwoH6qW0g 9wlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=Yps8gmke; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id b22-20020a631b16000000b0056c4d97e157si1356201pgb.377.2023.09.19.07.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 07:19:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=Yps8gmke; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id BE3098211203; Tue, 19 Sep 2023 00:38:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231843AbjISHif (ORCPT + 26 others); Tue, 19 Sep 2023 03:38:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231812AbjISHiP (ORCPT ); Tue, 19 Sep 2023 03:38:15 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 309DD13A for ; Tue, 19 Sep 2023 00:38:08 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-502e6d632b6so8257522e87.0 for ; Tue, 19 Sep 2023 00:38:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695109087; x=1695713887; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TYhAeXJ6n0p1NLvV6l5GcJ19JSLs3+6aIPIDGI6CfRk=; b=Yps8gmkeTmp9JUZIsf1OHZOR5CVvG3FM9iwqX/oT2nQFL1/5tUX0m05MNvJox0Qzm1 xbeRaRvq9pJeHQEOmQSt70InTnK20NjKouJmjluTYVXFV4988iHPky+1cBfL5i8OQxvB /8TkroWxHiRJgQdvaEGbVCZf+Y9GS6zI4irb0efd26czhZnJdMEVZ6TjY6ZqUouIskR8 Tbyzbf45ACYDvxZNiJoo3+uv/y2blGxLbJ/PJ7U/QJYQ6Tw+PxrMjxB2QAHYyqyb5uqa 83UF6b+8GqYDwJVQl8Kpstb/ljJN33a6QpWWM3FWcgbrnmOCvFhcGc+gg7FQnHfHMYhE DgEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695109087; x=1695713887; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TYhAeXJ6n0p1NLvV6l5GcJ19JSLs3+6aIPIDGI6CfRk=; b=dtVa51RQuTYPNRnVe1rhzf1bwe3ftXQLiaQEFkw8qu9P2NAAFAQq8aVznMFdwiaeHE s6mskHd0H6/2nQf7tBCHHrPTMe0pgY9GA9K+YL5k6aMTAFD2dHN+u20ZiJVX9RITmb77 dXtPVq1sFeJk9rKR4L8vwJwnlpIjI9ZdOgjMPAqBsGLC6ZCNJUHMoqnJVh6QCaFGdJ58 QAT61A6dQk1MqmgAFYiO7DS1nxkJWy90OpRNmZMABMtJEDckfumMTKojIBb8PK+HyuOW z+S1U03oEWbfwIgGVbQBfzpgwgXHLvYvDXnjLS1Kar6B3Vq5vO0yv7nQMkjkFF84ZXta fdmQ== X-Gm-Message-State: AOJu0Yy7VGpEkUWgRCtF1Lt8Jrm9nukt/p5wQWILj58WAyCSeaIKnxjx ecd1iEB2j+FTFhC42I96VbbCrw== X-Received: by 2002:ac2:4285:0:b0:503:19d9:4b6f with SMTP id m5-20020ac24285000000b0050319d94b6fmr3374875lfh.0.1695109086944; Tue, 19 Sep 2023 00:38:06 -0700 (PDT) Received: from heron.intern.cm-ag (p200300dc6f209c00529a4cfffe3dd983.dip0.t-ipconnect.de. [2003:dc:6f20:9c00:529a:4cff:fe3d:d983]) by smtp.gmail.com with ESMTPSA id v4-20020aa7d644000000b0052567e6586bsm7049439edr.38.2023.09.19.00.38.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 00:38:06 -0700 (PDT) From: Max Kellermann To: Arnd Bergmann , Greg Kroah-Hartman Cc: Max Kellermann , linux-kernel@vger.kernel.org Subject: [PATCH] drivers/char/mem: implement splice() for /dev/zero, /dev/full Date: Tue, 19 Sep 2023 09:37:42 +0200 Message-Id: <20230919073743.1066313-1-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 19 Sep 2023 00:38:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777475965415244954 X-GMAIL-MSGID: 1777475965415244954 This allows splicing zeroed pages into a pipe, and allows discarding pages from a pipe by splicing them to /dev/zero. Writing to /dev/zero should have the same effect as writing to /dev/null, and a "splice_write" implementation exists only for /dev/null. (The /dev/zero splice_read implementation could be optimized by pushing references to the global zero page to the pipe, but that's an optimization for another day.) Signed-off-by: Max Kellermann --- drivers/char/mem.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 1052b0f2d4cf..263c19cd6fb9 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -640,6 +640,7 @@ static int open_port(struct inode *inode, struct file *filp) #define full_lseek null_lseek #define write_zero write_null #define write_iter_zero write_iter_null +#define splice_write_zero splice_write_null #define open_mem open_port static const struct file_operations __maybe_unused mem_fops = { @@ -677,6 +678,8 @@ static const struct file_operations zero_fops = { .read_iter = read_iter_zero, .read = read_zero, .write_iter = write_iter_zero, + .splice_read = copy_splice_read, + .splice_write = splice_write_zero, .mmap = mmap_zero, .get_unmapped_area = get_unmapped_area_zero, #ifndef CONFIG_MMU @@ -688,6 +691,7 @@ static const struct file_operations full_fops = { .llseek = full_lseek, .read_iter = read_iter_zero, .write = write_full, + .splice_read = copy_splice_read, }; static const struct memdev {